Python 3 - Need to make a program that will R/W a text file and show the amount of Char in new file -


i need make program, ask user .txt file want rewrite new file , should new files name + new file has in uppercase. after doing program has show amount of symbols(characters) in new file.

f1 ask name of file want re-write.

f2 ask new name should be.

#xxxxxxxxxxxx f1 = input("xxxxxxxxxxx xxxxxxxxxxxx (xxxxxxxxxx: ):") f2 = input("xxxxxxxxxxxxxxxxxxxxxx (xxxxxxxx: ):")  #xxxxxxxxxxxxxxxxxxxxx firstfail = open(f1, 'r') newones = firstfail.readlines()  #xxxxxxxxx indeed = open(f2, 'w') indeed.write((str(newones)).upper())   #xxxxxxxxxxxx firstfail.close() 

indeed.close()

#xxxxxxxxxxxxx sym = open(str(indeed, 'r')) print(str.count(start=0, end=len(sym)))  

this error i'm getting:

sym = open(str(indeed, 'r')) typeerror: decoding str: need bytes-like object, _io.textiowrapper found 

now know nfail in wrong format , need somehow change have no idea how.

the 2 last lines makes no sense:

sym = open(str(nfail, 'r')) 

passes tuple(file handle,'r') open.

print(str.count(start=0, end=len(sym))) 

tries call method count without object, , passing len(sym) can't work since sym file handle

i'd rewrite this:

with open(f2, 'r') sym:     print(len(sym.read())) 

also no need read file size, do:

print(os.path.getsize(f2)) 

(you may have slight difference on windows because of \r\n => \n conversion that's fastest way file size: file isn't read)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -