Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45060

Re: help on Implementing a list of dicts with no data pattern

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'yet.': 0.04; 'output': 0.05; 'string.': 0.05; 'error:': 0.07; 'subject:help': 0.08; 'content:': 0.09; 'data:': 0.09; 'line:': 0.09; 'next,': 0.09; 'wrong,': 0.09; '23,': 0.16; '32,': 0.16; 'block.': 0.16; 'columns': 0.16; 'different,': 0.16; 'for,': 0.16; 'nameerror:': 0.16; 'skip:q 30': 0.16; 'stumbling': 0.16; 'skip:= 10': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'bit': 0.19; 'pointed': 0.19; 'meant': 0.20; 'code,': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'headers': 0.24; 'earlier': 0.24; "haven't": 0.24; "i've": 0.25; 'references': 0.26; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'testing': 0.29; 'errors': 0.30; 'needed.': 0.30; 'subject:list': 0.30; 'code': 0.31; 'lines': 0.31; "skip:' 10": 0.31; 'are.': 0.31; 'bunch': 0.31; 'disable': 0.31; 'object.': 0.31; 'produces': 0.31; 'skip:q 20': 0.31; 'trivial': 0.31; 'file': 0.32; 'lists': 0.32; 'there.': 0.32; 'figure': 0.32; 'skip:c 30': 0.32; '(most': 0.33; 'bugs': 0.33; 'guess': 0.33; 'skip:# 10': 0.33; 'subject:with': 0.35; "can't": 0.35; 'but': 0.35; 'there': 0.35; 'subject:data': 0.36; "didn't": 0.36; "i'll": 0.36; 'list': 0.37; 'same.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'little': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'major': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'dave': 0.60; 'hope': 0.61; 'new': 0.61; "you're": 0.61; 'name': 0.63; 'more': 0.64; 'note:': 0.66; 'here': 0.66; 'yes': 0.68; 'content,': 0.68; 'received:74.208': 0.68; 'results': 0.69; 'containing': 0.69; 'cut': 0.74; '100': 0.79; "'state'": 0.84; 'received:74.208.4.194': 0.84; 'total,': 0.84; 'aging': 0.91; 'angel': 0.91; 'from.': 0.93; '2013': 0.98
Date Thu, 09 May 2013 18:32:21 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5
MIME-Version 1.0
To python-list@python.org
Subject Re: help on Implementing a list of dicts with no data pattern
References <c27c3eef-44f5-467c-b3a3-119263deb035@googlegroups.com> <5bc1d8b8-61b1-446d-8487-1e72c1ddf925@googlegroups.com> <mailman.1500.1368123592.3114.python-list@python.org> <3bcb3a3a-f1e2-4e31-b917-6a4391ddb9fa@googlegroups.com>
In-Reply-To <3bcb3a3a-f1e2-4e31-b917-6a4391ddb9fa@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:5fKca2GsvU9jf3WRiYkK+TKCp/HuCfZy2MXjtx95W90 Dp2KO8jKJifoYeXjRGgJcF9UnQO8ZgEDkM8WJRmXPbLSv0UsWG zTNEZXpJXFH6Up+cm302LUq4uuThmKRoydvV7kHE7o/5julN4U KsWsScOeyqmOEhAfCFPrCPYlL+/H8r6AqD1YgXPpqT61iaRyod l98TOlVihZqdHFtpi8tpdHbg0++FEPr9V2MBeO4A+mL4rRhJDp s4XAEGK1FzLCXhdUyYqa9OLf+1if3ZOJ8RSaZsENxAHWgBSTCX GFjMjVg2aLpJjsVkgLSwv0AOku1QgKY2FpB6b54VRkF9KYfbw= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1508.1368138770.3114.python-list@python.org> (permalink)
Lines 139
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368138770 news.xs4all.nl 15962 [2001:888:2000:d::a6]:51796
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45060

Show key headers only | View raw


On 05/09/2013 05:22 PM, rlelis wrote:
> On Thursday, May 9, 2013 7:19:38 PM UTC+1, Dave Angel wrote:
>
> Yes it's a list of string. I don't get the NameError: name 'file_content' is not defined in my code.

That's because you have the 3 lines below which we hadn't seen yet.

>
> After i appended the headers i wanted to cut the data list it little bit more because there was some data (imagine some other collumns) to the left that didn't needed.
>
> file_content = []
> for d in data:
>      file_content.append(d[1:])
>
> from this point on i've showed the code,
> highway_dict = {}
> aging_dict = {}
> queue_counters={}
> queue_row = []
> for content in file_content:
>          if 'aging' in content:
>                  # aging 0 100
>                  # code here
>

OK, so I now have some code I can actually run.  Unfortunately, it 
produces an error:

Traceback (most recent call last):
   File "ricardo.py", line 23, in <module>
     aging_dict['total'], aging_dict[columns] = total, aging_values
