Skip to content

Commit

Permalink
refactor: use print() instead of sys.stdout.write() (#1223)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Sep 4, 2021
1 parent 722224c commit 12a062a
Show file tree
Hide file tree
Showing 60 changed files with 153 additions and 307 deletions.
5 changes: 2 additions & 3 deletions flopy/mbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""
import abc
import sys
import os
import shutil
import threading
Expand Down Expand Up @@ -1203,8 +1202,8 @@ def change_model_ws(self, new_pth=None, reset_external=False):
# --reset the model workspace
old_pth = self._model_ws
self._model_ws = new_pth
line = f"\nchanging model workspace...\n {new_pth}\n"
sys.stdout.write(line)
if self.verbose:
print(f"\nchanging model workspace...\n {new_pth}")
# reset the paths for each package
for pp in self.packagelist:
pp.fn_path = os.path.join(self.model_ws, pp.file_name[0])
Expand Down
3 changes: 1 addition & 2 deletions flopy/modflow/mfbas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

import re
import sys
import numpy as np
from ..pakbase import Package
from ..utils import Util3d
Expand Down Expand Up @@ -324,7 +323,7 @@ def load(cls, f, model, ext_unit_dict=None, check=True, **kwargs):
"""

if model.verbose:
sys.stdout.write("loading bas6 package file...\n")
print("loading bas6 package file...")

# parse keywords
if "nlay" in kwargs:
Expand Down
4 changes: 1 addition & 3 deletions flopy/modflow/mfbcf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

import numpy as np

from ..pakbase import Package
Expand Down Expand Up @@ -349,7 +347,7 @@ def load(cls, f, model, ext_unit_dict=None):
"""

if model.verbose:
sys.stdout.write("loading bcf package file...\n")
print("loading bcf package file...")

openfile = not hasattr(f, "read")
if openfile:
Expand Down
3 changes: 1 addition & 2 deletions flopy/modflow/mfchd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

import sys
import numpy as np
from ..pakbase import Package
from ..utils import MfList
Expand Down Expand Up @@ -266,7 +265,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None, check=True):
"""

if model.verbose:
sys.stdout.write("loading chd package file...\n")
print("loading chd package file...")

return Package.load(
f,
Expand Down
3 changes: 1 addition & 2 deletions flopy/modflow/mfde4.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<http://water.usgs.gov/ogw/modflow-nwt/MODFLOW-NWT-Guide/de4.htm>`_.
"""
import sys
from ..pakbase import Package


Expand Down Expand Up @@ -256,7 +255,7 @@ def load(cls, f, model, ext_unit_dict=None):
"""

if model.verbose:
sys.stdout.write("loading de4 package file...\n")
print("loading de4 package file...")

openfile = not hasattr(f, "read")
if openfile:
Expand Down
4 changes: 1 addition & 3 deletions flopy/modflow/mfdis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<http://water.usgs.gov/ogw/modflow/MODFLOW-2005-Guide/index.html?dis.htm>`_.
"""

import sys
import warnings

import numpy as np
Expand Down Expand Up @@ -763,7 +761,7 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
"""

if model.verbose:
sys.stdout.write("loading dis package file...\n")
print("loading dis package file...")

openfile = not hasattr(f, "read")
if openfile:
Expand Down
5 changes: 1 addition & 4 deletions flopy/modflow/mfdisu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
the ModflowDisU class as `flopy.modflow.ModflowDisU`.
"""

