ANN: 4 little Python programs

2006-05-05 Thread RM
I recently got access to one of those new GooglePages and decided to
play around with it a little. I figured it would be a nice *easy* way
to get a website going. I may eventually do something more
professional, but hey, this was free in both money and time. :)

I had been thinking of releasing some of my little personal apps for a
while. So, this finally motivated me to clean them up enough for
release. The website is not yet finished, but I couldn't wait to share
with you these little Python programs. I have packaged them nicely for
Windows using py2exe and InnoSetup.  Unfortunately, I haven't had the
time to do the same for Linux.  I plan to that soon.  You can get them
here.

http://rmcorrespond.googlepages.com/customsoftware

I have been using them for several years, but never got around to
releasing them. Any way, I hope you like them. Oh, they are all
licensed with the GPL, but for now I am only making the source
available upon request. If you have any questions or suggestions let me
know. 
 
-Ruben

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Leipzig Python User Group - Meeting, May 9 2006, 8:00pm

2006-05-05 Thread Mike Mueller
=
Leipzig Python User Group
=

Next Meeting Tuesday, May 9 2006
---

We will meet on April 9 at 8:00 pm at the 
training center of Python Academy in Leipzig, 
Germany (http://www.python-academy.com/center/find.html).

Ralf Muschall will talk about Tkinter, the GUI 
toolkit that comes with a Python standard installation.

Food and soft drinks are provided. Please send a short confirmation
mail to [EMAIL PROTECTED], so we can prepare appropriately.

Everybody who uses Python, plans to do so or is 
interested in learning more about the language is encouraged to participate.

While the meeting language will be mainly German, 
English speakers are very welcome. We will 
provide English interpretation if needed.

Current information about the meetings can always be found at
http://www.python-academy.com/user-group/index.html




=
Leipzig Python User Group
=

Stammtisch am 09.05.2006
-

Wir treffen uns am 09.05.2006 um 20:00 Uhr wieder im
im Schulungszentrum der Python Academy in Leipzig 
(http://www.python-academy.de/Schulungszentrum/anfahrt.html).


Diesmal wird Ralf Muschall über die Anwendung von 
Tkinter, der Bibliothek für grafische 
Nutzeroberflächen, die in der 
Standard-Python-Installation enthalten ist, sprechen.


Für das leibliche Wohl wird gesorgt.
Wir bitten um kurze Anmeldung per e-mail an: [EMAIL PROTECTED]

An den Treffen der Python Anwendergruppe kann 
jeder teilnehmen, der Interesse an Python hat, 
die Sprache bereits nutzt oder nutzen möchte.

Die Arbeitssprachen des Treffens ist Deutsch. 
Englisch sprechende Python-Enthusiasten sind 
trotzdem herzlich eingeladen. Wir übersetzen gern.

Aktuelle Informationen zu den Treffen sind immer unter
http://www.python-academy.de/User-Group/index.html
zu finden.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Can I use python for this .. ??

2006-05-05 Thread Terry Reedy

placid [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
.)

 When you hibernate/boot up/hibernate for a long time without a clean
 reboot, Windows becomes unstable...

This seems to depend on the system.  I have gone at least a week, maybe 
two, with nightly hibernations and no problems.  Maybe you meant much 
longer than that.  But installs and updates often require reboots anyway.

tjr



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


Re: Possible constant assignment operators := and ::= for Python

2006-05-05 Thread Michele Simionato
Edward Elliott wrote:
 Michele Simionato wrote:
   A = []  # let's declare a constant here
   b = A   # and let's assign the constant here
   b.append('1') # OOPS!
 
  But it makes no sense to use a mutable object for a constant!
  The user should use a tuple,

 Sure.  Now show me the builtin immutable equivalent of a dict.

There is none. However it is pretty easy to get one:

import UserDict

class ReadOnlyDict(UserDict.DictMixin):
def __init__(self, dic):
self._dic = dic
def __getitem__(self, name):
return self._dic[name]
def keys(self):
return self._dic.keys()
def __getitem__(self, name):
raise TypeError('this dictionary is read-only')
def __delitem__(self, name):
raise TypeError('this dictionary is read-only')

I am sure you already know that, this snipped is for the benefit of the
other
readers of this thread. Of course, the ReadOnlyDict can be modified by
modifying ._dic, but the point was all about avoiding accidental
modifications.

  or a custom list-like type where
  all methods with side effects are removed, so it effectively acts
  as a tuple.

 Ugh, not worth the trouble imo.

Agreed, use a tuple if you need a tuple.

   Michele Simionato

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


Re: Tuple assignment and generators?

2006-05-05 Thread Michele Simionato
Carl Banks wrote:
  q = 0
  r = 0
  s = 0
  id(q)
 134536636
  id(r)
 134536636
  id(s)
 134536636


 It is okay with constant object, really.

No:

 r=11
 s=11
 t=11
 id(r)
135620508
 id(s)
135620532
 id(t)
135104688

It worked with the number 0 because of an implementation accident,
in general Python can use different ids for constant objects that are
equals in the == sense.

 Michele Simionato

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


Embedding Python: How to run compiled(*.pyc/*.pyo) files using Python C API?

2006-05-05 Thread Shankar
Hello,

I am trying to run compiled Python files (*.pyc and *.pyo) using Python C
API.

I am using the method PyRun_FileFlags() for this purpose.

The code snippet is as follows:-

PyCompilerFlags myFlags;
myFlags.cf_flags=1; // I tried all values 0, 1 and 2
PyRun_FileFlags(script, file, Py_file_input, globals, locals, myFlags);

But unfortunately I get the following exception:-
DeprecationWarning: Non-ASCII character '\xf2' in file E:\test.pyc on line
1, but no encoding declared; see http://www.python.org/peps/pep-0263.html
for details

When I run the .py file, then things work fine.
The .py file contains only one statement,
print Hello World

Which Python C API should I use to run compiled Python files(*.pyc and
*.pyo) in the scenario where the source file (*.py) is not present.

Thanks in advance,
Regards,
Shankar



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


Job opportunity in France

2006-05-05 Thread Rony Steelandt
We have a vacancy for a python programmer for a 6 months assignement.

If interested, please visit www.bucodi.com

And don't worry we speak english :)

R_

-- 
---
Rony Steelandt
BuCodi
rony dot steelandt (at) bucodi dot com

Visit the python blog at http://360.yahoo.com/bucodi


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


Re: Tuple assignment and generators?

2006-05-05 Thread vdrab
Wow, so, to see if I understand correctly:

 r = 0
 s = 0
 t = 11
 u = 11
 r == s
True
 t == u
True
 r is s
True
 t is u
False
 ... ?

what the...? 
does anybody else get mighty uncomfortable about this? 
s.

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


Re: Tuple assignment and generators?

2006-05-05 Thread Erik Max Francis
vdrab wrote:

 what the...? 
 does anybody else get mighty uncomfortable about this? 

No.  Why should you ever care about whether two integers representing 
values are the same object?  Your tests should be with `==`, not `is`.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   More fodder for the new lost generation
   -- Nik Kershaw
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __init__.py, __path__ and packaging

2006-05-05 Thread Sandro Dentella
   Now, why you couldn't do dbg.DBG = ...? Very simple... from
 module import * doesn't give you a dbg /module/, it only gives you
 references to each piece inside the module.

  really the reason why I wanted that should probably be solved in other
  ways. I just wanted to split my dbg module in different files but load the
  dbg module in one single operation:

  dbg/
  |-- __init__.py
  |-- lib
 |-- __init__.py
 |-- debug.py
 |-- gtk_dbg.py

  and inside dbg/__init__.py I used from dbg.debug import * so that a single 
  'import dbg' could present me the module 'debug' (of course in this simple
  case seems easier to put debug.py directly under dbg, but my main case is
  a much more complex module, with a tree structure that reflects the
  relation between modules that I want to hide to the end user).

  But to summarize, if I use 'from my_module import *' there is no way to reach 
  directly 'my_module' and set a variable there?

Thanks again
sandro
*:-)

 I'm trying to fix the packaging of a very simple package, but some problem
 show me that I have not well understood 
 
 the structure of my package (some debug functions) is as follows:
 
 python/
 `-- dbg/
|-- __init__.py
`-- lib
|-- __init__.py
|-- debug.py
`-- gtk_dbg.py
 
 
 my sys.path includes 'python' and I wanted that the content of debug.py was
 simply included by: 'import dbg', so I wrote dbg/__init__.py as follows:
 
 import os
 Dir = os.path.dirname(__file__)
 __path__ = [os.path.join(Dir, 'lib')]
 from debug import *
 
 
-- 
Sandro Dentella  *:-)
e-mail: [EMAIL PROTECTED] 
http://www.tksql.orgTkSQL Home page - My GPL work
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Job opportunity in France

2006-05-05 Thread Alexandre Fayolle
Le 05-05-2006, Rony [EMAIL PROTECTED] nous disait:
 We have a vacancy for a python programmer for a 6 months assignement.

Hi Rony,

You may find interested people on fr.comp.lang.python and on the
python-fr mailing list (python at aful dot org), if you post your
announce (in French) on these forums. 


-- 
Alexandre Fayolle  LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:   http://www.logilab.fr/services
Python et calcul scientifique:   http://www.logilab.fr/science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Perl programmers

2006-05-05 Thread Christoph Haas
On Thu, May 04, 2006 at 12:02:52PM -0400, A.M wrote:
 Is there any efficient online resource or book that help experienced Perl 
 programmers to Python?

I've been using Perl for a decade and had a hard start into Python. Mainly
because I used those phrasebooks and tried to convert my Perl syntax
statement-by-statement. However Python doesn't just have another syntax but
also other concepts. It's worth working yourself through the diveintopython
tutorial. Or if you want to spend money I strongly recommend the book
Beginning Python: From Novice to Professional (ISBN 159059519X) because
you learn a lot about daily problems and gotchas, too.

Besides from the I'm cool because I'm the only one who can read my code
factor that Perl delivers Python has everything you need. :)

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


Re: Embedding Python: How to run compiled(*.pyc/*.pyo) files using Python C API?

2006-05-05 Thread Serge Orlov
Shankar wrote:
 Hello,

 I am trying to run compiled Python files (*.pyc and *.pyo) using Python C
 API.

 I am using the method PyRun_FileFlags() for this purpose.

 The code snippet is as follows:-

 PyCompilerFlags myFlags;
 myFlags.cf_flags=1; // I tried all values 0, 1 and 2
 PyRun_FileFlags(script, file, Py_file_input, globals, locals, myFlags);

 But unfortunately I get the following exception:-
 DeprecationWarning: Non-ASCII character '\xf2' in file E:\test.pyc on line
 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html
 for details

Note, it's not an exception, it's a warning.


 When I run the .py file, then things work fine.
 The .py file contains only one statement,
 print Hello World

 Which Python C API should I use to run compiled Python files(*.pyc and
 *.pyo) in the scenario where the source file (*.py) is not present.

I believe it's PyImport_ImportModule(test)

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


Re: Tuple assignment and generators?

2006-05-05 Thread Diez B. Roggisch
vdrab wrote:

 Wow, so, to see if I understand correctly:
 
 r = 0
 s = 0
 t = 11
 u = 11
 r == s
 True
 t == u
 True
 r is s
 True
 t is u
 False
 ... ?
 
 what the...?
 does anybody else get mighty uncomfortable about this?

#include stdio.h

int main(int argc, char **argv) {
  int a = 1;
  int b = 1;
  printf(a == b: %i\n, a == b);
  printf(a == b: %i\n, a == b);
  return 0;
}

[EMAIL PROTECTED]:/tmp$ ./test
a == b: 1
a == b: 0


Feeling the same might uncomfortableness? Get used to it: object identity
and two objects being part of an equality-relation are two different
beasts. It can get even worse: I can define an object (in C++ as well as in
python) that is not even equal to itself. Not that I felt the need for that
so far

So: don't use object identity where you want equality. In all languages.

Diez

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


Re: Python for Perl programmers

2006-05-05 Thread bruno at modulix
A.M wrote:
 Hi,
 
 Is there any efficient online resource or book that help experienced Perl 
 programmers to Python?
 

My fellow coworker - experimented Perl coder - confirms that the
official tutorial and diveintopython should be enough to get you
started. Also, the Python Cookbook and reading this group may help you
grasp pythonic idioms.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


enriching return values / symetric callreturn in P3K ? - Re: Tuple assignment and generators?

2006-05-05 Thread robert
Tim Chase wrote:
 Just as a pedantic exercise to try and understand Python a bit better, I 
 decided to try to make a generator or class that would allow me to 
 unpack an arbitrary number of calculatible values.  In this case, just 
 zeros (though I just to prove whatever ends up working, having a 
 counting generator would be nice).  The target syntax would be something 
 like
 
   a,b,c = zeros()
   q,r,s,t,u,v = zeros()
 
 where zeros() returns an appropriately sized tuple/list of zeros.
 
 I've tried a bit of googling, but all my attempts have just ended up 
 pointing to pages that blithly describe tuple assignment, not the 
 details of what methods are called on an object in the process.
 
 My first thought was to get it to use a generator:
 
 def zeros():
 while 1: yield 0
 
 However, I get back a ValueError: too many values to unpack result.
 
 As a second attempt, I tried a couple of attempts at classes (I started 
 with the following example class, only derived from object rather than 
 list, but it didn't have any better luck):
 
   class zeros(list):
 ... def __getitem__(self,i):
 ... return 0
 ...
   z = zeros()
   a,b,c = z
 Traceback (most recent call last):
   File stdin, line 1, in ?
 ValueError: need more than 0 values to unpack
 
 
 It looks like I need to have a pre-defined length, but I'm having 
 trouble figuring out what sorts of things need to be overridden.  It 
 seems like I sorta need a
 
 def __len__(self):
 return INFINITY
 
 so it doesn't choke on it.  However, how to dupe the interpreter into 
 really believing that the object has the desired elements is escaping 
 me.  Alternatively if there was a doYouHaveThisManyElements 
 pseudo-function that was called, I could lie and always return true.
 
 Any hints on what I'm missing?

Think the use case, you present, is (pythonically) ill as such. if you 
want to fill literal variable's do it like: a=b=c=...=0.  Otherwise 
you'd handle variable lists zeros(7)

Yet there is a real freqent need for adding transparent extra/decorating 
return values in cases, where you don't want to break the simple return 
scheme (in maybe big existing code). For such use cases check out this 
RICHVALUE approach with _named_ extra values - no puzzles about 
non-matching tuple assignments:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496676  :

...
def f():
 return RICHVALUE(7, extra='hello')

ret=f()
print ret, ret+1, ret.extra
...


As I have this need very very often I'd like to see an even more natural 
builtin method for enriching return values (both positional and by name) 
in Python3000 - maybe by making calling and returning almost symetric!
Yet, this ideas maybe strange ? ...

def f_P3K(*args,**kwargs):
 xreturn((7,8), 3, extra=5, *args, **kwargs)   # first is main

v = f_P3K()# (7,8)
v,x = f_P3K()  # (7,8),3
v,x,*pret,**kwret= f_P3K()
extra=kwret.get('extra',-1)


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


Re: Tuple assignment and generators?

2006-05-05 Thread vdrab
 No.  Why should you ever care about whether two integers representing
 values are the same object?  Your tests should be with `==`, not `is`.

Given this though, what other such beauties are lurking in the
interpreter, under the name of 'implementation accidents'? One of the
things that drew me to python is the claimed consistency and
orthogonality of both language and implementation, not sacrificing
clarity for performance, minimizing ad-hoc design hacks and weird
gotcha's, etc...
In fact, I think my code contains things like if len(arg) is 0: and
so on, and I feel I should be able to do so given the way python treats
(claims to treat?) constant objects, even if I don't care whether the
values actually represent the same object.
s.

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


Re: noob question: TypeError wrong number of args

2006-05-05 Thread bruno at modulix
Edward Elliott wrote:
 bruno at modulix wrote:
 
Edward Elliott wrote:

Ah, well then, there's no need for a full-blown parser.  It should
suffice to recognize a class definition and modify the parameter list of
every def indented one level further than that.

won't do :

class CounterExample(object):
  if compute_some_const_according_to_phase_of_moon():
def meth(...):
  do_something(self, 42)
 
 
 Uuunn, you got me pardner.  (cough, cough) my hands, they're so cold. 
 bruno?  where'd you go, bruno?  i can't see you anymore.  are we back on
 the farm?  tell ma i love her.  (clunk)
 

We'll remember you foreever Eddy...

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange Threads Behaviour...

2006-05-05 Thread rodmc
Hi Diez,

No this occurs when the client is executed. Basically it runs as you
see above then terminates. It should be noted that the errors involving
the /xmpp libraries seem to change each time. I have no doubt it is
connected to that, but the error does not happen at all when I run the
client through IDLE.

Best,

rod

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


Re: Tuple assignment and generators?

2006-05-05 Thread vdrab
 beasts. It can get even worse: I can define an object (in C++ as well as in
 python) that is not even equal to itself. Not that I felt the need for that
 so far

hehe... now you've picked my curiosity... how?

ps.
def __eq__(self, other): return False
does not count !

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


Re: Possible constant assignment operators := and ::= for Python

2006-05-05 Thread Fredrik Lundh
Christophe wrote:

 I think you've made a mistake in your example.

  constant A = []
  def foo(var):
 ... var.append('1')
 ... print var
 ...
  b = A
  foo(b)
  foo(b)

  and this ?
 
   constant A = []
   print A is A

 Obviously, False.

why obviously ? why shouldn't a constant be constant ?

/F 



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


Re: Tuple assignment and generators?

2006-05-05 Thread Diez B. Roggisch
vdrab wrote:

 beasts. It can get even worse: I can define an object (in C++ as well as
 in python) that is not even equal to itself. Not that I felt the need for
 that so far
 
 hehe... now you've picked my curiosity... how?
 
 ps.
 def __eq__(self, other): return False
 does not count !

Sure it does! The rich comparison methods can very well be used to define
whatever semantics you want. Now I agree that 

def __eq__(self, other):
if self is other:
   return False
... # do something more sane


doesn't make much sense usually. Or maybe even never. Still, it illustrates
the point: object identity is not to be confused with two objects being
part of an equality relation.

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


Re: Tuple assignment and generators?

2006-05-05 Thread Fredrik Lundh
vdrab wrote:

 Given this though, what other such beauties are lurking in the
 interpreter, under the name of 'implementation accidents'? One of the
 things that drew me to python is the claimed consistency and
 orthogonality of both language and implementation, not sacrificing
 clarity for performance, minimizing ad-hoc design hacks and weird
 gotcha's, etc...

so anything you don't understand, and cannot be bothered to look up in
the documentation, just has to be an inconsistent ad-hoc weird-gotcha
design ?

I think we can all safely *plonk* you know.

/F 



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


SIGTERM handling

2006-05-05 Thread Manlio Perillo
Hi.

I have tried this script:

from ctypes import cdll, c_int
from signal import SIGTERM, SIGINT
from time import sleep


msvcrt = cdll.LoadLibrary(MSVCR71) # is this the lib to use?
sig = c_int(SIGTERM)
raise_ = getattr(msvcrt, raise)
raise_(sig)
sleep(10)


The problem is that SIGTERM causes the program to exit (without calling
atexit registered functions).

Why?
In the MSDN documentations it is written that SIGTERM is by default
ignored and in the Python documentation for signal module it is written
that there should be no handler for SIGTERM.



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


Re: Tuple assignment and generators?

2006-05-05 Thread Diez B. Roggisch
vdrab wrote:

 No.  Why should you ever care about whether two integers representing
 values are the same object?  Your tests should be with `==`, not `is`.
 
 Given this though, what other such beauties are lurking in the
 interpreter, under the name of 'implementation accidents'? One of the
 things that drew me to python is the claimed consistency and
 orthogonality of both language and implementation, not sacrificing
 clarity for performance, minimizing ad-hoc design hacks and weird
 gotcha's, etc...
 In fact, I think my code contains things like if len(arg) is 0: and
 so on, and I feel I should be able to do so given the way python treats
 (claims to treat?) constant objects, even if I don't care whether the
 values actually represent the same object.

Python doesn't claim that 0 is 0 == True. You are abusing the is operator.
The only (or at least 99%) occasions I use is are 

if foo is None:
   ...

as None is guaranteed to be a singleton object. 

The thing you observe as accident is that sometimes 0 is 0 is true just
because of an optimization of number objects allocation. Such things happen
in the real world - other examples are string-interning in e.g. the JVM
(and I bet they have a similar scheme to boxed number object allocation as
python has).

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


ISSPR2006_School_etc.:NEW_EXTENDED_Deadline

2006-05-05 Thread andrea

REGISTER NOW FOR PATTERN RECOGNITION EVENTS THIS SUMMER, 2006

___
4TH INTERNATIONAL SUMMER SCHOOL ON PATTERN RECOGNITION (ISSPR, 2006)
23-28 JULY, UK

http://www.PatternRecognitionSchool.com

NEW...EXTENDED Early Bird Deadline for Registration. 
New Deadline 25th May 2006! and payments can be made Online

CALL FOR PARTICIPATION
The 4th International Summer School on Pattern Recognition will be organised at 
the University of Plymouth, UK (23-28 July, 2006). The  school programme is 
listed below. Please pass on this email to your interested colleagues and 
students. This is a  great summer school which I would recommend for everyone 
to attend. 
DEADLINE: Register BEFORE 01 MAY, 2006 through the website to get a discount on 
the fee. More than 100 participants in 2005!

Speakers at the Summer School (ISSPR'2006)
Dr. Sam Roberts Mathworks, UK (Introduction to Matlab)
Prof. Wojtek Krzanowski University of Exeter, UK (Multivariate Statistics: Data 
Description)
Dr. Mike Tipping, Microsoft Research, UK (Bayesian Pattern Recognition: 
Principles and Practice)
Prof. Chris Bishop, Microsoft Research, UK (Latent Variables, Mixture Models 
and EM)
Dr. Richard Everson, University of Exeter, UK (Dimensionality Reduction)
Dr. Peter Tino  University of Birmingham, UK (Probabilistic framework for 
model-based topographic map formation)
Prof. Chris Williams, University of Edinburgh, UK (Neural Networks and Kernel 
Machines) 
Dr. Colin Campbell, University of Bristol, UK (Support Vector Machines and 
Kernel Methods: An Introduction and  Review)
Prof. John Shawe- Taylor, University of Southampton, UK (Kernel Based Methods)
Dr. Steve Gunn, University of Southampton, UK (Matlab for Support Vector 
Machines)
Prof. Mahesan Niranjan, University of Sheffield, UK (Classifier Performance 
Particle Filters for Tracking and  Sequential Problems) 
Dr. Andrew Webb Qinetiq, UK (Decision TreesData Clustering)
Prof. Xin Yao, University of Birmingham, UK (A Gentle Introduction to 
Evolutionary Computation; ATutorial on  Evolutionary Multi-objective 
Optimisation) 
Dr. Richard Deardon, University of Birmingham, UK (Sequential Decision Making; 
Markov Chains Monte Carlo Methods)
Dr. Jeremy Wyatt, University of Birmingham, UK (An Introduction to 
Reinforcement Learning)
Dr. Ludmila Kuncheva, University of Wales, UK   (Classifier Combination)
Prof. Joseph Kittler, University of Surrey, UK  (Feature Selection and 
Extraction)
Prof. Sameer Singh, Loughborough University, UK (Multiresolution Pattern 
Recognition)
Prof. Susan Craw, Robert Gordon University, UK  (Case Based Reasoning)
SUPPORTED BY: Microsoft, Springer, British Computer Society, and Mathworks. 
___
IEEE CVPR CONFERENCE
www.CVPR.org/2006
17-22 June, 2006
Registration Deadline is now 2nd of June, 2006
___
18th INTERNATIONAL CONFERENCE ON PATTERN RECOGNITION 
www.comp.hkbu.edu.hk/~icpr06
August 20-24, 2006
Early Bird Registration: 31 May, 2006
__
Please see the event websites to get FULL information.

Compiled by: Dr. Heather Mclleland 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I use python for this .. ??

2006-05-05 Thread san
Rick

Thanks for your reply .. didnt quite get your point in loggin into
password protected site.
Will try to seach this group for more ..

Still looking for tab browsing and logging in password protected site
..

can i use ctype or something like that .. some modute that will
introduce key strokes .. so that i can do username tab password
enter so that i can log in .. ??

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


Re: Tuple assignment and generators?

2006-05-05 Thread vdrab
 so anything you don't understand, and cannot be bothered to look up in
 the documentation, just has to be an inconsistent ad-hoc weird-gotcha
 design ?

Does the documentation mention that x is y returns True when they are
both 0 but not when they are 11 ? If so, I stand corrected. *plonk*
away ...
s.

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


Re: Tuple assignment and generators?

2006-05-05 Thread Daniel Nogradi
  Given this though, what other such beauties are lurking in the
  interpreter, under the name of 'implementation accidents'? One of the
  things that drew me to python is the claimed consistency and
  orthogonality of both language and implementation, not sacrificing
  clarity for performance, minimizing ad-hoc design hacks and weird
  gotcha's, etc...

 so anything you don't understand, and cannot be bothered to look up in
 the documentation, just has to be an inconsistent ad-hoc weird-gotcha
 design ?

 I think we can all safely *plonk* you know.

I was just at a point when I thought I learned something but got
confused again after trying the following and unfortunately didn't
find an answer in the docs.

 a = 10
 b = 10
 id(a)
134536516
 id(b)
134536516

So the two memory addesses are the same, but

 a = 1
 b = 1
 id(a)
134604216
 id(b)
134604252

and they are not the same (I restarted the interpreter between the two
cases). So how is this now? Sorry if it's too trivial, but I simply
don't get it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple assignment and generators?

2006-05-05 Thread Alexandre Fayolle
Le 05-05-2006, Diez [EMAIL PROTECTED] nous disait:

 The thing you observe as accident is that sometimes 0 is 0 is true just
 because of an optimization of number objects allocation. Such things happen
 in the real world - other examples are string-interning in e.g. the JVM
 (and I bet they have a similar scheme to boxed number object allocation as
 python has).

String interning is available in Python too, by using the intern()
builtin function. 

-- 
Alexandre Fayolle  LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:   http://www.logilab.fr/services
Python et calcul scientifique:   http://www.logilab.fr/science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple assignment and generators?

2006-05-05 Thread Fredrik Lundh
vdrab wrote:

 Does the documentation mention that x is y returns True when they are
 both 0 but not when they are 11 ?

language reference, comparisions (is operator):

The operators is and is not test for object identity: x is y is true if and
only if x and y are the same object

language reference, objects:

Even the importance of object identity is affected in some sense: for
immutable types, operations that compute new values may actually
return a reference to any existing object with the same type and value,
while for mutable objects this is not allowed. E.g., after a = 1; b = 1,
a and b may or may not refer to the same object with the value one,
depending on the implementation, but after c = []; d = [], c and d are
guaranteed to refer to two different, unique, newly created empty lists.

(note the use of may or may not and depending on the implementation)

/F 



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


Re: Tuple assignment and generators?

2006-05-05 Thread Diez B. Roggisch
 
 I was just at a point when I thought I learned something but got
 confused again after trying the following and unfortunately didn't
 find an answer in the docs.
 
 a = 10
 b = 10
 id(a)
 134536516
 id(b)
 134536516
 
 So the two memory addesses are the same, but
 
 a = 1
 b = 1
 id(a)
 134604216
 id(b)
 134604252
 
 and they are not the same (I restarted the interpreter between the two
 cases). So how is this now? Sorry if it's too trivial, but I simply
 don't get it.

It's an optimization scheme that will cache number objects up to a certain
value for optimized reuse. However this is impractical for larger numbers -
you only hold a table of lets say 1000 or so objects. Then the look up of
one of those objects is extremely fast, whereas the construction of
arbitrary numbers is somewhat more expensive.

And as is is the operator for testing if objects are identical and _not_
the operator for testing of equality (which is ==), the above can happen.
And is totally irrelevant from a practical POV (coding-wise that is - it
_is_ a relevant optimization).

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


Re: Tuple assignment and generators?

2006-05-05 Thread Daniel Nogradi
  I was just at a point when I thought I learned something but got
  confused again after trying the following and unfortunately didn't
  find an answer in the docs.
 
  a = 10
  b = 10
  id(a)
  134536516
  id(b)
  134536516
 
  So the two memory addesses are the same, but
 
  a = 1
  b = 1
  id(a)
  134604216
  id(b)
  134604252
 
  and they are not the same (I restarted the interpreter between the two
  cases). So how is this now? Sorry if it's too trivial, but I simply
  don't get it.

 It's an optimization scheme that will cache number objects up to a certain
 value for optimized reuse. However this is impractical for larger numbers -
 you only hold a table of lets say 1000 or so objects. Then the look up of
 one of those objects is extremely fast, whereas the construction of
 arbitrary numbers is somewhat more expensive.

 And as is is the operator for testing if objects are identical and _not_
 the operator for testing of equality (which is ==), the above can happen.
 And is totally irrelevant from a practical POV (coding-wise that is - it
 _is_ a relevant optimization).

Thanks a lot! So after all I really learned something :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple assignment and generators?

2006-05-05 Thread vdrab

language reference, objects:

Even the importance of object identity is affected in some sense:
for
immutable types, operations that compute new values may actually
return a reference to any existing object with the same type and
value,
while for mutable objects this is not allowed. E.g., after a = 1;
b = 1,
a and b may or may not refer to the same object with the value one,
depending on the implementation, but after c = []; d = [], c and
d are
guaranteed to refer to two different, unique, newly created empty
lists.

(note the use of may or may not and depending on the
implementation)

/F

That, I knew. What I did not know, nor get from this explanation, is
that this behaviour may differ
not only within the same implementation, but with instances of the same
class or type (in this case, 'int'). Is this really a case of me being
too dumb or too lazy, or could it just be that this behaviour is not
all that consistent ?
v.
v.

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


Re: Subclassing array

2006-05-05 Thread TG
That's great, thanks !

To put it short, when I create a Stimulus object, it first seek
__new__() method. But if I don't define it, it looks for the one
defined in Vector. This raises a problem because the parameters passed
to Stimulus(params) aren't fitting with Vector parameters, raising an
exception.

That's why I have to use this *arg **kw syntax in order to allow my
subclasses having any arguments without causing troubles. Am I right ?

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


Is this a good use of __metaclass__?

2006-05-05 Thread Joel Hedlund
Hi!

I need some input on my use of metaclasses since I'm not sure I'm using them in 
a pythonic and graceful manner. I'm very grateful for any tips, pointers and 
RTFMs I can get from you guys.

Below, you'll find some background info and an executable code example.

In the code example I have two ways of doing the same thing. The problem is 
that the Neat version doesn't work, and the Ugly version that works gives 
me the creeps.

The Neat version raises a TypeError when I try the multiple inheritance 
(marked with comment in the code):

Traceback (most recent call last):
   File /bioinfo/yohell/pybox/gridjs/gridjs-2.0/test.py, line 132, in ?
 class FullAPI(JobAPI, UserAPI, AdminAPI):
   File /bioinfo/yohell/pybox/gridjs/gridjs-2.0/test.py, line 43, in __new__
 return type.__new__(cls,classname,bases,classdict)
TypeError: Error when calling the metaclass bases
 metaclass conflict: the metaclass of a derived class must be a 
(non-strict) subclass of the metaclasses of all its bases

In the Ugly version, I'm changing the metaclass in the global scope between 
class definitions, and that gives me bad vibes.

What should I do? Is there a way to fix my Neat solution? Is my Ugly 
solution in fact not so horrid as I think it is? Or should I rethink the whole 
idea? Or maybe stick with decorating manually (or in BaseAPI.__init__)?

Sincere thanks for your time.

Cheers!
/Joel Hedlund




Background
##
(feel free to skip this if you are in a hurry)
I'm writing an XMLRPC server that serves three types of clients (jobs, users 
and admins). To do this I'm subclassing SimpleXMLRPCServer for all the 
connection work, and I was planning on putting the entire XMLRPC API as public 
methods of a class, and expose it to clients using .register_instance(). Each 
session is initiated by a handshake where a challenge is presented to the 
client, each method call must then be authenticated using certificates and 
incremental digest response. Each client type must be authenticated 
differently, and each type of client will also use a discrete set of methods.

At first, I was planning to use method decorators to do the validation, and 
have a different decorator for each type of client validation, like so:

class FullAPI:
 @valid_job_required
 def do_routine_stuff(self, clientid, response, ...):
 pass
 @valid_user_required
 def do_mundane_stuff(self, clientid, response, ...):
 pass
 @valid_admin_required
 def do_scary_stuff(self, clientid, response, ...):
 pass
 ...

There will be a lot of methods for each client type, so this class would become 
monstrous. Therefore I started wondering if it weren't a better idea to put the 
different client APIs in different classes and decorate them separately using 
metaclasses, and finally bring the APIs together using multiple inheritance. 
This is what I had in mind:

class BaseAPI(object):
 pass

class JobApi(BaseAPI):
 pass

class UserApi(BaseAPI):
 pass

class AdminApi(BaseAPI):
 pass

class FullApi(JobAPI, UserAPI, AdminAPI):
 pass

Now, I'm having trouble implementing the metaclass bit in a nice and pythonic 
way.



Code example


test.py
===
# Base metaclass for decorating public methods:
from decorator import decorator

@decorator
def no_change(func, *pargs, **kwargs):
 return func(*pargs, **kwargs)

class DecoratePublicMethods(type):
 Equip all public methods with a given decorator.

 Class data members:
 decorator = no_change: decorator
 The decorator that you wish to apply to public methods of the class
 instances. The default does not change program behavior.
 do_not_decorate = []: iterable str
 Names of public methods that should not be decorated.
 multiple_decoration = False: bool
 If set to False, methods will not be decorated if they already
 have been decorated by a prior metaclass.
 decoration_tag = '__public_method_decorated__': str
 Decorated public methods will be equipped with an attribute
 with this name and a value of True.

 

 decorator = no_change
 do_not_decorate = []
 multiple_decoration = True
 decoration_tag = '__public_method_decorated__'

 def __new__(cls,classname,bases,classdict):
 for attr,item in classdict.items():
 if not callable(item):
 continue
 if attr in cls.do_not_decorate or attr.startswith('_'):
 continue
 if (not cls.multiple_decoration
 and hasattr(classdict[attr], cls.decoration_tag)):
 continue
 classdict[attr] = cls.decorator(item)
 setattr(classdict[attr], cls.decoration_tag, True)
 return type.__new__(cls,classname,bases,classdict)


## Authentication stuff:
class AuthenticationError(Exception):
 pass

import random


unittest.main-workalike that runs doctests too?

2006-05-05 Thread John J. Lee
...I wrote something to do this once, but didn't do as good a job as I
might have done and wondered if anybody else has done it properly.

I know about nose, but it seems just a little too magical for my
tastes, and includes stuff I don't really need.


John

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


Re: Tuple assignment and generators?

2006-05-05 Thread Diez B. Roggisch
vdrab wrote:

 That, I knew. What I did not know, nor get from this explanation, is
 that this behaviour may differ
 not only within the same implementation, but with instances of the same
 class or type (in this case, 'int').


E.g., after a = 1;
b = 1,
    a and b may or may not refer to the same object with the value one,
    depending on the implementation,


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

Re: Tuple assignment and generators?

2006-05-05 Thread Duncan Booth
Daniel Nogradi wrote:

 a = 10
 b = 10
 id(a)
 134536516
 id(b)
 134536516
 
 So the two memory addesses are the same, but
 
 a = 1
 b = 1
 id(a)
 134604216
 id(b)
 134604252
 
 and they are not the same (I restarted the interpreter between the two
 cases). So how is this now? Sorry if it's too trivial, but I simply
 don't get it.
 
If two immutable values are the same, then the interpreter has the right to 
simply reuse the same value. Apart from the guarantee that it will do this 
with None everything else is left open.

The current C-Python implementation will reuse small integers but not large 
integers, it also reuses some strings. It reuses the empty tuple but not 
(so far as I know) any other tuples. This could change at any time and 
other Python implementations may do totally different things here.

Just because you saw it reusing a small value such as 10 doesn't mean that 
there cannot be other small integers with the value 10 which aren't the 
same as that one. Back before Python had a separate bool type, it used to 
use two different integers for 0 (and two for 1), so you could (by an 
accident of implementation) tell whether a value had been created by a 
comparison operator. So far as I know, there is nothing stopping the author 
of an extension written in C continuing to create their own versions of 
small numbers today.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple assignment and generators?

2006-05-05 Thread vdrab
 
 E.g., after a = 1;
 b = 1,
 a and b may or may not refer to the same object with the value one,
 depending on the implementation,
 

But when in a specific implementation this property _does_ hold for
ints having value 1, I expect the
same behaviour for ints with other values than 1.
I guess I'm kind of weird that way.

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


Re: CRC calculation

2006-05-05 Thread Raymond L. Buvel
[EMAIL PROTECTED] wrote:
 Does anyone know where I can get python code to perform a CRC
 calculation on an IP packet?
 
Check out http://crcmod.sourceforge.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subclassing array

2006-05-05 Thread bruno at modulix
TG wrote:
 That's great, thanks !
 
 To put it short, when I create a Stimulus object, it first seek
 __new__() method. But if I don't define it, it looks for the one
 defined in Vector. This raises a problem because the parameters passed
 to Stimulus(params) aren't fitting with Vector parameters, raising an
 exception.
 
 That's why I have to use this *arg **kw syntax in order to allow my
 subclasses having any arguments without causing troubles. Am I right ?
 

To put it short : yes !-)

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Swaying A Coder Away From Python

2006-05-05 Thread A.M. Kuchling
On Thu, 4 May 2006 13:08:52 +0200, 
Fredrik Lundh [EMAIL PROTECTED] wrote:
 who's this, and why does he think that sampling some random comments by
 some random bloggers should mean anything to anyone ?  (and why do you
 seem to think that this matters, btw ?)

Michal Wallace, the original weblogger, was also working on Pirate,
the Python-to-Parrot translator, so I'm not surprised that he might be
bitter about not completing applications.  :) I guess no one is
working on Python-on-Parrot any more.

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


ANN: Crunchy Frog 0.2.5

2006-05-05 Thread André
Crunchy Frog is a desktop web application that transforms a
traditional Python web-based tutorial into an interactive session
within a browser.  At present it is limited to tutorials (html files)
that are contained within a single directory on the computer where it
is run.

You can download from
https://sourceforge.net/project/showfiles.php?group_id=125834
It consists of 3 python files, 5 sample html files in a single 10kB
zipped file.

Crunchy Frog is based on CherryPy (www.cherrypy.org) and requires
Elementtree. Further instructions are provided in the file
readme_first.html.

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


Re: Tuple assignment and generators?

2006-05-05 Thread Paul Boddie
Tim Chase wrote:

 I was hoping that there was just some __foo__ property I was
 missing that would have been called in the process of tuple
 unpacking that would allow for a more elegant solution such
 as a generator (or generator method on some object) rather
 than stooping to disassembling opcodes. :)

I suppose you wanted something like this...

a, b, c, d, e = xyz # first, let's consider a plain object

...to use the iterator protocol to populate the tuple elements, like
this:

_iter = xyz.__iter__()
a = _iter.next()
b = _iter.next()
c = _iter.next()
d = _iter.next()
e = _iter.next()

For such plain objects, it is possible to use such a mechanism. Here's
a countdown iterator:

class A:
def __init__(self, size):
self.size = size
def __iter__(self):
return B(self.size)

class B:
def __init__(self, size):
self.n = size
def next(self):
if self.n  0:
self.n -= 1
return self.n
else:
raise StopIteration

xyz = A(5)
a, b, c, d, e = xyz

In fact, similar machinery can be used to acquire new values from a
generator:

def g(size):
while size  0:
size = size - 1
yield size

a, b, c, d, e = g(5)

Note that if the iterator (specifically, the generator in the second
case) doesn't provide enough values, or provides too many, the tuple
unpacking operation will fail with the corresponding exception message.
Thus, generators which provide infinite or very long sequences will not
work unless you discard trailing values; you can support this either by
adding support for slicing to whatever is providing your sequences or,
if you're using generators anyway, by employing an additional
limiting generator:

def limit(it, size):
while size  0:
yield it.next()
size -= 1

xyz = A(5)
a, b, c, d = limit(iter(xyz), 4)

The above generator may be all you need to solve your problem, and it
may be the case that such a generator exists somewhere in the standard
library.

Paul

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


(question) How to use python get access to google search without query quota limit

2006-05-05 Thread Per
I am doing a Natural Language processing project for academic use,

I think google's rich retrieval information and query-segment might be
of help, I downloaded google api, but there is query limit(1000/day),
How can I write python code to simulate the browser-like-activity to
submit more than 10k queries in one day?

applying for more than 10 licence keys and changing them if
query-quota-exception raised is not a neat idea...

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


Re: Tuple assignment and generators?

2006-05-05 Thread Boris Borcic
vdrab wrote:
 
 E.g., after a = 1;
 b = 1,
 a and b may or may not refer to the same object with the value one,
 depending on the implementation,
 
 
 But when in a specific implementation this property _does_ hold for
 ints having value 1, I expect the
 same behaviour for ints with other values than 1.
 I guess I'm kind of weird that way.
 

Are you telling us that you *had* read that doc,
and tripped because it says depending on the implementation,
when it should say at the choice of the implementation ?

That's indeed a bit weird, imo.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (question) How to use python get access to google search without query quota limit

2006-05-05 Thread Heiko Wundram
Am Freitag 05 Mai 2006 13:37 schrieb Per:
 I think google's rich retrieval information and query-segment might be
 of help, I downloaded google api, but there is query limit(1000/day),
 How can I write python code to simulate the browser-like-activity to
 submit more than 10k queries in one day?

How about asking them for a license which doesn't have this restriction 
before taking the trouble to work around a limit they don't impose for 
nothing? Anything else might be considered text-/email-grabbing, and can get 
you into serious trouble...

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


Re: unittest.main-workalike that runs doctests too?

2006-05-05 Thread Jay Parlar

On May 5, 2006, at 6:35 AM, John J. Lee wrote:

 ...I wrote something to do this once, but didn't do as good a job as I
 might have done and wondered if anybody else has done it properly.

 I know about nose, but it seems just a little too magical for my
 tastes, and includes stuff I don't really need.


 John

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



nose actually has very little magic, its operation is quite 
straightforward. I've played with its codebase before, and it's quite 
clean.

And the new 0.9 branch uses a plugin system for some of the extra 
functionality, so you don't even have to install all the things it's 
capable of doing.

Jay P.

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


Re: (question) How to use python get access to google search without query quota limit

2006-05-05 Thread Duncan Booth
Heiko Wundram wrote:

 Am Freitag 05 Mai 2006 13:37 schrieb Per:
 I think google's rich retrieval information and query-segment might
 be of help, I downloaded google api, but there is query
 limit(1000/day), How can I write python code to simulate the
 browser-like-activity to submit more than 10k queries in one day?
 
 How about asking them for a license which doesn't have this
 restriction before taking the trouble to work around a limit they
 don't impose for nothing? Anything else might be considered
 text-/email-grabbing, and can get you into serious trouble...
 
Google's FAQ says they don't currently offer licenses for more than 100 
searches per day. The OP should accept this and try living within these 
limits.

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


Re: (question) How to use python get access to google search without query quota limit

2006-05-05 Thread Per
Yeah, Thanks Am,

I can be considered as an advanced google user, presumably.. But I am
not a advanced programmer yet.

If everyone can generate unlimited number of queries, soon the
user-query-data, which I believe is google's most advantage, will be in
chaos. Can they simply ignore some queries from a certain licence key
or.. so that they can keep their user-query-statistics normal and yet
provide cranky queriers reseanable response?

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


Re: Can I use python for this .. ??

2006-05-05 Thread nikie
san wrote:

 Hi

 I am using windows xp and have installed python and win32. I am
 familiar with basic Python. I wanted to control some of the
 applications via python script.

 I would like to write a python script to say:
 1. Open firefox and log on to gmail
 2. Another firefox window to visit slickdeals
 3. Open winamp and tune in to a shoutcast station
 4. Open groupwise ...
 etc ..

 These are the task I do every day whenever I log on my computer .. it
 just seems repetitive and hence probably can be coded in python.

 Can I do this in python? Where do I find the COM objects/interfaces for
 all these different programs? Are there any sample codes ?

I just googled for iTunes com python, there are lots of samples. If
you can't find any, or want to find out about an applications
interfaces yourself, you can sill use MakePy to find out what com
interfaces are installed on your computer, and simply use the dir and
help commands in the interactive console on those interfaces to find
out what they do. (There are other tools to explore COM interfaces,
like OleView, but if you're familiar with Python already, using
dir/help is probably going to be easier)
Reading Mark Hammond's excellent book (or at least the sample chapter
on automation) wouldn't hurt either ;-)

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


Re: ConfigParser and multiple option names

2006-05-05 Thread [EMAIL PROTECTED]
that will break horribly in windows, remenber it install all it's crap
in c:\Program Files

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


Re: Tuple assignment and generators?

2006-05-05 Thread vdrab
 Are you telling us that you *had* read that doc,
 and tripped because it says depending on the implementation,
 when it should say at the choice of the implementation ?

no.
let's see, where to start ... ?
let's say there's a certain property P, for the sake of this lng
discussion, something
more or less like a class or type's property of having immutable
values, such that any instance with value X has a single, unique
representation in memory and any two instantiations of objects with
that value X are in fact references to the same object.

Then, for example, python strings have property P whereas python lists
do not:

 x = test
 y = test
 x is y
True
 x = []
 y = []
 x is y
False


Now, as it turns out, whether or not python integers have property P
_depends_on_their_value_.
For small values, they do. For large values they don't. Yes, I
understand about the interpreter optimization. I didn't know this, and
I find it neither evident nor consistent. I don't think the above post
explains this, regardless of how you read implementation.

In fact, the whole string of replies after my initial question reminded
me of something I read not too long ago, but didn't quite understand at
the time.
source :
http://www.oreillynet.com/ruby/blog/2006/01/a_little_antiantihype.html

'''
Pedantry: it's just how things work in the Python world. The status
quo is always correct by definition. If you don't like something, you
are incorrect. If you want to suggest a change, put in a PEP,
Python's equivalent of Java's equally glacial JSR process. The
Python FAQ goes to great lengths to rationalize a bunch of broken
language features. They're obviously broken if they're frequently
asked questions, but rather than 'fessing up and saying we're
planning on fixing this, they rationalize that the rest of the world
just isn't thinking about the problem correctly. Every once in a
while some broken feature is actually fixed (e.g. lexical scoping), and
they say they changed it because people were confused. Note that
Python is never to blame.
'''

taking this rant with the proverbial grain of salt, I did think it was
funny.

Anyway, thanks for all the attempts to show me.
I will get it in the end. 
v.

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


Method acting on arguements passed

2006-05-05 Thread Panos Laganakos
I want a class method to take action depending on the type of the
arguement passed to it.

ie:
getBook(id) # get the book by ID
getBook(name) # get the book by name
...

Other languages use the term function/method overloading to cope with
this. And when I googled about it seems that GvR is testing it for 3.0
inclusion or so.

I was thinking of right after the function declaration check for the
parameter passed by isinstance() or type() and use if..elif..else to
act.

Is this the pythonic way/best practice to apply here?

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


Re: Tuple assignment and generators?

2006-05-05 Thread Diez B. Roggisch
vdrab wrote:

 
 E.g., after a = 1;
 b = 1,
 a and b may or may not refer to the same object with the value one,
 depending on the implementation,
 
 
 But when in a specific implementation this property _does_ hold for
 ints having value 1, I expect the
 same behaviour for ints with other values than 1.

That is an assumption you made. The above sentence is true for that
assumption, but also - and that is the key point here - for the current
implementation. 

And to put it frankly: if you'd had spend only half the time it took you to
participate in this argument to think about how one could possibly
implement the behavior you'd thought of, you'd realize that its totally
unfeasible. Try stuffing 2^64 python long objects in your memory to make
that guarantee hold... And then 2^65

 I guess I'm kind of weird that way.

Maybe.

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


Re: String Exceptions (PEP 352)

2006-05-05 Thread bruno at modulix
Paul Rubin wrote:
 bruno at modulix [EMAIL PROTECTED] writes:
 
What's wrong with:

assert foo and bar and i  10, \
  if foo and bar i must not be greater than 10
 
 
 It doesn't necessarily do anything.  With optimization enable, assert
 is a no-op.

quoting the OP (emphasis is mine):

I use string exceptions if the condition for an *assertion* is
to complex:


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Perl programmers

2006-05-05 Thread Thomas Guettler
Am Thu, 04 May 2006 12:02:52 -0400 schrieb A.M:

 Hi,
 
 
 
 Is there any efficient online resource or book that help experienced Perl 
 programmers to Python?

You can try the examples of pleac:

http://pleac.sourceforge.net/pleac_python/index.html

This is the Per Cookbook translated into several languages.

 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: [EMAIL PROTECTED]

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


Active Directory Authentication

2006-05-05 Thread D
Is it possible to have Python authenticate with Active Directory?
Specifically what I'd like to do is have a user enter a
username/password, then have Python check the credentials with AD - if
what they entered is valid, for example, it returns a 1, otherwise a
0..  Thanks!

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


Re: regex to exctract informations

2006-05-05 Thread Colin Gillespie
Bob wrote:
 Dears,
 
 I am trying to search and replace strings with regex.
 
 The string is identified by a keyword :
 
 IDImage(1M234567);
 DescriptionImage(Desc of the Image 1);
 
 I want to exctract the IDImage (1M234567 ) and the Description.
 
 The ID are characters and numbers, the description too.
 
 Thx,
 
 Bertrand
If the string is always in IDImage(#);

Then what about

x='IDImage(#);'
print x[9:-3]

Likewise for the Description.

HTH

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


Re: Method acting on arguements passed

2006-05-05 Thread Diez B. Roggisch
Panos Laganakos wrote:

 I want a class method to take action depending on the type of the
 arguement passed to it.
 
 ie:
 getBook(id) # get the book by ID
 getBook(name) # get the book by name
 ...
 
 Other languages use the term function/method overloading to cope with
 this. And when I googled about it seems that GvR is testing it for 3.0
 inclusion or so.
 
 I was thinking of right after the function declaration check for the
 parameter passed by isinstance() or type() and use if..elif..else to
 act.
 
 Is this the pythonic way/best practice to apply here?

google for gnosis multimethods for a clean approach.


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


Re: Progamming python without a keyboard

2006-05-05 Thread Eric S. Johansson
Rony Steelandt wrote:
 http://www.newscientisttech.com/article/dn9066
 
 To nice to be true ?

its early technology.  It's difficult to install and it definitely need 
some extra horsepower because the two people developing it are also 
disabled (like me).  The only thing I've done to support the project is 
host two workshops on speech driven programming and let Alain stay in 
our guest bedroom.

As I said on another mailing list, this kind of technology is incredibly 
important.  Depending on whose numbers you use, there are somewhere 
between 50,000 and 80,000 developers injured every year, most of them 
permanently.  Those these people just leave the field because there are 
little or no tools to support them.  Helping out on this project and 
making it easier to use and install may mean the difference between 
living a disability and earning a paycheck for a sizable number of people.

I must say however that Python is one of the friendlier languages when 
programming by unassisted speech recognition.  That is as long as you 
keep your symbols ordinary English words and don't try to control 
capitalization.  The easiest symbols are_like_this the hardest are 
CapitalizeWithoutSpaces (six misrecognition errors generating that last 
bit. one is still left uncorrected)

So if you want to make a serious difference in people's lives from your 
keyboard, you can help out in two ways.  The first is helping Alain and 
david in the voice coder project.  Second is working with probably 
myself and a couple of other folks in gnome at-spi land building a 
bridge between speech recognition on Windows and complete control of the 
environment on Linux.

As I said above and I'm not exaggerating, this kind of assistance makes 
a serious, quantifiable difference in the life of people with upper 
extremity disabilities.  I hope people can help.

--- eric


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


Re: Multiple Version Install?

2006-05-05 Thread David C.Ullrich
On Thu, 4 May 2006 13:19:46 -0400, Tim Peters [EMAIL PROTECTED]
wrote:

[David C.Ullrich]
 Would there be issues (registry settings, environment
 variables, whatever) if a person tried to install
 versions 1.x and 2.x simultaneously on one Windows
 system? Windows 98, if it matters.

 (I can handle the file associations with no problem.)

There are generally no issues 

One more thing you Python guys got right.

Just curious: How does pythonxx.dll determine things
like where to find the standard library? That's the
sort of thing I'd feared might cause confusion...

beyond file associations. 

Which is no problem. Either you add Run 1.x and Run 2.x
to the context menu or you associate .py with a tiny
windowless .exe that emulates the UNIX thing, reading
the first line of the file and then running the
appropriate python.exe.

(Before I tried it I thought that second might slow
down startup, but evidently even Windows is willing
to load a program quickly if it's small enough - I've
never noticed any delay.)

 On Windows,
Python versions i.j.k and i'.j'.k' coexist happily so long as i != i'
or j != j'.  For example, I currently have the python.org-released
Pythons 2.2.3, 2.3.5, and 2.4.3 installed on my Windows box. 

I wouldn't have bothered explaining why I cared except that
I was under the impression that the official line was that
if I wanted to use two versions I must be doing something
wrong. I guess not, fine.

 It would
be a challenge only if I wanted, say, 2.4.2 and 2.4.3 installed
simultaneously.

Another possible issue is that whenever the major or minor version
numbers (i or j) change on Windows, you also need to install matching
versions of any 3rd party extensions you want.  The major and minor
version numbers appear in the _name_ of the core Python DLL (like
python23.dll and python24.dll), and extensions with C code must be
compiled to link with the correct version of the Python DLL.

No problem with the one emedding I want to use - no recompile
needed, it requires that I simply set the name of the dll as
a property of the engine.

(But simply setting dllname = python2whatever.dll gives
errors about functions not found. Is this just me doing
something wrong or did functions with certain names
actually disappear? Not a complaint, just curious.)

 If anyone feels like pointing out that there's simply
 no reason to want to keep 1.x after installing the
 current version: By all means talk me into that!

If you've been using extensions with 1.j.k, then as above they have no
chance of working with 2.j'.k' bejore you install 2.j' versions of
those extensions.  That's a good reason to keep an old version.

There have been thousands of bugfixes and language enhancements since
1.j.k too, and not all are 100% backward-compatible.

In all, best advice is to keep the old version around until you're
sure you no longer need it.

 The problem is not that I'm concerned about backwards
 compatibility of Python code. The problem is that I
 use Python embedded in various Delphi programs,
 including a DIDE that I use really a lot, via
 a certain set of Delphi components. These components
 don't seem to work with 2.x. Presumably the PyDelphi
 people have new versions of the components that do
 work with Python 2.x. These presumably use much
 newer versions of Delphi than what I have. A new
 version of Delphi is not free... If I could use
 Python 2.x when I need to while continuing to
 use 1.x the way I have been for things that
 don't need 2.x that would be convenient.

That should work fine.  I don't know about PyDelphi, but found what
appears to be a still-active discussion list:

http://groups.yahoo.com/group/pythonfordelphi/

The theoretical joy of open source is that if they _don't_ support the
Python+Delphi combo you have, you can fix that yourself ;-)

Crossed my mind, but only briefly - theoretically seems right.
(One of the big improvements in later versions of Delphi is
reference-counted/garbage-colleted dynamically sized arrays.
Taking code using them and converting it to code with manual
memory management seems like it would be a fairly major pain.
Especially if a person wanted to get it right...)

But thanks, theoretically.



David C. Ullrich
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Method acting on arguements passed

2006-05-05 Thread Duncan Booth
Panos Laganakos wrote:

 I want a class method to take action depending on the type of the
 arguement passed to it.
 
 ie:
 getBook(id) # get the book by ID
 getBook(name) # get the book by name
 ...
 
 Other languages use the term function/method overloading to cope with
 this. And when I googled about it seems that GvR is testing it for 3.0
 inclusion or so.
 
 I was thinking of right after the function declaration check for the
 parameter passed by isinstance() or type() and use if..elif..else to
 act.
 
 Is this the pythonic way/best practice to apply here?
 
I think the most Pythonic way is probably to have separate methods. You 
presumably know at the point when you are calling getBook whether you have 
an id or a name. So be explicit:

  getBookById(id)
  getBookByName(name)

This has the advantage that id and name could both be strings and the code 
will still do the right thing. No amount of function overloading will 
resolve arguments which have the same type but mean different things.

Another reasonable way to go is to use keyword arguments:

  getBook(id=id)
  getBook(name=name)

which keeps down the number of different methods but could be confusing as 
you have mutually exclusive keyword arguments.

Another option you might have here, if getBook does a lookup in a 
dictionary, or database query, is simply to index the books by both id and 
name. Then the definition might be:

  def getBook(self, idorname):
 return self._books[idorname]

and there is still no typechecking.

If you do feel you need typechecking, consider pulling it out into a 
separate method so you are actually testing for the meaning of the 
parameter rather than explicitly testing its type everywhere:

  def getBook(self, idorname):
 if self.isvalidid(idorname):
  
 elif self.isvalidname(idorname):
  
 else:
 raise Oops()

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


Re: Method acting on arguements passed

2006-05-05 Thread bruno at modulix
Panos Laganakos wrote:
 I want a class method to take action depending on the type of the
 arguement passed to it.
 
 ie:
 getBook(id) # get the book by ID
 getBook(name) # get the book by name
 ...
 
 Other languages use the term function/method overloading to cope with
 this. And when I googled about it seems that GvR is testing it for 3.0
 inclusion or so.
 
 I was thinking of right after the function declaration check for the
 parameter passed by isinstance() or type() and use if..elif..else to
 act.

 Is this the pythonic way/best practice to apply here?

For simple case and if there's no need for extensibility, this is
usually quite enough - even if somewhat ugly. If the code for each case
is really different, I'd split the whole thing into three separate
methods : getBookById, getBookByName, and getBook that only do the
dispatch.

Else - and depending on the context, needs, specs and whatnot, I'd look
either at the visitor pattern (or any custom double-dispatch) or at an
existing multimethod implementation (like David Mertz's multimethod or
Philip Eby's protocol.dispatch).

My 2 cents
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: 4 little Python programs

2006-05-05 Thread RM
I recently got access to one of those new GooglePages and decided to
play around with it a little. I figured it would be a nice *easy* way
to get a website going. I may eventually do something more
professional, but hey, this was free in both money and time. :)

I had been thinking of releasing some of my little personal apps for a
while. So, this finally motivated me to clean them up enough for
release. The website is not yet finished, but I couldn't wait to share
with you these little Python programs. I have packaged them nicely for
Windows using py2exe and InnoSetup.  Unfortunately, I haven't had the
time to do the same for Linux.  I plan to that soon.  You can get them
here.

http://rmcorrespond.googlepages.com/customsoftware

I have been using them for several years, but never got around to
releasing them. Any way, I hope you like them. Oh, they are all
licensed with the GPL, but for now, since I don't yet have a way to
track downloads, I am only making the source available upon request. If
you have any questions or suggestions let me know. 
 
-Ruben

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


Re: Can I use python for this .. ??

2006-05-05 Thread Doug Bromley
Careful of using the wrong tool for the job. Don't use Python for the sake of it unless its as a learning experience.All of the things you ask for can be done by simply using the Windows start menu to launch a shortcut with various command line options. Voila - problem solved.
On 5 May 2006 05:15:46 -0700, nikie [EMAIL PROTECTED] wrote:
san wrote: Hi I am using windows xp and have installed python and win32. I am familiar with basic Python. I wanted to control some of the applications via python script.
 I would like to write a python script to say: 1. Open firefox and log on to gmail 2. Another firefox window to visit slickdeals 3. Open winamp and tune in to a shoutcast station 4. Open groupwise ...
 etc .. These are the task I do every day whenever I log on my computer .. it just seems repetitive and hence probably can be coded in python. Can I do this in python? Where do I find the COM objects/interfaces for
 all these different programs? Are there any sample codes ?I just googled for iTunes com python, there are lots of samples. Ifyou can't find any, or want to find out about an applications
interfaces yourself, you can sill use MakePy to find out what cominterfaces are installed on your computer, and simply use the dir andhelp commands in the interactive console on those interfaces to find
out what they do. (There are other tools to explore COM interfaces,like OleView, but if you're familiar with Python already, usingdir/help is probably going to be easier)Reading Mark Hammond's excellent book (or at least the sample chapter
on automation) wouldn't hurt either ;-)--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Active Directory Authentication

2006-05-05 Thread Christoph Haas
On Fri, May 05, 2006 at 05:39:08AM -0700, D wrote:
 Is it possible to have Python authenticate with Active Directory?
 Specifically what I'd like to do is have a user enter a
 username/password, then have Python check the credentials with AD - if
 what they entered is valid, for example, it returns a 1, otherwise a
 0..  Thanks!

Can't you query the AD through LDAP? Then
http://python-ldap.sourceforge.net/ might help.

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


Tkinter Canvas Pre-Buffer

2006-05-05 Thread [EMAIL PROTECTED]
Is there a way that using Tkinter I can pre-render the canvas then draw
it on the screen?

Thanks.

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


Re: Active Directory Authentication

2006-05-05 Thread Stephan Diehl
On Fri, 05 May 2006 05:39:08 -0700, D wrote:

 Is it possible to have Python authenticate with Active Directory?
 Specifically what I'd like to do is have a user enter a
 username/password, then have Python check the credentials with AD - if
 what they entered is valid, for example, it returns a 1, otherwise a
 0..  Thanks!

It's possible and you need the python-ldap package for it.
The actual authentication will look like (simplified):

def authenticate(user='',passwd=''):
dn = find_user_dn(user)
try:
l = ldap.open(AD_HOST_URL)
l.protocol_version = ldap.VERSION3
l.simple_bind_s(dn,passwd)
l.search_s(SEARCHDN,ldap.SCOPE_SUBTREE,'objectType=bla')
l.unbind_s()
return True
except ldap.LDAPError:
return False

obviously, you need to supply some function 'find_user_dn' that maps
the user to its DN.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cross platform libraries

2006-05-05 Thread diffuser78
Hi Ravi,

Do you have any idea how to perform such triigers ?
Every help is appreciated.


Ravi Teja wrote:
 No! That's not the way things work. Such code needs to run locally (in
 this case, Windows). You can run this program as a daemon on Windows
 with some nice simple remote interface (Eg: xmlrpc) and send a message
 to trigger the shutdown.

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


Re: Method acting on arguements passed

2006-05-05 Thread Andrew Gwozdziewycz
 I want a class method to take action depending on the type of the
 arguement passed to it.

 ie:
 getBook(id) # get the book by ID
 getBook(name) # get the book by name

Keyword arguments are going to be the best solution, but you'll still  
have to do checks like in this example which uses a generic keyword  
and determines it's type..

def getBook(arg):
 id = None
 name = None
 try:
   id = int(arg)
   # use the id here
 except ValueError:
   name = arg
   # use name here

Now, if you were to use named arguments:
def getBook(id=None, name=None):
 if id:
 # do whatever for id
 elif name:
 # do whatever for name here

They are nearly identical.
---
Andrew Gwozdziewycz
[EMAIL PROTECTED]
http://www.23excuses.com
http://ihadagreatview.org
http://and.rovir.us


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


how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Ju Hui
I want to remove about 5 elements from a list,which has 10
elements.
sample code like below:

 a=range(10)
 b=range(4)
 for x in b:
... a.remove(x)
...
 a
[4, 5, 6, 7, 8, 9]

when a and b is small size, it will finished quickly, but when a and b
have many elements.
such as:
 a=range(10)
 b=range(5)
 for x in b:
... a.remove(x)
...
it will very slowly. Shall I change to another data structure and choos
a better arithmetic?
any suggestion is welcome.
thanks a lot!

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


PUDGE - Colored Code Blocks / Mailing List Access

2006-05-05 Thread lazaridis_com
Colored Code Blocks

Pudge generated documentation can contain colored code blocks, using
the rst directive

..code-block:: Python (an other languages supported by SilverCity).

http://pudge.lesscode.org/trac/ticket/21
http://pudge.lesscode.org/trac/changeset/126

-

Mailing List

The Pudge Mailing List seems to be down since the change of the server:

http://news.gmane.org/gmane.comp.python.pudge.general

Possibly someone can notify some of the project admins.

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


Is this a legal / acceptable statement ?

2006-05-05 Thread Philippe Martin
Hi,

This code works, but is it appropriate ?

l_init = False

if True == l_init and 1234 = l_value:
 print 'l_value is initialized'

I know I can do this with a try but ...

Philippe


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


PUDGE - Colored Code Blocks / Mailing List Access

2006-05-05 Thread lazaridis_com
Colored Code Blocks

Pudge generated documentation can contain colored code blocks, using
the rst directive

..code-block:: Python (an other languages supported by SilverCity).

http://pudge.lesscode.org/trac/ticket/21
http://pudge.lesscode.org/trac/changeset/126

-

Mailing List

The Pudge Mailing List seems to be down since the change of the server:

http://news.gmane.org/gmane.comp.python.pudge.general

Possibly someone can notify some of the project admins.

--
http://lazaridis.com

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


Re: Tkinter Canvas Pre-Buffer

2006-05-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 Is there a way that using Tkinter I can pre-render the canvas then draw
 it on the screen?

not really; the canvas is double-buffered, but it regenerates (portions of) the
buffer when necessary.

if you want to draw in a separate buffer, and use that when updating the widget,
you can use the WCK for Tkinter:

http://effbot.org/zone/wck.htm

for examples, see e.g.

http://effbot.org/zone/wck-3.htm
http://effbot.org/zone/wck-aggview.htm

/F 



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


Re: cross platform libraries

2006-05-05 Thread diffuser78
I went to this webpage

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649

Isn't it supposed to run on the network and close the connected
machine.

Every help is appreciate,


Dennis Lee Bieber wrote:
 On 4 May 2006 09:57:15 -0700, [EMAIL PROTECTED] declaimed the
 following in comp.lang.python:

  I am using python on a linux terminal.
 
  I want to shutdown a remote windows box. I found a script which does
  something like this. My question is can we use windows libraries in
  linux as follows 
 
  import win32api
  import win32con
  import win32netcon
  import win32security
  import win32wnet
 
   That set... HIGHLY UNLIKELY... They all rely upon having the M$
 kernel DLLs available...

   Now, if the remote box is running a telnet server, you might be able
 to telnet over (logging in as the boxes admin account) and initiate a
 shutdown from it... (I seem to have a shutdown.exe on my system).
 --
   WulfraedDennis Lee Bieber   KD6MOG
   [EMAIL PROTECTED]   [EMAIL PROTECTED]
   HTTP://wlfraed.home.netcom.com/
   (Bestiaria Support Staff:   [EMAIL PROTECTED])
   HTTP://www.bestiaria.com/

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


Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Diez B. Roggisch
Ju Hui wrote:

 I want to remove about 5 elements from a list,which has 10
 elements.
 sample code like below:
 
 a=range(10)
 b=range(4)
 for x in b:
 ... a.remove(x)
 ...
 a
 [4, 5, 6, 7, 8, 9]
 
 when a and b is small size, it will finished quickly, but when a and b
 have many elements.
 such as:
 a=range(10)
 b=range(5)
 for x in b:
 ... a.remove(x)
 ...
 it will very slowly. Shall I change to another data structure and choos
 a better arithmetic?


How about a listcomprehension? 


new_list = [e for e in old_list if predicate(e)]
# Possibly you need this, too:
old_list[:] = new_list


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


Re: Tuple assignment and generators?

2006-05-05 Thread Sion Arrowsmith
vdrab [EMAIL PROTECTED] wrote:
let's say there's a certain property P, for the sake of this lng
discussion, something
more or less like a class or type's property of having immutable
values, such that any instance with value X has a single, unique
representation in memory and any two instantiations of objects with
that value X are in fact references to the same object.

Then, for example, python strings have property P whereas python lists
do not:

Er, no:

 x = test!
 y = test!
 x == y
True
 x is y
False

Strings only get a unique instance if they are valid identifiers.
Again, it's an optimisation issue. As with ints, it

_depends_on_their_value_.

I find it neither evident nor consistent. I don't think the above post
explains this, regardless of how you read implementation.

Implementation dependent = Any behaviour you observe which is not
explicitly documented is not to be relied upon. Also, Implementation
dependent = How this is implemented should be transparent and
irrelevant to the normal user. No, it's not particularly consistent.
Because it doesn't matter.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread [EMAIL PROTECTED]
Try to use set objects:
 a=set(range(10))
 b=set(range(5))
 a = a - b

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


Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Tim Chase
 but when a and b have many elements. such as:
 
a=range(10)
b=range(5)
for x in b:
 
 ... a.remove(x)
 ...
 it will very slowly. 

Well, your problem is rather ambiguous.  In your examples, 
you're removing contiguous ranges.  Thus, you should be able 
to do something like

  a = range(10)
  del a[:5]

which may have a considerable speedup.  However, if B 
contains a disjoint sets of entries, the simple solution 
will require A*B checks, making it dependant on the size of 
A and B (as you've discovered).

Assuming the del method is considerably faster, you might 
be able to do some sort of optimization of the disjoint set, 
using the above-mentioned method.  Break B into contiguous 
pieces, and then pass those as slices to delete.

Or if B is a pattern of some sort, you could do

  a = range(10)
  del a[::2]  #delete even numbers
  a = range(10)
  del a[1::2] #delete odd numbers
  a = range(10)
  del a[2::5] # delete every 5th element beginning with 
the 3rd

Another attempt might be to try

  a = [x for x in a if x not in b]

However, this is still doing A*B checks, and will likely 
degrade with as their sizes increase.

Just a few ideas.

-tkc




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


Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Jack Orenstein
On May 5, 2006, at 9:36 AM, Ju Hui wrote:

 a=range(10)
 b=range(5)
 for x in b:
  ... a.remove(x)
  ...
  it will very slowly. Shall I change to another data structure and 
choos
  a better arithmetic?
  any suggestion is welcome.

If removal is an O(n) operation, then removing 1/2 the list will take 
O(n**2), which you don't want. You'd be better off with the contents of 
  a being in a hash table (O(1) removal in practice) or a balanced 
tree (O(log n) removal).

Another possibility: If the a and b lists are ordered in the same way, 
then you could walk through the lists in order using a merge procedure, 
generating a new list as you go.

After ruling out slow data structures and algorithms, you'll almost 
certainly be better off using something built in to Python rather than 
coding your own data structure in Python.

Jack Orenstein 

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


Re: Is this a legal / acceptable statement ?

2006-05-05 Thread vbgunz
you don't have to say:

if True == l_init

it is suggested you simply say:

if l_init:

Remember the and operator requires expressions on both sides to be true
to continue. If you notice, your expression on the right side of the
'and' is an assignment and so this is forbidden (SyntaxError).
assignments only work on lines by themselves and no where else.

if you meant == rather than = remember this, l_value doesn't exist and
would pull up a NameError *but* because the first expression evaluates
as false the second expression is never evaluated.

refactor your code ASAP. good luck!

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


Re: Python for Perl programmers

2006-05-05 Thread Alex Martelli
John J. Lee [EMAIL PROTECTED] wrote:

 A.M [EMAIL PROTECTED] writes:
 
  Is there any efficient online resource or book that help experienced Perl
  programmers to Python?
 
 Worry instead about how you're going to keep maintaining your Perl
 code after you've developed an allergic response to it.

Nah, that's easy -- you port it to Python (that's what I did back in the
day, and I've heard at least three others relate similar choices).


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


Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Larry Bates
Ju Hui wrote:
 I want to remove about 5 elements from a list,which has 10
 elements.
 sample code like below:
 
 a=range(10)
 b=range(4)
 for x in b:
 ... a.remove(x)
 ...
 a
 [4, 5, 6, 7, 8, 9]
 
 when a and b is small size, it will finished quickly, but when a and b
 have many elements.
 such as:
 a=range(10)
 b=range(5)
 for x in b:
 ... a.remove(x)
 ...
 it will very slowly. Shall I change to another data structure and choos
 a better arithmetic?
 any suggestion is welcome.
 thanks a lot!
 
A list isn't going to respond very well to random removals of large
numbers of elements like this.  Remember that it must do linear search
to find the value to be removed and then basically build a completely
new list with the remaining values.  Depending on the data in question,
you might be able to leverage things.  Are the two lists sorted?  If so
you can iterate over both of them and build a third list with the results.

This is not particularly 'elegant' but it is fast for sorted lists:

import time
a=range(10)
b=range(5)

start_time=time.time()
for x in b:
a.remove(x)

stop_time=time.time()
print brute force elapsed time=%.2f seconds % (stop_time-start_time)



start_time=time.time()
n=[]
i1=0
i2=0
while 1:
try: v1=a[i1]
except IndexError:
break

try: v2=b[i2]
except IndexError:
n.extend(a[i1:])
break

if v1  v2:
n.append(v1)
i1+=1
continue

elif v1  v2:
i2+=1
continue

else:
i1+=1
i2+=1
continue

stop_time=time.time()
print new elapsed time=%.2f seconds % (stop_time-start_time)

start_time=time.time()
a=set(a)
b=set(b)
a.symmetric_difference(b)
stop_time=time.time()
print sets elapsed time=%.2f seconds % (stop_time-start_time)

brute force elapsed time=4.13 seconds
new elapsed time=0.05 seconds
sets elapsed time=0.03 seconds

There may be other ways using bisect or some other module.  If data
is random, unsorted or has duplicates, I would look at in-memory
database like SQLlite instead.

If the values are unique you can do something like:

a=set(range(10))
b=set(range(5))

a.symmetric_difference(b)

Which is the fastest way.

It all depends on the real data which we can't tell from your
test using range().

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


Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Diez B. Roggisch
 How about a listcomprehension?
 
 
 new_list = [e for e in old_list if predicate(e)]
 # Possibly you need this, too:
 old_list[:] = new_list


forgot the predicate. And you should use a set of objects to remove, as then
you'd have O(1) behavior for the in-operator

So:

to_remove = set(b)
new_list = [e for e in a if e not in to_remove]

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


Re: Is this a legal / acceptable statement ?

2006-05-05 Thread Philippe Martin
I'm sorry (typo):



l_init = False

if True == l_init and 1234 == l_value:
 print 'l_value is initialized'


Note that 1234 == l_value does not get evaluated.

Philippe




vbgunz wrote:

 you don't have to say:
 
 if True == l_init
 
 it is suggested you simply say:
 
 if l_init:
 
 Remember the and operator requires expressions on both sides to be true
 to continue. If you notice, your expression on the right side of the
 'and' is an assignment and so this is forbidden (SyntaxError).
 assignments only work on lines by themselves and no where else.
 
 if you meant == rather than = remember this, l_value doesn't exist and
 would pull up a NameError *but* because the first expression evaluates
 as false the second expression is never evaluated.
 
 refactor your code ASAP. good luck!

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


Re: Is this a legal / acceptable statement ?

2006-05-05 Thread Larry Bates
Philippe Martin wrote:
 Hi,
 
 This code works, but is it appropriate ?
 
 l_init = False
 
 if True == l_init and 1234 = l_value:
  print 'l_value is initialized'
 
 I know I can do this with a try but ...
 
 Philippe
 
 
1) You have a syntax error 1234 == l_value (note ==)
2) This doesn't test to see if l_value is initialized
   because if it isn't you get:

Traceback (most recent call last):
  File C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py,
line 310, in RunScript
exec codeObject in __main__.__dict__
  File junk.py, line 1, in ?
if True == l_init and 1234 == l_value:
NameError: name 'l_init' is not defined

3) It is unclear what l_init is used for in this context.
   Setting it to True doesn't tell you anything about l_value.

Normally you do something like:

l_value=None
.
. Intervening code
.
if l_value is None:
print l_value uninitialized

Or (something I never use):

if not locals().has_key('l_value'):
print l_value uninitialized


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


Re: Tuple assignment and generators?

2006-05-05 Thread vdrab
oh wow... it gets better...

 x = test!
 y = test!
 x is y
False
 x = test
 y = test
 x is y
True


... I had no clue.
I guess the take-away lesson is to steer clear from any reliance on
object identity checks, if at all possible.  Are there any other such
optimizations one should like to know about?
v.

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


Re: cross platform libraries

2006-05-05 Thread Max Erickson
[EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 I went to this webpage
 
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649
 
 Isn't it supposed to run on the network and close the connected
 machine.

That code uses the windows libraries on the machine it is run on to 
generate a request to the networked machine to shutdown. The code 
executes locally and sends the request over the network.

 Every help is appreciate,
 

If you have some way of remotely running programs on the windows 
machine(ssh, telnet, etc.), you might try pstools:

http://www.sysinternals.com/Utilities/PsTools.html

specifically, psshutdown.

max

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


Re: Tuple assignment and generators?

2006-05-05 Thread Dave Hansen
On 5 May 2006 05:23:24 -0700 in comp.lang.python, vdrab
[EMAIL PROTECTED] wrote:

 Are you telling us that you *had* read that doc,
 and tripped because it says depending on the implementation,
 when it should say at the choice of the implementation ?

no.
let's see, where to start ... ?
let's say there's a certain property P, for the sake of this lng
discussion, something
more or less like a class or type's property of having immutable
values, such that any instance with value X has a single, unique
representation in memory and any two instantiations of objects with
that value X are in fact references to the same object.

IOW, property P is (x == y) = (x is y) (read = as implies).

Note that only immutable objects can have property P.


Then, for example, python strings have property P whereas python lists
do not:

 x = test
 y = test
 x is y
True
 x = []
 y = []
 x is y
False


Note this last relationship is _guaranteed_.  Lists are not immutable,
and therefore can not have property P.


Now, as it turns out, whether or not python integers have property P
_depends_on_their_value_.

From the zen, I believe this falls out from practicality beats
purity.

For small values, they do. For large values they don't. Yes, I

Even that's not necessarily true.  The implementation is free to
always create a new immutable object, even for small values.

understand about the interpreter optimization. I didn't know this, and
I find it neither evident nor consistent. I don't think the above post
explains this, regardless of how you read implementation.

Think about implementation for a moment.  Consider the statement

   x = some_arbitrary_integer()

Do you really want the interpreter to go through all the existing
integer objects in the program to see if that particular value exists,
just to guarantee some some later statement

   x is y

returns True if x == y?

OK, maybe we can change the is operator on immutable objects such
that x is y returns True if x == y.  But then you can encounter a
situation where x is y but id(x) != id(y)  Now what?

Perhaps the solution would be to disable the is operator and id
function for immutable objects.  But then _they_ lose generality.
There doesn't seem to be a way to win.

So it all comes down to who cares?  Immutable objects are immutable.
You can't change them.  Object identity is a non-issue.

This is not the case for mutable objects.  Consider

a = [1,2,3]
b = [1,2,3]
c = a

a==b
a==c
b==c
a is not b
b is not c
c is a

c.append(4)


In fact, the whole string of replies after my initial question reminded
me of something I read not too long ago, but didn't quite understand at
the time.
source :
http://www.oreillynet.com/ruby/blog/2006/01/a_little_antiantihype.html

[...whinge elided...]

taking this rant with the proverbial grain of salt, I did think it was
funny.

Your original post in its entirety (ignoring the example) was what
the...? does anybody else get mighty uncomfortable about this? 

The first response (paraphrased) was No.  Why should I?  With
immutable objects, I care about ==, not is.

Your response seemed to want to cast doubt on the integrity of the
entire language: Given this though, what other such beauties are
lurking in the interpreter, under the name of 'implementation
accidents'?


Anyway, thanks for all the attempts to show me.
I will get it in the end. 

I will ignore the double entendre, and simply hope I was of help, and
wish you luck.  Regards,
-=Dave

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


Re: Is this a legal / acceptable statement ?

2006-05-05 Thread Philippe Martin


Larry Bates wrote:

 Philippe Martin wrote:
 Hi,
 
 This code works, but is it appropriate ?
 
 l_init = False
 
 if True == l_init and 1234 = l_value:
  print 'l_value is initialized'
 
 I know I can do this with a try but ...
 
 Philippe
 
 
 1) You have a syntax error 1234 == l_value (note ==)
 2) This doesn't test to see if l_value is initialized
because if it isn't you get:
 
 Traceback (most recent call last):
   File
   C
\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py,
 line 310, in RunScript
 exec codeObject in __main__.__dict__
   File junk.py, line 1, in ?
 if True == l_init and 1234 == l_value:
 NameError: name 'l_init' is not defined
 
 3) It is unclear what l_init is used for in this context.
Setting it to True doesn't tell you anything about l_value.
 
 Normally you do something like:
 
 l_value=None
 .
 . Intervening code
 .
 if l_value is None:
 print l_value uninitialized
 
 Or (something I never use):
 
 if not locals().has_key('l_value'):
 print l_value uninitialized
 
 
 -Larry Bates


l_init really is a boolean parameter and l_value a value that _might_ exist
in a shelve.

So I just want to have a parameter to a method so if the first value tested
is false (l_init) then the second (l_value) does not get tested ... because
it is the second in the statement and only seems to get evaluated if the
first one is true.

Philippe




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


Re: Tuple assignment and generators?

2006-05-05 Thread Fredrik Lundh
vdrab wrote:

 I guess the take-away lesson is to steer clear from any reliance on
 object identity checks, if at all possible.  Are there any other such
 optimizations one should like to know about?

so in your little world, an optimization that speeds things up and saves
memory isn't really an optimization ?

good luck with your future career in programming.

*plonk* 



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


Re: Is this a legal / acceptable statement ?

2006-05-05 Thread bruno at modulix
Philippe Martin wrote:
 Hi,
 
 This code works, but is it appropriate ?

appropriate for what ?-)

 l_init = False
 # corrected typo, cf other post in this thread
 if True == l_init and 1234 == l_value:
  print 'l_value is initialized'

Do this in production code, and have one of the first Python entry in
the Daily WTF !-)

What are you trying to do, exactly ? I've been scratching my head for at
least 5 minutes without finding any sensible reason to write such code.


 I know I can do this with a try but ...

???


ot
Slightly ot, but since you ask for idioms:

1/ Since binding (so-called 'assignment') is a statement (not an
expression), you can as well write your equality test the 'normal' way:

  if l_init == True and l_value == 1234:
...  pass

the litteral value == variable idiom comes from languages where
assignement being an expression, one could 'typo' '=' for '==', usually
leading to unwanted result !-)

2/ also, testing for equality against True or False is a bad idea, since
there are some things that will eval to false in a boolean context
without actually being equal to False:
 for item in [[], (), {}, None, '']:
... print item,  == False ?, item == False
... if not item:
... print but still evals to False...
...
[]  == False ? False
but still evals to False...
()  == False ? False
but still evals to False...
{}  == False ? False
but still evals to False...
None  == False ? False
but still evals to False...
  == False ? False
but still evals to False...


so :
 if l_init and l_value == 1234:
... pass

This still doesn't make sense to me, but it's at least a bit more
readable !-)
/ot

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple assignment and generators?

2006-05-05 Thread Diez B. Roggisch
 ... I had no clue.

We figured that

 I guess the take-away lesson is to steer clear from any reliance on
 object identity checks, if at all possible.

You've been told that quite a few times before that is is not intended for
what you used it. 

Some people actually listen to what others tell. Others seem to be driven by
the deep desire to make even the tiniest bit of getting-a-grasp a public
affair. 

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


Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Sion Arrowsmith
Tim Chase  [EMAIL PROTECTED] wrote:
Another attempt might be to try

  a = [x for x in a if x not in b]

However, this is still doing A*B checks, and will likely 
degrade with as their sizes increase.

Combine this with the use of sets others have suggested if the
order of a matters, ie:

 bset = set(b)
 a = [ x for x in a if x not in bset ]

which gets you down to O(A) since set membership is O(1).

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is this a legal / acceptable statement ?

2006-05-05 Thread bruno at modulix
Philippe Martin wrote:
(snip)
 
 l_init really is a boolean parameter and l_value a value that _might_ exist
 in a shelve.
 
 So I just want to have a parameter to a method so if the first value tested
 is false (l_init) then the second (l_value) does not get tested ... because
 it is the second in the statement and only seems to get evaluated if the
 first one is true.

s/seems to get/is/

But this is a really unpythonic way to do things IMHO. Either use a
try/except block (probably the most straightforward solution), or, as in
Larry's post, test for the existence of 'l_value' in locals().

My 2 cents...
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this a legal / acceptable statement ?

2006-05-05 Thread Fredrik Lundh
Philippe Martin wrote:

 l_init really is a boolean parameter and l_value a value that _might_ exist
 in a shelve.

 So I just want to have a parameter to a method so if the first value tested
 is false (l_init) then the second (l_value) does not get tested ... because
 it is the second in the statement and only seems to get evaluated if the

how do you look things up in the shelve ?

/F 



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


Re: cross platform libraries

2006-05-05 Thread diffuser78
Can we have some program in Linux which shuts down the windows computer
remotely.

Every help is appreciated.


Max Erickson wrote:
 [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]:

  I went to this webpage
 
  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649
 
  Isn't it supposed to run on the network and close the connected
  machine.

 That code uses the windows libraries on the machine it is run on to
 generate a request to the networked machine to shutdown. The code
 executes locally and sends the request over the network.

  Every help is appreciate,
 

 If you have some way of remotely running programs on the windows
 machine(ssh, telnet, etc.), you might try pstools:

 http://www.sysinternals.com/Utilities/PsTools.html
 
 specifically, psshutdown.
 
 max

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


  1   2   3   >