& Recursive function module package

 

Recursive function

Refers to a recursive function is repeated (called directly or indirectly) the function itself, which is a function of the performance of a nested calls form

Direct call: refers to the built-in function, direct call function itself.

Indirect call: call each other between the two functions cause recursive insights

I.e. python recursion depth of recursion limit: 998

PS: Each operating system will be based on the hard drive to set the default recursion depth.

View the current recursion depth: sys.getrecursionlimit ()

Import  SYS 
Print ( SYS . getrecursionlimit ()) # View recursion depth to withstand the current
SYS . setrecursionlimit ( 2000 ) # change the depth of recursion 2000

Simple recursive call does not make sense, you want recursion meaningful, two conditions must be followed

Back: refers repeatedly performed every time we take a much closer result, the back must have a termination condition.

Recursive: When backtracking to find a termination condition, start up step by step recursion.

Lowest 18-year-old man, according to the first person after more than two years old seeking a fifth person's age 
DEF Age ( the n- ): IF the n- == 1 : return 18 return Age ( the n- - 1 ) + 2 RES = Age ( 5 ) Print ( RES )
   
       
   

Module package

Module is a collection of a series of functions, is essentially one of py files

package

Refers to the internal packet contains a folder __ init __.py

Role package: storage module, the package can be better management module

Source module:

1.python built-in module (Python interpreter) As: sys / time / os / turtle

2. Third-party modules written by others :() such as: requests

3. Custom modules :( write their own), such as: demo.py own definition file

Forms module:

1. Use written in python py file

DLL or shared library in C or C ++ libraries after 2. Compile.

3. The package with the __init__ below . Py py a set of files.

File under 4.python interpreter

Why use modules?

Module can help us better manage the function code

The new items can be split into a function, are stored in different files py (modules) of

注意:模块在首次导入时,就已经固定好了,当前文件查找的顺序是先从内存中查找

如何创建,编写并使用模块:

鼠标右键创建一个py文件

在文件里编写python代码

在一个文件里通过import关键字导入模块

import 模块名(注意导入模块时,模块不能加.py后缀)

在使用模块阶段必须要注意谁是执行文件,谁时被导入文件

模块在导入时发生的事:

1.首先执行当前文件,并产生执行文件中的名称空间。

2.当执行到导入模块的代码时,被导入的模块会产生一个模块的名称空间。

3.将被导入模块的名称空间加载到内存中

模块的导入方式

1.import 模块 在执行文件中直接import导入

2.from包/模块import模块/(函数名,变量名,类名)在执行文件中直接import导入

循环导入问题:

 

model1.py from model2 import name name = 'jason'

model2.py from model1 import name name = 'tank'

  • 解决循环导入问题:1.需要查找的名字放在导入模块的上方2.在函数内部导入,将模块变成函数名称空间中的名字

    • 软件开发目录规范:注意: 每一次写项目时,都要新建一个文件夹与项目工程,必须让项目文件夹作为项目根目录。

    • 项目的文件夹

      • conf:

        • 用于存放配置文件的文件夹

      • core:

        • 核心业务代码 .py

      • interface:

        • 接口, 接口内写获取数据前的逻辑代码,通过后才能获取数据

      • db:

        • 用于存放文件数据

      • lib:

        • 存放公共功能文件

      • log:

        • 用于存放日志文件,日志用于记录用户的操作记录

      • bin:

        • 里面存放启动文件 / - 启动文件

      • readme.txt:

        • 项目说明书, 用户告诉使用者项目的操作

Guess you like

Origin www.cnblogs.com/cyfdtz/p/11892273.html