问题标签 [python-2.6]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
3948 浏览

python - Python + Leopard + Fink + Mac Ports + Python.org + Idiot = broken Python - fresh start?

I have been enjoying learning the basics of python, but before I started reading things I tried to install various python versions and modules clumsily. Now that I have some ideas of what I want to do and how to do it I'm finding that various aspects are broken. For instance, 2.6 IDLE won't launch, and when I try to import modules they usually don't work.

My question is, how would you recommend I clean this up and start fresh? I have read information about modifying the 2.6 install, but I still can't get it to work.

IDLE 2.4 works, and when I launch python from the terminal I am running python 2.4.4.

0 投票
4 回答
6279 浏览

python - Python 2.6 multiprocessing.Queue 与线程兼容?

我正在试验 Python 2.6 中的新多处理模块。我正在创建几个进程,每个进程都有自己的 multiprocessor.JoinableQueue 实例。每个进程产生一个或多个工作线程(threading.Thread 的子类),它们共享 JoinableQueue 实例(通过每个线程的__init__方法传入)。它似乎通常可以工作,但偶尔会出现无法预料的失败并出现以下错误:

我的 Queue get() 和 task_done() 调用紧随其后,因此它们应该相等。有趣的是,这似乎只有在 get() 和 task_done() 之间完成的工作非常快时才会发生。插入一个小的time.sleep(0.01)似乎可以缓解这个问题。

有什么想法吗?我可以使用带线程的多处理器队列而不是更传统的(Queue.Queue)吗?

谢谢!

-布赖恩

0 投票
4 回答
72228 浏览

python - 如果列表中的所有内容 == 某事

使用 Python 2.6,有没有办法在一个语句中检查序列的所有项目是否等于给定值?

而不是,说:

0 投票
3 回答
5749 浏览

python - Cygwin 和 Python 2.6

python(和编程)的新手。我到底需要 Cygwin 提供什么?我在winxp上运行python 2.6。我可以安全地下载完整的 Cygwin 吗?它看起来就像一大堆东西。

好吧,我不断遇到建议下载各种 cygwin 组件的模块和功能(即管道输出)。cygwin 会改变或修改任何其他操作系统功能或有任何其他副作用吗?

0 投票
3 回答
2447 浏览

python - 为什么 Python 2.6 增加了一个全局的 next() 函数?

我注意到 Python2.6 在它的全局函数列表中添加了一个 next() 。

next(iterator[, default])

如果default给出,则在迭代器耗尽时返回,否则 StopIteration引发。

添加这个的动机是什么?你能用你next(iterator)不能做的事情iterator.next()except处理 StopIteration 的子句做什么?

0 投票
1 回答
515 浏览

python - Django 模板如果标签在检查 bool True 时在 FastCGI 下不起作用

我在 Python 2.6 + Ubuntu + Apache 2.2 + FastCGI 下的 Django 部署有一个奇怪的问题。

如果我有这样的模板:

它应该输出字符串“It Worked!!!”。它不在我的带有 mod_fastcgi 的生产服务器上。

当我使用 runserver 在本地运行时,这非常有效。

为了方便起见,我将代码修改为以下代码以使其工作,问题就消失了。

似乎模板解析器在 FastCGI 下运行时,无法确定 bool 变量的真实性(或真实性)[如果您获得参考,请恭喜]。

有人见过这个吗?你有解决方案吗?

0 投票
5 回答
9797 浏览

python - Windows 上的 Python 2.6:如何使用“shell=True”参数终止 subprocess.Popen?

有没有办法终止以 subprocess.Popen 类启动的进程,其中“shell”参数设置为“True”?在下面的最小工作示例中(使用 wxPython),您可以愉快地打开和终止记事本进程,但是如果您将 Popen“shell”参数更改为“True”,则记事本进程不会终止。

为了这个问题,请接受“shell”确实必须等于“True”。

0 投票
7 回答
37246 浏览

python - Python 2.6 JSON 解码性能

我正在使用jsonPython 2.6 中的模块来加载和解码 JSON 文件。但是,我目前的表现比预期的要慢。json.loads()我正在使用一个大小为 6MB 且需要 20 秒的测试用例。

我认为该json模块有一些本机代码来加速解码?

我如何检查是否正在使用它?

作为比较,我下载并安装了python-cjson模块,并且cjson.decode()对于相同的测试用例需要 1 秒。

我宁愿使用 Python 2.6 提供的 JSON 模块,这样我的代码的用户就不需要安装额外的模块。

(我在 Mac OS X 上开发,但在 Windows XP 上得到了类似的结果。)

0 投票
3 回答
17959 浏览

python - 在 Python 2.6 中用对应的 utf-8 字符替换 html 实体

我有一个这样的html文本:

我想把它转换成可读的东西:

在 Python 中有什么简单(快速)的方法吗?

0 投票
5 回答
45129 浏览

python - Python 2.6 中的随机字符串(可以吗?)

我一直在尝试找到一种更 Pythonic 的方式来在 python 中生成随机字符串,它也可以扩展。通常,我看到类似于

如果你想生成长字符串,那就太糟糕了。

我一直在考虑 random.getrandombits ,并弄清楚如何将其转换为位数组,然后对其进行十六进制编码。使用 python 2.6 我遇到了未记录的 bitarray 对象。不知何故,我让它工作了,它似乎真的很快。

它会在大约 3 秒内在我的笔记本上生成一个 5000 万个随机字符串。


编辑

heikogerlach 指出是奇数个字符导致了这个问题。添加了新代码以确保它始终从十六进制发送偶数个十六进制数字。

仍然很好奇是否有更好的方法来做到这一点同样快。