0

I have created Python classes by an XML schema file using generateDS2.12a. I am using these classes to create XML files. My module works well with a Python 2.7 environment.

Now, due to some reason my environment is changed to Python 3.0.0. Now when I try to export the XML object it is throwing me following error:

Function : export(self, outfile, level, namespace_='', name_='rootTag', namespacedef_='', pretty_print=True)

Error : s1 = (isinstance(inStr, basestring) and inStr or NameError: global name 'basestring' is not defined

Is there a change I need to do to export XML in Python 3.0.0 or a new version of GenerateDS to be used for Python 3.0.0?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Manu
  • 67
  • 2
  • 3
  • 8
  • Something had to change your Python version. Did you change or update a Linux system? To run with 3.c, you need a version of generateDS intended to run with 3.x. 3.0.0 should not be used. Use the latest 3.3 or 3.4. – Terry Jan Reedy Oct 16 '14 at 22:20
  • To fix that particular error, replace 'basestring' with '(str, bytes)'. But I suspect there would be other problems if you do. – Terry Jan Reedy Oct 16 '14 at 22:22
  • Thanks for reply. Yes as per my project requirements, the python version was upgraded from 2.7 to 3.0. Your solution of changing basestring with ('str', bytes) didn't work. – Manu Oct 17 '14 at 03:40
  • Hi Terry, I was able to achieve the above by converting my xml Class.py file using 2to3.py script and also able to export the data into XML. But now the xml files contains all the string values within b''. Can you suggest how to encode these string values ? Thanks in Advance – Manu Oct 17 '14 at 09:20
  • 2.x string literals *are* encoded bytes literals. They are ascii or perhaps latin-1 encoded unless there is an encoding declaration. 2to3 leave then as they are, but some may need to become 3.x string == 2.x unicode literals. The 3.x have several How-Tos. The first is about conversion. – Terry Jan Reedy Oct 18 '14 at 07:57

1 Answers1

0

You could run generateDS to get your Python file then run, e.g.,

"2to3 -w your_python_file.py" to generate a Python 3 version of your generateDS file.

I'm went through the same process and I had luck with this. It looks to work just fine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yablargo
  • 3,520
  • 7
  • 37
  • 58
  • Hi Yablargo, Thanks for reply. I was able to generate xml as well but the problem is that when i tried to export xml, it has all string value with b'' literal. How you solved that ? – Manu Nov 05 '14 at 09:17