Determining which OS is running Python

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

Determining which OS is running Python
Which is better, PyPy or Python?
Which is faster, Python shuffle or sample?
Python is easy
Python OS operation
What is python
Python is instance
My os (python)
What is Python
python int is infinite
[Python] What is Pipeline ...
Which is better, python standard input receiving input () or sys.stdin?
[Python] What is virtualenv
Raspberry Pi with Elixir, which is cooler than Python
[Python] Which is executed first, the class variable or __init__?
[Beginners are worried] Which is better, Ruby, PHP or Python?
[Python] Debugging is more efficient!
Python is painful. But use
Python is an adult language
Python list is not a list
Specify options when running python
[Python] Python and security-① What is Python?
Python release cycle is faster!
Try running Python with Try Jupyter
[Python] * args ** What is kwrgs?
Identity and equivalence Python is and ==
Wrapper running Hadoop in Python
About Python and os operations
Platform (OS) determination by Python
What is a python map?
Python Basic Course (1 What is Python)
Explain what is stochastic gradient descent by running it in Python