René's URL Explorer Experiment


Title: Creating Modules (Video) – Real Python

Open Graph Title: Creating Modules – Real Python

Description: Open IDLE and start a new editor window. In the editor window, define a function named add() that returns the sum of its two parameters. def add(x, y): and then on the next line, indented, return x + y. Save the file as adder.py on your computer in…

Open Graph Description: Open IDLE and start a new editor window. In the editor window, define a function named add() that returns the sum of its two parameters. def add(x, y): and then on the next line, indented, return x + y. Save the file as adder.py on your computer in…

Opengraph URL: https://realpython.com/videos/creating-python-modules/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
  {
    "@context": "https://schema.org",
    "@type": "VideoObject",
    "name": "Creating Modules",
    "description": "Open IDLE and start a new editor window. In the editor window, define a function named add() that returns the sum of its two parameters. def add(x, y): and then on the next line, indented, return x + y. Save the file as adder.py on your computer in…",
    "thumbnailUrl": ["https://files.realpython.com/media/Modules-and-Packages_Watermarked.bc38abc24435.jpg"],
    "uploadDate": "2023-11-14T14:00:00+00:00",
    "duration": "PT1M55S",
    "embedUrl": "https://realpython.com/videos/creating-python-modules/embed/",
    "potentialAction": {
      "@type": "SeekToAction",
      "target": "https://realpython.com/videos/creating-python-modules/#t={seek_to_second_number}",
      "startOffset-input": "required name=seek_to_second_number"
    }
  }
  

