string.replace() produces TypeError: an integer is required

theKid cmlambert at hotmail.com
Wed Mar 12 16:16:58 EST 2003


> 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

I forgot to mention in my original post that I'd also tried what
you've suggested.  Indeed, it works on the command line, but not in
the script.  I've opted to use re.sub() instead to get round it.

Craig




More information about the Python-list mailing list