Re: [Tutor] cannot pickle instancemethod objects

2007-06-13 Thread Kent Johnson
hok kakada wrote:

>> What kind of object is matcher? Does it have any attributes that are
>> functions? (Not methods you defined for the class, but functions or
>> methods that you assign to attributes of self.)

> Actually, I use the translate-toolkit from 
> http://translate.sourceforge.net/snapshots/translate-toolkit-1.0.1rc1/
> in translate/search/match.py:
> if comparer is None:
> comparer = lshtein.LevenshteinComparer(max_length)
 > self.comparer = comparer

> I just found the problem that it is because of the LevenshteinComparer. Once 
> I 
> assign self.comparer = None, the I can dump the matcher successfully.
> However, I still don't understand what could be wrong with 
> LevenshteinComparer. 

I think the problem is this code in LevenshteinComparer.__init__():

 if Levenshtein:
 self.distance = self.native_distance
 else:
 self.distance = self.python_distance

which assigns an instance method to an instance attribute; this is the 
instancemethod that can't be pickled.

Kent

PS Please use Reply All to reply to the list.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] locking files

2007-06-13 Thread Jeff Peery
does anyone know if there is a way in python to lock a file so others cannot 
open it, or can only read it? I have a program that read/writes to a file and I 
would like to lock others out of it while I'm operating on it. 
   
  thanks.
   
  Jeff

 
-
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using zip

2007-06-13 Thread lucio arteaga
I am trying to learn using zip in combination with if statements. , If I do not 
make mistakes the program runs wlel. Otherwise very bad?
Can anyone help
Best wishes
Lucio___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using zip

2007-06-13 Thread lucio arteaga
I am trying to learn using zip in combination of if statemeny. , If I do not 
make mistakes the program runs wll. Otherwise very bad?
Can any one help
Best wishes
Lucio___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] locking files

2007-06-13 Thread Alan Gauld
"Jeff Peery" <[EMAIL PROTECTED]> wrote

> does anyone know if there is a way in python to lock 
> a file so others cannot open it, or can only read it? 

Thats normally controlled by your OS and the rules vary 
slightly between them. In general if you open a file for 
writing the OS should lock it against writing (and in 
some cases against reading too!). So if you want to 
lock an existing file while you read and write you could use 
a mode string of 'r+'. If you want to create a new locked 
file use 'w+''. BUT remember that its up to you to manage 
where the cursor is, otherwise you could wind up overwriting 
your data.

Another way to protect access, but less reliable, is 
to change the file permissions (using os.chmod()) 
at the start of the operation and change themback at 
the end. But that will only protect ahainst access by 
other users not against access by other programs that 
you might be running! Also you need to have 
permission to change permissions in the first place!

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Get max quantity

2007-06-13 Thread Carlos
Hello,

If I have a dictionary like:

inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}

How can I get the item with the largest quantity? I tried:

max(inventory)

but got:

'pears'

What I would like to get is 'oranges', at least in this case.

Thanks,
Carlos

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Get max quantity

2007-06-13 Thread Kent Johnson
Carlos wrote:
> Hello,
> 
> If I have a dictionary like:
> 
> inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
> 
> How can I get the item with the largest quantity? I tried:
> 
> max(inventory)
> 
> but got:
> 
> 'pears'
> 
> What I would like to get is 'oranges', at least in this case.

In Python 2.5, you can use the key= parameter to max:
In [3]: inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 
'pears': 217}
In [4]: max(inventory, key=inventory.__getitem__)
Out[4]: 'oranges'

In older Pythons, convert the dict to a list of (value, key) pairs and 
find the max of that:

In [5]: max((value, key) for key, value in inventory.iteritems())[1]
Out[5]: 'oranges'

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Get max quantity

2007-06-13 Thread Jason Massey

More than one way to skin a cat:


import operator
sort_key = operator.itemgetter(1)
sorted(inventory.items(),key=sort_key)[-1]

('oranges',525)

or...


inventory.items()

[('pears', 217), ('apples', 430), ('oranges', 525), ('bananas', 312)]

count_first = [(count,fruit) for fruit,count in inventory.items()]
count_first

[(217, 'pears'), (430, 'apples'), (525, 'oranges'), (312, 'bananas')]

max(count_first)

(525, 'oranges')

And then of course you could iterate over the dictionary setting up
variables that hold the highest fruit and count found so far.



On 6/13/07, Carlos <[EMAIL PROTECTED]> wrote:


Hello,

If I have a dictionary like:

inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}

How can I get the item with the largest quantity? I tried:

max(inventory)

but got:

'pears'

What I would like to get is 'oranges', at least in this case.

Thanks,
Carlos

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Get max quantity

2007-06-13 Thread Brian Wisti
Hi Carlos,

On 6/13/07, Carlos <[EMAIL PROTECTED]> wrote:
> Hello,
>
> If I have a dictionary like:
>
> inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
>
> How can I get the item with the largest quantity? I tried:
>
> max(inventory)
>
> but got:
>
> 'pears'
>
> What I would like to get is 'oranges', at least in this case.
>
> Thanks,
> Carlos
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

There are indeed several ways to sort this particular cat. Here's my
own favorite:

# Sort the list of keys by inventory count, from high to low
>>> inventory
{'pears': 217, 'apples': 430, 'oranges': 525, 'bananas': 312}
>>> items = inventory.keys()
>>> items
['pears', 'apples', 'oranges', 'bananas']
>>> items.sort(cmp=lambda a,b: cmp(inventory[b], inventory[a]))
>>> items
['oranges', 'apples', 'bananas', 'pears']
>>> items[0]
'oranges'

