-1

I'm making a basic editing software.

A simplified version of parts of the code are below (and they still produce the same result as with the actual program):

File named mod.py:

from mod2 import toptext

cmdtext = "Edit video: tt=test,"

presentCommands = ['tt=']

def initCommands(presentCommands, cmdtext):
    vidfilter = []
    if 'tt=' in presentCommands and 'bt=' not in presentCommands:
        vidfilter = toptext(cmdtext, vidfilter)
        print("Top text vidfilter is", vidfilter)
    else:
        print('no')

initCommands(presentCommands, cmdtext)

File named mod2.py:

import re

def toptext(cmdtext, vidfilter):
    vidfilter = vidfilter
    texts = (re.findall(r'tt=(.*?),', cmdtext))
    text = texts[0]
    print(text)
    vidfilter = vidfilter.append("subtitles=/example/file/path/toptext.srt:force_style='Fontname=Impact,Fontsize=30,Alignment=6'")
    print("The vidfilter is:", vidfilter)
    return vidfilter

The output of running mod.py is this:

test
The vidfilter is: None
Top text vidfilter is None

As you can see, vidfilter is printed as None, when I want it to be ["subtitles=/example/file/path/toptext.srt:force_style='Fontname=Impact,Fontsize=30,Alignment=6'"] instead. Is append() not working or something?

Can anyone please help me fix this and let me know why it's happening? Please note I'd like to keep mod.py and mod2.py as separate files.

cs95
  • 379,657
  • 97
  • 704
  • 746
scob_
  • 277
  • 1
  • 11

1 Answers1

0

list.append() works in place (and thus return None). You assign it back to vidfilter on this line:

vidfilter = vidfilter.append("subtitles=/example/file/path/toptext.srt:force_style='Fontname=Impact,Fontsize=30,Alignment=6'")

Also note that I am not sure what you think this like is doing:

vidfilter = vidfilter
buran
  • 13,682
  • 10
  • 36
  • 61
  • oh sorry - didnt mean to have the vidfilter = vidfilter there! i'll try your solution now – scob_ Nov 16 '20 at 05:37