python class method __del__ with xlsxwriter.workbook.close() - python

class house_crawl():
def __init__(self):
self.row=0
self.workbook = xlsxwriter.Workbook(self.getdesktoppath() + '\\house_price.xlsx')
self.worksheet1 = self.workbook.add_worksheet()
self.worksheet1.write_row(self.row,0,['address','describe1','describle2','price','avg_price'])
self.row+=1
def __call__(self, url):
self.page_crawl(url)
def __del__(self):
self.workbook.close()
def page_crawl(self,url):
page=requests.get(url)
tree=html.fromstring(page.text)
for house in tree.xpath('//*[#class="house-item clearfix"]'):
address=house.xpath('div[1]/p[3]/text()')[0]
address=re.sub('\r|\n| ','',address)
#print(address)浦东-潍坊崂山路571弄(旧址崂山东路571弄)
d1=[]
for i in house.xpath('div[1]/p[1]/child::*'):
d1.append(i.xpath('text()')[0])
st=','
d1=st.join(d1)
# print(d1)东欣高层,3室1厅,70平
d2=house.xpath('div[1]/p[2]/text()')
stringt=','
d2=stringt.join(d2)
d2 = re.sub('\r|\n| ','',d2)
#print(d2)南,中层,中装,1991年
price=house.xpath('div[2]/p[1]/text()')[0]
#print(price)580万
avg_price=house.xpath('div[2]/p[2]/text()')[0]
if '元/平' not in avg_price:
avg_price = house.xpath('div[2]/p[3]/text()')[0]
#print(avg_price)83400元/平
self.worksheet1.write_row(self.row, 0, [address,d1,d2,price,avg_price])
self.row+=1
def getdesktoppath(self):
return os.path.join(os.path.expanduser("~"), 'Desktop')
he exception thrown is:
Exception ignored in: <bound method house_crawl.__del__ of <__main__.house_crawl object at 0x000001A14533B940>>
Traceback (most recent call last):
File "D:/pythoncode/crawl/house.py", line 15, in __del__
File "C:\Anaconda3\lib\site-packages\xlsxwriter\workbook.py", line 311, in close
File "C:\Anaconda3\lib\site-packages\xlsxwriter\workbook.py", line 619, in _store_workbook
File "C:\Anaconda3\lib\site-packages\xlsxwriter\packager.py", line 131, in _create_package
File "C:\Anaconda3\lib\site-packages\xlsxwriter\packager.py", line 188, in _write_worksheet_files
File "C:\Anaconda3\lib\site-packages\xlsxwriter\xmlwriter.py", line 41, in _set_xml_writer
File "C:\Anaconda3\lib\codecs.py", line 895, in open
AttributeError: module 'builtins' has no attribute 'open'
It says the 'self.workbook.close()' in del is wrong.
I don't understand.......
please help me !

2022-07-06 20:02:33
2022-07-06 20:02:33 Traceback (most recent call last):
2022-07-06 20:02:33 File "/usr/lib/python3.8/encodings/__init__.py", line 31, in <module>
2022-07-06 20:02:33 File "/var/www/codecs.py", line 14, in <module>
2022-07-06 20:02:33 AttributeError
2022-07-06 20:02:33 :
2022-07-06 20:02:33 module 'builtins' has no attribute 'open'
2022-07-06 20:02:33

Related

How can I fix this Qo-DL-Reborn error i tried reinstalling python and the error continues?

Traceback (most recent call last):
File "F:\GAMES-MOVIE-VIDEO-MUSIC COLLECTION [OPTICAL-DIGITAL]\DIGITAL COPIES\QOBUZ MUSIC\Qo-DL-Reborn\qo-dl_reborn.py", line 21, in
client = qopy.Client()
File "F:\GAMES-MOVIE-VIDEO-MUSIC COLLECTION [OPTICAL-DIGITAL]\DIGITAL COPIES\QOBUZ MUSIC\Qo-DL-Reborn\qopy\qopy.py", line 16, in init
self.id, self.sec = self.cfg_setup(False)
File "F:\GAMES-MOVIE-VIDEO-MUSIC COLLECTION [OPTICAL-DIGITAL]\DIGITAL COPIES\QOBUZ MUSIC\Qo-DL-Reborn\qopy\qopy.py", line 163, in cfg_setup
id = spoofer.get_app_id()
File "F:\GAMES-MOVIE-VIDEO-MUSIC COLLECTION [OPTICAL-DIGITAL]\DIGITAL COPIES\QOBUZ MUSIC\Qo-DL-Reborn\spoofbuz.py", line 20, in get_app_id
return re.search(self.appId_regex, self.bundle).group("app_id")
AttributeError: 'NoneType' object has no attribute 'group'

