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 9230787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:54:24+00:00 2026-06-18T05:54:24+00:00

Say I have defined a class myself and I defined a __repr__ method for

  • 0

Say I have defined a class myself and I defined a __repr__ method for it. I want to about convert it back to my object. I know that object serialization may be a good way of doing so (using the json module) but is there anyway I can use the built-in eval function to achieve this?

  • 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-18T05:54:25+00:00Added an answer on June 18, 2026 at 5:54 am

    Write your __repr__() so it creates a valid Python expression for instantiating your object.

    class MyClass(object):
        def __init__(self, a, b):
            self.a = a
            self.b = b
        def __repr__(self):
            return "%s(%r, %r)" % (type(self).__name__, self.a, self.b)
    

    Obviously this relies on the values you’re using having their own reasonable repr().

    You don’t have to define any special eval()—just pass in whatever you get from repr().

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

Sidebar

Related Questions

Let's say that I have a class defined in moduleA.py which I want to
Let's say I have a base class defined as follows: class Form(object): class Meta:
I have defined an object that has several attribute.. class thing(object): def __init__(self, type,
Say I have a MATLAB object defined in a class file classdef foo properties
Say I have a class defined as class Object { public int ID {
Let's say I have a class structure that is defined below: Class Item(models.Model): ...
I want to invoke a method of an object from user defined class for
Say I have a class I defined called 'MyClass'. My 'main' method takes as
Let's say we have defined a CSS class that is being applied to various
Let's say I have defined the following class: public abstract class Event { public

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.