[BangPypers] how to override sys.stdin
Hi All, is there a way i can override raw_input or input function. I tried with below code but getting error import sys class xyz(object): def readline(self): print 'from fn readline',var sys.stdin = xyz raw_input('hi:') hi: Traceback (most recent call last): File pyshell#12, line 1, in module raw_input('hi:') TypeError: unbound method readline() must be called with xyz instance as first argument (got nothing instead) overriding sys.stdout is working fine. Nitin K ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] how to override sys.stdin
On Mon, Aug 4, 2014 at 2:38 PM, Nitin Kumar nitin.n...@gmail.com wrote: def readline(self): print 'from fn readline',var Where are you getting 'var' from? Shouldn't the method read as def readline(self, var)? -- Dhruv Baldawa (http://www.dhruvb.com) ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] how to override sys.stdin
thats a typo error. in simple term my question would be: How to override sys.stdin. Nitin K On Mon, Aug 4, 2014 at 2:44 PM, Dhruv Baldawa dhruvbald...@gmail.com wrote: On Mon, Aug 4, 2014 at 2:38 PM, Nitin Kumar nitin.n...@gmail.com wrote: def readline(self): print 'from fn readline',var Where are you getting 'var' from? Shouldn't the method read as def readline(self, var)? -- Dhruv Baldawa (http://www.dhruvb.com) ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] how to override sys.stdin
On Mon, Aug 04 2014, Nitin Kumar wrote: thats a typo error. in simple term my question would be: How to override sys.stdin. [...] The StringIO module gives you file like objects into which you can put data. They might work as substitues for sys.std* -- Cordially, Noufal http://nibrahim.net.in ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] how to override sys.stdin
Hi Nitin, Do u mean redirecting Standard IO streams? On Mon, Aug 4, 2014 at 3:08 PM, Noufal Ibrahim KV nou...@nibrahim.net.in wrote: On Mon, Aug 04 2014, Nitin Kumar wrote: thats a typo error. in simple term my question would be: How to override sys.stdin. [...] The StringIO module gives you file like objects into which you can put data. They might work as substitues for sys.std* -- Cordially, Noufal http://nibrahim.net.in ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] how to override sys.stdin
It might work, sys.stdin = open(sys.stdin.fileno(), 'r', Data descriptors) or Simply for replacing iostream, sys.stdin = open(filepath ,'r') On Mon, Aug 4, 2014 at 3:48 PM, Rohit Chormale rohitchorm...@gmail.com wrote: Hi Nitin, Do u mean redirecting Standard IO streams? On Mon, Aug 4, 2014 at 3:08 PM, Noufal Ibrahim KV nou...@nibrahim.net.in wrote: On Mon, Aug 04 2014, Nitin Kumar wrote: thats a typo error. in simple term my question would be: How to override sys.stdin. [...] The StringIO module gives you file like objects into which you can put data. They might work as substitues for sys.std* -- Cordially, Noufal http://nibrahim.net.in ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] how to override sys.stdin
On Mon, Aug 4, 2014 at 2:38 PM, Nitin Kumar nitin.n...@gmail.com wrote: Hi All, is there a way i can override raw_input or input function. This sooo smells of the XY Problem http://bitly.com/XyProblem. What are you really trying to do here? - d ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers