Re: Why my modification of source file doesn't take effect whendebugging?

2005-12-02 Thread Fredrik Lundh
Christophe wrote:

> > "import" only reads the file the first time it's called.  Every import
> > call after that looks up the module in memory.  This is to prevent
> > circular dependencies between modules from creating infinite loops.
> > You need to use the reload() function:
>
> As a matter of fact, it would help a lot if that stupid behaviour of
> Idle was dropped. I'm sure I'm not the only one who lost lots of time
> because of that bug. Yes I call it a bug.

in the version of IDLE I have on this machine, if I modify my script and
run it again (using F5), things work exactly as expected.

if I modify my script and import it into a clean shell (ctrl-F6), things work
exactly as expected.

the only way to get the "buggy" behaviour you're describing is to attempt
to run your program by importing it as a module more than once into an
existing python shell process.  in that case, import works in the same way
as it always works.

after all, "import" isn't designed to run programs, it's designed to import
modules.  if you want to run stuff in IDLE, why not just use the "run"
command ?

 



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


Re: advice : how do you iterate with an acc ?

2005-12-02 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote:
> hello,
> 
> i'm wondering how people from here handle this, as i often encounter
> something like:
> 
> acc = []# accumulator ;)
> for line in fileinput.input():
> if condition(line):
> if acc:#1
> doSomething(acc)#1
> acc = []
> else:
> acc.append(line)
> if acc:#2
> doSomething(acc)#2
> 
> BTW i am particularly annoyed by #1 and #2 as it is a reptition, and i
> think it is quite error prone, how will you do it in a pythonic way ?

Could you add a sentry to the end of your input?  E.g.:

for line in fileinput.input() + line_that_matches_condition:

This way, you wouldn't need a separate check at the end.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python & Unicode decimal interpretation

2005-12-02 Thread Scott David Daniels
In reading over the source for CPython's PyUnicode_EncodeDecimal,
I see a dance to handle characters which are neither dec-equiv nor
in Latin-1.  Does anyone know about the intent of such a conversion?

As far as I can tell, error handling is one of:
 strict, replace, ignore, xmlcharrefreplace, or something_else
What I don't understand is whether, in the ignore or something_else
cases, there is any chance that digits will show up anywhere that
they would not if these characters were treated as a character like '?'?

Can someone either give me definitive "why not" or (preferably) give
me a test case that shows where that interpretation does not hold.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: General question about Python design goals

2005-12-02 Thread Donn Cave
Quoth Mike Meyer <[EMAIL PROTECTED]>:
| Donn Cave <[EMAIL PROTECTED]> writes:
...
|> For me, conceptually, if an object can't be accessed
|> sequentially, then it can't be mapped to a sequence.
|
| So you're saying that for should implicitly invoke list (or maybe
| iter) on any object that it's passed that's not a list or iterator?

Not really saying anything so concrete about it -- doesn't make
any difference to me how it works, just saying that all these
things come together.  Convert to list, iterate, for.  They're
conceptually not just related, but bound together.

|> Anyway, it seems to me that in the end this is about
|> that balance between practicality and purity.  Maybe
|> it's more like tuples have a primary intended purpose,
|> and some support for other applications.  Not white,
|> but not pure black either.
|
| If you do that, you've just weakened the case for not having count
| etc. as methods of tuples.
|
| It really is the dichotomy of "tuples aren't meant to be sequences so
| they don't have ..." versus being able to access them sequentially
| that gets me. That just doesn't seem right.

The case is weakened only if we have been pretending it was really
strong.  I guess this may be why this issue drives certain people
crazy.  There's a case for "don't have", but it isn't air-tight, so
what do we do?  Well, that's the one thing I really like about the
winter holiday season -- some particularly flavorful ales come out
of the local micro-breweries around this time of year, just in time
to ease my worries about tuples.

Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why my modification of source file doesn't take effect when debugging?

2005-12-02 Thread Scott David Daniels
Christophe wrote:
> infidel a écrit :
>>> I'm using the Windows version of Python and IDLE. When I debug my .py
>>> file, my modification to the .py file does not seem to take effect
>>> unless I restart IDLE. Saving the file and re-importing it doesn't help
>>> either. Where's the problem?
>>
>> "import" only reads the file the first time it's called.  Every import
>> call after that looks up the module in memory.  This is to prevent
>> circular dependencies between modules from creating infinite loops.
>> You need to use the reload() function:
> 
> As a matter of fact, it would help a lot if that stupid behaviour of 
> Idle was dropped. I'm sure I'm not the only one who lost lots of time 
> because of that bug. Yes I call it a bug.
You are mistaken if you think this is an Idle behavior; it is a Python
behavior that speeds the execution of large systems.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


CGI and long running job

2005-12-02 Thread merry . sailor
Hello,
I am using python and CGI to initiate a long running simulation (up to
5h long) on a remote machine. The main idea is that I use a form, enter
the parameters and a CGI scripts start the simulation using these
parameters. The structure of the script is:

1. Read paremeters
2. Display some information
3. Start the simulation

For step 3 I use either os.system or os.popen(2). The problem is that
the web server does not send the information of step 2 back to the
browser, unless step 3 is completed. The browser simply waits for a
response, without displaying anything. How can I just read the params,
display the info I want, start the simulation and then terminate either
the script or at least the connection to the browser without having to
wait for the simulation to finish?

I am using activestate python 2.4, Apache and WinXP.

Thanks a lot for your help.

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


FiPy visualization results in MacOS Tiger "Bus Error"

2005-12-02 Thread David T
Has anyone run across this error?

When calling any of several visualization routines from FiPy, Python  
quits with a

  Bus Error

I'm using MacOS X Tiger 10.4.3, and I've tried several builds of  
Python 2.4: Framework build of 2.4.1, Fink build of 2.4.2,  Fink  
build of vtkPython 2.4.2. Same crash from each.

FiPy seems to run its examples just fine, but the visualization gives  
me fits.

The crash report tells me that FreeType is causing trouble, but the  
crash comes from deep within OS X.

I'd appreciate hearing of any such experiences, solutions, or help in  
tracking down this bugger.

Thanks,

--David

Command: vtkpython
Path:/sw/bin/vtkpython
Parent:  bash [807]

Version: ??? (???)

PID:825
Thread: 0

Exception:  EXC_BAD_ACCESS (0x0001)
Code[0]:0x000a
Code[1]:0x05770001


Thread 0 Crashed:
0   <<>>0x8ab0 __memcpy + 784 (cpu_capabilities.h:189)
1   libfreetype.6.dylib 0x053a8530 FT_Stream_ReadAt + 112  
(ftstream.c:146)
2   libfreetype.6.dylib 0x053acea4 IsMacResource + 1092 (ftobjs.c:1287)
3   libfreetype.6.dylib 0x053ac700 FT_Open_Face + 648 (ftobjs.c:1519)
4   libfreetype.6.dylib 0x053acfec FT_New_Face + 48 (ftobjs.c:971)
5   ft2font.so  0x0526db38 FT2Font::FT2Font[in-charge] 
(std::basic_string, std::allocator  
 >) + 460 (ft2font.cpp:322)
6   ft2font.so  0x0526eacc ft2font_module::new_ft2font 
(Py::Tuple const&) + 684 (ft2font.cpp:1536)
7   ft2font.so  0x05288e08  
Py::ExtensionModule::invoke_method_varargs 
(std::basic_string, std::allocator  
 > const&, Py::Tuple const&) + 788 (Extensions.hxx:285)
8   ft2font.so  0x0527c510 method_varargs_call_handler +  
1112 (Objects.hxx:220)
9   libpython2.4.dylib  0x00294b10 PyEval_EvalFrame + 16756 (ceval.c: 
3558)
10  libpython2.4.dylib  0x00296ec4 PyEval_EvalCodeEx + 2260 (ceval.c: 
2736)
11  libpython2.4.dylib  0x00294d30 PyEval_EvalFrame + 17300 (ceval.c: 
3651)
12  libpython2.4.dylib  0x00296ec4 PyEval_EvalCodeEx + 2260 (ceval.c: 
2736)
13  libpython2.4.dylib  0x00294d30 PyEval_EvalFrame + 17300 (ceval.c: 
3651)
14  libpython2.4.dylib  0x00296ec4 PyEval_EvalCodeEx + 2260 (ceval.c: 
2736)
15  libpython2.4.dylib  0x0022ffbc function_call + 332 (funcobject.c: 
555)
16  libpython2.4.dylib  0x0020e83c PyObject_Call + 52 (abstract.c:1757)
17  libpython2.4.dylib  0x00218b24 instancemethod_call + 764  
(classobject.c:2448)
18  libpython2.4.dylib  0x0020e83c PyObject_Call + 52 (abstract.c:1757)
19  libpython2.4.dylib  0x0028f734 PyEval_CallObjectWithKeywords +  
272 (ceval.c:3426)
20  libpython2.4.dylib  0x0021a054 PyInstance_New + 584  
(classobject.c:576)
21  libpython2.4.dylib  0x0020e83c PyObject_Call + 52 (abstract.c:1757)
22  libpython2.4.dylib  0x00296470 PyEval_EvalFrame + 23252 (ceval.c: 
3768)
23  libpython2.4.dylib  0x00296ec4 PyEval_EvalCodeEx + 2260 (ceval.c: 
2736)
24  libpython2.4.dylib  0x00296fd4 PyEval_EvalCode + 48 (ceval.c:490)
25  libpython2.4.dylib  0x002b5e84 PyImport_ExecCodeModuleEx + 292  
(import.c:632)
26  libpython2.4.dylib  0x002b6334 load_source_module + 952  
(import.c:906)
27  libpython2.4.dylib  0x002b746c import_submodule + 392 (import.c: 
2263)
28  libpython2.4.dylib  0x002b76b4 load_next + 260 (import.c:2083)
29  libpython2.4.dylib  0x002b7ce4 import_module_ex + 488 (import.c: 
1918)
30  libpython2.4.dylib  0x002b7f6c PyImport_ImportModuleEx + 212  
(import.c:1958)
31  libpython2.4.dylib  0x0028641c builtin___import__ + 100  
(bltinmodule.c:46)
32  libpython2.4.dylib  0x0020e83c PyObject_Call + 52 (abstract.c:1757)
33  libpython2.4.dylib  0x0028f734 PyEval_CallObjectWithKeywords +  
272 (ceval.c:3426)
34  libpython2.4.dylib  0x00293f6c PyEval_EvalFrame + 13776 (ceval.c: 
2020)
35  libpython2.4.dylib  0x00296ec4 PyEval_EvalCodeEx + 2260 (ceval.c: 
2736)
36  libpython2.4.dylib  0x00296fd4 PyEval_EvalCode + 48 (ceval.c:490)
37  libpython2.4.dylib  0x002b5e84 PyImport_ExecCodeModuleEx + 292  
(import.c:632)
38  libpython2.4.dylib  0x002b6334 load_source_module + 952  
(import.c:906)
39  libpython2.4.dylib  0x002b746c import_submodule + 392 (import.c: 
2263)
40  libpython2.4.dylib  0x002b76b4 load_next + 260 (import.c:2083)
41  libpython2.4.dylib  0x002b7ce4 import_module_ex + 488 (import.c: 
1918)
42  libpython2.4.dylib  0x002b7f6c PyImport_ImportModuleEx + 212  
(import.c:1958)
43  libpython2.4.dylib  0x0028641c builtin___import__ + 100  
(bltinmodule.c:46)
44  libpython2.4.dylib  0x0020e83c PyObject_Call + 52 (abstract.c:1757)
45  libpython2.4.dylib  0x0028f734 PyEval_CallObjectWithKeywords +  
272 (ceval.c:3426)
46  libpython2.4.dylib  0x00293f6c PyEval_EvalFrame + 13776 (ceval.c: 
2020

Re: Import path for unit tests

2005-12-02 Thread Ben Finney
Duncan Booth <[EMAIL PROTECTED]> wrote:
> Ben Finney wrote:
> > What is the common idiom here? I can conceive of several possible
> > ways to get around it, all of which seem hackish to some degree.
> 
> I don't know if it is the common idiom, but I tend to write:
> 
> TESTDIR = os.path.dirname(os.path.abspath(__file__))
> PROJECTDIR = os.path.dirname(TESTDIR)
> if not TESTDIR in sys.path:
> sys.path.insert(1, TESTDIR)
> if not PROJECTDIRDIR in sys.path:
> sys.path.insert(1, PROJECTDIR)

Thankyou, that works better than what I was doing.

But it's my idea of "hackish" :-) It works, and is comprehensible. But
it's pretty heavyweight for something I need to do all the time (i.e.
writing unit test modules for various projects).

Anyone else have a preferred way of doing this? Or will I have to wait
until PEP 328 is integrated?

http://www.python.org/peps/pep-0328.html>

-- 
 \"Laurie got offended that I used the word 'puke.' But to me, |
  `\  that's what her dinner tasted like."  -- Jack Handey |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: advice : how do you iterate with an acc ?

2005-12-02 Thread bonono

Bengt Richter wrote:
> It looks to me like itertools.groupby could get you close to what you want,
> e.g., (untested)
Ah, groupby. The generic string.split() equivalent. But the doc said
the input needs to be sorted.

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


Re: advice : how do you iterate with an acc ?

2005-12-02 Thread Dan Sommers
On 2 Dec 2005 16:45:38 -0800,
[EMAIL PROTECTED] wrote:

> hello,
> i'm wondering how people from here handle this, as i often encounter
> something like:

> acc = []# accumulator ;)
> for line in fileinput.input():
> if condition(line):
> if acc:#1
> doSomething(acc)#1
> acc = []
> else:
> acc.append(line)
> if acc:#2
> doSomething(acc)#2

> BTW i am particularly annoyed by #1 and #2 as it is a reptition, and i
> think it is quite error prone, how will you do it in a pythonic way ?

If doSomething handled an empty list gracefully, then you would have
less repetition:

acc = []
for line in fileinput.input():
if condition(line):
doSomething(acc)#1
acc = []
else:
acc.append(line)
doSomething(acc)#2

If condition were simple enough and the file(s) small enough, perhaps
you could read the whole file at once and use split to separate the
pieces:

contents = file.read()
for acc in contents.split( "this is the delimiter line\n" ):
doSomething(acc.split("\n"))

(There are probably some strange cases of repeated delimiter lines or
delimiter lines occurring at the beginning or end of the file for which
the above code will not work.  Caveat emptor.)

If condition were a little more complicated, perhaps re.split would
work.

Or maybe you could look at split and see what it does (since your code
is conceptually very similar to it).

OTOH, FWIW, your version is very clean and very readable and fits my
brain perfectly.

HTH,
Dan

-- 
Dan Sommers

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


Re: advice : how do you iterate with an acc ?

2005-12-02 Thread Bengt Richter
On 2 Dec 2005 17:08:02 -0800, [EMAIL PROTECTED] wrote:

>
>[EMAIL PROTECTED] wrote:
>> hello,
>>
>> i'm wondering how people from here handle this, as i often encounter
>> something like:
>>
>> acc = []# accumulator ;)
>> for line in fileinput.input():
>> if condition(line):
>> if acc:#1
>> doSomething(acc)#1
>> acc = []
>> else:
>> acc.append(line)
>> if acc:#2
>> doSomething(acc)#2
>>
>> BTW i am particularly annoyed by #1 and #2 as it is a reptition, and i
>> think it is quite error prone, how will you do it in a pythonic way ?
>>
It looks to me like itertools.groupby could get you close to what you want,
e.g., (untested)

import itertools
for condresult, acciter in itertools.groupby(fileinput.imput(), condition):
if not condresult:
dosomething(list(acciter)) # or dosomething(acciter) if iterator is 
usable

IOW, groupy collects contiguous lines for which condition evaluates to a 
distinct
value. Assuming this is a funtion that returns only two distinct values (for 
true
and false, like True and False), then if I understand your program's logic, you
do nothing with the line(s) that actually satisfy the condition, you just 
trigger
on them as delimiters and want to process the nonempty groups of the other 
lines,
so the "if not condresult:" should select those. Groupby won't return an empty 
group AFAIK,
so you don't need to test for that. Also, you won't need the list call in 
list(acciter)
if your dosomething can accept an iterator instead of a list.

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: General question about Python design goals

2005-12-02 Thread Aahz
In article <[EMAIL PROTECTED]>, Mike Meyer  <[EMAIL PROTECTED]> wrote:
>Donn Cave <[EMAIL PROTECTED]> writes:
>> 
>> For me, conceptually, if an object can't be accessed
>> sequentially, then it can't be mapped to a sequence.
>
>So you're saying that for should implicitly invoke list (or maybe
>iter) on any object that it's passed that's not a list or iterator?

for does in fact implicitly invoke iter() on its loop expression.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"Don't listen to schmucks on USENET when making legal decisions.  Hire
yourself a competent schmuck."  --USENET schmuck (aka Robert Kern)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Setting PYTHONPATH from Makefile

2005-12-02 Thread Inyeol Lee
On Fri, Dec 02, 2005 at 08:10:41PM -0500, Mike Meyer wrote:
> Inyeol Lee <[EMAIL PROTECTED]> writes:
> > On Fri, Dec 02, 2005 at 07:33:20PM -0500, Mike Meyer wrote:
> >> > The problem is that myscript.py and some modules that myscript.py
> >> > imports are not in the current directory, but in another place in the
> >> > filesystem, say, /path/to/stuff. If this was a tcsh script, I would
> >> > just do:
> >> >
> >> >setenv PYTHONPATH /path/to/stuff
> >> >python myscript.py
> > How about using python -m?
> > Assuming Make uses Bourne shell,
> >
> > %.abc: %.def
> > PYTHONPATH=/path/to/stuff:/path/to/another python -m myscript
> 
> That will break __name__ (at least with 2.4.2). Whether or not it
> matters will depend on the script.
> 

$ python -V
Python 2.4.2
$ cat foo/bar.py 
print __name__
$ (cd foo; python bar.py)
__main__
$ PYTHONPATH=$PWD/foo python -m bar
__main__
$ 


Am I missing something? I don't see any issue regarding __name__.

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


Re: General question about Python design goals

2005-12-02 Thread Mike Meyer
Donn Cave <[EMAIL PROTECTED]> writes:
> In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> 
> wrote:
>> Seriously. Why doesn't this have to be phrased as "for x in list((1,
>> 2, 3))", just like you have to write list((1, 2, 3)).count(1), etc.?
> How could list(t) work, if for x in t didn't?

Good question.

> For me, conceptually, if an object can't be accessed
> sequentially, then it can't be mapped to a sequence.

So you're saying that for should implicitly invoke list (or maybe
iter) on any object that it's passed that's not a list or iterator?

> Anyway, it seems to me that in the end this is about
> that balance between practicality and purity.  Maybe
> it's more like tuples have a primary intended purpose,
> and some support for other applications.  Not white,
> but not pure black either.

If you do that, you've just weakened the case for not having count
etc. as methods of tuples.

It really is the dichotomy of "tuples aren't meant to be sequences so
they don't have ..." versus being able to access them sequentially
that gets me. That just doesn't seem right.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Setting PYTHONPATH from Makefile

2005-12-02 Thread Mike Meyer
Inyeol Lee <[EMAIL PROTECTED]> writes:
> On Fri, Dec 02, 2005 at 07:33:20PM -0500, Mike Meyer wrote:
>> > The problem is that myscript.py and some modules that myscript.py
>> > imports are not in the current directory, but in another place in the
>> > filesystem, say, /path/to/stuff. If this was a tcsh script, I would
>> > just do:
>> >
>> >setenv PYTHONPATH /path/to/stuff
>> >python myscript.py
> How about using python -m?
> Assuming Make uses Bourne shell,
>
> %.abc: %.def
> PYTHONPATH=/path/to/stuff:/path/to/another python -m myscript

That will break __name__ (at least with 2.4.2). Whether or not it
matters will depend on the script.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: advice : how do you iterate with an acc ?

2005-12-02 Thread bonono

[EMAIL PROTECTED] wrote:
> hello,
>
> i'm wondering how people from here handle this, as i often encounter
> something like:
>
> acc = []# accumulator ;)
> for line in fileinput.input():
> if condition(line):
> if acc:#1
> doSomething(acc)#1
> acc = []
> else:
> acc.append(line)
> if acc:#2
> doSomething(acc)#2
>
> BTW i am particularly annoyed by #1 and #2 as it is a reptition, and i
> think it is quite error prone, how will you do it in a pythonic way ?
>
I think it is quite ok as the last "if acc:" is just an "end-of-stream"
implicit marker, whereas during the loop, you have explicit markers to
signal end/start of blocks. There is no unwanted variable introduced
and I don't see how it can be error prone.

This is one of the case I won't try to make it a one liner, because it
is already very natural :-)

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


Re: Setting PYTHONPATH from Makefile

2005-12-02 Thread Inyeol Lee
On Fri, Dec 02, 2005 at 07:33:20PM -0500, Mike Meyer wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > I have a Makefile target that uses a python script, like:
> >
> > %.abc: %.def
> > python myscript.py
> >
> > The problem is that myscript.py and some modules that myscript.py
> > imports are not in the current directory, but in another place in the
> > filesystem, say, /path/to/stuff. If this was a tcsh script, I would
> > just do:
> >
> >setenv PYTHONPATH /path/to/stuff
> >python myscript.py
> 
> And that still wouldn't work, because you said that myscript.py wasn't
> in the current directory either.
> 
> > but this cannot be done from a Makefile. So what do I do? Is there
> > another way to set the PYTHONPATH? Like giving an option to "python"
> > itself? Or?
> 
> No, you can't. You have to tweak the makefile. Try:
> 
> %.abc: %.def
>(cd /path/to/myscripts/dir; python myscript.py)
> 
> 
> N.B. - this probably depends on both the system and the make you're
> using.
> 

How about using python -m?
Assuming Make uses Bourne shell,

%.abc: %.def
PYTHONPATH=/path/to/stuff:/path/to/another python -m myscript


Don't forget to strip '.py' extension.

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


advice : how do you iterate with an acc ?

2005-12-02 Thread vd12005
hello,

i'm wondering how people from here handle this, as i often encounter
something like:

acc = []# accumulator ;)
for line in fileinput.input():
if condition(line):
if acc:#1
doSomething(acc)#1
acc = []
else:
acc.append(line)
if acc:#2
doSomething(acc)#2

BTW i am particularly annoyed by #1 and #2 as it is a reptition, and i
think it is quite error prone, how will you do it in a pythonic way ?

regards

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


Re: Setting PYTHONPATH from Makefile

2005-12-02 Thread Mike Meyer
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> I have a Makefile target that uses a python script, like:
>
> %.abc: %.def
> python myscript.py
>
> The problem is that myscript.py and some modules that myscript.py
> imports are not in the current directory, but in another place in the
> filesystem, say, /path/to/stuff. If this was a tcsh script, I would
> just do:
>
>setenv PYTHONPATH /path/to/stuff
>python myscript.py

And that still wouldn't work, because you said that myscript.py wasn't
in the current directory either.

> but this cannot be done from a Makefile. So what do I do? Is there
> another way to set the PYTHONPATH? Like giving an option to "python"
> itself? Or?

No, you can't. You have to tweak the makefile. Try:

%.abc: %.def
   (cd /path/to/myscripts/dir; python myscript.py)


N.B. - this probably depends on both the system and the make you're
using.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Alexander Zatvornitskiy
Hello, [EMAIL PROTECTED]

28 nov 2005 at 02:48, [EMAIL PROTECTED] wrote:

 p> This is just to let you know that the lastest version Dao language is
 p> released.

Please wrote "hello world" example for us, and some more simple examples which
highlight major features of this language. I think, it is the best way to
evaluate new language.


Alexander, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Mike Meyer
Carsten Haese <[EMAIL PROTECTED]> writes:
> (3) assumes that whatever shell the user is running looks up the shebang
> executable in the path, which bash, just to name one example, does not
> do.

For the record, on a modern Unix system, #! isn't handled by the
shell; it's handled by the kernel. #! is a "magic number" denoting a
type of executable. Some shells used to do that, and may still do that
if the underlying system doesn't handle it.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detect Blank DVD or CD in CDROM Drive

2005-12-02 Thread Gregory Piñero
not sure if this first email made it to the list.  Sorry if it ends up as a dupe.On 12/2/05, Gregory Piñero <[EMAIL PROTECTED]
> wrote:Hi guys,

I'm thinking it will take a real expert to do this, probably someone
who can use windows API's or directly poll the hardware or some such
thing.  But if you think you know how then please let me
know.  I'm trying to write an automation script that will burn an
ISO file each night.

By the way, I tried this recipe but it doesn't seem to work for blank media:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/180919
-- Gregory PiñeroChief Innovation OfficerBlended Technologies
(www.blendedtechnologies.com)

-- Gregory PiñeroChief Innovation OfficerBlended Technologies(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Cut and paste an EPS file

2005-12-02 Thread Larry Bates
There is a python iterface to imagemagik that might work.  I haven't
used it, just read about it.

-Larry Bates

John Henry wrote:
> I am looking for a Python tookit that will enable me to cut section of
> a picture out from an EPS file and create another EPS file.
> 
> I am using a proprietary package for doing certain engineering
> calculations.  It creates single page x-y line plots that has too much
> blank spaces around the plotted area located at the top 2/3 of the
> page.  I like to be  "cut" that white space out by extracting the image
> out and may be scale it up - while keeping the bottom 1/3 unchanged.
> 
> Does anybody has any suggestions?
> 
> Thanks,
> 
> --
> JH
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: JOB: Telecommute Python Programmer - IMMEDIATE NEED

2005-12-02 Thread Paul Rubin
"Beau Gould" <[EMAIL PROTECTED]> writes:
> JOB: Telecommute Python Programmer - IMMEDIATE NEED
> Please see www.superiorss.com/jobs.htm 

I hope this person is not trying to spam web BBS's, wikis, etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter menu

2005-12-02 Thread [EMAIL PROTECTED]

> 
> the easiest way to do this is to create a new function object for each
> file, and use default argument binding to pass in the right filename:
> 
> for file in self.allfiles:
> def callback(fname=file):
> self.showFile(fname, parent)
> self.showfilemenu_bar.addmenuitem('Show Files',
> 'command',label=file, command=callback)
> 
> the "def" statement creates a new instance of the callback function for
> each iteration.  the "fname" variable is bound to the current file object,
> while "self" and "parent" are bound to the variables with the same names
> in the outer scope.
> 
> 
> 

That was exactly what I was looking for.  It worked perfectly. Thanks.

John

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


Re: Cut and paste an EPS file

2005-12-02 Thread John Henry
Thanks for the reply.

Yes, that would have been too easy :=)

If I change the bbox, I would cut out the lower 1/3 of the plot.   I
only want to apply it to the top 2/3 of the page.

Regards,

--
JH

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


JOB: Telecommute Python Programmer - IMMEDIATE NEED

2005-12-02 Thread Beau Gould
JOB: Telecommute Python Programmer - IMMEDIATE NEED
Please see www.superiorss.com/jobs.htm 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.10/190 - Release Date: 12/1/2005
 

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


Re: Cut and paste an EPS file

2005-12-02 Thread Ben Caradoc-Davies
John Henry wrote:
> I am looking for a Python tookit that will enable me to cut section of
> a picture out from an EPS file and create another EPS file.
> I am using a proprietary package for doing certain engineering
> calculations.  It creates single page x-y line plots that has too much
> blank spaces around the plotted area located at the top 2/3 of the
> page.  I like to be  "cut" that white space out by extracting the image
> out and may be scale it up - while keeping the bottom 1/3 unchanged.
> Does anybody has any suggestions?

Hack the %%BoundingBox line in the EPS file. The importing application 
should honour this when determining the limits ofthe figure. See

 http://www.cs.indiana.edu/docproject/programming/postscript/eps.html

and Google for more.

%%BoundingBox coordinates are integers and are in points.

-- 
Ben Caradoc-Davies <[EMAIL PROTECTED]>
http://wintersun.org/
"Those who deny freedom to others deserve it not for themselves."
- Abraham Lincoln
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML and namespaces

2005-12-02 Thread uche . ogbuji
Alan Kennedy:
"""
> Oh no.  That only means that namespace declaration attributes are not
> created in the DOM data structure.  However, output has to fix up
> namespaces in .namespaceURI properties as well as directly asserted
> "xmlns" attributes.  It would be silly for DOM to produce malformed
> XML+XMLNS, and of course it is not meant to.  The minidom behavior
> needs fixing, badly.

My interpretation of namespace nodes is that the application is
responsible for creating whatever namespace declaration attribute nodes
are required, on the DOM tree.

DOM should not have to imply any attributes on output.
"""

I'm sorry but you're wrong on this.  First of all, DOM L2 (the level
minidom targets) does not have the concept of "namespace nodes".
That's XPath.  DOM supports two ways of expressing namespace
information.  The first way is through the node properties
.namespaceURI, .prefix (for the QName) and .localName.  It *also*
supports literal namespace declaration atrributes (the NSDecl
attributes themselves must have a namespace of
"http://www.w3.org/2000/xmlns/";).  As if this is not confusing enough
the Level 1 propoerty .nodeName must provide the QName, redundantly.

As a result, you have to perform fix-up to merge properties with
explicit NSDEcl attributes in order to serialize.  If it does not do
so, it is losing all the information in namespace properties, and the
resulting output is not the same document that is represented in the
DOM.

Believe me, I've spent many weary hours with all these issues, and
implemented code to deal with the mess multiple times, and I know it
all too painfully well.  I wrote Amara largely because I got
irrecoverably sick of DOM's idiosyncracies.

Andrew, for this reason I probably take the initiative to work up a
patch for the issue.  I'll do what I can to get to it tomorrow.  If you
help me with code review and maybe writing some tests, that would be a
huge help.

--
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

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


Cut and paste an EPS file

2005-12-02 Thread John Henry
I am looking for a Python tookit that will enable me to cut section of
a picture out from an EPS file and create another EPS file.

I am using a proprietary package for doing certain engineering
calculations.  It creates single page x-y line plots that has too much
blank spaces around the plotted area located at the top 2/3 of the
page.  I like to be  "cut" that white space out by extracting the image
out and may be scale it up - while keeping the bottom 1/3 unchanged.

Does anybody has any suggestions?

Thanks,

--
JH

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


Re: XML and namespaces

2005-12-02 Thread Alan Kennedy
[AMK]
> """
> (I assume not.  Section 1.3.3 of the DOM Level 3 says "Similarly,
> creating a node with a namespace prefix and namespace URI, or changing
> the namespace prefix of a node, does not result in any addition,
> removal, or modification of any special attributes for declaring the
> appropriate XML namespaces."  So the DOM can create XML documents that
> aren't well-formed w.r.t. namespaces, I think.)
> """

[Uche]
> Oh no.  That only means that namespace declaration attributes are not
> created in the DOM data structure.  However, output has to fix up
> namespaces in .namespaceURI properties as well as directly asserted
> "xmlns" attributes.  It would be silly for DOM to produce malformed
> XML+XMLNS, and of course it is not meant to.  The minidom behavior
> needs fixing, badly.

My interpretation of namespace nodes is that the application is 
responsible for creating whatever namespace declaration attribute nodes 
are required, on the DOM tree.

DOM should not have to imply any attributes on output.

#-=-=-=-=-=-=-=-=-=
import xml.dom
import xml.dom.minidom

DAV_NS_U = "http://webdav.org";

xmldoc = xml.dom.minidom.Document()
xmlroot = xmldoc.createElementNS(DAV_NS_U, "DAV:xpg")
xmlroot.setAttributeNS(xml.dom.XMLNS_NAMESPACE, "xmlns:DAV", DAV_NS_U)
xmldoc.appendChild(xmlroot)
print xmldoc.toprettyxml()
#-=-=-=-=-=-=-=-=-=

produces

"""

http://webdav.org"/>
"""

Which is well formed wrt namespaces.

regards,

-- 
alan kennedy
--
email alan:  http://xhaus.com/contact/alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to handle two forms in cgi?

2005-12-02 Thread lli
Hi Dan,

Sure. You are right. When I correct this according to your idea, it
works now. Thank you very much. But I have second problem. When users
run second form, other people can see adress in users' browers and know
how to run the second form, so they don't need to run login form. How I
can handle this case? How I can let users run login form firstly, then
they can run second form(search form)?

By the way I use python to write cgi.

Any help is appriciated!

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Inyeol Lee
On Fri, Dec 02, 2005 at 09:45:10PM +0100, Gerhard H�ring wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> Micah Elliott wrote:
> > On Dec 02, Dave Hansen wrote:
> > 
> >>Python recognizes the TAB character as valid indentation.  TAB
> >>characters are evil.  They should be banned from Python source code.
> > 
> > AGREE!  AGREE!  AGREE! 
> > 
> >>The interpreter should stop translation of code and throw an
> >>exception when one is encountered.
> > 
> > 
> > You could file a "Parser/Compiler" Feature Request for this [...]
> 
> Read PEP 666 first.
> 

And this one too ;-)
http://www.artima.com/weblogs/viewpost.jsp?thread=101968

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

Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Simon Brunning
On 12/2/05, Dave Hansen <[EMAIL PROTECTED]> wrote:
> FWIW, indentation scoping one one of the features that _attracted_ me
> to Python.

+1 QOTW

OK, it's a bit of a cliche. But it's a cliche because it's *true*.

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Gerhard Häring
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Micah Elliott wrote:
> On Dec 02, Dave Hansen wrote:
> 
>>Python recognizes the TAB character as valid indentation.  TAB
>>characters are evil.  They should be banned from Python source code.
> 
> AGREE!  AGREE!  AGREE! 
> 
>>The interpreter should stop translation of code and throw an
>>exception when one is encountered.
> 
> 
> You could file a "Parser/Compiler" Feature Request for this [...]

Read PEP 666 first.

- -- Gerhard
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDkLJWdIO4ozGCH14RAiOyAJ4gNZrf5rjv5Cqk2cj/hFGXRaeCZwCdEL/X
ITGPnj6tXblSY1r04zS5djY=
=z37M
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to list currently defined classes, methods etc

2005-12-02 Thread Colin J. Williams
Deep wrote:
> I have been looking a bit and am stuck at this point.
> 
> Given a string, how do i find what is the string bound to.
> Let me give an example.
> 
> def deep():
>  print "Hello"
> 
> now inspect.ismethod(deep) returns true. (As it should).
> But if I am trying to make a list of all bound methods), i use
> dir(), which is a list of strings. I get the string "deep" from this
> list.
> How do I obtain the reference to the method it is bound to.
> The same problem can be extended to attributes and classes.
> 
 >>> help('deep') in the interactive mode gives part of what you seek.

A prettier way is to use epydoc: 
http://www.answers.com/main/ntquery?s=epydoc&gwp=13

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


Re: How to list currently defined classes, methods etc

2005-12-02 Thread Kent Johnson
Deep wrote:
> I have been looking a bit and am stuck at this point.
> 
> Given a string, how do i find what is the string bound to.
> Let me give an example.
> 
> def deep():
>  print "Hello"
> 
> now inspect.ismethod(deep) returns true. (As it should).
> But if I am trying to make a list of all bound methods), i use
> dir(), which is a list of strings. I get the string "deep" from this
> list.

Look it up in the globals() dict:
 >>> def deep():
 ...   print 'Hello'
 ...
 >>> globals()['deep']


> How do I obtain the reference to the method it is bound to.
> The same problem can be extended to attributes and classes.

Use getattr() to inspect classes and instances:
 >>> class deeper:
 ...   def deepest(self):
 ... print 'goodbye'
 ...
 >>> getattr(deeper, 'deepest')

 >>> d=deeper()
 >>> getattr(d, 'deepest')
>

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


Re: unittest.assertRaise and keyword arguments?

2005-12-02 Thread Bo Peng
Giovanni Bajo wrote:
> You can pass keyword arguments to assertRaises without problems:
> 
> self.assertRaises(ValueError, myfunc, arg1,arg2, arg3, arg4, abc=0, foo=1,
> bar="hello")

Well, I though abc=0 would be keyword arguments for assertRaisers and 
never tried it!

> 
> Or you can always do something like:
> 
> self.assertRaises(ValueError, lambda: myfunc(arg1,arg2, arg3, arg4, abc=0,
> foo=1, bar="hello"))

This is also useful.

I now have nothing to complain against assertTaises. :-)

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Micah Elliott
On Dec 02, Dave Hansen wrote:
> Python recognizes the TAB character as valid indentation.  TAB
> characters are evil.  They should be banned from Python source code.

AGREE!  AGREE!  AGREE! 

> The interpreter should stop translation of code and throw an
> exception when one is encountered.

You could file a "Parser/Compiler" Feature Request for this (Hmm,
sf.net appears to have just renamed "Request For Enhancment" to
"Feature Request").  Seems the present enformencement of
disallowing tab/space mixing is with -t and -tt.  From PEP-8
http://www.python.org/peps/pep-0008.html>:

...
Tabs or Spaces?

Never mix tabs and spaces.  The most popular way of indenting
Python is with spaces only.  ... Code indented with a mixture
of tabs and spaces should be converted to using spaces
exclusively. ... When invoking the python command line
interpreter with the -t option, it issues warnings about code
that illegally mixes tabs and spaces.  When using -tt these
warnings become errors. These options are highly recommended!

For new projects, spaces-only are strongly recommended over
tabs. Most editors have features that make this easy to do.

If your "FR" is approved, -t and -tt could apply to any use of tabs.
+1 from me.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI module does not parse data

2005-12-02 Thread amfr
I am using execfile, setting stdin and stdout like this:
sys.stdin = self.wfile
sys.stdout = self.rfile
execfile(filename)

Its the same code used in the CGIHTTPServer module.  I know that the
python is executing corretly, a script with this content would work:

print ""
print ""
print ""
print "blah"
print ""
print "
print ""
print "test"
print ""
print ""

but this would not (lets say i submitted a form with the value of test
being "hello world"):

import cgi
form = cgi.FieldStorage()
print form["test"]
print "test"

I would only be able to see "test", not "hello world"
I am sure its not my browser

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


Volume of CSG (constructive solid geometry) objects

2005-12-02 Thread Charlie
>From python, I need to be able to create CSG objects and calculate their volume
(and from that their mass).

It looks like their are plenty of packages to create and display CSG objects,
however, I can not seem to find any API to get to the object's volume.

If anyone has any ideas/tips/pointers/etc., I would be very grateful.

Thanks,
Charlie

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


Re: unittest.assertRaise and keyword arguments?

2005-12-02 Thread Giovanni Bajo
Bo Peng wrote:

> The syntax for using assertRaise is
>
>assertRaise(exception, function, para1, para2,...)
>
> However, I have a long list of arguments (>20) so I would like to test
> some of them using keyword arguments (use default for others). Is there
> a way to do this except for manually try...except?


You can pass keyword arguments to assertRaises without problems:

self.assertRaises(ValueError, myfunc, arg1,arg2, arg3, arg4, abc=0, foo=1,
bar="hello")

Or you can always do something like:

self.assertRaises(ValueError, lambda: myfunc(arg1,arg2, arg3, arg4, abc=0,
foo=1, bar="hello"))
-- 
Giovanni Bajo


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


Re: XML and namespaces

2005-12-02 Thread A.M. Kuchling
On 2 Dec 2005 06:16:29 -0800, 
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Of course.  Minidom implements level 2 (thus the "NS" at the end of the
> method name), which means that its APIs should all be namespace aware.
> The bug is that writexml() and thus toxml() are not so.

Hm, OK.  Filed as bug #1371937 in the Python bug tracker.  Maybe I'll
look at this during the bug day this Sunday.

--amk

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


Re: How to list currently defined classes, methods etc

2005-12-02 Thread Deep
I have been looking a bit and am stuck at this point.

Given a string, how do i find what is the string bound to.
Let me give an example.

def deep():
 print "Hello"

now inspect.ismethod(deep) returns true. (As it should).
But if I am trying to make a list of all bound methods), i use
dir(), which is a list of strings. I get the string "deep" from this
list.
How do I obtain the reference to the method it is bound to.
The same problem can be extended to attributes and classes.

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


unittest.assertRaise and keyword arguments?

2005-12-02 Thread Bo Peng
Dear list,

The syntax for using assertRaise is

   assertRaise(exception, function, para1, para2,...)

However, I have a long list of arguments (>20) so I would like to test 
some of them using keyword arguments (use default for others). Is there 
a way to do this except for manually try...except?

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


Re: Death to tuples!

2005-12-02 Thread Bengt Richter
On 2 Dec 2005 13:05:43 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:

>On 2005-12-02, Bengt Richter <[EMAIL PROTECTED]> wrote:
>> On 1 Dec 2005 09:24:30 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>>
>>>On 2005-11-30, Duncan Booth <[EMAIL PROTECTED]> wrote:
 Antoon Pardon wrote:

>
>Personnaly I expect the following pieces of code
>
>  a = 
>  b = 
>
>to be equivallent with
>
>  a = 
>  b = a
>
>But that isn't the case when the const expression is a list.
>
ISTM the line above is a symptom of a bug in your mental Python source 
interpreter.
It's a contradiction. A list can't be a "const expression".
We probably can't make real progress until that is debugged ;-)
Note: assert "const expression is a list" should raise a mental exception ;-)

>A person looking at:
>
>  a = [1 , 2]
English: let a refer to a mutable container object initialized to contain
an ordered sequence of specified elements 1 and 2.
>
>sees something resembling
>
>  a = (1 , 2)
English: let a refer to an immutable container object initialized to contain
an ordered sequence of specified elements 1 and 2.
>
>Yet the two are treated very differently. As far as I understand the
>first is translated into somekind of list((1,2)) statement while
They are of course different in that two different kinds of objects
(mutable vs immutable containers) are generated. This can allow an optimization
in the one case, but not generally in the other.

>the second is build at compile time and just bound.
a = (1, 2) is built at compile time, but a = (x, y) would not be, since x and y
can't generally be known a compile time. This is a matter of optimization, not
semantics. a = (1, 2) _could_ be built with the same code as a = (x, y) picking 
up
1 and 2 constants as arguments to a dynamic construction of the tuple, done in 
the
identical way as the construction would be done with x and y. But that is a red 
herring
in this discussion, if we are talking about the language rather than the 
implementation.

>
>This seems to go against the pythonic spirit of explicit is
>better than implicit.
Unless you accept that '[' is explicitly different from '(' ;-)

>
>It also seems to go against the way default arguments are treated.
I suspect another bug ;-)

>

>> but that's independent of scope. An expression in general may depend on
>> names that have to be looked up, which requires not only a place to look
>> for them, but also persistence of the name bindings. so def 
>> foo(arg=PI*func(x)): ...
>> means that at call-time you would have to find 'PI', 'func', and 'x' 
>> somewhere.
>> Where & how?
>> 1) If they should be re-evaluated in the enclosing scope, as default arg 
>> expressions
>> are now, you can just write foo(PI*func(x)) as your call.
>
>I may be a bit pedantic. (Read that as I probably am)
>
>But you can't necesarry write foo(PI*func(x)) as your call, because PI
>and func maybe not within scope where the call is made.
Yes, I was trying to make you notice this ;-)

>
>> So you would be asking
>> for foo() to be an abbreviation of that. Which would give you a fresh list if
>> foo was defined def foo(arg=[]): ...
>
>This was my first thought.
>
[...]
> Why on earth should it be the same list, when a function is called
> and is provided with a list as a default argument?
>> It's not "provided with a list" -- it's provided with a _reference_ to a 
>> list.
>> You know this by now, I think. Do you want clone-object-on-new-reference 
>> semantics?
>> A sort of indirect value semantics? If you do, and you think that ought to be
>> default semantics, you don't want Python. OTOH, if you want a specific 
>> effect,
>> why not look for a way to do it either within python, or as a graceful 
>> syntactic
>> enhancement to python? E.g., def foo(arg{expr}):... could mean evaluate arg 
>> as you would like.
>> Now the ball is in your court to define "as you would like" (exactly and 
>> precisely ;-)
>
>I didn't start my question because I wanted something to change in
>python. It was just something I wondered about. Now I wouldn't
I wonder if this "something" will still exist once you get
assert "const expression is a list" to raise a mental exception ;-)

>mind python to be enhanced at this point, so should the python
>people decide to work on this, I'll give you my proposal. Using your
>syntax.
>
>  def foo(arg{expr}):
> ...
>
>should be translated something like:
>
>  class _def: pass
>
>  def foo(arg = _def):
>if arg is _def:
>  arg = expr
>...
>
>I think this is equivallent with your first proposal and probably
>not worth the trouble, since it is not that difficult to get
>the behaviour one wants.
Again, I'm not "proposing" anything except to help lay out evidence.
The above is just a spelling of typical idiom for mutable default
value initialization.

>
>I think such a proposal would be most advantaged for the newbees
>because the two possibilities for default values would make them
>think about what the differences are between the 

LDAP Authentication

2005-12-02 Thread Derek Perriero
Any help would be great on this.  I've been trying to bind a
username and password to the ldap server for authentication, but when I
locally run this script:

#!/usr/bin/python
import ldap

## Connect to LDAP host
try:
    ldapcn = ldap.initialize('ldap://xxx.xxx.xxx.xxx')
    ldapcn.bind('cn=username,o=domain','password',ldap.AUTH_SIMPLE)
    print "Successful."
except ldap.LDAPError, e:
    print e
    print "Declined.\n"

I always get a successful return even if the password or username is
incorrect.  Or, if I even leave the username and password field in
the initialize function blank, I get a successful return.
I need some guidance in the correct direction.

Thanks!
Derek-- Perriero, Derek[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 Dave Hansen <[EMAIL PROTECTED]> wrote:

> On 2 Dec 2005 10:08:21 -0800 in comp.lang.python, [EMAIL PROTECTED]
> wrote:
> 
> >Here it is again...  Python bypassed/discounted because, of all things,
> >scoping by indentation!?!?
> >
> >This used to surprise me.  Until I hear more and more otherwise
> >reasonable programmers list this as their number one reason for
> >shunning Python.
> >
> >I gauge design defects by how much after market
> >discussion/documentation a feature generates/requires.   Scoping by
> >indentation is a whopper of a defect.
> 
> FWIW, indentation scoping one one of the features that _attracted_ me
> to Python.

Me too.  Or rather, Python code is much more readable because every 
nincompoop has to use indentation correctly whether they want to or not, 
and I like readable code.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Instances behaviour

2005-12-02 Thread Inyeol Lee
On Fri, Dec 02, 2005 at 10:43:56AM +0100, bruno at modulix wrote:
> Inyeol Lee wrote:
> (snip)
> 
> class A(object):
> ... def __init__(self, foo):
> ... if self.__class__ is A:
> ... raise TypeError("A is base class.")   
> 
> 
> s/TypeError/NotImplementedError/
> s/base class/abstract class/

I prefer TypeError here, NotImplementedError would be OK though.
Here is an example from sets.py in stdlib.


class BaseSet(object):
"""Common base class for mutable and immutable sets."""

__slots__ = ['_data']

# Constructor

def __init__(self):
"""This is an abstract class."""
# Don't call this from a concrete subclass!
if self.__class__ is BaseSet:
raise TypeError, ("BaseSet is an abstract class.  "
  "Use Set or ImmutableSet.")


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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread [EMAIL PROTECTED]
You're not alone.
The first thing I do after installing an IDE or programmers editor is
to change the configuration to use spaces as identantion.

I still don't get why there is still people using real tabs as
indentation.

--
Paulo

Dave Hansen wrote:
> On 2 Dec 2005 10:08:21 -0800 in comp.lang.python, [EMAIL PROTECTED]
> wrote:
>  ... (cutted)
> Of these, only (2) is valid.  And the only reason it's valid is that
> Python recognizes the TAB character as valid indentation.  TAB
> characters are evil.  They should be banned from Python source code.
> The interpreter should stop translation of code and throw an exception
> when one is encountered.  Seriously.  At least, I'm serious when I say
> that.  I've never seen TAB characters solve more problems than they
> cause in any application.
>
> But I suspect I'm a lone voice crying in the wilderness.  Regards,
> -=Dave
> 
> -- 
> Change is inevitable, progress is not.

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


Re: an intriguing wifi http server mystery...please help

2005-12-02 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> The server runs fast when one computer is the server, but slow when the
> other computer is the server.
> How can this be, given that this asymmetry does not exist when both
> computers are wired.

Probably because the way your wireless interfaces are configured may be
different from the way your wired interfaces are configured. Network
problems are hard enough to solve "on site" with full access to all the
necessary information - doing so with substantially less information in
a newsgroup thread is substantially more difficult.

With regard to my point about the "fairly simple HTTP server" that you
are using, if you choose to run whichever server such that you can see
it writing its log - for BaseHTTPServer this is easy since it just
writes its log to the terminal/console - then you might be able to see
where the delay occurs by putting logging statements in your program at
the start and end of its work. If your program seems to write its
finishing logging message and yet a long delay occurs before the server
writes something about where the request came from (and the browser
gets to see the output of your program), then you may well have a
problem with the way the server prepares its logging messages as I
described in my last message.

Paul

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


Detect Blank DVD or CD in CDROM Drive

2005-12-02 Thread Gregory Piñero
Hi guys,

I'm thinking it will take a real expert to do this, probably someone
who can use windows API's or directly poll the hardware or some such
thing.  But if you think you know how then please let me
know.  I'm trying to write an automation script that will burn an
ISO file each night.

By the way, I tried this recipe but it doesn't seem to work for blank media:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/180919-- Gregory PiñeroChief Innovation OfficerBlended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Dave Hansen
On 2 Dec 2005 10:08:21 -0800 in comp.lang.python, [EMAIL PROTECTED]
wrote:

>Here it is again...  Python bypassed/discounted because, of all things,
>scoping by indentation!?!?
>
>This used to surprise me.  Until I hear more and more otherwise
>reasonable programmers list this as their number one reason for
>shunning Python.
>
>I gauge design defects by how much after market
>discussion/documentation a feature generates/requires.   Scoping by
>indentation is a whopper of a defect.

FWIW, indentation scoping one one of the features that _attracted_ me
to Python.  

It's far more interesting to me _why_ people think indentation scoping
is a bad thing.  The answer I get back fall into two general
categories: 1) I've heard/read/been told it's a bad thing, and 2) It
causes portability problems.

Of these, only (2) is valid.  And the only reason it's valid is that
Python recognizes the TAB character as valid indentation.  TAB
characters are evil.  They should be banned from Python source code.
The interpreter should stop translation of code and throw an exception
when one is encountered.  Seriously.  At least, I'm serious when I say
that.  I've never seen TAB characters solve more problems than they
cause in any application.

But I suspect I'm a lone voice crying in the wilderness.  Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: libxml2 and XPath - Iterate through repeating elements?

2005-12-02 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> I'm trying to iterate through repeating elements to extract data using
> libxml2 but I'm having zero luck - any help would be appreciated.

Here's how I attempt to solve the problem using libxml2dom [1] (and I
imagine others will suggest their own favourite modules, too):

import libxml2dom
d = libxml2dom.parseFile(filename)
order_numbers = d.xpath("//so:order/so:header/so:orderno",
namespaces={"so" : "some-ns"})

At this point, you have a list of nodes. (I imagine that whatever
object the libxml2 module API produces probably has those previous and
next attributes to navigate the result list instead.) The nodes in the
list represent the orderno elements in this case, and in libxml2dom you
can choose to invoke the usual DOM methods on such node objects, or
even the toString method if you want the document text. For the line
items...

lines = d.xpath("//so:order/so:lines/so:line", namespaces={"so" :
"some-ns"})
for line in lines:
print line.toString()

I can't remember what the libxml2 module produces for the content
attribute of a node, although the underlying libxml2 API produces a
"text-only" representation of the document text, as opposed to the
actual document text that the toString method produces in the above
example. I imagine that an application working with the line item
information would use additional DOM or XPath processing to get the
line item index and the product code directly.

Anyway, I recommend libxml2dom because if you're already using the
bundled libxml2 module, you should be able to install libxml2dom and
plug into the same infrastructure that the bundled module depends upon.
Moreover, libxml2dom is a "pure Python" package that doesn't require
any extension module compilation, so it should be quite portable to
whatever platform you're using.

Paul

[1] http://www.python.org/pypi/libxml2dom

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


Re: How to creat a file?

2005-12-02 Thread [EMAIL PROTECTED]

sandorf wrote:
> Thank to you all, guys. Here's another question:
>
> I'm using the Windows version of Python and IDLE. When I debug my .py
> file, my modification to the .py file does not seem to take effect
> unless I restart IDLE. Saving the file and re-importing it doesn't help
> either. Where's the problem?

>From your edit window, go to the Run menu and select Run Module.

It will prompt you to save the file, it will restart the shell and will
reload
and run the new version all in one operation.

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> Here it is again...  Python bypassed/discounted because, of all things,
> scoping by indentation!?!?

[...]

> Could the PyPy people find some way (I don't how) to eliminate this
> stumbling block going forward??

No: I believe they could only eliminate it "going backward". ;-)

Paul

P.S. I will admit that the first thing I do when editing someone else's
code (in any language) is to make sure the tab settings are sane in my
editor, but should basic editing skills really be so far beyond the
person/people entrusted with writing the software that runs your
business/organisation/lifestyle? Is Mr Rocket Scientist really
incapable of tying his own shoelaces?

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread JohnBMudd
Here it is again...  Python bypassed/discounted because, of all things,
scoping by indentation!?!?

This used to surprise me.  Until I hear more and more otherwise
reasonable programmers list this as their number one reason for
shunning Python.

I gauge design defects by how much after market
discussion/documentation a feature generates/requires.   Scoping by
indentation is a whopper of a defect.

Could the PyPy people find some way (I don't how) to eliminate this
stumbling block going forward??  That is, after they eliminate the GIL!

John

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


How to keep Pydoc from listing too much?

2005-12-02 Thread Tony Nelson
How can I tell Pydoc not to list information for some of the base 
classes?  For example, when a class inherits from gtk.Widget, lots of 
GTK stuff gets added that doesn't really need to be there.  Is there 
some option to Pydoc to tell it to skip some classes?  Is there 
something I can put in my source that is a hint to Pydoc?

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Setting PYTHONPATH from Makefile

2005-12-02 Thread François Pinard
[EMAIL PROTECTED]
> I have a Makefile target that uses a python script, like:

> %.abc: %.def
> python myscript.py

> If this was a tcsh script, I would just do:

>setenv PYTHONPATH /path/to/stuff
>python myscript.py

> but this cannot be done from a Makefile.

Use:

%.abc: %.def
PYTHONPATH=/path/to/stuff python myscript.py

In fact, within Make or outside Make, for any shell command, you may 
write:

VAR1=VALUE1 VAR2=VALUE2 ... COMMAND ARGUMENTS

so temporarily setting VAR1, VAR2... in the environment for the duration 
of COMMAND only.  This is a useful feature of the shell.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Death to tuples!

2005-12-02 Thread Mike Meyer
Antoon Pardon <[EMAIL PROTECTED]> writes:
> On 2005-12-02, Bengt Richter <[EMAIL PROTECTED]> wrote:
>> On 1 Dec 2005 09:24:30 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>>>On 2005-11-30, Duncan Booth <[EMAIL PROTECTED]> wrote:
 Antoon Pardon wrote:
>>>I think one could argue that since '[]' is normally evaluated when
>>>the expression containing it is excuted, it should also be executed
>>>when a function is called, where '[]' is contained in the expression
>>  ^^^[1] ^
>>>determining the default value.
>>  ^^^[2]
>> Ok, but "[]" (without the quotes) is just one possible expression, so
>> presumably you have to follow your rules for all default value expressions.
>> Plain [] evaluates to a fresh new empty list whenever it is evaluated,
> Yes, one of the questions I have is why python people whould consider
> it a problem if it wasn't.

That would make [] behave differently from [compute_a_value()]. This
doesn't seem like a good idea.

> Personnaly I expect the following pieces of code
>   a = 
>   b = 
> to be equivallent with
>   a = 
>   b = a
> But that isn't the case when the const expression is a list.

It isn't the case when the const expression is a tuple, either:

x = (1, 2)
>>> (1, 2) is x
False
>>> 

or an integer:

>>> a = 1234
>>> a is 1234
False
>>> 

Every value (in the sense of a syntactic element that's a value, and
not a keyword, variable, or other construct) occuring in a program
should represent a different object. If the compiler can prove that an
value can't be changed, it's allowed to use a single instance for all
occurences of that value. Is there *any* language that behaves
differently from this?

> A person looking at:
>   a = [1 , 2]
> sees something resembling
>   a = (1 , 2)
> Yet the two are treated very differently. As far as I understand the
> first is translated into somekind of list((1,2)) statement while
> the second is build at compile time and just bound.

No, that translation doesn't happen. [1, 2] builds a list of
values. (1, 2) builds and binds a constant, which is only possible
because it, unlike [1, 2], *is* a constant. list(1, 2) calls the
function "list" on a pair of values:

>>> def f():
...  a = [1, 2]
...  b = list(1, 2)
...  c = (1, 2)
... 
>>> dis.dis(f)
  2   0 LOAD_CONST   1 (1)
  3 LOAD_CONST   2 (2)
  6 BUILD_LIST   2
  9 STORE_FAST   0 (a)

  3  12 LOAD_GLOBAL  1 (list)
 15 LOAD_CONST   1 (1)
 18 LOAD_CONST   2 (2)
 21 CALL_FUNCTION2
 24 STORE_FAST   2 (b)

  4  27 LOAD_CONST   3 ((1, 2))
 30 STORE_FAST   1 (c)
 33 LOAD_CONST   0 (None)
 36 RETURN_VALUE

> This seems to go against the pythonic spirit of explicit is
> better than implicit.

Even if "[arg]" were just syntactic sugar for "list(arg)", why would
that be "implicit" in some way?

> It also seems to go against the way default arguments are treated.

Only if you don't understand how default arguments are treated.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: an intriguing wifi http server mystery...please help

2005-12-02 Thread jojoba
Hello again everyone,

First, I want to thank all those who have contributed to the
unravelling of this server-slow-down mystery.
But unfortunately, either:

1) i have not made my point clear about what my question is
2) i do not understand the responses given

So, let me briefly reiterate what the mystery is.
(i am assuming that readers have read most of my first post above).
I have two computers and a server program (written in python).
Both computers are on my home lan (using a linksys wifi router).
HERE IS THE MYSTERY:
The server runs fast when one computer is the server, but slow when the
other computer is the server.
How can this be, given that this asymmetry does not exist when both
computers are wired.

Please let me know if you need any more information,
Thanks again to all who have been helping with this,
jojoba

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


libxml2 and XPath - Iterate through repeating elements?

2005-12-02 Thread nickheppleston
I'm trying to iterate through repeating elements to extract data using
libxml2 but I'm having zero luck - any help would be appreciated.

My XML source is similar to the following - I'm trying to extract the
line number and product code from the repeating line elements:


  
123456
  
  

  1
  PENS


  2
  STAPLER


  3
  RULER

  


With the following code I can get at the non-repeating elements in the
header, and get the lines elements, but cannot extract the
lineno/productcode data via xpath:

XmlDoc = libxml2.parseFile(XmlFile);
XPathDoc = XmlDoc.xpathNewContext();
XPathDoc.xpathRegisterNs('so',"some-ns");


# Extract data from the order header
PurchaseOrderNo =
XPathDoc.xpathEval('//so:order/so:header/so:orderno');

# Extract data from the order lines
for line in XPathDoc.xpathEval('//so:order/so:lines/so:line'):
print line.content;

# Explicitly free Xml document and XPath context
XmlDoc.freeDoc()
XPathDoc.xpathFreeContext()

Ideally, I'd like to select the line data using xpath (similar to an
XSLT query after a 'for-each' - i.e. xpathEval('so:lineno') and
xpathEval('so:productcode') once I've got the line element).

Any suggestions grealty appreciated!

Cheers, Nick.

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


Re: Eclipse best/good or bad IDE for Python?

2005-12-02 Thread gene tani

[EMAIL PROTECTED] wrote:
> I'm trying to move beyond Emacs/Vim/Kate
> and was wondering if Eclipse is better and if it is the *best*
> IDE for Python.
>
> Should I leave Emacs and do Python coding in Eclipse?
>
> Chris

I'm agnostic; lots of IDE's/editors have buzz, you should learn to use
at least a couple well:

- vim, emacs
- Wing, Komodo, Textmate (OS X only)
- jedit, eclipse,
- eric, PythonWin, kate, leo, etc.

Check the wiki:
http://wiki.python.org/moin/DevelopmentTools

then google c.l.py for how your most desired features are supported:
syntax coloring, SVN integrate, auto-complete (if you think it helps),
pylint, threaded debugger, smart tags, object/class/code
folding/browser etc.  This guy spent a lot of time composing this:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/e3a65f2908bb8ba4/12ea5915f8f09546?q=IDE+subversion&rnum=1#12ea5915f8f09546

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


Re: Problem cmpiling M2Crypto under Plone

2005-12-02 Thread Thomas G. Apostolou

"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Thomas G. Apostolou wrote:
>
> > So what you say is that the Python installed with Plone doesn't have
> > Python.h in ./include but Python installers from Python.org do have the
> > file?
>
> that's likely, given building didn't work for you.
>
> after all, Plone's an application that happens to include a Python
interpreter,
> not a Python distribution.
>
> > If yes i guess i should install the same version to the same location
> > (over-writing). Is that so?
>
> to minimize the risk, I'd grab the corresponding python.org version,
install it
> in a separate location, use the python.org version to build the
extensions, and
> finally install them in the Plone tree.
>
> but maybe there's no risk for conflict; maybe someone from the Plone team
> can clarify ?

The above sudgestion is right. Unfortunatelly i found out the problem the
bad way...
After installing the full package of python 2.3.3 on top of the
plone's(2.0.5) python installation, the build and install of m2crypto went
ok but the zope server service was refusing to start...
I thought ok the installation kept a BACKUP directory so i can allways roll
back...
I did unistall it and there was realy a rollback option there witch i
choosed.
But still the service was refusing to start giving me an error witch i could
read at windows EventViewer/Application that was saying :

"Python could not import the service's module
File "C:\Program Files\Plone 2\Data\bin\zopeservice.py", line 100, in ?
from nt_svcutils.service import Service
File "C:\Program Files\Plone 2\Zope\lib\python\nt_svcutils\service.py", line
18, in ?
import win32serviceutil
exceptions.ImportError: No module named win32serviceutil
Python could not import the service's module
File "C:\Program Files\Plone 2\Data\bin\zopeservice.py", line 100, in ?
from nt_svcutils.service import Service
File "C:\Program Files\Plone 2\Zope\lib\python\nt_svcutils\service.py", line
18, in ?
import win32serviceutil
exceptions.ImportError: No module named win32serviceutil"


Good for me i had backups of everything (External Methods, Script(Python),
and DTML-PT). So i unistalled Plone 2.0.5, reistalled it and restored my
site. Of course i was not stupid enough and the problem was encountered in
my development pc instead of the real site pc
Now everithing is ok as i run python setup.py install and it ran ok...

Time for me to learn about how to apply patches (there is one for python
2.3.3 for Connection.py and on for m2crypto named xmlrpclib.py.patch inside
patches directory of mycrypto)

After that i'll start with trying to use the whole thing compiling all this
time...
Thanks to the people imlementing m2crypto and all of you helping me with the
compilation.

PS: After all that strugling for building on windows i am sure that i am
going to use the whole thing on linux box next time i set it up for someone
else


Thomas G. Apostolou



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


Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 Adriano Ferreira <[EMAIL PROTECTED]> wrote:

> Hey, that's not fair. In your illustration above, does 'python' can be
> found in the PATH? That is,
> 
> $ python /tmp/hello.py
> 
> works? If it does, probably
> 
> #!/usr/bin/python
> #!/usr/bin/env python
> #!python
> 
> would also work if
> (1) 'python' is at '/usr/bin/python' (but that's inflexible)
> (2) 'python' can be found in the environment variable path (if 'env'
> is at '/usr/bin/env')
> (3) 'python' can be found in the environment variable path (no need
> for 'env' utility)

Contrary to popular belief, #! is not intended for the shell,
but rather for the execve(2) system call of the UNIX operating
system.  These two characters form the 16 bit "magic number"
of interpreter files.  Any executable file must start with a
16 bit field that identifies it so the operating system will
know how to execute it.

In the case of a #! interpreter file, the operating system
expects the rest of that line to be the path to the file.
PATH is not searched, and is irrelevant.  The only way
#!python can work, is if it's in the current working directory.

Just to help make it confusing, when this mechanism fails
and execve(2) returns an error, most shells will go on to
try to execute the file themselves, regardless of whether
there's a #! or not.  csh (the shell language that doesn't
look anything like C, Bill Joy's attempt at language design
before he started over with Java) does that only if the first
line is "#"; otherwise it invokes the Bourne shell.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Death to tuples!

2005-12-02 Thread Mike Meyer
Antoon Pardon <[EMAIL PROTECTED]> writes:
>>> Well there are two possibilities I can think of:
>>>
>>> 1)
>>>   arg_default = ...
>>>   def f(arg = arg_default):
>>>  ...
>>
>> Yuch. Mostly because it doesn't work:
>>
>> arg_default = ...
>> def f(arg = arg_default):
>> ...
>>
>> arg_default = ...
>> def g(arg = arg_default):
>>
>> That one looks like an accident waiting to happen.
> It's not because accidents can happen, that it doesn't work.
> IMO that accidents can happen here is because python
> doesn't allow a name to be marked as a constant or unreboundable.

Loets of "accidents" could be fixed if Python marked names in various
ways: with a type, or as only being visible to certain other types, or
whatever. A change that requires such a construct in order to be
usable probably needs rethinking.

Even if that weren't a problem, this would still require introducting
a new variable into the global namespace for every such
argument. Unlike other similar constructs, you *can't* clean them up,
because the whole point is that they be around later.

The decorator was an indication of a possible solution. I know it
fails in some cases, and it probably fails in others as well.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detect TKinter window being closed?

2005-12-02 Thread Glen
Thanks Fredrik and Adonis that's just what I needed, plus a bit more to
learn about.

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


Dr. Dobb's Python-URL! - weekly Python news and links (Dec 2)

2005-12-02 Thread Cameron Laird
QOTW:  "Python makes it easy to implement algorithms." - casevh

"Most of the discussion of immutables here seems to be caused by
newcomers wanting to copy an idiom from another language which doesn't
have immutable variables. Their real problem is usually with binding,
not immutability." - Mike Meyer


Among the treasures available in The Wiki is the current
copy of "the Sorting min-howto":
http://www.amk.ca/python/howto/sorting/sorting.html

Dabo is way cool--at least as of release 0.5:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/becf84a4f8b3d34/

Tim Golden illustrates that wmi is *not* the only way to
access win32 functionality, and in fact that Python can
mimic VisualBasicScript quite handily.  It's only mimicry,
though; VBS remains better suited for this specific class
of tasks:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/fa84850666488500/

Claudio Grondi explains ActiveX componentry--OCXs, the
registry, apartments, ...--for a Python audience:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/471306f2d6f6927/

Dao is a novel high-level language which advertises strong
multi-threading, Unicode, and particularly comfortable C++ 
interfacing.  Limin Fu provides details:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4418fac8dda696d9/

Donn Cave leads at least a score of others in comparing
lists and tuples:
http://groups.google.com/group/comp.lang.python/msg/dd6ba8df451d57e0?


Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi
http://python.de/backend.php
For more, see
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python "To-Do List" now lives principally in a
SourceForge reincarnation.
http://sourc

Re: Why my modification of source file doesn't take effect when debugging?

2005-12-02 Thread Christophe
infidel a écrit :
>>I'm using the Windows version of Python and IDLE. When I debug my .py
>>file, my modification to the .py file does not seem to take effect
>>unless I restart IDLE. Saving the file and re-importing it doesn't help
>>either. Where's the problem?
> 
> 
> "import" only reads the file the first time it's called.  Every import
> call after that looks up the module in memory.  This is to prevent
> circular dependencies between modules from creating infinite loops.
> You need to use the reload() function:

As a matter of fact, it would help a lot if that stupid behaviour of 
Idle was dropped. I'm sure I'm not the only one who lost lots of time 
because of that bug. Yes I call it a bug.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why my modification of source file doesn't take effect when debugging?

2005-12-02 Thread infidel
> I'm using the Windows version of Python and IDLE. When I debug my .py
> file, my modification to the .py file does not seem to take effect
> unless I restart IDLE. Saving the file and re-importing it doesn't help
> either. Where's the problem?

"import" only reads the file the first time it's called.  Every import
call after that looks up the module in memory.  This is to prevent
circular dependencies between modules from creating infinite loops.
You need to use the reload() function:

>>> import foo

#change the contents of foo

>>> foo = reload(foo)

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


Re: Is there no compression support for large sized strings in Python?

2005-12-02 Thread Christopher Subich
Fredrik Lundh wrote:
> Harald Karner wrote:

>>>python -c "print len('m' * ((2048*1024*1024)-1))"
>>
>>2147483647
> 
> 
> the string type uses the ob_size field to hold the string length, and
> ob_size is an integer:
> 
> $ more Include/object.h
> ...
> int ob_size; /* Number of items in variable part */
> ...
> 
> anyone out there with an ILP64 system?

I have access to an itanium system with a metric ton of memory.  I 
-think- that the Python version is still only a 32-bit python, though 
(any easy way of checking?).  Old version of Python, but I'm not the 
sysadmin and "I want to play around with python" isn't a good enough 
reason for an upgrade. :)


Python 2.2.3 (#1, Nov 12 2004, 13:02:04)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> str = 'm'*2047*1024*1024 + 'n'*2047*1024*1024
 >>> len(str)
-2097152

Yes, that's a negative length.  And I don't really care about rebinding 
str for this demo. :)

 >>> str[0]
Traceback (most recent call last):
   File "", line 1, in ?
IndexError: string index out of range
 >>> str[1]
Traceback (most recent call last):
   File "", line 1, in ?
IndexError: string index out of range
 >>> str[-1]
Traceback (most recent call last):
   File "", line 1, in ?
SystemError: error return without exception set
 >>> len(str[:])
-2097152
 >>> l = list(str)
 >>> len(l)
0
 >>> l
[]

The string is actually created -- top reports 4.0GB of memory usage.

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


Re: aligning a set of word substrings to sentence

2005-12-02 Thread Steven Bethard
Steven Bethard wrote:
> Michael Spencer wrote:
> 
>> Steven Bethard wrote:
>>
>>> I've got a list of word substrings (the "tokens") which I need to 
>>> align to a string of text (the "sentence").  The sentence is 
>>> basically the concatenation of the token list, with spaces sometimes 
>>> inserted beetween tokens.  I need to determine the start and end 
>>> offsets of each token in the sentence.  For example::
>>>
>>> py> tokens = ['She', "'s", 'gon', 'na', 'write', 'a', 'book', '?']
>>> py> text = '''\
>>> ... She's gonna write
>>> ... a book?'''
>>> py> list(offsets(tokens, text))
>>> [(0, 3), (3, 5), (6, 9), (9, 11), (12, 17), (18, 19), (20, 24), (24, 
>>> 25)]
>>>
>>
> [snip]
> 
>>
>> and then, for an entry in the wacky category, a difflib solution:
>>
>>  >>> def offsets(tokens, text):
>>  ... from difflib import SequenceMatcher
>>  ... s = SequenceMatcher(None, text, "\t".join(tokens))
>>  ... for start, _, length in s.get_matching_blocks():
>>  ... if length:
>>  ... yield start, start + length
>>  ...
>>  >>> list(offsets(tokens, text))
>>  [(0, 3), (3, 5), (6, 9), (9, 11), (12, 17), (18, 19), (20, 24), (24, 
>> 25)]
> 
> 
> That's cool, I've never seen that before.  If you pass in str.isspace, 
> you can even drop the "if length:" line::
> 
> py> def offsets(tokens, text):
> ... s = SequenceMatcher(str.isspace, text, '\t'.join(tokens))
> ... for start, _, length in s.get_matching_blocks():
> ... yield start, start + length
> ...
> py> list(offsets(tokens, text))
> [(0, 3), (3, 5), (6, 9), (9, 11), (12, 17), (18, 19), (20, 24), (24, 
> 25), (25, 25)]

Sorry, that should have been::
 list(offsets(tokens, text))[:-1]
since the last item is always the zero-length one.  Which means you 
don't really need str.isspace either.

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


Re: Detect TKinter window being closed?

2005-12-02 Thread Fredrik Lundh
Glen wrote:

> Is it possible to to detect a Tkinter top-level window being closed with the
> close icon/button (top right), for example to call a function before the
> window actually closes?

http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm#protocols

 



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


Re: Eclipse best/good or bad IDE for Python?

2005-12-02 Thread Aaron Bingham
[EMAIL PROTECTED] wrote:

>I'm trying to move beyond Emacs/Vim/Kate
>and was wondering if Eclipse is better and if it is the *best*
>IDE for Python.
>
>Should I leave Emacs and do Python coding in Eclipse?
>  
>
I've been a heavy Emacs user for several years, but recently switched to 
Eclipse for Python development.  I was skeptical at first, but I gave it 
a chance for a few days and was convinced.

The killer PyDev feature for me is pylint integration.  Being informed 
immediately when you mistype a variable name is a big timesaver.  Also 
nice is the refactoring support (although this it is possible to 
integrate BicycleRepairMan! with Emacs, I found it easier to use in 
Eclipse).  I still find the Eclipse editor awkward for some things that 
are easy in Emacs (Emacs is in my fingers), so I occasionally switch 
back to Emacs for a quick edit.

Eclipse performance is not a problem for me, but I have a beefy box.

Enjoy,

Aaron Bingham

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


Re: Detect TKinter window being closed?

2005-12-02 Thread Adonis
Glen wrote:
> Is it possible to to detect a Tkinter top-level window being closed with the
> close icon/button (top right), for example to call a function before the
> window actually closes?
> 
> Python 2.4 / Linux (2.6 kernel) if that makes any difference.
> Any info would be greatly appreciated.
> Thanks
> Glen

Here is an example code taken from:
http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm
(located at very end)

Example 7-2. Capturing destroy events

# File: protocol1.py

from Tkinter import *
import tkMessageBox

def callback():
 if tkMessageBox.askokcancel("Quit", "Do you really wish to quit?"):
 root.destroy()

root = Tk()
root.protocol("WM_DELETE_WINDOW", callback)

root.mainloop()

Hope this helps.

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


Re: How do you create a custom QCursor in Python Qt?

2005-12-02 Thread Phil Thompson
On Friday 02 December 2005 3:31 pm, [EMAIL PROTECTED] wrote:
> I am a newcomer to using Python and Qt and the main problem that I have
> is the dearth of any example code or books describing the use of Python
> and Qt together.
>
> My current problem is that I want to create a custom cursor, from my
> understanding of it I need to create two "QBitmap"s, one of which will
> be the mask and then using these to create a "QCursor".
> I don't mine whether the "QBitmap"s are hardcoded in the source code or
> come from image files, just as long as I can create a new cursor:
>
> I have searched all the available code sources I can find:
> www.koders.com
> Eric
> Veus
> Civil
> Qomics
> for examples of how to create cursors but to no avail. So if amyone can
> tell me what I'm doing wrong, it would be much appreciated, here's my
> code:

How about looking at the cursor.py example that comes with PyQt? It 
demonstrates the standard cursors and implements a custom cursor.

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


Detect TKinter window being closed?

2005-12-02 Thread Glen
Is it possible to to detect a Tkinter top-level window being closed with the
close icon/button (top right), for example to call a function before the
window actually closes?

Python 2.4 / Linux (2.6 kernel) if that makes any difference.
Any info would be greatly appreciated.
Thanks
Glen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: aligning a set of word substrings to sentence

2005-12-02 Thread Steven Bethard
Michael Spencer wrote:
> Steven Bethard wrote:
> 
>> I've got a list of word substrings (the "tokens") which I need to 
>> align to a string of text (the "sentence").  The sentence is basically 
>> the concatenation of the token list, with spaces sometimes inserted 
>> beetween tokens.  I need to determine the start and end offsets of 
>> each token in the sentence.  For example::
>>
>> py> tokens = ['She', "'s", 'gon', 'na', 'write', 'a', 'book', '?']
>> py> text = '''\
>> ... She's gonna write
>> ... a book?'''
>> py> list(offsets(tokens, text))
>> [(0, 3), (3, 5), (6, 9), (9, 11), (12, 17), (18, 19), (20, 24), (24, 25)]
>>
>
[snip]
>
> and then, for an entry in the wacky category, a difflib solution:
>
>  >>> def offsets(tokens, text):
>  ... from difflib import SequenceMatcher
>  ... s = SequenceMatcher(None, text, "\t".join(tokens))
>  ... for start, _, length in s.get_matching_blocks():
>  ... if length:
>  ... yield start, start + length
>  ...
>  >>> list(offsets(tokens, text))
>  [(0, 3), (3, 5), (6, 9), (9, 11), (12, 17), (18, 19), (20, 24), (24, 25)]

That's cool, I've never seen that before.  If you pass in str.isspace, 
you can even drop the "if length:" line::

py> def offsets(tokens, text):
... s = SequenceMatcher(str.isspace, text, '\t'.join(tokens))
... for start, _, length in s.get_matching_blocks():
... yield start, start + length
...
py> list(offsets(tokens, text))
[(0, 3), (3, 5), (6, 9), (9, 11), (12, 17), (18, 19), (20, 24), (24, 
25), (25, 25)]

I think I'm going to have to take a closer look at 
difflib.SequenceMatcher; I have to do things similar to this pretty often...

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


Re: aligning a set of word substrings to sentence

2005-12-02 Thread Steven Bethard
Fredrik Lundh wrote:
> Steven Bethard wrote:
> 
> 
I feel like there should be a simpler solution (maybe with the re
module?) but I can't figure one out.  Any suggestions?
>>>
>>>using the finditer pattern I just posted in another thread:
>>>
>>>tokens = ['She', "'s", 'gon', 'na', 'write', 'a', 'book', '?']
>>>text = '''\
>>>She's gonna write
>>>a book?'''
>>>
>>>import re
>>>
>>>tokens.sort() # lexical order
>>>tokens.reverse() # look for longest match first
>>>pattern = "|".join(map(re.escape, tokens))
>>>pattern = re.compile(pattern)
>>>
>>>I get
>>>
>>>print [m.span() for m in pattern.finditer(text)]
>>>[(0, 3), (3, 5), (6, 9), (9, 11), (12, 17), (18, 19), (20, 24), (24, 25)]
>>>
>>>which seems to match your version pretty well.
>>
>>That's what I was looking for.  Thanks!
> 
> 
> except that I misread your problem statement; the RE solution above allows the
> tokens to be specified in arbitrary order.  if they've always ordered, you 
> can re-
> place the code with something like:
> 
> # match tokens plus optional whitespace between each token
> pattern = "\s*".join("(" + re.escape(token) + ")" for token in tokens)
> m = re.match(pattern, text)
> result = (m.span(i+1) for i in range(len(tokens)))
> 
> which is 6-7 times faster than the previous solution, on my machine.

Ahh yes, that's faster for me too.  Thanks again!

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


How do you create a custom QCursor in Python Qt?

2005-12-02 Thread Steegg
I am a newcomer to using Python and Qt and the main problem that I have
is the dearth of any example code or books describing the use of Python
and Qt together.

My current problem is that I want to create a custom cursor, from my
understanding of it I need to create two "QBitmap"s, one of which will
be the mask and then using these to create a "QCursor".
I don't mine whether the "QBitmap"s are hardcoded in the source code or
come from image files, just as long as I can create a new cursor:

I have searched all the available code sources I can find:
www.koders.com
Eric
Veus
Civil
Qomics
for examples of how to create cursors but to no avail. So if amyone can
tell me what I'm doing wrong, it would be much appreciated, here's my
code:


#
# InlineBitmapCursor.py
# environment:  Mac OS X 10.4.2  -  Python 2.4.1  -  Qt 3.3.5
# status:   does not produce any error messages but also does not
change
#   the cursor.
# standalone file

import sys, os
from qt import *

class MainWindow(QMainWindow):

def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.setCaption("Custom Cursor")
self.grid=QGrid(2, self)
self.setCentralWidget(self.grid)

self.grid.setFrameShape(QFrame.StyledPanel)

self.button1=QPushButton("Arrow Cursor", self.grid)

self.button2=QPushButton("Bitmap Cursor", self.grid)

self.arrowCursor = QCursor(Qt.ArrowCursor)
self.setCursor(self.arrowCursor)

self.connect(self.button1, SIGNAL("clicked()"), self.arrow)
self.connect(self.button2, SIGNAL("clicked()"), self.bitmap)

# 8 * 8 bitmap - two random bit maps
#self.bitmap2 = QBitmap(8, 8,
"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a")
self.bitmap2 = QBitmap(8, 8,
"\x89\x55\x55\x55\x0d\x0a\x1a\x0a")
self.bitmap3 = QBitmap(8, 8,
"\x88\x67\x34\xaa\x23\x60\x84\xbb")
print "bitmap2 " + repr(self.bitmap2)
print "bitmap3 " + repr(self.bitmap3)

self.inlineBitmapCursor = QCursor(self.bitmap2, self.bitmap3)
print "before setCursor"
self.setCursor(self.inlineBitmapCursor)
print "after setCursor"



def arrow(self):
self.setCursor(self.arrowCursor)


def bitmap(self):
self.setCursor(self.inlineBitmapCursor)


def main(args):
app=QApplication(args)
win=MainWindow()
win.show()
app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")
)
app.exec_loop()


if __name__=="__main__":
main(sys.argv)




This is what happen when it executes:

[~] steve% "/usr/local/bin/pythonw"
"/Users/steve/PythonDev/qt3.3.5/CursorExamples/InlineBitmapCursor.py"
&& echo Exit status: $? && exit 1
bitmap2 
bitmap3 
before setCursor
after setCursor


thanks,
Steve Greenwood

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


Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Adriano Ferreira
On 12/2/05, Klaus Alexander Seistrup <[EMAIL PROTECTED]> wrote:
> /me is using bash on linux.

I think that was not a bash issue in my case, but a Cygwin/Win32
issue. Windows has some monstruous oddities in order to assure broken
behavior of yesterday is here today in the name of compatibility.
Examples of these everlasting broken behaviors in Windows are looking
at current directory and path no matter what you say. Cygwin isn't
immune to this.

> According to :
>
>   »However, env(1) is not /usr/bin/env but /bin/env at least on
>Unicos 9.0.2, OpenServer 5.0.6 and IIRC on at least one older
>Linux distribution. Free-, Net- and OpenBSD in turn only come
>with /usr/bin/env. So the env-mechanism is increasing conven-
>ience, but not strictly assuring portability.«

That is to the point. Thanks.

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


Re: [[x,f(x)] for x in list that maximizes f(x)] <--newbie help

2005-12-02 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> As while DSU is a very smart way to guard the max compare thing, it is
> still being introduced as a way that is not related to the original
> problem, i.e. I just want to compare f(x)

And that's why in 2.5 you'll just code max(mylist, key=f) to express
this intent exactly -- that's precisely what 'key=' means.


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


Re: Ruby on Rails Job Site -- Is there a Python equivalent?

2005-12-02 Thread Paul Boddie
Adrian Holovaty wrote:
> http://code.djangoproject.com/wiki/DevelopersForHire
>
> See the "Django-powered jobs" section. We could definitely advertise
> this page more, as it's a bit hidden at the moment on the Django wiki.

Don't forget the Python Job Board:

http://www.python.org/Jobs.html

Yes, it's a bit more general than just "Django-powered jobs", but I'm
sure you could persuade the webmaster to link to specific, maintained,
Python-related employment resources.

Paul

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


Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Klaus Alexander Seistrup
Adriano Ferreira wrote:

> So that "#!/usr/bin/env python" is more portable than "#! python" 
> and that's probably why it worked for me with cygwin/bash but not 
> for Klaus on whatever platform he used.

/me is using bash on linux.

> I agree. Only a very strange Unix-like installation would not have
> 'env' at '/usr/bin/env'.

According to :

  »However, env(1) is not /usr/bin/env but /bin/env at least on 
   Unicos 9.0.2, OpenServer 5.0.6 and IIRC on at least one older 
   Linux distribution. Free-, Net- and OpenBSD in turn only come 
   with /usr/bin/env. So the env-mechanism is increasing conven-
   ience, but not strictly assuring portability.«

Cheers,

-- 
Klaus Alexander Seistrup
PNX · http://pnx.dk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Adriano Ferreira
On 12/2/05, Carsten Haese <[EMAIL PROTECTED]> wrote:
> (3) assumes that whatever shell the user is running looks up the shebang
> executable in the path, which bash, just to name one example, does not
> do.

I think that was the answer I was looking for. So that "#!/usr/bin/env
python" is more portable than "#! python" and that's probably why it
worked for me with cygwin/bash but not for Klaus on whatever platform
he used.

> (2) and (1) require that you know where env and python live,
> respectively, that's true, but env is likely to be found in an
> OS-dependent standard location than python, so (2) is preferable.

I agree. Only a very strange Unix-like installation would not have
'env' at '/usr/bin/env'.

Many thanks to Klaus and Carsten for helping me find out why this
convention is helpful/useful.

Best regards,
Adriano
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: an intriguing wifi http server mystery...please help

2005-12-02 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> Could the above server-speed assymetry that i spoke of above be caused
> by this reverse dns lookup?

I think so. You stated that you use "a fairly simple HTTP server",
although that's not exactly specific enough to diagnose the problem,
but if that were the standard library's BaseHTTPServer then reverse DNS
lookups could well be an issue: that particular server attempts to log
addresses, and in the address_string method there's a call to
socket.getfqdn which could invoke such reverse lookups.

Paul

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


Re: (newbie) N-uples from list of lists

2005-12-02 Thread bonono

Martin Miller wrote:
> I'd be interested in seeing the one liner using reduce you mentioned --
> how it might be done that way isn't obvious to me.
>
> Another aspect of Taschuk's solution I like and think is important is
> the fact that it is truly iterative in the sense that calling it
> returns a generator which will yield each of the combinations, one at
> time.  All the others create and return all the combinations at once
> (as I suspect the one liner using reduce you mention does, too).
>
> As you point out, "best" is always in the eyes of the beholder.
>
> "Best" regards, ;-)

def combine_lol(seq): return reduce(lambda x,y: (a+(b,) for a in x for
b in y), seq, [()])

I use generator expression but being a reduce, it will still goes all
the way till the last sequence before you can have any output. That is
the nature of the problem anyway. You can use scanl equivalent to have
intermediate result if the problem allows but I don't that is true in
this case.

The python community is quite against this kind of thing and treat
map/filter/reduce as plague, it is described as ugly/messy :-)

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


Re: Eclipse best/good or bad IDE for Python?

2005-12-02 Thread Fabio Zadrozny
Hi Chris,

I think that you should try it yourself... being the *best ide*  is 
usually a subjective matter, so, you should decide yourself if it is the 
best IDE for the task you want it to.

I must also warn you that I'm its current maintainer, and it is *my* 
favorite IDE :-)

Also, I use it for large projects (2569 .py files on my python 
installation and about 1800 .py files in my project), and, altough I 
agree with the general idea that you need a fast computer to use it at 
optimal performance, I found that using an athlon 1600+ with 512mb RAM 
was enough for me when using eclipse with pydev (also, the features 
provided by eclipse are more than worth the loss of speed when editing 
some things when compared to editors such as vi or emacs, altough the 
learning curve for that might not be so light, in the long run, I'm 
pretty sure that it is worth it -- altough I really miss a faster 
machine for compiling c++).

But in the end, as I said, it is a subjective matter, so, you'll have to 
decide it for yourself.

Cheers,

Fabio

[EMAIL PROTECTED] wrote:

>I'm trying to move beyond Emacs/Vim/Kate
>and was wondering if Eclipse is better and if it is the *best*
>IDE for Python.
>
>Should I leave Emacs and do Python coding in Eclipse?
>
>Chris
>
>  
>


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


Setting PYTHONPATH from Makefile

2005-12-02 Thread [EMAIL PROTECTED]
I have a Makefile target that uses a python script, like:

%.abc: %.def
python myscript.py

The problem is that myscript.py and some modules that myscript.py
imports are not in the current directory, but in another place in the
filesystem, say, /path/to/stuff. If this was a tcsh script, I would
just do:

   setenv PYTHONPATH /path/to/stuff
   python myscript.py

but this cannot be done from a Makefile. So what do I do? Is there
another way to set the PYTHONPATH? Like giving an option to "python"
itself? Or?

/David

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


Re: Why my modification of source file doesn't take effect when debugging?

2005-12-02 Thread Jeremy Jones
sandorf wrote:

>I'm using the Windows version of Python and IDLE. When I debug my .py
>file, my modification to the .py file does not seem to take effect
>unless I restart IDLE. Saving the file and re-importing it doesn't help
>
>either. Where's the problem? 
>
>Thanks.
>
>  
>
No problem.  Just reload() it.


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


Re: Eclipse best/good or bad IDE for Python?

2005-12-02 Thread Jean-François Doyon
I'm a big fan of Eclipse and reocmmend it to anyone who asks :)

No one can say any one is the *best*, since it's a matter of taste,
but it's pretty darn good.

The main benefit IMO is it's felibility ... Eclipse is a *framework*, 
that can handle lots things quite well, like HTML (If you're coding 
python for the web), C/C++ (If you're building extensions), XML if 
you're using that, and so on ... All from within one application, all 
with common paradigms.

The handling of RCS' is also common ...

I use Eclipse + PyDev + Subclipse everyday!

Of course I never could get into Emacs ... It's incredibly powerful too 
though ... Why move away from it?  Is it missing something you need?

+1 on eclipse from me!

J.F.

[EMAIL PROTECTED] wrote:
> I'm trying to move beyond Emacs/Vim/Kate
> and was wondering if Eclipse is better and if it is the *best*
> IDE for Python.
> 
> Should I leave Emacs and do Python coding in Eclipse?
> 
> Chris
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Carsten Haese
On Fri, 2005-12-02 at 09:12, Adriano Ferreira wrote:
> On 12/2/05, Klaus Alexander Seistrup <[EMAIL PROTECTED]> wrote:
> > #v+
> >
> > $ ls -l /tmp/hello.py
> > -rwxr-xr-x  1 klaus klaus 38 2005-12-02 14:59 /tmp/hello.py
> > $ cat /tmp/hello.py
> > #! python
> > print 'Hello, world!'
> > # eof
> > $ /tmp/hello.py
> > bash: /tmp/hello.py: python: bad interpreter: No such file or directory
> > $
> >
> > #v-
> 
> Hey, that's not fair. In your illustration above, does 'python' can be
> found in the PATH? That is,
> 
> $ python /tmp/hello.py
> 
> works? If it does, probably
> 
> #!/usr/bin/python
> #!/usr/bin/env python
> #!python
> 
> would also work if
> (1) 'python' is at '/usr/bin/python' (but that's inflexible)
> (2) 'python' can be found in the environment variable path (if 'env'
> is at '/usr/bin/env')
> (3) 'python' can be found in the environment variable path (no need
> for 'env' utility)

(3) assumes that whatever shell the user is running looks up the shebang
executable in the path, which bash, just to name one example, does not
do.

(2) and (1) require that you know where env and python live,
respectively, that's true, but env is likely to be found in an
OS-dependent standard location than python, so (2) is preferable.

HTH,

Carsten.


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


Re: Instances behaviour

2005-12-02 Thread Mr.Rech
I see your point. Looking again at my metaclass implementation and
comparing it with your abstract class + inheritance approach it turns
out that the latter is definetively more straightforward, easier to
maintain and all in all more pythonic.

Sorry, but being an OOP newbie put me in the position of
overcomplexifing(tm) things a little bit. I'll be back soon with other
(I hope less silly) questions. ;-p

Thanks for all your suggestions,
 Andrea

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


Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Klaus Alexander Seistrup
Adriano Ferreira skrev:

>> #v+
>>
>> $ ls -l /tmp/hello.py
>> -rwxr-xr-x  1 klaus klaus 38 2005-12-02 14:59 /tmp/hello.py
>> $ cat /tmp/hello.py
>> #! python
>> print 'Hello, world!'
>> # eof
>> $ /tmp/hello.py
>> bash: /tmp/hello.py: python: bad interpreter: No such file or directory
>> $
>>
>> #v-
>
> Hey, that's not fair. In your illustration above, does 'python' can be
> found in the PATH? That is,
>
> $ python /tmp/hello.py
>
> works? If it does, probably
>
> #!/usr/bin/python
> #!/usr/bin/env python
> #!python
>
> would also work if
> (1) 'python' is at '/usr/bin/python' (but that's inflexible)
> (2) 'python' can be found in the environment variable path (if 'env'
> is at '/usr/bin/env')
> (3) 'python' can be found in the environment variable path (no need
> for 'env' utility)

Sure, I wasn't fair.  But look here:

#v+

$ python /tmp/hello.py
Hello, world!
$ which python
/usr/bin/python
$ 

#v-

I do not know the syntax of the shebang-line, but perhaps an absolute 
path is required?

PS: The "Mail-Copies-To: nobody" header line means that I do not wish 
to receive mail replies - please follow-up to group only.

Cheers,

-- 
Klaus Alexander Seistrup
Copenhagen, Denmark
http://streetkids.dk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Why my modification of source file doesn't take effect when debugging?

2005-12-02 Thread sandorf
I'm using the Windows version of Python and IDLE. When I debug my .py
file, my modification to the .py file does not seem to take effect
unless I restart IDLE. Saving the file and re-importing it doesn't help

either. Where's the problem? 

Thanks.

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


Re: XML and namespaces

2005-12-02 Thread uche . ogbuji
Quoting Andrew Kuchling:
"""
> >>> element = document.createElementNS("DAV:", "href")

This call is incorrect; the signature is createElementNS(namespaceURI,
qualifiedName).
"""

Not at all, Andrew.  "href" is a valid qname, as is "foo:href".  The
prefix is optional in a QName.  Here is the correct behavior, taken
from a non-broken DOM library (4Suite's Domlette)

>>> from Ft.Xml import Domlette
>>> document = Domlette.implementation.createDocument(None, None, None)
>>> element = document.createElementNS("DAV:", "href")
>>> document.appendChild(element)

>>> Domlette.Print(document)

>>>

"""
If you call .createElementNS('whatever', 'DAV:href'),
the output is the expected:

"""

Oh, no.  That is not at all expected.  The output should be:



"""
It doesn't look like there's any code in minidom that will
automatically create an 'xmlns:DAV="whatever"' attribute for you.  Is
this automatic creation an expected behaviour?
"""

Of course.  Minidom implements level 2 (thus the "NS" at the end of the
method name), which means that its APIs should all be namespace aware.
The bug is that writexml() and thus toxml() are not so.

"""
(I assume not.  Section 1.3.3 of the DOM Level 3 says "Similarly,
creating a node with a namespace prefix and namespace URI, or changing
the namespace prefix of a node, does not result in any addition,
removal, or modification of any special attributes for declaring the
appropriate XML namespaces."  So the DOM can create XML documents that
aren't well-formed w.r.t. namespaces, I think.)
"""

Oh no.  That only means that namespace declaration attributes are not
created in the DOM data structure.  However, output has to fix up
namespaces in .namespaceURI properties as well as directly asserted
"xmlns" attributes.  It would be silly for DOM to produce malformed
XML+XMLNS, and of course it is not meant to.  The minidom behavior
needs fixing, badly.

--
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

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


Re: why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Fredrik Lundh
Adriano Ferreira wrote:

> Many Python scripts I see start with the shebang line
>
> #!/usr/bin/env python
>
> What is the difference from using just
>
> #!python

$ more test.py
#!python
print "hello"
$ chmod +x test.py
$ ./test.py
-bash: ./test.py: python: bad interpreter: No such file or directory

 



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


Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Adriano Ferreira
On 12/2/05, Klaus Alexander Seistrup <[EMAIL PROTECTED]> wrote:
> #v+
>
> $ ls -l /tmp/hello.py
> -rwxr-xr-x  1 klaus klaus 38 2005-12-02 14:59 /tmp/hello.py
> $ cat /tmp/hello.py
> #! python
> print 'Hello, world!'
> # eof
> $ /tmp/hello.py
> bash: /tmp/hello.py: python: bad interpreter: No such file or directory
> $
>
> #v-

Hey, that's not fair. In your illustration above, does 'python' can be
found in the PATH? That is,

$ python /tmp/hello.py

works? If it does, probably

#!/usr/bin/python
#!/usr/bin/env python
#!python

would also work if
(1) 'python' is at '/usr/bin/python' (but that's inflexible)
(2) 'python' can be found in the environment variable path (if 'env'
is at '/usr/bin/env')
(3) 'python' can be found in the environment variable path (no need
for 'env' utility)

Cheers,
Adriano.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Ordered Dictionery to Criticise

2005-12-02 Thread Fuzzyman
Hello Bengt,

Bengt Richter wrote:
> On 1 Dec 2005 03:38:37 -0800, "Fuzzyman" <[EMAIL PROTECTED]> wrote:
>
> >
> >Fuzzyman wrote:
> >> Sorry for this hurried message - I've done a new implementation of out
> >> ordered dict. This comes out of the discussion on this newsgroup (see
> >> blog entry for link to archive of discussion).
> >>
> >> See the latest blog entry to get at it :
> >> http://www.voidspace.org.uk/python/weblog/index.shtml
> >>
> >
> >Hello all,
> >
> >I've just done a new "beta 2" version. It has a full version of
> >FancyODict with the custome "callable sequence objects" for keys,
> >values and items. They are almost completely covered by tests.
> >
> >You can download the new(er) version from :
> >http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=odictbeta2.py
> >
> Ran my tests on it: this one may be of interest:
>  __ entrypoint: test_popitem 
> ___
>
>  def test_popitem():
>  d = CandidateDict([(k,i*100) for i,k in enumerate('abcde')])
>  >   assert d.popitem() == ('e', 400)
>
>  [C:\pywk\ut\test\test_odicts.py:228]
>  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ _
>  ...
>  ...
>  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ _
>
>  def __getattr__(self, name):
>  """
>  Implemented so that access to ``sequence`` raises a warning.
>
>  >>> d = OrderedDict()
>  >>> d.sequence
>  []
>  """
>  if name == 'sequence':
>  warn('use of sequence attribute is deprecated. Use keys method '
>  'instead.', DeprecationWarning)
>  # NOTE: Still (currently) returns a direct reference. Need to
>  #   because code that uses sequence will expect to be able to
>  #   mutate it in place.
>  return self._sequence
>  else:
>  # NOTE: strictly unnecessary, but it raises the appropriate error
>  >   getattr(self, name)
>
>  [c:\pywk\clp\odictbeta2.py:309]
>  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ _
>  Recursion detected (same locals & position)
>  
> !!!
>  = tests finished: 19 passed, 9 failed in 1.57 seconds 
> =
>

Yep the line :

getattr(self, name)

is a bug.

I've replaced it now (not yet "published") with
object.__getattr__(self, name)
It could equally just be replaced with a raise AttributeError

You've picked up on another typo in the code, whichis odd because
``popitem`` is tested.

Oh well - works now.

[snip..]
> >You can currently alter the order (of keys, values *and* items) by
> >passing an iterable into those methods.
> I'm playing this game, but I wonder how much of it really makes sense ;-)
>

Can you explain what you mean ?


> >
> >Someone has suggested that this "smells bad" - and it ought to be
> >done through separate `setkeys``, ``setvalues``, and ``setitems``
> >methods.
> >
> >I'm *inclined* to agree, but I don't feel strongly about it. Anyone
> >else got any opinions ?
> I don't see a big difference. What's important, if you ask me, is
> whether you get an idea of what will happen when you pass the iterable as
> an argument. OTTOMH that suggests that keys/values/items[slice] = iterable
> have more expectation-generating precedent, and in fact perhaps should define
> what is to happen if no other constraints are violated.

Don't completely follow.

Are you saying that

d = OrderedDict(some_iterable)
d.keys[slice] = iterable

is more *understandable*  ("expectation-generating precedent" WTF) ?

The alternative being : d.keys(iterable)

In which case I'm inclined to agree. *However* - having custom objects
for items/keys/values is undoubtably less efficient.

Therefore I'm supplying two classes OrderedDict and FancyODict (name
not yet fixed).

OrderedDict needs a way of changing the keys - so it needs either

d.keys(iterable)

*or*

d.setkeys(iterable)

Which is preferable, is my question.

I think you're saying you don't care :-)
In which case I will leave it as it presently is.

> >
> >* ``repr`` ought to return a value that ``eval`` could use to turn back
> >into an OrderedDict.
> >
> >I have actually done an implementation of this, but it would mean
> >that *all* the doctests need to be changed. I *will* do this at some
> >point.
> Point in favor of py.test's separation of test/tested I guess.
>

Probably. :-)

doctest is part of the standard library - which is a point in it's
favour.


> >
> >* Slice assignment.
> >
> >The semantics for slice assignment are fiddly.
> >
> >For example, what do you do if in a slice assignment a key collides
> >with an existing key ?
> IMO, a slice defines the sliced-out as well as the untouched, and I think
> it is an error to collide with the unouched part, since it requires eit

Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Klaus Alexander Seistrup
Adriano Ferreira wrote:

> Many Python scripts I see start with the shebang line
>
> #!/usr/bin/env python
>
> What is the difference from using just
>
> #!python

#v+

$ ls -l /tmp/hello.py
-rwxr-xr-x  1 klaus klaus 38 2005-12-02 14:59 /tmp/hello.py
$ cat /tmp/hello.py
#! python
print 'Hello, world!'
# eof
$ /tmp/hello.py
bash: /tmp/hello.py: python: bad interpreter: No such file or directory
$ 

#v-

Cheers,

-- 
Klaus Alexander Seistrup
Copenhagen, Denmark
http://streetkids.dk/
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >