Adding text to variables that already contain text

时间:2017-04-24 17:31:23

标签: python python-3.x operating-system mp3

I'm attempting to create a music player in Python 3.5.2 and I'm having trouble making it so users won't have to put the exact filepath for the music they wish to play. This is the code I am experimenting with:

import os    
Minput= input("Insert exact path of mp3: ")    
os.startfile(Minput)

I'm confused on how I would go about making this code so that the user would only input the name of the MP3, not the exact filepath.

In order to play an MP3 file now, a user would input 'MP3_folder\example.mp3'.

1 个答案:

答案 0 :(得分:0)

The easiest way would be to use relative pathing. You will need your users to specify the starting point (typically the directory in which the app was started). The user would then use ./ to represent that directory or ../ to reference the directory above. These can be applied multiple times so ../../ would reference the directory above the directory above the current one. AFAIK all of python's built in file libraries support this by default so it should just work