Python 2.x字符串:Unicode与字节

时间:2015-12-31 13:05:09

标签: python string unicode character-encoding

我处理非我们的语言,有时仍然需要用Python 2.x编写。阅读本文:Brett Cannon的http://www.snarky.ca/why-python-3-exists让我想知道如果这意味着如果我使用的字符串只是字符而不是字节,我应该在 <a href="javascript:void(0);" onclick="users.displayInfo(<?php echo $user['user_id']; ?>);"> <i class="icon-pencil glyphicon glyphicon-pencil"></i> <?php echo ASLang::get('details'); ?> </a> <div class="modal" id="modal-user-details" style="display: none;"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <h4 class="modal-title" id="modal-username"> <?php echo ASLang::get('loading'); ?> </h4> </div> <div class="modal-body" id="details-body"> <dl class="dl-horizontal"> <dt title="<?php echo ASLang::get('email'); ?>"><?php echo ASLang::get('email'); ?></dt> <dd id="modal-email"></dd> <dt title="<?php echo ASLang::get('first_name'); ?>"><?php echo ASLang::get('first_name'); ?></dt> <dd id="modal-first-name"></dd> <dt title="<?php echo ASLang::get('last_name'); ?>"><?php echo ASLang::get('last_name'); ?></dt> <dd id="modal-last-name"></dd> <dt title="<?php echo ASLang::get('address'); ?>"><?php echo ASLang::get('address'); ?></dt> <dd id="modal-address"></dd> <dt title="<?php echo ASLang::get('age'); ?>"><?php echo ASLang::get('age'); ?></dt> <dd id="modal-age"></dd> <dt title="<?php echo ASLang::get('phone'); ?>"><?php echo ASLang::get('phone'); ?></dt> <dd id="modal-phone"></dd> <dt title="<?php echo ASLang::get('last_login'); ?>"><?php echo ASLang::get('last_login'); ?></dt> <dd id="modal-last-login"></dd> </dl> </div> <div align="center" id="ajax-loading"><img src="assets/img/ajax_loader.gif" /></div> <div class="modal-footer"> <a href="javascript:void(0);" class="btn btn-primary" data-dismiss="modal" aria-hidden="true"> <?php echo ASLang::get('ok'); ?> </a> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal --> 之前添加所有字符串,以避免混淆在字节串和unicode字符串之间?并且:这也适用于Jython吗?

最后一个问题:u完全不依赖于上述内容,仅提供文件本身的编码 - 正确吗?

1 个答案:

答案 0 :(得分:5)

是的,您希望将文本保留在<style type "text/css"> <!-- /* @group Blink */ .blink { -webkit-animation: blink .75s linear infinite; -moz-animation: blink .75s linear infinite; -ms-animation: blink .75s linear infinite; -o-animation: blink .75s linear infinite; animation: blink .75s linear infinite; } @-webkit-keyframes blink { 0% { opacity: 1; } 50% { opacity: 1; } 50.01% { opacity: 0; } 100% { opacity: 0; } } @-moz-keyframes blink { 0% { opacity: 1; } 50% { opacity: 1; } 50.01% { opacity: 0; } 100% { opacity: 0; } } @-ms-keyframes blink { 0% { opacity: 1; } 50% { opacity: 1; } 50.01% { opacity: 0; } 100% { opacity: 0; } } @-o-keyframes blink { 0% { opacity: 1; } 50% { opacity: 1; } 50.01% { opacity: 0; } 100% { opacity: 0; } } @keyframes blink { 0% { opacity: 1; } 50% { opacity: 1; } 50.01% { opacity: 0; } 100% { opacity: 0; } } /* @end */ --> </style> <p style="font-family:Courier; color:white; font-size: 20px; background-color: #660E0E"><p class="tab blink">This is an example of blinking text using CSS.</p> 个对象(Python 3中的unicode类型)中,并保持Unicode三明治(尽快解码传入数据,推迟编码直到数据需要退出你的申请)。请参阅Ned Batchelder's excellent Unicode presentation

这也适用于Jython,它只是Python语言的另一种实现。

PEP 263 source code encoding declaration告诉解释器在解码源代码中的字节时要使用的编解码器。它在使用非ASCII字节定义Unicode文字时有帮助,但没有规定除源代码之外的其他数据是如何编码或解码的。