authorReal Python
theme-color#18354c
color-schemelight dark
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/Modules-and-Packages_Watermarked.bc38abc24435.jpg
og:imagehttps://files.realpython.com/media/Modules-and-Packages_Watermarked.bc38abc24435.jpg
twitter:creator@realpython
og:typevideo.episode
og:site_nameReal Python
apple-mobile-web-app-titleReal Python

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/videos/creating-python-modules/
Your Learning Plan →Your personalized Python learning planhttps://realpython.com/account/learning-plan/
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest&_from=nav_library
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/search?kind=exercise&kind=quiz&_from=nav_library
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Mentor AI →NewYour personal Python mentorhttps://realpython.com/mentor/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Live Courses →Live, instructor-led Python courseshttps://realpython.com/live/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Unlock All Content and Become a Python Expert →Get unlimited access to all Real Python has to offerhttps://realpython.com/account/join/?from=navbar_learn
Unlock All Content →Become a Python Experthttps://realpython.com/account/join/?from=navbar_learn
More https://realpython.com/videos/creating-python-modules/
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Contributorhttps://realpython.com/jobs/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?intent=navbar&next=%2Fvideos%2Fcreating-python-modules%2F
https://realpython.com/courses/python-basics-modules-packages/#team
Python Basics: Modules and Packageshttps://realpython.com/courses/python-basics-modules-packages/
Philipp Acsanyhttps://realpython.com/courses/python-basics-modules-packages/#team
Course Slides (.pdf)https://realpython.com/courses/python-basics-modules-packages/downloads/python-basics-modules-packages-slides/
Sample Code (.zip)https://realpython.com/courses/python-basics-modules-packages/downloads/python-basics-modules-packages-code/
Ask a Questionhttps://realpython.com/videos/creating-python-modules/#discussion
https://realpython.com/feedback/survey/course/python-basics-modules-packages/liked/?from=lesson-title
https://realpython.com/feedback/survey/course/python-basics-modules-packages/disliked/?from=lesson-title
Contentshttps://realpython.com/videos/creating-python-modules/#description
Transcripthttps://realpython.com/videos/creating-python-modules/#transcript
Discussionhttps://realpython.com/videos/creating-python-modules/#discussion
00:00https://realpython.com/videos/creating-python-modules/#t=0.675
Open IDLE and start a new editor window.https://realpython.com/videos/creating-python-modules/#t=0.675
In the editor window,https://realpython.com/videos/creating-python-modules/#t=3.382
define a function named add() that returns the sum of its two parameters.https://realpython.com/videos/creating-python-modules/#t=5.095
def add(x, y):https://realpython.com/videos/creating-python-modules/#t=9.775
and then on the next line, indented, return x + y.https://realpython.com/videos/creating-python-modules/#t=15.045
00:23https://realpython.com/videos/creating-python-modules/#t=23.715
Save the file as adder.py on your computer in a new directoryhttps://realpython.com/videos/creating-python-modules/#t=23.715
named myproject/.https://realpython.com/videos/creating-python-modules/#t=28.455
00:33https://realpython.com/videos/creating-python-modules/#t=33.225
Just like you learned a moment ago, adder.py is a Python module.https://realpython.com/videos/creating-python-modules/#t=33.225
So far so good.https://realpython.com/videos/creating-python-modules/#t=37.175
Now open another editor window and type the following code:https://realpython.com/videos/creating-python-modules/#t=40.025
value = add(2, 2)https://realpython.com/videos/creating-python-modules/#t=45.055
and then on the next line,https://realpython.com/videos/creating-python-modules/#t=50.885
print(value).https://realpython.com/videos/creating-python-modules/#t=54.555
00:58https://realpython.com/videos/creating-python-modules/#t=58.545
Save the file as main.py in the same myproject/ folder.https://realpython.com/videos/creating-python-modules/#t=58.545
That’s important.https://realpython.com/videos/creating-python-modules/#t=62.194
It must be in the same folder,https://realpython.com/videos/creating-python-modules/#t=63.135
so make sure to save it in the myproject/ folder on your computer.https://realpython.com/videos/creating-python-modules/#t=65.175
01:10https://realpython.com/videos/creating-python-modules/#t=70.345
Then run the module.https://realpython.com/videos/creating-python-modules/#t=70.345
01:15https://realpython.com/videos/creating-python-modules/#t=75.285
Oops.https://realpython.com/videos/creating-python-modules/#t=75.285
Okay.https://realpython.com/videos/creating-python-modules/#t=75.731
When the module runs,https://realpython.com/videos/creating-python-modules/#t=76.178
you’ll see a NameError displayed in IDLE’s interactive window.https://realpython.com/videos/creating-python-modules/#t=77.875
The important part here is the last line of the traceback: NameError:https://realpython.com/videos/creating-python-modules/#t=82.235
name 'add' is not defined.https://realpython.com/videos/creating-python-modules/#t=86.165
01:29https://realpython.com/videos/creating-python-modules/#t=89.695
The NameError occurs because add() is defined in adder.py and not inhttps://realpython.com/videos/creating-python-modules/#t=89.695
main.py.https://realpython.com/videos/creating-python-modules/#t=94.595
That’s the file you ran.https://realpython.com/videos/creating-python-modules/#t=95.704
01:36https://realpython.com/videos/creating-python-modules/#t=96.964
So if you think a moment,https://realpython.com/videos/creating-python-modules/#t=96.964
then this error makes sense.https://realpython.com/videos/creating-python-modules/#t=98.545
How should Python know thathttps://realpython.com/videos/creating-python-modules/#t=100.341
you mean the add() function from the adder.py file?https://realpython.com/videos/creating-python-modules/#t=102.075
01:46https://realpython.com/videos/creating-python-modules/#t=106.215
In order to use add() in main.py,https://realpython.com/videos/creating-python-modules/#t=106.215
you must first import the module.https://realpython.com/videos/creating-python-modules/#t=108.775
So let’s do this.https://realpython.com/videos/creating-python-modules/#t=111.842
Become a Memberhttps://realpython.com/account/join/
https://realpython.com/videos/working-with-python-modules/
Overviewhttps://realpython.com/courses/python-basics-modules-packages/
https://realpython.com/lessons/call-imported-object/
Python Basics: Modules and Packages (Overview) 01:44 https://realpython.com/videos/modules-packages-overview/
Working With Modules 00:27 https://realpython.com/videos/working-with-python-modules/
Creating Modules 01:55 https://realpython.com/videos/creating-python-modules/
Calling an Imported Object 01:45 https://realpython.com/lessons/call-imported-object/
Understanding Namespaces 00:27 https://realpython.com/lessons/understanding-namespaces/
Accessing Objects From Inside a Module 01:02 https://realpython.com/lessons/accessing-module-objects/
Using Dot Notation for Imported Objects 00:54 https://realpython.com/lessons/dot-notation-imported-objects/
Adding Objects to a Namespace 01:29 https://realpython.com/lessons/adding-namespace-objects/
Breaking a Program Into Modules 00:45 https://realpython.com/lessons/break-program-into-modules/
Exercise: Import and Use a Module 08:00 https://realpython.com/lessons/exercise-import-use-module/
Exercise: Fix a Broken Import 08:00 https://realpython.com/lessons/exercise-fix-broken-import/
Renaming an Imported Module 02:42 https://realpython.com/lessons/rename-imported-module/
Importing Objects From a Module 03:20 https://realpython.com/lessons/import-module-objects/
Summarizing Import Statements 03:18 https://realpython.com/lessons/summarizing-import-statements/
Exercise: Import Specific Functions 08:00 https://realpython.com/lessons/exercise-import-specific-functions/
Taking Advantage of Namespaces 01:04 https://realpython.com/lessons/namespace-advantages/
Introducing Packages 01:16 https://realpython.com/lessons/introducing-python-packages/
Creating Packages 03:21 https://realpython.com/lessons/creating-python-packages/
Working With Packages 04:16 https://realpython.com/lessons/working-with-packages/
Summarizing Import Statements for Packages 01:40 https://realpython.com/lessons/package-import-statements/
Importing Modules From Subpackages 03:57 https://realpython.com/lessons/importing-modules-from-subpackages/
Exercise: Import From a Package 08:00 https://realpython.com/lessons/exercise-import-from-package/
Python Basics: Modules and Packages (Exercises) 02:55 https://realpython.com/lessons/python-modules-packages-exercises/
Python Basics: Modules and Packages (Quiz) 05:30 https://realpython.com/lessons/modules-packages-quiz/
Python Basics: Modules and Packages (Summary) 01:37 https://realpython.com/lessons/modules-packages-summary/
Privacy Policyhttps://realpython.com/privacy-policy/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.