|
CheckIo is pretty great for problems once you get into it. I tried HackerRank for a bit with Java 8 and some of the questions were shockingly bad, like they were taking community submissions with no quality control. No idea what the Python section's like though! But those kinds of things tend to be isolated problems, Eela's suggestion is good because you get practice actually designing and building an application in Python, working with classes and messing with command-line args and whatever else. So you're ready to just dive in and build whatever the interviewer wants, without being unfamiliar with some of the basic language stuff
|
# ? Apr 23, 2017 15:00 |
|
|
# ? May 15, 2024 03:42 |
|
laxbro posted:Newbie question: I'm trying to build a web scraper with Beautiful Soup that pulls table rows off of the roster pages for a variety of college sports teams. I've got it working with regular HTML pages, but it doesn't seem to work with what appear to be Angular pages. Some quick googling makes it seem like I will need to use a python library like selenium to virtually load the page in order to scrape the html tables on the page. Would a work around be to first use Beautiful Soup, but if a table row returns as None, then call a function to try scraping the page using something like selenium. Or, should I just try to scrape all of the pages with selenium or a similar library? Load the page with Chrome deveoper tools open. The Network tab, I think, is where you can inspect requests. You might be able figure out how the page is fetching the data. I've been in a similar situation and found that the site was making a request to some JSON API before loading the data. In developer tools you can see what the request headers and response looks like. In the easiest case you can just hit the API url and get JSON back. In a more complicated case you can examine the request headers and mimic them in your scraper.
|
# ? Apr 23, 2017 15:19 |
|
laxbro posted:Newbie question: I'm trying to build a web scraper with Beautiful Soup that pulls table rows off of the roster pages for a variety of college sports teams. I've got it working with regular HTML pages, but it doesn't seem to work with what appear to be Angular pages. Some quick googling makes it seem like I will need to use a python library like selenium to virtually load the page in order to scrape the html tables on the page. Would a work around be to first use Beautiful Soup, but if a table row returns as None, then call a function to try scraping the page using something like selenium. Or, should I just try to scrape all of the pages with selenium or a similar library? I also typically separate the HTML collection from the parsing, saving the HTML to disk so I can fine-tune the parsing without hitting the server. And if the site layout changes in the future, the captured HTML is available so I can update the parsing rules. baka kaba posted:Also Selenium was a real pain last time I used it, they updated something so the Firefox webdriver wasn't included anymore and everything broke. There might be a better scraper out there? Setting up selenium now involves an extra step. It isn't hard, but seems to be really poorly described. Essentially, you need a middleware geckodriver in addition to selenium, and either specify the path to that driver when initializing the webdriver or just add it to your PATH. I've always just added it to PATH, but the other way is supposed to be as simple as this: code:
code:
onionradish fucked around with this message at 15:40 on Apr 23, 2017 |
# ? Apr 23, 2017 15:21 |
|
pathlib is cool, Path.iterdir() is not because it's not sorted. Is there a natural sort I'm missing (where 'file2' < 'file10') or do I need to screw around parsing numbers from filenames here
|
# ? Apr 24, 2017 18:50 |
|
baka kaba posted:do I need to screw around parsing numbers from filenames here Most likely yes. If you make it explicit that the number part is an integer you'll get the sorting you want: >>> ('file', 2) < ('file', 10) True >>> ('file', '2') < ('file', '10') False
|
# ? Apr 24, 2017 19:12 |
|
Symbolic Butt posted:Most likely yes. If you make it explicit that the number part is an integer you'll get the sorting you want: I didn't know you could compare tuples like that.
|
# ? Apr 24, 2017 19:13 |
|
Why is there no natural sort in standardlib!?!!!
|
# ? Apr 24, 2017 19:33 |
|
EDIT: query deleted. Instead of getting an inexplicable error for the list item I said, I was getting a very easily explained error for the value after it. I should have read my own code more closely as well as restored the try and except clauses I removed yesterday while trying to diagnose another error.
Death Zebra fucked around with this message at 19:59 on Apr 24, 2017 |
# ? Apr 24, 2017 19:32 |
baka kaba posted:pathlib is cool, Path.iterdir() is not because it's not sorted. Is there a natural sort I'm missing (where 'file2' < 'file10') or do I need to screw around parsing numbers from filenames here pathlib Paths are hashable and orderable (and therefore sortable) so you can just call sorted! EX: code:
Python code:
code:
Death Zebra, can you give us the full stack trace? Eela6 fucked around with this message at 19:50 on Apr 24, 2017 |
|
# ? Apr 24, 2017 19:46 |
|
Eela6 posted:pathlib Paths are hashable and orderable (and therefore sortable) so you can just call sorted! How does it deal with a folder that has file1, file9, file10 and so on?
|
# ? Apr 24, 2017 19:55 |
Ordering is lexigrapic according to the path of the file. It works 'like you would expect' - file0 < file1 < file9. More specifically, Lexigraphic ordering of strings and paths works more or less as follows: Note that Python code:
EDIT: Oh, I see, your files aren't left-padded with zeros! I'm dumb. You can fix this by re-labeling the files. I'll have a solution up in a jiffy. Eela6 fucked around with this message at 20:32 on Apr 24, 2017 |
|
# ? Apr 24, 2017 20:01 |
|
Eela6 posted:Death Zebra, can you give us the full stack trace? Thanks but that won't be necessary. Turns out the search term I used afterwards was getting no results. I really should have put something in to account for that already.
|
# ? Apr 24, 2017 20:03 |
|
HardDiskD posted:How does it deal with a folder that has file1, file9, file10 and so on? Badly, I was using sorted() until I realised my data was out of order, tracked it down to the files coming in all file1, file10, file11. That's why I was hoping a natural sort was lurking in the standard library Oh well, maybe I can work around it with that split tuple suggestion up there, thanks! It just feels bad because it's brittle and Windows does natural sort ordering, missed opportunities
|
# ? Apr 24, 2017 20:06 |
baka kaba posted:Badly, I was using sorted() until I realised my data was out of order, tracked it down to the files coming in all file1, file10, file11. That's why I was hoping a natural sort was lurking in the standard library This is kind of an overwrought solution but it should work just fine. I'm sure a REGEX wizard can do this in three lines if not less. Python code:
Python code:
code:
Eela6 fucked around with this message at 21:14 on Apr 24, 2017 |
|
# ? Apr 24, 2017 21:07 |
|
Just had a quick glance at it, but you could Space Kablooey fucked around with this message at 21:21 on Apr 24, 2017 |
# ? Apr 24, 2017 21:17 |
|
baka kaba posted:CheckIo is pretty great for problems once you get into it. I tried HackerRank for a bit with Java 8 and some of the questions were shockingly bad, like they were taking community submissions with no quality control. No idea what the Python section's like though! I wish I had any completed applications to port! I've been messing around with small projects so I won't have nothing to show off, but I have not been great, historically, at finishing personal projects.
|
# ? Apr 24, 2017 21:20 |
|
Cheers Eela! I ended up doing a regex to grab the digits and everything else from the filename, but it's good to see other solutions because it feels like there should be a neat way of solving it in generalHardDiskD posted:Just had a quick glance at it, but you could Yeah that and stem are handy (I've been messing around in that drat library for a couple of days)
|
# ? Apr 24, 2017 21:27 |
|
Vivian Darkbloom posted:I wish I had any completed applications to port! I've been messing around with small projects so I won't have nothing to show off, but I have not been great, historically, at finishing personal projects. Hell it's less about finishing them and more about starting them - I'm just thinking of an interview situation where they want you to model some data where you need a class, or they want a basic command-line tool that handles arguments, or they want you to to create a simple utility library where you only expose certain functions. Are you comfortable hitting the ground running with that stuff? A lot of problem sites are more like 'here's some input and your function needs to provide a result' and you just write a function or two - which is great, but it doesn't touch on the design side of things too much. So I was just thinking it would be good to do some stuff where you have to handle that side of things, just for the practice and so you're not lost if they start expecting that kind of thing
|
# ? Apr 24, 2017 21:38 |
|
Here's my common snippet to convert an iterable into natural sort order:Python code:
Python code:
|
# ? Apr 24, 2017 22:00 |
|
code:
|
# ? Apr 24, 2017 23:55 |
ynohtna posted:Here's my common snippet to convert an iterable into natural sort order: Ooh, this one is nice.
|
|
# ? Apr 25, 2017 00:26 |
|
Oh yeah, that's swish as hell
|
# ? Apr 25, 2017 15:15 |
|
dougdrums posted:
How come when I search pip it always shows me like a list of 648383628 packages, most of which don't even have what I searched for in the title or short description? Or maybe it does and I just don't see it because the list is just so huge that I gloss over everything.
|
# ? Apr 25, 2017 18:10 |
|
I'm not sure, but you might be able to put searchable keywords or something into the setup.py. I know that if the package name is not the same as the module name, and I search for the module name, I will still get the package even if it's not in the description. I decided to enter python's gates of dependency hell and it's a fuckin blast. dougdrums fucked around with this message at 18:37 on Apr 25, 2017 |
# ? Apr 25, 2017 18:35 |
|
I'm finding how hard it is to make a cross-platform console interface that isn't horrible for a little strategy game project, so it's time to get a basic GUI framework set up. I just read the Python Wiki page on GUI programming and I am looking at pyjs as a possibility, since targeting web browsers might be easier than rolling my own GUI entirely. Not sure, though -- ideally I'd like something that's programmer-friendly and doesn't require a lot of setup for a user running my program. Any recommendations on what might be the best GUI choice?
|
# ? Apr 25, 2017 23:30 |
|
Vivian Darkbloom posted:I'm finding how hard it is to make a cross-platform console interface that isn't horrible for a little strategy game project, so it's time to get a basic GUI framework set up. I just read the Python Wiki page on GUI programming and I am looking at pyjs as a possibility, since targeting web browsers might be easier than rolling my own GUI entirely. Not sure, though -- ideally I'd like something that's programmer-friendly and doesn't require a lot of setup for a user running my program. Any recommendations on what might be the best GUI choice? What are you envisioning in terms of the GUI?
|
# ? Apr 25, 2017 23:58 |
|
accipter posted:What are you envisioning in terms of the GUI? A central canvas, a few lines of text underneath, and a few buttons horizontally arranged beneath the text. The canvas would need to be updated to recolor different areas on the board. Don't really need the ability to read clicks from the canvas or interact with any fancy widgets -- just whipping up a demo. e: I am thinking tkinter will be ok for what I need. Vivian Darkbloom fucked around with this message at 02:49 on Apr 26, 2017 |
# ? Apr 26, 2017 00:11 |
I want to deploy a python package to my private pypi repo. Is this guide a decent one to follow? http://peterdowns.com/posts/first-time-with-pypi.html
|
|
# ? Apr 26, 2017 01:40 |
|
Vivian Darkbloom posted:A central canvas, a few lines of text underneath, and a few buttons horizontally arranged beneath the text. The canvas would need to be updated to recolor different areas on the board. Don't really need the ability to read clicks from the canvas or interact with any fancy widgets -- just whipping up a demo. Can tkinter handle those canvas operations you described? That sounds more like something you'd use Qt for (which is multi-platform but would create a pyqt dependency)
|
# ? Apr 26, 2017 04:31 |
ynohtna posted:Here's my common snippet to convert an iterable into natural sort order: It took me a little bit to prove to myself that you would never end up comparing a string and an int with this, but yeah, you never do so this is totally valid. Nice!
|
|
# ? Apr 26, 2017 04:57 |
|
QuarkJets posted:Can tkinter handle those canvas operations you described? That sounds more like something you'd use Qt for (which is multi-platform but would create a pyqt dependency) Yeah you're right, but I can replicate the functionality by using tkinter to render the board as a bunch of buttons. Ugly but fine for what I need.
|
# ? Apr 26, 2017 05:45 |
|
Confused about an issue with passing functions. This might be related to tkinter weirdness, but I might just be doing something else wrong.code:
Vivian Darkbloom fucked around with this message at 08:31 on Apr 26, 2017 |
# ? Apr 26, 2017 08:08 |
|
Python's closures are late binding: the values of variables used within them are looked up at the time the inner function/closure is called. It feels a bit of a hack, but I've seen a default argument used as a common workaround (the default value is bound at the time of definition), i.e.: Python code:
|
# ? Apr 26, 2017 08:48 |
|
Vivian Darkbloom posted:Confused about an issue with passing functions. This might be related to tkinter weirdness, but I might just be doing something else wrong. IMO, if you're going to be learning the GUI library from scratch you'd be much better served going with a small Flask app and learning the basics of HTML/CSS/JS. That's an actual marketable skill with virtually infinite learning resources vs some weird, arcane language on top of a language that produces interfaces from 1995.
|
# ? Apr 26, 2017 15:33 |
|
I've just finished my first Flask project for my new job which is basically a page with a form that allows users to do CRUD operations on a database table. It took me about a week to create. Of course there was a bunch of stuff like having to learn MySQL, JavaScript form validation, navigate their code base, etc. along the way so it took a bit of time. I was just able to recreate what took me about a week with Flask Admin in an hour and was even able to add additionally functionality like a list view, searching, and filtering. I feel like this was deceptively simple though and when I start working on more complex projects I'd be better off writing the SQL and JS myself. Is that correct?
|
# ? Apr 26, 2017 18:31 |
|
Tigren posted:That's an actual marketable skill with virtually infinite learning resources vs some weird, arcane language on top of a language that produces interfaces from 1995. These descriptions both describe Flask
|
# ? Apr 26, 2017 22:53 |
|
huhu posted:I've just finished my first Flask project for my new job which is basically a page with a form that allows users to do CRUD operations on a database table. It took me about a week to create. Of course there was a bunch of stuff like having to learn MySQL, JavaScript form validation, navigate their code base, etc. along the way so it took a bit of time. I was just able to recreate what took me about a week with Flask Admin in an hour and was even able to add additionally functionality like a list view, searching, and filtering. I feel like this was deceptively simple though and when I start working on more complex projects I'd be better off writing the SQL and JS myself. Is that correct? At some point yes, you will have to customize something or other, but Flask Admin really is that powerful.
|
# ? Apr 27, 2017 01:28 |
|
Python code:
Haha take that noisy module!
|
# ? Apr 27, 2017 01:43 |
|
QuarkJets posted:These descriptions both describe Flask Touche. But you're not going to find a lot of employers impressed by your Tcl/Tk skills.
|
# ? Apr 27, 2017 02:01 |
|
|
# ? May 15, 2024 03:42 |
|
ynohtna posted:Python's closures are late binding: the values of variables used within them are looked up at the time the inner function/closure is called. Thanks, that helped a lot. It's kind of an odd feature, I'll have to read more on it.
|
# ? Apr 27, 2017 03:21 |