Reading in external file - error checking and line numbers...

Hugh Macdonald hugh.macdonald at gmail.com
Wed Sep 7 04:52:43 EDT 2005


I'm writing a tool at the moment that reads in an external file (which
can use any Python syntax)

At the moment, I'm reading the file in using:

	scriptLines = open(baseRippleScript).read()
	exec scriptLines

However, if I raise an exception in my main code, in a function that is
called from the external script, the stack trace just has:

	File "<string>", line 8, in ?

Ideally, I'd want to be able to avoid throwing exceptions and would
like to, from my main code, print out an error that included the script
name (easily accessible) and the line number (less easily accessible).

Is there a better way of executing an external script that would let me
access at any time the line number from the external script that is
being executed.


More specifically, if a function is called from an external script with
an invalid parameter type, I want to be able to flag it accurately to
the user....

Hope this made sense - let me know if I've confused you at all.....


--
Hugh Macdonald




More information about the Python-list mailing list