Подпроцесс Popen в модуле класса завершается ошибкой с исключением NameError для аргументов - PullRequest
0 голосов
/ 11 октября 2018

Я сталкиваюсь со странным поведением, которое не могу объяснить ...

Платформа = Windows 7 / Python 2.7.13

Вот мой код

# coding: utf-8

import subprocess

# TTS engine wrapper class
class EngineWrapper:

    def __init__(self):
        """Constructor"""
        pass

    def say(self, sSentenceValue):
        """Speak sentence"""
        # Do some magical stuff with sSentenceValue, like for instance...
        print sSentenceValue

        # Execute command
        aCommandLineArray = ["notepad.exe", "foo.txt"]
        print aCommandLineArray                           # This is successfully printed
        oTTSProcess = subprocess.Popen(aCommandLineArray) # This fails like a big piece of s..t


##################################### MAIN LOOP ###################################
if __name__ == '__main__':

    oTTSEngine = EngineWrapper()
    oTTSEngine.say("hello")    
###################################################################################

может кто-нибудь сказать мне, почему я получаю это ...

Traceback (most recent call last):
  File "test2.py", line 6, in <module>
    class EngineWrapper:
  File "test2.py", line 20, in EngineWrapper
    oTTSProcess = subprocess.Popen(aCommandLineArray)
NameError: name 'aCommandLineArray' is not defined

Этот код отлично работает вне класса, но не работает в методе.Я не могу понять, почему !!!!Это сводит меня с ума.

Спасибо.

...