Re: List to string
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: On Tue, 20 Mar 2007 13:01:36 +0100, Bruno Desthuilliers wrote: 8< --- confusion about left and right It gets worse. When you work on a lathe, a "right hand cutting tool" has its cutting edge on the left... And the worse part is that its for good reason. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
That's pretty funny :) On 3/20/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote: On Tue, 20 Mar 2007 13:01:36 +0100, Bruno Desthuilliers wrote: > Steven D'Aprano a écrit : >> On Mon, 19 Mar 2007 13:11:09 +0100, Bruno Desthuilliers wrote: >> >>> There's no "cast" in Python. It would make no sens in a dynamically >>> typed language, where type informations belong to the LHS of a binding, >>> not the RHS. >> >> Surely you have left and right mixed up? > > (rereading) > (ashamed) > Obviously, yes. > Thanks for the correction. That's okay, I have a big "L" and "R" written on the bottom of my shoes. Of course, they didn't do me any good until I got a "L" and "R" tattooed on my feet. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
On Tue, 20 Mar 2007 13:01:36 +0100, Bruno Desthuilliers wrote: > Steven D'Aprano a écrit : >> On Mon, 19 Mar 2007 13:11:09 +0100, Bruno Desthuilliers wrote: >> >>> There's no "cast" in Python. It would make no sens in a dynamically >>> typed language, where type informations belong to the LHS of a binding, >>> not the RHS. >> >> Surely you have left and right mixed up? > > (rereading) > (ashamed) > Obviously, yes. > Thanks for the correction. That's okay, I have a big "L" and "R" written on the bottom of my shoes. Of course, they didn't do me any good until I got a "L" and "R" tattooed on my feet. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
Steven D'Aprano a écrit : > On Mon, 19 Mar 2007 13:11:09 +0100, Bruno Desthuilliers wrote: > >> There's no "cast" in Python. It would make no sens in a dynamically >> typed language, where type informations belong to the LHS of a binding, >> not the RHS. > > Surely you have left and right mixed up? (rereading) (ashamed) Obviously, yes. Thanks for the correction. -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
On Mon, 19 Mar 2007 13:11:09 +0100, Bruno Desthuilliers wrote: > There's no "cast" in Python. It would make no sens in a dynamically > typed language, where type informations belong to the LHS of a binding, > not the RHS. Surely you have left and right mixed up? x = 1 x = None x = "spam" x = [] The name x has no type associated with it. The object bound to the name does. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
On Mar 19, 8:11 am, Bruno Desthuilliers wrote: > Hitesh a écrit : > > > On Mar 18, 12:28 am, "Hitesh" <[EMAIL PROTECTED]> wrote: > >> Hi, > > >> I've a list like this.. > >> str1 = ['this is a test string inside list'] > > >> I am doing it this way. > > >> for s in str1: > >> temp_s = s > >> print temp_s > > Why this useless temp_s var ? > > > > >> Any better suggestions? > > >> Thank you, > >> hj > > > I want to cast value of a list into string.. > > There's no "cast" in Python. It would make no sens in a dynamically > typed language, where type informations belong to the LHS of a binding, > not the RHS. > > I guess that what you want is to build a string out of a list of > strings. If so, the answer is (assuming you want a newline between each > element of the list): > > print "\n".join(str1) Thank you guys. Yes that helped. :) hj -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
Hitesh a écrit : > On Mar 18, 12:28 am, "Hitesh" <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I've a list like this.. >> str1 = ['this is a test string inside list'] >> >> I am doing it this way. >> >> for s in str1: >> temp_s = s >> print temp_s Why this useless temp_s var ? >> >> Any better suggestions? >> >> Thank you, >> hj > > I want to cast value of a list into string.. > There's no "cast" in Python. It would make no sens in a dynamically typed language, where type informations belong to the LHS of a binding, not the RHS. I guess that what you want is to build a string out of a list of strings. If so, the answer is (assuming you want a newline between each element of the list): print "\n".join(str1) -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
On Sat, 17 Mar 2007 21:28:56 -0700, Hitesh wrote: > > Hi, > > I've a list like this.. > str1 = ['this is a test string inside list'] That's a bad name for the variable. It's called "str1" but it is a list. > I am doing it this way. > > for s in str1: > temp_s = s > print temp_s That's redundant. Why not just "print s"? That will work perfectly. You can do any of the following, depending on what you are trying to do. my_list = ["first string", "second string", "third string"] # print the entire list as a string print my_list # print each string individually for s in my_list: print s # save the string representation of the entire list as a variable my_str = repr(my_list) another_str = str(my_list) Note that repr() and str() may have different results, depending on the type of object you pass into them. # extract the first string into another variable my_str = my_list[0] # insert the third string into another string my_string = "This is the %s here." % my_list[2] Hope that helps. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
On Mar 18, 12:28 am, "Hitesh" <[EMAIL PROTECTED]> wrote: > Hi, > > I've a list like this.. > str1 = ['this is a test string inside list'] > > I am doing it this way. > > for s in str1: > temp_s = s > print temp_s > > Any better suggestions? > > Thank you, > hj I want to cast value of a list into string.. -- http://mail.python.org/mailman/listinfo/python-list