python-3.xaccent-sensitive

invalid syntax when working with french accents


Well, I'm trying to clean my file which have codes for french accents:

#353= IFCPROPERTYSINGLEVALUE('Charge d''\X2\00E9\X0\clairage sp\X2\00E9\X0\cifi\X2\00E9\X0\e par surface',$,IFCREAL(10.7639104167097),$);

I created this little function:

def CleanSpace(sp):
    sp.replace("\X2\00F4\X0\","ô")
    sp.replace("\X2\00E9\X0\","é")
    return(sp)

but Python 3 gave me the error:

    sp.replace("\X2\00F4\X0\","ô")
                               ^
SyntaxError: invalid syntax

How can I resolve this, please? Thanks in advance

Edit: if it can help, I rather tryed this line in console but answer was strange:

$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a='02_RADIOTHERAPIE/ ARC -plateforme recherche- Radioth\X2\00E9\X0\rapie'
>>> a
'02_RADIOTHERAPIE/ ARC -plateforme recherche- Radioth\\X2\x00E9\\X0\rapie'
>>> a.replace('\X2\00E9\X0\\','é')
'02_RADIOTHERAPIE/ ARC -plateforme recherche- Radioth\\X2\x00E9\\X0\rapie'

Solution

  • Well, after a lot of tries and searches, solution for one line was to use raw-strings:

    >>> a.replace(r'\X2\00E9\X0\ '[:-1], 'é')
    "#353= IFCPROPERTYSINGLEVALUE('Charge d''éclairage spécifiée par surface',$,IFCREAL(10.7639104167097),$);"
    

    For more lines, it was more difficult because bytes into my file are already written and it is not because I see a '\' that it is existing... Solution found for me was to work on bytes with antlr4