Hacker News new | ask | show | jobs
by xg15 122 days ago
here's a valid f-string:

>>> f'{'}'}' '}'

Huh? I remember learning the rule that you can't nest quotes inside fstrings if they are the same kind (unlike in bash) - e.g

  f"{mydict["foo"]}"
would be a syntax error, but

  f"{mydict['foo']}"
or

  f'{mydict["foo"]}'
would be valid.

The reason being the same like for the rstring weirdness: The lexer comes first and identifies the string literal, then for fstrings, the python parser is invoked again for each {...} expression to parse it.

This is unlike other nested expressions, which are already split up by the lexer and then parsed in one go.

Did that change at some point?

1 comments

Wow, I didn't know this either. I find it a bit crazy. It must make no sense without syntax highlighting. But I suppose who writes code without highlighting any more?
It's been a long time since I've had to SSH into a box to fix an issue in production. But it is comforting to know that I _could_.

VI (not even VIM) on minimal Debian installs does not have syntax highlighting.

How often do you have SSH access to a box but don't have SFTP access?

Most IDEs support editing files on a remote machine through SFTP.

It would be scp, not sftp, but I often don't know what I'm about to edit until I get in there and dig around.
No, I was talking about SFTP, not scp. OpenSSH server has SFTP enabled by default. You can mount it using sshfs or browse it using any SFTP client (or any program with embedded SFTP client, which is most IDEs).

So, if "digging around" means looking at folders' structure, you can do it through SFTP without copying everything (unlike scp or rsync).

And if digging around means running commands, nothing prevents you from having a session for running commands open in parallel.

Interesting read. I had no ides that they switched the parser https://peps.python.org/pep-0617/