Remix.run Logo
another_twist a day ago

This is not a prank right ? Is it really gone ?

bonzini a day ago | parent | next [-]

It is, and it will be back soon just like Python's "if __name__ == '__main__'"...

garbagepatch a day ago | parent | next [-]

It makes sense to still have a main function. It doesn't make sense to have a class only to wrap that main function.

nromiun a day ago | parent | prev [-]

What? When did that go away? What is the alternative?

rhdunn a day ago | parent [-]

In a pyproject.toml file you can create/define scripts that reference an entry function. E.g.:

    # myapp/app.py
    def main():
        print('Hello!')
and in the pyproject.toml:

    [project.scripts]
    app = "myapp.app:main"
You can still use the __name__ check at the end of the file, e.g.:

    if __name__ == '__main__':
        main()
That way it works both as a standalone and when installed via pip/uv. -- Note: The scripts created by the installer are slightly more complicated versions of that __name__ check that handle the application argument (arg 0) and the exit code as the return value from main().
rhdunn a day ago | parent | prev [-]

It's not gone per se -- you can still write out the long form version if you want (this is required for backward compatibility).

What's now permitted is:

1. a simpler way of declaring a main method on a class -- you don't need the public or static, and the args is optional, so you can declare a `void main() { ... }` method on a constructable class;

2. declaring a main function (and other variables/functions) outside of a class -- here, the startup code will handle calling the main function, although I don't think the ability to call anonymous functions currently extends outside of the main function/file.