nickmilon / mongoutils Goto Github PK
View Code? Open in Web Editor NEWUtilities for mongoDB mainly based on pymongo python mongoDB driver
License: Apache License 2.0
Utilities for mongoDB mainly based on pymongo python mongoDB driver
License: Apache License 2.0
hi,
In parsing my excel sheet, I instructed the library to use the first row as the field name. However, it runs into an error if the first row is not a string.
The exception
Original exception was:
Traceback (most recent call last):
File "/home/wale/PycharmProjects/MongoImport3.6/TEST.py", line 14, in <module>
res = importsExports.import_workbook(args.fileName, MongoClient()[args.dbName], fields=True)
File "/usr/local/lib/python3.6/dist-packages/mongoUtils/importsExports.py", line 37, in import_workbook
for i in range(0, workbook.nsheets)]
File "/usr/local/lib/python3.6/dist-packages/mongoUtils/importsExports.py", line 37, in <listcomp>
for i in range(0, workbook.nsheets)]
File "/usr/local/lib/python3.6/dist-packages/mongoUtils/importsExports.py", line 143, in __init__
self.auto_field_names(fields)
File "/usr/local/lib/python3.6/dist-packages/mongoUtils/importsExports.py", line 161, in auto_field_names
self._fields_or_fun = [self.fix_name(fn, cnt) for cnt, fn in enumerate(row0_values)]
File "/usr/local/lib/python3.6/dist-packages/mongoUtils/importsExports.py", line 161, in <listcomp>
self._fields_or_fun = [self.fix_name(fn, cnt) for cnt, fn in enumerate(row0_values)]
File "/usr/local/lib/python3.6/dist-packages/mongoUtils/importsExports.py", line 156, in fix_name
return name.replace(' ', '_').replace('.', '_').replace('$', '_')
AttributeError: 'int' object has no attribute 'replace'
The source of the exception
def fix_name(self, name, cnt=0):
if name == '':
return 'fld_{}'.format(cnt)
else:
return name.replace(' ', '_').replace('.', '_').replace('$', '_')
A potential fix is to first cast the name to a string in the event the field name is not a string
def fix_name(self, name, cnt=0):
if name == '':
return 'fld_{}'.format(cnt)
else:
return str(name).replace(' ', '_').replace('.', '_').replace('$', '_')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.