Python local folder path for each platform -


my script works in special folder, name "fold". on different computers , operation systems path folder different. example, on mac will: "/users/user/fold". on windows - "c:\users\user\desktop\fold" . how can input path folder in python script working on each platform? should type inside script, if script works inside "fold" folder?

the os module has functionality identifying various operating systems

in code can this

import os  if os.name == 'nt'     # nt stands windows     path = 'c:\users\user\desktop\fold' elif os.name == 'posix'     # linux or mac     path = '/home/user/desktop/fold' 

the platform module gives more details os module os might return posix both linux , mac on linux machine platform outputs this

import platform  >>> print(platform.system()) linux >>> print(platform.release()) 3.13.0-76-generic 

platform.system() should return 'darwin' mac


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -