any plans to make pprint() a builtin?

J

John Salerno

Just wondering if this will ever happen, maybe in 3.0 when print becomes
a function too? It would be a nice option to have it available without
importing it every time, but maybe making it a builtin violates some
kind of pythonic ideal?
 
D

Duncan Booth

John said:
Just wondering if this will ever happen, maybe in 3.0 when print becomes
a function too? It would be a nice option to have it available without
importing it every time, but maybe making it a builtin violates some
kind of pythonic ideal?

There are so many things which *could* be builtins, and it really is better
not to pollute the global namespace with more than absolutely necessary.

Personally I'd just like to see 'python' a builtin shorthand for importing
a name you aren't going to use much
e.g.

python.pprint.pprint(x)
 
T

Tim Golden

Duncan said:
There are so many things which *could* be builtins, and it really is better
not to pollute the global namespace with more than absolutely necessary.

Personally I'd just like to see 'python' a builtin shorthand for importing
a name you aren't going to use much
e.g.

python.pprint.pprint(x)

I think that's what the py.lib people have done with
their py.std module:

http://codespeak.net/py/current/doc/misc.html#the-py-std-hook

(At least, it looks like it; I've never used it myself).

TJG
 
J

John Salerno

Kent said:
Would you settle for
import py
py.std.pprint.pprint(x) ?

http://codespeak.net/py/current/doc/misc.html#the-py-std-hook

Kent

Interesting, but that could start to get a little too messy I think. I'd
rather just have the 'authentic' code in my program (i.e. pprint.pprint)
instead of the py.std prefix as well.

It's a good point not to pollute the builtin namespace with too much, so
I think I'd rather just import pprint when needed instead of using the
py.std call.
 
A

Ant

Considering that the current:

import pprint
pprint.pprint(x)

is hardly lengthy, I can't see how either of the alternatives proposed
are any better.
python.pprint.pprint(x)

6 characters shorter, but considerably more keystrokes if you are using
pprint more than once. Is it worth adding the 'python' builtin to save
an import statement?
import py
py.std.pprint.pprint(x)

Longer, messy, and what's the actual point? Wouldn't:

import pprint as pp
pp.pprint(x)

be better, standard *and* shorter?
 
J

John Salerno

Ant said:
Considering that the current:

import pprint
pprint.pprint(x)

is hardly lengthy, I can't see how either of the alternatives proposed
are any better.


6 characters shorter, but considerably more keystrokes if you are using
pprint more than once. Is it worth adding the 'python' builtin to save
an import statement?


Longer, messy, and what's the actual point? Wouldn't:

import pprint as pp
pp.pprint(x)

be better, standard *and* shorter?

I guess the idea is that you can use the import py statement to access
many other modules as well, without importing them all separately.
 
E

Edward Elliott

Ant said:
Longer, messy, and what's the actual point? Wouldn't:

import pprint as pp
pp.pprint(x)

be better, standard *and* shorter?

why not just:

from pprint import pprint
pprint (x)

No need to modify the interpreter when you can pollute the global namespace
yourself just as easily.
 

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,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top