小编Vla*_*yev的帖子

Python setup.py运行shell脚本

我需要在'sdist'阶段运行我自己的脚本,同时创建Python包.我写了以下脚本.你知道更好的方法吗?您是否可以推荐更好的一个或链接到setuptools上的官方文档,其中已经解释了这个时刻?

import subprocess
import sys

from setuptools import setup, find_packages, os

if 'sdist' in sys.argv:
    cwd = os.getcwd()
    os.chdir('website/static/stylesheets/')
    result = subprocess.call("scss --update --compass ./*.scss", shell=True)
    if result != 0:
        exit(1)
    os.chdir(cwd)

setup(name = "site",
    author="Vladimir Ignatev",
    author_email="mail@gmail.com",
    version="0.1",
    packages=find_packages(),
    include_package_data=True,
    zip_safe=True,
)
Run Code Online (Sandbox Code Playgroud)

python setuptools

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

适用于Linux的Python类似物“文件”命令

我正在寻找file用Python制造的linux命令模拟。它应该提供有关文件类型的信息,如中所述man file。我正在寻找的最小功能集是确定文件是原始文件还是文本(人类可读)文件。包装库将是一个不错的建议。我知道,我可以file作为子进程运行并获取其输出以确定文件类型。但是我的程序应该解析成千上万个文件,在这种情况下,我担心执行时间会很长。

python linux file

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

如何在Rust中正确实现Iterable结构?

我正在尝试实现可以​​无限迭代的结构。认为它是自然数。我有一个局限性:它不能实现Copy特征,因为结构包含一个String字段。

我还实现了一个Iterable特征及其唯一成员fn next(&mut self) -> Option<Self::Item>

当前,我有以下代码可以迭代结构的前10个项目:

let mut counter = 0;
let mut game:Option<Game> = Game::new(&param);
loop {
    println!("{:?}", game); 

    game = g.next();
    counter = counter + 1;
    if counter > 10 { break; }
}
Run Code Online (Sandbox Code Playgroud)

我想让用户crate能够使用for in构造对我的结构进行迭代,如下所示:

for next_game in game {
  println!("{:?}", next_game);
} 
Run Code Online (Sandbox Code Playgroud)

有可能吗?我该如何实现?如何使我的代码更好,以及与我的结构有什么关系?

迭代器实现:

pub struct Game {
    /// The game hash
    pub hash: Vec<u8>
}

impl Iterator for Game {
    type Item …
Run Code Online (Sandbox Code Playgroud)

iterator rust

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

如何在Python 2和Python 3中生成密码?安全?

这里的Stackoverflow至少存在一个与此主题相关的帖子:在python中生成密码

你会发现这个话题甚至在PEP中也发现了一些批评者.它在这里提到:https://www.python.org/dev/peps/pep-0506/

那么,如何正确安全地在Python 2和Python 3中生成随机密码?

python security random cryptography python-3.x

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

在过滤掉 Rust 中的 None 元素后,是否有可能以某种方式将 Vec&lt;Option&lt;Value&gt;&gt; 转换为 Vec&lt;Value&gt; ?

在编写这样的代码时,我想要某种方式来进行这样的转换:

struct Value;

fn remove_missed(uncertain_vector: Vec<Option<Value>>) -> Vec<Value> {
    uncertain_vector
        .into_iter()
        .filter(|element| match element {
            Some(val) => true,
            None => false,
        })
        .collect()
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我相信类型隐含机制不够聪明,无法确定生成的集合将仅包含Option<Value>所有此类对象的类型相同的地方 ( Value)。

编译器部分回答了我的问题:

error[E0277]: a collection of type `std::vec::Vec<Value>` cannot be built from an iterator over elements of type `std::option::Option<Value>`
  --> src/lib.rs:10:10
   |
10 |         .collect()
   |          ^^^^^^^ a collection of type `std::vec::Vec<Value>` cannot be built from `std::iter::Iterator<Item=std::option::Option<Value>>`
   |
   = help: the trait `std::iter::FromIterator<std::option::Option<Value>>` is not implemented for `std::vec::Vec<Value>`
Run Code Online (Sandbox Code Playgroud)

iterator functional-programming rust

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