![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Nov 2008
Posts: 305
Rep Power: 2
![]() |
Problems with the interpreter's exit() function.
I'm using the code module to add an interactive interpreter to an object. This object has an interact method that when called creates an interactive interpreter with the object's dictionary as the namespace for the interpreter.
When done interacting with the object, I want the "exit" function to return execution back to the original thread of execution. Here is the initial code. Python Syntax (Toggle Plain Text)
In the command prompt, calling the object's interact method and then calling the exit function results in a complete exit, but using ctrl+z and return returns the thread of execution to the original interpreter. In the IDLE GUI interpreter, calling the object's interact method and then calling the exit function results in a complete exit, and ctrl+z and return only erases the last input or output. So I'm open to suggestions. If possible I'd like to avoid redefining the exit function. My first instinct was to catch the SystemExit exception in the interact function and return. This works well in the command prompt. However, it still results in a complete exit in the IDLE GUI interpreter. Python Syntax (Toggle Plain Text)
I have one tangent question about this. The object's attributes and methods not in the object's dictionary are obviously not accessible in the new interpreter. (In this case the property functions and the interact function.) This isn't a problem at the moment because I cannot think of any compelling reason why they should be accessible, and variables and functions defined in the new interpreter will be accessible from the object once the interpreter exits. If I did want these attributes and methods to be accessible though, what would be the best way to do it? Thank you for reading this.
__________________
IT'S int main() DAMN IT!!! Chronic sufferer of fancy programming syndrome. |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Nov 2008
Posts: 305
Rep Power: 2
![]() |
Re: Problems with the interpreter's exit() function.
I was able to answer my last question.
In order to access all of the attributes of the object simply pass locals() as the local, and then refer to the object as "self".
__________________
IT'S int main() DAMN IT!!! Chronic sufferer of fancy programming syndrome. Last edited by lrh9; Jan 18th, 2010 at 12:32 PM. |
|
|
|
|
|
#3 | |
|
Programmer
Join Date: Jun 2008
Posts: 34
Rep Power: 0
![]() |
Re: Problems with the interpreter's exit() function.
Quote:
__________________
Linux counter #99383 |
|
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Nov 2008
Posts: 305
Rep Power: 2
![]() |
Re: Problems with the interpreter's exit() function.
Neither. The code module's interpreter is merely an emulator of the Python interpreter. In simple terms, it starts an input loop that executes input as code - in the fashion of the Python interpreter.
Unfortunately, the only way to interrupt this loop as far as I know without redefining it is to use the exit function. Instead of exiting, I want to go back to the original interpreter.
__________________
IT'S int main() DAMN IT!!! Chronic sufferer of fancy programming syndrome. |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jun 2008
Posts: 34
Rep Power: 0
![]() |
Re: Problems with the interpreter's exit() function.
Can you put the code under a while loop and set a variable to 'False' when you want to exit instead of calling sys.exit(), or return from a function?
__________________
Linux counter #99383 |
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Nov 2008
Posts: 305
Rep Power: 2
![]() |
Re: Problems with the interpreter's exit() function.
I would have liked the intuitive command for exiting an interpreter to be the command for exiting this interpreter emulator.
__________________
IT'S int main() DAMN IT!!! Chronic sufferer of fancy programming syndrome. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem using function | exquisite000 | C | 4 | Oct 23rd, 2009 4:21 AM |
| Calling the function using function pointer in the perl script. | dattaforit | Perl | 2 | Mar 3rd, 2009 4:49 AM |
| Assigning a class function as a callback function | core8583 | C++ | 4 | Jun 18th, 2008 7:20 PM |
| Function problems | Prm753 | C | 8 | Jan 5th, 2006 3:13 PM |
| change the empty function from the old format to the new format | powah | Sed and Awk | 0 | Jun 23rd, 2005 11:10 AM |