Re: is parameter an iterable?

2005-11-17 Thread Steven D'Aprano
Ah, found the right solution! Thanks to Fredrik Lundh 
for so gently pointing me at this post. Just one 
question, if I may:-

Alex Martelli wrote:

> It's not hard...:
> 
> try:
> _it = iter(whatever)
> except TypeError:
> print 'non-iterable'
> else:
> for i in _it: # etc, etc


Alas and alack, I have to write code which is backwards 
compatible with older versions of Python:

Python 2.1.1 (#1, Aug 25 2001, 04:19:08)
[GCC 3.0.1] on sunos5
Type "copyright", "credits" or "license" for more 
information.
 >>> iter
Traceback (most recent call last):
   File "", line 1, in ?
NameError: name 'iter' is not defined

What should I do when I can't rely on functions that 
don't exist in older versions of Python?


-- 
Steven.

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


Re: How to write an API for a Python application?

2005-11-17 Thread Eric Brunel
On Wed, 16 Nov 2005 15:43:33 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote:

> "Eric Brunel" <[EMAIL PROTECTED]> writes:
>> On 16 Nov 2005 06:18:05 -0800, Paul Boddie <[EMAIL PROTECTED]> wrote:
>>> One technology that I used many years ago with Python, and which should
>>> still do the job is CORBA - at that time ILU, but I suppose the various
>>> other ORBs should also be as capable; certainly, ILU permitted
>>> callbacks from the server into the client. These days, you might want
>>> to look at omniORB, Fnorb and ORBit.
>> I never saw any way to create callbacks from server to client with CORBA. 
>> How would you describe such a callback in the IDL file?
>
> It's OO, not functional. You pass an object to the server, and the
> server invokes methods on that object. In the IDL, you use the
> interface name as a type. I.e.:
>
>   interface Window {
>   ...
>   }
>  and in another interface:
>   WindowList  FindWindows(in Window name) ;

This is slowly drifting OT, but aren't the interfaces in the IDL implemented on 
the server, and not on the client? So passing an "interface instance" to a 
method will just make the server call itself, won't it? Or you have to turn 
your client into a server, which makes things a lot more complicated.

> And, FWIW, Fnorb hasn't been maintained for a while. It requires
> patching to run on recent versions of Python.

Back on-topic: it seems to run fine with Python 2.1. I don't know about later 
versions.
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in 
'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating (rather) generic plugin framework?

2005-11-17 Thread Edvard Majakari
Jean-Paul Calderone <[EMAIL PROTECTED]> writes:

> You may want to look at a few existing Python plugin systems.  To get you
> started, here's a link to the Twisted plugin system documentation:
> 

Thanks both to Bruno and Jean-Paul! I think I'll go the twisted way (I try to
avoid re-inventing the wheel here)

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!

"Debugging is twice as hard as writing the code in the firstplace. Therefore,
 if you write the code as cleverly as possible, you are, by definition,
 not smart enough to debug it."  -- Brian W. Kernighan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is parameter an iterable?

2005-11-17 Thread Steven D'Aprano
Roy Smith wrote:

> Now you're assuming that the message is a constant for all TypeErrors
> caused by attempting to iterate over a non-iterable object.

Yes I am, and of course you are correct that that could 
change and so shouldn't be relied on.

Seems that my crappy solution is not quite as 
future-proof as I thought it was. Since a better 
solution does exist, I agree it should be used in 
preference to my crappy one, assuming you are running a 
recent enough version of Python.


-- 
Steven.

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


Re: Python obfuscation

2005-11-17 Thread Steven D'Aprano
The Eternal Squire wrote:

> Plenty of case law exists behind judgements made to repair loss of
> sales opportunites... these are called infringement upon sales
> territories..

Is that supposed to impress me? There are plenty of 
lousy laws on the books being enforced.

Oh yeah, that's right, they are the Authorities, and 
the Authorities can do no wrong.



-- 
Steven.

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


newbie question: 'import site' failed; use -v for traceback

2005-11-17 Thread Tony Gill



Hi,
 
I've just downloaded 
and installed Python 2.4.2 for Windows and am having troubling getting 
started.
 
My system is: MS 
Windows XP Pro SP2
 
When I run 'python 
(command line)' from the start menu the first line in the CMD window 
is:
'import site' 
failed; use -v for traceback
 
This seems to be 
causing other problems; for example: when I type 'import os' at the prompt I get the 
error:
 
Traceback (most 
recent call last):  File "", line 1, in ?ImportError: 
No module named os
 
Also I cannot run 
the IDLE (Python GUI) from the start menu either. Nothing loads. I presume my 
problems all come back to the fact that import site fails when python 
starts.
 
Any help getting me 
started greatly appreciated.
 
Thanks
 
Tony
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: newbie - How do I import automatically?

2005-11-17 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
> I also checked in command prompt, and there it works!, but not in IDLE.
> And it's in IDLE that I work all the time. Can anything be done to get
> it to work there?

According to command line help
   (run C:\Python24\Lib\idlelib>idle.py -h )
"idle -s" is what you're looking for.

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


Re: python-dev summary

2005-11-17 Thread Tony Meyer
On 17/11/2005, at 7:20 PM, Titus Brown wrote:

>> [The HTML version of this Summary is available at
>> http://www.python.org/dev/summary/2005-09-01_2005-09-15.html]
>
> no... no, it's not ;)

Sorry; I should amend the copy that's posted to say "will be  
available".  The summaries get posted here, to python-announce, and  
sent to Brett to be put online.  The one here appears immediately,  
the python-announce one appears whenever a moderator has time to  
approve it, and the one online appears when Brett has time to put it up.

=Tony.Meyer

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


Re: pySonic - writing a sample to a file

2005-11-17 Thread Serge Orlov

netspeed.com.au wrote:
> Hi all:
>
> Hopefully a simple question. I have been putting together an application
> using pySonic. I find the documentaion fine with plenty of examples but I
> cant see how to save a sample (or any recorded audio) to a file.
>
> Am I missing something obvious?

Python comes with read/write support for several audio file formats:
http://docs.python.org/lib/mmedia.html
perhaps you can get raw stream from pySonic and save it using python
stdlib module?

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


Re: Addressing the last element of a list

2005-11-17 Thread Duncan Booth
Mike Meyer wrote:

> Wouldn't one.__dict__ = dict(**two.__dict__) be a bit better?
> 

Those stars are redundant here. It would be cleaner to write:

   one.__dict__ = dict(two.__dict__)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to discover this process's current memory usage, cross-platform?

2005-11-17 Thread Serge Orlov

Jack Diederich wrote:
> Electric Fence[1] uses the LD_PRELOAD method.  I've successfully used it to
> track down leaks in a python C extension.  If you look at the setup.py in
> probstat[2] you'll see
>   #libraries = ["efence"] # uncomment to use ElectricFence
> which is a holdover from developing.

I've also successfully used Electric Fence many years ago to track down
leaks in a C/Linux program. Since that time Electric Fence has been
forked into DUMA project http://duma.sourceforge.net/ and was ported to
windows, perhaps it has become cross-platform? I've never tried it on
anything besides Linux.

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


Re: PyExcelerator - mishandling of formulas?

2005-11-17 Thread Serge Orlov
Marco Aschwanden wrote:
> Hi,
>
> Yesterday I placed a bug report on PyExcelerators-Sourceforge-page... but
> I am not so sure anymore, whether this is really a bug - I could imagine
> that I missed something, but I don't see what. Please confirm that my bug
> is due to mishandling and I will gladly retreat my bug report.
>
> In a formula, I would like to point to a field on another worksheet.
> pyExcelerator chokes on these references!
>
> 
>
> import pyExcelerator
>
> wb = pyExcelerator.Workbook()
> ws_summary = wb.add_sheet('Summary')
> ws_data = wb.add_sheet('Data')
>
> ws_summary.write(0,0, pyExcelerator.Formula('Data:A1')) <--- Here it
> chokes!
> ws_data.write(0, 0, '4000')
>
> wb.save('not_parsing.xls')
>
> 
>
> Is this a bug or am I doing something wrong?

I think you're doing it wrong. ":" character means range, to refer to a
sheet use "!" charater: Data!A1

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


Python Library Reference - question

2005-11-17 Thread bobueland
The "Python LIbrary Reference" at
http://docs.python.org/lib/contents.html seems to be an important
document. I have two questions

Q1. How do you search inside "Python LibraryReference" ? Does it exist
in pdf or chm form?

Q2. In some other languages (for instance PHP if I recall correctly)
readers can add comments and give examples to the various headings in
the reference manual. This gives valuable information to the reader. Is
there such a version of "Python Library Reference", and if not would it
be a good idea to have such a version.

Thanks
Bob Ueland

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


IDLE question

2005-11-17 Thread bobueland
IDLE doesn't seem to honor PYTHONSTARTUP environment variable nor
sitecustomize.py

How do you then customize in IDLE?

(basically I want to execute the statement
   from btools import *
each time I restart IDLEs Python Shell)

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


Re: Addressing the last element of a list

2005-11-17 Thread Antoon Pardon
Op 2005-11-16, Mike Meyer schreef <[EMAIL PROTECTED]>:
> Antoon Pardon <[EMAIL PROTECTED]> writes:
>> Op 2005-11-15, Mike Meyer schreef <[EMAIL PROTECTED]>:
>>> Antoon Pardon <[EMAIL PROTECTED]> writes:
>> Like having an assignment operator (let use @= for it) next to a
>> (re)bind operator.
>> We could then have something like the following.
>> a = 5
>> b = a
>> a @= 7
>> b ==> would result in 7.
> You've just overwritten the object referred to by the token "5" in the
> source code with the value 7, so you get:
> print 5
> 7
 You have a valid point, but I think a different approach is possible.
 Don't make the distinction between mutable and immutable types but
 between mutable and immutable objects. So an int wouldn't be an
 immutable type, but 5 would be an immutable object.
 So the code above I gave would throw an exception, but the following
 might work.
 a @= 5
 b = a
 b @= 7
 a ==> would result in 7.
>>>
>>> Which solves that issue but brings up - well, more issues. What
>>> happens if the third line is 'b @= "seven"'? Does this require an
>>> extra level of indirection in the implementation? Avoiding that kind
>>> of thing was the reason for suggesting this:
>>
>> It depends on how far you want to go.
>>
>> I think one can argue that in case of an inplace replacement, this
>> only makes sense if the two objects belong to the same class. So
>> no extra level of indirection is then required.
>
> Now factor in inheritance. Do users of this facility have to worry
> about static OO typing? That is, two objects that are otherwise
> completely interchangeable will raise an exception if you try to
> assign one to a variable holding the other, because they have the
> wrong type. That seems unpythonic.

I don't care much about pythonic or not. It seems a very volatile
concept, that adapts as the language evolves. I wouldn't be
surprised if augmented arithmetic operations would have been
considered unpythonic at some point. You could see this
limitation as a wart, but IMO the idea would still be usefull
with that limitation.

The limitation would ensure for example that although the value
of an argument could change, it's class couldn't. I think that
is worthwhile.

>> Otherwise it really depends on how the builtin objects are implemented.
>> For user classes, a somewhat simplistic implementation could be
>> something like:
>>
>>   def '@=' (one, two):
>> one.__dict__.clear()
>> one.__dict__.update(two.__dict__)
>
> Wouldn't one.__dict__ = dict(**two.__dict__) be a bit better?
>
> Anyway, this won't' work if the class of one of the objects has
> slots.

So? I wrote it was a simplistic idea. but things like setattr and
getattr, still work with objects that have slots. So which attributes
are present for a particulare object has to be available in the
python interpreter. So my guess is that slots wont be the big stumbling
block, should one consider implementing something like this.

>>> The critical thing is that this doesn't introduce any new facilities
>>> into the language, just some new syntax, so there's no implementation
>>> impact. In fact, if you're willing to put up with some notational
>>> abuse, we can do this now:
>>>
>>> class Ref(object):
>>> _unbound = object()
>>> def __new__(cls, value = _unbound):
>>> """We're an object, but need to ignore the optional argument."""
>>>
>>> return object.__new__(cls)
>>>
>>> def __init__(self, value = _unbound):
>>> """Bind the  optional value, if provided."""
>>> if value is not self._unbound:
>>> self._value = value
>>>
>>> def __pos__(self):
>>> """Return value, if bound."""
>>> try:
>>> return self._value
>>> except AttributeError:
>>> raise ValueError, "%s object does not have a value stored." % \
>>>   self.__class__.__name__
>>>
>>> def __iadd__(self, value):
>>> self._value = value
>>> return self
>>>
>>> Usage:
>>>
>> x = Ref.Ref()
>> x += 23
>> +x
>>> 23
>> a = x
>> x += 25
>> +a
>>> 25
>> a += "this is a test"
>> +x
>>> 'this is a test'
>>>
>>> Since it doesn't have real lannguage support, things like +x += 25
>>> don't work. That's the only obvious gotcha. Maybe ~ would be a better
>>> prefix.
>>
>> I'm a bit puzzled on how you would implement this as real language
>> support. As far as I understand this only works with Ref objects.
>
> Correct. That's the point.
>
>> You can't do something like the following.
>>
>> l = [3, 7]
>> a = Ref(l[0])
>>
>> Instead you would have to do something like
>> l = [Ref(3), Ref(7)]
>> a = l[0]
>>
>> So it seems that if you want to use this idea for implementing langauge
>> support you will have to wrap all objects in a Ref internally and this
>> seems some kind of extra indirection too.
>
> No, the idea is to expose this class to the user. They would h

Re: newbie - How do I import automatically?

2005-11-17 Thread Claudio Grondi
Thanks to "Serge Orlov" for the hint:
   "run C:\Python24\Lib\idlelib>idle.py -h"

Following works for me now
if I start IDLE by following console command:

C:\Python24\pythonw.exe C:\Python24\Lib\idlelib\idle.py -c "import os;from
path import path"

The IDLE console prompt appears in the second line
(so -c "import os;from path import path"
probably fakes execution of an input line)
and os and path modules are available for usage.

To be honest I don't like this solution and the solution with setting any
environment variable.
I would be much more happy to understand how I can modify PyShell.py or
another script file IDLE uses in order to achieve same effect.

Claudio

<[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> When I start Python Shell I can see that some names or loaded
> automatically, ready for me to use
>
> >>> dir()
> ['__builtins__', '__doc__', '__name__']
>
> I have written some functions in a file called btools.py. I would like
> to import them automatically when I start up Python shell. Today I must
> do it by hand like this
>
> >>> from btools import *
> >>> dir()
> ['__builtins__', '__doc__', '__name__', 'func1', 'func2', 'func3']
> >>>
>
> Is there a way to do this automatically so that I always have 'func1',
> 'func2' and so on available, without me having to do it by hand?
>
> Bob
>



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


Re: newbie - How do I import automatically?

2005-11-17 Thread bobueland
I tried to do it on my computer (win XP). I put an extra line in
PyShell.py

#! /usr/bin/env python

import os
import os.path
import sys
import string
import getopt
import re
import socket
import time
import threading
import traceback
import types
import exceptions

# test
sys.modules['__main__'].__dict__['os'] = os

import linecache

Then when I start idle I get

IDLE 1.1.1
>>> dir()
['__builtins__', '__doc__', '__name__']
>>>

So I don't see 'os'

Do you see 'os' on your computer. If yes, what could be the difference?

Bob

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


Re: Python obfuscation

2005-11-17 Thread Ben Sizer
Mike Meyer wrote:
> > Are you claiming therefore that it's more acceptable to you to have to
> > access the data remotely every time you use the software than once per
> > install?
>
> Alex's solution doesn't require special treatment for disaster
> recovery and/or planning, and as such is a valid answer to the
> question. It may be unacceptable for *other* reasons, but it beats
> dictating a disaster recovery plan for your software to the end user
> hands down on that basis.

Sorry, I just don't see this as being a significant difference that
makes 'access-always' acceptable and 'access rarely' unacceptable.

> > No, I am just pointing out that you are mixing up the concept of an
> > actual 'right' such as one embodied in a state's constitution, with an
> > implied 'right' that is just an exemption from committing an offence.
> > The term 'right' does not even appear in the relevant part of US
> > copyright law, except to state that it is a limitation on the copyright
> > holder's rights.
>
> You're still just playing semantic games. The common usage is "fair
> use rights." If you mean "... without infringing on the end users
> rights, except for fair use rights", then you should say that.

Call it what you like; still, I cannot be infringing on your right when
such a right does not exist to be infringed. If you want to term it a
'right', feel free, but that's not what you're granted under US law or
the Berne Convention. The 'common usage' here leads to a
misinterpretation of what you're entitled to. What is actually stated
is a limitation on the copyright holder's exclusive rights, which is a
very different matter.

-- 
Ben Sizer

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


Re: is parameter an iterable?

2005-11-17 Thread Duncan Booth
Steven D'Aprano wrote:

> What should I do when I can't rely on functions that 
> don't exist in older versions of Python?
> 
Ideally:

if 'iter' not in dir(__builtins__):
import sys
sys.exit('Archaic Python not supported, please upgrade')


Alternatively fill in the blanks with appropriate fallback code:

if 'iter' not in dir(__builtins__):
def iter(obj):
   ... remainder of definition left as an exercise ...
 __builtins__.iter = iter

where iter does roughly what the iter builtin does.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE question

2005-11-17 Thread Claudio Grondi

<[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> IDLE doesn't seem to honor PYTHONSTARTUP environment variable nor
> sitecustomize.py
>
> How do you then customize in IDLE?
>
> (basically I want to execute the statement
>from btools import *
> each time I restart IDLEs Python Shell)
>
Following works for me:

C:\Python24\pythonw.exe E:\Python24\Lib\idlelib\idle.py -r
E:\Python24\sitecustomize.py

or

C:\Python24\pythonw.exe   E:\Python24\Lib\idlelib\idle.py -c "import os;
from path import path"

content of my sitecustomize.py is:
"
import os
from path import path
"

and both ways of invoking IDLE have the same effect (apparently of faking
execution of not shown input line) of making the modules  os  and the class
path  available at start of IDLE.

My question in this context:
  Can the PyShell.py file in C:\Python24\Lib\idlelib directory be edited
somehow to achieve same effect?

Claudio


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


Re: GTK for windows and Linux

2005-11-17 Thread Renato
You'll need to install the libglade/gtk/pygtk packages from:

http://www.pcpm.ucl.ac.be/~gustin/win32_ports/

When your app is complete you can package it with py2exe

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


Re: newbie - How do I import automatically?

2005-11-17 Thread Claudio Grondi
"Mikael Olofsson" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> [EMAIL PROTECTED] wrote:
> > I tried to put the line
> > from btools import *
> > in several places in PyShell.py
> > but to now avail. It does not work, IDLE does not execute it???
>
> IDLE definitely executes PyShell.py upon startup, since IDLE does not
> even appear on the screen if there is an error in that file. The
> following seems to work for me, in PyShell.py. After importing both sys
> and os,
>
> sys.modules['__main__'].__dict__['os'] = os
>
> Then, if I start IDLE, the module os is directly available.
>
> HTH
> /MiO


I have put
sys.modules['__main__'].__dict__['os'] = os
at the beginning of PyShell.py :
"
#! /usr/bin/env python

import os
import os.path
import sys

sys.modules['__main__'].__dict__['os'] = os
"

and also here:
"
class ModifiedInterpreter(InteractiveInterpreter):

def __init__(self, tkconsole):
self.tkconsole = tkconsole

sys.modules['__main__'].__dict__['os'] = os
locals = sys.modules['__main__'].__dict__
"

but it does not work ... (why ???)

What happens if you remove the line
sys.modules['__main__'].__dict__['os'] = os
from your PyShell.py?
Will  os  be no more available or is it still there?

Claudio



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


Re: newbie - How do I import automatically?

2005-11-17 Thread Mikael Olofsson
[EMAIL PROTECTED] wrote:
> I tried to do it on my computer (win XP). I put an extra line in
> PyShell.py
> [snip]
> # test
> sys.modules['__main__'].__dict__['os'] = os
> [snip]
> Then when I start idle I get
> 
> IDLE 1.1.1
> 
dir()
> 
> ['__builtins__', '__doc__', '__name__']
> 
> 
> So I don't see 'os'
> 
> Do you see 'os' on your computer. If yes, what could be the difference?

Yes, I do. The following is with IDLE 1.0.3 and Python 2.3.4 on WinXP.

Without the line in PyShell.py:

 IDLE 1.0.3   No Subprocess 
 >>> dir()
 ['__builtins__', '__doc__', '__file__', '__name__', 'main']

With the line in PyShell.py:

 IDLE 1.0.3   No Subprocess 
 >>> dir()
 ['__builtins__', '__doc__', '__file__', '__name__', 'main', 'os']
 >>> os
 

I know nothing about the details of how IDLE work. All I know is what I 
have reported here. I was simply inspired by the following remark from 
Claudio Grondi up-thread:

 > edit the first lines of %SystemDrive%\Python24\Lib\idlelib\PyShell.py

I guess that PyShell.py is imported as a module by IDLE at startup.

One thought, though: Du you have more than one Python installed? If so: 
Could it be that you are editing the wrong PyShell.py?

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


Re: IDLE question

2005-11-17 Thread bobueland
Okey I tried what you recommended

My C:\Python24\sitecustomize.py looks like this:

# sitecustomize.py
import os
from btools import *

When I enter
C:\Python24>C:\Python24\pythonw.exe C:\Python24\Lib\idlelib\idle.py -r
C:\Python24\sitecustomize.py

in commad propmt IDLE starts up and automatically imports 'os' and all
names from my btools folder. So far so good. But when I hit Ctrl+F6 and
restart Python Shell both 'os' and names from btools are gone!

When I work with IDLE I typically start a new file (File/New Window)
and when I have written the code I hit (Ctrl+S) to Save and F5 to run.
This restarts Python Shell and my names from btools are gone. It's no
solution if I'm forced to go back to command prompt and enter the long
sequance again. 

Bob

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


Simulating call-by-reference

2005-11-17 Thread Rikard Bosnjakovic
I'm tidying up some code. Basically, the code runs a bunch of 
regexp-searches (> 10) on a text and stores the match in a different variable.

Like this:

 re1 = r' ..(.*).. '
 re2 = r'  '
 re3 = r' .(.*).. '
 ...
 m = re.search(re1, data)
 if m:
   myclass.bar = m.group(1)

 m = re.search(re2, data)
 if m:
   myclass.foo = m.group(1)

 m = re.search(re3, data)
 if m:
   myclass.baz = m.group(1)


While this code works, it's not very good looking.

What I want is to rewrite it to something like this:

l = [ (re1, myclass.bar),
  (re2, myclass.foo),
  (re3, myclass.baz),
]

for (x,y) in l:
  m = re.search(x, y)
  if m:
   y = m.group(1)

But since Python doesn't work that way, that idea is doomed. What I'm 
looking for are other (better) ways or pointers to accomplish this task of 
cleanup.


-- 
Sincerely,  |http://bos.hack.org/cv/
Rikard Bosnjakovic  | Code chef - will cook for food

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


Re: newbie - How do I import automatically?

2005-11-17 Thread Claudio Grondi
The only difference I can see is,

that you are on Python 2.3.4 and I use Python 2.4.2:
"Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on
win32 - IDLE 1.1.2"

So maybe if you upgrade ... this will become obsolete?

Claudio

"Mikael Olofsson" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> [EMAIL PROTECTED] wrote:
> > I tried to do it on my computer (win XP). I put an extra line in
> > PyShell.py
> > [snip]
> > # test
> > sys.modules['__main__'].__dict__['os'] = os
> > [snip]
> > Then when I start idle I get
> >
> > IDLE 1.1.1
> >
> dir()
> >
> > ['__builtins__', '__doc__', '__name__']
> >
> >
> > So I don't see 'os'
> >
> > Do you see 'os' on your computer. If yes, what could be the difference?
>
> Yes, I do. The following is with IDLE 1.0.3 and Python 2.3.4 on WinXP.
>
> Without the line in PyShell.py:
>
>  IDLE 1.0.3   No Subprocess 
>  >>> dir()
>  ['__builtins__', '__doc__', '__file__', '__name__', 'main']
>
> With the line in PyShell.py:
>
>  IDLE 1.0.3   No Subprocess 
>  >>> dir()
>  ['__builtins__', '__doc__', '__file__', '__name__', 'main', 'os']
>  >>> os
>  
>
> I know nothing about the details of how IDLE work. All I know is what I
> have reported here. I was simply inspired by the following remark from
> Claudio Grondi up-thread:
>
>  > edit the first lines of %SystemDrive%\Python24\Lib\idlelib\PyShell.py
>
> I guess that PyShell.py is imported as a module by IDLE at startup.
>
> One thought, though: Du you have more than one Python installed? If so:
> Could it be that you are editing the wrong PyShell.py?
>
> Regards
> /MiO


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


Re: GTK for windows and Linux

2005-11-17 Thread Antoon Pardon
Op 2005-11-17, Ask schreef <[EMAIL PROTECTED]>:
> Hi All,
>
> Can someone please tell me what I need to use GTK with python for windows 
> and Linux?
>
> Any links to the appropriate installations would be greatly appreciated as I 
> don't know what I need... GIMP... GTK+ etc

Well I think if you visit http://www.pygtk.org/, it will answer most of
your questions.

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


Re: newbie - How do I import automatically?

2005-11-17 Thread bobueland
There is one C:\Python24\Lib\site-packages\sitecustomize.py but no
C:\Python24\Lib\sitecustomize.py

However I created one as you suggested but then I started IDLE nothing
showed up. Have you tested that it works on your computer?

Bob

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


Re: Simulating call-by-reference

2005-11-17 Thread [EMAIL PROTECTED]

Rikard Bosnjakovic wrote:
> I'm tidying up some code. Basically, the code runs a bunch of
> regexp-searches (> 10) on a text and stores the match in a different variable.
>
> Like this:
>
>  re1 = r' ..(.*).. '
>  re2 = r'  '
>  re3 = r' .(.*).. '
>  ...
>  m = re.search(re1, data)
>  if m:
>myclass.bar = m.group(1)
>
>  m = re.search(re2, data)
>  if m:
>myclass.foo = m.group(1)
>
>  m = re.search(re3, data)
>  if m:
>myclass.baz = m.group(1)
>
>
> While this code works, it's not very good looking.
>
> What I want is to rewrite it to something like this:
>
> l = [ (re1, myclass.bar),
>   (re2, myclass.foo),
>   (re3, myclass.baz),
> ]
>
> for (x,y) in l:
>   m = re.search(x, y)
>   if m:
>y = m.group(1)
>
> But since Python doesn't work that way, that idea is doomed. What I'm
> looking for are other (better) ways or pointers to accomplish this task of
> cleanup.
> -

I believe you can use the "setattr/getattr" call

l = [ (re1, myclass, "bar") ]

for x,y,z in l:
  m = re.search(x,getattr(y,z))
  if m: setattr(y,z,m.group(1))

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


Re: IDLE question

2005-11-17 Thread Claudio Grondi
now a patch fixing it I have no good feeling about, but it works:

in PyShell.py in
def restart_subprocess(self):

insert in section:
"
console.showprompt()
# restart subprocess debugger

# (-Patch)
# making additional modules available in IDLE directly after
re-start of it:
self.runsource("import os; from path import path")
# (Patch-)

if debug:
"
This will provide the modules also after restart.

Hope this will not crash elsewhere because of unexpected effects of
inserting the runsource() method at that point in the code without any other
commands which are maybe necessary to keep IDLE consistent.

So IDLE experts, HELP PLEASE !!!

Claudio

<[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> Okey I tried what you recommended
>
> My C:\Python24\sitecustomize.py looks like this:
>
> # sitecustomize.py
> import os
> from btools import *
>
> When I enter
> C:\Python24>C:\Python24\pythonw.exe C:\Python24\Lib\idlelib\idle.py -r
> C:\Python24\sitecustomize.py
>
> in commad propmt IDLE starts up and automatically imports 'os' and all
> names from my btools folder. So far so good. But when I hit Ctrl+F6 and
> restart Python Shell both 'os' and names from btools are gone!
>
> When I work with IDLE I typically start a new file (File/New Window)
> and when I have written the code I hit (Ctrl+S) to Save and F5 to run.
> This restarts Python Shell and my names from btools are gone. It's no
> solution if I'm forced to go back to command prompt and enter the long
> sequance again.
>
> Bob
>


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


Re: newbie - How do I import automatically?

2005-11-17 Thread Mikael Olofsson
[EMAIL PROTECTED] wrote:
>> I tried to do it on my computer (win XP). I put an extra line in
>> PyShell.py
>> [snip]
>> # test
>> sys.modules['__main__'].__dict__['os'] = os
>> [snip]
>> Then when I start idle I get
>>
>> IDLE 1.1.1
>>
> dir()
>>
>>
>> ['__builtins__', '__doc__', '__name__']
>>
>>
>> So I don't see 'os'
>>
>> Do you see 'os' on your computer. If yes, what could be the difference?
> 
> 

I answered:
> Yes, I do. [snip details]

I have to step back a bit. IDLE seems to work differently depending on 
how it is started. My comments above hold when I start IDLE by 
right-clicking on a python-file and choosing "Edit with IDLE".

If I instead start IDLE itself (from the windows start-menu) I get the 
same behaviour as you do, namely no os around. Another difference, which 
I've noted before is that shell restart is only available when IDLE has 
been started this way.

All this seems to be handled in PyShell.py, but I do not have the time 
to trace that in any detail.

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


Re: HTML generation vs PSP vs Templating Engines

2005-11-17 Thread Luis M. Gonzalez
With Karrigell (http://karrigell.sf.net/), all you need to know is
Python and HTML.
No templates, no python-like or special languages, only pure and simple
python.

You can embedd python into html or, if it better suits your programming
tyle, you can embed html into python. Why don't you give it a try?

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


Re: IDLE question

2005-11-17 Thread bobueland
I did as you suggested, however

after I make a new File (File/New Window) and save and then run (F5) I
get the following alert

The Python Shell is already executing a command; please waith until it
is finished

I also get the error message

Traceback (most recent call last):
  File "", line 1, in -toplevel-
import os; from path import path
ImportError: No module named path
>>> 

Bob

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


Re: Simulating call-by-reference

2005-11-17 Thread Dan Sommers
On Thu, 17 Nov 2005 10:03:50 GMT,
Rikard Bosnjakovic <[EMAIL PROTECTED]> wrote:

> What I want is to rewrite it to something like this:

> l = [ (re1, myclass.bar),
>   (re2, myclass.foo),
>   (re3, myclass.baz),
> ]

> for (x,y) in l:
>   m = re.search(x, y)
>   if m:
>y = m.group(1)

> But since Python doesn't work that way, that idea is doomed. What I'm
> looking for are other (better) ways or pointers to accomplish this
> task of cleanup.

Put the results into a dictionary (untested code follows!):

l = [ (re1, 'bar'),
  (re2, 'foo'),
  (re3, 'baz'),
]
results = {}
for (regexp, key) in l:
m = re.search(regexp, data)
if m:
results[key] = m.group(1)

Now you can access the results as results['foo'], etc.  Or look up the
Borg pattern in the ASPN cookbook and you can access the results as
results.foo, etc.

Regards,
Dan

-- 
Dan Sommers

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


Re: Python Library Reference - question

2005-11-17 Thread bobueland
I found the answer to Q1. One can download all Python docs in pdf from
http://www.python.org/doc/current/download.html

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


Re: python-mysqldb__debian_to_freebsd

2005-11-17 Thread Cousin Stanley

> 
> For the interested, the OP (Stanley Kitching), wants to use a
> python-mysqldb module on his web host running FreeBSD. They don't have
> the that installed, so he tried getting the Debian binary distrubtion
> of the library to work, and failed. He's wondering if this is at all
> possible.
>
> Answer: yes, it might (key word - might) be made to work. Linux shared
> libraries have been made to work with native applications on FreeBSD
> before. I don't have the details, but would expect you'd have to
> install large chunks of a Debian system to make this work. If you
> really want to do this, let me know and I'll chase the details down
> for you.
>
> However, that's the wrong way to do this. First step - ask your
> hosting service to install databases/py-MySQLdb. That's the Python
> MySQLdb port in the FreeBSD ports tree.
> 

Mike 

  Although I've never done it personally, I have seen a few
  newsgroup references that some Debian/FreeBSD packages
  are interchangeable so thought the minimal effort required
  for uploading the Debian MySQLdb package I have might be worth
  the long shot  

> However, that's the wrong way to do this. First step - ask your
> hosting service to install databases/py-MySQLdb. 
>
> That's the Python MySQLdb port in the FreeBSD ports tree. 
> Installing it should be trivial.  
> 

  I did a bit more google-izing last night and found
  that a FreeBSD/MySQLdb install should indeed be
  a trivial matter to install via FreePorts 

  I'll go ahead and petition the host for an install  

  Thanks very much for taking the time to provide
  a detailed explanation and your kind offer 
  for further assistance 

  Both are greatly appreciated 


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona


== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


install python2.4 on FreeBSD and keep using python2.3

2005-11-17 Thread Ksenia Marasanova
Hi,

I have python2.3, installed from port /lang/python long time ago. The
current version is 2.4, but I'd rather have two python versions,
instead of upgrading.
Is there maybe a way to somehow link installed python to
/lang/python2.3 port, and then upgrade ports and install /lang/python
as a new (2.4) version, without upgrading?
Or am I missing something and the things are much easier? I am not a
FreeBSD guru and it's my first python upgrade... thanks!

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


Re: IDLE question

2005-11-17 Thread Claudio Grondi

<[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> I did as you suggested, however
>
> after I make a new File (File/New Window) and save and then run (F5) I
> get the following alert
>
> The Python Shell is already executing a command; please waith until it
> is finished
>
> I also get the error message
>
> Traceback (most recent call last):
>   File "", line 1, in -toplevel-
> import os; from path import path
> ImportError: No module named path
> >>>
>
> Bob
>
Sure you have to replace "import os; from path import path"
with " from btools import *", than you avoid the error message
but not the problem you have got with the message box.
A "solution" to the problem with the message box may be as follows:

"
console.showprompt()
# restart subprocess debugger

# (-Patch)
# making additional modules available in IDLE directly after
re-start of it:
self.runsource("import os; from path import path")
time.sleep(0.1)
# (Patch-)

if debug:
"
If 0.1 doesn't work on your system, just increase the value, but this will
delay the response.
e.g. 0.001 doesn't work for me, but 0.1 does (Intel Pentium 4 running at 2.8
GHz).

Claudio


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


sqlite utf8 encoding error

2005-11-17 Thread Greg Miller
I have an application that uses sqlite3 to store job/error data.  When
I log in as a German user the error codes generated are translated into
German.  The error code text is then stored in the db.  When I use the
fetchall() to retrieve the data to generate a report I get the
following error:

Traceback (most recent call last):
  File "c:\Pest3\Glosser\baseApp\reportGen.py", line 199, in
OnGenerateButtonNow
self.OnGenerateButton(event)
  File "c:\Pest3\Glosser\baseApp\reportGen.py", line 243, in
OnGenerateButton
warningresult = messagecursor1.fetchall()
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 13-18:
unsupported Unicode code range

does anyone have any idea on what could be going wrong?  The string
that I store in the database table is:

'Keinen Text für Übereinstimmungsfehler gefunden'

I thought that all strings were stored in unicode in sqlite.

Greg Miller

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


Re: Python Library Reference - question

2005-11-17 Thread limodou
17 Nov 2005 00:53:59 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> The "Python LIbrary Reference" at
> http://docs.python.org/lib/contents.html seems to be an important
> document. I have two questions
>
> Q1. How do you search inside "Python LibraryReference" ? Does it exist
> in pdf or chm form?
>
Yeah. You should install windows version. There is a chm form document.

> Q2. In some other languages (for instance PHP if I recall correctly)
> readers can add comments and give examples to the various headings in
> the reference manual. This gives valuable information to the reader. Is
> there such a version of "Python Library Reference", and if not would it
> be a good idea to have such a version.
>
I don't know.

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE question

2005-11-17 Thread Claudio Grondi
Here a correction of the code snippet:

   console.text.mark_gravity("restart", "left")
# (-Patch)
# making additional modules available in IDLE directly after
re-start of it:
self.runsource("import os; from path import path")
time.sleep(0.1)
# (Patch-)
console.showprompt()

# restart subprocess debugger

I have no slightest idea why does it make a difference.
What would make much more sense for me is to wait until
  self.tkconsole.executing
is False
but this resulted in an endless loop ...

Claudio

"Claudio Grondi" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
>
> <[EMAIL PROTECTED]> schrieb im Newsbeitrag
> news:[EMAIL PROTECTED]
> > I did as you suggested, however
> >
> > after I make a new File (File/New Window) and save and then run (F5) I
> > get the following alert
> >
> > The Python Shell is already executing a command; please waith until it
> > is finished
> >
> > I also get the error message
> >
> > Traceback (most recent call last):
> >   File "", line 1, in -toplevel-
> > import os; from path import path
> > ImportError: No module named path
> > >>>
> >
> > Bob
> >
> Sure you have to replace "import os; from path import path"
> with " from btools import *", than you avoid the error message
> but not the problem you have got with the message box.
> A "solution" to the problem with the message box may be as follows:
>
> "
> console.showprompt()
> # restart subprocess debugger
>
> # (-Patch)
> # making additional modules available in IDLE directly after
> re-start of it:
> self.runsource("import os; from path import path")
> time.sleep(0.1)
> # (Patch-)
>
> if debug:
> "
> If 0.1 doesn't work on your system, just increase the value, but this will
> delay the response.
> e.g. 0.001 doesn't work for me, but 0.1 does (Intel Pentium 4 running at
2.8
> GHz).
>
> Claudio
>
>


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


Re: strange file.write() behavior on windows: $ConvertToNonresident, $ReplaceAttribute2

2005-11-17 Thread Fredrik Lundh
"welch" <[EMAIL PROTECTED]> wrote:

> while taking some rough disk performance measures on windows machines,
> and snooping with FileMon, i've noticed some odd behavior

> sometimes, depending on the phase of the moon, instead of
> $ReplaceAttribute2 the write goes to $ConvertToNonresident. within a
> single run of writeTest the write always goes to the same one,
> whichever one that is. these runs are always slower (sometimes greatly)
> than writing the same with 64K blocks, even though many fewer
> file.write()'s are being issued because of the larger block size.
>
> finally, where you'd expect an even 10 of the WRITE
> C:\$ReplaceAttribute2 lines per WRITE C:\writeTest.out lines in the
> example above, instead FileMon reports 8 lines for the first, 6 for the
> second, 8 for the third, 6 for the fourth, etc... i've no idea if this
> means FileMon is missing messages, but this pattern is absolutely
> consistent across every run i've made, on both xp and win2k3 server
> machines.
>
> a look at the python fileobject.c source shed no light for me, anyone
> know what could be going on? the "equivalent" c version of writeTest
> using fwrite() shows a succession of 1K blocks writing to the named
> file (even when fwrite is given 64K blocks), and no mysterious
> $ReplaceAttribute2 lines

you're seeing activities by the Windows caching system (c:\$ stuff is various
NTFS data streams).  unless you're writing low-level drivers, you don't really
have to care about what it does, and when it does what...

 



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


Re: sqlite utf8 encoding error

2005-11-17 Thread Fredrik Lundh
Greg Miller wrote:

> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 13-18:
> unsupported Unicode code range
>
> does anyone have any idea on what could be going wrong?  The string
> that I store in the database table is:
>
> 'Keinen Text für Übereinstimmungsfehler gefunden'

$ more test.py
# -*- coding: iso-8859-1 -*-
u = u'Keinen Text für Übereinstimmungsfehler gefunden'
s = u.encode("iso-8859-1")
u = s.decode("utf-8") # <-- this gives an error

$ python test.py
Traceback (most recent call last):
  File "test.py", line 4, in ?
u = s.decode("utf-8") # <-- this gives an error
  File "lib/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 13-18:
unsupported Unicode code range

> I thought that all strings were stored in unicode in sqlite.

did you pass in a Unicode string or an 8-bit string when you stored the text ?

 



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

Re: running functions

2005-11-17 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Gorlon the Impossible  <[EMAIL PROTECTED]> wrote:
.
.
.
>the fly' so to speak. I checked out the threading module and its
>working for what I am trying to do at the moment, but I am open to
>suggestions and eager to learn all I can about other options. Thanks
.
.
.
If threading is already working for you, stay with it; it
certainly has the technical ability to do all you describe
for your eventual goal.  Apart from that, just keep reading
the standard documentation.  You might also consider
http://www.unixreview.com/documents/s=7822/ur0303j/ > and
http://www.unixreview.com/documents/s=7750/uni1041364857773/ >
(except that the latter is now in its second edition--why hasn't
the reviewer addressed this yet!?).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write an API for a Python application?

2005-11-17 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
dwelch  <[EMAIL PROTECTED]> wrote:
>Gary Kshepitzki wrote:
>> Hello
>> I would like to create an API for a piece of Python code. The API is for use 
>> by non Python code.
>> It should support interaction in both directions, both accessing functions 
>> on the API and the ability for the API to raise events on its client.
>> What is the best way to do that?
>> I though of doing it as a python COM server but I am not familiar with COM 
>> and I saw that implementing a COM server with events in python is not 
>> trivial for me.
>> Is there a better (or simpler) solution?
>> What are the common ways for doing that?
.
.
.
>You could try Elmer:
>http://elmer.sourceforge.net/index.html
>
>I'm sure you could create a callable library (.so, .dll, etc) with it.
.
.
.
You guys work too hard.

My reaction is this:  Mr. Kshepitzki asks for an IPC choice,
says that COM looks like a bit too much, and respondents
start by loading him with even *heavier* technical alterna-
tives, such as CORBA.  Whew!  My recommendation:  a simple
project-specific line-oriented bilateral TCP/IP implementa-
tion.  Both server and client can listen for incoming
messages.  My guess is that the *... Cookbook* has a sketch
of this in a few dozen lines.  Perhaps after I've searched
it, I'll follow-up with a specific reference.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Library Reference - question

2005-11-17 Thread [EMAIL PROTECTED]
See this nice tool for Firefox.

It's like a chm form live updated. :)

http://projects.edgewall.com/python-sidebar

[]'s

Luciano Pacheco

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


Re: IDLE question

2005-11-17 Thread bobueland
This works!

Thanks Claudio

For complete happiness I would also like to know what's hapening. Is
there anywhere I can read about PyShell.py.

Bob

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


Re: Python gui

2005-11-17 Thread Sybren Stuvel
batfree enlightened us with:
> Now GTK can use the local theme.You can choose the local theme to
> make your application windows style on Winodws and Mac likely on mac
> os.

But why do that yourself, when you can use a GUI toolkit that does it
for you?

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python obfuscation

2005-11-17 Thread Chris Mellon
On 17 Nov 2005 01:29:23 -0800, Ben Sizer <[EMAIL PROTECTED]> wrote:
> Mike Meyer wrote:
> > > Are you claiming therefore that it's more acceptable to you to have to
> > > access the data remotely every time you use the software than once per
> > > install?
> >
> > Alex's solution doesn't require special treatment for disaster
> > recovery and/or planning, and as such is a valid answer to the
> > question. It may be unacceptable for *other* reasons, but it beats
> > dictating a disaster recovery plan for your software to the end user
> > hands down on that basis.
>
> Sorry, I just don't see this as being a significant difference that
> makes 'access-always' acceptable and 'access rarely' unacceptable.
>
> > > No, I am just pointing out that you are mixing up the concept of an
> > > actual 'right' such as one embodied in a state's constitution, with an
> > > implied 'right' that is just an exemption from committing an offence.
> > > The term 'right' does not even appear in the relevant part of US
> > > copyright law, except to state that it is a limitation on the copyright
> > > holder's rights.
> >
> > You're still just playing semantic games. The common usage is "fair
> > use rights." If you mean "... without infringing on the end users
> > rights, except for fair use rights", then you should say that.
>
> Call it what you like; still, I cannot be infringing on your right when
> such a right does not exist to be infringed. If you want to term it a
> 'right', feel free, but that's not what you're granted under US law or
> the Berne Convention. The 'common usage' here leads to a
> misinterpretation of what you're entitled to. What is actually stated
> is a limitation on the copyright holder's exclusive rights, which is a
> very different matter.
>

Do you have a legal right to wear an orange shirt? To sit backwards in
your chair?

Your rights are anything you can do that is not forbidden - the US
constitution is explicitly designed in this way, something that people
often forget. There is no difference between an "explicit" and an
"inferred" right, by design. If you read the text of the US
constitution, even the phrasing makes this clear. In fact, the format
of the Bill of Rights was considered harmful by some of the founding
fathers, because they felt that people would interpert it exactly as
they have - as enumerating the limits of government power, instead of
enumerating the powers themselves.

Therefore, by extending your rights via DRM, you are infringing upon
the rights of your customers. I *do* have a legal right to backup and
archive my purchased software, just as I have a legal right to write
this email, and I have a legal right to watch a DVD I've purchased.

The very basis of law is about drawing lines between where one persons
rights end and another begins. What (all current) DRM solutions do is
extend the rights of the copyright holder. This, *by definition*,
comes at the expense of the rights of everyone else. The granting of
copyright at all is a limitation of the rights of everyone else, but
one that is legally enshrined and that people (generally) accept as
being in the common good. It's very similar to the concept of private
property. The law grants you the right to keep people from walking
into your house. However, if you decide to build an electric fence
across the sidewalk and into the street, you are infringing on thier
right to walk past.

Further, if you decide to define "right" as something that is
specifically legally protected, then you have no right to embed DRM in
your software at all - you are *explicitly* expanding the rights
granted to you by copyright law, and you do not have explicit legal
rights to do that. Further, you do not have explicit legal rights to
prevent fair-use copying.


> --
> Ben Sizer
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python gui

2005-11-17 Thread Chris Mellon
On 11/16/05, batfree <[EMAIL PROTECTED]> wrote:
> Now GTK can use the local theme.You can choose the local theme to make
> your application windows style on Winodws and Mac likely on mac os.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

This is true only in an very, very loose sense. Gtk does not use the
native rendering tools, and does not have native behavior. The
"native" theme just mimics some of the basic shapes & colors of the
controls.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposal for adding symbols within Python

2005-11-17 Thread Kay Schluehr

Steven Bethard wrote:
> Pierre Barbier de Reuille wrote:
> > Proposal
> > 
> >
> > First, I think it would be best to have a syntax to represent symbols.
> > Adding some special char before the name is probably a good way to
> > achieve that : $open, $close, ... are $ymbols.
>
> How about using the prefix "symbol." instead of "$"?
>
>  >>> symbol.x

I recognize 3 symbols: a "symbol" a dot and another symbol. So I
wouldn't call this a symbol. Maybe a "diabolon"? Other languages have
symbols, Python has diaboli ;)

Kay

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


Re: sqlite utf8 encoding error

2005-11-17 Thread Sybren Stuvel
Greg Miller enlightened us with:
> 'Keinen Text für Übereinstimmungsfehler gefunden'

You posted it as "Keinen Text fr ...", which is Latin-1, not
UTF-8.

> I thought that all strings were stored in unicode in sqlite.

Only if you put them into the DB as such. Make sure you're inserting
UTF-8 text, since the DB won't do character conversion for you.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


searching for files on Windows with Python

2005-11-17 Thread Shane
I've been giving Google a good workout with no luck. I would like to be able to 
search a Windows filesystem for filenames, returning a list off absolute paths 
to the found files, something like:

def findFiles(filename, pathToSearch):
 ...
 ...
 return foundFileNames

Is the os module where I should start?

Thanks,

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


Re: IDLE question

2005-11-17 Thread Claudio Grondi
<[EMAIL PROTECTED]> wrote
> This works!
>
> Thanks Claudio
I am glad, that the time I put into it was not wasted.

> For complete happiness I would also like to know what's hapening.
> Is there anywhere I can read about PyShell.py.

Not that I would know about (except reading the source code).

Maybe this below is the right place to ask further questions (2004 there was
a discussion about IDLE):
  http://mail.python.org/mailman/listinfo/tutor
but I have to admit, I haven't used this forum myself yet.

>From my experience with learning Python I suppose, that it will be not very
easy to fully understand what is going on in IDLE (i.e. in PyShell.py)
because this probably requires full understanding of the Tkinter interface
and some insight into deep Python internals. Perhaps this is the reason why
noone knowledgable in this area has responded here expecting from a response
more trouble than success?

Claudio


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


Re: How to write an API for a Python application?

2005-11-17 Thread Paul Boddie
Cameron Laird wrote:
> You guys work too hard.

I beg to differ. ;-)

> My reaction is this:  Mr. Kshepitzki asks for an IPC choice,
> says that COM looks like a bit too much, and respondents
> start by loading him with even *heavier* technical alternatives, such as 
> CORBA.

Well, my relatively limited experience with COM-related technologies
suggests that it can be "a bit too much" in terms of the administrative
hassle of declaring interfaces, registering components, and so on.
However, if CORBA-related technologies from the late 1990s could manage
to work so well with Python that one didn't even need to manually
generate the various stubs to access remote services, one would hope
that such practices haven't been abandoned in the CORBA systems
available for Python today.

Looking at some of the omniORB tutorials gives the impression that
there's a certain number of magic utterances that need to be included
in any given program (either client or server) in order to get the
underlying mechanisms up and running, but I think that's to be expected
for any kind of distributed system. My point was that in adopting
something like CORBA, you might need to tolerate a certain amount of
boilerplate code but can then expect various tricky aspects of the
communications mechanisms to have been thought through on your behalf,
meaning that callbacks and other things just work. Rolling your own
solution, on the other hand, can end in a long road discovering what
those CORBA people were doing for all those years.

I suppose if CORBA is too heavy, there's always PYRO. I can't comment
on whether PYRO will be able to do what was requested, however.

Paul

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


How to - import code not in current directory

2005-11-17 Thread py
I have a python script that I want to test/debug.  It contains a class
which extends from some other class which is located in some other
python file in a different directory.

For example:

[script to test]
c:\python_code\foo.py

[needed python files]
c:\some\other\directory\bar.py

...so I want to test/debug foo.py, which needs bar.py.  foo.py imports
bar.py ...but in order to test out foo (in the python shell) I normally
copy bar.py into the same directory as foo.py...but this is painful.
Is there some way that I can have python know about the directory where
bar.py is located, like a system variable, etc?  If so, how do I set
that up?

Thanks.

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


Re: How to - import code not in current directory

2005-11-17 Thread Carsten Haese
On Thu, 2005-11-17 at 08:41, py wrote:
> Claudio Grondi wrote:
> > so this should work in your case:
> >
> > import sys
> > sys.path.append("C:\some\other\directory")
> > import bar
> 
> ...that will certainly work.  Only issue is that each time I start up
> foo.py in the python shell I have to retype those three lineskind
> of why I was hoping for a environment variable or path setting that i
> could stick in.

That would be PYTHONPATH.

-Carsten


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


Re: How to - import code not in current directory

2005-11-17 Thread Claudio Grondi
"py" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> Claudio Grondi wrote:
> > so this should work in your case:
> >
> > import sys
> > sys.path.append("C:\some\other\directory")
> > import bar
>
> ...that will certainly work.  Only issue is that each time I start up
> foo.py in the python shell I have to retype those three lineskind
> of why I was hoping for a environment variable or path setting that i
> could stick in.
>
> This will do for now...
>
See the recent threads
"IDLE question" and
"newbie - How do I import automatically?"
in THIS newsgroup for further help.

Claudio


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


Re: How to - import code not in current directory

2005-11-17 Thread Claudio Grondi
This question seems to come up in this newsgroup quite often, so looking
through past threads will sure provide more details.

Here from "Re: how to import a module from a arbitraty path?"
  posted to comp.lang.python by Simon Brunning on May 26, 2005 09:20 :

"
> I have a program which is going to dynamicly load components from some
> arbitrary defined paths. How to do that?

You can locate them with os.walk and fnmatch. Then you can temporarily
add the directory to sys.path, and import using __import__().
"

so this should work in your case:

import sys
sys.path.append("C:\some\other\directory")
import bar

Claudio


"py" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> I have a python script that I want to test/debug.  It contains a class
> which extends from some other class which is located in some other
> python file in a different directory.
>
> For example:
>
> [script to test]
> c:\python_code\foo.py
>
> [needed python files]
> c:\some\other\directory\bar.py
>
> ...so I want to test/debug foo.py, which needs bar.py.  foo.py imports
> bar.py ...but in order to test out foo (in the python shell) I normally
> copy bar.py into the same directory as foo.py...but this is painful.
> Is there some way that I can have python know about the directory where
> bar.py is located, like a system variable, etc?  If so, how do I set
> that up?
>
> Thanks.
>


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


Re: searching for files on Windows with Python

2005-11-17 Thread Dennis Benzinger
Shane schrieb:
> I've been giving Google a good workout with no luck. I would like to be able 
> to search a Windows filesystem for filenames, returning a list off absolute 
> paths to the found files, something like:
> 
> def findFiles(filename, pathToSearch):
>  ...
>  ...
>  return foundFileNames
> 
> Is the os module where I should start?
> [...]

Yes, especially the os.walk() function should help you.

Bye,
Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to discover this process's current memory usage, cross-platform?

2005-11-17 Thread Scott Tsai
libgtop has python bindings and supports most modern unixes including
linux, BSD, solaris, and AIX.
You probably already has it installed on your linux box.

ftp://ftp.gnome.org/pub/GNOME/sources/libgtop/
ftp://ftp.gnome.org/pub/GNOME/sources/gnome-python-extras/

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


Re: How to - import code not in current directory

2005-11-17 Thread py
PYTHONPATH is perfectcheck out this link for more info..

http://docs.python.org/tut/node8.html#searchPath

I just added the environment variable (on windows) named "PYTHONPATH"
and set it to "C:\some\other\directory"

:)

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


RE: How to - import code not in current directory

2005-11-17 Thread Dmytro Lesnyak
Yes, you can. 
Try this:

import sys

sys.path.append('c:\some\other\directory\')
import bar

Good luck!

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of py
Sent: 17. marraskuuta 2005 15:19
To: python-list@python.org
Subject: How to - import code not in current directory

I have a python script that I want to test/debug.  It contains a class
which extends from some other class which is located in some other
python file in a different directory.

For example:

[script to test]
c:\python_code\foo.py

[needed python files]
c:\some\other\directory\bar.py

...so I want to test/debug foo.py, which needs bar.py.  foo.py imports
bar.py ...but in order to test out foo (in the python shell) I normally
copy bar.py into the same directory as foo.py...but this is painful.
Is there some way that I can have python know about the directory where
bar.py is located, like a system variable, etc?  If so, how do I set
that up?

Thanks.

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


Re: How to - import code not in current directory

2005-11-17 Thread py
Claudio Grondi wrote:
> so this should work in your case:
>
> import sys
> sys.path.append("C:\some\other\directory")
> import bar

...that will certainly work.  Only issue is that each time I start up
foo.py in the python shell I have to retype those three lineskind
of why I was hoping for a environment variable or path setting that i
could stick in.

This will do for now...

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


Re: is parameter an iterable?

2005-11-17 Thread Roy Smith
Steven D'Aprano <[EMAIL PROTECTED]> wrote:

> Alas and alack, I have to write code which is backwards 
> compatible with older versions of Python:
> [...]
> NameError: name 'iter' is not defined
> 
> What should I do when I can't rely on functions that 
> don't exist in older versions of Python?

It really sucks trying to support obsolete environments.  Been there, done 
that.  But sometimes you just have to pull out the duct tape and deal with 
the problem any way you can.  Parsing undocumented exception strings is 
sort of like screen scraping; it's good to know that it's possible as an 
absolute last resort, but you really want to put some effort into finding a 
better way.

You could use two nested try blocks that both catch TypeErrors, one 
enclosing the entire loop, the other enclosing just the body.  Anything 
that gets caught by the outer try had to have been generated within the 
loop control code itself:

-
Roy-Smiths-Computer:play$ cat iter.py
#!/usr/bin/env python

def doSomething (obj):
sum = 0
try:
for i in obj:
try:
sum += i
except TypeError, ex:
print "exception (%s) in the inner block" % ex
return
except TypeError, ex:
print "non iterable object (%s)" % ex
return
print "sum = %d" % sum

doSomething ([1, 2, 3])
doSomething (["one", "two", "three"])
doSomething (0)
Roy-Smiths-Computer:play$ ./iter.py
sum = 6
exception (unsupported operand type(s) for +=: 'int' and 'str') in the 
inner block
non iterable object (iteration over non-sequence)
-

This is pretty ugly, but I think it does what you want.  It could be made a 
bit less ugly by refactoring the body of the for loop into another function.

BTW, if you do resort to trying to parse the exception messages, and it 
breaks in some future code, you might have me to blame.  I submitted a bug 
report a while back which, if it's ever acted on, would break your code!

http://sourceforge.net/tracker/index.php?func=detail&aid=1187437&group_id=54
70&atid=105470
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: searching for files on Windows with Python

2005-11-17 Thread Fredrik Lundh
Shane wrote:

> I've been giving Google a good workout with no luck. I would like to be
> able to search a Windows filesystem for filenames, returning a list off 
> absolute
> paths to the found files, something like:

maybe some variation of

http://article.gmane.org/gmane.comp.python.general/422691

is what you need ?

 



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


PyQt layout question: QScrollView and QGridLayout?

2005-11-17 Thread Volker Lenhardt
For a QApplication (PyQt) on the small screen of my Zaurus 5500 PDA I 
try to layout my data output in a QScrollView as the central widget. I'd 
prefer to use QGridLayout, but cannot add it to the scroll view.

sc=QScrollView(self)
layout=QGridLayout(..., sc.viewport())
sc.addChild(layout)

results in a TypeError.

Is there a way to get it to work? Filling a box viewport with lots of 
padding boxes and white space labels to establish grids is very 
cumbersome. And I need 4 different layouts to change places.

Best wishes
Volker

-- 
Volker Lenhardt
E-Mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Why is "if fileitem.file:" (almost) never false?

2005-11-17 Thread mark
How do I detect that a particular form element is a file upload or if
the file upload has worked?

In the Python cgi module documentation I found suggested code...

form = cgi.FieldStorage()
fileitem = form["userfile"]
if fileitem.file:
# It's an uploaded file; count lines


I've tried something like this in a test script and fileitem.file
evaluates to true when form element "userfile" is just a text box in
the web page. When "userfile" is a type="file" it evaluates true when I
select a real file to upload and when I manually type in a false path
to a file that doesn't exist. When I do upload a file, the script
correctly prints out the file contents (fileitem.value) so the upload
does work OK.

It seems that provided there's a form element called "userfile" then
fileitem.file evaluates to true provided the form has
enctype="multipart/form-data" (it doesn't matter if the file upload
works or if the form element is not type="file").

When I tried different forms without the enctype then fileitem.file
evaluated to false when userfile was either type="text" or type="file".

My conclusion is that if fileitem.file: detects enctype of form rather
than if a particular element is a file upload. How do I detect that a
particular form element is a file upload or if the file upload has
worked?

My best suggestion (but I'd like to hear your views) is to use:
if fileitem.filename and len(fileitem.value):
   # It's an uploaded file

When the form element userfile is just a text box or the form lacks the
enctype then the filename attribute evaluates to false. When I supply
an incorrect file path to the file form element the upload fails so
len(fileitem.value) evaluates to false. When I upload a real file, both
fileitem.filename and len(fileitem.value) evaluate to true.

If I upload a real file that's empty then fileitem.value is an empty
string so len(fileitem.value) evaluates to false which is not quite
right (an empty file is an obscure test but it is a valid file to
upload).

Any suggestions for improvements would be gratefully received.

Thanks

Mark

PS if it's relevant, I'm using Windows2000, Python 2.3.2, the shebang
includes -u, Apache 2.0.42 and Firefox 1.0.4.

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


Current execution frame of another thread?

2005-11-17 Thread skip
I would like to try a sampling approach to profiling.  My thought is to have
a profiling thread that samples the execution frame of all the other
started threads.  I don't see any path from the threads returned by
threading.enumerate() to their current frames.  Am I missing something?

Thx,

Skip

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


Re: Newb ?

2005-11-17 Thread Paul Watson
Chad Everett wrote:
> Hey guys,
> 
> Thanks for the hint.
> I found that info last night but I could never get it to print more than 
> just the last letter.
> or it would only print partially.
> I was using just a single colon,  the double colon did it.

If you were using a single colon, then it would print everything except 
the last character.  Use the Python interactive mode for experimentation.

$ python
Python 2.4.1 (#1, Jul 19 2005, 14:16:43)
[GCC 4.0.0 20050519 (Red Hat 4.0.0-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> s = 'abc'
 >>> s
'abc'
 >>> s[:-1]
'ab'
 >>> s[-1]
'c'
-- 
http://mail.python.org/mailman/listinfo/python-list


get just one character

2005-11-17 Thread Sinan Nalkaya
hello everybody,
how can i just get 1 character ? i`ve done a search but just found 
getch() for windows, i need same for unix and raw_input has any option 
that is not documented ?
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


PyDev 0.9.8.5 released

2005-11-17 Thread Fabio Zadrozny
Hi All,

PyDev - Python IDE (Python Development Enviroment for Eclipse) version 
0.9.8.5 has been released.

Check the homepage (http://pydev.sourceforge.net/) for more details.

Details for Release: 0.9.8.5

Major highlights:
---

* Removed the dependency on packages 'sun..Base64', so that 
other VMs can be targetted
* Some code-completion problems in the 'resolution order' regarding 
tokens in __init__ were solved
* Added option so that the user can choose whether to automatically 
add 'self' or not in method declarations

Cheers,

Fabio

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
www.esss.com.br

PyDev - Python Development Enviroment for Eclipse
pydev.sf.net
pydev.blogspot.com



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


Re: install python2.4 on FreeBSD and keep using python2.3

2005-11-17 Thread Paul Watson
Ksenia Marasanova wrote:
> Hi,
> 
> I have python2.3, installed from port /lang/python long time ago. The
> current version is 2.4, but I'd rather have two python versions,
> instead of upgrading.
> Is there maybe a way to somehow link installed python to
> /lang/python2.3 port, and then upgrade ports and install /lang/python
> as a new (2.4) version, without upgrading?

Yes, you can have several versions installed in different directories.

Many people make /usr/local/bin/python or /usr/bin/python a link to the 
default version they choose for the machine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is parameter an iterable?

2005-11-17 Thread Micah Elliott
On Nov 17, Duncan Booth wrote:
> Steven D'Aprano wrote:
> > What should I do when I can't rely on functions that 
> > don't exist in older versions of Python?

>   sys.exit('Archaic Python not supported, please upgrade')

+1 QOTW.

I recently gave up on trying to support (backport to) pre-2.2 in my
projects.  It's been ~3 years since 2.2 released and that seem like a
pretty reasonable support window.  I wound up with HACK and
PORTABILITY comments all over the place and too much boilerplate.  Now
I go with a startup check on sys.hexversion, and exit with similar
wording.

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


Re: get just one character

2005-11-17 Thread Paul Watson
Sinan Nalkaya wrote:
> hello everybody,
> how can i just get 1 character ? i`ve done a search but just found 
> getch() for windows, i need same for unix and raw_input has any option 
> that is not documented ?
> thanks.

Please use Google.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get just one character

2005-11-17 Thread Sinan Nalkaya
Paul Watson wrote:

>Sinan Nalkaya wrote:
>  
>
>>hello everybody,
>>how can i just get 1 character ? i`ve done a search but just found 
>>getch() for windows, i need same for unix and raw_input has any option 
>>that is not documented ?
>>thanks.
>>
>>
>
>Please use Google.
>
>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
>  
>
thanks , i found something in 
http://the.taoofmac.com/static/grimoire.html  also works but i thought 
that there is short way for doing it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating package question

2005-11-17 Thread erick_bodine

Bruno Desthuilliers wrote:
> [EMAIL PROTECTED] a écrit :
> > I think I have an answer to my own question.  In the
> > WindowsComponents/__init__.py file, I have the following, that feels
> > like a better answer for the problem.  Is there a better answer than
> > this?
> >
> > import os, sys
> > sys.path.append(os.path.join(os.getcwd(), 'Common'))
> >
>
> Err... if the script is called from somewhere else, this won't work.
> replace os.getcwd() with os.path.dirname(os.path.realpath(__file__))
>
Right, I anticipate the script(s) won't be called from elsewhere,
but
>
> Or better, use a .pth or add the needed path in your PYTHONPATH
THis would be ideal if I could gaurantee that the users (other software
testers) would install the *.pth file. 

thanks for all the suggestions.

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


Re: PyExcelerator - mishandling of formulas?

2005-11-17 Thread Marco Aschwanden
On Thu, 17 Nov 2005 09:27:26 +0100, Serge Orlov <[EMAIL PROTECTED]>  
wrote:


>> ws_summary.write(0,0, pyExcelerator.Formula('Data:A1'))
>> ws_data.write(0, 0, '4000')

> I think you're doing it wrong. ":" character means range, to refer to a
> sheet use "!" charater: Data!A1
>

Right you are. It "changed" somehow... anyhow, even if you change it, it  
will choke on the same line. I received an answer... a workaround which  
doesn't make me happy, but it is, as it is!

[...]
This is not a bug. This is by design. pyExcelerator does not
unerstand such syntax. Try Formula("HYPERLINK(address; name)")
[...]

Which means:

ws_summary.write(0,0, pyExcelerator.Formula('HYPERLINK("Data!A1"))

does the trick, but the text shown is a hyperlink now!

Thanks for your help,
Regards,
Marco

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


Re: install python2.4 on FreeBSD and keep using python2.3

2005-11-17 Thread Micah Elliott
On Nov 17, Ksenia Marasanova wrote:
> I have python2.3, installed from port /lang/python long time ago. The
> current version is 2.4, but I'd rather have two python versions,
> instead of upgrading.
> Is there maybe a way to somehow link installed python to
> /lang/python2.3 port, and then upgrade ports and install /lang/python
> as a new (2.4) version, without upgrading?
> Or am I missing something and the things are much easier? I am not a
> FreeBSD guru and it's my first python upgrade... thanks!

Just pass "configure" an option like "--prefix /wherever/you/want".
Then make and make install.  Do this with as many Pythons as you like.

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


Re: GTK for windows and Linux

2005-11-17 Thread batfree
all you need are GTK+ envirement and the pygtk module.You can get more
information in www.pygtk.org.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why is "if fileitem.file:" (almost) never false?

2005-11-17 Thread Peter
I think:

   form = cgi.FieldStorage()
   fileitem = form["userfile"]
   if fileitem.filename:
 data = form.getfirst("userfile")
 if data:
  #do somethinfg with it


FieldStorage objects always have a filename attribute which is  the
filename that the user used to upload the file or '' (maybe None) when
the FieldStorage object was not created for  a File upload. The
getfirst call returns the data of the file, but you need to access the
FieldStorage object directly forthe filename (as you did).

HTH

Peter


mark wrote:
> How do I detect that a particular form element is a file upload or if
> the file upload has worked?
>
> In the Python cgi module documentation I found suggested code...
>
> form = cgi.FieldStorage()
> fileitem = form["userfile"]
> if fileitem.file:
> # It's an uploaded file; count lines
>
>
> I've tried something like this in a test script and fileitem.file
> evaluates to true when form element "userfile" is just a text b
ox in
> the web page. When "userfile" is a type="file" it evaluates true when I
> select a real file to upload and when I manually type in a false path
> to a file that doesn't exist. When I do upload a file, the script
> correctly prints out the file contents (fileitem.value) so the upload
> does work OK.
>
> It seems that provided there's a form element called "userfile" then
> fileitem.file evaluates to true provided the form has
> enctype="multipart/form-data" (it doesn't matter if the file upload
> works or if the form element is not type="file").
>
> When I tried different forms without the enctype then fileitem.file
> evaluated to false when userfile was either type="text" or type="file".
>
> My conclusion is that if fileitem.file: detects enctype of form rather
> than if a particular element is a file upload. How do I detect that a
> particular form element is a file upload or if the file upload has
> worked?
>
> My best suggestion (but I'd like to hear your views) is to use:
> if fileitem.filename and len(fileitem.value):
># It's an uploaded file
>
> When the form element userfile is just a text box or the form lacks the
> enctype then the filename attribute evaluates to false. When I supply
> an incorrect file path to the file form element the upload fails so
> len(fileitem.value) evaluates to false. When I upload a real file, both
> fileitem.filename and len(fileitem.value) evaluate to true.
>
> If I upload a real file that's empty then fileitem.value is an empty
> string so len(fileitem.value) evaluates to false which is not quite
> right (an empty file is an obscure test but it is a valid file to
> upload).
>
> Any suggestions for improvements would be gratefully received.
>
> Thanks
>
> Mark
>
> PS if it's relevant, I'm using Windows2000, Python 2.3.2, the shebang
> includes -u, Apache 2.0.42 and Firefox 1.0.4.

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


Re: get just one character

2005-11-17 Thread Micah Elliott
On Nov 17, Sinan Nalkaya wrote:
> how can i just get 1 character ? i`ve done a search but just found
> getch() for windows, i need same for unix and raw_input has any
> option that is not documented ?

Get all the characters one at a time:

>>> inp = raw_input('enter a string> ')
enter a string> this is a string
>>> for ch in inp: print ch
...
t
h
i
s

i
s

a

s
t
r
i
n
g

Or just get a single character:

>>> inp[3]
's'
>>>   

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


Re: Python obfuscation

2005-11-17 Thread Anton Vredegoor
Alex Martelli wrote:

> Modern equivalent of serialization (publishing one chapter at a time on
> the web, the next chapter to come only if the author receives enough
> payment for the previous one) have been attempted, but without much
> success so far; however, the holy grail of "micropayments" might yet
> afford a rebirth for such a model -- if paying for a chapter was
> extremely convenient and cheap, enough people might choose to do so
> rather than risk the next chapter never appearing.  Remember that, by
> totally disintermediating publishers and bookstores, a novelist may
> require maybe 1/10th of what the book would need to gross in stores, in
> order to end up with the same amount of cash in his or her pockets.
>
> One could go on for a long time, but the key point is that there may or
> may not exist viable monetization models for all sorts of endeavours,
> including the writing of novels, depending on a lot of other issues of
> social as well as legal structures.  Let's not be blinded by one model
> that has worked sort of decently for a small time in certain sets of
> conditions, into believing that model is the only workable one today or
> tomorrow, with conditions that may be in fact very different.

Maybe this micropayment thing is already working and active. What is
the cost of a mouseclick and what is the monetarial value of the fact
that someone is clicking on a link? Someone bought virtual property for
real money and sold it later with a lot of profit. There are pages
where one can buy pixels. Maybe me replying to you will provoke some
other chain of events with payoffs for you or me (I hope positive :-)

The idea of using a webservice to hide essential secret parts of your
application can only work well if one makes some random alterations to
the results of the queries. Like GPS signals that are deliberately made
less exact. Obfuscated Python code could for example return variable
precision numbers with a slight random alteration. I think such things
would make it harder to reverse engineer the code behind the server.

But the more one messes with the ideal output the more often the user
will rather click another link. (or launch another satellite)

Anton.

what's the current exchange rate for clicks and dollars?

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


Re: PyQt layout question: QScrollView and QGridLayout?

2005-11-17 Thread Phil Thompson
On Thursday 17 November 2005 2:56 pm, Volker Lenhardt wrote:
> For a QApplication (PyQt) on the small screen of my Zaurus 5500 PDA I
> try to layout my data output in a QScrollView as the central widget. I'd
> prefer to use QGridLayout, but cannot add it to the scroll view.
>
> sc=QScrollView(self)
> layout=QGridLayout(..., sc.viewport())
> sc.addChild(layout)
>
> results in a TypeError.
>
> Is there a way to get it to work? Filling a box viewport with lots of
> padding boxes and white space labels to establish grids is very
> cumbersome. And I need 4 different layouts to change places.

QGridLayout is not a sub-class of QWidget, which is what addChild() is 
expecting. You probably want QGrid.

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


test_locale & test_pty fail for 2.4 SVN on Solaris 8/10

2005-11-17 Thread skip

We are getting a couple test failures at work when building Python 2.4.2 or
the 2.4 Subversion branch on Solaris 8 and Solaris 10 (both on PC hardware).
test_pty fails and test_locale is unexpectedly skipped.  The locale
environment is

LC_ALL=C
LC_CTYPE=iso_8859_1

I also tried test_locale with no LC_* environment variables set.  Should my
LC_* settings be different?  Can anyone else confirm these problems?

Thx,

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


Re: IDLE question

2005-11-17 Thread bobueland
I made bat file called startidle.bat which I put in C:\Python24
directory. This is how it looks

@echo off
start C:\Python24\pythonw.exe C:\Python24\Lib\idlelib\idle.py -r
C:\Python24\sitecustomize.py
exit

Now I put a shortcut of startidle.bat in Quick Launch. The only thing I
have to do now is to click on the shortcut icon in the Quick Launch and
I'm up and running. 

Alla Tua Salute Claudio

Bob

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


Re: A way for closing an app monitor

2005-11-17 Thread Daniel Crespo
Ok. Thanks for your answer :-)

I have implemented  this and works correctly.

Daniel

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


Re: Current execution frame of another thread?

2005-11-17 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:
> I would like to try a sampling approach to profiling.  My thought is to have
> a profiling thread that samples the execution frame of all the other
> started threads.  I don't see any path from the threads returned by
> threading.enumerate() to their current frames.  Am I missing something?

I doubt that works. As python uses the OS underlying threading model, it 
doesnn't know about the internal management structures - and even it 
knew, these had to be carefully designed for that exact purposes of 
yours, as the stack frame can only be safely inspected by the thread 
_running_ in it.

An external thread could be interrupted at all times while traversing 
other threads management structures, and then find a corrupted memory 
location when it is re-scheduled.

Maybe one could write a threading model that allwos for hooks in the 
scheduler (which has all the time in the world for such stuff) - but I'm 
not aware that that's possible under e.g. pthreads, so there is unlikely 
a python-way to do so.

Regards,

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


Re: How to write an API for a Python application?

2005-11-17 Thread Mike Meyer
"Eric Brunel" <[EMAIL PROTECTED]> writes:
> On Wed, 16 Nov 2005 15:43:33 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote:
>
>> "Eric Brunel" <[EMAIL PROTECTED]> writes:
>>> On 16 Nov 2005 06:18:05 -0800, Paul Boddie <[EMAIL PROTECTED]> wrote:
 One technology that I used many years ago with Python, and which should
 still do the job is CORBA - at that time ILU, but I suppose the various
 other ORBs should also be as capable; certainly, ILU permitted
 callbacks from the server into the client. These days, you might want
 to look at omniORB, Fnorb and ORBit.
>>> I never saw any way to create callbacks from server to client with CORBA. 
>>> How would you describe such a callback in the IDL file?
>> It's OO, not functional. You pass an object to the server, and the
>> server invokes methods on that object. In the IDL, you use the
>> interface name as a type. I.e.:
>>
>>   interface Window {
>>   ...
>>   }
>>  and in another interface:
>>   WindowList FindWindows(in Window name) ;
>
> This is slowly drifting OT, but aren't the interfaces in the IDL implemented 
> on the server, and not on the client? So passing an "interface instance" to a 
> method will just make the server call itself, won't it? Or you have to turn 
> your client into a server, which makes things a lot more complicated.

Yes, your client turns into a server. That's pretty much required for
callbacks to work, no matter what technology you use. While the
details are a lot more complicated than being a simple client, you get
to ignore a lot of them - like how clients find you - and a lot of the
rest are taken care of by the ORB, which you have to have to be a
CORBA client.

What you pass isn't an "interface instance", it's a locator for an
object that implements the interface. So you can pass an instance on
the server if you really want to, but you can also pass one for the
client.

  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: Current execution frame of another thread?

2005-11-17 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:
> I would like to try a sampling approach to profiling.  My thought is to have
> a profiling thread that samples the execution frame of all the other
> started threads.  I don't see any path from the threads returned by
> threading.enumerate() to their current frames.  Am I missing something?


Just another thought: Maybe stackless python can be of use here - as it 
epxlicits the stack frame, you might be able to inspect it. But I 
_think_ basically the same limitations apply as in my other post - you'd 
need to be able to stop a thread, scan its frame, and reschedule it.

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


Re: Python obfuscation

2005-11-17 Thread Stephen Kellett
In message <[EMAIL PROTECTED]>, The 
Eternal Squire <[EMAIL PROTECTED]> writes
>My point exactly.  A good application of moderate to large size (100K
>lines of code) is about as large as a single person can write without
>automation,

You have not been working with the right people. They do exist, but they 
are rare.

Stephen
-- 
Stephen Kellett
Object Media Limitedhttp://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Library Reference - question

2005-11-17 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
> The "Python LIbrary Reference" at
> http://docs.python.org/lib/contents.html seems to be an important
> document. I have two questions
> 
> Q1. How do you search inside "Python LibraryReference" ? Does it exist
> in pdf or chm form?

One other option.  Go to google and use:

 site:docs.python.org inurl:lib

That should work, though I haven't tested it thoroughly.

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


Re: Python obfuscation

2005-11-17 Thread Mike Meyer
Chris Mellon <[EMAIL PROTECTED]> writes:
> Your rights are anything you can do that is not forbidden - the US
> constitution is explicitly designed in this way, something that people
> often forget. There is no difference between an "explicit" and an
> "inferred" right, by design. If you read the text of the US
> constitution, even the phrasing makes this clear. In fact, the format
> of the Bill of Rights was considered harmful by some of the founding
> fathers, because they felt that people would interpert it exactly as
> they have - as enumerating the limits of government power, instead of
> enumerating the powers themselves.

It should be noted that the 10th amendment was added to the bill of
rights to deal with this fear. It states explicitly that any rights
not listed were reserved to the states or the public.

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


Any help with PLY?

2005-11-17 Thread mark . green
Hi folks,

I've been trying to write a PLY parser and have run into a bit of
bother.

At the moment, I have a RESERVEDWORD token which matches all reserved
words and then alters the token type to match the reserved word that
was detected.  I also have an IDENTIFIER token which matches
identifiers that are not reserved words.

The problem is, if I put RESERVEDWORD before IDENTIFIER, then
identifiers that happen to begin with reserved words are wrongly lexed
as the reserved word followed by an identifier.  For example, because
"if" is a RESERVEDWORD, the string "ifollowyou" is wrongly lexed as the
RESERVEDWORD "if" followed by IDENTIFIER "ollowyou", rather than just
as the IDENTIFIER "ifollowyou".

If I put IDENTIFIER first, though, every single reserved word in the
input is lexed as an IDENTIFIER.

Is there any way I can tell PLY that it should only return a
RESERVEDWORD in the correct circumstances?  If PLY can't do this, can
any of the other Python parser generators?  (It seems that Lex can..)

Thanks!

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


Re: is parameter an iterable?

2005-11-17 Thread Roy Smith
Micah Elliott  <[EMAIL PROTECTED]> wrote:
> I recently gave up on trying to support (backport to) pre-2.2 in my
> projects.  It's been ~3 years since 2.2 released and that seem like a
> pretty reasonable support window.

It depends on what you're doing.  If you're developing for in-house
use, you have control over what you run and can upgrade whenever you
feel you can justify devoting the resources to the upgrade effort.  If
you're a one-man band, upgrading to a new version may be an hour's
work to download and install the latest and greatest.  If you're a cog
in a large organization, it may be quite a bit more hassle.

If you're developing for outside customers, it's a whole different
story.  Lots of people are running operating systems which are several
years old (heck, I'm typing this on a Windows-2000 box), and those
operating systems may have shipped with versions of langauges which
were several years old at the time they shipped.

Consider the following conversation with a prospective customer:

Prospect: "I really love your product, the price is OK, and I've got
budget approval for the purchase.  Now, what do we need to run it?"

You: "All you need is a box running Python 2.2".

Prospect: "Oh, bummer, we run 2.1 [or 2.0, or 1.5.2] in-house on all
our machines".

You: "No problem, it's easy to upgrade to 2.2"

Prospect: "Unfortunately, not around here it isn't.  I.T. owns the
servers, and they won't do the upgrade.  Looks like we won't be able
to use your product after all.  Sorry."

I'm not saying you shouldn't use new stuff, but don't fool yourself
about how long a lifetime old versions have in the field.  And, the
old adage that "The customer is always right" is a good one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: install python2.4 on FreeBSD and keep using python2.3

2005-11-17 Thread Mike Meyer
Ksenia Marasanova <[EMAIL PROTECTED]> writes:

> Hi,
>
> I have python2.3, installed from port /lang/python long time ago. The
> current version is 2.4, but I'd rather have two python versions,
> instead of upgrading.
> Is there maybe a way to somehow link installed python to
> /lang/python2.3 port, and then upgrade ports and install /lang/python
> as a new (2.4) version, without upgrading?
> Or am I missing something and the things are much easier? I am not a
> FreeBSD guru and it's my first python upgrade... thanks!

You can't install from ports and keep multiple versions around. Well,
at least not easily. You'll have to install from the Python
sources. If you haven't changed LOCALBASE, then installing from
sources will overwrite the things installed in /usr/local/bin, the
python manual page, and the emacs python-mode file (at least, that's
what's installed by the Python port that isn't in a version-specific
file). As others have said, you can work around that with the --prefix
argument to configure when you build python.

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


catch dbi.program-error ?

2005-11-17 Thread Brian Herbert Withun
I'm having difficulty catching dbi.program-error which occurs this way:

import dbi, odbc
[...]
self.__cur.execute(sql)

>>> dbi.program-error: [Sybase][ODBC Driver][Adaptive Server Anywhere]Table 
>>> 'depfile' not found in EXEC

but

try:
   self.__cur.execute(sql)
except dbi.program-error,e:
   print " caught "
   raise

causes

>>> except dbi.program-error, e:
>>> AttributeError: 'module' object has no attribute 'program'


What, in general, is the offender here?  The hyphen in
"dbi.program-error" or the dot?

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


Re: How to write an API for a Python application?

2005-11-17 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Paul Boddie <[EMAIL PROTECTED]> wrote:
.
.
.
>meaning that callbacks and other things just work. Rolling your own
>solution, on the other hand, can end in a long road discovering what
>those CORBA people were doing for all those years.
>
>I suppose if CORBA is too heavy, there's always PYRO. I can't comment
.
.
.
Indeed, Paul:  those who scorn CORBA often *do* re-create it,
poorly.

I still don't think it's the right answer for Mr. Kshepitzki.
Pyro might be perfect.  My own instinct is to start even more
primitively, with a minimal asynchat client and server.  I've
looked through the *Cookbook*, and see that it doesn't have
what I want.  Maybe it's time Phaseit donate one of the
little models we use ...  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python obfuscation

2005-11-17 Thread Alex Martelli
Anton Vredegoor <[EMAIL PROTECTED]> wrote:
   ...
> Maybe this micropayment thing is already working and active. What is
> the cost of a mouseclick and what is the monetarial value of the fact
> that someone is clicking on a link? Someone bought virtual property for

I believe that all of the currently dominant models for pricing in this
field are based on auctions -- each would-be advertiser bids how many
cents (or dollars;-) a click-through into their advertisement is worth
to them, Google or one of our competitors shows the "highest bidding"
ads for a query or site (adjusted by all sort of factors, such as for
example the click-through rates), and money changes "hands" only if a
click-through does happen (the amount of money involved may be the
amount that was bid, or a lesser one based for example on a
"second-price auction" or other mechanisms yet -- there's a lot of
fascinating economic literature on auction mechanisms and the various
effects slightly different mechanisms may have).

If an auction mechanism is well-designed and tuned in minute detail, it
will presumably determine accurately the "monetarial value of [a click]
on a link" when that link is an ad paid for by such a mechanism.  Value
of clicks on other kinds of links is harder to compute, of course, since
the monetization may be extremely indirect, if one exists at all.

> real money and sold it later with a lot of profit. There are pages
> where one can buy pixels. Maybe me replying to you will provoke some
> other chain of events with payoffs for you or me (I hope positive :-)

Maybe -- but you'd have to estimate the probabilities in order to
estimate the expected payoffs;-).

> The idea of using a webservice to hide essential secret parts of your
> application can only work well if one makes some random alterations to
> the results of the queries. Like GPS signals that are deliberately made

I disagree on this general statement and I have already given two
counterexamples:

a. a webservice which, for some amount X of money, gives an excellent
heuristic estimate of a good cutting-path for a woodcutting tool (for a
set of shapes to be cut out of standard-sized planks of wood by a
numerically driven cutter): this is a case where ESR, acting as a
consultant, advised his clients (who had developed a heuristic for this
task which saved a lot of wood compared to their competitors') to keep
their code closed-source, and it makes a good use case for the "hide
essential secret parts" in general;

b. a (hypothetical) website that, given time-space coordinates (and some
amount Y of money), produces and returns weather predictions that are
better than those you can get from its competitors.

It appears to me that any application of this kind could work well
without at all "making random alterations" to whatever.  Point is, if
you develop a better algorithm (or, more likely, heuristic) for good
solutions to such problems, or predictions of just about anything which
might have economic value to somebody, using a webservice to hide the
essential secret parts of your discovery is an option, and it might be a
preferable alternative to relying on patents (since software patents may
not be enforceable everywhere in the world, and even where they're
nominally enforceable it could prove problematic and costly to actually
deter all would-be competitors from undercutting you).  I do not see
anything in your post that contradicts this, except the bare unsupported
assertion that a webservice "can only work well if one makes random
alterations".

> But the more one messes with the ideal output the more often the user
> will rather click another link. (or launch another satellite)

Of course.  If my "better weather predictor" is in fact based not on
inventing some new algorithm/heuristic, but on having better or more
abundant raw data due to my private network of satellites or other
observation platforms, this doesn't change the economic situation by all
that much (except that patenting may not even be an option in the latter
case, if there's no patentable innovation in that private network); a
competitor *could* reach or surpass my predictions' quality by investing
enough to re-develop the heuristic or duplicate the sensors-network.
So, my pricing should probably take that risk into account.

Deliberately giving predictions worse than I could have given, in this
context, seems a deliberate self-sabotage without any return.

> what's the current exchange rate for clicks and dollars?

As far as I know, it varies wildly depending on the context, but I
suspect you can find ranges of estimates on the web.


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


how to organize a module that requires a data file

2005-11-17 Thread Steven Bethard
Ok, so I have a module that is basically a Python wrapper around a big 
lookup table stored in a text file[1].  The module needs to provide a 
few functions::

 get_stem(word, pos, default=None)
 stem_exists(word, pos)
 ...

Because there should only ever be one lookup table, I feel like these 
functions ought to be module globals.  That way, you could just do 
something like::

 import morph
 assist = morph.get_stem('assistance', 'N')
 ...

My problem is with the text file.  Where should I keep it?  If I want to 
keep the module simple, I need to be able to identify the location of 
the file at module import time.  That way, I can read all the data into 
the appropriate Python structure, and all my module-level functions will 
work immediatly after import.

I can only think of a few obvious places where I could find the text 
file at import time -- in the same directory as the module (e.g. 
lib/site-packages), in the user's home directory, or in a directory 
indicated by an environment variable.  The first seems weird because the 
text file is large (about 10MB) and I don't really see any other 
packages putting data files into lib/site-packages.  The second seems 
weird because it's not a per-user configuration - it's a data file 
shared by all users.  And the the third seems weird because my 
experience with a configuration depending heavily on environment 
variables is that this is difficult to maintain.

If I don't mind complicating the module functions a bit (e.g. by 
starting each function with "if _lookup_table is not None"), I could 
allow users to specify a location for the file after the module is 
imported, e.g.::

 import morph
 morph.setfile(r'C:\resources\morph_english.flat')
 ...

Then all the module-level functions would have to raise Exceptions until 
setfile() was called.  I don't like that the user would have to 
configure the module each time they wanted to use it, but perhaps that's 
unaviodable.

Any suggestions?  Is there an obvious place to put the text file that 
I'm missing?

Thanks in advance,

STeVe

[1] In case you're curious, the file is a list of words and their 
morphological stems provided by the University of Pennsylvania.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >