Date: Fri, 10 Feb 2012 00:11:05 -0800
Reply-To: tko <ko.tiffany@gmail.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: tko <ko.tiffany@gmail.com>
Subject: Curly brace plague?
Content-Type: text/plain; charset=us-ascii
Hello,
I work with survey data files with raw variable labels that are filled with
unecessary programming characters/strings. Here's what removes almost
everything I don't want, except for "*{#Company1}*", probably because of the
curly braces issue. Any advice on how to escape a curly brace within a
string?
Thanks,
tko
begin program.
import spss, spssaux, cgi
vdict=spssaux.VariableDict()
nvars = len(vdict)
html_escape_table = {
"&": "&",
">": ">",
"<": "<",
"/": "&fs;",
}
def html_escape(text):
"""Produce entities within text."""
return "".join(html_escape_table.get(c,c) for c in text)
for i in range(nvars):
myvarname = vdict[i].VariableName
myvarlabel = html_escape(vdict[i].VariableLabel)
myvarlabel = myvarlabel.replace(" :","")
myvarlabel = myvarlabel.replace("<b>","")
myvarlabel = myvarlabel.replace("<&fs;b>","")
myvarlabel = myvarlabel.replace("*{#Company1}*", "[Company]")
myvarlabel = myvarlabel.strip(" '")
spss.Submit(r"""
variable labels %s %s .
""" %(myvarname, myvarlabel))
end program.
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Curly-brace-plague-tp5471796p5471796.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
|