How to fix a AttributeError in Python? - python

I don't success to fix this error on my code. Python wrote me this error message:
"Traceback (most recent call last):
File "C:\Users\ChloƩ CHAUMETON\Documents\BioAxial\1_R&D\4_Software\2_Python\Measurement_script\Matlab_to_Python\2019\Chloe_script_V3.py", line 114, in <module>
if 0 < len((lrir)(lrir.name_file)):
AttributeError: 'function' object has no attribute 'name_file' "
I defined the "name_file = 'BSR_Main.exe2018_09_14.csv' " up of my code but I don't understand why python don't attribute this name fto the function. Here is my code.
i_r=[]
def lrir():
lrir = liste_record[i_r]
name_file = 'BSR_Main.exe2018_09_14.csv';
for i_r in range(0,rec-1):
if 0 < len((lrir)(lrir.name_file)):
str1 = ligne.find(lrir.name_file,'/')
pr_rep = os.path.join(dir_PR,s(i_r).name_file)
log_rep = os.path.join(pr_rep,'Log')
log_file = glob.glob(os.path.join(log_rep,'*.log'))
print('log file:',log_file)

Related

Syntax error with exec call to an object in Python 3

I really don't understand what causes the problem, could someone point it out for me please?
with shelve.open(obj_path) as obj:
for as_num in obj['as_number_list']: # ignore warning, obj['as_number_list'] is a list
temp = charge_as(obj['as_' + str(as_num)]) # temp is an object
as_test = temp # doing like this is ok
print(type(as_test))
exec("as_{}_obj = {}".format(as_num, temp)) # **error here**
And it gives syntax error like this:
<class 'instruments.AS'>
Traceback (most recent call last):
File "...", line 45, in <module>
exec("as_{}_obj = {}".format(as_num, temp))
File "<string>", line 1
as_1_obj = <instruments.AS object at 0x000002A86732E290>
^
SyntaxError: invalid syntax
I tried
exec("as_{}_obj = {}".format(as_num, temp.__dict__))
no error is shown but now as_{}_obj is of class 'dict' instead of class 'instruments.AS'
line 45:
exec("as_{}_obj = temp".format(as_num))

findNotesMetadata AttributeError: 'function' object has no attribute 'write'

Found similar questions to this, but the solutions proposed didn't seem to work for me.
I'm struggling to make the findNotesMetadata call. My getUser() from the userStore works, and my createNote from the notestore works as well. It is only the call to findNotesMetaData that is failing currently.
from evernote.api.client import EvernoteClient
import evernote.edam.type.ttypes as Types
dev_token = "blah blah blah"
client = EvernoteClient(token=dev_token, sandbox=True)
userStore = client.get_user_store()
user = userStore.getUser()
print user.username
notestore = client.get_note_store()
notebooks = notestore.listNotebooks()
note = Types.Note()
note.title = "I'm a test note!"
note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
note.content += '<en-note><en-todo/>Hello, world!</en-note>'
note = noteStore.createNote(note)
tags = notestore.listTags()
CheckedTags = set()
for tag in tags:
if tag.name[0:4] == "CheckThisTag":
print tag
CheckedTags.add(tag.guid)
print CheckedTags
myfilter = notestore.NoteFilter()
spec = notestore.NotesMetadataResultSpec()
spec.includeTitle = True
notes = notestore.findNotesMetadata(dev_token, myfilter, 0, 100, spec)
print notes
Running this code gets me the following error on the findNotesMetaData line
Traceback (most recent call last):
File "main.py", line 27, in <module>
notes = notestore.findNotesMetadata(dev_token, filter, 0, 100, spec)
File "build/bdist.macosx-10.13-x86_64/egg/evernote/api/client.py", line 145, in delegate_method
File "build/bdist.macosx-10.13-x86_64/egg/evernote/edam/notestore/NoteStore.py", line 3981, in findNotesMetadata
File "build/bdist.macosx-10.13-x86_64/egg/evernote/edam/notestore/NoteStore.py", line 3992, in send_findNotesMetadata
File "build/bdist.macosx-10.13-x86_64/egg/evernote/edam/notestore/NoteStore.py", line 12996, in write
AttributeError: 'function' object has no attribute 'write'

