Oct-05-2016, 02:14 PM
Sometimes it would be nice to single out the functions defined by users in a big project. So is there any way to differentiate user-defined functions from library functions? Thanks.
(Oct-05-2016, 02:20 PM)metulburr Wrote: [ -> ]Your going to have to be more specific. User defined functions in what?
def a_function():it will be a user defined function
import math variable = math.ceil(x)It will be a function from a library, in this case 'math'
(Oct-05-2016, 03:28 PM)sparkz_alot Wrote: [ -> ]Usually it's pretty straight forward, if I understand your question correctly. If you see something like
def a_function():it will be a user defined function
If you see something like
import math variable = math.ceil(x)It will be a function from a library, in this case 'math'
(Oct-05-2016, 03:28 PM)sparkz_alot Wrote: [ -> ]Usually it's pretty straight forward, if I understand your question correctly. If you see something likeGiven a function a_function in your case, how would you check if a_function is a user-defined function programmatically?
def a_function():it will be a user defined function
If you see something like
import math variable = math.ceil(x)It will be a function from a library, in this case 'math'
(Oct-05-2016, 03:32 PM)dullboy Wrote: [ -> ](Oct-05-2016, 03:28 PM)sparkz_alot Wrote: [ -> ]Usually it's pretty straight forward, if I understand your question correctly. If you see something likeGiven a function a_function in your case, how would you check if a_function is a user-defined function programmatically?
def a_function():it will be a user defined function
If you see something like
import math variable = math.ceil(x)It will be a function from a library, in this case 'math'
victor@jerry:~$ ls -l | head -n 5 total 2079052 -rw-rw-r-- 1 victor victor 132737 Mar 1 2016 \ -rw-rw-r-- 1 victor victor 1267 Sep 9 15:52 00349d0ac60ab0cab5e5-f19784922882fd6982c917852d90fff798155313.zip -rw-rw-r-- 1 victor victor 398422 Sep 16 09:49 0.18.1 -rw-rw-r-- 1 victor victor 2494 Apr 26 21:02 10.1371%2Fjournal.pone.0056779.bibAs you can see victor victor is the owner of those 5 files or directories. First is the owner the second is the group.
def myfunc(): passThen 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.
from requests import getThe get function from the requests module will now be listed in the previously mentioned print statement.