Re: extra rows in a CSV module output when viewed in excel 2007

2010-08-12 Thread alex23
On Aug 13, 4:22 pm, JonathanB wrote: >         writer = csv.writer(open(output, 'w'), dialect='excel') I think - not able to test atm - that if you open the file in 'wb' mode instead it should be fine. -- http://mail.python.org/mailman/listinfo/python-list

extra rows in a CSV module output when viewed in excel 2007

2010-08-12 Thread JonathanB
The subject basically says it all, here's the code that's producing the csv file: def write2CSV(self,output): writer = csv.writer(open(output, 'w'), dialect='excel') writer.writerow(['Name','Description','Due Date','Subject', 'Grade','Maximum Grade', se

Re: easy question on parsing python: "is not None"

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 19:52:07 -0700, Matt Schinckel wrote: a = "hello" b = "hello" a is b > True > > Ooh, that looks dangerous. Are they the same object? You don't need another test to know that they are the same object. The `is` operator does exactly that: a is b *only* if a and

Re: default behavior

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 13:28:26 -0700, David Niergarth wrote: > Peter Otten <[email protected]> wrote: >> >> >>> 1 .conjugate() >> >> > This is a syntax I never noticed before. My built-in complier (eyes) > took one look and said: "that doesn't work." Has this always worked in > Python but I never not

Re: EXOR or symmetric difference for the Counter class

2010-08-12 Thread Chris Rebert
On Thu, Aug 12, 2010 at 10:36 PM, Steven D'Aprano wrote: > On Thu, 12 Aug 2010 13:20:19 -0700, Paddy wrote: > >> I find myself needing to calculate the difference between two Counters >> or multisets or bags. > > Is this collections.Counter from Python 3.1? "Changed in version **2.7**: Added Coun

Re: inline exception handling in python

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 14:19:13 -0400, wheres pythonmonks wrote: > I think the problem in my case is best solved by look before you leap, > or a wrapper function. [I just hate function call overhead for this. ] Sounds suspiciously like premature micro-optimization to me. Function call overhead is

Re: inline exception handling in python

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 20:08:01 +0200, Thomas Jollans wrote: [...] > Besides, more often than not, you want to have a finally clause around > when you're dealing with exceptions. Oh I don't know about that. Doing a quick and totally unscientific survey of my own code, I find that try...except with n

Re: Importing libs on Windows?

2010-08-12 Thread Nobody
On Thu, 12 Aug 2010 16:09:10 -0700, Brian Salter wrote: > I've seen a number of tutorials that describe how to bring in a dll in > python, but does anybody know of a tutorial for how to bring in a lib? Is > it even possible? No. ctypes relies upon the OS to actually load the library, and the O

Re: EXOR or symmetric difference for the Counter class

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 13:20:19 -0700, Paddy wrote: > I find myself needing to calculate the difference between two Counters > or multisets or bags. Is this collections.Counter from Python 3.1? If so, you should say so, and if not, you should tell us which Counter class this is. It will save peopl

Re: Floating numbers

2010-08-12 Thread Nobody
On Thu, 12 Aug 2010 18:19:40 -0700, Benjamin Kaplan wrote: > But that's not keeping the number the way it was typed. It's just not > showing you the exact approximation. Nor is 34.523 showing you the "exact approximation". The closest "double" to 34.52 is 4858258098025923 / 2**47, wh

Re: easy question on parsing python: "is not None"

2010-08-12 Thread Terry Reedy
On 8/12/2010 10:52 PM, Matt Schinckel wrote: a = "hello" b = "hello" a is b True Ooh, that looks dangerous. Only for mutable objects Are they the same object? Yes. a += "o" This is equivalent to a = a+"o". The expression creates a new object. The assignment binds the object to name

Re: Inserting/Deleting newline(s) in very large text files

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 21:25:59 +0200, Thomas Jollans wrote: > Everybody agrees that text files > should end with a line feed, because some text editors might mess up if > they don't. For some definition of "everybody". Obviously the text editors which DON'T mess up don't make the assumption that a

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread Lawrence D'Oliveiro
In message , Jean- Michel Pichavant wrote: > for mcNugget in range(0,10): > sendTo(trashbin) Ah, but should that be mcNugget.sendTo(trashbin) or trashbin.insert(mcNugget) ? -- http://mail.python.org/mailman/listinfo/python-list

morethen 34, 100, 617 active members r waiting 4 live hot chat, dating ...

2010-08-12 Thread UR DREEM GIRL
morethen 34,100,617 active members r waiting 4 live hot chat, dating ... free and eazy to meet and enjoy just click start http://adultfriendfinder.com/go/page/reg_form_video_03?pid=g1250650-ppc http://adultfriendfinder.com/go/page/reg_form_video_03?pid=g1250650-ppc http://adultfr

Re: Decompressing a file retrieved by URL seems too complex

2010-08-12 Thread Aahz
In article <[email protected]>, John Nagle wrote: > >I'm reading a URL which is a .gz file, and decompressing it. This >works, but it seems far too complex. Yet none of the "wrapping" >you might expect to work actually does. You can't wrap a GzipFile >around an HTTP conne

Re: easy question on parsing python: "is not None"

2010-08-12 Thread Matt Schinckel
On Aug 6, 8:15 am, "Rhodri James" wrote: > On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks   > > wrote: > > Well, I am not convinced of the equivalence of not None and true: [snip] > >>> "spam, eggs, chips and spam" is "spam, eggs, chips and spam" > True > >>> a = "spam, eggs, chips and sp

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread John Posner
On 8/12/2010 6:31 PM, News123 wrote: candidate_box_counts = product( xrange(target/box_sizes[0] + 1), xrange(target/box_sizes[1] + 1), xrange(target/box_sizes[2] + 1), ) Couldn't this be rewritten as: candidate_box_counts = product( * [ xrange

Re: re.sub and variables

2010-08-12 Thread MRAB
Steven D'Aprano wrote: On Thu, 12 Aug 2010 14:33:28 -0700, fuglyducky wrote: if anyone happens to know about passing a variable into a regex that would be great. The same way you pass anything into any string. Regexes are ordinary strings. If you want to construct a string from a variable t

Re: Floating numbers

2010-08-12 Thread Ned Deily
In article , Benjamin Kaplan wrote: > > Well, it is a *bit* of a Python issue since, as others have pointed out, > > Python's behavior has changed due to the implementation of Gay's > > rounding algorithm in 3.1 and also in 2.7: > > > > $ python2.6 -c 'print(repr(34.52))' > > 34.523

Re: re.sub and variables

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 14:33:28 -0700, fuglyducky wrote: > if anyone happens to know about > passing a variable into a regex that would be great. The same way you pass anything into any string. Regexes are ordinary strings. If you want to construct a string from a variable t = "orl", you can do an

Re: Importing libs on Windows?

2010-08-12 Thread Tycho Andersen
On Thu, Aug 12, 2010 at 04:09:10PM -0700, Brian Salter wrote: > I've seen a number of tutorials that describe how to bring in a dll > in python, but does anybody know of a tutorial for how to bring in a > lib? Is it even possible? I don't know if it's possible, but why do you want to do it? .lib

Re: Floating numbers

2010-08-12 Thread Benjamin Kaplan
On Thu, Aug 12, 2010 at 6:14 PM, Ned Deily wrote: > In article , >  Christian Heimes wrote: >>> Is there a way I can keep my floating point number as I typed it? For >>> example, I want 34.52 to be 34.52 and NOT 34.520002. >> This isn't a Python issue. Python uses IEEE 754 [1] double precisio

Re: Floating numbers

2010-08-12 Thread Ned Deily
In article , Christian Heimes wrote: >> Is there a way I can keep my floating point number as I typed it? For >> example, I want 34.52 to be 34.52 and NOT 34.520002. > This isn't a Python issue. Python uses IEEE 754 [1] double precision > floats like most other languages. 34.52 can't be stor

Re: Importing libs on Windows?

2010-08-12 Thread Brian Salter
It appears that every example is calling a dll, and I'm looking to bring in a lib. Does ctypes work with libs too? "Gary Herron" wrote in message news:[email protected]... On 08/12/2010 04:09 PM, Brian Salter wrote: I've seen a number of tutorials that descr

Re: Importing libs on Windows?

2010-08-12 Thread Gary Herron
On 08/12/2010 04:09 PM, Brian Salter wrote: I've seen a number of tutorials that describe how to bring in a dll in python, but does anybody know of a tutorial for how to bring in a lib? Is it even possible? Thanks, in advance! Look at the Python module named ctypes: http://docs.python.

Re: re.sub and variables

2010-08-12 Thread John Machin
On Aug 13, 7:33 am, fuglyducky wrote: > On Aug 12, 2:06 pm, fuglyducky wrote: > > > > > I have a function that I am attempting to call from another file. I am > > attempting to replace a string using re.sub with another string. The > > problem is that the second string is a variable. When I get t

Importing libs on Windows?

2010-08-12 Thread Brian Salter
I've seen a number of tutorials that describe how to bring in a dll in python, but does anybody know of a tutorial for how to bring in a lib? Is it even possible? Thanks, in advance! -- http://mail.python.org/mailman/listinfo/python-list

Re: segfault with small pyqt script

2010-08-12 Thread Lee Harr
> I'm desperate. I'm having a real application, which fails rather often > when finishing it. I'm not sure, whether any serious problem could be > hidden behind it > > The script is a pyqt script, which segfaults most of the time on my > ubuntu 10.4 linux 64 bit and I'm having trouble to understan

Re: unicode string alteration

2010-08-12 Thread BAvant Garde
Thanks MRAB, I'll have to do some reading about unicode surrogates. Also need to research which python versions/platforms are narrow builds and which are wide. Much to learn here. Thanks!  --- On Thu, 8/12/10, MRAB wrote: From: MRAB Subject: Re: unicode string alteration To: python-list@p

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread News123
On 08/12/2010 10:51 PM, John Posner wrote: > On 8/12/2010 9:22 AM, Dave Angel wrote: >>> >>> Now you have to find the largest number below 120, which you can >>> easily do with brute force > > Dept of overkill, iterators/generators division ... > > -John > > #-- > from itertools

Re: inline exception handling in python

2010-08-12 Thread Carey Tilden
On Thu, Aug 12, 2010 at 1:18 PM, wheres pythonmonks wrote: > Well I suppose it matters depending on the nature of the data you are > looking at...  But small function calls tend to be the death of interpreted > languages... I would be interested to see a real application that had performance neg

Re: Decompressing a file retrieved by URL seems too complex

2010-08-12 Thread Thomas Jollans
On Thursday 12 August 2010, it occurred to John Nagle to exclaim: > (Repost with better indentation) Good, good. > > def readurl(url) : > if url.endswith(".gz") : The file name could be anything. You should be checking the reponse Content- Type header -- that's what it's for. > n

Re: Python "why" questions

2010-08-12 Thread Hexamorph
Terry Reedy wrote: On 8/9/2010 11:16 AM, Grant Edwards wrote: Just for the record: I sincerely apologize for my rant. I usually don't loose control so heavily, but this "Rick" person makes me mad (killfile'd now) IOW, the "Ugly American". No! That's not what I said. I'm myself one of tho

Re: re.sub and variables

2010-08-12 Thread fuglyducky
On Aug 12, 2:06 pm, fuglyducky wrote: > I have a function that I am attempting to call from another file. I am > attempting to replace a string using re.sub with another string. The > problem is that the second string is a variable. When I get the > output, it shows the variable name rather than t

Re: Floating numbers

2010-08-12 Thread Christian Heimes
> Is there a way I can keep my floating point number as I typed it? For > example, I want 34.52 to be 34.52 and NOT 34.520002. This isn't a Python issue. Python uses IEEE 754 [1] double precision floats like most other languages. 34.52 can't be stored in a float. The next valid float is 34.520

Re: Floating numbers

2010-08-12 Thread Grant Edwards
On 2010-08-12, Grant Edwards wrote: >> Here are the nitty-gritty details: >> >> http://docs.sun.com/source/806-3568/ncg_goldberg.html > > Here is a gentler intro: > > http://pyfaq.infogami.com/why-are-floating-point-calculations-so-inaccurate And another good page: http://docs.python.org/t

Re: Floating numbers

2010-08-12 Thread Chris Rebert
On Thu, Aug 12, 2010 at 1:43 PM, Bradley Hintze wrote: > Hi all. > > Is there a way I can keep my floating point number as I typed it? For > example, I want 34.52 to be 34.52 and NOT 34.520002. See also: http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_ro

Re: Floating numbers

2010-08-12 Thread Thomas Jollans
On Thursday 12 August 2010, it occurred to Bradley Hintze to exclaim: > Hi all. > > Is there a way I can keep my floating point number as I typed it? For > example, I want 34.52 to be 34.52 and NOT 34.520002. The conversion from decimal to binary and vice versa is inexact -- but they're the

Re: Floating numbers

2010-08-12 Thread Philip Semanchuk
On Aug 12, 2010, at 4:43 PM, Bradley Hintze wrote: Hi all. Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. Hi Bradley, Use the Decimal type instead. It's not as convenient as float, but it will give you a consis

Re: Floating numbers

2010-08-12 Thread Grant Edwards
On 2010-08-12, Grant Edwards wrote: > On 2010-08-12, Bradley Hintze wrote: > >> Is there a way I can keep my floating point number as I typed it? > > No. > >> For example, I want 34.52 to be 34.52 and NOT 34.520002. > > You can't represent 34.52 using base-2 IEEE floating point (the HW > floa

Re: Floating numbers

2010-08-12 Thread Grant Edwards
On 2010-08-12, Bradley Hintze wrote: > Is there a way I can keep my floating point number as I typed it? No. > For example, I want 34.52 to be 34.52 and NOT 34.520002. You can't represent 34.52 using base-2 IEEE floating point (the HW floating point format used by pretty much all modern co

Re: Floating numbers

2010-08-12 Thread Gary Herron
On 08/12/2010 01:43 PM, Bradley Hintze wrote: Hi all. Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. Is this a Python question? The answer is both Yes and No. The binary floating point representation of nu

re.sub and variables

2010-08-12 Thread fuglyducky
I have a function that I am attempting to call from another file. I am attempting to replace a string using re.sub with another string. The problem is that the second string is a variable. When I get the output, it shows the variable name rather than the value. Is there any way to pass a variable i

Re: default behavior

2010-08-12 Thread Peter Otten
David Niergarth wrote: > [Oops, now complete...] > Peter Otten <[email protected]> wrote: >> >> > >>> 1 .conjugate() >> > This is a syntax I never noticed before. My built-in complier (eyes) > took one look and said: "that doesn't work." (1).conjugate may hurt a little less. Anyway, the space is

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread John Posner
On 8/12/2010 9:22 AM, Dave Angel wrote: Now you have to find the largest number below 120, which you can easily do with brute force Dept of overkill, iterators/generators division ... -John #-- from itertools import imap, product, ifilter from operator import mul box_sizes =

Re: looping through possible combinations of McNuggets packs of 6,9 and 20

2010-08-12 Thread News123
On 08/12/2010 09:56 PM, Martin P. Hellwig wrote: > On 08/11/10 21:14, Baba wrote: > > > How about rephrasing that question in your mind first, i.e.: > > For every number that is one higher then the previous one*: > If this number is dividable by: > 6 or 9 or 20 or any combination of

Decompressing a file retrieved by URL seems too complex

2010-08-12 Thread John Nagle
(Repost with better indentation) I'm reading a URL which is a .gz file, and decompressing it. This works, but it seems far too complex. Yet none of the "wrapping" you might expect to work actually does. You can't wrap a GzipFile around an HTTP connection, because GzipFile, reasonably enough,

Floating numbers

2010-08-12 Thread Bradley Hintze
Hi all. Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. -- Bradley J. Hintze Graduate Student Duke University School of Medicine 801-712-8799 -- http://mail.python.org/mailman/listinfo/python-list

Re: default behavior

2010-08-12 Thread David Niergarth
[Oops, now complete...] Peter Otten <[email protected]> wrote: > > > >>> 1 .conjugate() > This is a syntax I never noticed before. My built-in complier (eyes) took one look and said: "that doesn't work." Has this always worked in Python but I never noticed? I see other instance examples also work.

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread News123
One more small tip to verify whether your code is working: On 08/12/2010 10:28 PM, News123 wrote: > Hi Baba, Your code, but returning the result as suggested in my preious post: > def can_buy(n_nuggets): >for a in range (1,n_nuggets): >for b in range (1,n_nuggets): >for

Re: shelf-like list?

2010-08-12 Thread Thomas Jollans
On Tuesday 10 August 2010, it occurred to kj to exclaim: > I'm looking for a module that implements "persistent lists": objects > that behave like lists except that all their elements are stored > on disk. IOW, the equivalent of "shelves", but for lists rather > than a dictionaries. > > Does anyo

Re: default behavior

2010-08-12 Thread David Niergarth
Peter Otten <[email protected]> wrote: > > >>> 1 .conjugate() > This is a syntax I never noticed before. My built-in complier (eyes) took one look and said: "that doesn't work." Has this always worked in Python but I never noticed? I see other instance examples also work. >>> '1' .zfill(2) '01

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread News123
Hi Baba, The last tips should really help you getting started: for testing your function you could do: Below your uncorrected code and a test for it def can_buy(n_nuggets): for a in range (1,n_nuggets): for b in range (1,n_nuggets): for c in range (1,n_nuggets):

EXOR or symmetric difference for the Counter class

2010-08-12 Thread Paddy
I find myself needing to calculate the difference between two Counters or multisets or bags. I want those items that are unique to each bag. I know how to calculate it: >>> b = Counter(a=1, b=2) >>> c = Counter(a=3, b=1) >>> diff = (b - c) + (c - b) >>> (b - c) Counter({'b': 1

Decompressing a file retrieved by URL seems too complex

2010-08-12 Thread John Nagle
I'm reading a URL which is a .gz file, and decompressing it. This works, but it seems far too complex. Yet none of the "wrapping" you might expect to work actually does. You can't wrap a GzipFile around an HTTP connection, because GzipFile, reasonably enough, needs random access, and tries t

Re: inline exception handling in python

2010-08-12 Thread wheres pythonmonks
On Thu, Aug 12, 2010 at 2:57 PM, Thomas Jollans wrote: > On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: >> [I just hate function call overhead for this.] > > I think you've got your priorities wrong. If you want to avoid unnecessary > overhead, avoid exceptions more than

Re: Announcing: python-ghostscript 0.3

2010-08-12 Thread Peter Kleiweg
Aahz schreef op de 12e dag van de oogstmaand van het jaar 2010: > In article , > Peter Kleiweg wrote: > >Hartmut Goebel schreef op de 12e dag van de oogstmaand van het jaar 2010: > > > >> Here is an example for how to use the high-level interface of > >> `python-ghostscript`. This implements a v

Re: looping through possible combinations of McNuggets packs of 6,9 and 20

2010-08-12 Thread Martin P. Hellwig
On 08/11/10 21:14, Baba wrote: How about rephrasing that question in your mind first, i.e.: For every number that is one higher then the previous one*: If this number is dividable by: 6 or 9 or 20 or any combination of 6, 9, 20 than this number _can_ be bought in an exac

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread Roald de Vries
On Aug 12, 2010, at 9:02 PM, Peter Otten wrote: Baba wrote: Thank You for helping me out. Indeed i am not looking for the code but rather for hints that direct my reasoning as well as hints as to how to write basic programs like this. You have broken down the approach into 2 parts. I have

Re: Why can't I set sys.ps1 to a unicode string?

2010-08-12 Thread Thomas Jollans
On Thursday 12 August 2010, it occurred to RG to exclaim: > %%% /&%%% > > If this were a properly unicode-enabled newsreader you would see a > yin-yang symbol in the middle of s2. Are you sure about that? Now maybe the mailing list gateway is messing things up, but I rather suspect your newsread

Re: Announcing: python-ghostscript 0.3

2010-08-12 Thread Aahz
In article , Peter Kleiweg wrote: >Hartmut Goebel schreef op de 12e dag van de oogstmaand van het jaar 2010: > >> Here is an example for how to use the high-level interface of >> `python-ghostscript`. This implements a very basic ps2pdf-tool:: >> >> import sys >> import ghostscript >> >>

Re: Line-by-line processing when stdin is not a tty

2010-08-12 Thread Nobody
On Wed, 11 Aug 2010 18:49:26 -0700, RG wrote: > This doesn't explain why "cat | cat" when run interactively outputs > line-by-line (which it does). STDIN to the first cat is a TTY, but the > second one isn't. GNU cat doesn't use stdio, it uses read() and write(), so there isn't any buffering.

Re: exception handling with sqlite db errors

2010-08-12 Thread Aahz
In article <2a47b306-45d1-474a-9f8e-5b71eba62...@p11g2000prf.googlegroups.com>, CM wrote: > >Maybe it's not much of an issue, but I think it would be a shame if >occasional hangs/crashes could be caused by these (rare?) database >conflicts if there is a good approach for avoiding them. I guess I

Re: looping through possible combinations of McNuggets packs of 6,9 and 20

2010-08-12 Thread MRAB
Baba wrote: Hi News123 Thank You for helping me out. Indeed i am not looking for the code but rather for hints that direct my reasoning as well as hints as to how to write basic programs like this. You have broken down the approach into 2 parts. I have tried to solve part 1 but i'm not quite th

Re: Inserting/Deleting newline(s) in very large text files

2010-08-12 Thread Thomas Jollans
On Thursday 12 August 2010, it occurred to Dlanor Slegov to exclaim: > Hi, > > I am dealing with very large text files (a few million lines) and would > like to check and modify them according to a well defined format. The > format requires ONLY ONE NEWLINE (followed by some sort of text) on top o

Re: image resize doesn't work

2010-08-12 Thread Aahz
In article , Chris Hare wrote: > >And I see now what I did wrong - thanks for putting up with the questions. Posting that information is useful for any other newbies who might be following along -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "...if I were

Re: urllib2 does not implement "with" Python 2.6

2010-08-12 Thread Terry Reedy
On 8/12/2010 1:34 AM, John Nagle wrote: Somewhat to my surprise, in Python 2.6, with urllib2.urlopen(url) as fh : doesn't work. It fails with "AttributeError: addinfourl instance has no attribute '__exit__'". I thought that all the file-like objects supported "with" in 2.6. No? This seems

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread Peter Otten
Baba wrote: > Thank You for helping me out. Indeed i am not looking for the code but > rather for hints that direct my reasoning as well as hints as to how > to write basic programs like this. > > You have broken down the approach into 2 parts. I have tried to solve > part 1 but i'm not quite th

Re: cx_Oracle 5.0.4 + Python 3.1.2 + Oracle Instant Client 10.2.04; DLL Load failed on import (Win/NT)

2010-08-12 Thread tormod
On Aug 12, 12:30 pm, Alexander Gattin wrote: > Does Windows have anything like > LD_LIBRARY_PATH/SHLIB_PATH? No, isn't that only if I have an actual Oracle client installed (not the instant client)? But great tip, wasn't exactly the solution, but your question triggered me to check the Windows e

Re: looping through possible combinations of McNuggets packs of 6,9 and 20

2010-08-12 Thread Brian Victor
Baba wrote: > def can_buy(n_nuggets): [snip] > can_buy(55) > > as you can see i am trying to loop through all combinations of values > bewtween 1 and n_nuggets and when the equation resolves it should > return True, else it should return False. > > I was hoping that when i then call my function and

Re: inline exception handling in python

2010-08-12 Thread Thomas Jollans
On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: > [I just hate function call overhead for this.] I think you've got your priorities wrong. If you want to avoid unnecessary overhead, avoid exceptions more than functions. -- http://mail.python.org/mailman/listinfo/python

Re: inline exception handling in python

2010-08-12 Thread wheres pythonmonks
On Thu, Aug 12, 2010 at 2:42 PM, MRAB wrote: > wheres pythonmonks wrote: >> >> Hi! >> >> I have on a few occasions now wanted to have inline-exception >> handling, like the inline if/else operator. >> >> For example, >> >> The following might raise ZeroDivisionError: >> >> f = n / d >> >> So, I ca

Re: inline exception handling in python

2010-08-12 Thread MRAB
wheres pythonmonks wrote: Hi! I have on a few occasions now wanted to have inline-exception handling, like the inline if/else operator. For example, The following might raise ZeroDivisionError: f = n / d So, I can look before I leap (which is okay): f = float("nan") if d == 0 else n/d; But

Re: looping through possible combinations of McNuggets packs of 6,9 and 20

2010-08-12 Thread Baba
Hi News123 Thank You for helping me out. Indeed i am not looking for the code but rather for hints that direct my reasoning as well as hints as to how to write basic programs like this. You have broken down the approach into 2 parts. I have tried to solve part 1 but i'm not quite there yet. Here'

Re: inline exception handling in python

2010-08-12 Thread wheres pythonmonks
On Thu, Aug 12, 2010 at 2:19 PM, wheres pythonmonks wrote: > On Thu, Aug 12, 2010 at 2:08 PM, Thomas Jollans wrote: >> On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: >>> try: >>>    f = n / d >>> except: >>>    f = float("nan") >> >> A catch-all except clause. Never a g

Re: inline exception handling in python

2010-08-12 Thread wheres pythonmonks
On Thu, Aug 12, 2010 at 2:08 PM, Thomas Jollans wrote: > On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: >> try: >>    f = n / d >> except: >>    f = float("nan") > > A catch-all except clause. Never a good idea. It's not as bad in this case, as > there is only one expres

Re: inline exception handling in python

2010-08-12 Thread Thomas Jollans
On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: > try: >f = n / d > except: >f = float("nan") A catch-all except clause. Never a good idea. It's not as bad in this case, as there is only one expression, but there are still a couple of other exceptions that have

Re: OptParse and Constant values

2010-08-12 Thread J
On Thu, Aug 12, 2010 at 12:41, Robert Kern wrote: > On 8/12/10 11:19 AM, J wrote: >> >> How do you use OptParse with constants? > http://docs.python.org/library/optparse#standard-option-actions > > 'store_const' means that the option is a flag without arguments and stores > the value provided by

inline exception handling in python

2010-08-12 Thread wheres pythonmonks
Hi! I have on a few occasions now wanted to have inline-exception handling, like the inline if/else operator. For example, The following might raise ZeroDivisionError: f = n / d So, I can look before I leap (which is okay): f = float("nan") if d == 0 else n/d; But, what I'd like to be able t

Re: Why can't I set sys.ps1 to a unicode string?

2010-08-12 Thread RG
In article , "Martin v. Loewis" wrote: > > So... why does having a non-ascii character in sys.ps1 make the prompt > > vanish? > > I can't pinpoint it to a specific line of code. Most likely, it tries > to encode the prompt as ASCII before writing it to stdout. That fails, > and it silently ign

Re: unicode string alteration

2010-08-12 Thread MRAB
BAvant Garde wrote: HELP!!! I need help with a unicode issue that has me stumped. I must be doing something wrong because I don't believe this condition would have slipped thru testing. Wherever the string u'\udbff\udc00' occurs u'\U0010fc00' or unichr(1113088) is substituted and the file l

Re: Long rant about Python in Education

2010-08-12 Thread John Bokma
"D'Arcy J.M. Cain" writes: > On Thu, 12 Aug 2010 05:05:55 -0700 (PDT) > เข้านอน wrote: >> have to teach them to enjoy programming, enjoy computers, and develop >> their minds in a way that doesn't involve becoming 'Imams' who are >> essentially the learned mafia bosses of terrorism. > > This is

Re: OptParse and Constant values

2010-08-12 Thread Robert Kern
On 8/12/10 11:19 AM, J wrote: How do you use OptParse with constants? Example: usage = 'Usage: %prog [OPTIONS]' parser = OptionParser(usage) parser.add_option('-l','--level', action='store_const', default=LOG_INFO, he

OptParse and Constant values

2010-08-12 Thread J
How do you use OptParse with constants? Example: usage = 'Usage: %prog [OPTIONS]' parser = OptionParser(usage) parser.add_option('-l','--level', action='store_const', default=LOG_INFO, help='Set the log level to inject into

Re: Renaming OS files by file type in python

2010-08-12 Thread MRAB
blur959 wrote: Hi all, I am creating a program that renames all files of the similar file type. But i am stuck at this part. I tried running this code and I got this error:new_name = os.rename(path, newpath) WindowsError: [Error 183] Cannot create a file when that file already exists. Hope yo

Extract stack from running python program

2010-08-12 Thread Zac Burns
Is there a utility to extract the stacks from a running python program that is hung? Sounds like a long shot but if anyone knows it would be you guys. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer Zindagi Games -- http://mail.python.org/mailman/listinfo/python-list

How to parse a sentence using grammars provided by nltk?

2010-08-12 Thread Sohail
Hi, When I define my own production rules for the grammar the code below runs fine. Can anyone tell me how to use the built in grammars of nltk (if there are any)? >>> groucho_grammar = nltk.parse_cfg(""" ... S -> NP VP ... PP -> P NP ... NP -> Det N | Det N PP | 'I' ... VP -> V NP | VP PP ... De

unicode string alteration

2010-08-12 Thread BAvant Garde
HELP!!! I need help with a unicode issue that has me stumped. I must be doing something  wrong because I don't believe this condition would have slipped thru testing. Wherever the string u'\udbff\udc00' occurs u'\U0010fc00' or unichr(1113088) is substituted and the file loses 1 character result

Re: Announcing: python-ghostscript 0.3

2010-08-12 Thread Peter Kleiweg
Hartmut Goebel schreef op de 12e dag van de oogstmaand van het jaar 2010: > Here is an example for how to use the high-level interface of > `python-ghostscript`. This implements a very basic ps2pdf-tool:: > > import sys > import ghostscript > > args = [ > "ps2pdf", # actual val

Re: Programming Puzzles? What's your favorite puzzle?

2010-08-12 Thread Ian Kelly
On Thu, Aug 12, 2010 at 5:41 AM, Matty Sarro wrote: > Hey All! > Hope your thursday is treating you well. I'm looking for suggestions on > books of programming/engineering puzzles that range from beginners to > advanced and even expert level problems. I know they exist; we had them back > in colle

Announcing: python-ghostscript 0.3

2010-08-12 Thread Hartmut Goebel
Announcing: python-ghostscript 0.3 A Python-Interface to the Ghostscript C-API using ctypes :Copyright: GNU Public License v3 (GPLv3) :Author: Hartmut Goebel :Homepage: http://bitbucket.org/htgoebel/python-ghostscript :Download:

Inserting/Deleting newline(s) in very large text files

2010-08-12 Thread Dlanor Slegov
Hi, I am dealing with very large text files (a few million lines) and would like to check and modify them according to a well defined format. The format requires ONLY ONE NEWLINE (followed by some sort of text) on top of the file and NO NEWLINE in the very end. The input files can be very dive

Re: __class__ of what

2010-08-12 Thread Stefan Schwarzer
Hello Jean-Michel, On 2010-08-12 16:06, Jean-Michel Pichavant wrote: > Eric J. Van der Velden wrote: > Should be > > class C: > n = 0 > def __init__(self): >self.__class__.n+=1 >C.n+=1 # equivalent to this line (I prefer this one, more > readable, less refactor-friendly)

Re: Using elementtree to Create HTML Form / Set "selected"

2010-08-12 Thread Doug
On Aug 12, 10:47 am, Peter Otten <[email protected]> wrote: > Doug wrote: > > I'm using elementtree to create a form. > > > I would like to set the "selected" attribute. > > > Setting using the usual > >  option.set( "selected" = "" ) > > Maybe that should be option.set(selected="selected"). I think

Re: Using elementtree to Create HTML Form / Set "selected"

2010-08-12 Thread Peter Otten
Doug wrote: > I'm using elementtree to create a form. > > I would like to set the "selected" attribute. > > Setting using the usual > option.set( "selected" = "" ) Maybe that should be option.set(selected="selected"). I think and are equivalent. http://www.w3.org/TR/html4/intro/sgmltut.

Re: __class__ of what

2010-08-12 Thread Peter Otten
Eric J. Van der Velden wrote: > I have, > > class C: > n=0 > def __init__(s): > __class__.n+=1 > > > I do C() > > This is fine. But of what thing I am taking the __class__ of? > I can also do > > @staticmethod > def p(): > p

Re: __class__ of what

2010-08-12 Thread Eric Brunel
In article <72151646-65cb-47bb-bd55-e7eb67577...@z10g2000yqb.googlegroups.com>, "Eric J. Van der Velden" wrote: > Hello, > > I have, > > class C: > n=0 > def __init__(s): > __class__.n+=1 > > > I do > >>> C() > > This is fine. No it's not, at least in Pytho

Re: __class__ of what

2010-08-12 Thread Jean-Michel Pichavant
Eric J. Van der Velden wrote: Hello, I have, class C: n=0 def __init__(s): __class__.n+=1 Should be class C: n = 0 def __init__(self): self.__class__.n+=1 C.n+=1 # equivalent to this line (I prefer this one, more readable, less refactor-

Re: Does anyone use Quixote for web developing?

2010-08-12 Thread ph4nut
On Aug 12, 5:40 pm, Bruno Desthuilliers wrote: > ph4nut a écrit : > > > Hi all,I am learning Quixote a few days ago,,,and i have no idea about > > whether there is any Google Group talking about Quixote,so i post this > > post to check that is Quixote been talking in this group before or can > > i

Re: Does anyone use Quixote for web developing?

2010-08-12 Thread ph4nut
On Aug 12, 5:40 pm, Bruno Desthuilliers wrote: > ph4nut a écrit : > > > Hi all,I am learning Quixote a few days ago,,,and i have no idea about > > whether there is any Google Group talking about Quixote,so i post this > > post to check that is Quixote been talking in this group before or can > > i

  1   2   >