I need to get the name of a variable in python. For example:
task = EmailTask()
I need to get the "task" mapped to the actual object.
The use case for this is as follows: I am building an ETL tool which will have a lot of reusable generic tasks and instead of a user providing an extra task name for every instance he creates, I will use the variable name that the user has chosen. This variable name is only used for logging purposes. Example of use case:
process_task = MoveDataTask()
email_task = EmailTask()
job = Job(
tasks: [process_task, email_task])
job.start()
I will have to use globals() since the task will be declared in the parent namespace. I understand that I will have a place a few constraints on how the user declares the whole "job", in that, he will have to assign each task to a variable name, instead of doing the following:
job = Job(
tasks: [MoveDataTask(), EmailTask()])
I know that globals() pretty much gives me what I want, but I have reservations about using it since it a little bit non-standard usage of python. Also as I understand, there can be multiple names for the same object in globals(), so, therefore, I need to somehow get the parent name ("process_task", "email_task" from above's an example).
Are there any other pitfalls/issues/things I am missing with this approach?