Home > other >  Where is this code is wrong?
Where is this code is wrong?

Time:09-20

The example given format is like this, but I run after you will be prompted I expected an indented block



This is the sample code in full, is the picture form


Here's my hand dozen code

 
# - * - coding: cp936 - * -
The import tempfile as expected
Def surfer2arcinfo (surfergrid arcinfogrid) : # define a function
F1=file (surfergrid)
F2=file (arcinfogrid, 'w')
N=1
The header=[] # will Surfer grid header file is written to a list
A=[] # writing surfer grid data values in a list
For I in f1. Readlines () :
J=i. plit ()
data=https://bbs.csdn.net/topics/[] # writing surfer grid data values in a list
For I in f1. Readlines () :
J=i. plit ()

If n==1:
ID=j [0]
The header. Append (ID)
If n==2:
Ncols=j [0]
Nrows=j [1]
The header. Append (ncols)
The header. Append (nrows)
If n==3:
Xmin=j [0]
Xmax=j [1]
The header. Append (xmin)
The header. Append (xmax)
If n==4:
Ymin=j [0]
Ymax=j [1]
The header. Append (ymin)
The header. Append (ymax)
If n> 5:
value=https://bbs.csdn.net/topics/i.replace (' 1.70141 e+038 ', '9999') # replace countless according to the value of arcinfo NODATA values
Value1=value. The split ()
For v in value1:
Data. Append (v)
N=n + 1
Fl. Close ()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# will Surfer header files into arcinfo grid header file
Xmax=float (heeader [4])
Xmin=float (header [3])
Ncols=int (header [1])
Cellsize=(xmax - xmin)/(ncols - 1)
#
Temp=tempfile as expected. Mktemp (' temp ')
Tempf=file (TMP, 'w')
For the index in the range (len (data) - 1, 1, 1) :
Md=% int index (ncols)
If md==0:
[index] tempf. Write (STR (data))
Tempf. Write (')
Tempf. Write (' \ n ')
The else:
[index] tempf. Write (STR (data))
Tempf. Write (')
Tempf. Close ()
# will arcinfo grid first written to the file
F2. Write (' ncols)
F2. Write (STR (ncols))
F2. Write (' \ n ')
F2. Write (' nrows')
F2. Write (STR (nrows))
F2. Write (' \ n ')
F2. Write (' xllcenter ')
F2. Write (header [3])
F2. Write (' \ n ')
F2. Write (' yllcenter ')
F2. Write (header [5])
F2. Write (' \ n ')
F2. Write (' cellsize ')
F2. Write (STR (cellsize))
F2. Write (' \ n ')
F2. Write (' NODATA_value - 9999 ')
F2. Write (' \ n ')
#
# will arcinfo grid data written to the file
Tempf=file (temp)
For the value in tempf. Readlines () :
Value1=value. The split ()
For leng in range (len (value1) - 1, 1, 1) :
F2. Write (STR (value1 [leng]))
F2. Write (')
F2. Write (' \ n ')

Tempf. Close ()
F2. The close ()
# operation function
If (__name__=="__main__") :
Surfer2arcinfo (' D: \ \ co GRD ', 'D: \ \ BA. Asc)


Pray god help!

CodePudding user response:

The WC! Change book,
 

# will arcinfo grid data written to the file
Tempf=file (temp)
For the value in tempf. Readlines () :
Value1=value. The split ()
For leng in range (len (value1) - 1, 1, 1) :
F2. Write (STR (value1 [leng]))
F2. Write (')
F2. Write (' \ n ')

Tempf. Close ()
F2. The close ()




According to this try to change the indentation,

CodePudding user response:

Hello, the file function?? Now everyone's popular with Python3, you still use python2.
To kiss you a little advice:
1, install the pycharm, directly from the ide, there is an error when you red, be clear at a glance,
2, suggest change a tutorial, overhand python3 directly, don't learn python2, because after 2020 years, version 2 stop maintenance,
Learn python3! Learn python3! Learn python3!

The following show you error:






CodePudding user response:

It was pretty interesting ha ha ha ok around BBS

CodePudding user response:

Indent the learning python but around the pain
  • Related