`
yoshiyan
  • 浏览: 46511 次
社区版块
存档分类
最新评论

Python笔记

阅读更多
Python Project Structure

Python was conceived as a scripting language.  Unlike compiled languages like C or Java, Python files are designed to be directly runnable.

    * RunMe.java -p someargument < Not ok!
    * RunMe.py -p someargument < Ok!

This is convenient for small scripts, but doesn’t help applications.  Since you are intended to run .py files directly, Python projects should not have source (src) or binary (bin) folders.  Having a source folder makes a program difficult to run.  The root of the Python package structure should be the root of the project.

For the same reason, the test folder should not be separate.  It should be a package in the main project.  Since the root folder is the root package, you won’t have much choice.
Example

引用
    * MyProject
          o __init__.py
          o model
                + __init__.py
                + user.py
          o service
                + __init__.py
                + user_service.py
                + ldap_user_service.py
          o test
                + __init__.py
                + unit
                      # __init__.py
                      # service
                            * __init__.py
                            * user_service_test.py
                + functional
                      # __init__.py
                      # service
                            * __init__.py
                            * user_service_test.py


If you’re new to Python, please note that those __init__.pys are required.  They tell Python which folders contain Python files.  This is Python’s way of allowing you to have other folders, such as config, that don’t contain source files.
Note

You should specify exactly one class per file.  It makes your code easier to find and read.

参考链接:http://www.connorgarvey.com/blog/?p=184

如何将unicode编码的含有中文字符的url地址转换成符合url地址要求的地址?
            pageUrlAscii = pageUrl.encode('utf-8')
            pageUrlValid = urllib.quote(pageUrlAscii, safe=':/')
            pageSource = urllib2.urlopen(pageUrlValid, None, 5).read()

参考链接:http://stackoverflow.com/questions/120951/how-can-i-normalize-a-url-in-python
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics