Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyCharm Error?
#1
I have a problem with PyCharm. The Desctructor Method gets initialized, without it even been called. If I try it in the Python IDLE the intepreter doesn´t iniatialize the method, but it in PyCharm it does do it

class Vehicle:
    def __init__(self, nme, ve):
        self.name = nme
        self.velocity = ve
    def __del__(self):
        print("Object", self.name, "got deleted")
    def beschleunigen(self, value):
        self.velocity += value
        self.output()
    def output(self):
        print(self.name, self.velocity, "km/h")

# Objekte der Klasse erzeugen

car1 = Vehicle("Ford",40)
car2 = Vehicle("BMW", 45)

# Objekte betrachten
car1.output()
car2.output()
Output:
Ford 40 km/h BMW 45 km/h Object Ford got deleted Object BMW got deleted
Can somebody help me?
Reply
#2
The references to objects are deleted when the program ends.
coder_sw99 likes this post
Reply
#3
(Sep-24-2021, 05:51 PM)Yoriz Wrote: The references to objects are deleted when the program ends.

But why does this not happen in IDLE?
Reply
#4
Your problem is actually with IDLE. Pycharm runs the program correctly. Objects should get deleted when the program reaches end of execution. In IDLE the program never really ends. This is why you can "run" your program in IDLE and still see variables after the program is finished.

You see this same kind of thing when writing GUI programs. Most GUI toolkits have some sort of mainloop() function that you call at the end of the program that keeps the program running. Forget the mainloop() and the all you see when you run the program is a blink of the windows appearing when created and disappearing when the program ends. Run the same program in IDLE and the windows stay open.
coder_sw99 likes this post
Reply
#5
IDLE is written in python and is probably keeping a reference to the objects for longer so they don't show up as being garbage collected.

I think it might be more accurate to say IDLE is written in tkinter and that is what is holding a reference to the objects in memory.
coder_sw99 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pycharm error zuri 1 492 Nov-01-2023, 03:38 PM
Last Post: deanhystad
  Pandas - error when running Pycharm, but works on cmd line zxcv101 1 1,376 Jun-18-2022, 01:09 PM
Last Post: snippsat
  Keep getting Session management error when running imshow in pycharm pace 0 2,103 Mar-25-2021, 10:06 AM
Last Post: pace
  REGEX Install Error in PyCharm charlesauspicks 1 2,776 May-14-2020, 08:10 PM
Last Post: buran
  Traceback error in PyCharm but not in other IDEs? devansing 7 6,384 Mar-05-2020, 11:27 AM
Last Post: buran
  Error in importing package in pycharm fullstop 0 2,357 Dec-12-2019, 04:03 PM
Last Post: fullstop
  can't assign to literal error in pycharm ryder5227 2 2,986 Oct-07-2019, 08:57 PM
Last Post: Bmart6969
  Weird error in pycharm TheRedFedora 1 2,680 Mar-11-2018, 09:01 PM
Last Post: Larz60+
  python turtle module in pycharm error sajley 2 13,104 Dec-12-2016, 08:52 PM
Last Post: sajley

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020