Importing Libraries
Importing Libraries

Importing Libraries

CMS Sprint
CMS Unit
Item ID

Link to
Related to Content (1) (Production Pages)
Tags
Type
Learning Item
Lang
EN
Parent item
Sharable link for students

Please watch the following video, and complete the exercise below.

In this video we mention the dunder main, because it’s vital for helping us create libraries. No worries if it’s not completely sinking in, we will soon cover it more closely in Intermediate Python 2.

📖
Quick Exercise No need to submit, just check your understanding.

Attached in this file is a new library, developed by us, called masterlib. Download the file to your project folder in PyCharm, and follow the steps:

  1. Import the library in the terminal, using the Python interactive shell. Try to play around with it. What are the names of the functions are inside the library?
  2. Import the library from your main file, and run one of the functions.
  3. Did the import cause any prints? If so, try to fix the library so that when it is imported, it will not print anything (hint: when imported, the main function shouldn’t run).
  4. Try to add a new function to the library, and run it from your main file.
  5. Way to go, you’re done! 🚀