views:

182

answers:

6

I just completed a program that should (hopefully) play a GUI Tetris program. I've cleaned up all the syntax errors, but now when I double-click, or go through the Command Prompt to run the program a DOS window pops up for less than a second and disappears without ever running the program.

What's going on?


Heres a link to the code at codepad.org

http://codepad.org/tq4et1rO

A: 

The DOS window pops up because you are using the wrong python binary (python.exe instead of pythonw.exe?)

It does not show anything because, there is a bug in you program. If there is no stack trace I guess you forgot to enter the main loop. Try posting some code.

ebo
pythonw.exe would avoid the DOS window altogether.
Thomas Wouters
+2  A: 

An error occurred. Unfortunately, the DOS window closed (because the Python program ended) and you didn't get to see the actual error. Start a DOS window yourself (start -> run -> 'cmd') and run the program from there. That will show you the traceback.

Thomas Wouters
That's what I did after it wouldn't run from just double clicking it. So I ran it from there and it showed Syntax Errors, I fixed those and it still isn't running. But this time there is no traceback
Brad Johansen
You'll have to either show us some code (or post a new question with the code) or do some debugging yourself. Are you sure your script is actually trying to do something? Try adding some print statements to find out what's actually happening.
Thomas Wouters
So you're saying the reason for this is that there is most likely an error?
Brad Johansen
100% chance there is an error. Don't be obtuse, take the advice above.
KevinDTimm
I didn't mean to sound that way, I'm fairly novice with programming in general, so I didn't know running a program worked*. *Especially since most of my programs were really small before hand and didn't really have errors in them, so the program never acted this way before.
Brad Johansen
A: 
Traceback (most recent call last):
  Line 3, in <module>
    import wx
ImportError: No module named wx

You need to install wxPython

Lennart Regebro
It is installed, it's most likely just codepad.
Brad Johansen
It is not installed in the Python installation that you are using. The sentence fragment "it's most likely just codepad" makes no sense to me. I have no idea what you are trying to say.
Lennart Regebro
codepad actually tries to run the pasted Python code, but codepad doesn't have wx installed. The error isn't what he's getting when he runs it.
Thomas Wouters
There is no error being produced through the command prompt or through my editor. So I don't know whats going on.
Brad Johansen
I think you get an error. When I try to run the code I get this error: Traceback (most recent call last): File "tetris.py", line 356, in <module> Tetris(None, -1, 'Tetris') File "tetris.py", line 10, in __init__ self.statusbar - self.CreateStatusBar() AttributeError: 'Tetris' object has no attribute 'statusbar'
Lennart Regebro
+8  A: 

Running your script actually does produce a traceback:

Traceback (most recent call last):
  File "tetris.py", line 356, in <module>
    Tetris(None, -1, 'Tetris')
  File "tetris.py", line 10, in __init__
    self.statusbar - self.CreateStatusBar()
AttributeError: 'Tetris' object has no attribute 'statusbar'

Your script has an error on line 10:

self.statusbar - self.CreateStatusBar()

You mean to be assigning there, not subtracting from an attribute that does not yet exist.

Thomas Wouters
ah thanks... I don't know what I did because for some reason it doesn't show that on my computer. Thanks for the help... I'll go through everything closely and make sure there isn't anything else like that.
Brad Johansen
@Brad, see my answer, I identified a couple dozen more "things like that" and fixed them all before posting (my friend and colleague Thomas obviously had the right idea by posting the first bug found instead of taking as long as I did to find them all, given the difference in resulting upvotes;-).
Alex Martelli
It's not like you need the votes, Alex :)
Thomas Wouters
@Thomas, conceded, you're right -- it's just that I always wonder whether I should be thorough or fast in my SO answers, and keeping being biased to thoroughness and thinking maybe I should recalibrate -- back when I responded on comp.lang.python, I always focused on thoroughness (it was never a race based on speed -- Usenet, remember?-), but SO is different (speed _does_ matter here, clearly), so, assuming people's votes do indeed reflect how useful an answer is to them, fast answers appear to be **very** useful to people here, often more than more thorough ones. Hmmm...
Alex Martelli
Thanks. Checking now
Brad Johansen
A: 

You may want to change (at the bottom of your script)

app = wx.App()

to

app = wx.App(redirect=False)

Otherwise the segmentation faults that happen as wxPython is starting up won't be printed to the console, and can be a nightmare to track down.

Steven Sproat
+9  A: 

Wow, there's really a huge number of errors in your code. I started running it under pdb, identifying and fixing them one by one, but after 20 or so I gave up. What I fixed so far (in diff's output, lines start with < to mean they're in your version, or with > to mean they're in my partially fixed version). Note the variety: you often write Flase instead of False, use wrong capitalization, use - (minus) instead of = (equals), misspell variables (e.g. Boardd instead of Board, even instead of event), rnage instead of range, and so on, and so forth.

37c37
<       self.isStarted = Flase
---
>       self.isStarted = False
63c63
<       self.isWaitingAfterLine - Flase
---
>       self.isWaitingAfterLine = False
87c87
<       for i in range(Board.BoardHeight * Board.Boardwidth):
---
>       for i in range(Board.BoardHeight * Board.BoardWidth):
135c135
<       if even.GetId() == Boardd.ID_TIMER:
---
>       if event.GetId() == Board.ID_TIMER:
205c205
<       self.curY = Board.Height - 1 + self.curPiece.minY()
---
>       self.curY = Board.BoardHeight - 1 + self.curPiece.minY()
214c214
<       for i in rnage(4):
---
>       for i in range(4):
217c217
<           if x < 0 or x >= Board.BoardWidth or y < 0 or y >= Board.Boardheight:
---
>           if x < 0 or x >= Board.BoardWidth or y < 0 or y >= Board.BoardHeight:
278c278
<       self.coords = [[0, 0] for i in rnage(4)]
---
>       self.coords = [[0, 0] for i in range(4)]
356c356,357
< Tetris(None, -1, 'Tetris')
---
> tetris = Tetris(None, -1, 'Tetris')
> app.SetTopWindow(tetris)

After all these fixes, I've stopped upon spotting one more typo (you def sqaureHeight when you clearly mean squareHeight) -- I have no idea how many typos and other mistakes are still hiding in these 360 lines of code... A density of more such bugs than 1/10th of the lines is plenty high enough for me.

I heartily recommend that you start with much less ambitious projects and teach yourself to carefully "copyedit" your code for these typos you appear to be so prone to: it's possible to be dyslexic and an excellent programmer at the same time, but it does take extra effort and diligence on your part. Tools such as pylint may also help a little, although they do have limits.

Edit: as it turns out, after fixing a couple of occurences of sqaure into square, the program does run -- and immediately shows an empty window saying "Game Over" and gets to the raw_input prompt you have as your very last line. So beyond the many typos there must be one or more nasty logic-level bugs as well. I repeat the entreaty to start with something much, much simpler in your first forays into programming.

Alex Martelli
Great answer, you're so helpful here, Alex. :)
Steven Sproat
Yea, I guess I really jumped the gun when doing this. But thanks for your help anyways.
Brad Johansen
@Brad, you're welcome!
Alex Martelli
....... pwned :)
Stefano Borini