Тёмный

Intermediate Python Tutorial: How to Use the __init__.py File 

Eric O Meehan
Подписаться 8 тыс.
Просмотров 132 тыс.
50% 1

A succinct tutorial on how to use the __init__.py file to import directories as python libraries.
Welcome to my series for Learning Python, where I will be teaching fundamental concepts in the Python programming language.
These videos will focus on one aspect of Python at a time, but your understanding of the material will be greatly improved through usage. I recommend applying the concepts described here in your own project, or viewing the Developer Diary series where I use these tools on bigger projects.
• Developer Diary: Open ...

Наука

Опубликовано:

 

12 янв 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 179   
@eom-dev
@eom-dev 3 года назад
Hello everyone! Another user was having a problem that I want to share with you guys. When you import a package to python, the interpreter searches several paths to find your library - one of which being the working directory. If, however, one of those other paths has a library with the same name, that one will take precedence! If you create a library called Matplotlib, python will still import the original instead of yours!
@jackcaesar2596
@jackcaesar2596 3 года назад
Finally a short and to the point tutorial that actually tells me what the frick a __init__.py is and how to use it, thank you!
@ajayjoseph4498
@ajayjoseph4498 3 года назад
I came here to learn __init__, but the way you have demonstrated is absolutely amazing; now I understand what from, import, and __init__.py do. Brilliant!.
@eom-dev
@eom-dev 3 года назад
Thank you! I appreciate it!
@PatrickSteil
@PatrickSteil Год назад
Same! Good job
@MarkSmith-vo1vn
@MarkSmith-vo1vn 26 дней назад
Slight correction. I haven’t finished watching it yet. But if you do import resources.object_ones. You can do object_ones.Ones(). That’s it. It’s more to type, which is why the from is used. But you will often see packages like pandas like this. import pandas as pd. Then we do pd.DataFrame() blah blah.
@JV-jc7ci
@JV-jc7ci Год назад
You're a gem! Such a great teacher! If everyone taught like this anyone could learn Python in days!
@mihailb0r0koko89
@mihailb0r0koko89 2 года назад
Jeeez I always used init files without typing in anything. 2 years passed here I am finding out this blessing of information. This will clean up a lot of mess in my projects. Huge thanks!!!!!
@derekknowlton2384
@derekknowlton2384 2 года назад
Thanks for that clear description. This make reusing code so much easier. I have been trying to figure this out for two weeks.
@samarjitdebnath5996
@samarjitdebnath5996 2 года назад
Short and straightforward, great work Eric!
@mrc1500
@mrc1500 Год назад
Thanks, Eric. This short video was just what I was looking for. I'm a Python newcomer and packages have been difficult to grok until now.
@davidnobles162
@davidnobles162 Год назад
Thank you! The first two minutes explained my confusion about why some of my code would work without errors when other code wouldn't. Definitely helped me. Thanks!!!
@poncelas91
@poncelas91 Год назад
Very good explanation. I was wondering why a lot of projects had hundreds of lines of code added to their __init__ file and this has helped a lot. Thanks mate!
@Jerry-uc1pn
@Jerry-uc1pn Год назад
Short and straight to the point. I love this!
@utpalmohane1416
@utpalmohane1416 Год назад
concise, short, to the point, just what I was expecting
@splendorman7922
@splendorman7922 Год назад
this might be the best explanation about imports on youtube. thanks man
@devdrane
@devdrane 2 дня назад
OH MY GOD it's so simple yet noone has ever explained it like this!!!
@cysong88161
@cysong88161 Месяц назад
randomly came across and whatever this is, this helped me understand soo much init and the concept of library, in such a short and engaging video. thank you so much.
@armandoWebDev
@armandoWebDev 2 года назад
Thank you so much for this video. I find this topic relatively challenging to understand but now is completely clear for me. Thanks again.
@ahmedalhamadah5999
@ahmedalhamadah5999 6 месяцев назад
Great! I was reading tutorials about python to grasp everything. Not a great idea. It was confusing especially the __init__ but your videos makes it so easy to understand! Love it. Thank you so much
@c0nsumption
@c0nsumption 9 месяцев назад
This was the 'dark souls boss' of python for me. You executed him in under 6 minutes. Thank you sensei.
@swarnimjambhule3264
@swarnimjambhule3264 23 дня назад
Thanks, no confusing words used. Clearly explained!
@CyberPsyLen
@CyberPsyLen 2 года назад
Superb succinct tutorial - many thanks!
@alkhashtee
@alkhashtee 3 года назад
Thank you very much Eric, I sure appreciate you for this short informative video. Will support you till the end .
@eom-dev
@eom-dev 3 года назад
Much appreciated!
@user-zv9pu7kf6z
@user-zv9pu7kf6z 6 месяцев назад
Super helpful! I love how you walked through the logic
@chianlee1381
@chianlee1381 3 года назад
Very nice and clear tutorial, it helps a lot!
@junealexissantos4341
@junealexissantos4341 Год назад
Broo, you are a genius. Thank you for explaining it so clearly. Subbed and liked!
@elias043011
@elias043011 3 года назад
One of the better explanations i have seen on youtube!
@eom-dev
@eom-dev 3 года назад
Thank you!
@kya-baat
@kya-baat Год назад
Short and to the point. Great work Eric 👌 I think I would be coming back to you the next time as well for any help on python.
@parralelife
@parralelife 25 дней назад
Concise, clear and very informative. Thank you ❤
@adrianmisak07
@adrianmisak07 2 года назад
i dont see how this video could have been better. thank you
@Vishnuishere
@Vishnuishere Год назад
Thanks a lot mate, was trying for ages this.. but resolved now. Thank you .
@jonnynilsen9276
@jonnynilsen9276 3 года назад
Really good explanation Eric! you are really the first RU-vidr that explained it so good that i can understand it right away without becoming confused xD. You got my sub :)
@eom-dev
@eom-dev 3 года назад
Thank you! Feel free to join our discord server if you have any questions! I'm happy to help :)
@cusematt23
@cusematt23 7 месяцев назад
You are very good at explaining things. Great video!
@Ma1ne2
@Ma1ne2 Год назад
Straight to the point, thanks!
@adityanjsg99
@adityanjsg99 2 года назад
It takes an altogether different mind to even bother about this aspect!! Thanks.
@bulldawg4498
@bulldawg4498 Год назад
Clear and concise ... Good job!
@RealisticSohaib
@RealisticSohaib 3 года назад
subscriber number 382 here. great content. to the point. thanks
@eom-dev
@eom-dev 3 года назад
Thanks for the sub, welcome aboard!
@nathanielhorn144
@nathanielhorn144 3 месяца назад
Extremely helpful and very well explained.
@nikhil182
@nikhil182 2 года назад
This is really helpful. Thank you so much!
@gpet2184
@gpet2184 2 года назад
Excellent! man, I will recommend your channel.
@t-distributedkid3825
@t-distributedkid3825 Год назад
Just what I was looking for!
@JustPlainRob
@JustPlainRob 8 месяцев назад
Thank you for this. You're a good teacher and your explanations are clear. I was struggling because all the answers were "just append the directory to the system path" or "put it in the init file" with no information on WHAT to put in the file.
@giacomodavide3316
@giacomodavide3316 7 месяцев назад
Very useful and very clear. Thank you!
@maksymilianbiruk6877
@maksymilianbiruk6877 2 года назад
Brilliant explanation! Thank you:)
@inteligenciaartificiuau
@inteligenciaartificiuau 6 месяцев назад
Amazing! Thanks!
@eddyeffy
@eddyeffy 2 года назад
Thanks for the explanation, it's now clearer
@rubyashby8303
@rubyashby8303 Год назад
Awesome tutorial ........
@dhirajkumarsahu999
@dhirajkumarsahu999 5 месяцев назад
Thanks a ton Eric!!
@sivanesans2424
@sivanesans2424 2 года назад
Simple but great work.. Thanks
@kirito3082
@kirito3082 5 месяцев назад
Excellent explanation, thank you
@user-fe9hy4uq4i
@user-fe9hy4uq4i 4 месяца назад
Awesome!
@sumangupta871
@sumangupta871 6 месяцев назад
Very short and nice and clear explanation.
@christofferd647
@christofferd647 Год назад
Waow, great explanation thank you so much. I was able to follow along :)
@nyanlinnhtet7773
@nyanlinnhtet7773 Год назад
Thanks a lot Mr.Eric 😍😍
@himanshuyadav1712
@himanshuyadav1712 Год назад
Thanks , this video help me to get more clear and easily understanadable information
@jsj757
@jsj757 10 месяцев назад
Great🎉 .Crystal clear ❤
@avnichakraverty7783
@avnichakraverty7783 Год назад
great explanation!
@MuhammadAbdullahTariq-iz4ij
@MuhammadAbdullahTariq-iz4ij 7 месяцев назад
Explained very well 👏
@senthilnayagan7047
@senthilnayagan7047 10 месяцев назад
It helps understand the concept better!
@patrickkrenz515
@patrickkrenz515 Год назад
Fantastic explanation!
@oursblanc6477
@oursblanc6477 2 года назад
Thanks You very much from France !
@arunkumaranbalagan6048
@arunkumaranbalagan6048 Год назад
Thanks Mr.Eric. it's a good explanation... 🎉
@the12nina
@the12nina 3 года назад
Thanks for the help! Really good explanation
@eom-dev
@eom-dev 3 года назад
Glad you liked it, thank you!
@fhuadbalogun2997
@fhuadbalogun2997 3 года назад
Thanks for this. I really needed to understand this.
@eom-dev
@eom-dev 3 года назад
Glad it was helpful!
@darioBenedict
@darioBenedict 3 года назад
Congrats!! Very very well explained.
@eom-dev
@eom-dev 3 года назад
Thank you!
@girishdoddi4831
@girishdoddi4831 2 года назад
Wow how come this guy have very less subscribers. you deserve more.
@andrewiglinski148
@andrewiglinski148 Год назад
Oh my lord my eyes!!! You are one of like three people I’ve ever met that works in a light theme….
@nadeemNadamat
@nadeemNadamat 2 года назад
Very beautifully explained brother
@purpetualbeats
@purpetualbeats 2 года назад
Thanks man this was helpful
@xinglinli9874
@xinglinli9874 2 года назад
Thank you!
@user-of2ni3ju7j
@user-of2ni3ju7j 10 месяцев назад
thank youfor this.
@dusk_and_dawn2187
@dusk_and_dawn2187 3 года назад
was awesome, cheers!
@eom-dev
@eom-dev 3 года назад
Glad you enjoyed it!
@alv1947
@alv1947 2 года назад
great job !!
@amit12000
@amit12000 2 года назад
Nice video
@rubenschulte1299
@rubenschulte1299 2 года назад
Nice Video Bro
@ahobbo6401
@ahobbo6401 2 года назад
Well done. Explained excellently.
@eom-dev
@eom-dev 2 года назад
Glad it was helpful!
@pascal831
@pascal831 Год назад
Thanks Brozeff!
@adhikarikalyan
@adhikarikalyan 3 года назад
Thanks Eric, this was helpful
@eom-dev
@eom-dev 3 года назад
You're welcome, glad it helped!
@codevars
@codevars 3 года назад
Thank you a lot for this.
@eom-dev
@eom-dev 3 года назад
You're very welcome!
@kmehour
@kmehour 9 месяцев назад
Thank you very much
@ngwilliam2534
@ngwilliam2534 3 года назад
Thank you Eric!
@eom-dev
@eom-dev 3 года назад
My pleasure!
@hasanshovon3402
@hasanshovon3402 Месяц назад
nice video
@rogerayalarojas4617
@rogerayalarojas4617 6 месяцев назад
Interesante. Gracias
@thetwogoats6851
@thetwogoats6851 2 года назад
thank you for the video
@drover7476
@drover7476 Год назад
oh my days thank you
@udemycourses-bq7uj
@udemycourses-bq7uj 7 месяцев назад
Thanks a lot
@olekristianmller-hansen4220
@olekristianmller-hansen4220 6 месяцев назад
Hi! Can I loop through files and import them at run time? I don't know which files to import beforehand.
@alexandarjelenic7718
@alexandarjelenic7718 2 года назад
5:25 is there another solution to copy and paste the resources? For example, i want to share common resources among many projects, and I dont want to have to maintain copies. Thank you!
@Airoupmusic
@Airoupmusic 9 месяцев назад
thank you fore share it
@indometalpython4969
@indometalpython4969 2 года назад
Thanks! Understood it well and clear. The naming __init__.py is by convention, right?
@constantfear
@constantfear 3 года назад
Great video thanks my dude
@eom-dev
@eom-dev 3 года назад
Thank you!
@kcvinu
@kcvinu Год назад
Is it possible to write conditional import statements in __init__.py ? i mean, If I have a package with 50 files and I want to use 10 among them in one case and in another case, I want to use 30 among them.
@user-lz6uz9rc8u
@user-lz6uz9rc8u 10 месяцев назад
thank you
@TomWelch-l5q
@TomWelch-l5q 19 часов назад
Thank you so much for this video! However, I was wondering if we could simply use "from resources import *" to avoid specifying which object we're trying to import? Thanks for your help!
@airatvaliullin8420
@airatvaliullin8420 Год назад
I think you can also write something like __add__ = ["object_one", "object_two"] inside of this __init__.py file.
@kalekber
@kalekber 3 года назад
That was straight up to the point. Can you make more vids on tricky parts of python? Some concepts might be challenging to wrap your head around, especially from someone coming from other languages.
@eom-dev
@eom-dev 3 года назад
Thank you, I try to make videos like these as the topic comes up in my daily workflow. If you point something out to me, though, I'd be happy to make a video on it.
@kalekber
@kalekber 3 года назад
​@@eom-dev I have some topics in mind. How to structure a python code since, I have noticed that untyped languages are not ideal for big projects. And another topic that would have been sweet is software development architecture styles. Those two topics always come up together.
@StefanoVerugi
@StefanoVerugi Год назад
The title of this video should be: "how to make a tutorial that lets you quickly learn something useful" 🙂
@user-nx8ux5ls7q
@user-nx8ux5ls7q 3 года назад
Thank you man!
@eom-dev
@eom-dev 3 года назад
Happy to help!
@user-nx8ux5ls7q
@user-nx8ux5ls7q 3 года назад
@@eom-dev I would like to see you making a video for argparse, struct, pack(), unpack(), toarray() and tobytes()
@boringsoftware2093
@boringsoftware2093 5 месяцев назад
thanks man that was excellent, also: for python2 empty __init__.py files work wonders X-D
@Ryder334455
@Ryder334455 Год назад
Ty
@toxxmoloi1873
@toxxmoloi1873 2 года назад
Now everything just makes sense 😁
@liamhuang2687
@liamhuang2687 2 года назад
Hi Eric, what if the modules you want to import are from a different directory (non-parental relationship)?
@theeox
@theeox Год назад
You would either create another _init__.py or move the files in such a way that you can call them. Think if the libraries as if they are in a file structure. As long as the Python_path has the folders in the parent path then you can call them. This is about not having to recall functions over and over again and being able to utilize one file to establish everything in a collective state.,
Далее
5 Tips To Organize Python Code
12:16
Просмотров 226 тыс.
Avoiding import loops in Python
10:21
Просмотров 92 тыс.
Китайка Шрек всех Сожрал😂😆
00:20
Это iPhone 16
00:52
Просмотров 522 тыс.
What is Python's Main Function Useful For?
8:08
Просмотров 75 тыс.
How to Build a Complete Python Package Step-by-Step
20:28
How Much FASTER Is Python 3.13 Without the GIL?
10:00
10 Nooby Mistakes Devs Often Make In Python
24:31
Просмотров 57 тыс.
If __name__ == "__main__" for Python Developers
8:47
Просмотров 392 тыс.
Python Tutorial: if __name__ == '__main__'
8:43
Просмотров 2 млн