Modules in Python

290 views

Published on

Modules in Python

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
290
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Modules in Python

  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  2. 2. Typing Speed Week Targ et Achieve d 1 20 18 2 25 23 3 30 27 4 45 38
  3. 3. Jobs Applied # Company Designation Applied Date Current Status 1 ioss php developer 20/08/13 Not selected 2 nuecore Python developer 3 Skill search limited Junior software developer 4 butterfly 10/09/13 selected Python developer
  4. 4. MODULES IN PYTHON ● Shameena ● shameenavayoli@gmail.com ● www.facebook.com/shameenalatheef ● twitter.com/shameena ● in.linkedin.com/in/shamean ● 9567135569
  5. 5. What is module?? ● ● a module is a file consisting of Python code. A module can define functions, classes and variables. A module can also include runnable code. The file name containing suffix .py
  6. 6. def fib(n): # write Fibonacci series up to n a, b = 0, 1 while b < n: print b, a, b = b, a+b ● ● Save the file in fibo.py We can use fibo.py in other program by importing fibo.py
  7. 7. Example: import fibo.py fibo.fib(1000) output 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
  8. 8. ● ● ● ● ● A module can contain executable statements as well as function definitions They are executed only the first time the module name is encountered in an import statement Modules can import other modules. Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. The author of a module can use global variables in the module without worrying about accidental clashes with a user’s global variables.
  9. 9. ● There is a variant of the import statement that imports names from a module directly into the importing module’s symbol table. For example: from fibo import fib, fib2 Fib(500) Output: 1 1 2 3 5 8 13 21 34 55 89 144 233 377 ● There is another variant to import all names that a module defines: from fibo import * ● This imports all names except those beginning with an underscore (_).
  10. 10. ● ● Each module is only imported once per interpreter session if you change your modules, you must restart the interpreter or if it’s just one module you want to test interactively, use reload() Eg: reload(modulename).
  11. 11. The Module Search Path When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. “Compiled” Python files ● ● If a file called spam.pyc exists in the directory where spam.py is found
  12. 12. Thanks...
  13. 13. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance.    www.baabtra.com | www.massbaab.com | www.baabte.com
  14. 14. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550

×