Re: Nested Mapping

2010-10-21 Thread Arnaud Delobelle
Raymond Hettinger writes: > I'm considering a nested mapping class for the collections module and > would like to solicit feedback from people here on comp.lang.python: > > > http://code.activestate.com/recipes/577434-nested-contexts-a-chain-of-mapping-objects/ > Django has such contexts in

ANN: wxPython 2.9.1.1

2010-10-21 Thread Robin Dunn
Announcing -- The 2.9.1.1 release of wxPython is now available for download at http://wxpython.org/download.php. This is the first official release in the 2.9 development release series. There are lots and lots of new widgets and other awesome stuff that have been added since the 2.8 se

Help Needed - Using Safenet( Previously, Aladdin) HASP Hardware Lock with Python

2010-10-21 Thread Bishwarup Banerjee
Dear All, It will be very kind of you, if you can let me know (Or point to some links), how to use HASP Hardware Lock using Python ? I am trying to handle Hardware Lock authentication for our project, but cant find any clear cut solution. I am using python 2.5 on windows XP platform. With Warm R

Re: pythagorean triples exercise

2010-10-21 Thread Terry Reedy
On 10/21/2010 7:55 PM, Baba wrote: the bit i'm having difficulties with in constructing my loops is: "whose small sides are no larger than n" from math import sqrt def py_trips(n): for b in range(4,n+1): for a in range(3,b+1): cf = sqrt(a*a+b*b) c = int(cf) if c == cf

removing a post from python

2010-10-21 Thread Mike L
http://www.mail-archive.com/python-list@python.org/msg175722.html hello could you remove above post... off topic and spam thank you -- http://mail.python.org/mailman/listinfo/python-list

Re: functions, list, default parameters

2010-10-21 Thread Andreas Waldenburger
On Thu, 21 Oct 2010 19:53:53 -0700 John Nagle wrote: > On 10/21/2010 2:51 PM, Chris Rebert wrote: > > On Thu, Oct 21, 2010 at 2:36 PM, Sean Choi wrote: > >> I found two similar questions in the mailing list, but I didn't > >> understand the explanations. > >> I ran this code on Ubuntu 10.04 with

Re: functions, list, default parameters

2010-10-21 Thread John Nagle
On 10/21/2010 2:51 PM, Chris Rebert wrote: On Thu, Oct 21, 2010 at 2:36 PM, Sean Choi wrote: I found two similar questions in the mailing list, but I didn't understand the explanations. I ran this code on Ubuntu 10.04 with Python 2.6.5. Why do the functions g and behave differently? If cal

Re: Ideas on how to parse a dynamically generated html pages

2010-10-21 Thread Tim Harig
On 2010-10-22, chad wrote: > Let's say there is a site that uses javascript to generate menus. More > or less what happens is when a person clicks on url, a pop up menu > appears asking the users for some data. How would I go about > automating this? Just curious because the web spider doesn't act

Ideas on how to parse a dynamically generated html pages

2010-10-21 Thread chad
Let's say there is a site that uses javascript to generate menus. More or less what happens is when a person clicks on url, a pop up menu appears asking the users for some data. How would I go about automating this? Just curious because the web spider doesn't actually pick up the urls that generate

Earn unlimited in Management careers.

2010-10-21 Thread gaurav
Additional income resources - Fresher or experience candidate can grow career http://managementjobs.webs.com/pm.htm Get careers in Management work. Careers recruitments. http://topcareer.webs.com/businessmanagement.htm Work from home genuine bulk data entry, home and government jobs sources. http

Re: Nested Mapping

2010-10-21 Thread Paul Rubin
Raymond Hettinger writes: > The c.parent.parent.parent chain finds successive enclosing contexts: I was asking about finding the child contexts, not the parents. This is analogous to how you can find the keys in a dict with dict.keys(). >> One question: what should >> >>    c["foo"] = 7 >>    d

Re: Nested Mapping

2010-10-21 Thread Raymond Hettinger
On Oct 21, 5:18 pm, Paul Rubin wrote: > The API you suggested looks reasonable although you should also say how > to delete a context, how to find the inner contexts of a context, etc. The c.parent.parent.parent chain finds successive enclosing contexts: while c.parent is not None: pri

Re: Nested Mapping

2010-10-21 Thread Paul Rubin
Raymond Hettinger writes: > Hopefully, that discussion can be in a separate thread. > This is really about keeping all the nice O(1) characteristics > of dicts and keeping their straight-forward API while adding > the ability to support nested lookups. Are you saying the O(1) characteristics are

Re: pythagorean triples exercise

2010-10-21 Thread Baba
On Oct 21, 10:18 pm, Terry Reedy wrote: > On 10/21/2010 6:55 AM, Baba wrote: > > > Hi everyone > > > i need a hint regarding the following exercise question: > > > "Write a program that generates all Pythagorean triples whose small > > sides are no larger than n. > > This is not well worded. I tak

Re: Nested Mapping

2010-10-21 Thread Raymond Hettinger
On Oct 21, 4:28 pm, Paul Rubin wrote: > Raymond Hettinger writes: > What I really want is a Haskell-like persistent (i.e. purely functional) > dictionary implemented as an AVL tree or something like that. Hopefully, that discussion can be in a separate thread. This is really about keeping all th

Re: Nested Mapping

2010-10-21 Thread Paul Rubin
Raymond Hettinger writes: > I would appreciate any feedback on the API and on how well it fits > with various use cases that you've found in the wild. What I really want is a Haskell-like persistent (i.e. purely functional) dictionary implemented as an AVL tree or something like that. It means t

Nested Mapping

2010-10-21 Thread Raymond Hettinger
I'm considering a nested mapping class for the collections module and would like to solicit feedback from people here on comp.lang.python: http://code.activestate.com/recipes/577434-nested-contexts-a-chain-of-mapping-objects/ The class is an attempt to generalize from existing use cases (i.e.

Re: socket.sendto / UDP problem

2010-10-21 Thread MRAB
On 21/10/2010 21:05, Todd Walter wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 21 Oct 2010 17:03:58 +0100 MRAB wrote: On 21/10/2010 15:57, Todd Walter wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 21 Oct 2010 00:07:58 +0100 MRAB wrote: [snip] The docs fo

question regarding thread display on python mailing list

2010-10-21 Thread Sean Choi
I notice sometimes when I follow a thread on the mailing list archives, the thread will not be all together. To see what I mean, look at the thread "splitting comp.lang.python" as shown here: http://mail.python.org/pipermail/python-list/2000-March/thread.html#639685. You can see one large chunk of

Re: python shell silently ignores termios.tcsetattr()

2010-10-21 Thread Nobody
On Wed, 20 Oct 2010 16:18:57 +, kj wrote: > I tried to fix the problem by applying the equivalent of "stty -echo" > within a python interactive session, but discovered that this setting is > immediately (and silently) overwritten. FWIW, I don't see this behaviour with Python 2.6.5 on Linux. I

Re: functions, list, default parameters

2010-10-21 Thread Chris Rebert
On Thu, Oct 21, 2010 at 2:36 PM, Sean Choi wrote: > I found two similar questions in the mailing list, but I didn't understand > the explanations. > I ran this code on Ubuntu 10.04 with Python 2.6.5. > Why do the functions g and behave differently? If calls (3) and > g(3) both exit their

Re: how do I search python mailing list archives?

2010-10-21 Thread Sean Choi
just sending out a late thank you for the response -- http://mail.python.org/mailman/listinfo/python-list

functions, list, default parameters

2010-10-21 Thread Sean Choi
I found two similar questions in the mailing list, but I didn't understand the explanations. I ran this code on Ubuntu 10.04 with Python 2.6.5. Why do the functions g and behave differently? If calls (3) and g(3) both exit their functions in the same state, why do they not enter in the s

Re: pythagorean triples exercise

