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

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.

主站蜘蛛池模板: 务川| 虞城县| 晋中市| 新兴县| 德格县| 平凉市| 长宁县| 沂源县| 凌源市| 克拉玛依市| 江城| 昌邑市| 八宿县| 临沂市| 科尔| 体育| 雷州市| 海淀区| 湘乡市| 西宁市| 肇东市| 乐山市| 泽普县| 宜兰县| 铅山县| 察隅县| 大庆市| 松滋市| 綦江县| 巴塘县| 清流县| 道孚县| 尼玛县| 阿克陶县| 芷江| 定州市| 大兴区| 林周县| 尉犁县| 宜州市| 高青县|