Vii. python modules and packages

Source: Internet
Author: User

Python module

python modules are the basic way to organize your code

Python scripts are saved with a text file with the extension py, and a script can be run either alone or in another script. When a script is imported to run, it is called a module

Cat test.py

#!/usr/bin/python

#coding: Utf-8

From __future__ Import Division

def a (x, y):

Print X+y

def b (x, y):

Print X*y



Cat new.py

#!/usr/bin/python

Import Test

TEST.A (ON)

TEST.B (3,4)


Package

Python modules can be organized into packages by directory

The steps to create a package are:

--Create a folder named Package name

--Create a __init__.py file under this folder

--store script files, compiled extensions, and child packages under this folder as needed


mkdir/python/

touch/python/__init__.py

VI test.py

#!/usr/bin/python

Import Python.test

Print Python.test.a


This article from "Meteor Yu" blog, declined reproduced!

Vii. python modules and packages

Related Article

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.