Re: Conditional iteration

2006-12-14 Thread Carl Banks
at wrote:
> Carl Banks wrote:
>
> > at wrote:
> >> Well, all I can say that for me as a user it would make sense...
> >
> > Which is, like, step one out of a hundred for getting a syntax change
> > into the language.
> >
> >> Curiosity: in what sense is it redundant?
> >
> > It creates syntactical support for two different ways to do something.
> > If your plan were adopted, then we'd have two different spellings for
> > the same thing:
> >
> > for i in a:
> > if i != 0:
> > use(i)
> >
> > for i in a if i != 0:
> > use(i)
>
> With the current Python syntax, I can create for every two lines of code a
> dozen alternative implementations:
>
> # example 1
> a = {}
> a['b'] = 'c'
>
> versus:
> a = {'b': 'c'}
>
>
> # example 2
> l = []
> for l in some_list:
> if some_condition:
> l.append(l)
>
> versus:
> l = []
> for x in some_list:
> if some_condition:
> l = l + [x]
>
> or:
> l = [x for x in some_list if some_condition]
>
> (the beautiful one)
>
> So your argument doesn't mean much I would say!

That's a pretty asinine and/or stupid thing for you to say, since you
took my argument completely out of context.  In particular, you ignored
the following paragraph, where I weighed the benefits of the new syntax
versus the cost of redundancy.

Have you done that in your counterexamples?  Did you weigh the
benefits, and somehow conclude that what different the syntaxes in the
counterexamples buy is just as little as what your proposal buys?  No,
you didn't.

Next time, wait till I've actually made my argument before passing
judgment on whether it means anything.


> > Now, redundant syntax isn't a deal breaker by itself.  You have to ask
> > what is buys you.  In this case, all it does is save you a single level
> > of indentation--that's it.  There's no performance benefit.  It doesn't
> > simplify logic.  It doesn't make the code any more readable of clear.
> > It's only a minor improvement in conciseness.  It hardly saves any
> > typing (unless you indent by hand).  Even its one clear benefit, saving
> > indentation, is something you can already get with "if not x:
> > continue".
>
>
> Well there is a clear performance benefit, or more precisely a productivity
> benefit.

Performance and productivity aren't the same thing.  There is no
peformance benefit of your syntax.  Productivity is not so clear cut.
You might be able to argue that there's some marginal productivity
benefit to using your syntax, but I can't imagine it'd be anything
substantial.


> And -please- do not underestimate this for a language like Python,
> which has many supporters due to its perceived and high productivity and
> challenged on this point by languages like Ruby.
>
> 'for x in some_list if some_condition:'
>
> is psychological very strong, because the brain will most likely treat the
> in the same way as :
>
> for every apple in the fruitbasket take one if green
>
>
> Basically upon reading this first line you know exactly to what list of
> items your next section of code applies.

I don't understand why this wouldn't also apply if the if statement
happens to be on the following line.  I still think all this is is
whining about the extra indentation.


> But again everything is a matter of taste and I assume that's why the change
> control body is put into the hand of one person.
[snip]
> >> Does Guido ever change his mind?
> >
> > Yes, but I guarantee "it makes sense for me" isn't going to convince
> > him.  By the way, I'd suggest when posting to comp.lang.python and/or
> > python-list in the future, you put your replies beneath the quoted text
> > for the benefit of any future readers (not to mention present readers).
>
> I hope this this thread will support the "it makes sense for me" with
> arguments. Again it is not my intention to fight windmills,

I would just stop right now, then.  It's not going to change.

> but to see if
> there are strong arguments against it on one hand and if there supporters
> on the other hand.


Carl Banks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting Multidimesional array(newbie)

2006-12-14 Thread Brian Mills

Fredrik Lundh wrote:

> Brian Mills wrote:
>
> > There's another (IMHO more readable) way to do it if you can afford
> > defining a short little "compare" function, and telling .sort()
> > to use that instead of its default:
> >
>  def myListCmp(lst1, lst2):
> > ...   if lst1[0] < lst2[0]: return -1
> > ...   if lst2[0] > lst2[0]: return 1
> > ...   return 0
>
> shorter:
>
>   def myListCmp(a, b):
>   return cmp(a[0], b[0])

Good point.

> but using a compare function instead of a key mapper is not good advice,
> in general.  brief discussion here:
> http://effbot.org/pyfaq/i-want-to-do-a-complicated-sort-can-you-do-a-schwartzian-transform-in-python

Is this mostly because of the stability problem described here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234 ?  Or is
it more a performance issue due having to make so many function calls?
>
> also note the OP didn't specify what to do for records where the first
> column was identical, so I guess a plain sort() call, without any custom
> compares or mappings, would work as well as the fancier alternatives...

I can't believe I didn't try this, but for the given example it works
perfectly.  It even acts gracefully when you give it such sociopathic
lists as

>>> c = [[3, 1], [8, 2], [6, 3], [12, 4], [1, 5], ["oh noes!", 6], [24, 7], [ope
n("file.txt", 'r'), 8], [[1, 2, 3], 9]]
>>> c.sort()
>>> c
[[1, 5], [3, 1], [6, 3], [8, 2], [12, 4], [24, 7], [, 8], [[1, 2, 3], 9], ['oh noes!', 6]]

Though changing the ordering system it decides to use may take some
more research.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to determine Operating System in Use?

2006-12-14 Thread Prateek
also try:

sys.platform

if sys.platform == "darwin":
macStuff()
elif sys.platform == "win32":
linuxStuff()


James Cunningham wrote:
> On 2006-12-13 19:28:14 -0500, [EMAIL PROTECTED] said:
>
> >
> >
> > On Dec 13, 6:32 pm, "Ian F. Hood" <[EMAIL PROTECTED]> wrote:
> >> Hi
> >> In typically windows environments I have used:
> >> if 'Windows' in os.environ['OS']...
> >> to prove it, but now I need to properly support different environments.
> >> To do so I must accurately determine what system the python instance is
> >> running on (linux, win, mac, etc).
> >> Is there a best practises way to do this?
> >> TIA
> >> Ian
> >
> > I would do this:
> > 
> > if os.name == ''posix':
> > linuxStuff()
> > elif os.name == 'nt':
> > windowsStuff()
> > elif os.name == 'os2': ...
> > ---
> > os.name is  'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
> >
> > -N
>
> Bearing in mind, of course, that Mac will return "posix", too. And
> Cygwin might. Erg.
> 
> Best,
> James

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to determine Operating System in Use?

2006-12-14 Thread Prateek
eeps! typo.

> if sys.platform == "darwin":
> macStuff()
> elif sys.platform == "win32":
> winStuff()
>

Not sure what the string is on linux. Just fire up the interpreter and
try it.

Prateek

Prateek wrote:
> also try:
>
> sys.platform
>
> if sys.platform == "darwin":
> macStuff()
> elif sys.platform == "win32":
> linuxStuff()
>
>
> James Cunningham wrote:
> > On 2006-12-13 19:28:14 -0500, [EMAIL PROTECTED] said:
> >
> > >
> > >
> > > On Dec 13, 6:32 pm, "Ian F. Hood" <[EMAIL PROTECTED]> wrote:
> > >> Hi
> > >> In typically windows environments I have used:
> > >> if 'Windows' in os.environ['OS']...
> > >> to prove it, but now I need to properly support different environments.
> > >> To do so I must accurately determine what system the python instance is
> > >> running on (linux, win, mac, etc).
> > >> Is there a best practises way to do this?
> > >> TIA
> > >> Ian
> > >
> > > I would do this:
> > > 
> > > if os.name == ''posix':
> > > linuxStuff()
> > > elif os.name == 'nt':
> > > windowsStuff()
> > > elif os.name == 'os2': ...
> > > ---
> > > os.name is  'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
> > >
> > > -N
> >
> > Bearing in mind, of course, that Mac will return "posix", too. And
> > Cygwin might. Erg.
> > 
> > Best,
> > James

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Ken Tilton


Paul Rubin wrote:
> Ken Tilton <[EMAIL PROTECTED]> writes:
> 
Man that whole thing is messy.
>>
>>I do not see much difference, except that the character count is 25%
>>less in the macro version:
> 
> 
> The macro calls aren't so bad, but the macro definition is pretty
> horrendous. 

(a) /Precisely/ :)

(b) Omigod, that macro is trivial (except I forgot how to reach out two 
levels of backquote to get a parameter and had to kludge it!). You just 
aren't used to thinking at a level where one is writing code to write code.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional iteration

2006-12-14 Thread at
By the way,

I think by approving

a = b if condition else c

used to avloind

if condition:
a = b
else:
a = c

which is dealing with same psychological problem, Guido also recognizes some
need...

Is it redundant according to your criteria, yes I would say:

a = {True: a, False: c}[condition]

or 

a = [c, a][condition]

would yield exactly the same even in one sentence

Cheers,

@


at wrote:

> My comments below.
> 
> Kind regards,
> @
> 
> 
> Carl Banks wrote:
> 
>> at wrote:
>>> Well, all I can say that for me as a user it would make sense...
>> 
>> Which is, like, step one out of a hundred for getting a syntax change
>> into the language.
>> 
>>> Curiosity: in what sense is it redundant?
>> 
>> It creates syntactical support for two different ways to do something.
>> If your plan were adopted, then we'd have two different spellings for
>> the same thing:
>> 
>> for i in a:
>> if i != 0:
>> use(i)
>> 
>> for i in a if i != 0:
>> use(i)
> 
> With the current Python syntax, I can create for every two lines of code a
> dozen alternative implementations:
> 
> # example 1
> a = {}
> a['b'] = 'c'
> 
> versus:
> a = {'b': 'c'}
> 
> 
> # example 2
> l = []
> for l in some_list:
> if some_condition:
> l.append(l)
> 
> versus:
> l = []
> for x in some_list:
> if some_condition:
> l = l + [x]
> 
> or:
> l = [x for x in some_list if some_condition]
> 
> (the beautiful one)
> 
> So your argument doesn't mean much I would say!
> 
>> 
>> Now, redundant syntax isn't a deal breaker by itself.  You have to ask
>> what is buys you.  In this case, all it does is save you a single level
>> of indentation--that's it.  There's no performance benefit.  It doesn't
>> simplify logic.  It doesn't make the code any more readable of clear.
>> It's only a minor improvement in conciseness.  It hardly saves any
>> typing (unless you indent by hand).  Even its one clear benefit, saving
>> indentation, is something you can already get with "if not x:
>> continue".
> 
> 
> Well there is a clear performance benefit, or more precisely a
> productivity benefit. And -please- do not underestimate this for a
> language like Python, which has many supporters due to its perceived and
> high productivity and challenged on this point by languages like Ruby.
> 
> 'for x in some_list if some_condition:'
> 
> is psychological very strong, because the brain will most likely treat the
> in the same way as :
> 
> for every apple in the fruitbasket take one if green
> 
> 
> Basically upon reading this first line you know exactly to what list of
> items your next section of code applies.
> 
> But again everything is a matter of taste and I assume that's why the
> change control body is put into the hand of one person.
> 
> 
> 
>> Considering how little this syntax change buys, it really doesn't make
>> a lot of sense for a language that places high emphasis on avoiding
>> redundancy.
>> 
>> 
>>> All solution/workarounds I have seen so far involve creation of new
>>> lists (subsets) adding to more processing/computation/memory usage.
>>> Redundant suggests that you know alternatives that don't do that.
>>>
>>> Does Guido ever change his mind?
>> 
>> Yes, but I guarantee "it makes sense for me" isn't going to convince
>> him.  By the way, I'd suggest when posting to comp.lang.python and/or
>> python-list in the future, you put your replies beneath the quoted text
>> for the benefit of any future readers (not to mention present readers).
>>
> I hope this this thread will support the "it makes sense for me" with
> arguments. Again it is not my intention to fight windmills, but to see if
> there are strong arguments against it on one hand and if there supporters
> on the other hand.
> 
> 
>> 
>> Carl Banks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stupid email disclaimers (was: [unicode] inconvenient unicodeconversion of non-string arguments)

