LZO decompressing with Python 2.5x on Windows for C dummies

2010-09-07 Thread Kim Hansen
Hi list, I have some binary data files which contain embedded LZO compressed payloads mixed with normal C-struct like headers. I would like to have the ability to LZO decompress these payloads using a python 2.5.x script. I was hoping that there was an up-to-date plug-and-play LZO library availa

Re: list of tuples with dynamic change in position

2010-09-07 Thread Ulrich Eckhardt
sajuptpm wrote: > i want to find the loaded machine based on cpu and mem and desk > utilization by changing this order. > > I created a UI using that i can change the order of item in the tuple. > But the problem is asc and desc sorting How about only changing the order in which the elements are

Re: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0]))

2010-09-07 Thread sajuptpm
Detailed Description - l1 = [] l2 = [ ((3,8),(1,2)), ((1,3),(1,7)), ((7,0),(1,8)), ((4,2),(1,2)), ((2,9),(9,1)) ] I need to take each item from l2 and insert into l1 with first element(column)(3,1,7,4,2) sorted in ascending order and second element(column)(8,3,0,2,9) so

Re: The Samurai Principle

2010-09-07 Thread Ian Kelly
On Tue, Sep 7, 2010 at 9:35 PM, Phlip wrote: > Exceptions are very dangerous by themselves, because if you don't trap > them just right they can cause side-effects. And returning None on failure is dangerous, because if the programmer does not take care to handle that case, the program may attemp

Re: mail sending -- smtplib

2010-09-07 Thread Kurian Thayil
Got it fixed. It was a very silly mistake. mssg variable had each line with indent. Removed the indent and it worked. Regards, Kurian Thayil. On Tue, Sep 7, 2010 at 9:57 AM, Kurian Thayil wrote: > Hi All, > > I am a newbie in python. Just 2-3 days old wanting to learn this amazing > programming

Re: Bug in Python 2.6 urlencode

2010-09-07 Thread John Nagle
On 9/7/2010 9:56 PM, Ned Deily wrote: In article<4c87013f$0$1625$742ec...@news.sonic.net>, John Nagle wrote: On 9/7/2010 5:43 PM, Terry Reedy wrote: On 9/7/2010 3:02 PM, John Nagle wrote: There's a bug in Python 2.6's "urllib.urlencode". If you pass in a Unicode character outside the ASCII

Re: compare dictionaries

2010-09-07 Thread pdlemper
On Tue, 7 Sep 2010 12:46:36 -0700 (PDT), Baba wrote: >level: beginner > >word= 'even' >dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > >i want to know if word is entirely composed of letters in dict2 > >my approach: >step 1 : convert word to dictionary(dict1) > >step2: >for k in dict1.keys():

Re: Bug in Python 2.6 urlencode

2010-09-07 Thread Ned Deily
In article <4c87013f$0$1625$742ec...@news.sonic.net>, John Nagle wrote: > On 9/7/2010 5:43 PM, Terry Reedy wrote: > > On 9/7/2010 3:02 PM, John Nagle wrote: > >> There's a bug in Python 2.6's "urllib.urlencode". If you pass > >> in a Unicode character outside the ASCII range, instead of it > >> b

Re: Bit fields in python?

2010-09-07 Thread Eli Bendersky
> > > I'm trying to rewrite a c program in python & encountered several problems. > I have some data structures in my c program like below: > > typedef struct > { > unsigned short size; > > unsigned short reserved:8; > unsigned short var_a1:2; > unsigned short var_a2:2; > unsign

Re: Speed-up for loops

2010-09-07 Thread Stefan Behnel
BartC, 08.09.2010 03:45: Getting back to the OP's code again (trivial and pointless as it might seem), I got these results: C (gcc 3.4.5 -O3) 0.8 secs C (DMC-o) 2.3 secs C (lccwin32 -O) 2.9 secs [...] I've seen LuaJIT in action. It's timing for this test is 1.5 secs: forget being only 10x slower

Re: The Samurai Principle

2010-09-07 Thread Ben Finney
Phlip writes: > On Sep 7, 4:38 pm, Benjamin Kaplan wrote: > > > When you're using a language, you should use the style that the > > language emphasizes. > > You mean like this? > > uri = reverse('my_uri_name', kwargs=dict(pk=record.pk)) Do you think that style is emphasised by Python? What gi

Re: The Samurai Principle

