0

So my script is working for pulling up the menu but when I pick and option it does not catch the variable outside the main method. I know I just may be doing something small wrong or not can anyone see what my issue is. Much appreciated in advance.

## Text Menu Dynamic test
##version 1
## Created By DragonShadow
## Code produce in Notpad++ For python v3.4.4
import os
import subprocess
import time
import pathlib


## Directory Enumerator
fileFolderLocationFilter = os.listdir('C:\\Users\\myFiles\\Documents\\_Scripts\\MyScripts\\')
selectedFile=""

## Menu defined setting veriables
def My_menu():
    files = fileFolderLocationFilter
    counter = 1
    print (20 * "=" , "Enoc Quick Menu" , 20 * "=")
    enumFiles = list(enumerate(files))
    for counter, value in enumFiles:
        str = repr(counter) + ") " + repr(value);
        print(str)
    str = repr(counter+1) + ") Exit";
    print(str)
    print (47 * "_")
    str = "Enter your choice [1 - " + repr((counter+1)) + "]:"
    choice = int(input("Please Enter a Selection: "))
    selectedFiles = enumFiles[choice]
    return(selectedFiles[1])
    if choice > counter :
        choice = -1
    else:
        selectedFiles = enumFiles[choice]
        print(selectedFiles[1])
        selectedFile = selectedFiles[1]
    return choice



##initiating loop
loop = True
while loop:
    choice = My_menu()
    print (choice)
    print ("---" +str(selectedFile))
  • Possible duplicate of [Using global variables in a function other than the one that created them](https://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them) – Galen Dec 08 '17 at 04:23
  • Thank you I will take a look and see if it works in my situation. – DragonShadow Dec 10 '17 at 02:54

0 Answers0