I'm trying to find a way to run vulture (which finds unused code in python projects) inside a python script.vulture documentation can be found here:https://pypi.org/project/vulture/Does anyone know how to do it?The only way I know to use vulture is by shell commands.I tried to tun the shell commands from the script, using module subprocess, something like this:process = subprocess.run(['vulture', '.'], check=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True)which I though would have the same effect as running the shell command "vulture ."but it doesn't work.Can anyone help?Thanks 解决方案 Vulture dev here.The Vulture package exposes an API, called scavenge - which it uses internally for running the analysis after parsing command line arguments (here in vulture.main).It takes in a list of Python files/directories. For each directory, Vulture analyzes all contained *.py files.To analyze the current directory:import vulturev = vulture.Vulture()v.scavenge(['.'])If you just want to print the results to stdout, you can call:v.report()However, it's also possible to perform custom analysis/filters over Vulture's results. The method vulture.get_unused_code returns a list of vulture.Item objects - which hold the name, type and location of unused code.For the sake of this answer, I'm just gonna print the name of all unused objects:for item in v.get_unused_code(): print(item.name)For more info, see - https://github.com/jendrikseipp/vulture 这篇关于从 python 脚本运行 vulture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 11:22