Alan Gauld wrote: > "Suzanne Peel" <[EMAIL PROTECTED]> wrote > > >> However both suggestions will only give me that name of the 1st file >> executed eg when I use execfile('EA_Owner.py') the name returned >> when >> the __file__ or sys.argv[0] is executed always EA_Owner.py . >> > > You didn't mention you were doing wacky stuff like using execfile... > That makes it a bit more challenging. Is there any reason why you > need to use execfile rather than just importing the file? > > execfile acts as if another interpreter session was running so its > quite tricky to find out the name of the file that the original > interpreter > was running. You might be able to do it by setting a global variable > to the current __file__ before calling execfile... >
I agree with Alan that execfile can usually be replaced with a more elegant solution. But if you're not looking to rearchitect the code and are looking for the least amount of work, you could try wrapping or decorating the execfile function. Possibly something like this (off-the-top-of-my-head and untested): create a module, say, myExec.py: def myExecfile( filename ): doSomeLoggingOn( filename ) return execfile( filename ) Then, in your code: from myExec import myExecfile as execfile No other code should have to change. > >> The trace-back feature provides this - can I force an error of sorts >> that >> will not suspend programming but will report the file/module/script >> that >> it is running ??? (Probably a bit dramatic but I am at a loss..) >> > > Look at the traceback module. I think its possible but messy. > It would be better if you can find a way to avoid using execfile. > > HTH, > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor