Use Python to detect your computer system and name
I work on several computers, sometimes Widows, sometimes Linux, so I got a problem after I pull my project file from Git. That is the file path.
To cope with this problem, I have to find out which computer I am working on at moment. With Python, you have sevral ways to do that:
- >>>import platform
>>>platform.node() => you will get the name of the computer
[Out]: codehamster-home - >>>import socket
>>>socket.gethostname() => get also the name of the computer
[Out]: codehamster-work - >>>import platform
>>>platfrom.uname() => you will get the detail information about your computer - >>>import sys
>>>sys.platform => you will the type of the system
[Out]: win32
Here is my function, which adjust the path according your computer: