开发者

Python splitting string. Need help

开发者 https://www.devze.com 2023-02-10 12:47 出处:网络
I\'m trying to split a string into two different words. I have the following string: test / I want to split it so I can do

I'm trying to split a string into two different words. I have the following string:

test /

I want to split it so I can do

os.chdir('/')

I've tried different splitting techniques but they split by letter so it b开发者_如何学Cecomes

't','e','s','t', '', '/'


'test /'.split() will give you ['test', '/']. os.path.split() is for splitting paths and you might find it useful.


Splitting on a space isn't working? What are you trying to do eventually?

'test /'.split(' ')

or no parameters at all:

tst, path = 'test /'.split()
os.chdir(path)
0

精彩评论

暂无评论...
验证码 换一张
取 消