皮层不断在我的进口处给我一个错误

发布于 2025-02-06 16:56:27 字数 1864 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青瓷清茶倾城歌 2025-02-13 16:56:27

您在同一行上有多个进口:

import os import json import six from dotenv import dotenv from google.cloud import translate

它们应分离到单个线上,或者通过逗号分隔,例如:

import os, json, six
from dotenv import dotenv

You have multiple imports on the same line:

import os import json import six from dotenv import dotenv from google.cloud import translate

They should be either separated onto individual lines or separated by commas, e.g:

import os, json, six
from dotenv import dotenv
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文