用大写字母写吗?
我有下一个代码:
bestand = open("6_frame.txt", "r")
seq = bestand.readlines()
#to make a list
for line in seq:
alle = line
while True:
if alle.isupper():
break
else:
print ("try again ")
使用此代码,我想确保有人在文件中写入序列,用大写字母写入此序列,并希望排除其他错误:但他想做我想做的事。
有人可以帮助我吗?
i have the next code:
bestand = open("6_frame.txt", "r")
seq = bestand.readlines()
#to make a list
for line in seq:
alle = line
while True:
if alle.isupper():
break
else:
print ("try again ")
with this code i want to make sure that someone , who write a sequence in the file, write this sequence in capital letters, and want to except the other errors: but he want do what i want.
can somebody help me ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你是说你想确保整个文件都是大写的。如果这就是您正在寻找的内容,那么这将解决问题:
这将一次测试文件中的所有大写字符。如果它找到不是的行,它将返回 false,否则如果所有行都是大写的,则返回 true(并打印“整个文件都是大写的”)。
更新(文件监视版)
看起来您想继续检查文件直到它全部大写。这是一种相当低效的方法(您可以添加 modtime 检查,或使用 inotify 使其更好):
此外,如果当您的脚本检查文件时该人正在保存中,您可能会遇到异常(我不确定)再次,因此您可能需要在
all
行周围添加一些异常捕获。不管怎样...希望这有帮助!I think you are saying you want to ensure the entire file is in upper-case. If that's what you are looking for, this will do the trick:
This will test the file, line-at-a-time, for all upper-case characters. If it finds a line that is not, it will return false, otherwise if all lines are upper-case, return true (and print "entire file is upper-case").
Update (File watching edition)
It looks like you want to keep checking the file until it's all uppercase. Here's a fairly ineffecient way to do it (you could add modtime checks, or use inotify to make it better):
Also, you may get exceptions (I'm not sure) if the person is mid-save when your script checks the file again, so you may need to add some exception catching around the
all
line. Either way... Hope this helps!我的
abc.txt
内容是aBC
,因此并非全部大写:我的输出 =
重试
因此,如果我的
abc.txt
, code> 内容是ABC
我的输出是全部大写
My
abc.txt
content isaBC
, so not all uppercase:therefore my output =
try again
if my
abc.txt
content isABC
my output isall capital
判断文件中的所有大小写字符是否都是大写,如果不是则重试:
Determine whether all cased characters in the file are uppercase, retry if not: