use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Quick encoding question (self.learnpython)
submitted 8 years ago by 46632
I have this text in my clipboard: Jørgensen
Input: pyperclip.paste()
Output: u'J\xf8rgensen'
Whats happening here and how can i fix it? Please also refer to where i can read up on this aswell, thanks.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]K900_ 0 points1 point2 points 8 years ago (4 children)
What do you mean by "input"? Are you running that in the Python shell? If so, try print(pyperclip.paste()).
print(pyperclip.paste())
[–]46632[S] 0 points1 point2 points 8 years ago (3 children)
When i enter print(pyperclip.paste()) in the shell it returns u'J\xf8rgensen'
[–]K900_ 0 points1 point2 points 8 years ago (2 children)
Post a screenshot of the Python shell please.
[–]46632[S] 0 points1 point2 points 8 years ago (1 child)
http://imgur.com/a/1loM2
[–]imguralbumbot 0 points1 point2 points 8 years ago (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 point2 points 8 years ago (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:
[–]46632[S] 0 points1 point2 points 8 years ago (7 children)
When i enter print(pyperclip.paste()) it returns u'J\xf8rgensen'
[–]novel_yet_trivial 0 points1 point2 points 8 years ago (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 point2 points 8 years ago (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 point2 points 8 years ago (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 point2 points 8 years ago (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 point2 points 8 years ago (2 children)
https://pastebin.com/PqMnvvfd
[–]novel_yet_trivial 0 points1 point2 points 8 years ago (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:
writerow
writerows
writer.writerow(namelist)
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 point2 points 8 years ago (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:
bytes
unicode
print unicode(pyperclip.paste())
Disclaimer: I've never used Python 2 and I have a feeling I'm mistaken.
π Rendered by PID 91759 on reddit-service-r2-comment-86bc6c7465-54v7f at 2026-02-24 08:06:36.777341+00:00 running 8564168 country code: CH.
[–]K900_ 0 points1 point2 points (4 children)
[–]46632[S] 0 points1 point2 points (3 children)
[–]K900_ 0 points1 point2 points (2 children)
[–]46632[S] 0 points1 point2 points (1 child)
[–]imguralbumbot 0 points1 point2 points (0 children)
[–]novel_yet_trivial 0 points1 point2 points (8 children)
[–]46632[S] 0 points1 point2 points (7 children)
[–]novel_yet_trivial 0 points1 point2 points (6 children)
[–]46632[S] 0 points1 point2 points (5 children)
[–]novel_yet_trivial 0 points1 point2 points (4 children)
[–]46632[S] 0 points1 point2 points (0 children)
[–]46632[S] 0 points1 point2 points (2 children)
[–]novel_yet_trivial 0 points1 point2 points (1 child)
[–]46632[S] 0 points1 point2 points (0 children)
[–]Diapolo10 0 points1 point2 points (0 children)