-
-
Notifications
You must be signed in to change notification settings - Fork 592
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
Use import_set #166
Comments
Read a file and set the contents as input to the function import_set. import tablib
data = open("test.csv").read()
dataset = tablib.import_set(data)
header = dataset.headers
rows = dataset._data
for row in rows:
print row |
i've tried the csvfiles = glob.glob( 'backup_db/{date}/*.csv'.format( date=args[0] ) ) # args[0] = '2015_05_02' (like year, month, day)
for csvf in csvfiles : # csvf = 'backup_db/2015_05_02/SomeModel.csv'
#print( 'importing ' , csvf , '\n' , ''.join(open(csvf,'r')) )
dataset = tablib.import_set( open(csvf,'r').read() )
print( 'dataset -> ' , dataset ) # None
modelname = os.path.basename(csvf)[:-4]
print( modelname+'Resource' )
model = getattr(admin,modelname+'Resource')()
print(dataset)
model.import_data(dataset=dataset,dry_run=True) # Error - > 'NoneType' object has no attribute 'dict' |
Same issue. >>> import tablib
>>> print tablib.import_set(open("derp.xls", "rb"))
None File is existing |
Just encountered this issue with a CSV file. When using |
Please reopen if you still have issues on the latest release. |
It seems it's not documented how to import a file and loop through the rows and columns.
Can someone help me out with a small example?
In the API the function import_set() is listed, but I don't know how to use this function.
The text was updated successfully, but these errors were encountered: