How to recast integer to a string

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

    #1

    How to recast integer to a string

    How to recast an integer to a string?

    something like
    n = 5
    str = str + char(n)


    J.L

  • Christoph Haas

    #2
    Re: How to recast integer to a string

    On Tue, May 09, 2006 at 12:17:34PM -0700, James wrote:[color=blue]
    > How to recast an integer to a string?
    >
    > something like
    > n = 5
    > str = str + char(n)[/color]

    str(n)

    Kindly
    Christoph

    Comment

    • James

      #3
      Re: How to recast integer to a string


      Christoph Haas wrote:[color=blue]
      > On Tue, May 09, 2006 at 12:17:34PM -0700, James wrote:[color=green]
      > > How to recast an integer to a string?
      > >
      > > something like
      > > n = 5
      > > str = str + char(n)[/color]
      >
      > str(n)
      >
      > Kindly
      > Christoph[/color]

      In python2,4, I 've got
      TypeError: 'str' object is not callable

      J.L

      Comment

      • Grant Edwards

        #4
        Re: How to recast integer to a string

        On 2006-05-09, James <hslee911@yahoo .com> wrote:[color=blue]
        > How to recast an integer to a string?[/color]
        [color=blue]
        > something like
        > n = 5
        > str = str + char(n)[/color]

        str = str + chr(5)

        --
        Grant Edwards grante Yow! I want EARS! I
        at want two ROUND BLACK
        visi.com EARS to make me feel warm
        'n secure!!

        Comment

        • Larry Bates

          #5
          Re: How to recast integer to a string

          James wrote:[color=blue]
          > How to recast an integer to a string?
          >
          > something like
          > n = 5
          > str = str + char(n)
          >
          >
          > J.L
          >[/color]
          Two items:

          1) Never use 'str' as a variable name as it will
          shadow the built in str function. If you do, this
          WILL jump up and bite you.

          2) Either s=str(n) or s="%i" % n will return string
          containing '5' (without the quotes of course).

          Note: chr(n) would return character whose ASCII decimal
          value is 5 (ASCII ENQ).

          -Larry Bates

          Comment

          • Fredrik Lundh

            #6
            Re: How to recast integer to a string

            James wrote:
            [color=blue][color=green][color=darkred]
            > > > How to recast an integer to a string?
            > > >
            > > > something like
            > > > n = 5
            > > > str = str + char(n)[/color]
            > >
            > > str(n)
            > >
            > > Kindly
            > > Christoph[/color]
            >
            > In python2,4, I 've got
            > TypeError: 'str' object is not callable[/color]

            if you want to use a builtin function, you cannot use the same name
            for your own variables.

            </F>



            Comment

            • Christoph Haas

              #7
              Re: How to recast integer to a string

              On Tue, May 09, 2006 at 12:34:05PM -0700, James wrote:[color=blue]
              >
              > Christoph Haas wrote:[color=green]
              > > On Tue, May 09, 2006 at 12:17:34PM -0700, James wrote:[color=darkred]
              > > > How to recast an integer to a string?
              > > >
              > > > something like
              > > > n = 5
              > > > str = str + char(n)[/color]
              > >
              > > str(n)
              > >
              > > Kindly
              > > Christoph[/color]
              >
              > In python2,4, I 've got
              > TypeError: 'str' object is not callable[/color]

              What I meant was:

              string_from_num ber = str(n)

              Kindly
              Christoph

              Comment

              Working...