Issue
I am currently facing really weird issues, I tried almost everything and still not able to figure out why this is happening.
I am trying to import tornado in one of my python script however I am not able to see all the available classes while importing.
import tornado, sys
print(dir(tornado))
outputs:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'version', 'version_info']
I tried locating the "\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\tornado" and it exists. All the files under package tornado are there in site-packages/tornado folder. For me it means my package is installed properly, I checked the python path with
print(sys.path)
And the site-packages directory is available under python path. I don't know what I am missing here. I am on Windows 10, using python 3.8
I have added images below.
img:cmd prompt img:explorer - site-packages folder
Solution
tornado is the main package containing all the information. If you want to access the classes and subclasses, you will have to import them individually.
For example, if you wanted to access the web class, you would have do import it as such:
import tornado.web
And then reference subclasses as:
tornado.web.[subclass]
This is also the same with other big python packages, such as selenium, where just running import selenium will only get you the package information, but importing using import selenium.[subclass] grants you access to the subclass
Try seeing the Example code for more information.
Answered By - Frederick Reynolds Answer Checked By - David Goodson (Python.Easybugfix Volunteer)
Post a Comment
Post a Comment