Python code file prototype

B

Bruce Eckel

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.
 
J

John Gordon

In said:
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.
 
I

Ian Kelly

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
 
G

Grant Edwards

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).
 
D

Dennis Lee Bieber

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>
 
B

Bruce Eckel

        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.
 
G

Grant Edwards

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.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top