我已经尝试阅读有关兄弟进口甚至 包文档的问题,但我还没有找到答案.
具有以下结构:
??? LICENSE.md
??? README.md
??? api
? ??? __init__.py
? ??? api.py
? ??? api_key.py
??? examples
? ??? __init__.py
? ??? example_one.py
? ??? example_two.py
??? tests
? ??? __init__.py
? ??? test_one.py
Run Code Online (Sandbox Code Playgroud)
如何在脚本 examples和tests目录从导入
api模块,并可以从命令行运行?
此外,我想避免sys.path.insert每个文件的丑陋黑客.当然这可以在Python中完成,对吧?
我正在测试以前的一个问题中的以下代码(将列表转换为字典):
single = ['key1', 'value1', 'key2', 'value2', 'key3', 'value3']
if __name__ == '__main__':
from timeit import Timer
print Timer("dict(zip(single[::2], single[1::2]))",
"from __main__ import single").timeit()
print Timer("si = iter(single); dict(izip(si, si))",
"from __main__ import single; from itertools import izip").timeit()
Run Code Online (Sandbox Code Playgroud)
而我不能确定是否使用时,最好的做法timeit是进口izip的Timer的语句或设置(我假设的设置,但最终的结果时间有所不同,这取决于我做的).
无论如何,我只是希望你们在为代码计时等时获得任何额外的见解.(另外,我只是想学习 - 我不会因为过早的优化或任何事情而受苦.)
谢谢.
使用保存在名为foo.txt的文件中的这个虚拟代码...
COG,station1,station2,station3,station4,station5
COG000Z,0.019393497,0.183122497,0.089911227,0.283250444,0.074110521
COG0002,0.044632051,0.019118032,0.034625785,0.069892277,0.034073709
COG0001,0.033066112,0,0,0,0
COG0004,0.115086472,0.098805295,0.148167492,0.040019101,0.043982814
COG0005,0.064613057,0.03924007,0.105262559,0.076839235,0.031070155
COG0006,0.079920475,0.188586049,0.123607421,0.27101229,0.274806929
COG0007,0.051727492,0.066311584,0.080655401,0.027024185,0.059156417
COG0008,0.126254841,0.108478559,0.139106704,0.056430812,0.099823028
Run Code Online (Sandbox Code Playgroud)
我在ggplot2中制作了一个热图,其中附带的代码来自于stackexchange上的这个答案.
> library(ggplot2)
> foo = read.table('foo.txt', header=T, sep=',')
> foomelt = melt(foo)
Using COG as id variables
> ggplot(foomelt, aes(x=COG, y=variable, fill=value)) + geom_tile() + scale_fill_gradient(low='white', high='steelblue')
Run Code Online (Sandbox Code Playgroud)
它产生了一个非常好的热图,但我真的只是在每个瓷砖的颜色代码之后(基本上是原始的foo,但用颜色代码代替每个变量).知道如何去做吗?
我有这个清单:
single = ['key1', 'value1', 'key2', 'value2', 'key3', 'value3']
Run Code Online (Sandbox Code Playgroud)
从这里创建字典的最佳方法是什么?
谢谢.
我有兴趣获取这些人口普查制图文件并将它们转换为 SVG 文件。到目前为止,我已经找到了这个shptosvg Perl 脚本,但我真的更喜欢在 Python 中进行任何编码或数据处理。
另外,我知道shpUtils.py可用于解析 Python 中的 .shp 文件,但我不知道如何获取该输出并创建 SVG 路径。
无论如何,我肯定会对你们的任何建议或你知道的模块感兴趣。