+ 3

Why do we need to import in Python?

Why do we still need to import a module in Python if it's already part of it like using object methods in JavaScript where you can use it anytime without importing? I'm still new to Python so sorry for this stupid question.

15th Feb 2018, 6:18 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
6 Respuestas
+ 26
Because You Can Custom Your Own Stuff Not Like Building TLS Package again for some objects 😒 It's also better than ELF Executables like trying to write a code imports some binary file noooo just import a module up to 400kb and that's it except if you're talking about something like paramiko that takes an hour to be imported that library is very heavy also the modules can provide something by the developers so they made it to make it easier to use system calls or some other stuff like tell me do you want to write some 52kb of code to do this: parser.add_argument('-h','--hello',help='print hello')
15th Feb 2018, 10:54 PM
warlord
warlord - avatar
+ 7
Yes, several. It means that there is less to compile and run by default. Your program will load faster, because it only knows about the parts of Python that it actually needs. It keeps the global namespace clean, and allows functionality to be grouped logically into modules. Different modules can have identically-named functions without clashes (a file and socket class would probably both have open and close functions, for example). For more details: https://stackoverflow.com/questions/20306373/why-do-you-have-to-import-python-standard-library-functions
15th Feb 2018, 6:33 AM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
+ 5
I've given the link with title " For more details",try to understand brother 🤔
15th Feb 2018, 8:55 AM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
+ 5
Python is a dynamically typed language. Unlike statically typed languages like C++ and Java calls to methods aren't bound until they are actually executed, thus why importing the module were that method is defined is not necessary. This has several implications: 1. Methods (and data members) can be added to and removed from an instance at runtime, so two instances of class Foo can actually have different methods even though they are of the same type. 2. Methods (and data members) can be added to and removed from a class at runtime, which will impact all current instances as well as new instances. 3. Bases classes can be added and removed to a class at runtime.
15th Feb 2018, 9:26 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
+ 2
@ A Z M Mushfiqur Rahman, Thanks for the link. Now I'm getting it.👍 But you should indicate that you only copied the answer from Stackoverflow.
15th Feb 2018, 8:08 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 2
ok.
15th Feb 2018, 9:07 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar