Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #71215
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-05-09 19:21 -0700 |
| References | <1ba8744e-943b-4c71-abd7-9dea12db8780@googlegroups.com> |
| Message-ID | <4f659d7a-1175-4348-a097-41efc33d13c8@googlegroups.com> (permalink) |
| Subject | Re: How to implement key of key in python? |
| From | CHIN Dihedral <dihedral88888@gmail.com> |
On Saturday, May 10, 2014 9:22:43 AM UTC+8, eckh...@gmail.com wrote:
> I'm migrating from Perl to Python and unable to identify the equivalent of key of key concept. The following codes run well,
>
>
>
> import csv
>
>
>
> attr = {}
>
>
>
> with open('test.txt','rb') as tsvin:
>
> tsvin = csv.reader(tsvin, delimiter='\t')
>
>
>
> for row in tsvin:
>
> ID = row[1]
>
>
>
>
>
> until:
>
> attr[ID]['adm3'] = row[2]
>
>
>
> I then try:
>
> attr[ID].adm3 = row[2]
>
>
>
> still doesn't work. Some posts suggest using module dict but some do not. I'm a bit confused now. Any suggestions?
Please check your attr as an empty dictionary or so-called a hash in perl.
The syntax of adding a (K,V) pair
is different between python and perl.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to implement key of key in python? eckhleung@gmail.com - 2014-05-09 18:22 -0700
Re: How to implement key of key in python? CHIN Dihedral <dihedral88888@gmail.com> - 2014-05-09 19:21 -0700
Re: How to implement key of key in python? MRAB <python@mrabarnett.plus.com> - 2014-05-10 03:30 +0100
Re: How to implement key of key in python? eckhleung@gmail.com - 2014-05-09 20:28 -0700
Re: How to implement key of key in python? Andrea D'Amore <anddamNOALPASTICCIODICARNE+gruppi@brapi.net> - 2014-05-10 09:07 +0200
Re: How to implement key of key in python? Peter Otten <__peter__@web.de> - 2014-05-10 10:21 +0200
csiph-web