René's URL Explorer Experiment


Title: Accessing Objects From Inside a Module (Video) – Real Python

Open Graph Title: Accessing Objects From Inside a Module – Real Python

Description: Variables, functions, and classes in a module can be accessed from within the same module by just typing their name. Let me show you what I mean by that. If you add the two lines of code that you used in main.py in adder.py and then run the code…

Open Graph Description: Variables, functions, and classes in a module can be accessed from within the same module by just typing their name. Let me show you what I mean by that. If you add the two lines of code that you used in main.py in adder.py and then run the code…

Opengraph URL: https://realpython.com/lessons/accessing-module-objects/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
  {
    "@context": "https://schema.org",
    "@type": "VideoObject",
    "name": "Accessing Objects From Inside a Module",
    "description": "Variables, functions, and classes in a module can be accessed from within the same module by just typing their name. Let me show you what I mean by that. If you add the two lines of code that you used in main.py in adder.py and then run the code…",
    "thumbnailUrl": ["https://files.realpython.com/media/Modules-and-Packages_Watermarked.bc38abc24435.jpg"],
    "uploadDate": "2023-11-14T14:00:00+00:00",
    "duration": "PT1M2S",
    
    "potentialAction": {
      "@type": "SeekToAction",
      "target": "https://realpython.com/lessons/accessing-module-objects/#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/lessons/accessing-module-objects/
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/lessons/accessing-module-objects/
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=%2Flessons%2Faccessing-module-objects%2F
Unlock This Lessonhttps://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-basics-modules-packages
Unlock This Lessonhttps://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-basics-modules-packages
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/lessons/accessing-module-objects/#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/lessons/accessing-module-objects/#description
Transcripthttps://realpython.com/lessons/accessing-module-objects/#transcript
Discussionhttps://realpython.com/lessons/accessing-module-objects/#discussion
00:00https://realpython.com/lessons/accessing-module-objects/#t=0.995
Variables,https://realpython.com/lessons/accessing-module-objects/#t=0.995
functions, and classes in a module can be accessed from within the same module byhttps://realpython.com/lessons/accessing-module-objects/#t=1.595
just typing their name.https://realpython.com/lessons/accessing-module-objects/#t=5.595
Let me show you what I mean by that.https://realpython.com/lessons/accessing-module-objects/#t=6.728
If you add the two lines of code that you used in main.py in adder.pyhttps://realpython.com/lessons/accessing-module-objects/#t=9.375
and then run the code, then the code should work.https://realpython.com/lessons/accessing-module-objects/#t=14.215
00:17https://realpython.com/lessons/accessing-module-objects/#t=17.815
So at the end of adder.py, add the line value =https://realpython.com/lessons/accessing-module-objects/#t=17.815
add(2, 2).https://realpython.com/lessons/accessing-module-objects/#t=23.135
On the next line, print(value).https://realpython.com/lessons/accessing-module-objects/#t=24.812
And then you run it, then it works.https://realpython.com/lessons/accessing-module-objects/#t=28.615
00:32https://realpython.com/lessons/accessing-module-objects/#t=32.155
And the reason for this is because you are accessing add() from within the samehttps://realpython.com/lessons/accessing-module-objects/#t=32.155
file.https://realpython.com/lessons/accessing-module-objects/#t=36.285
They’re in the same module, and therefore in the same namespace.https://realpython.com/lessons/accessing-module-objects/#t=36.661
00:42https://realpython.com/lessons/accessing-module-objects/#t=42.395
So that was just an example for the namespace inside of one module.https://realpython.com/lessons/accessing-module-objects/#t=42.395
Remove both lines of code, the value variable definition,https://realpython.com/lessons/accessing-module-objects/#t=47.115
and the print() function call, save the file, and get back to main.py.https://realpython.com/lessons/accessing-module-objects/#t=50.115
00:54https://realpython.com/lessons/accessing-module-objects/#t=54.675
So adder.py should look like it was at the beginning with only the add()https://realpython.com/lessons/accessing-module-objects/#t=54.675
function definition.https://realpython.com/lessons/accessing-module-objects/#t=59.815
Become a Memberhttps://realpython.com/account/join/
https://realpython.com/lessons/understanding-namespaces/
Overviewhttps://realpython.com/courses/python-basics-modules-packages/
https://realpython.com/lessons/dot-notation-imported-objects/
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.