Embedded comments in Python?

Discussion in 'Python' started by Ernie, May 3, 2004.

  1. Ernie

    Ernie Guest

    Hi,
    Whats the legal way in Python to embed comments in Python code?
    Example:

    def foo(a <:int>, b <:float>): <:array>
    return [a, b]

    Want the CPython interpreter to ignore the <:int>, <:float> and
    <:array>(this one can be written as #array). Using triple quoted
    strings would be longer and is invalid syntax. This would be
    extremely useful for those who write tools for processing Python
    scripts. In C/C++, this would be no problem with /* */.

    Regards,

    Ernie
     
    Ernie, May 3, 2004
    #1
    1. Advertising

  2. Ernie wrote:

    > Hi,
    > Whats the legal way in Python to embed comments in Python code?
    > Example:
    >
    > def foo(a <:int>, b <:float>): <:array>
    > return [a, b]
    >
    > Want the CPython interpreter to ignore the <:int>, <:float> and
    > <:array>(this one can be written as #array). Using triple quoted
    > strings would be longer and is invalid syntax. This would be
    > extremely useful for those who write tools for processing Python
    > scripts. In C/C++, this would be no problem with /* */.


    Why not:

    def foo(a,b): # (a:int,b:int)-->array
    return [a,b]

    That should be almost as easy to generate/process?

    --Irmen
     
    Irmen de Jong, May 3, 2004
    #2
    1. Advertising

  3. Ernie wrote:
    > Whats the legal way in Python to embed comments in Python code?
    > Example:
    >
    > def foo(a <:int>, b <:float>): <:array>
    > return [a, b]


    def foo(a, #int
    b #float
    ): #array
    return [a, b]

    Or better yet, put it all in a docstring:

    def foo(a, b):
    """Given an int and a float, returns an array of [int, float]."""
    return [a, b]

    > In C/C++, this would be no problem with /* */.


    This is not C/C++. In Python, comments begin with a "#" and end
    at the end of the line. That's it.

    -- David Goodger
     
    David Goodger, May 3, 2004
    #3
  4. Ernie

    Ville Vainio Guest

    >>>>> "Ernie" == Ernie <> writes:

    Ernie> def foo(a <:int>, b <:float>): <:array>
    Ernie> return [a, b]

    Ernie> Want the CPython interpreter to ignore the <:int>, <:float> and
    Ernie> <:array>(this one can be written as #array). Using triple quoted

    I imagine this would be something that would work best with the
    upcoming decorators. That way you could also use the 'comments' as a
    way to validate that the correct types of arguments actually go in to
    the method/function in "debug builds".

    --
    Ville Vainio http://tinyurl.com/2prnb
     
    Ville Vainio, May 3, 2004
    #4
  5. Ernie

    Tonio Guest

    "Ernie" <> ha scritto nel messaggio
    news:...
    > Hi,
    > Whats the legal way in Python to embed comments in Python code?
    > Example:
    >
    > def foo(a <:int>, b <:float>): <:array>
    > return [a, b]
    >
    > Want the CPython interpreter to ignore the <:int>, <:float> and
    > <:array>(this one can be written as #array). Using triple quoted
    > strings would be longer and is invalid syntax. This would be
    > extremely useful for those who write tools for processing Python
    > scripts. In C/C++, this would be no problem with /* */.
    >
    > Regards,
    >
    > Ernie



    Thanks Arkon, i'm a italian student and i need your tutorial.
    If you have a example, can you send me in my email?
    Thanks.
     
    Tonio, May 7, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,184
  2. Colin Paul Gloster
    Replies:
    48
    Views:
    1,972
    Colin Paul Gloster
    Apr 10, 2007
  3. Monk
    Replies:
    10
    Views:
    1,546
    Michael Wojcik
    Apr 20, 2005
  4. qazmlp
    Replies:
    2
    Views:
    156
    Ben Morrow
    Nov 17, 2004
  5. Replies:
    4
    Views:
    659
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page