Hacker News new | ask | show | jobs
by aeonflux 1475 days ago
As already pointed out, whole file is parsed before it's actually run. If you have any unsupported syntax, you will get a SyntaxError without your message being printed at all.

What would be your suggestion to do this for single file scripts?

1 comments

Turn them into two-file scripts, or have a readme, or just let it fail because supporting every single version of Python is insane. This whole thing is just a classic case of the XY Problem[1]: a solution looking for a problem.

[1] https://xyproblem.info/

> Turn them into two-file scripts, or have a readme, or just let it fail because supporting every single version of Python is insane.

The point is obviously to let if fail, but clearly explain why it fails. This is obviously not meant for software distributed to users that are proficient in Python.

I guess it's useful for the kind of scripts you write and post in pastebin, or share on a web forum or whatever. Think a wrapper script that downloads and patches Wine so that it can run a certain exe or whatever. These users have never heard of pip, and you don't want to publish this stuff to pypi anyway. You just want to post it in a code block on forums.obscureindiegame.com so the three Linux users there can join the effin' game already!

Or so I would guess. Never felt a need for something similar myself.

But single-file script is still more convenient than two files. e.g. It is easier to scp or copy just one file than two files. Sometimes even if people already know they want to solve X problem, it might still make sense to solve Y problem because the solution to Y problem have some benefit in some cases.
What you just linked doesn't seem to be about solutions looking for problems. Rather it seems to be about people looking for solutions but being bad at expressing what the problems are.
It's not an XY problem. That describes a mismatched problem-solution pair. Not the case here.