[Tutor] convert array into string

Ibraheem Umaru-Mohammed iumarumo@eidosnet.co.uk
Fri, 30 Aug 2002 13:39:48 +0100


["Kyle Babich"="Kyle"]
Kyle >> How would I convert something like:
Kyle >> abc = ["abcdef"]
Kyle >> into
Kyle >> abc = "abcdef"
Kyle >> 

Assuming you have stored your string in a list, you can just index into 
the list as follows:

	abc = ["abcdef"]
	abc = abc[0]

But you may also want to use the "str" function, but in this case it is
unnecessary.

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

You can use the read() method instead of readlines() to read everything
into a variable, and then apply the split() method on the result.

e.g

	abc = open("/path/to/foo").read().split()

then you can just index into the list referenced by abc, e.g abc[0] for
the first line, abc[1] for the second line etc etc.
	
Kyle >> Thank you,
Kyle >> --
Kyle >> Kyle
Kyle >> 

Kindest regards,

				--ibz.

-- 
				Ibraheem Umaru-Mohammed 
					"ibz"
			umarumohammed (at) btinternet (dot) com