V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  timonwong  ›  全部回复第 9 页 / 共 25 页
回复总数  491
1 ... 5  6  7  8  9  10  11  12  13  14 ... 25  
2015-01-01 13:37:14 +08:00
回复了 yakczh 创建的主题 问与答 sqlalchemy 能通过 dict 添加纪录吗?
2015-01-01 13:36:21 +08:00
回复了 yakczh 创建的主题 问与答 sqlalchemy 能通过 dict 添加纪录吗?
http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#create-an-instance-of-the-mapped-class
如果你没有自定义 __init__ 方法,那么SQLAlchemy已经提供了一个keyword arguments的调用方法,你的代码就只需要:
Article(**data) 就可以了

但是如果你自定义了__init__ 就不行了,要写个包装函数,比如from_dict

PS, 这个是默认 __init__ 的实现:

```
def _declarative_constructor(self, **kwargs):
"""A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and
values in ``kwargs``.

Only keys that are present as
attributes of the instance's class are allowed. These could be,
for example, any mapped columns or relationships.
"""
cls_ = type(self)
for k in kwargs:
if not hasattr(cls_, k):
raise TypeError(
"%r is an invalid keyword argument for %s" %
(k, cls_.__name__))
setattr(self, k, kwargs[k])
_declarative_constructor.__name__ = '__init__'
```
2014-12-26 17:55:38 +08:00
回复了 moxuanyuan 创建的主题 问与答 如何解决 Sublime Text 3 无法打开文件名有空格的文件?
关联有问题而已,不知道你怎么弄的,参数请包裹 double quotes
2014-12-25 15:04:32 +08:00
回复了 ryanking8215 创建的主题 Python ctypes 的问题
因为 ctypes.Structure 类型是可以转换为 "buffer" 类型的

然后 file 类型支持写入 "buffer" 类型,因此可行。
fileobject.write(str or buffer)

bytes(buffer(t))
2014-12-19 11:40:41 +08:00
回复了 xdeng 创建的主题 问与答 这是什么写法谁知道的? C++的
2014-12-17 17:16:56 +08:00
回复了 hack2012 创建的主题 Python 如何替换 url 中的参数值?
@hack2012
完整的我已经给了
2014-12-17 10:54:13 +08:00
回复了 hack2012 创建的主题 Python 如何替换 url 中的参数值?
bits = list(urlparse.urlparse(url))
qs = urlparse.parse_qs(bits[4]) # 注意value是一个list
# 修改qs,略
bits[4] = urllib.urlencode(qs, True)
url = urlparse.urlunparse(bits)
2014-12-04 15:21:16 +08:00
回复了 yeelone 创建的主题 Vagrant vagrant 上搭建的开发环境怎么又不见了?
注意$HOME,如果是在Win下,cygwin, msys, cmd,环境不同,装的位置不一样
2014-11-29 16:44:23 +08:00
回复了 foomorrow 创建的主题 前端开发 技术讨论:你喜欢哪种模板引擎
Razor
2014-11-28 23:09:54 +08:00
回复了 abccba 创建的主题 Python 突然之间,很多 python 程序都出现了相同的错误
2014-11-28 23:06:18 +08:00
回复了 abccba 创建的主题 Python 突然之间,很多 python 程序都出现了相同的错误
你说对了,这些错误提示和帮助信息,还真是pygments (pygmentize命令)
2014-10-30 22:37:37 +08:00
回复了 Yiner 创建的主题 问与答 docs.python-requests.org 访问不了了
检查一下DNS吧
看看 readthedocs.org 之类的能不能解析
2014-10-24 09:09:48 +08:00
回复了 dbow 创建的主题 Python windows 下 python 文件编码的问题
the 'b' is ignored on all POSIX conforming systems, including Linux. (Other systems may treat text files and binary files differently, and adding the 'b' may be a good idea if you do I/O to a binary file and expect that your program may be ported to non-UNIX environments.)

习惯Linux的也需要看看man吧
2014-10-21 14:01:31 +08:00
回复了 curiousjude 创建的主题 问与答 大家在什么情况下会用拼音命名变量什么的?
这不是没有先例,不过成功案例一般是日文,中文的文化影响力不够强,拼音也不酷,被喷也正常。

dojo
emoji
go
2014-10-21 11:50:12 +08:00
回复了 spencerqiu 创建的主题 问与答 C 艹 字符串问题求解
方法很多种

vector<string> words{istream_iterator<string>{istringstream(s)},
istream_iterator<string>{}};

reverse_copy(words.begin(), words.end(), ostream_iterator<string>(cout, " "));
@Azone
嗯,你是对的,0~10FFFF 已包含目前全部定义的 code point
@larkifly
你确定是 f6b6 而不是 1f6b6?
@Azone
就目前的Unicode范围来说,是1-6字节

unicode codepoint range: 0x00000000 ~ 0x7FFFFFFF
2014-10-14 10:45:05 +08:00
回复了 vivalon 创建的主题 Python 一个关于 Python 2/3 中 Unicode 及常见问题的介绍
* unique number (code point) for each character of every language
注意 Unicode code point 和 character 并不是一一对应关系

http://www.unicode.org/faq/char_combmark.html#7
2014-10-07 08:39:11 +08:00
回复了 WildCat 创建的主题 Swift Swift 中如何使用 UnsafePointer(方法传参)
@WildCat
func takesAMutablePointer(x: UnsafeMutablePointer<Float>) { /*...*/ }
var x: Float = 0.0
takesAMutablePointer(&x)
1 ... 5  6  7  8  9  10  11  12  13  14 ... 25  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2632 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 27ms · UTC 14:03 · PVG 22:03 · LAX 07:03 · JFK 10:03
Developed with CodeLauncher
♥ Do have faith in what you're doing.