Re: [Tutor] Accessing Specific Dictionary items

2011-08-01 Thread bob gailer
On 8/1/2011 8:34 PM, Mike Nickey wrote: [snip] [{'city': 'Buena Park', 'region_name': 'CA', 'area_code': 714}, {'city': 'Wallingford', 'region_name': 'CT', 'area_code': 203}, {'city': 'Schenectady', 'region_name': 'NY', 'area_code': 518}, {'city': 'Athens', 'region_name': '35'}] IMHO this is

Re: [Tutor] Accessing Specific Dictionary items

2011-08-01 Thread Mike Nickey
Thank you all, I have found the assistance needed and the guidance here was wonderful. I needed to add a line in the middle that did a temporary storage for me before trying to append this to the list. It might not be the most elegant solution but it works. On Mon, Aug 1, 2011 at 17:28, wrote:

Re: [Tutor] Accessing Specific Dictionary items

2011-08-01 Thread eire1130
Dictionaries are objects and you access their attributes through keys. So, let's say I had a dict: d = {'city':'plattsburgh'} I would thus access the attribute by doing this d['city'] You can store that value to a variable Or you can append to a list directly. l = [] for d in yourdict:

Re: [Tutor] Accessing Specific Dictionary items

2011-08-01 Thread Steven D'Aprano
Mike Nickey wrote: The input being used is through pygeoip. Using this I am pulling the data by IP and from what I am reading this populates as a dictionary. Here is some of the output that I can show currently [{'city': 'Buena Park', 'region_name': 'CA', 'area_code': 714}, {'city': 'Wallingford

Re: [Tutor] Accessing Specific Dictionary items

2011-08-01 Thread Mike Nickey
The input being used is through pygeoip. Using this I am pulling the data by IP and from what I am reading this populates as a dictionary. Here is some of the output that I can show currently [{'city': 'Buena Park', 'region_name': 'CA', 'area_code': 714}, {'city': 'Wallingford', 'region_name': 'CT

Re: [Tutor] time zone conversion

2011-08-01 Thread spawgi
Quick question - Is any daylight saving taken into consideration for this? On Tue, Aug 2, 2011 at 1:35 AM, ian douglas wrote: > Hi all, > > Been trying to wrap my head around some datetime vs time stuff with regards > to parsing a string as a date plus time with a timezone offset. > > This is the

Re: [Tutor] Accessing Specific Dictionary items

2011-08-01 Thread ian douglas
On 08/01/2011 03:05 PM, Mike Nickey wrote: Hi all, I'm trying to access and use specific items within a dictionary that is returned but am having issues in doing so. [{'city': 'Sunnyvale', 'region_name': 'CA', 'area_code': 408, 'metro_code': 'Santa Clara, CA', 'country_name': 'United States'}]

Re: [Tutor] Accessing Specific Dictionary items

2011-08-01 Thread eire1130
I'm not sure I'm following. Could you give an example of expected input and expected output? Sent from my Verizon Wireless BlackBerry -Original Message- From: Mike Nickey Sender: tutor-bounces+eire1130=gmail@python.org Date: Mon, 1 Aug 2011 15:05:30 To: Subject: [Tutor] Accessing

[Tutor] Accessing Specific Dictionary items

2011-08-01 Thread Mike Nickey
Hi all, I'm trying to access and use specific items within a dictionary that is returned but am having issues in doing so. [{'city': 'Sunnyvale', 'region_name': 'CA', 'area_code': 408, 'metro_code': 'Santa Clara, CA', 'country_name': 'United States'}] How can I populate a list of many different r

Re: [Tutor] Question about sorting a list within a dictionary within a list

2011-08-01 Thread Peter Otten
Peter Otten wrote: > Untested: > > from operator import attrgetter, itemgetter > from itertools import imap > > firsts = imap(itemgetter(0), conn.get_all_instances()) > reservations = sorted(firsts, key=attrgetter("launch_time")) > > This gives you objects rather than the objects' __dict__s. O

Re: [Tutor] Question about sorting a list within a dictionary within a list

2011-08-01 Thread Peter Otten
ian douglas wrote: > On 08/01/2011 01:03 PM, Peter Otten wrote: >> ian douglas wrote: >> >>> I'm using the Bono library for talking to EC2, and I'm getting a list of >>> >>> I cannot help you with the django or boto part. > > Well, I suppose that using django/bono wasn't really relevant to the >

Re: [Tutor] Question about sorting a list within a dictionary within a list

2011-08-01 Thread ian douglas
On 08/01/2011 01:03 PM, Peter Otten wrote: ian douglas wrote: I'm using the Bono library for talking to EC2, and I'm getting a list of I cannot help you with the django or boto part. Well, I suppose that using django/bono wasn't really relevant to the question. I appreciate the feedback t

[Tutor] time zone conversion

2011-08-01 Thread ian douglas
Hi all, Been trying to wrap my head around some datetime vs time stuff with regards to parsing a string as a date plus time with a timezone offset. This is the string I'm given: 2010-01-22T00:14:33.000Z And I can use time.strptime to parse out its individual elements, but then I need to adj

Re: [Tutor] Question about sorting a list within a dictionary within a list

2011-08-01 Thread Peter Otten
ian douglas wrote: > I'm using the Bono library for talking to EC2, and I'm getting a list of > EC2 instances back in a list called "reservations". Each element in the > list is a dictionary of information. One of those dictionary elements is > a list called 'instances', and I only ever care about

Re: [Tutor] get last 7 days string in a log file

2011-08-01 Thread Bjørn Roar Eriksen
Yes, that is what I want to do. Kind Regard Bjørn-Roar Den 1. aug. 2011 kl. 20:24 skrev spa...@gmail.com: > Hi, > > Let me understand the problem > - Do you want to count the number of times the application was restarted > between today and 7 days back? > => If yes, then you will need to do s

Re: [Tutor] get last 7 days string in a log file

2011-08-01 Thread spawgi
Hi, Let me understand the problem - Do you want to count the number of times the application was restarted between today and 7 days back? => If yes, then you will need to do some string manipulation to get the required dates. Then you will need to apply both the conditions to the line i.e. if the

[Tutor] get last 7 days string in a log file

2011-08-01 Thread Bjørn-Roar Eriksen
Hi I'm new to Python and I'm trying to write a script that's count restart of an application. The log file contains: 2009-03-06 18:20:26,423 User operation - start nanny 2009-03-06 18:20:26,423 User operation - start all services And 2009-03-06 18:20:26,423 User operation - start all services t

[Tutor] Question about sorting a list within a dictionary within a list

2011-08-01 Thread ian douglas
I'm using the Bono library for talking to EC2, and I'm getting a list of EC2 instances back in a list called "reservations". Each element in the list is a dictionary of information. One of those dictionary elements is a list called 'instances', and I only ever care about the first entry. That i