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

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.

主站蜘蛛池模板: 武川县| 南华县| 商城县| 深圳市| 丘北县| 资中县| 钟山县| 丹巴县| 鹰潭市| 五常市| 九江县| 尚志市| 阿瓦提县| 新余市| 花莲市| 奉贤区| 饶平县| 西青区| 衡东县| 大埔区| 大关县| 长汀县| 洛川县| 鲜城| 中超| 商南县| 洮南市| 莱西市| 城口县| 文化| 青岛市| 九江县| 凌源市| 阿鲁科尔沁旗| 墨脱县| 循化| 余江县| 同德县| 娄烦县| 兴安盟| 龙岩市|