Python Forum

Full Version: Making a code.py file to function, does not run
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Why could a code that I wrote, runs perfectly as let's say mycode.py file, and when I make this code a function, let's say

def myfunction(self):
   . . .
and run it inside a class, as self.myfunction() it does not run correctly? It does not even read/get the data from the excel file.

the class is like this:

class MyClass(qt.QMainWindow):
    def __init__(self, parent = None):
        . . .

        self.myfunction() 

    def myfunction(self):
        . . . 
Thanks...
once you have created a class, in order to make it run you must instantiate (create an instance) the class:
you haven't done that, or at least don't show that you have
(Jan-20-2021, 01:16 AM)Larz60+ Wrote: [ -> ]once you have created a class, in order to make it run you must instantiate (create an instance) the class:
you haven't done that, or at least don't show that you have

How I do that?
my_instance = MyClass()
(Jan-20-2021, 08:34 AM)DeaD_EyE Wrote: [ -> ]
my_instance = MyClass()

I have done inside an area called this:

if __name__ == "__main__":
Another thing that I am looking is the call by value VS. call by reference...could it be there the problem?
It's really difficult to tell when we don't see any code, a guessing game. Could you produce some code. Also what exactly "it does not run correctly" means? Do you get error, does it run at all, etc.?
(Jan-20-2021, 01:39 PM)hobbyist Wrote: [ -> ]Another thing that I am looking is the call by value VS. call by reference

Python has names (in documentation they call it also variables) which are pointing internally to a memory address where the object lives. Assignment = always replaces the reference to the new object. The old object could have more than one reference pointing to it. If no reference is left, the object is garbage collected.


Quote:...could it be there the problem?
Code?