Python:如何在我的函数中使用进度条

标签 python performance coding-style progress-bar easy-install

我正在使用以下功能:

def LAS2TXTGridClip(inFile,poly,MinPoints=1):
        sf = shapefile.Reader(poly) #open shpfile
        sr = sf.shapeRecords()
        poly_filename, ext = path.splitext(poly)
        inFile_filename = os.path.splitext(os.path.basename(inFile))[0]
        for i in xrange(len(sr)):
            verts = np.array(sr[i].shape.points,float)
            record = sr[i].record[0]
            inside_points = [p for p in lasfile.File(inFile,None,'r') if pnpoly(p.x, p.y, verts)]
            if len(inside_points) >= MinPoints:
                file_out = open("{0}_{1}_{2}.txt".format(poly_filename, inFile_filename, record), "w")
                for p in inside_points:
                    file_out.write("%s %s %s %s %s %s %s %s %s %s %s" % (p.x, p.y, p.z, p.intensity,p.return_number,p.number_of_returns,p.scan_direction,p.flightline_edge,p.classification,p.scan_angle,record)+ "\n")
                file_out.close()

where for i in xrange(len(sr)): 该函数将被处理多次。 len(sr) 约为 50 万,我希望插入一个进度条,以便了解我需要等待的时间(今天是星期五)。我有以下问题:

  1. 哪个是 Windows 操作系统上 python 27 的“最好、最简单”的进度条 64位?
  2. 我发现progressbar module但我使用时遇到问题 此步骤之后的 easy_install 进度条。
  3. 插入进度条的最佳位置在哪里?

最佳答案

您在使用模块progressbar时遇到什么问题?这是非常好的解决方案。

$ cd progressbar-2.2/
$ sudo python setup.py install
...blablabla...
$ python
>>> from progressbar import ProgressBar
>>> pbar = ProgressBar(10)
>>> for i in range(10):
...     pbar.update(i+1)
... 
100% |######################################################################|

关于Python:如何在我的函数中使用进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12859253/

相关文章:

尝试 new 移动到新的 python 版本后出现 Python "command not found"

java - 使用 MIDI 进行编程,并将音符调至特定频率

c 的编码风格检查器(变量名,而不是缩进)

c++ - 大多数签名/未签名警告的可接受修复?

python - Google QPX Express API 返回 HTTP 错误 403 : Forbidden - Python

python - 在 Python 中为 Django Choice 字段创建智能循环列表

Python:将值添加到预定义索引处的列表

c# - 具有可空值类型的 as 运算符是否不必要地慢?

c# - 检查字符串是否包含列表(字符串)中的元素

coding-style - 在 Python 代码中使用名称 "function"作为变量