Search in list of dictionaries

2009-02-19 Thread Alex Gusarov
 Hello everybody!

I've a list of dictionaries with 'shorcut' and 'command' keys. When user
types a word program must search this list for a typed shortcut and then run
linked command. What I've wrote:

for cmd in self.commands:
if cmd['shortcut'] == input:
os.popen(cmd['command'])
break
else:
os.popen(input)

But it's a brute-force method and I think there is another way in searching
items through a list by dictionary key. Please give me advice how can I
implement fast search in list of dictionaries by some dictionary key. In my
mind language:

list.get({'shortcut' == input})

Thanks a lot, Alex
--
http://mail.python.org/mailman/listinfo/python-list


Re: Search in list of dictionaries

2009-02-19 Thread Alex Gusarov
Thanks! This example is quite simple and works exactly the way I wanted.

On Thu, Feb 19, 2009 at 11:39 PM, MRAB  wrote:

> Alex Gusarov wrote:
>
>> Hello everybody!
>>
>> I've a list of dictionaries with 'shorcut' and 'command' keys. When user
>> types a word program must search this list for a typed shortcut and then run
>> linked command. What I've wrote:
>>
>>for cmd in self.commands:
>>if cmd['shortcut'] == input:
>>os.popen(cmd['command'])
>>break
>>else:
>>os.popen(input)
>>
>> But it's a brute-force method and I think there is another way in
>> searching items through a list by dictionary key. Please give me advice how
>> can I implement fast search in list of dictionaries by some dictionary key.
>> In my mind language:
>>
>> list.get({'shortcut' == input})
>>
>>  If want to go from the shortcut to the command (cmd['shortcut'] ->
> cmd['command']) the quickest way is using a dict, where cmd['shortcut']
> is the key and cmd['command'] is the value:
>
>self.command_dict = {}
>for cmd in self.commands:
>self.command_dict[cmd['shortcut']] = cmd['command']
>
> and then:
>
>os.popen(self.command_dict[input])
>
> This will raise a KeyError if it's unknown. The equivalent of your code
> above is:
>
>os.popen(self.command_dict.get(input, input))
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


How to get all variables of some module in that module

2008-10-20 Thread Alex Gusarov
Hello, I have a following module and in its end I want to initalize
collection of tables:

Module:

from sqlalchemy import *

metadata = MetaData()

calendars_table = Table('calendars', metadata,
Column('id', Integer, primary_key=True),
Column('title', Unicode(50)),
Column('color', Unicode(6)),
)

events_table = Table('events', metadata,
Column('id', Integer, primary_key=True),
Column('calendar', Integer, ForeignKey('calendars.id')),
Column('date', Date),
Column('title', Unicode(50)),
Column('description', Unicode(1000)),
Column('color', Unicode(6)),
)

tables_collection = {}

Here I want to get all Table instances of current module and put them
into dictionary by names, but I don't know how I can get all variables
of current module in the end of this module. Please, give me a hint.

--
Best regards, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to get all variables of some module in that module

2008-10-21 Thread Alex Gusarov
Steven, Peter, thanks a lot from a Python newcomer. Problem solved
with you help.
Still, Python community is best I ever met :)

--
Best regards, Alex
--
http://mail.python.org/mailman/listinfo/python-list


Re: PYQT- How to prevent a dialog being resized in qtdesigner

2008-05-25 Thread Alex Gusarov
There is no simple way to do it. But it seems to be a meaningless - resizing
dialog in Designer is equal to changing its geometry.


On Mon, May 26, 2008 at 9:30 AM, bbmerong <[EMAIL PROTECTED]> wrote:

> I have a question about qtdesigner.
>
> I'd like to know how to prevent a dialog being resized in qtdesigner.
>
> I'll wait for your answer.
>
> Then, Thank you in advance.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: Overloading virtual method of widget without inheriting (PyQt)

