Is hilarious mistake in Python design. Thanks @elfprince13.

```python
def x():
e = None
while e is None:
try: print(input("? "))
except Exception as e: print(repr(e))

x()
```

Result:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in x
UnboundLocalError: local variable 'e' referenced before assignment
```

Thomas Dickerson  
@shriramk seems like a good thread to port over this doozy from Twitter. “here's possibly the worst Python scoping rule I've ever seen.” Try for ...

@freemo why is the formatting in this post broken? The pseudo-Markdown implementation seems to be eating all the newlines. How does that happen and how can we fix it?

Follow

@radehi @freemo

FWIW The only way I got the listing to format correctly posting to myself was 1) post in plain text mode 2) in markdown mode, prepend 4 spaces to each line (which sucks, obviously)

4 backticks didn't work. code tag didn't work.

@ambihelical @freemo By "plain text mode" mean "not Markdown mode"? I don't have a problem with prepending four spaces to each line (that's standard Markdown, fenced code blocks are a common extension) but that didn't keep the buggy implementation from eating my newlines.

Let's try four spaces:

def main():
pass

@ambihelical @freemo See, there was a newline after the colon, but got eaten. Inspecting the page DOM shows that there's a `<pre>` and a somewhat unnecessary but harmless `<code>` inside it, but the actual text node in the DOM has no newline in it.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.