Function not available after importing module

S

Stephen Boulet

This must be a dumb error on my part.

I'm creating a module called "wxMessageBox.py".

When I do an "import wxMessageBox" I don't see my "askopenfilename"
function in the wxMessageBox namespace.

When I do a "python -i wxMessageBox.py" it's there and seems to work fine.

Here's the (short) code:

def askopenfilename(startdir, filetypes="All files (*.*)|*.*"):
.....import wx
.....app = wx.PySimpleApp()

.....dlg = wx.FileDialog(None,
.........message="Choose a file",
.........defaultDir=startdir,
.........defaultFile="",
.........wildcard=filetypes,
.........style=wx.OPEN | wx.CHANGE_DIR)

.....path = -1
.....if dlg.ShowModal() == wx.ID_OK:
.........path = dlg.GetPath()

.....return path

def showerror(caption, message):
.....import wx
.....app = wx.PySimpleApp()
.....dlg = wx.MessageDialog(None,
.........message=message,
.........caption=caption,
.........style=wx.ICON_ERROR)

.....app.MainLoop()
.....dlg.ShowModal()

if __name__ == '__main__':
.....#showerror('Error!', 'No text on clipboard')
.....print askopenfilename(startdir="C:\\")
 
D

David Bolen

Stephen Boulet said:
When I do an "import wxMessageBox" I don't see my "askopenfilename"
function in the wxMessageBox namespace.

Can you show the actual code (or an interactive session) that shows
the error you get? I believe that given the module you show, you
should be able to:

import wxMessageBox

print wxMessageBox.askopenfilename(startdir="C:\\")

for example, within your main module.

Could you be forgetting to qualify the askopenfilename name with its
wxMessageBox module?

-- David
 
S

Stephen Boulet

David said:
> Can you show the actual code (or an interactive session) that shows
> the error you get? I believe that given the module you show, you
> should be able to:

It was a dumb error, as I thought. I copied my script to
"site-packages", but then left a copy in the current directory. When I
imported the module, the current directory's version came up.

Well, you live and you learn...

Stephen
 

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,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top