前言
本篇博客是python开发的工具篇相关,介绍pycharm的使用和相关配置,收录python的相关操作,比如如何启动jupyter。
目录
- 前言
- 引出
- Pycharm
- pycharm如何不同等级日志显示不同颜色
- 设置不同pycharm的python环境
- Python操作
- 如何启动Jupyter
- 总结
引出
1.pycharm的配置,选择不同的python环境,根据不同等级日志显示不同颜色;
2.如何启动jupyter;
Pycharm
pycharm如何不同等级日志显示不同颜色
在PyCharm中,可以通过修改日志记录器的日志级别来改变日志的显示颜色。以下是一些常见的日志级别及其对应的颜色:
- DEBUG:灰色
- INFO:绿色
- WARNING:黄色
- ERROR:红色
- CRITICAL:红色
要修改日志级别,请按照以下步骤操作:
- 打开PyCharm并导航到"File" -> “Settings”。
- 在设置窗口中,选择"Editor" -> “Color Scheme”。
- 在"Color Scheme"选项卡中,选择"Console Colors"。
- 在"Console Colors"选项卡中,找到"Log Console"部分。
- 在"Log Console"部分,可以看到不同的日志级别和它们的颜色设置。
- 单击要修改的日志级别,并选择所需的颜色。
- 单击"Apply"或"OK"按钮以保存更改。
#!/usr/bin/env python
# encoding: utf-8
import logging# now we patch Python code to add color support to logging.StreamHandler
def add_coloring_to_emit_windows(fn):# add methods we need to the classdef _out_handle(self):import ctypesreturn ctypes.windll.kernel32.GetStdHandle(self.STD_OUTPUT_HANDLE)out_handle = property(_out_handle)def _set_color(self, code):import ctypes# Constants from the Windows APIself.STD_OUTPUT_HANDLE = -11hdl = ctypes.windll.kernel32.GetStdHandle(self.STD_OUTPUT_HANDLE)ctypes.windll.kernel32.SetConsoleTextAttribute(hdl, code)setattr(logging.StreamHandler, '_set_color', _set_color)def new(*args):FOREGROUND_BLUE = 0x0001 # text color contains blue.FOREGROUND_GREEN = 0x0002 # text color contains green.FOREGROUND_RED = 0x0004 # text color contains red.FOREGROUND_INTENSITY = 0x0008 # text color is intensified.FOREGROUND_WHITE = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED# winbase.hSTD_INPUT_HANDLE = -10STD_OUTPUT_HANDLE = -11STD_ERROR_HANDLE = -12# wincon.hFOREGROUND_BLACK = 0x0000FOREGROUND_BLUE = 0x0001FOREGROUND_GREEN = 0x0002FOREGROUND_CYAN = 0x0003FOREGROUND_RED = 0x0004FOREGROUND_MAGENTA = 0x0005FOREGROUND_YELLOW = 0x0006FOREGROUND_GREY = 0x0007FOREGROUND_INTENSITY = 0x0008 # foreground color is intensified.BACKGROUND_BLACK = 0x0000BACKGROUND_BLUE = 0x0010BACKGROUND_GREEN = 0x0020BACKGROUND_CYAN = 0x0030BACKGROUND_RED = 0x0040BACKGROUND_MAGENTA = 0x0050BACKGROUND_YELLOW = 0x0060BACKGROUND_GREY = 0x0070BACKGROUND_INTENSITY = 0x0080 # background color is intensified.levelno = args[1].levelnoif (levelno >= 50):color = BACKGROUND_YELLOW | FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_INTENSITYelif (levelno >= 40):color = FOREGROUND_RED | FOREGROUND_INTENSITYelif (levelno >= 30):color = FOREGROUND_YELLOW | FOREGROUND_INTENSITYelif (levelno >= 20):color = FOREGROUND_GREENelif (levelno >= 10):color = FOREGROUND_MAGENTAelse:color = FOREGROUND_WHITEargs[0]._set_color(color)ret = fn(*args)args[0]._set_color(FOREGROUND_WHITE)# print "after"return retreturn newdef add_coloring_to_emit_ansi(fn):# add methods we need to the classdef new(*args):levelno = args[1].levelnoif (levelno >= 50):color = '\x1b[31m' # redelif (levelno >= 40):color = '\x1b[31m' # redelif (levelno >= 30):color = '\x1b[33m' # yellowelif (levelno >= 20):color = '\x1b[32m' # greenelif (levelno >= 10):color = '\x1b[35m' # pinkelse:color = '\x1b[0m' # normaltry:args[1].msg = color + args[1].msg + '\x1b[0m' # normalexcept Exception as e:pass# print "after"return fn(*args)return newimport platformif platform.system() == 'Windows':# Windows does not support ANSI escapes and we are using API calls to set the console colorlogging.StreamHandler.emit = add_coloring_to_emit_windows(logging.StreamHandler.emit)
else:# all non-Windows platforms are supporting ANSI escapes so we use themlogging.StreamHandler.emit = add_coloring_to_emit_ansi(logging.StreamHandler.emit)# log = logging.getLogger()# log.addFilter(log_filter())# //hdlr = logging.StreamHandler()# //hdlr.setFormatter(formatter())
设置不同pycharm的python环境
Python操作
如何启动Jupyter
指定位置,输入cmd,然后jupyter notebook
jupyter notebook
总结
1.pycharm的配置,选择不同的python环境,根据不同等级日志显示不同颜色;
2.如何启动jupyter;