python dict赋值时有逗号自动变成元组

webpack 查找n.m时用的加载器是页面上调用的,因为赋值了s等于加载器 s('8536') s.m['8536']

bash 复制代码
`headers['Cookie'] = f'_m_h5_tk={cookie_list[0]}; _m_h5_tk_enc={cookie_list[1]}'`

{'accept': '*/*', 'accept-language': 'zh-CN,zh;q=0.9', 'cache-control': 'no-cache', 'pragma': 'no-cache', 'Cookie': '_m_h5_tk=6c0d566bb411af218ae8ae951f798a3f_1715316103021; _m_h5_tk_enc=7a5b741c5cda5a0a5577be606913612b', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', 'Referer': 'https://factory.1688.com/'}

headers['Cookie'] = f'_m_h5_tk={cookie_list[0]}; _m_h5_tk_enc={cookie_list[1]}',

{'accept': '*/*', 'accept-language': 'zh-CN,zh;q=0.9', 'cache-control': 'no-cache', 'pragma': 'no-cache', 'Cookie': ('_m_h5_tk=590d422504684efef6c30e047df7ff75_1715319173019; _m_h5_tk_enc=785e9c5e8f85accf2c2f6ac4b0e4412e',), 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', 'Referer': 'https://factory.1688.com/'}

在反斜杠后链接一些字符可以表示某种类型的一个字符。

  • \d匹配0-9之间任意一个数字字符,等价于表达式:[0-9]

  • \D匹配任意一个不是0-9之间的数字字符,等价于表达式: [^0-9]

  • \s匹配任意一个空白字符,包括空格、tab、换行符等,等价于表达式:[\t\n\r\f\v]

  • \S匹配任意一个非空白字符,等价于表达式:[^\t\n\r\f\v]

  • \w匹配任意一个文字字符,包括大小写字母、数字、下划线,等价于表达式:[a-zA-Z0-9_]

  • \W匹配任意一个非文字字符,等价于表达式:[^a-zA-Z0-9_]

反斜杠也可以用在方括号里面,比如[\s,.]表示匹配 : 任何空白字符, 或者逗号,或者点

匹配元字符 . {} ()

bash 复制代码
content = '''
苹果.是绿色的
橙子.是橙色的
香蕉.是黄色的
'''

for temp in re.findall(r'.*[.]', content):
    print(temp)
for temp in re.findall(r'.*\.', content):
    print(temp)

正则模式

bash 复制代码
修饰符	描述	实例
re.IGNORECASE 或 re.I	使匹配对大小写不敏感	
import re
pattern = re.compile(r'apple', re.I)
result = pattern.match('Apple')
print(result.group())  # 输出: 'Apple'


re.MULTILINE 或 re.M	多行匹配,影响 ^ 和 $,使它们匹配字符串的每一行的开头和结尾。	
import re
pattern = re.compile(r'^\d+', re.M)
text = '123\n456\n789'
result = pattern.findall(text)
print(result)  # 输出: ['123', '456', '789']


re.DOTALL 或 re.S:	使 . 匹配包括换行符在内的任意字符。	
import re
pattern = re.compile(r'a.b', re.S)
result = pattern.match('a\nb')
print(result.group())  # 输出: 'a\nb'


re.ASCII	使 \w, \W, \b, \B, \d, \D, \s, \S 仅匹配 ASCII 字符。	
import re
pattern = re.compile(r'\w+', flags=re.ASCII)
result = pattern.match('Hello123')
print(result.group())  # 输出: 'Hello123'


re.VERBOSE 或 re.X	忽略空格和注释,可以更清晰地组织复杂的正则表达式。	
import re
pattern = re.compile(r'''
    \d+  # 匹配数字
    [a-z]+  # 匹配小写字母
''', flags=re.X)
result = pattern.match('123abc')
print(result.group())  # 输出: '123abc'
相关推荐
明月_清风5 小时前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风5 小时前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python
Flittly20 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(3)TodoWrite (待办写入)
python·agent
千寻girling1 天前
一份不可多得的 《 Django 》 零基础入门教程
后端·python·面试
databook1 天前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
明月_清风1 天前
Python 性能微观世界:列表推导式 vs for 循环
后端·python
明月_清风1 天前
Python 性能翻身仗:从 O(n) 到 O(1) 的工程实践
后端·python
helloweilei2 天前
python 抽象基类
python
用户8356290780512 天前
Python 实现 PPT 转 HTML
后端·python
zone77392 天前
004:RAG 入门-LangChain读取PDF
后端·python·面试