Desired python topics

In this discussion you can post content about which you would like to learn more. I will give you some examples:

  • setting up the python IDE
  • basic introduction to data types
  • basic introduction to lists
  • reading user input
  • reading and writing files
  • list comprehensions
  • dictionaries
  • tuples and tuple packing and unpacking
  • positional and keyword arguments
  • classes and inheritance
  • decorators
  • generators
  • python data model
  • unittesting
  • ...
Tagged:

Comments

  • If you could take some time to teach how to get started, setting up the environment for starting python, it'd be really helpful.

  • If I could quote some of the above that I very interested in:

    inheritance, decorators, generators, unittesting

    And I don't know if that's more application than topic, but any topic that aids in writing code for other users, in situations like these:

    Case 1: You wrote a script for a colleague who knows no or little python. How do you make passing certain parameters (input files, output directories, etc.) easiest for them?

    Case 2: Writing modules that other colleagues might incorporate into their code. Best practices, how to maintain them, how to improve them later without accidentally breaking your colleague's code.

  • @WinterGreenMints

    One of the first intermediate topics that I will introduce are decorators, so stay tuned :)

    Case 1: The first thing that comes in my mind is argument parsing. With the help of argument parsing modules you can make better sanity checks of passed arguments and define optional and mandatory arguments. This makes your program easy to use and the you can add further argument more easy.

    There are different modules for argument parsing in python. The python standard library includes the module "argparse". It's easy because it is already built in. See https://docs.python.org/3/library/argparse.html

    Another argument parsing library is e.g click. It uses decorator syntax for argument parsing. See https://click.palletsprojects.com/en/7.x/

    Case 2: I think this is a classical topic of software engineering. How to extend something without breaking "client code". Maybe "python properties" can be help in this case. I have not yet prepared any demonstration yet, but I will put it on my list :)

  • Thank you, Alex!

    I didn't know about click, thank you for pointing me to it :)

    Wondering about argparse versus config - I've noticed different teams will prefer one over the other. As a user, one of the advantages of config was that there had to be a config file, and that file usually contained dummy or example values for the parameters, explanations in comments, etc. It was a neat thing. I wonder if there was a reason why one would prefer argparse (so passing the parameters at the command line) versus having a config file. Is the config file method considered outdated?

  • Oh, and thank you for adding python properties to the list! Much appreciated!

  • I checked my literature to see if I can get a well thought answer from the "gurus", when to use a config file and when to use command line arguments but have not found an answer.

    So everything following is just personal preference and opinion ;)

    I think config files are not outdated at all. I use them if I have a lot of parameters and maybe need to explain some combinations of them with comments (as you mentioned). The config file itself can become quiet large, but it does not matter. If I have a lot of options as CLI-arguments it might get messy and hard to invoke for the end user.

    But CLI arguments are faster to change and are easy to script, for example in bash scripts with the usage of variable substitution, which is a very handy thing.

    I have found this python module which combines everything together: https://pypi.org/project/ConfigArgParse/

    You can have command-line arguments, config file, environment variables and default settings which seem to me to be most flexible. I have not used this module for myself, but maybe it will serve you well :)

    A more general addition is the advice "design for the common case". This means use as many defaults as possible which will fit most clients best.

    A trivial example would be: If I start an email client it would should request emails from the server every 5 minutes per default and I will only invoke run_mail . It would be disturbing if I have to call the program `run_mail --poll_interval=5` every time. This is what i mean with "common case".

    I hope this helps.

    TLDR:

    many options: config file, less options cli arguments and maybe consider: why not both?! ;)

  • Thank you so much for your answer, Alex!
    That's a good point about command line arguments and bash scripts that I had not considered. Come to think of when I've seen argparse used, those were indeed cases where people wanted to run several python scripts in succession via bash script (and maybe go home for the day). The scripts that used config files were definitely scripts that had a lot of non-optional parameters.
    Thank you for explaining the different considerations that go into these design decisions. Will check out ConfigArgParse - nice to have it all in one!

Sign In or Register to comment.