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
nbv4
Aug 21, 2002

by Duchess Gummybuns

Scaevolus posted:

I ran into this bug yesterday.

code:
class LeakyDict(dict):
    def __init__(self):
        dict.__init__(self)
        self.__dict__ = self


while True:
    a = LeakyDict()
I'm annoyed that they've had a patch to fix it for 3+ years and haven't committed it yet.

don't ya hate it when your dict leaks?

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007
I... how the hell do you run into that.

nbv4
Aug 21, 2002

by Duchess Gummybuns

king_kilr posted:

I... how the hell do you run into that.

for me it was from my last visit to juarez :roflolmao:

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
Does anyone have any ideas for how to get the file sizes for a large number of files (all recursive files under a root directory)?

Right now I'm using os.walk and os.path.getsize - but it becomes pretty slow after a couple thousand files.

My next thought was to parse the output of ls (or dir) - but I was hoping I could avoid that but have the same performance.

tripwire
Nov 19, 2004

        ghost flow

supster posted:

Does anyone have any ideas for how to get the file sizes for a large number of files (all recursive files under a root directory)?

Right now I'm using os.walk and os.path.getsize - but it becomes pretty slow after a couple thousand files.

My next thought was to parse the output of ls (or dir) - but I was hoping I could avoid that but have the same performance.

du /*

Scaevolus
Apr 16, 2007

king_kilr posted:

I... how the hell do you run into that.

I wanted a dict where I could access keys as attributes (because it looks nicer), and that "solution" is shorter than the proper one where you overload __gettattr__ and __setattr__ :downs:

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Didn't your mother ever tell you that sugar rots your teeth?

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH

tripwire posted:

du /*

again, i'm trying to avoid a shell command (but thanks, du is much more appropriate than ls)

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
stat every file recursively, maybe? I doubt you'll see a huge performance improvement though

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

Scaevolus posted:

I ran into this bug yesterday.

code:
class LeakyDict(dict):
    def __init__(self):
        dict.__init__(self)
        self.__dict__ = self


while True:
    a = LeakyDict()
I'm annoyed that they've had a patch to fix it for 3+ years and haven't committed it yet.

There's plenty of bugs which slip through. Finite resources. Feel free to log into the tracker and comment on it/wake it up.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

supster posted:

Does anyone have any ideas for how to get the file sizes for a large number of files (all recursive files under a root directory)?

Right now I'm using os.walk and os.path.getsize - but it becomes pretty slow after a couple thousand files.

My next thought was to parse the output of ls (or dir) - but I was hoping I could avoid that but have the same performance.

Interestingly, I'm actually writing a multithreaded tree walker (essentially, a find clone) right now. It would be trivial to make it compile sizes/stat information. If I get approval, I'll share it with you.

HoldYourFire
Oct 16, 2006

What's the time? It's DEFCON 1!
Are there any good web development/database frameworks that work with Python 3.0? SQLAlchemy claims to, but I can't seem to find any others.

I'm trying to write a browser game in Python 3, but should I just bite the bullet and switch to Rails? :colbert:

ErIog
Jul 11, 2001

:nsacloud:

HoldYourFire posted:

Are there any good web development/database frameworks that work with Python 3.0? SQLAlchemy claims to, but I can't seem to find any others.

I'm trying to write a browser game in Python 3, but should I just bite the bullet and switch to Rails? :colbert:

Why does it have to be Python 3? There's stuff available for Python 2.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

HoldYourFire posted:

Are there any good web development/database frameworks that work with Python 3.0? SQLAlchemy claims to, but I can't seem to find any others.

I'm trying to write a browser game in Python 3, but should I just bite the bullet and switch to Rails? :colbert:

How about switching down to Python 2.6?

No Safe Word
Feb 26, 2005

Bottle sorta does but yeah why python 3.x?

HoldYourFire
Oct 16, 2006

What's the time? It's DEFCON 1!

No Safe Word posted:

Bottle sorta does but yeah why python 3.x?

Because it's new! And therefore better. :colbert:

OK, I'll look at 2.6 then. Thanks! :shobon:

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

HoldYourFire posted:

Because it's new! And therefore better. :colbert:

OK, I'll look at 2.6 then. Thanks! :shobon:

It's really not wise to use Python 3 at this point if you want to, you know, use libraries.

Haystack
Jan 23, 2005





HoldYourFire posted:

Because it's new! And therefore better. :colbert:

OK, I'll look at 2.6 then. Thanks! :shobon:

From what I understand, the official recommendation is that users looking to do practical work use 2.6. The 3.x releases essentially amount to a really drawn out beta, which the Python Foundation is slowly easing the community towards.

As for web frameworks, the usual options are Django (see the book about it, here), Pylons (which also has a book, here), Turbogears, and webpy.

ErIog
Jul 11, 2001

:nsacloud:
A small pro tip regarding django. For as much as it encapsulated SQL calls, you will need to know just a few smidgens of SQL if you want to change your schema around. It isn't good at resetting schemas with liberal use of foreign keys. I always had to reset my db tables manually, and then have django re-init them. It's not bad, but it's just slightly more difficult than some of the django advocacy stuff would have you believe.

It's still the only web framework I've ever liked, though. It's so drat convenient. I'll probably use it to prototype in the future even if I don't end up launching anything that uses it.

ErIog fucked around with this message at 18:53 on Mar 7, 2010

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
My favorite part is that the admin interface is the coolest thing for making a real quick CRUD application. The icing on the cake is that you can easily extend it to fit whatever other requirements you have.

LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

I'm creating a range of dates for a stock market script, I need a tuple with a date, then another date 10 days back from the original excluding weekends (and ideally any time when the market is closed), another 10 days back from the last date in the tuple, etc. I've been looking at the docs and the only way I can think of to do it is to extract the name of the days between the date ranges and adjusting how many days I go back depending on whether a saturday or sunday turns up, but in my coding so far it doesn't seem very elegant nor would it take into account public holidays (which would probably require a preloaded list of excluded dates to be checked against which make my little method even more cluttered).

Is there an easy way to do this or am I doing this the hard way?

ChiralCondensate
Nov 13, 2007

what is that man doing to his colour palette?
Grimey Drawer

LuckySevens posted:

Is there an easy way to do this or am I doing this the hard way?
The datetime module has some helpful stuff for counting back and forth on the calendar, if you haven't found it already. You could make a date object out of the starting date, and decrement it by a timedelta(days=1) instance, counting off those days that aren't weekends (date.weekday() not in (5,6)) and aren't in a list_of_public_holidays.

Scaevolus
Apr 16, 2007

LuckySevens posted:

Is there an easy way to do this or am I doing this the hard way?

If the datetime module that ChiralCondensate mentioned isn't enough for you, you may want to try mxDateTime.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Jonnty posted:

It's really not wise to use Python 3 at this point if you want to, you know, use libraries.

If the NumPy folks would get off their butts and release a Python 3 compatible version (even just an alpha), people might start caring more about it. I really want to release a Python 3 version of my package, but I can't because it needs NumPy.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

Haystack posted:

From what I understand, the official recommendation is that users looking to do practical work use 2.6. The 3.x releases essentially amount to a really drawn out beta, which the Python Foundation is slowly easing the community towards.

No. 3.x is not a drawn out beta; and the PSF is not slowly easing the community towards it. 3.x is out there; can be used in production; but lacks third party library support.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

Avenging Dentist posted:

If the NumPy folks would get off their butts and release a Python 3 compatible version (even just an alpha), people might start caring more about it. I really want to release a Python 3 version of my package, but I can't because it needs NumPy.

Last I heard; the NumPy folks had recently announcing the py3 port would spin up soon - this was at pycon, and I don't know who the official source was, so ymmv.

LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

ChiralCondensate posted:

The datetime module has some helpful stuff for counting back and forth on the calendar, if you haven't found it already. You could make a date object out of the starting date, and decrement it by a timedelta(days=1) instance, counting off those days that aren't weekends (date.weekday() not in (5,6)) and aren't in a list_of_public_holidays.

Nice, what I was looking for, thank you

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

m0nk3yz posted:

Last I heard; the NumPy folks had recently announcing the py3 port would spin up soon - this was at pycon, and I don't know who the official source was, so ymmv.

Christ, finally. I looked into the changes required to get stuff working on Python 3, and they're honestly pretty minimal. All I really want is an alpha-quality version so I can test stuff out.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

m0nk3yz posted:

No. 3.x is not a drawn out beta; and the PSF is not slowly easing the community towards it. 3.x is out there; can be used in production; but lacks third party library support.

These two statements are mutually exclusive to me and I imagine a large part of the python community.

Preemptively calling myself a big baby who can't write web applications without a framework.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

MEAT TREAT posted:

These two statements are mutually exclusive to me and I imagine a large part of the python community.

Preemptively calling myself a big baby who can't write web applications without a framework.

I'm right there with you; I can't move to py3k until Django and a few other things I need move over. Until then, only small pet projects for py3k. Which sucks.

nbv4
Aug 21, 2002

by Duchess Gummybuns

m0nk3yz posted:

I'm right there with you; I can't move to py3k until Django and a few other things I need move over. Until then, only small pet projects for py3k. Which sucks.

yeah, add me to the list of babbys who can't write apps without a framework.

another thing that should be mentioned, it's not so much people are lazy and just haven't gotten around to porting their stuff over, theres also the issue of python3 not being installed on as many systems as python2. For instance, Ubuntu 8.04, which is very commonly used only has 2.4 and 2.5. A lot of people use 8.04, and it'll be around for at least another year. And thats just Ubuntu, which is usually as bleeding edge as they come. Other distros are even worse. There are still quite a lot of crappy web hosts out there with 2.1 installed.

tripwire
Nov 19, 2004

        ghost flow

nbv4 posted:

yeah, add me to the list of babbys who can't write apps without a framework.

another thing that should be mentioned, it's not so much people are lazy and just haven't gotten around to porting their stuff over, theres also the issue of python3 not being installed on as many systems as python2. For instance, Ubuntu 8.04, which is very commonly used only has 2.4 and 2.5. A lot of people use 8.04, and it'll be around for at least another year. And thats just Ubuntu, which is usually as bleeding edge as they come. Other distros are even worse. There are still quite a lot of crappy web hosts out there with 2.1 installed.

Which makes it a self-reinforcing problem. I know this is big talk for someone who's only written relatively tiny programs in python2.6 and not ported any of them over to 3.0, BUT, I don't think "not enough people use python3" is a valid excuse not to port over your old code- if everyone thought that way, we'd never advance in versions at all.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

tripwire posted:

Which makes it a self-reinforcing problem. I know this is big talk for someone who's only written relatively tiny programs in python2.6 and not ported any of them over to 3.0, BUT, I don't think "not enough people use python3" is a valid excuse not to port over your old code- if everyone thought that way, we'd never advance in versions at all.

It will all come - it just takes time. Once some big dominoes fall - such as numpy - we will begin to see things shift. Until then, we're all consigned to the darkness which is the old print statement.

BigRedDot
Mar 6, 2008

m0nk3yz posted:

It will all come - it just takes time. Once some big dominoes fall - such as numpy - we will begin to see things shift. Until then, we're all consigned to the darkness which is the old print statement.
I used to work with Travis Oliphant. Since so many people have been asking, I decided to email him, here's what he replied:

quote:

The trunk of NumPy has preliminary Python 3K support. There is no official roadmap, but the end of the summer looks promising.

Stabby McDamage
Dec 11, 2005

Doctor Rope
I'm playing with numpy to do some flocking algorithm graphics stuff, and I think I might be missing something.

I'm using 1 dimensional numpy.array() objects for my vectors, and I guess the best way to get the magnitude (AKA vector length, i.e. |v| = v.x2 + v.y2) is to call numpy.linalg.norm() on it, right?

Is this how people play with vectors in python? I figured there would be a dedicated vector class rippling with OO functions.



Also, what is the preferred package to do simple pixel-addressed 2D graphics? Basically all I want is a fast virtual framebuffer in a window that I can diddle with RGB values on.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Stabby McDamage posted:

Also, what is the preferred package to do simple pixel-addressed 2D graphics? Basically all I want is a fast virtual framebuffer in a window that I can diddle with RGB values on.

I've been using Python Image Library. If there's something better, I'd like to know about it, too.

tripwire
Nov 19, 2004

        ghost flow

Stabby McDamage posted:

I'm playing with numpy to do some flocking algorithm graphics stuff, and I think I might be missing something.

I'm using 1 dimensional numpy.array() objects for my vectors, and I guess the best way to get the magnitude (AKA vector length, i.e. |v| = v.x2 + v.y2) is to call numpy.linalg.norm() on it, right?

Is this how people play with vectors in python? I figured there would be a dedicated vector class rippling with OO functions.



Also, what is the preferred package to do simple pixel-addressed 2D graphics? Basically all I want is a fast virtual framebuffer in a window that I can diddle with RGB values on.
What i've done before is using PIL images and aliasing them as numpy arrays to take advantage of some fancy numpy functionality, or vice versa.

Depending on if you just want to read from the image or write to it, you can either use the "asarray"/"fromarray" methods of PIL images, or you can actually convert the whole array to a string and use the fromstring method of either numpy or PIL.

Heres an example I found on the PIL homepage:
code:
i = Image.open('lena.jpg')
a = numpy.asarray(i) # a is readonly
i = Image.fromarray(a)
Now as for getting that image drawn to a framebuffer, that depends on whether you care about making your program multiplatform. I've used pyqt before to accomplish this: PIL provides functionality for converting PIL images to QT images, after which you need to set a label to that image. I'm sure there is a similar path yuo can follow for TKinter, but I'm afraid I haven't done it before.

If you are developing just on win32, I've seen (but haven't used) a module in PIL for drawing on windows device contexts: http://www.pythonware.com/library/pil/handbook/imagewin.htm

tripwire fucked around with this message at 02:48 on Mar 11, 2010

Jo
Jan 24, 2005

:allears:
Soiled Meat
On a related note, what is the preferred Python way to handle video?

tripwire
Nov 19, 2004

        ghost flow
Beats me!

Adbot
ADBOT LOVES YOU

ATLbeer
Sep 26, 2004
Über nerd

Jo posted:

On a related note, what is the preferred Python way to handle video?

I've played with pyglet... It works but, isn't nice

  • Locked thread