Successfully reported this slideshow.
Upcoming SlideShare
×

# اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی

209 views

Published on

Published in: Technology
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

### اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی

1. 1. Python for Ethical Hackers Mohammad reza Kamalifard
2. 2. Python Language Essentials Part 6 : Creating Modules
3. 3. Modules Better way to orgnizing code can define classes,functions and variables Import a module: import MODULE_NAME form MODULE_NAME import ….
4. 4. Creating Module \$ vim calculator.py #!/usr/bin/env python ''' This is a simple calculator add for addition sub for subtraction ''' def add(a, b): return a+b def sub(a, b): return a-b ~ ~
5. 5. Creating Module \$ vim calculator.py #!/usr/bin/env python import calculator print '2 + 3 is equal to : %d ' % calculator.add(2,3) print '10 - 3 is equal to : %d ' % calculator.sub(10,3) ~ ~ \$ chmod a+x testcalc.py \$ ./testcalc.py 2 + 3 is equal to : 5 10 - 3 is equal to : 7
6. 6. from … import \$ vim testcalc.py #!/usr/bin/env python from calculator import add print '2 + 3 is equal to : %d ' % calculator.add(2,3) print '10 - 3 is equal to : %d ' % calculator.sub(10,3) ~ \$ ./testcalc.py 2 + 3 is equal to : 5 Traceback (most recent call last): File "./testcalc.py", line 6, in <module> print '10 - 3 is equal to : %d ' % sub(10,3) NameError: name 'sub' is not defined