It took a long time for me to debug something that was simple.
I had a method defined as a property and I built another method that took its output.
Out of habit, I called the function. And my operation failed. The lesson was pretty simple: don't try to call a property. It's a value now, not a method.
Recursive algorithms can be slow because they end up solving the same little problems over and over again. To speed them up, you can use a technique called "memoization." Memoization allows algorithms go much more quickly by remembering solutions to problems they have already solved. I’m the recursive algorithm. This blog is my memoization.
Showing posts with label python. Show all posts
Showing posts with label python. Show all posts
Wednesday, May 20, 2015
Friday, January 9, 2015
Nice list of algorithms with Python and Java implementations
Monday, December 29, 2014
Awhile ago I used pip to install python's cssselect. I'm not sure (should have taken notes!), but it seems like it was difficult, requiring that I get in and install various c libraries. This time it was effortless. Here are the instructions that I followed:
http://www.installion.co.uk/ubuntu/saucy/universe/p/python-cssselect/en/install/index.html
http://www.installion.co.uk/ubuntu/saucy/universe/p/python-cssselect/en/install/index.html
Labels:
apt-get,
cssselect,
pip,
python,
ubuntu universe
Monday, December 8, 2014
The Hitchhiker’s Guide to Python!--the next book
I've been reading a chapter each day from the Django book. I'm now almost through working through the appendix. Now, just in the nick of time, I discovered where to go next.
The book is an open-source, ongoing project that is headed by my current python hero, Kenneth Reitz.
http://docs.python-guide.org/en/latest/
The book is an open-source, ongoing project that is headed by my current python hero, Kenneth Reitz.
http://docs.python-guide.org/en/latest/
Saturday, November 29, 2014
Why not to use Python's 'eval' in a public service calculator
Here's a fun write-up on python eval security issues:
http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
Basically, even if you try to restrict access to any and all functions and classes, you can use lambda functions and introspection to get a huge amount of access.
The most fun example in the write-up is
This gives a list of all classes instantiated to that point in the program.
http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
Basically, even if you try to restrict access to any and all functions and classes, you can use lambda functions and introspection to get a huge amount of access.
The most fun example in the write-up is
().__class__.__bases__[0].__subclasses__()
This gives a list of all classes instantiated to that point in the program.
Friday, November 28, 2014
cool tool in django: inspectdb
Say you have a legacy database and you want to put django on top of it. One line will construct python models for the database structure:
python mysite/manage.py inspectdb > mysite/myapp/models.pyYou can then clean up the result as explained in chpt 18 of the Djangobook: http://www.djangobook.com/en/2.0/chapter18.html
Labels:
awesomeness,
databases,
django,
legacy code,
python
Wednesday, November 12, 2014
Friday, November 7, 2014
Getting python path associated with default python version
Getting python path associated with default python version:
python -c 'import sys, pprint; pprint.pprint(sys.path)'
Semicolons to delimit lines, pprint to make the output pretty, sys.path to see what will actually be called.
In my case I learned that my virtual environment version of python is calling libraries outside of that environment.
python -c 'import sys, pprint; pprint.pprint(sys.path)'
Semicolons to delimit lines, pprint to make the output pretty, sys.path to see what will actually be called.
In my case I learned that my virtual environment version of python is calling libraries outside of that environment.
Labels:
pprint,
python,
python path,
python version,
sys,
sys.path,
virtualenv
Subscribe to:
Posts (Atom)