我试图理解为什么Python被认为是一种美丽的语言.我被引导到PEP 8的美丽......这很奇怪.实际上它说你可以使用你想要的任何约定,只是保持一致......然后突然我在核心库中发现了一些奇怪的东西:
request()
getresponse()
set_debuglevel()
endheaders()
http://docs.python.org/py3k/library/http.client.html
Run Code Online (Sandbox Code Playgroud)
以下函数是Python 3.1中的新功能.这里使用PEP 8约定的哪一部分?
popitem()
move_to_end()
http://docs.python.org/py3k/library/collections.html
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:PEP 8是否在核心库中使用?为什么会那样?
是否存在与PHP相同的情况,我不能只记住函数的名称,因为有可能编写名称的所有方法?
为什么即使是新功能,PEP 8也不会在核心库中使用?
我使用Python下载了一个bz2文件.然后我想用以下方法解压缩档案:
def unpack_file(dir, file):
cwd = os.getcwd()
os.chdir(dir)
print "Unpacking file %s" % file
cmd = "tar -jxf %s" % file
print cmd
os.system(cmd)
os.chdir(cwd)
Run Code Online (Sandbox Code Playgroud)
不幸的是,这以错误结束:
bzip2: Compressed file ends unexpectedly;
perhaps it is corrupted? *Possible* reason follows.
bzip2: Inappropriate ioctl for device
Input file = (stdin), output file = (stdout)
It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.
You can use the `bzip2recover' program to …Run Code Online (Sandbox Code Playgroud) 我不明白有一些CMake魔法.对于包含这样的目录的小型C++项目,CMakeLists.txt文件应该如何?
.
??? bin
??? src
??? src
??? test
bin — directory for built program
src/src — directory for source
src/test — directory for tests
Run Code Online (Sandbox Code Playgroud)
测试需要包含src/src中的文件.我想管理cmake的所有操作,但是此时我甚至不能让cmake在src/c.cpp中编译文件.
任何帮助,欢迎链接.
对于Django测试,我想加载一个在csv文件中的fixture.最好的方法是什么?
我的测试有问题.有一种算法用于一些奇特的程序.该算法从一个范围[-999,999; +999,999],将其视为表中的id号,并在数据库中执行一些随机操作.这意味着我需要多次调用该方法以确保随机数分布正确.
我想用TDD编写所有代码(只是为了更多地学习它).
问题是我不知道如何用TDD原理测试算法.
根据TDD,如果不首先编写测试,则不应运行代码.
我想到的解决方案之一是在主类中使用一个名为debug(text)的伪方法.此方法在生产代码中不执行任何操作.然而,我会使这个方法的子类重载,这次它会存储一些有趣的信息.以后可以通过测试使用此信息来确定函数是否正常工作.数据库连接将被模拟,不会执行任何操作.
另一种解决方案是创建一个模拟的数据库连接,该连接将存储稍后在测试中使用的有趣信息.然而,创建这样的连接将是如此巨大的工作,我认为不值得花时间.
稍后将进行集成测试以检查数据库是否正确更改.但集成测试不是TDD的一部分.
我是否进入了TDD失败且无用或难以使用的地方?
我在文件'bin/test'中有一个简单的python脚本:
#!/usr/bin/env python
import argparse
PROGRAM_NAME = "name"
PROGRAM_VERSION = "0.0.1"
PROGRAM_DESCRIPTION = "desc"
parser = argparse.ArgumentParser(prog=PROGRAM_NAME, description=PROGRAM_DESCRIPTION)
parser.add_argument('--version', action='version', version='%(prog)s ' + PROGRAM_VERSION)
args = parser.parse_args()
Run Code Online (Sandbox Code Playgroud)
当我用--versionparam 运行它,或者--help,它打印一切OK:
$ bin/test --version
name 0.0.1
$ bin/test --help
usage: name [-h] [--version]
desc
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
Run Code Online (Sandbox Code Playgroud)
当我使用文件运行时subprocess.check_output,它没有得到任何东西:
>>> subprocess.check_output(["bin/test", "--help"], stderr=subprocess.STDOUT, shell=True)
''
>>> subprocess.check_output(["bin/test", "--version"], stderr=subprocess.STDOUT, shell=True)
''
Run Code Online (Sandbox Code Playgroud)
我正在使用带有Python版本的Ubuntu 11.10: …