471,321 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

open a file and changing its data

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 1175
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.
  6. f = open('see.txt','w') # mode "w" will overwrite the file's contents.
  7. f.write(data)
  8. f.close()
  10. #and you're done.
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.