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

[quote] * 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[/quote]

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

[color=red]如何将unicode编码的含有中文字符的url地址转换成符合url地址要求的地址?[/color]
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值