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(baseRipple Script).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 2 2123
Hugh Macdonald wrote: 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(baseRipple Script).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).
exec compile(scriptL ines, baseRippleScrip t, "exec")
(but in this case, you might as well use the "execfile" built-in)
</F>
Thankyou! That was much easier than I expected.....
One more thing on a similar note..... When raising exceptions, is it
possible to remove a few items from the top of the stack trace?
My stack trace is looking something like:
File "ripple", line 160, in ?
File "ripple", line 94, in executeRipple
File "test.rip", line 8, in ?
dependsOnFrame = new)
File "ripple", line 133, in __init__
File "ripple", line 148, in addDependsOnFra me
__main__.Ripple Error: 'Cannot add frame dependency to non frame-based
node'
I'd like to be able to remove the last two items in the stack so that
it just shows the user:
File "ripple", line 160, in ?
File "ripple", line 94, in executeRipple
File "test.rip", line 8, in ?
dependsOnFrame = new)
__main__.Ripple Error: 'Cannot add frame dependency to non frame-based
node'
Unfortunately, I don't know how many 'ripple' stack items there will
be...
This is why I'd much rather, if I can, do this without exceptions and
just be able to print out my own error message with the problem line
number marked....
Or am I asking too much? ;)
--
Hugh Macdonald This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: muser |
last post by:
With the following code I'm trying to read a text file (infile) and
output inaccuracies to the error file (printerfile). The text file is
written and stored on disk, while the printerfile has to be created
when the program executes. But the compile keeps reading that it can't
find the text file.
Karl you wrote the original program from which this one is but a poor
copy, can you or anyone else enlighten me as to why yours worked and
mine...
|
by: pruebauno |
last post by:
Hello all,
I am having issues compiling Python with large file support. I tried
forcing the configure script to add it but then it bombs in the make
process. Any help will be appreciated.
Information:
Architecture:
PowerPc on AIX version 5
Compiler:
|
by: Daniel Moree |
last post by:
I'm working on a program that must first establish if the file exists in the
program directory then it must open if for reading, read each line and set
the variables then the program goes on about it's buisness.
My problem is all the resources I have found aren't very clear on these
things. All of them open the file then check to see if the stream is open.
Well, the problem with using file.open("filename.dat", ios::in |
ios::binary) is...
|
by: Matthew Crema |
last post by:
Hello,
Say I have 1000 text files and each is a list of 32768 integers.
I have written a C program to read this data into a large matrix. I am
using fopen in combination with fscanf to read the data in. However, it
takes about 20 seconds to complete and I wonder if there is a faster way.
For example, I found that I could use 'fread' to read the data into a
string that looks like this:
|
by: Millennium Falcon |
last post by:
Hi!
Help is kindly requested in reading floating point numbers from a text file.
File is organized like this :
2000 // number of data
-1.00000 -2.000000 -0.008944 // x, y & z-coordinates to the end of file
...
...
| |
by: GeekBoy |
last post by:
I am reading a file of numbers using for loops.
The numbers are in a grid as follows:
8 36 14 11 31 17 22 23 17 8 9 33
23 32 18 39 23 25 9 38 14 38 4 22
18 11 31 19 16 17 9 32 25 8 1 23
|
by: Eric Lilja |
last post by:
Hi! I have a program with a class that needs to be able to write
itself to a file in clear text format. The file has two integers and
vector of struct objects. The struct has a string that can consist of
one or more words and a few integers. I'm able to create the file
properly, as confimed by viewing it in a text editor, but something
goes wrong when I tried to read it. I've made a test program
illustrating the problem:
#include...
|
by: =?Utf-8?B?emFsZHk=?= |
last post by:
Hi!
I have a question..
How can csharp read a text file and execute it in another application? What
I mean is that, Im doing a drawing using Tekla Structures. But instead of
doing the same thing over and over again, I want to create an exe file that
allows it to read a text file and execute it in Tekla Structures. All I can
do now is to copy the contents of that text file and paste it in csharp
editor and run it, therefore I cannot...
|
by: imailz |
last post by:
Hi all,
since I'm forced to switch from Fortran to C I wonder if there is
posibility in C:
1) to use implicit loops
2) to parse several variables which number is determined at runtime.
Following example:
The output contains n columns which have to be read in. The number of
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |