官术网_书友最值得收藏!

Adding modules to the package

Now, let's take look at how to add actual code to the package and look out for a couple of pitfalls to avoid.

Python modules have the same name as objects that they have as filenames, except without the .py suffix. This means that the filenames need to be valid Python variable names  and also that they should use letters and symbols that are reliably available across different operating systems. The following screenshot showns an example for this:

So, module names should not start with a number because Python variables are not allowed to start with numbers. Also, it should not use capital letters because some common operating system don't differentiate between filenames containing capital letters and filenames that are all lowercase. As long as we stay within Python variable name guidelines and remember to use a .py suffix, we can name our modules anything we please.

So, we just pick a filename and start writing Python code into a file with that name in the package folder. That simple scenario is also the common case, but there's another possibility.

主站蜘蛛池模板: 鄂托克旗| 崇明县| 耿马| 南宁市| 白水县| 本溪| 桐庐县| 大庆市| 旬阳县| 临武县| 潍坊市| 苏尼特左旗| 甘孜县| 鄄城县| 太和县| 抚顺市| 思茅市| 麻江县| 兴化市| 叙永县| 敦化市| 巴南区| 武宣县| 红河县| 星子县| 高淳县| 波密县| 正阳县| 泸定县| 蓬莱市| 保德县| 荣成市| 扶余县| 墨脱县| 扎兰屯市| 晋州市| 新野县| 庆元县| 定兴县| 凤冈县| 清河县|