[Pythonmac-SIG] Weird import problem with PythonIDE on Mac (was 'import problem')

Chris Smith smichr at bigfoot.com
Fri Apr 22 12:41:11 CEST 2005


On Friday, Apr 22, 2005, at 03:52 America/Chicago, Just van Rossum - 
just at letterror.com wrote:

> Importing __main__ is a very silly thing to do anyway, if you ask me.
>

All comments from you, Bob, and Jack have been *very* helpful.  I think 
I understand better what is going on.  What's got me scratching my head 
is that I thought it worked several at one time, but I must have been 
misunderstanding what script was actually being run. (?)

Anyway, as to importing from main, I was trying to learn to use the 
timeit module and wanted to be able to pass functions to it (rather 
than literal strings of code).  The init of timeit takes the strings 
you pass and creates a function that is exec'ed.

Do you have a suggestion as to what can I give a module so it has 
enough information to execute a function that resides in __main__? Here 
is a visual of what is going on:

------__main__
def y1():
   pass
import foo
foo.run(string_from_main) #what should I pass?

------external module, foo

def run(string_from_main):
	#
	exec(string_from_main) #y1 is run as if it were in __main__


/c



More information about the Pythonmac-SIG mailing list