tobie (owner)

Revisions

gist: 78424 Download_button fork
public
Description:
Python repr of common types
Public Clone URL: git://gist.github.com/78424.git
Embed All Files: show embed
Python #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
repr(False)
#-> False
 
repr(True)
#-> True
 
repr(None)
#-> None
 
repr('foo')
#-> 'foo'
 
repr(123)
#-> 123
 
repr(123.4)
#-> 123.40000000000001
 
import re
r = re.compile('foo')
repr(r)
#-> <_sre.SRE_Pattern object at 0x22758>
 
import time
from datetime import date
repr(date.today())
#-> datetime.date(2009, 3, 13)
 
repr([0, 1, [2, 3]])
#-> [0, 1, [2, 3]]
 
repr({'foo': 123})
#-> {'foo': 123}
 
# self-containing arrays
a = [1, 2, 3]
a.append(a)
repr(a)
#-> [1, 2, 3, [...]]
 
# self-containing hashes
h = {'foo': 123}
h['bar'] = h
repr(h)
#-> {'foo': 123, 'bar': {...}}
 
class Foo:
  def __init__(self):
    self.foo = 123
    self.bar = 456
  
repr(Foo())
#-> <__main__.Foo instance at 0x64260>
 
repr(Foo)
#-> <class __main__.Foo at 0x51a20>
 
repr([].reverse)
#-> <built-in method reverse of list object at 0x50738>