Override "remaining elements truncated" in Python

I'm using the Python shell in Django to make some queries. The results keep getting truncated. I get the message, "remaining elements truncated." How can I see all the results? Or, how can I write the results to a file?


Querysets do this automatically when you just output them in the shell - which implictly calls repr on them. If you call list on the queryset instead, that will output everything:


Note that you don't need to do this within your code, this is just for output within the shell. Obviously, beware of doing this on a model with a very large number of entries.

Say your query is:

>>> Foo.objects.all()

Instead try:

>>> for x in Foo.objects.all(): print x

Or to dump them to a file:

>>> f = open('your_filename','w')
>>> for x in Foo.objects.all(): f.write(u'%s\n' % x)
>>> f.close()

Category:python Time:2010-07-14 Views:13
Tags: python django

Related post

  • Searching for elements in a python list 2011-03-27

    Searching for elements in a python list and then accessing particular values Mylist = [('A',3,['x','y','z']),('B',2,['m','n'])] Variable = 'A' i = Mylist.index(Variable) print i For example I would like to check if is Variable is present and access i

  • Remove an array and shift the remaining elements 2009-05-18

    How do I remove an element of an array and shift the remaining elements down. So, if I have an array, array[]={1,2,3,4,5} and want to delete 3 and shift the rest so I have, array[]={1,2,4,5} How would I go about this in the least amount of code? ----

  • Overriding a static method in python 2009-05-21

    Referring to the first answer about python's bound and unbound methods here, I have a question: class Test: def method_one(self): print "Called method_one" @staticmethod def method_two(): print "Called method_two" @staticmethod def method_three(): Te

  • How to apply a logical operator to all elements in a python list 2009-11-24

    I have a list of booleans in python. I want to AND (or OR or NOT) them and get the result. The following code works but is not very pythonic. def apply_and(alist): if len(alist) > 1: return alist[0] and apply_and(alist[1:]) else: return alist[0] A

  • How to look ahead one element in a Python generator? 2010-03-11

    I can't figure out how to look ahead one element in a Python generator. As soon as I look it's gone. Here is what I mean: gen = iter([1,2,3]) next_value = gen.next() # okay, I looked forward and see that next_value = 1 # but now: list(gen) # is [2, 3

  • Layout measurement override of element should not return NaN values as its DesiredSize 2011-03-11

    I've run into a similar issue when I try to call Measure and pass the dynamically calculated size to that method: Layout measurement override of element 'System.Windows.Controls.StackPanel' should not return NaN values as its DesiredSize. I am trying

  • How to make a custom element im gst-python 2011-03-21

    i have quite a lot of experience with python and gst-python, but no experience with plain gstreamer. does anyone know (well, someone on earth probably does but...) how to create a custom element? i got as far as class MyElement(Element): by intuition

  • How can I display first n elements, then expand to show remaining elements? 2011-10-27

    I have a list of elemnts (let's say 10) and I only show first 4 on page load. Clicking more will expand the list and show remaining elements. My html code looks like this: <div id="sales"> <div class="listContainer"> <ul> <li>

  • How can I override class attribute access in python? 2012-03-22

    How can I override class attribute access in python? P.S. Is there a way to leave regular access to class attributes alone but calling a more specific exception on missing attribute? --------------Solutions------------- The __getattr__ magic method i

  • Overriding 'to boolean' operator in python? 2009-04-17

    I'm using a class that is inherited from list as a data structure: class CItem( list ) : pass oItem = CItem() oItem.m_something = 10 oItem += [ 1, 2, 3 ] All is perfect, but if I use my object of my class inside of an 'if', python evaluates it to Fal

  • Overriding default tab behaviour in Python Tkinter 2010-11-03

    I am writing an application in Python using Tkinter to manage my GUI. There is a text entry box on which I am trying to implement an autocompletion function which will bind to the Tab key. I have bound the tab key to my entry box, but when I press ta

  • HTML Truncating in Python 2011-02-11

    Is there a pure-Python tool to take some HTML and truncate it as close to a given length as possible, but make sure the resulting snippet is well-formed? For example, given this HTML: <h1>This is a header</h1> <p>This is a paragraph

  • Any way to override the and operator in Python? 2009-01-23

    I tried overriding __and__, but that is for the & operator, not and - the one that I want. Can I override and? --------------Solutions------------- You cannot override the and, or, and not boolean operators. No you can't override and and or. With

  • Overriding class member variables in Python (Django/Satchmo) 2009-04-17

    I'm using Satchmo and Django and am trying to extend Satchmo's Product model. I'd like to make one of the fields in Satchmo's Product model have a default value in the admin without changing Satchmo's source code. Here is an abbreviated version of Sa

  • Empty XML element handling in Python 2009-07-27

    I'm puzzled by minidom parser handling of empty element, as shown in following code section. import xml.dom.minidom doc = xml.dom.minidom.parseString('<value></value>') print doc.firstChild.nodeValue.__repr__() # Out: None print doc.first

  • Delete many elements of list (python) 2009-09-20

    I have a list L. I can delete element i by doing: del L[i] But what if I have a set of non contiguous indexes to delete? I=set([i1, i2, i3,...]) Doing: for i in I: del L[i] Won't work. Any ideas? --------------Solutions------------- Eine Minuten bitt

  • How to prevent log file truncation with python logging module? 2009-10-05

    I need to use python logging module to print debugging info to a file with statements like: logging.debug(something) The file is truncated (i am assuming - by the logging module) and the messages get deleted before I can see them - how can that be pr

  • What is the pythonic way to detect the last element in a python 'for' loop? 2009-10-27

    I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only between elements, being suppressed in the last one. Here is how I curren

  • How to join lists element-wise in Python? 2009-12-11

    l1 = [4, 6, 8] l2 = [a, b, c] result = [(4,a),(6,b),(8,c)] How do I do that? --------------Solutions------------- Use zip. l1 = [1, 2, 3] l2 = [4, 5, 6] >>> zip(l1, l2) [(1, 4), (2, 5), (3, 6)] Note that if your lists are of different length

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.656 (s). 13 q(s)