Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

209 views

Published on

Published in: Technology
  • 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
  7. 7. This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/3.0/ Copyright 2013 Mohammad reza Kamalifard. All rights reserved.

×