#1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    Turning Chr() Around.


    I need my application to have something that works like Asc() does in VB6. This is the exact opposite of Chr(). Instead of using chr() to get me the number of a certain character(s), I need something like Asc() to give me back the numbers instead of the character(s).
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Use the ord() function, or define your own asc function.
    Code:
    def asc(c):
         return ord(c)
    
    print asc('A')
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    You might find the following link useful:
    Python Quick Reference

    grimey
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by Scorpions4ever
    Use the ord() function, or define your own asc function.
    Code:
    def asc(c):
         return ord(c)
    
    print asc('A')
    If you want to create copies/aliases to built-in functions/modules/classes using custom names the simplest way to do it is to assign the object to a variable i.e.

    Code:
    >>> someChar = chr(97)
    >>> someChar
    'a'
    >>> asc = ord
    >>> ord(someChar)
    97
    >>> asc(someChar)
    97
    >>>
    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo