Since PyCharm knows which file is "main", how can I tell it "run this project" - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Since PyCharm knows which file is "main", how can I tell it "run this project" (/thread-4636.html) |
Since PyCharm knows which file is "main", how can I tell it "run this project" - sylas - Aug-31-2017 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 ''' RE: Since PyCharm knows which file is "main", how can I tell it "run this project" - Larz60+ - Aug-31-2017 This section of the code: if __name__ == '__main__': print(minmax(lessthan, 4, 2, 1, 5, 6, 3)) # Self-test code print(minmax(grtrthan, 4, 2, 1, 5, 6, 3))is only run if starting if the module is called directly, by pressing run in PyCharm, or from command line by typing: python minmax.py RE: Since PyCharm knows which file is "main", how can I tell it "run this project" - sylas - Aug-31-2017 Thanks for your reply Larz60. I tried with the terminal "python min.py". It works well. But I don't understand your reply concerning PyCharm. Where in this enormous PyCharm must I go in order to run the whole project ?? RE: Since PyCharm knows which file is "main", how can I tell it "run this project" - Larz60+ - Aug-31-2017 In PyCharm upper right corner is the run button with a pull-down list. you select the module you want to run, then click the run button. but ... The first time, you must:
RE: Since PyCharm knows which file is "main", how can I tell it "run this project" - sylas - Aug-31-2017 In the pull-down list I have 4 items: EditConfigurations,saveminmax2configuration,minmax,minmax2....................The choice belongs to me.Does the "saveminmax2configuration" means: I know minmax2 is the main, and you save it if you like ????? RE: Since PyCharm knows which file is "main", how can I tell it "run this project" - Larz60+ - Aug-31-2017 You must click in the module you wnt to run first (step 1). It sounds like you are clicking in the command window RE: Since PyCharm knows which file is "main", how can I tell it "run this project" - sylas - Sep-03-2017 I think I found how to run the whole project, in PyCharm. You open your project. On the top at left, in the menu bar, you have: 1. Run (with main file name). 2. Debag (with main file name 3.Run 4. Debug......The third is the good one for running the whole project. RE: Since PyCharm knows which file is "main", how can I tell it "run this project" - Larz60+ - Sep-03-2017 It's a good debugger. You can step into or run step by step displayin whatever you wish. there is also a Run command on the same meny. If you have first clicked i the source code window, you cane use that to run the entire module or entire package if you start with the top level module, and have the proper imports in place. |