File tree 2 files changed +8
-22
lines changed
2 files changed +8
-22
lines changed Original file line number Diff line number Diff line change 42
42
)
43
43
44
44
try :
45
- f = open ('logs/file.txt' , 'a' )
46
- except IOError as e :
47
- # dir & file don't exist; create them
48
- os .mkdir ('logs' )
49
- f = open ('logs/file.txt' , 'a' )
45
+ if not os .path .exists ('logs' ):
46
+ os .mkdir ('logs' )
47
+ with open ('logs/file.txt' , 'a' ) as lh :
48
+ lh .write ("Message sent at " + strftime ("%a, %d %b %Y %H:%M:%S" ) + "\n " )
50
49
except Exception as e :
51
50
print e
52
- else :
53
- pass
54
-
55
- # log it
56
- f .write ("Message sent at " + strftime ("%a, %d %b %Y %H:%M:%S" ) + "\n " )
57
- f .close ()
Original file line number Diff line number Diff line change 43
43
)
44
44
45
45
try :
46
- f = open ('logs/file.txt' , 'a' )
47
- except IOError as e :
48
- # dir & file don't exist; create them
49
- os .mkdir ('logs' )
50
- f = open ('logs/file.txt' , 'a' )
46
+ if not os .path .exists ('logs' ):
47
+ os .mkdir ('logs' )
48
+ with open ('logs/file.txt' , 'a' ) as lh :
49
+ lh .write ("Message sent at " + strftime ("%a, %d %b %Y %H:%M:%S" ) + "\n " )
51
50
except Exception as e :
52
51
print e
53
- else :
54
- pass
55
-
56
- # log it
57
- f .write ("Message sent at " + strftime ("%a, %d %b %Y %H:%M:%S" ) + "\n " )
58
- f .close ()
You can’t perform that action at this time.
0 commit comments