Upgrade to Pro — share decks privately, control downloads, hide ads and more …

جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲

جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲

در جلسه به بررسی ماژول ها و برنامه نویسی ماژولار در پایتون پرداختیم

Mohammad reza Kamalifard

November 18, 2013
Tweet

More Decks by Mohammad reza Kamalifard

Other Decks in Education

Transcript

  1. Python language essentials Module 1: Introduction to Python and Setting

    up an Environment for Programing Part 6 : Modular Programming
  2. Modular Programming • Develop programs which are readable, reliable and

    maintainable without too much effort • Software design technique to split your code into separate parts • The focus for this separation should be to have modules with no or just few dependencies upon other modules • Minimization of dependencies is the goal • The executable application will be created by putting separate module together.
  3. Module in Python • Module in Python is just a

    file containing Python definitions and statements • The module name is moulded out of the file name by removing the suffix .py
  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. 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. from … import $ vim testcalc.py #!/usr/bin/env python from calculator

    import add print '2 + 3 is equal to : %d ' % add(2, 3) print '10 - 3 is equal to : %d ' % 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. References SPSE securitytube training by Vivek Ramachandran SANS Python for

    Pentesters (SEC573) Violent python Security Power Tools python-course.eu ----------------------------- http://www.tutorialspoint.com/python/python_modules.htm http://www.python-course.eu/modules_and_modular_programming.php
  8. 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. Go to Kamalifard.ir/pysec101 to Download Slides and Course martials .