#1
  1. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    30

    Question How do you combine strings and ints?


    How do you combine a string and an int in Python? For example, I was messing around with some of the winsound functions, and when I tried something like:

    print "Bitrate: " + params[1]

    Params[1] being the second element in the params array, which is contains information about the sound file (ie. type, bitrate, mono/stereo, etc.). I got an error saying I couldn't combine a string with an int (which, by the way is the stupidest syntax rule I've ever heard).
    Matt
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13

    Re: How do you combine strings and ints?


    Originally posted by marron79
    How do you combine a string and an int in Python? For example, I was messing around with some of the winsound functions, and when I tried something like:

    print "Bitrate: " + params[1]

    Params[1] being the second element in the params array, which is contains information about the sound file (ie. type, bitrate, mono/stereo, etc.). I got an error saying I couldn't combine a string with an int (which, by the way is the stupidest syntax rule I've ever heard).
    Code:
    print "Bitrate: %d" % params[1]
    print "Bitrate: " + str(params[1])
    Either will work.

    Have you gone through the tutorial on www.python.org ?
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  4. #3
  5. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    30
    print "Bitrate: " + str(params[1])
    Converting the int to a string....duh! Why didn't I think of that?

    Thanks!
    Matt

IMN logo majestic logo threadwatch logo seochat tools logo