Re: [gcj] Python IO help
you can use command line redirection to make a file be sys.stdin: python mySolution.py < A-small-attempt85.in > a.out This will treat that in file as standard in and output to the out file. Sent from my iPad On 15 Apr 2013, at 06:27, wonjun wrote: > Hello All, > > I mainly code in Python, and is quite confused with the IO part. > Well I normally do the following for IO: > > f = open('filename','r') > a = f.read() > b = a.split('\n') > > Now, depending on the problem at hand, I use a for loop / while loop to look > over all cases and solve them accordingly. > I believe this is time consuming (when there is a very big input), and when I > download the solution, they all are written something like this: > > (Code taken from the Analysis for Tic-Tac-Toe-Tomek) > > numcases = int(sys.stdin.readline()) > for casenum in range(1,numcases+1): >board = [] >for i in range(0,5): > board.append(sys.stdin.readline().strip()) >print 'Case #' + repr(casenum) + ': ' + solve(board) > > > > Now, when we run this code, we have to manually write down everything - and > then it will solve the problem. Is there a way to do it via command line to > solve everycase in one go? > > And, is there any good material on Python IO which touches on stuff like > above? > Thanks. > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to google-code+unsubscr...@googlegroups.com. > To post to this group, send email to google-code@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [gcj] Python IO help
Building on this, I use raw_input() and call " ".split() and int() as needed. On Apr 15, 2013 4:48 AM, "Luke Pebody" wrote: > you can use command line redirection to make a file be sys.stdin: > > python mySolution.py < A-small-attempt85.in > a.out > > This will treat that in file as standard in and output to the out file. > > Sent from my iPad > > On 15 Apr 2013, at 06:27, wonjun wrote: > > Hello All, > > I mainly code in Python, and is quite confused with the IO part. > Well I normally do the following for IO: > > f = open('filename','r') > a = f.read() > b = a.split('\n') > > Now, depending on the problem at hand, I use a for loop / while loop to > look over all cases and solve them accordingly. > I believe this is time consuming (when there is a very big input), and > when I download the solution, they all are written something like this: > > (Code taken from the Analysis for Tic-Tac-Toe-Tomek) > > numcases = int(sys.stdin.readline()) > for casenum in range(1,numcases+1): >board = [] >for i in range(0,5): > board.append(sys.stdin.readline().strip()) >print 'Case #' + repr(casenum) + ': ' + solve(board) > > > > Now, when we run this code, we have to manually write down everything - > and then it will solve the problem. Is there a way to do it via command > line to solve everycase in one go? > > And, is there any good material on Python IO which touches on stuff like > above? > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to google-code+unsubscr...@googlegroups.com. > To post to this group, send email to google-code@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to google-code+unsubscr...@googlegroups.com. > To post to this group, send email to google-code@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [gcj] Python IO help
I see. Thanks alot :) 2013/4/15 Wolfgang Faust > Building on this, I use raw_input() and call " ".split() and int() as > needed. > On Apr 15, 2013 4:48 AM, "Luke Pebody" wrote: > >> you can use command line redirection to make a file be sys.stdin: >> >> python mySolution.py < A-small-attempt85.in > a.out >> >> This will treat that in file as standard in and output to the out file. >> >> Sent from my iPad >> >> On 15 Apr 2013, at 06:27, wonjun wrote: >> >> Hello All, >> >> I mainly code in Python, and is quite confused with the IO part. >> Well I normally do the following for IO: >> >> f = open('filename','r') >> a = f.read() >> b = a.split('\n') >> >> Now, depending on the problem at hand, I use a for loop / while loop to >> look over all cases and solve them accordingly. >> I believe this is time consuming (when there is a very big input), and >> when I download the solution, they all are written something like this: >> >> (Code taken from the Analysis for Tic-Tac-Toe-Tomek) >> >> numcases = int(sys.stdin.readline()) >> for casenum in range(1,numcases+1): >>board = [] >>for i in range(0,5): >> board.append(sys.stdin.readline().strip()) >>print 'Case #' + repr(casenum) + ': ' + solve(board) >> >> >> >> Now, when we run this code, we have to manually write down everything - >> and then it will solve the problem. Is there a way to do it via command >> line to solve everycase in one go? >> >> And, is there any good material on Python IO which touches on stuff like >> above? >> Thanks. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Google Code Jam" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to google-code+unsubscr...@googlegroups.com. >> To post to this group, send email to google-code@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Google Code Jam" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to google-code+unsubscr...@googlegroups.com. >> To post to this group, send email to google-code@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to google-code+unsubscr...@googlegroups.com. > To post to this group, send email to google-code@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [gcj] Python IO help
Well, there is a lot of material involving the Python IO modules, via command line you should use the command line arguments. http://stackoverflow.com/questions/4117530/sys-argv1-meaning-in-script On Sun, Apr 14, 2013 at 10:27 PM, wonjun wrote: > Hello All, > > I mainly code in Python, and is quite confused with the IO part. > Well I normally do the following for IO: > > f = open('filename','r') > a = f.read() > b = a.split('\n') > > Now, depending on the problem at hand, I use a for loop / while loop to > look over all cases and solve them accordingly. > I believe this is time consuming (when there is a very big input), and > when I download the solution, they all are written something like this: > > (Code taken from the Analysis for Tic-Tac-Toe-Tomek) > > numcases = int(sys.stdin.readline()) > for casenum in range(1,numcases+1): >board = [] >for i in range(0,5): > board.append(sys.stdin.readline().strip()) >print 'Case #' + repr(casenum) + ': ' + solve(board) > > > > Now, when we run this code, we have to manually write down everything - > and then it will solve the problem. Is there a way to do it via command > line to solve everycase in one go? > > And, is there any good material on Python IO which touches on stuff like > above? > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to google-code+unsubscr...@googlegroups.com. > To post to this group, send email to google-code@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.