'write and save a txt file using spyder

I am trying to write a txt file from Python:

for i in range(len(X)):
    k+=1
    g.write('CoordinatesX='+str(i)+str(X[i])+'\n')
    g.write('D'+str(k)+'@Sketch'+str(sketch_number)+'=CoordinatesX'+str(k)+'\n')
    k+=1
    g.write('CoordinatesY='+str(i)+str(Y[i])+'\n')
    g.write('D'+str(k)+'@Sketch'+str(sketch_number)+'=CoordinatesY'+str(k)+'\n')
    k+=1
    g.write('CoordinatesZ='+str(i)+str(Z[i])+'\n')
    g.write('D'+str(k)+'@Sketch'+str(sketch_number)+'=CoordinatesZ'+str(k)+'\n')
        
g.close()

I get no error, but then when I go to look for the downloaded file, I don't find it, and nothing was written. Does someone know what I am doing wrong? Thank you so much already. cheers!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source