Python Forum
Making a code.py file to function, does not run
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a code.py file to function, does not run
#1
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...
Reply
#2
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
hobbyist likes this post
Reply
#3
(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?
Reply
#4
my_instance = MyClass()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
(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?
Reply
#6
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.?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
(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?
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo Making Zip file of a file and Directory Nasir 2 1,017 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Making a function more efficient CatorCanulis 9 1,827 Oct-06-2022, 07:47 AM
Last Post: DPaul
Star I was making code for collision for my character izmamonke 2 2,080 Aug-06-2021, 04:30 PM
Last Post: izmamonke
Question Making a copy list in a function RuyCab 1 1,793 Jul-11-2021, 02:06 PM
Last Post: Yoriz
  Putting code into a function breaks its functionality, though the code is identical! PCesarano 1 1,983 Apr-05-2021, 05:40 PM
Last Post: deanhystad
  Making new lines of code AvioxyYT 1 1,801 Jan-22-2021, 07:02 PM
Last Post: buran
  Making .exe file that requires access to text and html files ClassicalSoul 0 1,578 Apr-23-2020, 05:03 PM
Last Post: ClassicalSoul
  making a function that writes variables (is possible?) miker2808 3 2,341 Jan-30-2020, 06:27 PM
Last Post: buran
  making the code easier, list comprehension go127a 2 2,059 May-26-2019, 06:19 PM
Last Post: Gribouillis
  need help with making a validating function drasil 8 3,721 Mar-28-2019, 10:38 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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