Re: Which is faster?

2008-08-29 Thread Steven D'Aprano
On Fri, 29 Aug 2008 21:26:35 -0700, cnb wrote: > def averageGrade(self): > tot = 0 > for review in self.reviews: > tot += review.grade > return tot / len(self.reviews) > > def av_grade(self): > return sum(review.grade for review in self.reviews) / \ >

Re: When to use try and except?

2008-08-29 Thread Fredrik Lundh
Carl Banks wrote: I wouldn't say that the possibility of EAFP in Python makes it obsolute to use LBYL. when using CPython, EAFP at the Python level always involve LBYL at the C level. and it should be obvious to any programmer that checking for the same thing twice is quite often a waste of

Re: Which is faster?

2008-08-29 Thread Gabriel Genellina
En Sat, 30 Aug 2008 01:26:35 -0300, cnb <[EMAIL PROTECTED]> escribi�: For a big nbr of it might matter? Is av_grade O(n*2) and the first O(n) when it comes to adding or is "sum x for x in y" just traversing the list ones, accumulating the values, it doesnt first build the list and then travese

Re: Which is faster?

2008-08-29 Thread Fredrik Lundh
cnb wrote: For a big nbr of it might matter? Is av_grade O(n*2) and the first O(n) when it comes to adding or is "sum x for x in y" just traversing the list ones, accumulating the values, it doesnt first build the list and then travese it for sum? sum() doesn't build a list, but even if it wo

Re: Ensure only single application instance.

2008-08-29 Thread Frank Millman
On Aug 29, 11:25 pm, Uberman <[EMAIL PROTECTED]> wrote: > On Fri, Aug 29, 2008 at 6:51 AM, Heston James <[EMAIL PROTECTED]> wrote: > > Good afternoon all. > > > I have an application/script which is launched by crontab on a regular > > basis. I need an effective and accurate way to ensure that only

Re: struct.Struct random access

