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
m0nk3yz
Mar 13, 2002

Behold the power of cheese!

Bozart posted:

This, 1000 times.

IANAWU (I am not a windows user) - but during the 2.6 release process, I had some multiprocessing bugs that came up on windows I needed to break the vmware out for. I can not even begin to image the pain of regular windows users when it comes to the windows build process. I eventually gave up, winged the patch and deleted the VM. Also, gently caress mingw.

Adbot
ADBOT LOVES YOU

bitprophet
Jul 22, 2004
Taco Defender

m0nk3yz posted:

IANAWU (I am not a windows user) - but during the 2.6 release process, I had some multiprocessing bugs that came up on windows I needed to break the vmware out for. I can not even begin to image the pain of regular windows users when it comes to the windows build process. I eventually gave up, winged the patch and deleted the VM. Also, gently caress mingw.

I tend to roll my eyes whenever David Hanssen (the Rails guy) speaks, but he said something relatively fitting a couple years ago, something about how "web developers who continue choosing to develop primarily on Windows will become increasingly marginalized", and I think that sentiment can be extended generally (not just Web development).

Unix (and by extension OS X, system framework problems aside) is just such a better development environment in almost every fashion. It's a real shame Microsoft had to do their own thing back when they started DOS/Windows; I'm imagining a world where they did what Apple did circa 2001, and took Unix and put their own stuff on top of it. It'd be a very different climate, I feel (although I doubt they'd approach it quite the same way Apple did).

/derail

tef
May 30, 2004

-> some l-system crap ->

bitprophet posted:

I'm imagining a world where they did what Apple did circa 2001,

Lets all run Xenix and AUX

Bozart
Oct 28, 2006

Give me the finger.

m0nk3yz posted:

IANAWU (I am not a windows user) - but during the 2.6 release process, I had some multiprocessing bugs that came up on windows I needed to break the vmware out for. I can not even begin to image the pain of regular windows users when it comes to the windows build process. I eventually gave up, winged the patch and deleted the VM. Also, gently caress mingw.

This literally made me reinstall linux after staying with windows for 3 years.

deimos
Nov 30, 2006

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

bitprophet posted:

I tend to roll my eyes whenever David Hanssen (the Rails guy) speaks, but he said something relatively fitting a couple years ago, something about how "web developers who continue choosing to develop primarily on Windows will become increasingly marginalized", and I think that sentiment can be extended generally (not just Web development).


:cry: my company is an ASP.NET shop and they haven't upgraded to 2008 yet because it actually costs money to upgrade the IDE because in order to write the programs you need so much boilerplate automagically done by the IDE it's not even funny.

bitprophet
Jul 22, 2004
Taco Defender

tef posted:

Lets all run Xenix and AUX

I hope you're just being silly and aren't missing the fact that I'm alluding to OS X :) A/UX is a cute historical footnote but isn't what I was going for.

tef
May 30, 2004

-> some l-system crap ->
I guess what I'm trying to say that both companies have dabbled in unix before.

bitprophet
Jul 22, 2004
Taco Defender

tef posted:

I guess what I'm trying to say that both companies have dabbled in unix before.

Right, but Apple has actually gone a very long ways with it now and made a very compelling OS with the idea; Microsoft hasn't. Anyway...this is no longer Python related, so I'll shut up now :)

duck monster
Dec 15, 2004

ahem

http://www.andlinux.org/

Basically installs linux as a windows process. Note: Not a VM, its a linux kernel that runs on windows, and it all works rather well. Similar sort of experience to parallells on the mac I guess.

edit: Or just run parallells on a mac :hellyeah:

cowboy beepboop
Feb 24, 2001

How do you reset an iterator in a for loop?
code:
switch = True

for i in range(0, 5):
	print i

	if (i == 4) and (switch == True):
		i = 0
		switch = False
Why doesn't this loop twice?

saiyr
May 23, 2004

my stepdads beer posted:

How do you reset an iterator in a for loop?
code:
switch = True

for i in range(0, 5):
	print i

	if (i == 4) and (switch == True):
		i = 0
		switch = False
Why doesn't this loop twice?
I think you're stuck in C mode, where at the end of the loop you do i++. Python simply assigns the next value in the iterator to i until no values remain, which is why it doesn't loop twice. It's probably cleaner to put the number of repetitions you want in an outer loop, instead:

code:
for j in range(2):
    for i in range(5):
        print i

cowboy beepboop
Feb 24, 2001

Yeah, I'm coming from C. Thanks for the quick response!

hey mom its 420
May 12, 2007

2.6 is out, w00t!

