python doesn't like my numbers

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

    python doesn't like my numbers

    hi,

    is there any way to convince python not to take my (phone)numbers
    starting with zero as octals?
    [color=blue][color=green][color=darkred]
    >>> int(088)[/color][/color][/color]
    File "<stdin>", line 1
    int(088)
    ^
    SyntaxError: invalid token

    thanks
    Paul
  • Peter Kleiweg

    #2
    Re: python doesn't like my numbers

    paul k schreef:
    [color=blue]
    > hi,
    >
    > is there any way to convince python not to take my (phone)numbers
    > starting with zero as octals?
    >[color=green][color=darkred]
    > >>> int(088)[/color][/color]
    > File "<stdin>", line 1
    > int(088)
    > ^
    > SyntaxError: invalid token[/color]


    What is the integer value of a phone number?


    --
    Peter Kleiweg L:NL,af,da,de,e n,ia,nds,no,sv, (fr,it) S:NL,de,en,(da, ia)
    info: http://www.let.rug.nl/~kleiweg/ls.html

    Comment

    • Alan Kennedy

      #3
      Re: python doesn't like my numbers

      [paul k][color=blue]
      > is there any way to convince python not to take my (phone)numbers
      > starting with zero as octals?
      >[color=green][color=darkred]
      > >>> int(088)[/color][/color]
      > File "<stdin>", line 1
      > int(088)
      > ^
      > SyntaxError: invalid token[/color]

      Answer 1: Use strings: that's really what telephone numbers should be

      Answer 2: Use valid octal digits in your phone numbers. The digit '8'
      cannot appear in base 8 numbers, only the digits 0-7.
      [color=blue][color=green][color=darkred]
      >>> int(077)[/color][/color][/color]
      63[color=blue][color=green][color=darkred]
      >>> int(088)[/color][/color][/color]
      Traceback (innermost last):
      (no code object) at line 0
      File "<console>" , line 1
      int(088)
      ^
      SyntaxError: invalid syntax[color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]

      --
      alan kennedy
      ------------------------------------------------------
      email alan: http://xhaus.com/contact/alan

      Comment

      • Reid Nichol

        #4
        Re: python doesn't like my numbers

        paul k wrote:[color=blue]
        > hi,
        >
        > is there any way to convince python not to take my (phone)numbers
        > starting with zero as octals?
        >[color=green][color=darkred]
        > >>> int(088)[/color][/color]
        > File "<stdin>", line 1
        > int(088)
        > ^
        > SyntaxError: invalid token
        >
        > thanks
        > Paul[/color]

        int("088")

        Comment

        • Leif K-Brooks

          #5
          Re: python doesn't like my numbers

          paul k wrote:[color=blue]
          > is there any way to convince python not to take my (phone)numbers
          > starting with zero as octals?
          >[color=green][color=darkred]
          > >>> int(088)[/color][/color]
          > File "<stdin>", line 1
          > int(088)
          > ^
          > SyntaxError: invalid token[/color]

          Why do they have to start with zeros in your source code?

          The fact that you're passing the number through int() makes me guess
          that you're actually talking about input of some kind which you'll pass
          through int(). If that's the case, they will be strings, and the problem
          will go away:
          [color=blue][color=green][color=darkred]
          >>> int('088')[/color][/color][/color]
          88

          Comment

          • paul k

            #6
            Re: python doesn't like my numbers

            Alan Kennedy wrote:[color=blue]
            > [paul k][/color]
            [color=blue]
            > Answer 1: Use strings: that's really what telephone numbers should be[/color]
            Yea, should have done this in the first place...
            [color=blue]
            >
            > Answer 2: Use valid octal digits in your phone numbers. The digit '8'
            > cannot appear in base 8 numbers, only the digits 0-7.[/color]
            I can't change reality (yet) ;)

            thanks for all your comments
            Paul

            Comment

            • Andrea Griffini

              #7
              Re: python doesn't like my numbers

              On Sun, 22 Aug 2004 18:52:50 -0400, Leif K-Brooks
              <eurleif@ecritt ers.biz> wrote:
              [color=blue]
              >paul k wrote:[color=green]
              >> is there any way to convince python not to take my (phone)numbers
              >> starting with zero as octals?
              >>[color=darkred]
              >> >>> int(088)[/color]
              >> File "<stdin>", line 1
              >> int(088)
              >> ^
              >> SyntaxError: invalid token[/color]
              >
              >Why do they have to start with zeros in your source code?[/color]

              My guess is that his program was simply using "input()"

              Im rather new to python and I've to say that I found quite
              surprising that the "input" function does also evaluate
              (so entering "1+1" i get the number 2 and not the string
              "1+1") and that I've to use "raw_input" to get what the
              user typed in.

              Andrea

              Comment

              Working...