Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what does # -*- mean?
#1
i see this a lot and even use it myself:
# -*- coding: utf-8 -*-
i would like to know what the -*- part means, or at least the first one. can it be used for other things? how are these things defined? is it part of the formal language despite being in comments?

i have something like this of my own i was to put in my code. i am wondering if doing that could interfere with other things. what i want to do is set up begin and end markers for files i have included inside another larger file. the marker would identify what was included. a begin marker would precede the included content and an end marker would follow. a script can be run on the larger file to update everything that is included this way.

for example:

# -*- include: somecode.py -*-
# this is data:
blocksize = 4096
buffersize = 32768
# -*- include end: somecode.py -*-
some day it might be changed. then i just re-run that update script on the larger file.

# -*- include: somecode.py -*-
# this is data:
blocksize = 4096
buffersize = 1048576
# -*- include end: somecode.py -*-
so can i use -*- or do i need to make up my own thing?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Python HOWTO Wrote:The syntax is inspired by Emacs’s notation for specifying variables local to a file. Emacs supports many different variables, but Python only supports ‘coding’. The -*- symbols indicate to Emacs that the comment is special; they have no significance to Python but are a convention. Python looks for coding: name or coding=name in the comment.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
does Python accept coding: or coding= in a comment (or in the first comment) even without the -*-?

i'll look around emacs stuff, then. i do use emacs, but not an IDE.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(Apr-07-2019, 03:26 AM)Skaperen Wrote: does Python accept coding: or coding= in a comment (or in the first comment) even without the -*-?

You could always try it and find out.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Sometimes I have the feeling, that you ask us for permission to test something.
It is your sandbox, you can do what you want.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#6
i do test many things. the default encoding, at least in Python3.5, is utf-8 so i don't know why i am doing this since i have used, nor expect to use, anything else. i guess it can help with Emacs as it has been a problem with some files that have Unicode characters above 127 coded as utf-8 in them. it might be default ascii. so testing this with python will probably show nothing.

i am not asking for permission. but i do, often, try to get opinions of experience as they might apply to ideas i have. not everything i do bad breaks immediately.

i have seen # -*- coding: utf8 -*- in some code. i wonder if that would be recognized.

so Python doesn't need the -*- but Emacs does.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020