Search code examples
pythonideindentation

What is the best way to work cross-platform with an IDE/editor for Python indentation?


I have python code that I have to run on multiple servers (1 Windows and 2 Linux). I always get indentation error.

I tried multiple methods and always get an issue. I tried to use TAB as indent and also used 4 SPACES, but always get either error or the script does not run in a way it should

I cannot show the whole code but here is part of it:

Sec_all = 0
sk = 0
my = 0

if __name__ == "__main__":
    
  for i in df_Filter["iMap"]:
    #i = 65   #comment
    sk = sk + 1
    print("SK i = " + str(i) + "  @ " + datetime.datetime.now().strftime("%H:%M:%S") )
    y = z[:, (i)]#,54,133,122,63,102,105,39]
    X = df.drop(Code, axis=1, errors='ignore')
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=TestSize, random_state=42)
    
   
  
  print("********** : " + str(99999))
  for i in df_my[df_my["Sec_x"].isnull()]["iMap_x"]:
    print("^^^^^^^^^^^^^ : " + str(i))
    my = my + 1
    print("My i = " + str(i) + "  @ " + datetime.datetime.now().strftime("%H:%M:%S") )
    y = z[:, (i)]#,54,133,122,63,102,105,39]
    X = df.drop(Code, axis=1, errors='ignore')
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=TestSize, random_state=42)

  print(">>>>>>>>>>> F1_mi score All : ", F1_mi)
  print(">>>>>>>>>>> F1_ma score All : ", F1_ma)

I google to find if I can use brackets or any other clear way to determine FOR blocks (begin and end) but clearly python does not support that.

is there any other method i can be sure that indentation will be compiled as intended?


Solution

  • I found the problem

    The issue is that empty lines in between code lines cause indent issues in Linux server.

    I removed all empty lines and the code seems to run smoothly.