Click here to Skip to main content
15,891,871 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys, I have 10 csv file and I want to send each file to the same function, i am trying to use some thing like this code but I get this error

TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper

What I have tried:

path = 'C:/Users/lap/Desktop/ff/fr*.csv'
for file in iglob(path):
    with open(file, "r") as f:
        h = HuffmanCoding(f)
        output_path = h.compress()
        print("Compressed file path: " + output_path)
        decom_path = h.decompress(output_path)
        print("Decompressed file path: " + decom_path)

NOTE::
When I use this code with just one path it work good!!
path = 'C:/Users/lap/Desktop/ff/fr*.csv'
        h = HuffmanCoding(path)
        output_path = h.compress()
        print("Compressed file path: " + output_path)
        decom_path = h.decompress(output_path)
        print("Decompressed file path: " + decom_path)
Posted
Updated 14-Apr-20 10:02am

1 solution

I don't "do" Python, but the obvious issue is that you're opening the file in the code that doesn't work, whereas you're just passing in the path in the code that does work.

Try just passing in the path instead:
Python
path = 'C:/Users/lap/Desktop/ff/fr*.csv'
for file in iglob(path):
    h = HuffmanCoding(file)
    output_path = h.compress()
    print("Compressed file path: " + output_path)
    decom_path = h.decompress(output_path)
    print("Decompressed file path: " + decom_path)
 
Share this answer
 
Comments
Member 14801968 14-Apr-20 16:30pm    
done! thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900