execfile fun!

Emile van Sebille emile at fenx.com
Fri Oct 12 09:55:33 EDT 2001


This works for me as is.  Perhaps you're importing a different bar_module?

--

Emile van Sebille
emile at fenx.com

---------
"Steve Thompson" <Steve_Thompson at maxtor.com> wrote in message
news:f4b4ce26.0110120512.1337a497 at posting.google.com...
> I'm trying to do something rather awkward in Python, and not having a
> great deal of success at that!  I have the following modules:
>
> #bar module (bar_module.py):
> class Bar:
>    def add(self, first, second):
>       return first + second
>
> bar = Bar()
>
>
> #foo module (foo_module.py):
> from bar_module import *
> print "The sum of 23 and 45 is %d\n" %bar.add(23,45)
>
>
> #main module (main_module.py):
> class Main:
>    def do_bar(self):
>       execfile("foo_module.py")
>
> main = Main()
> main.do_bar()
>
> While performing execfile, I get 'NameError: There is no variable
> named 'bar'.  From this I surmise that the execfile statement loaded
> and compiled foo, but did not import bar, as it was told.  Is there
> any way of around this?
>
> Thanks in advance and best regards to all!,
>
> Steve Thompson




More information about the Python-list mailing list