Skip to content Skip to sidebar Skip to footer

Python Does Not Allow Additional Comment With Env Python

I have a commenting line problem in python. I created a ages.py with vim and here is my script #!/usr/bin/env python ages={'dad':42, 'mom':35, 'lisa':7} for item in ages: p

Solution 1:

That first line is a very important one. It's called the Hashbang and sometimes known as the shebang. It tells the operating system what interpreter to use to execute the script. When the shebang is used, it has to be the first line. Other variations include

#!/bin/sh#!/usr/bin/perl/#!/usr/bin/python

These are for system default sh, perl and python. Any other comments in your code has to be after this line.

Solution 2:

  1. the line containing #!/usr/bin/env pythonmust be first, you can add your comments below;

  2. yes, you can do it like this: exec(open('yourscript.py').read()) - however, results might sometimes differ from your expectations.

Post a Comment for "Python Does Not Allow Additional Comment With Env Python"