This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
python:python [2013/03/13 17:16] dblume |
python:python [2022/06/15 07:49] (current) dblume Mention flask gunicorn nginx |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Python ====== | + | ====== |
| Man, there' | Man, there' | ||
| Line 7: | Line 7: | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| - | * Of course, there' | + | * Of course, there' |
| * There' | * There' | ||
| - | * Look into the microframework [[http:// | + | * Look into the microframework [[http:// |
| + | * [[https:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[https:// | ||
| + | * A Power Point deck by Alex Martelli describing [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| Would be nice to create a binary search in text files in Python. | Would be nice to create a binary search in text files in Python. | ||
| Line 23: | Line 30: | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| + | |||
| ===== Template Files to Start With ===== | ===== Template Files to Start With ===== | ||
| Line 35: | Line 43: | ||
| </ | </ | ||
| - | ===== Linux or Bash Tips ===== | ||
| - | |||
| - | Useful bash command for finding strings within python files... | ||
| - | |||
| - | <code bash> | ||
| - | find . -name \*.py -type f -print0 | xargs -0 grep -nI " | ||
| - | </ | ||
| - | |||
| - | Interesting way to use '' | ||
| - | |||
| - | <code bash> | ||
| - | #!/bin/bash | ||
| - | find $PWD -regex " | ||
| - | grep -v " \|unwantedpath/ | ||
| - | cscope -q -b | ||
| - | </ | ||
| - | |||
| - | And these two have nothing to do with Python. | ||
| - | |||
| - | <code bash> | ||
| - | nm obj-directory/ | ||
| - | find bindirectory/ | ||
| - | c++filt | grep -P " | ||
| - | </ | ||
| - | |||
| - | Also handy to merge two streams together... | ||
| - | |||
| - | <code bash> | ||
| - | ( cat file1 && cat file2 ) | sort | ||
| - | </ | ||
| - | |||
| - | When a little quick math is needed, use '' | ||
| - | <code bash> | ||
| - | $ bc <<< | ||
| - | F | ||
| - | $ bc -l <<< | ||
| - | .33333333333333333333 | ||
| - | $ bc <<< | ||
| - | .33 | ||
| - | $ bc <<< | ||
| - | 11 | ||
| - | </ | ||
| - | |||
| - | and, when coverting from hex to dec... | ||
| - | |||
| - | <code bash> | ||
| - | echo $((0x2dec)) | ||
| - | </ | ||
| - | |||
| - | But, then again, does that really seem easier than, | ||
| - | |||
| - | < | ||
| - | python -c "print int(' | ||
| - | </ | ||
| - | |||
| - | There' | ||
| - | |||
| - | <code bash> | ||
| - | $ echo $(( ($(date +%s) - $(date -d " | ||
| - | </ | ||
| - | |||
| - | And a Python way... | ||
| - | |||
| - | <code python> | ||
| - | python -c " | ||
| - | </ | ||
| - | |||
| - | And for displaying lines to get cut instead of wrapped: | ||
| - | |||
| - | <code bash> | ||
| - | cat_one_line_per_row() { | ||
| - | cat " | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ctags' | ||
| - | |||
| - | <code bash> | ||
| - | ctags -n --if0=yes --c++-kinds=+p --langmap=c++: | ||
| - | --langmap=asm: | ||
| - | --exclude=unwanted_file.lst \ | ||
| - | --exclude=' | ||
| - | --regex-C++='/ | ||
| - | </ | ||
| ===== For / Else (Nobreak) ===== | ===== For / Else (Nobreak) ===== | ||
| Line 181: | Line 105: | ||
| [[http:// | [[http:// | ||
| + | |||
| + | ===== cProfile vs. line_profiler and kernprof ===== | ||
| + | |||
| + | Raymond Hettinger [[https:// | ||
| + | |||
| + | Here it is: [[http:// | ||
| ===== timeit ===== | ===== timeit ===== | ||
| Line 302: | Line 232: | ||
| x = property( getx, setx ) | x = property( getx, setx ) | ||
| + | </ | ||
| + | |||
| + | ====== filelock ====== | ||
| + | |||
| + | Evan Fosmark has a filelock module. | ||
| + | |||
| + | <code python> | ||
| + | import os | ||
| + | import fcntl | ||
| + | import inspect | ||
| + | # Maybe use os.path.abspath(__file__) ? | ||
| + | with open(os.path.abspath inspect.getfile(inspect.currentframe())), | ||
| + | try: | ||
| + | fcntl.flock(f, | ||
| + | call_that_cannot_be_concurrent() | ||
| + | finally: | ||
| + | fcntl.flock(f, | ||
| + | </ | ||
| + | |||
| + | ====== Various Approaches to threaded URL Requests ====== | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * Or, use the doc's [[https:// | ||
| + | * And, as mentioned in Parallelism in One Line, [[https:// | ||
| + | |||
| + | ====== Fibonacci Generator with Itertools ====== | ||
| + | |||
| + | <code python> | ||
| + | import itertools | ||
| + | |||
| + | def fib(n): | ||
| + | """ | ||
| + | a, b = 0, 1 | ||
| + | while True: | ||
| + | yield a | ||
| + | b = a + b | ||
| + | yield b | ||
| + | a = a + b | ||
| + | |||
| + | if __name__ == ' | ||
| + | for x in itertools.islice(fib(), | ||
| + | print x | ||
| + | |||
| + | # for i in range( 5 ): | ||
| + | # print i, fib( i ) | ||
| </ | </ | ||
| Line 307: | Line 284: | ||
| TODO Link to my tips from LiveJournal and GMail, and why I chose which timing modules. | TODO Link to my tips from LiveJournal and GMail, and why I chose which timing modules. | ||
| - | Touching this page to see if the indexmenu will update its data. | ||