2006-12-14 Thread Holger Joukl
[EMAIL PROTECTED] schrieb am 13.12.2006
23:10:38:
> [...]
> In all likelihood, the OP isn't choosing specifically to attach it;
> these things are often done to *every* outgoing message at an
> organisational level by people who don't think the issue through very
> well.
>
> http://goldmark.org/jeff/stupid-disclaimers/>

That's exactly the case.

> Please, those with such badly-configured systems, discuss the issue of
> public discussion forums with the boneheads who think these disclaimer
> texts are a good idea and at least try to change that behaviour.

Believe me I've tried, in subtle and not-so-subtle ways. They won't change
it, it's stupid and that's that.

> Alternatively, post from some other mail system that doesn't slap
> these obnoxious blocks onto your messages.

I would but my browser environment is different from the rest so I
can not copy source text or attach files to mails I could write via
web mail. That would render mailing lists quite unusable for me.
This is going to change soon, hopefully.

So my apologies for the disclaimer but I an not do anything about it right
now.

Holger

And now for another mighty stupid disclaimer ;-):

Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde,
verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht
gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

The contents of this  e-mail are confidential. If you are not the named
addressee or if this transmission has been addressed to you in error,
please notify the sender immediately and then delete this e-mail.  Any
unauthorized copying and transmission is forbidden. E-Mail transmission
cannot be guaranteed to be secure. If verification is required, please
request a hard copy version.


-- 
http://mail.python.org/mailman/listinfo/python-list


Survey environment for Python?

2006-12-14 Thread exhuma.twn
Hi,

Just recently I had to take over support for legacy software written in
Blaise (www.cbs.nl). As I did not know of this "Programming Language"
until one year ago I started to learn it. Well more like "read it"
as it's very very easy/simple.

However, I don't feel comfortable in that language. As far not as comfy
as in python ;) So I wanted to see if anyone knows of any surveying
system written in or usable with python.

For those that do not know Blaise:
First of all, it's a simplified syntax of Pascal so the syntax is quite
readable. And here is what you do with it: You define variables, then
define "routes". Those routes are simply definitions in which order
those variables should be processed, and if some variables should be
skipped. In addition to that it can perform a series of data-validation
tests and some simple computations.

It then uses these fields and routes to automatically generate a
user-interface to fill in those fields.

And that's about it.

I am aware that something like this should be doable in python. Also, I
think that a solid User Interface is very important for this task. Qt
would be nice, but I still have trouble getting it to run properly with
python. But that's a different story. And to avoid installing
third-party libraries (on windows),  Tk or a HTML-Interface seem to be
the only choices.

Is there anything like that around? If no, would anyone be interested
in giving me a hand for this sort of project? Somebody that understands
Tk would be useful, as I am mostly fluent in HTML&co.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional iteration

2006-12-14 Thread at

Hi Paul,

I appreciate your explanation!

Thanx

@

Paul Rubin wrote:

> at <[EMAIL PROTECTED]> writes:
>> >   for x in (x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0):
>> >... more code ...
> 
>> Do you know if this generates a new list internally (memory consumption?)
> 
> It does not.  That parenthesized expression is a called generator
> expression.  It compiles to a small subroutine, more or less, that
> gets invoked repeatedly as you iterate through it.
> 
> A similar expression with square brackets is called a list
> comprehension and does generate a new list.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting Multidimesional array(newbie)

2006-12-14 Thread Peter Otten
Brian Mills wrote:

>> but using a compare function instead of a key mapper is not good advice,
>> in general.  brief discussion here:
>>
http://effbot.org/pyfaq/i-want-to-do-a-complicated-sort-can-you-do-a-schwartzian-transform-in-python

> Is this mostly because of the stability problem described here:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234 ?  Or is
> it more a performance issue due having to make so many function calls?

http://docs.python.org/lib/typesseq-mutable.html

"""Starting with Python 2.3, the sort() method is guaranteed to be
stable."""

So performance it is. It is also often simpler once you get used to it and
start seeing the pattern

def mycmp(a, b):
   return cmp(mykey(a), mykey(b))

in many of your custom comparison functions.

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Ken Tilton


Paul Rubin wrote:
> Ken Tilton <[EMAIL PROTECTED]> writes:
> 
>>btw, you called the defskill messy (repeated below) "messy". The only
>>text not specific to absolute value is D-E-F-S-K-I-L-L.
> 
> 
> No, the messiness was not in the macro instantation (defskill blah...),
> but in the defmacro that tells the compiler how to expand it.

Again, that is precisely the point of macrology (in cases like this). 
When a pattern will repeat a sufficient number of times, and a function 
cannot handle the job, we do a little extra work (write some meta-code) 
to make dozens (or hundreds) of applications as minimalist as possible.

That makes them concise, readable, and maintainable.

>  Python
> function defs are lightweight enough that I don't experience a big pain
> from using an extra one for a thing like that.

Check out the latest, plz. The example has grown now beyond what a 
function can do, I think. meanwhile, I have not seen how Python lets you 
avoid revisiting dozens of instances when changes to a mechanism are 
required.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Defining classes

2006-12-14 Thread Michele Simionato
Nick Maclaren wrote:
> It would be much cleaner not to have to fiddle with static
> members after the class is initialised.

You can hide the fiddling, for instance with the trick explained here:

http://www.phyast.pitt.edu/~micheles/python/classinitializer.html


 Michele Simionato

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I edit a PythonWin path to import custom built modules???

2006-12-14 Thread Fredrik Lundh
BartlebyScrivener wrote:

>> what do you get if you do:
> 
>>> python -S
>> ...
 import sys
 sys.path
> 
> ['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python',
> 'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
> 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\
> \Python24']

since it appears *after* the ZIP archive, but before the standard path, 
it should be either a registry setting or a custom-built interpreter
(is this an ActiveState build?).  or maybe you could get this effect if 
you have a copy of "python.exe" in d:\python, but I'm pretty sure that
the directory should end up at the *end* of the path in that case.

have you searched the *entire* registry for the "PythonCore" key? 
(python looks under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER)

what's sys.prefix and sys.exec_prefix set to on your machine, btw?



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread jurgen_defurne

Ken Tilton wrote:
> George Sakkis wrote:
> > [EMAIL PROTECTED] wrote:
> >
> >>Okay, since everyone ignored the FAQ, I guess I can too...
> >>
> >>Mark Tarver wrote:
> >>
> >>>How do you compare Python to Lisp?  What specific advantages do you
> >>>think that one has over the other?
> >>
> >>(Common) Lisp is the only industrial strength language with both pure
> >>compositionality and a real compiler. What Python has is stupid slogans
> >>("It fits your brain." "Only one way to do things.") and an infinite
> >>community of flies that, for some inexplicable reason, believe these
> >>stupid slogns. These flies are, however, quite useful because they
> >>produce infinite numbers of random libraries, some of which end up
> >>being useful. But consider: Tcl replaced Csh, Perl replaced Tcl, Python
> >>is rapidly replacing Perl, and Ruby is simultaneously and even more
> >>rapidly replacing Python. Each is closer to Lisp than the last; the
> >>world is returning to Lisp and is dragging the flies with it.
> >>Eventually the flies will descend upon Lisp itself and will bring with
> >>them their infinite number of random libraries, and then things will be
> >>where they should have been 20 years ago, but got sidetracked by Tcl
> >>and other line noise.
> >
> >
> > I know we shouldn't feed the trolls, but this one was particularly
> > amusing to resist the urge. The joke about lisp's world domination in
> > some unspecified point in the future never fails to bring a good
> > chuckle. I heard it's scheduled right after strong AI and before time
> > travel, is this still the plan? A quick look at
> > http://www.tiobe.com/tpci.htm may be helpful as a reality check before
> > you go back to your ivory tower (interesting how close in ratings and
> > growth is the "Lisp/Scheme" entry with another dinosaur, Cobol).
> >
>
> And it interesting that VB is almost three times "better" than Python,
> and that a Honda could kick a Lamboghini's ass for it at Laguna Seca:
>
> http://www.googlefight.com/index.php?lang=en_GB&word1=lamborghini&word2=ford
>
> Come on, COBOL is a great language, even has macros (copy ... replacing)
> and the worlds greatest case statement, evaluate. We are proud to be its
> neightbor.
>
> ken
>
> --
> Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm
>
> "Well, I've wrestled with reality for thirty-five
> years, Doctor, and I'm happy to state I finally
> won out over it." -- Elwood P. Dowd
>
> "I'll say I'm losing my grip, and it feels terrific."
> -- Smiling husband to scowling wife, New Yorker cartoon

Well, Cobol still has the largest and most easy to comprehend system
for doing decimal arithmetic.

Jurgen

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: YouTube written in Python

2006-12-14 Thread John Nagle
Terry Reedy wrote:
> In a thread on the PyDev list, Guido van Rossum today wrote:
> 
>>And I just found out (after everyone else probably :-) that YouTube is
>>almost entirely written in Python.

Probably just the web page maintenance system is in Python.
I doubt that actual video passes through Python at any point.
Transcoding in Python would take forever.

John Nagle
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting Multidimesional array(newbie)

2006-12-14 Thread Fredrik Lundh
Brian Mills wrote:
>

>> but using a compare function instead of a key mapper is not good advice,
>> in general.  brief discussion here:
>> http://effbot.org/pyfaq/i-want-to-do-a-complicated-sort-can-you-do-a-schwartzian-transform-in-python
> 
> Is this mostly because of the stability problem described here:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234 ?

as mentioned in the comments to that recipe, Python's sort has been 
stable since 2.3.

 > Or is it more a performance issue due having to make so many function 
calls?

exactly (see the last sentence in the FAQ entry).



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Question - Checkboxes

2006-12-14 Thread Leanne

John Machin wrote:
>> I'd try this:
>
> if isinstance(returned_value, basestring):
> returned_value = [returned_value]
> for item in returned_value:
> do_something_with(item)
> 
> HTH,
> John

This sounds like a neat way of doing it, thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Famous Error Message: "ImportError: No module named python_script"

2006-12-14 Thread Gabriel Genellina

At Thursday 14/12/2006 03:44, rich murphy wrote:


The tutorial says: "For instance, use your favorite text editor to
create a file called fibo.py in the current directory with the
following contents:"

So, I assumed "the current directory" is C:\Python25 which did not
work. Then I placed the fibo.py file in C: director. That did not work
either. What directory does it mean then?


It doesn't matter *which* directory you are, as far as you don't 
change it when you enter the interpreter:


C:\TEMP\test\basura>type fibo.py
print "inside",__file__

C:\TEMP\test\basura>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fibo
inside fibo.py
>>>

When it later says "enter the Python interpreter" that means "execute 
python from the command line", not PythonWin nor IDLE nor...



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: merits of Lisp vs Python

2006-12-14 Thread Andrew Reilly
On Thu, 14 Dec 2006 03:01:46 -0500, Ken Tilton wrote:

> You just 
> aren't used to thinking at a level where one is writing code to write code.

Firstly, I'm looking into lisp because my current python project is too
full of boilerplate :-) and too slow.  Coming from a C and assembler
background, I'm *used* to meta-programming, and do it all the time.  I
even use python, Matlab and bash to write C, sometimes :-)

