below is the data I am trying to read

"000004"        "AS0042123BO"   "AS 0042.123 ROYAL ELONG SEAT
BO"     "001610"        "A/S Fixtures"  0       $99.00  3.70    ""      
"0042123"       11/20/2003
"000024"        "AS0042001BK"   "AS 0042.001 ROYAL EL*DISC BY
MFG*BK" "001610"        "A/S
Fixtures"       0       $99.00  8.00    "723085611663"  "0042001"       
11/20/2003
"000104"        "CH130TTWH"     "CH 130TT   EL PLAS SEAT C/F W/C
WH"     "207067"        "Church Seats"  12      $25.00  6.75    "073088079961"  
"130TT
000"    12/28/1995
"000112"        "CH130TTBO"     "CH 130TT   EL PLAS SEAT C/F W/C
BO"     "207067"        "Church Seats"  23      $29.00  7.50    "073088079954"  
"130TT
006"    02/23/1998
"000124"        "CH130TTSS"     "CH 130TT   EL PLAS SEAT C/F W/C
SS"     "207067"        "Church Seats"  14      $29.00  6.75    "073088079985"  
"130TT 162"
"000176"        "XPT562"        "PP T562"       "201681"        "Price
Pfister"        0       $233.50 0.00    ""      ""      01/22/1998
"000180"        "XPT564"        "PP T564"       "201681"        "Price
Pfister"        0       $0.00   0.00    ""      ""      07/19/1996
"000224"        "MO5270"        "MO 5270*DBM*MON BIDET FCT L/HDL
CP"     "204938"        "Moen"  0       $0.00   8.00    "026508050286"  "005270"
"000236"        "MO5270P"       "MO 5270P*DBM*BIDET FCT LVR/HDL
PB"     "204938"        "Moen"  0       $0.00   8.00    "026508050309"  "05270P"
"000240"        "MO5275"        "MO 5275 *DBM* BIDET FCT L/HDLS
CP"     "204938"        "Moen"  1       $0.00   8.00    ""      ""      
11/20/2003
"000244"        "MO5275P"       "MO 5275P*DBM* MON BIDET FCT
PB"     "204938"        "Moen"  0       $0.00   8.00    "026508050347"  
"05275P"        01/04/1996
"000248"        "MO5201"        "MO 5201 *DBM* TRAD BIDET LVR FCT
CP"     "204938"        "Moen"  0       $0.00   6.70    "026508050354"  "5201"  
01/04/1996
"000260"        "MO5201P"       "MO 5201P TRAD BIDET FCT
LVR/H*DBM*B"    "204938"        "Moen"  0       $0.00   7.00    "026508050378"  
"5201P" 01/04/1996
"000264"        "MO5201W"       "MO 5201W**DBM**IDET FCT LVR/HDL
WH"     "204938"        "Moen"  0       $0.00   6.70    "026508050385"  
"05201W"        01/04/1996
"066916"        "FB1418AB"      "FB D2418AB  18 TOWEL BAR
AB"     "220502"        "Liberty
Hardware"       0       $18.70  1.15    "079171141898"  "D2418AB"       
04/14/1998
"066920"        "FBD2424AB"     "FB D2424AB  24 TOWEL BAR
AB"     "220502"        "Liberty
Hardware"       39      $20.50  1.32    "079171242427"  "D2424AB"
"066956"        "P7341FLC"      "PP 734-1FLC*DBM* SNK FCT 1H L/SP
CP"     "201681"        "Price
Pfister"        0       $147.65 7.00    "038877420218"  "7341FLC"       
04/14/1998
"066960"        "P7341FLW"      "PP 734-1FLW FILT SNK FCT 1H L/SP
WH"     "201681"        "Price
Pfister"        0       $157.99 7.00    "038877420225"  "7341FLW"       
04/14/1998

