\x开头的编码是十六进制字符,\x后面跟的字符即为十六进制的字符串。 In [41]: s1 = "世界如此美妙,我却如此暴躁,这样不好不好" In [42]: s1.encode("utf-8") Out[42]: b'\xe4\xb8\x96\xe7\x95\x8c\xe5\xa6\x82\xe6\xad\xa4\xe7\xbe\x8e\xe5\xa6\x99\xef\xbc\x8c\xe6\x88\x91\xe5\x8d\xb4\xe5\xa6\x82\xe6\xad\xa4\xe6\x9a\xb4\xe8\xba\x81\xef\xbc\x8c\xe8\xbf\x99\xe6\xa0\xb7\xe4\xb8\x8d\xe5\xa5\xbd\xe4\xb8\x8d\xe5\xa5\xbd' 将\x转为中文的几种方式: $ echo -e '\xe4\xb8\x96\xe7\x95\x8c\xe5\xa6\x82\xe6\xad\xa4\xe7\xbe\x8e\xe5\xa6\x99\xef\xbc\x8c\xe6\x88\x91\xe5\x8d\xb4\xe5\xa6\x82\xe6\xad\xa4\xe6\x9a\xb4\xe8\xba\x81\xef\xbc\x8c\xe8\xbf\x99\xe6\xa0\xb7\xe4\xb8\x8d\xe5\xa5\xbd\xe4\xb8\x8d\xe5\xa5\xbd' 世界如此美妙,我却如此暴躁,这样不好不好 REF: https://linuxhint.com/string-to-hexadecimal-in-python/ https://blog.csdn.net/YungGuo/article/details/110197818
今天有个批量下载图片的任务,不打算用python或者其他高级语言实现,决定用bash尝试下。 接下来我们一起了解下bash的并发任务是如何实现的?先上一版简单粗暴的代码: #!/bin/bash todo () { sleep 3;echo "$1OK"; } # --- 串行 for x in `seq 5`;do echo $x; todo $x; done # --- 并行 for x in `seq 5`;do { echo $x; todo $x; }& done wait # 是的,你没看错,并行相较于串行之多了几个符号 `{ }&` 和 `wait`。 # 其中,wait函数,该函数将等待后台所有子进程结束。正是因为有了此函数, # 才能保证commands2在所有commands1并行子任务执
Python string split() method allows a string to be easily split into a list based on a delimiter. Though in some cases, you might need the separation to occur based on not just one but multiple delimiter values. This quick 101 article introduces two convenient approaches this can be achieved in Python.
Split String With Two Delimiters in Python Assume the following string.
text = "python is, an easy;language; to, learn." For our example, we need to split it either by a semicolon followed by a space ;, or by a comma followed by a space ,. In this case, any occurrences of singular semicolons or commas i.e. , , ; with no trailing spaces should not be concerned.
Regular Expressions A delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data streams. An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values.
Use Basic Expression Python’s built-in module re has a split() method we can use for this case.
Let’s use a basic a or b regular expression (a|b) for separating our multiple delimiters.
import re text = "python is, an easy;language; to, learn." print(re.split('; |, ', text)) Output:
['python is', 'an easy;language', 'to', 'learn.'] As mentioned on the Wikipedia page, Regular Expressions use IEEE POSIX as the standard for its syntax.