皮层不断在我的进口处给我一个错误
import os
import json
import six
from dotenv import dotenv
from google.cloud import translate
#Translates english to french
# Initialize Translation client
def english_to_french(english_text="Hello", project_id="ferrous-amphora-352613"):
"""Translating Text."""
client = translate.TranslationServiceClient()
location = "global"
parent = f"projects/{ferrous-amphora-352613}/locations/{My First Project}"
# Translate text from English to French
response = client.translate_text(
request={
"parent": parent,
"contents": [text],
"mime_type": "text/plain", #
"source_language_code": "en-US",
"target_language_code": "fr",
}
)
# Display the translation for each input text provided
for translation in response.translations:
print("Translated text: {}".format(translation.translated_text))
# Translates french to english
# Initialize Translation client
def english_to_french(french_text="Bonjour", project_id="ferrous-amphora-352613"):
"""Translating Text."""
client = translate.TranslationServiceClient()
location = "global"
parent = f"projects/{ferrous-amphora-352613}/locations/{My First Project}"
# Translate text from English to French
response = client.translate_text(
request={
"parent": parent,
"contents": [french_text],
"mime_type": "text/plain", #
"source_language_code": "fr",
"target_language_code": "en",
}
)
# Display the translation for each input text provided
for translation in response.translations:
print("Translated text: {}".format(translation.translated_text))
if __name__ == "__main__":
pass
我一直在导入操作系统的位置遇到错误,但是一切都还可以。有人可以看我的语法并帮助我,被困了好几天吗
import os
import json
import six
from dotenv import dotenv
from google.cloud import translate
#Translates english to french
# Initialize Translation client
def english_to_french(english_text="Hello", project_id="ferrous-amphora-352613"):
"""Translating Text."""
client = translate.TranslationServiceClient()
location = "global"
parent = f"projects/{ferrous-amphora-352613}/locations/{My First Project}"
# Translate text from English to French
response = client.translate_text(
request={
"parent": parent,
"contents": [text],
"mime_type": "text/plain", #
"source_language_code": "en-US",
"target_language_code": "fr",
}
)
# Display the translation for each input text provided
for translation in response.translations:
print("Translated text: {}".format(translation.translated_text))
# Translates french to english
# Initialize Translation client
def english_to_french(french_text="Bonjour", project_id="ferrous-amphora-352613"):
"""Translating Text."""
client = translate.TranslationServiceClient()
location = "global"
parent = f"projects/{ferrous-amphora-352613}/locations/{My First Project}"
# Translate text from English to French
response = client.translate_text(
request={
"parent": parent,
"contents": [french_text],
"mime_type": "text/plain", #
"source_language_code": "fr",
"target_language_code": "en",
}
)
# Display the translation for each input text provided
for translation in response.translations:
print("Translated text: {}".format(translation.translated_text))
if __name__ == "__main__":
pass
I keep getting an error where the import os is, but everything is looks ok. Can someone look at my syntax and help me, been stuck on this for days
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在同一行上有多个进口:
它们应分离到单个线上,或者通过逗号分隔,例如:
You have multiple imports on the same line:
They should be either separated onto individual lines or separated by commas, e.g: