lrh9 95 Posting Whiz in Training

Very cool.

lrh9 95 Posting Whiz in Training

Nice catch.

Python's builtin rounding function can help with that. Trouble is determining the number of significant digits for rounding.

lrh9 95 Posting Whiz in Training

That's not what I would do. Two integer objects are equal if and only if their numeric value is the same and unequal if and only if their numeric value is different. That isn't dependent upon their existence as an object. Looking at the '__eq__' method on the shapes it checks only that both shape objects are the same type and that their dimensions are equal. Two shapes are equal if and only if they are the same type and the same size. Two shapes are unequal if and only if they are a different type or they have a different size.

But the decision isn't up to me. That's just what I would think if I were in the poster's position.

lrh9 95 Posting Whiz in Training

Anyone with sufficient skills at Google could have found that information in the Python documentation.

http://www.lmgtfy.com/?q=python+dictionary

http://docs.python.org/tutorial/datastructures.html#dictionaries

lrh9 95 Posting Whiz in Training

P.S. I skimmed over the problem set. I'm not seeing any stipulation that the set needs to be sortable. Where did you see it?

lrh9 95 Posting Whiz in Training

You are also right about '__repr__'. However, for this assignment the set's '__str__' method does need to be overwritten.

OK. Hash returns an integer value representing an object. Two objects with the same value will return the same hash value, but the opposite is not necessarily true. Two objects with the same hash value may not necessarily have the same value. However, since set uses this value it must be accurate enough for the purposes of set.

I'm thinking that if I implement a '__hash__' method on each shape then set will work properly. I'm thinking that since tuples are hashable I should make each shape return the hash value for the tuple of its data.

class Square(Shape):

    def __hash__(self):
        return hash((type(self), self.side))

class Circle(Shape):

    def __hash__(self):
        return hash((type(self), self.radius))

I tested sets composed of shape object's with this method. They worked as specified. Only shapes with unique values were added to the set.

from ps9 import Square, Circle

myset = set([Square(9.5), Circle(4.2), Square(9.5)])
print(myset)

That should result in a representation of the contents. One circle object and one square object. (I overrode the '__repr__' methods to ensure that they had the values I specified. They did.)

lrh9 95 Posting Whiz in Training

I made another error. ps9 does have '__str__' methods for some of the classes.

I should have tested what I was suggesting. It didn't work for me. I assumed it would but I made an ass out of myself.

I'm getting a different bug though. My interpreter is complaining that the Circle type is not hashable.

Maybe fixing this would solve the problem? I'll get back when I learn what hashing is all about.

P.S. Nice work importing all from ps9. Me having to type ps9 over and over should have been a good indication to import the names that I needed.

lrh9 95 Posting Whiz in Training

To express my opinion frankly, the instructions are stupid. I'll explain why later.

However, let me see if I can help.

We're looking at Problem 2?

In this problem you are implementing a custom container class to hold shape objects. The main purposes of this container are to ensure that each shape is unique, provide a method to return a string representation of the shapes in the container, and to provide a method to iterate over the shapes in the container.

You won't have to worry about creating a list of several element tuples. Each shape is represented by a shape object. The shape classes are in ps9.py. When you add a shape to the container you'll be adding a shape object not the shape's data.

