Thanks for covering the role of __init__.py in the import of a module. Because a lot of video tutorials skip this information.
@useronetwothree-z6fАй бұрын
fr
@arkie872 ай бұрын
This is a great start on this topic. There arent actually a lot of youtube videos about this topic, and its hard to find information. Would appreciate a follow up that went more into detail, if you can. For instance: what exactly happens when you import things in the __init__.py file. What sort of start up logic do you need to do. What is the appropriate use of this file etc....
@danialothman2 ай бұрын
that one class I ignored, it was this one in 2021. i got it now 😂 thanks for this!
@BohonChina2 ай бұрын
you should mention the difference between having _init_.py and not having one in your module directory
@luisdominguesforprogramaca32212 ай бұрын
He explained it's the _init_.py that makes the directory module a package and how to use that file to define the behaviour of the imports.
@BohonChina2 ай бұрын
@@luisdominguesforprogramaca3221 NO _init_.py, INSERT path in PYTHONPATH, import module statement after inserting path will behave like a package too.
@DhavalAhir102 ай бұрын
When you have `__init__.py` file in your folder directory, your folder called as "package". When you don't have `__init__.py` file in your folder directory, your folder still count as package but now your folder called as "Namespace Package" instead of "package".
@creed404yt92 ай бұрын
Rewatch the video
@Omsip1232 ай бұрын
How about explaining the difference in your comment?
@laitei-e402 ай бұрын
Great! Loved it, my hero 🎉
@petsandpaws89062 ай бұрын
Crystal clear. Thank you for explaining it very simpel!
@dragweb77252 ай бұрын
Thanks for this basic tutorial about imports, could it be possible to make a video about imports between modules in the same package ? cause this is always a pain in the a** to know how to do these correctly and everyone seems to use different tricks when searching for solutions on the net. That would be a really helpful video
@jokmenen_2 ай бұрын
Same. Had to use sys.path to import packages from another folder yesterday. My brain exploded
@ego-lay_atman-bay2 ай бұрын
I don't understand how it's difficult. If you have an __init__?py file in each folder, they become submodules, which you can import the same way as a file inside a package. If you need to import from one submodule to another, you use two dots instead of one.
@dragweb77252 ай бұрын
@@ego-lay_atman-bay I'm not talking about imports outside a package (involving __init__.py), but more about imports between modules in the same package (same folder), as relative imports easily gives you a "attempted relative import but no parent package found" even with __init__.py everywhere, and direct import like "from module import func" without a dot it easily gives you a "no module named 'module' found"
@ego-lay_atman-bay2 ай бұрын
@@dragweb7725 and what is the use case for such a project with that kind of folder structure?
@lisaw707426 күн бұрын
This is so helpful and clearly explained! Thank you very much!
@onlysin530Ай бұрын
thank you very much! this also explains why some packages won't work when you just use import *... the __init__ flie in the package didn't explicitly declare the file that was needed! It is always a safer way to explicitly declaring the packages that one need then
@prach-poomАй бұрын
You're awesome. This one has a lot of great tips
@thefanboy32852 ай бұрын
Thanks. Mind refresher, Life saver.
@mukisajohnmary2 ай бұрын
Wonderful explanation. Thanks 🙏
@purplemonkeydishwasher5269Ай бұрын
This is amazing. Im completely rebuilding an app Im working on based on this!!!
@awetinoawets92902 ай бұрын
Very useful 🙏🙏🙏
@michaelangellotti57412 ай бұрын
Quick and accurate. Thanks.
@average_paniker2 ай бұрын
Clearly explained. Thank you!
@nobody29372 ай бұрын
Thank you indeed... Extremely clear, concise... Thank you ...
@mikecanaday48882 ай бұрын
Good job! Pycharm was a nice touch since that’s the environment that many use.
@EquiliMarioАй бұрын
The __all__ dunder method is something i didnt know yet. Neat
@ml_with_pranay2 ай бұрын
I enjoy your videos a lot! Keep posting😊
@tejasmarvel2023Ай бұрын
very clear video. thanks
@HiltonFernandes2 ай бұрын
Great video. Congrats !
@7th_dwarf5422 ай бұрын
brilliant! 👏
@AdrianCortes-b7f2 ай бұрын
Veryw ell explained, Thank you!
@AlWardani-k2h2 ай бұрын
❤❤❤❤❤ awesome
@davidlu10032 ай бұрын
I love you, great videos, and please keep going.😁😁😁
@FighterAceee942 ай бұрын
It would have been interesting to see the behavior of __init__.py when importing the same package from multiple different modules within your project. If I'm not mistaken, the __init__.py will be called only once (the first time any import statement is used).
@_Garm_2 ай бұрын
aveasome thank you, would like to learn more about it :D
@goobiie2 ай бұрын
Very useful video
@basilchinedu1442 ай бұрын
Thanks a lot, very helpful.
@odevperovano2 ай бұрын
Excellent, thankyou!
@elastvd7503Ай бұрын
Super , thanks
@banjijohn2 ай бұрын
❤ thank you 🎉
@benmatt89402 ай бұрын
Utterly usefull
@Pawlo3702 ай бұрын
very good tutorial 👍
@giocic942 ай бұрын
I use "__init__.py" also for importing all the libraries that I will import in the submodules. And then, in the submodules, I use "from . import ". I don't know if it's useful, I wanted to have organized imports.. Does it make sense?
@timbrap4693Ай бұрын
I do that too!
@Muhammad-zu6lk2 ай бұрын
You'r plane went well!
@HoSza12 ай бұрын
so a package is a container that contains an __init__ in it! 😂
@BohonChina2 ай бұрын
you can compare with or wihout __init__.py in two scenarios 1. HAVING _init_.py, No INSERT of path in sys 2. NO _init_.py, INSERT path in PYTHONPATH, import module statement after inserting path import sys sys.path.append('/python/NoInitModule') from dir import module statement
@sean-uw6op2 ай бұрын
Could you please make a video on python garbage collection
@PennyEvolus2 ай бұрын
i didnt even know i needed to know this
@akalrove483428 күн бұрын
I came I saw and i liked
@michaelrstudley2 ай бұрын
Fantastic video. How do you feel about placing all imports needed for the files inside? For example... From enum import Enum
@m00n-Child962 ай бұрын
🙏
@pratikkshirsagar71522 ай бұрын
Thanks
@makersbeeАй бұрын
Share your vscode setup
@mukombradon8 күн бұрын
That's pycharm not vscode
@murphygreen84842 ай бұрын
I thought the __init__.py was no longer needed? I've never used it. Though I also have issues with pytest when my test files are in a sub directory, so that could be part of it
@eduferreyraok2 ай бұрын
I think the interpreter has added some layer of inference to this… but it can still be buggy sometimes. I.e: i dont get import errors when trying mysql in django, but when including the module at init then the hug goes away
@DhavalAhir102 ай бұрын
When you have `__init__.py` file in your folder directory, your folder called as "package". When you don't have `__init__.py` file in your folder directory, your folder still count as package but now your folder called as "Namespace Package" instead of "package".
@arungumpina46442 ай бұрын
@murphygreen8484 could you please suggest if know any tutorials for pytest?
@drakouzdrowiciel9237Ай бұрын
thx
@arungumpina46442 ай бұрын
Hey @Indently, If I have multiple modules (so many modules) in packages, & our init script has this __all__ dunder method, do I need to give each & every module name in __all__ = ['wifi', 'mobile', 'bluetooth', 'module4', 'module5'..... ] Is there a better way for us to include all modules in package initalizer? in order for * recognizes all modules?
@oneforall40492 ай бұрын
Which code editor you use
@null-0x2 ай бұрын
PyCharm
@atmadeeparya24542 ай бұрын
what's the code editor
@apollowilsons2 ай бұрын
Can you do blender python? plz
@frazer262 ай бұрын
How would you make the connections module accessible with different projects without copying it over to every new project?
@Mark_Point2 ай бұрын
Do the functions in the new package still need, the if name == main line?
@eduferreyraok2 ай бұрын
If you want to execute code exclusively at the file, then yes… it applies for all files/imports/packages/modules
@mohammadjawad4806Ай бұрын
I guess it would be a poor practice or even dangerous to execute a code from __init__ file, right?
@antoniov8452 ай бұрын
Star import is a really poor practice
@michaelcummings72462 ай бұрын
If you are basically using everything in a package already it makes sense to use it. If you only need a couple then it might make sense not to so naming conflicts are less likely but personally once my import line gets past 3-4 things I switch.
@antoniov8452 ай бұрын
@@michaelcummings7246 there are many issues with star imports. Honestly when I just discovered it I started to use it all over the place since it’s def easier But after a few days I changed all that 😀 it makes refactoring etc much harder and imagine solving circular import error with this approach 😀
@spaniard135 күн бұрын
Star imports are essential for some Python libraries, where you want to get a whole new "dialect" into your script (versus borrowing specific functionality). The best example I know is FastHTML, in which HTML tags are brought into Python to simplify server side rendering with HTMX.
@sarundayo2 ай бұрын
Learning python on the go apps?
@mlocverm2 ай бұрын
👋👋👋
@realortigotze2 ай бұрын
Does anybody knows what font he's using?
@seasn55532 ай бұрын
Dude holy I legit was thinking about this an hour ago LOL
@majinmarkus9682 ай бұрын
its loading some libraries. Innit? :D
@LucaCappelletta2 ай бұрын
While learning a bit more on how star import works is useful and interesting, star import is really a bad practice. I hope this video doesn't encourage anyone to use it.
@ego-lay_atman-bay2 ай бұрын
Sometimes it's useful, such as importing c_types. You're most likely going to just import everything instead of using ctypes.c_uint32(). However, they still are not very good most of the time.
@SeigeGoatАй бұрын
When did python became British?
@IndentlyАй бұрын
Since it was founded it was based on a British TV series
@miguelvasquez98492 ай бұрын
i read the __init__ file is no longer necesary
@eduferreyraok2 ай бұрын
Not its infered, but i would still recommend it since it can be buggy sometimes
@DhavalAhir102 ай бұрын
When you have `__init__.py` file in your folder directory, your folder called as "package". When you don't have `__init__.py` file in your folder directory, your folder still count as package but now your folder called as "Namespace Package" instead of "package".
@rhettsmedia2 ай бұрын
For us blind guys you need to speak__or thunder
@rhettsmedia2 ай бұрын
Also, what is this whole thing is a variable is it a list? What is it is a dictionary