title: NameError: global name 'MyProcess' is not defined
body: <p>I wrote a litte script to make a internet radio with a Raspberry pi zero. I first wrote this code on an PI 3. When I try to compile it on my zero I get this error</p>
  
  <pre><code>Traceback (most recent call last):&lt;br&gt;
  File "Radio.py", line 193, in &lt;module&gt; ChangeRadioChannel(0)&lt;br&gt;
  File "Radio.py", line 87, in ChangeRadioChannel&lt;br&gt;
  MyProcess.stdin.write('q')&lt;br&gt;
  NameError: global name 'MyProcess' is not defined&lt;br&gt;
  </code></pre>
  
  <p>I added my some code</p>
  
  <pre><code>    import RPi.GPIO as GPIO
      import os
      import keyboard
      from time import sleep
      import shlex, subprocess
      from MAX9744 import MAX9744
  
      # Channels
      CurrentChannel = 0
      Channels = [
          'Radio P.R.O.S.', 'http://audiostreamen.nl:8012',
          'Star Radio', 'http://internetradio.radiostar.be:8000/;stream.nsv&amp;type=mp3',
      ]
      isPlaying = False
  
      GPIO.setup(Pin_Next, GPIO.IN, pull_up_down = GPIO.PUD_UP)
      GPIO.setup(Pin_Prev, GPIO.IN, pull_up_down = GPIO.PUD_UP)
  
      def ChangeRadioChannel(choice):
          print('Change radio channel')
          global CurrentChannel 
          global Channels
          global MyProcess
          global Amplifier
  
          CurrentChannel = CurrentChannel + choice*2
  
          if CurrentChannel &lt; 0:
              CurrentChannel = len(Channels)-2
          if CurrentChannel &gt; len(Channels)-1:
              CurrentChannel = 0
  
          MyProcess.stdin.write('q')
          sleep(0.5)
          Amplifier.set_volume(SPEECH_VOLUME)
          os.system('echo "' + Channels[CurrentChannel] + '" | festival --tts')
          Amplifier.set_volume(Volume)
          MyProcess = subprocess.Popen(['omxplayer', '-o', 'local', Channels[CurrentChannel+1]], stdin=subprocess.PIPE)
          file = open("LastChannel.txt","w")  #Store latest chosen channel in txt file
          file.write(str(CurrentChannel)+"\n")
          file.close()
  
      def Next(dummy):
          print('Next radio channel')
          ChangeRadioChannel(1)
  
      def Previous(dummy):
          print('Previous radio channel')
          ChangeRadioChannel(-1)
  
      GPIO.add_event_detect(Pin_Next, GPIO.RISING, callback = Next, bouncetime = 200)
      GPIO.add_event_detect(Pin_Prev, GPIO.RISING, callback = Previous, bouncetime = 200)
  
      try:
          try:
              # At boot
              # 1) restore volume
              try: 
                  file = open("lastvolume.txt", "r")
                  Volume = int(file.read())
                  Amplifier.set_volume(Volume)
                  file.close()
                  print('Volume is set')
              except: pass
  
              # 2) restore channel
              file = open("LastChannel.txt","r")
              CurrentChannel = int(file.read())
              file.close()
              Amplifier.set_volume(SPEECH_VOLUME)
              os.system('echo "' + Channels[CurrentChannel] + '" | festival --tts')
              Amplifier.set_volume(Volume)
              MyProcess = subprocess.Popen(['omxplayer', '-o', 'local', Channels[CurrentChannel+1]], stdin=subprocess.PIPE)
          except:
              CurrentChannel=0
              ChangeRadioChannel(0)
  
          while True:
              sleep(0.5)
      except KeyboardInterrupt:
          GPIO.cleanup()
  </code></pre>
  
  <p>Somebody any idea? I made my 'MyProcess' global and I imported it
  Best regards 
  Nick</p>