2008-08-29 Thread castironpi
On Aug 29, 10:30 pm, Tim Roberts <[EMAIL PROTECTED]> wrote: > castironpi <[EMAIL PROTECTED]> wrote: > > >CMIIW correct me if I'm wrong, I don't think that pack_into returns a > >value the way that pack does. > > Sorry, I was not aware that struct.pack_into and struct.unpack_from already > existed (

Which is faster?

2008-08-29 Thread cnb
For a big nbr of it might matter? Is av_grade O(n*2) and the first O(n) when it comes to adding or is "sum x for x in y" just traversing the list ones, accumulating the values, it doesnt first build the list and then travese it for sum? def averageGrade(self): tot = 0 for review i

Re: When to use try and except?

2008-08-29 Thread Carl Banks
On Aug 29, 2:33 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > On Fri, Aug 29, 2008 at 10:56 AM, cnb <[EMAIL PROTECTED]> wrote: > > On Aug 29, 7:40 pm, Daniel <[EMAIL PROTECTED]> wrote: > >> On Aug 29, 11:23 am, cnb <[EMAIL PROTECTED]> wrote: > > >> > If I get zero division error it is obv a poor

Re: struct.Struct random access

2008-08-29 Thread Tim Roberts
castironpi <[EMAIL PROTECTED]> wrote: > >CMIIW correct me if I'm wrong, I don't think that pack_into returns a >value the way that pack does. Sorry, I was not aware that struct.pack_into and struct.unpack_from already existed (they were added in Python 2.5). I thought you were proposing them as n

Re: Date Comparison and Manipulation Functions?

2008-08-29 Thread John Machin
On Aug 30, 10:41 am, "W. eWatson" <[EMAIL PROTECTED]> wrote: > What I'm trying to do is adjust date-time stamped file names for date and > time errors. The software program collects through a period that roughly > coincides with night hours every day and according to the OS clock. It > sometimes h

Re: When to use try and except?

2008-08-29 Thread Craig Allen
On Aug 29, 7:23 am, cnb <[EMAIL PROTECTED]> wrote: > If I get zero division error it is obv a poor solution to do try and > except since it can be solved with an if-clause. > > However if a program runs out of memory I should just let it crash > right? Because if not then I'd have to write exceptio

Re: When to use try and except?

2008-08-29 Thread Carl Banks
On Aug 29, 1:56 pm, cnb <[EMAIL PROTECTED]> wrote: > On Aug 29, 7:40 pm, Daniel <[EMAIL PROTECTED]> wrote: > > > > > On Aug 29, 11:23 am, cnb <[EMAIL PROTECTED]> wrote: > > > > If I get zero division error it is obv a poor solution to do try and > > > except since it can be solved with an if-clause

Re: posix semaphore support?

2008-08-29 Thread Paul Rubin
Neal Becker <[EMAIL PROTECTED]> writes: > Does that provide semaphores between unrelated processes? The threading module is just for threads of a single process. There's an shm module that implements semaphores: http://nikitathespider.com/python/shm/ -- http://mail.python.org/mailman/listinfo

Re: Multipart - Counting the amount of Values for One key

2008-08-29 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Gabriel Genellina <[EMAIL PROTECTED]> wrote: >En Fri, 29 Aug 2008 14:41:53 -0300, Ron Brennan <[EMAIL PROTECTED]> >escribi�: > >> I am trying to find the amount of values there are pertaining to one key. >> >> For example: >> >> - To find the average of the value

Re: ctypes version mismatch

2008-08-29 Thread Paul McNett
Thomas Heller wrote: Paul McNett schrieb: Anyone have anything to suggest on this error: {{{ Traceback (most recent call last): File "shutter_studio.py", line 41, in File "App.pyo", line 25, in File "ui\__init__.pyo", line 23, in File "ui\FrmProductionOrders.pyo", line 10, in

Re: Date Comparison and Manipulation Functions?

2008-08-29 Thread W. eWatson
John Machin wrote: On Aug 30, 2:32 am, "W. eWatson" <[EMAIL PROTECTED]> wrote: I just tried the following code, and got an unexpected result. from pyfdate import * t = Time() ts = Time(2008, 8, 29,15,20,7) tnew = ts.plus(months=6) print "new date: ", tnew Result: new date: 2009-02-28 15:20:0

Re: Module __file__ attribute in Python 3

2008-08-29 Thread MRAB
On Aug 29, 6:11 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > That will mean that there will be no (easy?) way to determine after the > > import whether the module was imported from a source file or a compiled > > file. I've suggested that the original justification for the patch no > > lon

Re: How to delete a ast character from a string?

2008-08-29 Thread norseman
[EMAIL PROTECTED] wrote: On Fri, Aug 29, 2008 at 7:40 PM, Chris Rebert <[EMAIL PROTECTED]> wrote: On Fri, Aug 29, 2008 at 11:25 AM, <[EMAIL PROTECTED]> wrote: Hi, I've a list some of whose elements with character \. I want to delete this last character from the elements that have this charact

Prothon and Mark Hahn?

2008-08-29 Thread average
Anyone know how to get ahold of Mark Hahn, the would-be creator of next-generation Python? He had a language project called Prothon (classless Python, or Python with Prototypes) a few years ago that was being built upon the Apache Portable Runtime, using a stackless, 64- bit architecture and nativ

Re: Command lime code

2008-08-29 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Timothy Grant <[EMAIL PROTECTED]> wrote: >On Fri, Aug 29, 2008 at 3:38 PM, <[EMAIL PROTECTED]> wrote: >>>Seriously, did you think we've hacked your computer and are spying on >>>your web browsing? How would we know what web page you have visited? >> >> I was hoping

Re: no string.downer() ?

2008-08-29 Thread Gabriel Genellina
En Thu, 28 Aug 2008 02:52:42 -0300, Fredrik Lundh <[EMAIL PROTECTED]> escribi�: Asun Friere wrote: Never ascribe to humour that which can be adequately explained by increadible stupidity! On the other hand given up/down vs. high/low, upper/downer might appear logical to someone who doesn't

Re: PyDoc in Windows Vista

2008-08-29 Thread Tyler Shopshire
On Fri, 29 Aug 2008 07:12:28 -0700, Mike Driscoll wrote: > On Aug 28, 5:45 pm, Tyler Shopshire <[EMAIL PROTECTED]> wrote: >> I can't seem to access the pydoc sever from my web browser. I start the >> server from the command prompt and everything seems to be working fine, >> then I got tohttp://loc

Re: Multipart - Counting the amount of Values for One key

2008-08-29 Thread Gabriel Genellina
En Fri, 29 Aug 2008 14:41:53 -0300, Ron Brennan <[EMAIL PROTECTED]> escribi�: I am trying to find the amount of values there are pertaining to one key. For example: - To find the average of the values pertaining to the key. - Use the amount of values to calculate a histogram What is a "mul

Re: Date Comparison and Manipulation Functions?

2008-08-29 Thread John Machin
On Aug 30, 2:32 am, "W. eWatson" <[EMAIL PROTECTED]> wrote: > I just tried the following code, and got an unexpected result. > > from pyfdate import * > t = Time() > > ts = Time(2008, 8, 29,15,20,7) > tnew = ts.plus(months=6) > print "new date: ", tnew > > Result: > new date: 2009-02-28 15:20:07 >

Re: posix semaphore support?

2008-08-29 Thread Christian Heimes
Neal Becker wrote: Does that provide semaphores between unrelated processes? No, it just provides unshared semaphores. You can either create your own Python extensions or you can use ctypes if you need a shared or named semaphore. Depending on your requirements you can choose between sem_in

Re: Can I write a binary windows executable with Python?

2008-08-29 Thread Christian Heimes
walterbyrd wrote: I have heard about Pysco. But does create a single executable that can run without Python being installed? Or does that just compile the libraries? Psyco is a kind of JIT (just in time) optimizer for Python. It's limited to i386 compatible CPUs (aka X86 architecture). It has

Re: Ensure only single application instance.

2008-08-29 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Uberman <[EMAIL PROTECTED]> wrote: >On Fri, Aug 29, 2008 at 6:51 AM, Heston James <[EMAIL PROTECTED]> wrote: >> Good afternoon all. >> >> I have an application/script which is launched by crontab on a regular >> basis. I need an effective and accurate way to ensure

Re: Can I write a binary windows executable with Python?

2008-08-29 Thread Aleksandar Radulovic
Hi, What you're probably referring to is py2exe tool (http://www.py2exe.org/) which creates windows executable programs out of python scripts. Once created, such executable can be run on a Windows machine without Python installed. Psyco, on the other hand, is a tool that greatly optimizes and inc

Can I write a binary windows executable with Python?

2008-08-29 Thread walterbyrd
I have heard about Pysco. But does create a single executable that can run without Python being installed? Or does that just compile the libraries? -- http://mail.python.org/mailman/listinfo/python-list

Re: posix semaphore support?

2008-08-29 Thread Neal Becker
Christian Heimes wrote: > Neal Becker wrote: >> Is there a posix semaphore wrapper for python? >> >> Would that be a good addition? > > The threading module provides a high level interface to native > semaphores, e.g. pthread. > > Christian > Does that provide semaphores between unrelated pro

Re: Command lime code

2008-08-29 Thread Timothy Grant
On Fri, Aug 29, 2008 at 3:38 PM, <[EMAIL PROTECTED]> wrote: >>Seriously, did you think we've hacked your computer and are spying on >>your web browsing? How would we know what web page you have visited? > > I was hoping someone would give me a page add where such code could be > found. > Thanks fo

Re: subclassing complex

2008-08-29 Thread BiDi
On Aug 30, 6:18 am, Patrick Maupin <[EMAIL PROTECTED]> wrote: > On Aug 29, 4:24 am, Peter Otten <[EMAIL PROTECTED]> wrote: > > > > > A minimal example is > > > >>> class Complex(complex): > > > ...     def __radd__(self, other): print "radd" > > ...>>> 1j + Complex() > > > 1j > > > versus > > > >>>

Re: Problem with list.insert

2008-08-29 Thread John Machin
On Aug 29, 5:10 pm, SUBHABRATA <[EMAIL PROTECTED]> wrote: > Dear group, > Thanx for your idea to use dictionary instead of a list. Your code is > more or less, OK, some problems are there, I'll debug them. Well, I > feel the insert problem is coming because of the Hindi thing. It's nothing to do w

Re: logging - how to use in a library?

2008-08-29 Thread Thomas Heller
Vinay Sajip schrieb: > On Aug 27, 11:28 am, Thomas Heller <[EMAIL PROTECTED]> wrote: >> >> I came up with a workaround that seems to do what I want. I add a NULL >> handler >> to my top-level logger which is not the root logger but a logger named >> 'comtypes', >> other loggers are named 'comtyp

Re: problem with packages and path

2008-08-29 Thread Daniel
On Aug 29, 1:15 pm, Paul Boddie <[EMAIL PROTECTED]> wrote: > On 29 Aug, 19:08, Daniel <[EMAIL PROTECTED]> wrote: > > > > > > > I have tried running both commands above from the mypackage directory > > and unittests directory.  I get the following response universtally. > > > C:\mypackage>dir > >  V

Re: posix semaphore support?

2008-08-29 Thread Christian Heimes
Neal Becker wrote: Is there a posix semaphore wrapper for python? Would that be a good addition? The threading module provides a high level interface to native semaphores, e.g. pthread. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: ctypes version mismatch

2008-08-29 Thread Thomas Heller
Paul McNett schrieb: > Anyone have anything to suggest on this error: > > {{{ > Traceback (most recent call last): >File "shutter_studio.py", line 41, in >File "App.pyo", line 25, in >File "ui\__init__.pyo", line 23, in >File "ui\FrmProductionOrders.pyo", line 10, in >File

Google License Keys for pyGoogle

2008-08-29 Thread Alex Bryan
I know this isn't the right mailing list, but it saves me the hassle of signing up for another one if someone on here knows. I have never used pyGoogle before, and I just read that google isn't giving out license keys anymore? If that is the case, can I still get pygoogle to work another wa

Re: Ensure only single application instance.

2008-08-29 Thread Uberman
On Fri, Aug 29, 2008 at 6:51 AM, Heston James <[EMAIL PROTECTED]> wrote: > Good afternoon all. > > I have an application/script which is launched by crontab on a regular > basis. I need an effective and accurate way to ensure that only one instance > of the script is running at any one time. You c

posix semaphore support?

2008-08-29 Thread Neal Becker
Is there a posix semaphore wrapper for python? Would that be a good addition? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to delete a last character from a string

2008-08-29 Thread Derek Martin
On Fri, Aug 29, 2008 at 07:37:50PM +, Steven D'Aprano wrote: > On Fri, 29 Aug 2008 14:46:53 -0400, Derek Martin wrote: > > > On Fri, Aug 29, 2008 at 07:28:40PM +0100, [EMAIL PROTECTED] wrote: > >> dirListFinal = [] > >> for item in dirList: > >>print item > >>if item.en

Re: Lining Up and PaddingTwo Similar Lists

2008-08-29 Thread Marc 'BlackJack' Rintsch
On Fri, 29 Aug 2008 09:40:32 -0700, W. eWatson wrote: > Actually, I'm getting the file names from listdir, and they appear to be > sorted low to high. I tried it on a folder with lots of dissimilar > files. But that's not guaranteed. It depends on the operating system and file system driver if

RE: [wwwsearch-general] (no subject)

2008-08-29 Thread bruce
Hi john. Thanks for your reply. I tried your suggestion of using RobustFactory, and still get a badly maligned html back!!! The html is listed below. I would have thought that the mech process, would have interpreted the "http-equiv="refresh" Unfortunately, mechanize apparently isn't able to handl

Re: Ensure only single application instance.

2008-08-29 Thread Timothy Grant
On Fri, Aug 29, 2008 at 6:51 AM, Heston James <[EMAIL PROTECTED]> wrote: > Good afternoon all. > > I have an application/script which is launched by crontab on a regular > basis. I need an effective and accurate way to ensure that only one instance > of the script is running at any one time. > > Af

ctypes version mismatch

2008-08-29 Thread Paul McNett
Anyone have anything to suggest on this error: {{{ Traceback (most recent call last): File "shutter_studio.py", line 41, in File "App.pyo", line 25, in File "ui\__init__.pyo", line 23, in File "ui\FrmProductionOrders.pyo", line 10, in File "ui\PagEditProductionOrders.pyo", line 8, i

Re: Syntax error in ".py" file and globals variable values not available.

2008-08-29 Thread Timothy Grant
On Fri, Aug 29, 2008 at 12:48 AM, Alexis Boutillier <[EMAIL PROTECTED]> wrote: > Timothy Grant a écrit : >> >> On Thu, Aug 28, 2008 at 1:40 AM, Alexis Boutillier >> <[EMAIL PROTECTED]> wrote: >>> >>> Timothy Grant a écrit : On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier <[EMAIL P

Re: How to delete a last character from a string

2008-08-29 Thread dudeja . rajat
On Fri, Aug 29, 2008 at 8:37 PM, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Fri, 29 Aug 2008 14:46:53 -0400, Derek Martin wrote: > >> On Fri, Aug 29, 2008 at 07:28:40PM +0100, [EMAIL PROTECTED] wrote: >>> dirListFinal = [] >>> for item in dirList: >>>print item >>>if it

Re: Beginner's question about string's join() method

2008-08-29 Thread Macygasp
On Aug 29, 3:51 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Macygasp wrote: > > Hi, > > > Can anybody tell me why and how this is working: > > ','.join(str(a) for a in range(0,10)) > > '0,1,2,3,4,5,6,7,8,9' > > > I find this a little weird because join takes a sequence as argument; > >

Re: [1,2,3] exactly same as [1,2,3,] ?

2008-08-29 Thread Paul McNett
Steven D'Aprano wrote: On Thu, 28 Aug 2008 16:28:03 -0700, Paul McNett wrote: [EMAIL PROTECTED] wrote: x=[1,2,3] and x=[1,2,3,] are exactly the same, right? When confronted with this type of question, I ask the interpreter: {{{ mac:~ pmcnett$ python Python 2.5.2 (r252:60911, Feb 22 2008, 07

Re: Process "Killed"

2008-08-29 Thread Fredrik Lundh
Glenn Hutchings wrote: Have you checked memory usage while your program is running? Your lines = f.readlines()[2:] statement will need almost twice the memory of your largest file. footnote: list objects contain references to string objects, not the strings themselves. the above tempo

Re: How to delete a last character from a string

2008-08-29 Thread Steven D'Aprano
On Fri, 29 Aug 2008 14:46:53 -0400, Derek Martin wrote: > On Fri, Aug 29, 2008 at 07:28:40PM +0100, [EMAIL PROTECTED] wrote: >> dirListFinal = [] >> for item in dirList: >>print item >>if item.endswith('\\') == True: > > if item[-1] == '\\': Which will fail b

Re: Process "Killed"

2008-08-29 Thread Fredrik Lundh
dieter wrote: Any Ideas? Is there a buffer limitation? Do you think it could be the filesystem? what does "ulimit -a" say? -- http://mail.python.org/mailman/listinfo/python-list

Re: [wwwsearch-general] (no subject)

2008-08-29 Thread John J Lee
On Fri, 29 Aug 2008, bruce wrote: [...] does the page (test.html) need to be completely valid html? No, but there are certainly (poorly-defined) limitations. I haven't tried to understand your script or the HTML, but did you try this: br = mechanize.Browser(mechanize.RobustFactory()) ...

Re: Process "Killed"

2008-08-29 Thread Paul Boddie
On 28 Aug, 07:30, dieter <[EMAIL PROTECTED]> wrote: > > I'm doing some simple file manipulation work and the process gets > "Killed" everytime I run it. No traceback, no segfault... just the > word "Killed" in the bash shell and the process ends. The first few > batch runs would only succeed with o

Re: eval() == evil? --- How to use it safely?

2008-08-29 Thread castironpi
On Aug 29, 1:51 pm, Fett <[EMAIL PROTECTED]> wrote: > > Your way of thinking is similar to Microsoft's. Encrypting and Signing > > is a kludge, a real fix should fix the underlying cause. Anyway using > > data parsers isn't that much harder than using eval/exec. > > While I agree that in this situa

Re: problem with packages and path

2008-08-29 Thread Paul Boddie
On 29 Aug, 19:08, Daniel <[EMAIL PROTECTED]> wrote: > > I have tried running both commands above from the mypackage directory > and unittests directory. I get the following response universtally. > > C:\mypackage>dir > Volume in drive C is Default > > Directory of C:\mypackage > > 08/29/2008 11

Re: How to delete a last character from a string

2008-08-29 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: There is just a single \ at the end of every item. My list is as below: ['Results v1.0/', 'Results v1.1/'] so, if x.endswith('\\'): is that correct? if your list contains forward slashes, maybe you should test for forward slashes and not backward slashes. -- ht

Re: Process "Killed"

2008-08-29 Thread Glenn Hutchings
dieter <[EMAIL PROTECTED]> writes: > I'm doing some simple file manipulation work and the process gets > "Killed" everytime I run it. No traceback, no segfault... just the > word "Killed" in the bash shell and the process ends. The first few > batch runs would only succeed with one or two files be

Memory Leek, critique me. Thanks!!!

2008-08-29 Thread Kevin McKinley
cnb, That is on of the things i want to fix with this code. I meant to mention in my original post that i've only been programming with Python for a little over two weeks. The only other experience with programming i've had is with Basic on my TI-83 calculator in high school. This isn't my ex

Re: Memory Leek, critique me. Thanks!!!

2008-08-29 Thread Peter Otten
Kevin McKinley wrote: > # I posted a few days ago about a memory leak that I think i'm having > # with my first Tkinter program. I've had trouble pinpointing what is > # wrong so i thought i would submit the code and see if anyone would like > # to critique it. Don't create new widgets every

Re: How to delete a last character from a string

2008-08-29 Thread dudeja . rajat
On Fri, Aug 29, 2008 at 7:59 PM, <[EMAIL PROTECTED]> wrote: > On Fri, Aug 29, 2008 at 7:41 PM, Mike Driscoll <[EMAIL PROTECTED]> wrote: >> On Aug 29, 1:28 pm, [EMAIL PROTECTED] wrote: >>> Sorry : Earlier mail had a typo in Subject line which might look >>> in-appropriate to my friends >>> >>> Hi,

Re: How to delete a ast character from a string?

2008-08-29 Thread Terry Reedy
[EMAIL PROTECTED] wrote: Hi, I've a list some of whose elements with character \. I want to delete this last character from the elements that have this character set at their end, I don't understand this. Give an example of input and expected output. I have written a small program, unfort

Re: How to delete a last character from a string

2008-08-29 Thread dudeja . rajat
On Fri, Aug 29, 2008 at 7:41 PM, Mike Driscoll <[EMAIL PROTECTED]> wrote: > On Aug 29, 1:28 pm, [EMAIL PROTECTED] wrote: >> Sorry : Earlier mail had a typo in Subject line which might look >> in-appropriate to my friends >> >> Hi, >> >> I've a list some of whose elements with character \. >> I want

Re: Using class-attribute as key to sort?

2008-08-29 Thread Terry Reedy
cnb wrote: In median grade, can I sort on Review-grade somehow? Google "Python sort key attribute" the first hit (after your post) is http://wiki.python.org/moin/HowTo/Sorting Find 'attribute' on that page for your answer (two options). -- http://mail.python.org/mailman/listinfo/python-list

Re: eval() == evil? --- How to use it safely?

2008-08-29 Thread Fett
> Your way of thinking is similar to Microsoft's. Encrypting and Signing > is a kludge, a real fix should fix the underlying cause. Anyway using > data parsers isn't that much harder than using eval/exec. While I agree that in this situation I should do both, what would you propose for cases where

Re: How to delete a last character from a string

2008-08-29 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: I've a list some of whose elements with character \. I want to delete this last character from the elements that have this character set at their end, I have written a small program, unfortunately this does not work: dirListFinal = [] for item in dirList: pr

Re: Python - ubuntu

2008-08-29 Thread Luis M . González
It's worth noting that Ubuntu's creator is a fan of python. So it comes as no surprise that the distribution has a lot of components written in this language. Also, and as far as I know, the use of python is encouraged for making contributions. On Aug 29, 11:57 am, azrael <[EMAIL PROTECTED]> wrot

Re: How to delete a ast character from a string?

2008-08-29 Thread dudeja . rajat
On Fri, Aug 29, 2008 at 7:40 PM, Chris Rebert <[EMAIL PROTECTED]> wrote: > On Fri, Aug 29, 2008 at 11:25 AM, <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I've a list some of whose elements with character \. >> I want to delete this last character from the elements that have this >> character set at the

Re: Using class-attribute as key to sort?

2008-08-29 Thread Chris Rebert
Just use the "key" argument to list.sort; e.g. class Foo(object): def __init__(self, x): self.x = x def __repr__(self): return "Foo:"+str(self.x) foos = [Foo(75), Foo(10), Foo(-1)] foos.sort(key = lambda foo: foo.x) print foos #=> [Foo:-1, Foo:10, Foo:75] - Chris

Re: How to delete a last character from a string

2008-08-29 Thread Derek Martin
On Fri, Aug 29, 2008 at 07:28:40PM +0100, [EMAIL PROTECTED] wrote: > dirListFinal = [] > for item in dirList: >print item >if item.endswith('\\') == True: if item[-1] == '\\': -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D pgp5fVWPp4A

Re: How to delete a last character from a string

2008-08-29 Thread Mike Driscoll
On Aug 29, 1:28 pm, [EMAIL PROTECTED] wrote: > Sorry : Earlier mail had a typo in Subject line which might look > in-appropriate to my friends > > Hi, > > I've a list some of whose elements with character \. > I want to delete this last character from the elements that have this > character set at

Re: How to delete a last character from a string

2008-08-29 Thread Mike Kent
On Aug 29, 2:28 pm, [EMAIL PROTECTED] wrote: > Sorry : Earlier mail had a typo in Subject line which might look > in-appropriate to my friends > > Hi, > > I've a list some of whose elements with character \. > I want to delete this last character from the elements that have this > character set at

Re: Date Comparison and Manipulation Functions?

2008-08-29 Thread norseman
W. eWatson wrote: I just tried the following code, and got an unexpected result. from pyfdate import * t = Time() ts = Time(2008, 8, 29,15,20,7) tnew = ts.plus(months=6) print "new date: ", tnew Result: new date: 2009-02-28 15:20:07 I believe that should be April 1, 2009. If I use months = 1

Re: How to delete a ast character from a string?

2008-08-29 Thread Chris Rebert
On Fri, Aug 29, 2008 at 11:25 AM, <[EMAIL PROTECTED]> wrote: > Hi, > > I've a list some of whose elements with character \. > I want to delete this last character from the elements that have this > character set at their end, > > I have written a small program, unfortunately this does not work: >

Re: When to use try and except?

2008-08-29 Thread Chris Rebert
On Fri, Aug 29, 2008 at 10:56 AM, cnb <[EMAIL PROTECTED]> wrote: > On Aug 29, 7:40 pm, Daniel <[EMAIL PROTECTED]> wrote: >> On Aug 29, 11:23 am, cnb <[EMAIL PROTECTED]> wrote: >> >> > If I get zero division error it is obv a poor solution to do try and >> > except since it can be solved with an if-

Re: When to use try and except?

2008-08-29 Thread Glenn Hutchings
cnb <[EMAIL PROTECTED]> writes: > A ZeroDivisionError is better avoided wth an if-clause, don't you > think? It is a predictable exception... It depends. If zero-division is unlikely, then things would probably[*] run faster without checking. If speed is what you're interested in, that is... G

Re: Using class-attribute as key to sort?

2008-08-29 Thread bearophileHUGS
cnb: > In median grade, can I sort on Review-grade somehow? operator.attrgetter may help. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

How to delete a last character from a string

2008-08-29 Thread dudeja . rajat
Sorry : Earlier mail had a typo in Subject line which might look in-appropriate to my friends Hi, I've a list some of whose elements with character \. I want to delete this last character from the elements that have this character set at their end, I have written a small program, unfortunately

How to delete a ast character from a string?

2008-08-29 Thread dudeja . rajat
Hi, I've a list some of whose elements with character \. I want to delete this last character from the elements that have this character set at their end, I have written a small program, unfortunately this does not work: dirListFinal = [] for item in dirList: print item i

Using class-attribute as key to sort?

2008-08-29 Thread cnb
In median grade, can I sort on Review-grade somehow? something like: sr = self.reviews.sort(key=self.reviews.instance.grade) class Review(object): def __init__(self, movieId, grade, date): self.movieId = movieId self.grade = grade self.date = date class Customer(object

Re: return reduce(lambda x, y: x.grade+y.grade, self.reviews)

2008-08-29 Thread George Sakkis
On Aug 29, 1:54 pm, cnb <[EMAIL PROTECTED]> wrote: > class Customer(object): > def __init__(self, idnumber, review): > self.idnumber = idnumber > self.reviews = [review] > > def addReview(self, review): > self.reviews.append(review) > > def averageGrade(self): >

Re: subclassing complex

2008-08-29 Thread Patrick Maupin
On Aug 29, 4:24 am, Peter Otten <[EMAIL PROTECTED]> wrote: > A minimal example is > > >>> class Complex(complex): > > ... def __radd__(self, other): print "radd" > ...>>> 1j + Complex() > > 1j > > versus > > >>> class Int(int): > > ... def __radd__(self, other): print "radd" > ...>>> 1 + In

Re: exactly same as [1,2,3,] ?

2008-08-29 Thread Mensanator
On Aug 29, 10:11 am, Roy Smith <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, >  Grant Edwards <[EMAIL PROTECTED]> wrote: > > > > > > > On 2008-08-29, Roy Smith <[EMAIL PROTECTED]> wrote: > > > > Exactly.  This is one of those little pieces of syntactic > > > sugar which makes python

Re: Sending e-mail

2008-08-29 Thread Mike Driscoll
On Aug 29, 11:44 am, [EMAIL PROTECTED] wrote: > On Aug 28, 3:23 pm, gordyt <[EMAIL PROTECTED]> wrote: > > > > > Peter here is an example.  I just tried it and it works fine. > > > from smtplib import SMTP > > HOST = "smtp.gmail.com" > > PORT = 587 > > ACCOUNT = ""  # put your gmail email account na

Re: Memory Leek, critique me. Thanks!!!

2008-08-29 Thread cnb
you could prob abstract away a lot of that code, very similar-looking. then it would be easier to find bugs. -- http://mail.python.org/mailman/listinfo/python-list

Re: When to use try and except?

2008-08-29 Thread cnb
On Aug 29, 7:40 pm, Daniel <[EMAIL PROTECTED]> wrote: > On Aug 29, 11:23 am, cnb <[EMAIL PROTECTED]> wrote: > > > If I get zero division error it is obv a poor solution to do try and > > except since it can be solved with an if-clause. > > > However if a program runs out of memory I should just let

Re: Python - ubuntu

2008-08-29 Thread Joshua Kugler
> A friend of mine told me something about Guido and google developing > an Ubuntu distribution based and totaly oriented for the Python > appliction development. I googled for it with no results. Is it > possible that My Buddy is trying to foole me or is it possible that > someone knows something

return reduce(lambda x, y: x.grade+y.grade, self.reviews)

2008-08-29 Thread cnb
class Customer(object): def __init__(self, idnumber, review): self.idnumber = idnumber self.reviews = [review] def addReview(self, review): self.reviews.append(review) def averageGrade(self): tot = 0 for review in self.reviews: tot +

__stack_chk_fail_local

2008-08-29 Thread gianluca
hy list, I've built _libfoo.so and libfoo.py library with swig and I've copied in /usr/lib/python2.5/lib-dynload/ but when import the module >>import libfoo I've that message Traceback (most recent call last): File "", line 1, in ImportError: /usr/lib/python2.5/lib-dynload/_libfoo.so: undefi

Re: Tkinter event loop question

2008-08-29 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>, gordon <[EMAIL PROTECTED]> wrote: > On Aug 29, 4:45 am, "Russell E. Owen" <[EMAIL PROTECTED]> wrote: > >your Controller object should not create root nor should > > it call mainloop to start the event loop. > > guys > thanks for the helpful replies..I rewrote the

Re: When to use try and except?

2008-08-29 Thread George Sakkis
On Aug 29, 1:23 pm, cnb <[EMAIL PROTECTED]> wrote: > If I get zero division error it is obv a poor solution to do try and > except since it can be solved with an if-clause. > > However if a program runs out of memory I should just let it crash > right? Because if not then I'd have to write excepti

Re: When to use try and except?

2008-08-29 Thread Daniel
On Aug 29, 11:23 am, cnb <[EMAIL PROTECTED]> wrote: > If I get zero division error it is obv a poor solution to do try and > except since it can be solved with an if-clause. > > However if a program runs out of memory I should just let it crash > right? Because if not then I'd have to write excepti

Multipart - Counting the amount of Values for One key

2008-08-29 Thread Ron Brennan
hello, I am trying to find the amount of values there are pertaining to one key. For example: - To find the average of the values pertaining to the key. - Use the amount of values to calculate a histogram Also, how do reference a specific value for a key in a multipart? Thanks, Ron -- FYI,

Memory Leek, critique me. Thanks!!!

2008-08-29 Thread Kevin McKinley
# I posted a few days ago about a memory leak that I think i'm having with my first Tkinter program. # I've had trouble pinpointing what is wrong so i thought i would submit the code and see if anyone would # like to critique it. # I have one more problem that i can't figure out either.

Re: How to check is something is a list or a dictionary or a string?

2008-08-29 Thread George Sakkis
On Aug 29, 12:16 pm, [EMAIL PROTECTED] wrote: > Hi, > > How to check if something is a list or a dictionary or just a string? > Eg: > > for item in self.__libVerDict.itervalues(): > self.cbAnalysisLibVersion(END, item) > > where __libVerDict is a dictionary that holds values as strings

When to use try and except?

2008-08-29 Thread cnb
If I get zero division error it is obv a poor solution to do try and except since it can be solved with an if-clause. However if a program runs out of memory I should just let it crash right? Because if not then I'd have to write exceptions everywhere to prevent that right? So when would I actual

Re: Tkinter event loop question

2008-08-29 Thread gordon
On Aug 29, 4:45 am, "Russell E. Owen" <[EMAIL PROTECTED]> wrote: >your Controller object should not create root nor should > it call mainloop to start the event loop. guys thanks for the helpful replies..I rewrote the code as you advised. It creates a controller object and a gui object from main s

Re: Lining Up and PaddingTwo Similar Lists

2008-08-29 Thread George Sakkis
On Aug 29, 1:29 am, "W. eWatson" <[EMAIL PROTECTED]> wrote: > It looks like I have a few new features to learn about in Python. In > particular, > dictionaries. In Python it's hard to think of many non-trivial problems that you *don't* have to know about dictionaries. George -- http://mail.pyth

Re: Command lime code

2008-08-29 Thread Steven D'Aprano
On Fri, 29 Aug 2008 17:20:37 +0100, London wrote: > I am new to python. > I did find a page which listed some code - IE "chdir" type code but can > not find it again. > Can you supply an address? http://www.google.com is a good address to use. Seriously, did you think we've hacked your compute

Re: Module __file__ attribute in Python 3

2008-08-29 Thread Diez B. Roggisch
> That will mean that there will be no (easy?) way to determine after the > import whether the module was imported from a source file or a compiled > file. I've suggested that the original justification for the patch no > longer applies, and that the secondary purpose of the patch is better > solve

  1   2   >