小编Rik*_*yng的帖子

Python 日志记录:Flask + uWsgi + nginx

所有,在 uwsgi 后面运行 Flask 应用程序时,我无法记录 INFO 和 DEBUG 消息。不仅没有记录调试和信息消息,而且格式也不起作用。

formatter = logging.Formatter(  # pylint: disable=invalid-name
    '%(asctime)s %(levelname)s %(process)d ---- %(threadName)s  '
    '%(module)s : %(funcName)s {%(pathname)s:%(lineno)d} %
    (message)s','%Y-%m-%dT%H:%M:%SZ')

handler = StreamHandler()
handler.setLevel(logging.DEBUG)
handler.setFormatter(formatter)

application.logger.addHandler(handler)

logging.debug('Debug Message')
logging.info('Info Message')
logging.warning('Warning Message')
logging.error('Error Message')
logging.critical('Critical ')
Run Code Online (Sandbox Code Playgroud)

uwsgi 日志文件中的输出是:

*** Operational MODE: preforking ***
WARNING:root:Warning Message
ERROR:root:Error Message
CRITICAL:root:Critical 
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x26f39b0 pid: 9574 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned …
Run Code Online (Sandbox Code Playgroud)

python nginx uwsgi python-2.7

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

pandas:使用正则表达式验证数据框单元格

我有一个非索引数据框,从 csv 文件读取超过 50000 行,如下所示:

John   Mullen  12/08/1993  Passw0rd
Lisa   Bush    06/12/1990  myPass12
Maria  Murphy  30/03/1989  qwErTyUi
Seth   Black   21/06/1991  LoveXmas
Run Code Online (Sandbox Code Playgroud)

我想根据特定的正则表达式验证每行的每个单元格:

  • PassRegex使用以下内容验证密码
  • NameRegex使用以下内容验证名字/姓氏
  • ETC...

然后将任何单元格不验证的行移动到新的数据框。

import re
PassRegex = re.compile(r"^(?!.*\s)(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,50}$")
NameRegex = re.compile(r"^[a-zA-Z0-9\s\-]{2,80}$")
Run Code Online (Sandbox Code Playgroud)

例如,在本例中,以下行不会使用 PassRegex 进行验证,因此我想将它们移至单独的数据框:

Maria  Murphy  30/03/1989  qwErTyUi
Seth   Black   21/06/1991  LoveXmas
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以做到这一点,而无需逐行、逐个单元地迭代整个数据框?

任何帮助深表感谢。

python regex python-2.7 pandas

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

Python:流程避免嵌套的IF语句

我有一个进程(类),我分成几个步骤(方法).只有前一个步骤成功,才能调用每个步骤.我创建了一个方法run(),通过在调用下一个步骤之前检查每个步骤来运行该过程:

def run(self):
    status = False
    if step_1():
        if step_2():
            if step_3():
                etc... [several nested IFs]
                status = True
            else:
                self.logger.error('Error in step 3')
        else:
            self.logger.error('Error in step 2')
    else:
        self.logger.error('Error in step 1')
    return status
Run Code Online (Sandbox Code Playgroud)

是否有更优雅的方式(设计模式?)来避免这些嵌套的IF语句?

非常感谢,

python design-patterns python-2.7

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

标签 统计

python ×3

python-2.7 ×3

design-patterns ×1

nginx ×1

pandas ×1

regex ×1

uwsgi ×1