Embedded comments in Python?

E

Ernie

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
 
I

Irmen de Jong

Ernie said:
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
 
D

David Goodger

Ernie said:
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
 
V

Ville Vainio

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".
 
T

Tonio

Ernie said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top