Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Embedded comments in Python?

Reply
Thread Tools

Embedded comments in Python?

 
 
Ernie
Guest
Posts: n/a
 
      05-03-2004
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
 
Reply With Quote
 
 
 
 
Irmen de Jong
Guest
Posts: n/a
 
      05-03-2004
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
 
Reply With Quote
 
 
 
 
David Goodger
Guest
Posts: n/a
 
      05-03-2004
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


 
Reply With Quote
 
Ville Vainio
Guest
Posts: n/a
 
      05-03-2004
>>>>> "Ernie" == Ernie <(E-Mail Removed)> 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
 
Reply With Quote
 
Tonio
Guest
Posts: n/a
 
      05-07-2004

"Ernie" <(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed) m...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded <divs> with events: How to prevent the parent div's eventfrom being fired when the embedded div's event is fired? Num GG Javascript 2 11-17-2008 08:56 PM
Embedded vs. Non-embedded Tests Trans Ruby 11 09-05-2007 11:22 AM
Embedded languages based on early Ada (from "Re: Preferred OS, processor family for running embedded Ada?") Colin Paul Gloster VHDL 48 04-10-2007 10:31 AM
How to display images embedded in e-mail as embedded, not attachments Jim Firefox 4 12-11-2004 05:36 AM
Databind an embedded control in an embedded datagrid Thomas Dodds ASP .Net Datagrid Control 0 07-26-2004 08:20 PM



Advertisments