Python shlex - Split -


i split shlex kind of string:

str = 'this doesn''t work' 54e+5 15 .false. 'another example of "test"' 

result expected:

  • this doesn''t work
  • 54e+5
  • 15
  • .false.
  • another example of "test"

my main issue syntax uses double simple quotes '' inside quoted string. cannot shlex work. tried following settings:

lex = shlex.shlex(str) lex.whitespace_split = true lex.quotes = "'" 

but splits between '' if there no whitespace character.

thank !!

ideally, if control how text generated, write file csv , allow csv module quote items. reading list cinch.

but given text is, how about:

in [4]: import shlex in [6]: text = """'this doesn''t work' 54e+5 15 .false. 'another example of "test"'""" in [34]: [item.replace('\\"\\"',"''") item in shlex.split(text.replace("''",'\\"\\"'))] out[34]: ["this doesn''t work", '54e+5', '15', '.false.', 'another example of "test"'] 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -