I have a main script, which imports another python library that I've been writing. The library contains the following command:
print getattr(__builtins__, "list")
This produces the following error when I call it from the library:
'dict' object has no attribute 'list'
But, if I copy and paste that same command into the main script it works fine. Any ideas why this isn't working?
The header of my main file looks like this:
#/usr/bin/env python
from sys import argv
import re, sys, os, argparse
sys.path.extend(map(os.path.abspath, ['C:/Users/xxxx/scripts/modules/']))
import general
The header for my "general" library is:
#!/usr/bin/env python
from sys import argv
import re, sys, os, argparse
def getBuiltin(name):
##Convert a string into an attribute
try:
return getattr(__builtins__, name)
except Exception as e:
print "Unhandled type in function \"get_builtin\""
print name
print e
exit()
I was calling the library like this:
print general.getBuiltin("list")
where, "getBuiltin" is the name of my function