为什么下划线比文件名的连字符更好? [英] Why are underscores better than hyphens for file names?

查看:335
本文介绍了为什么下划线比文件名的连字符更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自使用Python构建技能:

exercise_1.py这样的文件名胜于execise-1.py的文件名.我们可以从命令行很好地运行两个程序,但是带有连字符的名称限制了我们编写更大,更复杂程序的能力.

A file name like exercise_1.py is better than the name execise-1.py. We can run both programs equally well from the command line, but the name with the hyphen limits our ability to write larger and more sophisticated programs.

这是为什么?

推荐答案

此处的问题是使用连字符-减号(默认键盘键-; U+002D)的名称无效,因为它表示Python中的减号.因此,如果您要导入自己的模块,则其名称中不应包含连字符:

The issue here is that importing files with the hyphen-minus (the default keyboard key -; U+002D) in their name doesn't work since it represents minus signs in Python. So, if you had your own module you wanted to import, it shouldn't have a hyphen in its name:

>>> import test-1
  File "<stdin>", line 1
    import test-1
               ^
SyntaxError: invalid syntax
>>> import test_1
>>>

大型程序倾向于在逻辑上分为许多不同的模块,因此引号

Larger programs tend to be logically separated into many different modules, hence the quote

带连字符的名称限制了我们编写更大,更复杂的程序的能力.

the name with the hyphen limits our ability to write larger and more sophisticated programs.

这篇关于为什么下划线比文件名的连字符更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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