[Zope] [python] converting int to string?

Lee lee.reilly@ntlworld.com
Sun, 07 Jan 2001 16:12:58 +0000


Hi,

I wonder if anyone could help me here...

Is there any way to convert an integer to a string data type in Python?
I see there is a facility for accomplishing the reverse conversion
(string -> int)?

I have 4 integers, which are primarily used to handled the logic in the
program below (in the while loops). The value of this integer must also
be added to a string (as a table column name), which will be used to
create a SQL query.

Here's a rough sketch of the program:

p = 2 # no.of practicals
t = 2 # no.of tutorials
a = 2 # no.of assignments
b = 3 # no.of bomus marks

c = "52225"

SQL = "CREATE TABLE CLASS" + c + "\n"
SQL = SQL + "( \n"
SQL = SQL + "matric float, \n"
SQL = SQL + "fname varchar, \n"
SQL = SQL + "lname varchar, \n"
SQL = SQL + "uname varchar, \n"

while p > 0 :
     SQL = SQL + "p" + p + " integer, \n" # cannot add type "int" to
string
     p = p - 1

while t > 0 :
     SQL = SQL + "t" + t + " char(1), \n"
     t = t - 1

while a > 0 :
     SQL = SQL + "a" + a + " integer, \n"
     a = a - 1

while b > 1 :
     SQL = SQL + "b" + b + " integer, \n"
     b = b - 1
while b > 0 :
      SQL = SQL + "b" + b + " integer \n" # ',' taken out from last
query
      b = b - 1

SQL = SQL + ")"

Of course, I could have a load of statements in the while loops like:

if p = 1:
    pString="1"
    ... etc.

But that would look hella ugly!

Another alternative would be to send both the integer value and a string
parameter (converted by Zope) in the calling DTML method. This is okay -
but is there a better way to do it?

As usual, thankyou very much in advance.

Is this off-topic BTW? Should I address any future questions regarding
Python to a Python newsgroup/list?

--
Lee Reilly
mailto:lee.reilly@ntlworld.com
http://www.footkick.co.uk/lee