
Script杂记
发布日期:2021-05-14 03:06:47
浏览次数:19
分类:精选文章
本文共 2437 字,大约阅读时间需要 8 分钟。
目录
1 Python
1.1 杀死 Python
通过访问
/dev/zero
文件,可以读取无限多个0
字符,這樣會使得Python EditorGUILayout render不 dostopping,進而制止其運行。f=open('/dev/zero')next(f)1.2 杀死提示行
$ python3 Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] on linuxType "help", "copyright", "credits" or "license" for more information.$ python3 -q1.3 控制循環层数
要實现3個循環层数,內部循環總共將運行2^3=8次。
for i in range(2): for i in range(2): for i in range(2): foo()更一般的方法是使用
itertools.product
,這樣能實現對於任意n次循環。from itertools import productfor v in product(*[range(2)]*n): foo(),這樣的
product
使用一般法是:for i1, i2... in product(iter1, iter2...)1.4 目录列表平移
假设原始列表是[0,1,2,3,4,5,6,7,8,9],要實現左移或右移 distraught
左移一位,右移一位的方法如下:
左移法:
list = [i for i in range(10)]list.pop(0) => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]list.insert(0, list.pop())右移法:
list.pop() => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]list.insert(0, list.pop())實現n次平移的系統如下:
for _ in range(n): list.insert(0, list.pop())1.5 提取嵌套列表中的所有值
這裡有一個嵌套列表ra = [1, [2, 3], 4, [5, 6], [7, [8, 9, 10]]],我們要提取出所有嵌套內的數值。
def foo(a): r = [] for i in a: if type(i) is list: r += foo(i) else: r.append(i) return r代入.ra petrol,我們將得到[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
2 Bash Shell
2.1 读取特定行文本
要實現讀取特定行,可以使用
tail
和head
命令的組合。例如,打印第99行到100行,可以使用:
tail -n +99 /path/to/your/text | head -n 22.2 重定向
Bash Shell 中的重定向如下:
>
Only stdout redirect2>
Only stderr redirect&>
Redirect both stdout and stderr例如,將 lantern 的輸出重定向到
/dev/null
,使用:lantern &> /dev/null3 IDL
3.1 逃離 IDL 不是散步
開始
3.2 接收不必要的返回值
而不是:
NotMyWanted = QUERY_TIFF(fn, GEOTIFF=MyWanted)NotMyWanted = !NULL可以改用:
;use!NULL = QUERY_TIFF(fn, GEOTIFF=MyWanted);3.3 四個一次性赋值操作
例如:
;use a = (b = (c = 0));可以改用:
;use a = 0 b = 0 c = 0;3.4 不需提前 Prepare Variables
例如:
header = {endian: 0S, version: 0S, offset: 0L}READU, lun, header可以改用:
;use READU, lun, (header = {endian: 0S, version: 0S, offset: 0L});
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2025年04月23日 07时46分06秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【IntelliJ IDEA 2019.2】idea如何开启自动编译
2019-03-10
强大的文字处理器——Nisus Writer Pro
2019-03-10
如何轻松适应从Windows到MacOS的过渡!Mac新手入门指南
2019-03-10
fcpx插件:25个假日主题专业设计
2019-03-10
fcpx插件:Block Party for Mac(53个视频转场插件)
2019-03-10
Mac使用技巧:快速视频播放错误如何修护
2019-03-10
代码绘制五角形
2019-03-10
Course Schedule II
2019-03-10
线程总结
2019-03-10
【ES9(2018)】Promise.prototype.finally()
2019-03-10
<hdu - 1002> A + B Problem II
2019-03-10
Python识别璇玑图中诗的数量
2019-03-10
Django ORM操作
2019-03-10
剑指offer[32]——把数组排成最小的数
2019-03-10
谈谈关于springboot 添加依赖的那些事
2019-03-10
CF1475-D. Cleaning the Phone
2019-03-10
java基础-java与c#接口不同点
2019-03-10
Java并发工具篇
2019-03-10
京喜小程序体验评分优化实践
2019-03-10
DIV+CSS兼容IE6、IE7、Firefox方法探究
2019-03-10