Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Wednesday, May 20, 2015

Today I learned that properties can't be accessed as functions

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.

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

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/

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

().__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.py
You can then clean up the result as explained in chpt 18 of the Djangobook: http://www.djangobook.com/en/2.0/chapter18.html

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.