python怎么写多行_python 多行字符串怎么写才能不破坏缩进
有時候需要在python script里拼出個.mel文件,然后讓mayabatch去執(zhí)行
如果多行字符串的定義在function里面,嵌套很深,又希望左側(cè)沒空格,那默認情況下會是這樣
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
只有多行字符串都頂?shù)阶筮吶?#xff0c;寫出去的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把左側(cè)的空格幫你去掉,python里縮進符合規(guī)范,mel里左側(cè)也沒有空格
贊過:
贊 正在加載……
相關(guān)
總結(jié)
以上是生活随笔為你收集整理的python怎么写多行_python 多行字符串怎么写才能不破坏缩进的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springboot map数据类型注入
- 下一篇: python list排序_python