【发布时间】:2016-01-15 02:38:05
【问题描述】:
基本上,它是来自我们合作者的用于生成网格的python代码,它是在Linux环境下开发的。我使用 Cygwin 在 Windows 上运行此代码。麻烦的部分如下。 BiV_temp.geo 也是一个 python 脚本。所以命令是用预定义的数字和文件名替换脚本 BiV_temp.geo 中的字符串 。
os.system('cp BiV_fiber.geo BiV_temp.geo')
cmd = "sed -i 's/<<Meshsize>>/"+"%5.2f"%(meshsize)+"/g' BiV_temp.geo"
os.system(cmd)
cmd = "sed -i 's/<<LVfilename>>/"+"\"%s\""%(LVendocutfilename)+"/g' BiV_temp.geo"
os.system(cmd)
cmd = "sed -i 's/<<RVfilename>>/"+"\"%s\""%(RVendocutfilename)+"/g' BiV_temp.geo"
os.system(cmd)
cmd = "sed -i 's/<<Epifilename>>/"+"\"%s\""%(epicutfilename)+"/g' BiV_temp.geo"
os.system(cmd)
cmd = "gmsh -3 BiV_temp.geo -o %s"%(mshfilename)
os.system(cmd)
cmd = "rm BiV_temp.geo"
os.system(cmd)
【问题讨论】:
-
您确定这是 Python 回溯,而不是 sed 错误吗?我从未见过这样的错误消息。
-
可能。由于我是 python 和 unix 的新手,所以可能是 sed 错误...
-
@H.Zou 请将您在运行脚本的尝试和随后出现的错误粘贴到您的问题中,以便我们确定。
-
您不知道是哪一行导致了错误(
<<有多行)。您也不提供输入文件供其他人尝试,或者(最好)提供仍然导致您的错误的小输入文件。这使得帮助您变得更加困难。 -
这太疯狂了。如果您的整个程序由 shell 脚本组成,请编写一个 shell 脚本,而不是 Python 包装器,以便为每个 shell 脚本启动一个新的 shell。还要注意
sed是一种脚本语言,所以你可以combine all of thesesedsnippets into one;然后将源文件复制到临时文件并进行内联替换-i不再有意义(如果曾经这样做的话)。