私はコードをもっとコンパクトにしようとしています。きれいに減らすことができる部分があるとは思いますが、それをどうやって行うかはわかりません。私は速くそれを見つけるためにあなたのために下にコピーされたコードの中にコメントを入れました。このpython関数を合成する方法
コードは、次のいずれかです。
def change_to_mop_gen(infile, namedir="",charge=0, gnorm=None, separate=True, hamiltonian="PM6", calctype="opt", multiplicity="singlet", eps=None, cycles=None):
#armado de la salida
if calctype=="thermo(298,298,0)":
calctype1="thermo"
else:
calctype1=calctype
outfile=infile.split(".")[0] + "-" + calctype1 + "-" + hamiltonian
#~ here comes the set of if/else sentences i think could be reduced
if gnorm !=None:
gnorm="gnorm=" + str(gnorm)
else:
gnorm= " "
if cycles!=None:
cycles="cycles="+str(cycles)
else:
cycles=""
if separate==True:
outfile=outfile + "_*.mop"
else:
outfile=outfile + ".mop"
if eps !=None:
eps="eps=" + str(eps)
else:
eps = ""
#~here it ends
keywords = "-xk '%s %s %s %s %s %s charge=%i'"%(cycles, hamiltonian, calctype, multiplicity, eps, gnorm, charge)
#change directory of outfile
if namedir!="":
outfile= namedir + "/" + outfile
return change_format(infile,outfile, keywords)
すべてのヘルプは良いでしょう。
私はあなたがtex.stackexchangeではなく、stackoverflowになりたいと思います。また、 '' gnormがNoneであれば ''なし ''を使用してください。 – percusse
'' gnorm = "" gnormがNoneならば "gnorm =" + str(gnorm) ' – percusse
@percusseはい、ごめんなさい – HernanProust