I have accepted the answer to this question by @dtanabe Here is my code
def abc(): pass
x = abc
class label:
def __init__(self,fnname):
self.lbl = fnname
def __repr__(self):
repr(self.lbl)
def __str__(self):
# how should this be defined?
# I have no objection if other class functions
# or variables need to be defined
u = label(x)
I would like print(u)
to respond with abc
(three characters) on the screen and print([u])
to respond with [abc]
(five characters). In each of these two cases, I do not want to see on screen any single or double quote mark anywhere near the strings of length 3 or 5.
Of course, I would like the analogous behaviour for a function abcdefg
, with print(u)
giving rise to abcdefg
on the screen and print([u])
giving rise to [abcdefg]
on the screen.
Your answer is allowed to change the definition of the class, but it is not allowed to change anything outside the class definition.