extracting a dictionary from perforce. The following code returns the
output that follows it:
>'monitor': 'enabled',
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',
> 'serverRoot': 'H:\\p4root\\', 'serverVersion':'P4D/NTX64/2007.3/143793 (2008/01/
> 21)', 'serverDate': '2008/08/12 11:18:56 -0400 EasternDaylight Time', 'clientAd
> dress': '10.24.20.97:1918', 'serverLicense': 'Mad DocSoftware, Inc. 140 users (
> support expired 2008/05/31) ', 'serverAddress':'rsgnwep4s1.rockstar.t2.corp:166
> 6', 'clientHost': 'nwew-mfielding', 'security':'enabled', 'password': 'enabled'
> , 'clientName': 'mfielding'}]the server, which I clearly am. I then followed by adding the following
I did this to test that I was receiving a dictionary back from
lines to the code:
>(2008/01/23), but instead it spits out the following error:
print info
s = info[serverVersion]
print s
p4.disconnect()
I would expect this to print out P4D/NTX64/2007.3/143793
>info['serverVersion']" only gives me another error, which is:
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 =
>the help. I've spent a few hours over the past two days trying to figure
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
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