Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python I cannot append to a list

Kaworu

Active Coder
Hi!

I am currently translating a text from English to Polish. I have a file with translations of terms and right now I have lists (not in Python, just lists) of copy-paste translations terms. I decided it would be much easier to just run a Python script and do the copy-paste translations for me instead of doing the laborious tasks manually.

For some reason, when I try to use append Method to add Polish versions of terms to the list, I get a SyntaxError (in the place the dot is located).

The troublesome part looks like it:

Python:
final_list = list()
for item in trans_list:
    for item2 in ENG_list_2:
        if findingENGword(item2) == item:
            global final_list.append(findingPOLword(item2)) #Error here!!!
            break
        else:
            continue

The error I get is this:

Code:
  File "E:\Personal Data\My Folders\RPG\Cypher System The Strange\Cypher System\SRD\GitHub\Nowe\CSRD-main\CSRD-main\(0) Dodatki\Python_abi_temp.py", line 50
    global final_list.append(findingPOLword(item2))
                     ^
SyntaxError: invalid syntax

I would appreciate help 🙂
 
The issue is you're misusing the global keyword. Global is used to declare that a variable inside a function refers to a global variable, but it doesn't work with method calls like append() in Python.
It should be:: final_list.append(findingPOLword(item2)) # No 'global' keyword needed
 

New Threads

Buy us a coffee!

Back
Top Bottom