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

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.

主站蜘蛛池模板: 金门县| 博乐市| 扶风县| 贡嘎县| 铅山县| 彭水| 岳阳市| 昭觉县| 油尖旺区| 江源县| 金山区| 泉州市| 沈阳市| 甘南县| 江都市| 巴楚县| 井陉县| 贺兰县| 镇雄县| 永仁县| 惠东县| 昆山市| 咸宁市| 永年县| 康乐县| 东乡县| 综艺| 金溪县| 台东县| 南宁市| 文安县| 新源县| 临泉县| 景泰县| 缙云县| 册亨县| 蚌埠市| 邹平县| 镇原县| 西城区| 常山县|