File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ * .txt
2+ * .bin
3+ * .json
Original file line number Diff line number Diff line change 1+ test :
2+ for path in $$ (ls ./* .py); \
3+ do \
4+ echo " \n\nRunning $$ path" ; \
5+ $$ path 0< /dev/null; \
6+ if [ $$ ? -ne 0 ]; then \
7+ echo " FAIL: $$ path" ; \
8+ exit 1; \
9+ fi ; \
10+ done
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ def to_bytes(bytes_or_str):
4747# Example 5
4848try :
4949 import os
50- with open ('/tmp/ random.bin' , 'w' ) as f :
50+ with open ('random.bin' , 'w' ) as f :
5151 f .write (os .urandom (10 ))
5252except :
5353 logging .exception ('Expected' )
@@ -56,5 +56,5 @@ def to_bytes(bytes_or_str):
5656
5757
5858# Example 6
59- with open ('/tmp/ random.bin' , 'wb' ) as f :
59+ with open ('random.bin' , 'wb' ) as f :
6060 f .write (os .urandom (10 ))
Original file line number Diff line number Diff line change 2222
2323# Example 1
2424import random
25- with open ('/tmp/ my_file.txt' , 'w' ) as f :
25+ with open ('my_file.txt' , 'w' ) as f :
2626 for _ in range (10 ):
2727 f .write ('a' * random .randint (0 , 100 ))
2828 f .write ('\n ' )
2929
30- value = [len (x ) for x in open ('/tmp/ my_file.txt' )]
30+ value = [len (x ) for x in open ('my_file.txt' )]
3131print (value )
3232
3333
3434# Example 2
35- it = (len (x ) for x in open ('/tmp/ my_file.txt' ))
35+ it = (len (x ) for x in open ('my_file.txt' ))
3636print (it )
3737
3838
Original file line number Diff line number Diff line change 2121
2222
2323# Example 1
24- handle = open ('/tmp/ random_data.txt' , 'w' , encoding = 'utf-8' )
24+ handle = open ('random_data.txt' , 'w' , encoding = 'utf-8' )
2525handle .write ('success\n and\n new\n lines' )
2626handle .close ()
27- handle = open ('/tmp/ random_data.txt' ) # May raise IOError
27+ handle = open ('random_data.txt' ) # May raise IOError
2828try :
2929 data = handle .read () # May raise UnicodeDecodeError
3030finally :
@@ -82,7 +82,7 @@ def divide_json(path):
8282 handle .close () # Always runs
8383
8484# Everything works
85- temp_path = '/tmp/ random_data.json'
85+ temp_path = 'random_data.json'
8686handle = open (temp_path , 'w' )
8787handle .write ('{"numerator": 1, "denominator": 10}' )
8888handle .close ()
Original file line number Diff line number Diff line change @@ -71,11 +71,11 @@ def index_file(handle):
7171and dedicated to the proposition that all men
7272are created equal."""
7373
74- with open ('/tmp/ address.txt' , 'w' ) as f :
74+ with open ('address.txt' , 'w' ) as f :
7575 f .write (address_lines )
7676
7777from itertools import islice
78- with open ('/tmp/ address.txt' , 'r' ) as f :
78+ with open ('address.txt' , 'r' ) as f :
7979 it = index_file (f )
8080 results = islice (it , 0 , 3 )
8181 print (list (results ))
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ def normalize(numbers):
3737
3838
3939# Example 3
40- path = '/tmp/ my_numbers.txt'
40+ path = 'my_numbers.txt'
4141with open (path , 'w' ) as f :
4242 for i in (15 , 35 , 80 ):
4343 f .write ('%d\n ' % i )
@@ -49,13 +49,13 @@ def read_visits(data_path):
4949
5050
5151# Example 4
52- it = read_visits ('/tmp/ my_numbers.txt' )
52+ it = read_visits ('my_numbers.txt' )
5353percentages = normalize (it )
5454print (percentages )
5555
5656
5757# Example 5
58- it = read_visits ('/tmp/ my_numbers.txt' )
58+ it = read_visits ('my_numbers.txt' )
5959print (list (it ))
6060print (list (it )) # Already exhausted
6161
@@ -72,7 +72,7 @@ def normalize_copy(numbers):
7272
7373
7474# Example 7
75- it = read_visits ('/tmp/ my_numbers.txt' )
75+ it = read_visits ('my_numbers.txt' )
7676percentages = normalize_copy (it )
7777print (percentages )
7878
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ def debug_logging(level):
7070
7171
7272# Example 7
73- with open ('/tmp/ my_output.txt' , 'w' ) as handle :
73+ with open ('my_output.txt' , 'w' ) as handle :
7474 handle .write ('This is some data!' )
7575
7676
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ def __init__(self):
3535
3636# Example 3
3737import pickle
38- state_path = '/tmp/ game_state.bin'
38+ state_path = 'game_state.bin'
3939with open (state_path , 'wb' ) as f :
4040 pickle .dump (state , f )
4141
You can’t perform that action at this time.
0 commit comments