楼主: Enthuse
1174 2

Python: Modules [推广有奖]

  • 4关注
  • 39粉丝

大师

8%

还不是VIP/贵宾

-

威望
0
论坛币
74718 个
通用积分
800.5211
学术水平
103 点
热心指数
114 点
信用等级
86 点
经验
299322 点
帖子
12978
精华
0
在线时间
5848 小时
注册时间
2007-4-7
最后登录
2024-1-22

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
Each file is a module, and modules import other modules to use the names they define. Modules are process using the following
1. import: fetch a module as a whole. It serves two purposes: it identifies the external file to be loaded, but it also becomes
      a variable assigned to the loaded module.
2. from: fetch particular names from a module
3. reload: reload a module's code without stopping Python


All names defined at the top level of a module file become attributes of the imported module object. Modules have the following roles:
1. Code reuse
2. System namespace partitioning:  you can never see a name in another file, unless you explicitly import that file. Like the local
     scopes of functions, this helps avoid name clashes across your programs.
3. Implementing shared services and data

A Python program typically consists of text files containing Pythong statements, with one main top-level file, and zero or more
supplemental files known as modules. The top level file contains the main flow of control of your pgoram -- this is the file you run
to launch your application. The module files are libraries of tools used to collect components used by the top-level file, and possibly
elsewhere. Top level files use tools defined in module files, and modules use tools defined in other modules.

Although they are files of code too, module files generally don’t do anything when run
directly; rather, they define tools intended for use in other files. A file imports a module
to gain access to the tools it defines, which are known as its attributes—variable names
attached to objects such as functions. Ultimately, we import modules and access their
attributes to use their tools.





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Modules module python modul Mod particular assigned purposes process without

沙发
Enthuse 发表于 2015-5-6 03:08:41 |只看作者 |坛友微信交流群
Objects defined by a module are also created at runtime, as the import is
executing: import literally runs statements in the target file one at a time to create its
contents. Along the way, every name assigned at the top-level of the file becomes an
attribute of the module, accessible to importers.

Import does the following three things:
1. Find the module's file
2. Compile it to byte code (if needed)
3. Run the module's code to build the objects it defines

all imported modules are stored in a table named sys.modules.
The finding of the module is composed of the following
1. Home directory of the program (automatic)
2. PYTHONPATH directories (if set) (configurable)
3. Standard library directories (automatic)
4. the contens of any .pth files (if present) (configurable)
5. The site-packages home of third party extensions (automatic)


Ultimately, the concatenation of these four componets becomes sys.path, a mutable list of directory name
strings .

使用道具

藤椅
Enthuse 发表于 2015-5-6 03:42:10 |只看作者 |坛友微信交流群
Objects defined by a module are also created at runtime, as the import is
executing: import literally runs statements in the target file one at a time to create its
contents. Along the way, every name assigned at the top-level of the file becomes an
attribute of the module, accessible to importers.

Import does the following three things:
1. Find the module's file
2. Compile it to byte code (if needed)
3. Run the module's code to build the objects it defines

all imported modules are stored in a table named sys.modules.
The finding of the module is composed of the following
1. Home directory of the program (automatic)
2. PYTHONPATH directories (if set) (configurable)
3. Standard library directories (automatic)
4. the contens of any .pth files (if present) (configurable)
5. The site-packages home of third party extensions (automatic)


Ultimately, the concatenation of these four componets becomes sys.path, a mutable list of directory name
strings .

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 00:48