Python Forum
How to you find the file where a class or a function was implemented?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to you find the file where a class or a function was implemented?
#1
Hello,

I have a big program where a python code calls several codes (written in Python and C++ ) and software. From function2 which is in my main program, I want to know where function1 where created knowing that function1 is called by function2. The function 1 might be available from an import, I guess. How do I print the name of the file in which the function 1 was implemented?

Thank you.
Reply
#2
These functions are inside of .py files like MyOtherStuff.py
Just import the module where you need to use it:
import MyOtherStuff

then call function as MyOtherStuff.FunctionName()
Reply
#3
The problem is that I don't know which module or file1.py, function1 is. Basically, I want to find in which file the called functions are?
Reply
#4
you can get a list of all files in the directory using
os.listdir()
you can get a file extension with
filename, file_extension =  os.path.splittext(fullpath)
look only at files with extension py

then:
place all function names in a list
read each file in and check:
for item in list:
   if item in filebuffer:
       display filename and function name
Reply
#5
Glob module can get all files by patern.

from glob import glob
py_files = list(glob("*.py"))
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  DF.groupby(col).min works, mean gets a "not implemented" error samgardner5 3 352 Feb-29-2024, 06:13 PM
Last Post: deanhystad
  The function of double underscore back and front in a class function name? Pedroski55 9 562 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,495 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Cannot find py credentials file standenman 5 1,554 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 701 Feb-14-2023, 03:21 PM
Last Post: SouAmego22
  Find (each) element from a list in a file tester_V 3 1,155 Nov-15-2022, 08:40 PM
Last Post: tester_V
  how can a function find the name by which it is called? Skaperen 18 3,322 Aug-24-2022, 04:52 PM
Last Post: Skaperen
  what will be the best way to find data in txt file? korenron 2 1,127 Jul-25-2022, 10:03 AM
Last Post: korenron
  find some word in text list file and a bit change to them RolanRoll 3 1,482 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
Brick Have I implemented this function correctly? naggafin 4 2,275 May-22-2022, 02:52 AM
Last Post: stevendaprano

Forum Jump:

User Panel Messages

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