小编Pau*_*jan的帖子

Python:OAuth库

oauth有一个完整的flegged python库吗?我没有找到任何处理oauth令牌过期后重新发布的消息(Yahoo OAuth流程的第5步).

那么最完整的是什么?我尝试了来自oauth.net的oauth_session_handle那个,如果端点返回它,它就不能处理oauth规范所说的内容(就像雅虎那样).

那么,我应该使用哪个库?它们都是不完整的,我必须自己做吗?

python yahoo oauth

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

Python @property与方法性能 - 使用哪一个?

我编写了一些使用对象属性的代码:

class Foo:
    def __init__(self):
        self.bar = "baz"
myFoo = Foo()
print (myFoo.bar)
Run Code Online (Sandbox Code Playgroud)

现在我想做一些花哨的计算来回归bar.我可以使用@property方法作为属性bar,或者我可以重构我的代码使用myFoo.bar().

我应该回去为我的所有bar访问添加parens 还是使用@property?假设我的代码库现在很小但是由于熵会增加.

python performance properties

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

合并python中的排序列表

我有一堆排序的对象列表和一个比较函数

class Obj :
    def __init__(p) :
        self.points = p
def cmp(a, b) :
    return a.points < b.points

a = [Obj(1), Obj(3), Obj(8), ...]
b = [Obj(1), Obj(2), Obj(3), ...]
c = [Obj(100), Obj(300), Obj(800), ...]

result = magic(a, b, c)
assert result == [Obj(1), Obj(1), Obj(2), Obj(3), Obj(3), Obj(8), ...]
Run Code Online (Sandbox Code Playgroud)

是什么magic样子的?我目前的实施是

def magic(*args) :
    r = []
    for a in args : r += a
    return sorted(r, cmp)
Run Code Online (Sandbox Code Playgroud)

但这是非常低效的.更好的答案?

python arrays sorting merge

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

良好的图遍历算法

抽象问题:我有一个大约250,000个节点的图形,平均连接性大约为10.找到一个节点的连接是一个漫长的过程(10秒钟就可以了).将节点保存到数据库也需要大约10秒钟.我可以非常快速地检查数据库中是否已存在节点.允许并发,但一次不超过10个长请求,您将如何遍历图表以获得最快的覆盖率.

具体问题:我正在尝试抓一个网站用户页面.为了发现新用户,我正在从已知用户那里获取好友列表.我已经导入了大约10%的图形但是我一直陷入循环或使用太多内存记住太多节点.

我目前的实施:

def run() :
    import_pool = ThreadPool(10)
    user_pool = ThreadPool(1)
    do_user("arcaneCoder", import_pool, user_pool)