NameError: name 'total' is not defined

So I'll make a reasonable guess that you meant total_values there.  I 
still can't understand how you're testing this code, when there are 
trivial bugs in it.

Next, I get:

Traceback (most recent call last):
   File "ricardo.py", line 32, in <module>
     highway_dict['lanes'], highway_dict['state'], 
highway_dict['limit(mph)'] = lanes, state, limit_values
NameError: name 'lanes' is not defined

and then:

Traceback (most recent call last):
   File "ricardo.py", line 32, in <module>
     highway_dict['lanes'], highway_dict['state'], 
highway_dict['limit(mph)'] = lanes_values, state, limit_values
NameError: name 'state' is not defined

Each of those not-defined errors was pointed out by me earlier in the 
thread.

I don't see any output logic, so I guess it's up to us to guess what the 
meanings and scope of the various lists and dicts are.  I figure the 
queue_row is your final collection that you hope to get results from. 
It's a list containing many references to a single queue_counters 
object.  So naturally, they all look the same.

If you want them to be different, you have to create a new one each 
time.  Move the line:
     queue_counters={}

inside the loop, right after the line:
     for content in file_content:

There are a bunch of other things wrong, like not lining up the columns 
when you're substringing content, but this may be your major stumbling 
block.  Note:  you may have to also move the highway_dict and 
aging_dict;  I haven't figured out what they're for, yet.

Following is the code I've been using to try to figure out what you were 
intending:


file_content = [
         "aging 0 100",
         "aging 2 115",
         "aging 3 1",
         "highway 4 disable 25",
         "highway 2 disable 245",
         "highway 0 enable 125",
     ]

highway_dict = {}
aging_dict = {}
#queue_counters={}
queue_row = []
for content in file_content:
         queue_counters={}
         if 'aging' in content:
                 # aging 0 100
                 columns = ', '.join(map(str, 
content[:1])).replace('-','_').lower()
                 print "columns:", columns
                 total_values =''.join(map(str, content[1:2]))
                 aging_values = '\t'.join(map(str, content[2:]))

                 aging_dict['total'], aging_dict[columns] = 
total_values, aging_values
                 queue_counters[columns] = aging_dict
         if 'highway' in content:
                 #highway        |       4       |       disable |       25
                 columns = ''.join(map(str, 
content[:1])).replace('-','_').lower()
                 lanes_values  =''.join(map(str, content[1:2]))
                 state_values = ''.join(map(str, content[2:3])).strip('')
                 limit_values = ''.join(map(str, content[3:4])).strip('')

                 highway_dict['lanes'], highway_dict['state'], 
highway_dict['limit(mph)'] = lanes_values, state_values, limit_values
                 queue_counters[columns] = highway_dict
         queue_row.append(queue_counters)


print
print "h dict:", highway_dict
print
print "aging dict:", aging_dict
print
print "q counters:", queue_counters
for key, item in  queue_counters.iteritems():
     print key, item

print
print "q row:", queue_row
for item in queue_row:
     print item






-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

help on Implementing a list of dicts with no data pattern rlelis <ricardo.lelis3@gmail.com> - 2013-05-08 16:47 -0700
  Re: help on Implementing a list of dicts with no data pattern Dave Angel <davea@davea.name> - 2013-05-08 20:05 -0400
  Re: help on Implementing a list of dicts with no data pattern MRAB <python@mrabarnett.plus.com> - 2013-05-09 01:16 +0100
  Re: help on Implementing a list of dicts with no data pattern rlelis <ricardo.lelis3@gmail.com> - 2013-05-09 02:57 -0700
    Re: help on Implementing a list of dicts with no data pattern Dave Angel <davea@davea.name> - 2013-05-09 08:26 -0400
    Re: help on Implementing a list of dicts with no data pattern Neil Cerutti <neilc@norwich.edu> - 2013-05-09 13:08 +0000
  Re: help on Implementing a list of dicts with no data pattern rlelis <ricardo.lelis3@gmail.com> - 2013-05-09 07:33 -0700
    Re: help on Implementing a list of dicts with no data pattern Dave Angel <davea@davea.name> - 2013-05-09 10:50 -0400
  Re: help on Implementing a list of dicts with no data pattern rlelis <ricardo.lelis3@gmail.com> - 2013-05-09 09:14 -0700
    Re: help on Implementing a list of dicts with no data pattern Dave Angel <davea@davea.name> - 2013-05-09 14:19 -0400
      Re: help on Implementing a list of dicts with no data pattern rlelis <ricardo.lelis3@gmail.com> - 2013-05-09 14:22 -0700
        Re: help on Implementing a list of dicts with no data pattern Dave Angel <davea@davea.name> - 2013-05-09 18:32 -0400
          Re: help on Implementing a list of dicts with no data pattern Neil Cerutti <neilc@norwich.edu> - 2013-05-10 12:54 +0000

csiph-web