[Tutor] easy newbie questions: text file to list?

Gerrit Holl gerrit@nl.linux.org
Tue May 20 05:54:02 2003


ashleigh smythe schreef op dinsdag 20 mei om 03:53:43 +0000:
> I would like to turn these items into a list (that I can save, not just
> work with in the interpreter) but I'm confused about strings and
> pickling etc.

There is a string method that does exactly that:

  9 >>> s = "aaa\nbbb\nccc"
 10 >>> s.splitlines()
['aaa', 'bbb', 'ccc']
 11 >>> s.splitlines(True) # keep the newlines
[aaa\n', 'bbb\n', 'ccc']

> Thanks for any help/documentation pointers!

All string methods are documented at:

http://www.python.org/dev/doc/devel/lib/string-methods.html

yours,
Gerrit.

-- 
39. He may, however, assign a field, garden, or house which he has
bought, and holds as property, to his wife or daughter or give it for
debt. 
        -- Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/