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

Use context manager to open/close file #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Use context manager to open/close file #116

wants to merge 1 commit into from

Conversation

jdufresne
Copy link
Contributor

No description provided.

@McSinyx
Copy link

McSinyx commented Nov 25, 2018

Funny enough, the entire following snippet

def read(fname):
    inf = open(os.path.join(os.path.dirname(__file__), fname))
    out = "\n" + inf.read().replace("\r\n", "\n")
    inf.close()
    return out

# Do not import `appdirs` yet, lest we import some random version on sys.path.
for line in read("appdirs.py").splitlines():
    if line.startswith("__version__"):
        version = ast.literal_eval(line.split("=", 1)[1].strip())
        break

can be replaced by simply

import re

# TBH I have no idea what does ``lest'' mean
# Do not import `appdirs` yet, lest we import some random version on sys.path.
with open("appdirs.py") as source:
    ast.literal_eval(re.search('^__version__[ \t\f]*=(.*)$', source.read()).group(1))

@pradyunsg
Copy link

I have no idea what does ''lest'' mean

to avoid the risk of, in order to avoid, just in case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants