Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
king_kilr
May 25, 2007
I got started with Python a few months a go, I've been using it for exclusively web stuff so far, using Django. I really like it so far, I would say the best part is code is so readable.

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007
I have a python application that is just about finished up, you can check out the code here: http://github.com/alex/pyelection/tree/master any thoughts on it would be great, there are some areas where the code is a little messy and any thoughts would be great.

king_kilr
May 25, 2007
sum - takes the sum of an iterable
int(x) for x in str(1234567890) - a generator expression, it iterates over '1234567890'(strings are iterable and yield each charecter), and yields the integer

king_kilr
May 25, 2007

Milde posted:

sum("hello") gives an error - it iterates over the string fine, but internally it tries to call "h" + "e", which is invalid.

'h' + 'e' is perfectly valid, the problem is sum appears to do
code:
total = 0
for i in iterable
    total += i
return total
(the error it raises says that int can't be added to str), except for the fact that it is hyper optimized and written in C.

king_kilr
May 25, 2007
If/when the PyCon talks are released(they were all recorded), the PyPy one was really excellent.

king_kilr
May 25, 2007
EDIT: I hate my life.

king_kilr
May 25, 2007

No Safe Word posted:

There's a whole Django thread actually, and I answered a similar question in it, which basically boils down to having django generate a sql dump script with your data in it, recreating the model (drop/recreate), and then re-inserting the data after you've modified the dump appropriately.

If you use SQLite (which is awesome), it unfortunately doesn't support removal of columns from schema anyway, so you'd have to drop the table :(

Or you can use a 3rd party project such as django-evolution(which works pretty drat well IMO).

king_kilr
May 25, 2007
Tuples are immutable, use them as such.

king_kilr
May 25, 2007

ashgromnies posted:

Yeah, I know I want templating but this is just a one-off for now to test my algorithm and will go away so I don't want to put too much effort into it - just enough to be readable. This is eventually going to be called from a Django application.

I didn't know Python had an equivalent of sprintf! Thanks!

If this is for use in a Django app, you should probably take a look at the Django templating language.

king_kilr
May 25, 2007
http://docs.python.org/lib/node528.html

Are you using Popen and giving them a file object, or something else to write to?

king_kilr
May 25, 2007
I just set up mod_wsgi and I like it a lot, it's super easy to get going and I imagine it would be pretty easy to invoke scripts using subpress.Popen and pipe their stdout back to the user.

king_kilr
May 25, 2007
I used pyprocessing(aka multiprocessing) this weekend and it was really great to work with, I managed to offload all the simulations(aka computationally expensive work) to another process in hardly any work, just set up a pipe to communicate and set the process off, you can see the what change I made to made for this to happen here: http://github.com/alex/election-sim/commit/cc93df649d1295deab96f1f1ab1ff709e8b0f391

king_kilr
May 25, 2007

No Safe Word posted:

Something like the table on these pages:

http://www.cplusplus.com/reference/stl/

(which are the STL container operations' complexities)

for Python would be awesome.

http://wiki.python.org/moin/TimeComplexity

Tada :)

king_kilr
May 25, 2007
Mr. Noller(forgot your SA name), your proposals for pycon sound very cool, I'd attend both of them.(As long as they don't interfere with mine of coure :P )

king_kilr
May 25, 2007

m0nk3yz posted:

I proposed one on MultiProcessing, and one on Concurrency/Distributed systems. Dunno if they'll get approved.

Hehe, I can see votes on other people's proposals(but not mine own), not sure if I'm allowed/supposed to say anything. But I wouldn't worry about he MultiProcessing one :P

king_kilr
May 25, 2007

m0nk3yz posted:

Oh no guys, I've picked up "Programming Erlang" - I'm going to the dark side :jihad:

Of course, this is all part of my clever plot to introduce Actors/Message passing pieces to python.

Guido said that he though Actors were one of the "right ways" to do concurency. It's somewhere in

http://moderator.appspot.com/#e%253Dagltb2RlcmF0b3JyDQsSBlNlcmllcxjJAQw%252Bt%253Dagltb2RlcmF0b3JyDAsSBVRvcGljGP8BDA%252Bv%253D15

king_kilr
May 25, 2007

m0nk3yz posted:

Need some help: I want to pick out a few "easy to grok" app examples to implement with single-threads, multi threads and then multiprocessing. I want the examples to be as approachable as possible. Ergo, no map-reduces or hadooping :)

