0

Python files

Can anybody tel me why its not writing the words with special symbols to the outFile def wordsWithSymbols(inFile,outFile): in_file=open(inFile,'r') out_file=open(outFile,'w') special = "!@#$%^&*,.;:!" for line in in_file: for words in line: if special in words: out_file.write(words) in_file.close() out_file.close() wordsWithSymbols('C:\\Users\\Matin\\Desktop\\week 7\\roadNotTaken.txt','outfile2.txt')

3rd Nov 2019, 4:50 AM
Matin Aduko
5 Respostas
+ 1
try something like:- for word in in_file.read().split(): for symbol in special: if symbol in word: blah blah blah
3rd Nov 2019, 10:38 AM
rodwynnejones
rodwynnejones - avatar
0
Because you are looking for special string in whole. You must treat those characters separately.
3rd Nov 2019, 5:17 AM
Qasem
0
so lets say ... text = “i love becon, and becom loves me” how can i have get the word “becon,” into the outfile ?
3rd Nov 2019, 5:23 AM
Matin Aduko
0
msg = "Hello world!" file = open("newfile.txt", "w") amount_written = file.write(msg) print(amount_written) file.close() How does this return 12? I am so lost right now.
11th Oct 2020, 12:03 AM
Branden
Branden - avatar