Skip to content

Commit cc62e5d

Browse files
committed
create file for using temp file
1 parent c7d19ab commit cc62e5d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

python_csv/create_tempfile.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import tempfile
3+
4+
temp = tempfile.NamedTemporaryFile(delete=False)
5+
print(temp.name)
6+
7+
temp.write(b"Hello world\n")
8+
temp.seek(0)
9+
print(temp.read())
10+
temp.close()
11+
os.unlink(temp.name)
12+
print(os.path.exists(temp.name))
13+
14+
with tempfile.NamedTemporaryFile(delete=False) as tp:
15+
print(tp.name)
16+
tp.write(b"Greetings python")
17+
tp.seek(0)
18+
print(tp.read())
19+
tp.close()
20+
os.unlink(tp.name)
21+
print(os.path.exists(tp.name))
22+
23+
24+
with tempfile.NamedTemporaryFile() as temp:
25+
print(temp.name)
26+
temp.write(b"writing data in temporary file")
27+
temp.seek(0)
28+
print(temp.read())
29+
temp.close()
30+
print(os.path.exists(temp.name))

0 commit comments

Comments
 (0)