[Chicago] 2 unique keys in a python dict?
Massimo Di Pierro
mdipierro at cs.depaul.edu
Thu Oct 9 18:19:02 CEST 2008
Or....
edit the header of the CSV file and call your columns
tid, paid, ttid
instead of
id, paid, transaction
and remove the '$' signs from there
download web2py and type
python web2py.py -S welcome
>>> db=SQLDB()
>>> db.define_table('mytable',
SQLField('tid','integer'),
SQLField('paid','double'),
SQLField('ttid','string'))
>>> db.import_from_csv_file(open('yourfilename.csv'))
>>> db.commit()
>>>
rows
=
db
().select
(db
.mytable
.ttid
,db.mytable.paid.sum(),orderby=db.mytable.ttid,groupby=db.mytable.ttid)
>>> for row in rows:
... print 'transaction',row.ttid,'total
amount',row[db.mytable.paid.sum()]
On Oct 9, 2008, at 11:06 AM, Lukasz Szybalski wrote:
> On Thu, Oct 9, 2008 at 10:49 AM, <skip at pobox.com> wrote:
>>
>> Lukasz> Is it possible to have multiple keys in a python
>> dictionary?
>>
>> Certainly. Though I don't think that's really what you intended to
>> ask.
>>
>> Lukasz> Normally its only 1 key, and I need to have 2
>> dictionaries and
>> Lukasz> somehow manage the uniqueness.
>> Lukasz> me={}
>> Lukasz> me['First']='Lucas'
>> Lukasz> me['Last']='szybalski'
>>
>> Lukasz> I would like to get 2 keys? Is there something similar to
>> dict
>> Lukasz> that would have the property that 2 or more keys are
>> unique?
>> Lukasz> me= ?
>>
>> I'm unclear what you are asking. Do you want a list of
>> dictionaries?, e.g.:
>>
>> names = [
>> {
>> 'First': 'Lucas',
>> 'Last': 'Szybalski',
>> },
>> {
>> 'First': 'Skip',
>> 'Last': 'Montanaro',
>> }
>> ]
>>
>
>
> I have multiple records in a csv file for each userid. I need to
> calculate total amount paid and last transaction.
>
> id,paid,transaction
> 3,$10,20080101
> 3,$10,20080201
>
>
> Final Total
> me={}
> me[3]=($20,20080201) (dictionary with a list)
>
> now
> id,subid, paid,transaction
> 3,1,$10,20080101
> 3,2,$10,20080201
>
> I guess what Massimo said will work, but now I need to know which row
> is the paid and which is transaction?!!
> me[3,1]=(10,20080101)
> me[3,2]=(10,20080201)
>
> I guess this could do it
> me[3,1]={'paid':10 , 'transaction':20080101}
>
> Thanks,
> Lucas
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
More information about the Chicago
mailing list