Setting Up Your Development Environment(Chapter 1 of Gray Hat Python)
时间:2011-04-02 来源:Ray Z
1 >>> from ctypes import *
2 >>> c_int()
3 c_long(0)
4 >>> c_char_p("hello world!")
5 c_char_p('hello world!')
6 >>> c_ushort(-5)
7 c_ushort(65531)
8 >>> seitz = c_char_p("loves python")
9 >>> print seitz
10 c_char_p('loves python')
11 >>> print seitz.value
12 loves python
1 from ctypes import *
2
3 msvcrt = cdll.msvcrt
4 message_string = "Hello world!\n"
5 msvcrt.printf("Testing: %s", message_string)
1 from ctypes import *
2
3 class barley_amount(Union):
4 _fields_ = [
5 ("barley_long", c_long),
6 ("barley_int", c_int),
7 ("barley_char", c_char * 8),
8 ]
9
10 value = raw_input("Enter the amount of barley of put into the beer vat:")
11 my_barley = barley_amount(int(value))
12 print "Barley amount as a long: %ld" % my_barley.barley_long
13 print "Barley amount as a int: %d" % my_barley.barley_int
14 print "Barley amount as a char: %s" % my_barley.barley_char
相关阅读 更多 +