However, in this particular instance, I'm inclined to wonder why
meta-programming is the right answer, rather than just doing all of the
interpolation and what-not at run-time, based on a big table of your
algebra rules?  It's for output to a human, isn't it?  It's not as though
it needs to be particularly fast?

Maybe I'm just not digging the example sufficiently.  That's likely: I've
yet to write my first lisp program...

Cheers,

-- 
Andrew
-- 
http://mail.python.org/mailman/listinfo/python-list


variables with dynamicly generated names

2006-12-14 Thread avlee
Hello

Is it possible to use in python variables with dynamicly created names ?
How ?


Thanx
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Ken Tilton


Andrew Reilly wrote:
> On Thu, 14 Dec 2006 03:01:46 -0500, Ken Tilton wrote:
> 
> 
>>You just 
>>aren't used to thinking at a level where one is writing code to write code.
> 
> 
> Firstly, I'm looking into lisp because my current python project is too
> full of boilerplate :-) and too slow.  Coming from a C and assembler
> background, I'm *used* to meta-programming, and do it all the time.  I
> even use python, Matlab and bash to write C, sometimes :-)
> 
> However, in this particular instance, I'm inclined to wonder why
> meta-programming is the right answer, rather than just doing all of the
> interpolation and what-not at run-time, based on a big table of your
> algebra rules? 

I am afraid I do not see what alternative you are suggesting. I 
especially do not see how interpolation is in play.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional iteration

2006-12-14 Thread Duncan Booth
at <[EMAIL PROTECTED]> wrote:

> By the way,
> 
> I think by approving
> 
> a = b if condition else c
> 
> used to avloind
> 
> if condition:
> a = b
> else:
> a = c

Neither of those is much of an improvement over the other, and in fact if 
b or c are complex expressions I would definitely favour the longhand form. 
The benefit of having a conditional expression though is that in some 
situations it can make the code clearer by allowing you to avoid creating a 
name at all. e.g. if 'a' was then used as a parameter in a function call:

d = fn(b if condition else c)

and a has disappeared entirely.

> 
> which is dealing with same psychological problem, Guido also
> recognizes some need...
> 
> Is it redundant according to your criteria, yes I would say:
> 
> a = {True: a, False: c}[condition]
> 
> or 
> 
> a = [c, a][condition]
> 
> would yield exactly the same even in one sentence

You do realise, I hope, that neither of these last two gives the same 
results as the inline 'if'?

>>> x = 0
>>> print 3/x if x != 0 else -1
-1
>>> print {True: 3/x, False: -1}[x != 0]

Traceback (most recent call last):
  File "", line 1, in 
print {True: 3/x, False: -1}[x != 0]
ZeroDivisionError: integer division or modulo by zero
>>> print [-1, 3/x][x != 0]

Traceback (most recent call last):
  File "", line 1, in 
print [-1, 3/x][x != 0]
ZeroDivisionError: integer division or modulo by zero
>>> 

and before you suggest the good old standby and/or technique, that fails 
for other values:

>>> print x != 0 and 3/x or -1
-1
>>> x=5
>>> print x != 0 and 3/x or -1
-1
>>> 

You need to use the messy:

>>> print (x != 0 and (3/x,) or (-1,))[0]
0

to get exactly the same effect as the inline if with loss of both 
readability and performance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: variables with dynamicly generated names

2006-12-14 Thread Diez B. Roggisch
avlee schrieb:
> Hello
> 
> Is it possible to use in python variables with dynamicly created names ?
> How ?

In such cases, use a dictionary:

vars = {}

for some_name, some_value in some_values_generating_thing():
 vars[some_name] = some_value


Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Paul Rubin
Ken Tilton <[EMAIL PROTECTED]> writes:
> Again, that is precisely the point of macrology (in cases like
> this). When a pattern will repeat a sufficient number of times, and a
> function cannot handle the job,

But this is not a case where a function can't handle the job.

> Check out the latest, plz. The example has grown now beyond what a
> function can do, I think. meanwhile, I have not seen how Python lets
> you avoid revisiting dozens of instances when changes to a mechanism
> are required.

I'm missing what the difficulty is.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: variables with dynamicly generated names

2006-12-14 Thread Paul Rubin
avlee <[EMAIL PROTECTED]> writes:
> Is it possible to use in python variables with dynamicly created names ?

Yes, but don't.

> How ?

You almost certainly want to use something like a dictionary instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Ken Tilton


Ken Tilton wrote:
> 
> 
> Andrew Reilly wrote:
> 
>> On Thu, 14 Dec 2006 03:01:46 -0500, Ken Tilton wrote:
>>
>>
>>> You just aren't used to thinking at a level where one is writing code 
>>> to write code.
>>
>>
>>
>> Firstly, I'm looking into lisp because my current python project is too
>> full of boilerplate :-) and too slow.  Coming from a C and assembler
>> background, I'm *used* to meta-programming, and do it all the time.  I
>> even use python, Matlab and bash to write C, sometimes :-)
>>
>> However, in this particular instance, I'm inclined to wonder why
>> meta-programming is the right answer, rather than just doing all of the
>> interpolation and what-not at run-time, based on a big table of your
>> algebra rules? 
> 
> 
> I am afraid I do not see what alternative you are suggesting. I 
> especially do not see how interpolation is in play.

[Guessing pending your clarification] "Interpolation" does happen at 
runtime. This not about the actually quite rare use of macrology to move 
certain calculations to compile time, this is about getting dozens of 
transformation-specifc rules written to fit into a larger mechanism (by 
having the right arguments and returning the right kinds of results, 
with a minimum of boilerplate and a maximum of resiliency in the face of 
refactoring.

The reason I post macro expansions along with examples of the macro 
being applied is so that one can see what code would have to be written 
if I did not have the defskill macro to "write" them for me. I sugest 
one start there, by comparing before and after.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: variables with dynamicly generated names

2006-12-14 Thread Gabriel Genellina

At Thursday 14/12/2006 05:50, avlee wrote:


Is it possible to use in python variables with dynamicly created names ?
How ?


Use a dictionary:

d = {}
d[almost_arbitrary_key] = value


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Survey environment for Python?

2006-12-14 Thread Kay Schluehr
exhuma.twn schrieb:

> Hi,
>
> Just recently I had to take over support for legacy software written in
> Blaise (www.cbs.nl).

I don't understand the meaning of the link. Do you mean this language?

http://blaise.sourceforge.net/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Defining classes

2006-12-14 Thread Nick Maclaren

In article <[EMAIL PROTECTED]>,
Michael Spencer <[EMAIL PROTECTED]> writes:
|> 
|> "instantiation" (i.e., calling the __new__ method) of new-style classes 
|> can return whatever you like, but I'm not sure how that helps.

Yes and no.  While it can return any value you like, it can't act as
a class declaration - and that is what I need in this context!  My
request in this thread was because I am trying to find a way around
that restriction.  All right, I am looking for a seriously advanced
language feature, that doesn't exist in 99% of known languages :-)

I am very much out of touch with Lisp, but there was an almighty
hoo-hah over this point some 25 years back, during the design of
Common Lisp.  I believe that it included it, and I am pretty sure
that I could do it in Haskell (which I am almost as out of touch
with), but in no other language that most people will ever have
heard of.  But I am (again) out of touch with this area!

Ideally, what I want to do is to define a class (A) in Python that
has essentially no exposed methods, but which can be instantiated to
produce another class (B), which can then be used exactly like a
built-in class (which is what it is designed to be).  Each such
instantiation of (A) would be a distinct class (B), derived from (A).
All of the methods of (B) would be inherited from 'hidden' methods
of (A), most would be in C (the language), and few would usable
directly on 'objects' of class (A).

There are several ways of doing this in Python, but I can't find
any that are as transparent to the user as I would really like.

There is method in my madness :-)


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Defining classes

2006-12-14 Thread Nick Maclaren

In article <[EMAIL PROTECTED]>,
"Michele Simionato" <[EMAIL PROTECTED]> writes:
|> Nick Maclaren wrote:
|> > It would be much cleaner not to have to fiddle with static
|> > members after the class is initialised.
|> 
|> You can hide the fiddling, for instance with the trick explained here:
|> 
|> http://www.phyast.pitt.edu/~micheles/python/classinitializer.html

Thanks very much.  I shall definitely read that, to gain more understanding
if nothing else.


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread David Golden
William James wrote:

> Actually, it's 'among', not 'amongst', except to those who are
> lisping, degenerate pansies.
> 

lisping: "amongst" => "amongthpt" ?

"amongst" is a fairly common british english variant of "among".
 
>  Some pronunciations and usages "froze" when they reached the
>  American shore. In certain respects, American English is closer to
>  the English of Shakespeare than modern British English is. 


In certain respects, modern British English is closer to the
English of Shakespeare than American English is.

In this particular case, in Shakespeare's actual time, we can be pretty
sure ([1],[2]) that "parenthesis" meant the inserted parenthetical
phrase.

I do admit that since the later extension to round brackets themselves
is mentioned at link [2] below (and OED) as first appearing in 1715,
and given your later british examples, I was Just Wrong to lay sole
blame on the americans for it. 


[1]
The Arte of English Poesie by George Puttenham, 1589
http://www.gutenberg.org/etext/16420
Chap. XIII
"""
  [Sidenote: _Parenthesis_, or the Insertour]
Your first figure of tollerable disorder is [_Parenthesis_] or by an
English name the [_Insertour_] and is when ye will seeme for larger
information or some other purpose, to peece or graffe in the middest of
your tale an vnnecessary parcell of speach, which neuerthelesse may be
thence without any detriment to the rest. The figure is so common that
it
needeth none example, neuerthelesse because we are to teache Ladies and
Gentlewomen to know their schoole points and termes appertaining to the
Art, we may not refuse ro yeeld examples euen in the plainest cases, as
that of maister _Diars_ very aptly.
  _But now my Deere_ (_for so my loue makes me to call you still_)
  _That loue I say, that lucklesse loue, that works me all this ill._

Also in our Eglogue intituled _Elpine_, which we made being but eightene
yeares old, to king _Edward_ the sixt a Prince of great hope, we
surmised
that the Pilot of a ship answering the King, being inquisitiue and
desirous to know all the parts of the ship and tackle, what they were, &
to what vse they serued, vsing this insertion or Parenthesis.
  _Soueraigne Lord (for why a greater name
  To one on earth no mortall tongue can frame
  No statelie stile can giue the practisd penne:
  To one on earth conuersant among men.)_

And so proceedes to answere the kings question?
  _The shippe thou seest sayling in sea so large, &c._

This insertion is very long and vtterly impertinent to the principall
matter, and makes a great gappe in the tale, neuerthelesse is no
disgrace
but rather a bewtie and to very good purpose, but you must not vse such
insertions often nor to thick, nor those that bee very long as this of
ours, for it will breede great confusion to haue the tale so much
interrupted.

"""

[2] http://www.etymonline.com/index.php?term=parenthesis
[3] http://rhetoric.byu.edu/Figures/P/parenthesis.htm 


