+ 6

How to take unicode input here on Sololearn?

There are solutions for printing unicode letters like ü in our Sololearn console codes. But what do we do with user input? Whenever I input() German umlauts, I get an error.

9th Oct 2019, 8:47 PM
HonFu
HonFu - avatar
14 odpowiedzi
+ 4
HonFu With difficulty. I recently made a code using unicode in C++. Later helped someone generate Farsi characters in Python. It took time to find a method and format that worked. Examples: Python: https://code.sololearn.com/cNtlKBbnBQPn/?ref=app C++: https://code.sololearn.com/c5z7Wfic8yWU/?ref=app
9th Oct 2019, 9:43 PM
Manual
Manual - avatar
+ 4
Hm, interesting (I don't really get it). So no easy way around this? Why is this even a problem? Shouldn't Sololearn's PC's be able to process unicode voluntarily?
9th Oct 2019, 9:53 PM
HonFu
HonFu - avatar
+ 4
/* HonFu , I Know this question is 24 days old but I should say that now it's possible. Since SL started using Linux you can use emojis without any external libraries. Manual your C++ code will no longer work. io.h and fcntl.h is windows specific. however you can keep it unchanged to show how it works on windows. 🤓 https://www.sololearn.com/post/166812/?ref=app Try below code : */ #include <iostream> int main() { std::string emoji="😸"; //😸 if no input std::cin>>emoji; std::cout<<emoji; return 0; } #python emoji = input('enter emoji ') or "😸" print(emoji)
3rd Nov 2019, 8:12 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 3
A few minutes to make a sample. The C++ example does not need the parameter pack.
9th Oct 2019, 9:54 PM
Manual
Manual - avatar
+ 2
HonFu Who knows. The non web codes, do not work like they do in IDEs.
9th Oct 2019, 9:57 PM
Manual
Manual - avatar
+ 2
Hm, but how can you make use of that with input which seems to come as str? 🤔
9th Oct 2019, 10:40 PM
HonFu
HonFu - avatar
+ 2
HonFu I currently would not make a project with unicode input. If the input is critical, I feel the result may not be good.
9th Oct 2019, 10:43 PM
Manual
Manual - avatar
+ 2
Can you post a MWE? My keyboard is Spanish/English so I don't run into troubles.
10th Oct 2019, 4:32 AM
Diego
Diego - avatar
+ 2
Diego import sys, codecs sys.stdout = codecs.getwriter('utf-16')(sys.stdout.buffer, 'strict') print('ü') print(input()) # input 'ü' Without the encoding lines, only one line works; outcomment them, suddenly only the other works.
11th Oct 2019, 7:12 AM
HonFu
HonFu - avatar
+ 2
Oh wow, that's an actual, tangible improvement for a change. Nice! :)
3rd Nov 2019, 8:39 AM
HonFu
HonFu - avatar
+ 1
Thank you for waiting since you needed a python version. Python: https://code.sololearn.com/clG1q5b5nIr9/?ref=app
9th Oct 2019, 10:16 PM
Manual
Manual - avatar
+ 1
HonFu Unfortunatly I do not know how it works, yet. I found mixed answers online. C++ version: https://code.sololearn.com/c8UOZ3E0s3HL/?ref=app
9th Oct 2019, 10:37 PM
Manual
Manual - avatar
+ 1
You can try "\U" or "\u" before the string. Both will help. But the first one is for 16 bit hexadecimal value and the second one is for 16 bit hexadecimal value. And it's a python function.
11th Oct 2019, 4:30 AM
Ishmam
Ishmam - avatar
0
cv
10th Oct 2019, 12:05 AM
Well Ďewaaï Äwĺ
Well Ďewaaï Äwĺ - avatar