<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16674" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=785144815-12082008><FONT face=Arial size=2>I 
actually figured out the solution to my problem, of all times, right 
after I finished sending this mail. It seems P4Python returns a command as 
a dictionary, also inside of an array. The solution is in the following 
code:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=785144815-12082008><FONT face=Arial 
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV><FONT face=Courier size=2>from P4 import P4, P4Exception<BR>p4 = 
  P4()<BR>p4.port = "rsgnwep4s1:1666"<BR>p4.user = "mfielding"</FONT></DIV>
  <DIV><FONT face=Courier></FONT> </DIV>
  <DIV><FONT face=Courier size=2>try:<BR><SPAN class=785144815-12082008>  
  </SPAN> p4.connect()<BR> <SPAN class=785144815-12082008>  
  </SPAN>info = p4.run("info")<BR> <SPAN class=785144815-12082008>  
  </SPAN>info = info[0]<BR> <SPAN class=785144815-12082008>  
  </SPAN>print info<BR><SPAN class=785144815-12082008>  </SPAN> s = 
  info['serverVersion']<BR> <SPAN class=785144815-12082008>  
  </SPAN>print s<BR> <SPAN class=785144815-12082008>  
  </SPAN>p4.disconnect()<BR>except P4Exception:<BR> <SPAN 
  class=785144815-12082008>  </SPAN>for e in 
  p4.errors:<BR>  <SPAN class=785144815-12082008>   
  </SPAN>print e</FONT></DIV>
  <DIV dir=ltr align=left><SPAN class=785144815-12082008><FONT face=Arial 
  size=2></FONT></SPAN> </DIV></BLOCKQUOTE>
<DIV> </DIV>
<DIV align=left><FONT face=Arial size=2>Matt Fielding</FONT></DIV>
<DIV align=left><EM><FONT face=Arial size=2>IT Technician</FONT></EM></DIV>
<DIV align=left><STRONG><FONT face=Arial size=2>Rockstar New 
England</FONT></STRONG></DIV>
<DIV> </DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> 
python-list-bounces+matt.fielding=rockstarnewengland.com@python.org 
[mailto:python-list-bounces+matt.fielding=rockstarnewengland.com@python.org] 
<B>On Behalf Of </B>Matt Fielding (R* New England)<BR><B>Sent:</B> Tuesday, 
August 12, 2008 11:27 AM<BR><B>To:</B> python-list@python.org<BR><B>Subject:</B> 
Unable to lookup keys in dictionary<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><SPAN class=343501615-12082008><FONT face=Arial size=2>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:</FONT></SPAN></DIV>
<DIV><SPAN class=343501615-12082008><FONT face=Arial 
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV><SPAN class=343501615-12082008><FONT face=Courier size=2>from P4 import 
  P4, P4Exception<BR>p4 = P4()<BR>p4.port = "erased"   
  #deleted<BR>p4.user = "erased"   #deleted</FONT></SPAN></DIV>
  <DIV><FONT face=Courier></FONT> </DIV>
  <DIV><SPAN class=343501615-12082008><FONT face=Courier 
  size=2>try:<BR>   p4.connect()<BR>   info = 
  p4.run("info")<BR>   print info<BR>   
  p4.disconnect()<BR>except P4Exception:<BR>   for e in 
  p4.errors:<BR>     print e</FONT></SPAN></DIV>
  <DIV><SPAN class=343501615-12082008><FONT face=Arial 
  size=2></FONT></SPAN> </DIV></BLOCKQUOTE>
<DIV dir=ltr><SPAN class=343501615-12082008><FONT face=Arial 
size=2>Output:</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV><SPAN class=343501615-12082008><FONT face=Arial 
  size=2></FONT></SPAN> </DIV>
  <DIV><SPAN class=343501615-12082008><FONT face=Arial size=2>[{'userName': 
  'mfielding', 'clientRoot': 'c:\\perforce', 'monitor': 'enabled', 
  </FONT></SPAN></DIV>
  <DIV><SPAN class=343501615-12082008><FONT face=Arial size=2>'serverRoot': 
  'H:\\p4root\\', 'serverVersion': 'P4D/NTX64/2007.3/143793 (2008/01/<BR>21)', 
  'serverDate': '2008/08/12 11:18:56 -0400 Eastern Daylight Time', 
  'clientAd<BR>dress': '10.24.20.97:1918', 'serverLicense': 'Mad Doc Software, 
  Inc. 140 users (<BR>support expired 2008/05/31) ', 'serverAddress': 
  'rsgnwep4s1.rockstar.t2.corp:166<BR>6', 'clientHost': 'nwew-mfielding', 
  'security': 'enabled', 'password': 'enabled'<BR>, 'clientName': 
  'mfielding'}]</FONT></SPAN></DIV></BLOCKQUOTE>
<DIV><SPAN class=343501615-12082008><FONT face=Arial size=2>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:</FONT></SPAN></DIV>
<DIV><SPAN class=343501615-12082008><FONT face=Arial 
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV><SPAN class=343501615-12082008><FONT face=Courier size=2>print 
  info</FONT></SPAN></DIV>
  <DIV><SPAN class=343501615-12082008><FONT face=Courier size=2><STRONG>s = 
  info[serverVersion]</STRONG></FONT></SPAN></DIV>
  <DIV><SPAN class=343501615-12082008><FONT face=Courier size=2><STRONG>print 
  s</STRONG></FONT></SPAN></DIV>
  <DIV><SPAN class=343501615-12082008><FONT face=Courier 
  size=2>p4.disconnect()</FONT></SPAN></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial size=2><SPAN class=343501615-12082008>I would 
expect this to print out P4D/NTX64/2007.3/143793 (2008/01/23), but instead it 
spits out the following error:</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2><SPAN 
class=343501615-12082008></SPAN></FONT> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV dir=ltr><FONT face=Arial size=2><SPAN class=343501615-12082008>Traceback 
  (most recent call last):<BR>  File "test.py", line 10, in 
  <module><BR>    s = info[serverVersion]<BR>NameError: 
  name 'serverVersion' is not defined</SPAN></FONT></DIV>
  <DIV dir=ltr><FONT face=Arial size=2><SPAN 
  class=343501615-12082008></SPAN></FONT> </DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial size=2><SPAN class=343501615-12082008>Changing "s 
= info[serverVersion]" to "s = info['serverVersion']" only gives me another 
error, which is:</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2><SPAN 
class=343501615-12082008></SPAN></FONT> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV dir=ltr><FONT face=Arial size=2><SPAN class=343501615-12082008>Traceback 
  (most recent call last):<BR>  File "test.py", line 10, in 
  <module><BR>    s = info['serverVersion']<BR>TypeError: 
  list indices must be integers</SPAN></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial size=2><SPAN 
class=343501615-12082008></SPAN></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2><SPAN class=343501615-12082008>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.</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2><SPAN 
class=343501615-12082008></SPAN></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2><SPAN class=343501615-12082008>Matt 
Fielding</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2><SPAN class=343501615-12082008><EM>IT 
Technician</EM></SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2><SPAN 
class=343501615-12082008><STRONG>Rockstar New 
England</STRONG></SPAN></FONT></DIV></BODY></HTML>