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...

Комментарии • 58

  • @moorelo
    @moorelo 5 лет назад +5

    Thank you for explaining modules so clearly. I starting programming in FORTRAN IV in the 80s, Python has me excited about programming again.

  • @ratonmagico
    @ratonmagico 6 лет назад +6

    This video is gold. Best explanation on modules and packages I've found in RUclips.

  • @ryansossou646
    @ryansossou646 3 года назад

    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

  • @wiliextreme
    @wiliextreme 2 года назад

    thanks for this great video, coming from nodejs I found it pretty confusing how python imports work but now I get it

  • @HtorneDK
    @HtorneDK 3 года назад

    what an EXCELLENT video - this content is beyond any other tutorials on the web. omg this is good. Instant subscribe. Thanks

  • @AhmedAli-dz1hy
    @AhmedAli-dz1hy 4 года назад

    He is full of information. Better than professors

  • @cybervigilante
    @cybervigilante 6 лет назад +4

    Wow, that cross-importing is cool. And it doesn't even have to be a class. I tried it on a simple function.

  • @ProfessionalTycoons
    @ProfessionalTycoons 7 лет назад +4

    I use this all the time, but never knew whats going on behind the scene lol

  • @MoistKing
    @MoistKing 4 года назад +3

    Thankyou for the great lecture! Love the "Banana" examples.

  • @RaynerDaCruz
    @RaynerDaCruz 4 года назад +2

    @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()?

  • @nkosikhonampungose1500
    @nkosikhonampungose1500 2 месяца назад

    2024, still Gold🎉

  • @Mortum_Rex
    @Mortum_Rex 6 лет назад +1

    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.

  • @haopeiyang3443
    @haopeiyang3443 5 лет назад

    Thank you for this video Mr. Gordon. The content is solid.

  • @EasyLanguageCoach
    @EasyLanguageCoach 5 лет назад +1

    Very well done. A good explanation of it. Thank you very much.

  • @feniordi
    @feniordi 2 года назад

    Simple explenation and good examples, thanks for the tutorial!

  • @AhmedAli-dz1hy
    @AhmedAli-dz1hy 4 года назад

    That is great. Like these slides and like your easy way of explanation

  • @likysquad
    @likysquad 3 года назад

    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.

  • @djamelfertas
    @djamelfertas 4 года назад

    Wow that's such an amazing explanation, Thank you Sir

  • @dishonmwabashfano3627
    @dishonmwabashfano3627 3 года назад

    Thanks a lot. You are the best.

  • @beratakuzum8381
    @beratakuzum8381 6 лет назад

    Amazing and detailed tutorial. Thank you so much!

  • @PwrTrumper
    @PwrTrumper 4 года назад +1

    great video, fantastic explanation. I still think this whole __init__ idea is an unintuitive design choice in python.

  • @richiekho1159
    @richiekho1159 3 года назад

    It is well explained, just that the sound need to be improveed

  • @سفيانقريميدة
    @سفيانقريميدة 4 года назад

    Excellent explanation, thank you very much

  • @Adks007
    @Adks007 6 лет назад

    Very nice video. Respect from United states

  • @dbmaster46446
    @dbmaster46446 2 года назад

    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

  • @Pedritox0953
    @Pedritox0953 Год назад

    Great video!

  • @dileepaozi2352
    @dileepaozi2352 3 года назад

    Wow nicely explained... can you do a video like this about distribution of python program to users, things like setup.py, python egg, pyInstaller.

  • @seghairtarek4629
    @seghairtarek4629 5 лет назад +1

    the best video ever thank you... you helped me a lot ^_^

  • @scienceblossom6197
    @scienceblossom6197 5 лет назад

    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)

    • @damiantgordon
      @damiantgordon  5 лет назад

      With new Python this should work >>> from import *

  • @niyagentleman8143
    @niyagentleman8143 3 года назад +1

    x-llent explanations! thanks so much for this tutorial! ^^

  • @sfcoawol6273
    @sfcoawol6273 4 года назад

    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

  • @mikerihm
    @mikerihm 6 лет назад +1

    This is fantastic

  • @yomajo
    @yomajo 5 лет назад

    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

    • @Brandon-hb7tx
      @Brandon-hb7tx 5 лет назад

      yomajo from Drawing.Maths import Theorem I would think

  • @PihFrags
    @PihFrags 2 года назад

    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

  • @motherofako
    @motherofako 6 лет назад

    Wow sir , you are brilliant!

  • @shivamchaudhary470
    @shivamchaudhary470 7 лет назад +4

    thank you sir

  • @omphemetsemafoko830
    @omphemetsemafoko830 3 года назад

    Thank you.

  •  6 лет назад

    clean explanation.

  • @danibaba7058
    @danibaba7058 5 лет назад

    How do i import a file but not run it?Just so i can use the variables??

    • @damiantgordon
      @damiantgordon  5 лет назад

      Are they in a class in the file?

    • @danibaba7058
      @danibaba7058 5 лет назад

      @@damiantgordon what do you mean?

    • @danibaba7058
      @danibaba7058 5 лет назад

      @@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()

    • @danibaba7058
      @danibaba7058 5 лет назад

      @@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()

    • @danibaba7058
      @danibaba7058 5 лет назад

      @@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.

  • @ettercap5384
    @ettercap5384 6 лет назад

    How do I import the .py that is in the main folder and not in the subdirectory?

  • @deeproy7292
    @deeproy7292 7 лет назад

    You have helped a lot

  • @MadhuExplorer
    @MadhuExplorer 7 лет назад

    Nicely explained...

  • @kitcat2449
    @kitcat2449 2 года назад

    I love learning python after languages like c++ and java haha, less work

  • @dontspeakitdoit
    @dontspeakitdoit 2 года назад

    11:58

  • @BS-eu9do
    @BS-eu9do 4 года назад

    Thank a lot

  • @kitcat2449
    @kitcat2449 2 года назад

    💕

  • @FERNAND0_MEDElR0S
    @FERNAND0_MEDElR0S 7 лет назад

    Very good! Tks