Python Forum
Since PyCharm knows which file is "main", how can I tell it "run this project"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Since PyCharm knows which file is "main", how can I tell it "run this project"
#1
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
'''
Reply
#2
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
Reply
#3
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 ??
Reply
#4
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:
  • 1. Click anywhere in module.
  • 2. Click on run menu (in top menu)
  • 3. Select Run or press Alt-Shift-F10.
  • 4. After first time, the module will be i the pull-down list.
Reply
#5
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  ?????
Reply
#6
You must click in the module you wnt to run first (step 1).
It sounds like you are clicking in the command window
Reply
#7
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.
Reply
#8
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 638 Today, 07:07 AM
Last Post: Bronjer
  Web project and running a .py file emont 0 637 Dec-11-2022, 11:15 PM
Last Post: emont
  export project to an installable software in Pycharm jalal0034 2 1,370 Oct-17-2022, 06:15 PM
Last Post: deanhystad
  python run all py files from main py file mg24 6 1,306 Oct-12-2022, 04:41 AM
Last Post: mg24
  PyCharm One Interpreter for every file? muzikman 3 1,858 Sep-28-2021, 02:09 AM
Last Post: snippsat
  Read csv file through PyCharm kimx0961 3 3,936 Aug-01-2021, 07:05 PM
Last Post: perfringo
  help with project of reading and searching big log file korenron 6 2,163 Jun-24-2021, 01:57 PM
Last Post: korenron
  guys please help me , pycharm is not able to identify my xlsx file CrazyGreenYT7 1 2,009 Jun-13-2021, 02:22 PM
Last Post: Larz60+
  Calling main in project structure fails sandro4912 0 1,335 Aug-22-2020, 01:51 PM
Last Post: sandro4912
  how to run another function from main file Mekala 3 2,526 Aug-09-2020, 04:41 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020