checking for ASCII character

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

    checking for ASCII character

    Hi, is there a way to check if a letter entered is an uppercase ASCII
    character?

    Thanks

    Daniel


  • Greg Krohn

    #2
    Re: checking for ASCII character

    Daniel wrote:[color=blue]
    > Hi, is there a way to check if a letter entered is an uppercase ASCII
    > character?
    >
    > Thanks
    >
    > Daniel[/color]

    If you just want to know if a character is uppercase:

    if character.isupp er():
    <some code>

    If it needs to be ASCII, the simplest way is probably:

    if ord(character) in range(65, 91):
    <some code>



    greg

    Comment

    • rm

      #3
      Re: checking for ASCII character

      Greg Krohn wrote:[color=blue]
      > Daniel wrote:
      >[color=green]
      >> Hi, is there a way to check if a letter entered is an uppercase ASCII
      >> character?
      >>
      >> Thanks
      >>
      >> Daniel[/color]
      >
      >
      > If you just want to know if a character is uppercase:
      >
      > if character.isupp er():
      > <some code>
      >
      > If it needs to be ASCII, the simplest way is probably:
      >
      > if ord(character) in range(65, 91):
      > <some code>
      >
      >
      >
      > greg
      >[/color]

      one could check for ascii by doing:

      try :
      character.encod e('ascii')
      except UnicodeDecodeEr ror :
      ascii = False
      else :
      ascii = True

      if ascii and character.isupp er() :
      pass

      or something like it

      bye,
      rm

      Comment

      • Andrei

        #4
        Re: checking for ASCII character

        Daniel wrote on Thu, 13 Nov 2003 19:59:12 -0000:
        [color=blue]
        > Hi, is there a way to check if a letter entered is an uppercase ASCII
        > character?[/color]

        ascii_uppercase in the string module contains all uppercase ASCII chars.
        Use "if ... in ..." to find out whether your letter is in that constant.

        --
        Yours,

        Andrei

        =====
        Mail address in header catches spam. Real contact info (decode with rot13):
        cebwrpg5@jnanqb b.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
        gur yvfg, fb gurer'f ab arrq gb PP.


        Comment

        • Andrew Dalke

          #5
          Re: checking for ASCII character

          Greg Krohn:[color=blue]
          > If it needs to be ASCII, the simplest way is probably:
          >
          > if ord(character) in range(65, 91):
          > <some code>[/color]

          or

          if character in string.ascii_up percase:
          ...

          Andrew
          dalke@dalkescie ntific.com


          Comment

          • Dan Bishop

            #6
            Re: checking for ASCII character

            "Daniel" <danielNO@SPAMh alliwell1.plus. com> wrote in message news:<QmRsb.799 7$lm1.54932@war ds.force9.net>. ..[color=blue]
            > Hi, is there a way to check if a letter entered is an uppercase ASCII
            > character?[/color]

            letter.isupper( )

            Comment

            Working...