m0nk3yz
Mar 13, 2002

Behold the power of cheese!
Yup, as Bonus pointed out, 2.6 is live: http://www.python.org/download/releases/2.6/

I posted a bit of info about the changes, and the MP package too: http://jessenoller.com/2008/10/02/python-26-is-released/

deimos
Nov 30, 2006

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

bitprophet
Jul 22, 2004
Taco Defender
Congrats m0nk3yz (and the rest of the core team obviously)! :toot:

I wish I was more excited, though; I'm not even making use of everything new in 2.5, and it feels like only yesterday that 2.5 even became widely available in package managers, versus 2.4. So it's not like I'll realistically be able to make use of 2.6 in a "run on something that's not my personal workstation" capacity for goodness knows how long :(

Still! The road to 3.0...

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

bitprophet posted:

Congrats m0nk3yz (and the rest of the core team obviously)! :toot:

I wish I was more excited, though; I'm not even making use of everything new in 2.5, and it feels like only yesterday that 2.5 even became widely available in package managers, versus 2.4. So it's not like I'll realistically be able to make use of 2.6 in a "run on something that's not my personal workstation" capacity for goodness knows how long :(

Still! The road to 3.0...

I know, that's what sucks. One of the biggest reasons we dropped 3.0 on the floor was to get 2.6 done soon enough to be able to be included in things like Snow Leopard, and the rest of the OS ecosystem.

todesschaf
Nov 6, 2006
Sheep of Death!
Hooray, python 2.6! (Too bad we probably won't start using it at work until some time after the heat death of the universe.)

Now, a question: does anyone know of an already-existing SOAP filter (2.2) or hook (3.0) for cherrypy? I'm sticking a SOAP API into an existing cherrypy URL tree, and I would prefer to not have to hack one together myself out of SOAPpy or something similar. Thanks!

ATLbeer
Sep 26, 2004
Über nerd
I have a huge array (400k+) of dicts that I'm trying to work with without iterating over the list multiple times since it's a time-sensitive execution. I'm trying to just break out the value of the dictionary back into the array.

[{'DxY': 17L}, {'DxY': 9L}, {'DxY': 8L}, ............ {'DxY': 7L}, {'DxY': 6L}, {'DxY': 4L}]

What I want is [17L, 9L, 8L, ..........., 7L, 6L, 4L] but, without having to do something like
code:
new_array = []
for x in big_list:
    new_array.append(x['DxY'])
Well.. I should probably tack on what I need as an end result since there might be a way to do it without constructing new data structures on the fly here.

The list I'm receiving is already sorted and I'm trying to find out what position a new integer would be in the list. I don't need to insert it just identify the position. I was planning on using bisect to identify the position in the array since it's a pretty optimized function

ATLbeer fucked around with this message at 16:09 on Oct 2, 2008

hey mom its 420
May 12, 2007

Use generators! (What a surprise! :v: )
code:
>>> big_list = [{'DxY':17L}, {'DxY':9L}, {'DxY':199L}]
>>> new_list_gen = (a['DxY'] for a in big_list)
Then you can iterate over new_list_gen. No new copies of big_list are created.

ATLbeer
Sep 26, 2004
Über nerd

Bonus posted:

Use generators! (What a surprise! :v: )
code:
>>> big_list = [{'DxY':17L}, {'DxY':9L}, {'DxY':199L}]
>>> new_list_gen = (a['DxY'] for a in big_list)
Then you can iterate over new_list_gen. No new copies of big_list are created.

Grr... I always forget about generators. I need to just write a few hundred and play with them so they get stuck in my head.

Unfortunately in this case (I updated my OP) I don't know if a generator is going to be the best solution since I don't need (or really want) to iterate over the list I need to search through the list.

Or do I need to get another coffee?

vvv I'm not storing them that way. I'm just getting them that way. I'm looking at trying to solve it upstream

ATLbeer fucked around with this message at 16:43 on Oct 2, 2008

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

ATLbeer posted:

I have a huge array (400k+) of dicts that I'm trying to work with without iterating over the list multiple times since it's a time-sensitive execution. I'm trying to just break out the value of the dictionary back into the array.

[{'DxY': 17L}, {'DxY': 9L}, {'DxY': 8L}, ............ {'DxY': 7L}, {'DxY': 6L}, {'DxY': 4L}]

Are the dicts always 1 entry, with the key DxY? Why are you even storing them like this, since the DxY is constant?

hey mom its 420
May 12, 2007

Then you can just implement normal bisection on the list that you have, only instead of doing your_list[x], you do your_list[x]['DxY'].

Bozart
Oct 28, 2006

Give me the finger.

m0nk3yz posted:

Yup, as Bonus pointed out, 2.6 is live: http://www.python.org/download/releases/2.6/

I posted a bit of info about the changes, and the MP package too: http://jessenoller.com/2008/10/02/python-26-is-released/

I gotta say the MP package looks great. This will probably be the first thing I play around with in 2.6

duck monster
Dec 15, 2004

Oh hey the BSD DB lib is getting axed in 3.0... Did anyone ever actually use that thing for anything? I'd of thought that SQLlite has been the flat file db of choice for a while now

ATLbeer
Sep 26, 2004
Über nerd

Bonus posted:

Use generators! (What a surprise! :v: )
code:
>>> big_list = [{'DxY':17L}, {'DxY':9L}, {'DxY':199L}]
>>> new_list_gen = (a['DxY'] for a in big_list)
Then you can iterate over new_list_gen. No new copies of big_list are created.

4x factor improvement... I'm def going to start practicing generators

deimos
Nov 30, 2006

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

duck monster posted:

Oh hey the BSD DB lib is getting axed in 3.0... Did anyone ever actually use that thing for anything? I'd of thought that SQLlite has been the flat file db of choice for a while now

One of the problems with it is the lack of maintenance, no one takes care of it, so it's just gonna split from the main core, if someone needs it they can make it a module.

deimos
Nov 30, 2006

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

bitprophet posted:

Congrats m0nk3yz (and the rest of the core team obviously)! :toot:

I wish I was more excited, though; I'm not even making use of everything new in 2.5, and it feels like only yesterday that 2.5 even became widely available in package managers, versus 2.4. So it's not like I'll realistically be able to make use of 2.6 in a "run on something that's not my personal workstation" capacity for goodness knows how long :(

Still! The road to 3.0...

While I agree, 2.5 does have basically one of the better things of 2.6 which is context managers. Also 2.6 starts moving towards more PEP8 compatibility and the new print() which is always a good thing. 2.6 is more of a revision IMHO but a good solid step forward.

bitprophet
Jul 22, 2004
Taco Defender

deimos posted:

While I agree, 2.5 does have basically one of the better things of 2.6 which is context managers. Also 2.6 starts moving towards more PEP8 compatibility and the new print() which is always a good thing. 2.6 is more of a revision IMHO but a good solid step forward.

That's true, a few of the 2.6 stuff leaked into 2.5, didn't it...and yes, I'm well aware that 2.6 is largely a stepping-stone release to help folks get onto 3.0, but I still won't be able to do stuff like aforementioned new print() until I can expect to use 2.6 everywhere. Poop.


Ironically...this may matter less as I find myself moving at least partially into the Ruby/Rails camp, due to my job (Rails and PHP shop, and christ do I hate PHP, and sadly can't spend 100% of my time doing my sysadmin duties). Speaking of which, I plan to "open up" a blog (don't have one yet) with a series of posts comparing -- at a realistic, daily-usage level -- the two ecosystems (Ruby/Rails vs Python/Django).

I haven't seen anything else at this level, just high level overviews, which makes sense -- I expect very few people would ever be in my situation, being well versed in one framework but essentially "forced" to become fluent in another. Most people will get good at one and then stick with it due to simple inertia if nothing else.

Anyone find that idea interesting? Wonder if it would make sense to do it as a thread here instead -- I definitely plan to get feedback, somehow, from both sides, as I expect to miss or misunderstand some stuff :)

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
Sounds really interesting - be sure to submit it to sn.printf.net so it shows up in my goon feed.

deimos
Nov 30, 2006

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

bitprophet posted:

I haven't seen anything else at this level, just high level overviews, which makes sense -- I expect very few people would ever be in my situation, being well versed in one framework but essentially "forced" to become fluent in another. Most people will get good at one and then stick with it due to simple inertia if nothing else.

I am stuck doing ASP.NET 2.0 (VS 2k5) and I miss django so much.

SlightlyMadman
Jan 14, 2005

So I just decided to give pyglet another shot, since everyone here was raving about how much the sprite performance has improved. I wrote a simple program to display 400 sprites on the screen, and I'm only getting about 15fps.

I think I might be doing it wrong though. I'm creating and populating a new sprite batch in my draw method, because eventually I'll be moving around the screen and replacing sprites with new ones and such.

Should I actually be keeping a static sprite batch and manually updating the properties of the sprites in every iteration of my draw method? Seems like a really wonky way of doing things.

