Home > other >  Pycharm import module error
Pycharm import module error

Time:10-01

This is the code


The from urllib import request
The file=urllib. Request. Urlopen (" http://www.baidu.com ")
A=file. The read ()

With the open (' baidu. HTML, "w") as file_ob:
File_ob. Write (STR) (a)


This is an error:

CodePudding user response:

How to still use urllib
Requests is bad to use

CodePudding user response:

Or the file, I am a hellowirld program error, the same error is how to return a responsibility

CodePudding user response:

Did you use the from urllib import request, then all is the request of package method, for the present you this question, there are two solution
1, put the from urllib import request to import urllib can
2, put the file=urllib. Request. Urlopen (" http://www.baidu.com ") instead of the file=request. Urlopen (" http://www.baidu.com ")
You have to understand
The from packagename import packageone at this moment you can only use all of the packages as well as its own packageone method
The from packagename import * then you can use all the method under the packagename, but when using the front can't add packaname. Way to use, can only use the method name directly
Import packaname when must use packagebane. Way to use the
For example:
1, from the time the import sleep by this time you can only use the only sleep in time module and its methods, such as sleep (3), suspended for 3 seconds, directly using the
2, the import time can use time any package at this moment, how time. Sleep (3), suspended for 3 seconds, time, time (), get the current time float type timestamp, pay attention to and the different. You must use the time is the time to use the way to reference
3, from the time at this time of the import * and 2 methods are similar, but using the front can't add time. The mistakes you make the above is
  • Related