Search notes:

Python: repr

repr(obj) returns a string that usually(?) can be used in an eval(…) statement to get the original object back:
#!/usr/bin/python3

var = {'foo':  42,
       'bar':'baz'
      }

var_repr = repr(var)
print('type(var_repr) = {:s}'.format(str(type(var_repr)))) # type(var_repr) = <class 'str'>

print(var_repr) # {'foo': 42, 'bar': 'baz'}
    
repr_evald = eval(var_repr)

print('type(repr_evald) = {:s}'.format(str(type(repr_evald)))) # type(repr_evald) = <class 'dict'>
                                                                  
for k,v in repr_evald.items():
    print("{:s} = {:s}".format(k, str(v)) )
Github repository about-python, path: /builtin-functions/repr/eval.py

See also

Behind the scenes, repr() calls an object's __repr__ method.
sys.float_repr_style is a string that controls the behaviour of repr() for floats.
Python: Built in functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758206306, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/built-in-functions/repr/index(63): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78