我正在尝试访问网络扫描仪以通过此代码扫描文档。这是我正在使用的库和代码
import sane
sane.init()
class saneScanner(object):
def __init__(self, URI):
self.URI = URI
def __enter__(self):
self.dev = sane.open(self.URI)
return self.dev
def __exit__(self, exception_type, exception_value, traceback):
self.dev.close()
print(exception_type, exception_value, traceback)
def t():
with saneScanner("airscan:HP OfficeJet Pro 8020 series [973B68]") as k:
return k.opt
print(t())
我最终遇到了这个错误
Traceback (most recent call last):
File "with.py", line 23, in <module>
print(t())
File "/usr/local/lib/python3.7/dist-packages/sane.py", line 86, in __repr__
curValue = repr(getattr(self.scanDev, self.py_name))
File "/usr/local/lib/python3.7/dist-packages/sane.py", line 232, in __getattr__
return d['dev'].get_option(opt.index)
_sane.error: SaneDev object is closed
如果从函数 t() 中删除 return 语句,则不会引发错误。你能告诉我哪里出错了吗
提前致谢