views:

154

answers:

4

Sometimes I'll be working with, say, a list of thousands of items in IDLE, and accidently print it out to the shell. When this happens, it crashes or at least very significaly slows down IDLE. As you can imagine, this is extremely inconvenient. Is there a way to make it, rather than printing the entire thing, just give me a summarised [1, 2, ...] output? Any help would be much appreciated.

A: 

Use IPython as shell instead.

bialix
Will iPython works on Python 3?
Selinap
A: 

You could use custom print function.

Maiku Mori
+2  A: 

As above, try a custom print function like:

def my_print(obj):  
    if hasattr(obj, '__len__') and len(obj) > 100:  
        print '... omitted object of %s with length %d ...' % (type(obj), len(obj))  
    else: print obj
marqueed
A: 

In Python 3, since print is a function, you should be able to "override" it. (I don't have it installed so I can't try it out to make sure.) Probably not recommended for real applications but if you're just trying things out, it would be okay I suppose.

It would go something like:

def myprint(*args):
    # write the function as described by other people
print = myprint
MatrixFrog