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

as "fd" not "f" #1

Open
guettli opened this issue Oct 6, 2015 · 2 comments
Open

as "fd" not "f" #1

guettli opened this issue Oct 6, 2015 · 2 comments

Comments

@guettli
Copy link

guettli commented Oct 6, 2015

Hi,

thank you for these hints.

Here is some feedback:

I think it is much better to use "fd" and not "f" if you store
a file descriptor :-)

with open(...) as fd:
    ...
@svisser
Copy link
Owner

svisser commented Oct 6, 2015

Hey there, thanks for your feedback. I'm going to look into this; the Python documentation says it returns a file object which means f is possibly clear enough. I think the object that you get back is a bit higher level than a file descriptor (as used at operating system level) but I could be wrong here.

https://docs.python.org/3/library/functions.html#open

@guettli
Copy link
Author

guettli commented Oct 7, 2015

@svisser my concerns are not the technical details. It is "best practice". I see "fd" very often. And I personally think that one letter variables are not clean code. I just wanted to tell you this.

I checked the python source ...

===> find /usr/lib/python2.7/ -name '*.py'|xargs grep 'with open' | sed -nre 's/^.*as (.*):.*$/\1/p'| sort | uniq -c | sort -rn
    113 f
     22 fp
     16 fd

... the result is not what I guessed before. The single character f is very common.

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

No branches or pull requests

2 participants