[Tutor] shlex.split if there is an apostrophe in the string?

Emile van Sebille emile at fenx.com
Fri Jan 7 21:13:53 CET 2011


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()

Emile


which works great until it gets to
> the first apostrophe:
>
> fin = open('huckfinn.txt')
> startstring = 'START OF THIS PROJECT'
>
> for line in fin:
>      print line
>      words = shlex.split(line)
>
> This is the line is where it's choking, complaining that there is no
> closing quote:
>
> YOU don't know about me without you have read a book by the name of The
>
> How can I get shlex.split to ignore single apostrophes such as the one above?
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>




More information about the Tutor mailing list