From: http://blog.csdn.net/chenggong2dm/article/details/7677028

#coding=utf-8

#-*- coding: utf-8 -*-

一直搞不清楚这俩头什么区别。直觉上一样。今天特意查了一下,大致明白了:

对于python解释器来说,这两种写法一样。但是对于编辑器来讲,可能会出现识别问题。

参考:http://www.python.org/dev/peps/pep-0263/

Defining the Encoding

    Python will default to ASCII as standard encoding if no otherencoding hints are given.To define a source code encoding, a magic comment mustbe placed into the source files either as first or secondline in the file, such as:# coding=<encoding name>or (using formats recognized by popular editors)#!/usr/bin/python# -*- coding: <encoding name> -*-or#!/usr/bin/python# vim: set fileencoding=<encoding name> :More precisely, the first or second line must match the regularexpression "coding[:=]\s*([-\w.]+)". The first group of thisexpression is then interpreted as encoding name. If the encodingis unknown to Python, an error is raised during compilation. Theremust not be any Python statement on the line that contains theencoding declaration.To aid with platforms such as Windows, which add Unicode BOM marksto the beginning of Unicode files, the UTF-8 signature'\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well(even if no magic encoding comment is given).If a source file uses both the UTF-8 BOM mark signature and amagic encoding comment, the only allowed encoding for the commentis 'utf-8'.  Any other encoding will cause an error.

python文件头--文件编码指定相关推荐

  1. python批量转换文件编码

    python批量转换文件编码   3年之前   python 今天在 eclipse 中导入了个之前的 swing 项目,结果跑起来后乱码,检查代码发现竟然一部分 java 文件是 utf-8 编码, ...

  2. 文件头文件尾全面总结

    目录 文件头文件尾汇总: PNG (png) zip文件 文件头文件尾汇总: 文件类型 文件头 文件尾 特征 JPEG (jpg) FFD8FF FF D9 ÿØÿà PNG (png) 89504E ...

  3. 杂项 文件头文件尾总结

    文件名 文件头 文件尾 JPEG(jpg), 文件头:FFD8FF 文件尾:FF D9 PNG(png), 文件头:89504E47 文件尾:AE 42 60 82 GIF(gif), 文件头:474 ...

  4. chatgpt赋能python:如何在Python中保存文件到指定文件夹

    如何在Python中保存文件到指定文件夹 如果您正在使用Python编写应用程序或脚本,您可能需要将输出保存到特定的文件夹中. 本文将介绍如何在Python中保存文件到指定文件夹. 使用os模块创建文 ...

  5. 利用python保存txt文件的指定行/前n行

    ** 利用python保存txt文件的指定行/前n行-等 1.txt文件,每隔n行保存 originPath='open.txt' savePath='save.txt' # 每隔多少行保存一次 l= ...

  6. 【CTF杂项】常见文件文件头文件尾格式总结及各类文件头

    文件头文件尾总结 JPEG (jpg),                         文件头:FFD8FF 文件尾:FF D9 PNG (png),                         ...

  7. 看不懂简明python教程_简明python教程之Python文件头注释的含义,你肯定不懂

    https://www.xin3721.com/eschool/pythonxin3721/ 本文档描述了Python语言文件头里典型注释的含义. 1. 指定解释器 不管在linux还是在window ...

  8. 各种类型文件头标准编码

    JPEG (jpg),文件头:FF D8 FF PNG (png),文件头:89 50 4E 47 [参考:png文件头详解]89 50 4e 47 0d 0a 1a 0a GIF (gif),文件头 ...

  9. Java根据文件头文件信息判断文件类型

    InputStream in = file.getInputStream(); //根据文件头获取文件类型 String type = FileType.getFileType(in); 注意file ...

最新文章

  1. 大家帮忙.谢谢!..(急急急急急)
  2. Python | 用PrettyPrinter,让Python输出更漂亮,你值得拥有
  3. JAVA正则表达式的学习
  4. 权威报告丨2018-2019 新型互联网生态研究报告摘要
  5. ipv6host更新
  6. IP多播技术及其应用
  7. HTML如何添加锚点,我先收藏为敬
  8. android 桌面视频播放器,ZY-Player ,一款跨平台桌面端视频资源播放器
  9. 顺序三元组 java_hihocoder-1550-顺序三元组
  10. 大数据学习笔记55:搭建HBase环境
  11. 计算机教室的教师端,极域电子教室教师端使用.doc
  12. 按键精灵开发后台命令脚本的操作教程
  13. PUMA 560机器人正运动学
  14. 多隆,他从阿里的第一位程序员,做到了阿里的合伙人,是神一样的人物
  15. 利用梆梆加固逻辑漏洞取巧脱壳
  16. 不得不说,这19个程序员兼职平台让我1年收入60w
  17. 如何显示文件夹的后缀和隐藏文件
  18. RV-LINK:GDB 使用 RV-LINK 仿真器调试 RISC-V 程序
  19. java老师实例_java实例关于继承求实例,有关学生和老师的程序代码!望诸位软件达人帮忙,谢谢大虾!...
  20. 编程资料 -C# 多线程 1

热门文章

  1. Angularjs 通过asp.net web api认证登录
  2. UVa 10026 - Shoemaker's Problem
  3. 高扫后督解决方案 力助银行内部核查
  4. 数据科学生命周期_数据科学项目生命周期第1部分
  5. 367. 有效的完全平方数
  6. leetcode 377. 组合总和 Ⅳ(dp)
  7. restful解决什么问题_当您陷入RESTful,WordPress和一个困难的地方时,如何解决CMS问题...
  8. 了解ES6 The Dope Way第三部分:模板文字,扩展运算符和生成器!
  9. 超详细windows安装mongo数据库、注册为服务并添加环境变量
  10. Day-17: 网络编程