What's up with Python's __init__ ?

Started by
8 comments, last by Zahlman 16 years, 4 months ago
I'm not entirely sure this problem is related to the __init__ method. It might be a flaw in the API I am using. Hell, maybe I'm just screwing up my tabs again. Either way, hopefully somebody may clue me in. As I understand, __init__ is not technically a constructor because the class is already instantiated when it is called, but I can't seem to understand why this message pump doesn't work under certain circumstances. I am using Python 2.5 with DirectPython 0.9 The following example causes the application to hang due to the message pump not processing anything. I could make a few assumptions about the problem but I'd rather just get a straight answer from somebody that knows.

class Application:
     
     def __init__(self,appTitle,xRes,yRes):
          d3d.createDevice(appTitle,u"",xRes,yRes,False,d3dc.CREATE.HARDWARE)

          d3d.setState(d3dc.RS.FVF, d3dc.FVF.XYZRHW |  d3dc.FVF.DIFFUSE | d3dc.FVF.TEX1)
          d3d.setState(d3dc.TS.COLOROP,      d3dc.TS.OP.MODULATE)
          d3d.setState(d3dc.TS.COLORARG1,    d3dc.TS.TA.TEXTURE)
          d3d.setState(d3dc.TS.COLORARG2,    d3dc.TS.TA.DIFFUSE)
          d3d.setState(d3dc.TS.ALPHAOP,      d3dc.TS.OP.DISABLE)
          

     def Pump(self):
          for message in d3d.getMessages():
               if message[0] == d3dc.WM.QUIT:
                    return 1
          return 0

def main():
     App = Application(u"Test",640,480)
          
     while True:
          if App.Pump():     break
          else:
               Render(0xff330011)


Now, if I take the "Pump()" method out of that class and call it from there, everything works just fine and dandy. Even more, if I place all of the code from "__init__" in a separate method called, say, "Init()" everything works fine. What is going on here? EDIT: Ok, what the hell? As a test I threw in some print statements at the beginning and end of __init__() and at the beginning of Pump(). Now, everything works. Ahhrg! Maybe I just misspelled something, or a tab was mutilated. I just can't seem to get the hang of this language =P
Advertisement
Yeah one of the downsides with this language is finding a decent IDE that can alert you to those silly code blocks not aligned problems in Python since it's really picky since it doesn't use braces like c/c++,etc to tell code blocks apart.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
You wouldn't happen to have any suggestions for IDE's. I tried ActivePython. It wasn't too bad but it has a nasty habit of closing down when my app exits. I also tried Open Komodo, but the current build as of a few days ago was a bit on the broken side.
Wing101, the free one from Wingware, is pretty decent. Basically I use it as a glorified text editor, though since it doesn't handle sys.exit() calls very well when you try to execute a program from inside it.

Notepad++ is a pretty decent free text editor, too.
Eric Richards
PyScripter (http://www.mmm-experts.com/). Beautiful Python IDE written in delphi (so it's fast, not like many others that I tried) and has lots of features. Updated fairly frequently as well.

(lol no, I am not a Bot, nor am I a member of the dev team)
Whatever editor religion you happen to subscribe to, I have an universal tip for everyone: Make your editor insert spaces when tab is pressed.
That way, visible whitespace is just that, spaces.

To make it is hell. To fail is divine.

Python distributions almost all include tabnanny.py.

For IDE, I use Komodo 3.5 Personal. $35, well worth it. Depending on how much Python I use in production work going forward (I project quite a bit), I might spring for an upgrade to 4.1 Professional. We'll see.
I've tried Wing101 for the last few days. It's not bad but Media Player doesn't seem to get along with it. When I use both, my taskbar gets locked open until restart.

I've tried PyScripter in the past and while I like it when I use it in conjunction with DirectPython annoyance ensues. When the WM_QUIT message is handled causing the application to end and the app window to close, the entire IDE closes too. If anyone has a suggestion for avoiding that I'm all for it.

I've heard nothing but good things about Komodo. But like I said before, the free version doesn't currently work for me (I'm still getting that Plug-in failure crap) so I'm not about spend $35 for a virtual paperweight.
Have you tried External Run (Alt+F9) with PyScripter? That should avoid the problem.
Quote:Original post by Zao
Whatever editor religion you happen to subscribe to, I have an universal tip for everyone: Make your editor insert spaces when tab is pressed.
That way, visible whitespace is just that, spaces.


Whatever editor religion you happen to subscribe to, I have a universal tip for everyone: Make your editor use tabs for indentation.
That way, indentation is just that: indentation (and it automatically looks like what each reader of the code wants it to look like).

(Personally, I use gVim, and I never have problems with inconsistencies in indentation. Although I do get them when I try to use IDLE - which comes with Python! - because of its space-conversion behaviour. AFAICT IDLE is simply broken in this regard - it doesn't offer all the configurations for tabs that it should, and the ones that are offered simply don't work as advertised.

Although I still suffer the annoyance with gVim that extra spacing on a line is also done with tabs, when I would like it to be done with spaces beyond the current indentation level - but I assume there is a way to fix this in the configuration files...)

This topic is closed to new replies.

Advertisement