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

csv writer does not work in Python 2 #217

Closed
KittelC opened this issue May 23, 2019 · 4 comments
Closed

csv writer does not work in Python 2 #217

KittelC opened this issue May 23, 2019 · 4 comments

Comments

@KittelC
Copy link
Contributor

KittelC commented May 23, 2019

Hello!

I recently updated to v. 1.5.1 and ran into the following error message (I am using Python 2.7):

In the script csv.py, the line:
self.db.write(str(','.join(self.header) + '\n'))
produces TypeError: write() argument 1 must be unicode, not str

The error seems to come from the line above
self.db = io.open(self.dbname + '.csv', 'w')

The native open function supports string as input, or the file must be opened in "wb" mode instead of only "w" (see: https://stackoverflow.com/questions/18449233/2-7-csv-module-wants-unicode-but-doesnt-want-unicode )

thouska added a commit that referenced this issue May 27, 2019
@thouska
Copy link
Owner

thouska commented May 27, 2019

Thank you for reporting this issue and I warmly appreciate your solution suggestion. I implemented it accordingly.

bees4ever added a commit to bees4ever/spotpy that referenced this issue Jun 4, 2019
* master: (29 commits)
  Updated the statistics output
  Updated fscabc
  Updated fscabc
  Fix for thouska#217
  Update version number
  Update new style of Rosenbrock example on docs thouska#213
  Add missing keyword, fix for thouska#213
  Update version number
  Add basic test for parallel computing
  Remove altobjfunc from dream example
  Enlarge runs for dream in unittest
  Update Test script for rosenbrock setup thouska#213
  Update new style of rosenbrock_setup
  Fix for thouska#213
  Making status print more informativ
  Remov Gelman Rubin plot from test suite for Python < 3.6
  Remove Hymod support for Python <3.6
  Remove copy functions for py2 support
  Add classmethod statement
  WIP fix Python 2 errors
  ...

# Conflicts:
#	spotpy/__init__.py
#	spotpy/algorithms/_algorithm.py
@philippkraft
Copy link
Collaborator

I would not suggest to follow that path. A .csv file is a text file and I see no reason to handle it as a binary file. It is the problem of Python 2, which is falling out of support soon, to handle text and binary data in an inconsistant way. I would rather remove the str(...), since the result of join is str in Python 3 and unicode or str in Python 2 anyway.

@MuellerSeb
Copy link
Contributor

I would let this die with dropping py2 support following https://python3statement.org/

@thouska
Copy link
Owner

thouska commented Apr 13, 2021

And some point I will clean up the code with all this stuff that was necessary to be able to support py2 and py3 versions.
Since versions >=1.5.13 spotpy is not tested any more for py2, i.e. support was dropped.

@thouska thouska closed this as completed Apr 13, 2021
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

4 participants