The concept of modules and application software development directory specification


'' '' ''
'' '
Module: a combination of a series of functional
three sources: the third-party custom built
four kinds of forms: a series combination py py document file (packet) c is connected to the interpreter prepared built-in modules compiled shared library
with modules reasons: to improve development efficiency, a method called repeatedly written module, called directly
with the module Note: distinguish executable file and the import file
Note py file name should not be the name of the module (built-in, third party) conflict

# import md1 # import module syntax import multiple modules, each need separate write each line of the import module written in the beginning of the file
under the name of the module when more complex cases can take alias import module file name to the module name as an alias
multiple imports will not duplicate execution, as long as you continue to use the existing name space of


the executable file to run: to create a local file name space of the execution of the
execution module file
the name of the code module execution module into space generated
executable file space module generates a pointer to the name

using the sentences from ... import ... Type
Disadvantages:
1. Access module name does not need to add the module name prefix
2. name in the access module may be executed with the current file name conflicts


value # access the module's name pointing
# Print (md.money) # access module using import import module namespace name potential unified sentence: the name of the module name md.money function name is the same
executable file can have the same name, but in reference to the module is named Road name


1. As long as you can get in terms of function names are bracketed by what function to call the function (function definition will return to the stage in order to execute code)
2. function looks at the definition stage name has not fixed dead because the change in the call site is changed

__all__ py is currently located can be specified as a file is imported modules, they can limit the number of persons able to get introduced name
written in the current module file __all__ = [ 'name 1', 'name 2 ',' name. 3 ']
__all__ is = [' Money ',' Read1 ',' Read2 '] a list of


import other modules in a module, other modules will be referenced later in this module code has not yet defined variables given
if import problems arise circulation then it must be your program design is unreasonable, circulation problems should import in the program design phase should avoid
solution circulation import questions
1. Option 1: import the cycle Sentence written in the bottom of the file (), to prevent the introduction of other modules, other modules will be referenced later in this module code has not yet defined variables being given
2.





When the script file is executed as: __ name__ equal '__main__' file is present if the executable file equal __name__ '__main__ function may be performed
when a file is imported as a module: __ name__ equal to the module name If this file module file __name__ equal only provides call module file name, the function is not executed
# action: to control the execution of different logic .py files in different application scenarios
if __name__ == '__main__': index1 ()
this means that if this document is to perform a file , then run the function, otherwise function module file does not run, only to call


lookup order module
1. start looking for memory
2. built-in look
3.sys.path in looking for (environment variables):
Import SYS
Print (SYS. path)
Print (sys.path): is a big list, which put a file path, a path is always the first file in the current folder where the execution
sys.path.append (r'D: \ Python project \ day14 \ dir1 ') to add the default path environment variable which is an absolute path
have to make clear who is who executable file is imported files (******)


absolutely must import folders based on file path where the executable file Prevail, that is the absolute path
1. Import both in absolute executable file or files being imported are applicable to
relative imports
. On behalf of the current path
The path represents a ..
... represents an upper path
Note:
relative import file can not be performed using only the use of the module is introduced, there is no need to consider relative import
execution file in the end who is the relative path is relative between the mold and is relative to the current application module, only need to know the path relations between the module and the module


# software development specification catalog
the contents of the boot file start.py at # bin directory

Import SYS
Import os

base_dir os.path.dirname = (os.path.dirname (__ file__))
sys.path.append (base_dir)
"" "
# Import os
# Print (os.path.dirname (__ file__))
# print result is sys. path (print (sys.path)) in the first directory, i.e., an absolute path of the current directory, is provided by the os module for stitching path
# 1. Add the path to the file system path core in too ... Low
# 2 the ATM folder to the system path in
os.path.dirname (os.path.dirname (__ file__)) this means that nested parent directory of the current directory of the executable file, the path for customers to download software to use
pycharm automatically saves your new top-level Directory environment variable is automatically added to
the above two sentences are not against you is for the user to download the software you
"" "
From core Import src
# because it is the parent directory of the executable file that bin parent directory can be found in the startup directory of files into the core code module file name core directory

if __name__ == '__main__': # If the file is executable file, import module is executed in the run () function
src.run ()


software development directory specification
bin directory
start.py startup file
conf directory
settings.py profile
core directory
src.py core logic functions, the core code files
db directory
database
lib directory
common.py common module file
log directory
log.log log file
Readme interpreter features, documentation
'' '




Guess you like

Origin www.cnblogs.com/xiaozhenpy/p/11220589.html