python--Module

Source: Internet
Author: User

Introducing Modules

Grammar

Import Modename

one.py

def printsomething (str):    print ("" + str);

main.py

Import oneone.printsomething ("jiao");     #hello jiaoone.printsomething ("fftu");     #hello FFTU

Partially introduced

Grammar

 from modename import functionname, VarName

one.py

def printsomething (str):    print ( "+"should go now  ";d EF printbye ():    print (str);

main.py

 from One import printsomething, printbyeprintsomething ("jiao");     #hello Jiaoprintbye ();     #you should go now

Note: Part of the introduction cannot use the module name one

In addition to the function, you can also introduce the variables of the module (do not introduce access errors, but the module function can access the variable)

All introduced (all functions and variables within the module are introduced into the current file)

Grammar

 from one import *

The introduction of post-usage is the same as partial introduction

Dir () function

Returns all names defined in the module as a list of strings

Import Oneprint (dir (one));
#[
'__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__spec__','printsomething','Printbye','str1']

No arguments return all names of the current file definition (the introduced module does not parse, only one name)

Import Onenuma=Ten; StrB="haha";p rint (dir ()); #['__annotations__','__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__spec__','NumA',' One','StrB']

This parses the objects that are introduced into the module

 fromOne import printsomething, Printbye, Str1numa=Ten; StrB="haha";p rint (dir ()); #['__annotations__','__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__spec__','NumA','printsomething','Printbye','str1','StrB']

Standard modules
Python itself comes with some standard library of modules that will be introduced in the Python Library Reference document (that is, the library Reference document, later).
Some modules are built directly into the parser, which is not a feature built into the language, but can be used efficiently, even system-level calls.
These components are configured differently depending on the operating system, such as the WinReg module, which is only available to Windows systems.

python--Module

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.