你好,我是新的正则表达式,我开始使用python.我坚持从英语句子中提取所有单词.到目前为止,我有:
import re
shop="hello seattle what have you got"
regex = r'(\w*) '
list1=re.findall(regex,shop)
print list1
Run Code Online (Sandbox Code Playgroud)
这给出了输出:
['你好','西雅图','什么','有','你']
如果我替换正则表达式
regex = r'(\w*)\W*'
Run Code Online (Sandbox Code Playgroud)
然后输出:
['你好','西雅图','什么','有','你','有','']
而我想要这个输出
['你好','西雅图','什么','有','你','有']
请指出我哪里出错了.
我有一个 python2.7 django 项目(我知道,我在 20 世纪!),其中有一些模型。我需要重写 makemigrations ,以便迁移文件名的形式为 0001.py、0002.py 等,而不是像 0001_initial.py、0002_model1.py 等那样,默认情况下会发生这种情况。
我已经研究了如何创建自定义管理.py 命令,并且能够覆盖 makemigrations 命令。目前我的自定义命令(python2.7)的代码如下所示:
路径/to/project/app/management/commands/makemigrations.py
from django.core.management.commands.makemigrations import Command as CoreMakeMigrationsCommand
class Command(CoreMakeMigrationsCommand):
def handle(self, *args, **options):
super(Command, self).handle(*args, **options)
Run Code Online (Sandbox Code Playgroud)
目前它只是调用原来的 makemigrations 而已。autodetector.py我需要能够修改决定文件命名的方式(这是 makemigrations 流程的一部分)。在这个文件中,有suggest_name如下所示的方法:
@classmethod
def suggest_name(cls, ops):
"""
Given a set of operations, suggest a name for the migration they might
represent. Names are not guaranteed to be unique, but put some effort
into the fallback name to avoid VCS conflicts if …Run Code Online (Sandbox Code Playgroud)