Always check your code thoroughly before asking for help. Ref: request Cross Site error caused by []
- use
pyenv
to get around root privileges - use
Anaconda
to get around compiling restriction - Anaconda missing packages:
- plotly
-
crontab can use cd to change working directory
-
#!
can be changed to pyenv .shim -
.py file need to be excutable
chmod +x
-
Sample crontab command
. ~/.bashrc cd /home/liuyidh/laviex/pyreport/ ./ALL_report.py`
-
use map() to simplify things
-
use list comprehension to flatten a nested list/dict
[b for dic in [dict1, dict2, dict3] for (a,b) in dic.items()]
-
use dict / list comprehension for powerful process:
info = {k: [x.strip() for x in v] for (k, v) in info.iteritems()} Use a dictionary when you have a set of unique keys that map to values. Use a list if you have an ordered collection of items. Use a set to store an unordered set of items.
-
filter empty string:
str_list = filter(None, str_list)
-
use functools.partial to freeze/set certain arguments
-
remember to close file to finish writing.
-
syntax brackets error due to sublime autocompletion
-
memory release
- del + gc.collect()
- multiprocessing
- divide into smaller chunks then use shell script to run one by one
-
class Object does not update automatically if you revise the class after the object is created.
-
Fucntions: reuse, readability, avoid redundancy
- KimPeek 2 years ago
- Functions should be small, sharp tools that do one thing well. This is a guideline, not a hard rule, but you should generally make a new function for each code block. Every loop, try/except block, whenever you indent more than 3 times, and anytime you are doing more than one thing.
- use astype(float) to change stype
- pandas-datareader 0.5.0 not available from conda, use pip instead, no need to downgrade
- be careful with JS re-written attributes and capitalization.
- be careful with text with /t/n spaces
- be careful wih variable explorer
- how to uWSGI
- how to multiple domains
- use nohup xxxx & to run background or use screen to run ssh tunneled python admin
- use crontab @reboot to start web2py.py -K app
- define table
- use request.args to dynamicly define variables (mailer headers etc.)
- request.requires_https() includes redirect and session.secure() link