Python: Modules and Packages
HTML-код
- Опубликовано: 6 фев 2025
- Python: Modules and Packages. NOTE: Since this video was created the newer versions of Python 3 don't allow you to call a package from inside a sub-folder any more. It seems it's been decided that doing so is now considered "bad practice" in the last few years, so the theorem.py call won't call the classes in the Drawing folder. More at:
www.damiantgord...
Thank you for explaining modules so clearly. I starting programming in FORTRAN IV in the 80s, Python has me excited about programming again.
This video is gold. Best explanation on modules and packages I've found in RUclips.
Hey Damian, this is exactly what I was looking for, I just started working on a big project with python but package and modules management was really confused, now everything is clear, you're the best Damian, thanks for bringing those free resources for the community
thanks for this great video, coming from nodejs I found it pretty confusing how python imports work but now I get it
what an EXCELLENT video - this content is beyond any other tutorials on the web. omg this is good. Instant subscribe. Thanks
He is full of information. Better than professors
Wow, that cross-importing is cool. And it doesn't even have to be a class. I tried it on a simple function.
I use this all the time, but never knew whats going on behind the scene lol
Thankyou for the great lecture! Love the "Banana" examples.
@9:20 Wouldn't the first snippet of code result in a ModuleNotFoundError since point-call.Point() is not prefixed with Drawing? Like this, Drawing.point-call.Point()?
2024, still Gold🎉
Did anyone else keep thinking Damian was holding a cane the whole time in his remote hand? He'd look pretty badass with a cane I reckon. Anyway, brilliant lecture! Thank you, sir.
Thank you for this video Mr. Gordon. The content is solid.
Very well done. A good explanation of it. Thank you very much.
Simple explenation and good examples, thanks for the tutorial!
That is great. Like these slides and like your easy way of explanation
Geez, this is annoying, I can't compile my payload now because I've been using sys this whole time to duct tape the issue. My .py code is scattered all throughout my computer in different folders. Now I see I got a lot of learning to do. Thanks for the lecture.
Wow that's such an amazing explanation, Thank you Sir
Thanks a lot. You are the best.
Amazing and detailed tutorial. Thank you so much!
great video, fantastic explanation. I still think this whole __init__ idea is an unintuitive design choice in python.
It is well explained, just that the sound need to be improveed
Excellent explanation, thank you very much
Very nice video. Respect from United states
is following code the right way to use __init__ ? im still not sure how i should construct packages
for module in os.listdir(os.path.dirname(__file__)):
if module.startswith("__"):
continue
name = "{}.{}".format(__name__,module) if not module.endswith('.py') else "{}.{}".format(__name__,module[:-3])
__import__( name)
del module
Perfect
@@damiantgordon excelent, thank you
Great video!
Wow nicely explained... can you do a video like this about distribution of python program to users, things like setup.py, python egg, pyInstaller.
the best video ever thank you... you helped me a lot ^_^
What if we want to import more than a module from a sub-directory? E.g. what if we want to import all the methods in a module in a subdirectory(e.g. ./childDir1/module ---> contains 10 methods)
With new Python this should work >>> from import *
x-llent explanations! thanks so much for this tutorial! ^^
Thanks for this lecture! I've been trying to import code from other files but I was having issues with referenceing variables from outside the code snippet into the code. Most guides are way to basic to explain this
This is fantastic
Say near the Maths, there's Biology folder, which has Calculations.py. How does one import Theorem.py into it?
[...]
|---Maths
|--- --- __init.py
|--- --- Theorem.py
|---Biology
|--- --- __init.py
|--- --- Calculations.py
yomajo from Drawing.Maths import Theorem I would think
Very nice presentation Thank you for great content. One thing i noticed though was that you used uppercase names for packages. PEP 8 says points that lowercase should be used 😉But still. Structure and code was readable so still A+ for presentation
Wow sir , you are brilliant!
thank you sir
Thank you.
clean explanation.
How do i import a file but not run it?Just so i can use the variables??
Are they in a class in the file?
@@damiantgordon what do you mean?
@@damiantgordon This is first:
import sys
def Register():
choice = input("Would you like to register?
Type yes or no.
")
if choice == "yes":
secured = open("login.txt" ,"w")
Username = input("Username: ")
secured.write(Username)
Password = input("Password: ")
secured.write(Password)
secured.close()
elif choice == "no":
cond = False
else:
print("Please choose between Yes or No")
Register()
Register()
sys.exit()
@@damiantgordon This is second :
def Login():
question = input("Would you like to login?
Type yes or no.
")
if question == "yes":
user = input("Username: ")
passw = input("Password: ")
secured.open("login.txt","r")
secured.read(Username)
secured.read(Password)
if Username == user and Password == passw:
print("Login successful")
else:
ex_or_res = input("Username/Password incorrect!
Please try again or exit
To try again type restart
To exit type exit")
if ex_or_res == "restart":
Login()
elif ex_or_res == "exit":
sys.exit()
else:
sys.exit()
if question == "no":
sys.exit()
Login()
@@damiantgordon I want to get input that is saved in a file login.txt in the module register and then read it in module login.So obviously i want to run module 1 but by running module 1 not by importing it to module2(if that makes sense).And then read the input from module 1 but in module 2.
How do I import the .py that is in the main folder and not in the subdirectory?
Just say "Import FileName"
You have helped a lot
Nicely explained...
I love learning python after languages like c++ and java haha, less work
11:58
Thank a lot
💕
Very good! Tks