@@ -46,7 +46,8 @@ def __init__(self, *args, **kwargs):
4646
4747 self .input_file = open (self .input_filename , 'w' )
4848 self .output_file = open (self .output_filename , 'w' ) if self .output_filename else None
49- print (self .input_filename ," start" )
49+ self .is_first_char = dict ()
50+ print ("Processing %s" % self .input_filename )
5051
5152 def __del__ (self ):
5253 """__del__(self) -> None
@@ -70,11 +71,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
7071 self .output_file .close ()
7172 except Exception :
7273 pass
73-
7474
75- @staticmethod
76- def __write (file , * args , ** kwargs ):
77- """__write(file, *args, **kwargs) -> None
75+ def __write (self , file , * args , ** kwargs ):
76+ """__write(self, file, *args, **kwargs) -> None
7877 Write every element in *args into file. If the element isn't "\n ", insert a space. It will convert every element into str
7978 file file -> the file object to write
8079 **kwargs:
@@ -83,19 +82,22 @@ def __write(file, *args, **kwargs):
8382 separator = kwargs .get ("separator" , " " )
8483 for arg in args :
8584 if list_like (arg ):
86- IO .__write (file , * arg , ** kwargs )
85+ self .__write (file , * arg , ** kwargs )
8786 else :
88- file .write (str (arg ))
89- if arg != "\n " :
87+ if arg != "\n " and not self .is_first_char .get (file , True ):
9088 file .write (separator )
89+ self .is_first_char [file ] = False
90+ file .write (str (arg ))
91+ if arg == "\n " :
92+ self .is_first_char [file ] = True
9193
9294 def input_write (self , * args , ** kwargs ):
9395 """input_write(self, *args, **kwargs) -> None
9496 Write every element in *args into the input file. Splits with spaces. It will convert every element into string
9597 **kwargs:
9698 str separator = " " -> a string used to separate every element
9799 """
98- IO .__write (self .input_file , * args , ** kwargs )
100+ self .__write (self .input_file , * args , ** kwargs )
99101
100102 def input_writeln (self , * args , ** kwargs ):
101103 """input_writeln(self, *args, **kwargs) -> None
@@ -125,7 +127,7 @@ def output_write(self, *args, **kwargs):
125127 **kwargs:
126128 str separator = " " -> a string used to separate every element
127129 """
128- IO .__write (self .output_file , * args , ** kwargs )
130+ self .__write (self .output_file , * args , ** kwargs )
129131
130132 def output_writeln (self , * args , ** kwargs ):
131133 """output_writeln(self, *args, **kwargs) -> None
0 commit comments