pythonandroidwindowspath

File path good for Windows and Android


I have a python script that uses images from a folder. The script might work on Windows and Android as well. The problem is I should indicate different file path for the same images (included in the folder where the script is). Is there a format I can use valid for both? For Android I am using "./image.png", but this does not work on Windows.


Solution

  • If you want some dynamic path, you can use os:

    import os
    path = os.path.join('folder1', 'folder2', '...', 'image.png')
    

    You can use as many as you need, or just image.png.