0

Hello I am trying to build a tool that will compress a list of folders and rename the compressed file, this list of the names of folders I want to compress are located in a .txt file, the .txt is something like this:

james, 5005
kyle,  02939
Betty, 40234

I have used multiple methods to try and build this code but I keep getting a python error set object is not subscriptable and I have no idea what to do to rectify this and on how to continue from here. Can I not use shutil.make_archive with dictionaries or can I use lists? because I would like to run this function down the first column and to rename the files i am creating using the second column. I am using python 3, and any help would be great!

import os
import shutil
x = input("Input Path your user list: ")
filename = input("Input user file name: ")
changedir = input("Input where your folders are: ")
os.chdir(changedir)

userfile = x + filename + ".txt"
print("Awesome your path is now", userfile)
with open(userfile, "rt") as userfileone:
    count = 0
    while 1:
        buffer = userfileone.read(8192*1024)
        if not buffer: break
        count += buffer.count('\n')
        print("It is indicated that there are", count + 1, "in the file")
with open(userfile, "rt") as f:
        lines = f.readlines()
dic = {}
for x in lines:
    x = x.strip().split(',')
    dic[x[0]]=tuple(x[1:])

for i in dic:
    shutil.make_archive(i, "zip", dic[i])
Nick
  • 102
  • 8
  • It is not clear what this code does: why is is opening the file twice? Why is it counting '\n' characters, and not using the result? Why is it reading the second column in to a tuple? And why is the archive created with the name from the first column, when you said you wanted the second column to be the name? – Periodic Maintenance Jan 17 '13 at 22:17

1 Answers1

1

It seems like you are looking for the map function.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621