Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20555 > unrolled thread

Python code file prototype

Started byBruce Eckel <lists.eckel@gmail.com>
First post2012-02-17 07:35 -0800
Last post2012-02-18 15:25 +0000
Articles 7 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  Python code file prototype Bruce Eckel <lists.eckel@gmail.com> - 2012-02-17 07:35 -0800
    Re: Python code file prototype John Gordon <gordon@panix.com> - 2012-02-17 16:20 +0000
      Re: Python code file prototype Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-17 09:55 -0700
      Re: Python code file prototype Grant Edwards <invalid@invalid.invalid> - 2012-02-17 17:02 +0000
      Re: Python code file prototype Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-02-17 12:56 -0500
        Re: Python code file prototype Bruce Eckel <lists.eckel@gmail.com> - 2012-02-17 11:03 -0800
        Re: Python code file prototype Grant Edwards <invalid@invalid.invalid> - 2012-02-18 15:25 +0000

#20555 — Python code file prototype

FromBruce Eckel <lists.eckel@gmail.com>
Date2012-02-17 07:35 -0800
SubjectPython code file prototype
Message-ID<66ea0353-02ee-4152-947a-97b44ff3ec45@p7g2000yqk.googlegroups.com>
I finally figured out how to set up the Windows explorer's right-click
"new" so that it will create Python files. Here's how:
http://superuser.com/questions/34704/windows-7-add-an-item-to-new-context-menu

There's an option when you do this to insert default file contents, so
I began searching the web for some kind of prototype Python file that
would be appropriate to start with. I'm certain I've seen this before
and that there's been discussions about the best starting point for a
python code file, but I find I can't get any search hits for it.

Hoping for some links, thanks.

[toc] | [next] | [standalone]


#20556

FromJohn Gordon <gordon@panix.com>
Date2012-02-17 16:20 +0000
Message-ID<jhluol$63c$1@reader1.panix.com>
In reply to#20555
In <66ea0353-02ee-4152-947a-97b44ff3ec45@p7g2000yqk.googlegroups.com> Bruce Eckel <lists.eckel@gmail.com> writes:

> There's an option when you do this to insert default file contents, so
> I began searching the web for some kind of prototype Python file that
> would be appropriate to start with. I'm certain I've seen this before
> and that there's been discussions about the best starting point for a
> python code file, but I find I can't get any search hits for it.

Here's what PyScripter inserts in a new python file:

  #---------------------------------------------------------------------
  # Name:        module1
  # Purpose:
  #
  # Author:      $USERNAME
  #
  # Created:     $DATE
  # Copyright:   (c) $USERNAME $YEAR
  # Licence:     <your licence>
  #---------------------------------------------------------------------
  #!/usr/bin/env python

  def main():
      pass

  if __name__ == '__main__':
      main()


Where $USERNAME, $DATE and $YEAR are expanded to the actual values.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#20557

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-02-17 09:55 -0700
Message-ID<mailman.5920.1329497777.27778.python-list@python.org>
In reply to#20556
On Fri, Feb 17, 2012 at 9:20 AM, John Gordon <gordon@panix.com> wrote:
> Here's what PyScripter inserts in a new python file:
>
>  #---------------------------------------------------------------------
>  # Name:        module1
>  # Purpose:
>  #
>  # Author:      $USERNAME
>  #
>  # Created:     $DATE
>  # Copyright:   (c) $USERNAME $YEAR
>  # Licence:     <your licence>
>  #---------------------------------------------------------------------
>  #!/usr/bin/env python
>
>  def main():
>      pass
>
>  if __name__ == '__main__':
>      main()

The shebang has to be the first thing in the file to be useful.  As it
is above, it might as well not be there.  I would suggest also
including a doc string in the skeleton.

Cheers,
Ian

[toc] | [prev] | [next] | [standalone]


#20558

FromGrant Edwards <invalid@invalid.invalid>
Date2012-02-17 17:02 +0000
Message-ID<jhm177$9go$1@reader1.panix.com>
In reply to#20556
On 2012-02-17, John Gordon <gordon@panix.com> wrote:
> In <66ea0353-02ee-4152-947a-97b44ff3ec45@p7g2000yqk.googlegroups.com> Bruce Eckel <lists.eckel@gmail.com> writes:
>
>> There's an option when you do this to insert default file contents, so
>> I began searching the web for some kind of prototype Python file that
>> would be appropriate to start with. I'm certain I've seen this before
>> and that there's been discussions about the best starting point for a
>> python code file, but I find I can't get any search hits for it.
>
> Here's what PyScripter inserts in a new python file:
>
>   #---------------------------------------------------------------------
>   # Name:        module1
>   # Purpose:
>   #
>   # Author:      $USERNAME
>   #
>   # Created:     $DATE
>   # Copyright:   (c) $USERNAME $YEAR
>   # Licence:     <your licence>
>   #---------------------------------------------------------------------
>   #!/usr/bin/env python
>
>   def main():
>       pass
>
>   if __name__ == '__main__':
>       main()
>
>
> Where $USERNAME, $DATE and $YEAR are expanded to the actual values.

That's just plain broken.

The "#!" line has to be first thing in the file for it to be
recognized.

Apart from that, my personal opinion is that comment blocks like that
are bad practice.  They're too often wrong (e.g. file got copied
modified, but comment block not updated), and the right place for
metadata like that is the filesystem and the source-control system
(git, mercurial, subversion, CVS, whatever -- anything but VSS).

-- 
Grant

[toc] | [prev] | [next] | [standalone]


#20561

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-02-17 12:56 -0500
Message-ID<mailman.5921.1329501392.27778.python-list@python.org>
In reply to#20556
On Fri, 17 Feb 2012 09:55:46 -0700, Ian Kelly <ian.g.kelly@gmail.com>
wrote:

>
>The shebang has to be the first thing in the file to be useful.  As it
>is above, it might as well not be there.  I would suggest also
>including a doc string in the skeleton.
>
	Of course, since the OP was talking Windows... the #! line is
ignored no matter where it was <G>
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#20563

FromBruce Eckel <lists.eckel@gmail.com>
Date2012-02-17 11:03 -0800
Message-ID<7e33534f-0898-4cab-9782-9bdc2584586a@t5g2000yqk.googlegroups.com>
In reply to#20561
>         Of course, since the OP was talking Windows... the #! line is
> ignored no matter where it was <G>

Yes, but I use Windows, Mac and Linux so I'm searching for something
universal.

[toc] | [prev] | [next] | [standalone]


#20586

FromGrant Edwards <invalid@invalid.invalid>
Date2012-02-18 15:25 +0000
Message-ID<jhoft3$cug$1@reader1.panix.com>
In reply to#20561
On 2012-02-17, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
> On Fri, 17 Feb 2012 09:55:46 -0700, Ian Kelly <ian.g.kelly@gmail.com>
> wrote:
>
>>
>>The shebang has to be the first thing in the file to be useful.  As it
>>is above, it might as well not be there.  I would suggest also
>>including a doc string in the skeleton.
>>
> 	Of course, since the OP was talking Windows... the #! line is
> ignored no matter where it was <G>

That depends.  It always used to work for me, but I'm usually using
bash and Cygwin.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web