Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant open modes #2121

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AutoDuck/Dump2HHC.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def main():
cats = parseCategories()
for cat in cats:
file = os.path.join(gen_dir, cat.dump_file)
input = open(file, "r")
input = open(file)
parseTopics(cat, input)
input.close()

Expand Down
2 changes: 1 addition & 1 deletion AutoDuck/InsertExternalOverviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main():
print("Invalid args")
sys.exit(1)
file = sys.argv[1]
input = open(file, "r")
input = open(file)
out = open(file + ".2", "w")
doc = document_object.GetDocument()
linksHTML = genLinksHTML(doc.links)
Expand Down
2 changes: 1 addition & 1 deletion AutoDuck/TOCToHHK.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def main():
file = sys.argv[1]
output = sys.argv[2]
input = open(file, "r")
input = open(file)
out = open(output, "w")
line = input.readline()
out.write(
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/framework/mdi_pychecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def OnOpenDocument(self, fnm):
# and starting a new grep can communicate the default parameters to the
# new grep.
try:
params = open(fnm, "r").read()
params = open(fnm).read()
except:
params = None
self.setInitParams(params)
Expand Down Expand Up @@ -386,7 +386,7 @@ def _inactive_idleHandler(self, handler, count):
if self.verbose:
self.GetFirstView().Append("# .." + f + "\n")
win32ui.SetStatusText("Searching " + f, 0)
lines = open(f, "r").readlines()
lines = open(f).readlines()
for i in range(len(lines)):
line = lines[i]
if self.pat.search(line) is not None:
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/framework/sgrepmdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def OnOpenDocument(self, fnm):
# and starting a new grep can communicate the default parameters to the
# new grep.
try:
params = open(fnm, "r").read()
params = open(fnm).read()
except:
params = None
self.setInitParams(params)
Expand Down Expand Up @@ -299,7 +299,7 @@ def SearchFile(self, handler, count):
# while grep is running
if os.path.isfile(f):
win32ui.SetStatusText("Searching " + f, 0)
lines = open(f, "r").readlines()
lines = open(f).readlines()
for i in range(len(lines)):
line = lines[i]
if self.pat.search(line) is not None:
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/client/genpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ def open_writer(self, filename, encoding="mbcs"):
# don't step on each others' toes.
# Could be a classmethod one day...
temp_filename = self.get_temp_filename(filename)
return open(temp_filename, "wt", encoding=encoding)
return open(temp_filename, "w", encoding=encoding)

def finish_writer(self, filename, f, worked):
f.close()
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/client/makepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def main():
path = os.path.dirname(outputName)
if path != "" and not os.path.exists(path):
os.makedirs(path)
f = open(outputName, "wt", encoding="mbcs")
f = open(outputName, "w", encoding="mbcs")

else:
f = None
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def ExecuteShellCommand(
output_name = tempfile.mktemp("win32com_test")
cmd = cmd + ' > "%s" 2>&1' % output_name
rc = os.system(cmd)
output = open(output_name, "r").read().strip()
output = open(output_name).read().strip()
os.remove(output_name)

class Failed(Exception):
Expand Down
2 changes: 1 addition & 1 deletion com/win32comext/axdebug/Test/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _query_interface_(self, iid):
def _GetCodeContainer(self):
if self.codeContainer is None:
try:
codeText = open(self.module.__file__, "rt").read()
codeText = open(self.module.__file__).read()
except OSError as details:
codeText = "# Exception opening file\n# %s" % (details)

Expand Down
2 changes: 1 addition & 1 deletion com/win32comext/axdebug/codecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def GetText(self):
fname = self.GetFileName()
if fname:
try:
self.text = open(fname, "r").read()
self.text = open(fname).read()
except OSError as details:
self.text = "# Exception opening file\n# %s" % (repr(details))
else:
Expand Down
10 changes: 5 additions & 5 deletions win32/Lib/win32rcparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,21 +584,21 @@ def ParseStreams(rc_file, h_file):

def Parse(rc_name, h_name=None):
if h_name:
h_file = open(h_name, "r")
h_file = open(h_name)
else:
# See if same basename as the .rc
h_name = rc_name[:-2] + "h"
try:
h_file = open(h_name, "r")
h_file = open(h_name)
except OSError:
# See if MSVC default of 'resource.h' in the same dir.
h_name = os.path.join(os.path.dirname(rc_name), "resource.h")
try:
h_file = open(h_name, "r")
h_file = open(h_name)
except OSError:
# .h files are optional anyway
h_file = None
rc_file = open(rc_name, "r")
rc_file = open(rc_name)
try:
return ParseStreams(rc_file, h_file)
finally:
Expand All @@ -617,7 +617,7 @@ def GenerateFrozenResource(rc_name, output_name, h_name=None):
rcp = Parse(rc_name, h_name)
in_stat = os.stat(rc_name)

out = open(output_name, "wt")
out = open(output_name, "w")
out.write("#%s\n" % output_name)
out.write("#This is a generated file. Please edit %s instead.\n" % rc_name)
out.write("__version__=%r\n" % __version__)
Expand Down
2 changes: 1 addition & 1 deletion win32/scripts/VersionStamp/bulkstamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def load_descriptions(fname, vars):
retvars = {}
descriptions = {}

lines = open(fname, "r").readlines()
lines = open(fname).readlines()

for i in range(len(lines)):
line = lines[i].strip()
Expand Down
2 changes: 1 addition & 1 deletion win32/scripts/VersionStamp/vssutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def SubstituteInString(inString, evalEnv):


def SubstituteInFile(inName, outName, evalEnv):
inFile = open(inName, "r")
inFile = open(inName)
try:
outFile = open(outName, "w")
try:
Expand Down