Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open count

Status
Not open for further replies.

3li773

Programmer
Jan 23, 2003
20
0
0
CA
ok say you want to count how many times a progrma got opened like this

while True:
cmd=raw_input(">")

if cmd == "open":
import os
os.system("open_try.py")

how could i count how many times that program got opened
 
If you want to track how many time "open_try.py" has been run, you should put the following lines at the beginning of "open_try.py":

counterfilename = 'open_try.count'
try:
file=open(counterfilename,'r')
counter = int(file.readline())
file.close()
counter += 1
file = open(counterfilename,'w+b')
file.write(str(counter))
file.close()
except:
open(counterfilename,'w+b').write('0')


Then, each time you run open_try.py, the counter in open_try.count will be incremented.

It could be done in a more elegant manner, but this will work.
 
thanx alot
ill try it when i get home
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top