Python Forum
io.UnsupportedOperation: not readable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
io.UnsupportedOperation: not readable
#1
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)
Output:
Traceback (most recent call last): File "C:/Users/shervin/Downloads/15233519514032056 (1).py", line 26, in <module> hash_password_hack(input_file_name, output_file_name) File "C:/Users/shervin/Downloads/15233519514032056 (1).py", line 11, in hash_password_hack for row in reader: io.UnsupportedOperation: not readable
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Storing data in readable place user_404_lost_and_found 4 1,453 Jul-22-2024, 06:14 AM
Last Post: Pedroski55
  io.UnsupportedOperation: not readable RedSkeleton007 2 21,536 Nov-06-2023, 06:32 AM
Last Post: gpurdy
  io.UnsupportedOperation: fileno toml12953 3 4,372 Jun-15-2023, 08:48 PM
Last Post: toml12953
  How to make x-axis readable with matplotlib Mark17 7 6,960 Mar-01-2022, 04:30 PM
Last Post: DPaul
  Function global not readable by 'main' fmr300 1 2,113 Jan-16-2022, 01:18 AM
Last Post: deanhystad
  Display output in readable format and save hnkrish 1 3,414 Jul-19-2019, 09:29 AM
Last Post: Larz60+
  How to convert Python crawled Bing web page content to human readable? dalaludidu 4 4,390 Sep-02-2018, 04:15 PM
Last Post: dalaludidu
  Time Difference in Epoch Microseconds then convert to human readable firesh 4 13,870 Feb-27-2018, 09:08 AM
Last Post: firesh
  which code is more readable? Skaperen 5 7,051 Nov-14-2016, 02:37 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020