Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change a variable value depending on the system being used? (Python)

E.g. if Windows is used, add this option:

chrome_options.add_argument('user-data-dir=C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default)

in case of OS X:

chrome_options.add_argument('user-data-dir=~/Library/Application Support/Google/Chrome/Default')

I could not find any information on this topic. It’s kind of more a question about how usually in development os versions problems are resolved? E.g for GitHub: should I write and push 2 versions of code for each OS?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

import platform

system = platform.system()

if system == "Windows":
    chrome_options.add_argument('user-data-dir=C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default')
elif system == "Darwin":
    chrome_options.add_argument('user-data-dir=~/Library/Application Support/Google/Chrome/Default')
else:
    raise Exception("Unsupported operating system")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading