• Writing to clipboard in Python 3.11

    From Rob Cliffe@21:1/5 to All on Mon Nov 6 00:51:03 2023
    Recently I switched from Python 3.8.3 to Python 3.11.4.  A strange
    problem appeared which was not there before:
    I am using the win32clipboard backage (part of pywin32), and when I use SetClipboardData() to write text which consists ENTIRELY OF DIGITS to
    the clipboard, I either get an error (not always the same error message)
    or a program crash.  The problem does not appear if I use
    SetClipboardText() instead.
    Sample program:

    from win32clipboard import *
    OpenClipboard()
    SetClipboardData(CF_UNICODETEXT, "A")
    SetClipboardData(CF_UNICODETEXT, "A0")
    SetClipboardData(CF_UNICODETEXT, "0A")
    SetClipboardText("0", CF_UNICODETEXT)
    print("OK so far")
    SetClipboardData(CF_UNICODETEXT, "0")
    CloseClipboard()

    Sample output:

    OK so far
    Traceback (most recent call last):
      File "R:\W.PY", line 8, in <module>
        SetClipboardData(CF_UNICODETEXT, "0")
    pywintypes.error: (0, 'SetClipboardData', 'No error message is available')

    I can get round the problem by using SetClipboardText().  But can anyone
    shed light on this?
    Best wishes
    Rob Cliffe

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to Rob Cliffe via Python-list on Tue Nov 7 17:01:33 2023
    On 2023-11-06 00:51, Rob Cliffe via Python-list wrote:
    Recently I switched from Python 3.8.3 to Python 3.11.4.  A strange
    problem appeared which was not there before:
    I am using the win32clipboard backage (part of pywin32), and when I use SetClipboardData() to write text which consists ENTIRELY OF DIGITS to
    the clipboard, I either get an error (not always the same error message)
    or a program crash.  The problem does not appear if I use
    SetClipboardText() instead.
    Sample program:

    from win32clipboard import *
    OpenClipboard()
    SetClipboardData(CF_UNICODETEXT, "A")
    SetClipboardData(CF_UNICODETEXT, "A0")
    SetClipboardData(CF_UNICODETEXT, "0A")
    SetClipboardText("0", CF_UNICODETEXT)
    print("OK so far")
    SetClipboardData(CF_UNICODETEXT, "0")
    CloseClipboard()

    Sample output:

    OK so far
    Traceback (most recent call last):
      File "R:\W.PY", line 8, in <module>
        SetClipboardData(CF_UNICODETEXT, "0")
    pywintypes.error: (0, 'SetClipboardData', 'No error message is available')

    I can get round the problem by using SetClipboardText().  But can anyone shed light on this?

    It also happens in Python 3.10, but not Python 3.9.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Rob Cliffe via Python-list on Tue Nov 7 13:08:00 2023
    On 11/5/2023 7:51 PM, Rob Cliffe via Python-list wrote:
    Recently I switched from Python 3.8.3 to Python 3.11.4.  A strange
    problem appeared which was not there before:
    I am using the win32clipboard backage (part of pywin32), and when I use SetClipboardData() to write text which consists ENTIRELY OF DIGITS to
    the clipboard, I either get an error (not always the same error message)
    or a program crash.  The problem does not appear if I use
    SetClipboardText() instead.
    Sample program:

    from win32clipboard import *
    OpenClipboard()
    SetClipboardData(CF_UNICODETEXT, "A")
    SetClipboardData(CF_UNICODETEXT, "A0")
    SetClipboardData(CF_UNICODETEXT, "0A")
    SetClipboardText("0", CF_UNICODETEXT)
    print("OK so far")
    SetClipboardData(CF_UNICODETEXT, "0")
    CloseClipboard()

    Sample output:

    OK so far
    Traceback (most recent call last):
      File "R:\W.PY", line 8, in <module>
        SetClipboardData(CF_UNICODETEXT, "0")
    pywintypes.error: (0, 'SetClipboardData', 'No error message is available')

    I can get round the problem by using SetClipboardText().  But can anyone shed light on this?

    No, but I use pyperclip. It's cross platform. Maybe it doesn't have
    this problem, though I don't know for sure.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jim Schwartz@21:1/5 to Rob Cliffe via Python-list on Tue Nov 7 12:52:28 2023
    It doesn't work in python 3.12.0

    -----Original Message-----
    From: Python-list <python-list-bounces+jschwar=sbcglobal.net@python.org> On Behalf Of Thomas Passin via Python-list
    Sent: Tuesday, November 7, 2023 12:08 PM
    To: python-list@python.org
    Subject: Re: Writing to clipboard in Python 3.11

    On 11/5/2023 7:51 PM, Rob Cliffe via Python-list wrote:
    Recently I switched from Python 3.8.3 to Python 3.11.4. A strange
    problem appeared which was not there before:
    I am using the win32clipboard backage (part of pywin32), and when I
    use
    SetClipboardData() to write text which consists ENTIRELY OF DIGITS to
    the clipboard, I either get an error (not always the same error
    message) or a program crash. The problem does not appear if I use SetClipboardText() instead.
    Sample program:

    from win32clipboard import *
    OpenClipboard()
    SetClipboardData(CF_UNICODETEXT, "A")
    SetClipboardData(CF_UNICODETEXT, "A0")
    SetClipboardData(CF_UNICODETEXT, "0A") SetClipboardText("0",
    CF_UNICODETEXT) print("OK so far") SetClipboardData(CF_UNICODETEXT,
    "0")
    CloseClipboard()

    Sample output:

    OK so far
    Traceback (most recent call last):
    File "R:\W.PY", line 8, in <module>
    SetClipboardData(CF_UNICODETEXT, "0")
    pywintypes.error: (0, 'SetClipboardData', 'No error message is
    available')

    I can get round the problem by using SetClipboardText(). But can
    anyone shed light on this?

    No, but I use pyperclip. It's cross platform. Maybe it doesn't have this problem, though I don't know for sure.

    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)