On Mon, Nov 15, 2021 at 5:05 AM Christopher Barker <[email protected]> wrote: > > On Sun, Nov 14, 2021 at 6:05 AM Steven D'Aprano <[email protected]> wrote: >> >> global a = 3 > > > The issue i see is that Python doesn't have declarations. So you could use > the name, a in multiple places. what would this mean: > > a = 34 > > global a = 0 > > would it mean that the first a was loca, and the second local? or would it be > illegal -- glob could only be used on the first invocation? or ??
Presumably illegal, same as if you write "a = 34" followed by "global a; a = 0". > and frankly, global (should have) limited use anyway -- making it a bit > easier to use seems not very helpful. > Yes, but when you DO need it, you often want to immediately assign. I don't see a lot of times when "global def" would be appropriate, nor "for global i", but a quick grep of my source code shows these: global last_huffman_tree; last_huffman_tree = root # Inside a function, load up curses before the first use, but then make it available to helper functions without passing it as a pointless argument global curses; import curses global total_income; total_income += net etc. (I've put all these with semicolons for the sake of email but they might just as easily be on two separate lines.) IMO it would be kinda handy to be able to combine a global statement with an assignment, but it's not a particularly high priority for me. It would reduce a bit of repetition, but that's all. ChrisA _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/YMNA7N2XQSHZPFO5TJJ3ZY47DNQYUF65/ Code of Conduct: http://python.org/psf/codeofconduct/
