2. Introduction
• Why Python?
• How can we automate the stuffs using Python?
• How can Python will make our life easier
• Playing with APIs
• Automations we have done using Python
Are you ready? Let’s Automate Everything…
3. Why Python
• Python is object-oriented
Structure supports such concepts as polymorphism,
operation overloading, and multiple inheritance
• It's free (open source)
Downloading and installing Python is free and easy
Source code is easily accessible
Free doesn't mean unsupported! Online Python
community is huge
• It's portable
Python runs virtually every major platform used today
As long as you have a compatible Python interpreter
installed, Python programs will run in exactly the same
manner, irrespective of platform
4. Why Python
• It's powerful
Dynamic typing
Built-in types and tools
Library utilities
Third party utilities (e.g. Numeric, NumPy, SciPy)
Automatic memory management
• It's mixable
Python can be linked to components written in other languages
easily
Linking to fast, compiled code is useful to
computationally intensive problems
Python is good for code steering and for merging
multiple programs in otherwise conflicting languages
5. World of API
An application programming interface (API) is a set of
routines, protocols and tools for building software
applications
9. Standard Libraries
OS module
Some os module functions:
os.getcwd() # get current working directory
os.chdir('/usr/cs265') # change current working directory
os.system('mkdir lab1') # perform a mkdir in the system shell
Shutil module
• Use for daily file/directory management tasks
#copies data.db to archive.db
shutil.copyfile('data.db', 'archive.db')
#move(source, destination)
shutil.move('/build/executables', 'installdir')
10. Standard Libraries
re Module
• The re module provides regular expression tools for
advanced string processing.
• r - Python’s raw string notation for regular expression
patterns
re.findall(r'bf[a-z]*', 'which foot or hand fell fastest')
['foot', 'fell', 'fastest']
14. Data Structures
List
[‘a’,’b’,’c’]
Sortable
Sequence of
object
Grows and
shrinks as
needed
Tuple
(‘a’,’b’,’c’)
Immutable
Useful for
fixed data
Sequence type
Dict
{‘a’:’b’,’c’:’d’}
Key/value
pair
Keys are
immutable
Unordered
Set
{‘a’,’b’,’c’}
Store non-
duplicate item
Unordered
Math Set ops
(union,interse
cts)
16. Scheduling Tasks and
Launching Programs
• The Time Module:
Based on Unix Epoch timestamp (12 AM on January 1, 1970)
Application : Stopwatch
17. Scheduling Tasks and
Launching Programs
• The DateTime Module:
To display a date in a more convenient format, or do arithmetic
operations with dates.
18. Scheduling Tasks and
Launching Programs
• The Subprocess Module:
- Open external applications
- poll() : like asking if program is still running
- Passing command line arguments
- Running other python/shell script
22. Working with Excel and
CSV
• The openpyxl module:
o allows your Python programs to read and modify Excel spreadsheet
files
23. Working with Excel and
CSV
• The openpyxl module:
o Create and Save Excel Documents.
o Create and Remove Sheets.
o Set Font style and size.
o Apply Formulae:
24. Working with Excel and
CSV
• The openpyxl module:
o Adjust Row heights and Columns widths.
o Freeze Panes.
o Create Charts.
25. Working with Excel and
CSV
• The CSV module:
o CSV files are simplified spreadsheets stored as plaintext files. The advantage of
CSV files is simplicity.
o Read from CSV.