abaqus的python安装⽂件在哪_python、abaqus执⾏脚本路径python中获取执⾏脚本路径⽅法
1、sys.path[0]:获取执⾏脚本⽬录绝对路径
#每次执⾏脚本时,python会将执⾏脚本⽬录加⼊PYTHONPATH环境变量中(sys.path获取)
#!/usr/bin/python3
import os
import sys
print(sys.path)
print(sys.path[0])
执⾏结果:
[root@localhost tmp]# ./py_test1/pytest24.py
['/tmp/py_test1', '/usr/local/lib/python36.zip', '/usr/local/lib/python3.6', '/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages/pip-9.0.']
/tmp/py_test1
2、sys.argv[0]:获取脚本执⾏本⾝路径;
#!/usr/bin/python3
import os
import sys
python默认安装路径print(sys.argv[0])
执⾏1结果:
[root@localhost tmp]# ./py_test1/pytest24.py   #相对路径执⾏脚本则会返回相对路径
./py_test1/pytest24.py
执⾏2结果:
[root@localhost tmp]# /tmp/py_test1/pytest24.py #绝对路径执⾏脚本则返回绝对路径
/tmp/py_test1/pytest24.py
注:sys.argv[0]获取得不是脚本⽬录路径,⽽是脚本本⾝执⾏时的路径!
3、__file__:同sys.argv[0]相似,获取脚本执⾏本⾝路径:
#!/usr/bin/python3
import os
import sys
print("sys.argv[0] Output:",sys.argv[0])
print("__file Output:",__file__)
执⾏1结果:
[root@localhost tmp]# ./py_test1/pytest24.py #相对路径执⾏脚本则会返回相对路径
sys.argv[0] Output: ./py_test1/pytest24.py
__file Output: ./py_test1/pytest24.p
执⾏2结果:
[root@localhost tmp]# /tmp/py_test1/pytest24.py #绝对路径执⾏脚本则会返回绝对路径sys.argv[0] Output: /tmp/py_test1/pytest24.py
__file Output: /tmp/py_test1/pytest24.py
注:__file__获取得不是脚本⽬录路径,⽽是脚本本⾝执⾏时的路径!
4、os.path.abspath(__file__)和alpath(__file__):获取脚本执⾏本⾝的绝对路径
通过获取__file__路径,然后转换成绝对路径
#!/usr/bin/python3
import os
import sys
print("__file Output:",__file__)
print(os.path.abspath(__file__))
print(alpath(__file__))
执⾏结果:
[root@localhost tmp]# ./py_test1/pytest24.py
__file Output: ./py_test1/pytest24.py
/tmp/py_test1/pytest24.py
/tmp/py_test1/pytest24.py
注:os.path.abspath(__file__)和alpath(__file__)获取得是脚本本⾝的绝对路径!------------------------------------------------------
ABAQUS与执⾏脚本路径
ABAQUS cae script=xxx.py 命令下
1、sys.path[0],;
2、sys.argv[0],cae执⾏⽂件路径;
3、sys.argv[5],⼯作路径;
4、os.getcwd(),同3⼯作路径;
5、os.path.abspath(__file__),出错;
难以获取py⽂件路径
ABAQUS cae script=xxx.py 命令下
1、sys.argv[3],py⽂件路径;
待补充

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。