'Tuple' object is not callable - Python - python

I'm using pygame and I'm using a function that set the selected position of a text
in PyGame :
def textPos(YPos , TextSize):
TextPosition.center(60,YPos)
print("Size : " + TextSize)
but when I run the program, I get an error:
TextPosition.center(60,YPos) : TypeError : 'Tuple' object is not callable
There's a way to solve this problem?

'Tuple' object is not callable error means you are treating a data structure as a function and trying to run a method on it. TextPosition.center is a tuple data structure not a function and you are calling it as a method. If you are trying to access an element in TextPosition.Center, use square brackets []
For example:
foo = [1, 2, 3]
bar = (4, 5, 6)
# trying to access the third element with the wrong syntax
foo(2) --> 'List' object is not callable
bar(2) --> 'Tuple' object is not callable
# what I really needed was
foo[2]
bar[2]

Related

'tuple' object does not support item assignment in torch.cat()

I am trying to use the torch.cat() to contenate the torch tensor. However, I face the error messagge with --> 'tuple' object does not support item assignment.
Here are my code:
inputs = tokenizer.encode_plus(txt, add_special_tokens=False, return_tensors="pt")
input_id_chunks = inputs["input_ids"][0].split(510)
mask_chunks = inputs["attention_mask"][0].split(510)
print(type(input_id_chunks))
for i in range(len(input_id_chunks)):
print(type(input_id_chunks[i]))
print(input_id_chunks[i])
input_id_chunks[i] = torch.cat([
torch.Tensor([101]), input_id_chunks[i], torch.Tensor([102])
])
The outputs looks fine, the inputs_id_chunks[i] is torch.Tensor:
`<class 'tuple'>
<class 'torch.Tensor'>`
But I got the following print and error message:
TypeError: 'tuple' object does not support item assignment
in torch.cat()
I have using the small testing code for torch.cat() and it works fine, but I don't know what is missing in my original codes.
you can't change tuple value, instead you can assign it to list, then append new value to it and then after all changes you want to implement, you should assign again it to tuple.
please check this link

Attribute Error: list object has no attribute 'apply'

time_weight = list(100*np.exp(np.linspace(-1/divisor, -(num_steps-1)/divisor, num_steps))).apply(lambda x:int(x))
When I try this, I get the following error in Python 3.7.
AttributeError: 'list' object has no attribute 'apply'
Can anyone help with this?
As the error said, list type has no apply attribute.
This said, if you have a list l and you want to set to int type every element in it you may use:
l = [int(x) for x in l]
or
l = list(map(int,l))
As the error suggests, list has no apply method. If what you want to do is convert every element to an int, you could remove the lambda function and instead use astype(int):
time_weight = list((100*np.exp(np.linspace(-1/divisor, -(num_steps-1)/divisor, num_steps))).astype(int))

AttributeError: 'NoneType' object has no attribute 'Mrc' in python using jupyter notebook

Can someone please tell me where I am going wrong? Here's my code and the error I am getting.
p.s I have given the somefile.mrc path correctly.
import numpy
import Mrc
a = Mrc.bindFile('home/smitha/deep-image-prior/data/Falcon_2015_05_14-20_42_18.mrc')
# a is a NumPy array with the image data memory mapped from
# somefile.mrc. You can use it directly with any function
# that will take a NumPy array.
hist = numpy.histogram(a, bins=200)
# a.Mrc is an instances of the Mrc class. One thing
# you can do with that class is print out key information from the header.
a.Mrc.info()
wavelength0_nm = a.Mrc.hdr.wave[0]
AttributeError Traceback (most recent call
last) in ()
3 a = Mrc.bindFile('/home/smitha/deep-image-prior/data/Falcon_2015_05_14-20_42_18.mrc')
4 hist = numpy.histogram(a, bins=200)
----> 5 a.Mrc.info()
6 wavelength0_nm = a.Mrc.hdr.wave[0]
7
AttributeError: 'NoneType' object has no attribute 'Mrc'
​
AttributeError: 'NoneType' object has no attribute 'Mrc' means that you are trying to access an object's 'Mrc' member even though the object is NoneType, thus the object has no such member.
You are trying to do so in a.Mrc.info(), meaning that a is None (the unique instance of NoneType). The reason is that either
a = Mrc.bindFile('/home/smitha/deep-image-prior/data/Falcon_2015_05_14-20_42_18.mrc')
OR
hist = numpy.histogram(a, bins=200)
had assigned None to a. Check type(a) after each line, see where the problem is, and debug the function

How to append list in list in python3?

def cal(i,L,cset,comp):
for n in range(i,len(L)):
print(cset+[L[1]])
comp.insert(cset+[L(n)])
cal(i+1,L,comp[len(comp)-1],comp)
return comp
print(cal(0,[1,2,3,4,5],[],[]))
in this code it gives me an error from the first iterration
line 4, in cal
comp.insert(cset+[L(n)])
TypeError: 'list' object is not callable
I did change
comp.insert(cset+[L(n)])
to
comp.insert(cset+[L[n]])
Just got lost there :/

partition and rpartiton getting TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'

I'm getting this error when I try to run the script.
TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
Here is the script:
containerFile = open((tmpImageDirectory+"container.rvbr"), "r")
containedString = containerFile.read()
containerFile.close()
containedFiles = containedString .partition[","]
container.rvbr contains a string with several comas.
If execute this str(conatinedString) I get this <type 'str'>, so it's a string.I wonder if somebody can explain this.
Use parentheses rather than square brackets to call a method:
containedFiles = containedArray.partition(",")
Furthermore, you probably want to do split rather than partition: partition will keep the commas in the resulting tuple, even though those commas are not in fact files:
"hello,world".partition(",")
# ('hello', ',', 'world')
"hello,world".split(",")
# ['hello', 'world']
containedFiles = containedString .partition(",")
not
containedFiles = containedString .partition[","]
use parentheses when you want to call a method.

Categories