It does result in another list, same as the the approaches listed by
Kent and Jason. If *all* you were interested was the key associated
with the greatest inventory count, you could wrap your favorite
solution in a function and return the key from that.

Kind Regards,

Brian Wisti
http://coolnamehere.com/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] wxPython GUI builders?

2007-06-13 Thread Alan Gauld
What's available and in what state of readiness?

I tried Boa Constructor but after half a dozen code tweaks 
I was still running into compatibility errors with the latest 
wxPython and gave up. 

I know that Glade is out there, but what state is it in?
And PythonCard offers another approach but I haven't 
looked at it for about 3 years.

Are there any others? And which ones do people 
actually use? Commercial or Freeware.

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wxPython GUI builders?

2007-06-13 Thread Carlos Daniel Ruvalcaba Valenzuela
wxGlade is a good GUI builder, very much like Glade, however it may o
may not integrate with your coding style but you should definitively
give it a try.

PythonCard is a nice concept I personally do something similar but
with XML, parse and build the GUI from it, then tweak the layout
manually, with PythonCard this is easier to do since it has a resource
editor.

Personally I would like an IDE + wxPython GUI editor integrated, that
would help a lot, I'm starting to work on that myself.

Good luck!

On 6/13/07, Alan Gauld <[EMAIL PROTECTED]> wrote:
> What's available and in what state of readiness?
>
> I tried Boa Constructor but after half a dozen code tweaks
> I was still running into compatibility errors with the latest
> wxPython and gave up.
>
> I know that Glade is out there, but what state is it in?
> And PythonCard offers another approach but I haven't
> looked at it for about 3 years.
>
> Are there any others? And which ones do people
> actually use? Commercial or Freeware.
>
> Alan G.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wxPython GUI builders?

2007-06-13 Thread Dick Moores
At 01:08 PM 6/13/2007, Alan Gauld wrote:
>What's available and in what state of readiness?

I don't have the details you want, but you might look at SPE. 


Dick Moores


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Table of replacements for deprecated fns from 'string' module?

2007-06-13 Thread Stephen McInerney
Hi,

Where is there a table of replacements for the deprecated 'string' fns
esp. the basic common ones e.g. string.split(), join(), replace(), find(), 
index() ?
http://docs.python.org/lib/node42.html

Are we supposed to use 're' fns even for very simple operations?
that seems like way overkill.
This stuff is badly covered by the docpages.

(the deprecated fns from 'string' module will finally go away in Python 3.0)

Thanks,
Stephen

[This is a repost - I had to resubscribe to the list]

_
Get a preview of Live Earth, the hottest event this summer - only on MSN 
http://liveearth.msn.com?source=msntaglineliveearthhm

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Table of replacements for deprecated fns from 'string' module?

2007-06-13 Thread John Fouhy
On 14/06/07, Stephen McInerney <[EMAIL PROTECTED]> wrote:
> Where is there a table of replacements for the deprecated 'string' fns
> esp. the basic common ones e.g. string.split(), join(), replace(), find(),
> index() ?
> http://docs.python.org/lib/node42.html

They've basically all moved into the string type.

e.g. instead of typing "string.split(foo, sep)", you would now type
"foo.split(sep)".

Hence the leading comment on the page you cite: "The following list of
functions are also defined as methods of string and Unicode objects;
see ``String Methods'' (section 3.6.1) for more information on those.
"

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] capwords, maketrans

2007-06-13 Thread Jacob S.
Hi guys.
I was just wondering what's going to happen to capwords and maketrans
when the string module is finally terminated. Is python just not going to
support those to functions anymore? Or are they going to suddenly be
implemented as string methods at the last minute? Or are they on the list to
be phased out because no one uses them? Lack of use? Just wondering.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] capwords, maketrans

2007-06-13 Thread John Fouhy
On 14/06/07, Jacob S. <[EMAIL PROTECTED]> wrote:
> Hi guys.
> I was just wondering what's going to happen to capwords and maketrans
> when the string module is finally terminated.

As far as I know, the string module as a whole is not going away.  In
particular, the string module supplies various constants that are
quite useful.  Only those string functions that exist as string
methods (and are on the deprecated list) will eventually die.

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Componentone - TrueDBGrid Control

2007-06-13 Thread Pradeep Kumar

Hi,

Is wxPython have Componentone Trudbgrid like control. If yes,
Please inform. if No, how we can made one.

Pradeep
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] capwords, maketrans

2007-06-13 Thread Stephen McInerney
Ok thanks all.

The doucmentation is confusing on that point.
Also when it refers to the methods becoming methods
of string objects a link would be nice.

Regards,
Stephen



>From: "John Fouhy" <[EMAIL PROTECTED]>
>To: "Jacob S." <[EMAIL PROTECTED]>
>CC: tutor@python.org
>Subject: Re: [Tutor] capwords, maketrans
>Date: Thu, 14 Jun 2007 13:30:42 +1200
>
>On 14/06/07, Jacob S. <[EMAIL PROTECTED]> wrote:
> > Hi guys.
> > I was just wondering what's going to happen to capwords and 
>maketrans
> > when the string module is finally terminated.
>
>As far as I know, the string module as a whole is not going away.  In
>particular, the string module supplies various constants that are
>quite useful.  Only those string functions that exist as string
>methods (and are on the deprecated list) will eventually die.
>
>--
>John.
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

_
Hotmail to go? Get your Hotmail, news, sports and much more! 
http://mobile.msn.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor