# HG changeset patch
# User Simon King <king@mathematik.unijena.de>
# Date 1218647623 7200
# Node ID 60427c9065c4427b12f7da4b0b59d7ac94d083db
# Parent 6417e6c84a2a6f4851d87a7702a6257624ec8f13
Bugfix and enhancement for RElement element access
diff r 6417e6c84a2a r 60427c9065c4 sage/interfaces/r.py
a

b


1159  1159  
1160  1160  def __getitem__(self, n): 
1161  1161  """ 
1162   Return nth element of self. 
 1162  Return element(s) of self. 
1163  1163  
1164  1164  INPUT: 
1165   n  an integer 
 1165  n  an integer, a tuple, a string that makes sense to R, or an RElement 
1166  1166  OUTPUT: 
1167  1167  RElement 
1168  1168  
… 
… 

1178  1178  [1] 10.4 3.1 6.4 21.7 
1179  1179  sage: x[3] 
1180  1180  [1] 10.4 5.6 6.4 21.7 
1181   sage: x[4] 
1182   [1] 6.4 
 1181  sage: x['c(2,3)'] 
 1182  [1] 5.6 3.1 
 1183  sage: x[2,3,4] 
 1184  [1] 5.6 3.1 6.4 
 1185  sage: key=r.c(2,3) 
 1186  sage: x[key] 
 1187  [1] 5.6 3.1 
1183  1188  """ 
1184  1189  P = self._check_valid() 
1185  1190  if isinstance(n, basestring): 
1186  1191  n = n.replace('self', self._name) 
1187  1192  return P.new('%s[%s]'%(self._name, n)) 
1188   elif not isinstance(n, tuple): 
 1193  elif (hasattr(n,'parent') and n.parent()==P): # the key is RElement itself 
 1194  return P.new('%s[%s]'%(self._name, n.name())) 
 1195  elif not isinstance(n,tuple): 
1189  1196  return P.new('%s[%s]'%(self._name, n)) 
1190  1197  else: 
1191   return P.new('%s[%s]'%(self._name, str(n)[1:1])) 
 1198  return P.new('%s[c%s]'%(self._name, str(n))) 
1192  1199  
1193  1200  def __nonzero__(self): 
1194  1201  """ 