lundi 7 décembre 2020

Two equal string viewed different by python but they are equal, using panda.read_fwf

I have the following code but actually str1 even if are the type and value same, I can see if print on the output or from the variable explorer using spyder, are considered different from python. While str2 and str3 are seen equal. Why?

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import pandas as pd
import sys
slash='/'
name=str(sys.argv[1])
cwd = os.getcwd()
csv_name =slash+name

#Check if the coordinate
#Check if the coordinates are direct or cartesian
coord = pd.read_fwf(f"{cwd}{csv_name}",
                 skiprows=8, nrows=1, names=['coord' ], 
                 delimiter='\s+',engine='python',header=None)
str1=str(coord.iat[0,0])
print(str1)
str2='Cartesian'
str3="Cartesian"
if (str1==str3): #same problem with str1==str3
print('equal')

The row the I read from the input file actually just contains this:

Cartesian

Edit: This script is included into a bigger one and If I execute fhe script from the terminal it is seen as nan even if spyders sees it as str. But extracting this part and executing only this, it actually gives Cartesian from the terminal!

Aucun commentaire:

Enregistrer un commentaire