Python Forum
Getting a small Python2 prog to run in Python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a small Python2 prog to run in Python3
#1
Hi All,

I started to learn Python a few years ago, and wrote my only useful program in python2 - which I use all the time.

I want to start learning python again (py3), but when I install py3 my useful program won't run (it just flashes a window and closes).

I've forgotten everything I previously learnt, is there a 'fix quick' problem that jumps out as to why it wont run in py3 ?


It's a very simple program that monitors the clipboard for a block of text (they are links), and when it finds some it converts them into a block of links suitable for inserting into a webpage

Eg it finds on the clipboard

h+tp://anysite.com/file/textfile1
h+tp://anysite.com/file/textfile2


it converts that to
<a href=http://anysite.com/file/textfile1 target=_blank>http://anysite.com/file/textfile1</a>
<a href=http://anysite.com/file/textfile2 target=_blank>http://anysite.com/file/textfile2</a>

Then puts that new links back on the clipboard ready for pasting.


I have installed
Python2.7.13 (x86)
Pythoncard 0.8.2 (x86)
Pywin32-218
wxpython3.0 (x86)

I want to install Python3.

Thank you for any help,

Steve

import win32clipboard as w
import sys, time

def cleanboard():
    w.OpenClipboard(0)
    w.SetClipboardText('')
    w.CloseClipboard()

LastData=''
templine2=''
amountOfLines=0


cleanboard()


while 1:
    time.sleep(1)

    w.OpenClipboard()
    data=w.GetClipboardData()
    w.CloseClipboard()

    nullIndex=data.find('\0')
    if nullIndex != -1:
        data=data[:nullIndex]


    if data != LastData:
        LastData=data
        linkstoprint=[]
        templine2=''
        amountOfLines = len(data.splitlines());



        ref=0
        while ref < amountOfLines:
            line = data.splitlines()
            templine1=line[ref]
            templine1 = '<a href='+str(templine1)+' target=_blank>'+str(templine1)+'</a>'
            linkstoprint.append(templine1)
            ref=ref+1

        for i in range (0,amountOfLines):
            templine2=templine2+linkstoprint[i]+'\n'


        templine2=str(templine2)
        w.OpenClipboard(0)
        w.EmptyClipboard()
        w.SetClipboardText(templine2)
        w.CloseClipboard()
        LastData=str(templine2)
Reply


Messages In This Thread
Getting a small Python2 prog to run in Python3 - by steve140 - Apr-19-2020, 08:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Sad Migrating of python2 script to python3 zuri 7 1,304 Oct-05-2023, 02:40 PM
Last Post: snippsat
  Migration of Python2 and Python3 using Modernize and Future Rakshan 5 2,769 Oct-05-2023, 08:55 AM
Last Post: zuri
  python2 python3 messed up : How to fix ? hary 15 8,468 Dec-30-2020, 08:26 PM
Last Post: hary
  output mismatching when porting a python from python2 env to python3 env prayuktibid 2 2,747 Jan-21-2020, 04:41 AM
Last Post: prayuktibid
  python3 decoding problem but python2 OK mesbah 0 1,905 Nov-30-2019, 04:42 PM
Last Post: mesbah
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 5,120 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  python prog davy_yg 0 2,726 Sep-25-2019, 02:23 AM
Last Post: davy_yg
  Trying to run a python2 script dagamer1991 3 2,675 Aug-12-2019, 12:33 PM
Last Post: buran
  python2.7 executables thus the system python2.7 was erroring utility.execute()? vivekm 1 1,858 May-20-2019, 11:24 AM
Last Post: vivekm
  Python2 is not supported Skaperen 2 2,302 Mar-01-2019, 07:50 PM
Last Post: stranac

Forum Jump:

User Panel Messages

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