-- 
http://mail.python.org/mailman/listinfo/python-list


pwinauto to remote automate a GUI ?

2006-12-14 Thread baitelli
Hi!

pywinauto is a set of python modules to automate the Microsoft Windows GUI.
With the lines below we start and atomates the apllication Notepad:
 
from pywinauto import application
app = application.Application()
app.start('C:\Notepad.exe')
 ... pywinauto automation code

Question: Is it possible to start and automate a remote GUI using Python?

baitelli,r.

 _
 AVISO
   Esta mensagem é destinada exclusivamente a(s) pessoa(s) indicada(s)
   como destinatário(s), podendo conter informações confidenciais,
   protegidas por lei.
   A transmissão incorreta da mensagem não acarreta a perda de sua
   confidencialidade.
   Caso esta mensagem tenha sido recebida por engano, solicitamos que
   seja devolvida ao remetente e apagada imediatamente de seu sistema. É
   vedado a qualquer pessoa que não seja destinatário, usar, revelar,
   distribuir ou copiar ainda que parcialmente esta mensagem.
 _
 DISCLAIMER
   This message is destined exclusively to the intended receiver. It may
   contain confidential or legally protected information.
   The incorrect transmission of this message does not mean loss of its
   confidentiality.
   If this message is received by mistake, please send it back to the
   sender and delete it from your system immediately. It is forbidden to
   any person who is not the intended receiver to use, reveal,
   distribute, or copy any part of this message.
 _
-- 
http://mail.python.org/mailman/listinfo/python-list


javadoc equivalent?

2006-12-14 Thread Kant, Fredrik
Hi!

I saw this question, have you tried the standard python module pydoc
(you find it under Lib in the standard installation)?

 

Fredrik Kant

Phone: +46 (8) 4100 9795
Mobile: +46 (733) 38 50 42
Email: [EMAIL PROTECTED]   

TradeTech
Sturegatan 46
SE-114 36 Stockholm, SWEDEN
www.tradetech.se   


Confidentiality Notice
The content of this e-mail message is intended only for the confidential
use of the person(s) to whom it is addressed above. If the reader of
this message is not the designated person to whom it is addressed, you
are hereby notified that you have received this communication in error
and that reading it, copying it, or in any way disseminating its content
to any other person, is strictly prohibited. If you have received this
e-mail in error, please notify the author by using the reply key
immediately.

 

-- 
http://mail.python.org/mailman/listinfo/python-list

ANN: Pyflix-0.1

2006-12-14 Thread George Sakkis
Hi there,

I'm happy to announce Pyflix, a small Python package that provides an
easy entry point for those wishing to get up and running at the Netflix
Prize competition (http://www.netflixprize.com/). For those who are not
aware of it, the Netflix Prize challenge is to write a recommendation
algorithm that improves the accuracy of predictions about how much
someone is going to love a movie based based on their past ratings.
Netflix offers $1,000,000 (one million dollars) to the first team that
provides an algorithm that outperforms Cinematch (TM), the movie
recommendation system developed by Netflix, by 10% or more; there's
also a $50,000 Progress Prize awarded to the team with the most
improvement over the previous year's accuracy.

Pyflix requires Python 2.4 or later and Numpy 1.0. It combines an
efficient storage scheme with a high-level API that allows contestants
to focus on the real problem, the recommendation system algorithm.

You may download Pyflix and find more about it at
http://pyflix.python-hosting.com.

Enjoy and good luck!

George

-- 
http://mail.python.org/mailman/listinfo/python-list


open a directory in widows

2006-12-14 Thread Bell, Kevin
If I want "C:\temp" to pop open on screen, how do I do it?


-- 
http://mail.python.org/mailman/listinfo/python-list


Easier way yo use Py2exe

2006-12-14 Thread Scheol Service
The directions are confusing. Can someone clear them up.

Intructions Location: http://www.py2exe.org/index.cgi/Tutorial

OS: Windows XP Pro.
-- 
http://mail.python.org/mailman/listinfo/python-list


error: Error -5 while decompressing data from struct.unpack

2006-12-14 Thread Gary Robinson
One of our users received an exception, "error: Error -5 while 
decompressing data from struct.unpack," in the course of a 
struct.unpack operation. I haven't been able to discern what Error -5 
is in this context. In experiments here I wasn't able to elicit that 
exception.

There's a system exception EINTR which is 5 -- but that's 5, not -5.

Any help on this would be most appreciated.

-- 

Gary Robinson
CTO
Emergent Music, LLC
[EMAIL PROTECTED]
207-942-3463
Company: http://www.goombah.com
Blog:http://www.garyrobinson.net
-- 
http://mail.python.org/mailman/listinfo/python-list


logging

2006-12-14 Thread Lutz Steinborn
Hello,

I need to log each and only this loglevel to a different file.
So for example all INFO to info.log and all ERROR to error.log.

And I need a master logfile with all messages.

How can I do this ?
Any example ?


Kindly regards

Lutz

http://www.4c-wohnen.de
http://www.4c-parfum.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Snake references just as ok as Monty Python jokes/references inpython community? :)

2006-12-14 Thread Hendrik van Rooyen
 "John Machin" <[EMAIL PROTECTED]> wrote:


> Ah yes, exposure to Blackadder helps enormously ... after some hours
> spent trying to understand things like metaclasses, it's helpful to
> know what to do: put a pencil or chopstick up each nostril, wear your
> underpants on your head, and sit there muttering "wibble wibble" until
> they come to take you away.

Alternatively, you are allowed to sing Flanders and Swan's "Happy Song", 
in order to achieve the same end.

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


New York City Python Users Group meeting is planned for Dec. 12th @ 6pm - please RSVP!

2006-12-14 Thread John Clark
Greetings!

The next New York City Python Users Group meeting is this Tuesday, Dec.
12th, 6pm at at the Millennium Partners office at 666 Fifth Avenue on the
8th Floor.  We welcome all those in the NYC area who are interested in
Python to attend.  However, we need a list of first and last names to give
to building security to make sure you can gain access to the building.  If
you would please RSVP to clajo04ATmacDOTcom to add your name to the list.  

More information can be found on the yahoo group page:

http://tech.groups.yahoo.com/group/nycpython/

Hope to see you there!

-John


-- 
http://mail.python.org/mailman/listinfo/python-list


Working w/ Yield

2006-12-14 Thread Javier Subervi
Hi;
I'm trying to tweak a script I found here:
http://zopelabs.com/cookbook/1118667115
to get it to do what I want. I'm no wizard at Python, much less newfangled 
tools like yield. I understand that one cannot use "return" when working with 
yield, but I don't understand how to achieve the same result. Here's my code:

from random import randrange

def getRandomQuote(top, topdown=True):
  objs = top.objectValues()
  num = 1
  numAndQuote, quotes = [], []
  for obj in objs:
if isdir(obj):
  dirs.append(obj)
else:
  quotes.append(obj)
  if topdown:
yield top, dirs, quotes
  for obj in dirs:
for x in getRandomQuote(obj, topdown):
  yield x
  if not topdown:
yield top, dirs, quotes
  for q in quotes:
numAndQuote.append(num, q)
num += num

def isdir(obj):
  if obj.meta_type == 'Folder':
return True
  else:
return False

def demo(self):
  root = self.restrictedTraverse('/theSite/en-us/Books')
  num = randrange(1, len(num), 1)
  luckyWinner = numAndQuote.pop(num)
  path = '/'.join(luckyWinner.getPhysicalPath()) or '/'
  return path

How can I stitch all this together to return the path? Or, how do I call the 
demo after executing the yield?
TIA,
Javier


 

Want to start your own business?
Learn how on Yahoo! Small Business.
http://smallbusiness.yahoo.com/r-index-- 
http://mail.python.org/mailman/listinfo/python-list

Client side COM and Python Problem

2006-12-14 Thread Mark
Hey Guys, Im new to working with com but i only want to do one thing.

I have activestate python and am trying to get python to run a simple 
function in a com enabled 3d program called 3dsmax.  If i try and 
execute a function over the com interface it works fine as long as i 
dont try and run the function with an argument. when i run it with an 
argument like so. "o.mypingmax("test string")" it gives me an error in 
my client app and an error in python.

please help me understand this error and what i am doing wrong?  I have 
tried a similar script in another language and it works.  but python 
does not like it.

#code
import win32com.client
o = win32com.client.Dispatch("MAX.Application.8")
o.mypingmax("test string")

# Python Error

Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python24\lib\site-packages\win32com\client\dynamic.py", line 
491, in __getattr__
raise pythoncom.com_error, details
com_error: (-2147220992, 'CONNECT_E_NOCONNECTION', None, None)

#client Application error (3dsmax script output)

-- Argument count error: mypingmax wanted 1, got 0
   during OLE automation function call

Sorry if its blindingly obvious but i just cant work out what is going on.

Cheers,

Mark


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__

2006-12-14 Thread Almad
Thanks to everybody for replies, I'm now satisfied ^_^

Almad

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: pwinauto to remote automate a GUI ?

2006-12-14 Thread Tim Golden
[baitelli]

| pywinauto is a set of python modules to automate the 
| Microsoft Windows GUI.
| With the lines below we start and atomates the apllication Notepad:
|  
| from pywinauto import application
| app = application.Application()
| app.start('C:\Notepad.exe')
|  ... pywinauto automation code
| 
| Question: Is it possible to start and automate a remote GUI 
| using Python?

One way might be to have something like 
Pyro (http://pyro.sf.net) running on the
remote machine linked to a proxy on the local
machine.

TJG 


Tim Golden 
Senior Analyst Programmer 

Viacom Outdoor Ltd, Camden Wharf, 28 Jamestown Road, London, NW1 7BY T: 020 
7482 3000 F: 020 7267 4944 
Email: [EMAIL PROTECTED] www.viacom-outdoor.co.uk

The contents of this e-mail are confidential to the ordinary user of the e-mail 
address to which it was addressed, and may also be privileged. If you are not 
the addressee of this e-mail you may not copy, forward, disclose or otherwise 
use it or any part of it in any form whatsoever. If you have received this 
e-mail in error, please e-mail the sender by replying to this message. Viacom 
Outdoor Ltd reserves the right to monitor e-mail communications from 
external/internal sources for the purposes of ensuring correct and appropriate 
use of Viacom Outdoor facilities.


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About alternatives to Matlab

2006-12-14 Thread Jon Harrop
Paul Rubin wrote:
> Interesting, where do I get it, and is there source?  I've never been
> interested in Mono but maybe this is a reason.  How does the compiled
> code compare to OCaml or MLton code?

GC intensive code is 2-4x slower than OCaml or 4-8x slower than MLton.
Floating point intensive code is as fast as OCaml and MLton.

-- 
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread [EMAIL PROTECTED]

Neil Cerutti wrote:
> On 2006-12-13, [EMAIL PROTECTED]
> <[EMAIL PROTECTED]> wrote:
> > Try reading again. In Lisp, you use () and *your editor*
> > automatically indents according to the universal standard, or
> > you leave it sloppy until other folks reading your code
> > convince you to get a proper programming editor. Indentation
> > does not get out of sync with semantics because the editor
> > virtually never misses parentheses that the Lisp compiler sees.
> > Expressions keep the same meaning even if you have to start
> > breaking them across lines, etc.
>
> Yes, it's the same way in Python. Of course, not everything is an
> expression in Python, so it's not saying quite as much.

I fail to see how it is the same in Python. I go into a Lisp buffer
white-space area, and press  and absolutely nothing changes about
my program. There are two reasons for this: I am using a dumb editor
that puts a Tab in that my compiler doesn't care about, or I am using
the moral equivalent of Emacs, which reads  as "put this line on
the standard Lisp indentation level, as determined by the
non-whitespace characters in the area."

In Python, I hit that  and the smartest editor in the world would
have to say "Oh, you want to put this line on a different indentation
level, possibly including this line as part of the if: consequences
block above. Hope that helps!"

> > In Python, you group in your mind, and press indentation keys
> > to make it happen in your editor. The editor cannot help that
> > much, because it cannot read your mind. White space screwups in
> > copy-paste cannot be fixed by the editor automatically, because
> > it cannot read the original programmer's mind, and you have to
> > fix it manually, and risk screwing it up.
>
> It is very easy a manual process, possibly as simple as selecting
> the correct s-expr and pasting it into the right place in your
> code.

How does a manual correction process come out as simple as "don't
bother fixing the indentation if you don't care."?

This is exactly the questionable math that I was questioning in the
original post.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pwinauto to remote automate a GUI ?

2006-12-14 Thread Tim Golden
Tim Golden wrote:

[... snip horrendous company-generated sig/disclaimer ...]

Sorry about that, folks. We've started using a new
server-based sig generation thing so I'll have to start
not sending via company email!

TJG

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Andrew Reilly
On Thu, 14 Dec 2006 04:06:26 -0500, Ken Tilton wrote:
> Ken Tilton wrote:
>> Andrew Reilly wrote:
>>> However, in this particular instance, I'm inclined to wonder why
>>> meta-programming is the right answer, rather than just doing all of the
>>> interpolation and what-not at run-time, based on a big table of your
>>> algebra rules? 
>> 
>> I am afraid I do not see what alternative you are suggesting. I 
>> especially do not see how interpolation is in play.
> 
> [Guessing pending your clarification] "Interpolation" does happen at 
> runtime. This not about the actually quite rare use of macrology to move 
> certain calculations to compile time, this is about getting dozens of 
> transformation-specifc rules written to fit into a larger mechanism (by 
> having the right arguments and returning the right kinds of results, 
> with a minimum of boilerplate and a maximum of resiliency in the face of 
> refactoring.
> 
> The reason I post macro expansions along with examples of the macro 
> being applied is so that one can see what code would have to be written 
> if I did not have the defskill macro to "write" them for me. I sugest 
> one start there, by comparing before and after.

Please pardon my woeful grasp of lisp: that's probably why I'm off-beam
here.  It seemed to me that the bulk of your macro-ified/templated version
was taking some text and a "reverse" operation and creating the methods of
an object, or generic functions or ??  Each skill seems to have a title, a
list of annotations, and a list of hints (and a reverse, which I don't
understand).  That all looks like data.  Couldn't you do that with a table
containing those fields, and key it off the defskill argument (or even the
title?) at startup?  Then you don't have to worry about re-factoring the
code: there's only going to be one piece of code, driven by a table.

I only mentioned interpolation because it seemed likely that you might
want to be mutating these strings to be more specific to what your student
was actually doing.  I didn't expect that "42" was necessarily the right
answer...

To back out a bit, here, and get back to the meat of the matter: if one is
using Python, then it's because one doesn't much care about performance,
and it's reasonable to do expansions, pattern matching and domain specific
language creation/use at run-time.  After all, that's how the language
itself works, mostly.

When one finds that one *does* care about performance, that doesn't leave
much wriggle room, though...

-- 
Andrew
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional iteration

2006-12-14 Thread Diez B. Roggisch
> Is it redundant according to your criteria, yes I would say:
> 
> a = {True: a, False: c}[condition]
> 
> or 
> 
> a = [c, a][condition]
> 
> would yield exactly the same even in one sentence

Obviously it is _not_ the exact same.


def fac(n):
  return n * fac(n-1) if n else 1


Try that with your recipes above.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread [EMAIL PROTECTED]

Christophe wrote:
> [EMAIL PROTECTED] a écrit :
> > Bjoern Schliessmann wrote:
> >> Robert Uhl wrote:
> >>
> >>> Because it's the language for which indentation is automatically
> >>> determinable.  That is, one can copy/paste a chunk of code, hit a
> >>> key and suddenly everything is nicely indented.
> >> Cool, so in other languages I need to set block marks like () and {}
> >> and also indent the code for readability, and in Python I indent
> >> only. From my POV that's less work.
> >
> > Try reading again. In Lisp, you use () and *your editor* automatically
> > indents according to the universal standard, or you leave it sloppy
> > until other folks reading your code convince you to get a proper
> > programming editor. Indentation does not get out of sync with semantics
> > because the editor virtually never misses parentheses that the Lisp
> > compiler sees. Expressions keep the same meaning even if you have to
> > start breaking them across lines, etc.
> >
> > In Python, you group in your mind, and press indentation keys to make
> > it happen in your editor. The editor cannot help that much, because it
> > cannot read your mind. White space screwups in copy-paste cannot be
> > fixed by the editor automatically, because it cannot read the original
> > programmer's mind, and you have to fix it manually, and risk screwing
> > it up.
>
> Call us when you have an editor that reads your mind and writes the ()
> for you.

This is an irrelevancy. Typos that drop printing characters in either
language will generally cause changes to the semantics. Lisp
programmers, incidentally, will see that their editor indented things
in a funky way and recognize "hey, I dropped a paren somewhere in that
copy-paste." (And, if so, it is usually at the end, and can be
recovered using automatic matching when typing the ')' ). And,
honestly, the punctuation is no harder to type in Lisp than in other
languages, they just occur in different (and more consistent) places.

The point of Python is that changing white-space to
different-white-space changes the semantics. At best an editor can
notice "hey, funky white-space here, please correct" as IDLE did when I
wrote my first Python in a non-Python-aware editor, and somehow had
swapped tabs and spaces; when I moved it to IDLE---the indentation
*looked fine* but was invisibly weird. At worst, an editor can go
"sure, I'll let you change your program."

I'm not saying the worst case is typical. The annoying case is more
likely. I will even admit that white-space significance does not
materially increase errors among experienced Pythonistas. What it isn't
is some kind of miraculous invention that saves programmers from ever
making mistakes that are common in other languages, or that reduces
effort in copy-paste, as Bjoern seemed to be claiming.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About alternatives to Matlab

2006-12-14 Thread Jon Harrop
Filip Wasilewski wrote:
> Jon Harrop wrote:
>> Filip Wasilewski wrote:
>> > Jon, both Python and Matlab implementations discussed here use the
>> > lifting scheme, while yours is a classic convolution based approach.
>>
>> I've done both in OCaml. The results are basically the same.
> 
> Have you tried taking advantage of the 50% reduction of arithmetic
> operations for the lifting scheme?

Yes. The time taken is dominated by memory accesses. The amount of
arithmetic is almost irrelevant.

>> It makes sense because they solve the same problem. When you're comparing
>> non-trivial problems between disparate languages you are not likely to
>> use the same algorithms. Using built-in hash functions is an obvious
>> example.
> 
> I don't even ask if you have checked the output result coefficients
> because I'm pretty sure you have not.

I checked the coefficients against other DWTs from the web.

> They solve similar problem but in 
> different ways and give a bit different results, for example the
> layout of coefficients in the memory is different as well as border
> distortion handling. Please don't tell me it's better to do something
> else instead of presenting a relevant solution.

I used a more efficient approach because I could. Using a compiled language
gave me that choice. We should compare both approaches in both languages.

>> No. The effects you are talking about are swamped by the interpreted vs
>> compiled effect.
> 
> Have I already mentioned it was observed with low-level C
> implementation on x86? I would really appreciate you took some time on
> exploring the unfortunate topic of this benchmark before posting
> another comment like that.

We are talking about this Python implementation, not some "low-level C
implementation on x86". With Python, it is the overhead of the interpreter
that makes it slow and encourages you to obfuscate your code in order to
make it run in a reasonable amount of time.

> What I would really like to see is a lifting scheme 
> implementation that can take 1- to 10-dimensional arrays

I believe that is just a case of abstracting get/set.

> (single and double precision floats,

That is also a case of abstracting get/set.

> convert on the fly from integer types when necessary

That is dynamic typing.

> and handle strided, non-contiguous arrays),

That is also an abstraction of get/set.

> axis and maximum decomposition level as input

I don't know what that is.

> and return list of views (or arrays if necessary)

Probably just a closure.

> with transform coefficients for every level of 
> decomposition. Can do?

Sure. Sounds like a lot of work though. This would be best done in F#
because you can make your own IList derivatives with get_Item and set_Item
that provide views but look like arrays.

> Are you telling I have to define a different operator for every
> arithmetic operation for every two types?

In OCaml, yes. Not in F#.

> That definitely does not look 
> like a quick, flexible and clear solution to start with. Any working
> example I could type into OCamlWinPlus of the following would be very
> appreciated. I'm fairly new to this and would really like to see how to
> handle differently shaped arrays and data types in the interactive mode
> without much hassle:
> 
> from numpy import ones, arange, reshape, int32
> a = ones((2,3,4,5))
> b = ones(a.shape, dtype=int32)
> c = ones((3,4,5))
> d = 2*a + 2.5*(3*b + 3.3)
> d[0] = d[0] + 5
> d[1] *= c * (2+3*1.2)
> d[:,2,...] = reshape(arange(d[:,2,...].size), d[:,2,...].shape)
> print d[...,1]

I can't get that to work in Python. What do I need to do?

>>> import numpy
>>> a = ones((2,3,4,5))
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'ones' is not defined

> The ray tracer example is really nice, however the sudoku solver is not
> so impressive when compared to the K thingy ;-) -
> http://markbyers.com/moinmoin/moin.cgi/ShortestSudokuSolver.

Well, OCaml does ok on the sudoku but K does awfully on the ray tracer.

>> > I was also unable to run your OCaml example for n >= 2^21 (win32, out
>> > of the box OCaml installation). Is there some 16MB memory limit imposed
>> > on Array?
>> > # let q = Array.make (1 lsl 21) 0.0;;
>> > Exception: Invalid_argument "Array.make".
>>
>> On 32-bit, yes. You'd either have to use a different data structure
>> (Bigarrays), upgrade or switch to F#.
> 
> That renders the Array type almost useless for me. Where can I find
> documentation or tutorial on using Bigarrays?

http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.html

You probably want to use F# though.

-- 
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open a directory in widows

2006-12-14 Thread Tim Golden
Bell, Kevin  slcgov.com> writes:

> 
> If I want "C:\temp" to pop open on screen, how do I do it?


import os
os.startfile (r"c:\temp")



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Christophe
Robert Uhl a écrit :
> Christophe <[EMAIL PROTECTED]> writes:
>> Saying that the French units are technically worse than standard units
>> is a troll of very poor quality and a very weak argument.
> 
> It was just an example that the argument from popularity is invalid.
> However, I (and many others) would argue that optimisation for unit
> conversion is the wrong choice when designing a system of measures.  But
> this is not the venue for such a discussion, so I'll stop now:-)

Well, I spent some time on Wikipedia looking up metric systems and 
things like that because of you, and I found a page that shows how to 
improve the current SI system by reducing the number of fundamental 
units to only two ( S for space and T for time ), and it was a great 
read. It even went so far as give a theory for the disapearance of the 
dinosaurs!

Thank you for that it was a great read.

Here it is : http://www.blazelabs.com/f-u-suconv.asp
-- 
http://mail.python.org/mailman/listinfo/python-list


remove matching pairs

2006-12-14 Thread Evan
Is there a simple way to to identify and remove matching pairs from 2
lists?

For example:

I have

a=[2, 5, 3, 4, 7, 2, 2, 4, 8, 1]
b=[7, 3, 5, 8, 1, 7, 4, 8, 2, 6]

and I want to get this:

a=[2, 5, 3, 4, 7, 2, 8, 1]
b=[7, 3, 5, 8, 1, 4, 2, 6]

There are recurring pairs of (2, 7) and (4, 8), and so I want to remove
one of each pair.

Many thanks, Evan

-- 
http://mail.python.org/mailman/listinfo/python-list


tuple.index()

2006-12-14 Thread Nick Maclaren

Why doesn't the tuple type have an index method?  It seems such a
bizarre restriction that there must be some reason for it.  Yes,
I know it's a fairly rare requirement.


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Survey environment for Python?

2006-12-14 Thread Paddy


On Dec 14, 9:12 am, "Kay Schluehr" <[EMAIL PROTECTED]> wrote:
> exhuma.twn schrieb:
>
> > Hi,
>
> > Just recently I had to take over support for legacy software written in
> > Blaise (www.cbs.nl).I don't understand the meaning of the link. Do you mean 
> > this language?
>
> http://blaise.sourceforge.net/

http://www.cbs.nl/nl-NL/menu/_unique/_search/default.htm?querytxt=blaise

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: remove matching pairs

2006-12-14 Thread Tim Chase
> Is there a simple way to to identify and remove matching pairs from 2
> lists?
> 
> For example:
> 
> I have
> 
> a=[2, 5, 3, 4, 7, 2, 2, 4, 8, 1]
> b=[7, 3, 5, 8, 1, 7, 4, 8, 2, 6]
> 
> and I want to get this:
> 
> a=[2, 5, 3, 4, 7, 2, 8, 1]
> b=[7, 3, 5, 8, 1, 4, 2, 6]

Well, with a few caveats, the following works:

 >>> a=[2, 5, 3, 4, 7, 2, 2, 4, 8, 1]
 >>> b=[7, 3, 5, 8, 1, 7, 4, 8, 2, 6]
 >>> a_prime, b_prime = zip(*set(zip(a,b)))
 >>> a_prime
(2, 8, 4, 7, 1, 5, 2, 3)
 >>> b_prime
(7, 2, 8, 1, 6, 3, 4, 5)

Caveat #1: the order changed because sets are unordered
Caveat #2: a_prime and b_prime are tuples, not lists

If this isn't a true solution (because either #1 or #2 is an 
unacceptable condition), you'd have to go with a loop...something 
like this untested

