string.replace() produces TypeError: an integer is required
Max M
maxm at mxm.dk
Wed Mar 12 03:22:20 EST 2003
theKid wrote:
> As far as I can tell, I'm using the function correctly:
>
> import string
> import types
>
> print type(data)
> print data
> data = string.replace(data, '\t', '\\t') # line 58
> data = string.replace(data, '\n', '\\n')
> print data
>
>
> Am I using string.replace() correctly?
Yes. Most likely the problem is that you have deleted your "data"
variable by mistake. It works when I define data.
data = "Hi\tThere"
import string
import types
print type(data)
print data
data = string.replace(data, '\t', '\\t') # line 58
data = string.replace(data, '\n', '\\n')
print data
>>> <type 'str'>
>>> Hi There
>>> Hi\tThere
--
hilsen/regards Max M Rasmussen, Denmark
http://www.futureport.dk/
Fremtiden, videnskab, skeptiscisme og transhumanisme
More information about the Python-list
mailing list