[go: up one dir, main page]

0% found this document useful (0 votes)
20 views1 page

How To Write A Python Module

A Python module is a file with the .py extension that contains definitions and statements. A function can be defined in a module file like hello.py and then imported and called from another file using the module name. Modules can be organized into packages by placing .py files in a folder with an __init__.py file, allowing the files to be imported as a group using the folder name.

Uploaded by

Iamhere Iamhere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

How To Write A Python Module

A Python module is a file with the .py extension that contains definitions and statements. A function can be defined in a module file like hello.py and then imported and called from another file using the module name. Modules can be organized into packages by placing .py files in a folder with an __init__.py file, allowing the files to be imported as a group using the folder name.

Uploaded by

Iamhere Iamhere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

A module is a file containing Python definitions and statements.

The file name is the module


name with the suffix .py

create hello.py then write the following function:

def helloworld():
print "hello"

>>> import hello


>>> hello.helloworld()
'hello'
>>>

To group many .py files put them in a folder. Any folder with an __init__.py is considered a
module by python and you can call them a package

|-HelloModule
|_ __init__.py
|_ hellomodule.py

You can go about with the import statement on your module the usual way.

You might also like