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
zelah
Dec 1, 2004

Diabetes, you are not invited to my pizza party.
Not sure if this is worth putting in the OP but I'm brand new to coding and this is helping a lot

Adbot
ADBOT LOVES YOU

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

zelah posted:

Not sure if this is worth putting in the OP but I'm brand new to coding and this is helping a lot

Added.

Ben Nerevarine
Apr 14, 2006
I went back about 30 pages and didn't see anything so I'll pose the question:

I'm interested in playing developing a sprite-based game using either pygame or pyglet. I've searched around for comparisons of the two, and the general consensus seems to be that pyglet's not the best at sprite manipulation, though otherwise the two are comparable despite pygame's infrequent updates. But all of these comparisons seem to be a good year or two old. Is it still the case that pygame is the better way to go here?

UberJumper
May 20, 2007
woop
loving comtypes. If anyone has any ideas to how to deal with these things i would absolutely love to know.

1. There is a handful of interfaces/coclasses that are not being picked up by comtypes typelib parser. Now i thought this was simply because of me monkey patching / reworking chunks of their automatic code generation. However after spending a night debugging / struggling i pretty much found out they just are not getting extracted from the typelib. However visual studio / some other random tools reports they are there. Looking through the source of how comtypes makes me want to :suicide:.

2. Comtypes appears in certain situations to be doing a double release. This occurs kinda at random and i cannot nail this down to a single problem, however i am pretty sure it has to do with me overloading __new__ for interfaces, and calling the baseclass new. However this seems to be somewhere screwing with all the bullshit contained in _cominterface_meta.

3. I still have not found a a good way to handle COMMethod, since in certain cases i would love for the user to be able to get the HRESULT in certain situations. Like an optional parameter that takes an HRESULT object, and fills in the values. Right now anything that is S_XXX, just gets tossed away. However when HRESULT tells you information you need that is not an error, your hosed.

Looking through the code i noticed you can add a private method that instead will be called. E.g.:

IRaster::GetPixelCoordX(__in row, __in col, __out output_value )

code:
class IRaster(IUnknown):
    def GetPixelCoordX(row, col):
       output_value = c_int()
       hr = self.__com_GetPixelCoordX(row, col, byref(output_value))
       return hr, output_value.value
That works except, generating a stub for every single corresponding method, when the file size is already so stupidly large. This becomes a major hassle. Attempting to modify COMMETHOD, is a nightmare....

Also why would you ever name a class like this...?

code:
class _(partial.partial, POINTER(p)):

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Here's another reason NumPy owns. I had an array of vertices [A, B, C, ..., N] and wanted to make a perimeter of line segments out of them by passing them to a function that took them as [A,B, B,C, C,D, ... M,N, N,A]:

code:
numpy.roll(numpy.repeat(verts, 2), -1)
Blam.

tripwire
Nov 19, 2004

        ghost flow

Avenging Dentist posted:

Here's another reason NumPy owns. I had an array of vertices [A, B, C, ..., N] and wanted to make a perimeter of line segments out of them by passing them to a function that took them as [A,B, B,C, C,D, ... M,N, N,A]:

code:
numpy.roll(numpy.repeat(verts, 2), -1)
Blam.

Yowza! Numpy is probably the single most amazing library for python. It actually makes doing number crunching fun, and I don't even know how to use 1/10th of the functionality in it.

MaberMK
Feb 1, 2008

BFFs

UberJumper posted:

Also why would you ever name a class like this...?

code:
class _(partial.partial, POINTER(p)):

Knowing absolutely nothing about comtypes, I would guess it's intended to be used as a shorthand "operator" to prepare data for further use. Something like this:

code:
result = a_function(_(data, more_data))
Pylons uses a similar concept, assigning _ as a reference to ugettext.

e: this of course doesn't take into account that it appears to be inheriting a factory class, which is just bizarre, I can't begin to image why you would do that.

MaberMK fucked around with this message at 22:34 on Apr 29, 2010

king_kilr
May 25, 2007

MaberMK posted:

Pylons uses a similar concept, assigning _ as a reference to ugettext.

e: this of course doesn't take into account that it appears to be inheriting a factory class, which is just bizarre, I can't begin to image why you would do that.

Making ugettext _ isn't just a pylon's thing, it's nearly universal, cross language.

MaberMK
Feb 1, 2008

BFFs

king_kilr posted:

Making ugettext _ isn't just a pylon's thing, it's nearly universal, cross language.

Noted. I pretty much stick to Python, I don't get out much. :)

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I'm writing a small(ish) program that requires a database. I'd like end-users to be able to use either SQLite or MySQL.

This is a little out of my comfort zone, but I guess SQLAlchemy is what I need to look in to? Is there anything lighter weight that I may want to consider?

king_kilr
May 25, 2007

Thermopyle posted:

I'm writing a small(ish) program that requires a database. I'd like end-users to be able to use either SQLite or MySQL.

