Re: list comprehension to do os.path.split_all ?

2011-07-30 Thread Hrvoje Niksic
Neil Cerutti writes: > On 2011-07-29, Dennis Lee Bieber wrote: >> Fine... So normpath it first... >> > os.path.normpath(r'C:/windows').split(os.sep) >> ['C:', 'windows'] That apparently doesn't distinguish between r'C:\windows' and r'C:windows'. On Windows the first is an absolute pat

Re: What is xrange?

2011-07-30 Thread Ethan Furman
Dennis Lee Bieber wrote: On Sat, 30 Jul 2011 21:36:41 +1000, Steven D'Aprano declaimed the following in gmane.comp.python.general: Probably because nobody thought about it, but if it had been proposed to change xrange into an iterator, I'm pretty confident that the suggestion would have been

Re: PEP 8 and extraneous whitespace

2011-07-30 Thread Gregory Ewing
OKB (not okblacke) wrote: You don't need to include extraneous whitespice to get it to line up ^^ +1 on Python 4 providing whitespice. Should liven things up nicely. :-) -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension to do os.path.split_all ?

2011-07-30 Thread Michael Poeltl
* Michael Torrie [2011-07-31 03:44]: > On Jul 29, 2011 6:33 PM, "Michael Poeltl" > wrote: > > > > what about this? > > >>> ' '.join('/home//h1122/bin///ghi/'.split('/')).split() > > ['home', 'h1122', 'bin', 'ghi'] > > >>> > > Doesn't work on filenames with spaces in them. you are right; me, I ne

Re: NoneType and new instances

2011-07-30 Thread Steven D'Aprano
Terry Reedy wrote: > On 7/30/2011 12:39 PM, bruno.desthuilli...@gmail.com wrote: >> On 28 juil, 17:39, Ethan Furman  wrote: >>> >>> -->  bool(0) is bool(0) >>> True > >> This test is not reliable > > It is in the sense that it will always work -- because False/True are > doubletone constants and

Re: NoneType and new instances

2011-07-30 Thread Terry Reedy
On 7/30/2011 12:39 PM, bruno.desthuilli...@gmail.com wrote: On 28 juil, 17:39, Ethan Furman wrote: --> bool(0) is bool(0) True This test is not reliable It is in the sense that it will always work -- because False/True are doubletone constants and so documented. But expr is expr == Tr

Re: PyWart: os.path needs immediate attention!

2011-07-30 Thread Robert Kern
On 7/29/11 8:50 PM, Steven D'Aprano wrote: Andrew Berg wrote: os.path.exists(path, ignoreSymLnks=False) I actually agree with you on these, which I suppose is interesting. Guido has a rule of thumb: "No constant arguments". Or another way to put it: if a function takes an argument which is

Re: Deeply nested dictionaries - should I look into a database or am I just doing it wrong?

2011-07-30 Thread Andrew Berg
On 2011.07.30 09:43 PM, Rustom Mody wrote: > I use pyyaml for such. http://yaml.org/ > The builtin json support http://docs.python.org/library/json.html is a bit > weaker but has the advantage of no extra install I don't need a format to share or store the data. I'm perfectly content to pickle the

Re: Deeply nested dictionaries - should I look into a database or am I just doing it wrong?

2011-07-30 Thread Rustom Mody
I use pyyaml for such. http://yaml.org/ The builtin json support http://docs.python.org/library/json.html is a bit weaker but has the advantage of no extra install -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension to do os.path.split_all ?

2011-07-30 Thread Michael Torrie
On Jul 29, 2011 6:33 PM, "Michael Poeltl" wrote: > > what about this? > >>> ' '.join('/home//h1122/bin///ghi/'.split('/')).split() > ['home', 'h1122', 'bin', 'ghi'] > >>> Doesn't work on filenames with spaces in them. -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 8 and extraneous whitespace

2011-07-30 Thread OKB (not okblacke)
Chris Angelico wrote: > On Sat, Jul 30, 2011 at 4:45 AM, OKB (not okblacke) > Suppose you want to have a lengthy piece of text embedded in your > source code, which you will then pass to a GUI widget for display. > You want the widget to handle word wrap, so you don't want internal > line breaks g

Re: Trying to learn about metaclasses

2011-07-30 Thread Steven D'Aprano
bruno.desthuilli...@gmail.com wrote: > On 25 juil, 17:36, "Steven W. Orr" wrote: >> I have been doing a lot of reading. I'm starting to get it. I think it's >> really cool as well as dangerous, > > Dangerous ??? Why so ? Is there anything "dangerous" in a constructor > or an initialiser ??? A me

Re: What is xrange?

2011-07-30 Thread Gregory Ewing
Brian Blais wrote: On Jul 29, 2011, at 9:22 PM, Steven D'Aprano wrote: Billy Mays wrote: Is xrange not a generator? I know it doesn't return a tuple or list, so what exactly is it? It's an iterable object. There are advantages in having xrange (or range in python3) return an iterable obje

Re: What is xrange?

2011-07-30 Thread Chris Angelico
On Sun, Jul 31, 2011 at 1:06 AM, Dennis Lee Bieber wrote: >        Ah, but what did they change range() into -- I seem to recall > reading the Python 3.x turned the regular range() into something else... > (from Python <3.x returning a full list) > xrange got renamed to range, as I understand it.

Re: Windows: setting title of console window

2011-07-30 Thread Ethan Furman
Thomas Jollans wrote: On 30/07/11 20:39, Ethan Furman wrote: How it works: since the sys.argv object does yet exist, I create an object and assign it to sys.argv; then, when Python assigns the actual argv to sys.argv, my object is tossed, and the __del__ method is called; the __del__ method is t

Re: eval, exec and execfile dilemma

2011-07-30 Thread Steven D'Aprano
Laszlo Nagy wrote: > 100 functions/second > installed to global namespace doesn't sound well. What on earth are you doing needing to use exec to create hundreds of functions?? Have you considered not using exec at all, and using a good old-fashioned factory function and closures? def facto

Re: Windows: setting title of console window

2011-07-30 Thread Thomas Jollans
On 30/07/11 20:39, Ethan Furman wrote: > How it works: since the sys.argv object does yet exist, I create an > object and assign it to sys.argv; then, when Python assigns the actual > argv to sys.argv, my object is tossed, and the __del__ method is called; > the __del__ method is then able to acces

Re: eval, exec and execfile dilemma

2011-07-30 Thread Laszlo Nagy
UnboundLocalError: local variable 'bar' referenced before assignment This works, though (at least it does on 2.7): --> exec "def foo():\n\tglobal bar\n\tbar+=1\n\treturn 1\n" --> bar = 9 --> foo() 1 --> bar 10 Laszlo, why do you think you can't use exec? I'm sorry, first I was not aware of

Deeply nested dictionaries - should I look into a database or am I just doing it wrong?

2011-07-30 Thread Andrew Berg
As part of my muxer/encoder backend module, I need to store data in its main class. While each instance won't typically store a lot of data, but I really want it broken up into distinct categories so that a program using the module won't need to figure out what piece of data refers to what (e.g. is

Re: eval, exec and execfile dilemma

2011-07-30 Thread Ethan Furman
Chris Angelico wrote: On Sat, Jul 30, 2011 at 8:48 PM, Laszlo Nagy wrote: the exec statement can be used to execute a def statement. However, I see no way to change the globals, so I cannot use the exec statement. A quick test in Python 2.4.5: exec "def foo():\n\tbar+=1\n\treturn 1\n" bar=2

Re: eval, exec and execfile dilemma

2011-07-30 Thread Chris Angelico
On Sat, Jul 30, 2011 at 8:48 PM, Laszlo Nagy wrote: > the exec statement can be used to execute a def statement. However, I see no > way to change the globals, so I cannot use the exec statement. You can't use: exec "blah blah" in globals() ? I've not used exec, nor its Python 3 equivalent exe

eval, exec and execfile dilemma

2011-07-30 Thread Laszlo Nagy
Hi, I have a program that generates source code for a function. I need to compile that function so that it can be executed (relatively) fast later. In most cases, I'll be generating about 10 functions per second, and evaluate them frequently. But sometimes I'll have to generate 100 functio

Re: Windows: setting title of console window

2011-07-30 Thread Ethan Furman
Chris Angelico wrote: On Sat, Jul 30, 2011 at 7:39 PM, Ethan Furman wrote: Well, you /could/ have followed the link and read the explanation there... ;) I tend to avoid clicking random links in posts :) Ah -- I understand. How it works: since the sys.argv object does yet exist... That's

