Re: [Tutor] urllib ... lost novice's question
On 10/05/17 17:06, Rafael Knuth wrote: >>> Then, there is another package, along with a dozen other >>> urllib-related packages (such as aiourllib). >> >> Again, where are you finding these? They are not in >> the standard library. Have you been installing other >> packages that may have their own versions maybe? > > they are all available via PyCharm EDU It looks like PyCharm may be adding extra packages to the standard library. Thats OK, both ActiveState and Anaconda (and others) do the same, but it does mean you need to check on python.org to see what is and what isn't "approved". If it's not official content then you need to ask on a PyCharm forum about the preferred choices. The fact they are included suggests that somebody has tested them and found them useful in some way, but you would need to ask them why they chose those packages and when they would be more suitable than the standard versions. These bonus packages are often seen as a valuable extra, but they do carry a burden of responsibility for the user to identify which is best for them, and that's not always easy to assess, especially for a beginner. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib ... lost novice's question
>> Then, there is another package, along with a dozen other >> urllib-related packages (such as aiourllib). > > Again, where are you finding these? They are not in > the standard library. Have you been installing other > packages that may have their own versions maybe? they are all available via PyCharm EDU ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib ... lost novice's question
this is one of those things where if what you want is simple, they're all usable, and easy. if not, some are frankly horrid. requests is the current hot module. go ahead and try it. (urllib.request is not from requests, it's from urllib) On May 8, 2017 9:23:15 AM MDT, Rafael Knuthwrote: >Which package should I use to fetch and open an URL? >I am using Python 3.5 and there are presently 4 versions: > >urllib2 >urllib3 >urllib4 >urllib5 > >Common sense is telling me to use the latest version. >Not sure if my common sense is fooling me here though ;-) > >Then, there is another package, along with a dozen other >urllib-related packages (such as aiourllib). I thought this one is >doing what I need: > >urllib.request > >The latter I found on http://docs.python-requests.org along with these >encouraging words: > >"Warning: Recreational use of the Python standard library for HTTP may >result in dangerous side-effects, including: security vulnerabilities, >verbose code, reinventing the wheel, constantly reading documentation, >depression, headaches, or even death." > >How do I know where to find the right package - on python.org or >elsewhere? >I found some code samples that show how to use urllib.request, now I >am trying to understand why I should use urllib.request. >Would it be also doable to do requests using urllib5 or any other >version? Like 2 or 3? Just trying to understand. > >I am lost here. Feeback appreciated. Thank you! > >BTW, here's some (working) exemplary code I have been using for >educational purposes: > >import urllib.request >from bs4 import BeautifulSoup > >theurl = "https://twitter.com/rafaelknuth; >thepage = urllib.request.urlopen(theurl) >soup = BeautifulSoup(thepage, "html.parser") > >print(soup.title.text) > >i = 1 >for tweets in soup.findAll("div",{"class":"content"}): >print(i) >print(tweets.find("p").text) >i = i + 1 > >I am assuming there are different solutions for fetching and open URLs? >Or is the above the only viable solution? >___ >Tutor maillist - Tutor@python.org >To unsubscribe or change subscription options: >https://mail.python.org/mailman/listinfo/tutor -- Sent from my Android device with K-9 Mail. Please excuse my brevity. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib ... lost novice's question
As a side note see a tutorial on urllib and requests and try them at the same time see for python 3.x; 3.4 or 3.6 also see the data type received by the different combinations, when you should use .read() etc also use utf-8 or unicode like .decode("utf8") Well play around fool mess with it, feel free as when you'll do serious stuffs you won't need to test to know what should be done or not, what breaks it or not. summary : learn it well from the begining Finding the right package. Hum either in your beginner learning path you learn popular third party modules or You find how the people round the net did what you are doing, see how they did it and what modules they used or google "module " or browse pypi or _long term_ never stop reading about python. so you'll constantly discover new things and reduce the probability of you not knowing how to do something. Hope it helps, Abdur-Rahmaan Janhangeer Vacoas, Mauritius https://abdurrahmaanjanhangeer.wordpress.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib ... lost novice's question
On 08/05/17 16:23, Rafael Knuth wrote: > Which package should I use to fetch and open an URL? > I am using Python 3.5 and there are presently 4 versions: > > urllib2 > urllib3 > urllib4 > urllib5 I don't know where you are getting those from but the standard install of Python v3.6 only has urllib. This is a package with various modules inside. ISTR there was a urllib2 in Python 2 for a while but I've never heard of any 3,4, or 5. > Then, there is another package, along with a dozen other > urllib-related packages (such as aiourllib). Again, where are you finding these? They are not in the standard library. Have you been installing other packages that may have their own versions maybe? > urllib.request > > The latter I found on http://docs.python-requests.org along with these > encouraging words: > > "Warning: Recreational use of the Python standard library for HTTP may > result in dangerous side-effects, including: security vulnerabilities, > verbose code, reinventing the wheel, constantly reading documentation, > depression, headaches, or even death." That's true of almost any package used badly. Remember that this is "marketing" propaganda from an alternative package maintainer. And while most folks (including me)seem to agree that Requests is easier to use than the standard library, the standard library version works just fine if you take sensible care. > How do I know where to find the right package There is no right package, just the one you find most effective. Most folks would say that Requests is easier to use than the standard library, if you are doing anything non-trivial I'd second that opinion. > I found some code samples that show how to use urllib.request, now I > am trying to understand why I should use urllib.request. Because as part of the standard library you can be sure it will be thee, whereas Requests is a third party module that needs to be downloaded/installed and therefore may not be present (or even allowed by the server admins) Or maybe because you found some old code written before Requests became popular and you need to integrate with it or reuse it. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] urllib ... lost novice's question
Which package should I use to fetch and open an URL? I am using Python 3.5 and there are presently 4 versions: urllib2 urllib3 urllib4 urllib5 Common sense is telling me to use the latest version. Not sure if my common sense is fooling me here though ;-) Then, there is another package, along with a dozen other urllib-related packages (such as aiourllib). I thought this one is doing what I need: urllib.request The latter I found on http://docs.python-requests.org along with these encouraging words: "Warning: Recreational use of the Python standard library for HTTP may result in dangerous side-effects, including: security vulnerabilities, verbose code, reinventing the wheel, constantly reading documentation, depression, headaches, or even death." How do I know where to find the right package - on python.org or elsewhere? I found some code samples that show how to use urllib.request, now I am trying to understand why I should use urllib.request. Would it be also doable to do requests using urllib5 or any other version? Like 2 or 3? Just trying to understand. I am lost here. Feeback appreciated. Thank you! BTW, here's some (working) exemplary code I have been using for educational purposes: import urllib.request from bs4 import BeautifulSoup theurl = "https://twitter.com/rafaelknuth; thepage = urllib.request.urlopen(theurl) soup = BeautifulSoup(thepage, "html.parser") print(soup.title.text) i = 1 for tweets in soup.findAll("div",{"class":"content"}): print(i) print(tweets.find("p").text) i = i + 1 I am assuming there are different solutions for fetching and open URLs? Or is the above the only viable solution? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor