-
Notifications
You must be signed in to change notification settings - Fork 90
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
No isinstance unicode in Python3 #51
Comments
It might be cleaner to keep that conditional statement as is. At the top of the module you could do this: is_python3 = sys.version_info.major == 3
if is_python3:
unicode = str Then, all references to |
@tsroten Oh sweet, I've never thought of that! that looks good! Thanks, I know that unicodecsv isn't really testing for Python3, but I'll incorporate in my code 👍 |
This is probably a bit of a newb question, especially since I'm just making the transition from Python 2 to 3, but doesn't Python 3's If so, then you can just do:
|
Python 3 does handle Unicode in the CSV module, however when you build your
code to work for both versions you will eventually have your code break at
the `isinstance` function since the `unicode` variable doesn't exist in
Python 3. This little code piece helps solve this issue.
|
I've added py3 in 0.12.0 - please try it out and open another issue if you find specific problems. :) |
The isinstance statement with unicode does not exist in python3:
Here's how I fixed it in my versions, but I still don't know if it's actually the best way to test unicode so I won't do a pull request unless someone can tell me it's actually correct.
Python3 error
Traceback (most recent call last):
File "/home/denis/Github/ACAPS-tools/parser.py", line 166, in
export('Guinea_Locations_Export.csv', ['google', 'bing', 'osm'])
File "/home/denis/Github/ACAPS-tools/parser.py", line 124, in export
writer.writeheader()
File "/usr/local/lib/python3.4/dist-packages/unicodecsv/init.py", line 158, in writeheader
self.writerow(header)
File "/usr/lib/python3.4/csv.py", line 153, in writerow
return self.writer.writerow(self._dict_to_list(rowdict))
File "/usr/local/lib/python3.4/dist-packages/unicodecsv/init.py", line 86, in writerow
return self.writer.writerow(_stringify_list(row, self.encoding, self.encoding_errors))
File "/usr/local/lib/python3.4/dist-packages/unicodecsv/init.py", line 51, in _stringify_list
return [_stringify(s, encoding, errors) for s in iter(l)]
File "/usr/local/lib/python3.4/dist-packages/unicodecsv/init.py", line 51, in
return [_stringify(s, encoding, errors) for s in iter(l)]
File "/usr/local/lib/python3.4/dist-packages/unicodecsv/init.py", line 41, in _stringify
if isinstance(s, unicode):
NameError: name 'unicode' is not defined
The text was updated successfully, but these errors were encountered: