How to get all the words of the doc2 in the doc1?
file_stop = open('doc1','r')
isi_stop = file_stop.read()
file_doc1 = open('doc2','r')
isi_doc1 = file_doc1.read()
How to get all the words of the doc2 in the doc1?
file_stop = open('doc1','r')
isi_stop = file_stop.read()
file_doc1 = open('doc2','r')
isi_doc1 = file_doc1.read()
If you want to copy the text of doc2 TO doc1 use:
with open('doc2', 'r') as doc2:
read = doc2.readlines()
with open('doc1', 'w') as doc2: # Not 'r' (read), use 'w' (write)
doc1.writelines(read)
Explanation (sorry if is bad):
open(file that you want to open, mode of opening)
# open the file with an specific mode, ('r' read, 'w' write, there are other like 'r+', 'w+', etc)
# you have to use open with a variable like:
file = open('doc1', 'r')
with open('doc1', 'r') as doc:
# you open the doc1 in the variable doc for a shot while, i mean, when you finish to use the file, it will automatly close.
read = doc2.readlines()
# you read the file (in this case 'doc2') (only can be done with reading modes [or readding and writting modes]) and load it in a variable ('read')
doc1.writelines(read)
# you write in the file ('doc1') all the text or values loaded in the variable ('read'), (you can only write in writting modes (or writting and readding)
I hope that it help you and sorry for my bad english.
Your question is not clear at all. Im just guessing here:
You want to read all the contents of doc1 and write them to doc2.
with open('doc2', 'r') as doc2:
reader = doc2.readlines()
with open('doc1', 'a') as doc1:
doc1.writelines(reader)
Do you really give a try to understand your code. You should open your destination file in a write mode first to be able to write.
So your third line of code should be.
file_doc1=open('doc2','w')
and as well in your fourth line of code your are using read function where you should be using write function as you have to copy the contents of doc1 to it it would be as below.
file_doc1.write(isi_stop)
here you would put to doc2 what you have read from doc1.