日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 操作oracle 执行脚本_python、abaqus执行脚本路径

發布時間:2024/1/23 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 操作oracle 执行脚本_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.1-py3.6.egg'] /tmp/py_test1

2、sys.argv[0]:獲取腳本執行本身路徑;

#!/usr/bin/python3 import os import sys 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__)和os.path.realpath(__file__):獲取腳本執行本身的絕對路徑

  通過獲取__file__路徑,然后轉換成絕對路徑

#!/usr/bin/python3import os import sysprint("__file Output:",__file__) print(os.path.abspath(__file__)) print(os.path.realpath(__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__)和os.path.realpath(__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文件路徑;

待補充

總結

以上是生活随笔為你收集整理的python 操作oracle 执行脚本_python、abaqus执行脚本路径的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。