这个简短的函数只是获取存储设备的可用空间,但是在运行代码时出现上述错误。
其功能是:
def disk_space1(drive):
freespace = ctypes.c_ulonglong()
calcspace = ctypes.windll.kernel32.GetDiskFreeSpaceExA
calcspace(drive, ctypes.byref(freespace))
disk_size = freespace.value
return disk_size
Run Code Online (Sandbox Code Playgroud)
这个功能一直运行得很好,直到今天它无缘无故停止工作,我没有改变任何东西。最让我困惑的是,该函数工作正常,如果我运行它后打印出“freespace”的值,它已经找到了正确的值,但仍然给出错误。
是什么原因导致了这个问题?
ERROR_FILE_NOT_FOUND当我尝试打开一个不存在的文件时,我通常会得到,但现在fopen失败了ERROR_PATH_NOT_FOUND.
那么ERROR_FILE_NOT_FOUND和之间的区别是什么ERROR_PATH_NOT_FOUND?
我正在尝试用Python编写一个简单的程序,它从我的Downloads文件夹中获取所有音乐文件并将它们放入我的Music文件夹中.我正在使用Windows,我可以使用cmd提示移动文件,但是我收到此错误:
WindowsError: [Error 2] The system cannot find the file specified
这是我的代码:
#! /usr/bin/python
import os
from subprocess import call
def main():
os.chdir("C:\\Users\Alex\Downloads") #change directory to downloads folder
suffix =".mp3" #variable holdinng the .mp3 tag
fnames = os.listdir('.') #looks at all files
files =[] #an empty array that will hold the names of our mp3 files
for fname in fnames:
if fname.endswith(suffix):
pname = os.path.abspath(fname)
#pname = fname
#print pname
files.append(pname) #add the mp3 files to our array
print files …Run Code Online (Sandbox Code Playgroud) 我尝试使用 Pytesseract 从图像中读取文本。运行以下脚本时收到拒绝访问消息。
from PIL import Image
import pytesseract
import cv2
import os
filename=r'C:\Users\ychandra\Documents\teaching-text-structure-3-728.jpg'
pytesseract.pytesseract.tesseract_cmd = r'C:\Python27\Lib\site-packages\pytesseract'
image=cv2.imread(filename)
gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
gray=cv2.threshold(gray,0,255,cv2.THRESH_BINARY|cv2.THRESH_OTSU)[1]
gray=cv2.medianBlur(gray,3)
filename='{}.png'.format(os.getpid())
cv2.imwrite(filename,gray)
text=pytesseract.image_to_string(Image.open(filename))
print text
cv2.imshow("image",image)
cv2.imshow("res",gray)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
当我运行脚本时,我遇到了错误
Traceback (most recent call last):
File "F:\opencv\New_folder_3\text_from_image.py", line 17, in <module>
text=pytesseract.image_to_string(Image.open(filename))
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 5] Access is denied
Run Code Online (Sandbox Code Playgroud)