Instant Hacking The Basics
Document Sample


Instant Hacking: The Basics
Lotfi Ben Othmane
Department of Computer Science
Western Michigan University
1/6/2009 1
Roadmap
Installing Python
Scripting with Python
Python help
Using Python language
Getting input from a user
Using modules
Creating programs
1/6/2009 2
1
Introduction
Website: www.python.org
We use Python 2.6 for Windows operating system
(Windows XP, Windows Vista)
Other operating systems that support Python
Linux and Unix
Macintosh
Other implementations: IronPython (Windows),
Jython (Java) , Django
1/6/2009 3
1. Installing Python
Download msi installation for Python 2.6 from the
link http://www.python.org/download/
Run the downloaded msi file by double-clicking on it
from windows explorer.
Follow the instructions provided by the wizard until
you finish the installation
The installation program
creates a shortcut on the
computer desktop.
1/6/2009 4
2
1. Installing Python—Cont.
Python
IDLE
1/6/2009 5
2. Scripting with Python
Generate an output
Arithmetic operations
Arithmetic operations
with integers
Arithmetic operations
with decimals
1/6/2009 6
3
3. Python Help
1/6/2009 7
4. Overview of the Basics of Python
Language
Variables
Statements
Functions
1/6/2009 8
4
4.1. Variables
A variable is a holder of a value. It has a name
which is used to refer to its value. A variable name
must start with a character (not a decimal)
A variable could be assigned a value
1/6/2009 9
4.1. Variables—Cont.
Not correct variable
name
Variable assignment
1/6/2009 10
5
4.2 Statements
It is a legitimate combinations of variables, reserved
words, functions, and values that does something
Examples
Print x
X=3
1/6/2009 11
4.3 Functions
A little program you can use to perform a task
Power function
Absolute value
function
Round function
1/6/2009 12
6
5. Getting Input from a User
1/6/2009 13
6. Using Modules
Functions are organized in modules
In Python you need to import a module or function
before using it—Except built-in functions
Import a module to the interpreter: import [module
name]
Call of a function within module: [module
name].[function name]([parameters])
1/6/2009 14
7
6. Using Modules—Cont.
Module import
Error function
call
Correct function
call
1/6/2009 15
7. Using Programs
So far we used the interactive interpreter: we write
statements and get the results
To write a program we need to create a script file.
To do so, from Python IDLE, select File->New
Windows, and write your code
The extension for python script file is “py”
You can save your script file (see next slides)
A script module could be executed from the from
the IDLE or using a windows command (see next
slides)
1/6/2009 16
8
7.1 Create a module
1/6/2009 17
7.2 Save a Module
1/6/2009 18
9
7.3 Run a module
1/6/2009 19
Conclusion
The chapter covered
Python installation
Scripting
Use of modules
Creating programs
1/6/2009 20
10
Related docs
Get documents about "