import sys
import warnings
import numpy as np
from ..pakbase import Package
from ..utils import Util2d, Util3d, read1d
Expand Down Expand Up @@ -552,7 +549,7 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
"""

if model.verbose:
sys.stdout.write("loading disu package file...\n")
print("loading disu package file...")

if model.version != "mfusg":
print(
Expand Down
3 changes: 1 addition & 2 deletions flopy/modflow/mfdrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<http://water.usgs.gov/ogw/modflow/MODFLOW-2005-Guide/index.html?drn.htm>`_.
"""
import sys
import numpy as np
from ..pakbase import Package
from ..utils.util_list import MfList
Expand Down Expand Up @@ -323,7 +322,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None, check=True):
"""

if model.verbose:
sys.stdout.write("loading drn package file...\n")
print("loading drn package file...")

return Package.load(
f,
Expand Down
3 changes: 1 addition & 2 deletions flopy/modflow/mfdrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<http://water.usgs.gov/ogw/modflow/MODFLOW-2005-Guide/index.html?drt.htm>`_.
"""
import sys
import numpy as np
from ..pakbase import Package
from ..utils.util_list import MfList
Expand Down Expand Up @@ -309,7 +308,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None, check=True):
"""

if model.verbose:
sys.stdout.write("loading drt package file...\n")
print("loading drt package file...")

return Package.load(
f,
Expand Down
4 changes: 1 addition & 3 deletions flopy/modflow/mfevt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<http://water.usgs.gov/ogw/modflow/MODFLOW-2005-Guide/index.html?evt.htm>`_.
"""
import sys

import numpy as np
from .mfparbc import ModflowParBc as mfparbc
from ..utils import Transient2d, Util2d
Expand Down Expand Up @@ -267,7 +265,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
"""
if model.verbose:
sys.stdout.write("loading evt package file...\n")
print("loading evt package file...")

openfile = not hasattr(f, "read")
if openfile:
Expand Down
60 changes: 23 additions & 37 deletions flopy/modflow/mffhb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<http://water.usgs.gov/ogw/modflow/MODFLOW-2005-Guide/index.html?fhb.htm>`_.
"""
import sys

import numpy as np

