我試圖運行Adobe的樣品蟒蛇策略服務器腳本,鏈接到這裏:http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.htmlpython在這裏抱怨什麼?
,我發現了以下錯誤:
# python flashpolicyd.py --file=policy.xml
File "flashpolicyd.py", line 40
with file(path, 'rb') as f:
^
SyntaxError: invalid syntax
在背景:
class policy_server(object):
def __init__(self, port, path):
self.port = port
self.path = path
self.policy = self.read_policy(path)
self.log('Listening on port %d\n' % port)
try:
self.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
except AttributeError:
# AttributeError catches Python built without IPv6
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
# socket.error catches OS with IPv6 disabled
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind(('', port))
self.sock.listen(5)
def read_policy(self, path):
with file(path, 'rb') as f:
我對python一無所知,所以這可能是非常簡單明顯的事情。
正如Ignacio指出的那樣,如果你用'from __future__ import with_statement'特別要求它,它僅在2.5中可用。 – 2010-02-09 19:45:03