'None type' object has not attribute error
enter image description here Traceback (most recent call last): AttributeError: 'NoneType' object has no attribute 'reverse', I don't know why the function name is none type. Thank you for ur answer in advance!
See also questions close to this topic
UnicodeDecodeError when reading from file
I am quite new to python and I am looking at an AI code and I need to read a file containing the training data. The code provided for this part looks like this:
import _pickle as cPickle import gzip import numpy as np f = gzip.open('../data/mnist.pkl.gz', 'rb') training_data, validation_data, test_data = cPickle.load(f) f.close()
However I get this error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128)
Can someone tell me why and how to fix it? Or what else should I use to read it? (The code I am using is from a quite reliable source so it should work out of the box...)
os.read() gives OSError: [Errno 22] Invalid argument when reading large data
I use the following method to read binary data from any given offset in the binary file. The binary file I have is huge 10GB, so I usually read portion of it when needed by specifying from which offset I should
start_readand how many bytes to read
num_to_read. I use Python 3.6 and os module:
def read_from_disk(path, start_read, num_to_read, dim): fd = os.open(path, os.O_RDONLY) os.lseek(fd, start_read, 0) # Where to (start_read) from the beginning 0 raw_data = os.read(fd, num_to_read) # How many bytes to read C = np.frombuffer(raw_data, dtype=np.int64).reshape(-1, dim).astype(np.int8) os.close(fd) return C
This method works very well when the chunk of data to be read is about less than 2GB. When
num_to_read > 2GG, I get this error:
raw_data = os.read(fd, num_to_read) # How many to read (num_to_read) OSError: [Errno 22] Invalid argument
I am not sure why this issue appears and how to fix it. Any help is highly appreciated.
Selecting all numerical values in data-frame and converting it to int in panda
I have data like:
I want to make all numerical values to int, no decimal will be here. like this:
I was using code like list:
df=pd.read_csv("file.csv") df = df.astype('int64')
But it was not working. Because it was saying:
ValueError: Cannot convert NA to integer
Because, I have some nan value inside. There are string also in the column one row 2&3. I think the solution could be, selecting all numerical values from the data frame and converting to int. Can you suggest anything?
Self Not Defined - python 2
I know this topic has already been discussed, but my problem is a little different: I am running my code on a Raspberry Pi, for the Adeept Starter Kit (Raspberry Pi Version). I am up to lesson 9 which is controlling an LCD1602. But when I run the code I get an error saying:
Traceback (most recent call last): File "/home/pi/Desktop/Adeept_Starter_Kit_for_RPi3_V2.0/code/Starter_Kit_Python_Code_for_RPi/09_lcd1602.py", line 11, in <module> class Adafruit_CharLCD: File "/home/pi/Desktop/Adeept_Starter_Kit_for_RPi3_V2.0/code/Starter_Kit_Python_Code_for_RPi/09_lcd1602.py", line 62, in Adafruit_CharLCD self.GPIO = GPIO NameError: name 'self' is not defined
And here is the code snippet it gets cranky about:
def __init__(self, pin_rs=14, pin_e=15, pins_db=[17, 18, 27, 22], GPIO = None): if not GPIO: import RPi.GPIO as GPIO self.GPIO = GPIO self.pin_rs = pin_rs self.pin_e = pin_e self.pins_db = pins_db self.GPIO.setmode(GPIO.BCM) self.GPIO.setup(self.pin_e, GPIO.OUT) self.GPIO.setup(self.pin_rs, GPIO.OUT)
You can view the full code file at this link
Thanks for your time!
Python 2.7 Traceback (most recent call last): key error
Traceback (most recent call last): line 17, in <module> print(auth['response']['success']['tokens']['bearer']['access_token']) KeyError: 'success'
Python 2.7 and PyQT - issues related to combobox item data retrieval
Something unexpected is happening within a function connected to pyqt combo box currentIndexChanged event. Two combo boxes are populated and connected to a function to fire upon index change. The function then retrieves specific information from the selected combo box item and populates two other combo boxes respectively.
While all comboboxes are eventually and correctly populated, something is still occurring at the wrong time as I get
AttributeError: 'NoneType' object has no attribute pendingFieldson the lines indicated in the layerChanged function when the plugin is run. After I exit out of the python error warning, I get the dialog with all comboboxes properly populated.
I am wondering if the problem may be related to the moment when combobox items are added--perhaps the currentIndexChanged signal is firing before the first item is added, and therefore is undefined?
The run function upon opening the plugin:
def run(self): # show the dialog self.dlg.show() self.dlg.ui.compteurCombo.clear() self.dlg.ui.resCombo.clear() layers = QgsMapLayerRegistry.instance().mapLayers().values() for layer in layers: if layer.type() == QgsMapLayer.VectorLayer and layer.geometryType() == QGis.Line: self.dlg.ui.resCombo.addItem(layer.name(), layer) if layer.type() == QgsMapLayer.VectorLayer and layer.geometryType() == QGis.Point: self.dlg.ui.compteurCombo.addItem(layer.name(), layer) self.dlg.ui.vServIn.setMaximum(500000.99) # Run the dialog event loop result = self.dlg.exec_() # See if OK was pressed if result == 1: # do something useful (delete the line containing pass and # substitute with your code) self.calcStats()
This is how the comboboxes are connected to the signal and the run function is called.
def initGui(self): # Create action that will start plugin configuration self.action = QAction( QIcon(":/plugins/statsaep/icon.png"), u"Calculer statistiques du réseau AEP", self.iface.mainWindow()) # connect the action to the run method self.action.triggered.connect(self.run) # Add toolbar button and menu item self.iface.addToolBarIcon(self.action) self.iface.addPluginToMenu(u"&statsAEP", self.action) QObject.connect(self.dlg.ui.compteurCombo,SIGNAL("currentIndexChanged(int)"),self.layerChanged) QObject.connect(self.dlg.ui.resCombo,SIGNAL("currentIndexChanged(int)"),self.layerChanged)
The function called upon currentIndexChanged:
def layerChanged(self): registry = QgsMapLayerRegistry.instance() self.comptLayer = self.dlg.ui.compteurCombo.itemData(self.dlg.ui.compteurCombo.currentIndex()) self.resLayer = self.dlg.ui.resCombo.itemData(self.dlg.ui.resCombo.currentIndex()) #QMessageBox.information(None, 'Connection result', "Res layer %s" % self.resLayer.name()) #Error occurs here comptField_names = [str(field.name()) for field in self.comptLayer.pendingFields()] #Error also occurs here resField_names = [str(field.name()) for field in self.resLayer.pendingFields()] self.dlg.ui.consoCombo.clear() self.dlg.ui.longCombo.clear() for field in comptField_names: self.dlg.ui.consoCombo.addItem(field) for field in resField_names: self.dlg.ui.longCombo.addItem(field)