Thread: ASCII numbers

    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11

    ASCII numbers


    how would I store these numbers because I am gonna try to make a ASCII program that identifs all ASCII and prints them...

    But where would I put the numbers and letter a dictionary does not work because you can't assign a string to a number
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Why not use the int() function and the str() function to change your numbers back and forth to strings and integers until you are done doing what you have to do?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    24
    you can use a string as the index for a integer in a dictionary? What exactly where you trying to do?
  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 CyBerHigh
    you can use a string as the index for a integer in a dictionary? What exactly where you trying to do?
    I was just thinking the same thing here. I also don't understand why you say cant use ints as keys in a dictionary:

    Code:
    >>> aDict = {1:'one', 2:'two'}
    >>> aDict
    {1: 'one', 2: 'two'}
    >>>
    Depending on what your trying to do you might not even need to create a dictionary; you could be able to use the ord() and chr() functions here.

    Take care,

    Mark.

    Comments on this post

    • SimonGreenhill agrees : Yes! ord() and chr() will do it.
    programming language development: www.netytan.com Hula

  8. #5
  9. (retired)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2003
    Location
    The Laboratory
    Posts
    10,101
    Rep Power
    0
    ord & chr will do it:

    Code:
    lurch:/home# python
    Python 2.3.5 (#2, Feb  9 2005, 00:38:15)
    [GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> ord('a')
    97
    >>> chr(97)
    'a'
    If you really wanted:
    Code:
    def return_ascii( chr ):
        return ord( chr )
    
    def return_char ( asc ):
        return chr( int (asc) ) # may need to make sure this is an int first.
    --Simon
    Last edited by SimonGreenhill; May 17th, 2005 at 06:25 PM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    well I don't know dictionaries well so ill probably use chr and ord

    Thanks guys
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2005
    Location
    canada, B.C.
    Posts
    12
    Rep Power
    0
    wow, i just learned how to do this in my information technology class, ASCII nubmers n stuff, what a coincidence

IMN logo majestic logo threadwatch logo seochat tools logo