python3 encode replace unicode characters - Stack Overflow

文章推薦指數: 80 %
投票人數:10人

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  



請為這篇文章評分?