>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:
'monitor': 'enabled',
'P4D/NTX64/2007.3/143793 (2008/01/
Daylight Time', 'clientAd
Software, Inc. 140 users (
'rsgnwep4s1.roc kstar.t2.corp:1 66
'enabled', 'password': 'enabled'
the server, which I clearly am. I then followed by adding the following
lines to the code:
(2008/01/23), but instead it spits out the following error:
info['serverVersion']" only gives me another error, which is:
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
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',
> 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' :
> 21)', 'serverDate': '2008/08/12 11:18:56 -0400 Eastern
> dress': '10.24.20.97:19 18', 'serverLicense' : 'Mad Doc
> support expired 2008/05/31) ', 'serverAddress' :
> 6', 'clientHost': 'nwew-mfielding', 'security':
> , 'clientName': 'mfielding'}]
>
> I did this to test that I was receiving a dictionary back from
>
> I did this to test that I was receiving a dictionary back from
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
>
> print info
> s = info[serverVersion]
> print s
> p4.disconnect()
>
> I would expect this to print out P4D/NTX64/2007.3/143793
>
>
> 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 =
>
> 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 =
>
>
> 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
>
> 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