mirror of
https://github.com/narkoz/hacker-scripts
synced 2025-08-25 20:07:14 +00:00
use with to open and close a file
This commit is contained in:
parent
f9321f0f07
commit
d4eccca9fb
@ -42,16 +42,9 @@ client.messages.create(
|
||||
)
|
||||
|
||||
try:
|
||||
f = open('logs/file.txt', 'a')
|
||||
except IOError as e:
|
||||
# dir & file don't exist; create them
|
||||
if not os.path.exists('logs'):
|
||||
os.mkdir('logs')
|
||||
f = open('logs/file.txt', 'a')
|
||||
with open('logs/file.txt', 'a') as lh:
|
||||
lh.write("Message sent at " + strftime("%a, %d %b %Y %H:%M:%S") + "\n")
|
||||
except Exception as e:
|
||||
print e
|
||||
else:
|
||||
pass
|
||||
|
||||
# log it
|
||||
f.write("Message sent at " + strftime("%a, %d %b %Y %H:%M:%S") + "\n")
|
||||
f.close()
|
||||
|
@ -43,16 +43,9 @@ client.messages.create(
|
||||
)
|
||||
|
||||
try:
|
||||
f = open('logs/file.txt', 'a')
|
||||
except IOError as e:
|
||||
# dir & file don't exist; create them
|
||||
if not os.path.exists('logs'):
|
||||
os.mkdir('logs')
|
||||
f = open('logs/file.txt', 'a')
|
||||
with open('logs/file.txt', 'a') as lh:
|
||||
lh.write("Message sent at " + strftime("%a, %d %b %Y %H:%M:%S") + "\n")
|
||||
except Exception as e:
|
||||
print e
|
||||
else:
|
||||
pass
|
||||
|
||||
# log it
|
||||
f.write("Message sent at " + strftime("%a, %d %b %Y %H:%M:%S") + "\n")
|
||||
f.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user