V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  fghzpqm  ›  全部回复第 2 页 / 共 3 页
回复总数  51
1  2  3  
2014-12-26 15:10:07 +08:00
回复了 ryanking8215 创建的主题 Python ctypes 的问题
@ryanking8215 感觉你在找 Construct 这样的东西。http://construct.readthedocs.org/en/latest/
2014-12-19 00:59:33 +08:00
回复了 Livid 创建的主题 云计算 httpbin
2014-12-04 16:39:56 +08:00
回复了 Livid 创建的主题 V2EX 关于目前 V2EX 的自动标签功能
@Fedor
@takatost

V2EX 给我们演示站点带来了很大的压力,的确第一次有这么多人关注我们 :)非常感谢 @Livid

我们大部分的工作重心都是在核心引擎上面,演示网站只投入了很少的资源,可用性方面给大家带来困扰非常抱歉,我们会尽快修复。
2014-12-04 16:28:12 +08:00
回复了 Livid 创建的主题 V2EX 关于目前 V2EX 的自动标签功能
@WildCat 可以直接联系商务: http://bosonnlp.com/about#contact
2014-12-03 15:09:40 +08:00
回复了 dbas 创建的主题 Python python 时间处理问题
我来用正确的方式喂一下「伸手党」:

https://github.com/crsmithdev/arrow

In [1]: import arrow

In [2]: arrow.get('2014-12-02T04:13:11.993453')
Out[2]: <Arrow [2014-12-02T04:13:11.993453+00:00]>

In [3]: _.to('Asia/Shanghai')
Out[3]: <Arrow [2014-12-02T12:13:11.993453+08:00]>

In [4]: _.format('YYYY-MM-DD HH:mm:ss')
Out[4]: '2014-12-02 12:13:11'
2014-11-21 00:28:17 +08:00
回复了 Gestalt 创建的主题 酷工作 讲讲做 NLP 的某 team,顺带招些人
@s51431980 谢谢支持。目前已修复。

[email protected]_processor
+def inject_copyright_year():
+ return dict(copyright_year=arrow.now('Asia/Shanghai').format('YYYY'))
2014-11-20 10:09:10 +08:00
回复了 Gestalt 创建的主题 酷工作 讲讲做 NLP 的某 team,顺带招些人
我在这里写 Python,欢迎大家过来一起愉快的玩耍。
Node 的情况不清楚,Python 的 XlsxWriter 相当好用:

https://github.com/jmcnamara/XlsxWriter

与主题无关的一点是,建议使用 .xlsx 的格式,.xls 可能是由于封闭格式的原因,除非使用 COM 直接呼叫 Excel,自定义背景这个需求就难办到。
2014-10-30 23:37:25 +08:00
回复了 yakczh 创建的主题 Python 让 python3 下面的写的程序,能运行在 python2.7 上
@yakczh 看输出的异常信息:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-7: ordinal not in range(128)

是在 print 的时候将 unicode 用默认的 ASCII codec 编码(encode)的时候出错。和你直接:

print u"你好"

抛出的是同样的异常。

也就是说,为了确保你 print 的 unicode 不抛异常,你需要显示的把 unicode 编码成你终端使用的文本编码。
2014-10-30 23:26:09 +08:00
回复了 xgfan 创建的主题 Python 头痛的 python 编码问题
@xgfan 你完整的复制这个代码试试,虽然我没有 Windows 机器,但是不应该出问题:

import requests
resp = requests.post('http://www.baidu.com/')
resp.encoding = 'utf-8'
print(resp.text.encode('gbk', 'ignore'))
2014-10-29 17:35:38 +08:00
回复了 yakczh 创建的主题 Python 让 python3 下面的写的程序,能运行在 python2.7 上
Python 2:

$ ipython
Python 2.7.8 (default, Aug 20 2014, 12:09:53)

In [1]: import codecs

In [2]: print codecs.open('GBK', encoding='gbk').read()
你好

Python 3:

$ ipython
Python 3.4.2 (default, Oct 29 2014, 17:32:14)

In [1]: import codecs

