mirror of https://github.com/ecmwf/eccodes.git
ECC-776: Python examples: Use 'open' with binary mode
This commit is contained in:
parent
6b62f610b8
commit
7585fddc0e
|
@ -18,8 +18,8 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
f = open(sys.argv[1])
|
||||
fout = open(sys.argv[2], 'w')
|
||||
f = open(sys.argv[1], 'rb')
|
||||
fout = open(sys.argv[2], 'wb')
|
||||
|
||||
while 1:
|
||||
gid = codes_grib_new_from_file(f)
|
||||
|
|
|
@ -25,7 +25,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open BUFR file
|
||||
fin = open(INPUT)
|
||||
fin = open(INPUT, 'rb')
|
||||
|
||||
# open output BUFR file
|
||||
fout = open(OUTPUT, 'w')
|
||||
fout = open(OUTPUT, 'wb')
|
||||
|
||||
# get handle for message
|
||||
bufr = codes_bufr_new_from_file(fin)
|
||||
|
|
|
@ -23,7 +23,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example(input_filename, output_filename):
|
||||
ibufr = codes_new_from_samples('BUFR3', CODES_PRODUCT_BUFR)
|
||||
f = open(input_filename)
|
||||
f = open(input_filename, 'rb')
|
||||
ibufrin = codes_bufr_new_from_file(f)
|
||||
ivalues = (
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -61,7 +61,7 @@ def example(input_filename, output_filename):
|
|||
codes_set(ibufrin, 'unpack', 1)
|
||||
codes_bufr_copy_data(ibufrin, ibufr) # Copy data across
|
||||
|
||||
with open(output_filename, 'w') as outfile:
|
||||
with open(output_filename, 'wb') as outfile:
|
||||
codes_write(ibufr, outfile)
|
||||
codes_release(ibufr)
|
||||
codes_release(ibufrin)
|
||||
|
|
|
@ -22,7 +22,7 @@ from eccodes import *
|
|||
VERBOSE = 1 # verbose error reporting
|
||||
|
||||
def example(input_filename, output_filename):
|
||||
f = open(input_filename)
|
||||
f = open(input_filename, 'rb')
|
||||
ibufrin = codes_bufr_new_from_file(f)
|
||||
f.close()
|
||||
|
||||
|
@ -42,7 +42,7 @@ def example(input_filename, output_filename):
|
|||
|
||||
codes_bufr_copy_data ( ibufrin,ibufrout)
|
||||
|
||||
outfile=open(output_filename,'wb')
|
||||
outfile=open(output_filename, 'wb')
|
||||
codes_write(ibufrout,outfile)
|
||||
outfile.close()
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example(INPUT):
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
# define the keys to be printed
|
||||
keys = [
|
||||
|
|
|
@ -30,7 +30,7 @@ def get_key_value(msgid, key):
|
|||
|
||||
def example(INPUT):
|
||||
# open BUFR file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
# These keys should be in the sample files
|
||||
keys = [
|
||||
|
|
|
@ -31,7 +31,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
# define the keys to be printed
|
||||
keys = [
|
||||
|
|
|
@ -29,8 +29,8 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
# open BUFR file
|
||||
f = open(INPUT, 'rb')
|
||||
cnt = 0
|
||||
# loop over the messages in the file
|
||||
while 1:
|
||||
|
|
|
@ -26,7 +26,7 @@ data = collections.defaultdict(dict)
|
|||
|
||||
def example():
|
||||
# open BUFR file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -27,10 +27,10 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open BUFR file
|
||||
fin = open(INPUT)
|
||||
fin = open(INPUT, 'rb')
|
||||
|
||||
# open output BUFR file
|
||||
fout = open(OUTPUT, 'w')
|
||||
fout = open(OUTPUT, 'wb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
# open bufr file
|
||||
f = open(INPUT)
|
||||
# open BUFR file
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ def example():
|
|||
print('Usage: ', sys.argv[0], ' file', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
f = open(sys.argv[1])
|
||||
f = open(sys.argv[1], 'rb')
|
||||
while 1:
|
||||
ident = codes_new_from_file(f, CODES_PRODUCT_ANY)
|
||||
if ident is None:
|
||||
|
|
|
@ -18,7 +18,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
keys = [
|
||||
'ccsdsFlags',
|
||||
|
|
|
@ -21,8 +21,8 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
fin = open(INPUT)
|
||||
fout = open(OUTPUT, 'w')
|
||||
fin = open(INPUT, 'rb')
|
||||
fout = open(OUTPUT, 'wb')
|
||||
|
||||
gid = codes_grib_new_from_file(fin)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
mcount = codes_count_in_file(f)
|
||||
gid_list = [codes_grib_new_from_file(f) for i in range(mcount)]
|
||||
|
|
|
@ -18,7 +18,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
keys = [
|
||||
'Ni',
|
||||
|
|
|
@ -27,7 +27,7 @@ def example():
|
|||
print('Usage: ', sys.argv[0], ' file', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
f = open(sys.argv[1])
|
||||
f = open(sys.argv[1], 'rb')
|
||||
while 1:
|
||||
ident = codes_grib_new_from_file(f)
|
||||
if ident is None:
|
||||
|
|
|
@ -19,7 +19,7 @@ missingValue = 1e+20 # A value out of range
|
|||
|
||||
|
||||
def example(INPUT):
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
while 1:
|
||||
gid = codes_grib_new_from_file(f)
|
||||
|
|
|
@ -22,7 +22,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example(INPUT):
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
while 1:
|
||||
gid = codes_grib_new_from_file(f)
|
||||
|
|
|
@ -20,7 +20,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
while 1:
|
||||
gid = codes_grib_new_from_file(f)
|
||||
|
|
|
@ -23,7 +23,7 @@ default_namespace = 'ls'
|
|||
|
||||
|
||||
def do_print(namespace, INPUT):
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
first_time = True
|
||||
|
||||
print('{')
|
||||
|
|
|
@ -20,8 +20,8 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
fin = open(INPUT)
|
||||
fout = open(OUTPUT, 'w')
|
||||
fin = open(INPUT, 'rb')
|
||||
fout = open(OUTPUT, 'wb')
|
||||
|
||||
gid = codes_grib_new_from_file(fin)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
def example():
|
||||
points = ((30, -20), (13, 234))
|
||||
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
gid = codes_grib_new_from_file(f)
|
||||
|
||||
for lat, lon in points:
|
||||
|
|
|
@ -20,7 +20,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
gid = codes_grib_new_from_file(f)
|
||||
|
||||
values = codes_get_values(gid)
|
||||
|
|
|
@ -24,7 +24,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example(INPUT):
|
||||
# open GRIB file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
# These keys should be in the sample files
|
||||
keys = [
|
||||
|
|
|
@ -21,8 +21,8 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
sample_id = codes_grib_new_from_samples("regular_ll_sfc_grib1")
|
||||
fin = open(INPUT)
|
||||
fout = open(OUTPUT, 'w')
|
||||
fin = open(INPUT, 'rb')
|
||||
fout = open(OUTPUT, 'wb')
|
||||
|
||||
keys = {
|
||||
'dataDate': 20080104,
|
||||
|
|
|
@ -18,8 +18,8 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
fin = open(INPUT)
|
||||
fout = open(OUTPUT, 'w')
|
||||
fin = open(INPUT, 'rb')
|
||||
fout = open(OUTPUT, 'wb')
|
||||
gid = codes_grib_new_from_file(fin)
|
||||
|
||||
# The missingValue is not coded in the message.
|
||||
|
|
|
@ -21,8 +21,8 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
fin = open(INPUT)
|
||||
fout = open(OUTPUT, 'w')
|
||||
fin = open(INPUT, 'rb')
|
||||
fout = open(OUTPUT, 'wb')
|
||||
gid = codes_grib_new_from_file(fin)
|
||||
|
||||
dt = date.today()
|
||||
|
|
|
@ -20,8 +20,8 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
fin = open(INPUT)
|
||||
fout = open(OUTPUT, 'w')
|
||||
fin = open(INPUT, 'rb')
|
||||
fout = open(OUTPUT, 'wb')
|
||||
|
||||
gid = codes_grib_new_from_file(fin)
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ def example():
|
|||
numberOfCoefficients = 2 * (numberOfLevels + 1)
|
||||
assert (len(pv) == numberOfCoefficients)
|
||||
|
||||
fout = open('grib_set_pv.py.temp.grib', 'w')
|
||||
fout = open('grib_set_pv.py.temp.grib', 'wb')
|
||||
gid = codes_grib_new_from_samples('reduced_gg_sfc_grib1')
|
||||
|
||||
codes_set(gid, 'typeOfLevel', 'hybrid')
|
||||
|
|
|
@ -26,7 +26,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
def example():
|
||||
# open GTS file
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
cnt = 0
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ VERBOSE = 1 # verbose error reporting
|
|||
|
||||
|
||||
def example():
|
||||
f = open(INPUT)
|
||||
f = open(INPUT, 'rb')
|
||||
|
||||
while 1:
|
||||
bid = gts_new_from_file(f)
|
||||
|
|
Loading…
Reference in New Issue