所以我在为无聊的工作写一个临时程序。在这个程序中,我将写的文本写入给定的文件名。稍后我要用这些文件来做单词记忆程序。以下是Xubuntu文件的外观
(用PyQt4编写)
http://i.stack.imgur.com/yEPSh.png
(文件是用土耳其语写的,所以翻译如下
Dosyayıaç=打开文件 )你知道吗
好吧,问题是有个语法错误我不明白。我已经检查了30分钟了,但还是看不出问题。你知道吗
因此,在下面的QLineEdit中,如果你写一个类似于“der Wasser Su”的文本,在文件中它看起来像“der,Wasser,Su”,但是在德语中有一些单词等于2个土耳其语单词。例如“derÄrztin Kadın Doktor”。在文件里看起来像是‘der,rztin,Kad,Doktor’,这是错误的。你知道吗
我希望这样:当用户在引号中输入“derÄrztin”Kadın Doktor“时,它将保存在文件中为“der,Ärztin,Kadın Doktor”。为此,我提供了以下程序:
如果这很难阅读,因为它不是彩色的,下面是代码共享链接: https://codeshare.io/Hso6t
#Quotation Control Unit
for i in words:
try:
#If the file's first character is a quotation mark keep looking
#for the other one
if(i[0] == '"'):
#This for loop checks every character in the current(i) word
for idx in i:
#If the quotation mark is found in the same word which
#the first quotation mark is in, then delete the
#quotation marks and print the word into the file
#without them.
if(i[idx] == '"'):
words[words.index(i)] = i[1:(len(i) - 2)]
raise Done
#If the closing quotation mark couldn't be found in the
#same word, go to the other word and search for it
if('"' not in i[1:]):
searched_words = 1
#Start looking for the words which comes after the
#word, which hosts the first quotation mark
for a in words[(words.index(i) + 1):]:
searched_words += 1
#If the second quotation mark is found like this:
# "Ärztin "Ka.......
#Throw an error window
if (a[0] == '"'):
iP = NoFileNameError()
ip.setupUiInappropiateText()
ip.show()
#If the second quotation mark is found then
if (a[(len(a) - 1)] == '"'):
#combine the text between them
words[words.index(i)] = i[1:] + a[:
(len(xd) - 1)]
#After this is done, delete the strings
#which comes after the string which hosts
#the first quotation mark
#E.g a = ['"a', 'b', 'c"']
#a[0] = 'abc'
#del b,c
#final list = a = ['abc']
for s in words[(words.index(i) + 1):(searched_words + 1)]
del words[words.index(s)]
raise Done
except Done:
continue
但是python给了我一个错误:
File "editor.py", line 173
for s in words[(words.index(i) + 1):(searched_words + 1)]
^
SyntaxError: invalid syntax
我只是不知道为什么它会给我这个:'(请帮忙。你知道吗
在173行作为编辑.py说你忘了冒号(
:
)魔鬼在细节上!你知道吗
相关问题 更多 >
编程相关推荐