Undoing character read from file

Dave Angel d at davea.name
Fri Feb 17 22:58:52 EST 2012


On 02/17/2012 10:38 PM, Emeka wrote:
> Hello All,
>
> Say I have something like this:
>
> mfile = open("cc.txt", "rb")
> mcount = 0
> mset = False
> while True:
> c = mfile.read(1)
> if c == "e" and mset is True and mcount == 0:
>      print c
>      mfile.seek(-1,1)
>      mcount = 1
>      continue
> elif c == "e" and mset is False and mcount == 0:
>      print c
>      mfile.seek(-1, 0)
>      mcount = 1
>      continue
> elif c == "e" and mcount == 1:
>      print c
>      mcount = 0
>      continue
> print c
>   if mset is False:
>      mset = True
> if len(c) == 0:
>      break
>
> cc.txt
>
> foor the this the been we hate to sh wiukr bee here today. But who are we
> to question
> him concerning this issue.
>
> Is the above code the right way?

You top-posted, instead of putting your response after whatever you were 
quoting.  So you lose all context.

Your code won't compile, and it's unclear just what you were trying to 
accomplish.  What do you mean by "the right way"?

Please post the actual code that you're running, and explain what you 
expected, what you got, and how it didn't do what you wanted.  In this 
case, you should give us the traceback, so it's obvious that you're 
trying to figure out how to indent.



-- 

DaveA




More information about the Python-list mailing list