Dennis Lee Bieber wrote:
> On 4 Jul 2006 07:01:55 -0700, "Roman" <[EMAIL PROTECTED]> declaimed
> the following in comp.lang.python:
>
> > I would appreciate it if somebody could tell me where I went wrong in
> > the following snipet:
> >
>       It would help if you gave a sample of the input data (three lines
> worth, say) AND an example of what the final output should be from those
> three lines.
>
> >     for col in line:
> >        p[:0].append(str(col))
>
>       As has been pointed out, as soon as you used the [:0], you created a
> local/temporary EMPTY slice of the original P, and you are appending one
> column's value to this temporary, which is then thrown away.
> import csv
>
> -=-=-=-=-=-=-=-               PROGRAM
> p = []
>
> fin = open("firearms.csv", "r")
> reader = csv.reader(fin, dialect="excel", quotechar='"', delimiter=",")
>
> for line in [reader.next() for i in range(7)]:
>     p.append(line)
>
> fin.close()
> print p
> -=-=-=-=-=-=-=-               OUTPUT
> [['Category', 'Model', 'Caliber', 'Serial #', 'Description',
> 'Accessories'], ['Air', 'Daisy 717 Pistol', '.177 pellet', '', '', ''],
> ['Air', 'Daisy/NRA PowerLine 953 Rifle', '.177 pellet', 'n/a',
> 'Micrometer Peep, "Globe" front (missing alternate inserts', 'Shooting
> sling'], ['Air', 'RWS Diana Model 54 "Air King" Rifle', '.22 pellet',
> '4022395', 'Hunting grade - >900fps', '2-7x BSA AOL scope'], ['Air',
> 'Gamo/NRA', '0.177', '', 'Hunting grade - ~1000fps; NRA markings on
> barrel, stock', '4x (BSA?) AOL scope, NRA badge'], ['Air',
> 'Walther/Crossman CP99 Pistol', '.177 pellet', '', 'CO2, repeater
> (currently magazine jams trigger/safety)', ''], ['Percussion', '? New
> Orleans Ace boot-pistol', '.36 lead', '', '', '']]
> -=-=-=-=-=-=-=-               INPUT (just first seven lines)
> Category,Model,Caliber,Serial #,Description,Accessories
> Air,Daisy 717 Pistol,.177 pellet,,,
> Air,Daisy/NRA PowerLine 953 Rifle,.177 pellet,n/a,"Micrometer Peep,
> ""Globe"" front (missing alternate inserts",Shooting sling
> Air,"RWS Diana Model 54 ""Air King"" Rifle",.22 pellet,4022395,Hunting
> grade - >900fps,2-7x BSA AOL scope
> Air,Gamo/NRA,0.177,,"Hunting grade - ~1000fps; NRA markings on barrel,
> stock","4x (BSA?) AOL scope, NRA badge"
> Air,Walther/Crossman CP99 Pistol,.177 pellet,,"CO2, repeater (currently
> magazine jams trigger/safety)",
> Percussion,? New Orleans Ace boot-pistol,.36 lead,,,
>
>
>
>       But your explanations are unclear... Maybe you wanted the first
> sublist to be all the first column, etc.
>
> -=-=-=-=-=-=-=-               PROGRAM
> import csv
>
> p = None
>
> fin = open("firearms.csv", "r")
> reader = csv.reader(fin, dialect="excel", quotechar='"', delimiter=",")
>
> for line in [reader.next() for i in range(7)]:
>     if not p:
>         p = [[] for j in range(len(line))]
>     for c in range(len(line)):
>         p[c].append(line[c])
>
> fin.close()
> print p
> -=-=-=-=-=-=-=-               OUTPUT (same input)
> [['Category', 'Air', 'Air', 'Air', 'Air', 'Air', 'Percussion'],
> ['Model', 'Daisy 717 Pistol', 'Daisy/NRA PowerLine 953 Rifle', 'RWS
> Diana Model 54 "Air King" Rifle', 'Gamo/NRA', 'Walther/Crossman CP99
> Pistol', '? New Orleans Ace boot-pistol'], ['Caliber', '.177 pellet',
> '.177 pellet', '.22 pellet', '0.177', '.177 pellet', '.36 lead'],
> ['Serial #', '', 'n/a', '4022395', '', '', ''], ['Description', '',
> 'Micrometer Peep, "Globe" front (missing alternate inserts', 'Hunting
> grade - >900fps', 'Hunting grade - ~1000fps; NRA markings on barrel,
> stock', 'CO2, repeater (currently magazine jams trigger/safety)', ''],
> ['Accessories', '', 'Shooting sling', '2-7x BSA AOL scope', '4x (BSA?)
> AOL scope, NRA badge', '', '']]
> --
>       Wulfraed        Dennis Lee Bieber               KD6MOG
>       [EMAIL PROTECTED]               [EMAIL PROTECTED]
>               HTTP://wlfraed.home.netcom.com/
>       (Bestiaria Support Staff:               [EMAIL PROTECTED])
>               HTTP://www.bestiaria.com/

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to