Module 1.2 - Python Libraries
Module 1.2 - Python Libraries
2
Python Libraries
Learning Objectives
• You will be able to import modules and libraries into Python
• You will be able to research libraries and their contents with tools provided in
Python
Importing Libraries
Python Scripts
• Python files are text files, filled with Python code.
• Let’s say we want to use (execute) the code that is in a different Python
script.
• We can do this by using the import statement. When using import, the whole
file is executed, line-by-line.
– This means that the current script is paused until all lines of the other script have
finished executing.
– Only then, the current script continues to run.
• You can only import scripts that are in the same directory (folder) as your
script.
10 minutes exercise…
• kali@kali:~$ nano script_1.py
• We can use the from keyword to import a specific object from our script.
– from script_2 import your_function
– from script import function_1, function_2
• In the remainder of the course, please do import the full libraries when doing
demo’s / presentations without renaming. Why?
Python Standard
Library
• Make a short presentation about the libraries methods and properties (max
5 slides – 10 minutes)
• Write a very simple script, demonstrating the possibilities of this library
Project 1.1 –
Turtle Library