mirror of
https://github.com/narkoz/hacker-scripts
synced 2025-08-26 12:27:13 +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:
|
try:
|
||||||
f = open('logs/file.txt', 'a')
|
if not os.path.exists('logs'):
|
||||||
except IOError as e:
|
|
||||||
# dir & file don't exist; create them
|
|
||||||
os.mkdir('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:
|
except Exception as e:
|
||||||
print 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:
|
try:
|
||||||
f = open('logs/file.txt', 'a')
|
if not os.path.exists('logs'):
|
||||||
except IOError as e:
|
|
||||||
# dir & file don't exist; create them
|
|
||||||
os.mkdir('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:
|
except Exception as e:
|
||||||
print 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