2010-10-21 Thread Terry Reedy
On 10/21/2010 6:55 AM, Baba wrote: Hi everyone i need a hint regarding the following exercise question: "Write a program that generates all Pythagorean triples whose small sides are no larger than n. This is not well worded. I take 'small sides' (plural) to mean the two smaller, non-hypotenu

Re: socket.sendto / UDP problem

2010-10-21 Thread Todd Walter
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 21 Oct 2010 17:03:58 +0100 MRAB wrote: > On 21/10/2010 15:57, Todd Walter wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA1 > > > > On Thu, 21 Oct 2010 00:07:58 +0100 > > MRAB wrote: > > > >>> > >> [snip] > >> > >> The docs for 's

Re: Python has a "really hidden encapsulation"?

2010-10-21 Thread Arnaud Delobelle
dmytro starosud writes: > Hello, > I'm Python beginner (from Ukraine). > I may have found the way to really hide attributes in Python class. > The whole control on this attribute is implemented inside of the > class. > *(code is below, Python 3) > You see that we can't get the reference to instan

Re: Python has a "really hidden encapsulation"?

2010-10-21 Thread dmytro starosud
Thanks for answer, Attribute accessing inside the class is implemented by getters and setters: "min_set", "min_get", "max_set" and "max_get". You can put your logic to this functions and parameter "prop" is the direct reference to this property. I can create a "really read-only attribute", and oth

Re: embarrassing class question

