小编sko*_*nos的帖子

序数替换

我目前正在寻找用适当的序数表示(第1,第2,第3)替换第一,第二,第三等字的方法.我上周一直在谷歌搜索,我没有找到任何有用的标准工具或NLTK的任何功能.

那么有没有或者我应该手动编写一些正则表达式?

谢谢你的建议

python ordinals nlp nltk

41
推荐指数
8
解决办法
4万
查看次数

Python-peewee获得最后保存的行

有没有办法如何在使用peewee及其所有属性的同时获取数据库中最后保存的行?假设我这样做:

user = User.create(
    email = request.json['email'],
    nickname = request.json['nickname'],
    password = request.json['password'],
    salt = "salt"
)
Run Code Online (Sandbox Code Playgroud)

user.idNone,我可以得到的唯一属性上述规定.我可以打电话给select()方法但是那里有没有更快的方法?

谢谢

python orm peewee

8
推荐指数
2
解决办法
5011
查看次数

SQLAlchemy - 自引用与额外列的多对多关系

我有一个代表用户的模型,我想在表示他们是朋友的用户之间建立关系.我的功能模型与关联表和列出所有朋友的方法看起来像这样

friendship = db.Table('friend',
    db.Column('id', db.Integer, primary_key=True),
    db.Column('fk_user_from', db.Integer, db.ForeignKey('user.id'), nullable=False),
    db.Column('fk_user_to', db.Integer, db.ForeignKey('user.id'), nullable=False)
)

class User(db.Model):
   ...
   ...
   friends = db.relationship('User',
        secondary=friendship,
        primaryjoin=(friendship.c.fk_user_from==id),
        secondaryjoin=(friendship.c.fk_user_to==id),
        backref = db.backref('friend', lazy = 'dynamic'), 
        lazy = 'dynamic')

    def list_friends(self):
        friendship_union = db.select([
                        friendship.c.fk_user_from, 
                        friendship.c.fk_user_to
                        ]).union(
                            db.select([
                                friendship.c.fk_user_to, 
                                friendship.c.fk_user_from]
                            )
                    ).alias()
        User.all_friends = db.relationship('User',
                       secondary=friendship_union,
                       primaryjoin=User.id==friendship_union.c.fk_user_from,
                       secondaryjoin=User.id==friendship_union.c.fk_user_to,
                       viewonly=True) 
        return self.all_friends
Run Code Online (Sandbox Code Playgroud)

问题是,我需要在确认之前实施询问友好状态和状态(就像你从Facebook上知道的那样)所以在附带的列中添加一个额外的列是必要的.根据SQLAlchemy教程,我应该创建一个关联对象但是如何让它再次自我引用?

或者是否可以将此列添加到我当前的frienship表中并以某种方式访问​​并更改状态值?

谢谢

python database database-design sqlalchemy flask-sqlalchemy

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

Facebook Applinks - 在al_applink_data中传递自定义JSON数据

是否可以al_applink_data使用Facebook applinks 传递自定义数据?

我可以检索此JSON示例,但我看不到将自定义数据附加到其中的位置.如果这不可能,我唯一的解决方案就是解析获得的URL,但这似乎没有多少防弹.

{
    "target_url": "https://www.example.com/abc.html",
    "extras": {
        "fb_app_id": [YOUR_FACEBOOK_APP_ID],
        "fb_access_token": "[ACCESS_TOKEN']",
        "fb_expires_in": "3600"
    },
    "referer_app_link": {
        "url": "[FACEBOOK_APP_BACK_LINK]",
        "app_name": "Facebook"
    }
}
Run Code Online (Sandbox Code Playgroud)

json facebook deep-linking applinks

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

带前缀的Argparse位置参数

我的python3脚本使用命令行中指定的输入和输出文件.用法应如下所示

xxxx.py [-h] --input=file --output=file
Run Code Online (Sandbox Code Playgroud)

在我正在使用的代码中

parser.add_argument("input", help='Input file');
parser.add_argument("output", help='Output file');
Run Code Online (Sandbox Code Playgroud)

但是参数没有必要的前缀.有没有办法为每个参数指定前缀?

python argparse python-3.x

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

OpenCV图像混合

我使用OpenCV做faceswap应用程序,让我说我在图片中找到了2个面,然后我用椭圆裁剪了面部矩形.我的问题是这两个面都有不同的肤色,所以如果我只是简单地交换椭圆的坐标,结果就不那么好了.所以我至少在考虑根据原始面部调整脸部的颜色.

我相信用OpenCV库可以实现,但我只是不知道我应该寻找的方法的名称.同样重要的是该方法足够快,因为我正在为Android开发此应用程序.

opencv

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