pairs = zip(a,b)
uniq = set(pairs)
a_prime = []
b_prime = []
for pair in pairs:
if pair in uniq:
a_prime.append(pair[0])
b_prime.append(pair[1])
uniq.remove(pair)
#if not uniq: break

This should preserve the order as well as maintain listsrather 
than return tuples.  Depending on the number of duplicates you 
expect and the size of your a/b lists, uncommenting out that last 
line may give you a short speedup, as if you've already pulled 
all the items out the uniq set, there's no reason to continue 
iterating over the list of pairs.

HTH,

-tkc





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional iteration

2006-12-14 Thread Roberto Bonvallet
at wrote:
> I think by approving
> 
> a = b if condition else c
> 
> used to avloind
> 
> if condition:
>a = b
> else:
>a = c
> 
> which is dealing with same psychological problem, Guido also recognizes some
> need...

GvR did not introduce the new conditional syntax because he felt it was
needed or just to avoid typing a couple of extra lines.  He did it just to
avoid people keep using the ugly and error-prone "a and b or c" idiom.  See
the related PEP:  http://www.python.org/dev/peps/pep-0308/

-- 
Roberto Bonvallet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Fredrik Lundh
Nick Maclaren wrote:

> Why doesn't the tuple type have an index method?  It seems such a
> bizarre restriction that there must be some reason for it.

hah!  not being able to remove or add things to tuples is an even 
bizarrer restriction!



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed of python vs matlab.

2006-12-14 Thread Christophe
Chao a écrit :
> My Bad,  the time used by python is 0.46~0.49 sec,
> I tried xrange, but it doesn't make things better.
> 
> import time
> tic = time.time()
> a = 1.0
> 
> array = range(1000)
> 
> for i in array:
> for j in array:
>   a = a + 0.1
> 
> toc = time.time()
> print toc-tic,' has elapsed'

Place all your code inside functions please. IIRC, local variable access 
is much faster that way, and you do a lot of lookup for the a local 
variable in that code.


import time

def main():
 a = 1.0

 array = range(1000)

 for i in array:
 for j in array:
 a = a + 0.1

tic = time.time()
main()
toc = time.time()
print toc-tic,' has elapsed'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error: Error -5 while decompressing data from struct.unpack

2006-12-14 Thread Fredrik Lundh
Gary Robinson wrote:

> One of our users received an exception, "error: Error -5 while 
> decompressing data from struct.unpack," in the course of a 
> struct.unpack operation. I haven't been able to discern what Error -5 
> is in this context. In experiments here I wasn't able to elicit that 
> exception.
> 
> There's a system exception EINTR which is 5 -- but that's 5, not -5.
> 
> Any help on this would be most appreciated.

from what I can tell, the word "decompressing" is only used in the zlib 
sources in Python.  are you sure the user didn't mean "zlib.decompress" 
instead of "struct.unpack" ?



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed of python vs matlab.

2006-12-14 Thread Roberto Bonvallet
Chao wrote:
> My Bad,  the time used by python is 0.46~0.49 sec,
> I tried xrange, but it doesn't make things better.

Actually it does:  it doesn't waste time and space to create a big list.

-- 
Roberto Bonvallet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Nick Maclaren

In article <[EMAIL PROTECTED]>,
Fredrik Lundh <[EMAIL PROTECTED]> writes:
|> 
|> > Why doesn't the tuple type have an index method?  It seems such a
|> > bizarre restriction that there must be some reason for it.
|> 
|> hah!  not being able to remove or add things to tuples is an even 
|> bizarrer restriction!

Eh?  Why?

My understanding of the difference between a tuple and a list is
PRECISELY that the former is immutable and the latter mutable.
But an index method makes precisely as much sense on an immutable
sequence as it does on a mutable one.


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Routine for prefixing '>' before every line of a string

2006-12-14 Thread Sanjay
Hi All,

Is somewhere a routine useful to convert a string to lines of maxsize,
each prefixed with a '>'. This is a typical requirement for 'keeping
existing text while replying to a post in a forum'.

It can be developed, but if something obvious is already there(I being
new to python might not be aware), than it would be great just to reuse
it!

thanks
sanjay

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Christophe
[EMAIL PROTECTED] a écrit :
> Christophe wrote:
>> Call us when you have an editor that reads your mind and writes the ()
>> for you.
> 
> This is an irrelevancy. Typos that drop printing characters in either
> language will generally cause changes to the semantics. Lisp
> programmers, incidentally, will see that their editor indented things
> in a funky way and recognize "hey, I dropped a paren somewhere in that
> copy-paste." (And, if so, it is usually at the end, and can be
> recovered using automatic matching when typing the ')' ). And,
> honestly, the punctuation is no harder to type in Lisp than in other
> languages, they just occur in different (and more consistent) places.
> 
> The point of Python is that changing white-space to
> different-white-space changes the semantics. At best an editor can
> notice "hey, funky white-space here, please correct" as IDLE did when I
> wrote my first Python in a non-Python-aware editor, and somehow had
> swapped tabs and spaces; when I moved it to IDLE---the indentation
> *looked fine* but was invisibly weird. At worst, an editor can go
> "sure, I'll let you change your program."
> 
> I'm not saying the worst case is typical. The annoying case is more
> likely. I will even admit that white-space significance does not
> materially increase errors among experienced Pythonistas. What it isn't
> is some kind of miraculous invention that saves programmers from ever
> making mistakes that are common in other languages, or that reduces
> effort in copy-paste, as Bjoern seemed to be claiming.

So, you are more or less saying that, using a smart Lisp editor, you'll 
easily catch block errors when you misplace a bracket, but using dumb 
Python editors allows inconsistent tab-space usage to go unnoticed?

Yeah, nothing wrong in what you said but hardly relevant I say :)

For the Python side, I just hope that -tt becomes the default option one 
day ( interpreter causes errors when mixing spaces and tabs )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Easier way yo use Py2exe

2006-12-14 Thread Fredrik Lundh
Scheol Service wrote:

> The directions are confusing. Can someone clear them up.
> 
> Intructions Location: http://www.py2exe.org/index.cgi/Tutorial

looks pretty straightforward to me.  create a simple python script, 
write a short setup.py file that points to the script, run it to get
an executable, and then run the executable.

maybe you could explain what you found confusing?



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Nick Maclaren wrote:
> Why doesn't the tuple type have an index method?  It seems such a
> bizarre restriction that there must be some reason for it.

In fact, tuples have no non-__underscored__ methods at all.  The list
count() method would also be useful for tuples, since it doesn't modify
anything.  I have no idea why they aren't implemented either.

Glenn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Simon Brunning
On 12/14/06, Nick Maclaren <[EMAIL PROTECTED]> wrote:
> Well, if that were so, it would explain things.  But lists AREN'T
> necessarily homogeneous!
>
> >>> a=[52,"abc",[1,2],5.6]
> >>> print repr(a)
> [52, 'abc', [1, 2], 5.5996]

It's not a technical restriction, as I said, but it's what lists are *for*.

Indeed, it *can't* be a technical restriction, because, as I said, by
'type' I wasn't referring to anything technical. A list might contain,
for example, "things to process". That's a conceptual kind of thing,
so the list is conceptually homogeneous, but technically speaking, the
list might contain instances of any class (or built-in type).

A good example of a tuple, OTOH, might be a database tuple, i.e. a row
returned from an RDBMS. Even if all the tables columns are of the same
type - say, strings - it doesn't mean that they are interchangeable.
Their position has semantic significance - it means something.

Make sense?

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Fredrik Lundh
Nick Maclaren wrote:

> My understanding of the difference between a tuple and a list is
> PRECISELY that the former is immutable and the latter mutable.

while tuples can be used as "frozen lists", that's definitely not what 
they are, from a design perspective.

just like in math [1], a Python tuple is a heterogeneous sequence where 
the position implies type and usage.  in contrast, a list is a homo- 
geneous collection where all the items are "the same" in some sense,
no matter where they are.  if you sort or otherwise reorder a list
of things, it's still a list of the same things.  if you sort a tuple, 
you'll break it.

in other words, you're supposed to know what the individual items are in 
a tuple; if you feel the need to search for things by value in a tuple, 
you're using the wrong container type.



1) http://en.wikipedia.org/wiki/Tuple

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Simon Brunning
On 14 Dec 2006 11:24:04 GMT, Nick Maclaren <[EMAIL PROTECTED]> wrote:
>
> Why doesn't the tuple type have an index method?  It seems such a
> bizarre restriction that there must be some reason for it.  Yes,
> I know it's a fairly rare requirement.

It's because, philosophically, a Python tuple isn't just a read-only list.

