我想在基于Python的官方图像python:2.7.9-wheezy的Docker容器中打开一个搁架.但是我收到导入错误.
syncer/util.py:19: in get_from_shelve
db = shelve.open(conf.SHELVE_LOCATION)
/usr/local/lib/python2.7/shelve.py:239: in open
return DbfilenameShelf(filename, flag, protocol, writeback)
/usr/local/lib/python2.7/shelve.py:223: in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback)
/usr/local/lib/python2.7/anydbm.py:84: in open
mod = __import__(result)
/usr/local/lib/python2.7/dbhash.py:7: in <module>
import bsddb
...
E ImportError: No module named _bsddb
Run Code Online (Sandbox Code Playgroud)
在我的主机上问题不存在,_bsddb位于
/usr/lib/python2.7/lib-dynload/_bsddb.so.这个文件也可以在我的Docker容器中使用,所以我不明白为什么它无法导入.
Ignacio Vazquez-Abrams建议安装db4-devel,但我的容器中没有此包.
如何打开Docker容器中的搁架?
我使用Nginx,uWSGI和Python Flask应用程序进行了设置.您可以在下面找到Nginx配置的服务器指令:
location /api {
try_files $uri @api;
}
location @api {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
Run Code Online (Sandbox Code Playgroud)
我用uWSGI开始uwsgi --ini /etc/uwsgi.ini.那个文件看起来像这样:
[uwsgi]
uid = root
gid = root
socket = 127.0.0.1:3031
module = iris.api
callable = app
Run Code Online (Sandbox Code Playgroud)
请求/工作正常,Nginx返回"欢迎使用Nginx"页面.但要求/api失败.第一个请求/api/analog_output/1通过uWSGI传递给Python应用程序.Python应用程序返回HTTP 200响应,但Nginx没有通过将此响应发送回客户端来完成请求.
--- Operational MODE: single process --- WSGI app 0 (mountpoint='') ready in 11 seconds on interpreter 0x1567e8 pid: 957 (default app)
--- uWSGI is running in multiple interpreter mode --- spawned uWSGI worker 1 …Run Code Online (Sandbox Code Playgroud) 我有一个正则表达式,允许字符串为空.如果它不为空,则字符串可能只包含字母和空格.但它可能无法以空格开始或结束.
这个RegExp应该做这个工作:
^(?! )[a-zA-Z]*[a-zA-Z ]*$
我在这里测试过:http://tools.netshiftmedia.com/regexlibrary/
但是当我在我的js中实现它时,它不允许字符串为空.
这是代码
function validatePreposition(name) {
string = string = document.forms['form'][name].value;
pattern = new RegExp('^(?! )[a-zA-Z]*[a-zA-Z ]*$');
checkString(name, pattern, string);
}
function checkString(name, pattern, string) {
if(!pattern.test(string)) {
error[name] = 1;
} else {
error[name] = 0;
}
printErrors();
}
Run Code Online (Sandbox Code Playgroud)
如何更改我的代码以便允许空字符串?
这些<<=和|=运算符对Python意味着什么?我猜他们是按位运算符.我知道运算符|(按位或)和<<(位移),但我不知道它们与...结合=.
我在这段代码中找到了它.下面的代码属于该代码.
commandout = adcnum
commandout |= 0x18 # start bit + single-ended bit
commandout <<= 3 # we only need to send 5 bits here
for i in range(5):
if (commandout & 0x80):
GPIO.output(mosipin, True)
else:
GPIO.output(mosipin, False)
commandout <<= 1
GPIO.output(clockpin, True)
GPIO.output(clockpin, False)
Run Code Online (Sandbox Code Playgroud) 我一直在努力重命名Python项目的项目文件夹。它被称为Foo,我希望将其重命名为Bar。
Foo/
/src
__init__.py
x.py
/test
__init__.py
x_test.py
__init__.py
Run Code Online (Sandbox Code Playgroud)
成为
Bar/
/src
__init__.py
x.py
/test
__init__.py
x_test.py
__init__.py
Run Code Online (Sandbox Code Playgroud)
当项目文件夹命名为Foo时,我所有的测试都通过了,但是将其重命名为Bar后,我的测试不再起作用。所有的进口都会增加ImportError: no module src.x。
我可以在使用python控制台时导入模块:
$ python
>>> import src.x
Run Code Online (Sandbox Code Playgroud)
然后,当我将Bar重命名为Foo并运行测试时,会出现此错误:
import file mismatch:
imported module 'test.x' has this __file__ attribute:
/home/orangetux/projects/Foo/test/x_test.py
which is not the same as the test file we want to collect:
/home/orangetux/projects/Bar/test/x_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
Run Code Online (Sandbox Code Playgroud)
我可以通过删除所有__pycache__文件夹来解决此问题。但是现在我又回来了。一个名为Foo且具有工作测试的文件夹。如何将项目文件夹重命名为Bar并保持测试正常?
class Test: pass
print(Test.__subclasses__())
Run Code Online (Sandbox Code Playgroud)
收益:
AttributeError: class Test has no attribute '__subclasses__'
Run Code Online (Sandbox Code Playgroud)
和
print(int.__subclasses__())
Run Code Online (Sandbox Code Playgroud)
收益:
[<type 'bool'>]
Run Code Online (Sandbox Code Playgroud)
为什么我不能在自定义对象上调用subclasses()?
这种内置方法不是自定义类型的reserver,是吗?
每个类都保留一个对其直接子类的弱引用列表.此方法返回所有仍然存活的引用的列表.例:
我想\n从头开始删除这样的行\n id int(10) NOT NULL.我试过strip(),rstrip(),lstrip() replace('\n', '').我不明白.我究竟做错了什么?
print(column)
print(column.__class__)
x = column.rstrip('\n')
print(x)
x = column.lstrip('\n')
print(x)
x = column.strip('\n')
print(x)
print(repr(column))
Run Code Online (Sandbox Code Playgroud)
给
\n id int(10) NOT NULL
<type 'str'>
\n id int(10) NOT NULL
\n id int(10) NOT NULL
\n id int(10) NOT NULL
\n id int(10) NOT NULL
'\\n `id` int(10) NOT NULL'
Run Code Online (Sandbox Code Playgroud)