python怎么写多行_python 多行字符串怎么写才能不破坏缩进
有時候需要在python script里拼出個.mel文件,然后讓mayabatch去執行
如果多行字符串的定義在function里面,嵌套很深,又希望左側沒空格,那默認情況下會是這樣
def fuckme(fuck=True):
...
if fuck:
fixCmd = '''\n
if ($doFix){
print "Calling fuckme.bakeInChar() becauase xxx is in scene\\n";
python("fuckme.bakeInChar()");
file -f -save -defaultExtensions 0 -type "mayaAscii";
}
'''
...
# write the fixCmd strip to a .mel file
只有多行字符串都頂到左邊去,寫出去的mel文件左邊才不會是空格,但是這樣寫python里的縮進不好看,所以可以如下操作
import textwrap
def fuckme(fuck=True):
...
if fuck:
fixCmd = '''\n
if ($doFix){
print "Calling fuckme.bakeInChar() becauase xxx is in scene\\n";
python("fuckme.bakeInChar()");
file -f -save -defaultExtensions 0 -type "mayaAscii";
}
'''
fixCmd = textwrap.dedent(fixCmd)
...
# write the fixCmd strip to a .mel file
這樣的話,textwrap module把左側的空格幫你去掉,python里縮進符合規范,mel里左側也沒有空格
贊過:
贊 正在加載……
相關
總結
以上是生活随笔為你收集整理的python怎么写多行_python 多行字符串怎么写才能不破坏缩进的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springboot map数据类型注入
- 下一篇: websocket python爬虫_p