Lists are for homogeneous data, all entries being of the same 'type'.
('Type' here doesn't refer to class or anything like that - just
conceptual type - what kind of thin g it is.) So, you can infer no
semantic meaning from an items position in the list. Sorting makes
sence,m and does looking though a list to find something - hence
index().

A tuple, on the other hand, is heterogeneous. The fact that an item is
the nth item is a tuple *means* something. Sorting a tuple would make
no sense, even if it were possible, and you are supposed to know where
in the tuple things are, so it makes no sense to search for it.

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: remove matching pairs

2006-12-14 Thread Evan
That's great, thank you, the caveats are no matter!

-Evan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Neil Cerutti
On 2006-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Neil Cerutti wrote:
>> On 2006-12-13, [EMAIL PROTECTED]
>> <[EMAIL PROTECTED]> wrote:
>> > Expressions keep the same meaning even if you have to start
>> > breaking them across lines, etc.
>>
>> Yes, it's the same way in Python. Of course, not everything is
>> an expression in Python, so it's not saying quite as much.
>
> I fail to see how it is the same in Python.

if self.flee == (foo.humble(pie) / 500 * hats
+ hippity.hoppity)

The indentation of the second line of that expression is entirely
irrelevant to Python. The parenthesis I added means I don't have
to use the new-line escape character (\), either.

>> > In Python, you group in your mind, and press indentation
>> > keys to make it happen in your editor. The editor cannot
>> > help that much, because it cannot read your mind. White
>> > space screwups in copy-paste cannot be fixed by the editor
>> > automatically, because it cannot read the original
>> > programmer's mind, and you have to fix it manually, and risk
>> > screwing it up.
>>
>> It is very easy a manual process, possibly as simple as
>> selecting the correct s-expr and pasting it into the right
>> place in your code.
>
> How does a manual correction process come out as simple as
> "don't bother fixing the indentation if you don't care."?
>
> This is exactly the questionable math that I was questioning in
> the original post.

Python simply replaces one manual process (moving to the correct
scope (usually sitting on an open or close parenthesis) and then
hitting the grab-s-expr command) with another (after pasting,
correct the indentation--generally a trivial task). I think it's
a major stretch to call either process anything but trivially
easy for an experiences user of the language.

-- 
Neil Cerutti
The Pastor would appreciate it if the ladies of the congregation would lend
him their electric girdles for the pancake breakfast next Sunday morning.
--Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic style involves lots of lightweight classes (for me)

2006-12-14 Thread Andrea Griffini
metaperl wrote:

>  The above program started out as a list of dictionaries, but I
> like the current approach much better.

There is even a common idiom for this...

class Record(object):
 def __init__(self, **kwargs):
 self.__dict__.update(kwargs)

This way you can use

 user = Record(name="Andrea Griffini", email="[EMAIL PROTECTED]")

and then access the fields using user.name syntax

HTH
Andrea
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Routine for prefixing '>' before every line of a string

2006-12-14 Thread Boris Borcic
Sanjay wrote:
> Hi All,
> 
> Is somewhere a routine useful to convert a string to lines of maxsize,
> each prefixed with a '>'. This is a typical requirement for 'keeping
> existing text while replying to a post in a forum'.
> 
> It can be developed, but if something obvious is already there(I being
> new to python might not be aware), than it would be great just to reuse
> it!
> 
> thanks
> sanjay
> 

def fixlines(stuff) :
for line in stuff.split(line_separator) :
for chunkstart in range(0,len(line),maxsize) :
yield prefix + line[chunkstart:chunkstart+maxsize]
-- 
http://mail.python.org/mailman/listinfo/python-list


PyThreadState_SetAsyncExc (nThreadId ??????, exc);

2006-12-14 Thread iwl
what is the nThreadId-Parameter of PyThreadState_SetAsyncExc?

I try to implement a Terminate-Button in my C-Prog for my
embedded Python, but its hard to find an example how to
stop an interpreter running in an thread.

I found no other Python C-App-Func returning such a parameter.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Survey environment for Python?

2006-12-14 Thread exhuma.twn
Kay Schluehr wrote:
> exhuma.twn schrieb:
>
> > Hi,
> >
> > Just recently I had to take over support for legacy software written in
> > Blaise (www.cbs.nl).
>
> I don't understand the meaning of the link. Do you mean this language?
>
> http://blaise.sourceforge.net/

Not quite ;)

Sorry for being too vague. This is the correct link:
http://www.cbs.nl/en-GB/menu/informatie/onderzoekers/blaise-software/default.htm

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread [EMAIL PROTECTED]

Neil Cerutti wrote:
> On 2006-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> > Neil Cerutti wrote:
> >> On 2006-12-13, [EMAIL PROTECTED]
> >> <[EMAIL PROTECTED]> wrote:
> >> > Expressions keep the same meaning even if you have to start
> >> > breaking them across lines, etc.
> >>
> >> Yes, it's the same way in Python. Of course, not everything is
> >> an expression in Python, so it's not saying quite as much.
> >
> > I fail to see how it is the same in Python.
>
> if self.flee == (foo.humble(pie) / 500 * hats
> + hippity.hoppity)
>
> The indentation of the second line of that expression is entirely
> irrelevant to Python. The parenthesis I added means I don't have
> to use the new-line escape character (\), either.

Is this so unconscious that you don't recognize you are doing it, even
though you take a sentence to explain what you had to do to work around
it? Adding parentheses, new-line escape characters---all this is a
burden specific to Python.


> > How does a manual correction process come out as simple as
> > "don't bother fixing the indentation if you don't care."?
> >
> > This is exactly the questionable math that I was questioning in
> > the original post.
>
> Python simply replaces one manual process (moving to the correct
> scope (usually sitting on an open or close parenthesis) and then
> hitting the grab-s-expr command) with another (after pasting,
> correct the indentation--generally a trivial task). I think it's
> a major stretch to call either process anything but trivially
> easy for an experiences user of the language.

The reformatting (admittedly generally trivial, although again your
qualifier of "generally" undermines your point) process is extra in
Python. Period.

1) Recognizing where your code begins and ends to begin the copy-paste
process is not unique to either. Equal.
2) In a python-aware editor, I presume the grab-block keystroke exists
and is equivalent to grab-s-expr. Or, you have to manually select to
tell the editor where the block ends. Equal.
3) Recognizing where you want to paste is the same. Equal.
4) The paste keystroke is presumed Equal.

Lispers are done here.

5) After you are done, Pythonistas admit there is a possible step
called "manually correct the indentation."

Can I be any clearer? Now, you can say 5 is usually generally trivially
easy for an experienced Pythonista in 'the flow' or whatever you like,
but it just is not there for Lisp.

This is pointless discussion if you guys can't even see what you are
saying when you write it in your own posts.

By the way, you guys seem fixate on the parentheses of Lisp without
having the experience which shows that open parens are trivial to find,
because they don't occur in clumps and they are marked by the operator
symbol. The close parens occur in somewhat ugly clumps, but the editor
is the only thing that needs to deal with them.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Routine for prefixing '>' before every line of a string

2006-12-14 Thread Peter Otten
Sanjay wrote:

> Is somewhere a routine useful to convert a string to lines of maxsize,
> each prefixed with a '>'. This is a typical requirement for 'keeping
> existing text while replying to a post in a forum'.

>>> import textwrap
>>> format = textwrap.TextWrapper(20, initial_indent="] ",
subsequent_indent="] ").fill
>>> print format("alpha beta gamma delta\nepsilon zeta eta theta")
] alpha beta gamma
] delta epsilon zeta
] eta theta

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I edit a PythonWin path to import custom built modules???

2006-12-14 Thread BartlebyScrivener
Fredrik Lundh wrote:

> is this an ActiveState build?

Yes, I think I mentioned it further up the thread.

> what's sys.prefix and sys.exec_prefix set to on your machine, btw?

'C:\\Python24'

No big deal. I always just assumed that it found my scripts via the
path variable. As long as it finds them. I'm happy.

But you got me thinking. I just did the commands you suggested on my
laptop, after installing python.org 2.5. With 'd:\python' in the path
environmental variable there also, it does NOT appear when I do plain
old:

>>>sys.path

but does appear when I import site first.

rd

-- 
http://mail.python.org/mailman/listinfo/python-list


Multiple inheritance and __slots__

2006-12-14 Thread [EMAIL PROTECTED]
Hi all,
>From the google search, it seems its not possible to do the following.

>>> class Test1(object):
... __slots__ = ['a']
...
>>> class Test2(object):
... __slots__ = ['b']
...
>>> class Test3(Test1,Test2):
... __slots__ = ['c']
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: Error when calling the metaclass bases
multiple bases have instance lay-out conflict

I just want to make sure that I am using only the attributes a,b and c
from the instances of Test3 . Is there any other hack that could be
done.

--
Suresh

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Routine for prefixing '>' before every line of a string

2006-12-14 Thread Roberto Bonvallet
Sanjay wrote:
> Is somewhere a routine useful to convert a string to lines of maxsize,
> each prefixed with a '>'. This is a typical requirement for 'keeping
> existing text while replying to a post in a forum'.

Take a look to the textwrap module:
http://docs.python.org/lib/module-textwrap.html

Here is an example:

# the text is actually a very long line
text = '''Lorem ipsum dolor sit amet, consectetuer adipiscing [...]'''
prefix = '>'

import textwrap
lines = ["%s %s" % (prefix, line) for line in textwrap.wrap(text, width=75)]

for line in lines:
print line

This prints:

> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam rhoncus,
> justo eget facilisis gravida, lorem elit pellentesque urna, sed imperdiet
> orci nisl sed nibh. Curabitur dignissim pretium magna. Proin nunc justo,
> luctus ut, mollis sed, bibendum vel, nibh. Morbi rutrum est in nisl. Fusce
> sagittis. Integer varius. Vivamus dapibus lectus sed nisl. Phasellus
> gravida dignissim augue. Curabitur eget orci. Nulla ante augue, adipiscing
> a, consequat ut, elementum ac, libero. Donec malesuada lacus vel quam. Ut 
a
> massa vel velit fringilla rutrum. Maecenas massa sem, vulputate non,
> lacinia eu, cursus ut, urna. Donec ultrices sollicitudin nunc. Sed vel 
arcu
> in lacus posuere faucibus. Lorem ipsum dolor sit amet, consectetuer
> adipiscing elit.

HTH.  Cheers,
-- 
Roberto Bonvallet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Neil Cerutti
On 2006-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Neil Cerutti wrote:
>> On 2006-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> >
>> > Neil Cerutti wrote:
>> >> On 2006-12-13, [EMAIL PROTECTED]
>> >> <[EMAIL PROTECTED]> wrote:
>> >> > Expressions keep the same meaning even if you have to start
>> >> > breaking them across lines, etc.
>> >>
>> >> Yes, it's the same way in Python. Of course, not everything
>> >> is an expression in Python, so it's not saying quite as
>> >> much.
>> >
>> > I fail to see how it is the same in Python.
>>
>> if self.flee == (foo.humble(pie) / 500 * hats
>> + hippity.hoppity)
>>
>> The indentation of the second line of that expression is entirely
>> irrelevant to Python. The parenthesis I added means I don't have
>> to use the new-line escape character (\), either.
>
> Is this so unconscious that you don't recognize you are doing
> it, even though you take a sentence to explain what you had to
> do to work around it? Adding parentheses, new-line escape
> characters---all this is a burden specific to Python.

It already indicated that you are right about Python identation
*outside* of an expression, which is where most indentation takes
place in Python. But you were wrong that it is meaningful inside
an expression.