If you were making a program you would import the ps9 module to provide access to the shape classes. Then you can add a shape to a ShapeSet. (Reading the ps9 module some more I see that the ShapeSet should be in the ps9 module, but let's keep it in the script for the moment.)

import ps9

class ShapeSet:

    def addShape(self, sh):
        #Add shape 'sh' to the container after ensuring that it is unique.
        pass

myShapeSet = ShapeSet()
mySquare = ps9.Square(9.5)
myShapeSet.addShape(mySquare)

Luckily each shape has a '__eq__' method you can call to compare it to another shape. (And you won't have to bother to ensure that each shape is of the same type. The '__eq__' method of …

lrh9 95 Posting Whiz in Training

And I figured out a way to do it no thanks to you guys. :D

I thought I was asking for an arm, a leg, a firstborn child, and a million dollars the way you guys were holding out on assistance.

The script on the desktop.

from mypackage import mymodule

print(mymodule.MYVARIABLE)

The module.

import configparser
import os
import sys

config = configparser.ConfigParser()

#If the module is executed as a script __name__ will be '__main__' and sys.argv[0] will be the full path of the module.
if __name__ == '__main__':
    path = os.path.split(sys.argv[0])[0]
#Else the module was imported and it has a __file__ attribute that will be the full path of the module.
else:
    path = os.path.split(__file__)[0]

#The configuration parser reads the file at the full path made by joining the base path and the file name.
config.read(os.path.join(path, 'mycfg.cfg'))

MYVARIABLE = config.get('MYSECTION', 'MYVARIABLE', 0)

The configuration file in the same directory as the module.

[MYSECTION]
MYVARIABLE=55
lrh9 95 Posting Whiz in Training

Sometimes specifying a path or package relative to the current module is the best way to do it, especially when the path or package referred to can change location.

Say you have a package and you create a submodule with several dependencies to other submodules in the same package. You explicitly import each module from the package.

from mypackage import module1
from mypackage import module2
from mypackage import module3

Works fine. No complaints. However, later your package becomes a subpackage for another package. So you have to edit the file.

from mypackage.mysubpackage import module1
from mypackage.mysubpackage import module2
from mypackage.mysubpackage import module3

Not good. The more dependencies or the larger the change in nesting the worse editing is. Even if you didn't mind your users might. That's why you use relative imports.

#'.' represents the module's package.
from . import module1
from . import module2
from . import module3

That will always work no matter if the package is the highest package or it is turned into a subpackage. No editing required.

It's not too much to ask for relative paths.

lrh9 95 Posting Whiz in Training

I'm not using a directory name with spaces in it.

That was just the error message.

lrh9 95 Posting Whiz in Training

Doesn't work. Here's an example of what I'm trying to do.

My script that I'm running from the desktop.

#import module from package in site-packages.
from mypackage import mymodule

print(mymodule.variable)

My module.

import configparser

myconfig = configparser.ConfigParser()

#Read in the configuration file in the same directory as the module.
myconfig.read('mycfg.cfg')

myvariable = myconfig.get('MYSECTION', 'MYVARIABLE', 0)

The configuration file.

[MYSECTION]
MYVARIABLE=55

Running the desktop script produces this error, like the configuration file isn't even there.

Traceback (most recent call last):
  File "C:\Documents and Settings\User\Desktop\myscript.py", line 2, in <module>
    from mypackage import mymodule
  File "C:\Python31\lib\site-packages\mypackage\mymodule.py", line 8, in <module>
    myvariable = myconfig.get('MYSECTION', 'MYVARIABLE', 0)
  File "C:\Python31\lib\configparser.py", line 537, in get
    raise NoSectionError(section)
configparser.NoSectionError: No section: 'MYSECTION'

Moving the configuration file to the desktop remedies this, but I don't want to have to keep the module configuration file where any script that uses the module is at. I want the module to refer to the configuration file in its directory.

lrh9 95 Posting Whiz in Training

I know that certain functions will check the script's or module's current directory for the file if no path is specified.

open('test.txt')

If that script is run and test.txt is in the same directory that will open the correct file.

However, if I try to import that module it doesn't work because presumably the path is different. How can I get this to work proper?

lrh9 95 Posting Whiz in Training

Another way.

float1 = 6.4
float2 = 6.3 + 0.1

print([float1, float2]) # [6.4, 6.3999999999999995]

print(float1 == float2) # False

#print(help(round)) # Uncomment to learn about the round function.
print([round(float1, 1), round(float2, 1)]) # [6.4, 6.4]

print(round(float1, 1) == round(float2, 1)) # True
lrh9 95 Posting Whiz in Training

I'd answer number 1 a little differently than Gribouillis.

Technically everything under the hood is entirely object oriented and you can certainly write pure object oriented programs in Python, but it is also possible to write programs in a purely functional style as well.

As for number 5?

You can fill me in if time would permit you.

:D

lrh9 95 Posting Whiz in Training

First, Python doesn't use semicolons to terminate lines of code.

P.S. Someone beat me to it, but maybe I can help a little more.

A fairly quick way to accomplish what you wish to accomplish is to create a set of the string and then check the length of that.

A set is a container for unique, hashable objects. (Strings are hashable because they are immutable, but hashability and mutability are really tangent to this discussion.)

Typecasting a string to a set will automatically filter out duplicate characters with three caveats. First, it won't preserve the order of the characters as they were in the original string. Second, lowercase letters and uppercase letters are represented using different values meaning a set won't filter out a capital 'T' if there is a lowercase 't' or vice versa. Third, it will also count whitespace meaning if it has spaces the set will have one space or if it has newlines the set will have one newline.

However, the first doesn't appear to be an issue for you and the second can be remedied using a string's 'lower' method. The third can be remedied by using a string's 'replace' method to replace any whitespace with a no character of two single quotes.

I'll give you an example using code like yours.

from string import whitespace

def char_items(string, count_caps = False, count_whitespace = False):
    if not count_caps:
        string = string.lower()
    if not count_whitespace:
        """
        Inefficient.
        Strings are …
d5e5 commented: Good supplemental info. After reading your answer I see mine had an unnecessary step. +1
lrh9 95 Posting Whiz in Training

Gribouillis makes some good suggestions.

As for storing the data to a file there are really two standard, commonplace options that I think are suited to this.

I'd either pickle or marshal the object.

pickle and marshal can store and retrieve a Python object on file.

Both are similar, but pickle creates a file that will work across platforms and marshal creates a file that will only work on a type of system it is created on.

I read another post you have, and if structured text is necessary I'd try to devise a solution using json, but I'm not familiar with it so I can't help you there.

lrh9 95 Posting Whiz in Training

Cool. Here is a post with some of my older work.

Aside from some minor changes in some function definitions and the new write_bytecode method it is fairly representative of what I have.

http://www.daniweb.com/forums/thread243780.html

lrh9 95 Posting Whiz in Training

Why do you need to generate pyc files ?

I'm just building a custom importer using abstract methods in importlib.abc and one of the methods for a importer that supports loading compiled modules is the ability to write bytecode files.

I could've used py_compile, but the write_bytecode method accepts a module name and bytecode to write so I wanted to keep it in line with the importlib.abc specification.

lrh9 95 Posting Whiz in Training

OK. I managed to generate the pyc file.

I think I was writing the bytes for the timestamp incorrectly.

lrh9 95 Posting Whiz in Training

Interesting changes.

You are probably right about the struct unpacking.

I was using borrowed code.

I'm on a 32 bit system, so long automatically is the largest number of bytes that can fit in that number of bits - four bytes.

However, on a 64 bit system long is eight bytes.

Nice catch.

I didn't expect the error to appear in Linux because it uses UTC time internally without automatically adjusting for DST. Windows does automatically account for DST in local time.

However, according to earlier information I think the problem isn't that the timestamp I am using is invalid, but I am actually not generating a valid pyc file. I'll need to look into py_compile for more info.

lrh9 95 Posting Whiz in Training

Looking in the py_compile module for a solution. Much to my surprise it actually generates the "pyc" files itself instead of depending on the interpreter to handle it.

lrh9 95 Posting Whiz in Training

Unfortunately, the file I generated did induce a recompile on import.

lrh9 95 Posting Whiz in Training

Did some experimentation, and I discovered that the py_compile compile function will generate a pyc file with an internal source modification time matching the source modification time.

Importing the module or reloading it did not induce the generation of a new pyc file.

Interesting.

lrh9 95 Posting Whiz in Training

I'm having a problem with 'os.path.getmtime'.

I've been doing some research into generating '.pyc' files and I am able to retrieve the source modification time (in seconds) as recorded in the '.pyc' file.

It is merely the second set of four bytes unpacked as a long integer.

import random, sys, os, struct

#Points to the random.pyc module.
testfilepath = os.path.join(sys.prefix, 'lib', 'random' + os.extsep + 'pyc')

istream = open(testfilepath, 'rb')

#Read and discard the first four bytes (the magic pyc identifier).
istream.read(4)

#The last modification time of the source according to the file.
modtime = istream.read(4)
istream.close()

#Convert the bytes to an integer.
modtime = struct.unpack('L', modtime)[0]

print('According to the pyc file the time the source file was last modified measured in the number of seconds from the last epoch is:')

print(modtime)

print('Retrieving source modification time using os.path.getmtime.')

#Points to the random.py module.
sourcefilepath = os.path.join(sys.prefix, 'lib', 'random' + os.extsep + 'py')

print('According to os.path.getmtime the time the source file was last modified measured in the number of seconds from the last epoch is:')

print(os.path.getmtime(sourcefilepath))

Oddly for me, the pyc time is one hour behind the time returned by os.path.getmtime. I suspect it is because of wonky dst errors. I'm using Windows XP SP3. I'd appreciate it if you would execute this code and report your results as well as your os and maybe suggest general purpose solutions to this problem.

lrh9 95 Posting Whiz in Training

@Ene Uran

While anyone is free to use any directory they wish, I think the common directory to store third party modules and packages in is the "site-packages" directory in the "lib" directory.

Even better, you don't have to append the "site-packages" directory to the search path which means that any import statement should be able to find your modules and packages.

lrh9 95 Posting Whiz in Training

I've been doing some more work, and this is what I have so far.

#!/usr/bin/env python

version = '3.1.1'

READ_BYTES = 'rb'
REPLACE_BYTES = 'w+b'

import sys

import imp

from importlib import abc

from tokenize import detect_encoding

import os.path

from os import linesep as LINESEP

from string import whitespace
NEWLINE = whitespace[2]

class CopyImporter(abc.Finder, abc.PyPycLoader):

    def __init__(self):
        pass

    def find_module(self, fullname, path = None):
        return self

    def load_module(self, fullname):
        imp.acquire_lock()
        imp.release_lock()
        
    def get_data(self, path):
        try:
            istream = open(file = path,
                           mode = READ_BYTES)
            data = istream.read()
        except:
            raise IOError
        finally:
            if istream:
                istream.close()
        return data

    def get_code(self, fullname):
        source_path = self.source_path(fullname)
        if source_path:
            try:
                data = self.get_data(source_path)
                return compile(source = data.replace(LINESEP.encode(), NEWLINE.encode()),
                               filename = source_path,
                               mode = 'exec')
            except:
                raise ImportError
        return None
    
    def get_source(self, fullname):
        source_path = self.source_path(fullname)
        if source_path:
            try:
                data = self.get_data(source_path)
                source = data.decode(detect_encoding(readline = open(source_path, READ_BYTES).__next__)[0])
                return source.replace(LINESEP, NEWLINE)
            except:
                raise ImportError
        return None
    
    def is_package(self, fullname):
        pass

    def source_path(self, fullname):
        return 'C:\\Python31\\Lib\\random.py'

    def source_mtime(self, fullname):
        source_path = self.source_path(fullname)
        try:
            if source_path:
                return int(os.path.getmtime(source_path))
            return None
        except:
            raise ImportError

    def bytecode_path(self, fullname):
        pass

    def write_bytecode(self, fullname, bytecode):
        if sys.dont_write_bytecode:
            return
        try:
            ostream = open(None,
                           mode = REPLACE_BYTES)
            ostream.write(bytecode)
        except:
            return False
        finally:
            if ostream:
                ostream.close()
        return True


def main():
    pass

if __name__ == '__main__':
    main()

Now I just need to implement the find_module, load_module, is_package, source_path, bytecode_path, and write_bytecode methods.

lrh9 95 Posting Whiz in Training

You're probably right. It'd be especially tough considering that you'd want to return the same type of object and many sequences don't support the "reversed" method.

lrh9 95 Posting Whiz in Training

That's a good solution, Gribouillis. I was wondering if something like that would work. Nice use of "isinstance" to allow users to pass subclasses of lists as an argument. Would we want to use duck typing to allow other sequences?

I don't know if it will be useful, but lists have a method called "reverse" that will reverse the items of a list 'in place', meaning that the original list is reversed instead of a copy returned.

lrh9 95 Posting Whiz in Training

That's going to be a tougher one if I think you are asking for a procedure that can work on lists with mixed items in them down to an arbitrary number of levels.

In a real application you could probably find a better way of representing the data and use simpler programming logic to access it.

lrh9 95 Posting Whiz in Training

Object oriented programming has some advantages in virtually all situations, even if functional programming is sometimes easier to write.

That's why I generally tend to encourage its use over functional programming, but make no mistake that a poorly conceptually designed program will be harder to write using object oriented programming - not easier.

But I agree with Gribouillis that the most important thing to do first is to ask questions about who will be using the program, what they will be using it for, and how they will be using it. This will allow you to form a clearer design - even if its just in your mind. Thinking like a person who will be using the program is a feat that will improve your programs.

So let's start out.

Who will be using your program?
What do they want to use your program to accomplish?

lrh9 95 Posting Whiz in Training

Create an operating system prototype/emulator in Python. You might research into various operating systems to get an idea for what to implement.

Things you can implement:

  • A login.
  • A shell system.
  • A explorer system (If done well enough, you can disable your own explorer process at startup and execute your own.)
  • A desktop window.
  • A web browser. (A project in and of itself.)
  • A plain text editor. (Another individual project.)
  • A control panel/system configuration set of utilities.
lrh9 95 Posting Whiz in Training

Implement a custom importer in conformance with PEP 302 utilizing code from the "importlib" and "imp" modules. This importer can emulate Python import functionality, or you can alter it to suit your desired behavior. For instance, implement an importer that returns a copy of a module instead of modules stored in "sys.modules", or implement an importer that can import from archive formats other than zip files.

lrh9 95 Posting Whiz in Training

There is a variable in the os module called linesep that represents the line separator in text files.

In order to get the bytes for the linesep all you have to do is "os.linesep.encode()".

lrh9 95 Posting Whiz in Training

Then the documentation is wrong.

I did learn that the exec function will only take source that uses '\n' to represent newlines.

I also learned that byte data (and string data) has a replace method that can replace each instance of a byte sequence (or string) with another byte sequence (or string).

Your information led me to realize that you can't manually replace all instances of a specific byte sequence, because different operating systems use different byte sequences to represent newlines. Is there a variable defined in a module that represents the system's newline bytes?

lrh9 95 Posting Whiz in Training

I've seen these in documentation, namely in the "importlib" documentation for Python 3.1, and I'm wondering what the difference is between a "universal newline" and a "standard newline", if any.

I know it has to do with the byte sequence that is used to represent newlines, and I think universal newlines are simply a single linefeed byte, but I'm not sure about standard newlines. Are they simply the form the host machine uses?

lrh9 95 Posting Whiz in Training

One thing that I'm very glad I learned to do as a beginner and still use today - even though I'm probably still a beginner - is to have a basic file with code that is used more often than not in the script. I can copy this file each time I want to create a script and have several things I'd normally want to do in a polished script all ready done.

I call my file "base.py".

#!/usr/bin/env python

version = '3.1.1'

def main():
    pass

if __name__ is "__main__":
    main()

The first line is called a "shebang" I think. I'm a Windows user, but as I understand it having this line in a script allows Linux users to execute the script more easily than if it wasn't included. Having the line doesn't alter program execution so it isn't necessary, but I do it out of consideration for Linux users when I publish code.

The variable "version" does not represent the script's version, but it is the version of Python I wrote the script in. I do this out of consideration for users who might be using different versions of Python.

The 'if __name__ is "__main__":' idiom allows a script to function as an executable script or a module. If the program is executed as a script, the __name__ attribute is "__main__" and the "main" function is called. However, if the script is imported then this code is not executed. The pass statement in …

lrh9 95 Posting Whiz in Training

Also, it is considered bad code to use the '+' operator to concatenate strings. Strings are immutable objects, so appending a string to another string creates a new string object which takes time and memory.

It is better to store each piece in a list until a concatenated string is needed, then join each piece using a string's "join" method on the list.

string1 = 'This'
string2 = 'is'
string3 = 'worse.'
final_string = string1 + ' ' + string2 + ' ' + string3
"""This is worse."""

mylist = ['This', 'is', 'better.']
better_string = ' '.join(mylist)
"""This is better."""
lrh9 95 Posting Whiz in Training

If you find a solution to one of your own problems, it is considered polite to post the solution regardless because other people might also have the same problem.

As for my solution to the problem statement?

I'd probably just strip the string of any non-alphabetic characters excepting spaces and newlines, replace all newlines with spaces, split the resulting string around spaces, iterate over the resulting sequence, and add the word to the dictionary if it is not present with a count of one or increment the counter for the word. (Using the word as the dictionary key. First check that the dictionary has the key for the word, if not then add the key as one or if it does increment the key.)

lrh9 95 Posting Whiz in Training

Hypocrisy?

On the government and supporters of these prayers yes.

lrh9 95 Posting Whiz in Training

The Timer executes the code in a new namespace. This namespace doesn't know lista and listb because they are not in the name space. If you create a module that declares and sets these variables, you could then import it using the Timer's setup statement. (If you need the cell module, just import it in your module and it will be available.)

It says in the timeit module that it is really only suitable for measuring the performance of small snippets of code. If you want to be more serious about profiling code, consider learning about the "profile" module.

lrh9 95 Posting Whiz in Training

What I really believe is that if Christian biblical quotes are being imprinted on military hardware, then any other religious group that wishes to have quotes from their holy books should be offered the same access to government support for their religious views.

Why?

lrh9 95 Posting Whiz in Training

I think the humane treatment of animals - insofar as we should not cause unnecessary distress or pain - is a reasonable standard for law, but otherwise I'm a proponent for the use of animal resources to support and advance human lives.

But no to human rights for animals.

Basically I'm mostly in agreement with AncientDragon so far.

lrh9 95 Posting Whiz in Training

Exactly my point -- The constitution does not state that US government can not practice a religion.

The subtler point of that fact is that the founders of the United States had every opportunity to include religion into the Constitution, yet they made a conscious effort not to do so. To me this separation does indeed imply a wall where the two do not intermingle.

Not relevant. TJ does not speak for the Constitution. That was only his opinion.

Thomas Jefferson was a very important founding father. To me his opinion is highly relevant.

Yes there have been a lot of court cases about this, but not one of them said the Constitution required separation of church and state. Just one example:
Marsh v. Chambers

The court is not a static body, but it changes over the years and can reflect differing interpretations of the Constitution and of events. All though I initially disagree with their decision, politicians do have the right to hold their own beliefs and practice their religion as they see fit. If they need to hire a private chaplain to meet their private needs, then it is not unreasonable to suggest that they might use tax money to do so. Especially considering that their salary is paid with tax money. A case could be made that since they would use their salary to hire individuals anyway, we might as well allow them to use the tax money.

So in fact this …

lrh9 95 Posting Whiz in Training

Now, now. We shouldn't be acting in animosity, but in a spirit of unity and freedom that only a secular democracy can provide.

lrh9 95 Posting Whiz in Training

There is no such thing as "separation of church and state".

What about the fact that there is no mention of a deity anywhere in the United States Constitution?

Or the fact that Thomas Jefferson - author of the Declaration of Independence, founding father, and third President of these United States - coined the phrase in a letter written to Danbury Baptists, in which he referred to the First Amendment to the United States Constitution as creating a "wall of separation" between church and state.

The United States Supreme Court also recognizes the separation of church and state. First in 1878, and then in a series of cases starting in 1947.

And contrary to the argument that only the government is prohibited from interfering in religion, the Treaty of Tripoli has stated, and I quote:

As the Government of the United States of America is not, in any sense, founded on the Christian religion;

This is a strong indication that the founding fathers never intended the United States to be a Christian nation, especially considering that it was drafted by George Washington's administration and Thomas Jefferson.

In addition, the Constitution is a living document that has always traditionally been considered open to the reasonable interpretation of law makers and judges. While there are no explicit words "separation of church and state" in the Constitution, the Establishment clause along with what I've mentioned above as well as the opinions of the founding fathers have been considered …

lrh9 95 Posting Whiz in Training

U.S. Military Weapons Inscribed With Secret 'Jesus' Bible Codes
Pentagon Supplier for Rifle Sights Says It Has 'Always' Added New Testament References

http://abcnews.go.com/Blotter/us-military-weapons-inscribed-secret-jesus-bible-codes/story?id=9575794

I saw this. I think this is wrong.

lrh9 95 Posting Whiz in Training

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".

lrh9 95 Posting Whiz in Training

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.

from uuid import uuid4
import code

ANONYMOUS = None
UUID = 0

class Agent:

    def __init__(self, name = UUID):
        self.__uuid = uuid4()
        if name == UUID:
            name = self.__uuid
        self.__name = name


    @property
    def uuid(self):
        return self.__uuid


    @property
    def name(self):
        return self.__name

    @name.setter
    def name(self, value):
        self.__name = value

    @name.deleter
    def name(self):
        self.__name = ANONYMOUS

    # The interactive interpreter.
    def interact(self):
        code.interact(local = self.__dict__)

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.

def …
lrh9 95 Posting Whiz in Training

There is more than one Python interpreter. There is the command line interpreter that starts when you open the command prompt, navigate to the Python root folder, and type python.exe and hit return.

There is also the IDLE interpreter, the GUI interpreter that starts from the IDLE toolkit.