Summary of the use of the OS module and Python learning notes

Source: Internet
Author: User

Summary of the use of the OS module and Python learning notes

Copy codeThe Code is as follows:
#! /Usr/bin/env python
#-*-Coding: UTF-8 -*-
 
Import OS
 
Print "n welcome everyone to learn Python with me ";
 
System = OS. name; # obtain the system type
If (system = "nt "):
Print "your operating system is windows ";
Print "the specific path delimiter in windows is" + OS. sep; # obtain the system Separator
Print "Terminator effect of your computer system" + OS. linesep; # obtain the system line break
Else:
Print "your operating system is Linux ";
Print "the specific path delimiter in windows is" + OS. sep;
Print "The Terminator of your computer system is" + OS. linesep;
 
Path = OS. getcwd (); # obtain the current directory
Print "the directory in which you run the program is" + path;
 
Print "your computer's Path environment variable is" + OS. getenv ("Path"); # Get the environment variable value OS. putenv (key, value) You can set the environment variable value
 
Print "the files in your current folder are :";
Print OS. listdir (path); # obtain all files in the folder
If (OS. path. exists ("test.txt"): # checks whether the file exists.
OS. remove ("test.txt") # delete a specified file
Print "n deleted ";
Else:
Print "n file does not exist ";
Print "Let's delete an object. The deleted Result :";
Print OS. listdir (path );
 
Print "n view your ip address: n ";
Print OS. system ("ipconfig"); # Run the system command
 
Filepath1 = "C: Python27 ";
Filepath2 = "C: Python27os. py ";
 
If (OS. path. isfile (filepath2): # Check whether the file is correct.
Print filepath2 + "is a file ";
If (OS. path. isfile (filepath1 )):
Print filepath1 + "is a file ";
Else:
Print filepath1 + "not a file ";
 
Name = "OS. py ";
Print "The program size is ";
Print OS. path. getsize (name); # Get the file size
Name = OS. path. abspath (name); # obtain the absolute path of the object
Print "the absolute path of this program is" + name;
 
 
Print "The program path file names are :";
Print OS. path. split (name); # separate file names from paths
 
Files = OS. path. splitext (name); # separate file names from extensions
Print "the extension of this program is" + files [1];
 
Print "The program file name is" + OS. path. basename (name); # Get the file name
 
Print "the path of this program is" + OS. path. dirname (name); # obtain the path of the file


What if people always cough?

Take medicine! Or go to the hospital to check the lung
 
How to Learn about Python

C ++, Java, and even C # can all be seen as the same type of language: C ++ is flexible, but complicated syntax makes production efficiency low, and Java improves production efficiency, however, flexibility is lost. C # is a good balance between production efficiency and flexibility, but it is still not enough. Otherwise, the father of Boo language will not be angry with Boo. Python is a dynamic type and a strong type language. A dynamic type means that you no longer need to make numerous declarations for the type of each variable, because the compiler will help you make type judgments, it will determine the type of the Variable Based on the Value assignment of the variable. A strong type means that you cannot use a string as an int unless you explicitly convert it. Python itself is compact, because space is ignored in C ++, Java, C #, and "{}" to define code blocks, if you like it, you can write all the code on one line, so you can write it as dizzy as possible. It is not possible, because there is only one Separator in it, namely the colon ":", and the code block is distinguished by indentation. Maybe you will be a bit unaccustomed to this method at the beginning, but later, you will find that this method will benefit you a lot, because you have developed a good code style. Don't think that Python is a very academic language, although many people think it is very suitable as an entry-level language for learning programming. In fact, Python is not only suitable for beginners to learn programming, but also a powerful language. You can use it to do anything other languages can do. Python itself is almost everywhere, and programs written in Python can run in various mainstream operating systems, even Palm. Oh, I almost forgot. Eric Raymond also told us that hackers must master four languages. The first step is Python ., Of course, if you cannot leave. NET in a day, you should start learning Python from IronPython. Compared with C ++, Java, and even C #, is it much faster to write and execute this classic program in Python? Haha ~~~ If I make up my mind to say that Python is highly productive, you will already scold me for being a lie. Okay. Let's try some practical code. But before that, you have to download two very famous class libraries: wxPython and Twisted. Is the download and Installation complete? Let's start our tour of EnjoyPythonwith you in ten minutes. FromwxPython. wximportwxPySimpleApp, wxFrameapp = wxPySimpleApp () frame = wxFrame (None,-1, "HelloWorld ")

Related Article

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.