Re: [Zope] [python] converting int to string?
> > >in python you can do: > > > > >str(int) > > > > >and in zope you do it like > > > > >_.str(int) > > > > You can also use the short form in both Zope and Python: > > > > `int` > > > > Two of those funny `` characters surrounding what you want converted to a > > string. > > The backtick notation `` is actually the shorthand for repr(), not str(). In the > case of ints this will give you the same result but not in all cases. I second > Jens's recommendation. _Learning Python_ is a great book. Oops. Please pardon the ambiguity. I meant, "in the case of ints... but not in the case of some other types of objects." --jfarr ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] [python] converting int to string?
> >in python you can do: > > >str(int) > > >and in zope you do it like > > >_.str(int) > > You can also use the short form in both Zope and Python: > > `int` > > Two of those funny `` characters surrounding what you want converted to a > string. The backtick notation `` is actually the shorthand for repr(), not str(). In the case of ints this will give you the same result but not in all cases. I second Jens's recommendation. _Learning Python_ is a great book. --jfarr ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] [python] converting int to string?
From: Jens Vagelpohl >in python you can do: >str(int) >and in zope you do it like >_.str(int) You can also use the short form in both Zope and Python: `int` Two of those funny `` characters surrounding what you want converted to a string. Regards Max M Max M. W. Rasmussen,Denmark. New Media Director private: [EMAIL PROTECTED] work: [EMAIL PROTECTED] - Specialization is for insects. - Robert A. Heinlein ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] [python] converting int to string?
in python you can do: str(int) and in zope you do it like _.str(int) "Learning Python" by o'reilly is a pretty good beginner's book for python. i suggest you read it. it's well written and gives you the basics. jens on 1/7/01 11:12, Lee at [EMAIL PROTECTED] wrote: > 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:[EMAIL PROTECTED] > http://www.footkick.co.uk/lee > ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] [python] converting int to string?
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:[EMAIL PROTECTED] http://www.footkick.co.uk/lee ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )