在易于混淆的Python类(例如OS和SYS)中命名的原因是什么? [英] Reasons behind naming in easy-to-confuse Python's classes such as OS and SYS?

查看:75
本文介绍了在易于混淆的Python类(例如OS和SYS)中命名的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注意到,SO中与Python有关的大量问题都是关于人们弄乱Sys-class,OS class和no class的问题.例如,情况很容易混淆:os.open("something")open("something")sys.open("something").我还不了解类命名的原因,也许这只是一个演变.

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. 我想听听why它们是用当前名称创建的吗?
  2. 命名是由于类中有FD之类的吗?
  3. 命名是因为某些类需要特殊特权吗?
  4. 命名设计解决方案的程度是什么?
  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.

推荐答案

内置函数是您经常需要的东西.您无需导入任何模块即可访问它们,因此也无需使用任何模块前缀. open()是这样的功能之一,因为打开文件是非常常见的操作.它会打开一个文件并返回一个易于使用的文件对象.

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.

os模块用于操作系统接口. os.open()是操作系统文件接口的原始接口.它会打开一个文件并返回裸文件描述符,通常不需要任何内容​​.

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.

sys模块用于系统特定的东西. sys.open()不存在.

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

这篇关于在易于混淆的Python类(例如OS和SYS)中命名的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