python3 encode replace unicode characters - Stack Overflow
文章推薦指數: 80 %
To be totally honest, I want to convert the unicode characters to their xmlcharref, keeping everything as a string). Thank you. python · python- ... Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. LearnmoreaboutCollectives Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams python3encodereplaceunicodecharacters AskQuestion Asked 5years,5monthsago Modified 5years,5monthsago Viewed 4ktimes 3 Accordingtothedocumentation,thefollowingcommand 'Brückenspinne'.encode("utf-8",errors='replace') Shouldgivemethebytesequenceb'Br??ckenspinne'.However,unicodecharactersarenotreplacedbutencodednevertheless: b'Br\xc3\xbcckenspinne' CanyoutellmehowIactuallyeliminateunicodecharacters?(Iusereplacefortestingpurposes,Iintendtouse'xmlcharrefreplace'later.Tobetotallyhonest,Iwanttoconverttheunicodecharacterstotheirxmlcharref,keepingeverythingasastring). Thankyou. pythonpython-3.xunicodepython-unicode Share Follow editedMay15,2017at14:30 falsetru 344k5757goldbadges684684silverbadges608608bronzebadges askedMay15,2017at14:23 LærneLærne 2,75111goldbadge1919silverbadges3131bronzebadges Addacomment | 1Answer 1 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 3 utf-8encodingcanrepresentthecharacterü;noreplacementoccur. Useotherencodingthatcannotrepresentthecharacter.Forexampleascii: >>>'Brückenspinne'.encode("ascii",errors='replace') b'Br?ckenspinne' >>>'Brückenspinne'.encode("ascii",errors='xmlcharrefreplace') b'Brückenspinne' Share Follow answeredMay15,2017at14:29 falsetrufalsetru 344k5757goldbadges684684silverbadges608608bronzebadges Addacomment | YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedpythonpython-3.xunicodepython-unicodeoraskyourownquestion. TheOverflowBlog HowtoearnamillionreputationonStackOverflow:beofservicetoothers Therightwaytojobhop(Ep.495) FeaturedonMeta BookmarkshaveevolvedintoSaves Inboximprovements:markingnotificationsasread/unread,andafiltered... Revieweroverboard!Orarequesttoimprovetheonboardingguidancefornew... CollectivesUpdate:RecognizedMembers,Articles,andGitLab Shouldweburninatethe[script]tag? Related 709 Whatisthebestwaytoremoveaccents(normalize)inaPythonunicodestring? 1356 Whatcharacterscanbeusedforup/downtriangle(arrowwithoutstem)fordisplayinHTML? 42 Howtofilter(orreplace)unicodecharactersthatwouldtakemorethan3bytesinUTF-8? 2198 HowdoIprintcurly-bracecharactersinastringwhileusing.format? 1455 UnicodeEncodeError:'ascii'codeccan'tencodecharacteru'\xa0'inposition20:ordinalnotinrange(128) 1 HowtoprintUnicodeinPython2whenLANG=C 612 HowtouseStringIOinPython3? 1402 WhyisexecutingJavacodeincommentswithcertainUnicodecharactersallowed? HotNetworkQuestions Whatistheconventionalwaytonotateameterwithaccentsoneverysecond8thnote? WhyisitnecessarytoconfigureanACLwhenconfiguringDynamicNat? LeavingaTTjobthenre-enteringacademia:Areaofbusinessandmanagement Howtoprovethisalgebraicidentity? Awordfor"amessagetomyself" ArethereanyspellsotherthanWishthatcanlocateanobjectthroughleadshielding? Myfavoriteanimalisa-singularandpluralform HowtoviewpauseandviewcurrentsolutioninCPLEXOptimisationStudio? IsdocumentingabigprojectwithUMLDiagramsneeded,goodtohaveorevennotpossible? Howtotellifmybikehasanaluminumframe meaningof'illesas'inMagnaCarta AreChernclasseswelldefineduptocontractiblechoice? Sciencefictionbook/novelaboutaliensinhumans'bodies Howdoparty-listsystemsaccommodateindependentcandidates? Changelinkcolorbasedinbackgroundcolor? Howtocreateamatrixofpairedvaluesfromtwomatrices? ConvertanintegertoIEEE754float Probabilisticmethodsforundecidableproblem HowdoIresolverecentearthworksaroundmyfuturefenceline? Whattranslation/versionoftheBiblewouldChaucerhaveread? IfthedrowshadowbladeusesShadowSwordasarangedattack,doesitthrowasword(thatitthenhastoretrievebeforeusingitagain)? UnderstandingsuspiciousHTTPGETRequest InD&D3.5,canafamiliarbetemporarilydismissed? WhathadEstherdonein"TheBellJar"bySylviaPlath? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-py Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings
延伸文章資訊
- 1用python抓網頁data,及做圖表之六:抓102年之後月營收的data
, strip()把字串前後的空白去掉,replace(",", "")把字串中某個字元換成另一個。 for迴圈中常用的range. 將上次的練習片段湊起來: import urllib.req...
- 2Unicode & Character Encodings in Python: A Painless Guide
Unicode vs UTF-8; Encoding and Decoding in Python 3; Python 3: All-In on ... is a way of specifyi...
- 3Python String encode() Method - W3Schools
'backslashreplace', - uses a backslash instead of the character that could not be encoded. 'ignor...
- 4Python String encode() - Programiz
In this tutorial, we will learn about the Python String encode() method with the help of ... repl...
- 5Python Strings encode() method - GeeksforGeeks
Python String encode() converts a string value into a collection of bytes, ... replace – replaces...