SlideShare a Scribd company logo
Python Modules
        Python 3

  Katkam Nitin Reddy
    k.nitin.r [at] gmail.com
    www.nitinkatkam.com
Python Modules

●   When you “import” a function, for instance,
    you are essentially using a module
●   A module is essentially a Python file with a .py
    extension
Using Modules

●   You can import a module using
    import <module-name>
    and access the contents using
    <module-name>.<entity-name>
●   You can also access entities directly
    from <module-name> import <entity-name>
    OR
    import <module-name>
    <alias>=<module-name>.<entity-name>
Creating Modules

●   Example: Create the following and save it as
    example.py
    def add(x,y):
     return x+y
●   Now, in another Python file, call the add()
    function using the following:
    import example
    print(example.add(1,2))
Creating Modules (Contd)

●   Modules have the __name__ variable set to the
    module name
●   When a Python file is called as a script, the
    __name__ is set to “__main__”. This lets you
    create modules that can also be executed as
    scripts using the following:
    def add(x,y):
      return x+y
    if __name__ == “__main__”:
      print(add(1,2))
Packages

●   Python modules can be categorized into
    packages by placing them within folders. The
    folder name becomes the package name and
    is used as a prefix with a period (dot) with the
    module name.
●   Packages can be initialized with a module
    named __init__.py
Python Module Search Path

●   PYTHONPATH is an environment variable set
    with the locations where the Python interpreter
    searches for modules
●   Typically, the module search path is defined
    as:
    PYTHONPATH=./usr/local/lib/pythonX.X
    which is the current directory and
    /usr/local/lib/pythonX.X
Questions?
         Ask at:
k.nitin.r [at] gmail.com
Ad

More Related Content

What's hot (20)

Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
Siddique Ibrahim
 
Packages in java
Packages in javaPackages in java
Packages in java
Elizabeth alexander
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
Binay Kumar Ray
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
Megha V
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Python file handling
Python file handlingPython file handling
Python file handling
Prof. Dr. K. Adisesha
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
Srinivas Narasegouda
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
baabtra.com - No. 1 supplier of quality freshers
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 

Viewers also liked (20)

Functions and modules in python
Functions and modules in pythonFunctions and modules in python
Functions and modules in python
Karin Lagesen
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
Narendra Sisodiya
 
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and PackagesPython Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and Packages
P3 InfoTech Solutions Pvt. Ltd.
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
CodeIgniter
CodeIgniterCodeIgniter
CodeIgniter
Nitin Reddy Katkam
 
Python exceptions
Python exceptionsPython exceptions
Python exceptions
rikbyte
 
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
Ranel Padon
 
Day2
Day2Day2
Day2
Karin Lagesen
 
Functions
FunctionsFunctions
Functions
Marieswaran Ramasamy
 
Functions in python
Functions in python Functions in python
Functions in python
baabtra.com - No. 1 supplier of quality freshers
 
python Function
python Function python Function
python Function
Ronak Rathi
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
Input and Output
Input and OutputInput and Output
Input and Output
Marieswaran Ramasamy
 
Python
Python Python
Python
Edureka!
 
Python datatype
Python datatypePython datatype
Python datatype
건희 김
 
Hot Spot Columbia
Hot Spot ColumbiaHot Spot Columbia
Hot Spot Columbia
Stanford University
 
4. python functions
4. python   functions4. python   functions
4. python functions
in4400
 
The Awesome Python Class Part-4
The Awesome Python Class Part-4The Awesome Python Class Part-4
The Awesome Python Class Part-4
Binay Kumar Ray
 
Function arguments In Python
Function arguments In PythonFunction arguments In Python
Function arguments In Python
Amit Upadhyay
 
Python Programming - XII. File Processing
Python Programming - XII. File ProcessingPython Programming - XII. File Processing
Python Programming - XII. File Processing
Ranel Padon
 
Ad

Similar to Python Modules (20)

Python module 3, b.tech 5th semester ppt
Python module 3, b.tech 5th semester pptPython module 3, b.tech 5th semester ppt
Python module 3, b.tech 5th semester ppt
course5325
 
CLTL python course: Object Oriented Programming (2/3)
CLTL python course: Object Oriented Programming (2/3)CLTL python course: Object Oriented Programming (2/3)
CLTL python course: Object Oriented Programming (2/3)
Rubén Izquierdo Beviá
 
Python libraries
Python librariesPython libraries
Python libraries
Prof. Dr. K. Adisesha
 
Python import mechanism
Python import mechanismPython import mechanism
Python import mechanism
Yuki Nishiwaki
 
Modules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdfModules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdf
RavindraTambe3
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdf
SoumyadityaDey
 
Class 12 CBSE Chapter: python libraries.pptx
Class 12 CBSE Chapter: python libraries.pptxClass 12 CBSE Chapter: python libraries.pptx
Class 12 CBSE Chapter: python libraries.pptx
AravindVaithianadhan
 
package module in the python environement.pptx
package module in the python environement.pptxpackage module in the python environement.pptx
package module in the python environement.pptx
MuhammadAbdullah311866
 
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
anikedheikhamsingh
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
Singamvineela
 
Python Session - 5
Python Session - 5Python Session - 5
Python Session - 5
AnirudhaGaikwad4
 
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
RoshanJoshuaR
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
baabtra.com - No. 1 supplier of quality freshers
 
packages.pptx
packages.pptxpackages.pptx
packages.pptx
SHAIKIRFAN715544
 
