473,383 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

RE: Unable to lookup keys in dictionary

>I am trying to run p4python API on top of python 2.5.2 and am
extracting a dictionary from perforce. The following code returns the
output that follows it:
>
from P4 import P4, P4Exception
p4 = P4()
p4.port = "erased" #deleted
p4.user = "erased" #deleted

try:
p4.connect()
info = p4.run("info")
print info
p4.disconnect()
except P4Exception:
for e in p4.errors:
print e


Output:


[{'userName': 'mfielding', 'clientRoot': 'c:\\perforce',
'monitor': 'enabled',
> 'serverRoot': 'H:\\p4root\\', 'serverVersion':
'P4D/NTX64/2007.3/143793 (2008/01/
> 21)', 'serverDate': '2008/08/12 11:18:56 -0400 Eastern
Daylight Time', 'clientAd
> dress': '10.24.20.97:1918', 'serverLicense': 'Mad Doc
Software, Inc. 140 users (
> support expired 2008/05/31) ', 'serverAddress':
'rsgnwep4s1.rockstar.t2.corp:166
> 6', 'clientHost': 'nwew-mfielding', 'security':
'enabled', 'password': 'enabled'
> , 'clientName': 'mfielding'}]

I did this to test that I was receiving a dictionary back from
the server, which I clearly am. I then followed by adding the following
lines to the code:
>

print info
s = info[serverVersion]
print s
p4.disconnect()

I would expect this to print out P4D/NTX64/2007.3/143793
(2008/01/23), but instead it spits out the following error:
>

Traceback (most recent call last):
File "test.py", line 10, in <module>
s = info[serverVersion]
NameError: name 'serverVersion' is not defined


Changing "s = info[serverVersion]" to "s =
info['serverVersion']" only gives me another error, which is:
>

Traceback (most recent call last):
File "test.py", line 10, in <module>
s = info['serverVersion']
TypeError: list indices must be integers


If anyone has any idea what is going on here, I would appreciate
the help. I've spent a few hours over the past two days trying to figure
this little quirk out, but to no avail.

It looks like you're getting a list with the dictionary as the only
element.

Try...

s = info[0]['serverVersion']

Cheers,

Drea
Aug 12 '08 #1
0 663

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: M. Clift | last post by:
Hi All, Can someone tell me is there a shorthand version to do this? l1 = Names = {'n1':'Cuthbert','n2' :'Grub','n3' :'Dibble' etc...} for name in l1: print Names,
21
by: Chris S. | last post by:
I have a number of strings, containing wildcards (e.g. 'abc#e#' where # is anything), which I want to match with a test string (e.g 'abcdef'). What would be the best way for me to store my strings...
57
by: Egor Bolonev | last post by:
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements?
8
by: rh0dium | last post by:
Hi all, I have a dict which looks like this.. dict={'130nm': {'umc': }, '180nm': {'chartered': , 'tsmc': }, '250nm': {'umc': , 'tsmc': } }
14
by: vatamane | last post by:
This has been bothering me for a while. Just want to find out if it just me or perhaps others have thought of this too: Why shouldn't the keyset of a dictionary be represented as a set instead of a...
11
by: John | last post by:
I am coding a radix sort in python and I think that Python's dictionary may be a choice for bucket. The only problem is that dictionary is a mapping without order. But I just found that if the...
2
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have a class that inherits from Generics Dictionary The string that is used for the key is passed thru-out my pgm and sometimes it has modifiers added to the key string that are used in the...
2
by: Andy B | last post by:
I have the following listView control on a page: <asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="PlaceHolder1"> <ItemTemplate> <dl> <dt>
0
by: Jerry Hill | last post by:
On Tue, Aug 12, 2008 at 11:27 AM, Matt Fielding (R* New England) <Matt.Fielding@rockstarnewengland.comwrote: That's not a dictionary. Try adding print type(info) and you'll see that what you...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.