|
Python code:
|
# ? Apr 5, 2015 02:09 |
|
|
# ? May 9, 2024 11:32 |
The book I'm going through at the moment says that _ should return last output obtained. I reconstruct their example:Python code:
|
|
# ? Apr 5, 2015 17:35 |
|
kalstrams posted:The book I'm going through at the moment says that _ should return last output obtained. I reconstruct their example: Can you post exactly what you're doing?
|
# ? Apr 5, 2015 17:45 |
|
kalstrams posted:The book I'm going through at the moment says that _ should return last output obtained. I reconstruct their example: The _ variable contains the return value of the last python function call you made. run isn't a python function, it's an ipython command that doesn't return anything. Look in ball1.py, I'm betting it's just printing that number out, which isn't the same as returning it.
|
# ? Apr 5, 2015 17:53 |
EAT THE EGGS RICOLA posted:Can you post exactly what you're doing? ball1.py Python code:
Edit: good jovi posted:Look in ball1.py, I'm betting it's just printing that number out, which isn't the same as returning it. Python code:
Python code:
Python code:
cinci zoo sniper fucked around with this message at 18:04 on Apr 5, 2015 |
|
# ? Apr 5, 2015 17:58 |
|
Either the book's wrong or you're misunderstanding it. Underscore contains the value of the last expression whose return was not assigned to a variable name. Print and run do not return anything, so they do not populate the underscore. Neither do any lines with an assignment (=).
|
# ? Apr 5, 2015 18:45 |
SurgicalOntologist posted:Either the book's wrong or you're misunderstanding it. Underscore contains the value of the last expression whose return was not assigned to a variable name. Print and run do not return anything, so they do not populate the underscore. Neither do any lines with an assignment (=).
|
|
# ? Apr 5, 2015 18:49 |
|
kalstrams posted:Maybe that's how it is intended to work, but then I have to wonder how the gently caress did guys in book get it done. with their code being: Open up a python console and type this: Python code:
|
# ? Apr 5, 2015 19:00 |
EAT THE EGGS RICOLA posted:Open up a python console and type this:
|
|
# ? Apr 5, 2015 19:27 |
|
Hey dudes, having an issue with Pypi. I'm following this tutorial. I registered and activated accounts on pypi and pypi test. .pypirc code:
Python code:
code:
code:
code:
code:
Dominoes fucked around with this message at 20:28 on Apr 6, 2015 |
# ? Apr 6, 2015 16:55 |
|
Is there some peculiar reason why somebody might want to explicitly pass self into an instance method rather than call it from self directly? I can't imagine what's going on. I'm reading some code from somebody I initially was giving a lot of slack since he was generally doing decent software engineering conceptually. However, bells started to go off when I saw some Systems Hungarian Notation.
|
# ? Apr 6, 2015 16:58 |
|
Rocko Bonaparte posted:Is there some peculiar reason why somebody might want to explicitly pass self into an instance method rather than call it from self directly? I can't imagine what's going on. I'm reading some code from somebody I initially was giving a lot of slack since he was generally doing decent software engineering conceptually. However, bells started to go off when I saw some Systems Hungarian Notation. You mean as an other argument other than the standard self? Python code:
|
# ? Apr 6, 2015 17:29 |
|
Any reason alembic's autogenerate won't pick up a named UniqueConstraint added to a table? The table is a subclass of a parent table via joined table inheritance if that makes a difference.
|
# ? Apr 6, 2015 19:29 |
|
Rocko Bonaparte posted:Is there some peculiar reason why somebody might want to explicitly pass self into an instance method rather than call it from self directly? I can't imagine what's going on. I'm reading some code from somebody I initially was giving a lot of slack since he was generally doing decent software engineering conceptually. However, bells started to go off when I saw some Systems Hungarian Notation. If the method is being called on a superclass I guess?
|
# ? Apr 6, 2015 20:12 |
|
I'm trying to learn how to scrape websites for useful information. For this, I was thinking I could scrape the local minor league baseball team's schedule for this year. I've found two websites that display their schedule, and they both seem to heavily use java script: http://www.milb.com/schedule/index.jsp?sid=t4124 http://www.milb.com/milb/stats/stats.jsp?t=t_sch&cid=4124&sid=t4124&stn=true Some google searches have pointed me towards using a combination of selenium and BeautifulSoup but I'm not having too much luck getting anything meaningful out of it. Python code:
|
# ? Apr 7, 2015 05:56 |
|
Hughmoris posted:I'm trying to learn how to scrape websites for useful information. For this, I was thinking I could scrape the local minor league baseball team's schedule for this year. I've found two websites that display their schedule, and they both seem to heavily use java script:
|
# ? Apr 7, 2015 07:16 |
|
Dominoes posted:Have you considered Regex? Are you serious? I hope you are not. Hughmoris: I would have suggested beautifulsoup.
|
# ? Apr 7, 2015 10:30 |
|
Dominoes posted:Have you considered Regex? http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags This should tell you everything you need to know about constructing regex html consumers. tl;dr ALL IS LOST the pony he comes. Seconding beautifulsoup. Selenium can be handy for some things (Like trying to parse the insane mess facebook shits into your browser) but its brittle as hell, and frankly not as flexible. At my old job we spidered about 500 different travel agents on a small cluster running stackless python greenlets (This was back in the mid 2000s) and beautifulsoup. Writing scrapers is never fun, writing LOTS of scrapers especially so. But bs takes the pain out of a lot of it. duck monster fucked around with this message at 14:27 on Apr 7, 2015 |
# ? Apr 7, 2015 14:24 |
|
Hughmoris posted:I'm trying to learn how to scrape websites for useful information. For this, I was thinking I could scrape the local minor league baseball team's schedule for this year. I've found two websites that display their schedule, and they both seem to heavily use java script: I use LXML to parse rather than BeautifulSoup, so you''ll need to translate the syntax of the below: Python code:
onionradish fucked around with this message at 15:12 on Apr 7, 2015 |
# ? Apr 7, 2015 14:43 |
|
BeautifulSoup uses lxml (and other parsers) under the hood so the only reason not to use it is if you really hate its API and know that your other favorite parser is perfectly capable of handling whatever you happen to throw at it.
|
# ? Apr 7, 2015 16:05 |
|
Munkeymon posted:BeautifulSoup uses lxml (and other parsers) under the hood so the only reason not to use it is if you really hate its API and know that your other favorite parser is perfectly capable of handling whatever you happen to throw at it.
|
# ? Apr 7, 2015 16:49 |
|
I think everyone missed your joke, Dominoes!
|
# ? Apr 7, 2015 16:51 |
|
onionradish posted:True. I didn't mean I used LXML "rather than" BeautifulSoup to be . That was intended to be clarification on why I didn't use BeautifulSoup in the code snippet. I learned on and have done all my parsing with LXML so I know its syntax and just haven't had a reason to switch. That's fair, but I feel like I see a lot of advice to avoid BS because lxml is better at parsing, which grates on me.
|
# ? Apr 7, 2015 16:54 |
|
Munkeymon posted:That's fair, but I feel like I see a lot of advice to avoid BS because lxml is better at parsing, which grates on me. Didn't BS used to not use lxml? I feel like that was a thing and the reason people started recommending lxml instead.
|
# ? Apr 7, 2015 16:56 |
|
I thought it was the other way around, but I sure as hell didn't know what I was doing when I first started looking into scraping and parsing. I'll bet it had to do with XML parsing support, which BS says requires LXML. That might have even been the first type of parsing I needed to do — I can't remember. Anyway, as a noob at the time, I was also looking to minimize dependencies because, uh, ?. So if I needed LXML anyway, why install something else, right? Of course that same kind of ignorance led me to use urllib far longer than I should until I finally installed requests and made my code a whole lot simpler. From a quick scan of BS docs, the syntax looks pretty similar. Not sure how to do a "first-child" selector on games, though. We only want the first TD element in those rows. Python code:
onionradish fucked around with this message at 17:31 on Apr 7, 2015 |
# ? Apr 7, 2015 17:25 |
|
Thermopyle posted:Didn't BS used to not use lxml? I feel like that was a thing and the reason people started recommending lxml instead. Maybe at some point but it has for years and was using lxml when I first saw that advice pop up onionradish posted:From a quick scan of BS docs, the syntax looks pretty similar. Not sure how to do a "first-child" selector on games, though. We only want the first TD element in those rows. It's an iterator, so just call next() once.
|
# ? Apr 7, 2015 19:23 |
|
Calling next() seems icky. Isn't it possible to refine the selector to only return the items we care about in the first place? I'm sure it's just me not knowing the BS syntax here.
|
# ? Apr 7, 2015 19:28 |
|
I think it supports :first-of-type but you're still getting an iterator back, so... E: you could .find('td') Munkeymon fucked around with this message at 20:55 on Apr 7, 2015 |
# ? Apr 7, 2015 20:05 |
|
Just saw this today, which might be useful here, as it smooths over the BS interface: http://soupy.readthedocs.org/en/latest/
|
# ? Apr 7, 2015 20:31 |
|
They overcomplicatedPython code:
I'm sure that can be done without calling strip twice, but I have a sinus headache and don't feel like giving myself a nested generator headache, too.
|
# ? Apr 7, 2015 20:58 |
|
Thermopyle posted:I think everyone missed your joke, Dominoes!
|
# ? Apr 7, 2015 22:29 |
|
Munkeymon posted:They overcomplicated Python code:
Sinestro fucked around with this message at 22:41 on Apr 7, 2015 |
# ? Apr 7, 2015 22:38 |
|
gently caress, I can't tell whether responses are real or just cruel obfuscation and code golf anymore.... I'm going back to LXML. E: Dominoes' joke is the only one I got... onionradish fucked around with this message at 23:10 on Apr 7, 2015 |
# ? Apr 7, 2015 22:57 |
|
Python code:
onionradish posted:gently caress, I can't tell whether responses are real or just cruel obfuscation and code golf anymore.... You decide: Python code:
|
# ? Apr 7, 2015 23:13 |
|
Oh my god, is that still Python? There's gotta be a point at which it isn't...
onionradish fucked around with this message at 23:26 on Apr 7, 2015 |
# ? Apr 7, 2015 23:23 |
|
Is there a clean way to cause a key to be inserted in a dict if it doesn't exist, but increment it if it does? I triedPython code:
|
# ? Apr 8, 2015 00:15 |
|
hooah posted:Is there a clean way to cause a key to be inserted in a dict if it doesn't exist, but increment it if it does? I tried .get('keyname') on a dictionary will never raise a KeyError, and accepts a keyword argument for what to return in lieu of the value (default is None). So you could do Python code:
|
# ? Apr 8, 2015 00:19 |
|
hooah posted:Is there a clean way to cause a key to be inserted in a dict if it doesn't exist, but increment it if it does? I tried d[key] = d.get(key, 0) + 1 efb
|
# ? Apr 8, 2015 00:20 |
|
hooah posted:Is there a clean way to cause a key to be inserted in a dict if it doesn't exist, but increment it if it does? I tried Use a collections.Counter instead of a regular dict.
|
# ? Apr 8, 2015 00:24 |
|
|
# ? May 9, 2024 11:32 |
|
Great, get(key, 0) worked fine!Edison was a dick posted:Use a collections.Counter instead of a regular dict. How come?
|
# ? Apr 8, 2015 00:26 |