loops - No such file or directory OR TypeError: coercing to Unicode: need string or buffer, list found -
in python 2.6:
i haven't been able implement of responses other posts error , make work need direct here code. know basics of python , i'm trying write own script
- open folder
- list files in folder
- open files 1 one , count in each file unique entries.
i create dictionary each entry stored key , values being total number of times each entry present. ask print length of dictionary know how many unique entries there are. dictionary works loop through folder doesn't. tells me there not such file or directory or error below:
#!/usr/bin/python import sys import os # takes files in folder , counts unique records in each file, returns number of each record followed name of file ##usage: perl countunique.py folder folder = (sys.argv[1]) list = open(os.listdir(folder), "ru") filename in list: count = {} gene in filename: if not gene in count : count[gene]=1 else: count[gene]+=1 print( "there {0} unique entries in {1}".format(len(count.keys()), f))
list = open(os.listdir(folder), "ru")
typeerror: coercing unicode: need string or buffer, list found
thank in advance
edited:
i try:
folder = (sys.argv[1]) list = os.listdir(folder) filename in list: file = open(filename, "ru") count = {} gene in file: if not gene in count : count[gene]=1 else: count[gene]+=1 print( "there {0} unique entries in {1}".format(len(count.keys()), filename))
and error: file = open(filename, "ru") ioerror: [errno 2] no such file or directory: 'file1.renamed'
file1.renamed in folder don't know why can't find it.
solved:
#!/usr/bin/python import sys import os folder = sys.argv[1] root, dirs, files in os.walk(folder): filename in files: filepath = folder + '/' + filename file = open(filepath, "ru") count = {} gene in file: if not gene in count : count[gene]=1 else: count[gene]+=1 print( "there {0} unique entries in {1}".format(len(count.keys()), filename))
Comments
Post a Comment