首页 新闻 会员 周边

Python3.6,运行以下代码时为什么不能打印hello

0
悬赏园豆:5 [已解决问题] 解决于 2018-09-16 10:50

amerFilename1=['03-01-2018 .txt','03-36-2018.txt']
for mo in amerFilename1:
print(mo)
if mo == None:
continue
print(hello)

李荣洋的主页 李荣洋 | 初学一级 | 园豆:190
提问于:2018-09-15 10:47
< >
分享
最佳答案
0

下面的代码可以打印出 hello

amerFilename1=['03-01-2018.txt','03-36-2018.txt']
for mo in amerFilename1:
    print(mo)
    if mo == None:
      continue
    print('hello')
收获园豆:5
dudu | 高人七级 |园豆:31003 | 2018-09-15 14:47

import shutil, os, re

创建一个表达式,用来查找美国风格的日期

datePattern = re.compile(r"""^(.?) # all text before the date
((0|1)?\d)- # one or two digits for the month
((0|1|2|3)?\d)- # one or two digits for the day
((19|20)\d\d) # four digits for the year
(.
?)$ # all text after the date
""", re.VERBOSE)

TODO: 循环目录下的文件

for amerFilename in os.listdir('.'):
#符合表达式的内容赋值给mo
mo = datePattern.search(amerFilename)
#print(mo)

TODO: Skip files without a date.

判断mo是否为空

if mo == None:
    continue
    print('hello')

‘’‘
目录中已经有了'03-01-2018.txt','03-36-2018.txt'两个符合表达式的文件,但是不能走到continue后面去。我用Debug模式查看到,表达式没有问题可以查询到文件并且给了mo,但是在if是mo一致为None
’‘’

李荣洋 | 园豆:190 (初学一级) | 2018-09-15 16:21

李荣洋 | 园豆:190 (初学一级) | 2018-09-15 16:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册