pythonspecial-characterskomodo

Strings with special characters


I have to check for the presence of a substring in a string in python. The problem comes from the fact that the substring contains a special character.

I am reading a feature from a csv file. The feature is a distance with numbers and its units:

12.4 miles
34 Kilómetros
800 metros

I have to read the feature, check the units and convert to metres.

for line in filename:
    if 'miles' in line:  #checking for miles is straight forward
       #do whatever I have to do
    if 'Kilómetros' in line:  #the problem is here
       #do whatever I have to do

Komodo will not let me save my .py file because of the special character in Kilómetros. Any help? Even if Komodo let me save the file, would this work?


Solution

  • Komodo attempts to detect and set which encoding your file is using when the file is first opened. It might have missed the mark. You can see which encoding Komodo chose in the status bar at the top of the text editing area. Click the drop down to change it.

    Encoding Settings in Komodo.  Note screen shot is from IDE but Encoding drop down is in the same location.

    For future Komodo questions you should use the Komodo Forums.