1

I am new in python 3 and I have a question, I have a script in QGIS 2.8 and is working, but my problem is in QGIS 3 the next part of script read the file but don't add the new line in each row.

import os
import numpy as np

os.chdir(r'C:\IDW_v3')    
file="HP.txt"    
HP = np.loadtxt(file, dtype='float')    
np.savetxt('HP_2_np.txt', HP, fmt='%10.5f', delimiter=' ')

Result in 2.8 enter image description here

Result in version 3

enter image description here Any idea?

closed as off-topic by underdark May 22 '18 at 19:18

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    That's not about QGIS, maybe numpy or python version. – Kadir Şahbaz May 22 '18 at 17:03
  • Can you recommend a change or another way of reading the text file? – hugo roman May 22 '18 at 17:12
2

That's not about QGIS, maybe numpy or python version. QGIS 2 uses Python 2.7, QGIS 3 uses Python 3.6.

delimiter parameter adds string/character seperating columns. If you don't specify newline parameter, I guess, numpy doesn't add newline character in Python 3.

So use in that way:

np.savetxt('HP_2_np.txt', HP, fmt='%10.5f', delimiter=' ', newline='\r\n')

Output:

    1.00000   2.00000   3.00000
    4.00000   5.00000   6.00000

Not the answer you're looking for? Browse other questions tagged or ask your own question.