Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Saturday, June 18, 2016

Python: What is a header?

Python: What is a header?


I'm new to Python and programming in general. I am taking a module at university which requires me to write some fairly basic programs in Python. However, I got this feedback on my last assignment:

There should be a header block containing the file name, author name, date created, date modified and python version

What is a header block? Is it just comments at the top of your code or is it be something which prints when the program runs? Or something else?

Answer by recursive for Python: What is a header?


In this context, you are correct. A header block means a set of comments at the top of the source file that contains the requested information. It does not need to contain any code that does anything.

Answer by Bar?ş Akkurt for Python: What is a header?


Your instructor wants you to add some information to your assignment's source code's top section something like this, so you are right you will add comments:

####################################  # File name: ...                   #  # Author: ...                      #  # Submission:                      #  # Instructor:                      #  ####################################  

Answer by ustroetz for Python: What is a header?


A header block are just comments at the top of the code. It doesn't print when the program runs.

A example could look like the following:

# File name: test.py  # Author: Peter Test  # Date created: 4/20/2013  # Date last modified: 4/25/2013  # Python Version: 2.7    # Begin code    a = 1  b = 2    c = a + b    print c  

Answer by Vyktor for Python: What is a header?


There's thing called Docstring in python (and here're some conventions on how to write python code in general - PEP 8) escaped by either triple single quote """ or triple double quote """ well suited for multiline comments:

'''      File name: test.py      Author: Peter Test      Date created: 4/20/2013      Date last modified: 4/25/2013      Python Version: 2.7  '''  

You also may

used special variables later (when programming a module) that are dedicated to contain info as:

__author__ = "Rob Knight, Gavin Huttley, and Peter Maxwell"  __copyright__ = "Copyright 2007, The Cogent Project"  __credits__ = ["Rob Knight", "Peter Maxwell", "Gavin Huttley",                      "Matthew Wakefield"]  __license__ = "GPL"  __version__ = "1.0.1"  __maintainer__ = "Rob Knight"  __email__ = "rob@spot.colorado.edu"  __status__ = "Production"  

More details in answer here.

Answer by mckenzm for Python: What is a header?


Very good discussion here --> Python: What is the common header format?

The Python docstring should be concise, and not really contain revision history, or anything not directly related to the current version behaviour. I have yet to see "man" style docstrings and it may be just as well.

A flower box, with revision history independent of source control (as some of the revisions may pre-date your source control eventually) goes back to the days of reading code on paper or as emailed. We were not always as connected as we are now.

Using a modern IDE this has fallen out of favour, but can be seen for older/larger high level works. In some shops the sign in is not performed by the coder, especially if the code has been "shopped out". Some signin's are commented in a lazy, slovenly fashion.

So it varies, but :

#! /usr/bin/python  #--------------------------------#  # optional flower box    #--------------------------------#  """   Multiple lines of doc if required  """    import foo  import bar    __metastuff__='some value'  

I see the 'meta' higher up, notably in the youtube promotionals for "pycharm". People like to see it below the imports as it is really code and the imports are expected to come before the code. I can imagine it may become easy to get carried away. Sensible and informative comments in the low level code are worth way more than what is written upstairs anyway.

In the real world, just do what everybody else is doing on your project and you will be fine. It is common to re-use a template anyway, or copy and paste (i.e. ripoff) from a "prototype".


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

Related Posts:

0 comments:

Post a Comment

Popular Posts

Fun Page

Powered by Blogger.