[Tutor] Needing help with variables

Kent Johnson kent37 at tds.net
Wed Apr 23 22:06:42 CEST 2008


On Wed, Apr 23, 2008 at 2:55 PM, Cain, Steven <Steven.Cain at norfolk.gov> wrote:
> I have the code below and I am in need of a little help with variables.
>  What I am trying to do is substitute a variable where it says insert
>  variable. I actually need to place 3 variables. 1 for date, 1 for time
>  and 1 for a string of text.
>
>  Any help would be greatly appreciated.
>
>  Steve
>
>  def BackwardsReader(file, BLKSIZE = 4096):

Presumably the files you are trying to read are too large to fit in
memory? Otherwise this could be implemented as
  return reversed(file)

>  for line in BackwardsReader(open('stopServer.log')):
>     if line[0] == '[':
>         print line[1:8],line[9:16],line[62:93] ( insert Variable )

I'm not too sure what you want to do here. Do you want to create three
variables with the three substrings? That would be
  date, time, text = line[1:8],line[9:16],line[62:93]

or of course you could use three separate assignments:
  date = line[1:8]
  time = lline[9:16]
  text = line[62:93]

Kent


More information about the Tutor mailing list