Search code examples
pythonpython-3.xpyqt4qt-designer

What's wrong with my code? [SyntaxError]


So I'm writing a temporary program for boring jobs. In this program I'm writing the written text into the given file name. Later I'm gonna use these files for a word memorization program. Here's how the file looks like in Xubuntu;

(Written with PyQt4)

https://i.sstatic.net/yEPSh.png

(The file is written in Turkish, so here's the translation;

  • Dosya İsmi = File Name
  • Dosya Türü = File Extension
  • Kelime = Word (It's the directory where the given file will be created.)
  • Dosyayı aç = Open File )

    Okay, the problem is that there's a syntax error which I can't understand. I've been checking it like 30 minutes but still I cant't see the problem.

    So in the below QLineEdit if you write a text like this 'der Wasser Su', in the file it looks like this 'der, Wasser, Su' but there are some words in German that are equal to 2 Turkish words. E.g 'der Ärztin Kadın Doktor'. In the file it looks like this 'der, Ärztin, Kadın, Doktor' and that's wrong.

    I want this to be like this: When user gives an input in quotation marks like this 'der Ärztin "Kadın Doktor"' it will be saved in the file as 'der, Ärztin, Kadın Doktor'. To do this I've came with the following program:

If this is hard to read, since it isn't coloured, here's the codeshare 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

But python gives me an error:

  File "editor.py", line 173
for s in words[(words.index(i) + 1):(searched_words + 1)]
                                                        ^
SyntaxError: invalid syntax

And I just don't know why it gives me this :'( Please help.


Solution

  • In line 173 as the editor.py says you forgot the colon (:)

    File "editor.py", line 173
    for s in words[(words.index(i) + 1):(searched_words + 1)]
                                                            ^
    

    The devil's in the detail!