repr on a string

David Shochat shochatd at yahoo.com
Mon Jun 2 02:08:28 CEST 2003


On Sun, 01 Jun 2003 22:58:54 +0100, Alexander Schmolck wrote:

> David Shochat <shochatd at yahoo.com> writes:
> 
>> The Library Reference says this about built-in repr():
>>  Return a string containing a printable representation of an object.
>> 
>> While studying Programming Python, 2nd Ed. Example 2-18, p. 84, I was
> 
> Haven't got the book, so I can't comment on the specific example, but see
> below.
> 
Thanks for your reply (also to Gerrit Holl). I can see I need 
to learn more about eval().

Anyway, here is a fragment of the book example I was 
referring to, with a bit more context:

for dir in sys.path:
    if string.find(os.path.abspath(dir), 'PyTools') != -1:
        print 'removing', repr(dir)
        sys.path.remove(dir)

In the 3d line, why does he not just say:

  print 'removing', dir

Why the call to repr() here?





More information about the Python-list mailing list