Best python module for Oracle, but portable to other RDBMSes

Magnus Lycka lycka at carmen.se
Fri Mar 3 09:36:17 EST 2006


dananrg at yahoo.com wrote:
> # Print new list
> print recordList
> 
> 
>>>>[872L, 'ACTIVE', <DbiDate object at 011F6000>, <DbiDate object at 00EA1428>, None, '1.0.0.0', None, None, None]

Read the Python library manual chapter 2. Read all of it, it's all
very useful information, but take a particular look at str() and
repr(). All Python object can be "viewed" in two standard ways, via
the str() or repr() functions. In short, the str() stringification
is typically to be more end-user friendly, while the repr() stringi-
fication is more intended to properly identify exactly what kind of
an object we see: what type it is, and often the value too. (Above,
you don't see any reasonable value at all in the DbiDate objects,
but for some reason that didn't seem to bother you as much as the
suffixed L on the long ints.)

When you just print a Python object x of some kind, i.e.

print x

it will be equivalent of

print str(x)

To see the other representation, use

print repr(x)

Python collections, such as lists, tuples and dicts, aren't really
intended to be printed as is to end users. If recordList is a list,
and there is a statement "print recordList", it's probable that it
is intended as a diagnostic help to a programmer during development,
rather than to an end user. So, it's rather clever to use the repr()
stringification, so that it's clear exactly what we see, e.g. all
strings are quoted, so you clearly see things as trailing spaces,
can differentiate between tabs and sequences of spaces, and aren't
confused by commas inside the strings. Also, for longs, you get a
trailing L to indicate that this isn't simply a normal integer, but
an arbitrarily long one.



More information about the Python-list mailing list