python文件头--文件编码指定

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.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/403196.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

axios上传文件;el-upload上传图片和post接口上传file文件;前端给后端接口上传file文件。通过formData给接口传递file文件

本文使用element-ui的el-upload图片上传功能。上传链接 接口参数&#xff1a; <el-uploadaction"https://jsonplaceholder.typicode.com/posts/"list-type"picture-card":on-success"handleAvatarSuccess":on-preview"handlePictureCar…

硬件通讯协议的数据传输方式

硬件协议数据传输的包含要素主要为&#xff1a;物理介质&#xff0c;编码方式&#xff0c;通讯协议&#xff0c;传输特点。 下面就对常见的硬件通讯协议进行简单总结。 1. UART LSB First 2. USB LSB First&#xff0c;小端传输 3. SPI MSB First 4. IIC MSB First 5. 网络 大…

2、Eternal框架-svn_有更新!

2019独角兽企业重金招聘Python工程师标准>>> 我在code.google.com上建立了eternal项目。 下载地址为&#xff1a;http://code.google.com/p/eternal-mvc/downloads/list 包含了示例war包和源代码。 转载于:https://my.oschina.net/eternal/blog/100233

redis memcache 性能比较

From: http://blog.51yip.com/cache/1318.html redis和memcache非常像的&#xff0c;都是key,value的方式&#xff0c;将数据存放内存中。最近在学习redis&#xff0c;在网上看了一些这方面的资料&#xff0c;有三种观点&#xff1a; 1,redis读写内存比memcache快 2,memcache读…

SQL性能优化案例分析

这段时间做一个SQL性能优化的案例分析&#xff0c; 整理了一下过往的案例&#xff0c;发现一个比较有意思的&#xff0c;拿出来给大家分享。 这个项目是我在项目开展2期的时候才加入的&#xff0c; 之前一期是个金融内部信息门户&#xff0c; 里面有个功能是收集各个上市公司的…

前端下载图片、pdf、excel、world文件;前端下载图片和pdf文件;前端a标签下载图片和pdf文件;下载文件名称不生效原因。

参考文章1 参考文章2 以下的下载是&#xff0c;拿到了后端给的下载图片的接口地址url > 方法1&#xff1a;将文本或者JS字符串通过 Blob 转换成二进制下载 优点&#xff1a;可以下载&#xff0c;也可以保存名称。 //文件流参数和图片名称 function downloadTxt(str, filenam…

JavaBean规范

&#xff08;1&#xff09;JavaBean 类必须是一个公共类&#xff0c;并将其访问属性设置为 public &#xff0c;如&#xff1a; public class user{......}&#xff08;2&#xff09;JavaBean 类必须有一个空的构造函数&#xff1a;类中必须有一个不带参数的公用构造器 &#…

USB 设备类代码表

USB Class Codes 官方地址&#xff1a;http://www.usb.org/developers/defined_classUSB defines class code information that is used to identify a device’s functionality and to nominally load a device driver based on that functionality. The information is conta…

Redis安装和使用指南

From: http://mwt198668.blog.163.com/blog/static/48803692201132141755962/ Redis安装指南 作者&#xff1a;Red_Ant 时间&#xff1a;2011-04-20 简 介 redis是一个key-value存储系统。和Memcached类似&#xff0c;它支持存储的value类型相对更多&#xff0c;包括string…

员工打卡课后小项目

public class Fm{//员工类public string Id { get; set; }public string Name { get; set; }public int Age { get; set; }public string Gender { get; set; }} public class SI{//打卡类public string Name { get; set; }public DateTime Begin { get; set; }public DateTime…

通过后端接口,预览文件流图片;预览和下载文件流

后端接口返回的是文件流 1.如果是pdf等文件&#xff0c;通过iframe结合文件流&#xff0c;做到文件的下载和预览 // 预览文件openPdf1 () {// 后端下载文件流的地址接口let url G_CGI_PHP.group.documentDownload ?id this.paymentImage1const newWindow window.open()ne…

SAP里删除trace文件的方法

1. stat.DAT&#xff1a;性能统计文件。 这个统计文件增长很快&#xff0c;不小心就涨到900MB以上。 对应的OS路径: D:\usr\sap\DEV\DVEBMGS00\data 处理方法: ST03N -> Expert mode -> Collector and Perfromance DB ->Statistics Records & File -> D…

HID设备类详解

HID设备类 Base Class 03h (HID – Human Interface Device) This base class is defined for devices that conform to the HID Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. V…

DatePicker动态设置picker-options 中的disabledDate属性操作;

一、场景&#xff1a; 有两个时间选择器A和B。A的时间任意选&#xff0c;B的时间必须选择A之后的时间。此时就需要给B设置可选时间区间&#xff0c;而且是动态的值&#xff0c;既动态设置picker-options 中的disabledDate。 二、代码片段 html&#xff1a; <el-col :span&…

Linux使用笔记: 设置Samba服务器中新建文件/目录的权限

From: http://easwy.com/blog/archives/set-file-directory-attribute-for-linux-samba/ 通过Samba服务器实现windows和Linux之间的文件共享&#xff0c;相信是绝大多数人的选择。通常我们都会使用Samba的缺省配置&#xff0c;这样&#xff0c;每次通过Samba从Windows向Linux中…

[转]序列化悍将Protobuf-Net,入门动手实录

最近在研究web api 2&#xff0c;看了一篇文章&#xff0c;讲解如何提升性能的&#xff0c; 在序列化速度的跑分中&#xff0c;Protobuf一骑绝尘&#xff0c;序列化速度快&#xff0c;性能强&#xff0c;体积小&#xff0c;所以打算了解下这个利器 1&#xff1a;安装篇 谷歌官方…

单线程写多线程读安全的结构体

大型网络游戏服务器的逻辑大多采用单线程设计&#xff0c;典型的就是一个线程处理一个区域(地图),跨区域通过跳转实现&#xff0c;这样&#xff0c;不同区域的对象在逻辑上是不发生交互的。 这样在一台服务器上开启N个线程就可以处理N个区域。但一个线程处理一个区域毕竟有其瓶…

Linux 内核打印级别

printk的打印级别 #define KERN_EMERG "<0>" /* system is unusable */ #define KERN_ALERT "<1>" /* action must be taken immediately */ #define KERN_CRIT "<2>" /* critical conditions */ #define KERN_ERR "…

时间戳转日期;日期转时间戳;

一、 拓展:如何用js将日期转换成时间戳 new Date(2022-06-01).getTime() //1654041600000 //这个safari无法将时分秒转时间戳// 推荐用这个&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&…

swoole之代码热更新实现

From: http://www.th7.cn/Program/php/201405/211057.shtml 持续的思考: 本人参与的swoole项目有幸被很多朋友使用&#xff0c;我也大力向周边的一些朋友推荐&#xff0c;随着swoole的版本迭代更新&#xff0c;已经足够稳定了&#xff0c;在阿里&#xff0c;腾讯&#xff0c;yy…