Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/File-input-output/Python/file-input-output-1.py
Normal file
2
Task/File-input-output/Python/file-input-output-1.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import shutil
|
||||
shutil.copyfile('input.txt', 'output.txt')
|
||||
6
Task/File-input-output/Python/file-input-output-2.py
Normal file
6
Task/File-input-output/Python/file-input-output-2.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
infile = open('input.txt', 'r')
|
||||
outfile = open('output.txt', 'w')
|
||||
for line in infile:
|
||||
outfile.write(line)
|
||||
outfile.close()
|
||||
infile.close()
|
||||
20
Task/File-input-output/Python/file-input-output-3.py
Normal file
20
Task/File-input-output/Python/file-input-output-3.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import sys
|
||||
try:
|
||||
infile = open('input.txt', 'r')
|
||||
except IOError:
|
||||
print >> sys.stderr, "Unable to open input.txt for input"
|
||||
sys.exit(1)
|
||||
try:
|
||||
outfile = open('output.txt', 'w')
|
||||
except IOError:
|
||||
print >> sys.stderr, "Unable to open output.txt for output"
|
||||
sys.exit(1)
|
||||
try: # for finally
|
||||
try: # for I/O
|
||||
for line in infile:
|
||||
outfile.write(line)
|
||||
except IOError, e:
|
||||
print >> sys.stderr, "Some I/O Error occurred (reading from input.txt or writing to output.txt)"
|
||||
finally:
|
||||
infile.close()
|
||||
outfile.close()
|
||||
9
Task/File-input-output/Python/file-input-output-4.py
Normal file
9
Task/File-input-output/Python/file-input-output-4.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import sys
|
||||
try:
|
||||
with open('input.txt') as infile:
|
||||
with open('output.txt', 'w') as outfile:
|
||||
for line in infile:
|
||||
outfile.write(line)
|
||||
except IOError:
|
||||
print >> sys.stderr, "Some I/O Error occurred"
|
||||
sys.exit(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue