Python module using method notes

Source: Internet
Author: User

A. py file can be seen as a module that resembles a class library encapsulated in other languages

Module Categories:
Built-in Modules
Custom Modules
Third-party modules (need to be installed to use)

I want to use the functions defined in cal.py, I can do this
For example: cal.py source code:

#!/usr/bin/python#coding:utf-8def Add (A, B): return a + b

import_test.py to use the Add function:

' #!/usr/bin/python #coding: Utf-8 import cal print Cal.add (10, 20) '

Second, built-in properties name
cal.py
' #!/usr/bin/python

            #coding:utf-8          def add ( a, b ):             return a + b             print __name__      [email protected]:~/python$  python cal.py 

main
[email protected]:~/python$ python Import_ test.py
Cal

[email protected]:~/python$

                #!/usr/bin/ python         #coding:utf-8           def add ( a, b ):           return a + b  if __name__ ==  ' __main__ ':p rint add ( 100 , 200 )     [email protected]:~/python$ python import_test.py  [email protected]:~/python$ python cal.py300 ' 

This is a small function of name , when a module (. py file) is called by another file, it is generally wanted to invoke the function or method defined inside it, we can make the external module call mode by name , and will not execute to a similar print add ( 100, 200) such a specific business code. Only the function or method definition inside is used.

Cylindrical Templates


Python module using method notes

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.