I have this as my code right now
main.py
:
JavaScript
x
18
18
1
help = ["/help", ["This returns a list of all commands"]]
2
color = ["/color", ["This changes the color of the console"]]
3
cmds = [help, color]
4
5
def getHelp(cmd:str=None):
6
if not cmd:
7
for index, c in enumerate(cmds):
8
for i, help in enumerate(c):
9
print(help+":", c[1])
10
return
11
print("Retrieving command")
12
for c in cmds:
13
for help in c:
14
if c == cmd[1]:
15
print(console_color+help)
16
else:
17
continue
18
It returns the first list, but not the second one. Traceback:
JavaScript
1
11
11
1
Traceback (most recent call last):
2
File "main.py", line 93, in <module>
3
login()
4
File "main.py", line 63, in login
5
main()
6
File "main.py", line 51, in main
7
getHelp()
8
File "main.py", line 34, in getHelp
9
print(help+":", c[1])
10
TypeError: can only concatenate list (not "str") to list
11
How do I fix this?
Advertisement
Answer
Found a fix:
JavaScript
1
12
12
1
def getHelp(cmd:str=None):
2
ct = 0
3
if not cmd:
4
for c in cmds:
5
for help in c:
6
ct += 1
7
if ct % 2 == 0: # prevents printing the command and desc twice
8
continue
9
elif ct == len(cmds):
10
return
11
print(str(help)+":", str(c[1]).strip('[']')) # removes the brackets and quotes
12
If the count is a multiple of 2, it is skipped (to prevent printing twice). If the count is equal to the amount of commands, the iteration is stopped.