python3: how to convert "\u3000" (ideographic space) to " "?

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

hello ['あかさ', 'あいうえ お', 'いい']!. How can I achieve this? python-3.x · python-unicode. 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 python3:howtoconvert"\u3000"(ideographicspace)to" "? AskQuestion Asked 2years,4monthsago Modified 2years,4monthsago Viewed 3ktimes 1 japanese.txt あかさ あいうえ お いい mycode.py withopen('japanese.txt','r',encoding='utf-8')asf: old=[line.strip()forlineinf.readlines()] send_mail(from,to,title,message=f"hello{old}!") ThenIreceivemaillikethis hello['あかさ','あいうえ\u3000お','いい']! WhatIwanttomailisthis hello['あかさ','あいうえ お','いい']! HowcanIachievethis? python-3.xpython-unicode Share Follow editedJun1,2020at7:59 Arbitrary askedJun1,2020at7:12 ArbitraryArbitrary 14833silverbadges99bronzebadges 5 1 Mymailmessageis"helloあか\u3000さた!"-doyouseethiscontentinreceivedmail,orthisisjustdebugoutputinconsole? – awesoon Jun1,2020at7:42 1 InJupyterandinmyconsole,thecommanda="あか さた";print(f"hello{a}!")workswithoutshowingthe\u3000.Inwhatapplicationareyourunningyourcode? – pyOliv Jun1,2020at7:45 str.replace(u'\u3000',u'') – ZhubeiFederer Jun1,2020at8:02 @awesoonSorrythepre-editedversionofmyquestionwasmymistake.Ieditedmyquestionmoreprecisely – Arbitrary Jun1,2020at8:03 @pyOlivIgetthesameresultfromyourcodealsoinmycomputer.Sorry.Ieditedmyquestion. – Arbitrary Jun1,2020at8:04 Addacomment  |  2Answers 2 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 3 Ifyouwanttoreplacethe\u3000characterwithastandardspaceanddothesametypeofthingforotherlesscommonunicodecharacters,youcanusetheunicodedatamodule: importunicodedata jText="""あかさ あいうえ お いい""" jList=[line.strip()forlineinjText.split("\n")] #['あかさ','あいうえ\u3000お','いい'] normalizedList=[unicodedata.normalize('NFKC',line)forlineinjList] #['あかさ','あいうえお','いい'] Share Follow answeredJun1,2020at9:01 jdazjdaz 5,21622goldbadges1919silverbadges3131bronzebadges Addacomment  |  2 list's__str__methodusesrepronelements,thereforeyou'reseeing\u3000inyourmail.Justconvertlisttostringyourself: In[28]:l=['あかさ','あいうえ\u3000お','いい'] In[29]:print(','.join(map(str,l))) あかさ,あいうえ お,いい Ifyou'resureallyourlistelementsarestrings,youcanomitmap(str,...)andjustuse','.join(l) Share Follow answeredJun1,2020at8:10 awesoonawesoon 30.7k99goldbadges6969silverbadges9494bronzebadges 1 Thankssomuch.Yoursolutions(including','.join(l)version)work.Justitwashardandconfusingformetodebugbecause','.join(l)inconsoleoutputs\u3000butnotintherealmailmessage... – Arbitrary Jun1,2020at8:35 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?Browseotherquestionstaggedpython-3.xpython-unicodeoraskyourownquestion. TheOverflowBlog HowtoearnamillionreputationonStackOverflow:beofservicetoothers Therightwaytojobhop(Ep.495) FeaturedonMeta BookmarkshaveevolvedintoSaves Inboximprovements:markingnotificationsasread/unread,andafiltered... Revieweroverboard!Orarequesttoimprovetheonboardingguidancefornew... CollectivesUpdate:RecognizedMembers,Articles,andGitLab Shouldweburninatethe[script]tag? Related 1141 HowcanIrepresentan'Enum'inPython? 1517 HowcanIflushtheoutputoftheprintfunction? 3469 Convertbytestoastring 1347 BestwaytoconvertstringtobytesinPython3? 612 HowtouseStringIOinPython3? 373 UnicodeDecodeError:'utf8'codeccan'tdecodebyte0x9c 390 Howtoconvert'binarystring'tonormalstringinPython3? 1 Convertstringtoutf-16 HotNetworkQuestions Isthe2...g6DutchautomaticallywinningforWhite? ConvertanintegertoIEEE754float FMEmergefeatures(many-to-one)withpriority LaTeX2(e)vsLaTeX3 Theunusualphrasing"verb+the+comparativeadjective"intheLordoftheRingsnovels IfthedrowshadowbladeusesShadowSwordasarangedattack,doesitthrowasword(thatitthenhastoretrievebeforeusingitagain)? Doesindecentexposurerequireintentionality? WillIgetdeniedentryafterIremovedavisasticker?Ismypassportdamaged? Whatisthebestwaytocalculatetruepasswordentropyforhumancreatedpasswords? Sortbycolumngroupandignoreothercolumnsfailingforthisexample,why? IsdocumentingabigprojectwithUMLDiagramsneeded,goodtohaveorevennotpossible? Canaphotonturnaprotonintoaneutron? Whydoes«facture»mean"bill,invoice"? Whydostringhashcodeschangeforeachexecutionin.NET? HowdothosewhoholdtoaliteralinterpretationofthefloodaccountrespondtothecriticismthatNoahbuildingthearkwouldbeunfeasible? What'sthedifferencebetween'Dynamic','Random',and'Procedural'generations? Howtoformalizeagamewhereeachplayerisaprogramhavingaccesstoopponent'scode? Howtodestroydatapermanentlyinaworldwheretimetraveliseasilydone? HowdoIsignafileusingSSHandverifyitusingacertificateauthority? HowtogetridofUbuntuProadvertisementwhenupdatingapt? WhydoNorthandSouthAmericancountriesoffercitizenshipbasedonunrestrictedJusSoli(rightofsoil)? Levinson'salgorithmandQRdecompositionforcomplexleast-squaresFIRdesign Flatkeyboardwithoutanyphysicalkeys HowdoGPSreceiverscommunicatewithsatellites? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-py Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?