467,146 Members | 988 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

what does 0 mean in MyApp(0)

I'm looking at a tutorial with the code below

from wxPython.wx import *

class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, "winApp", size = (800,640))
frame.Show(true)
self.SetTopWindow(frame)
return true

app = MyApp(0)
app.MainLoop()

Everything is explained nicely except the zero parameter in MyApp(0).
Anybody knows what that zero refers to?

Alex

Sep 30 '05 #1
  • viewed: 1812
Share:
9 Replies
i see you inherit from wxApp.
mybe the constructor of that object takes an int value?

Sep 30 '05 #2
"Alex" <li*******@yahoo.se> schrieb im Newsbeitrag
news:11**********************@o13g2000cwo.googlegr oups.com...
| I'm looking at a tutorial with the code below
|
| from wxPython.wx import *
|
| class MyApp(wxApp):
| def OnInit(self):
| frame = wxFrame(NULL, -1, "winApp", size = (800,640))
| frame.Show(true)
| self.SetTopWindow(frame)
| return true
|
| app = MyApp(0)
| app.MainLoop()
|
| Everything is explained nicely except the zero parameter in MyApp(0).
| Anybody knows what that zero refers to?

See:
http://aspn.activestate.com/ASPN/Coo.../Recipe/334620
|

--
Vincent Wehren
| Alex
|
Sep 30 '05 #3
Thanks for the replies. It seems that I have three options
1. app=MyApp()
2. app=MyApp(0)
3. app=MyApp('myfile.txt')

1. In the first case the output stream will be set to stdout/stderr,
which means that errors will be sent to a window which will be closed
when the app crashes.
2. In the second case the output will be set to the command prompt
window, which means that I will be able to catch the errors when my app
crashes.
3. There is also a third alternative which is to set the output to a
file.

Alterbnative 2 is simple and useful, so that's why everybody use that
alternative.

Is that correct?
Alex

Sep 30 '05 #4
"Alex" <li*******@yahoo.se> schrieb im Newsbeitrag
news:11**********************@g44g2000cwa.googlegr oups.com...
| Thanks for the replies. It seems that I have three options
| 1. app=MyApp()
| 2. app=MyApp(0)
| 3. app=MyApp('myfile.txt')
|
| 1. In the first case the output stream will be set to stdout/stderr,
| which means that errors will be sent to a window which will be closed
| when the app crashes.
| 2. In the second case the output will be set to the command prompt
| window, which means that I will be able to catch the errors when my app
| crashes.
| 3. There is also a third alternative which is to set the output to a
| file.
|
| Alterbnative 2 is simple and useful, so that's why everybody use that
| alternative.
|
| Is that correct?

Not entirely:

1. app=MyApp(): stdout/stderr is redirected to its own window, so you're
right here
2. app=MyApp(0): stdout/stderr is not redirected to a window.
Tracebacks will show up at the console. So you're right here to...

But:
3(a). app=MyApp(1, 'some/file/name.txt'):
stdout/stderr is redirected to to the file 'some/file/name.txt').

The arguments you pass to MyApp are named parameters, so for improved
readability you may want to use:

3(b). app=MyApp(redirect=1, filename='some/file/name'): will redirect stdout
to 'filespec'

and instead of 2:

2(b). app=MyApp(redirect=0) # stdout/stderr will stay at the console...

Anyway, if you omit the parameter names, make sure you you position them
correctly, i.e., a filename should only be positioned as /second/ argument.

HTH,
--

Vincent Wehren

| Alex
|
Oct 1 '05 #5
Alex wrote:
Thanks for the replies. It seems that I have three options
1. app=MyApp()
2. app=MyApp(0)
3. app=MyApp('myfile.txt')


I just want to emphasize the part of vincent's reply in which he points
out that using the keyword arguments makes this more readable.

If more examples and actual code would just use the darned "redirect="
keyword argument, you probably wouldn't have had to ask the question.

I remember when I had the same question and spent more time than I
should have had to digging out the answer. Now I try to make sure that
all my wx.Apps are initialized with redirect=False or whatever else I
need to make clear to a reader what I'm doing. For some widely used and
understood methods and constructors, using positional arguments might be
adequate. For ones like wx.App where everyone initializes them but
nobody seems to know what the arguments are doing (sometimes they seem
to be handed down from earlier generations), keyword arguments are a
real blessing.

The world needs more keyword arguments. Use them everywhere! ;-)

-Peter
Oct 2 '05 #6
See the documentation for the __init__() method here

<http://www.wxpython.org/docs/api/wx.App-class.html>

Btw, this is wxPython 2.6, AFAIK.

/Jean Brouwers

Oct 3 '05 #7
Good question, but Y'know, i don't think i'm the only one using a
threaded mail reader. Pls don't hijack others' threads.

David Pratt wrote:
Hi. Is anyone aware of any python based unacceptable language filter
code to scan and detect bad language in text from uploads etc.

Many thanks.
David


Oct 3 '05 #8
Alex wrote:
Alterbnative 2 is simple and useful, so that's why everybody use that
alternative.


Everybody doesn't... Particularly in Windows, it's common that
people make a .pyw-file, and then you don't see any console,
or otherwise they double-click on a .py-file, and if the app
dies with an error, they'll never get a chance to read the
traceback (unless they have a horribly slow computer). Even
worse, it they use command.com as their shell (default on
MS DOS derivates such as Windows ME) copying text from the
shell doesn't work very well, even if the shell didn't close.

Getting all printouts, tracebacks etc into a file is very
convenient during development. In a decent development
environment, you're likely to have a window open where you
do "tail -f" on the file.

Even in production, it's a good thing if it's at least possible
to enable output to a debug file. I've had that as a command
line switch, and asked users to turn that on and mail me the
resulting log file as they reproduced a buggy behaviour.
Oct 4 '05 #9
From Google:

Results 1 - 10 of about 1,340,000,000 for 0. (0.09 seconds)

James

On Friday 30 September 2005 07:15, Alex wrote:
I'm looking at a tutorial with the code below

from wxPython.wx import *

class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, "winApp", size = (800,640))
frame.Show(true)
self.SetTopWindow(frame)
return true

app = MyApp(0)
app.MainLoop()

Everything is explained nicely except the zero parameter in MyApp(0).
Anybody knows what that zero refers to?

Alex


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Oct 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Charles Law | last post: by
7 posts views Thread by Brian Shafer | last post: by
1 post views Thread by Shannon Richards | last post: by
2 posts views Thread by damonjulian@yahoo.com | last post: by
1 post views Thread by Alexnb | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.