我最近使用了tesseract OCR和python,当我尝试image_to_string从tesseract 导入时,我一直收到错误.
导致问题的代码:
# Perform OCR using tesseract-ocr library
from tesseract import image_to_string
image = Image.open('input-NEAREST.tif')
print image_to_string(image)
Run Code Online (Sandbox Code Playgroud)
上述代码导致的错误:
Traceback (most recent call last):
file "./captcha.py", line 52, in <module>
from tesseract import image_to_string
ImportError: cannot import name image_to_string
Run Code Online (Sandbox Code Playgroud)
我已经确认安装了tesseract模块:
digital_alchemy@roaming-gnome /home $ pydoc modules | grep 'tesseract'
Hdf5StubImagePlugin _tesseract gzip sipconfig
ORBit cairo mako tesseract
Run Code Online (Sandbox Code Playgroud)
我相信我已经抓住了所有必需的套餐,但不幸的是我只是陷入了困境.看来该功能不在模块中.
任何帮助非常感谢.
所以,我正在尝试使用python获得与使用bash脚本类似的结果.
bash脚本的代码:
#!/bin/bash
for ip in $(seq 1 254); do
ping -c 1 10.10.10.$ip | grep "bytes from" | cut -d " " -f 4 | cut -d ":" -f 1 &
done
Run Code Online (Sandbox Code Playgroud)
我想做的是以相似的速度获得相同的结果.我对每个版本的python脚本所遇到的问题是,与批处理脚本所花费的几秒钟相比,它需要很长时间才能完成.
批处理文件大约需要2秒来扫描一个/ 24网络,而我可以用python脚本获得的最佳时间大约为5-8分钟.
最新版本的python脚本:
import subprocess
cmdping = "ping -c1 10.10.10."
for x in range (2,255):
p = subprocess.Popen(cmdping+str(x), shell=True, stderr=subprocess.PIPE)
while True:
out = p.stderr.read(1)
if out == '' and p.poll() != None:
break
if out != '':
sys.stdout.write(out)
sys.stdout.flush()
Run Code Online (Sandbox Code Playgroud)
我在python中尝试了几种不同的方法,但是无法接近bash脚本的速度.
有什么建议?
我正在尝试编写一个快速的python脚本来遍历当前文件夹中的所有csv文件,并从它们中删除标题行,然后将它们存储在单独的文件夹中。
当前的工作目录包含四个示例csv文件和python脚本。执行后,脚本将创建HeaderRemoved目录。
看来,一旦创建了文件夹,试图读取文件的代码就会尝试访问该文件夹,但是查看代码后,我不确定为什么会这样。
我目前在Windows机器上。
import csv, os, argparse, string
from ctypes import *
os.makedirs('HeaderRemoved', exist_ok=True)
# Loop through files in the current working directory
for csvFile in os.listdir('.'):
if not csvFile.endswith('.csv'):
continue # Skips non-csv files
print ('Removing header from ' + csvFile + '...')
# Read in CSV skipping the first row
csvRows = []
csvFileObj = open(csvFile)
csvReader = csv.reader(csvFileObj)
for row in csvReader:
if csvReader.line_num == 1:
continue # Skips the first row
csvRows.append(row)
csvFileObj.close()
# Write …Run Code Online (Sandbox Code Playgroud)