Reasons behind naming in easy-to-confuse Python's classes such as OS and SYS?
Asked Answered
B

2

3

I have noticed that considerably amount of questions in SO, relating to Python, are about people messing up Sys -class, OS class and no class. For example, an easy confusing is the case: os.open("something"), open("something") and sys.open("something"). I haven't understood yet the reasons behind the naming of classes, perhaps it is just an evolution.

  1. I would like to hear why they were created with their current names?
  2. Are naming due to things like having FDs in a class?
  3. Is naming because some classes require special privileges?
  4. To which extent is the naming a design solution?

If you cannot answer the question, feel free to suggest some good mnemonics to memorize the classes and to differentiate them.

Brummett answered 9/4, 2011 at 2:6 Comment(1)
There's no "class" for the built-in open function. It's a function. Not a member of a class. It's called a built-in function in the Python documentation. Here's the list: docs.python.org/library/functions.html#built-in-functions Please revise your question to use the proper name, otherwise it will be hopelessly confusing.Auroora
A
2

Built-in functions are things that you need often. You do not have to import any module to access them, and thus don't use any module prefix either. open() is one such function, since opening files is a very common operation. It opens a file and returns a file object, which is easy to use.

The os module is for operating system interfaces. os.open() is a raw interface to the file interface of the operating system. It opens a file and returns the bare file descriptor, which you do not normally need for anything.

The sys module is for system-specific things. sys.open() does not exist.

Asare answered 9/4, 2011 at 2:40 Comment(0)
A
3

Easy confusing is lies in the case: os.open("something"), open("something") and sys.open("something").

A "mnemonic" is the documentation, available on-line or downloaded to your workstation.

The "mnemonic" is easy. Use the one that matches your requirements.

why they were created with their current names

To keep clutter out of the language an in separate libraries.

Are naming due to things like having FDs in a class?

Probably. FD's are an OS feature, not a language feature. That's why they're in a separate library.

Is naming because some classes require special privileges?

Not at all.

To which extent is the naming a design solution?

To keep clutter out of the language an in separate libraries.

Auroora answered 9/4, 2011 at 2:39 Comment(3)
@hhh: Please delete the "New question analyzing just rings" comment. It is confusing because it is not related to this answer or this question at all. Please delete it.Auroora
It investigates statements such as "This function is intended for low-level I/O." and privileges. I think it is too much for this question, better for a new question. Sorry but I want to understand what your answer really incur. Are the low-level things rings or something else? It is not clear yet. The question analyzing deeper them here.Brummett
@hhh: Please try to focus. One question or the other. Try to avoid links between questions in comments. "Low-level" in this context has nothing to do with any "rings". "Rings" are just permissions. Nothing more. Here, "low-level" means OS-level ("low") or Python library level ("high"). Low-level == OS level == raw OS open/close/read/write == no Python parsing or buffering == byte-level I/O. High-level == Python library == Python parsing and buffering == Python strings.Auroora
A
2

Built-in functions are things that you need often. You do not have to import any module to access them, and thus don't use any module prefix either. open() is one such function, since opening files is a very common operation. It opens a file and returns a file object, which is easy to use.

The os module is for operating system interfaces. os.open() is a raw interface to the file interface of the operating system. It opens a file and returns the bare file descriptor, which you do not normally need for anything.

The sys module is for system-specific things. sys.open() does not exist.

Asare answered 9/4, 2011 at 2:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.