str() representation of sequences and dicts

K

Kwikrick

When calling str() on a sequence or dict object, the elements of the
sequence/dict will be represented as if their __repr__ method was
called. Why is this? Wouldn't it be more consistent when calling str()
on sequence to use the __str__ method of the elements in the sequence?

As it is now, I often find myself typing something like:

print map(str, alist)

instead of just

print str(alist)

For dicts, it's more eleborate still.

Is there a better way to deal with this?

Rick.
 
S

Steve Holden

praba said:
Dear All,

I want to know about Modules and packages.
I can understand about Modules but I cannot understand
about Packages. Kindly let me
know about Packages with small example.
I can understand conceptually but I don't know
how to write programmatically.

regards
Prabahar
Prabahar:

In your headers I see "In-Reply-To:
<[email protected]>". This means
that people will see your message as part of another thread. It's better
not to do that if you want your message to be read in the proper context.

A package is simply a directory containing an __init__.py file, which is
executed when the package is imported. Sub-packages are subdirectories
of the package main directory containing __init__.py files, which will
be executed when the sub-package is imported. Packages can also contains
modules, which are regular Python files that are executed when the
module is imported.

So, in brief, packages are just a way to let you organize your code in
to a set of mutually dependent modules and sub-packages, making source
maintenance easier and allowing selective import of parts of the
implemented functionality.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top