|
I came to a web programming company after doing nothing but hobbyist python programming for several years. I had no background in javascript or HTML at all, but that didn't matter since we did a lot of server-side stuff using pylons and cherrypy that really just writing regular python, no need to be a networking expert. We mostly setup secure communications / internal websites for banks / financial companies. an example of a common problem I was assigned early on, was how to efficiently traverse a multi-KB blob of JSON (essentially just a python dictionary) and shove the important bits into a postgres database using SQLAlchemy. That's pretty much just leveraging your knowledge of python data structures and the absolutely barest of knowledge about SQLA's object relational mapper That's my "how I got a real job (TM) writing python" story Lurchington fucked around with this message at 21:16 on Mar 30, 2012 |
# ? Mar 30, 2012 21:14 |
|
|
# ? May 9, 2024 12:01 |
|
I'm struggling with something pretty basic. I have an XML file that looks like this:code:
code:
What I say "some useful data object", I don't really care what it looks like as long as I can easily extract an address along with it's associated resolution, and resolutionDate. This is also something I'm doing completely for fun that has nothing to do with my job, etc, so I'm not asking anyone to do my job-work for me.
|
# ? Mar 31, 2012 02:09 |
|
spengler posted:It has a ton of other nodes that I don't care about. All I want to do is parse this into some useful, simple data structure such that I end up with a list of associated inspectiondates, siteaddresses and resolutions. I've been playing with xml.dom.minidom.parse, and have not come up with anything helpful: I recommend using 'from xml.etree.ElementTree import ElementTree' over the minidom if you don't immediately understand DOM, I know I certainly don't. Something like code:
|
# ? Mar 31, 2012 02:19 |
|
I was mucking with ElementTree and got discouraged before I found a tutorial based on minidom that I got equally discouraged by, but if you think it's simpler then I will give it another go tomorrow. My goal here is to use city supplied data to make a google map that shows that over-privileged white people are more likely to bitch about how dirty their neighbors lawns are; I got the gmaps stuff figured out lickity-split but am struggling with basic XML parsing, which amuses me because going into this I assumed it would be the other way around.
|
# ? Mar 31, 2012 02:35 |
|
EDIT: BEGINNER STUFF NM I'm going through Learning Python using 2.3, IDLE i'm using is 3.2.2 Should I throw this book away? Has too much syntax been changed? ButtWolf fucked around with this message at 01:44 on Apr 2, 2012 |
# ? Apr 2, 2012 01:39 |
|
jimcunningham posted:EDIT: BEGINNER STUFF NM I wouldn't throw it away, but Py 2 is a *lot* different from Py 3. I've never used Py 3, and many libraries don't yet support Py 3. See a few pages back for our discussion on who used what. I use Py 2.7 and have no desire to move towards Py 3. Most of that is because I can't, because my entire field uses 2.6/2.7. I'd hold onto your 2.3 manual though, because you'll probably find Py 2 code for which you'll be glad you kept a reference. Alternatively, everyone loves "learning python the hard way". FAKE EDIT: What the poo poo, didn't that thing used to just be a free website?
|
# ? Apr 2, 2012 04:50 |
|
The HTML version still is free.
|
# ? Apr 2, 2012 06:13 |
|
Plorkyeran posted:The HTML version still is free. http://learnpythonthehardway.org/book/
|
# ? Apr 2, 2012 15:27 |
|
I still think the way he teaches OO is abysmal. His "gogoths are getting classy" is terrible. If the first thing you learn about a class is that it can be a abused as a faux dictionary, your just going to end up more confused about OO than you started.
duck monster fucked around with this message at 14:24 on Apr 3, 2012 |
# ? Apr 3, 2012 14:20 |
|
I just finished setting this up at work where we have a flaky Internet connection, but for those of you that redownload the same packages over and over again, take a look at Localshop.
|
# ? Apr 3, 2012 16:16 |
|
duck monster posted:I still think the way he teaches OO is abysmal. His "gogoths are getting classy" is terrible. If the first thing you learn about a class is that it can be a abused as a faux dictionary, your just going to end up more confused about OO than you started. Admittedly, I view OO in what might be an overly prosaic (and imperative) way. And I should perhaps read what you're talking about before answering... Computer viking fucked around with this message at 17:34 on Apr 3, 2012 |
# ? Apr 3, 2012 17:32 |
|
spengler posted:I'm struggling with something pretty basic. I have an XML file that looks like this: "dcst:siteaddress" is also a tag name, fyi. The minidom DOM is, by Python standards pretty obtuse. Try this stuff: code:
And if that's not quite what you want, hopefully you can figure out how to modify it.
|
# ? Apr 3, 2012 18:40 |
|
I'm having a bit of an issue with managing UI. This is going to basically just be me using this, but given that I'm prone to keystroke errors often, I like to keep my code smart enough to tell me to gently caress myself if I'm going to screw my data. Here's what I wrote, but it is not doing what I want:code:
Anyway, it works fine if I do something dumb like enter in a number and a letter or a letter. However, if I try an odd number, it decides it's fine and continues on its way. Is there a cleaner way to do this? As I write this, it occurs to me I could make an array of possible answers and refuse to leave the loop if the answer isn't in there... code:
|
# ? Apr 3, 2012 21:33 |
|
JetsGuy posted:
This seems fine to me. Three suggestions: use an integer, not a float, put this in its own function so that the loop is encapsulated easily, and use smart range expressions: code:
|
# ? Apr 3, 2012 21:40 |
|
Suspicious Dish posted:This seems fine to me. Three suggestions: use an integer, not a float, put this in its own function so that the loop is encapsulated easily, and use smart range expressions: How'd I forget about continue?? Thanks man. Also, yeah, I don't know why I didn't use a better range exception. This is for a snippet that I needed to just quickly edit data sets for myself. The whole "program" is only 80 lines, and the bulk of it is catching idiotic entries. VV
|
# ? Apr 3, 2012 21:59 |
|
Computer viking posted:I don't really agree - seeing an object as a container of data sounds like a reasonable first step? Add on "and relevant functions" as the next step, and then move on to interfaces and eventually class hierarchies. I actually found LPTHW pretty useless for learning OO programming. I mean, it's fine for learning the syntax of classes and how they work, but it really doesn't do much for how or why you would want to use them. His first example of a class is "let's see what that game we made would look like if we used classes." Then he makes a 'game' class and throws the entire program into it. My reaction on seeing that was that classes were either pointless, or this was a terrible example of how to use a class.
|
# ? Apr 4, 2012 18:41 |
|
Is there any way to check if a method is decorated? (and decorated with what?)
|
# ? Apr 4, 2012 20:48 |
|
Not My Leg posted:I actually found LPTHW pretty useless for learning OO programming. I mean, it's fine for learning the syntax of classes and how they work, but it really doesn't do much for how or why you would want to use them. I would argue that this is a failing of all language specific programming books. At least those that I have read. None of them cover why you would use OO or how to truly use it effectively. Simply covering what a class is and what an object is, is insufficient for learning object oriented design.
|
# ? Apr 4, 2012 21:14 |
|
German Joey posted:Is there any way to check if a method is decorated? (and decorated with what?) http://schinckel.net/2012/01/20/get-decorators-wrapping-a-function/ talks about it...
|
# ? Apr 4, 2012 22:03 |
|
German Joey posted:Is there any way to check if a method is decorated? (and decorated with what?) Why would you ever need to do this?
|
# ? Apr 5, 2012 00:41 |
|
ComptimusPrime posted:I would argue that this is a failing of all language specific programming books. At least those that I have read. None of them cover why you would use OO or how to truly use it effectively. I would agree, and I don't know how much I actually mean that to be a criticism of LPTHW (even though it did come out that way). Since we're on the subject, anyone have a good resource for learning object oriented design?
|
# ? Apr 5, 2012 01:00 |
|
German Joey posted:Is there any way to check if a method is decorated? (and decorated with what?) Yes. What are you trying to do from the outset ?
|
# ? Apr 5, 2012 01:25 |
|
Not My Leg posted:I would agree, and I don't know how much I actually mean that to be a criticism of LPTHW (even though it did come out that way). Since we're on the subject, anyone have a good resource for learning object oriented design? The only book I can ever recommend is The Object-Oriented Thought Process by Weisfeld. It is not perfect, but it is good. And it is only 200 pages, which I feel is pretty adequate.
|
# ? Apr 5, 2012 01:57 |
|
Tried googling this. Probably wasn't using the right terms... combined OSX/Python question. Working on a project for my machine learning course (Written in Python). Group member designed it to run paralleled so it's spawning 1-5 processes at once. Cool. On my friend's Windows machine, this eats up 100% of his CPU and blazes through the work it has to do. On my Quad core mac, with Chrome, Safari, Mail, Pages, Spotify, iTunes, and Steam running in addition to it, I'm running at around 35% CPU, though each Python process says 100%? His windows machine of comparable specs is knocking out roughly three times as much data processing as mine, and the entire goal of this part of the project is to run the learning algorithm with different parameters and compare them... so I kinda want this poo poo to run fast. So my question is uhhhh... is there a way to force CPU priority on python in general (or in Python when I create the process)? Each new process spawned by our app has a unique pid so I can't just sit here and call nice on it every five seconds.
|
# ? Apr 5, 2012 06:58 |
|
You have 8 virtual cores. 4 cores * 2 due to hyper threading. You will need to up the process count.
|
# ? Apr 5, 2012 08:48 |
|
German Joey posted:Is there any way to check if a method is decorated? (and decorated with what?) Suspicious Dish posted:Why would you ever need to do this? I'll sort of answer both. I'm building a framework and want to allow people to define functions as normal ones (return something) or asynchronous ones that pass the result into a callback function. I wanted to determine if a function was decorated with http://www.tornadoweb.org/documentation/_modules/tornado/gen.html#engine This is what I did. I welcome suggestions for improvement because it's pretty weird. code:
raymond fucked around with this message at 10:18 on Apr 5, 2012 |
# ? Apr 5, 2012 10:15 |
|
ComptimusPrime posted:You have 8 virtual cores. 4 cores * 2 due to hyper threading. You will need to up the process count. Thing is, the data I'm mining runs the same algorithm five times per generation, so five is kinda the max I can spawn... Is that the only way to speed it up?
|
# ? Apr 6, 2012 02:36 |
|
I am not familiar with the problem. So I have no idea. Process two generations at the same time?
|
# ? Apr 6, 2012 05:59 |
|
The second reply here might give you a way to set a nice limit for the processes.
|
# ? Apr 6, 2012 06:35 |
|
ComptimusPrime posted:I am not familiar with the problem. So I have no idea. Process two generations at the same time? Teaching a computer to play checkers. Each generation starts with 15 'solutions', they're mutated into 15 more, and mine plays each of the 30 against a random 5. 15 best of the 30 move on to the next generation. So, processing more than one at a time doesn't really make sense. ^^^this thread looks like it might work! Trying to un-limit the processes, not limit them, but, I'll give it a go tomorrow.
|
# ? Apr 6, 2012 06:44 |
|
Well you could restate the solution. Run 2 generations at the same time, combine the results by taking the set of 30 all the way through. At each step the ai agent could gain information from each distinct generation. Of course I do not really know much about chess, so this solution may be pointless.
|
# ? Apr 6, 2012 07:00 |
|
Running parallel simulations and interbreeding the survivors between them is also a highly effective way of rapidly evolving optimal solutions. (GAs are funny like that: fundamentally simple but all the magic happens in the system tweaking and nurturing.)
|
# ? Apr 6, 2012 17:36 |
|
raymond posted:I'll sort of answer both. This sounds actually pretty similar to what I'm trying to do as well! In my case, users interface with a processing engine by subclassing a base "Component" class and redefining a method called "simulate." The engine is supposed to take care of finding and pre-processing data, but has no real way of knowing the minimum amount of data required, as it can vary by both quantity, quality, and condition from component to component. In the cases of a complex condition, I can have advanced users define a "simCondition" method to be called by the engine that can check to see if the input is adequate. However, most components will be simple, requiring only that all input-slots have *something* in them or that all input slots have a minimum quantity of *something* in them (e.g. like 10s worth of data in each slot). The easiest interface for that is to define a decorator on the simulate method such as "@combinational" in the first case or "@runTime(10)" in the second. Thanks for all the help, from both you and Hughlander!
|
# ? Apr 6, 2012 18:53 |
|
If you want a decorator to act as a flat, what about :code:
code:
code:
|
# ? Apr 6, 2012 19:25 |
|
I had to reinstall python completely today. gently caress macports forever. That poo poo is an insidious disease that really fucks your system. -m32? gently caress YOU, I KNOW BETTER NO REFUSE TO PAY ATTENTION TO ANY OTHER BUILDS! EVERYTHING MUST BE IN THE OPT FOLDER OR IT DOESN'T EXIST! Seriously, I had a compiler issue with perl because for whatever reason, heasoft was using the macports perl (which is poo poo, perl is poo poo). So I had enough of macports being a bitch, and uninstalled the whole thing. This meant having to install python and ipython (etc etc) again, but it was remarkably pleasant how easy it was this time around. I'm not looking forward to doing it when I get home on the Lion machine.
|
# ? Apr 6, 2012 21:59 |
|
Not sure if this belongs here or the scientific computing thread, but I think this is more of a Python question. I'm trying use the facecolors argument in matplotlib's plot_surface() and I'm getting this error back:code:
Edit: forgot to make clear the real problem. There are no values of 0.0 in the N that I supply. This value only shows up in a new list returned by cm.jet. FoiledAgain fucked around with this message at 22:23 on Apr 6, 2012 |
# ? Apr 6, 2012 22:15 |
|
FoiledAgain posted:Not sure if this belongs here or the scientific computing thread, but I think this is more of a Python question. I'm trying use the facecolors argument in matplotlib's plot_surface() and I'm getting this error back: Can you give the place where you explicitly define N? I suspect you unwittingly are adding in a 0 and not knowing it. Happened to me a bunch of times. Also, there's a scientific computing thread?
|
# ? Apr 6, 2012 22:39 |
|
JetsGuy posted:I had to reinstall python completely today. gently caress macports forever. That poo poo is an insidious disease that really fucks your system. Not sure what all you use module wise, but look at SciPySuperpack. It's a bash script that will build numpy, scipy, matplotlib, statsmodels, pymc, pandas, and ipython against the Apple default Python and all you'll need additionally is Xcode. Otherwise I use the python.org site to install 2.7 or use homebrew instead of macports to install it.
|
# ? Apr 6, 2012 22:44 |
|
vikingstrike posted:Not sure what all you use module wise, but look at SciPySuperpack. It's a bash script that will build numpy, scipy, matplotlib, statsmodels, pymc, pandas, and ipython against the Apple default Python and all you'll need additionally is Xcode. This whole experience has soured me on macports, and I was already soured on fink and god help us, easy_install. I'm just going to install all my own poo poo from now on. Also, of course I have Xcode, what kind of pleb do you think I am?
|
# ? Apr 6, 2012 23:37 |
|
|
# ? May 9, 2024 12:01 |
|
JetsGuy posted:This whole experience has soured me on macports, and I was already soured on fink and god help us, easy_install. I'm just going to install all my own poo poo from now on. I am perfectly fine with easy_install (actually pip) for most non-numpy/scipy things, but fink and macports are the enemy. Homebrew for things that have a recipe, the installer for things with an installer, and pip for everything else.
|
# ? Apr 7, 2012 00:40 |