close

最近要練習寫python,

因為nuke、houdini、realflow、maya等軟體都支援python,
所以才萌生學寫python的念頭,
要寫python有幾個預備步驟,
去python官網抓IDLE來寫或上網找一些支援python的IDE,
但是如果有灌NUKE或Houdini的朋友就方便辣,
首推nuke,
30608820-2011-08-19_110737  
開啟script就可以開始寫了,
30608819-2011-08-19_121842  
選取寫好的script再ctrl+ent就會看到結果了,
ctrl+backspace(退後鍵) 可以快速清除結果,

 

至於houdini,
也是一樣開一個script pane
30608822-2011-08-19_122500  
Houdini  叫作python shell
30608821-2011-08-19_122545  

 

一些簡單的觀念,
Do not use backtick  `(不要用~這個鍵的`)
use double quotes " (用雙引)
use single quotes ' (用單引)
ex:
print 'alex is starting to learn \"python\"' 

 

# Result:

alex is starting to learn "python"

 

不能用數字或$當變數的開頭

 

 

非常簡單小事身手區

 

再nuke中建立node
nuke.createNode('Blur')
# Result:

<Blur1 at 0x00000000054BD850>

 

 

連續建立node
for i in range(1,100):
    nuke.createNode('Blur')
就會建立100個blur node

 

 

顯示type
varalex = 5
print type(varalex)

# Result:

<type 'int'>

 

 

myvar = 1
myvar += 1
意思就是
myvar = myvar +1

 

 

取正數
varalex = -5
print abs(varalex)

# Result:

5

 

質相加
mystring = 'alex'
mystring += ' hello'

print mystring

# Result:

alex hello

 

取質

mystring = 'alex'
mystring += ' hello'

 

print mystring[0]

# Result:

a

print mystring[2:-1]
# Result:

ex hell

 

變大寫

mystring = 'ALEX'
mystring += ' hello'

 

print mystring.upper()

# Result:

ALEX HELLO

print mystring.upper()[2:-1]
# Result:

EX HELL

 

變小寫

mystring = 'ALEX'
mystring += ' hello'

 

print mystring.lower()

# Result:

alex hello
print mystring.lower()[2:-1]
# Result:

ex hell

 

說明幫助

help(*****) ***填上要說明的物件

ex:

help(nuke)

help(str)

 

分段

varalex = 'today is a good day to learn python'
print varalex.split(' ')

# Result:

['today', 'is', 'a', 'good', 'day', 'to', 'learn', 'python']

 

mystring = 'ALEX'
mystring += ' hello'

vralex = mystring.lower()[2:-1]

print vralex.split(' ')

# Result:

['ex', 'hell']

 

split(填入判別的字元)

 

檢查開始字元

mystring = 'ALEX'
mystring += ' hello'

vralex = mystring.lower()[2:-1]

print vralex.startswith('e')

# Result:

True

 

檢查最後的字元

mystring = 'ALEX'
mystring += ' hello'

vralex = mystring.lower()[2:-1]

print vralex.endswith('ell')

# Result:

True

arrow
arrow
    文章標籤
    python tutor
    全站熱搜

    A咖來D賽 發表在 痞客邦 留言(0) 人氣()