V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  chenstack  ›  全部回复第 6 页 / 共 7 页
回复总数  130
1  2  3  4  5  6  7  
2018-04-25 23:07:37 +08:00
回复了 Syaoran 创建的主题 程序员 感觉这几天 vx 小游戏跟病毒似的传播……
最强弹一弹真的毒,几个群都沦陷了
2018-04-25 19:09:14 +08:00
回复了 wsds 创建的主题 Python Python 类中的方法如何多线程调用?
可以把 start 和 join 分开
for t in thread_:
t.setDaemon(True)
t.start()

for t in thread_:
t.join()

另外你一开始那样把 t.join()放在循环外面会出错大概是因为,有些线程设置为守护线程,但主线程退出后那些子线程还未结束。
2018-04-25 16:57:36 +08:00
回复了 wsds 创建的主题 Python Python 类中的方法如何多线程调用?
把 t.join()注释后也许是你想要的效果。join 的作用是保证当前线程执行完成后,再执行其它线程。
回复图片直接贴网址就行
2018-04-25 11:56:44 +08:00
回复了 wsds 创建的主题 Python Python 类中的方法如何多线程调用?
2018-04-24 23:08:46 +08:00
回复了 Exceptionluo 创建的主题 JavaScript 对执行结果无法理解 ,求助~
不太理解所说的 style:{}挂载到 My 上面,第一次循环相当于 My.dom = {}; current = My.dom; 第二次循环相当于 My.dom.style = {};
2018-04-17 13:30:20 +08:00
回复了 assad 创建的主题 程序员 Python3 数字 chr 后拼接成字符串和其他语言有区别?
百科的介绍:Latin1 是 ISO-8859-1 的别名,有些环境下写作 Latin-1。ISO-8859-1 编码是单字节编码,向下兼容 ASCII,其编码范围是 0x00-0xFF。因为 ISO-8859-1 编码范围使用了单字节内的所有空间,在支持 ISO-8859-1 的系统中传输和存储其他任何编码的字节流都不会被抛弃。
所以用 encode('latin-1')时所以字节会原封不动的保留,不会被转换。
2018-04-17 12:16:05 +08:00
回复了 assad 创建的主题 程序员 Python3 数字 chr 后拼接成字符串和其他语言有区别?
要说区别可能是 python3 字符串 encode 成 bytes 后不一样,因为 encode 默认编码是 utf-8,所给的测试代码并不完整。

python3:
from hashlib import md5
items = [119,156,161,138,90,240,56,165,114,4]
strlenth = len(items)

result = ''
i = 0
while i < strlenth:
result += chr(items[i])
i += 1
print(md5(result.encode('latin-1')).hexdigest())


php:
<?php

$items = [119,156,161,138,90,240,56,165,114,4];
$strlenth = count($items);

$i = 0;
$result = '';
while ($i < $strlenth) {
$result .= chr($items[$i]);
$i++;
}
print(md5($result));
?>

结果均为 0e996abf46e4d5acadead68fbf1f877e
@myyou @crb912
本来是讨论 append 和 extend,结果有些人讨论的是+=操作符是不是 extend 了。
+= 会优先看有没有__iadd__方法,对于 list,是有的。在这个情况下 a += b 和 a = a + b 不是等价的。如 xpresslink 所说,
list 的+=和 extend 几乎是等价的,如果还纠结+操作符,不如做个试验
a = [1, 2]
print(id(a))
a += [3]
print(id(a))
a = a + [4]
print(id(a))

对于楼主的问题,如果只有一个元素添加,我选 appand,语义上更符合,而且没有创建 list 的开销
2018-03-21 11:44:21 +08:00
回复了 dwjgwsm 创建的主题 问与答 把字符串变成变量的问题
最小复现样例:
def test():
locals()['a'] = 1
print(locals())
print(a)

python3 的文档是这样说的:
locals()
Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks.

Note The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter.

所以 function 中修改 locals()是没有意义的
2018-03-20 17:48:46 +08:00
回复了 Mavious 创建的主题 Python 十六进制编码 str 转汉字的方法?!
python3 的 str 类型内部存的是 unicode, str.encode 默认编码是 utf-8,'\xe6\xb9\x96'.encode()结果并不是 b'\xe6\xb9\x96'

说一下结论,个人认为比较好的方式,使用 latin-1 或 charmap 编码器编码到相同字节的 bytes:
text = '\xe6\xb9\x96\xe5\xb7\x9e\xe6\x96\xb0\xe5\x9f\x8e\xe5\xbb\xba'
print(text.encode('latin-1').decode('utf-8'))

或者手动映射:
print(bytes(map(ord, text)).decode('utf-8'))
2018-03-19 14:51:39 +08:00
回复了 lsdir 创建的主题 游戏 绝地求生。
堡垒之夜了解一下?
2018-02-16 17:45:17 +08:00
回复了 tianxiacangshen 创建的主题 程序员 有没有一种悲剧,是工作成了唯一乐趣?
还喜欢看动漫逛 B 站和逛 V 站
2018-02-15 18:52:30 +08:00
回复了 chenstack 创建的主题 问与答 来求个提示,阿里技术的贺岁彩蛋
@jasonsheh @moult 感谢,解出来了
2018-02-05 21:05:08 +08:00
回复了 GeekDuanLian 创建的主题 Linux 如何批量将英文的双引号替换为中文的前后双引号
给个简单的,例如文件名是 test.txt
sed 's/"\([^"]\{0,\}\)"/“$1 ”/g' -i test.txt
2018-02-01 17:27:48 +08:00
回复了 hfpp2012 创建的主题 程序员 个人录制的 60 集前后端技术视频分享 - 全部免费观看
mark
2018-01-31 14:10:52 +08:00
回复了 tsoingkam 创建的主题 Python 请教下大神关于正则表达式的用法
@Ctry Help on function findall in module re:

findall(pattern, string, flags=0)
Return a list of all non-overlapping matches in the string.

If one or more capturing groups are present in the pattern, return
a list of groups; this will be a list of tuples if the pattern
has more than one group.

Empty matches are included in the result.

结合我在#2 说的,如果想存粹地获取匹配的内容,可以
import re
text = 'ABCDE'
f2 = re.compile('(B|C|D)+')
print([m.group(0) for m in re.finditer(f2, text)])
2018-01-30 19:00:04 +08:00
回复了 tsoingkam 创建的主题 Python 请教下大神关于正则表达式的用法
如果模式有 group,findall 返回的列表中的元素是所有 group 的内容组成的元组,(B|C|D)+的只有一个 group,其匹配内容是字串 BCD 的最后一个部分 D (结合#1 的讲解),比如把模式改为((B|C|D)+),f2.findall(text)的结果则为[('BCD', 'D')]
2018-01-27 22:48:30 +08:00
回复了 piaochen0 创建的主题 Python wxPython,如何自定义列表项?
wxpython 说到底也是 wxWidgets 的绑定,控件都是各平台原生的实现。真要做的话这个估计要用 ScrolledWindow 模拟列表。
2018-01-27 14:23:43 +08:00
回复了 septet 创建的主题 程序员 你们对进制的转换都熟悉吗?
有段时间热衷于 GBA 和 NES 游戏的修改及汉化,经常用到 2 进制和 16 进制,对转换比较敏感。平时转换的话,可以随时调出终端用 python 算,hex, bin 函数很方便
1  2  3  4  5  6  7  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3379 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 29ms · UTC 11:14 · PVG 19:14 · LAX 04:14 · JFK 07:14
Developed with CodeLauncher
♥ Do have faith in what you're doing.