Importing Your Own Python Modules Properly

  Рет қаралды 245,372

NeuralNine

NeuralNine

Күн бұрын

Пікірлер
@robbiefryers13
@robbiefryers13 2 жыл бұрын
You're confusing the term module with what is actually a package in python. Any file with a py extension is a 'module' in python. A collection of py files in a directory along with an __init__ file is a package, not a module
@PavitraGolchha
@PavitraGolchha Жыл бұрын
It's actually python which made this confusing. JS ESM is so simple
@raenastra
@raenastra Жыл бұрын
@@PavitraGolchha JS imports may not be the best example of simplicity, due to the competing standards, but I get what you mean
@BooklyCrashCourse
@BooklyCrashCourse 8 ай бұрын
It is kind of confusing. Also a package can be comprised of packages.
@bloodywolftr
@bloodywolftr 2 жыл бұрын
I was looking for init usage and most of the tutorials in the wild were showing importing files just from next to the main python file.Now this is useful.Thanks.
@somecallmetimelderberries432
@somecallmetimelderberries432 Жыл бұрын
Nice explanation, best one yet I've seen on modules!
@kaushiksinghrawat
@kaushiksinghrawat Жыл бұрын
Was stuck on this for almost two days with most solutions on stack overflow and chatgpt suggesting to use absolute paths, instead of this type of relative pathing to import stuff. Finally managed to understand it 😆
@Ridwan-vb8nm
@Ridwan-vb8nm 5 ай бұрын
yeah if you want to do "real work," chatGPT just crashes.
@terryjophlin
@terryjophlin 3 ай бұрын
​@@Ridwan-vb8nmI am amazing at debugging because I used ChatGPT to learn to code. I really don't recommend it.
@subi_rocks
@subi_rocks 2 жыл бұрын
What if I want to import fourth.py inside second.py and then call second.py from main.py?
@CattleRustlerOCN
@CattleRustlerOCN 10 ай бұрын
In second.py Import Fourth, in main Import Second maybe 😊
@aceldama
@aceldama 2 жыл бұрын
nice. only thing i'd add is that you can import from a parent directory using .., so it would read "from ..parent_directory import y"
@authentic_101
@authentic_101 7 ай бұрын
But this hasn't worked for me so far. Getting an error citing something about "unspecified parent package"
@aceldama
@aceldama 7 ай бұрын
@authentic_101 there are a few rules you need to stick to. Every directory you import from must have an __init__.py file, for example.
@authentic_101
@authentic_101 7 ай бұрын
@@aceldama this I tried actually
@felixmerz00
@felixmerz00 4 ай бұрын
Unfortunately, this doesn't work for me either.
@siddhubhai2508
@siddhubhai2508 4 ай бұрын
Your explaination is soooooo cooooool like your intro! Your explaination made me your fan only in one video, ultra cool bro! I'm glad you have a youtube channel so that I can learn from you!
@sirsquirrel0
@sirsquirrel0 Жыл бұрын
Thanks for the video and making the effort. I found it quite difficult to see which files you were editing with the editor. I have rewatched a few times, but its blowing my mind.
@DokterTonga
@DokterTonga Жыл бұрын
I had the same. The file he is editing is named below (bottom)
@Cordic45
@Cordic45 2 жыл бұрын
what does . mean at 8:31?
@MrCipek1221
@MrCipek1221 2 жыл бұрын
Thank you! :) I always learn something new with your videos :D Please keep it up!! Very well done :)
@ninavanleeuwen1183
@ninavanleeuwen1183 8 ай бұрын
THIS!! This is exactly what i have been looking for! Thank you so much
@philipp4980
@philipp4980 2 жыл бұрын
Is that also possible to import the modules without the "from..."? E.g. with "import functionality" and call the functions with "functionality.add()". In comparison when I import the "math" module I use that method and can call "math.pi" afterwards.
@amiralizadeh6621
@amiralizadeh6621 2 жыл бұрын
what if our module is in another directory? should we amend the system path?
@benjaminnelson5455
@benjaminnelson5455 2 ай бұрын
This is what I came here hoping to learn. I just spent 2 days dealing with all manner of issues with namespacing in an ultimately vain attempt to keep the test coverage in a discrete folder from the production code.
@Lefthandup
@Lefthandup 2 жыл бұрын
Is there a library I can import that will allow me to read in user input without them having to press enter? Like for a WPM tester for example to see if they had a typo
@mables8698
@mables8698 2 жыл бұрын
Yes, but which one depends on your project. For a typing tester in the console you can check out this video from Tech with Tim: kzbin.info/www/bejne/hIKYmmShf6Z0bLs Also, you could create something with pygame, which checks continually for input.
@Lefthandup
@Lefthandup 2 жыл бұрын
@@mables8698 wow this is exactly what I was trying to do thx
@jameswilliams-nw3lq
@jameswilliams-nw3lq Жыл бұрын
Thank you SO much. This was a difficult concept for me to grasp but so helpful. Your awesome
@saurabh7489
@saurabh7489 Жыл бұрын
Thank You Sir. You went into great length to explain this concept.
@404errorpagenotfound.6
@404errorpagenotfound.6 2 жыл бұрын
Please do a video on different IDE's, pros, cons etc. Thanks for your great comment.
@Lefthandup
@Lefthandup 2 жыл бұрын
I can recommend pycharm for python and blueJay for Java
@404errorpagenotfound.6
@404errorpagenotfound.6 2 жыл бұрын
@@Lefthandup but more people especially on YT are using VS Code.
@stwni
@stwni 2 жыл бұрын
@@404errorpagenotfound.6 Vscode isn't really an IDE it's a text editor
@404errorpagenotfound.6
@404errorpagenotfound.6 2 жыл бұрын
@@stwni what does an IDE do that VS doesn't? It's incredibly popular with YT programmers teaching coding.
@Lefthandup
@Lefthandup 2 жыл бұрын
@@404errorpagenotfound.6 I’m pretty sure an ide has the advantage of using other peoples libraries etc.
@Person-hb3dv
@Person-hb3dv Жыл бұрын
you saved me a lot of time with this video. thank you. earned my sub
@patrikpatrik8421
@patrikpatrik8421 Жыл бұрын
Quick and simple explanation thank you !
@DJaycerOfficial
@DJaycerOfficial Жыл бұрын
Making a text based rpg, and really needed a way for stats of enemies to be imported properly. I try not to use videos unless I’m A. Learning something or B. Completely lost and have no idea of the full concept of something.
@pabloalonso9083
@pabloalonso9083 23 күн бұрын
One video like this but explaining shared variables between modules I think would be perfect !!
@stevenhoang7297
@stevenhoang7297 Жыл бұрын
what's your vim setup 👉👈
@soklagenhet
@soklagenhet Жыл бұрын
Great, but you really tend not to use the star * import, it's generally bad practice as it bloats your namespace with potentially unwanted modules
@royw2
@royw2 4 ай бұрын
Small programs with a single developer may be able to get away with wildcard imports. In any serious program wildcard imports can introduce hard to find bugs when multiple packages just happen to have the same module name so import order determines which module is actually imported. This is why wildcard imports are a code smell and in truth, just evil. Modern IDEs facilitate explicitly importing the module you want. Please, please get in the habit of avoiding wildcard imports.
@bobjohnson3427
@bobjohnson3427 7 ай бұрын
Thanks, that clears up several of my problems that other resiurces weren't helping me resolve. I also have a couple of self-made modules that I use in multiple projects. Do you have any tips for how to access them using the environmentsl vafuable PATH or PYTHONPATH?
@donjackson3520
@donjackson3520 Жыл бұрын
Excellent video! I’m new to python and this is a big help
@canozer1954
@canozer1954 Жыл бұрын
When i try to run my code which is 2 python file inside a folder with all import rules, i am facing __pycache__ and code does not running. I cannot get input some print ext. How can i fix this.
@hovh03
@hovh03 11 ай бұрын
thanks you for very clear explanation. What about a source module downloaded from github and build by me? It is in a different location, not sub directory.
@supermankelly
@supermankelly 7 ай бұрын
What if the module file is not under the project folder. How do you define a totally different path?
@swifttech7853
@swifttech7853 2 жыл бұрын
BROTHER, YOU ARE THE BEST!!! You oooh really helped me!! THANK YOU VERY MUCH!
@H4KnSL4K
@H4KnSL4K Жыл бұрын
Thanks for the video. I recommend some daily careful typing practice, btw - so you don't need to constantly correct your typing
@Dinco422
@Dinco422 Жыл бұрын
As a noob, I've watched this and still have no idea how to add modules, thanks.
@stephen285
@stephen285 Жыл бұрын
fyi ~ this did not work for me, yes I had my functions file in the same directory as my blend file, but still I had to add the explicit path as follows, then it worked as shown in video import bpy import system sys.path.append('E:\content\working\latest') from func import testfunc
@jakobmatt8632
@jakobmatt8632 Жыл бұрын
Im having trouble with this using gRPC I'm importing with from gRPC.python import * I have an __init__.py in the python directory do I somehow also need one in the gRPC directory which is the parent?.
@sahilgarg94
@sahilgarg94 2 жыл бұрын
Thank you very much sir .... This was badly needed...
@salarghaffarian4914
@salarghaffarian4914 Жыл бұрын
Really informative video. Thanks for recording and sharing it.
@austinmoody4719
@austinmoody4719 Жыл бұрын
any idea why my vs code isnt importing files from the same directory?
@MrJet84
@MrJet84 Жыл бұрын
Thank you for lesson. But how import from upper module to lower?
@Tom-JS
@Tom-JS Жыл бұрын
When the teacher says add every number from to 100 instead of doing this 1 +2+3 Of a text editor and type this total = 0 for num in range(101): total = num + total print(total) It will print the correct answer 5050
@rizaldicakra826
@rizaldicakra826 Жыл бұрын
It works. Thank you, really help my project :)
@stormbytes
@stormbytes 2 жыл бұрын
Really cool video and explained very clearly. What about making a video on packaging modules for sharing?
@reviii-s4t
@reviii-s4t 2 жыл бұрын
Thank you so much for this, very clear explanation.
@YoubiTheGreat
@YoubiTheGreat Жыл бұрын
I'm using VS Code. I followed pretty well until I got to __all__ = ["second", "third"]. second and third are grizzled underscored with a message ""second" is specified in __all__ but is not present in module Pylance".I'm still searching for a way to make it work. Note : from othermodule import *, second.myfunction() works and I get an Hello anyway but I still don't know why it works if I get errors in my code. Just to add. When I added the from .second import myfunction, from .third import another_function in the init file, under __all__ line, those errors are gone. Thanks for the video, it helps a lot.
@vinayakpandey6299
@vinayakpandey6299 Жыл бұрын
very nice explanation. understood everything very clearly
@paulohsgoes1959
@paulohsgoes1959 2 жыл бұрын
Excelent job! Congrats
@matteodelgrosso4364
@matteodelgrosso4364 Жыл бұрын
The terms module and package are mixed up! A module is a python file. A package is a collection of python modules!
@katlegophele8909
@katlegophele8909 Жыл бұрын
Tutorial on how to setup the environment like yours please
@xiupingli2892
@xiupingli2892 6 ай бұрын
I tried to import my own module that uses pandas or yahoo finance. but it did not work. How can i solve it
@dragnar4743
@dragnar4743 8 ай бұрын
Dude, the practical explanation was very good. In fact, on of the best on yt. But, I think you should have termed the directory containing all those modules as Package. Because, most of the beginners get little confused with term module, package and library. otherwise.... 👍👍
@MagnusAnand
@MagnusAnand 2 жыл бұрын
But why use * in the first place? It's supposed to be an antipattern because of namespacing issues.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
Absolutely, yes. Avoid wildcard imports.
@kcvinu
@kcvinu 2 жыл бұрын
Learned a new thing. "__all__". Thanks a lot.
@scottielin1076
@scottielin1076 Жыл бұрын
Very clear explanation Thanks 🎉
@AhmedThahir2002
@AhmedThahir2002 2 жыл бұрын
According to pyinstaller's official documentation " It is not a cross-compiler - to make a Windows app you run PyInstaller on Windows - to make a Linux app you run it on Linux, etc " Any workaround this?
@anurasenarathna1703
@anurasenarathna1703 Жыл бұрын
Very informative. Thank you very much.
@earthchan568
@earthchan568 Жыл бұрын
thank man u saved my so much time
@szenghoe
@szenghoe 2 жыл бұрын
why we dont have to declare submodule in the init file?
@amit12000
@amit12000 Жыл бұрын
how use linting in neovim using pylint and how to avoid import error
@iloloey
@iloloey 9 ай бұрын
Fantastic explanation.
@JamesThiering
@JamesThiering 2 жыл бұрын
Thanks for the helpful video!
@eton9931
@eton9931 Жыл бұрын
Wow, that was actually pretty easy Thanks you sir
@krystiansawicki4985
@krystiansawicki4985 9 ай бұрын
Thank you this helped me a lot
@bla7091
@bla7091 Жыл бұрын
Good stuff! I did notice that if I package everything into a wheel, without adding the classes to the __init__.py I was getting ModuleNotFound errors whenever I used submodules from the package.
@akshatsharmasre
@akshatsharmasre Жыл бұрын
Does this work if the folders are in git repo?
@ShadyNetworker
@ShadyNetworker Жыл бұрын
Yooo, what is this terminal program and setup, it looks sexy. Thanks for the video!
@ChristopherBruns-o7o
@ChristopherBruns-o7o 5 ай бұрын
this combined with if __name__ == "__main__": would have been the best youtube in history.
@ranknwarjitsinghdhaliwal9856
@ranknwarjitsinghdhaliwal9856 Жыл бұрын
what ui is this??? sorry, new to this
@Cordic45
@Cordic45 2 жыл бұрын
what is this test editor name?
@tejasnirantar
@tejasnirantar Жыл бұрын
thx for this, really helpful
@redlight8752
@redlight8752 8 ай бұрын
Thanks bro, much love
@tehreemakhtar8652
@tehreemakhtar8652 Жыл бұрын
Impressive. To the point content
@tanto_id
@tanto_id 2 жыл бұрын
Thank you, you explained very clearly
@petereziagor4604
@petereziagor4604 2 жыл бұрын
Nice video, I have to learn to use vim like you
@danielpartyhead2234
@danielpartyhead2234 Жыл бұрын
all good. but it dont see import pandas as pd in function :(
@tki967
@tki967 2 жыл бұрын
can you please put module and code(main) at different folder and access module from code
@GuillermoGarcia75
@GuillermoGarcia75 7 ай бұрын
GOING Awesome!! Still great!!
@BeeryDorin
@BeeryDorin 2 жыл бұрын
thanks a lot, solved many problems.
@ahmadov01
@ahmadov01 2 жыл бұрын
What is this ide name ? Is it vim ? May you send config ?
@mathsfun4097
@mathsfun4097 6 ай бұрын
I was import error like they can't be imported from my module
@timshort9787
@timshort9787 2 жыл бұрын
Please make a tutorial on how you set up your neovim environment
@NeuralNine
@NeuralNine 2 жыл бұрын
I have two already
@yashasvimantha6012
@yashasvimantha6012 2 жыл бұрын
You didn't talk about having the module not in the same directory and using it.
@hecker5563
@hecker5563 10 ай бұрын
Nice tutor!
@sweetshoez
@sweetshoez Жыл бұрын
To the point, thanks!
@tsvasekar
@tsvasekar 2 жыл бұрын
Needed exactly this. Trying to add a pre built library to a system where I can't use pip, or setupmodule. I hope this will work.
@manfrombritain6816
@manfrombritain6816 Жыл бұрын
most of the time i love python but there's something about the way we do this stuff that really does not compute in my head. the file structure of flask apps in general just doesn't work in my head... i find JS frameworks much more simpler to grasp for god's sake
@zakaryreilly
@zakaryreilly 10 ай бұрын
Not clear on package/module/sub-module terminology. A bit confusing.
@tomatte99
@tomatte99 5 ай бұрын
you are just amazing
@RazanIbrahimOmerMohamed
@RazanIbrahimOmerMohamed Жыл бұрын
Thanks bro!
@nishantgarg3688
@nishantgarg3688 2 жыл бұрын
thanks bhai
@leonidgrishenkov
@leonidgrishenkov 2 жыл бұрын
Thanks a lot!
@arcanelore168
@arcanelore168 11 ай бұрын
I use neovim on KDE Plasma!
@portal_it_id
@portal_it_id 9 ай бұрын
Well explained!
@10MinuteTutorials15
@10MinuteTutorials15 Жыл бұрын
Thx so much
@joaocanteiro4655
@joaocanteiro4655 Ай бұрын
Good info the topic is not well explained in other places even the manual i found was confusing
@javad-q7w
@javad-q7w Жыл бұрын
very useful
@caribbeanchild
@caribbeanchild 10 ай бұрын
You should have done this in Blender. This is no help at all. You keep saying "don't be confused". Well... you did this in a confusing manner.
@cybern9ne
@cybern9ne 6 ай бұрын
Naming everything with the same name and leaving code not used made this very confusing.
@kevintanudjaja7597
@kevintanudjaja7597 8 ай бұрын
ah.. why not cover sibling module..
@psi4588
@psi4588 Жыл бұрын
amazing!!
@purpplleyt
@purpplleyt 2 жыл бұрын
Love you bro
@abba6104
@abba6104 Жыл бұрын
Honestly it was a bit hard to follow due to the strange IDE or whatever. Pretty good tutorial I suppose but presentation was a bit unclear.
@Anonymous-ri4mk
@Anonymous-ri4mk Жыл бұрын
I am not gonna lie sometimes I get lose in the middle of my code and get confused
@AbubakarNaveedMinhas
@AbubakarNaveedMinhas Жыл бұрын
Thanks
Python Modules for Beginners
18:03
Dave Gray
Рет қаралды 12 М.
Wheel Files: Packaging Python Applications & Modules
21:10
NeuralNine
Рет қаралды 26 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Authorization in Next.js is Easy! (RBAC)
36:15
Jan Marshal
Рет қаралды 2,6 М.
10 Python Comprehensions You SHOULD Be Using
21:35
Tech With Tim
Рет қаралды 161 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 819 М.
Make Your Python Code More Professional
19:43
NeuralNine
Рет қаралды 68 М.
5 Tips To Organize Python Code
12:16
Tech With Tim
Рет қаралды 251 М.
5 Custom Python Decorators For Your Projects
25:40
NeuralNine
Рет қаралды 9 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 660 М.
2,000 People Fight For $5,000,000
24:45
MrBeast
Рет қаралды 37 МЛН
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 407 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН