我想在一个字符串的任何位置找到大写字母,我想如果一个字符串在一个字符串的任何位置由大写字母组成,那么应该打印字符串“1”,如果字符串在任何位置不包含任何大写字母,那么应该打印字符串“0”。为此,我编写了一个python代码,但它不能正常工作file='C:/Python26/test.txt'
f=open('letters.txt','w')
pattern='[A-Z+]'
with open(file, 'r') as rf:
for word in rf:
for i in word.split():
if word[0].isupper(): ## finding letters starting with uppercase letters
f.write(word.strip("\n")+"\t"'1'"\n");
elif word.isupper(): ## finding string containing all capital letters
f.write(word.strip("\n")+"\t"'1'"\n");
elif re.search(pattern, word): ## finding string containing capital letter at
any position
f.write(word.strip("\n")+"\t"'1'"\n");
else:
f.write(word.strip("\n&