Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasattr() getattr() setattr() #23

Open
westurner opened this issue Nov 21, 2014 · 0 comments
Open

hasattr() getattr() setattr() #23

westurner opened this issue Nov 21, 2014 · 0 comments

Comments

@westurner
Copy link
Contributor

http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-1-Introduction-to-Python-Programming.ipynb#Type-utility-functions

Something like:

import collections
from collections import OrderedDict
_Thing = collections.namedtuple('_Thing', ('attr1', 'attr2'))
class Thing(_Thing):
    pass

values = [
    True,
    0b01,
    0x42,
    1e42,
    42,
    42.0,
    "str",
    [1,2,3],
    (1,2,3,),  # tuples are immutable (but their references are not)
    {1,2,3},
    {'one':1,'two':2},
    OrderedDict([('one',1), ('two', 2)]),
    Thing(attr1=1, attr2=2),
    (x for x in range(4)),
    [x for x in range(2)],
]
print("# type, obj, iter(obj), list(iter(obj))")
for obj in values:
    output = (type(obj), obj, iter(obj), list(iter(obj))) if hasattr(obj, '__iter__') else (obj,)
    print(obj)

# ...

# * https://docs.python.org/3/whatsnew/2.7.html#python-3-1-features

And then something about tablib, dataset, pandas etc for reading/writing actual safe CSV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant