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.
Is there any way to check if a function is user-defined?
|
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
Your going to have to be more specific. User defined functions in what?
Recommended Tutorials:
Oct-05-2016, 02:44 PM
Oct-05-2016, 03:28 PM
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'
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch" Python 3.6.5, IDE: PyCharm 2018 Community Edition
Oct-05-2016, 03:30 PM
(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 I thought he was talking about functions defined be each user :doh:
Recommended Tutorials:
Oct-05-2016, 03:32 PM
(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?
Oct-05-2016, 03:33 PM
(This post was last modified: Oct-05-2016, 03:40 PM by sparkz_alot.)
You may be right :P
(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? I suppose you could open the file and search it for lines beginning with 'def' then doing something with that information.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch" Python 3.6.5, IDE: PyCharm 2018 Community Edition
Oct-05-2016, 04:04 PM
I think if there is some kind of software that manage the project there will be records what piece of code from who is written.
If a user write a function to a file this file should have an owner. 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.
Oct-05-2016, 04:58 PM
(This post was last modified: Oct-05-2016, 05:00 PM by Crimson King.)
If by user-defined functions you mean functions that you've written yourself in your current file, like:
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. The thing is, if you import a function directly from a module: from requests import getThe 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__
Oct-05-2016, 05:05 PM
There's also the inspect module, if you really want to dive into the deep end...
|
|