Page 1 of 1

Adafruit Raspberry Pi Python Code TabError in v3.2

Posted: Thu Mar 06, 2014 8:02 pm
by Maddog64
Hi

Still a newbie (just less newbie than a fortnight ago!) and just trying to learn about using GPIO and the Adafruit Cobbler. I've downloaded the code from http://github.com/adafruit/Adafruit-Ras ... n-Code.git. Two issues:

1. Unless I'm in the specific directory for a module, the import won't work. If I echo $PYTHONPATH I get a blank line returned. The code has several directories for each of the modules so do I have to add every one to the PYTHONPATH? What's the easiest way to add paths?

2. If I use Python3.2 (which is what started on) I get a TabError importing the Adafruit_CharLCD.py module but I don't get the error if I use Python2.7. I'm assuming this will happen with other modules and I'm guessing 3.2 is stricter on the indentation rules. How can I get the modules to import without error in 3.2? Do I need to edit every module to get the indentation right!?

Sorry if these are dumb questions but struggling a bit now!

Cheers

Rob

Re: Adafruit Raspberry Pi Python Code TabError in v3.2

Posted: Thu Mar 06, 2014 8:32 pm
by Douglas6
1. Python will search the directories that are listed in the sys.path variable for imported modules. I like to put common modules like the Adafruit ones in 'site-packages'. You can get a list for your environment by:

Code: Select all

>>> import sys
>>> sys.path
2. If I recall, Python3 will not allow a mixture of tabs and space indents. So yes, i think you'll need to clean up 2.7 code for Python3. You may also run across differences in the print() syntax. There may be a utility to help with the conversions; me I'm sticking with 2.7

Re: Adafruit Raspberry Pi Python Code TabError in v3.2

Posted: Thu Mar 06, 2014 10:45 pm
by Maddog64
Hi Douglas

Many thanks - makes sense to move all the Adafruit modules into one directory and then add that to the PYTHONPATH - why didn't I think of that!!

I guess still being new to this, I'll not notice any difference between 2.7 and 3.2 so for now I'll stick with 2.7 as well.

Thanks for the swift reply,

Rob