小编Jak*_*yer的帖子

如何在Python单元测试中运行Single Test Suite中的多个类?

如何在Python单元测试中运行单个测试套件中的多个类.....

python unit-testing

26
推荐指数
3
解决办法
2万
查看次数

任何人都可以告诉我的关系有什么不对吗?

我使用sqlalchemy设计一个论坛风格的网站.我开始淘汰设计,但每当我尝试使用一些插件进行测试时,它就会丢弃一块砖;

NoForeignKeysError: Could not determine join condition between parent/child 
tables on relationship Thread.replies - there are no foreign keys linking 
these tables. Ensure that referencing columns are associated with a 
ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
Run Code Online (Sandbox Code Playgroud)

这是我的"模特"

from sqlalchemy import Integer, Column, String, create_engine, ForeignKey
from sqlalchemy.orm import relationship, sessionmaker, backref
from .database import Base # declarative base instance

class User(Base):
    __tablename__ = "user"
    id = Column(Integer, primary_key=True)
    username = Column(String, unique=True)
    email = Column(String, unique=True)
    threads = …
Run Code Online (Sandbox Code Playgroud)

python orm sqlalchemy

14
推荐指数
2
解决办法
6288
查看次数

从youtube下载flv格式的视频.

我真的不明白youtube是如何提供视频的,但我一直在阅读我能做的事情,似乎旧的方法get_video现在已经过时而且不能再使用了因为这样我会问是否还有另一个pythonic和简单收集YouTube视频的方法.

python youtube download urllib2

11
推荐指数
2
解决办法
1万
查看次数

无法使用Python 2.6导入SQLite

我在Unix上运行Python 2.6,当我运行交互式提示符(SQLite应该是预装的)时,我得到:

