io.UnsupportedOperation: not readable - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: io.UnsupportedOperation: not readable (/thread-22144.html) |
io.UnsupportedOperation: not readable - navidmo - Oct-31-2019 i dont understand why i get this error, thnks for your helping import hashlib import csv input_file_name = 'c:/users/shervin/documents/pass.csv' output_file_name = 'c:/users/shervin/documents/pass1.csv' def hash_password_hack(input_file_name, output_file_name): source = [] source_names = [] with open(input_file_name,'r', newline='') as f, open(output_file_name, 'w',newline='') as f: reader = csv.reader(f) for row in reader: source.append(row[1]) source_names.append(row[0]) pass_hash = {} for i in range(1000, 10000): i_st = str(i) i_st = hashlib.sha256(i_st.encode("utf-8")) hashed = i_st.hexdigest() pass_hash[hashed] = i for h in range(0, len(source)): if source[h] in pass_hash: csv_output.writerow(source_names[h], pass_hash[source[h]]) hash_password_hack(input_file_name, output_file_name)
RE: io.UnsupportedOperation: not readable - ichabod801 - Oct-31-2019 In your with statement on line 9, you have assigned both the input and output versions of your file to 'f'. So the output one overwrites the input one, and you can't read from a file open in 'w' mode. Since you are not writing to the output in that with block, I would just remove that second file assignment. |