You can resolve the value of myobjectfrom the module where it is defined with getattr. If it is in the main module, this should work:
import __main__
mystring = 'This is a test.'
def foo(object):
print object
variableName = 'mystring'
foo(getattr(__main__, variableName))
variableName = 'variableName'
foo(getattr(__main__, variableName))
This should print
This is a test.
variableName
The import of the main module is necessary for variables from the main scope.
Edit: You can also get the content of the string with very dangerous eval(). Just replace foo(getattr(__main__, variableName)) with foo(eval(variableName)).
You can resolve the value of myobjectfrom the module where it is defined with getattr. If it is in the main module, this should work:
import __main__
mystring = 'This is a test.'
def foo(object):
print object
variableName = 'mystring'
foo(getattr(__main__, variableName))
variableName = 'variableName'
foo(getattr(__main__, variableName))
This should print
This is a test.
variableName
The import of the main module is necessary for variables from the main scope.
Edit: You can also get the content of the string with very dangerous eval(). Just replace foo(getattr(__main__, variableName)) with foo(eval(variableName)).
You can resolve the value of myobjectfrom the module where it is defined with getattr. If it is in the main module, this should work:
import __main__
mystring = 'This is a test.'
def foo(object):
print object
variableName = 'mystring'
foo(getattr(__main__, variableName))
variableName = 'variableName'
foo(getattr(__main__, variableName))
This should print
This is a test.
variableName
The import of the main module is necessary for variables from the main scope.
Edit: You can also get the content of the string with very dangerous eval(). Just replace foo(getattr(__main__, variableName)) with foo(eval(variableName)).
You can resolve the value of myobjectfrom the module where it is defined with getattr. If it is in the main module, this should work:
import __main__
mystring = 'This is a test.'
def foo(object):
print object
variableName = 'mystring'
foo(getattr(__main__, variableName))
variableName = 'variableName'
foo(getattr(__main__, variableName))
This should print
This is a test.
variableName
The import of the main module is necessary for variables from the main scope.
Edit: You can also get the content of the string with very dangerous eval(). Just replace foo(getattr(__main__, variableName)) with foo(eval(variableName)).
You can resolve the value of myobjectfrom the module where it is defined with getattr. If it is in the main module, this should work:
import __main__
mystring = 'This is a test.'
def foo(object):
print object
variableName = 'mystring'
foo(getattr(__main__, variableName))
variableName = 'variableName'
foo(getattr(__main__, variableName))
This should print
This is a test.
variableName
The import of the main module is necessary for variables from the main scope.
You can resolve the value of myobjectfrom the module where it is defined with getattr. If it is in the main module, this should work:
import __main__
mystring = 'This is a test.'
def foo(object):
print object
variableName = 'mystring'
foo(getattr(__main__, variableName))
variableName = 'variableName'
foo(getattr(__main__, variableName))
This should print
This is a test.
variableName
The import of the main module is necessary for variables from the main scope.
Edit: You can also get the content of the string with very dangerous eval(). Just replace foo(getattr(__main__, variableName)) with foo(eval(variableName)).
You can resolve the value of myobjectfrom the module where it is defined with getattr. If it is in the main module, this should work:
import __main__
mystring = 'This is a test.'
def foo(object):
print object
variableName = 'mystring'
foo(getattr(__main__, 'mystring'variableName))
variableName = 'variableName'
foo(getattr(__main__, variableName))
This should print
This is a test.
variableName
The import of the main module is necessary for variables from the main scope.
You can resolve the value of myobjectfrom the module where it is defined with getattr. If it is in the main module, this should work:
import __main__
mystring = 'This is a test.'
def foo(object):
print object
foo(getattr(__main__, 'mystring'))
This should print
This is a test.
The import of the main module is necessary for variables from the main scope.
You can resolve the value of myobjectfrom the module where it is defined with getattr. If it is in the main module, this should work:
import __main__
mystring = 'This is a test.'
def foo(object):
print object
variableName = 'mystring'
foo(getattr(__main__, variableName))
variableName = 'variableName'
foo(getattr(__main__, variableName))
This should print
This is a test.
variableName
The import of the main module is necessary for variables from the main scope.