How to replace characters in a string?

Dave dave at looktowindward.com
Wed Jun 8 04:16:11 EDT 2022


PS

I’ve also tried:
myCompareFile1 = myTitleName
myCompareFile1.replace("\u2019", "'")
myCompareFile2 = myCompareFileName
myCompareFile2.replace("\u2019", "'")
Which also doesn’t work, the replace itself work but it still fails the compare?


> On 8 Jun 2022, at 10:08, Dave <dave at looktowindward.com> wrote:
> 
> Hi All,
> 
> I decided to start a new thread as this really is a new subject.
> 
> I've got two that appear to be identical, but fail to compare. After getting the ascii encoding I see that they are indeed different, my question is how can I replace the \u2019m with a regular single quote mark (or apostrophe)?
> 
> myCompareFile1 = ascii(myTitleName)
> myCompareFile2 = ascii(myCompareFileName)
> myCompareFile1: 'I\u2019m Mandy Fly Me'
> myCompareFile2: "I'm Mandy Fly Me"
> 
> I tried the but it doesn’t seem to work?
> myCompareFile1 = ascii(myTitleName)
> myCompareFile1.replace("\u2019", "'")
> myCompareFile2 = ascii(myCompareFileName)
> myCompareFile2.replace("\u2019", "'")
> if myCompareFile1 != myCompareFile2:
>    print('myCompareFile1:',myCompareFile1)
>    print('myCompareFile2:',myCompareFile2)
>    myLength1 = len(myCompareFileName)
>    myLength2 = len(myTitleName)
>    print('File Name Mismatch - Artist: [' + myArtistName + ']  Album: ['+ myAlbumName + ']  Track: [' + myTitleName + ']  File: [' + myCompareFileName + ']')
>    if (myLength1 == myLength2):
>        print('lengths match: ',myLength1)
>    else:
>        print('lengths mismatch: ',myLength1,'  ',myLength2)
>        print('     ')
> Console:
> 
> myCompareFile1: 'I\u2019m Mandy Fly Me'
> myCompareFile2: "I'm Mandy Fly Me"
> 
> So it looks like the replace isn’t doing anything?
> 
> I’m an experienced developer but learning Python.
> 
> All the Best
> Dave
> 
> 
> 
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list