Detect operating system types (Linux or Windows) using Python

If you use Dropbox to sync files between platforms, you may face the problem of editing Python codes on Windows, but execute the code on Linux. In this case, identifying the OS type inside Python codes becomes necessary and unavoidable.

Here is the code.

import os

# on linux
if (os.name != 'nt'): 
	path_data = os.environ['HOME'] + '/Dropbox/'
# on windows
else: 
	path_data = 'C:/Users/' + os.getenv('username') + '/Dropbox/'

 

你可能感兴趣的:(Detect operating system types (Linux or Windows) using Python)