Ich habe folgendes Problem und verstehe es nicht......
Ziel ist es ein simples Skript zu erstellen welches einfach aus der Zwischenablage den inhalt ausliest und dann von den zeichen '!()-[]{};:'"\,<>./?@#$%^&*_~ befreit.
Aber IDLE meckert jedesmal über die "If Char in" Zeile.... Wenn ich allerdings nicht den String aus der Zwischenablage nehme sondern manuell per "Input()" einen String erzeuge gehts......
Kann mir da jemand helfen?
Code: Alles auswählen
import ctypes
import string
CF_TEXT = 1
kernel32 = ctypes.windll.kernel32
kernel32.GlobalLock.argtypes = [ctypes.c_void_p]
kernel32.GlobalLock.restype = ctypes.c_void_p
kernel32.GlobalUnlock.argtypes = [ctypes.c_void_p]
user32 = ctypes.windll.user32
user32.GetClipboardData.restype = ctypes.c_void_p
def get_clipboard_text():
user32.OpenClipboard(0)
try:
if user32.IsClipboardFormatAvailable(CF_TEXT):
data = user32.GetClipboardData(CF_TEXT)
data_locked = kernel32.GlobalLock(data)
text = ctypes.c_char_p(data_locked)
value = text.value
kernel32.GlobalUnlock(data_locked)
return value
finally:
user32.CloseClipboard()
s = get_clipboard_text()
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
input_str = s
print (s)
final_str = ""
for char in input_str:
if char not in punctuations:
final_str += char
print(final_str)
Code: Alles auswählen
Traceback (most recent call last):
File "G:\Zwischenablage .py", line 33, in <module>
if char not in punctuations:
TypeError: 'in <string>' requires string as left operand, not int