2008-05-28 Thread Alex Gusarov
> I have a feeling that the form produced by Qt Designer, once converted to
> code, contains references to QCalendarWidget where you really want to use a
> customized calendar widget. If so, you should "promote" the calendar widget
> in Qt Designer to use your widget instead, and make sure you import the
> module that supplies it in your application.

David, thanks for noticing about "promoting" within designer, it helped me.

> Anyway, IIRC (it's a long time since I used Qt), QT allows to connect
>  more than one slot with the same signal, so you should not need to
> subclass or to create your own multi-dispatcher. Just doing:
>
> calendar.paintCell.signal( SOME_SIGNAL_NAME, my_paint_method )
>
> should work. I don't know which signal you should connect to, however.
>
> This link gives you some detail on signal/slots in PyQT:

Thanks, but actually, paintCell is not a signal, it's simply a virtual
method of caledarwidget.

--
Best regards, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list


Re: Struct usages in Python

2008-05-28 Thread Alex Gusarov
>  class Event(object):
>
> Always subclass object, unless you have a very compelling reason not to,
> or you are subclassing something else.
>

I've thought that if I write

class Event:
pass

, it'll be subclass of object too, I was wrong?

--
Best regards, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list


Re: Struct usages in Python

2008-05-29 Thread Alex Gusarov
>
> Yes. That is the somewhat unfortunate difference between new-style and
> old-style classes. Use new-style if you can, and that means that "object"
> must be part of the inheritance graph.
>
...

> You are wrong for Python 2.X, but right for Python 3 where old-style
> classes are gone for good.
>

Thanks, I don't knew it before and it's a sensitive information for me.

--
Best regards, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list

Re: Struct usages in Python

2008-05-29 Thread Alex Gusarov
>
> Yes. That is the somewhat unfortunate difference between new-style and
> old-style classes. Use new-style if you can, and that means that "object"
> must be part of the inheritance graph.
>
...

> You are wrong for Python 2.X, but right for Python 3 where old-style
> classes are gone for good.
>

Thanks, I don't knew it before and it's a sensitive information for me.

--
Best regards, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list

Re: Struct usages in Python

2008-05-29 Thread Alex Gusarov
> Yes. That is the somewhat unfortunate difference between new-style and 
> old-style classes.
> Use new-style if you can, and that means that "object" must be part of the 
> inheritance graph.

...

>You are wrong for Python 2.X, but right for Python 3 where old-style
>
>classes are gone for good.

Thanks, I don't knew it before and it's a sensitive information for me.

--
Best regards, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list


Unit tests?

2008-05-29 Thread Alex Gusarov
Hello, it seems that I have a problem - I almost finished my program
and it's necessary to test it. But I've never do it before. I even
don't know how I can do it.
Please, give me some links to testing techniques, either common or
specific to Python.
I searched in Google for information, but 'cause I don't know anything
about subject, I don't know where to start from.

Thanks
--
Best regards, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unit tests?

2008-05-29 Thread Alex Gusarov
Thx, it's quite enough for a start.
Yes, googling is almost ultimate answer for such questions, sorry for
uneasiness.

> Try googling "python unit test".  I did it, and amongst the first hits
> were:
>
>* docs.python.org/lib/module-unittest.html
>
>* http://www.diveintopython.org/unit_testing/index.html
>
> --
> Arnaud
--
http://mail.python.org/mailman/listinfo/python-list


py2exe & application add-ons

2008-06-19 Thread Alex Gusarov
Hello, I've met a problem - I want my program working without Python
installation but I have some add-on mechanism (add-ons represented by
separate .py files, and application auto-recognize such files on
start).

So, if I will using py2exe for main program and separate .py files for
add-ons, will I need Python installation on client machine?
Maybe other ways exist for such tasks?

--
Thx, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe & application add-ons

2008-06-20 Thread Alex Gusarov
Thanks everybody, yes, I use 'exec' for files.
And "freeze" modules - thanks too, I almost forgot this opportunity.

--
Best regards, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list