# It is better to use module's name with its objects # in order to avoid confusion with objects of other # modules having the same name. print('Version of this program: {}'.format(__version__)) print('Version of MyModule: {}'.format(mm.__version__)) print('Version of sys module: {}'.format(sys.version)) # We can get Program's name via sys module as we get # from CLI in C. But we cannot get argc. print('Name of this program: {}'.format(sys.argv[0])) print('No. of CLI arguments: {}'.format(len(sys.argv))) # Module 'os' has interesting usage specially when # we need to deal with multiple files with different # naming styles. # os.walk() returns dirPath, subdirs and filenames. dirName = '/home/sangeeta/Programming/TensorFlow/ADCIS/exudates' for dirPath, subDir, imgFileList in os.walk(dirName): print(dirPath) print(subDir) for imgFileName in imgFileList: print(imgFileName) # Usage of user-defined module # (i.e., my module named MyModule) print('a + b: {}'.format(mm.add())) print('a - b: {}'.format(mm.sub())) print('a * b: {}'.format(mm.mul())) print('a / b: {}'.format(mm.div()))
import MyModule while True: print( '1 - Addition ; 2 - Subtraction ; 3 - Multiplication ; 4 - Division ; 5 - To the Power of... ; 0 - Exit ' ) code = input('Please enter option: ') if code == '0': exit(0) a = float(input('Please enter first number: ')) b = float(input('Please enter second number: ')) if code == '1': result = MyModule.add(a, b) elif code == '2': result = MyModule.sub(a, b) elif code == '3': result = MyModule.mult(a, b) elif code == '4': result = MyModule.div(a, b) elif code == '5': result = MyModule.power(a, b) print(f'Result is {result}')