diff --git a/gui/wxpython/gmodeler/model.py b/gui/wxpython/gmodeler/model.py index ae011f057f9..670afe17d90 100644 --- a/gui/wxpython/gmodeler/model.py +++ b/gui/wxpython/gmodeler/model.py @@ -39,6 +39,7 @@ import time import xml.etree.ElementTree as ET +from pathlib import Path from xml.sax import saxutils import wx @@ -542,9 +543,8 @@ def _substituteFile(self, item, params=None, checkOnly=False): for finput in self.fileInput: # read lines - with open(finput) as fd: - data = fd.read() - self.fileInput[finput] = data + data = Path(finput).read_text() + self.fileInput[finput] = data # substitute variables write = False diff --git a/gui/wxpython/gui_core/ghelp.py b/gui/wxpython/gui_core/ghelp.py index 63f7eff2280..b2a0d0500e9 100644 --- a/gui/wxpython/gui_core/ghelp.py +++ b/gui/wxpython/gui_core/ghelp.py @@ -23,6 +23,9 @@ import re import textwrap import sys + +from pathlib import Path + import wx from wx.html import HtmlWindow from operator import itemgetter @@ -274,8 +277,7 @@ def _pageCopyright(self): """Copyright information""" copyfile = os.path.join(os.getenv("GISBASE"), "COPYING") if os.path.exists(copyfile): - with open(copyfile) as copyrightFile: - copytext = copyrightFile.read() + copytext = Path(copyfile).read_text() else: copytext = _("%s file missing") % "COPYING" diff --git a/gui/wxpython/modules/colorrules.py b/gui/wxpython/modules/colorrules.py index f0d5953867a..08a6a6ebd52 100644 --- a/gui/wxpython/modules/colorrules.py +++ b/gui/wxpython/modules/colorrules.py @@ -694,9 +694,7 @@ def OnLoadRulesFile(self, event): return self.rulesPanel.Clear() - - with open(path) as fd: - self.ReadColorTable(ctable=fd.read()) + self.ReadColorTable(ctable=Path(path).read_text()) def ReadColorTable(self, ctable): """Read color table diff --git a/gui/wxpython/modules/mcalc_builder.py b/gui/wxpython/modules/mcalc_builder.py index eb2dc7691f9..5567d6bd66d 100644 --- a/gui/wxpython/modules/mcalc_builder.py +++ b/gui/wxpython/modules/mcalc_builder.py @@ -752,8 +752,7 @@ def OnLoadExpression(self, event): dlg.Destroy() return - with open(path) as fobj: - mctxt = fobj.read() + mctxt = Path(path).read_text() try: result, exp = mctxt.split("=", 1)