Recently in porting a website, trying to get the data of this website to do analysis. To support the normal operation of a multi-system environment. What OS do you need to know about the current system environment?
1.python built-in platform library. It is convenient to get the current system environment when what OS system.
ImportPlatformPrintPlatform.system ()#get operating system environmentPrintPlatform.platform ()#get the operating system name and version numberPrintPlatform.version ()#get the operating system version numberPrintPlatform.architecture ()#get the number of bits in the operating systemPrintPlatform.machine ()#Computer TypePrintPlatform.node ()#the network name of the computerPrintPlatform.processor ()#Computer processor InformationHelp (Platform)#it's too much. One by one list, ask for help>>>windowswindows-7-6.1.7601-SP16.1.7601('32bit','WindowsPE') x86szdliunxx86 Family6 Model Stepping 9, Genuineintel
2. Remove newline characters.
Do not know how many people to understand the line character? Let's start with a brief introduction to the definition of different operating systems and newline characters.
Unix/linux system, the end of each line is only "< line >", that is, "\ n";
Inside the Windows system, each line ends with "< enter >< wrap >", or "\ r \ n";
Mac system, the end of each line is "< Enter >", that is "\ r".
For this action, the UNIX/LINUX environment generally has only one 0x0a for line break ("\ n"), Windows is generally 0x0d and 0x0a two characters ("\ r \ n"), the Mac OS system uses a carriage return CR 0x0d to represent the next line (\ r) .
3. The final code.
ifPlatform.system () = ="Windows": F.write (Data.get_text (). Strip ('\ r \ n'))) elifPlatform.system () = ="Linux": F.write (Data.get_text (). Strip ('\ n'))) Else:#For Mac OSF.write (Data.get_text (). Strip ('\ r')))
Python uses the Platform module to get the system environment and remove newline characters