def do_user(user, import_pool, user_pool) :
    id = user
    alias = models.Alias.get(id)

    # if its been updates in the last 7 days
    if alias and alias.modified + datetime.timedelta(days=7) > datetime.datetime.now() :
        sys.stderr.write("Skipping: %s\n" % user)
    else :
        sys.stderr.write("Importing: %s\n" % user)
        while import_pool.num_jobs() > 20 :
            print "Too many queued jobs, sleeping"
            time.sleep(15)

        import_pool.add_job(alias_view.import_id, [id], lambda rv : sys.stderr.write("Done Importing %s\n" % user))

    sys.stderr.write("Crawling: %s\n" % …
Run Code Online (Sandbox Code Playgroud)

python language-agnostic algorithm performance graph-traversal

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

没有root重新加载django wsgi脚本

我使用嵌入式wsgi在apache上安装了django.我没有在机器上有根.

在部署新的源代码时,如何告诉apache重新加载python实例?

我尝试删除所有.pyc文件,它仍然运行旧代码.

django django-wsgi

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

c ++*vs&in函数声明

可能重复:
C++中指针变量和引用变量之间的差异

我什么时候应该将我的变量声明为指针vs传递引用的对象?他们在汇编中编译成相同的东西(至少是渐近的运行时),那么什么时候应该使用哪个呢?

void foo(obj* param)
void foo(obj& param)
Run Code Online (Sandbox Code Playgroud)

c++ pointers reference pass-by-reference

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

Django:如何向后关注ForeignKey('self')

class Achievement(MyBaseModel):
    parent_achievement = models.ForeignKey('self', blank=True, null=True, help_text="An achievement that must be done before this one is achieved") # long name since parent is reserved
Run Code Online (Sandbox Code Playgroud)

我可以 :

Achievement.objects.get(pk="1").parent_achievement
Run Code Online (Sandbox Code Playgroud)

这很棒.但我如何让所有的孩子?

Achievement.objects.get(pk="1").parent_achievement_set
Run Code Online (Sandbox Code Playgroud)

不起作用(可能应该有一些更多的符号),我搜索时没有看到太多.

可能吗?陷入SQL?

django foreign-keys django-models

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

使一个Dom元素可见,但不占用页面上的空间?

什么CSS会产生一个元素,但浏览器不会考虑其他任何东西?这样的事情可能吗?

我希望此页面上的鸟和狗不会影响文本的居中.http://twitter-meme.appspot.com/

一些我不喜欢的解决方案:

  • 制作单个图像并将其设置为背景图像.(然后我最终得到一个大图像作为背景).
  • 绝对定位文本(Yuck)

css

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

Python:在单词边界上拆分unicode字符串

我需要一个字符串,并将其缩短为140个字符.

目前我在做:

if len(tweet) > 140:
    tweet = re.sub(r"\s+", " ", tweet) #normalize space
    footer = "… " + utils.shorten_urls(post['url'])
    avail = 140 - len(footer)
    words = tweet.split()
    result = ""
    for word in words:
        word += " "
        if len(word) > avail:
            break
        result += word
        avail -= len(word)
    tweet = (result + footer).strip()
    assert len(tweet) <= 140
Run Code Online (Sandbox Code Playgroud)

所以这对于英语非常有用,而英语就像字符串一样,但对于中文字符串来说却失败了,因为tweet.split()只返回一个数组:

>>> s = u"?????????????????????????????10?42???????????30?????????????????????????"
>>> s
u'\u7b80\u8baf\uff1a\u65b0\u83ef\u793e\u5831\u9053\uff0c\u7f8e\u570b\u7e3d\u7d71\u5967\u5df4\u99ac\u4e58\u5750\u7684\u300c\u7a7a\u8ecd\u4e00\u865f\u300d\u5c08\u6a5f\u665a\u4e0a10\u664242\u5206\u9032\u5165\u4e0a\u6d77\u7a7a\u57df\uff0c\u9810\u8a08\u7d0430\u5206\u9418\u5f8c\u62b5\u9054\u6d66\u6771\u570b\u969b\u6a5f\u5834\uff0c\u958b\u5c55\u4ed6\u4e0a\u4efb\u5f8c\u9996\u6b21\u8a2a\u83ef\u4e4b\u65c5\u3002'
>>> s.split()
[u'\u7b80\u8baf\uff1a\u65b0\u83ef\u793e\u5831\u9053\uff0c\u7f8e\u570b\u7e3d\u7d71\u5967\u5df4\u99ac\u4e58\u5750\u7684\u300c\u7a7a\u8ecd\u4e00\u865f\u300d\u5c08\u6a5f\u665a\u4e0a10\u664242\u5206\u9032\u5165\u4e0a\u6d77\u7a7a\u57df\uff0c\u9810\u8a08\u7d0430\u5206\u9418\u5f8c\u62b5\u9054\u6d66\u6771\u570b\u969b\u6a5f\u5834\uff0c\u958b\u5c55\u4ed6\u4e0a\u4efb\u5f8c\u9996\u6b21\u8a2a\u83ef\u4e4b\u65c5\u3002']
Run Code Online (Sandbox Code Playgroud)

我应该怎么做才能处理I18N?这在所有语言中都有意义吗?

如果重要的话,我正在使用python 2.5.4.

python unicode internationalization character-properties

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

Java:使用HTTPBasic身份验证获取URL

我正在做一些简单的HTTP身份验证,我得到了一个

java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic OGU0ZTc5ODBk(...trimmed from 76 chars...)
(...more password data...)
Run Code Online (Sandbox Code Playgroud)

我认为这是因为我有一个非常长的用户名和密码,编码器包含\n76个字符.有什么方法可以解决这个问题吗?该URL仅支持HTTP Basic Auth.

这是我的代码:

private class UserPassAuthenticator extends Authenticator {
    String user;
    String pass;
    public UserPassAuthenticator(String user, String pass) {
        this.user = user;
        this.pass = pass;
    }

    // This method is called when a password-protected URL is accessed
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(user, pass.toCharArray());
    }
}

private String fetch(StoreAccount account, String path) throws IOException {
    Authenticator.setDefault(new UserPassAuthenticator(account.getCredentials().getLogin(), account.getCredentials().getPassword()));

    URL url …
Run Code Online (Sandbox Code Playgroud)

java authentication url http http-authentication

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