python - 在 Python 中优化函数
问题描述
我在 Python 中有以下函数可以正常工作。如何改进语法以使其性能更好或总结行数?
def my_function(path):
with open(path) as f:
count = sum(line.count(";") for line in f)
query = open(path).read()
for i, query in enumerate(query.split(';')):
print(i," de ",count)
do_something(query)