[Tutor] convert array into string

Erik Price erikprice@mac.com
Fri, 30 Aug 2002 08:50:28 -0400


On Friday, August 30, 2002, at 12:25  PM, Kyle Babich wrote:

> How would I convert something like:
> abc = ["abcdef"]
> into
> abc = "abcdef"
>
> What I'm actually trying to do is convert a file.readlines() into a
> single string and then .split(" ").  Is this possible?  I've tried
> every kind of for loop I can think of to make this work, but I can't
> figure it out.

Well, file.readlines() takes a file and reads each line into a separate 
string, then puts each string into a list.  So you get a list of 
strings.

Two ways to put that back into one giant string are

   1) join() method found in the string module - glues a sequence 
together using whatever string you specify
   2) don't use file.readlines() - just use f.read(), which reads the 
whole file into a string

You can split(" ") afterward.

I don't recommend the first option because it's redundant -- use the 
second one.



Erik




--
Erik Price

email: erikprice@mac.com
jabber: erikprice@jabber.org