what does 0 mean in MyApp(0)

A

Alex

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
 
I

Ido.Yehieli

i see you inherit from wxApp.
mybe the constructor of that object takes an int value?
 
V

vincent wehren

| 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/Cookbook/Python/Recipe/334620
|
 
A

Alex

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
 
V

vincent wehren

| 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
|
 
P

Peter Hansen

Alex said:
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
 
G

gene tani

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.
 
M

Magnus Lycka

Alex said:
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.
 
J

James Stroud

From Google:

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

James

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top