-
Notifications
You must be signed in to change notification settings - Fork 13
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
Fill objects from CSV #8
Comments
+1 I'm currently working on this. The class would be the actual "model". The spec would be something like: class ProductModel(object):
def __init__(self, title, price, currency, url, image_url=None):
self.title = title
self.price = price
self.currency = currency
self.url = url
self.image_url = image_url
with open('my-csv.csv', 'r') as f:
reader = smartcsv.reader(f, columns=COLUMNS_1, model=ProductModel) |
sweet. what do you think about some hooks or signals? Im sure there are other usecases for hooks/signals. |
I don't understand. How would it work? Can you do a quick code sample? |
|
I'm currently working with a simplified version of it. It'll be out soon. Just to be clear, you could easily do what you say in different ways: reader = smartcsv.reader(...)
# 1 way
for obj in reader:
commitToDb(obj)
# 2 way (directly in the for)
for obj in reader:
db.session.add(obj)
db.session.commit()
# other way
[commitToDb(obj) for obj in reader] |
It would be nice to be able to give the parser an class and have it create and fill it in. The given example would create those, and return them as a list or set.
The text was updated successfully, but these errors were encountered: