Basic Concepts-modules are the basic way for Python to organize your code-A Python script can be run separately or imported into another script, and when the script is imported run, we call it module-All. py files can be imported as a module features-The module name is the same as the file name of the scriptFor example, if you write a hello.py script, you can import it with an import Hello statement in another script-Python modules can be organized into packages by directoryto create a 1 package:-Create a directory with the name of the package name-Create a __init__.py file in this directory-store script files or compiled extensions and sub-packages in this directory, as needed-Import pack.m1,pack.m2,pack.m3 Extended-the location of the Python built-in module is stored in the (Sys.path environment variable, similar to the path in the shell)The main modules are installed under/usr/lib64/python 2.x/(Python-libs package installed)-Customize the Python module path1, Import sys package, use append to add pathsys.path.append ('/tmp ')2. Modify System VariablesVim ~/.BASHRCExport Pythonpath=/tmp Examplewrite a script like the WC command
# !/usr/bin/env python def = = = Len (content.split (' \ n ')) print = open ('/etc/passwd'). Read () printinfo (string)
compared with the WC command to find a row, the reason is that we count the line with \ n as a delimiter, although it is three rows, three \ n, then with \ n Split, it is 4 lines. Improved version:
# !/usr/bin/env python def = = = Content.count (' \ n ') print = open ('/etc/passwd'). Read () printinfo (string)
Only the number of occurrences can be counted.
Script calls
Cat 2. py#!/usr/bin/env python
Import WC
then execute 2.py can go to call wc.py (the current directory, no words will go to pythonpath), the call will be generated after the Wc.pyc file, convenient next call, note that the module name and variable name definition rules are the same, cannot start with a number
Use of the python-module