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.
Now the second:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#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 ''' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#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 ''' |