0

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 becomes

't','e','s','t', '', '/'
1
  • looks like you've tried exactly one "splitting technique" which is list("test /") Try looking at the str.split() method Commented Feb 15, 2011 at 22:56

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.