sfepy/sfepy — Issue #162: Test for "basestring" instead of "str"
Author: rc
Created: 2012-01-30 10:27:44+00:00
State: open

Please replace occurences of isinstance(something, str) by isinstance(something, basestring). This is an easy change, and it makes it more convenient to use SfePy with

from __future__ import unicode_literals

Otherwise, you have to say e.g.

mesh = Mesh.from_file(b'rectangle_tri.mesh')

(The "b" would become superfluous.)

Migrated from http://code.google.com/p/sfepy/issues/detail?id=160

earlier comments

robert.cimrman said, at 2011-12-20T13:14:47.000Z:

Looks like a good thing to do, thanks for creating the issue.

Do you have other ideas to python 3 compatibility?

torsten.bronger said, at 2011-12-20T13:27:38.000Z:

Import as many future statemens as feasible ("division", "absolute_imports", "unicode_literals", "print_function") in every module. "division" and "absolute_imports" are especially interesting in my opinion.

Replace % with .format().

By the way, for Python 3, the "basestring" has got to be re-changed to "str". But this will be done by 2to3 automatically.

robert.cimrman said, at 2011-12-21T11:11:30.000Z:

I would like to have a way that would work both for python 2 with "from __future__ import unicode_literals" and python 3. Would using types.StringType help?

I do not have a working python 3 installation yet, still using 2.6.6... I can try 2.7. and use -3 flag to simulate it, right?

I will create a new issue for python 3 porting to discuss this.

torsten.bronger said, at 2011-12-21T12:02:54.000Z:

You can start the modules with

try:
basestring
except:
basestring = str

robert.cimrman said, at 2011-12-21T12:38:40.000Z:

Could you test using "git clone git://github.com/rc/sfepy.git"?

torsten.bronger said, at 2011-12-21T15:19:29.000Z:

Sorry, not this year. I don't use Git but the plain release. I'll look into it on the first days of the new year.

robert.cimrman said, at 2011-12-22T11:14:43.000Z:

Ok, thanks! As a sidenote: using git is not that difficult, and you get fresh fixes easily, see [1].

[1] http://docs.sfepy.org/doc-devel/dev/gitwash/index.html#using-git

torsten.bronger said, at 2012-01-02T16:16:59.000Z:

Yes, it has worked. No "b" was necessary anymore. Thank you!

robert.cimrman said, at 2012-01-02T16:18:58.000Z:

Thanks for verifying, let's close this.