python Python片段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python片段相关的知识,希望对你有一定的参考价值。
### how to get python execuation time
start = timer()
# the opeartion you wanna measure
for x in range (80000000)
a = math.sin(math.cos(math.sin(x)))
end timer ()
print ("Time Elapsed:", end - start)
#How to bypass:
op('OPNAME').bypass = True
op('OPNAME').bypass = False
#Cooking flag:
op('OPNAME').allowCooking = True
op('OPNAME').allowCooking = False
#liscence class
# Nice printing
print('------------------------')
print(str(me.path) + " :" + "Running EmailScript")
print('------------------------')
# Run script
a = op('populateTable')
a.run()
#run function on another dat:
dat op name = my_dataconvert
run functions:
import my_dataconvert
my_dataconvert.functionName()
#DAT
#Databse Container obj.
db = op('database')
db.clear()
#my list needs to be str
my list = ('1','2','3')
mylist = user_data.row(1)
db.appendRow(mylist)
#clear the db
db.clear()
# Error checking status ops.
warning = op('tcpip1').warning
error = op('tcpip1').error
if warning != '' or error != '':
print('disconnected')
else:
print('connected')
# fectch values of cell in a row as a list. ( double list manipulation)
[ [cell.val for cell in row] for row in op('/path/to/table').rows()]
[float(cell.val) for cell in op('/path/to/table').row(0)]
#Conditional "if" in one line of a parameter
22 if me.time.frame<100 else 33
or
[33,22][me.time.frame<100]
#Neat pulse option
op('poll_Timer').par.start.pulse(1,frames=5)
##Center a bunch of nodes.
p = me.parent()
p.create(switchCHOP, 'switch')
op('switch').nodeX = 2400
op('switch').nodeY = 200
for i in range (0, 100) :
n = p.create(constantCHOP,'c'+str(i+1))
n.nodeX = math.floor(i/10) * 200
n.nodeY = (i%10) * -200
n.outputConnectors[0].connect(op('switch'))
if pollEnable == True & (numberOfPorts != 0) & (isConnectedVal == True):
#Yeah love list comps, for getting a column or row of a table as a list of strings though this is another way you can use:
list( map( str , SomeOp.col(0) ) )
Can also use map in td like this if you want to run each cell through a more complex function that lives in another text dat
list( map( mod(someOtherOp).someFunction() , SomeOp.col(0) ) )
[for x in map(str, SomeOp.col(0) ) if x == 1 ]
Also works for doing light logic on the result of map()
#setAttr:
movie = 'moviefilein2'
mypar = 'speed'
myVal = 0.47
setattr(op(movie).par,mypar,myVal)
check getattr and copyattr :)
#fancy way of errors:
try:
op('myTable')[0,0] = 3
except:
op('myTable').appendRow([3])
#Create a multi case test
1 in [op('table1')[0,0], op('table1')[0,1], op('table1')[0,2] ]
this return true if 1 occors in the list of table cell values
以上是关于python Python片段的主要内容,如果未能解决你的问题,请参考以下文章