News for hackers. Stuff that matters.
Re:What Is the Switch-Case Equivalent in Python? by neolog on Sunday April 04, 2021 @02:13AM (#26687307)
- Languages should only make special syntax for very common or very important needs. Neither applies here.

- It violates the longstanding Python rule that assignments don't escape the enclosing scope.

Re:What Is the Switch-Case Equivalent in Python? by smetj on Sunday April 04, 2021 @03:03AM (#26687483)
> It violates the longstanding Python rule that assignments don't escape the enclosing scope.

But doesn't that violate the longstanding Python rule that A Foolish Consistency is the Hobgoblin of Little Minds ?

Re:What Is the Switch-Case Equivalent in Python? by beforeolives on Sunday April 04, 2021 @04:02AM (#26687690)
The trick is tell when striving for consistensy is foolish and when it isn't. Otherwise you would always be able to fall back on this quote to justify creating unuseable code/frameworks/projects/languages.
Re:What Is the Switch-Case Equivalent in Python? by neolog on Sunday April 04, 2021 @03:24AM (#26687553)
No. Assignment leaking into enclosing scope is a bad idea.
Re:What Is the Switch-Case Equivalent in Python? by bobbylarrybobby on Sunday April 04, 2021 @02:15PM (#26691612)
Don’t assignments already escape scope?

if True: x = 1 print(x)

Re:What Is the Switch-Case Equivalent in Python? by neolog on Sunday April 04, 2021 @02:34PM (#26691748)
`if` blocks don't make a scope. Comprehensions do.