[root@idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sqlite
>>>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

python sqlite

10
推荐指数
3
解决办法
2万
查看次数

不能创造超过10个mqueues

我正在使用一个包含posix实时扩展的python模块来获取MessageQueues.

这是python代码

#!/usr/bin env python
import uuid
import posix_ipc
import time

def spawn():
    return posix_ipc.MessageQueue("/%s" % uuid.uuid4(), flags=posix_ipc.O_CREAT)

i = 0
while True:
    i += 1
    spawn()
    print(i)
Run Code Online (Sandbox Code Playgroud)

这将在报告之前创建大约10 mq OSError: This process already has the maximum number of files open

我调查了mq限制和rlimit并检查它们都设置得非常高.例如

fs.file-max = 2097152
fs.mqueue.msg_max = 1000
fs.mqueue.queues_max = 1000
Run Code Online (Sandbox Code Playgroud)

即使对于特权用户,它仍然只能创建大约10个队列.

直接使用实时扩展的等效C如下

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <mqueue.h>

#define handle_error(msg) \
    do { perror(msg); exit(EXIT_FAILURE); } while (0)

int main(int argc, …
Run Code Online (Sandbox Code Playgroud)

c python posix mqueue

9
推荐指数
1
解决办法
790
查看次数

实施SWIG类型

所以我有以下C++

#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

int hello(char *str);

int hello(char *str) {
    cout << "Hello World: " << str << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

以及swig接口

%module sphp

%{
extern int hello(char *str);
%}

extern int hello(char *str);
Run Code Online (Sandbox Code Playgroud)

我可以在php中编译和使用它,

php> hello("testing!");
Run Code Online (Sandbox Code Playgroud)

这一切都是邪恶的!

唯一的问题是

php> hello(3);
Run Code Online (Sandbox Code Playgroud)

仍然有效.我不想要这个,似乎默默无闻地投下了类型

  /*@SWIG:/usr/share/swig2.0/php/utils.i,62,CONVERT_STRING_IN@*/
  if ((*args[0])->type==IS_NULL) {
    arg1 = (char *) 0;
  } else {
    convert_to_string_ex(args[0]);
    arg1 = (char *) Z_STRVAL_PP(args[0]);
  }
  /*@SWIG@*/;
Run Code Online (Sandbox Code Playgroud)

现在我不想编辑包装器,因为它是自动生成的.有没有办法可以关闭这个静默转换,这样hello(3)就会抛出异常或错误,或者我可以提一下hello它最初传递的php参数的类型吗?

php c++ swig

7
推荐指数
1
解决办法
322
查看次数

如何按python降序排序整数列表

我试图以不同的方式解决这个问题,但没有成功.我一直按升序排序,而不是在打印时按降序排序.

ListB = [24, 13, -15, -36, 8, 22, 48, 25, 46, -9]
sorted(ListB, key=int, reverse=True)
print sorted(ListB)
Run Code Online (Sandbox Code Playgroud)

python list

7
推荐指数
2
解决办法
3万
查看次数

在龙卷风python中设置openId

嘿所有......我一直在阅读龙卷风文档,并遇到了开放的id mixin,所以我心里想着"邪恶的没有可怕的密码系统在我身边"然后我研究了如何实现它,我遇到的唯一例子就是这个

class GoogleHandler(tornado.web.RequestHandler, tornado.auth.GoogleMixin):
    @tornado.web.asynchronous
    def get(self):
        if self.get_argument("openid.mode", None):
            self.get_authenticated_user(self.async_callback(self._on_auth))
            return
        self.authenticate_redirect()

    def _on_auth(self, user):
        if not user:
            raise tornado.web.HTTPError(500, "Google auth failed")
Run Code Online (Sandbox Code Playgroud)

其中没有显示更大的图片,如路线,appsettings等等#用例如set_secure_cookie()保存用户

所以我的问题是.这如何适应龙卷风网站的大局.

python openid document tornado

3
推荐指数
1
解决办法
1080
查看次数

学习java,为什么我的私有私有?

我正在学习java,来自python有很多我不完全理解的东西存在于java中,其中第一个必须是公共和私有声明.我的意思是从一种没有真正可见的公共私人声明的语言到一切必须是私人的语言,我理解他们所做的基本原则.我问'为什么'他们这样做.为什么有人会关心谁接触私处?如果你是一个优秀的程序员,你应该知道你应该'和'不应该'在代码中戳的那些位,这应该不是一个问题.为什么要保密呢?为什么隐藏,模糊,让世界变得私密?为什么要开始照顾.

java programming-languages private public

3
推荐指数
3
解决办法
858
查看次数

是否可以验证发布的文件是否为pdf?

保守的网站主要工作是接受用户的文件并保存.一切都很好,直到2个月后,当我被告知强制约束只接受pdf文件.

在此之前,用户习惯于从文本,rtf到良好的pdf提交各种格式.

我通过检查文件扩展名来应用约束 - 简单吗?但是当管理员检查这些文件时,有60%的文件损坏了.

我花了很多不眠之夜来确定腐败的原因然后我突然想到他们可能正在提交腐败文件.

我采用了以前的记录,并确定了一些用户的文件类型最喜欢的格式,我们收到了损坏的文件.

我把扩展改回了那里最喜欢的扩展和繁荣......文件打开了.

然而我所知道的是粗略地告诉用户如何将文件转发到pdf一些(很多)只是改变了扩展和提交.由于网站奖励用户没有.文件提交管理人员对我嗤之以鼻.有什么办法可以在不依赖扩展的情况下检查文件是否为pdf?

我在c#3.5 asp.net中使用fileupload

c# pdf asp.net

3
推荐指数
2
解决办法
3881
查看次数

在Python类中传递变量

我有以下课程.但是当试图将变量x传递给re.match时,它似乎无法正常工作,因为我输入的任何输入都返回"无效"

class validate:
    def __init__(self, input_value):
        self.input_value = input_value
    def macaddress(self, oui):
        self.oui = oui
        #oui = 0, input deemed valid if it matches {OUI:DEVICE ID}.
        #oui = 1, input deemed valid if it matches {OUI}. 
        if self.oui == 0:
            x = 5
        elif self.oui == 1:
            x = 2   
        if re.match("[0-9a-fA-F]{2}([.-: ][0-9a-fA-F]{2}){x}$", self.input_value):
            return "valid"
        else:
            return "invalid"
Run Code Online (Sandbox Code Playgroud)

我应该以其他方式传递var x吗?

谢谢,

python

1
推荐指数
1
解决办法
113
查看次数