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

歡迎訪問 生活随笔!

生活随笔

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

python

runfile python_python文件执行路径问题

發(fā)布時間:2025/3/21 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 runfile python_python文件执行路径问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

python往相對路徑中寫日志,單獨運行該問題,沒問題,但是通過其他程序運行該python文件就會報錯寫日志的py文件:defwriteFileName(self,logtext):nowTime=str(time.strftime("%Y%m%d...

python往相對路徑中寫日志,單獨運行該問題,沒問題,但是通過其他程序運行該python文件就會報錯

寫日志的py文件:

def writeFileName(self,logtext):

nowTime =str(time.strftime("%Y%m%d",time.localtime(time.time())))

timeForWrite = str(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())))

fileName = "..\log\\result.txt"

if os.path.exists(fileName):

f = open(fileName,'a+')

f.write(logtext.decode("utf-8").encode("GBK"))

f.close()

else:

f = open(fileName,'w')

f.write(logtext.decode("utf-8").encode("GBK"))

f.close()

通過命令行運行報錯:

C:\Users\wanglongjun>python D:\software\python\PyProject\robotization\pythonFile

\runfile\test1.py

Traceback (most recent call last):

File "D:\software\python\PyProject\robotization\pythonFile\runfile\test1.py",

line 21, in

write.writeFileName("test2,2016-08-10 17:29:19,failse,time is out"+"\n")

File "D:\software\python\PyProject\robotization\pythonFile\runfile\test1.py",

line 16, in writeFileName

f = open(fileName,'w')

IOError: [Errno 2] No such file or directory: '..\\log\\result.txt'

在其他python文件中執(zhí)行該文件也報錯:

File "./runfile/test1.py", line 21, in

write.writeFileName("test2,2016-08-10 17:29:19,failse,time is out"+"\n")

File "./runfile/test1.py", line 16, in writeFileName

f = open(fileName,'w')

IOError: [Errno 2] No such file or directory: '..\\log\\result.txt'

跪求各位大神幫忙看看需要如何解決這種情況,跪謝

展開

總結(jié)

以上是生活随笔為你收集整理的runfile python_python文件执行路径问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。