I posted previously without reading your reply.
This is what Ive now done
This is what Ive now done
import os import globalVariables as gv def listCWD(): """ This section lists everything in the current working directory the if condition means that the code beneath it will only run if this file(__name__) is the Main Module(__main__) e.g it will not run if this module has been imported into another module. """ try: gv.directoryList = os.listdir(gv.directoryIn) print('directoryList =\n',gv.directoryList) except FileNotFoundError: print('FileNotFoundError:\na List for the Directory gv.directoryIn cannnot be created\nbecause the Global Variable gv.directoryIn is an empty string.\n' 'To correct this either:\na)run the returnCWD function in this Module to assign a directory to gv.directoryIn or\nb)open the globalVariables.py file and setgv.directoryIn to = None') except TypeError: print('TypeError:\na List for the Directory gv.directoryIn cannnot be created\nbecause the Global Variable gv.directoryIn has been assigned to equal either:\n' 'a)List\nb)Set\nc)Tuple\n' 'To correct this either:\na)run the returnCWD function in this M odule to assign a directory to gv.directoryIn or\nb)open the globalVariables.py file and setgv.directoryIn to = None') except NameError: print('NameError:\nbecause of the Syntax Error on import a NameError now occurs in the functions code\n' 'To correct the SyntaxError above open the globalVariables.py file and do either of the solutions below\n' 'a)make directoryIn = an empty string\nb)make directoryIn = None') listCWD() if __name__ == '__main__': listCWD()However after running the returnFileList Module I now get the following result which is including the FileNotFoundError that would otherwise be found if the listCwd.py Module was run on its own. I hope ive expalined that correctly.
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> RESTART: G:\2 Employment and Education\2 Education\2 Projects(All)\6 My Python Projects\MyPyProject\FileManagerProgram\1 Successfuly Tested\3 Working on - need to steeamline(22 09 19 9pm)\For Qs on Python Forum\returnFileList.py The os module has been imported The globalVariables module has been imported The returnCWD module has been imported FileNotFoundError: a List for the Directory gv.directoryIn cannnot be created because the Global Variable gv.directoryIn is an empty string. To correct this either: a)run the returnCWD function in this Module to assign a directory to gv.directoryIn or b)open the globalVariables.py file and setgv.directoryIn to = None The listCWD module has been imported The Current Working Directory is G:\2 Employment and Education\2 Education\2 Projects(All)\6 My Python Projects\MyPyProject\FileManagerProgram\1 Successfuly Tested\3 Working on - need to steeamline(22 09 19 9pm)\For Qs on Python Forum returnCWD ran corrrectly directoryList = ['globalVariables.py', 'listCWD.py', 'returnCWD.py', 'returnFileList.py', '__pycache__'] listCWD ran corrrectly