问题:

我是Python的新手,想要使用它的plot功能来创建图形。 我使用的是ubuntu 12.04。 我按照http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/上的Python安装步骤进行操作,但是当我这样做时

from pylab import *

我收到了这个错误

>>> from pylab import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pylab

我的Python版本是python 2.7 谁能告诉我这里缺少什么?

I am new to Python and want to use its plot functionality to create graphs.I am using ubuntu 12.04.I followed the Python installation steps from http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/ but when I doI am getting this errorMy Python version is python 2.7 .Can anybody tell me what I am missing here?

问题:

我只是用Python测试工程中的数值方法的一个例子。

from numpy import zeros, array
from math import sin, log
from newtonRaphson2 import *

def f(x):
    f = zeros(len(x))
    f[0] = sin(x[0]) + x[1]**2 + log(x[2]) - 7.0
    f[1] = 3.0*x[0] + 2.0**x[1] - x[2]**3 + 1.0
    f[2] = x[0] + x[1] + x[2] -5.0
    return f

x = array([1.0, 1.0, 1.0])
print newtonRaphson2(f,x)

当我运行它时,它显示以下错误:

File "example NR2method.py", line 8, in f
    f[0] = sin(x[0]) + x[1]**2 + log(x[2]) - 7.0
ValueError: math domain error

我已将其缩小到日志,因为当我删除日志并添加其他功能时,它可以正常工作。 我认为这是因为对基地的某种干扰,我无法弄清楚如何。 谁有人建议解决方案?

I was just testing an example from Numerical Methods in Engineering with Python .When I run it, it shows the following error:I have narrowed it down to the log as when I remove log and add a different function, it works.I assume it is because of some sort of interference with the base, I can’t figure out how.Can anyone suggest a solution?

问题:

我正在尝试运行使用Django 1.6的statsd / graphite。

访问石墨URL时,出现Django模块错误

django.conf.urls.defaults中的文件“ /opt/graphite/webapp/graphite/urls.py”,第15行,导入* ImportError:没有名为默认值的模块

但是,我在/Library/Python/2.7/site-packages/django/conf/urls/找不到默认的 django包

请帮助解决此问题。

I am trying to run statsd/graphite which uses django 1.6.While accessing graphite URL, I get django module errorFile “/opt/graphite/webapp/graphite/urls.py”, line 15, in from django.conf.urls.defaults import * ImportError: No module named defaultsHowever, I do not find defaults django package inside /Library/Python/2.7/site-packages/django/conf/urls/Please help fixing this issue.

问题:

当我定义要在多个远程服务器上运行的任务时,如果任务在服务器1上运行并退出并出现错误,则Fabric将停止并中止该任务。 但是我想让Fabric忽略错误并在下一个服务器上运行任务。 我该怎么做呢?

例如:

$ fab site1_service_gw
[site1rpt1] Executing task 'site1_service_gw'

[site1fep1] run: echo '[email protected]#' | sudo -S route
[site1fep1] err:
[site1fep1] err: We trust you have received the usual lecture from the local System
[site1fep1] err: Administrator. It usually boils down to these three things:
[site1fep1] err:
[site1fep1] err:     #1) Respect the privacy of others.
[site1fep1] err:     #2) Think before you type.
[site1fep1] err:     #3) With great power comes great responsibility.
[site1fep1] err: root's password:
[site1fep1] err: sudo: route: command not found

Fatal error: run() encountered an error (return code 1) while executing 'echo '[email protected]#' | sudo -S route '

Aborting.

When I define a task to run on several remote servers, if the task runs on server one and exits with an error, Fabric will stop and abort the task.But I want to make fabric ignore the error and run the task on the next server.How can I make it do this?For example:

问题:

我正在使用以下代码处理一些CSV文件:

reader = csv.reader(open(filepath, "rU"))
try:
    for row in reader:
        print 'Row read successfully!', row
except csv.Error, e:
    sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))

一个文件引发此错误:

file my.csv, line 1: line contains NULL byte

我能做什么? Google似乎建议它可能是Excel文件,未正确保存为.csv。 有什么办法可以解决Python中的这个问题?

==更新==

在下面@JohnMachin的评论之后,我尝试将以下行添加到脚本中:

print repr(open(filepath, 'rb').read(200)) # dump 1st 200 bytes of file
data = open(filepath, 'rb').read()
print data.find('\x00')
print data.count('\x00')

这是我得到的输出:

'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\ .... <snip>
8
13834

因此该文件确实包含NUL字节。

I’m working with some CSV files, with the following code:And one file is throwing this error:What can I do?Google seems to suggest that it may be an Excel file that’s been saved as a .csv improperly.Is there any way I can get round this problem in Python?== UPDATE ==Following @JohnMachin’s comment below, I tried adding these lines to my script:And this is the output I got:So the file does indeed contain NUL bytes.