468,747 Members | 1,664 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,747 developers. It's quick & easy.

open a file and changing its data

thatos
105 100+
I have developed a code to encrypt so what I would like to know is how can I open a file contaning certain data and change the data to encypted message for axample suppose my file in named see.txt and what I wrote inside is 'hello there' and after i encrypt in to maybe 'wwjkahkjahsjka' and I want my file see.txt to contain that encypted text not that 'hello there' which I had before if you are intersted to know I'm using vigenere cipher
Sep 23 '07 #1
1 1132
Basically, here:

Expand|Select|Wrap|Line Numbers
  1. f = open('see.txt','r')
  2. data = '\n'.join(f.readlines())
  3. f.close()
  4. # right here is where you would modify the data -- encrypting it however you want.
  5.  
  6. f = open('see.txt','w') # mode "w" will overwrite the file's contents.
  7. f.write(data)
  8. f.close()
  9.  
  10. #and you're done.
  11.  
I think this is all right but I didn't have a chance to test it, not on a machine with python right now.
Sep 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Andras Gilicz | last post: by
13 posts views Thread by Allison Bailey | last post: by
5 posts views Thread by mike | last post: by
13 posts views Thread by raykyoto | last post: by
2 posts views Thread by DOM_scripter | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.