我不知道这为什么会引起AttributeError,但在文件中,这似乎是正确的https://www.perforce.com/manuals/p4python/Content/P4Python/python.p4_progress.html
from P4 import P4, P4Exception, Progress
from tqdm import tqdm
class P4ProgressHandler(Progress):
TYPES = ["Unknown", "Submit", "Sync", "Clone"]
pbar = None
def init(self, type):
super().init(type)
if self.pbar is not None:
self.pbar.close()
self.pbar = tqdm(desc="P4 Progress: {}".format(self.TYPES[type]))
def setDescription(self, description, units):
super().setDescription(description, units)
def setTotal(self, total):
super().setTotal(total)
self.pbar.total = total
def update(self, position):
super().update(position)
if self.pbar is not None:
self.pbar.update(position)
def done(self, fail):
super().done(fail)
if self.pbar is not None:
self.pbar.close()
p4 = P4()
p4.using_progress(P4ProgressHandler()) Python版本: 3.10.0
P4Python版本: P4PYTHON/"NTX64"/"2022.1"/"2299330“("2022.1/2285021”API) ("2022"/"06"/"14")。
错误输出:
Traceback (most recent call last):
File "E:\ForgeCI\ForgeCI\Utils\P4Methods.py", line 37, in <module>
p4.using_progress(P4ProgressHandler())
File "E:\ForgeCI\venv\lib\site-packages\P4.py", line 517, in __getattr__
raise AttributeError(name)
AttributeError: using_progress发布于 2022-07-21 05:14:24
根据P4类的文档,没有using_progress方法:
https://www.perforce.com/manuals/p4python/Content/P4Python/python.p4.html#Instance_Methods_..39
在此与AttributeError之间,我认为可以安全地假定,文档中提到Progress类的P4.using_progress是文档中的一个错误。由于progress是P4的一个属性,所以您应该能够替换:
p4.using_progress(P4ProgressHandler()) 通过以下方式:
p4.progress = P4ProgressHandler()https://stackoverflow.com/questions/73060475
复制相似问题