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

Steven D'Aprano steve at pearwood.info
Sat Jan 8 01:38:44 CET 2011


Sean Carolan wrote:
[...]
> 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?


 >>> shlex.split("The Doctor's bow ties are cool, and Amy's uniform is 
hot.")
['The', 'Doctors bow ties are cool, and Amys', 'uniform', 'is', 'hot.']
 >>>
 >>> shlex.split("The Doctor's bow ties are cool, and Amy's uniform is 
hot.", posix=False)
['The', "Doctor's", 'bow', 'ties', 'are', 'cool,', 'and', "Amy's", 
'uniform', 'is', 'hot.']


Fans of Doctor Who will know exactly what I'm talking about...



-- 
Steven



More information about the Tutor mailing list