您的位置:首页 > 编程语言 > Python开发

Setting Up Your Development Environment(Chapter 1 of Gray Hat Python)

2011-04-02 19:50 465 查看
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
c_char_p('loves python')
>>> print seitz.value
loves python

from ctypes import *

msvcrt = cdll.msvcrt
message_string = "Hello world!\n"
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
value = raw_input("Enter the amount of barley of put into the beer vat:")
my_barley = barley_amount(int(value))
print "Barley amount as a long: %ld" % my_barley.barley_long
print "Barley amount as a int: %d" % my_barley.barley_int
print "Barley amount as a char: %s" % my_barley.barley_char
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: