Adding comment as answer since it solved the problem. count is somewhat of a protected keyword in DataFrame API, so naming columns count is dangerous. In your case you could circumvent the error by not using the dot notation, but bracket based column access, e.g.
info["count"]
Answer from LiMuBei on Stack Overflowpython - Spark join throws 'function' object has no attribute '_get_object_id' error. How could I fix it? - Stack Overflow
python - "AttributeError: 'function' object has no attribute 'get'" in SQLAlchemy ORM Object contructor - Flask - Stack Overflow
AttributeError: 'numpy.int64' object has no attribute '_get_object_id'
AttributeError: 'DataFrame' object has no attribute '_get_object_id'
Adding comment as answer since it solved the problem. count is somewhat of a protected keyword in DataFrame API, so naming columns count is dangerous. In your case you could circumvent the error by not using the dot notation, but bracket based column access, e.g.
info["count"]
Try to get info.count as a function call info.count().
movie_names_df = info.join(movies_df, info.movieId == movies_df.ID, "inner").select(movies_df.title, info.average, info.movieId, info.count()).show()
Answer
The reason it fails is thanks to the __dict__ method. Since the removal of it, everything works fine.
Of course this leads to the next question: How to define custom dict functions for those classes
I couldn't find an answer to this but still want to offer a solution: Define a custom function that takes the required obj as a parameter and then puts the wanted fields into a dict. Not the most elegant solution IMO but it works.
I have removed __dict__, and created get_dict(self) to make my dict through the object without my constructor get problems.
I am working on a Raspberry Pi Pico, programmed in Micropython. I have soldered a temperature sensor to it, and can read the values very well. The results are here: thingspeak.com...533 :-)
However, I'd like to use the average, min and max temperature values during a certain period of time (10 minutes in my current program).
Being the non-programmer, I used ChatGPT to write me a function that would give me the average values whenever I call the function. When I call avgtemp(sensor) it would add the value and return the current average, min & max values. When called avgtemp(sensor, True) it should reset the values for the next period.
ChatGPT gave me:
def avgtemp(new_value, reset=False):
if not hasattr(avgtemp, 'count'):
avgtemp.count = 0
avgtemp.total = 0
avgtemp.average = 0
avgtemp.min = float('inf')
avgtemp.max = float('-inf')
if reset:
avgtemp.count = 0
avgtemp.total = 0
avgtemp.average = 0
avgtemp.min = float('inf')
avgtemp.max = float('-inf')
avgtemp.count += 1
avgtemp.total += new_value
avgtemp.average = avgtemp.total / avgtemp.count
avgtemp.min = min(avgtemp.min, new_value)
avgtemp.max = max(avgtemp.max, new_value)
return avgtemp.average, avgtemp.min, avgtemp.max, avgtemp.countBut this gives me always an error: AttributeError: 'function' object has no attribute 'count'
The first if-block should take care of that: if the attribute is not initiated yet, it should create it. But this does not work... I tried to initialize the values in the beginning of the main program (where I set several other values), but could not get it to work yet...
Can someone with a better knowledge of (Micro)Python give me a pointer where I am going wrong?
Thanks in advance!
morseCodeM={".-":"A",
"-...":"B",
"-.-.":"C",
"-..":"D",
".":"E",
"..-.":"F",
"--.":"G",
"....":"H",
"..":"I",
".---":"J",
"-.-":"K",
".-..":"L",
"--":"M",
"-.":"N",
"---":"O",
".--.":"P",
"--.-":"Q",
".-.":"R",
"...":"S",
"-":"T",
"..-":"U",
"...-":"V",
".--":"W",
"-..-":"x",
"-.--":"Y",
"--..":"Z",
" / ":" "}
def morseToText(inp):
out=""
while(inp!=" "):
for i in morseCodeM:
if(inp.find(i)!=-1): <-----------------------
out=out+morseCodeM[i]
inp2=list(inp)
inp2[inp.find(i):inp.find(i)+(len(i)-1)]=""
inp="".join(inp2)
return outI honestly don't know whats wrong it just gives the error :"AttributeError: 'function' object has no attribute 'find'" on the line with the arrow .
edit: the code is about converting morse code to text
hello, i am working on a game using pygame and i am going for an OOP approach, the files are pretty big, i will post only a portion of the code; also i am using pycharm so i know for a fact my identation, typing are alright.. plus i have been coding in python for a while now but i just can't grasp onto this issue :(, so far in the game i am just in the main menu phase and whenever i try to run my code i get an error that my game object (which has a reference to another class including the main menu game loop) has no attribute ''screenWidth'' but it actually does have a variable for my screen.. i just use it in the main menu to set another midWidth variable half of that variable as value
here is the code:
main.py
from game import Game
myGame = Game()
while myGame.running:
myGame.currentMenu.drawMainMenu()
myGame.gameLoop()game.py
import pygame
from menu import MainMenu
class Game:
def __init__(self):
pygame.init()
self.running, self.playing = True, False
self.upKey, self.downKey, self.selectKey, self.backKey = False, False, False, False
self.currentMenu = MainMenu(self)
self.screenWidth = 1280
self.screenHeight = 720
self.gameWindow = pygame.display.set_mode((self.screenWidth, self.screenHeight))
pygame.display.set_caption("Game Prototype")
self.backgroundImage = pygame.image.load('Assets/Images/bg_greek.jpg')
self.backgroundImage = pygame.transform.scale(self.backgroundImage, (1920, 1080))
def gameLoop(self):
while self.playing:
self.checkEvents()
if self.selectKey:
self.playing = False
self.gameWindow.blit(self.backgroundImage, (-600, -300))
pygame.display.flip()
self.resetKeys()
menu.py
import pygame
class Menu:
def __init__(self, game):
self.gameClass = game
self.midWidth = self.gameClass.screenWidth / 2
self.midHeight = self.gameClass.screenHeight / 2
self.showMenu = True
self.selectionX, self.selectionY = 0, 0
def drawSelection(self):
selectSurface = pygame.Surface((260, 100), pygame.SRCALPHA)
selectSurface.fill((50, 50, 50, 175))
selectRect = selectSurface.get_rect()
selectRect.center = (self.selectionX, self.selectionY)
self.gameClass.gameWindow.blit(selectSurface, selectRect)
class MainMenu(Menu):
def __init__(self, game):
Menu.__init__(self, game)
self.hoveredState = "Start"
self.startX, self.startY = self.midWidth, self.midHeight
self.optionsX, self.optionsY = self.midWidth, self.midHeight + 100
self.creditsX, self.creditsY = self.midWidth, self.midHeight + 200
self.quitX, self.quitY = self.midWidth, self.midHeight + 300
self.selectionX, self.selectionY = self.startX, self.startY
def drawMainMenu(self):
self.showMenu = True
while self.showMenu:
self.gameClass.checkEvents()
self.checkInput()
self.gameClass.gameWindow.blit(self.gameClass.backgroundImage, (-600, -300))
self.drawSelection()
self.gameClass.drawText("Play", 72, self.startX, self.startY)
self.gameClass.drawText("Options", 72, self.optionsX, self.optionsY)
self.gameClass.drawText("Credits", 72, self.creditsX, self.creditsY)
self.gameClass.drawText("Quit", 72, self.quitX, self.quitY)
pygame.display.flip()
self.gameClass.resetKeys()
it is not complete though
Your indentation is goofed, and you've mixed tabs and spaces. Run the script with python -tt to verify.
If you’re using python 3+ this may also occur if you’re using private variables that start with double underscore, e.g., self.__yourvariable. Just something to take note of for some of you who may run into this issue.