hello world太简单,看不出语法,写个长点的,也算对python的语法有大概的了解了,哈哈哈。
功能:root是找到没有被包含的头文件,allh是看一个源文件都包含了哪些头文件。
没啥用,当练手。
#!/usr/bin/python #python code practice for include discovery import os pre = "#include" def compact(str): #local variable assignment before referenced l = len(str) i = 0 res = "" while i < l: if str[i] != ' ' and str[i] != '\n': res += str[i] i = i + 1 return res def geth_in_str(str): res = set() #init set l0 = len(str) l1 = len(pre) i = 0 while i + l1 + 2 <= l0: c = 'x' if str[i + l1] == '"': c = '"' elif str[i + l1] == '<': c = '>' else: i = i + 1 continue if str[i : i + l1] == pre: #substr[i, i + l1) j = i + l1 + 1 while j < l0: if str[j] == c: res.add(str[i + l1 + 1 : j]) break j = j + 1 if j < l0: i = j i = i + 1 return res def geth_in_file(fn): fd = open(fn, "r") text = fd.read() text = compact(text) res = geth_in_str(text) fd.close() return res def print_hset(hs): for e in hs: print e def hroot(dn): all = set() ex_all = set() tp = os.walk(dn).next() #to generates tuples (parent, dirnames, filenames), #and .next() to get the first for file in tp[2]: l = len(file) if l > 1 and file[l - 1] == 'h' and file[l - 2] == '.': all.add(file) ex_all = ex_all | geth_in_file(file) #set operation print ex_all res = all - ex_all return res def main(): print "h helper begin...." while True: cmd = raw_input("input cmd:\n") #raw_input a string, and input a int or float if cmd == "q" or cmd == "quit": break if cmd == "root": #show .hs in the dir of which is not included dn = raw_input("input dir:\n") print res = hroot(dn) print_hset(res) elif cmd == "allh": #show .hs included by the file fn = raw_input("input file:\n") print res = geth_in_file(fn) print_hset(res) print if __name__ == "__main__": main()
#include <C.h>
root@152.41 hnet>cat B.h
#include <iostream>
root@152.41 hnet>cat C.h
#include "sys/haha.h"
root@152.41 hnet>./h.py
h helper begin....
input cmd:
root
input dir:
./
root@152.41 hnet>cat B.h
#include <iostream>
root@152.41 hnet>cat C.h
#include "sys/haha.h"
root@152.41 hnet>./h.py
h helper begin....
input cmd:
root
input dir:
./
set(['B.h', 'iostream', 'C.h', 'sys/haha.h'])
A.h
A.h
input cmd:
allh
input file:
A.h
allh
input file:
A.h
B.h
C.h
C.h
input cmd:
allh
input file:
B.h
allh
input file:
B.h
iostream
input cmd:
allh
input file:
C.h
allh
input file:
C.h
sys/haha.h
补充:如果文件open太多,漏了close,程序会死掉的。
root@152.41 test>ulimit -a core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 210944 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 65535 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 131072 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
这里可以看到最多可以打开65535个file。
可以用ulimit -n xxx进行修改。这个没啥好改的,栈大小可以改改。
相关推荐
简单了解python,会安装,知道怎样配置python环境,不同版本怎么协同使用
自用,别下载
一、Python基础概述 二、Python基础教程 老王Python教程 基础篇 基础篇1-福利课python先入为主上 基础篇2-福利课-python先入为主下篇 基础篇3-虚拟机安装xubuntu开发环境 基础篇4-linux基本命令以及开发环境 基础篇...
主要为大家详细介绍了python算法表示概念扫盲教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
中文版 简明PYTHON,《a byte of python 中文版》绝对入门级,扫盲,零基础的人都可以看
项目简03- web编程扫盲之二 项目简04-数据库操作第一节 项目篇05-数据库操作第二节 项目简06-速攻之数据提交 项目篇07-django速攻之衔接 项目篇08-t第一节扫盲篇 项目篇09-第二节 项目篇10-o第三节 项目篇11-项目第...
maya动力学动画在建筑中的应用,脚本设计MEL, Python
0知识扫盲 相机模型 四大坐标关系与关系 1 相机标定 Q1:用MATLAB标定还是opencv标定? A1:我都试了。说起来,直接影响标定结果的好坏的因素,在图片质量大致的情况下,结果一样。 Q2:是两个相机一起标定还是...
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 ...在《老猿学5G扫盲贴:3GPP中的5G计费架构》介绍了3GPP的5G计费架构,其功能架构图如下: 博客专家
pyWeb是一个基于Knuth 扫盲编程工具,将编织文档和纠结源文件的操作结合在一起。 它独立于任何特定的文档标记或源语言。 Is使用一组简单的标记标签来定义代码和文档块。 pyweb.w文件是各种pyweb模块和脚本文件的源...
python进阶书籍,目录:1.模仿冷知识,2.魔法命令行,3.炫技魔法操作,4.魔法进阶扫盲,5.魔法开发技巧,6.良好编码习惯,7.神器魔法模块 建议:先学习python基础
学习socket知识与tcpip知识扫盲,涉及linux中套接字的细节,使用python脚本去实现一个小的通信
KK4VCZ的GoodPSK GoodPSK是用于生成PSK31录音的工具,有时具有奇怪或聪明... 作为一次扫盲尝试,我正在使用此工具来生成一系列有关PSK31的讲座,这些讲座将在PSK31中广播! 我将定期在6米和10米的范围内发送这些信息。
leetcode中文版 stars-list 使用python爬虫爬取stars然后生成折叠...工程师进阶知识完全扫盲:涵盖高并发、分布式、高可用、微服务、海量数据处理等领域知识,后端同学必看,前端同学也可学习 - - GitHub中文排行榜,帮
LuaJit扫盲 ToLua原理 (2月目标) Xlua原理 (2月目标) Unlua原理 PYQT 上手教程 Qt相关机制介绍 Unity GUI RetainedGUI UGUI 编辑器扩展 系列教程 场景 光照 遮挡剔除 TileMap TimeLine 源码探究 UI自动布局详解 内存...
技术面试必备基础知识、Leetcode、计算机操作系统、计算机网络、系统设计、Java、Python、C++等 免费的计算机编程类中文书籍 用动画的形式呈现解LeetCode题目的思路 互联网 Java 工程师进阶知识完全扫盲:涵盖高并发...
- :books:技术面试必备基础知识,Leetcode,计算机操作系统,计算机网络,系统设计,Java,Python,C ++ “ Java学习+面试指南”在Java程序员所需要掌握的核心知识上作了大量准备。准备Java面试,首选JavaGuide! ...
工程师进阶知识完全扫盲:涵盖高并发、分布式、高可用、微服务等领域知识,后端同学必看,前端同学也可学习 项目地址: (5)【Java学习+面试指南】 一份涵盖大部分Java程序员所需要掌握的核心知识。 项目地址: (6...
先扫盲一下什么是正则表达式的贪婪,什么是非贪婪?或者说什么是匹配优先量词,什么是忽略优先量词? 好吧,我也不知道概念是什么,来举个例子吧。 某同学想过滤之间的内容,那是这么写正则以及程序的。 代码如下: $...