Chris Angelico wrote:
> On Fri, May 29, 2020 at 5:25 AM Alex Hall alex.moj...@gmail.com wrote:
> >
> > On Thu, May 28, 2020 at 12:57 PM Paul Sokolovsky pmis...@gmail.com wrote:
> > >
> > And in all fairness, all good ideas already came
> > to somebody else years
> > ago. There's https://www.python.
On Sun, May 31, 2020 at 06:45:01AM +1000, Chris Angelico wrote:
> On Sun, May 31, 2020 at 6:14 AM Mike Miller wrote:
> >
> >
> > On 2020-05-28 18:02, Greg Ewing wrote:
> > >> If __name__ == '__main__':
> > >> sys.exit(main(sys.argv[1:]))
> > >
> > > It's not clear that exiting with the return
On Sun, May 31, 2020 at 6:14 AM Mike Miller wrote:
>
>
> On 2020-05-28 18:02, Greg Ewing wrote:
> >> If __name__ == '__main__':
> >> sys.exit(main(sys.argv[1:]))
> >
> > It's not clear that exiting with the return value of main() is
> > the most Pythonic thing to do -- it's more of a C idiom
On 2020-05-28 18:02, Greg Ewing wrote:
If __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
It's not clear that exiting with the return value of main() is
the most Pythonic thing to do -- it's more of a C idiom that
If you'd like a script to be uhh, highly-scriptable, returning one
I agree with Paul's sentiment. We do not need to bless just one way of
writing scripts. Code review or organization style guides, sure. But not at
language level.
I also write scripts with no explicit __main__. But I rarely name them as
.py. In the style of Unix commands, they have no extension, b
Also, I routinely write scripts that have no `if __name__ ==
'__main__'` line at all, they just run - no-one should ever import
them, so it makes no difference. And I exit (in multiple places) using
`raise SystemExit("reason")`.
My point being that yes, there are *lots* of ways of writing Python
s
I'm going to note here that it is perfectly reasonable to use Python as a
"scripting language" -- to, you know, write scripts.
And when I'm writing scripts, I make heavy use of the global namespace :-)
Granted, if it's really a quick and dirty script, I'll not bother with if
__name__ == "__main__
On Fri, May 29, 2020 at 12:43 PM Jonathan Goble wrote:
>
> On Thu, May 28, 2020 at 9:03 PM Greg Ewing
> wrote:
>>
>> On 29/05/20 8:05 am, tritium-l...@sdamon.com wrote:
>>
>> > People write main entry points that are not exactly this?
>> >
>> > If __name__ == '__main__':
>> > sys.exit(main(
On Thu, May 28, 2020 at 9:03 PM Greg Ewing
wrote:
> On 29/05/20 8:05 am, tritium-l...@sdamon.com wrote:
>
> > People write main entry points that are not exactly this?
> >
> > If __name__ == '__main__':
> > sys.exit(main(sys.argv[1:]))
>
> It's not clear that exiting with the return value of
On 05/28/2020 01:05 PM, tritium-l...@sdamon.com wrote:
People write main entry points that are not exactly this?
If __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
I have never written an entry point that looks like that.
--
~Ethan~
___
P
On 29/05/20 8:05 am, tritium-l...@sdamon.com wrote:
People write main entry points that are not exactly this?
If __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
It's not clear that exiting with the return value of main() is
the most Pythonic thing to do -- it's more of a C idiom tha
On 28/05/2020 21:05, tritium-l...@sdamon.com wrote:
People write main entry points that are not exactly this?
If __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Mostly I don't write main entry points at all. If I do the dance, it's
more likely to be:
if __name__ == '__main__':
Hello,
On Thu, 28 May 2020 16:05:52 -0400
wrote:
[]
> People write main entry points that are not exactly this?
>
> If __name__ == '__main__':
> sys.exit(main(sys.argv[1:]))
Yes, most of the time, I don't emulate C main function, so I write it
as:
if __name__ == "__main__":
main()
(
On Thu, May 28, 2020 at 9:52 PM Paul Sokolovsky wrote:
> On Fri, 29 May 2020 05:33:57 +1000
> Chris Angelico wrote:
> > People can already put all their main logic into a function. If you
> > want to unit-test your main function, that's the best way to do it.
>
Yes, and I want to make it easy,
On Fri, May 29, 2020 at 5:54 AM wrote:
>
> > -Original Message-
> > From: Chris Angelico
> >
> > People can already put all their main logic into a function. If you want
> to unit-
> > test your main function, that's the best way to do it.
> > The trouble is, how much goes into main() and
(Apologies to Chris, reply vs. replay all error on my part)
> -Original Message-
> From: Chris Angelico
>
> People can already put all their main logic into a function. If you want
to unit-
> test your main function, that's the best way to do it.
> The trouble is, how much goes into main
Hello,
On Fri, 29 May 2020 05:33:57 +1000
Chris Angelico wrote:
[]
> People can already put all their main logic into a function. If you
> want to unit-test your main function, that's the best way to do it.
> The trouble is, how much goes into main() and how much into if
> __name__ == '__main__
On Thu, May 28, 2020, 3:06 PM Chris Angelico wrote:
> There aren't multiple entry points, though. There would be multiple
> blocks of code that are skipped if the module is imported, but
> executed if it's run as a script. Remember, Python code is NOT
> declarative. That 'def' statement is an act
On Fri, May 29, 2020 at 5:25 AM Alex Hall wrote:
>
> On Thu, May 28, 2020 at 12:57 PM Paul Sokolovsky wrote:
>>
>> And in all fairness, all good ideas already came to somebody else years
>> ago. There's https://www.python.org/dev/peps/pep-0299/ , successfully
>> rejected yet back in 2002. (So, fe
On Thu, May 28, 2020 at 12:57 PM Paul Sokolovsky wrote:
> And in all fairness, all good ideas already came to somebody else years
> ago. There's https://www.python.org/dev/peps/pep-0299/ , successfully
> rejected yet back in 2002. (So, feel free to use it in your own
> environment/Python dialect.
On Fri, May 29, 2020 at 2:32 AM David Mertz wrote:
>
> On Thu, May 28, 2020, 12:17 PM wrote:
>>
>> The OP is proposing as a possibility: "we could require user to have only
>> one if __name__ == '__main__':". In that case, functionality will be
>> reduced, won't it?
>
>
> I don't support the pr
Cool !!
But it disappointed that this proposal was reject (
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message arc
On Thu, May 28, 2020, 12:17 PM wrote:
> The OP is proposing as a possibility: "we could require user to have only
> one if __name__ == '__main__':". In that case, functionality will be
> reduced, won't it?
>
I don't support the proposal. However, I've also never written a script
with multiple 'i
Artemis wrote:
> > So your proposal is reducing features instead of
> > expanding them.
> > Surely, the __name__ variable would remain, so if people needed a more
> > powerful way of doing it they could use that? But then, we introduce
> > multiple ways of
> > doing the same thing...
> >
The OP i
Hello,
On Thu, 28 May 2020 09:06:36 -
redrad...@gmail.com wrote:
> Hi all,
>
> In Python we often use the following syntax to call the main logic of
> script when it was ran: ```python
> def main():
> pass # whatever should be done for `python ./script.py`
>
> if __name__ == '__main__':
> So your proposal is reducing features instead of expanding them.
Surely, the `__name__` variable would remain, so if people needed a more
powerful way of doing it they could use that? But then, we introduce multiple
ways of doing the same thing...
___
redradist@gmail.com wrote:
> Hi all,
> In Python we often use the following syntax to call the main logic of script
> when it
> was ran:
> def main():
> pass # whatever should be done for `python ./script.py`
>
> if __name__ == '__main__':
> main()
>
> Maybe it is a time to introduce the
While is possible to use `if __name__ == '__main__':` several times in the
same script, your proposed magic function `def __main__()` cannot be
redefined. Not to speak about lexical scope differences between one
approach and the other.
So your proposal is reducing features instead of expanding the
28 matches
Mail list logo