{"assignment":{"_schema_version":2,"course_id":37,"date_created":"2022-06-28T19:00:00+00:00","date_modified":"2023-08-26T14:03:45.599450+00:00","extra_instructor_files":"","extra_starting_files":"{\"^helper.py\":\"scores = \\\"10, 30, 50, 20\\\"\"}","forked_id":null,"forked_version":null,"hidden":false,"id":941,"instructions":"## Modules\n\n* Modules are Python Programs\n\nWhenever you create a new Python program, you are creating a _module_.\nIn other words, a module is just a Python program.\nA module is useful, however, because it can be imported into another module.\nAny variables created in the module will then be available in the other module.\nSo far, we have been creating individual Python programs and running them.\nBut over time, we will have many programs.\nIt will be important to be able to reuse work we have done in new programs.\nWe also want to be able to use stuff created by other programmers.\n\n## Terminology\n\n* Module\n* Library\n* Package\n\nModules are sometimes also known as \"packages\" or \"libraries.\" Typically, a package is a collection of one or more modules.\nHowever, the words are all more or less interchangeable.\n\n## Import\n\n```python example-import\nimport helper\n\nprint(\"The other module has a variable named scores with the value\", helper.scores)\n```\n\nIf you have two Python files (or modules,) then you can create variables in one module and then import those variables into the other module.\nTo import data from another module, you use the `import` statement.\nThere are three different ways to import a module.\nThe simplest is shown here, where we write the keyword \"import\" and the name of the module.\nOnce a module is imported, you can reference its definitions using the name of the module, a period (`.`), and the name of the variable you want to use.\nWhen you run this example, you will see that there is a second Python file named `helper.py` with a variable named `scores` defined inside.\nThe module is imported as `helper` so that we can access the string variable.\n\n## Specific Import\n\n```python example-from-import\nfrom math import pi\n\nprint(\"The value of pi is\", pi)\n```\n\nIt can be bothersome to repeat the module name each time you want to use a variable from the module.\nTherefore, Python has a convenient syntax for importing the variables directly.\nThis version uses the `from` keyword, followed by the module name, the `import` keyword, and then the name of the variable or other definition you want to use.\nAfterwards, you can use the variable as if it were defined in that file.\n\n## Standard Library\n\n```python example-string-library\nfrom string import digits\n\nprint(\"The digits are\", digits)\n```\n\nPython has many useful built-in modules called the Standard Library.\nFurthermore, Python programmers have created many other \"third-party libraries\" that are easy to install.\nMany of these modules come prepackaged in versions of Python that are easy to obtain.\nWe will not cover all these modules in this course, but you will often come across them when solving real-world problems.\nThe `string` module shown here has string variables that you can import, which hold various strings of characters.\nFor example, the `digits` variable holds all the digits `0123456789`.\n\n## Math Module\n\n```python example-math-library\nfrom math import e\n\nprint(\"The value of e is\", e)\n```\n\nThe `math` module has mathematical constants like `e` (which is `2.718281`).\nThe programmers who created Python had to define these variables and put them in files that you can `import` even if you cannot normally see them.\nThere are a lot of standard libraries that are very convenient as we will see!\n\n\n## Installing New Libraries\n\n```\n> pip install pygame\n> pip install requests\n> pip install matplotlib\n```\n\nAlthough you will not need to do it in this environment, it is very easy to install new modules from a command line.\nPython has a special tool named `pip` to install a module.\nYou will need to know the exact module name when installing a library.\nMake sure you have the right module name; when you install a new module, you are trusting the developer to not install anything malicious! Some bad actors create packages with similar names to other popular libraries to try and trick unsuspecting developers into installing their version of the package instead.\n\n## New Modules in BlockPy\n\n![A screenshot of BlockPy's file system interface, with an additional file available to the user named `my_second_module.py`.](bakery_intro_import_blockpy_file.png)\n\nMost editors allow you to create additional Python files that can be imported into your main Python file.\nBlockPy has this feature, but most coding problems disable that functionality so that you are not distracted.\nStill, sometimes you will see an additional row of tabs that allow you to view and add new files.\nIn some cases, we'll have already created the file for you, but in others we may ask you to create the new file.\nThe second Python file will be available to be imported just like if it was in your local filesystem.\nIn this case, the external module would be `my_second_module.py`\n\n## Summary\n\n- A Python program stored in a file is also called a module.\n- Modules are sometimes known as packages or libraries, especially when they are composed of more than one module.\n- Data can be loaded from another Python module using an import statement.\n- Python allows you to import the entire module or just specific variables from the module.\n- Python has many built-in modules named the Standard Library.\n- You can also install third-party libraries, although you must be careful when doing so.\n- Finally, you can create your own modules and import data from them.\n- Splitting data across modules is helpful for organizing large programs, reusing data in multiple places without copying it into the code, and sharing code with other programmers.","ip_ranges":"","name":"1B5) Importing Reading","on_change":"","on_eval":"","on_run":"","owner_id":1,"owner_id__email":"acbart@udel.edu","points":0,"public":true,"reviewed":false,"sample_submissions":[],"settings":"{\n  \"header\": \"Importing\",\n  \"slides\": \"bakery_intro_import.pdf\",\n  \"youtube\": {\n    \"Bart\": \"yTFORY1mOvo\",\n    \"Amy\": \"megr_Sj3jI8\"\n  },\n  \"video\": {\n    \"Bart\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_import-Bart.mp4\",\n    \"Amy\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_import-Amy.mp4\"\n  },\n  \"summary\": \"In this lesson, you will learn how you can organize code into modules. Modules are a collection of code, and particularly functions. Rather than sharing functions directly, programmers actually share modules. You will learn how to use other modules to access more functions by importing them.\",\n  \"small_layout\": true,\n  \"hide_files\": false\n}","starting_code":"","subordinate":true,"tags":[],"type":"reading","url":"bakery_intro_import_read","version":9},"ip":"216.73.216.157","submission":{"_schema_version":3,"assignment_id":941,"assignment_version":9,"attempts":0,"code":"","correct":false,"course_id":37,"date_created":"2026-05-20T16:04:43.577181+00:00","date_due":"","date_graded":"","date_locked":"","date_modified":"2026-05-20T16:04:43.577181+00:00","date_started":"","date_submitted":"","endpoint":"","extra_files":"{\"helper.py\": \"scores = \\\"10, 30, 50, 20\\\"\"}","feedback":"","grading_status":"NotReady","id":2037035,"score":0.0,"submission_status":"Started","time_limit":"","url":"submission_url-c3cf1116-bec0-4f22-abf7-13bf85395127","user_id":2044701,"user_id__email":"","version":0},"success":true}
