Apr-01-2020, 05:42 PM
Hello
I am new to coding python and to this forum… If I do come with a NOOB question, please tell me..
My question is: what is the difference between import <a module> and from <a module> import *…
I am working at the console of IDLE running under windows 10.
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
If I type
Please note that I have this behaviour any time I start a new python shell via the icon… This is true for other module than os… I have the same effect with math…
Is "import <a module>" not often used in favour of "from <a module> import <what needed> ???
Thanks in advance.
I am new to coding python and to this forum… If I do come with a NOOB question, please tell me..
My question is: what is the difference between import <a module> and from <a module> import *…
I am working at the console of IDLE running under windows 10.
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
If I type
>>> import os >>> type(os) <class 'module'> >>> dir(os) ['DirEntry', 'F_OK', 'MutableMapping', <cut> , 'getcwd', <cut> >>> getcwd
Error:Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
getcwd
NameError: name 'getcwd' is not defined
>>> getcwd()
Error:Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
getcwd()
NameError: name 'getcwd' is not defined
Now, I use the other form of import…>>> from os import * >>> getcwd <built-in function getcwd> >>> getcwd() 'C:\\Program Files\\Python38'So either I do something wrong or there is a problem… I did some search and found this problem reported on GitHub… BUT it could not be reproduced…
Please note that I have this behaviour any time I start a new python shell via the icon… This is true for other module than os… I have the same effect with math…
Is "import <a module>" not often used in favour of "from <a module> import <what needed> ???
Thanks in advance.