In a Python program, you may want to distinguish between Windows and Linux because the path name is different, such as when you specify the file name with the full path.
If you just need to tell if it's Windows or Linux, ʻos.name` is enough.
https://docs.python.org/3.5/library/os.html#os.name
For Windows
>>> import os
>>> os.name
'nt'
For Linux such as Bash on Ubuntu on Windows
>>> import os
>>> os.name
'posix'
So, if you check ʻos.name`, you can see which OS.
Discrimination example
if os.name == 'nt': fname = 'C:\Windows\Fonts\YuGothM.ttc'
else: fname = '/mnt/c/Windows/Fonts/YuGothM.ttc'
Recommended Posts