Python学习(2)——编码
今天写了个程序但是在DOS窗口和IDEL窗口调试的结果不一样,有些郁闷~
#!/usr/bin/env python
#coding=utf-8
#python version:2.7.3
#system:windows 7
#http://www.cnblogs.com/evilxr/
evilxr=raw_input("Evilxr:")
screen_width=80
text_width=len(evilxr)
box_width=text_width+2
left_margin=(screen_width - box_width) // 2
print ' ' *left_margin + '+' + '-' * (box_width-2) + '+'
print ' ' *left_margin + '|' + ' ' * text_width + '|'
print ' ' *left_margin + '|' + evilxr + '|'
print ' ' *left_margin + '|' + ' ' * text_width + '|'
print ' ' *left_margin + '+' + '-' * (box_width-2) + '+'
补充:
修改后代码如下,感谢Fooying的帮助:
#!/usr/bin/env python
#coding=utf-8
#python version:2.7.3
#system:windows 7
#http://www.cnblogs.com/evilxr/
evilxr=raw_input("Evilxr:")
try:
evilxr = evilxr.decode('utf-8').encode('gbk')
except UnicodeDecodeError:
pass
screen_width=80
box_width=text_width+2
left_margin=(screen_width - box_width) // 2
print ' ' *left_margin + '+' + '-' * (box_width-2) + '+'
print ' ' *left_margin + '|' + ' ' * text_width + '|'
print ' ' *left_margin + '|' + evilxr + '|'
print ' ' *left_margin + '|' + ' ' * text_width + '|'
print ' ' *left_margin + '+' + '-' * (box_width-2) + '+'
Fooying推荐pep8规范:http://baid.ws/cCBn
Python学习(2)——编码的更多相关文章
- Python学习-字符编码, 数据类型
本篇主要内容: 字符编码 Python中的数据类型有哪些 类型的一些常用操作及方法 一.字符编码 编码解释的大部分内容摘自廖雪峰老师教程中的讲解,点击跳转. 简单介绍: 我们知道计算机只能处理数字,如 ...
- python 学习笔记-----编码问题
1.python 最早支持的是ASCII编码. 所以对于普通的字符串"ABC"为ASCII编码的形式.字母和数字之间的转换函数为ord('字母')和chr(‘数字’)函数. ord ...
- Python学习-字符编码浅析
1.什么是字符编码 既然是简述那肯定是简单明了.字符编码,看名字就是一种字符的编码格式,由于计算机内部采用二进制,想要将人类的语言字符输入到计算机就需要一种编码格式,这就是字符编码.字符------- ...
- Python学习---深入编码学习1225
1.1. Python2 Py2中只有2中数据类型,Str和Unicode,而且str中保存的是bytes,Unicode中保存的是unicode 一切我们能看到的明文都是unicode数据类型, b ...
- Python学习之——编码方式
1.各种编码方式 ASCII:http://zh.wikipedia.org/zh-hans/ASCII Unicode:http://zh.wikipedia.org/zh-hans/Unicode ...
- Python学习之编码
Python2默认解释器的编码:ascii: Python3默认解释器的编码:UTF-8 ascii码:只会识别英文字母.数字和标点.8位表示一个英文字符,1个字节 万国码Uicode:目前的所有语言 ...
- 字符编码——python学习
python学习—字符编码 例如汉字“中” 十进制:20013 二进制:01001110 00101101(unicode)/11100100 10111000 10101101(utf-8) 十六进 ...
- Python学习---Python安装与基础1205
1.0. 安装 1.1.1. 下载 官网下载地址:https://www.python.org/downloads/release/python-352/ 1.1.2. 配置环境变量 因为在安装的时候 ...
- 学习笔记之Python最简编码规范
Python最简编码规范 - 机器学习算法与Python学习 https://mp.weixin.qq.com/s/i6MwvC4jYTE6D1KHFgBeoQ https://www.cnblogs ...
随机推荐
- android 获取activity 的name
String contextString = this.toString();String name = contextString.substring(contextString.lastIndex ...
- SharePoint 2013 配置我的网站 图文引导
博客地址:http://blog.csdn.net/FoxDave 本篇我们来讲述一下关于SharePoint中我的网站(My Sites)相关的东西. 我的网站是SharePoint 2013中面向 ...
- C# Delete Url Cookie
public static void DeleteCookieFile(Uri url) { string path = Environment.GetFolderPath(Environment.S ...
- yeild
正在使用cpu的线程,退出,返回等待池,其他优先级相同的线程竞争上岗.
- 《同一个类中不同方法之间的调用相关问题(省略的类名或者this)》
//同一个类中不同方法之间的调用相关问题(省略的类名或者this) class A { public void B() { System.out.println("b方法运行"); ...
- Javascript ----字符串(String)中的方法
涉及字符串时,常用到的几个方法... --------------------------------------------------------------------------------- ...
- Python入门(三,初级)
一,函数调用 定义一个函数只给了函数一个名称,指定了函数里包含的参数,和代码块结构. 这个函数的基本结构完成以后,你可以通过另一个函数调用执行,也可以直接从Python提示符执行. 如下实例调用了pr ...
- Python行和缩进
Python缩进和冒号 对于Python而言代码缩进是一种语法,Python没有像其他语言一样采用{}或者begin...end分隔代码块,而是采用代码缩进和冒号来区分代码之间的层次. 缩进的空白数量 ...
- ERP权限系统(七)
添加链接权限的字段: //权限管理 n.Target = "MainFrame"; //折叠 TreeView1.Nodes.Add(n); n.Expanded = false;
- Chocolate_DP
Description In 2100, ACM chocolate will be one of the favorite foods in the world. "Green, oran ...