Confusion about scan_code in modulefinder.py (in python 2.6)

Brock Pytlik bpytlik at sun.com
Tue Jan 12 21:15:17 EST 2010


I've been working with the modulefinder.py code recently and I've come 
across a bit of code I'm not grasping. In the scan_code function, there 
are the following lines:
                if sys.version_info >= (2, 5):
                        scanner = self.scan_opcodes_25
                else:
                        scanner = self.scan_opcodes
I don't understand their purpose. Why would I be running a version of 
python less than 2.6 and using the 2.6 module? Should this be looking at 
the version of python that was used to compile 'co'?

In my use, I'm subclassing the modulefinder class and adapting the 
scan_code function to do what I need, but I've found I need separate 
classes for (2.4, 2.5) and 2.6 because when running 2.4 or 2.5, the 
above code traces back. (In 2.4 because self.scan_opcodes isn't defined, 
in 2.5 because self.scan_opcodes_25 isn't.)

In the end, I've gotten everything working to my satisfaction, but I'm 
curious about how this module (and those lines in particular) were 
designed to be used. Any insight would be appreciated.

Thanks,
Brock



More information about the Python-list mailing list