Search Amazon.com:
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 $3,400 per month for bandwidth bills alone, and since we don't believe in shoving popup ads to our registered users, we try to make the money back through forum registrations.
«388 »
  • Post
  • Reply
m0nk3yz
Mar 13, 2002

Behold the power of cheese!



What is Python? (from http://www.python.org)
Python is a dynamic object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code.

Official Website: http://www.python.org/
Official Documentation: http://docs.python.org/
Python Quick references: http://rgruet.free.fr/
Semi-Official Python FAQ: http://effbot.org/pyfaq/
Official Python Cheeseshop: http://pypi.python.org/pypi
Official Python Wiki: http://wiki.python.org/moin/
Python development tools, including editors: http://wiki.python.org/moin/DevelopmentTools
Official Planet Python (weblogs): http://planet.python.org/
Unofficial Planet Python (more weblogs): http://www.planetpython.org/
Python Magazine: http://pythonmagazine.com/
Norvig's Infrequently asked questions: http://norvig.com/python-iaq.html - This man exemplifies elegant code. His solutions are just... beautiful.

Python tutorials and free online books:

What version should I use? Python 2.x or 3.x?
http://wiki.python.org/moin/Python2orPython3 - The offical website tells all

Alternative Python interpreter implementations

Python: Myths about Indentations: http://www.secnetix.de/~olli/Python...ndentation.hawk

Python Editors and IDEs: http://wiki.python.org/moin/PythonEditors (Although you should use VIM http://sontek.net/turning-vim-into-a-modern-python-ide)

More about Python web frameworks than you could ever want to know: http://wiki.python.org/moin/WebFrameworks - though, you should just stick to Django, or Flask. Seriously!

PyCon US!
PyCon US is the largest annual gathering for the community using and developing the open-source Python programming language. PyCon is organized by the Python community for the community. We try to keep registration far cheaper than most comparable technology conferences, to keep PyCon accessible to the widest group possible. http://us.pycon.org/2012/

There are many PyCons - or Python Conferences - throughout the world. You can find one, should the US one not be your cup of tea at: http://www.pycon.org/

m0nk3yz posted:

Why I like python: I enjoy both it's syntax, dynamic (latent) typing, standard library and truly enjoy programming in the language. I've been hacking in python for about (edit) 7 or 8 years at this point, and I have come to really enjoy the community and ecosystem around the language as well. Python is expressive and while I've run into bits of python code that make me WTF, I've rarely run into a chunk I couldn't read, or understand - you have to go out of your way (or be abusive with say, list comprehensions) to make python unreadable.

And just to pimp my own "Good to great Python reads": http://jessenoller.com/good-to-great-python-reads/

TasteMyHouse posted:

Since python is often recommended as a beginner's language (especially here in CoC) it'd be nice for there to be a short discussion / link to a discussion about interpreted vs compiled in general, the distinction between CPython and Python itself, etc. I know that stuff kind of confused me when I was looking at python and didn't know poo poo from poo poo.
http://programmers.stackexchange.co...ted-or-compiled
http://en.wikipedia.org/wiki/Interpreted_language
http://en.wikipedia.org/wiki/Python...mming_language)

m0nk3yz fucked around with this message at Aug 27, 2011 around 03:26

Adbot
ADBOT LOVES YOU

Bonus
May 12, 2007

im gay

Yeah I agree, Python is by far my favourite language. It's concise yet readable. It's just a joy to work in, I love how the modules work, the duck typing is great, all in all I really like it. Well, everything except the GIL in CPython, which basically prevents Python from running on multiple cores concurrently. However, there's a great module called Parallel Python which lets you do just that.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

Bonus posted:

Yeah I agree, Python is by far my favourite language. It's concise yet readable. It's just a joy to work in, I love how the modules work, the duck typing is great, all in all I really like it. Well, everything except the GIL in CPython, which basically prevents Python from running on multiple cores concurrently. However, there's a great module called Parallel Python which lets you do just that.

That's only partially true: Python can use multiple cores, python threads can not (sort of, unless they're caught in a c module that's released the gil or blocking I/O), as shown by effbot's recent wide-finder experiment (http://effbot.org/zone/wide-finder.htm). If you fork processes you can easily make use of multiple cores. Of course, fork/exec means you loose the shared context of pthreads.

I personally prefer the Processing (http://pypi.python.org/pypi/processing/) module over the parallel python module, it's thread-API compatible which at least for most of my applications means it is a drop-in replacement.

As for the GIL, yes, the cPython interpreter has a GIL which is primarily a Python Dev feature, however there are talks and projects to add something like Parallel Python/Processing.py to the stdlib (I'm considering doing a PEP for Processing) and adding a patch set to Python 3000 that allows for free-threading.

More on the GIL:
GvR: http://www.artima.com/weblogs/viewp...p?thread=214235
Brett Cannon: http://sayspy.blogspot.com/2007/11/...oncurrency.html
Bruce Eckel: http://www.artima.com/weblogs/viewp...p?thread=214303

m0nk3yz fucked around with this message at Nov 5, 2007 around 00:45

N.Z.'s Champion
Jun 8, 2003

what's hara kiri?


After hating on the XML processing in Python (4suite is sluggish and buggy) I found LXML and P4X. So use them unless you want to break your brain.

Docvert converts MS Word to any HTML/XML.

N.Z.'s Champion fucked around with this message at Nov 4, 2007 around 23:30

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

N.Z.'s Champion posted:

After hating on the XML processing in Python (4suite is sluggish and buggy) I found LXML and P4X. So use them unless you want to break your brain.

Which version of Python were you using? For my XML needs I've loved elementtree (and it's brother, cElementtree). Elementtree is now in the stdlib as of 2.5.

N.Z.'s Champion
Jun 8, 2003

what's hara kiri?


m0nk3yz posted:

Which version of Python were you using?

2.4 and 2.5, but that doesn't really change the crappiness of 4suite xml processing (which is all I'm trying to warn people off).

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!


m0nk3yz posted:

That's only partially true: Python can use multiple cores, python threads can not, as shown by effbot's recent wide-finder experiment (http://effbot.org/zone/wide-finder.htm). If you fork processes you can easily make use of multiple cores. Of course, fork/exec means you loose the shared context of pthreads.

Another thing that Fredrik's article pointed me towards when I first read it was defaultdicts, which are, in few words, loving awesome. So much so that I went back through all my code looking for places to use them.

edit: OP: you might want to add this link up there:
Effbot's Python Standard Library book.

deimos fucked around with this message at Nov 5, 2007 around 00:49

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.

inveratulo
May 14, 2002
wat

Here's my question:

I am currently developing a web application that functions as sort of a spreadsheet. The client-side displays a dynamic table that the user can interact with and it works with a server-side db (MySQL).

I already wrote the bulk of the program in java, but uses the clientside JVM for everything, and it has gotten unwieldy very fast. So now I'm considering rewriting the whole thing using Python as a backend, preferably with things that belong serverside on the server.

I have considered the following options:
CGI - no this just won't do. I need more than i/o streams and i'm not the best html/css programmer anyway
Jython - halfway to python, but still enough java to give me a headache. Plus there are some performance concerns.
Frameworks like Zope or Django - these seem to have some kind of barrier to entry, lot of gotchas and I'm not sure I want to deal with those headaches just yet.
Pyjamas - seemed like the best option at a glance, but I had problems getting the libraries to work properly; plus with one developer and no updates in a year I don't know if it is worth getting in to anymore.
Google Web Toolkit (ajax) - this would be my ideal frontend. Uses native browser calls so its fast but unfortunately it does not support non-java backends. I've snooped around looking for python implementations, but so far have come up empty handed.

At this point I'm kinda scratching my head. I really want to use Python for this project, but it looks like to do that I will have to use a real python web framework, which just seems like overkill for what was supposed to be a neat and tidy app.

I'm just on the lookout for implementations that fit my needs without too much overkill. I guess if it comes down to it, I can get knee-deep into Django and make it work; but I'm open to any and all other suggestions.

Any recommendations/suggestions/warnings?

inveratulo fucked around with this message at Nov 5, 2007 around 07:24

Git
Aug 21, 2004



inveratulo posted:

At this point I'm kinda scratching my head. I really want to use Python for this project, but it looks like to do that I will have to use a real python web framework, which just seems like overkill for what was supposed to be a neat and tidy app.

You don't have to use a web framework to use Python for a web-app. You can, if you're so inclined, use Python Server Pages. They pretty much have you writing Python directly in your pages in a manner sort of akin to PHP.

Really though, Django might be overkill but it makes development fly by. I can't recommend it enough, but if you're absolutely certain that it won't suit, you might do well to look at the smaller frameworks like Pylons or CherryPy. Actually, you've a hell of a lot of frameworks you could choose from if any one doesn't suit.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!


inveratulo posted:

Frameworks like Zope or Django - these seem to have some kind of barrier to entry, lot of gotchas and I'm not sure I want to deal with those headaches just yet.

I can tell you this much: django can be as unobtrusive as you want it to be. The only thing you really can't change is the ORM, but it's also unobtrusive since you can do raw SQL with it.

Git posted:

Really though, Django might be overkill but it makes development fly by. I can't recommend it enough, but if you're absolutely certain that it won't suit, you might do well to look at the smaller frameworks like Pylons or CherryPy. Actually, you've a hell of a lot of frameworks you could choose from if any one doesn't suit.

Pylons is nice and very adaptable, but I prefer django since it comes with good standards for everything and if you don't like one aspect you can change it rather easily (I've use cheetah for my templating language, for example).

bitprophet
Jul 22, 2004



deimos posted:

I can tell you this much: django can be as unobtrusive as you want it to be. The only thing you really can't change is the ORM, but it's also unobtrusive since you can do raw SQL with it.

Not entirely true. Sure, if you don't use its ORM you lose the generic views and the admin (basically, the nice "extras") but it's entirely possible to just use its URL mapping + view functions + templating and use e.g. SQLAlchemy to populate the template contexts.

And, yea, the ORM is pretty flexible in general, it's possible to tweak most aspects of the generated SQL with a ".extra()" method on the query objects (e.g. adding WHERE clauses), and as you said, you can use 100% raw SQL alongside the ORM if those don't do the trick.

Ugg boots
Jul 8, 2004


deimos posted:

defaultdicts

Man, and I didn't even know I was missing these!

Defaultdicts are my new favorite coding-toy-of-the-week, now.

duck monster
Dec 15, 2004



Python Webware is kind of nice for a pretty straight J2EE/Tomcat style servlet system. Nice folks too.

Also, if coding for it Think ahead, about how your doing database. This poo poo is multithreaded and therefore has gotchas.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?


What's the Python community like? Do you guys really hate Perl? And have you ever heard of or used SQL Alchemy?

I went to one Python Users Group meeting and everyone had something nasty to say about Perl. And the presenter there was my former boss, creator of SQL Alchemy.

duck monster
Dec 15, 2004



Triple Tech posted:

What's the Python community like? Do you guys really hate Perl? And have you ever heard of or used SQL Alchemy?

I went to one Python Users Group meeting and everyone had something nasty to say about Perl. And the presenter there was my former boss, creator of SQL Alchemy.

Don't really interact with the Python community a lot.

I guess folks who really 'think' pythonic tend to see PERL as extremely clumsy and inelegant. Sort of a huge chainsaw to pythons clean scalpel.

But most of us admit that sometimes when theres a wall, the Chainsaw will bust that hole pretty drat fast. It'll just be an ugly hole.

That and turf war nonsense.

saiyr
May 23, 2004


Git posted:

Really though, Django might be overkill but it makes development fly by. I can't recommend it enough, but if you're absolutely certain that it won't suit, you might do well to look at the smaller frameworks like Pylons or CherryPy. Actually, you've a hell of a lot of frameworks you could choose from if any one doesn't suit.
Hmm, I don't really think Pylons is "small". It's small in the sense that you can swap out a lot of components, and the core code isn't really that big, but it's still very Rails-like/big. CherryPy is a bit more manageable. Web.py is pretty small as well. Reddit used it for one of their billions of rewrites and rewrote the entire site in a weekend or something.

bitprophet
Jul 22, 2004



Triple Tech posted:

What's the Python community like? Do you guys really hate Perl? And have you ever heard of or used SQL Alchemy?

I went to one Python Users Group meeting and everyone had something nasty to say about Perl. And the presenter there was my former boss, creator of SQL Alchemy.

That wasn't in New York, was it?

We don't "hate" anybody, generally - most of us like Python because it's awesome, rather than actively disliking other languages. That said, I've noticed a fair number of Pythonistas are former Perl monks, and that means those folks are generally very aware of the difference between Perl's "executable line noise" (exaggerated or no, it's still got a reputation for being messy) and Python's emphasis on clean, readable syntax. If they're still with Python now that means they prefer the latter over the former, and thus will gripe about the "bad old days" when they had to try and read their 6-month-old Perl scripts.

In general I like the Python community because it has an overall positive attitude, and there are a lot of smart people who ended up here after spending time solving problems with other languages, and are thus very happy to be able to focus exclusively on doing that instead of wrestling with syntax or whatnot. There's a lot of emphasis on doing things "the right way" and that tends to pervade the community, from what little I've seen.

Honestly, though, I don't interact with the community as much as I should, and definitely ought to add more blogs to my RSS feed I also don't have much experience in other communities, period, and can't contrast it too much with others outside of "PHP has lots of newbies", "Perl has lots of sysadmins", "Ruby has lots of arrogant twats*", etc.

* OK, only some of them. I work in a half-Rails shop and most of the devs here are pretty down to earth.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?


bitprophet posted:

That wasn't in New York, was it?

You know too much... And must be... taken care of... (yes it was, I was the one who walked in late)

contingencyplan
Nov 1, 2006
Ivory Tower Theorist

m0nk3yz posted:

Python Magazine: http://pythonmagazine.com/

Yeah, heard about this magazine coming out a while back. Looked and saw the price tag ($70 Canadian) and thought "why the hell is this magazine so expensive?"

Ugg boots
Jul 8, 2004


So, I'm working on a game for a class, in PyGame, and I had a question about Python:

I have several objects each with a common property (HitRectangle.) I have a collision detection algorithm working fine, but I'd like to have it so it calls a different collision method based on the types of the two collided objects. Since this will be called several times per frame, I'd like it to be as fast as possible, but really I don't know where I want to start.

The only real idea I had was to create a member variable called Type or something for each object, then compare two objects' Type strings and then determine which function to call, but it seems like there should be an easier way.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!


Ugg boots posted:

So, I'm working on a game for a class, in PyGame, and I had a question about Python:

I have several objects each with a common property (HitRectangle.) I have a collision detection algorithm working fine, but I'd like to have it so it calls a different collision method based on the types of the two collided objects. Since this will be called several times per frame, I'd like it to be as fast as possible, but really I don't know where I want to start.

The only real idea I had was to create a member variable called Type or something for each object, then compare two objects' Type strings and then determine which function to call, but it seems like there should be an easier way.

You can't use type(obj)?

Ugg boots
Jul 8, 2004


deimos posted:

You can't use type(obj)?

Not sure how fast that is, and additionally I may have some derived classes that I'll want to "inherit" the collision method of their parent.

Hmm, actually, what if I make a dictionary of tuples, (type1, type2) with the value being the method to call, then to know what method to call I just call dict[(type1, type2)] for however I determine to figure out the type.

No Safe Word
Feb 26, 2005

I sure do love holding onto the rock!

deimos posted:

You can't use type(obj)?

Really you want to use isinstance (sometimes in conjunction with type), because that handles inheritance better and is just in general more robust.
code:
>>> class A:
...     pass
...
>>> class B(A):
...     pass
...
>>> foo = A()
>>> bar = B()
>>> isinstance(bar, A)
True
>>> isinstance(bar, B)
True
>>> isinstance(foo, A)
True
>>> isinstance(foo, B)
False

Ugg boots
Jul 8, 2004


No Safe Word posted:

Really you want to use isinstance (sometimes in conjunction with type), because that handles inheritance better and is just in general more robust.

Thanks, I think I've got a reasonable prototype working.

duck monster
Dec 15, 2004



The other method is to just ask the object

code:

class ancestor:
        def method1(self):
                 print "called method1"

        def method2(self):
                 print "called method2"

class sprite1(ancestor):
        apropriatemethod = self.method1

class spite2(ancestor):
        apropriatemethod = self.method1

class sprite3(ancestor):
        apropriatemethod = self.method2


>> x = sprite1()
>> x.apropriatemethod()
called method1
>> y = sprite3()
>> y.apropriatemethod()
called method2
Note thats off the top of my head. Probably typos in there

duck monster fucked around with this message at Nov 12, 2007 around 22:36

Ugg boots
Jul 8, 2004


duck monster posted:

Note thats off the top of my head. Probably typos in there

Thanks for the help, but it's not quite that applicable for my problem, because I'm dealing with collisions between two different objects (of different types.)

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.


Ugg boots posted:

Thanks for the help, but it's not quite that applicable for my problem, because I'm dealing with collisions between two different objects (of different types.)

Google for "multimethods in python". You probably won't want as many indirections and searches as most of the implementations would likely have, but it should give you an idea of how to structure some well-thought out look up tables or whatever solution you decide upon.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

Just to share, here's some good reading on Python Metaclasses:

http://markshroyer.com/blog/2007/11...lass-windmills/
http://www.ibm.com/developerworks/l...y/l-pymeta.html
http://en.wikibooks.org/wiki/Progra...hon_MetaClasses

Digital Spaghetti
Jul 8, 2007
I never gave a reach-around to a spider monkey while reciting the Pledge of Alligence.

Ohh, very handy this thread has come up. I've been looking at Django for a while, and I'm thinking of switching my project from CakePHP to Django - but I must admit I can't find any "nice" tutorials to get me started - Apart from the Django site and book, can anyone recommend any good resources for it for a beginner at Python?

Misogynist
Jul 14, 2003



Is there any really good standard library reference for Python? Compared to Ruby, the official documentation absolutely sucks, and it's really frustrating me because I absolutely adore the Pylons framework and then doing more menial Python stuff in the framework is comparatively painful.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!


Mr. Heavy posted:

Is there any really good standard library reference for Python? Compared to Ruby, the official documentation absolutely sucks, and it's really frustrating me because I absolutely adore the Pylons framework and then doing more menial Python stuff in the framework is comparatively painful.

http://effbot.org/librarybook/

I posted it earlier but OP hasn't added it.

No Safe Word
Feb 26, 2005

I sure do love holding onto the rock!

Digital Spaghetti posted:

Ohh, very handy this thread has come up. I've been looking at Django for a while, and I'm thinking of switching my project from CakePHP to Django - but I must admit I can't find any "nice" tutorials to get me started - Apart from the Django site and book, can anyone recommend any good resources for it for a beginner at Python?

http://code.djangoproject.com/wiki/DjangoResources - this has tons of other links that are more specific
http://blixtra.org/blog/2006/07/17/...s-and-articles/ - this is actually on that link but has other unique links

dorkanoid
Dec 21, 2004



Mr. Heavy posted:

Is there any really good standard library reference for Python? Compared to Ruby, the official documentation absolutely sucks, and it's really frustrating me because I absolutely adore the Pylons framework and then doing more menial Python stuff in the framework is comparatively painful.

I you're using Windows, pywin32 includes a nice .chm of the official documentation, with the usual fast keyword searching of a Windows help file.

Threep
Apr 1, 2006

It's kind of a long story.

Convince me to learn Python!

I somehow skipped by Python back when it was still in its youth and only recently decided that maybe I ought to give it a look.

Trouble is that I've now picked up Ruby and while it would've been easy to give up PHP or Perl in favour of Python it's a bit harder when I've already got a language I actually like and not just tolerate.

However, it seems to me that Python's maturity and much better support would be beneficial, so since this is the Python thread I'd like to hear someone with experience in both tell me why they've chosen Python.

I'm using Ruby both for Linux scripting/utilities and for web development.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

deimos posted:

http://effbot.org/librarybook/

I posted it earlier but OP hasn't added it.

It was/is added

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!


m0nk3yz posted:

It was/is added

I am blind, sorry.


Now more on topic: woop, properties for 2.6 and 3k: http://bugs.python.org/issue1416

duck monster
Dec 15, 2004



Threep posted:

Convince me to learn Python!

I somehow skipped by Python back when it was still in its youth and only recently decided that maybe I ought to give it a look.

Trouble is that I've now picked up Ruby and while it would've been easy to give up PHP or Perl in favour of Python it's a bit harder when I've already got a language I actually like and not just tolerate.

However, it seems to me that Python's maturity and much better support would be beneficial, so since this is the Python thread I'd like to hear someone with experience in both tell me why they've chosen Python.

I'm using Ruby both for Linux scripting/utilities and for web development.

I can convince you really easy. Do this tutorial;-
http://docs.python.org/tut/tut.html
It'll take you a few hours to an afternoon

At the end of it you combine that knowledge with this page;-
http://docs.python.org/modindex.html

And you are now full bottle.

Thats the convincing. If you can't program python vaguely competently in a couple of days, you probably are not a coder. Its that easy.

Its all about objects, lists, dictionaries and tuples

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

deimos posted:

I am blind, sorry.


Now more on topic: woop, properties for 2.6 and 3k: http://bugs.python.org/issue1416

Nice, I totally missed that one. I am quite happy with what's coming down the pipe for py3k

Adbot
ADBOT LOVES YOU

duck monster
Dec 15, 2004



m0nk3yz posted:

Nice, I totally missed that one. I am quite happy with what's coming down the pipe for py3k

Ah. Nice. Much more elegant than the get_foo set_foo stuff.

I'm really keen on this decorator stuff. Lots of oportunities for aspect coding type stunts.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply
«388 »