In our company, we have a shared folder to which I read and write (mostly CSV files) using Python. I create Python scripts and my teammates run on their windows systems which have different path separators as follows.
- Linux :
/mnt/sherpa/Marketing
- Windows :
'S:\\Marketing\\
- Mac :
/Volumes/sherpa/Marketing/
How do I make these scripts portable to avoid manually changing the file paths as I send these scripts across to other OS?
I have considered solutions like pathlib, os.path but these don't work well with shared folders. Currently using below code to identify the OS on which the python script is being used and then select the path accordingly.
Is there a better way to handle this?
from sys import platform
if platform == "linux" or platform == "linux2":
# linux
elif platform == "darwin":
# OS X
elif platform == "win32":
# Windows...