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:
 

        from P4 import P4, P4Exception
        p4 = P4()
        p4.port = "rsgnwep4s1:1666"
        p4.user = "mfielding"
         
        try:
           p4.connect()
           info = p4.run("info")
           info = info[0]
           print info
           s = info['serverVersion']
           print s
           p4.disconnect()
        except P4Exception:
           for e in p4.errors:
             print e
         

 
Matt Fielding
IT Technician
Rockstar New England
 

________________________________

From:
[EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
org] On Behalf Of Matt Fielding (R* New England)
Sent: Tuesday, August 12, 2008 11:27 AM
To: python-list@python.org
Subject: 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.
 
Matt Fielding
IT Technician
Rockstar New England
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to