how to convert string to list or tuple
Duncan Booth
duncan.booth at invalid.invalid
Wed Jun 1 04:30:05 EDT 2005
Steven Bethard wrote:
> Interestingly, I don't seem to be able to create a file object as a
> class attribute in restricted mode:
>
> py> class C(object):
> ... def __init__(self):
> ... self.f = file('temp.txt', 'w')
> ...
> py> eval('''[ cls for cls in
> {}.__class__.__bases__[0].__subclasses__() if cls.__name__ ==
> 'C'][0]().f.write("stuff")''', dict(__builtins__=None)) Traceback
> (most recent call last):
> File "<interactive input>", line 1, in ?
> File "<string>", line 0, in ?
> AttributeError: 'C' object has no attribute 'f'
> py> eval('''[ cls for cls in
> {}.__class__.__bases__[0].__subclasses__() if cls.__name__ ==
> 'C'][0]().__dict__''', dict(__builtins__=None)) {}
>
Weird. I copied and paste your class and eval exactly (apart from deleting
the ... prompts) and it worked exactly as expected: writing 'stuff' to
temp.txt. (Python 2.4)
More information about the Python-list
mailing list