> The reformatting (admittedly generally trivial, although again
> your qualifier of "generally" undermines your point) process is
> extra in Python. Period.
>
> 1) Recognizing where your code begins and ends to begin the
> copy-paste process is not unique to either. Equal.

Reflecting on what you've written, I see you are right about this
issue. Thanks for the correction.

> 5) After you are done, Pythonistas admit there is a possible
> step called "manually correct the indentation."

Meaningful indentation has drawbacks *and* advantages, though.

> This is pointless discussion if you guys can't even see what
> you are saying when you write it in your own posts.

Please don't assume I speak for all Python programmers. They
might be rolling there eyes at me just as much as you are. ;-)

-- 
Neil Cerutti
In my prime I could have handled Michael Jordan.  Of course, he would be only
12 years old. --Jerry Sloan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple inheritance and __slots__

2006-12-14 Thread Simon Brunning
On 14 Dec 2006 05:23:33 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hi all,
> >From the google search, it seems its not possible to do the following.
>
> >>> class Test1(object):
> ... __slots__ = ['a']
> ...
> >>> class Test2(object):
> ... __slots__ = ['b']
> ...
> >>> class Test3(Test1,Test2):
> ... __slots__ = ['c']
> ...
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: Error when calling the metaclass bases
> multiple bases have instance lay-out conflict
>
> I just want to make sure that I am using only the attributes a,b and c
> from the instances of Test3 . Is there any other hack that could be
> done.

Difficulty with subclassing is the price you pay for abusing slots.
Slots are intended as a performance tweak only, to minimise the memory
footprint of classes of which you are going to have a great number of
instances.

In short - don't do that.

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Simon Brunning wrote:
> It's because, philosophically, a Python tuple isn't just a read-only list.

But there are situations where you might want to treat it as a
read-only list.  E.g., an argument to a function, so that you can
guarantee the function won't modify it.  In that case, it makes sense
for the non-modifying methods (index() and count()) to be available.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Roberto Bonvallet
Glenn Hutchings wrote:
> But there are situations where you might want to treat it as a
> read-only list.  E.g., an argument to a function, so that you can
> guarantee the function won't modify it.  In that case, it makes sense
> for the non-modifying methods (index() and count()) to be available.

list(my_arg).index(...)

-- 
Roberto Bonvallet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Routine for prefixing '>' before every line of a string

2006-12-14 Thread Neil Cerutti
On 2006-12-14, Roberto Bonvallet <[EMAIL PROTECTED]> wrote:
> Sanjay wrote:
>> Is somewhere a routine useful to convert a string to lines of
>> maxsize, each prefixed with a '>'. This is a typical
>> requirement for 'keeping existing text while replying to a
>> post in a forum'.
>
> Take a look to the textwrap module:
> http://docs.python.org/lib/module-textwrap.html
>
> Here is an example:
>
> # the text is actually a very long line
> text = '''Lorem ipsum dolor sit amet, consectetuer adipiscing [...]'''
> prefix = '>'
>
> import textwrap
> lines = ["%s %s" % (prefix, line) for line in textwrap.wrap(text, 
> width=75)]

The solution will need to be instrumented in case of text that is
already quotes to one level. All in all, I recommend using Vim's
gq command or Emacs' autofill mode, which arlready do the right
thing.

-- 
Neil Cerutti
The Rev. Merriwether spoke briefly, much to the delight of the audience.
--Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Bruno Desthuilliers
André Thieme a écrit :
> Bruno Desthuilliers schrieb:
> 
(snip)
>> Both are highly dynamic. Neither are declarative.
> 
> 
> Well, Lisp does support some declarative features in the ansi standard.

If you go that way, there are declarative stuff in Python too... But 
neither Lisp nor Python are close to, say, SQL.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Fredrik Lundh
Glenn Hutchings wrote:

> But there are situations where you might want to treat it as a
> read-only list.  E.g., an argument to a function, so that you can
> guarantee the function won't modify it.

if you cannot trust your own code not to modify objects you pass to it,
I'm not sure Python's the right language for you.

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I edit a PythonWin path to import custom built modules???

2006-12-14 Thread BartlebyScrivener
Fredrik Lundh wrote:
>
> have you searched the *entire* registry for the "PythonCore" key?
> (python looks under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER)
>

I found it in the Scripts key! I was searching on PythonPath before.
Sorry. Thank you for the enlightenment.

rd

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Roberto Bonvallet wrote:
> list(my_arg).index(...)

Absolutely -- you can work around the limitation without any problems.
But the question is, why doesn't the list type share all its
non-modifying methods with the tuple type?  All the previous arguments
about "homogenous" and "heterogenous" in this thread sound bogus to me.
Python is first and foremost a practical language; what lists and
tuples are supposedly "for" strikes me as being irrelevant.

Glenn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Fredrik Lundh
Neil Cerutti wrote:

> Please don't assume I speak for all Python programmers. They
> might be rolling there eyes at me just as much as you are. ;-)

we do, but that's only because you keep on arguing with cross-posting Lisp
programmers.

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Fredrik Lundh wrote:
> if you cannot trust your own code not to modify objects you pass to it,
> I'm not sure Python's the right language for you.

It's not my own code I'm worried about. :-)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Simon Brunning
On 14 Dec 2006 06:03:07 -0800, Glenn Hutchings <[EMAIL PROTECTED]> wrote:
> All the previous arguments
> about "homogenous" and "heterogenous" in this thread sound bogus to me.
> Python is first and foremost a practical language; what lists and
> tuples are supposedly "for" strikes me as being irrelevant.

Tell that to Guido. They are his arguments.

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Simon Brunning
On 12/14/06, Simon Brunning <[EMAIL PROTECTED]> wrote:
> Tell that to Guido. They are his arguments.

On 2nd thoughts, don't. He has enough on his plate at the moment. ;-)

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple inheritance and __slots__

2006-12-14 Thread [EMAIL PROTECTED]

Simon Brunning wrote:
> On 14 Dec 2006 05:23:33 -0800, [EMAIL PROTECTED]
> <[EMAIL PROTECTED]> wrote:
> > Hi all,
> > >From the google search, it seems its not possible to do the following.
> >
> > >>> class Test1(object):
> > ... __slots__ = ['a']
> > ...
> > >>> class Test2(object):
> > ... __slots__ = ['b']
> > ...
> > >>> class Test3(Test1,Test2):
> > ... __slots__ = ['c']
> > ...
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > TypeError: Error when calling the metaclass bases
> > multiple bases have instance lay-out conflict
> >
> > I just want to make sure that I am using only the attributes a,b and c
> > from the instances of Test3 . Is there any other hack that could be
> > done.
>
> Difficulty with subclassing is the price you pay for abusing slots.
> Slots are intended as a performance tweak only, to minimise the memory
> footprint of classes of which you are going to have a great number of
> instances.
>
> In short - don't do that.
OK. But is there any other way to do what __slots__ does as a 'side
effect' i.e. forcing me to think about the list of attributes my class
is going to have upfront and raising error whenever I violate it. IMHO
this is a very good thing to have even if one does not care about
memory.

--
Suresh

>
> --
> Cheers,
> Simon B
> [EMAIL PROTECTED]
> http://www.brunningonline.net/simon/blog/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-14 Thread Ken Tilton


Paul Rubin wrote:
> Ken Tilton <[EMAIL PROTECTED]> writes:
> 
>>Again, that is precisely the point of macrology (in cases like
>>this). When a pattern will repeat a sufficient number of times, and a
>>function cannot handle the job,
> 
> 
> But this is not a case where a function can't handle the job.

Is, too.

> 
> 
>>Check out the latest, plz. The example has grown now beyond what a
>>function can do, I think. meanwhile, I have not seen how Python lets
>>you avoid revisiting dozens of instances when changes to a mechanism
>>are required.
> 
> 
> I'm missing what the difficulty is.

Your terse response does not provide enough for me to.

:)

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Fredrik Lundh
Glenn Hutchings wrote:

> Python is first and foremost a practical language; what lists and
> tuples are supposedly "for" strikes me as being irrelevant.

if you don't want to understand the design, nobody can force you.  but arguing
that the people behind the design "don't get it" isn't very practical.

and if you want random hacks and no design philosophy, use PHP.

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Simon Brunning
On 14 Dec 2006 06:05:12 -0800, Glenn Hutchings <[EMAIL PROTECTED]> wrote:
> It's not my own code I'm worried about. :-)

If you want a language that protects you not only from your own
mistakes, but also the mistakes of others, well, err, sorry, I'm not
sure I can help you. Eiffel, perhaps?



-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Logging module: problem with some mapping keys

2006-12-14 Thread Tekkaman

sim.sim wrote:
> Hi, i've check documentation, and found that logging.basicConfig takes
> no arguments (probably we have different versions of logging package),

Your Python version is < 2.4. Now basicConfig takes optional keyword
args:

basicConfig([**kwargs])
Does basic configuration for the logging system by creating a
StreamHandler with a default Formatter and adding it to the root
logger. The functions debug(), info(), warning(), error() and
critical() will call basicConfig() automatically if no handlers are
defined for the root logger.

In my real application (not the small test script!) This behaviour is
very useful since I can call basicConfig only once in the main file and
then all I have to do in the other files is:

import logging
self.logger = logging.getLogger("myClass")

Everything works smoothly except for not being able to get file and
line number info.

> and i've never used it.
>
> just try this:
>
>
> fileName = 'testlog.log'
> logName = 'LOG'
> iHandler = logging.FileHandler(fileName)
> iHandler.setFormatter(
> logging.Formatter("%(levelname)-8s|%(asctime)s|%(pathname)s,%(name)s,
> line %(lineno)s|%(message)s") )
>
> iLog = logging.getLogger(logName)
> iLog.addHandler(iHandler)
> iLog.setLevel(logging.DEBUG)
>
> iLog.info('hello logging')
>
>
>
> it gives me:
>
> INFO|2006-12-13 19:57:33,575|test.py,LOG, line 12|hello logging
>
>
> On 13 Dec., 19:02, "Tekkaman" <[EMAIL PROTECTED]> wrote:
> > I'm getting a strange behaviour from the "pathname" and "lineno"
> > formatter mapping keys. Instead of my file and my line number I get:
> >
> > /usr/lib/python2.4/logging/__init__.py
> >
> > as the file, and 1072 as the line number. I set up my config as
> > follows:
> >
> > logBaseConf = {
> > 'level'   : logging.DEBUG,
> > 'format'  : "%(levelname)-8s|%(asctime)s|%(pathname)s,
> > %(name)s, line %(lineno)s|%(message)s",
> > 'datefmt ': '%d %b %Y, %H:%M:%S',
> > 'filename': 'logtest.log',
> > 'filemode': 'a'
> > }
> > logging.basicConfig(**logBaseConf)
> >
> > I'm not using any executable-generating tools such as cx_Freeze or
> > Psyco. In fact, I'm getting this error on a very basic script with the
> > specific purpose of testing the logging module capabilities.
> >
> > Thanks in advance for any contribution.
> > 
> > T.
> 
> --
> Maksim Kasimov

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Fredrik Lundh wrote:
> if you don't want to understand the design, nobody can force you.  but arguing
> that the people behind the design "don't get it" isn't very practical.

I'm not arguing that at all.  What I'm saying is that from the
perspective of someone not interested in design issues, it seems like
an omission for tuples to be missing the non-modifying methods that
lists have.

Glenn

-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >