Day 738
pycharm optimize imports
python argparse
Seems the best current default way to do cli options! Docs tutorial is as accessible as usual: Argparse Tutorial — Python 3.9.1 documentation
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) # show default args in help
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) # allow newlines in help text
parser.add_argument("-lp", "--localpath", help="Local path. \n %(default)s", default=local_path) # add default text in help text manually
Python shadowing modules
When creating argparse.py, don’t be surprised if you can’t use argparse from import argparse
. 1
Python to read, TODO
Nice article: PyFormat: Using % and .format() for great good!
ag as grep alternative for code
I should make an effort to learn it and use it.
ag -G "component.*yaml" regex
- searches for regex inside all files whose path matches the regex after -G
ag --python "myregex"
automatically looks for it in all python files, and really nicely outputs matches!
vim delete lines not containing a pattern
g!/pattern/d
, as opposed to the usual g
without exclamation mark.
Using less
to copy cli stuff with weird linebreaks
If command
returns output with newline breaks that are ignored when copypasting directly, using command | less
seems to make it work - I can copypaste from there without problems.