Python sort text file into a new format into another text file -


using python need take contents of text file e.g

http://pastebin.com/raw.php?i=dsbg6ud8 (the text file)

python code open file

file = open('file.txt', 'r') 

now need take each section separated "------------------" , rearrange own line in format of "internal://user:class@id". internal constant exists in new file not old , user, class , id taken old file.

unfortunately don't know how this, please help?

i'm not giving code, 1 of ways of doing it.

  1. iterate through file.
  2. if line == "------------------", implies new set of data going start. hence create blank data structure in store upcoming data. (eg- dict)
  3. else: split line on ":" character. , store first part key, , second part value of dict.
  4. finally using dict, print desired output in new file.

if have doubts regarding how implement these individual steps, google/so it. i'm sure you'll find answers.


Comments