Newbie help on wxPython
Robert Amesz
reqhye72zux at mailexpire.com
Tue Sep 4 23:03:14 EDT 2001
jsnyder wrote:
> I'm working with the wxPython tutorial and have a problem with this
> code for opening a file dialog:
>
> def OnOpen(self,e):
> -> dlg=wxFileDialog(self, "Choose a file", self.dirname,
> "","*.*", wxOPEN)
> if dlg.ShowModal()==wxID_OK:
> self.filename=dlg.GetFilename()
> self.dirname =dlg.GetDirectory()
> -> f=open(os.path.join(self.dirname,self.filename),'r')
> self.control.SetValue(f.read())
> f.close()
> dlg.Destroy()
>
> In the call to wxFileDialog, using the self.dirname call from the
> os module results in the error below, using the same call later in
> the open() works just fine.
>
> Traceback (most recent call last):
> File "C:\Python21\SampleEditor.pyw", line 46, in OnOpen
> dlg=wxFileDialog(self, "Choose a file", self.dirname, "","*.*",
> wxOPEN)
> AttributeError: MainWindow instance has no attribute 'dirname'
You neglected to set self.dirname to something (in the __init__
function) _before_ the dialog was called, isn't it obvious? Could be a
typo, so look carefully. You wouldn't be the first person to stare at
self.dirmane = "C:\\"
and wonder what's wrong.
Robert Amesz
More information about the Python-list
mailing list