Python uses the Platform module to get the system environment and remove newline characters

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.