AttributeError: 'Series' object has no attribute 'Id'

I am trying to create a malware classifier and I am experiencing the error
AttributeError: 'Series' object has no attribute 'Id. Not sure of the error.
Traceback (most recent call last):
File"C:/Users/Afiqmatters/PycharmProjects/MajorProject/feature_extraction.py", line 23, in <module>
rids = [mids.loc[i].Id for i in rchoice]
File "C:\Users\Afiqmatters\Miniconda\lib\site-packages\pandas\core\generic.py", line 2744, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'Id'
Here is the codes I have up to the error.
rs = Random()
rs.seed(1)
trainLabels = pd.read_csv('trainLabels.csv')
#print trainLabels
fids = []
opd = pd.DataFrame()
for label in range(1,10):
mids = trainLabels[trainLabels.Class == label]
mids = mids.reset_index(drop=True)
#print mids
rchoice = [rs.randint(0, len(mids) - 1) for i in range(10)]
print len
#print rchoice
rids = [mids.loc[i].Id for i in rchoice]
The error happens at rids = [mids.loc[i].Id for i in rchoice] and I am not sure of the error.
A sample of what is stored in the trainLabels.csv
Id Class
0A32eTdBKayjCWhZqDOQ 2
mids.loc[i] in this context is a "Series" object which is detailed here
This object type does not have an attribute Series.Id, so that's why you're seeing this error.
Did you mean to call the built-in function id( ) on the object?
rids = [id(mids.loc[i]) for i in rchoice]

Python: object does not support item assignment

I did not understand the message sent by compiler. Can someone help me?
Traceback (most recent call last):
File "C:/Users/edboa_000/PycharmProjects/RESULTADOS_FINAIS 3/ggcc1/quadrante_aplicacao_forca9.py", line 13, in <module>
matriz1[i-11][j] = posicao[j]
TypeError: 'int' object does not support item assignment
My code:
matriz1=((30,2))
for i in range(11,41):
graof = np.genfromtxt('DMconf0%d.dat'%i,skip_header=10254, usecols=(0))
grao = graof.astype('int')
posicao = np.genfromtxt('DMconf0%d.dat'%i,skip_header=grao, usecols=(0,1), max_rows=1)
for j in range(2):
matriz1[i-11][j] = posicao[j] #line 13
print(matriz1)

Python: TypeError: 'str' object is not callable Rating System

When I run this code:
def printPredictions(matches):
pPredictionTable = PrettyTable()
pPredictionTable.field_names = ["Player 1", "Player 2", "Difference", "Winner"]
for match in matches:
p1 = match['teamA']
p2 = match['teamB']
if match['aBeatb'] == True:
pPredictionTable.add_row([match['teamA'], match['teamB'], match['difference'], p1])
else:
pPredictionTable.add_row([match['teamA'], match['teamB'], match['difference'], p2])
print(pPredictionTable)
printPredictions(pmatches)
I get this error:
Traceback (most recent call last):
File "C:\Users\ericr_000\Desktop\PyDev\NPA-2-Rating-System\Rankings.py", line 645, in <module>
printPredictions()
TypeError: 'str' object is not callable
I have pmatches as a separate dictionary, and I don't have the coding skills to fix this issue. (Line 145 is printPredictions(pmatches)
If you're getting 'str' object is not callable when you try to call printPredictions, that means that by the time your program reaches line 645, the name printPredictions was reassigned to a string. Somewhere in your code you have something like
printPredictions = someStringValueGoesHere
You should choose a different name for that variable, or delete the line entirely.
foobar = someStringValueGoesHere

Categories

Resources