我有两个清单:
(setq x (list "a" "b" "c"))
(setq y (list "1" "2" "3" "4"))
Run Code Online (Sandbox Code Playgroud)
如何创建一个(("a" . "1") ("b" . "2") ("c" . "3") ("a" . "4"))使用较短列表回收的利弊单元列表?
包结构和文件设置如下:
$ tree .
.
??? doc
? ??? Makefile
? ??? README.md
? ??? _build
? ??? _static
? ??? conf.py
? ??? foo.rst
? ??? index.rst
? ??? make.bat
??? foo
??? __init__.py
??? spam.py
$ cat foo/__init__.py
r'''
The Foo module
==============
.. autosummary::
:toctree: generated
spam
'''
$ cat foo/spam.py
r'''
The Spam Module
===============
'''
def prepare(a):
'''Prepare function.
Parameters
----------
a : int
'''
print(a)
$ cat doc/index.rst
Welcome to foo's documentation!
=====================================
API …Run Code Online (Sandbox Code Playgroud) 让我们看一个例子:在我的main.sh中,我想找一个a.sh和b.sh. 但是,a.sh可能已经采购了b.sh. 因此,它将导致b.sh中的代码执行两次.在C++中是否有类似"包含守卫"的机制?
例如,我想编写一个bash shell脚本来使用进行轮换备份rsync。我应该将其作为独立脚本文件(backup.sh)还是将其包装在函数(backup)中?作为脚本文件,我可以运行它bash backup.sh。作为一项功能,我可以将其放置在诸如这样的文件中,foo.sh并在每次登录时将其作为源,然后我可以简单地backup作为命令运行以备份文件。问题是,这两种策略的利弊是什么?
或更笼统地说,我想知道在什么情况下应该将功能实现为独立的Shell脚本文件还是Shell函数?
我的一些想法:我知道某些图形会话(例如KDE,Gnome等)在登录时会生成不同的文件。如果要在以图形方式启动的应用程序中使用外壳程序功能(例如单击图标以打开emacs),可能会引起一些混乱。但是我更喜欢将其实现为shell函数,并将它们组合到文件中,我认为它们是整洁且组织良好的。
还有其他想法或建议吗?
在编程文件中,我使用空白模式来突出显示选项卡和长行.默认突出显示对我来说太装饰了.我只想用灰色背景突出显示它们并保留它应该是字体的正常颜色.我该怎么设置?
以下设置不起作用.我希望超过80列的代码看起来偏黄,作为快照中80列内的字符.
;; face for long lines' tails
(set-face-attribute 'whitespace-line nil
:background "#555"
:weight 'bold)
;; face for Tabs
(set-face-attribute 'whitespace-tab nil
:background "#555"
:weight 'bold)
Run Code Online (Sandbox Code Playgroud)

我想为不同的字符定义一堆面孔,如下所示:
(defface char-face-a
'((((type tty) (class color)) (:background "yellow" :foreground "black"))
(((type tty) (class mono)) (:inverse-video t))
(((class color) (background dark)) (:background "yellow" :foreground "black"))
(((class color) (background light)) (:background "yellow" :foreground "black"))
(t (:background "gray")))
"Face for marking up A's"
:group 'char-faces)
(defface char-face-b
'((((type tty) (class color)) (:background "red" :foreground "black"))
(((type tty) (class mono)) (:inverse-video t))
(((class color) (background dark)) (:background "red" :foreground "black"))
(((class color) (background light)) (:background "red" :foreground "black"))
(t (:background "gray")))
"Face for …Run Code Online (Sandbox Code Playgroud) script是记录终端所有活动的好工具(http://linuxers.org/article/script-command-line-tool-recordsave-your-terminal-activity).scriptMac上的内置可执行文件无法记录打字稿的时间.我正在尝试编译包util-linux(https://github.com/karelzak/util-linux,其中包含linux版本script),但没有成功:
$ make
make all-recursive
Making all in po
make[2]: Nothing to be done for `all'.
CC lib/libcommon_la-strutils.lo
In file included from lib/strutils.c:16:
./include/strutils.h:77: error: conflicting types for 'strmode'
/usr/include/string.h:168: error: previous declaration of 'strmode' was here
lib/strutils.c:351: error: conflicting types for 'strmode'
/usr/include/string.h:168: error: previous declaration of 'strmode' was here
lib/strutils.c: In function 'size_to_human_string':
lib/strutils.c:442: warning: format '%jd' expects type 'intmax_t', but argument 8 has type 'uint64_t'
make[2]: *** [lib/libcommon_la-strutils.lo] …Run Code Online (Sandbox Code Playgroud) 例如,我的函数中的一行代码
(message "char %c:%d" character count)
Run Code Online (Sandbox Code Playgroud)
将打印每个角色的计数.对于不可打印的字符,例如换行符和制表符,我希望输出看起来像:
\n:4
\t:6
Run Code Online (Sandbox Code Playgroud)
而不是字面上打印换行符和制表符.我怎样才能做到这一点?
我从有效的Python项目31中获得以下示例:
from weakref import WeakKeyDictionary
class Grade(object):
def __init__(self):
self._values = WeakKeyDictionary()
def __get__(self, instance, instance_type):
if instance is None: return self
return self._values.get(instance, 0)
def __set__(self, instance, value):
if not (0 <= value <= 100):
raise ValueError('Grade must be between 0 and 100')
self._values[instance] = value
# Example 16
class Exam(object):
math_grade = Grade()
writing_grade = Grade()
science_grade = Grade()
first_exam = Exam()
first_exam.writing_grade = 82
second_exam = Exam()
second_exam.writing_grade = 75
print('First ', first_exam.writing_grade, 'is right')
print('Second', second_exam.writing_grade, …Run Code Online (Sandbox Code Playgroud) 出于某种原因,我希望我的 HTML 小部件具有固定的高度,无论小部件中有多少行。如果行太多而无法适应高度,理想情况下可以滚动查看所有行。我尝试了类似以下的方法,但它不起作用:
import ipywidgets as widgets
widgets.HTML(
value="Hello <p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p>",
placeholder='Some HTML',
description='Some HTML',
disabled=True,
height='50px',
overflow_y='scroll'
)
Run Code Online (Sandbox Code Playgroud) elisp ×3
emacs ×3
python ×2
shell ×2
bash ×1
descriptor ×1
function ×1
ipython ×1
ipywidgets ×1
long-lines ×1
macos ×1
terminal ×1
whitespace ×1