edit:
Actually, I just tried that and it's not much better. If I only create as many sprites as are on the screen, it's great, but since I'm keeping a static batch, I need to create sprites for all the off-screen objects instead, and that seems to slow it down horribly. I guess I could remove the sprites from the batch when they go off the screen, and add them back in when they come back on? Seems like an awful lot of work compared to sprites in pygame though.

SlightlyMadman fucked around with this message at 21:46 on Oct 2, 2008

tef
May 30, 2004

-> some l-system crap ->

JoeNotCharles posted:

Sounds really interesting - be sure to submit it to sn.printf.net so it shows up in my goon feed.

I added m0nk3ys blog to sn.printf.net, on the asumption he doesn't mind being associated with goons :shobon:

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

deimos posted:

While I agree, 2.5 does have basically one of the better things of 2.6 which is context managers.

OK, I surrender. What's a "context manager"?

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

tef posted:

I added m0nk3ys blog to sn.printf.net, on the asumption he doesn't mind being associated with goons :shobon:

It's all good :)

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

outlier posted:

OK, I surrender. What's a "context manager"?

Well that's a loaded question :) - it's funny, I wrote an article on context managers for Python Magazine, it was in the July issue. In a nutshell, Context Managers came about with PEP 343 (http://www.python.org/dev/peps/pep-0343/)- PEP 343 defines a new keyword "with", which allows you to refactor the normal:
code:
try:
    ...
finally:
    ...
Code blocks into something like this:
code:
with EXPRESSION [as VARIABLE]: 
    BLOCK OF CODE 
The pep defined two new dunder methods - __enter__ and __exit__ for objects, this means what when you enter the BLOCK OF CODE as shown above, the __enter__ method is called, and when that block completes, the __exit__ is called. Additionally, __enter__ methods can return some variable which is where the "as VARIABLE" comes into play.

Here's one of my favorite examples:
code:
from Queue import Queue

class ThreadPool(object):
    def __init__(self, workers, workerClass):
        self.myq = Queue()
        self.workers = workers
        self.workerClass = workerClass
        self.pool = []

    def __enter__(self):
        # On entering, start all the workers, who will block trying to
        # get work off the queue
        for i in range(self.workers):
            self.pool.append(self.workerClass(self.myq))
        for i in self.pool:
            i.start()
        return self.myq

    def __exit__(self, type, value, traceback):
        # Now, shut down the pool once all work is done
        for i in self.pool:
            self.myq.put('STOP')
        for i in self.pool:
            i.join()
This is a simple context manager compatible class which can be used like this:
code:
from __future__ import with_statement
...

with ThreadPool(10, myThreadClass) as theQueue:
    for i in range(100):
        theQueue.put(i)
In this example, I'm constructing a new ThreadPool, and passing it in the number of threads to use, and the class (which would subclass threading.Thread) to call .run() on. The __enter__ method on the class will return a Queue.Queue object to the inner block, named theQueue which allows me to push things into the ThreadPool's internal queue.

When I am done putting things to be processed in the queue, and the inner function exits - the __exit__ method is called, and the queue is shut down gracefully.

In order to use context managers - you don't need to create your own classes, you can instead use contextlib to decorate functions which can yield control internally to achieve the same effect.

For more on contextlib, see: http://blog.doughellmann.com/2008/05/pymotw-contextlib.html

Hope that helps.

tbradshaw
Jan 15, 2008

First one must nail at least two overdrive phrases and activate the tilt sensor to ROCK OUT!

m0nk3yz posted:

I wrote an article on context managers for Python Magazine, it was in the July issue.

I love that magazine, and I loved your article. (Had no idea about the goon connection.)

Lurchington
Jan 2, 2003

Forums Dragoon
I've been writing stuff in python pretty much every day for a year and it's only now coming to my attention how little of the language I'm actually using day-to-day. Context management seems exciting and I'm looking forward to getting better.

I think this was floated earlier in reference to podcasts, but what are the python RSS I should consider staying with. I think I'm interested in items similar to "here's a feature you might be under-utilizing, and here's why it's useful."

Lurchington fucked around with this message at 03:09 on Oct 6, 2008

Allie
Jan 17, 2004

Sounds like you'd enjoy the Python Module of the Week. It runs the gamut from the mundane parts of the standard library to stuff you didn't even realize existed. The articles are pretty thorough and include example code.

There's also Planet Python (and its unofficial counterpart) if you want to keep up on what any number of people on the web are blogging about.

Adbot
ADBOT LOVES YOU

Lurchington
Jan 2, 2003

Forums Dragoon
Thanks for both of those. I need something informative to balance out 5 simulataneous listings for a new Gameboy DS color scheme

  • Locked thread