python List和String 转换注意

不能用str(list),
t=[‘\x87\xe9\xa5\xb0\xef\xbc‘]
In [28]: str(t)
Out[28]: "[‘\\x87\\xe9\\xa5\\xb0\\xef\\xbc‘]"

要用‘’.join(list)

In [29]: ‘‘.join(t)
Out[29]: ‘\x87\xe9\xa5\xb0\xef\xbc‘

时间: 2024-08-11 07:42:10

python List和String 转换注意的相关文章

[Python]Bytes 和 String转换

#----string to bytes------ # 方法一:直接复制bytes类型 b'<str>' b = b'Hello World' print(type(b)) print(b) # 方法二:转换 s = 'Hello World' b = bytes(s,encoding='utf-8') print(type(b)) print(b) #----bytes to string------ s = str(b,encoding='utf-8') print(type(s)) p

python 时间戳 datetime string 转换

import datetime import time **datetime转时间戳** In [1]: now = datetime.datetime.now() In [2]: time.mktime(now.timetuple()) Out[2]: 1433501775.0 **datetime转string** In [3]: now.strftime('%Y-%m-%d') Out[3]: '2015-06-05' In [4]: type(now.strftime('%Y-%m-%d

Python使用eval强制转换字符串为字典时报错:File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt; NameError: name &#39;nan&#39; is not defined

文本中保存的内容为: { 'QQQ': [0.067, 0.167, 0.2, 0.033, 0.233, 0.267, 0.1, 0.133], 'TTT': [0.5, 0.375, 0.25, 0.3, 0.6, 0.333, 0.857, 0.636, 0.667, 0.556] } 用eval转换为字符串时报错: File "test.py", line 43, in d1 data = eval(infile.readline()) File "<strin

Python 字符串和list转换

因为python的read和write方法的操作对象都是string.而操作二进制的时候会把string转换成list进行解析,解析后重新写入文件的时候,还得转换成string. >>> import string >>> str = 'abcde' >>> list = list(str) >>> list ['a', 'b', 'c', 'd', 'e'] >>> str 'abcde' >>>

python如何将字符串转换成json的几种办法

python如何将字符串转换成json的几种办法 最近在工作中遇到了一个小问题,如果要将字符串型的数据转换成dict类型,我第一时间就想到了使用json函数.但是里面出现了一些问题 1.通过json来转换: In [1]: import json In [2]: mes = '{"InsId": 2, "name": "lege-happy", "CreationTime": "2019-04-23T03:18:02

python unicode和string byte

python unicode 和string那?? 开发过程中总是会碰到string, unicode, ASCII, 中文字符等编码的问题, 每次碰到都要现搜, 很是浪费时间, 于是这次狠下心, 一定要搞清楚python 的string和Unicode到底怎么回事. 基础知识 我们都知道计算机只认0和1, 要想在计算机显示26个字母, 就要给他们一套映射规则: 计算机能认得的符号 --> 人类可读的符号. 这转换的过程就是一套编码规则. 字符集: 就是一套字符的集合(比如中文4000个汉字集合

python将下载地址转换成迅雷和qq旋风的下载地址

迅雷和qq旋风下载,有加速和离线功能,很方面,我是在网上看到的原始地址和迅雷地址,qq旋风地址的转化原理,然后用python+pyqt写了一个客户端 原理: 迅雷: 迅雷下载地址="thunder://"+Base64编码("AA"+"真实地址"+"ZZ") QQ旋风: qqdl="qqdl://"+Base64编码("真实地址") import re import base64 fro

c/c++日期时间处理与字符串string转换

在c/c++实际问题的编程中,我们经常会用到日期与时间的格式,在算法运行中,通常将时间转化为int来进行计算,而处理输入输出的时候,日期时间的格式却是五花八门,以各种标点空格相连或者不加标点. 首先,在c中,是有一个标准的日期时间结构体的,在标准库wchar.h内,我们可以看到结构体tm的声明如下: 1 #ifndef _TM_DEFINED 2 struct tm { 3 int tm_sec; /* seconds after the minute - [0,59] */ 4 int tm_

byte[] bytes和string转换

public static string ToHexString ( byte[] bytes ) // 0xae00cf => "AE00CF "        {            string hexString = string.Empty;            if ( bytes != null )            {                StringBuilder strB = new StringBuilder ();