Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок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')
5 ответов
+ 1
try something like:-
for word in in_file.read().split():
for symbol in special:
if symbol in word:
blah blah blah
0
Because you are looking for special string in whole. You must treat those characters separately.
0
so lets say ...
text = “i love becon, and becom loves me”
how can i have get the word “becon,” into the outfile ?
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.