コード例 #1
0
 def test_delslice(self):
     a = range(10)
     self.failUnlessRaises(TypeError, operator.delslice, a)
     self.failUnlessRaises(TypeError, operator.delslice, a, None, None)
     self.failUnless(operator.delslice(a, 2, 8) is None)
     self.assert_(a == [0, 1, 8, 9])
     operator.delslice(a, 0, test_support.MAX_Py_ssize_t)
     self.assert_(a == [])
コード例 #2
0
 def test_delslice(self):
     a = range(10)
     self.assertRaises(TypeError, operator.delslice, a)
     self.assertRaises(TypeError, operator.delslice, a, None, None)
     self.assertTrue(operator.delslice(a, 2, 8) is None)
     self.assertTrue(a == [0, 1, 8, 9])
     operator.delslice(a, 0, test_support.MAX_Py_ssize_t)
     self.assertTrue(a == [])
コード例 #3
0
ファイル: test_operator.py プロジェクト: isaiah/jython3
 def test_delslice(self):
     a = list(range(10))
     self.assertRaises(TypeError, operator.delslice, a)
     self.assertRaises(TypeError, operator.delslice, a, None, None)
     self.assertTrue(operator.delslice(a, 2, 8) is None)
     self.assertTrue(a == [0, 1, 8, 9])
     operator.delslice(a, 0, support.MAX_Py_ssize_t)
     self.assertTrue(a == [])
コード例 #4
0
print(" is ", "abc" is "abc")
print(" is_", op.is_("abc","abc"))
print(" is not ", "abc" is not "abcd")
print(" is_", op.is_not("abc","abcd"))

print(" in ", "a" in "abc")
print(" __contains__", "abc".__contains__('a'))
print(" contains", op.contains("abc",'a'))

print(" in ", "a" not in "abc")
print(" __contains__", not("abc".__contains__('a')))
print(" contains", op.not_(op.contains("abc",'a')))


print(" __getslice__ :", [0,1,2,3].__getslice__(0,2))
print("  getslice    :", op.getslice([0,1,2,3],0,2))
l=[0,1,2,3]
print(" __setslice__ :", l.__setslice__(0,2,[99,99]),l)
print(" __delslice__ :", l.__delslice__(0,2),l)
l=[0,1,2,3]
print("  setslice    :", op.setslice(l,0,2,[99,99]),l)
print("  delslice    :", op.delslice(l,0,2),l)

print(" __getitem__  : ", [0,1,2,3].__getitem__(slice(0,2)))
print(" getitem      : ", op.getitem([0,1,2,3],slice(0,2)))
l=[0,1,2,3]
print(" __setitem__ :", l.__setitem__(slice(0,2),[99,99]),l)
print(" __delitem__ :", l.__delitem__(slice(0,2)),l)
l=[0,1,2,3]
print("  setitem    :", op.setitem(l,slice(0,2),[99,99]),l)
print("  delitem    :", op.delitem(l,slice(0,2)),l)
コード例 #5
0
 def test_delslice(self):
     a = range(10)
     self.failUnless(operator.delslice(a, 2, 8) is None)
     self.assert_(a == [0, 1, 8, 9])
コード例 #6
0
ファイル: cimdb.py プロジェクト: pywbem/cimserver
 def close(self):
     if self.cursors:
         for c in self.cursors:
             c.close(True)
         operator.delslice(self.cursors, 0, len(self.cursors))
     self.conn.close(True)
コード例 #7
0
ファイル: operator_demo.py プロジェクト: sjl421/Python_Lib
print operator.countOf([1, 2, 1, 3, 1], 1)
#set序列可以去重
print operator.countOf(set([1, 2, 1, 3, 1]), 1)

#变量的值 同__index__()
a = 12
print operator.index(a)

#删除字典中的某对数值 同del a[b]
a = {0: "zero", 1: "one", 2: "two"}
operator.delitem(a, 0)
print a

#删除序列中的某片数值 同del a[b:c]
a = [1, 2, 3, 4, 5]
operator.delslice(a, 0, 1)
print a

#取得字典的值 同 a[b]
a = {0: "zero", 1: "one", 2: "two"}
print operator.getitem(a, 0)

#取得序列的片段 同 a[b:c]
a = [1, 2, 3, 4, 5]
print operator.getslice(a, 0, 2)

#设定字典的值 同 a[b]=c
a = {0: "zero", 1: "one", 2: "two"}
operator.setitem(a, 3, "three")
print a
コード例 #8
0
import operator
コード例 #9
0
ファイル: op.py プロジェクト: DjangoBD/django-native-tags
def delslice(a, b, c):
    return operator.delslice(a, b, c)
コード例 #10
0
ファイル: test_operator.py プロジェクト: mcyril/ravel-ftn
import operator
コード例 #11
0
ファイル: ch1134.py プロジェクト: AAQ6291/PYCATCH
# 否定運算
print "not 0 = operator.not_(0) = ", operator.not_(0)

# 右移運算
print "16 >> 1 = operator.rshift(16, 1) = ", operator.rshift(16, 1)

# 連續型態值乘法運算(tuple或list)
print "'-' * 10 = operator.repeat('-', 10) = ", operator.repeat('-', 10)

# 以切片指派值
seq = [1, 2, 3]
seq[2:3] = [4]
print "seq[2:3] = [4] = operator.setslice(seq,2,3,[4]) = ", seq

# 以切片刪除值
operator.delslice(seq, 1, 2)
print "del seq[1:2] = operator.delslice(seq,1,2) = ", seq

# 取得切片值
print "seq[1:2] = operator.getslice(seq,1,2) = ", operator.getslice(seq, 1, 2)

# 餘數運算
print "10 % 3 = operator.mod(10, 3) = ", operator.mod(10, 3)

# 減法運算
print "4 - 2 = operator.sub(4, 2) = ", operator.sub(4, 2)

# 真值運算(True或False)
print "1 == True, 0 == False = operator.truth(1), operator.truth(0) = ", operator.truth(
    1), operator.truth(0)
コード例 #12
0
ファイル: operator_demo.py プロジェクト: windard/Python_Lib
print operator.countOf([1,2,1,3,1],1)
#set序列可以去重
print operator.countOf(set([1,2,1,3,1]),1)

#变量的值 同__index__()
a = 12
print operator.index(a)

#删除字典中的某对数值 同del a[b]
a = {0:"zero",1:"one",2:"two"}
operator.delitem(a,0)
print a

#删除序列中的某片数值 同del a[b:c]
a = [1,2,3,4,5]
operator.delslice(a,0,1)
print a

#取得字典的值 同 a[b]
a = {0:"zero",1:"one",2:"two"}
print operator.getitem(a,0)

#取得序列的片段 同 a[b:c]
a = [1,2,3,4,5]
print operator.getslice(a,0,2)

#设定字典的值 同 a[b]=c
a = {0:"zero",1:"one",2:"two"}
operator.setitem(a,3,"three")
print a
コード例 #13
0
ファイル: operator_demo.py プロジェクト: ilib0x00000000/NULL
c = [1, 'a', None, 10.01, {'key':'value'}]


# 通过下标操作序列
print operator.getitem(c, 4)
print operator.getslice(c, 1, 4)

operator.setitem(c, 2, 9999)
print c
operator.setslice(c, 3,-1, [10,20,30,40,50])
print c

operator.delitem(c, 0)
print c
operator.delslice(c, 2, 7)
print c
# output
# {'key': 'value'}
# ['a', None, 10.01]
# [1, 'a', 9999, 10.01, {'key': 'value'}]
# [1, 'a', 9999, 10, 20, 30, 40, 50, {'key': 'value'}]
# ['a', 9999, 10, 20, 30, 40, 50, {'key': 'value'}]
# ['a', 9999, {'key': 'value'}]


"""
获取对象元素或属性方法:
	1.创建一个回调函数,
	2.将对象传入回调函数
"""
コード例 #14
0
ファイル: test_operator.py プロジェクト: bushuhui/pyKanjiDict
 def test_delslice(self):
     a = range(10)
     self.failUnlessRaises(TypeError, operator.delslice, a)
     self.failUnlessRaises(TypeError, operator.delslice, a, None, None)
     self.failUnless(operator.delslice(a, 2, 8) is None)
     self.assert_(a == [0, 1, 8, 9])
コード例 #15
0
ファイル: test_operator.py プロジェクト: sjb8100/UTM-Demo
 def test_delslice(self):
     a = range(10)
     self.failUnless(operator.delslice(a, 2, 8) is None)
     self.assert_(a == [0, 1, 8, 9])
コード例 #16
0
 def test_delslice(self):
     a = range(10)
     self.assertRaises(TypeError, operator.delslice, a)
     self.assertRaises(TypeError, operator.delslice, a, None, None)
     self.assertTrue(operator.delslice(a, 2, 8) is None)
     self.assertTrue(a == [0, 1, 8, 9])
コード例 #17
0
ファイル: op.py プロジェクト: ovidiuc/django-native-tags
def delslice(a, b, c):
    return operator.delslice(a, b, c)