I am working with a 150GB+ zipfile of dicom images.
I am trying to extract some of these by their filenames.
I am working on google collab python 3 interpreter and use zipfile module along with ZipFile.extractall() method on a list of filenames of length 500 (ex : ['stage_1_train_images/ID_53ff71bc4.dcm', 'stage_1_train_images/ID_001bb2c00.dcm',etc...]) :
.
Here's my code :
from zipfile import ZipFile
with ZipFile(src, 'r') as zipObj:
zipObj.extractall(members = ids, path = '/content/drive/My Drive/RSNA IH DETECTION CHALLENGE/DICOM') #ids is my file list
I got an error message :
"OSError: [Errno 5] Input/output error", related to a message in read(self, n) : "727 "Close the writing handle before trying to read.")"
I tried to close the file and re-open it, tried to extract with the .extract() method several times and always got the same err message.
I first attempted to use fuse zip along with shutil.copyfile() but it failed to...
Do you know what's causing this error message and a possible way to fix it?
I fixed this problem with re-downloading the original file.
My version, stored on Google Drive was probably corrupted.
Now fuse-zip works as well as ZipFile methods !
Related
I have tons of ".xls" format excel files that haves #NAME error in it.
I need to open each one, collect data from a specific range. but when I try to open it with xlrd I get the following error: "ERROR *** Token 0x2d (AreaN) found in NAME formula"
Code is below:
import xlrd
book = xlrd.open_workbook(r"C:\Users\metin.unlu\Desktop\Python\renk_study\labs\2-19.xls",ignore_workbook_corruption=True)
sheet=book.sheet_by_index(0)
While the error is safe explatornary and I know the cause of it, I have no idea how to solve it without openning each excel file manually and fixing it.
I'm having issues when I try to write a file in Python giving it a certain name and not only pathing it. Here is what I'm trying to do:
page_title=page.find('title')
raw_data_path ='output/'+page_title+'_raw.txt'
print (page_title)
with open(raw_data_path, 'w') as file:
file.write ()
When running this code, I receive the error [Errno 22] Invalid argument: 'output/myfile_raw.txt'
If instead of raw_data_path ='output/'+page_title+'_raw.txt' I put, for example, raw_data_path ='output/'+'_raw.txt' the code works well, so for some reason I can't combine the path with the name I'm trying to give the file.
I've searched that error and I see that it is a routing error, so it might be happening because when I want to add the page_title something happens with the path, but I can't see which is the mistake because it should be working.
Can someone give me some help with this issue?
my file is corrupted. I saved the file on window 7 system and the previous working file was overwritten. So I want to recover it somehow. I created a simple python script to search for binary sequence of bytes. I know the exact size of file and header content. I am not very familiar with linux, but I think that everything can be handled as file. So my problem is that when I use standard code:
with open(file_to_search_in) as data_file:
data = mmap.mmap(data_file.fileno(), 0, prot=mmap.PROT_READ, flags=mmap.MAP_PRIVATE)
...
and use for file_to_search_in = /media/root/E6EB-10AA I got error message on linux system
IOError: [Errno 21] Is a directory: '/media/root/E6EB-10AA/'
I am a python newbie and learning from "automate boring stuff" book, so it says in the book the I can use os.path.getsize(path) to get a file size but when I run this code it gives an error, can you please explain why I am getting this?
import os
mypath = 'C:\\Users\\C2D\\Desktop\\Embedded system\\u1.PNG'
os.chdir(mypath)
print(os.path.getsize(mypath))
error is :
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\Users\C2D\Desktop\Embedded system\u1.PNG'
I am working on windows 8.1 and using python3.8 on pycharm
mypath is a file and not a folder.
With the command os.chdir(mypath) you are trying to change the folder - into an image.
It is generally very important, in which exact line an exception occurs. In this case it will be line 4.
To solve your problem: You can probably just delete this line.
It is failing because of the line os.chdir(mypath). You don't need to chdir().
Assuming the path is correct and the file exists, it should work (print the file size) if you remove the os.chdir() statement.
I have tried to write a python program that creates another python program and when I direct it to where I want it saved it says:
`File "/Users/Fredrik/Documents/infinitylock copy.py", line 11, in createFile
f = open(dest,'w')
IOError: [Errno 1] Operation not permitted: '/Users/Fredrik/Documents/python\\'`
My entire code is:
import time as t
from os import path
def createFile(dest):
date = t.localtime(t.time())
name = '%d_%d_%d.txt' % (date[1], date[2], (date[0] %100))
if not (path.isfile(dest + name)):
f = open(dest + name,'w')
f.write('\n'*30)
f.close()
if __name__ == '__main__':
destination = '/Users/Fredrik/Documents/python\\'
createFile(destination)
raw_input("done")
Please answer on how I can get this program to work properly. And resolve the error. Thank you.
Suggestions for 'get this program to work correctly':
What I would do is go through each part of the code, and look up on StackOverflow on how most people use each part. For example, I would use
import os
instead of
from os import path
simply because you might later want to use other functions. Its important to keep your code reusable, especially if it gets rid of errors later on.
Answer to 'resolve the error':
Try using forward slashes - I don't know why you have 'python\'
The program is likely throwing an error because you wrote that, an it is not valid and so therefore not permitted. Use .txt or some extension like that. Finally, try to run it with administrative privileges. http://www.wikihow.com/Open-Applications-With-Root-Privileges-on-a-Mac has a fairly good explaination. Simply open the console, root yourself, then run the program from there.