[Tutor] How to set up an Array?
nickel flipper
nickelflipper at yahoo.com
Tue May 12 04:09:30 CEST 2009
Hello,
Just getting started with Python, and have had some early, although trivial success. It looks like just the ticket to parse a data file. Total noob at this, but really kind of overwhelmed by all the options. Looking for some direction on which modules, librarys, or ? to accomplish the goal.
To date have been using conditional type statement to tease out information. Now I need to match some strings, put them in an array or list? and read them back after X number of lines. The linesplits are in a predictable pattern and padded by '-' to get eight values or arrays that will be joined together after a set condition is no longer true.
So from the data set below, will be looking to print out:
RA7,OSC1,CLKI
RA6,OSC2
RA5,AN4,nSS1,LVDIN,RCV,RP2
ETC.
Any tips greatly appreciated. Thanks.
sfr (key=PORTA addr=0xf80 size=1 access='rw rw rw u rw rw rw rw')
reset (por='xxxxxxxx' mclr='uuuuuuuu')
bit (names='RA7 RA6 RA5 - RA3 RA2 RA1 RA0' width='1 1 1 1 1 1 1 1')
bit (tag=scl names='RA' width='8')
bit (names='OSC1 OSC2 AN4 - AN3 AN2 AN1 AN0' width='1 1 1 1 1 1 1 1')
bit (names='CLKI CLKO nSS1 - VREF_PLUS VREF_MINUS C2INA C1INA' width='1 1 1 1 1 1 1 1')
bit (names='- - LVDIN - C1INB CVREF_MINUS PMPA7 PMPA6' width='1 1 1 1 1 1 1 1')
bit (names='- - RCV - - C2INB RP1 RP0' width='1 1 1 1 1 1 1 1')
bit (names='- - RP2 - - - - -' width='1 1 1 1 1 1 1 1')
Here is some noob code used to pick out the RA7, RA6, RA5 etc. Comments welcome.
if line.startswith ( " bit (names='R" ):
(a, pin7, pin6, pin5, pin4, pin3, pin2, pin1, pin0) = (line.split() + ["", ""])[:9]
startpin = pin7[8:3]
if startpin.startswith == "RA" or "RB" or "RC" or "RD" or "RE" or "RF" or "RG" or "RH" or "RJ":
print pin7[8:] + "," + pin6 + "," + pin5 + "," + pin4 + "," + pin3 + "," + pin2 + "," + pin1 + "," + pin0[:3] + "\n"
else:
pass
More information about the Tutor
mailing list