From: Benny M. <ben...@gm...> - 2013-02-19 13:47:46
|
2013/2/19 Enno Borgsteede <enn...@gm...> > Hi Benny, > > python 2 behaves different because of pieces like: >> >> if sys.version_info[0] < 3: >> try: >> filepath = os.path.join(DATA_DIR, "gedcom.xml") >> ged_file = open(filepath.encode('iso8859- >> 1'), "r") >> except: >> return >> else: >> try: >> filepath = os.path.join(DATA_DIR, "gedcom.xml") >> ged_file = open(filepath, "rb") >> except: >> return >> the first part is the code from gramps 3.4, which is working at the >> moment. >> > John reminded me that this is not the actual GEDCOM, and to tell you the > truth, I have no idea why this code is there. I know that it's used, but in > the mean time I found the opening of the actual GEDCOM in importgedcom.py: > > if sys.version_info[0] < 3: > ifile = open(filename, "rU") > else: > ifile = open(filename, "rb") > > I wonder what will happen when I change that to "rb". The < 3 codepath is the old code which is well tested and is working at the moment in version 3.4. So there should be no need to change that, or a lot things will have to be changed. If things fail for you in python 2, it is because somebody changed something somewhere else since the 3.4 code. Benny > > So if you now have a fail with that, something somewhere else changed. >> Even if you only do the else part in your change, python2 might still >> behave different because the conversion functions that are used behave >> different. >> See what is imported from constfunc, eg cuni, ... >> > You mean things like this (in importgedcom.py): > > from gramps.gen.constfunc import STRTYPE > > Things like that probably explain why the if that gave me a problem, works > OK in a python shell, where nothing special is imported. > > I see lots of 'interesting' imports in libgedcom.py too, like: > > from __future__ import print_function, unicode_literals > > if sys.version_info[0] < 3: > from cStringIO import StringIO > else: > from io import StringIO > > But I tend to leave them as is, assuming that they were put there for a > reason. > > Latest news: When I change the open mentioned above to "rb" for all python > versions, my RootsMagic GEDCOM file still imports OK, but the b's before > the string literals are still needed. I think I can live with that, > especially when someone else can test the attached PAF GEDCOM with python 3. > > thanks, > > Enno > > |