我希望自动填充设置为79列代码段,72代表文档字符串,以获得自动PEP8合规性.似乎有一个选项可以为Lisp模式(emacs-lisp-docstring-fill-column)执行此操作,但不适用于Python.
是否有一个增强的python-mode.el在某处包含这个?
我编写了一个装饰器,它记录用于调用特定函数或方法的参数.如下图所示,除了报告logRecord的行号是装饰器的行号而不是func正在包装的行号之外,它运行良好:
from functools import wraps
import inspect
import logging
arg_log_fmt = "{name}({arg_str})"
def log_args(logger, level=logging.DEBUG):
"""Decorator to log arguments passed to func."""
def inner_func(func):
line_no = inspect.getsourcelines(func)[-1]
@wraps(func)
def return_func(*args, **kwargs):
arg_list = list("{!r}".format(arg) for arg in args)
arg_list.extend("{}={!r}".format(key, val)
for key, val in kwargs.iteritems())
msg = arg_log_fmt.format(name=func.__name__,
arg_str=", ".join(arg_list))
logger.log(level, msg)
return func(*args, **kwargs)
return return_func
return inner_func
if __name__ == "__main__":
logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
fmt = "%(asctime)s %(levelname)-8.8s [%(name)s:%(lineno)4s] %(message)s"
handler.setFormatter(logging.Formatter(fmt)) …Run Code Online (Sandbox Code Playgroud) 我有一个值列表.我希望在循环期间计算每个类的元素数(即1,2,3,4,5)
mylist = [1,1,1,1,1,1,2,3,2,2,2,2,3,3,4,5,5,5,5]
mydict = dict()
for index in mylist:
mydict[index] = +1
mydict
Out[344]: {1: 1, 2: 1, 3: 1, 4: 1, 5: 1}
Run Code Online (Sandbox Code Playgroud)
我希望得到这个结果
Out[344]: {1: 6, 2: 5, 3: 3, 4: 1, 5: 4}
Run Code Online (Sandbox Code Playgroud) 我真的很喜欢Mac Finder中的QuickLook功能,经常使用它来查找文本文件而无需在编辑器中打开它们。我使用许多文本类型的文件类型,但是具有QuickLook无法识别的扩展名。
如何告诉QuickLook带有各种扩展名(.rst,.aux等)的文件是纯文本,可以像.txt文件一样进行预览?
我已经看到了涉及在10.5和10.6中有效的黑客入侵者的解决方案,但是经过研究,似乎10.7处理事情的方式有所不同。
在SymPy中,是否可以对无限积分应用限制并对其进行评估?
import sympy
from sympy.abc import theta
y = sympy.sin(theta)
Y_indef = sympy.Integral(y)
Y_def = sympy.Integral(y, (theta, 0, sympy.pi / 2))
Run Code Online (Sandbox Code Playgroud)
Y_def.evalf() 产生一个数字.
我正在寻找Y_indef.evalf((theta, 0, sympy.pi/2))能得到相同答案的东西.
我在 Windows XP 中使用 Gnu emacs,默认窗口标题为“emacs@ACH1797VM2”而不是缓冲区标题,据我所知,这是我想要的,也是正确的默认行为。
阅读/sf/answers/163684671/后,我将以下行放在 ~/.emacs 文件的末尾,但行为没有变化。
(setq frame-title-format "%b - emacs")
Run Code Online (Sandbox Code Playgroud)
我可以更改窗口标题
M-x set-frame-name NewName RET
Run Code Online (Sandbox Code Playgroud)
但我希望它自动更改以匹配缓冲区名称。
IPython 具有用于定位内核连接文件的有用功能。
In [1]: from IPython.lib.kernel import find_connection_file
In [2]: find_connection_file()
Out[2]: 'C:\\Users\\me\\.ipython\\profile_default\\security\\kernel-1234.json'
Run Code Online (Sandbox Code Playgroud)
JupyterWindows 上的等效项是什么?
我终于开始尝试Chaco,所以这个问题可能很天真.目前我正在尝试绘制一个非常大的8位(又名灰度又名单通道)类型的图像numpy.uint8.似乎无论我做什么,图像都是彩色的.这是我的代码基于Chaco附带的image_plot.py示例:
#!/usr/bin/env python
"""
Draws an simple RGB image
- Left-drag pans the plot.
- Mousewheel up and down zooms the plot in and out.
- Pressing "z" brings up the Zoom Box, and you can click-drag a rectangular
region to zoom. If you use a sequence of zoom boxes, pressing alt-left-arrow
and alt-right-arrow moves you forwards and backwards through the "zoom
history".
"""
# Major library imports
from numpy import zeros, uint8
# Enthought library imports
from …Run Code Online (Sandbox Code Playgroud) python ×6
emacs ×2
chaco ×1
coding-style ×1
decorator ×1
dictionary ×1
docstring ×1
enthought ×1
integral ×1
ipython ×1
jupyter ×1
logging ×1
macos ×1
pep8 ×1
performance ×1
quicklook ×1
sympy ×1
text-files ×1
titlebar ×1
windows ×1