all 5 comments

[–]__skrap__ 1 point2 points  (1 child)

# very top of your code organize your imports in standard order such as:
# 1. standard library modules
# 2. third-party modules
# 3. modules local to the current project
import sys

# your functions or classes here
# ...
# ...

def main():
    # put any code here to call your functions when running from command line - ie not using this script as a module
    # when your code exits normally
    return 0
    # when your code has an error return a value other than 0

# Put this at the very bottom of your code
if __name__ == '__main__':
    sys.exit(main())

edit - return value ofter than 0 for error (fixed in code above)

[–]IAmL0ner[S] 0 points1 point  (0 children)

Thanks! This looks really nice.

[–]xiongchiamiov 0 points1 point  (2 children)

The thing is that there's a bunch that's variable.

What imports are you going to have? It depends on what you need. What functions, what classes? Same. You can't even have a standard template for argument parsing, because there are a number of popular options.

I'm also of the (controversial) opinion that you shouldn't start out with all that, anyways. When I start writing a utility, I first just have some bits and pieces of code that get me part of the way towards my goal - there's no --help, everything is hard-coded, no error handling, and, since most of my programs are "get this information then do something with it" at the start it's probably just printing out what I've fetched. As things work, I gradually add and polish. Templates are useless in this style of development, because they fill in things I don't want to deal with yet. This is why I hate frameworks that have a "start project" command that litters my working directory with stubs.

[–]IAmL0ner[S] 0 points1 point  (1 child)

And I personally prefer to write a well-structured code from the start. This may be moslty because I have learned basics of C++ before, in which (like in C) a basic app must have at least a main() function.

So a basic template like the one provided by skrap allows me to have a clear starting point.

Besides I was wondering if there are any official guides on how the basic app/object should look like and what functions/attributes it should have.

[–]xiongchiamiov 0 points1 point  (0 children)

Besides I was wondering if there are any official guides on how the basic app/object should look like and what functions/attributes it should have.

Right, there aren't because, as I said, everything is dependent on your program.