The app I just did uses one process for the GUI stuff, and a second for the heavy processing, something like that's a pretty good example IMO.

king_kilr
May 25, 2007
Guys, this: http://github.com/alex/pyelection/tree/master/models.py#L57 is why you shouldn't be using except: pass, because i don't have a loving clue what my own code does, or what the logic is.

king_kilr
May 25, 2007

tef posted:

If you're using beautiful soup still, try using lxml instead. You can use it to parse html and xml quickly, and run xpath over it.

I'm not talking about the BeautifulSoup stuff, I'm saying I have no idea what exceptions I'm trying to catch, or what circumstances lead to those things.

king_kilr
May 25, 2007

kaschei posted:

I've been googling for a little less than an hour for a Python module that can parse functions and evaluate them. I haven't found anything like that, and I'm looking for something that can handle multiple (at least two) variables.

Ideally I could prompt for keyboard input, they could type in "4(x^2)*y + x*sin(y)" and I would get an object that I could cause to evaluate at given values, like:

code:
>>> fn = functionParse(raw_input("f(x,y) = ")
f(x,y) = 4(x^2)*y + x*sin(y)
>>> fn.eval(.5,Math.pi)
3.1415926535897931

if you consider it safe to do a raw eval() you could use SymPy

king_kilr
May 25, 2007
I'm looking for a canvas library. Basically I'd like to emulate the HTML canvas element, specifically I need to be able to add polygons, whose color has an alpha channel/transparency, I need to be able to edit polygons on the canvas, and I need to be able to get the actual color for a given pixel. Basically I'm trying to implement http://alteredqualia.com/visualization/evolve/ in python :)

king_kilr
May 25, 2007
I'm super excited to say that my PyCon talk was accepted! It's a panel on ORM philosophies and design decisions with Jacob Kaplan-Moss, Ian Bicking, Mike Bayer, Guido van Rossum, and Massimo Di Pierro. I know we had a few other goons who submitted talk proposals, what were your results?

king_kilr
May 25, 2007

m0nk3yz posted:

Both of mine - an intro to multiprocessing, and the "state of concurrency and distributed systems w/ python" were accepted.

awesome, both of those sound super interesting, can't wait!

king_kilr
May 25, 2007

IntoTheNihil posted:

I literally just (an hour ago) jumped into programming with Python. Right now i'm using this and am up to the 5th part. I'm understanding it so far but I'm not holding much in my memory. Is there a better online tutorial or even book I should use or is this just normal confusion that goes away after using Python for a few weeks.

If you have some programming background dive into python is pretty good, otherwise I like the regular python tutorial.

king_kilr
May 25, 2007

tripwire posted:

Can someone help me get this stupid mona lisa approximator thing working? I've given up on trying anything remotely fancy and just mutate a list of floats which are the values used to draw triangles on a cairo canvas.

I'm using numpy to add up the squared difference between color values on each pixel and square rooting that to get the root mean square error.

For some reason my picture ALWAYS converges to some ridiculous garbage in a short amount of time which is frustrating, because it could mean either that my genetic algorithm is hosed up somehow (maybe I made a mistake with passing by reference vs passing by value somewhere?) or that the logic for my root mean square error code is hosed up.

Can anyone help me out?

I too tried to implement it(using Pyglet+OpenGL) and I had the same problem, here's my code: http://github.com/alex/evolves/tree/master

Perhaps we both have the same error in our code?

king_kilr
May 25, 2007

m0nk3yz posted:

thou shalt not prematurely optimize: http://bugs.python.org/issue5000

Heh, I just had some fun optimizing something myself: http://lazypython.blogspot.com/2009/01/optimizing-view.html :)

king_kilr
May 25, 2007

bitprophet posted:

2.6. 3.0 is extremely new and almost nothing has been ported to it yet. 2.6 will include some of the newer libraries/ideas present in 3.0, so you'll be better off for learning 3.0 than someone who's used to older verisons of Python. 3.0 will not be mainstream for at least a year or two (someone like m0nk3yz or king_kilr will have a better estimate, probably).

I can't really speak intelligently for other libraries but Django's current trajectory is to start having a 3.0 branch in about 1.5-2 years. That being said Martin Loewis has a patch available that combined with 2to3 brings Django to a usable state on 3.0, so if you had a pressing need(and it doesn't sound like you do) you could probably make it work.

king_kilr
May 25, 2007

m0nk3yz posted:

If you want cleanliness and purity; go with 3.0 (note that IO speeds suck) - if you want third party code, libraries and frameworks, go with 2.6.

Ultimately, to have strong python-fu, you'll need to know both.

To add to this, the hope is to have 3.1 or a beta out around PyCon, this continues a lot of the cleanup that defined 3.0(plus io speedups and another 20% speed increase).

king_kilr
May 25, 2007

deimos posted:

I am gonna ask the boss for PyCon, and I am pretty sure I am going to go regardless of job paying for it, at the very least for the conference.

That being said, this is discouraging.

m0nk3yz do you think it'll be better this year?

I attended last year and I really enjoyed it. This year I have the privilege of speaking and am once again really looking forward to it. One of the big things Bruce mentions, sponsored keynotes, I don't think we're having this year.

king_kilr
May 25, 2007

tripwire posted:

I guess they aren't too far apart, codepy just looks nice because you can build your code and compile + link it on the fly (i.e. have dynamically generated code), you don't have to dick around with makefiles and all that basically.

Cython can do that with the pyimportx module that it includes from .11 on, it can even try to compile ordinary python code and fall back to the raw interpretter if it can't handle that.

king_kilr
May 25, 2007

m0nk3yz posted:

Reminds me of another weird urge I had the other day; given stackless tasklets are picklable (as well as the channel), you could serialize them and put them into a database, and in theory, a SQL query of the objects in the database could actually dictate the "program structure". You just need an ORM that auto-depickles the objects and adds them to the scheduler. Store your channels in another table, and select those with the query too.

Yeah, no.

Isn't that part of the seaside framework, it pickles poo poo, stores it in the session or something like that, maybe I need to stop reading reddit while tired.

king_kilr
May 25, 2007
http://code.google.com/p/django-timezones/ may be just what you're looking for.

king_kilr
May 25, 2007
For those doing concurrency stuff I implemented futures in Python earlier today for those who may be interested: http://dpaste.com/11007/

king_kilr
May 25, 2007

Pooball posted:

ATLbeer, Thread.run() returns a Future object (see line 44). This is an object that proxies the real value.

I think line 43 should use "start" rather than "run" - run() just calls the handler synchronously.

To expand on this(because this was my revelation into how to do this), in Python everything about an object is in it's attributes. What does it mean for an object to be an integer? It means it acts like a number, we can display it, we can add it to other numbers, etc. Well in Python all it means to display something is for it to have an __str__ method, or to add an __add__ method. All being an integer means is that it walks, talks, and quacks like one.

king_kilr
May 25, 2007

tef posted:

I used pyodbc last time instead of pymssql, with a little more success.

http://code.google.com/p/pyodbc/


I dunno maybe there's still some working examples from the last time.

I think that's more likely to work, I know the django-pyodbc guys prefer it to -mssql and django uses unicode everywhere so I'm sure it does as well.

king_kilr
May 25, 2007

fnordcircle posted:

I'm working out of a python book that I burned about 75% of the way through, but I'm still feeling really, really hazy on some of the concepts and as many times as I've reread the big about classes my eyes still cross. I think I'd learn better from doing than reading, but powering through and moving on, trying to decipher the source code in this book it isn't getting any easier.

Does anyone have a suggestion for a book/online tutorial about python's implementation of classes so I can try to get a better handle on this?

checkout dive into python, it's a free online python book

king_kilr
May 25, 2007
For those who are interested in VM work or just want their Python faster this seems to be an intersting project: http://code.google.com/p/unladen-swallow/

king_kilr
May 25, 2007

m0nk3yz posted:

Interesting? It's pure awesome and win. I spoked to a few people about it today, and it's very very real. I could see this supplanting CPython-trunk quickly should they hit the goals for this year.

So jealous of people already at PyCon, one more day of class then I come home and join you guys no Friday. Looking forward to your talks, perhaps I'll see you there.

king_kilr
May 25, 2007

Scaevolus posted:

It would be awesome if they met all these goals (JIT & no GIL?!), but the pessimist in me says they'll lose steam before they reach any real results.

I hope they prove me wrong.

I too am a forever skeptic, however it appears that all of the group members are Google employees, and one of their members in a Cpython core contributer, so there's hope!

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007
For those curious as to why PyCon is the best conference ever, or wanting to see just what Mr. Monkeyz is up to: http://pycon.blip.tv/#1940650

  • Locked thread