Multiple errors when running example pyqtgraph program (mainly sip type errors)

I have been trying to make some graphs in pyqt5 that can update more quickly and efficiently than my currently embedded matplotlib ones.
I keep running into the same problem whenever I run any example code including pyqtgraph, which always throw the following error:
"TypeError: isdeleted() argument 1 must be sip.simplewrapper, not PlotWidget"
Environment:
Spyder 3.3.2 Python 3.7.1 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10.
After running pip freeze I learned my versions are numpy==1.20.1, PyQt5==5.15.2, PyQt5-sip==12.8.1, pyqtgraph==0.11.1
I'm using a very simple test graph from a turial (Link).
from PyQt5 import QtWidgets
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
import sys # We need sys so that we can pass argv to QApplication
import os
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.graphWidget = pg.PlotWidget()
self.setCentralWidget(self.graphWidget)
hour = [1,2,3,4,5,6,7,8,9,10]
temperature = [30,32,34,32,33,31,29,32,35,45]
# plot data: x, y values
self.graphWidget.plot(hour, temperature)
def main():
app = QtWidgets.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
The code which causes the error most recent in traceback is in "Qt.py", in the following code:
# Common to PyQt4 and 5
if QT_LIB in [PYQT4, PYQT5]:
QtVersion = QtCore.QT_VERSION_STR
try:
from PyQt5 import sip
except ImportError:
import sip
def isQObjectAlive(obj):
return not sip.isdeleted(obj)
loadUiType = uic.loadUiType
QtCore.Signal = QtCore.pyqtSignal
The full traceback is much longer, and is as follows:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 40, in itemChange
ret = sip.cast(ret, QtGui.QGraphicsItem)
TypeError: cast() argument 1 must be sip.simplewrapper, not PlotItem
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 438, in resizeEvent
self.updateAutoRange()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 890, in updateAutoRange
childRange = self.childrenBounds(frac=fractionVisible)
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 1355, in childrenBounds
px, py = [v.length() if v is not None else 0 for v in self.childGroup.pixelVectors()]
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 189, in pixelVectors
dt = self.deviceTransform()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 108, in deviceTransform
view = self.getViewWidget()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 65, in getViewWidget
if v is not None and not isQObjectAlive(v):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\Qt.py", line 328, in isQObjectAlive
return not sip.isdeleted(obj)
TypeError: isdeleted() argument 1 must be sip.simplewrapper, not PlotWidget
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 40, in itemChange
ret = sip.cast(ret, QtGui.QGraphicsItem)
TypeError: cast() argument 1 must be sip.simplewrapper, not PlotDataItem
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 40, in itemChange
ret = sip.cast(ret, QtGui.QGraphicsItem)
TypeError: cast() argument 1 must be sip.simplewrapper, not PlotDataItem
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 26, in itemChange
self.parentChanged()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 463, in parentChanged
self._updateView()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 480, in _updateView
view = self.getViewBox()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 88, in getViewBox
vb = self.getViewWidget()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 65, in getViewWidget
if v is not None and not isQObjectAlive(v):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\Qt.py", line 328, in isQObjectAlive
return not sip.isdeleted(obj)
TypeError: isdeleted() argument 1 must be sip.simplewrapper, not PlotWidget
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 40, in itemChange
ret = sip.cast(ret, QtGui.QGraphicsItem)
TypeError: cast() argument 1 must be sip.simplewrapper, not ChildGroup
Traceback (most recent call last):
File "<ipython-input-2-5f5dea77ec5e>", line 1, in <module>
runfile('C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice/pyqt5LiveGraphExample.py', wdir='C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice/pyqt5LiveGraphExample.py", line 30, in <module>
main()
File "C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice/pyqt5LiveGraphExample.py", line 24, in main
main = MainWindow()
File "C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice/pyqt5LiveGraphExample.py", line 19, in __init__
self.graphWidget.plot(hour, temperature)
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\PlotItem\PlotItem.py", line 653, in plot
self.addItem(item, params=params)
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\PlotItem\PlotItem.py", line 530, in addItem
self.vb.addItem(item, *args, **vbargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 409, in addItem
self.updateAutoRange()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 890, in updateAutoRange
childRange = self.childrenBounds(frac=fractionVisible)
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 1355, in childrenBounds
px, py = [v.length() if v is not None else 0 for v in self.childGroup.pixelVectors()]
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 189, in pixelVectors
dt = self.deviceTransform()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 108, in deviceTransform
view = self.getViewWidget()
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 65, in getViewWidget
if v is not None and not isQObjectAlive(v):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\Qt.py", line 328, in isQObjectAlive
return not sip.isdeleted(obj)
TypeError: isdeleted() argument 1 must be sip.simplewrapper, not PlotWidget

configparser.NoSectionError: No section: 'creds' in Python

I'm getting configparser.NoSectionError: No section: 'creds
Config.cfg file
[creds]
token = telegram_bot_token
code.py file
class telegram_bot() :
def __init__(self,config):
self.token=self.read("config.cfg")
self.base="https://api.telegram.org/bot{}/".format(self.token)
def read(self,config):
self.parser=cfg.RawConfigParser()
self.parser.read(config)
return self.parser.get('creds','token')
Error
Traceback (most recent call last):
File "MAINSERVER.PY", line 5, in <module>
bots=telegram_bot("config.cfg")
File "G:\BOT\TBOT\bs4\qrcode\main.py", line 6, in __init__
self.token=self.read("config.cfg")
File "G:\BOT\TBOT\bs4\qrcode\main.py", line 24, in read
return self.parser.get('creds','token')
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\configparser.py", line 781, in get
d = self._unify_values(section, vars)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\configparser.py", line 1149, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'creds'
Anybody know what could be the issue ?

FramenetError: Unknown frame

I run:
from nltk.corpus import framenet as fn
fn.frames()
And get the following error:
Traceback (most recent call last):
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1308, in frame_by_name
elt = XMLCorpusView(locpath, 'frame')[0]
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/xmldocs.py", line 155, in __init__
encoding = self._detect_encoding(fileid)
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/xmldocs.py", line 166, in _detect_encoding
with open(fileid, 'rb') as infile:
NotADirectoryError: [Errno 20] Not a directory: '/Users/me/nltk_data/corpora/framenet_v17.zip/framenet_v17/frame/Abandonment.xml'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 876, in __repr__
for elt in self:
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/collections.py", line 406, in iterate_from
try: yield self._func(self._lists[0][index])
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1407, in frame
f = self.frame_by_id(fn_fid_or_fname, ignorekeys)
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1268, in frame_by_id
return self.frame_by_name(name, ignorekeys, check_cache=False)
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1310, in frame_by_name
raise FramenetError('Unknown frame: {0}'.format(fn_fname))
nltk.corpus.reader.framenet.FramenetError: Unknown frame: Abandonment
Both the Framenet 1.5 and 1.7 corpora are installed, according to nltk.download()

'MatlabWorkSpace' object is not callable

eng = matlab.engine.start_matlab()
for line in matcode:
eng.workspace(line, nargout=0)
res = eng.workspace['x']
eng.quit()
and matcode.txt object string is
'x = [1 1;1 2;1 3;1 4];'
Couldn't figure out why is this happening :(
Traceback (most recent call last):
File "lreg.py", line 14, in <module>
main()
File "lreg.py", line 10, in main
data = matlab_engine.start_engine(code_object)
File "/Users/hiteshkr/PycharmProjects/MLCO/matlab_engine.py", line 7, in start_engine
eng.workspace(line, nargout=0)
TypeError: 'MatlabWorkSpace' object is not callable

Categories

Resources