Python Forum

Full Version: Even if my file is "main.py",cannot run my project
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I renamed my main.py to __main__.py, as you can see on the above error message.
(Mar-05-2018, 06:28 AM)sylas Wrote: [ -> ]I renamed my main.py to __main__.py, as you can see on the above error message.
I can't see that on the error message because the error message says that it cannot find __main__, not that it finds __main__ and is unhappy with it.

Try the following experiment: create a folder foo containing a single file __main__.py with the following code
print('hello world')
Then run
Output:
python foo
in a console. It should print hello world. On my box (linux) it works both with python 3 and python 2.
 Directory of E:\Documents\foo

05/03/2018  08:19    <DIR>          .
05/03/2018  08:19    <DIR>          ..
05/03/2018  08:20                21 __main__.py
               1 File(s)             21 bytes
               2 Dir(s)  467 952 185 344 bytes free

E:\Documents\foo>python __main__.py
hello world

E:\Documents\foo>

Bravo Gribouillis. Your foo works well.
E:\Documents>python foo
hello world

E:\Documents>
I made a mistake while renaming on Py1 the famous __main__.py. So my new Py1 works very well with "python Py1". Thanks again to Gribouillis.
Pages: 1 2