Python Forum
Python-Function object creation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python-Function object creation
#1
As I understand from a book that function in Python is nothing but object of Function class. I have some doubts as below:

1.When this object gets created? At the time we define function or at the time we call a function?

2.If it is getting created at the time we define a function, then will it not be a waste of memory if we do not call that function anywhere in program ?

Looking for detail answer.
Reply
#2
If you're not going to call the function doesn't it make sense not to write it?
Reply
#3
Quote:1.When this object gets created? At the time we define function or at the time we call a function?
The Python interpreter is parsing the whole code from your script or stdin and convert it to bytecode, which runs in the interpreter.

Quote:2.If it is getting created at the time we define a function, then will it not be a waste of memory if we do not call that function anywhere in program ?
The function object lives in memory at runtime. Yes, if you define it as wasting memory, it is wasting memory. But if you aware of memory you should better use C or assembler.
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
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,210 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  dynamic object creation using python gary 7 1,196 Oct-15-2022, 01:35 PM
Last Post: Larz60+
  python update binary object (override delivered Object properties) pierre38 4 1,710 May-19-2022, 07:52 AM
Last Post: pierre38
  AttributeError: 'function' object has no attribute 'metadata 3lnyn0 5 4,522 Mar-28-2022, 04:42 PM
Last Post: Larz60+
  Is there a library for recursive object creation using config objects johsmi96 0 1,823 May-03-2021, 08:09 PM
Last Post: johsmi96
  how to call an object in another function in Maya bstout 0 2,042 Apr-05-2021, 07:12 PM
Last Post: bstout
  subprogram issues: cannot unpack non-iterable function object error djwilson0495 13 5,864 Aug-20-2020, 05:53 PM
Last Post: deanhystad
  function/nonetype object is not iterable nanok66 5 3,965 May-08-2020, 07:39 PM
Last Post: nanok66
  Accessing method as function object ClassicalSoul 2 1,975 Feb-14-2020, 09:31 PM
Last Post: wavic
  How to mock an object that is created during function call? Schlangenversteher 0 1,946 Jan-31-2020, 01:36 PM
Last Post: Schlangenversteher

Forum Jump:

User Panel Messages

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