Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 2 to 3 Issue
#1
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
Reply
#2
There are differences. See: https://docs.python.org/3/howto/pyporting.html
Reply
#3
(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
Reply
#4
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"
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020