How to recast integer to a string

J

James

How to recast an integer to a string?

something like
n = 5
str = str + char(n)


J.L
 
L

Larry Bates

James said:
How to recast an integer to a string?

something like
n = 5
str = str + char(n)


J.L
Two items:

1) Never use 'str' as a variable name as it will
shadow the built in str function. If you do, this
WILL jump up and bite you.

2) Either s=str(n) or s="%i" % n will return string
containing '5' (without the quotes of course).

Note: chr(n) would return character whose ASCII decimal
value is 5 (ASCII ENQ).

-Larry Bates
 
F

Fredrik Lundh

James said:
In python2,4, I 've got
TypeError: 'str' object is not callable

if you want to use a builtin function, you cannot use the same name
for your own variables.

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top