Allen W
Allen W

Reputation: 139

Python - Is there a way to get who is calling (called from IDLE/Shell)

Is there a way to get is the method called from IDLE/python shell?

For example:

def print_in_console():
    if called_from_python_shell:
        print('Called from console')
    ...do other stuff later

Upvotes: 3

Views: 30

Answers (1)

Matthew
Matthew

Reputation: 267

The only feasible (easy) way I can see of doing this is by passing an argument / parameter to the function you're calling.

def function (foo, bar, called_from):
    print (called_from)
    *** do stuff with foo and bar ***

Upvotes: 2

Related Questions