Prining a pound sign from Python AND running from the command line at the same time
Archive - Originally posted on "The Horse's Mouth" - 2016-03-03 20:33:48 - Graham EllisIn order to make a python program executable on a Linix or Unix (e.g. OSX) system, you should:
a) change the file permissions using chmod (e.g.
chmod +x poundland
)b) Add as the very first line of the file
#!/usr/bin/env python
so the operating system knows it's a python programc) Optionally add the current folder to the path (
export PATH=$PATH:.
) if you don't want to have to run with "./"In order to display a pound sign from your Python program, common advise is to add
# -*- coding: utf-8 -*-
as the first line of your script.Problem is .. you can't have both the
#!
line and the -*- coding
lines as the first in your file.Solution - reading the manually very carefully, I learned that the
-*- coding
line can be the first or second line in the file .. thus it works if my code starts: #!/usr/bin/env python
# -*- coding: utf-8 -*-
Practical tests confirm that this works, but that even a blank line between the two causes it to fail.
Full source code example at [here]