gpt4 book ai didi

python - 如何在参数中输入长且非字符串的数据?

转载 作者:行者123 更新时间:2023-12-01 01:04:14 25 4
gpt4 key购买 nike

我在使用 Python 时遇到问题,需要您的帮助。看一下这段代码:

import os
os.chdir('''C:\\Users\\Admin\\Desktop\\Automate_the_Boring_Stuff_onlimematerials_v.2\\automate_online-materials\\example.xlsx''')

os.chdir() 不起作用,因为我放在 '''''' 之间的目录被认为是作为原始字符串。请注意,一行不超过 125 个字符,因此我必须换行。

那么我该如何解决这个问题呢?

最佳答案

您可以使用反斜杠 \ 将语句拆分为多行,以指示语句在新行上继续。

message = 'This message will not generate an error because \
it was split by using the backslash on your \
keyboard'

print(message)

输出

This message will not generate an error because it was split by using the backslash on your keyboard

关于python - 如何在参数中输入长且非字符串的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55527132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com