This is a little out of my comfort zone, but I guess SQLAlchemy is what I need to look in to? Is there anything lighter weight that I may want to consider?

Just use SQLAlchemy.

MaberMK
Feb 1, 2008

BFFs

king_kilr posted:

Just use SQLAlchemy.

I think what you mean to say was "the only thing you should ever even consider using to work with a database is SQLAlchemy."

Haystack
Jan 23, 2005





You might also consider using Elixir with SQLalchemy. Reportedly, it's better suited for simple projects than SQLalchemy's default declarative system.

king_kilr
May 25, 2007

MaberMK posted:

I think what you mean to say was "the only thing you should ever even consider using to work with a database is SQLAlchemy."

Nope, I've never even used SQLAlchemy for a real project. I'm the guy who implemented multi-db for django

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Haystack posted:

You might also consider using Elixir with SQLalchemy. Reportedly, it's better suited for simple projects than SQLalchemy's default declarative system.

This looks cool, and I'm now leaning towards using this. Thanks.

The cool thing I just figured out is that SQLAlchemy supports MySQL Connector/Python (native python Mysql) which means that all this should be Eventlet compatible!

clearly not a horse
May 8, 2009

undue butt brutality is not a criminal offense
I am having some problems with modules. I am a terrible beginner and resort to COBOL for this problem. I will introduce the code first. Notice the directory placement.

documents/urine/butthole.py
code:
class butt:
    def __init__(self, stuff)
        print(stuff)
documents/urine/thing.py
code:
from butthole import *

x = butt('text')
When I run the last code with TextWrangler on MAC OSX I get an error telling me that "there is no module named butthole". According to the documentation, python will first search the "currect directory" for the module and then PYTHONPATH. I define "current directory" as the folder when thin.py exist, and considering the fact that butthole.py is in the same folder, python should find the module easily.
What is wrong here?

king_kilr
May 25, 2007
What version of Python?

Edit: Do you have an __init__.py in that dir? It can be empty

hlfrk414
Dec 31, 2008
Notice the wording, "current directory". It is not the current directory of the module, it's the current directory where the starting script was run. I assume TextWrangler is running from documents or its parent directory. You either need to add urine to the pythonpath, (which you can do from butthole but is not recommended) or you need to import from the full path from the root of the package 'from urine.butthole import *' assuming that the packages have an empty __init__.py script. Someone correct me if I'm wrong.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

hlfrk414 posted:

Notice the wording, "current directory". It is not the current directory of the module, it's the current directory where the starting script was run. I assume TextWrangler is running from documents or its parent directory. You either need to add urine to the pythonpath, (which you can do from butthole but is not recommended) or you need to import from the full path from the root of the package 'from urine.butthole import *' assuming that the packages have an empty __init__.py script. Someone correct me if I'm wrong.

haha this is the first thing I thought of when I read your reply.

Italian Stalin
Jul 4, 2003

You-a gonna get-a purged!
I'm trying to create a dynamic 2D array. A comparable thing might be an arraylist of arraylists in Java. Is this possible in Python?

shrughes
Oct 11, 2008

(call/cc call/cc)

armed2010 posted:

I'm trying to create a dynamic 2D array. A comparable thing might be an arraylist of arraylists in Java. Is this possible in Python?

Yes?

Italian Stalin
Jul 4, 2003

You-a gonna get-a purged!

shrughes posted:

Yes?

Thanks for your help. :downsbravo:

I've Googled this, otherwise I wouldn't be asking this question. Could you perhaps gift me with the syntax of declaring such an array?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
code:
[[]]

shrughes
Oct 11, 2008

(call/cc call/cc)

armed2010 posted:

Thanks for your help. :downsbravo:

Hey, you're the one who asked a stupid question.

Italian Stalin
Jul 4, 2003

You-a gonna get-a purged!

Avenging Dentist posted:

code:
[[]]

Thanks!

Senso
Nov 4, 2005

Always working

Avenging Dentist posted:

code:
[[]]

:iceburn:

Italian Stalin
Jul 4, 2003

You-a gonna get-a purged!

shrughes posted:

Hey, you're the one who asked a stupid question.

Did I ruffle your feathers oh mighty goonsir? Durp durp.

Avenging Dentist
Oct 1, 2005

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

armed2010 posted:

Did I ruffle your feathers oh mighty goonsir? Durp durp.

Perhaps you shouldn't assume that "this is how you'd do something in one language" is enough context to provide a remotely useful answer. My "answer" probably isn't what you actually want.

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

armed2010 posted:

I'm trying to create a dynamic 2D array. A comparable thing might be an arraylist of arraylists in Java. Is this possible in Python?

It is, and you could do it basically the same way:
code:
outer_arr = []
first_row = [1, 2, 3]
outer_arr.append (first_row)
second_row = [4, 5, 6]
outer_arr.append (second_row)
# set second element of first row 
outer_arr[0][1] = 8
# etc
It wouldn't be the fastest and some operations (say, adding a column to every row) would be awkward, but as a quick-and-dirty solution, it works. Depending on what you mean by "dynamic", numpy might do the job.

LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

I'm having some stupid problem where I installed psycopg2, it said I need mx.datetime which I thought I had, so I re-installed that and now python can't see the module psycopg2 and won't import it. Other modules in my python2.6 folder import, what could cause this?

edit: pythonpaths are correct, module is where all the others are

LuckySevens fucked around with this message at 00:11 on May 4, 2010

Kire
Aug 25, 2006

zelah posted:

Not sure if this is worth putting in the OP but I'm brand new to coding and this is helping a lot

Thanks so much for this, now I'm having fun looking at all the other courses too.

king_kilr
May 25, 2007

LuckySevens posted:

I'm having some stupid problem where I installed psycopg2, it said I need mx.datetime which I thought I had, so I re-installed that and now python can't see the module psycopg2 and won't import it. Other modules in my python2.6 folder import, what could cause this?

edit: pythonpaths are correct, module is where all the others are

a) AFAIK mx isn't required for psycopg2

b) Just pip install it, save yourself the pain.

LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

Yeah I did that and now it works. Why I don't know :(

Italian Stalin
Jul 4, 2003

You-a gonna get-a purged!

outlier posted:

It is, and you could do it basically the same way:
code:
outer_arr = []
first_row = [1, 2, 3]
outer_arr.append (first_row)
second_row = [4, 5, 6]
outer_arr.append (second_row)
# set second element of first row 
outer_arr[0][1] = 8
# etc
It wouldn't be the fastest and some operations (say, adding a column to every row) would be awkward, but as a quick-and-dirty solution, it works. Depending on what you mean by "dynamic", numpy might do the job.

That's excellent and exactly what I'm looking for! None of the links I searched showed anything like that. Thanks!

Virigoth
Apr 28, 2009

Corona rules everything around me
C.R.E.A.M. get the virus
In the ICU y'all......



Kire posted:

Thanks so much for this, now I'm having fun looking at all the other courses too.

I agree, there is a course specifically for python introduction in there I found that is a 4 week class apparently. I'm about to start my summer projects of get my CCNA and learn Python so this will help.

king_kilr
May 25, 2007

armed2010 posted:

That's excellent and exactly what I'm looking for! None of the links I searched showed anything like that. Thanks!

Why would you expect them to? Lists of lists aren't special.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
So, anyone played with repoze.bfg and has an opinion to share? I'd ignored the project for a long time because of its association with Zope ("Zope - for when you've got just too much free time") but a recent visit to it has reignited my interest:

* Fully unit tested, fully documented
* Actually breaks out some of the Zope architecture into genuinely standalone components
* Runs on UNIX, Windows, Jython and Google App Engine
* Persistence-agnostic: SQLAlchemy, ZODB, CouchDB, etc

UberJumper
May 20, 2007
woop
Is there anyway to make a python list iterator to go backwards?

Basically i have this

code:
    class IterTest(object):
        def __init__(self, data):
            self.data = data
            self.__iter = None
    
        def all(self):
            self.__iter = iter(self.data)
            for each in self.__iter:
                mtd = getattr(self, type(each).__name__)
                mtd(each)
    
        def str(self, item):
            print item
    
            next = self.__iter.next()
            while isinstance(next, int):
                print next
                next = self.__iter.next()
    
        def int(self, item):
            print "Crap i skipped C"
    
    if __name__ == '__main__':
        test = IterTest(['a', 1, 2,3,'c', 17])
        test.all()
Running this code results in the output:

a
1
2
3
Crap i skipped C

I know why it gives me the output, however is there a way i can step backwards in the str() method, by one step?

Scaevolus
Apr 16, 2007

UberJumper posted:

I know why it gives me the output, however is there a way i can step backwards in the str() method, by one step?

No. Why not do this?

code:
    class IterTest(object):
        def __init__(self, data):
            self.data = data
    
        def all(self):
            for each in self.data:
                mtd = getattr(self, type(each).__name__)
                mtd(each)
    
        def str(self, item):
            print item
    
        def int(self, item):
            print item
    
    if __name__ == '__main__':
        test = IterTest(['a', 1, 2,3,'c', 17])
        test.all()

Adbot
ADBOT LOVES YOU

UberJumper
May 20, 2007
woop

Scaevolus posted:

No. Why not do this?

code:
    class IterTest(object):
        def __init__(self, data):
            self.data = data
    
        def all(self):
            for each in self.data:
                mtd = getattr(self, type(each).__name__)
                mtd(each)
    
        def str(self, item):
            print item
    
        def int(self, item):
            print item
    
    if __name__ == '__main__':
        test = IterTest(['a', 1, 2,3,'c', 17])
        test.all()

Because that makes grouping subelements difficult. Essentially i am looking for bidirectional iteration support within python.

  • Locked thread