Re: Windows: setting title of console window

2011-07-30 Thread Chris Angelico
On Sat, Jul 30, 2011 at 7:39 PM, Ethan Furman wrote: > Well, you /could/ have followed the link and read the explanation there... > ;) I tend to avoid clicking random links in posts :) > How it works: since the sys.argv object does yet exist... That's the bit I didn't understand. I assume that'

Re: Windows: setting title of console window

2011-07-30 Thread Ethan Furman
Chris Angelico wrote: I'm afraid I don't understand this. Why create an object and do the work in the destructor? When will the destructor be called? Will you subsequently be overwriting sys.argv with the actual arguments? This code snippet makes excellent sense if and only if it's executed befo

Re: Windows: setting title of console window

2011-07-30 Thread Chris Angelico
On Sat, Jul 30, 2011 at 6:23 PM, Ethan Furman wrote: > 8<-- sitecustomize.py - > class SetTitle(object): >    def __del__(self): >        command = ' '.join(sys.argv) > > sys.argv = SetTitle() I'm afraid I don't understand this. Why create an object and do the work

Windows: setting title of console window

2011-07-30 Thread Ethan Furman
I came across question http://stackoverflow.com/questions/6485678/ which has to do with setting the console title from sitecustomize.py. With some help from the folks on python-win32 (for the title portion ;) I came up with this: 8<-- sitecustomize.py - import

Re: Trying to learn about metaclasses

2011-07-30 Thread bruno.desthuilli...@gmail.com
On 25 juil, 17:36, "Steven W. Orr" wrote: > I have been doing a lot of reading. I'm starting to get it. I think it's > really cool as well as dangerous, Dangerous ??? Why so ? Is there anything "dangerous" in a constructor or an initialiser ??? A metaclass is just a class, and a class is just an

Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-30 Thread Chris Angelico
On Sat, Jul 30, 2011 at 5:52 PM, bruno.desthuilli...@gmail.com wrote: > On 28 juil, 00:34, rantingrick wrote: > >> In Python4000 i'm making it a syntax error to >> include ANY blank lines in a func/meth body. > > Hopefully this is not going to happen. It will happen when Rick stops ranting and s

Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-30 Thread bruno.desthuilli...@gmail.com
On 28 juil, 00:34, rantingrick wrote: > In Python4000 i'm making it a syntax error to > include ANY blank lines in a func/meth body. Hopefully this is not going to happen. (snip remaining stupidities). -- http://mail.python.org/mailman/listinfo/python-list

Re: Wondering in the Python Forrest

2011-07-30 Thread duncan smith
Ken Watford wrote: On Sat, Jul 30, 2011 at 7:13 AM, ray wrote: I found that structured data could be presented in Python using a module in wxPython. Where am I? I do not know the relationships between the Pythons. I feel that I am missing something. I started with Python as it has so much f

Re: NoneType and new instances

2011-07-30 Thread bruno.desthuilli...@gmail.com
On 28 juil, 17:39, Ethan Furman wrote: > > --> bool(0) is bool(0) > True > This test is not reliable - a same id can be reused for terms (I have already seen such things happening). If you want a reliable test, use: #> a = bool(0) #> b = bool(0) #> a is b True Note that this still fails to prov

Re: What's in a name?

2011-07-30 Thread Ethan Furman
Andrew Berg wrote: I know I really shouldn't be spending too much time and effort on a name, but for some reason, it's really bothering me that I can't come up with good names for the projects I'm working on. I came up with abstract names (see below) that I don't really like (because they're so

Re: PyWart: os.path needs immediate attention!

2011-07-30 Thread Andrew Berg
On 2011.07.30 10:33 AM, Grant Edwards wrote: > RR must think so, considering how much effort he seems to put into it. He hasn't replied to his last two troll threads, though. It does seem odd to write a wall of text and then not respond to replies. To be fair, though, most replies either mock him o

Re: NoneType and new instances

2011-07-30 Thread python
Hi Terry, > Ethan's proposal was accepted on python-ideas. In Python 3.3, the classes for > the singletons None, Ellipsis, and NotImplemented will be callables that > return the singleton. Thanks for sharing this news. Its motivating to see this type of feedback loop because it encourages other

Re: PyWart: os.path needs immediate attention!

2011-07-30 Thread Grant Edwards
On 2011-07-30, Michael Poeltl wrote: > join 'Python-Dev'-mailinglist and tell them! > > from now on I will just ignore threads you initiated > > does trolling really make that much fun? RR must think so, considering how much effort he seems to put into it. It

Re: Wondering in the Python Forrest

2011-07-30 Thread Terry Reedy
On 7/30/2011 7:13 AM, ray wrote: I am new to Python and am learning for engineering and scientific use. For some reason, which I don’t remember, I went to Scipy.org downloaded the module. I am sure it had explained things but that was a couple weeks ago and it’s all a blur. So now I am working

Re: PyWart: os.path needs immediate attention!

2011-07-30 Thread Terry Reedy
On 7/29/2011 8:50 PM, Steven D'Aprano wrote: Guido has a rule of thumb: "No constant arguments". Or another way to put it: if a function takes an argument which is nearly always a constant (usually, but not always, a flag) then it is usually better off as two functions. I do not really underst

Re: Wondering in the Python Forrest

2011-07-30 Thread Ken Watford
On Sat, Jul 30, 2011 at 7:13 AM, ray wrote: > I found that structured data could be presented in Python using a module in > wxPython. > > Where am I?  I do not know the relationships between the Pythons.  I > feel that I am missing something.  I started with Python as it has so > much functionalit

Re: What is xrange?

2011-07-30 Thread Brian Blais
On Jul 30, 2011, at 7:36 AM, Steven D'Aprano wrote: > xrange objects might be lazily generated, but > they're also sequence types: you can get their length, and you can index > them. (However you can't slice them.) Iterators are not sequence types: > they aren't indexable and you can't get their l

Re: NoneType and new instances

2011-07-30 Thread Terry Reedy
Ethan's proposal was accepted on python-ideas. In Python 3.3, the classes for the singletons None, Ellipsis, and NotImplemented will be callables that return the singleton. It turns out that the reason an exception is now raised is that there currently is no .__new__ method, so an exception is

Re: What is xrange?

2011-07-30 Thread Steven D'Aprano
Brian Blais wrote: > On Jul 29, 2011, at 9:22 PM, Steven D'Aprano wrote: > >> Billy Mays wrote: >> >>> Is xrange not a generator? I know it doesn't return a tuple or list, so >>> what exactly is it? >> >> xrange pre-dates generators by approximately forever. It returns a >> special "xrange obj

Re: What is xrange?

2011-07-30 Thread Brian Blais
On Jul 29, 2011, at 9:22 PM, Steven D'Aprano wrote: > Billy Mays wrote: > >> Is xrange not a generator? I know it doesn't return a tuple or list, so >> what exactly is it? > > xrange pre-dates generators by approximately forever. It returns a > special "xrange object", which generates values

Wondering in the Python Forrest

2011-07-30 Thread ray
I am new to Python and am learning for engineering and scientific use. For some reason, which I don’t remember, I went to Scipy.org downloaded the module. I am sure it had explained things but that was a couple weeks ago and it’s all a blur. So now I am working in Pythonxy. One of my activities

Re: removing nested iffs

2011-07-30 Thread Peter Otten
Chris Angelico wrote: > On Sat, Jul 30, 2011 at 6:42 AM, Peter Otten <__pete...@web.de> wrote: >> def format_pairs(pairs): >> for template, value in pairs: >> if value is None: >> break >> yield template.format(value) >> > > Cool! May I suggest a trifling change: > > def format_pairs(*pairs): >