我刚刚阅读了关于邮政炸弹 ,即包含非常大量的高度可压缩数据(00000000000000000 …)的zip文件。 打开时,它们将填充服务器的磁盘。 如何在解压缩之前检测到一个zip文件是一个zip压缩文件? 更新你能告诉我这是怎么做的Python或Java?
在MNIST初学者教程中 ,有accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) tf.cast基本上改变了对象的张量types,但是tf.reduce_mean和np.mean什么np.mean呢? 这里是关于tf.reduce_mean的文档: reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None) input_tensor: The tensor to reduce. Should have numeric type. reduction_indices: The dimensions to reduce. If `None` (the defaut), reduces all dimensions. # 'x' is [[1., 1. ]] # [2., 2.]] tf.reduce_mean(x) ==> 1.5 tf.reduce_mean(x, 0) ==> [1.5, 1.5] tf.reduce_mean(x, 1) ==> [1., 2.] 对于一维vector,它看起来像np.mean […]
此代码返回以下错误消息: 在out_f中打开(infile,mode ='r',buffering = -1)in_f,open(outfile,mode ='w',buffering = -1)TypeError:强制为Unicode:需要string或缓冲区,find文件 # Opens each file to read/modify infile=open('110331_HS1A_1_rtTA.result','r') outfile=open('2.txt','w') import re with open (infile, mode='r', buffering=-1) as in_f, open (outfile, mode='w', buffering=-1) as out_f: f = (i for i in in_f if i.rstrip()) for line in f: _, k = line.split('\t',1) x = re.findall(r'^1..100\t([+-])chr(\d+):(\d+)\.\.(\d+).+$',k) if not x: continue […]
python是否有不可变的列表? 假设我希望有一个有序的元素集合的function,但是我想要保证的function不会改变,这怎么能实现? 列表是有序的,但它们可以被改变。
你如何创build一个Bash脚本来激活一个Python的virtualenv? 我有一个目录结构,如: .env bin activate …other virtualenv files… src shell.sh …my code… 我可以激活我的virtualenv: user@localhost:src$ . ../.env/bin/activate (.env)user@localhost:src$ 但是,从Bash脚本执行相同的操作却什么也不做: user@localhost:src$ cat shell.sh #!/bin/bash . ../.env/bin/activate user@localhost:src$ ./shell.sh user@localhost:src$ 我究竟做错了什么?
尝试执行使用多处理程序包的python程序时出现错误: File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line 178, in RLock return RLock() File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line 142, in __init__ SemLock.__init__(self, RECURSIVE_MUTEX, 1, 1) File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line 49, in __init__ sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue) OSError: [Errno 13] Permission denied 它看起来像用户没有权限访问共享内存。 以root权限执行时,它工作正常。 有没有任何解决scheme,以普通用户(而不是根)运行它? Python版本2.6.2,OS是Linux 2.6.18(CentOS版本5.4),它是VPS机器。
我试图产生一个树结构的stream程图。 我已经能够用networkx创build代表性的graphics,但是当我输出一个graphics时,我需要一种显示树形结构的方法。 我正在使用matplotlib.pylab来绘制graphics。 我需要以类似于这里显示的结构显示数据。 虽然我没有子图。 我怎样才能保证这样的结构? 非信徒的例子: 我已经能够用pylab和graphviz显示graphics,但都不提供我正在寻找的树形结构。 我试过每个布局networking必须提供,但没有一个显示层次结构 。 我只是不知道什么选项/模式给予或如果我需要使用权重。 任何build议将帮助一堆。 @jterrace: 下面是我用来制作上面情节的粗略概述。 我已经添加了一些标签,但除此之外它是一样的。 import networkx as nx import matplotlib.pyplot as plt G = nx.Graph() G.add_node("ROOT") for i in xrange(5): G.add_node("Child_%i" % i) G.add_node("Grandchild_%i" % i) G.add_node("Greatgrandchild_%i" % i) G.add_edge("ROOT", "Child_%i" % i) G.add_edge("Child_%i" % i, "Grandchild_%i" % i) G.add_edge("Grandchild_%i" % i, "Greatgrandchild_%i" % […]
我正在尝试使用Sphinx为我的代码库自动生成基本文档。 然而,我很难指示狮身人面像recursion扫描我的文件。 我有一个像下面这样的文件夹结构的Python代码库: <workspace> src mypackage __init__.py subpackageA __init__.py submoduleA1 submoduleA2 subpackageB __init__.py submoduleB1 submoduleB2 我在<workspace>运行了sphinx-quickstart,所以现在我的结构如下所示: <workspace> src mypackage __init__.py subpackageA __init__.py submoduleA1 submoduleA2 subpackageB __init__.py submoduleB1 submoduleB2 index.rst _build _static _templates 我已经阅读了快速入门教程http://sphinx.pocoo.org/tutorial.html ,虽然我仍然试图理解文档,但是它的措辞让我担心Sphinx假设我将手动创build我的代码库中的每个模块/类/function的文档文件。 但是,我注意到了“automodule”语句,并且在快速启动期间启用了autodoc,所以我希望能够自动生成大部分文档。 我修改我的conf.py添加我的src文件夹到sys.path,然后修改我的index.rst使用automodule。 所以现在我的index.rst看起来像: Contents: .. toctree:: :maxdepth: 2 Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` .. automodule:: alphabuyer […]
使用pythons(2.7)'json'模块我正在寻找处理各种JSON提要。 不幸的是,这些提要中的一些不符合JSON标准 – 特定的某些键不包含在双重语音标记(“)中,这导致Python出错。 在编写一段丑陋的代码来parsing和修复传入的数据之前,我想我会问 – 是否有任何方法可以让Pythonparsing这个畸形的JSON或“修复”数据,以便它有效的JSON? 工作示例 import json >>> json.loads('{"key1":1,"key2":2,"key3":3}') {'key3': 3, 'key2': 2, 'key1': 1} 破碎的例子 import json >>> json.loads('{key1:1,key2:2,key3:3}') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\json\__init__.py", line 310, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 346, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File […]
如何获得与C的localtime呼叫给定的值相对应的Olson时区名称 (如Australia/Sydney )? 这是通过TZ覆盖的值,通过symlinking /etc/localtime ,或在时间相关的系统configuration文件中设置TIMEZONEvariables。