file line is not replacing with new value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nitinloml
    New Member
    • Mar 2007
    • 8

    #1

    file line is not replacing with new value

    #!/usr/bin/python
    import string
    import re
    import random
    import sys
    import time
    import fileinput

    tn = time.time()
    t = str(tn)
    ss = "5571"
    lv = open("/usr/local/https/data/session1.txt"," r")
    lvr = lv.readlines()
    l_lvr = len(lvr)
    #print lvr
    l_list = []
    for i in range(l_lvr):

    test = re.split('\|', lvr[i])
    l_list.append(t est)
    #print l_list
    for u,s,t,sp in l_list:
    if s == ss:
    so_list = [u, s, t, sp]
    u = string.join(so_ list)
    #print f
    s_list = u,s,t,sp
    e = so_list[2]
    print e
    to = s_list[2]
    #print st_to
    too = float(to)
    f = tn - too
    if f < 3600:
    so_list[2] = str(tn)
    sn_list = so_list
    print sn_list
    g =string.join(sn _list)
    print g
    for line in fileinput.input ('/usr/local/https/data/session1.txt', inplace=1):
    line = line.replace(u, g)
    sys.stdout.writ e(line)
    sys.exit()

    else:
    #return 1
    print "kK"
    sys.exit()
    print "no"







    file line is not replacing with new value
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    You'll have to post again. This time make sure that the indentation of your code comes through. Use CODE tags (instructions or on the right in "REPLY GUIDELINES"). Thanks.

    Comment

    Working...