2010-09-07 Thread Phlip
On Sep 7, 4:38 pm, Benjamin Kaplan wrote: > When you're using a language, you should use the style that the > language emphasizes. You mean like this? uri = reverse('my_uri_name', kwargs=dict(pk=record.pk)) That 'kwargs' there is ... a lapse of judgement. It is exposing a technical detail (t

Re: The Samurai Principle

2010-09-07 Thread Phlip
On Sep 7, 5:51 pm, Terry Reedy wrote: > On 9/7/2010 2:53 PM, Phlip wrote: > > > They are for situations which the caller should care not to handle. > > Python is simply not designed that way. Exception raising and catching > is a common flow-control method in Python. If you cannot stand that, > Py

Re: Queue cleanup

2010-09-07 Thread Gregory Ewing
Lawrence D'Oliveiro wrote: But alone of all of these, garbage collection still remains just as costly to implement as ever. That should tell you something about how poorly it matches the characteristics of modern computing hardware. So maybe we need to redesign the hardware. Perhaps referenc

Re: The Samurai Principle

2010-09-07 Thread Phlip
On Sep 7, 6:23 pm, Lawrence D'Oliveiro wrote: > Does catching the exception not defeat the “Samurai Principle”? Read my comic: http://c2.com/cgi/wiki?SamuraiPrinciple Exceptions are very dangerous by themselves, because if you don't trap them just right they can cause side-effects. They are

Re: The Samurai Principle

2010-09-07 Thread Gregory Ewing
Lawrence D'Oliveiro wrote: Does catching the exception not defeat the “Samurai Principle”? Not if it lets you turn defeat into victory. Or redefine victory so that it includes defeat. Or something. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Bug in Python 2.6 urlencode

2010-09-07 Thread John Nagle
On 9/7/2010 5:43 PM, Terry Reedy wrote: On 9/7/2010 3:02 PM, John Nagle wrote: There's a bug in Python 2.6's "urllib.urlencode". If you pass in a Unicode character outside the ASCII range, instead of it being encoded properly, an exception is raised. File "C:\python26\lib\urllib.py", line 1267,

Re: Speed-up for loops

2010-09-07 Thread MRAB
On 08/09/2010 02:45, BartC wrote: "David Cournapeau" wrote in message news:mailman.546.1283897932.29448.python-l...@python.org... On Sun, Sep 5, 2010 at 8:28 PM, BartC wrote: One order of magnitude (say 10-20x slower) wouldn't be so bad. That's what you might expect for a dynamically type

Re: Speed-up for loops

2010-09-07 Thread BartC
"David Cournapeau" wrote in message news:mailman.546.1283897932.29448.python-l...@python.org... On Sun, Sep 5, 2010 at 8:28 PM, BartC wrote: One order of magnitude (say 10-20x slower) wouldn't be so bad. That's what you might expect for a dynamically typed, interpreted language. 10/20x s

Re: what should __iter__ return?

2010-09-07 Thread Gregory Ewing
Thomas Jollans wrote: Hmm. Modifying an object while iterating over it isn't a great idea, ever: I wouldn't say never. Algorithms that calculate some kind of transitive closure can be expressed rather neatly by appending items to a list being iterated over. You can accommodate that kind of th

Re: The Samurai Principle

2010-09-07 Thread Lawrence D'Oliveiro
In message <74587da9-8861-4400-bbd7-1ea4f8182...@l38g2000pro.googlegroups.com>, Phlip wrote: > Pythonistas: > > The "Samurai Principle" says to return victorious, or not at all. This > is why django.db wisely throws an exception, instead of simply > returning None, if it encounters a "record not

Re: The Samurai Principle

2010-09-07 Thread Terry Reedy
On 9/7/2010 2:53 PM, Phlip wrote: They are for situations which the caller should care not to handle. Python is simply not designed that way. Exception raising and catching is a common flow-control method in Python. If you cannot stand that, Python is not for you. -- Terry Jan Reedy -- h

Re: Bug in Python 2.6 urlencode

2010-09-07 Thread Terry Reedy
On 9/7/2010 3:02 PM, John Nagle wrote: There's a bug in Python 2.6's "urllib.urlencode". If you pass in a Unicode character outside the ASCII range, instead of it being encoded properly, an exception is raised. File "C:\python26\lib\urllib.py", line 1267, in urlencode v = quote_plus(str(v)) U

Re: Speed-up for loops

2010-09-07 Thread Terry Reedy
On 9/7/2010 6:00 AM, BartC wrote: Why should it? But if you want it, you can do it: xrange = range There, that wasn't hard, was it? I think I just learned more about Python than from months of reading this group. So 'range' is just a class like any other. And that a class is something you c

Re: accessing a text file

2010-09-07 Thread Ben Finney
Baba writes: > However the following Wiki excerpt seems to go in my direction: No, it doesn't. It advises that people show kindness; as I've been arguing, that's exactly what you were shown. You haven't shown how the information being imparted could have been fully imparted in a way that's kinde

Re: (Webinar) Connecting the Dots: US SEC, ABS Mandates, Financial Modeling and Python

2010-09-07 Thread Jason Galyon
Will this webcast/webinar perform on Linux? Jason On Tue, 2010-09-07 at 14:08 -0700, Kendra Penrose wrote: > Connecting the Dots: US SEC, ABS Mandates, Financial Modeling and Python > > Date: Wednesday September 22, 2010python-announce-l...@python.org, > Time: 10:00am PST/1:00pm EST/ 17:00 UTC >

Re: include a file in a python program

2010-09-07 Thread bussiere maillist
Thanks all for your response i will try out this week, you have give me sufficient hint. Thanks again. Bussiere On Mon, Sep 6, 2010 at 9:50 AM, Niklasro(.appspot) wrote: > On Sep 5, 10:57 pm, bussiere bussiere wrote: >> i've got a python.txt that contain python and it must stay as it (python.txt

Re: The Samurai Principle

2010-09-07 Thread Benjamin Kaplan
On Tue, Sep 7, 2010 at 6:20 PM, Phlip wrote: > On Sep 7, 1:06 pm, Bruno Desthuilliers > wrote: > >> try: >>    return Model.objects.get(pk=42) >> except Model.DoesNotExist: >>    return sentinel > > Visual Basic Classic had a Collection Class, which worked essentially > like a real language's Has

Re: Queue cleanup

2010-09-07 Thread Gregory Ewing
Paul Rubin wrote: Now extrapolate that error rate from 30 lines to a program the size of Firefox (something like 5 MLOC), and you should see how fraught with danger that style of programming is. But you don't write 5 MLOC of code using that programming style. You use it to write a small core s

Re: compare dictionaries

2010-09-07 Thread MRAB
On 07/09/2010 22:36, Baba wrote: On 7 sep, 22:37, MRAB wrote: On 07/09/2010 21:06, Paul Rubin wrote: Babawrites: word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} i want to know if word is entirely composed of letters in dict2 set(word)<= set(dict2.keys()) Do the numb

Re: compare dictionaries

2010-09-07 Thread Gary Herron
On 09/07/2010 01:26 PM, Baba wrote: On 7 sep, 22:08, Gary Herron wrote: On 09/07/2010 12:46 PM, Baba wrote: word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} Just go through each letter of word checking for its existence in dict2. Return False if one misses, an

Re: formatted input

2010-09-07 Thread Kenny Meyer
Bob (roberto.pagli...@gmail.com) wrote: > Hi All, > I have another question about formatted input. Suppose I am reading a > text file, and that I want it to be something like this > > word11 = num11, word12 = num12, word13 = num13 etc... > word21 = num21, word22 = num12, word23 = num23 etc... > et

Re: The Samurai Principle

2010-09-07 Thread Phlip
On Sep 7, 1:06 pm, Bruno Desthuilliers wrote: > try: >    return Model.objects.get(pk=42) > except Model.DoesNotExist: >    return sentinel Visual Basic Classic had a Collection Class, which worked essentially like a real language's Hash, Map, or Dict. Except - it had no operation to test membe

Re: Speed-up for loops

2010-09-07 Thread David Cournapeau
On Sun, Sep 5, 2010 at 8:28 PM, BartC wrote: > > One order of magnitude (say 10-20x slower) wouldn't be so bad. That's what > you might expect for a dynamically typed, interpreted language. 10/20x slower than C is only reached by extremely well optimized dynamic languages. It would be a tremendo

Re: The Samurai Principle

2010-09-07 Thread Bruno Desthuilliers
Phlip a écrit : > On Sep 7, 10:36 am, Ian Kelly wrote: >> On Tue, Sep 7, 2010 at 10:02 AM, Phlip wrote: >>> Back to the topic, I tend to do this: >>> for record in Model.objects.filter(pk=42): >>> return record >>> return sentinel >> How is that any better than just catching the exception?

Re: The Samurai Principle

2010-09-07 Thread Bruno Desthuilliers
Phlip a écrit : > On Sep 7, 10:12 am, Bruno Desthuilliers 42.desthuilli...@websiteburo.invalid> wrote: >> Phlip a écrit : >> >>> Back to the topic, I tend to do this: >>> for record in Model.objects.filter(pk=42): >>> return record >>> return sentinel >> WTF alert here... > > I don't see

Re: formatted input

2010-09-07 Thread Diez B. Roggisch
Bob writes: > Hi All, > I have another question about formatted input. Suppose I am reading a > text file, and that I want it to be something like this > > word11 = num11, word12 = num12, word13 = num13 etc... > word21 = num21, word22 = num12, word23 = num23 etc... > etc... > > where wordx1 belon

Re: compare dictionaries

2010-09-07 Thread Paul Rubin
Baba writes: > for k in word.keys(): > if k not in hand: > return False > elif k in hand: > if word[k] > hand[k]: > return False > return True Untested: all(word[k] <= hand.get(k,0) for k in word) -- http://

Re: Help needed - function apparently global cannot be called.

2010-09-07 Thread Ian
Hi Rami, Stefan, Bruno. First a big thanks for your replies. On 07/09/2010 20:54, Rami Chowdhury wrote: Hi Ian, I think I see where you're going wrong -- this bit me too when I was learning Python, having come from PHP. Unlike PHP, when you import a module in Python it does *not* inherit th

Re: compare dictionaries

2010-09-07 Thread Baba
On 7 sep, 22:37, MRAB wrote: > On 07/09/2010 21:06, Paul Rubin wrote: > > > Baba  writes: > >> word= 'even' > >> dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > >> i want to know if word is entirely composed of letters in dict2 > > > set(word)<= set(dict2.keys()) > > Do the numbers in dict2 r

formatted input

2010-09-07 Thread Bob
Hi All, I have another question about formatted input. Suppose I am reading a text file, and that I want it to be something like this word11 = num11, word12 = num12, word13 = num13 etc... word21 = num21, word22 = num12, word23 = num23 etc... etc... where wordx1 belongs to a certain dictionary of

Re: compare dictionaries

2010-09-07 Thread Peter Otten
Baba wrote: > On 7 sep, 22:08, Gary Herron wrote: >> On 09/07/2010 12:46 PM, Baba wrote: >> >> > word= 'even' >> > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} >> >> Just go through each letter of word checking for its existence in >> dict2. Return False if one misses, and True if you get th

Re: compare dictionaries

2010-09-07 Thread Shashwat Anand
On Wed, Sep 8, 2010 at 1:56 AM, Baba wrote: > On 7 sep, 22:08, Gary Herron wrote: > > On 09/07/2010 12:46 PM, Baba wrote: > > > > > word= 'even' > > > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > > > Just go through each letter of word checking for its existence in > > dict2. Return Fal

Re: compare dictionaries

2010-09-07 Thread MRAB
On 07/09/2010 21:06, Paul Rubin wrote: Baba writes: word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} i want to know if word is entirely composed of letters in dict2 set(word)<= set(dict2.keys()) Do the numbers in dict2 represent the maximum number of times that the letter can

Re: can't send email

2010-09-07 Thread Ned Deily
In article , Bob wrote: >[...] > The error I get is this > > python email.py > Traceback (most recent call last): > File "email.py", line 2, in > import smtplib > File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/smtplib.py", line 46, in > import emai

Re: can't send email

2010-09-07 Thread Bob
On Sep 7, 10:27 pm, Chris Rebert wrote: > On Tue, Sep 7, 2010 at 1:12 PM, Bob wrote: > > Hello. > > I'm trying to send email using python 2.6.1 under snow leopard, but I > > can't get it to work. I'm trying one of the many examples I found on > > the web > > > The error I get is this > > > pytho

Re: compare dictionaries

2010-09-07 Thread Baba
On 7 sep, 22:08, Gary Herron wrote: > On 09/07/2010 12:46 PM, Baba wrote: > > > word= 'even' > > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > Just go through each letter of word checking for its existence in > dict2.  Return False if one misses, and True if you get through the > whole word

Re: can't send email

2010-09-07 Thread Chris Rebert
On Tue, Sep 7, 2010 at 1:12 PM, Bob wrote: > Hello. > I'm trying to send email using python 2.6.1 under snow leopard, but I > can't get it to work. I'm trying one of the many examples I found on > the web > The error I get is this > > python email.py > Traceback (most recent call last): >  File "

Re: compare dictionaries

