Python for Visual Basic or C# programmers

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

    #1

    Python for Visual Basic or C# programmers

    Hi,



    I am trying to find the equivalent functions such as vb's str or asc in
    Python. Is there any resource that help me to find these kinds of functions
    in Python faster?



    Thank you,

    Alan


  • Metalone

    #2
    Re: Python for Visual Basic or C# programmers

    A.M wrote:[color=blue]
    > Hi,
    >
    >
    >
    > I am trying to find the equivalent functions such as vb's str or asc in
    > Python. Is there any resource that help me to find these kinds of functions
    > in Python faster?
    >
    >
    >
    > Thank you,
    >
    > Alan[/color]
    [color=blue]
    >
    > Alan[/color]

    Python has a str() function that is close to vb's str. The Python
    version does not produce a leading space.
    str(123) --> '123'

    If you want to control the formatting to mimick vb or create different
    formatting you can use.
    " %d" % 123 --> ' 123'
    The format specifier is just like 'C's printf format strings.
    A tuple should follow the % sign if formatting more than 1 number.
    "%d %d" % (123, 456)

    Python has a similar function to vb's asc.
    It is ord().
    ord() accepts a single character, whereas asc operates on the first
    character of a string.
    To mimick vb you could do
    s = 'hello'
    ord(s[0]) --> 104

    I am unaware of any reference associating vb functionality with Python
    functionality.
    Then again, I never looked for one.

    Comment

    • Kent Johnson

      #3
      Re: Python for Visual Basic or C# programmers

      A.M wrote:[color=blue]
      > I am trying to find the equivalent functions such as vb's str or asc in
      > Python. Is there any resource that help me to find these kinds of functions
      > in Python faster?[/color]

      The Library Reference has a section on built-in functions:


      Also take a look at the section on string methods:


      Kent

      Comment

      • Metalone

        #4
        Re: Python for Visual Basic or C# programmers

        Slight correction.
        " %d" % 123 is not quite equivalent to str(123) as it does not handle
        negative numbers the same way.
        I am not sure there is a simple direct equivalent.
        "%+d" % 123 --> "+123" always gives a sign.
        "%4d" % 123 --> " 123"
        "%4d" % -123 --> "-123" so this works if you you know how wide the
        number is.

        This might be a little too tricky.
        [" %d", "%d][n < 0] % n --> selects list[0] or list[1] based upon sign
        of number

        Comment

        • Max

          #5
          Re: Python for Visual Basic or C# programmers

          Metalone wrote:
          <on imitatting VB's irritating space-or-minus>[color=blue]
          >
          > This might be a little too tricky.
          > [" %d", "%d][n < 0] % n --> selects list[0] or list[1] based upon sign
          > of number
          >[/color]

          ("%+d" % 123).replace("+ ", " ") is slightly longer but instantly
          comprehensible, although I for one think your boolean indexing trick is
          cool.

          --Max

          Comment

          • Laurent Pointal

            #6
            Re: Python for Visual Basic or C# programmers

            A.M a écrit :[color=blue]
            > Hi,
            >
            >
            >
            > I am trying to find the equivalent functions such as vb's str or asc in
            > Python. Is there any resource that help me to find these kinds of functions
            > in Python faster?[/color]

            <mode pub="on">

            I've written the PQRC for that purpose:


            </mode>

            A+

            Laurent.

            Comment

            • Chris Lambacher

              #7
              Re: Python for Visual Basic or C# programmers

              On Fri, Jun 02, 2006 at 10:26:28AM +0200, Laurent Pointal wrote:[color=blue]
              > A.M a ?crit :[color=green]
              > > Hi,
              > >
              > >
              > >
              > > I am trying to find the equivalent functions such as vb's str or asc in
              > > Python. Is there any resource that help me to find these kinds of functions
              > > in Python faster?[/color]
              >
              > <mode pub="on">
              >
              > I've written the PQRC for that purpose:
              > http://www.limsi.fr/Individu/pointal/python/pqrc/
              >
              > </mode>[/color]
              There is also the Python Quick reference series:
              http://rgruet.free.fr/#QuickRef[color=blue]
              >
              > A+
              >
              > Laurent.
              > --
              > http://mail.python.org/mailman/listinfo/python-list[/color]

              Comment

              Working...