Python Module Write and Call
What Is The Module ?
The other meaning of the modules is that they are pre-made parts that are compatible with each other. These pieces come together to form a coherent whole. In the meantime, the pre-production of the modules is not personal. What is Personal is the order in which parts will be merged. Python modules. Previously written parts of the program can be included in the whole at any time. Thus, the environment in which the programmer works will not be unnecessary memory consumption from the Module User, which only works for himself. As Python contains many modules, the user can write modules himself.
We can also call Python modules as a library.
Each Python program can be a module. A module can be composed of an empty file, or it can have a complex structure with one or more classes in which some functions are written with various variables. First, let’s create a module where only a few variables are defined.
1 2 3 | Name= 'Open Source' LastName= 'Projects' List = ['Blue','Yellow','Green'] |
Write the codes, module.py let’s save the file named.
When calling a module, only the file name is used (the extension is not written). The calling process is done with the import statement. Let’s call the Python interpreter and call the module we wrote before calling a different one .open the py file :
1 | import module |
We can now access the variables in the module we wrote. If we include a module using its name in this way, the objects within the module <module>.<ObjectName> :
It’s a different one .let’s call it from the py file.
1 2 3 4 | import module print(module.Name) print(module.LastName) print(module.list) |
Output
1 2 3 | Open Source Projects ['Blue', 'Yellow', 'Green'] |
Sometimes programmers may want to call some objects in a module only with their name for convenience. To do this, you need to include only that object in the module.
from <module name> import <content object>
We should write it in the form. For example, Module.py we just need names.
1 2 | from module import Name print(Name) |
Output
1 | Open Source |
If you want to use all the objects, you need to do the following:
from <module > import *
1 2 3 4 | from module import* print(Name) print(LastName) print(List) |
Output
1 2 3 | Open Source Projects ['Blue', 'Yellow', 'Green'] |
As you can see, we can use all its features by embedding the other module. This is how you should determine the calling process according to the module you are going to write.
Все матчи расписание футбол: все спортивные события дня футбол bobsoccer.ru. Смотрите описание автокресло детское рекаро тут.