from ..pakbase import Package
Expand Down Expand Up @@ -455,7 +453,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
"""
if model.verbose:
sys.stdout.write("loading fhb package file...\n")
print("loading fhb package file...")

openfile = not hasattr(f, "read")
if openfile:
Expand All @@ -477,7 +475,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):

# dataset 1
if model.verbose:
sys.stdout.write("loading fhb dataset 1\n")
print("loading fhb dataset 1")
raw = line.strip().split()
nbdtim = int(raw[0])
nflw = int(raw[1])
Expand All @@ -493,10 +491,8 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
flow_aux = []
if nfhbx1 > 0:
if model.verbose:
sys.stdout.write("loading fhb dataset 2\n")
sys.stdout.write(
"dataset 2 will not be preserved in the created hfb object.\n"
)
print("loading fhb dataset 2")
print("dataset 2 will not be preserved in the created hfb object.")
for idx in range(nfhbx1):
line = f.readline()
raw = line.strip().split()
Expand All @@ -510,10 +506,8 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
head_aux = []
if nfhbx2 > 0:
if model.verbose:
sys.stdout.write("loading fhb dataset 3\n")
sys.stdout.write(
"dataset 3 will not be preserved in the created hfb object.\n"
)
print("loading fhb dataset 3")
print("dataset 3 will not be preserved in the created hfb object.")
for idx in range(nfhbx2):
line = f.readline()
raw = line.strip().split()
Expand All @@ -525,7 +519,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):

# Dataset 4a IFHBUN CNSTM IFHBPT
if model.verbose:
sys.stdout.write("loading fhb dataset 4a\n")
print("loading fhb dataset 4a")
line = f.readline()
raw = line.strip().split()
ifhbun = int(raw[0])
Expand All @@ -539,7 +533,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):

# Dataset 4b
if model.verbose:
sys.stdout.write("loading fhb dataset 4b\n")
print("loading fhb dataset 4b")
line = f.readline()
raw = line.strip().split()
bdtime = []
Expand All @@ -553,7 +547,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
ds6 = None
if nflw > 0:
if model.verbose:
sys.stdout.write("loading fhb dataset 5a\n")
print("loading fhb dataset 5a")
# Dataset 5a IFHBUN CNSTM IFHBPT
line = f.readline()
raw = line.strip().split()
Expand All @@ -567,7 +561,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
ifhbpt = max(ifhbpt, int(raw[2]))

if model.verbose:
sys.stdout.write("loading fhb dataset 5b\n")
print("loading fhb dataset 5b")
dtype = ModflowFhb.get_default_dtype(
nbdtim=nbdtim, head=False, structured=model.structured
)
Expand Down Expand Up @@ -598,12 +592,10 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
dtype.append((name, np.float32))
for naux in range(nfhbx1):
if model.verbose:
sys.stdout.write(
f"loading fhb dataset 6a - aux {naux + 1}\n"
)
sys.stdout.write(
print(f"loading fhb dataset 6a - aux {naux + 1}")
print(
"dataset 6a will not be preserved in "
"the created hfb object.\n"
"the created hfb object."
)
# Dataset 6a IFHBUN CNSTM IFHBPT
line = f.readline()
Expand All @@ -619,12 +611,10 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
ifhbpt = max(ifhbpt, int(raw[2]))

if model.verbose:
sys.stdout.write(
f"loading fhb dataset 6b - aux {naux + 1}\n"
)
sys.stdout.write(
print(f"loading fhb dataset 6b - aux {naux + 1}")
print(
"dataset 6b will not be preserved in "
"the created hfb object.\n"
"the created hfb object."
)
current = np.recarray(nflw, dtype=dtype)
for n in range(nflw):
Expand All @@ -640,7 +630,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
ds8 = None
if nhed > 0:
if model.verbose:
sys.stdout.write("loading fhb dataset 7a\n")
print("loading fhb dataset 7a")
# Dataset 7a IFHBUN CNSTM IFHBPT
line = f.readline()
raw = line.strip().split()
Expand All @@ -654,7 +644,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
ifhbpt = max(ifhbpt, int(raw[2]))

if model.verbose:
sys.stdout.write("loading fhb dataset 7b\n")
print("loading fhb dataset 7b")
dtype = ModflowFhb.get_default_dtype(
nbdtim=nbdtim, head=True, structured=model.structured
)
Expand Down Expand Up @@ -685,12 +675,10 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
dtype.append((name, np.float32))
for naux in range(nfhbx1):
if model.verbose:
sys.stdout.write(
f"loading fhb dataset 8a - aux {naux + 1}\n"
)
sys.stdout.write(
print(f"loading fhb dataset 8a - aux {naux + 1}")
print(
"dataset 8a will not be preserved in "
"the created hfb object.\n"
"the created hfb object."
)
# Dataset 6a IFHBUN CNSTM IFHBPT
line = f.readline()
Expand All @@ -707,10 +695,8 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
ifhbpt = max(ifhbpt, ifhbpt6)

if model.verbose:
sys.stdout.write(
f"loading fhb dataset 8b - aux {naux + 1}\n"
)
sys.stdout.write(
print(f"loading fhb dataset 8b - aux {naux + 1}")
print(
"dataset 8b will not be preserved in "
"the created hfb object."
)
Expand Down
3 changes: 1 addition & 2 deletions flopy/modflow/mfflwob.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
import numpy as np
from ..pakbase import Package
from ..utils import parsenamefile
Expand Down Expand Up @@ -414,7 +413,7 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
"""

if model.verbose:
sys.stdout.write("loading flwob package file...\n")
print("loading flwob package file...")

openfile = not hasattr(f, "read")
if openfile:
Expand Down
3 changes: 1 addition & 2 deletions flopy/modflow/mfgage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""
import os
import sys

import numpy as np

Expand Down Expand Up @@ -318,7 +317,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None):
"""

if model.verbose:
sys.stdout.write("loading gage package file...\n")
print("loading gage package file...")

openfile = not hasattr(f, "read")
if openfile:
Expand Down
3 changes: 1 addition & 2 deletions flopy/modflow/mfghb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<http://water.usgs.gov/ogw/modflow/MODFLOW-2005-Guide/index.html?ghb.htm>`_.
"""
import sys
import numpy as np
from ..pakbase import Package
from ..utils import MfList
Expand Down Expand Up @@ -301,7 +300,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None, check=True):
"""

if model.verbose:
sys.stdout.write("loading ghb package file...\n")
print("loading ghb package file...")

return Package.load(
f,
Expand Down
Loading

0 comments on commit 12a062a

Please sign in to comment.