但是,当一本书学过之后,对一般的技术和函数都有了印象,突然想要查找某个函数的实例代码时,却感到很困难,因为一本书的源代码目录很长,往往有几十甚至上百个源代码文件,想要找到自己想要的函数实例谈何容易?
所以这里就是要将所有源代码按照目录和文件名作为标签,全部合并到一处,这样便于快速的搜索。查找,不是,那么查找下一个……于是很快便可以找到自己想要的实例,非常方便。当然,分开的源代码文件依然很有用,同样可以保留。合并之后的源代码文件并不大,n*100KB而已,打开和搜索都是很快速的。大家可以将同一种编程语言的所有实例通过这种方法全部合并为一个文件,搜索的效率就会大大提高。
注意:保存代码之后,将源文件复制到目录下,同一目录下的所有目录和其子目录都会被搜索;你可以加上后缀限定,只获取某种格式的文件的内容即可;源代码如下,请复制后保存:
# -*- coding: utf-8 -*-
import os,sys
info = os.getcwd()
fout = open('note.tpy', 'w') # 合并内容到该文件
def writeintofile(info):
fin = open(info)
strinfo = fin.read()
# 利用##作为标签的点缀,你也可以使用其他的
fout.write('\n##\n')
fout.write('## '+info[-30:].encode('utf-8'))
fout.write('\n##\n\n')
fout.write(strinfo)
fin.close()
for root, dirs, files in os.walk(info):
if len(dirs)==0:
for fl in files:
info = "%s\%s" % (root,fl)
if info[-2:] == 'py': # 只将后缀名为py的文件内容合并
writeintofile(info)
fout.close()
如果你不想合并内容,只想获得一个文件名的清单文件,也可以。这里给你代码。例如,有的作者就会使用这个功能为自己生成一个源代码文件清单,很实用。
源代码为:
# -*- coding: utf-8 -*-
'''
本程序自动搜索指定的目录,
打印所有文件的完整文件名到指定的文件中
'''
import os,sys
export = ""
i=1
for root, dirs, files in os.walk(r'..'):
#r'.'表示当前目录中的所有清单
#..表示平行的其他目录,多出很多内容
export += "--%s--\n%s\n\n%s\n\n" % (i,root,'\n'.join(files))
i=i+1
fp = open('cdcfile-4.txt', 'w')
fp.write(export)
fp.close()

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Error loading Pickle file in Python 3.6 environment: ModuleNotFoundError:Nomodulenamed...

How to solve the problem of Jieba word segmentation in scenic spot comment analysis? When we are conducting scenic spot comments and analysis, we often use the jieba word segmentation tool to process the text...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version
Chinese version, very easy to use