python检查字符串是否不包含“”

2024-04-19 18:03:23 发布

您现在位置:Python中文网/ 问答频道 /正文

if  '.' not in filename:
    if not os.path.exists("shortcut"):
        os.mkdir("shortcut")
    shutil.copy(filename,"shortcut") **this row is line 70**
    os.remove(filename)
    print("shortcut don")

这是我的代码,我在运行代码时在下面的图片中遇到了这个错误

error message is here


Tags: path代码inifisosexistsnot
1条回答
网友
1楼 · 发布于 2024-04-19 18:03:23

如果您有一个字符串,则只需在以下位置执行关键字:

strval = './test'
if '.' not in strval:
  print('this won\'t happen')
else:
  print('there was a period in the string')

如果您使用的是其他类型/函数,那么它应该具有类似的功能

相关问题 更多 >