1

How to get 'path/to/file/'

This is missing the last '/'

In [2]: os.path.join('path', 'to', 'file')
Out[2]: 'path/to/file'

This does not help:

In [3]: os.path.join('path', 'to', 'file', '/')
Out[3]: '/'
idjaw
26.8k10 gold badges68 silver badges84 bronze badges
asked Nov 3, 2015 at 2:06
3
  • I'm curious: why do you want a final slash on the filename? Commented Nov 3, 2015 at 3:29
  • I am concatenating 2 os.path.joins Commented Nov 3, 2015 at 6:53
  • If you concatenate two path joins then your code shoud look like os.path.join(os.path.join('path', 'to', 'file'), os.path.join('second', 'path')) and everything will be fine. Commented Nov 3, 2015 at 8:02

2 Answers 2

2

Just add it yourself: os.path.join('path', 'to', 'file') + os.path.sep

answered Nov 3, 2015 at 2:07
Sign up to request clarification or add additional context in comments.

Comments

1

have your tried: os.path.join('path','to','file'+os.sep)

answered Nov 3, 2015 at 2:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.