djiango 中unicode 和str 方法转换的问题
来源:互联网 发布:最新ppt制作软件 编辑:程序博客网 时间:2024/06/11 00:40
写django 时候发现,作者为了保证最好的可用性,统一使用了unicode 编码。
使用django 中的模块,它会自动转为合适的类型。
而自己的代码如果直接去调用底层的接口,则可能出现错误。
例如在调用sockets.py这个底层的文件中的create_connection()方法时,传递二个参数,host,port.这两个参数在django中赋值是默认为unicode。而sockets则要求为int 或者 str
from django.utils.encoding import smart_unicodefrom django.utils.encoding import smart_strhost=smart_unicode('192.168.10.1')print type(host)host=smart_str('192.168.10.1')print type(host)
完美解决咯。
阅读全文
0 0
- djiango 中unicode 和str 方法转换的问题
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str和unicode以及编码的问题
- 【python】str,unicode对象的encode和decode方法
- python unicode和str拼接的小问题
- 了解python中bytes,str和unicode的区别
- Python str unicode转换
- str字符和unicode字符的区别
- python 中文 str 以及 unicode区别和互相转换
- cjk和unicode之间的转换问题
- python的str,unicode对象的encode和decode方法(转)
- python2x的str/unicode转换以及python3x中的str/bytes转换
- unicode .decode /str.encode方法
- 动态库的动态链接、打开、调用,使用dlopen、dlsym和dlclose
- React-Native 组件 生命周期
- LeetCode 38. Count and Say
- logrotate linux 系统日志备份压缩工具
- memset函数注意事项
- djiango 中unicode 和str 方法转换的问题
- JAVA虚拟机(JVM)——类加载的时机之类的初始化
- angularJs控制input只能输入数字并且小数点后只能输入两位
- P3518 [POI2011]strongbox
- 3DES加密 java与 C# 可以相互加密解密
- 从匿名聊聊被封停,看微信小程序坚持的线下策略
- Kyoto Cabinet库的编译说明
- BZOJ 4475: [Jsoi2015]子集选取 快速幂
- 118. Pascal's Triangle