Mac OSX 上的 Pythonpath
我通读了 Add to python path mac os x 我想这样做这是一个好主意,但 IDLE 仍然会给我一个简单调用 open(filename, mode)
的语法错误,所以我进一步查看,发现我可以这样做http://developer.apple.com/library/mac/#qa/ qa1067/_index.html 并在 .MacOSX 文件夹中设置一个environment.plist,所以我在我的主目录中执行了此操作,但仍然没有任何更改...我现在迷路了:-)
这就是我在 .bash_profile 中添加为 python 路径的内容,以及在environment.plist 中添加的相同路径(不带 :$PYTHONPATH):
PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7:$PYTHONPATH"
export PYTHONPATH
编辑: 这就是我得到语法错误...在解释器中工作正常
import xml.etree.ElementTree as et
import json
app = Bottle()
@app.route('/proPass', method ='POST')
#here happens here, need it further down in the code... which is not really relevant
f = open('/Users/mohi/Desktop/proPass_project/server_service/systems.xml', 'rw')
def getData():
timestamp = request.POST.get('timestamp', '').strip()
data = request.POST.get('data', '').strip()
if timestamp:
processData(data, timestamp)
run()
错误:
File "proPass_script.py", line 9
f = open('/Users/mohi/Desktop/proPass_project/server_service/systems.xml', 'rw')
^
SyntaxError: invalid syntax
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PYTHONPATH
不会影响您是否收到SyntaxError
- 仅影响ImportError
。因此,如果您收到SyntaxError
,则说明您的代码存在另一个问题。请发布代码,我们会指出。编辑:您的错误在这一行:
@
指定一个装饰器,它仅在函数定义 (def
)、类定义 (< code>class),或其他装饰器。它在
open
行的第一个字符上显示错误,因为它需要那里的函数或类定义。有关装饰器的更多信息,请参阅函数定义的文档。
PYTHONPATH
doesn't effect whether or not you get aSyntaxError
-- only anImportError
. So, if you're getting aSyntaxError
, you've got another problem with your code. Please post the code and we'll point it out.Edit: Your error is on this line:
The
@
designates a decorator, which is only valid on the line immediately before a function definition (def
), a class definition (class
), or another decorator.It shows the error on the first character of the
open
line because it's expecting a function or class definition there.See the docs for function definitions for more info on decorators.