我是Cloud9的新手,我做了一个脚本。我希望代码出现在url https://python-william1835.c9.io中,并收到以下消息:
Important: use os.getenv(PORT, 8080) as the port and os.getenv(IP,0.0.0.0) as the host in your scripts!当我运行它的时候。
所以我把它放在脚本中(当然还有import os )。当我再次运行它时,它说:
File "/home/ubuntu/workspace/Python Projects/Python Enigma Program/main.py", line 14
os.getenv(IP, 0.0.0.0)
^
SyntaxError: invalid syntax你能告诉我为什么会这样吗?
发布于 2016-06-19 20:36:41
您将得到一个SyntaxError,因为文字0.0.0.0在语法上是无效的。
在这种特殊情况下,您收到的信息有点误导。此外,os.getenv https://docs.python.org/3/library/os.html#os.getenv的文档页。
但是,如果您查看https://hg.python.org/cpython/file/3.5/Lib/os.py#l814 for getenv,您会发现所有参数都必须是str类型的
def getenv(key, default=None):
"""Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default.
key, default and the result are str."""
return environ.get(key, default)将您的电话更改为:
os.getenv("PORT", "8080")
os.getenv("IP", "0.0.0.0")应该工作,你应该没有问题,使用它们。
https://stackoverflow.com/questions/29928092
复制相似问题