0

Such as the title. What should I do with python3?

test1.py

import os
def get_file_name():
    return os.path.basename(__file__)

test2.py

from test1 import get_file_name
file_name = get_file_name()
print(file_name)

now, I want to get the file name of test2

Chris
  • 29,127
  • 3
  • 28
  • 51
Delav
  • 9
  • 2

1 Answers1

0

Change test1.py to:

import os, inspect
def get_file_name():
    return os.path.basename(inspect.stack()[1].filename)
GordonAitchJay
  • 4,640
  • 1
  • 14
  • 16