我的代码有什么问题? [语法错误]
What's wrong with my code? [SyntaxError]
所以我正在为无聊的工作编写一个临时程序。在这个程序中,我将书面文本写入给定的文件名。稍后我将这些文件用于单词记忆程序。这是文件在 Xubuntu 中的样子;
(用PyQt4编写)
http://i.stack.imgur.com/yEPSh.png
(该文件是用土耳其语写的,所以这里是翻译;
- Dosya İsmi = 文件名
- Dosya Türü = 文件扩展名
- Kelime = Word(这是将创建给定文件的目录。)
Dosyayı aç = 打开文件
)
好的,问题是有一个我无法理解的语法错误。我已经检查了大约 30 分钟,但我仍然看不出问题所在。
所以在下面的 QLineEdit 中,如果你写这样的文本 'der Wasser Su',在文件中它看起来像这样 'der, Wasser, Su' 但有些德语单词等于 2 个土耳其语单词。例如 'der Ärztin Kadın Doktor'。在文件中它看起来像这样 'der, Ärztin, Kadın, Doktor' 这是错误的。
我希望它是这样的:当用户像这样 'der Ärztin "Kadın Doktor"' 在引号中输入时,它将在文件中保存为 'der, Ärztin, Kadın Doktor'。为此,我使用了以下程序:
如果这很难阅读,因为它没有彩色,这里是代码共享 link:
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 行中,editor.py 说您忘记了冒号 (:
)
File "editor.py", line 173
for s in words[(words.index(i) + 1):(searched_words + 1)]
^
细节决定成败!
所以我正在为无聊的工作编写一个临时程序。在这个程序中,我将书面文本写入给定的文件名。稍后我将这些文件用于单词记忆程序。这是文件在 Xubuntu 中的样子;
(用PyQt4编写)
http://i.stack.imgur.com/yEPSh.png
(该文件是用土耳其语写的,所以这里是翻译;
- Dosya İsmi = 文件名
- Dosya Türü = 文件扩展名
- Kelime = Word(这是将创建给定文件的目录。)
Dosyayı aç = 打开文件 )
好的,问题是有一个我无法理解的语法错误。我已经检查了大约 30 分钟,但我仍然看不出问题所在。
所以在下面的 QLineEdit 中,如果你写这样的文本 'der Wasser Su',在文件中它看起来像这样 'der, Wasser, Su' 但有些德语单词等于 2 个土耳其语单词。例如 'der Ärztin Kadın Doktor'。在文件中它看起来像这样 'der, Ärztin, Kadın, Doktor' 这是错误的。
我希望它是这样的:当用户像这样 'der Ärztin "Kadın Doktor"' 在引号中输入时,它将在文件中保存为 'der, Ärztin, Kadın Doktor'。为此,我使用了以下程序:
如果这很难阅读,因为它没有彩色,这里是代码共享 link: 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 行中,editor.py 说您忘记了冒号 (:
)
File "editor.py", line 173
for s in words[(words.index(i) + 1):(searched_words + 1)]
^
细节决定成败!