CLTL python course: Object Oriented Programming (3/3)
CLTL python course: Object Oriented Programming (3/3)CLTL python course: Object Oriented Programming (3/3)
CLTL python course: Object Oriented Programming (3/3)
Rubén Izquierdo Beviá
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
Praveen M Jigajinni
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
KALAISELVI P
 
CLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptxCLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptx
seccoordpal
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
krushnaraj1
 
Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12
JAYASURYANSHUPEDDAPA
 
Python module 3, b.tech 5th semester ppt
Python module 3, b.tech 5th semester pptPython module 3, b.tech 5th semester ppt
Python module 3, b.tech 5th semester ppt
course5325
 
CLTL python course: Object Oriented Programming (2/3)
CLTL python course: Object Oriented Programming (2/3)CLTL python course: Object Oriented Programming (2/3)
CLTL python course: Object Oriented Programming (2/3)
Rubén Izquierdo Beviá
 
Python import mechanism
Python import mechanismPython import mechanism
Python import mechanism
Yuki Nishiwaki
 
Modules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdfModules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdf
RavindraTambe3
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdf
SoumyadityaDey
 
Class 12 CBSE Chapter: python libraries.pptx
Class 12 CBSE Chapter: python libraries.pptxClass 12 CBSE Chapter: python libraries.pptx
Class 12 CBSE Chapter: python libraries.pptx
AravindVaithianadhan
 
package module in the python environement.pptx
package module in the python environement.pptxpackage module in the python environement.pptx
package module in the python environement.pptx
MuhammadAbdullah311866
 
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
anikedheikhamsingh
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
Singamvineela
 
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
7-_Modules__Packagesyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.pptx
RoshanJoshuaR
 
CLTL python course: Object Oriented Programming (3/3)
CLTL python course: Object Oriented Programming (3/3)CLTL python course: Object Oriented Programming (3/3)
CLTL python course: Object Oriented Programming (3/3)
Rubén Izquierdo Beviá
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
KALAISELVI P
 
CLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptxCLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptx
seccoordpal
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
krushnaraj1
 
Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12
JAYASURYANSHUPEDDAPA
 
Ad

More from Nitin Reddy Katkam (13)

FuelPHP
FuelPHPFuelPHP
FuelPHP
Nitin Reddy Katkam
 
Sales Lead Pro
Sales Lead ProSales Lead Pro
Sales Lead Pro
Nitin Reddy Katkam
 
Algorithms
AlgorithmsAlgorithms
Algorithms
Nitin Reddy Katkam
 
Program activation records
Program activation recordsProgram activation records
Program activation records
Nitin Reddy Katkam
 
C Standards: main()
C Standards: main()C Standards: main()
C Standards: main()
Nitin Reddy Katkam
 
Computer hardware
Computer hardwareComputer hardware
Computer hardware
Nitin Reddy Katkam
 
8 Simple Rules to Keep Burglars Away
8 Simple Rules to Keep Burglars Away8 Simple Rules to Keep Burglars Away
8 Simple Rules to Keep Burglars Away
Nitin Reddy Katkam
 
Software evaluation
Software evaluationSoftware evaluation
Software evaluation
Nitin Reddy Katkam
 
Creating WordPress themes
Creating WordPress themesCreating WordPress themes
Creating WordPress themes
Nitin Reddy Katkam
 
Code Igniter 2
Code Igniter 2Code Igniter 2
Code Igniter 2
Nitin Reddy Katkam
 
Types of knowledge management systems
Types of knowledge management systemsTypes of knowledge management systems
Types of knowledge management systems
Nitin Reddy Katkam
 
jQuery Date Picker
jQuery Date PickerjQuery Date Picker
jQuery Date Picker
Nitin Reddy Katkam
 
Organizational Uncertainty
Organizational UncertaintyOrganizational Uncertainty
Organizational Uncertainty
Nitin Reddy Katkam
 

Recently uploaded (20)

Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and MLGyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
Gyrus AI
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
BookNet Canada
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and MLGyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
Gyrus AI
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
BookNet Canada
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 

Python Modules

  • 1. Python Modules Python 3 Katkam Nitin Reddy k.nitin.r [at] gmail.com www.nitinkatkam.com
  • 2. Python Modules ● When you “import” a function, for instance, you are essentially using a module ● A module is essentially a Python file with a .py extension
  • 3. Using Modules ● You can import a module using import <module-name> and access the contents using <module-name>.<entity-name> ● You can also access entities directly from <module-name> import <entity-name> OR import <module-name> <alias>=<module-name>.<entity-name>
  • 4. Creating Modules ● Example: Create the following and save it as example.py def add(x,y): return x+y ● Now, in another Python file, call the add() function using the following: import example print(example.add(1,2))
  • 5. Creating Modules (Contd) ● Modules have the __name__ variable set to the module name ● When a Python file is called as a script, the __name__ is set to “__main__”. This lets you create modules that can also be executed as scripts using the following: def add(x,y): return x+y if __name__ == “__main__”: print(add(1,2))
  • 6. Packages ● Python modules can be categorized into packages by placing them within folders. The folder name becomes the package name and is used as a prefix with a period (dot) with the module name. ● Packages can be initialized with a module named __init__.py
  • 7. Python Module Search Path ● PYTHONPATH is an environment variable set with the locations where the Python interpreter searches for modules ● Typically, the module search path is defined as: PYTHONPATH=./usr/local/lib/pythonX.X which is the current directory and /usr/local/lib/pythonX.X
  • 8. Questions? Ask at: k.nitin.r [at] gmail.com
  翻译: