首页 > 解决方案 > 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")

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

错误信息在这里

标签: python

解决方案


如果你有一个字符串,你可以只做关键字:

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

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


推荐阅读