Scoping Error in Imported Method

This is not strictly a wxPython error, but apparently a filename scoping
error when I try to call a method imported from a different file. An
executable module with the external module and three sample data files are
attached in a tarball.

   When I run the file, makepairs.py, from the command line with the three
sample input files (*.in) and the filenames obtained with sys.argv[], it
works just as intended (and the name == __main__ code has been removed from
this copy). However, it's not picking up the input and output filenames from
the ScopingPage class. Changing the assignments yields an error of unknown
filename, 'infile'.

   Running the application through winpdb I see what appears to be another
problem in the method, OnMakePair(). According to the debugger, when I step
through the code I end up stepping over makepairs, not entering it. Despite
my reading of the python docs I have here the answers have not become obvious
to me.

Thanks,

Rich

filename.tgz (2.42 KB)

···

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

   This is not strictly a wxPython error, but apparently a filename scoping
error when I try to call a method imported from a different file. An
executable module with the external module and three sample data files are
attached in a tarball.

You get a scoping error because there doesn't exist any variables with
names infile or outfile in the function makepairs(), nor in the
module-level scope of makepairs.py .

If you want 'infile' and 'outfile' to be passed as arguments from
something else, you need to make sure that makepairs() takes the
arguments (infile, outfile) and not (input, output) as it currently does
(or make sure that infile and outfile are global variables of the
makepairs.py module).

   When I run the file, makepairs.py, from the command line with the three
sample input files (*.in) and the filenames obtained with sys.argv, it
works just as intended (and the name == __main__ code has been removed from
this copy). However, it's not picking up the input and output filenames from
the ScopingPage class. Changing the assignments yields an error of unknown
filename, 'infile'.

See my comment above.

   Running the application through winpdb I see what appears to be another
problem in the method, OnMakePair(). According to the debugger, when I step
through the code I end up stepping over makepairs, not entering it. Despite
my reading of the python docs I have here the answers have not become obvious
to me.

I have no idea. It looks like it should work to me.

One thing to note about OnMakePair():

  def OnMakePair(self, event):
    files = [('natural.in', 'natural.out'), ('economic.in', 'economic.out'),
           ('societal.in', 'societal.out')]
    for (infile,outfile) in files:
      try:
        makepairs(infile, outfile)
      except IOError:
        if not os.path.isfile(infile):
          print infile
        else:
          event.Skip()

The above code may skip the event multiple times. I don't know if
wxPython dies horribly in that case, but I always do my best to only to
skip at most once in an event handler.

Also, skipping is only necessary if you expect something else is waiting
for the event in the case that you didn't finish handling it. If you
don't have something else waiting for the event (it doesn't look like
you do), then skipping the event, regardless of the internal happenings
of your event handler, isn't necessary.

- Josiah

···

Rich Shepard <rshepard@appl-ecosys.com> wrote:

You get a scoping error because there doesn't exist any variables with
names infile or outfile in the function makepairs(), nor in the
module-level scope of makepairs.py.

Josiah,

   Thanks. I has been a long time since I did any serious coding.

Also, skipping is only necessary if you expect something else is waiting
for the event in the case that you didn't finish handling it. If you
don't have something else waiting for the event (it doesn't look like
you do), then skipping the event, regardless of the internal happenings
of your event handler, isn't necessary.

   Ah, I got mixed up here.

Rich

···

On Mon, 26 Dec 2005, Josiah Carlson wrote:

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863