# -*- coding: utf-8 -*-from filePackage import MyFileif __name__ == ‘__main__‘: a = MyFile("./filePackage/test.txt") a.printFilePath(); a.testReadFile();Directory structure:
If __init__.py not write anything, then in the main.py can also write:import filePackage.fileif __name__ == ‘__main__‘: a = filePackage.file.MyFile("./filePackage/test.txt") a.printFilePath();However, it is not recommended to do so, and it is recommended to expose the common classes in the module as described above
http://www.lfd.uci.edu/~gohlke/pythonlibs/Thank the University of California Irvine (University of California, Irvine) for the convenience of the fluorescent Power Lab (the Blind translator, formerly Laboratory for Fluorescence DYNAMICS,LFD), click to view the download.This address provides a number of 32-bit and 64-bit binary files released by the official CPython of the Open source expansion pack, which is easy to install.After downloading the WHL, use the %PYTHON_PATH%/Scripts/pip.exe Install
First, the moduleModule:A set of functions, in Python a py file is a module, the module name is the file name of the py file;Benefits of the module:1. Reduce duplication of code2. Take doctrineDefine the module:is to create a py file;Using modules:Keywords: importUsage: Import module name (do not add py suffix)Note that the execution file is your current logic program, and the module file is the file you use to invoke the function;First Import module:
sadfsadfasdfegon Alex SB Egon '))Print (Re.search (' ^alex ', ' Alex SB sadfsadfasdfegon Alex SB Egon '). Group ())Re.search, take the first result, if not return none, if you want the result to display directly after the group (); return to none with group () will give an errorPrint (Re.match (' Alex ', ' Alex SB sadfsadfasdfegon Alex SB Egon '). Group ())Print (Re.match (' Alex ', ' 123213 Alex SB sadfsadfasdfegon Alex SB Egon '))Re.match equivalent to ^ version of searchinfo= ' A:b:c:d 'Prin
Import module fromimport moduleWhat is the difference between the above code?From module Import * This kind of import imagination and the code inside the module is copied into the current module (that is, the location of the statement), you can directly use the module inside the variable name and method, etc.So this approach does not take effect if the variables and methods have the same name as the current module.Import Module If you use variables or methods inside, you must prefix the module
Similar to the C language contains the header file to refer to other files of the function, Python also has a similar mechanism, the common introduction method has the followingImport Module name # module name is the py file name # Use This method to use the module name when calling the function later. function name () This form from import function name # the function name () can be used directly when using this method to invoke functions.It's imp
First, the module imports with importcal.py:#!/usr/bin/pythondef Add (x, y): return x+yif __name__ = = ' __main__ ': Print addNote: __name__ is a built-in variable and is a file name if the value is called __mail__ directly in the CLI.Import in new.py:Import Calprint cal.add (2,3);II. Packages: Modules organized by directory name1. Create a folder with the name of the package name2. Create a __init__.py file under this folder3. Store script files, com
Author: vamei Source: http://www.cnblogs.com/vamei welcome reprint, please also keep this statement. Thank you!
The concept and system of Linux repeatedly mentions the importance of processes. The Python OS package contains query and modification.Process Information. These Python tools comply with the concepts related to the Linux system, so they can help you understand the Linux system.
1. Proces
name of the referenced module.second, the package1. Package1) definitionA package is a way to organize the Python module namespace by using the '. Module name ', specifically a folder containing __init__.py files, created to be organized with folders/modulesAttention:A. In python3.x, the import package does not fail even if there is no __init__.py file under the package, and in python2.x, the file must exist under the packageB. The purpose of creatin
1. After successfully installing Python under Windows, there are Easy_install and PIP tools in the scripts directory of the installation directory2. If the PIP is not installed, go to the command line, switch to the Scripts folder under the Python installation directory, run Easy_inatall pip3, Pip installed successfully, in CMD into the DOS environment to execute PIP, will prompt how to use4. Example: Pytho
)# import Xiaomei# import RE# import Sys# Print (sys.modules)# Print (Sys.path)# executes the Python interpreter, has loaded some built-in modules in memory, when importing the module, if the module does not exist# in the Sys.modules, only from the path given by Sys.path to find in turn# Sys.path can completely determine if a module can be found (except for some built-in modules that have already been loaded in memory)# import Xiaomei# When a py file
1. centos74 installed after the default python2.7.5 but no pip need to install themselves:Copy fromHttps://www.cnblogs.com/rain124/p/6196053.htmlSpecific commands1) wget https://pypi.python.org/packages/b8/04/be569e393006fa9a2c10ef72ea33133c2902baa115dd1d4279dae55c3b3b/ Setuptools-36.8.0.zip#md5=3ecaa938a4c95a74dfbcd6340a47c7c5Download Setup.toolsUnzip Setuptools-36.8.0.zipPython setup.py InstallInstallation2)wget https://pypi.python.org/
This article discusses Python's from import all from one module
From
# something.py
public_variable =
_private_variable =
public_function ():
print ("I ' m a public function! yay! ")
Def _private_function ():
print ("Ain ' t nobody accessing me from another module...usually")
class Publicclass ( Object):
Pass
class _weirdclass (object):
Pass
In the Python interpreter, we can perform the from something import * and see
The first thing to understand about the numerical Python package is that numerical python will not let you do any work that standard Python cannot do. It just allows you to do the same tasks that standard Python can accomplish with much faster speed. More than that, many array operations are much more elegant to expres
1. __init__.py defines the properties and methods of the packageGenerally empty file, but must exist, no __init__.py indicates that his directory is not a package2. When importing the package, useFor example, there is a test directory with xx1.py,xx2.py,__init__.py three files under test| Test| | __init__.py| | xx1.py| | xx2.pyThe test can be imported as a package, importing all the files under testFrom Test import *The actual import is the variable __all__ in __init__.py, i.e. __all__ = [' xx1
Take Centos7 as an example:
Source installation python, usually first install some devel package:
Yum-y install XZ wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel
Then download the source code
Decompression Source:
TAR-JXF PYTHON.X.TAR.XZ
CD pyhton.x
./configure
Here are some options,--Bindir: The path where which Python is located after installation is complete
--prefix
This example describes how Python uses 7z to unzip the APK package. Share to everyone for your reference. Specific as follows:
This code is extracted from the shell by invoking the 7z APK package
def run_shell (Command, Mayfreeze=false): Def check_retcode (Retcode, cmd): if 0! = Retcode:print >> sys.stderr, ' err Executing ' + cmd + ': ', Retcode sys.exit (retcode) def read_close (f): F.seek (0) d = f.read () f.close () return D #print G T;> Sys.std
Sometimes we use the download Python's own pip to install some toolkit, will report the following errorA satisfactory version is not found and our PIP may need to be upgraded, so usepython-m pip Install--upgrade pipUpgrade Pip,--upgrade followed by the name of the library that needs to be upgradedThen continue to try to find or not, will report the same error, when considering the network is a problem, my network is sometimes unstable, then we use the domestic image source to acceleratePip Insta
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.