简体   繁体   中英

string splitting in python with ignoring \r \n cases

I am having this problem which is really weird I am trying to solve it and i can't find the best way.

I am passing this string as an argv[] "copy c:\\root c:\\noot" in python.

and i want to gave c:\\root and c:\\noot all together as one piece when splitting

example:

commandLineOptions = "copy c:\root c:\noot" # this is passed from cmd. 
x = commandLineOptions.split() 
print x 
[copy , c:\root , c:\noot]

cheers,

str.split accepts second parameter - maximum number of 'splits':

>>> commandLineOptions = "copy c:\root c:\noot"
>>> commandLineOptions.split(' ', 1)
['copy', 'c:\root c:\noot']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM