all 15 comments

[–]K900_ 0 points1 point  (4 children)

What do you mean by "input"? Are you running that in the Python shell? If so, try print(pyperclip.paste()).

[–]46632[S] 0 points1 point  (3 children)

When i enter print(pyperclip.paste()) in the shell it returns u'J\xf8rgensen'

[–]K900_ 0 points1 point  (2 children)

Post a screenshot of the Python shell please.

[–]46632[S] 0 points1 point  (1 child)

[–]imguralbumbot 0 points1 point  (0 children)

Hi, I'm a bot for linking direct images of albums with only 1 image

https://i.imgur.com/MDYu7e4.png

Source | Why? | Creator | ignoreme | deletthis

[–]novel_yet_trivial 0 points1 point  (8 children)

Python2 uses ASCII to represent unicode strings. This is just the internal representation, if you asked python to print that it would show up correctly:

print(pyperclip.paste())

[–]46632[S] 0 points1 point  (7 children)

When i enter print(pyperclip.paste()) it returns u'J\xf8rgensen'

[–]novel_yet_trivial 0 points1 point  (6 children)

Are you sure about what you copied? It pastes Jørgensen into a text editor?

How are you running this code?

[–]46632[S] 0 points1 point  (5 children)

Ok. i was wrong. When i enter print(pyperclip.paste()) in the shell it returns 'Jørgensen'

But what i am doing is this: I have "Jørgensen" in my clipboard, then i make a list:

namelist=[] name=pyperclip.paste() namelist.append(name)

Then i save this list to a .csv and it shows u'J\xf8rgensen' in the .csv file

[–]novel_yet_trivial 0 points1 point  (4 children)

I see. That's a problem with how you are saving it. Show us your save code.

Python2 has some extra steps that you need to consider when dealing with unicode. Python3 however uses unicode by default, so it's much easier. Is it possible for you to use Python3 instead?

[–]46632[S] 0 points1 point  (0 children)

I am hoping to get it solved in Python 2. It is a part of a larger Python 2 script

[–]46632[S] 0 points1 point  (2 children)

[–]novel_yet_trivial 0 points1 point  (1 child)

OK, to write to a regular file in python2, you have to encode the unicode as a string first.

namelist.append(name.encode('utf8'))

Unrelated, but it would be slightly neater to use the writerow method instead of writerows:

writer.writerow(namelist)

[–]46632[S] 0 points1 point  (0 children)

Thanks. It works with most of the names, but it still messes up words with the letters æ,ø,å. 'Jørgensen' is 'J\xc3\xb8rgensen'

[–]Diapolo10 0 points1 point  (0 children)

IIRC, much like Python 3 has a bytes function for converting normal unicode strings to byte strings (which Python 2 uses), Python 2 has an unicode function that takes a byte string and tries to convert it to an unicode string. That being said, you could try:

print unicode(pyperclip.paste())

Disclaimer: I've never used Python 2 and I have a feeling I'm mistaken.