0

This is My Code.

import requests as req
from bs4 import BeautifulSoup
page = req.get('https://www.compart.com/en/unicode/block/U+0900')
soup = BeautifulSoup(page.content, 'html.parser')
myunicode = soup.select('.uid')
myunicodes = [myunicodes.text for myunicodes in myunicode]
res = [sub.replace('+', 'u') for sub in myunicodes]
res = [sub.replace('U', '') for sub in res]
list = ['\\' + item for item in res]
print(list)

When I am trying to add backslash \ in the list of strings with the following code. list = ['\\' + item for item in res] This Will remove + From the list and add '\\' in the starting of the code. I am also tried with r'\\' But this is not worked for me. Please Help me to Solvee this. Here is What I got.

['\\u0900', '\\u0901', '\\u0902', '\\u0903', '\\u0904', '\\u0905', '\\u0906', '\\u0907', '\\u0908', '\\u0909', '\\u090A', '\\u090B', '\\u090C', '\\u090D', '\\u090E', '\\u090F', '\\u0910', '\\u0911', '\\u0912', '\\u0913', '\\u0914', '\\u0915', '\\u0916', '\\u0917', '\\u0918', '\\u0919', '\\u091A', '\\u091B', '\\u091C', '\\u091D', '\\u091E', '\\u091F', '\\u0920', '\\u0921', '\\u0922', '\\u0923', '\\u0924', '\\u0925', '\\u0926', '\\u0927', '\\u0928', '\\u0929', '\\u092A', '\\u092B', '\\u092C', '\\u092D', '\\u092E', '\\u092F', '\\u0930', '\\u0931', '\\u0932', '\\u0933', '\\u0934', '\\u0935', '\\u0936', '\\u0937', '\\u0938', '\\u0939', '\\u093A', '\\u093B', '\\u093C', '\\u093D', '\\u093E', '\\u093F', '\\u0940', '\\u0941', '\\u0942', '\\u0943', '\\u0944', '\\u0945', '\\u0946', '\\u0947', '\\u0948', '\\u0949', '\\u094A', '\\u094B', '\\u094C', '\\u094D', '\\u094E', '\\u094F', '\\u0950', '\\u0951', '\\u0952', '\\u0953', '\\u0954', '\\u0955', '\\u0956', '\\u0957', '\\u0958', '\\u0959', '\\u095A', '\\u095B', '\\u095C', '\\u095D', '\\u095E', '\\u095F', '\\u0960', '\\u0961', '\\u0962', '\\u0963', '\\u0964', '\\u0965', '\\u0966', '\\u0967', '\\u0968', '\\u0969', '\\u096A', '\\u096B', '\\u096C', '\\u096D', '\\u096E', '\\u096F', '\\u0970', '\\u0971', '\\u0972', '\\u0973', '\\u0974', '\\u0975', '\\u0976', '\\u0977', '\\u0978', '\\u0979', '\\u097A', '\\u097B', '\\u097C', '\\u097D', '\\u097E', '\\u097F']

Here What is Expected .

# Need All the Strings Like the Following
['\u097E', '\u097F',] # Need All the Codes...

Thanks For Your Help in Advance ! ❤️

4
  • 3
    Escape sequences are only processed on program literals. They're not processed when you create strings in code. Commented Jul 23, 2020 at 15:41
  • Can you tell me How to Solve it ??? Commented Jul 23, 2020 at 15:43
  • On last example you have escape sequence, there is no u or 0 or 9 or 7 or e characters, so it is not the string you are in mind. Maybe you are looking something like: stackoverflow.com/questions/7595148/… Commented Jul 23, 2020 at 15:44
  • Python 3 won't display ['\u097e','\u097f']. It will display that list as ['ॾ', 'ॿ']. So do you want Unicode escapes instead of code points? That's what ['\\u097e','\\u097f'] is. A literal single backslash is always displayed in a list as '\\' Commented Jul 23, 2020 at 15:58

1 Answer 1

1

Your code is as i should be:

import requests as req
from bs4 import BeautifulSoup
page = req.get('https://www.compart.com/en/unicode/block/U+0900')
soup = BeautifulSoup(page.content, 'html.parser')
myunicode = soup.select('.uid')
myunicodes = [myunicodes.text for myunicodes in myunicode]
res = [sub.replace('+', 'u') for sub in myunicodes]
res = [sub.replace('U', '') for sub in res]
list = ['\\' + item for item in res]
for l in list:
    print(l)

Outputs:

\u0900
\u0901
\u0902
\u0903
\u0904
\u0905
\u0906
Sign up to request clarification or add additional context in comments.

4 Comments

This is for printing how can I store them all in a list.
@N1NG4 They are stored in a list. Lists just display strings using the repr() function. Printing uses str(). repr() escapes backslashes and unprintable characters.
@Mark Tolonen The repr() and str() functions are not printing right text. Please share with me the printing method. Please Help me Last Time 🤔
@N1NG4 Update your question. "Not printing right text" doesn't explain your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.