2010-09-07 Thread Gary Herron
On 09/07/2010 12:46 PM, Baba wrote: word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} Just go through each letter of word checking for its existence in dict2. Return False if one misses, and True if you get through the whole word: def ...(): for c in word: if c not in

can't send email

2010-09-07 Thread Bob
Hello. I'm trying to send email using python 2.6.1 under snow leopard, but I can't get it to work. I'm trying one of the many examples I found on the web EXAMPLE 1 import smtplib fromaddr = 'fromu...@gmail.com' toaddrs = 'tou...@gmail.com' msg = 'There was a terrible error that occured and I wan

Re: compare dictionaries

2010-09-07 Thread Paul Rubin
Baba writes: > word= 'even' > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > i want to know if word is entirely composed of letters in dict2 set(word) <= set(dict2.keys()) -- http://mail.python.org/mailman/listinfo/python-list

Re: Help needed - function apparently global cannot be called.

2010-09-07 Thread Stefan Schwarzer
Hi Ian, On 2010-09-07 12:18, Ian Hobson wrote: > f = open('d:\logfile.txt','a') Just a note: Using a backslash in a non-raw string will get you in trouble as soon as the backslash is followed by a character which makes a special character sequence, like "\n". For example, f = open('d:\nice_

Re: Help needed - function apparently global cannot be called.

2010-09-07 Thread Rami Chowdhury
Hi Ian, On Tue, Sep 7, 2010 at 20:00, Ian wrote: > On 07/09/2010 11:50, Bruno Desthuilliers wrote: > > note the order of the above - log is defined before the import. > > And ? Do you think it will affect the imported module in any way ? Like, > say, magically "inject" your log function in the

compare dictionaries

2010-09-07 Thread Baba
level: beginner word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} i want to know if word is entirely composed of letters in dict2 my approach: step 1 : convert word to dictionary(dict1) step2: for k in dict1.keys(): if k in dict2: if dict1[k] != dict2[k]:

Re: The Samurai Principle

2010-09-07 Thread Tim Chase
On 09/07/10 13:53, Phlip wrote: On Sep 7, 11:36 am, Tim Chase wrote: And no it's not "much clearer". Exceptions are for catastrophic errors that the caller should care not to handle. A "record not found" is not a catastrophe. Exceptions are not limited to catastrophic errors, simply exceptio

Re: Queue cleanup

2010-09-07 Thread Paul Rubin
Lawrence D'Oliveiro writes: > But you’ll notice that Free Software comes with no such > restrictions. In fact, it is contrary to commonly-accepted Free > Software guidelines to impose any sort of restrictions on areas of use. Free software comes with an explicit disclaimer of liability (you get w

Re: Bug in Python 2.6 urlencode

2010-09-07 Thread Ned Deily
In article <4c868c2d$0$1581$742ec...@news.sonic.net>, John Nagle wrote: > Is it worth reporting 2.x bugs any more? Or are we in the > version suckage period, where version N is abandonware and > version N+1 isn't deployable yet. Yes!! 2.7 is being actively maintained for bug fixes. (2.6 o

Re: Bit fields in python?

2010-09-07 Thread John Nagle
On 9/6/2010 11:55 PM, Stefan Behnel wrote: Kwan Lai Cheng, 07.09.2010 06:06: I'm trying to rewrite a c program in python& encountered several problems. I have some data structures in my c program like below: def __init__(self, size=0) Any equivalent for c data structures& bit fields in pytho

Bug in Python 2.6 urlencode

2010-09-07 Thread John Nagle
There's a bug in Python 2.6's "urllib.urlencode". If you pass in a Unicode character outside the ASCII range, instead of it being encoded properly, an exception is raised. File "C:\python26\lib\urllib.py", line 1267, in urlencode v = quote_plus(str(v)) UnicodeEncodeError: 'ascii' codec

Re: The Samurai Principle

2010-09-07 Thread Phlip
On Sep 7, 11:36 am, Tim Chase wrote: > > And no it's not "much clearer". Exceptions are for catastrophic errors > > that the caller should care not to handle. A "record not found" is not > > a catastrophe. > > Exceptions are not limited to catastrophic errors, simply > exceptional (not the common

Re: The Samurai Principle

2010-09-07 Thread Tim Chase
On 09/07/10 12:52, Phlip wrote: try: return Model.objects.get(pk=42) except Model.DoesNotExist: return sentinel The flow of control is much clearer this way. It reminds me of Visual Basic. And no it's not "much clearer". Exceptions are for catastrophic errors that the caller should

