Aug-31-2017, 07:00 AM
Hi all ! Since PyCharm knows which file is "main", how can I tell it: "run this project"(instead of "run this file") ? Here below the 2 files. Amazing ! ; no "import" present.
#minmax2.py
print('I am:', __name__)
def minmax(test, *args):
res = args[0]
for arg in args[1:]:
if test(arg, res):
res = arg
return res
def lessthan(x, y): return x < y
def grtrthan(x, y): return x > y
if __name__ == '__main__':
print(minmax(lessthan, 4, 2, 1, 5, 6, 3)) # Self-test code
print(minmax(grtrthan, 4, 2, 1, 5, 6, 3))
'''
output
/usr/bin/python3.5 /home/sylvain/PycharmProjects/minmax/minmax2.py
I am: __main__
1
6
'''Now the second:#minmax.py def minmax(test, *args): res = args[0] for arg in args[1:]: if test(arg, res): res = arg return res def lessthan(x, y): return x < y # See also: lambda def grtrthan(x, y): return x > y print(minmax(lessthan, 4, 2, 1, 5, 6, 3)) # Self-test code print(minmax(grtrthan, 4, 2, 1, 5, 6, 3)) ''' output /usr/bin/python3.5 /home/sylvain/PycharmProjects/minmax/minmax.py 1 6 '''
