Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:27:53+00:00 2026-06-11T02:27:53+00:00

I was trying IPython with a module I created and it does not show

  • 0

I was trying IPython with a module I created and it does not show the actual representation of class objects. Instead it shows something like

TheClass.__module__ + '.' + TheClass.__name__

I heavily use metaclasses in this module and I have really meaningful class representations that should be shown to the user.

Is there an IPython specific method I can change to make the right representation available instead of this namespace thingy that is quite useless in this application?

Or, if that’s not possible, how can I customize my version of IPython to show the information I want?


EDIT

As complementary information, if I get a class and change the __module__ attribute to e.g. None, it blows with this traceback when trying to show the representation:

Traceback (most recent call last):
  ... [Huge traceback] ...
  File "C:\Python32\lib\site-packages\IPython\lib\pretty.py", line 599, in _type_pprint
    name = obj.__module__ + '.' + obj.__name__
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

So my expectations were right and this function is used to show class objects:

def _type_pprint(obj, p, cycle):

I tried customizing it in my class but I don’t think I’m doing it right. This module IPython.lib.pretty does have a big dictionary linking type (the parent of metaclasses) with this function.


EDIT 2

Things I tried:

  1. Adding the _repr_pretty_ function to metaclass. It do work with instances but not with classes…
  2. Using this function IPython.lib.pretty.for_type(typ, func). It only changes the big dictionary a wrote above but not the copy of it made by the RepresentationPrinter instance… So this function has no use at all?!
  3. Calling the magic function %pprint. It disables (or enables) this pretty print feature, using the default Python __repr__ for all the objects. That’s bad because the pretty printing of lists, dict and many others are quite nice.

The first approach is more of what I want because it does not affect the environment and is specific for this class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:27:54+00:00Added an answer on June 11, 2026 at 2:27 am

    This is just an issue with IPython 0.12 and older versions. Now is possible to do:

    class A(type):
        def _repr_pretty_(cls, p, cycle):
            p.text(repr(self))
    
        def __repr__(cls):
            return 'This Information'
    
    class B:   #or for Py3K: class B(metaclass=A):
        __metaclass__ = A
    

    and it’ll show the desired representation for B.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
I'm trying to load pickled objects in iPython. The error I'm getting is: AttributeError:
I'm trying to determine the actual current module of a function (as seen if
I'm trying to use the IPython demo mode. I created a file called test.py
Is there anything like Zenity built into iPython? If not, what would be the
Trying to figure out how I can do this properly. The print_r looks like
Trying to install this ipython version. infact there's a django-starter project which uses buildout
I am trying to install Ipython 0.12 on to python 2.7. Because I'm using
I've got a Django product I'm using iPython to interact with. I'm trying to
I'm trying to setup ipython.el in emacs23. I've successfully installed it (after putting python-mode.el

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.