Re: Bit fields in python?

2010-09-07 Thread Terry Reedy
On 9/7/2010 12:06 AM, Kwan Lai Cheng wrote: Hi, I'm trying to rewrite a c program in python & encountered several problems. I have some data structures in my c program like below: typedef struct { unsigned short size; unsigned short reserved:8; unsigned short var_a1:2; unsigned short var_a2:2; un

Re: The Samurai Principle

2010-09-07 Thread Ian Kelly
On Tue, Sep 7, 2010 at 11:52 AM, Phlip wrote: > And no it's not "much clearer". It's clearer because it does exactly what it says it does, unlike your approach that masquerades as a loop. > Exceptions are for catastrophic errors No, they're for flagging "exceptional" states. /Errors/ are for c

Re: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0]))

2010-09-07 Thread Terry Reedy
On 9/7/2010 9:24 AM, sajuptpm wrote: I have a list of tuples. l = [((30,50),(70)), ((50,20),(20))] for i in range(10): k = ((i+30,i+50),(i+70)) The (i+70) parens do nothing, as already explained to (20) Your set of test data are not very good as they do not test all the insertion po

Re: What the \xc2\xa0 ?!!

2010-09-07 Thread John Roth
On Sep 7, 11:01 am, Brian D wrote: > In an HTML page that I'm scraping using urllib2, a  \xc2\xa0 > bytestring appears. > > The page's charset = utf-8, and the Chrome browser I'm using displays > the characters as a space. > > The page requires authentication:https://www.nolaready.info/myalertlog.

Re: The Samurai Principle

2010-09-07 Thread Phlip
On Sep 7, 10:36 am, Ian Kelly wrote: > On Tue, Sep 7, 2010 at 10:02 AM, Phlip wrote: > > Back to the topic, I tend to do this: > > >  for record in Model.objects.filter(pk=42): > >     return record > > >  return sentinel > > How is that any better than just catching the exception? > > try: >    

Re: accessing a text file

2010-09-07 Thread Baba
On 7 sep, 16:50, Grant Edwards wrote: > On 2010-09-07, Baba wrote: > > > Sloppy wording, I apologise. This should say: If you find the > > question you're reading too easy then just don't answer. Noone is the > > owner of a democratic forum where freedom to ask the question one > > likes is param

Re: The Samurai Principle

2010-09-07 Thread Ian Kelly
On Tue, Sep 7, 2010 at 10:02 AM, Phlip wrote: > Back to the topic, I tend to do this: > >  for record in Model.objects.filter(pk=42): >     return record > >  return sentinel How is that any better than just catching the exception? try: return Model.objects.get(pk=42) except Model.DoesNotExi

Re: Speed-up for loops

2010-09-07 Thread Aahz
In article , Roy Smith wrote: > >Imagine that you're looking at some code which was written years ago, by >people who are no longer around to answer questions. In one place, you >see: > >for i in range(n): > blah > >and in another, you see: > >for j in xrange(n): > blah > >If you are truly

datetime questions

2010-09-07 Thread Niklasro
Hello Learning python datetime somewhat similar to SQL type timestamp my attempt creating a 24 h 2 months ago is str(datetime.now () - timedelta (days = 60)) +' cron '+ str(datetime.now () - timedelta (days = 59)) Do you agree? Can I improve this declaration? Regards Niklas Rosencrantz -- http:/

Re: The Samurai Principle

2010-09-07 Thread Phlip
On Sep 7, 10:12 am, Bruno Desthuilliers wrote: > Phlip a écrit : > > > Back to the topic, I tend to do this: > > >   for record in Model.objects.filter(pk=42): > >      return record > > >   return sentinel > > WTF alert here... I don't see how anyone could WTF that. Are you pretending to be a ne

Re: What the \xc2\xa0 ?!!

2010-09-07 Thread Diez B. Roggisch
Brian D writes: > In an HTML page that I'm scraping using urllib2, a \xc2\xa0 > bytestring appears. > > The page's charset = utf-8, and the Chrome browser I'm using displays > the characters as a space. > > The page requires authentication: > https://www.nolaready.info/myalertlog.php > > When I

Re: The Samurai Principle

2010-09-07 Thread Bruno Desthuilliers
Phlip a écrit : Back to the topic, I tend to do this: for record in Model.objects.filter(pk=42): return record return sentinel WTF alert here... Having lots of short methods helps, because return provides both control-flow and a result value. But it abuses 'for' to mean 'if'. I fee

What the \xc2\xa0 ?!!

2010-09-07 Thread Brian D
In an HTML page that I'm scraping using urllib2, a \xc2\xa0 bytestring appears. The page's charset = utf-8, and the Chrome browser I'm using displays the characters as a space. The page requires authentication: https://www.nolaready.info/myalertlog.php When I try to concatenate strings containi

Re: accessing a text file

2010-09-07 Thread geremy condra
On Tue, Sep 7, 2010 at 4:39 AM, Baba wrote: > On 7 sep, 02:18, Ben Finney wrote: >> Ben Finney writes: >> > We value respect for people here, and that's what you've been shown >> > consistently. But respect for opinions, or for delicacy about >> > learning, is not welcome here. >> >> Sloppy word

Re: The Samurai Principle

2010-09-07 Thread Phlip
Back to the topic, I tend to do this: for record in Model.objects.filter(pk=42): return record return sentinel Having lots of short methods helps, because return provides both control-flow and a result value. But it abuses 'for' to mean 'if'. I feel _rally_ guilty about that! But I

audio time-stretching?

2010-09-07 Thread kj
Does anyone know of a Python module for *moderate* "time-stretching"[1] an MP3 (or AIFF) file? FWIW, the audio I want to time-stretch is human speech. TIA! ~K [1] By "moderate time stretching" I mean, for example, taking an audio that would normally play in 5 seconds, and stretch it so that i

Re: Minimum and Maximum of a list containing floating point numbers

2010-09-07 Thread nn
On Sep 6, 10:31 pm, Steven D'Aprano wrote: > On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: > > If you're going to use the list of float objects, you can convert them > > all with a list comprehension. > [...] > >     >>> numbers_as_float = [float(x) for x in numbers_as_str] > > That's awfu

Re: accessing a text file

2010-09-07 Thread Grant Edwards
On 2010-09-07, Baba wrote: > Sloppy wording, I apologise. This should say: If you find the > question you're reading too easy then just don't answer. Noone is the > owner of a democratic forum where freedom to ask the question one > likes is paramount (as long of course as it is related to the >

Volunteer help with porting

2010-09-07 Thread Prashant Kumar
Hi everyone, My name is Prashant Kumar and I wish to contribute to the Python development process by helping convert certain existing python over to python3k. Is there anyway I could obtain a list of libraries which need to be ported over to python3k, sorted by importance(by importance i mean pac

Re: knowing the caller of an import && exec question

2010-09-07 Thread Bruno Desthuilliers
bussiere bussiere a écrit : i've got toto.py : import titi def niwhom(): pass and titi.py : def nipang(): pass how can i know in titi.py that's it's toto.py that is calling titi.py and the path of toto ? You'd have to inspect the call stack. Not for the faint at heart... And w

Re: mutate dictionary or list

2010-09-07 Thread Ben Finney
de...@web.de writes: > Objects can be mutable or immutable. For example, in Python, integers, > strings, floats and tuples are immutable. That means that you can't > change their value. Yes. Importantly, wherever you see code that you *think* is changing the value of an immutable object, you're t

Re: Speed-up for loops

2010-09-07 Thread Aahz
In article , BartC wrote: >"Steven D'Aprano" wrote in message >news:4c85adfe$0$5$c3e8...@news.astraweb.com... >> >> xrange = range >> >> There, that wasn't hard, was it? > >I think I just learned more about Python than from months of reading this >group. > >So 'range' is just a class like an

Re: accessing a text file

2010-09-07 Thread Ben Finney
Baba writes: > to say "Please do us a favour and at least try to figure things out on > your own" is in my view inappropriate. That's what the person wanted you to see. How would you prefer that exact information to be imparted to you? How could it have been communicated so that it was not misun

Re: Help needed - function apparently global cannot be called.

2010-09-07 Thread Ian
Hi Bruno, Thanks for your quick response. I still do not understand. On 07/09/2010 11:50, Bruno Desthuilliers wrote: Ian Hobson a écrit : Hi all you experts, This has me beat. Has anyone any ideas about what might be going wrong? This is code from within a windows service (hence no print s

Re: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0]))

2010-09-07 Thread Peter Otten
sajuptpm wrote: > On Sep 7, 7:03 pm, Peter Otten <__pete...@web.de> wrote: >> sajuptpm wrote: >> > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in >> > another way .I want to know what the modification needed in the 'if' >> > check to sort this list of tuples in k[0][0] ascending

knowing the caller of an import && exec question

