Ruby boolean operator (or ruby parsing) bug

This has bitten me a couple times in the last few days. The Ruby “or” (or equals) operator appears to have a bug where, when used in an assignment, the first value is assigned rather than the results of the entire expression.

irb(main):001:0> x = false || true
=> true
irb(main):002:0> x
=> true
irb(main):003:0> z = false or true
=> true
irb(main):004:0> z
=> false

ruby version: ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.10.1]

I would expect z to be true in that last example.

Zemanta Pixie

Python Path and Module Basics

I’m getting started with Python and Google App Engine. One of the first things I had to figure out was how Python handles paths and module names.
You can see what paths python is looking on with this command sequence:


$ python
['', '/opt/local/var/macports/software/python25/2.5.2_2+darwin_8/opt/local/lib/', '/opt/local/var/macports/software/python25/2.5.2_2+darwin_8/opt/local/lib/python2.5', '/opt/local/var/macports/software/python25/2.5.2_2+darwin_8/opt/local/lib/python2.5/plat-darwin', '/opt/local/var/macports/software/python25/2.5.2_2+darwin_8/opt/local/lib/python2.5/plat-mac', '/opt/local/var/macports/software/python25/2.5.2_2+darwin_8/opt/local/lib/python2.5/plat-mac/lib-scriptpackages', '/opt/local/var/macports/software/python25/2.5.2_2+darwin_8/opt/local/lib/python2.5/lib-tk', '/opt/local/var/macports/software/python25/2.5.2_2+darwin_8/opt/local/lib/python2.5/lib-dynload', '/opt/local/var/macports/software/python25/2.5.2_2+darwin_8/opt/local/lib/python2.5/site-packages']
Python 2.5.2 (r252:60911, Jun  1 2008, 16:53:35)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
>>> exit()


Inside a python script Modules are included with this syntax:
from google.appengine.ext.bulkload import constants
All that means is that python is going to look on the paths above for /google/appengine/ext/bulkload/
In my case, the script I was trying to run sets up the paths for a secondary main script with some code like this:


os.path.join(GOOGLE_PATH, 'lib', 'django'),
os.path.join(GOOGLE_PATH, 'lib', 'webob'),
os.path.join(GOOGLE_PATH, 'lib', 'yaml', 'lib'),
if __name__ == '__main__':
sys.path = EXTRA_PATHS + sys.path
script_path = os.path.join(DIR_PATH, BULKLOAD_CLIENT_PATH)
execfile(script_path, globals())


So, you can see here that sys.path is assignable and retained when calling other scripts.
I also learned that you can set the $PYTHONPATH environment variable to a list of paths, just like the normal $PATH variable. However, unlike Windows, you have “export” the environment variable.


$ PYTHONPATH=$PYTHONPATH:/include/this:/and/this


The export command takes the local shell variable and makes it visible as a global variable (in this case to Python).