In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how Python solves the problem of Mobile QQ Wechat taking up too much memory". The editor shows you the process of operation through an actual case. The method of operation is simple and fast, and it is practical. I hope that this article "how to solve the problem of how to Python Mobile QQ Wechat takes up too much memory" can help you solve the problem.
Glob module
The glob module is very simple and is used to find files and folders. Only three matches are used to find the file: "*", "?", and "[]".
Wildcard function
*: match 0 or more characters
* *: match all files, directories, subdirectories and files in subdirectories
Matches a character, here with a regular expression? (regular? Match the previous expression 0 or 1 times)
[]: match characters within the specified range, for example: [1-9] match characters within 1-9
[!]: matches characters that are not within the specified range
Glob method
This method returns a list of all matching file paths
# all py files under the current path for fname in glob.glob ("* * / * .py", recursive=True): print (fname) # py file for fname in glob.glob ("py/*.py"): print (fname) # one-word wildcard under the current path file py? , under the current path file, there is a character folder for fname in glob.glob ("Tem?"): print (fname) # range wildcard [], and the py file for fname in glob.glob ("Tem [0-9] .py"): print (fname) # range wildcard [!], which begins with Tem under the current path file. Py file for fname in glob.glob ("Tem [! 0-9] .py") that starts with Tem under the current path file: file = glob.glob (rusted D:\ logs\ *\ * 'zlib.crc32) under print (fname) windowns
Overview of CRC32 algorithm CRC is the full name Cyclic Redundancy Check, also known as cyclic redundancy check. It belongs to hash as well as md5 code. When the CRC32 of two files is the same, the file is the same. On the contrary, the two files are different documents.
Def crc32 (file_path): with open (file_path, 'rb') as fh: hash = 0 while True: s = fh.read (65536) if not s: break hash = zlib.crc32 (s, hash) return "X"% (hash & 0xFFFFFFFF)
When you see this, you must know how to repeat the document:
1. Scan all files with glob.glob
two。 Put the crc32 value of the file in the dictionary
3. Find the key of the crc32 value that already exists in the dictionary and delete the current file.
Import osimport zlibimport glob def scanning_floder (glob_path): crc32Dict = {} for fname in glob.glob (glob_path Recursive=True): if os.path.isfile (fname): crc = crc32 (fname) if crc in crc32Dict: print ('existing file:' + crc32Dict.get (crc)) print ('duplicate file:' + fname) print ('delete file:' + fname) os.remove (fname) ) print ('') else: crc32Dict [crc] = fname def crc32 (file_path): with open (file_path 'rb') as f: hash = 0 while True: s = f.read (1024) if not s: break hash = zlib.crc32 (s, hash) return "X"% (hash & 0xFFFFFFFF) scanning_floder (r "C:\ Users\ xxxx\ Documents\ WeChat Files\ xxxx\ FileStorage\ *\ *")
This is the end of the introduction on "how Python solves the problem of Mobile QQ Wechat taking up too much memory". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.