2010-09-07 Thread bussiere bussiere
i've got toto.py : import titi def niwhom(): pass and titi.py : def nipang(): pass how can i know in titi.py that's it's toto.py that is calling titi.py and the path of toto ? And why : bidule.py : class bidetmusique: pass truc.py : X = __import__("bidule") why exec("X

Re: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0]))

2010-09-07 Thread sajuptpm
On Sep 7, 7:03 pm, Peter Otten <__pete...@web.de> wrote: > sajuptpm wrote: > > i need to implement  l.sort(key=lambda x:(x[0][0], -x[1][0])) in > > another way .I want to know what the modification needed in the 'if' > > check to sort this list of tuples in k[0][0] ascending and k[0][1] > > descend

Re: The Samurai Principle

2010-09-07 Thread geremy condra
On Tue, Sep 7, 2010 at 6:56 AM, Bruno Desthuilliers wrote: > Phlip a écrit : >>> >>> How does that compare to, say, the "Kamikaze Principle"? ;) >> >> Return victorious AND not at all! >> >> (All return values are packed up and thrown...;) > > ... and then it raises a SystemError !-) general prot

Re: mutate dictionary or list

2010-09-07 Thread deets
Baba writes: > Hi > > I am working on an exercise which requires me to write a funtion that > will check if a given word can be found in a given dictionary (the > hand). > > def is_valid_word(word, hand, word_list): > """ > Returns True if word is in the word_list and is entirely > co

Re: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0]))

2010-09-07 Thread Peter Otten
sajuptpm wrote: > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in > another way .I want to know what the modification needed in the 'if' > check to sort this list of tuples in k[0][0] ascending and k[0][1] > descending. It seems you are not getting any closer to your goal. Perhap

Re: Help needed - function apparently global cannot be called.

2010-09-07 Thread Bruno Desthuilliers
Ian Hobson a écrit : (snip) you may also want to read the recent "using modules" thread... -- http://mail.python.org/mailman/listinfo/python-list

Re: The Samurai Principle

2010-09-07 Thread Bruno Desthuilliers
Phlip a écrit : How does that compare to, say, the "Kamikaze Principle"? ;) Return victorious AND not at all! (All return values are packed up and thrown...;) ... and then it raises a SystemError !-) -- http://mail.python.org/mailman/listinfo/python-list

Re: mutate dictionary or list

2010-09-07 Thread Bruno Desthuilliers
Baba a écrit : Hi I am working on an exercise which requires me to write a funtion that will check if a given word can be found in a given dictionary (the hand). def is_valid_word(word, hand, word_list): """ Returns True if word is in the word_list and is entirely composed of letter

Re: accessing a text file

2010-09-07 Thread Bruno Desthuilliers
Baba a écrit : (snip) If i had received a friendly response from Benjamin (as opposed to "Please do us a favor and at least try to figure things out on your own") According to usenet standards and given your initial question, this is a _very_ friendly answer. -- http://mail.python.org/mailman

Re: The Samurai Principle

2010-09-07 Thread Phlip
> How does that compare to, say, the "Kamikaze Principle"? ;) Return victorious AND not at all! (All return values are packed up and thrown...;) -- http://mail.python.org/mailman/listinfo/python-list

another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0]))

2010-09-07 Thread sajuptpm
I have a list of tuples. l = [((30,50),(70)), ((50,20),(20))] for i in range(10): k = ((i+30,i+50),(i+70))#suppose creating new tuple in each iteration using some random value and in sert it into list. flag=True for i, v in enumerate(l): if v >= k:

Re: mutate dictionary or list

2010-09-07 Thread Xavier Ho
On 7 September 2010 22:05, Baba wrote: > > It would be great if someone could give me a brief explanantion of the > mutation concept. > In this case, to mutate is to change. If you must not mutate the list, you must not change it. In another words, reading from the list is fine. Writing to it i

Pydev 1.6.2 Released

2010-09-07 Thread Fabio Zadrozny
Hi All, Pydev 1.6.2 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: --- * Pydev is now also distributed with Aptana Studio 3, so it can be gotten in a version that doesn't require installi

Re: Speed-up for loops

2010-09-07 Thread Roy Smith
In article , "BartC" wrote: > (BTW why doesn't Python 3 just accept 'xrange' as a > synonym for 'range'?) If you've ever tried to maintain a legacy code base, you'll understand why "there's only one way to do it" is A Good Thing. Imagine that you're looking at some code which was written yea

  1   2   >