【问题标题】:What exactly does "tid" do in this code snippet, does it call out the thread id?这段代码片段中的“tid”究竟做了什么,它调用了线程ID吗?
【发布时间】:2020-05-18 13:21:43
【问题描述】:

谁能帮我理解这段代码的工作原理,当我在 jupyter notebook 上运行它时,这给了我一个语法错误。 Python 2.7x 任何帮助都将不胜感激。

def work(tid):
    with open(f"{tid}/test.txt", encoding='utf-8') as f:
        test_1 = f.read().strip().split("\n\n")

【问题讨论】:

  • 请尝试使用 ``` 帮助语法来格式化您的代码。此外, tid 看起来像是给函数的工作目录中的文件夹名称。

标签: python python-2.7 file


【解决方案1】:

您使用的代码中的问题 f"{tid}/test.txt" 这是一个 f 字符串,只能在 python3.6 及更高版本上使用,并且您使用的是 python 2.7x。
在低于 3.6 的 Python 中,您可以使用 "{}/test.txt".format(tid)

【讨论】:

    猜你喜欢
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-16
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多