In [2]: print(codecs.open('GBK', encoding='gbk').read())
你好
2014-10-29 17:20:26 +08:00
回复了 xgfan 创建的主题 Python 头痛的 python 编码问题
好吧,吐槽别人发现自己也错了。

原来楼主发起的是 POST 请求,会被重定向到另外一个页面,那个页面没有在 Content-Type header 里返回编码信息:

$ curl -sI http://www.baidu.com/search/error.html | grep 'Content-Type'
Content-Type: text/html

这种时候 requests 使用 ISO-8859-1 作为默认编码。

http://docs.python-requests.org/en/latest/user/advanced/#encodings

.text 属性在弄错编码的情况下当然是错误的,我们需要显示的指定一下编码,下面才是正确的程序:

import requests
resp = requests.post('http://www.baidu.com/')
resp.encoding = 'utf-8'
print(resp.text.encode('gbk', 'ignore'))
2014-10-29 17:03:52 +08:00
回复了 xgfan 创建的主题 Python 头痛的 python 编码问题
还好已经是用的 Python 3 了,否则会有一大堆人让你赶紧换 Python 3。

好像不用 Windows 的各位没遇到过编码问题一样,遇到问题难道不应该弄明白原因,为什么看到这么多人莫名其妙的一会儿怪罪 Windows,一会儿怪罪 Python 2!

这个问题的根本原因是 HTML 页面里的 '\xa1' 这个字符是在中文 Windows 终端默认编码 GBK 之外,所以 print 的时候将 .text(type 是 unicode)编码成 GBK 出错。

楼主可以试试下面的代码:

import requests
resp = requests.post('http://www.baidu.com/')
print(resp.encoding)
print(resp.text.encode('gbk', 'ignore'))
2014-10-23 11:07:13 +08:00
回复了 Tink 创建的主题 iOS 是我火星了吗?关于 iOS 自带备忘录
MIUI 的「黄页」充话费、打车、查快递、发快递无所不能。

「便签」的确还不能识别快递号。
2014-10-09 09:49:04 +08:00
回复了 heiher 创建的主题 奇思妙想 DNS 污染防御:转发 DNS 查询为 TCP 传输
很久以前我也用 golang 写过一个。

https://gist.github.com/mrluanma/3722792

安装:

go get gist.github.com/37227.git

使用:

```
$ go-dnsproxy -h
Usage of go-dnsproxy:
-local=":53": local listen address
-quiet=false: suppress output
-remote="8.8.4.4:53": remote dns address
```
2014-09-30 15:30:42 +08:00
回复了 wangleineo 创建的主题 问与答 怎样优雅解决 python 解析 xml gb2312 编码的问题?
2014-09-30 15:18:33 +08:00
回复了 wangleineo 创建的主题 问与答 怎样优雅解决 python 解析 xml gb2312 编码的问题?
所有 Python 问题都可以用 «换 Python 3» 解决?

$ ipython
Python 3.4.1 (default, Aug 20 2014, 12:12:32)
Type "copyright", "credits" or "license" for more information.

In [1]: import xml.etree.ElementTree as ET

In [2]: ET.parse('test.xml')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-df5d74dfe4aa> in <module>()
----> 1 ET.parse('test.xml')

/Users/fghzpqm/.pyenv/versions/3.4.1/lib/python3.4/xml/etree/ElementTree.py in parse(source, parser)
1185 """
1186 tree = ElementTree()
-> 1187 tree.parse(source, parser)
1188 return tree
1189

/Users/fghzpqm/.pyenv/versions/3.4.1/lib/python3.4/xml/etree/ElementTree.py in parse(self, source, parser)
596 # It can be used to parse the whole source without feeding
597 # it with chunks.
--> 598 self._root = parser._parse_whole(source)
599 return self._root
600 while True:

ValueError: multi-byte encodings are not supported
1  2  3  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5528 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 28ms · UTC 08:14 · PVG 16:14 · LAX 01:14 · JFK 04:14
Developed with CodeLauncher
♥ Do have faith in what you're doing.