使用wxPyton和dictionaries的默认值和配置文件类 [英] Default Values and Config File Class using wxPyton and dictionaries

查看:46
本文介绍了使用wxPyton和dictionaries的默认值和配置文件类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于那些从未使用过* listofargs和** dictofargs语法的人来说,这里是后者。通过使用** kwargs,将任何大小的字典作为dict(a = 1,b = 2)发送到函数中。在函数内部,它只是一个名为kwargs的字典(或者是whaterver,但这是传统的)。对我来说真正令人惊奇的是,我能够用如此少的界面写入Windows注册表!

For those of you who have never used the *listofargs and **dictofargs syntax, here is a look at the latter. By using **kwargs, a dictionary of any size is sent into the fuction as dict(a=1, b=2). Inside the function, it''s just a dictionary named kwargs (or whaterver, but this is conventional). The truly amazing thing to me is that I am able to write to the Windows registry with so little interface!

展开 | < span class =codeLinkonclick =selectAll(this);>选择 | 换行 | 行号

推荐答案

好吧,我最初的想法有点复杂,但并不多。

这里是最终版本。 GetVariables()使用list comprehension和list comprehension。返回词典列表。理解是漂亮的小列表构建器,如果你的循环中没有很多东西,就会避免list.append()调用。但是,有时会调用带append()的循环。生成器看起来很像是理解,但实际上并没有将内容列入内存,直到你分配它为止:

a,b =(i for i in range(2))

也非常方便。

Ok- it was a little more complicated that I initially thought, but not much.
Here''s the final version. GetVariables() uses a "list comprehension" to return a list of dictionaries. comprehensions are nifty little list builders which avoid list.append() calls if you don''t have lots of stuff going on in your loop. Sometimes, loops with append() are called for, however. Generators look a lot like comprehensions but don''t actually make the list in memory until you assign it something ie:
a, b = (i for i in range(2))
also very handy.

展开 | 选择 | Wrap | 行号


Good AM Barton!感谢您分享此代码。它结构合理,经过深思熟虑。我有一个问题。以下方法及其参数定义在何处/如何定义?
Good AM Barton! Thanks for sharing this code. It looks nicely structured and well thought out. I have one question though. Where/how is the below method and its argument defined?
展开 | 选择 | Wrap | 行号



Good AM Barton!感谢您分享此代码。它结构合理,经过深思熟虑。我有一个问题。以下方法及其参数定义在何处/如何定义?
Good AM Barton! Thanks for sharing this code. It looks nicely structured and well thought out. I have one question though. Where/how is the below method and its argument defined?
展开 | 选择 | Wrap | 行号


这篇关于使用wxPyton和dictionaries的默认值和配置文件类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