在Python中打印简单消息

时间:2013-03-30 11:37:32

标签: python windows printf ctypes

我已经安装了Python 2.7.3和PyScripter。 当我试图运行这个简单的代码时,interupter没有显示任何内容:

from ctypes import *
msvcrt = cdll.msvcrt
message_string = "Hello world!\n"
msvcrt.printf("Testing: %s".encode('ascii'), message_string.encode('ascii')

(也试过没有编码)

1 个答案:

答案 0 :(得分:2)

在交互式shell中为我工作:

>>> msvcrt.printf("Testing: %s".encode('ascii'), message_string.encode('ascii'))

Testing: Hello World!
22

尝试将其放在.py文件中,然后从cmd

运行
python C:\path\to\file
相关问题