Python Forum
Is there any way to check if a function is user-defined?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there any way to check if a function is user-defined?
#9
If by user-defined functions you mean functions that you've written yourself in your current file, like:

def myfunc(): pass
Then having a print statement could be of some help:

import types
print [f.__name__ for f in globals().values() if type(f) == types.FunctionType]
That statement will print the name of all type 'function' objects.

The thing is, if you import a function directly from a module:

from requests import get
The get function from the requests module will now be listed in the previously mentioned print statement.

PS: in my print statement, it should read f.__name__
Reply


Messages In This Thread
RE: Is there any way to check if a function is user-defined? - by Crimson King - Oct-05-2016, 04:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 750 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,648 Sep-03-2023, 03:22 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,278 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Getting NameError for a function that is defined JonWayn 2 1,230 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 3,233 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  How to print the output of a defined function bshoushtarian 4 1,451 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  User-defined function to reset variables? Mark17 3 1,820 May-25-2022, 07:22 PM
Last Post: Gribouillis
  Multiple user defined plots with secondary axes using for loop maltp 1 1,643 Apr-30-2022, 10:19 AM
Last Post: maltp
  Date format and past date check function Turtle 5 4,675 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Exit function from nested function based on user input Turtle 5 3,152 Oct-10-2021, 12:55 AM
Last Post: Turtle

Forum Jump:

User Panel Messages

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