Introduction to Python's OS module features

Source: Internet
Author: User
Tags zip

Learning Python has been intermittent, and today we're going to introduce a very powerful module of python---OS, when we came to the case not using standard Python, but using the Python sibling Ipython,ipython is a python Interactive shell, which is much easier to use than the default Python shell, supports variable automatic completion, automatically shrinks, supports bash shell commands, and has many useful functions and functions built into it.

Ipython are required to be installed individually and are simple to install, as follows:

wget http://ipython.scipy.org/dist/0.10.1/ipython-0.10.1.zip
Unzip ipython-0.10.1.zip 
CD ipython-0.10.1
ls    
python setup.py install    
support Ipython installation completed.

The biggest difference between Ipython and standard Python is that Ipython will number each line in the command prompt. Let's use Ipython to learn the following OS features:

[Root@localhost ~]# Ipython Python 2.6 (r26:66714, Dec, 11:17:00) Type "copyright", "credits" or "Licens    
        
E "For more information."    
IPython 0.10.1--an enhanced Interactive Python.         ?    
-> Introduction and Overview of IPython ' s features.    
%quickref-> Quick Reference.    
Help-> the Python ' s own Help system.   Object? -> Details about ' object '. ? object also works,??    
        
Prints more. In [1]: Import OS imports OS module in [2]: OS.GETCW os.getcwd os.getcwdu pressed the TAB key to automatically align and enumerate for you. This is the lazy man's favorite in [2]: OS.GETCWD () get current path out[2]: '/root ' in [3]: Os.chdir ("/et") replace Directory and path Display all 244 possibilities?     (Y or N) automatically enumerates in [3]: Os.chdir ("/etc/init.") The habitual hand pressed the tab, haha ... It's going to help us automatically align, strong,/etc/init.d/networkmanager/etc/init.d/mysqld/etc/init.d/acpid/etc/init.d/nag Ios/etc/init.d/anacron/etc/init.d/netconsole/etc/init.D/apmd/etc/init.d/netfs ...                    --more--in [3]: Os.chdir ("/etc/init.d/") Replace path to/ETC/INIT.D under [4]: OS.GETCWD ()                  Let's take a look at the current path out[4]: The '/etc/rc.d/init.d ' output shows the path we switched in [5]: Os.ctermid ()  Returns the control terminal of the process corresponding to the name of the filename out[5]: '/dev/tty ' in [6]: Os.getegid () Get the ID of the current process Out[6]: 0 in                 [7]: OS.GETG tab auto-align Os.getgid os.getgroups in [7]: Os.getgid ()    
        
Get the ID of the current process Out[7]: 0 in [8]: os.getgroups () Get the ID of the Supplemental Group list and the current process out[8]: [0, 1, 2, 3, 4, 6, 10]              In [9]: Os.getlogin () gets the login username for the current control terminal out[9]: ' Root ' in [[]: Os.getpgrp () Get current process group ID OUT[10]: 5484 in [one]: Os.getp os.getpgid os.getpgrp os.getpid os.getppid in           [One]: os.getpid () get current process ID out[11]: 5484 in [[]: Os.getppid ()  Get parent Process ID OUT[12]: 5456 in [[]: Os.getuid () get current User ID Out[13]: 0 in [[]: Os.uname () Get the currently running version details OUT[14]: (' Linux ', ' localhost.localdomain ', ' 2.6.18-194.26.1.el5 ', ' #1 SMP Tue Nov 9 12:54:40 EST ', ' i686 ') in [[]: Os.name ()-------------------------------------------    
        
--------------------------------TypeError Traceback (most recent call last)
        
/etc/rc.d/init.d/<ipython console> in <module> () TypeError: ' str ' object are not callable In []: Os.name Get the operating system, if it is under window, the resulting return value should be "NT" out[16]: ' POSIX '

Hehe, the above is some common OS module some introduction, of course, there are other more functions, if interested, their own research go, haha, today is here.

This article from "You are a passer-by or fearless" blog, please be sure to keep this source http://world77.blog.51cto.com/414605/482465

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.