python ¶íÂÞ˹·½¿é
Õâ¸öËãÊÇC++ǶÈëpython°É£¬ÀûÓÃpythonʵÏÖÏÔʾºÍʼþ´¦Àí£¬C++ʵÏÖÂß¼
ÒÔºóÓÐʱ¼äÒ²»á·´¹ýÀ´ÊÔÊÔ£º£©
import pygame
import sys
import os
import ctypes
def cur_file_dir():
#»ñÈ¡½Å±¾Â·¾¶
path = sys.path[0]
#ÅжÏΪ½Å±¾Îļþ»¹ÊÇpy2exe±àÒëºóµÄÎļþ£¬Èç¹ûÊǽű¾Îļþ£¬Ôò·µ»ØµÄÊǽű¾µÄĿ¼£¬Èç¹ûÊÇpy2exe±àÒëºóµÄÎļþ£¬Ôò·µ»ØµÄÊDZàÒëºóµÄÎļþ·¾¶
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
#call dll
path = cur_file_dir()
print path
rblogic = ctypes.CDLL(path+r'\rblogic.dll')
#pygame init
pygame.init()
screen = pygame.display.set_mode((640,500),0,32)
pygame.display.set_caption('RussiaBoxGame£¡_by warmtrue')
rblogic.InitGame()
moveflag = 0
font = pygame.font.Font(os.environ['SYSTEMROOT'] + u"\\Fonts\\simsun.ttc", 40)
fontsmall = pygame.font.Font(os.environ['SYSTEMROOT'] + u"\\Fonts\\simsun.ttc", 15)
fontless = pygame.font.Font(os.environ['SYSTEMROOT'] + u"\\Fonts\\simsun.ttc", 15)
#game main loop
while True:
screen.fill((0,0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
moveflag = 4
elif event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
moveflag = 1
elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
moveflag = 3
elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
moveflag = 2
elif event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
moveflag = 6
moveflag = rblogic.GameLoop(moveflag)
for i in range(0,19):
for j in range(0,10):
t = rblogic.check(i,j)
if t > 0:
if t ==
Ïà¹ØÎĵµ£º
pythonÖйúÂÛ̳ http://www.okpython.com/bbs/index.php
¿ªÔ´ÉçÇø http://sourceforge.net/
python¹ÙÍø http://www.python.org/
pythonIDE BOAhttp://boa-constructor.sourceforge.net/
pythonIDE ´óÈ«http://www.oschina.net/project/tag/120
python×é¼þhttp://py.dw ......
ÔÚpythonÖÐÈçºÎ´´½¨Ò»¸öÏ̶߳ÔÏó
Èç¹ûÄãÒª´´½¨Ò»¸öÏ̶߳ÔÏ󣬺ܼòµ¥£¬Ö»ÒªÄãµÄÀà¼Ì³Ðthreading.Thread£¬È»ºóÔÚ__init__ÀïÊ×Ïȵ÷ÓÃthreading.ThreadµÄ__init__·½·¨¼´¿É
import threading
class mythread(threading.Thread):
def __init__(self, threadname):
& ......
ÔÚPythonÖпÉÒÔ°Ñproperty¶¯Ì¬µÄ°ó¶¨µÄobjectµÄ¼Ì³ÐÀàÖУ¬²¢ÇÒ¿ÉÒÔ¶¨Òå´øÓвÎÊýµÄgetºÍset·½·¨¡£
±ÈÈ磬ÎÒÃǶ¨ÒåÁËÈ«¾Ö±äÁ¿g£¬È»ºóͨ¹ýÁ½¸ö·½·¨À´´æÈ¡gµÄÄÚÈÝ
def get_g(self):
return g
def set_g(self, _g):
global g
g = _g
¶¨ÒåÒ»¸öobjectµÄ¼Ì³ ......
PEP 0263
Defining Python Source Code Encodings
Python will default to ASCII as standard encoding if no other
encoding hints are given.
To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file, suc ......
ÓÉsubprocess´´½¨Ò»¸ö½ø³Ì£¬È»ºó½øÐмàÊÓ
ÿһÃëÖӲ鿴һ´Î£¬Èç¹ûÕýÔÚÔËÐУ¬´òÓ¡pidºÍrunning£¬Èç¹ûÒÑÍ£Ö¹£¬,¼ÌÐøÖ´ÐÐÈÎÎñ²¢´òÓ¡Termined
shellºÍstdout¾ùÉèÖÃΪFalse
Ò²ÐíÕâ¶Ô×ö²¡¶¾µÄÊØ»¤½ø³ÌºÜºÃ
#!/usr/bin/env python
import subprocess , sys , time
p=subprocess.Popen(['ping','127.0.0.1','-n','10'], she ......