RE: Are these tutorials the best tutorials for learning Python?
Hi Saurabh, those are good for ones to become proficient in writing Python Code. Regards, Sriram Srinivasan www.sriramsrinivasan.in -Original Message- From: Python-list [mailto:python-list-bounces+learning=sriramsrinivasan...@python.org] On Behalf Of Saurabh Hooda Sent: 09 August 2017 13:59 To: python-list@python.org Subject: Are these tutorials the best tutorials for learning Python? Hello, https://hackr.io/tutorials/learn-python proclaims that it's a collection of the best tutorials recommended by the programming community. Do you agree? Is there any better tutorial? Thanks in advance, Saurabh Hooda -- https://mail.python.org/mailman/listinfo/python-list --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -- https://mail.python.org/mailman/listinfo/python-list
Scrapy/XPath help
Hello all. I'm new to Python, but have been playing around with it for a few weeks now, following tutorials, etc. I've spun off on my own and am trying to do some basic web scraping. I've used Firebug/View XPath in Firefox for some help with the XPaths, however, I still am receiving errors when I try to run this script. If you could help, it would be greatly appreciated! from scrapy.spider import BaseSpider from scrapy.selector import HtmlXPathSelector from cbb_info.items import CbbInfoItem, Field class GameInfoSpider(BaseSpider): name = "game_info" allowed_domains = ["www.sbrforum.com"] start_urls = [ 'http://www.sbrforum.com/betting-odds/ncaa-basketball/', ] def parse(self, response): hxs = HtmlXPathSelector(response) toplevels = hxs.select("//div[@class='eventLine-value']") items = [] for toplevels in toplevels: item = CbbInfoItem() item ["teams"] = toplevels.select("/span[@class='team-name'/text()").extract() item ["lines"] = toplevels.select("/div[@rel='19']").extract() item.append(item) return items -- http://mail.python.org/mailman/listinfo/python-list
Re: Scrapy/XPath help
Sorry about that. I'm using Python 2.7.3, 32 bit one Windows 7. The errors I get are >>File >>"C:\python27\lib\site-packages\scrapy-0.16.3-py2.7.egg\scrapy\selector\lxmlsel.py", >> line 47, in select >>raise ValueError("Invalid XPath: %s" % xpath) >>exceptions.ValueError: Invalid XPath: /span[@class='team-name'/text() Ultimaly, I expect it to gather the team name in text, and then the odds in one of the columns in text as well, so I can then put it into a .csv -- http://mail.python.org/mailman/listinfo/python-list
a dummy python question
A example in learning Python by Mark Lutz and David Ascher about function scope example like this: >>def outer(x): def inner(i): print i, if i: inner(i-1) inner(x) >>outer(3) Here supposely, it should report error, because the function inner cannot see itself since inner is only in local namespace of outer. but I typed in this in python interface. It works! it print out: 3 2 1 0 If you turn this into a module file and run this it print out 3 2 1 0 none Can anyone explain to me what's going on? Thanks BTW: I am using Python 2.3 -- http://mail.python.org/mailman/listinfo/python-list
Re: a dummy python question
Thanks all for replying. I finally know what's going on. -- http://mail.python.org/mailman/listinfo/python-list
argument matching question
I know this is dummy, just never saw an example of this. I want to use the special argument matching. A code like this: def adder(**varargs): sum=varargs[varargs.keys()[0]] for next in varargs.keys()[1:]: sum=sum+varargs[next] return sum print adder( "first","second",'third') It pop up error like this: Traceback (most recent call last): File "learn.py", line 7, in ? print adder( "first","second",'third') TypeError: adder() takes exactly 0 arguments (3 given) How to pass arguments to a functions that use dictionary collection? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: argument matching question
thanks, got it. I want to test the **name option for argument matching. -- http://mail.python.org/mailman/listinfo/python-list
circular import problem
An example in the book I didn't understood well two modules files recursively import/from each other in recur1.py,we have: x=1 import recur2 y=1 in recur2.py, we have from recur1 import x from recur1 import y If we run interactively at python command line, >>> import recur1 it has errors like this: Traceback (most recent call last): File "", line 1, in ? File "recur1.py", line 2, in ? import recur2 File "recur2.py", line 2, in ? from recur1 import y ImportError: cannot import name y I understood this because recur1 is not finished when recur2 is trying to import y. However, if you run interactive for recur2.py interactively, it is fine. when you run as script from command line, recur1.py is fine. but when you python recur2.py at commmand line, it has errors like this: Traceback (most recent call last): File "recur2.py", line 1, in ? from recur1 import x File "recur1.py", line 2, in ? import recur2 File "recur2.py", line 2, in ? from recur1 import y ImportError: cannot import name y What's really the problem here? Thanks -- http://mail.python.org/mailman/listinfo/python-list
intermediate python csv reader/writer question from a beginner
anything related to csv, I usually use VB within excel to manipulate the data, nonetheless, i finally got the courage to take a dive into python. i have viewed a lot of googled csv tutorials, but none of them address everything i need. Nonetheless, I was wondering if someone can help me manipulate the sample csv (sample.csv) I have generated: ,, someinfo,,, somotherinfo,,, SEQ,Names,Test1,Test2,Date,Time,, 1,Adam,1,2,Monday,1:00 PM,, 2,Bob,3,4,Monday,1:00 PM,, 3,Charlie,5,6,Monday,1:00 PM,, 4,Adam,7,8,Monday,2:00 PM,, 5,Bob,9,10,Monday,2:00 PM,, 6,Charlie,11,12,Monday,2:00 PM,, 7,Adam,13,14,Tuesday,1:00 PM,, 8,Bob,15,16,Tuesday,1:00 PM,, 9,Charlie,17,18,Tuesday,1:00 PM,, into (newfile.csv): Adam-Test1,Adam-Test2,Bob-Test1,Bob-Test2,Charlie-Test1,Charlie- Test2,Date,Time 1,2,3,4,5,6,Monday,1:00 PM 7,8,9,10,11,12,Monday,2:00 PM 13,14,15,16,17,18,Tuesday,1:00 PM note: 1. the true header doesn't start line 4 (if this is the case would i have to use "split"?) 2. if there were SEQ#10-12, or 13-15, it would still be Adam, Bob, Charlie, but with different Test1/Test2/Date/Time -- http://mail.python.org/mailman/listinfo/python-list