Python Forum
Python 2 to 3 Issue - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python 2 to 3 Issue (/thread-2854.html)



Python 2 to 3 Issue - Kekerusey - Apr-15-2017

Hi,

I'm new here but a long time dabbler in Python ... I won't post any code just yet, don't want you laughing at me quite so soon ;)

OK ... so I have almost exclusively used Python 2 so far because, as far as I knew, PyWin32 only went as far as that. A few days back I found out I was wrong, that not only was there a PyWin32 for Python 3.5 there was also a 64bit version of both (even if the 64bit version of PyWin was still called PyWin32). So I installed Python 3.5.3 64 and PyWin 32-219. My OS is the most recent Windows 10 Pro.

Since then, my python backup program, won't run ... I have no real idea why. In fact, I'm not even sure PyWin is installing correctly since (right now) I can't run the PyWin editor.

So my question is, is there a python 3 64 bit compatible version of PyWin?

Thx

Keke


RE: Python 2 to 3 Issue - Larz60+ - Apr-15-2017

There are differences. See: https://docs.python.org/3/howto/pyporting.html


RE: Python 2 to 3 Issue - Kekerusey - Apr-16-2017

(Apr-15-2017, 02:01 PM)Larz60+ Wrote: There are differences. See: https://docs.python.org/3/howto/pyporting.html

Gah, that looks complicated.

OK, so I've sorted the actual running of Python 3 and PyWin ... I installed Python 3.6 and PyWin 3.6, both 32 bit (for now). I started looking at the code and it appears Python 3.x handles things a bit differently from 2.x.

For example, "print 1" ( which prints a 1 logically enough) doesn't work under python 3, it requires me to use "print (1)" ... that was an easy fix since "print" wasn't used much except to print out messages as my program ran, so I commented them out. Simples.

More bafflingly I assign a value to a string in my program:

>>> sINIFile = "C:\Utilities\jpybak\jpybak.ini"

That now requires me to put an additional "\":

>>> sINIFile = "C:\\Utilities\jpybak\jpybak.ini"

Weird, I don't really get why they changed things but I finally got the program working.

Thx

Keke


RE: Python 2 to 3 Issue - sparkz_alot - Apr-16-2017

As you discovered, there were changes between Python 2 and Python 3, two major ones are 'raw_input' became 'input' and 'print' became 'print()'.  You can run 2to3 and it will try to convert as much as it can.

As to your example
Quote:sINIFile = "C:\Utilities\jpybak\jpybak.ini"

can be avoided by either by
sINIFile = r"C:\Utilities\jpybak\jpybak.ini"

or
sINIFile = "C:/Utilities/jpybak/jpybak.ini"


RE: Python 2 to 3 Issue - Larz60+ - Apr-16-2017

It's really not that complicated at all. I converted a package with around 50 modules in about 1 hour.
You will gain so much by moving to python 3, especially 3.6