1

Let's say I have a = "C:\folder1\folder2\picture.jpg" How can I assign variable b to file's name with its extension: b = 'picture.jpg'

1
  • os.path.basename(mypath) Commented Mar 17, 2016 at 13:18

1 Answer 1

1

Without too many complications, you can just use the os module as follows:

import os
a = "C:\folder1\folder2\picture.jpg"
b = os.path.basename(a)

Which will output what you desire: 'picture.jpg'

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

Comments

Your Answer

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.