mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-18 18:14:34 +08:00
Fix ResourceWarning: unclosed file (#681)
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
This commit is contained in:

committed by
Libin Yang

parent
3dc50529ca
commit
2d70e9f747
@ -17,13 +17,12 @@ while True:
|
||||
print('Server received', repr(data))
|
||||
|
||||
filename = 'mytext.txt'
|
||||
f = open(filename, 'rb')
|
||||
in_data = f.read(1024)
|
||||
while (in_data):
|
||||
conn.send(in_data)
|
||||
print('Sent ', repr(in_data))
|
||||
in_data = f.read(1024)
|
||||
f.close()
|
||||
with open(filename, 'rb') as f:
|
||||
in_data = f.read(1024)
|
||||
while in_data:
|
||||
conn.send(in_data)
|
||||
print('Sent ', repr(in_data))
|
||||
in_data = f.read(1024)
|
||||
|
||||
print('Done sending')
|
||||
conn.send('Thank you for connecting')
|
||||
|
Reference in New Issue
Block a user