2012-03-02 146 views
1

我想知道这段代码究竟做了什么?repr(struct.pack('L',s))是什么意思?

python -c "import sys , struct ; s=int(sys.stdin.read(),16); print '0x%08x: %s' % (s,repr(struct.pack('L' , s)))" 

和什么pack()和repr()函数完全相同?

注:s是一样的东西080483分贝=>内存

回答

1

地址从help(struct.pack)help(repr)

repr(...) 
    repr(object) -> string 

    Return the canonical string representation of the object. 
    For most object types, eval(repr(object)) == object. 

pack(...) 
    Return string containing values v1, v2, ... packed according to fmt. 

repr是相当常用的Python中。

该行输出您输入的数字,但是作为字节的值。所以如果你给它4141414141414141它会吐出0x4141414141414141: 'AAAAAAAA'