On May 8, 2009, at 12:44 PM, Jenny Qing Qian wrote:

>
> I like the option of overwriting the builtin dir() for Python 2.6 or  
> later.  Is there a way to implement this without descriptors?  A way  
> that is universally supported by any Python version.  What's wrong  
> with __getattr__?

Hi Jenny,
I implemented a basic version of this.  First, I added __dir__ to  
worldbase (the new name for pygr.Data) objects.  Thus in Python 2.6  
you can do the following:

Python 2.6.1 (r261:67515, Apr  8 2009, 05:56:20)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> from pygr import worldbase
 >>> dir(worldbase.Bio) # pygr is doing a worldbase query to retrieve  
this...
['MSA', 'Seq']
 >>> dir(worldbase.Bio.MSA)
['UCSC']
 >>> dir(worldbase.Bio.MSA.UCSC)
['bosTau2ToBostau3', 'bosTau3ToBostau4', 'bosTau4_multiz5way',  
'calJac1_multiz9way', 'canFam2_multiz4way', 'ce2ToCe4',  
'danRer2ToDanrer3', 'danRer3ToDanrer2', 'danRer3ToDanrer4',  
'danRer3_multiz5way', 'danRer4ToDanrer3', 'danRer4ToDanrer5',  
'danRer4_multiz7way', 'danRer5ToDanrer4', 'dm2ToDm3',  
'dm2_multiz15way', 'dm2_multiz9way', 'dm3_multiz15way',  
'felCat3_multiz4way', 'fr2_multiz5way', 'galGal2ToGalgal3',  
'galGal2_multiz7way', 'galGal3_multiz7way', 'gasAcu1_multiz8way',  
'hg17ToHg18', 'hg17_multiz17way', 'hg18ToHg17', 'hg18_multiz17way',  
'hg18_multiz28way', 'mm5ToMm6', 'mm5ToMm7', 'mm5ToMm8', 'mm7ToMm5',  
'mm7ToMm6', 'mm7ToMm8', 'mm7_multiz17way', 'mm8ToMm7', 'mm8ToMm9',  
'mm8_multiz17way', 'mm9ToMm8', 'mm9_multiz30way',  
'monDom4_multiz7way', 'ornAna1_multiz6way', 'oryLat1_multiz5way',  
'panTro1ToPantro2', 'panTro2ToPantro1', 'ponAbe2_multiz8way',  
'rn3ToRn4', 'rn4ToRn3', 'rn4_multiz9way', 'xenTro1ToXentro2',  
'xenTro1_multiz5way']

Second, I added a pygr.dir() function that will work with __dir__  
methods on any version of Python (on Python 2.6+ it just defaults to  
the builtin dir()).  So in any version of Python you can do the  
following:

Python 2.5.2 (r252:60911, Apr  1 2008, 20:54:02)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> from pygr import worldbase, dir
 >>> dir(worldbase.Bio) # using pygr.dir()
['Seq', 'MSA']
...etc...

Third, I also added __dir__ support to sqlgraph.TupleO and SQLRow,  
which represent SQLTable row objects. e.g.
Python 2.6.1 (r261:67515, Apr  8 2009, 05:56:20)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> from pygr import sqlgraph
 >>> t = sqlgraph.SQLTable('music.itunes_in3') # itunes database  
loaded in MySQL...
/sw/lib/python2.6/site-packages/MySQLdb/__init__.py:34:  
DeprecationWarning: the sets module is deprecated
   from sets import ImmutableSet
 >>> o = t[1] # get track 1
 >>> dir(o) # will reflect the column names in the database table...
['Album', 'Artist', 'BitRate', 'Comments', 'Composer', 'DateAdded',  
'DateModified', 'DiscCount', 'DiscNumber', 'Equalizer', 'Genre',  
'Grouping', 'Kind', 'LastPlayed', 'LastSkipped', 'Location',  
'MyRating', 'Name', 'PlayCount', 'SampleRate', 'Size', 'SkipCount',  
'Time', 'TrackCount', 'TrackNumber', 'VolumeAdjustment', 'Year', 'id']

Try it out if you're interested.  Get the latest code from my github  
repository.

-- Chris


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pygr-dev" group.
To post to this group, send email to pygr-dev@googlegroups.com
To unsubscribe from this group, send email to 
pygr-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/pygr-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to