2010-10-21 Thread Robert Kern
On 10/21/10 2:12 PM, Brendan wrote: On Oct 21, 3:56 pm, Ethan Furman wrote: Jonas H. wrote: On 10/21/2010 08:09 PM, Brendan wrote: Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line: import y dir(y) ['__builtins

Re: embarrassing class question

2010-10-21 Thread Carl Banks
On Oct 21, 11:53 am, Brendan wrote: > On Oct 21, 3:47 pm, Carl Banks wrote: > > On Oct 21, 11:09 am, Brendan wrote: > > > > Two modules: > > > x.py: > > > class x(object): > > >     pass > > > > y.py: > > > from x import x > > > class y(x): > > >     pass > > > > Now from the python command line

Re: embarrassing class question

2010-10-21 Thread Brendan
On Oct 21, 3:56 pm, Ethan Furman wrote: > Jonas H. wrote: > > On 10/21/2010 08:09 PM, Brendan wrote: > >> Two modules: > >> x.py: > >> class x(object): > >>      pass > > >> y.py: > >> from x import x > >> class y(x): > >>      pass > > >> Now from the python command line: > > import y > >

Re: embarrassing class question

2010-10-21 Thread Ian
On Oct 21, 12:53 pm, Brendan wrote: > So it must never make sense to put subclasses in separate modules? It doesn't matter to Python whether the subclass is in the same module or imported. Do it whichever way makes the most sense to you from a code organization perspective. -- http://mail.pytho

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Arnaud Delobelle
Steven D'Aprano writes: > On Thu, 21 Oct 2010 11:37:36 +0200, Jean-Michel Pichavant wrote: > By the way: > >> xCoordinate, yCoordinate, zCoordinate = polygon.nextPointCoordinates() > > Coordinates are pairs or triples of *ordinates* (no "co"). You can't have > an "x coordinate" -- that would be

Re: embarrassing class question

2010-10-21 Thread Robert Kern
On 10/21/10 1:53 PM, Brendan wrote: On Oct 21, 3:47 pm, Carl Banks wrote: On Oct 21, 11:09 am, Brendan wrote: Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line:>>> import y dir(y) ['__builtins__', '__doc_

Re: embarrassing class question

2010-10-21 Thread Chris Rebert
On Thu, Oct 21, 2010 at 11:53 AM, Brendan wrote: > On Oct 21, 3:47 pm, Carl Banks wrote: >> On Oct 21, 11:09 am, Brendan wrote: >> > Two modules: >> > x.py: >> > class x(object): >> >     pass >> >> > y.py: >> > from x import x >> > class y(x): >> >     pass >> >> > Now from the python command l

Re: python shell silently ignores termios.tcsetattr()

2010-10-21 Thread kj
In Lawrence D'Oliveiro writes: >In message , kj wrote: >> I tried to fix the problem by applying the equivalent of "stty >> -echo" within a python interactive session, but discovered that >> this setting is immediately (and silently) overwritten. >That seems reasonable behaviour; the command

Re: embarrassing class question

2010-10-21 Thread Ethan Furman
Jonas H. wrote: On 10/21/2010 08:09 PM, Brendan wrote: Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line: import y dir(y) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x', 'y'] I do not understand

Re: embarrassing class question

2010-10-21 Thread Brendan
On Oct 21, 3:47 pm, Carl Banks wrote: > On Oct 21, 11:09 am, Brendan wrote: > > > > > > > Two modules: > > x.py: > > class x(object): > >     pass > > > y.py: > > from x import x > > class y(x): > >     pass > > > Now from the python command line:>>> import y > > >>> dir(y) > > > ['__builtins__',

Re: embarrassing class question

2010-10-21 Thread Carl Banks
On Oct 21, 11:09 am, Brendan wrote: > Two modules: > x.py: > class x(object): >     pass > > y.py: > from x import x > class y(x): >     pass > > Now from the python command line:>>> import y > >>> dir(y) > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > 'x', 'y'] > > I do n

Re: Spreadsheet-style dependency tracking

2010-10-21 Thread Stefaan Himpe
Florian Weimer wrote: Are there libraries which implement some form of spreadsheet-style dependency tracking? The first that come to mind (I have very limited experience with them): trellis http://peak.telecommunity.com/DevCenter/Trellis pycells http://pycells.pdxcb.net/ Best regards, Stefaa

Re: Python has a "really hidden encapsulation"?

2010-10-21 Thread Carl Banks
On Oct 21, 9:49 am, dmytro starosud wrote: > Hello, > I'm Python beginner (from Ukraine). > I may have found the way to really hide attributes in Python class. > The whole control on this attribute is implemented inside of the > class. > *(code is below, Python 3) > You see that we can't get the r

Re: embarrassing class question

2010-10-21 Thread Jonas H.
On 10/21/2010 08:09 PM, Brendan wrote: Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line: import y dir(y) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x', 'y'] I do not understand why class 'x' sh

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Seebs
On 2010-10-21, Jean-Michel Pichavant wrote: > It can be short if descriptive: > for o, c in cars: > park(o) > phone(c) > for owner, car in cars: # by just using meaningful names you give the > info to the reader that you expect cars to be a list of tuple (owner, car) > park(owner) >

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Seebs
On 2010-10-21, Jean-Michel Pichavant wrote: > Let me quote the paper I linked in the previous post: > > list1 = [] > for x in theList: > if x[0] == 4: > list1 += x; > return list1 > > compare it to: > > flaggedCells = [] > for cell in theBoard: > if cell[STATUS_VALUE] == FLAGGED:

embarrassing class question

2010-10-21 Thread Brendan
Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line: >>> import y >>> dir(y) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x', 'y'] I do not understand why class 'x' shows up here. -- http://mail.python.o

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Seebs
On 2010-10-21, Jean-Michel Pichavant wrote: > In the middle of thousand lines of code, when you are reviewing or > debugging, the later is better TMO, the point is that x, y, z = is only > easy to read during the assignement. Bull. > x, y, z = p.nextpoint() > [snip a dozen of code line] > ...

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Seebs
On 2010-10-21, Martin P. Hellwig wrote: > Although intuitively I would say the shorthand, however that is > depending on the context being me knowing at least the basics of 3d > spaces and having the pre-warning that you are going to mention > something with either coordinates or colours. > Ta

Re: socket.sendto / UDP problem

2010-10-21 Thread Todd Walter
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 21 Oct 2010 17:03:58 +0100 MRAB wrote: > On 21/10/2010 15:57, Todd Walter wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA1 > > > > On Thu, 21 Oct 2010 00:07:58 +0100 > > MRAB wrote: > > > >>> > >> [snip] > >> > >> The docs for 's

Python has a "really hidden encapsulation"?

2010-10-21 Thread dmytro starosud
Hello, I'm Python beginner (from Ukraine). I may have found the way to really hide attributes in Python class. The whole control on this attribute is implemented inside of the class. *(code is below, Python 3) You see that we can't get the reference to instance of class "en_property" outside the cl

Re: how to scrutch a dict()

2010-10-21 Thread John Nagle
On 10/20/2010 9:32 PM, Phlip wrote: Not Hyp: def _scrunch(**dict): result = {} for key, value in dict.items(): if value is not None: result[key] = value return result That says "throw away every item in a dict if the Value is None". Are there any tighter or smarmier

Re: Python3: Is this a bug in urllib?

2010-10-21 Thread Johannes Bauer
Am 20.10.2010 14:32, schrieb Justin Ezequiel: > On Oct 20, 12:47 am, Johannes Bauer wrote: >> > from urllib import request; request.URLopener().open("http://google.de";) > > aren't you supposed to call read on the return value of open? > i.e., > request.URLopener().open("http://google.de";).re

Re: socket.sendto / UDP problem

2010-10-21 Thread MRAB
On 21/10/2010 15:57, Todd Walter wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 21 Oct 2010 00:07:58 +0100 MRAB wrote: [snip] The docs for 'sendto' say: """The socket should not be connected to a remote socket, since the destination socket is specified by address."""

Re: memory management - avoid swapping/paging

2010-10-21 Thread Nobody
On Thu, 21 Oct 2010 02:34:15 -0700, Jon Clements wrote: > I'm after something that says: "I want 512mb of physical RAM, I don't > want you to page/swap it, if you can't do that, don't bother at all". > Now I'm guessing, that an OS might be able to grant that, but later on > have to kill the proces

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Neil Cerutti
On 2010-10-21, Jean-Michel Pichavant wrote: > So If I get you right, because comments can lie, we should stop > using comments? No, but use comment judiciously. Kernighan and Pike (_The Practice of Programming_) recommend writing your code to require as little comment as possible. They provide ty

Re: Filename for stdout

2010-10-21 Thread Nobody
Richard Gibbs wrote: > If my python script is called with stdout (or stdin or stderr) > redirected to a file, how can I find the filename under Linux?  Under > Windows? On Linux, you can read the /proc/self/fd/* symlinks, e.g.: stdin_filename = os.readlink('/proc/self/fd/0') This isn't

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Jean-Michel Pichavant
Mel wrote: Steven D'Aprano wrote: On Thu, 21 Oct 2010 12:49:47 +, Neil Cerutti wrote: _The Practice of Programming_ has this right. In general the bigger the scope of a variable, the longer and more descriptive should be its name. In a small scope, a big name is mostly noise.

Re: socket.sendto / UDP problem

2010-10-21 Thread Todd Walter
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 21 Oct 2010 00:07:58 +0100 MRAB wrote: > > > [snip] > > The docs for 'sendto' say: > > """The socket should not be connected to a remote socket, since > the destination socket is specified by address.""" > > Could your problem be caus

Re: pythagorean triples exercise

2010-10-21 Thread Jeffrey Gaynor
What you want is to realize that all integer Pythagorean triples can be generated by a pair of integers, (i,j), j < i. The values are just (* = multiply, ^ = exponentiation) a = 2*i*j b = i^2 - j^2 c = i^2 + j^2 (hypotenuse) So yes indeed a^2 + b^2 = c^2. This is a very ancient result, btw and

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Mel
Steven D'Aprano wrote: > On Thu, 21 Oct 2010 12:49:47 +, Neil Cerutti wrote: > >> _The Practice of Programming_ has this right. In general the bigger the >> scope of a variable, the longer and more descriptive should be its name. >> In a small scope, a big name is mostly noise. > > Thank you

Re: how to scrutch a dict()

2010-10-21 Thread Hrvoje Niksic
Joost Molenaar writes: > Using a 2.7/3.x dictionary comprehension, since you don't seem to mind > creating a new dictionary: > > def _scrunched(d): >     return { key: value for (key, value) in d.items() if value is not None } Note that a dict comprehension, while convenient, is not necessary fo

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Jean-Michel Pichavant
You won't be that happy everyone wrote their mail in this list like a mobile text message, if u c what I mean. I never suggested that. What I am trying to get across is that long names are not automatically better than short names, and even one letter names can be as good or better than

Python script executable

2010-10-21 Thread kostia
Hi all, I'm working with glite grid middleware. This is the server-side program which allows to calculate exe or sh files using languages like python, c++ and so on. No matter, my question is following: I need to make my python script executable to be able to run it under the glite. I have found

Re: Has Next in Python Iterators

2010-10-21 Thread Paul Rudin
Kelson Zawack writes: > Since an iterator having an end is not actually an exceptional case... There's no requirement on iterators to be finite, so in a sense it is. In general it may be impractical to know whether an iterator has reached the end without calling next(). -- http://mail.python

Re: how to scrutch a dict()

2010-10-21 Thread Phlip
> for k in [k for k, v in d.items() if v is None]: >   del d[k] Tx everyone! And I forgot about shadowing dict(), I forgot about del d[k], and I didn't know Python had "dict comprehensions" yet. Anyway this one might become the winner. -- http://mail.python.org/mailman/listinfo/python-list

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Steven D'Aprano
On Thu, 21 Oct 2010 11:27:57 +0200, Jean-Michel Pichavant wrote: > There is another important point: the time where code size matters is > over. That's ridiculous. Which would you rather write? import os if os.path.exists("myfile"): print open("myfile").read() or this? import the modul

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Steven D'Aprano
On Thu, 21 Oct 2010 12:49:47 +, Neil Cerutti wrote: > _The Practice of Programming_ has this right. In general the bigger the > scope of a variable, the longer and more descriptive should be its name. > In a small scope, a big name is mostly noise. Thank you! The scope of the variable is an i

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Steven D'Aprano
On Thu, 21 Oct 2010 11:37:36 +0200, Jean-Michel Pichavant wrote: > In the middle of thousand lines of code, If you have a function that is a thousand lines of code long, I don't care what you name the variables, you won't be able to keep it straight in your head. This is one of the reasons wh

Re: Unicode questions

2010-10-21 Thread OdarR
On Oct 19, 9:02 pm, Tobiah wrote: > I've been reading about the Unicode today. > I'm only vaguely understanding what it is > and how it works. > ... > Thanks, > > Tobiah Hi, A good advice, read this presentation, http://farmdev.com/talks/unicode/ Explanation and advices for coding. Olivier --

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Neil Cerutti
On 2010-10-21, Jean-Michel Pichavant wrote: > In the middle of thousand lines of code, when you are reviewing > or debugging, the later is better TMO, the point is that x, y, > z = is only easy to read during the assignement. Consider this: > > x, y, z = p.nextpoint() > [snip a dozen of code line]

Re: how to scrutch a dict()

2010-10-21 Thread Neil Cerutti
On 2010-10-21, James Mills wrote: > Rather than creating a new dict why don't you just do: > > def _scrunch(d): >for k, v in d.items(): > if v is None: > del d[k] In Python 3, where items returns an iterator, modifying the dictionary in this way may lead to cirrhossis of the di

Re: how to scrutch a dict()

2010-10-21 Thread Joost Molenaar
Using a 2.7/3.x dictionary comprehension, since you don't seem to mind creating a new dictionary: def _scrunched(d):     return { key: value for (key, value) in d.items() if value is not None } Joost On 21 October 2010 06:32, Phlip wrote: > > Not Hyp: > > def _scrunch(**dict): >    result = {}

Re: Has Next in Python Iterators

2010-10-21 Thread Steven D'Aprano
On Thu, 21 Oct 2010 19:08:00 +0800, Kelson Zawack wrote: > I have been programing in python for a while now and by in large love > it. One thing I don't love though is that as far as I know iterators > have no has_next type functionality. As a result if I want to iterate > until an element that

Re: memory management - avoid swapping/paging

2010-10-21 Thread Alain Ketterlin
Jon Clements writes: > Is there a cross-platform way using Python to guarantee that an object > will never be swapped/paged to disk? I'll be honest and say I'm really > not sure if this is a particular language question or rather specific > to an OS. > > Under linux it appears I could create a r

Re: Has Next in Python Iterators

2010-10-21 Thread Steven D'Aprano
On Thu, 21 Oct 2010 09:36:41 -0200, Felipe Bastos Nunes wrote: > Looking in the documentation, only the StopIteration raises. I'd like a > hasNext() too. I'll see if it is easy to implement, Iterators can be unpredictable. In general, you can't tell whether an iterator is finished or not until

Re: pythagorean triples exercise

2010-10-21 Thread Alex Hall
On 10/21/10, Baba wrote: > Hi everyone > > i need a hint regarding the following exercise question: > > "Write a program that generates all Pythagorean triples whose small > sides are no larger than n. > Try it with n <= 200." > > what is "n" ? i am guessing that it is a way to give a bound to the

Re: Has Next in Python Iterators

2010-10-21 Thread Ben Finney
Kelson Zawack writes: > […] if I want to iterate until an element that might or might not be > present is found I either wrap the while loop in a try block or break > out of a for loop. I'm not sure what exception you would catch, but that could be a good solution. The general solution would b

Re: Has Next in Python Iterators

2010-10-21 Thread Felipe Bastos Nunes
Looking in the documentation, only the StopIteration raises. I'd like a hasNext() too. I'll see if it is easy to implement, but maybe it'sn ot yet there coz for does the work greatly. 2010/10/21, Kelson Zawack : > I have been programing in python for a while now and by in large love > it. One thi

Has Next in Python Iterators

2010-10-21 Thread Kelson Zawack
I have been programing in python for a while now and by in large love it. One thing I don't love though is that as far as I know iterators have no has_next type functionality. As a result if I want to iterate until an element that might or might not be present is found I either wrap the while

pythagorean triples exercise

2010-10-21 Thread Baba
Hi everyone i need a hint regarding the following exercise question: "Write a program that generates all Pythagorean triples whose small sides are no larger than n. Try it with n <= 200." what is "n" ? i am guessing that it is a way to give a bound to the triples to be returned but i can't figur

pythagorean triples exercise

2010-10-21 Thread Baba
Hi everyone i need a hint regarding the following exercise question: "Write a program that generates all Pythagorean triples whose small sides are no larger than n. Try it with n <= 200." what is "n" ? i am guessing that it is a way to give a bound to the triples to be returned but i can't figu

Re: how to scrutch a dict()

2010-10-21 Thread John Pinner
On Oct 21, 5:40 am, Paul Rubin wrote: > Phlip writes: > > def _scrunch(**dict): > >     result = {} > > >     for key, value in dict.items(): > >         if value is not None:  result[key] = value > > >     return result > > > That says "throw away every item in a dict if the Value is None". > >

Re: The 'n' format specifier

2010-10-21 Thread Peter Otten
Boštjan Mejak wrote: > The locale.setlocale(category=locale.LC_NUMERIC, locale="Slovenian") > works like a charm in my application. Now the 'n format specifier works as > I want. But tell me whether the 'n' forma specifier can be forced to round > the float to just one decimal place. I know that

Re: OO and game design questions

2010-10-21 Thread Jonathan Hartley
On Oct 20, 12:11 pm, dex wrote: > On Oct 20, 12:25 pm, Jonathan Hartley wrote: > > > > > On Oct 18, 8:28 am, dex wrote: > > > > I'm building a turn based RPG game as a hobby. The design is becoming > > > increasingly complicated and confusing, and I think I may have > > > tendency to over-engine

Re: OO and game design questions

2010-10-21 Thread Jonathan Hartley
On Oct 20, 12:11 pm, dex wrote: > On Oct 20, 12:25 pm, Jonathan Hartley wrote: > > > > > On Oct 18, 8:28 am, dex wrote: > > > > I'm building a turn based RPG game as a hobby. The design is becoming > > > increasingly complicated and confusing, and I think I may have > > > tendency to over-engine

Re: OO and game design questions

2010-10-21 Thread Jonathan Hartley
On Oct 20, 12:11 pm, dex wrote: > On Oct 20, 12:25 pm, Jonathan Hartley wrote: > > > > > On Oct 18, 8:28 am, dex wrote: > > > > I'm building a turn based RPG game as a hobby. The design is becoming > > > increasingly complicated and confusing, and I think I may have > > > tendency to over-engine

Re: Unix-head needs to Windows-ize his Python script

2010-10-21 Thread Ulrich Eckhardt
gb345 wrote: > I have a handy Python script, which takes a few command-line > arguments, and accepts a few options. [...] > I want to adapt my script, with the minimum amount of > work, so that it can have a double-clickable icon that brings up > a small GUI to accept command-line options (includin

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Jean-Michel Pichavant
Martin P. Hellwig wrote: On 10/20/10 22:09, Seebs wrote: On 2010-10-20, Matteo Landi wrote: Another situation in which I needed to disable such kind of warnings is while working with graphics modules. I often use variable names such as x, y, z for coordinates, or r,g,b for colors. Would long

memory management - avoid swapping/paging

2010-10-21 Thread Jon Clements
Hi all, Is there a cross-platform way using Python to guarantee that an object will never be swapped/paged to disk? I'll be honest and say I'm really not sure if this is a particular language question or rather specific to an OS. Under linux it appears I could create a ramfs and mmap a file under

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Wed, 20 Oct 2010 12:47:02 +0200, Jean-Michel Pichavant wrote: except ValueError, e: Use meaningful names, this is so important. 'e' is not meaningful. 'exception' would be slighly better. While I agree with everything else you had to say, I have to take exc

Re: Reading Outlook .msg file using Python

2010-10-21 Thread Tim Golden
On 21/10/2010 09:34, Jon Clements wrote: Only just noticed this thread, and had something similar. I took the following approach:- (I'm thinking this might be relevant as you mentioned checking whether your client's Outlook could export .EML directly, which indicates (to me at least) that you ha

Re: Reading Outlook .msg file using Python

2010-10-21 Thread Jon Clements
On 20 Oct, 18:13, John Henry wrote: > On Oct 20, 9:01 am, John Henry wrote: > > > > > On Oct 20, 1:41 am, Tim Golden wrote: > > > > On 19/10/2010 22:48, John Henry wrote: > > > > > Looks like this flag is valid only if you are getting messages > > > > directly from Outlook.  When reading the msg

The 'n' format specifier

2010-10-21 Thread Boštjan Mejak
The locale.setlocale(category=locale.LC_NUMERIC, locale="Slovenian") works like a charm in my application. Now the 'n format specifier works as I want. But tell me whether the 'n' forma specifier can be forced to round the float to just one decimal place. I know that the 'f' format specifier does

Re: Unix-head needs to Windows-ize his Python script

2010-10-21 Thread Tim Golden
On 20/10/2010 18:38, gb345 wrote: I have a handy Python script, which takes a few command-line arguments, and accepts a few options. I developed it on Unix, with very much of a Unix-mindset. Some Windows-using colleagues have asked me to make the script "easy to use under Windows 7". I.e.: no

Re: pylint -- should I just ignore it sometimes?

2010-10-21 Thread Martin P. Hellwig
On 10/20/10 22:09, Seebs wrote: On 2010-10-20, Matteo Landi wrote: Another situation in which I needed to disable such kind of warnings is while working with graphics modules. I often use variable names such as x, y, z for coordinates, or r,g,b for colors. Would longer names make the reader's l

Re: Unix-head needs to Windows-ize his Python script

2010-10-21 Thread Eric Brunel
In article , Shawn Milochik wrote: > Also, wxPython automatically looks native Mac, Windows, and Linux. And so do the recent versions of Tkinter/tcl-tk... In Python, you just have to use the widgets in the new ttk module. These widgets also have fewer options than their equivalent in Tkinter,