Re: How can I handle the char immediately after its input,without waiting an endline?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lie Ryan

    Re: How can I handle the char immediately after its input,without waiting an endline?

    >>I want to write something that handle every char immediately after its
    >>input. Then tehe user don't need to type [RETURN] each time. How can I
    >>do this?
    >>>
    >>Thanks in advance.
    Don't you think that getting a one-character from console is something
    that many people do very often? Do you think that all these platform
    independent code should be moved to the interpreter level instead (and
    raises the appropriate error when the platform somehow cannot do
    unbuffered input)? So python developer could do something like this:

    raw_input(buffe rring = 0)

  • Steven D'Aprano

    #2
    Re: How can I handle the char immediately after its input,without waiting an endline?

    On Sat, 25 Oct 2008 08:36:32 +0000, Lie Ryan wrote:
    >>>I want to write something that handle every char immediately after
    >>>its input. Then tehe user don't need to type [RETURN] each time. How
    >>>can I do this?
    >>>>
    >>>Thanks in advance.
    >
    Don't you think that getting a one-character from console is something
    that many people do very often?
    No.

    I can't think of any modern apps that use one character commands like
    that. One character plus a modifier (ctrl or alt generally) perhaps, but
    even there, it's mostly used in GUI applications.

    Do you think that all these platform
    independent code should be moved to the interpreter level instead
    Absolutely not! There's no need for it to be given a keyword or special
    syntax.

    But maybe there should be a standard library function for it.

    (and
    raises the appropriate error when the platform somehow cannot do
    unbuffered input)? So python developer could do something like this:
    >
    raw_input(buffe rring = 0)
    No. Leave raw_input as it is. A better interface would be:

    import input_services
    c = input_services. get_char()

    Eventually the module could grow other services as well.





    --
    Steven

    Comment

    • Roel Schroeven

      #3
      Re: How can I handle the char immediately after its input, withoutwaiting an endline?

      Steven D'Aprano schreef:
      I can't think of any modern apps that use one character commands like
      that. One character plus a modifier (ctrl or alt generally) perhaps, but
      even there, it's mostly used in GUI applications.
      less, vi, info, top, cfdisk, lynx, links, ... come to mind. I suppose
      there are many more that I can't think of at the moment.

      --
      The saddest aspect of life right now is that science gathers knowledge
      faster than society gathers wisdom.
      -- Isaac Asimov

      Roel Schroeven

      Comment

      • Steven D'Aprano

        #4
        Re: How can I handle the char immediately after its input, withoutwaiting an endline?

        On Sat, 25 Oct 2008 16:30:55 +0200, Roel Schroeven wrote:
        Steven D'Aprano schreef:
        >I can't think of any modern apps that use one character commands like
        >that. One character plus a modifier (ctrl or alt generally) perhaps,
        >but even there, it's mostly used in GUI applications.
        >
        less, vi, info, top, cfdisk, lynx, links, ... come to mind. I suppose
        there are many more that I can't think of at the moment.
        I said modern *wink*

        But seriously... point taken.


        --
        Steven

        Comment

        • Lie Ryan

          #5
          Re: How can I handle the char immediately after its input,without waiting an endline?

          On Sat, 25 Oct 2008 09:04:01 +0000, Steven D'Aprano wrote:
          On Sat, 25 Oct 2008 08:36:32 +0000, Lie Ryan wrote:
          >
          >>>>I want to write something that handle every char immediately after
          >>>>its input. Then tehe user don't need to type [RETURN] each time. How
          >>>>can I do this?
          >>>>>
          >>>>Thanks in advance.
          >>
          >Don't you think that getting a one-character from console is something
          >that many people do very often?
          >
          No.
          >
          I can't think of any modern apps that use one character commands like
          that. One character plus a modifier (ctrl or alt generally) perhaps, but
          even there, it's mostly used in GUI applications.
          >
          >
          >Do you think that all these platform
          >independent code should be moved to the interpreter level instead
          >
          Absolutely not! There's no need for it to be given a keyword or special
          syntax.
          By "interprete r level", I meant python's VM including its standard
          libraries (i.e. anywhere but at end-programmer's level), I don't mean it
          should have a keyword or special syntax or anything of that sort.
          But maybe there should be a standard library function for it.
          >
          >
          >(and
          >raises the appropriate error when the platform somehow cannot do
          >unbuffered input)? So python developer could do something like this:
          >>
          >raw_input(buff erring = 0)
          >
          No. Leave raw_input as it is. A better interface would be:
          >
          import input_services
          c = input_services. get_char()
          That would be fine as well.
          >
          Eventually the module could grow other services as well.
          >


          Comment

          • Lie Ryan

            #6
            Re: How can I handle the char immediately after its input, withoutwaiting an endline?

            On Sat, 25 Oct 2008 15:27:32 +0000, Steven D'Aprano wrote:
            On Sat, 25 Oct 2008 16:30:55 +0200, Roel Schroeven wrote:
            >
            >Steven D'Aprano schreef:
            >>I can't think of any modern apps that use one character commands like
            >>that. One character plus a modifier (ctrl or alt generally) perhaps,
            >>but even there, it's mostly used in GUI applications.
            >>
            >less, vi, info, top, cfdisk, lynx, links, ... come to mind. I suppose
            >there are many more that I can't think of at the moment.
            >
            I said modern *wink*
            >
            But seriously... point taken.
            >
            I uses some of them a lot... less and top is on the top of my list (pun
            intended). I sometimes used vi(m), although I never really liked it, but
            it's sometimes unavoidable. info is replaced by man. lynx and links...
            well I remember a time when I tried to install Gentoo on a VMWare, lynx/
            links (I forgot which one) was a life-saver because I wouldn't need to
            get out to the Windows host every two seconds to see the installation
            instruction (I was new to Linux at that time), and that was on a VMWare,
            what if I installed it directly, not on a virtual machine?

            And as far as I know, it is impossible to implement a "press any key"
            feature with python in a simple way (as it should be). And if std input's
            character buffering is easy, it'd contribute a lot to command-line real
            time action games (and of course many other programs, but that is the
            first genre of programs that crosses my mind).

            PS:
            >>modern != GUI
            True
            >>commandline == old
            False

            Comment

            • Duncan Booth

              #7
              Re: How can I handle the char immediately after its input, without waiting an endline?

              Lie Ryan <lie.1296@gmail .comwrote:
              And as far as I know, it is impossible to implement a "press any key"
              feature with python in a simple way (as it should be).
              "press any key" is a misfeature at the best of times. Quite apart from the
              people who can't find the key with 'any' written on it there are also the
              people who can't figure out why it 'Ctrl', 'Alt', 'Shift', 'Caps Lock'
              aren't keys (not to mention the smartass's who think Ctrl+Break is a key).
              It is better to always ask for a specific key.

              Have you tried Google? Googling for "python getch" gives
              http://snippets.dzone.com/posts/show/915 as the first hit.

              Comment

              • Lie Ryan

                #8
                Re: How can I handle the char immediately after its input,without waiting an endline?

                On Sun, 26 Oct 2008 09:23:41 +0000, Duncan Booth wrote:
                Lie Ryan <lie.1296@gmail .comwrote:
                >
                >And as far as I know, it is impossible to implement a "press any key"
                >feature with python in a simple way (as it should be).
                >
                "press any key" is a misfeature at the best of times. Quite apart from
                the people who can't find the key with 'any' written on it there are
                also the people who can't figure out why it 'Ctrl', 'Alt', 'Shift',
                'Caps Lock' aren't keys (not to mention the smartass's who think
                Ctrl+Break is a key). It is better to always ask for a specific key.
                I know about those jokes. And it's the reason why I mentioned that (the
                serious point is about getting one-char input for "command-line GUI"
                applications like curse-based apps that is too simple to include the
                whole curse).

                Comment

                Working...