3

I have my custom class that represents an object. I want to make that object compatible with "ast.literal_eval()"

How can I do that? I can add necessary method/code to my class if necessary.

1
  • 4
    ast.literal_eval evaluates literals. Python does not support user defined literals. Ergo, you can't use ast.literal_eval to produce a user defined type. If you could, all the security guarantees of ast.literal_eval would go out the window. Commented Mar 18, 2017 at 5:39

2 Answers 2

5

You cannot. You will need to reimplement it from scratch, adding support for your class within it.

Sign up to request clarification or add additional context in comments.

2 Comments

my question is how can i add that support to my class?
You cannot. ast.literal_eval() chooses what it accepts.
1

Because you tagged your question with Pyro, I assume you're asking it in the context of serializing your own classes when using Pyro's remote method calls. Pyro provides a mechanism to do that.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.