Emile van Sebille wrote:
On 1/7/2011 11:22 AM Sean Carolan said...
I'm practicing manipulating data with a text file.  I'm trying to use
shlex.split to break up each line,

Is there a reason not to use split directly?

for line in fin:
  words = line.split()


shlex.split was specifically written to overcome a limitation of str.split, namely that str.split doesn't understand quoting:

>>> text = "This includes some 'quoted text', as they call it."
>>> text.split()
['This', 'includes', 'some', "'quoted", "text',", 'as', 'they', 'call', 'it.']
>>> shlex.split(text)
['This', 'includes', 'some', 'quoted text,', 'as', 'they', 'call', 'it.']

Although the functions have the same name, they do different things.


--
Steven

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to