Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call a def from a string
#1
I have a variable called "current" which is the name of the current def you are in. If you lose a life a new def is called. Since rooms are picked at random, I cant just use 'roomname()' to get back to the original room you were in before you lost a life. I need something that assignes current the as the current def name, then calls that variable in the death function like 'current()'.
I have tried this:
import inspect #this a test

def main():
    room1()

def room1():
    global current
    current = inspect.stack()[0].function
    dead()

def dead():
    current()

main()
but I get an error saying 'TypeError: 'str' object is not callable'

Any help on this would be appreciated!
Thanks, Dream.
Reply


Messages In This Thread
Call a def from a string - by DreamingInsanity - Jun-22-2018, 06:09 PM
RE: Call a def from a string - by buran - Jun-22-2018, 06:40 PM
RE: Call a def from a string - by Larz60+ - Jun-22-2018, 06:45 PM
RE: Call a def from a string - by ljmetzger - Jun-22-2018, 06:50 PM
RE: Call a def from a string - by volcano63 - Jun-22-2018, 08:03 PM
RE: Call a def from a string - by nilamo - Jun-22-2018, 08:04 PM
RE: Call a def from a string - by DreamingInsanity - Jun-23-2018, 08:21 AM
RE: Call a def from a string - by nilamo - Jun-25-2018, 06:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to call the values at the end of a text string? Dieselkaine 2 3,082 Jul-02-2018, 08:47 PM
Last Post: Dieselkaine

Forum Jump:

User Panel Messages

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