ECC-776: Python examples: Use 'open' with binary mode

This commit is contained in:
Shahram Najm 2018-11-13 17:13:53 +00:00
parent 6b62f610b8
commit 7585fddc0e
38 changed files with 51 additions and 51 deletions

View File

@ -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)

View File

@ -25,7 +25,7 @@ VERBOSE = 1 # verbose error reporting
def example():
# open bufr file
f = open(INPUT)
f = open(INPUT, 'rb')
cnt = 0

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -19,7 +19,7 @@ VERBOSE = 1 # verbose error reporting
def example():
# open bufr file
f = open(INPUT)
f = open(INPUT, 'rb')
cnt = 0

View File

@ -27,7 +27,7 @@ VERBOSE = 1 # verbose error reporting
def example():
# open bufr file
f = open(INPUT)
f = open(INPUT, 'rb')
cnt = 0

View File

@ -26,7 +26,7 @@ VERBOSE = 1 # verbose error reporting
def example():
# open bufr file
f = open(INPUT)
f = open(INPUT, 'rb')
cnt = 0

View File

@ -27,7 +27,7 @@ VERBOSE = 1 # verbose error reporting
def example():
# open bufr file
f = open(INPUT)
f = open(INPUT, 'rb')
cnt = 0

View File

@ -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 = [

View File

@ -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 = [

View File

@ -31,7 +31,7 @@ VERBOSE = 1 # verbose error reporting
def example():
# open bufr file
f = open(INPUT)
f = open(INPUT, 'rb')
cnt = 0

View File

@ -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 = [

View File

@ -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:

View File

@ -26,7 +26,7 @@ data = collections.defaultdict(dict)
def example():
# open BUFR file
f = open(INPUT)
f = open(INPUT, 'rb')
cnt = 0

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -18,7 +18,7 @@ VERBOSE = 1 # verbose error reporting
def example():
f = open(INPUT)
f = open(INPUT, 'rb')
keys = [
'ccsdsFlags',

View File

@ -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)

View File

@ -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)]

View File

@ -18,7 +18,7 @@ VERBOSE = 1 # verbose error reporting
def example():
f = open(INPUT)
f = open(INPUT, 'rb')
keys = [
'Ni',

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -23,7 +23,7 @@ default_namespace = 'ls'
def do_print(namespace, INPUT):
f = open(INPUT)
f = open(INPUT, 'rb')
first_time = True
print('{')

View File

@ -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)

View File

@ -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:

View File

@ -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)

View File

@ -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 = [

View File

@ -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,

View File

@ -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.

View File

@ -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()

View File

@ -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)

View File

@ -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')

View File

@ -26,7 +26,7 @@ VERBOSE = 1 # verbose error reporting
def example():
# open GTS file
f = open(INPUT)
f = open(INPUT, 'rb')
cnt = 0

View File

@ -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)