Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x AWS Greengrass V2 hello_world.py中的语法错误_Python 3.x_Amazon Web Services_Aws Iot Greengrass - Fatal编程技术网

Python 3.x AWS Greengrass V2 hello_world.py中的语法错误

Python 3.x AWS Greengrass V2 hello_world.py中的语法错误,python-3.x,amazon-web-services,aws-iot-greengrass,Python 3.x,Amazon Web Services,Aws Iot Greengrass,我正在试验AWS物联网绿草V2。我只是在遵循包含以下python代码的手册: import sys import datetime message = f"Hello, {sys.argv[1]}! Current time: {str(datetime.datetime.now())}." # Print the message to stdout. print(message) # Append the message to the log file. with o

我正在试验AWS物联网绿草V2。我只是在遵循包含以下python代码的手册:

import sys
import datetime

message = f"Hello, {sys.argv[1]}! Current time: {str(datetime.datetime.now())}."

# Print the message to stdout.
print(message)

# Append the message to the log file.
with open('/tmp/Greengrass_HelloWorld.log', 'a') as f:
    print(message, file=f)
根据我的日志记录,第4行有语法错误。将4号线更换为以下部件可以正常工作:

message = "Hello"
有人知道这句话有什么不对吗

message = f"Hello, {sys.argv[1]}! Current time: {str(datetime.datetime.now())}."

谢谢。

我是AWS IoT Greengrass的文档作者之一

格式化字符串文本(
f“some content”
)是Python 3.6+的一项功能,这种语法在早期版本中会导致语法错误。入门教程要求错误地将Python3.5列为要求,但Python3.5不支持格式化字符串文本。我们将把这个要求更新为3.6,或者更新脚本以删除格式化字符串文本


要解决此问题,可以升级到Python3.6+或修改脚本以删除格式化字符串文字。感谢您发现此问题

记录:我修改了代码,避免了
f“stringliteral”

import sys
import datetime

constrmessage ="Hello, ",str(sys.argv[1])," "+str(datetime.datetime.now())
#change from tuple to string
message = ''.join(constrmessage)
#print message to screen
print(message)

original_stdout = sys.stdout

# Append the message to the log file.
with open('/tmp/Greengrass_HelloWorld.log', 'a') as f:
    sys.stdout = f
    print(message)
    sys.stdout = original_stdout