Re: What's the difference between VAR and _VAR_?

2005-09-08 Thread EP

> I thought there must be something special when you named a VAR with '_'
> the first character. Maybe it's just a programming style and I had
> thought too much...

Perhaps you are thinking of the use of double leading underscore names within 
class declarations or system defined names with underscores?  

e.g.  __somePrivateVar

e.g. __init__


"""
9.6 Private Variables 
There is limited support for class-private identifiers. Any identifier of the 
form __spam (at least two leading underscores, at most one trailing underscore) 
is textually replaced with _classname__spam, where classname is the current 
class name with leading underscore(s) stripped. This mangling is done without 
regard to the syntactic position of the identifier, so it can be used to define 
class-private instance and class variables, methods, variables stored in 
globals, and even variables stored in instances. private to this class on 
instances of other classes. Truncation may occur when the mangled name would be 
longer than 255 characters. Outside classes, or when the class name consists of 
only underscores, no mangling occurs. 

Name mangling is intended to give classes an easy way to define ``private'' 
instance variables and methods, without having to worry about instance 
variables defined by derived classes, or mucking with instance variables by 
code outside the class. Note that the mangling rules are designed mostly to 
avoid accidents; it still is possible for a determined soul to access or modify 
a variable that is considered private. This can even be useful in special 
circumstances, such as in the debugger, and that's one reason why this loophole 
is not closed. (Buglet: derivation of a class with the same name as the base 
class makes use of private variables of the base class possible.) 

Notice that code passed to exec, eval() or evalfile() does not consider the 
classname of the invoking class to be the current class; this is similar to the 
effect of the global statement, the effect of which is likewise restricted to 
code that is byte-compiled together. The same restriction applies to getattr(), 
setattr() and delattr(), as well as when referencing __dict__ directly. """



"""
2.3.2 Reserved classes of identifiers 
Certain classes of identifiers (besides keywords) have special meanings. These 
classes are identified by the patterns of leading and trailing underscore 
characters: 


_* 
Not imported by "from module import *". The special identifier "_" is used in 
the interactive interpreter to store the result of the last evaluation; it is 
stored in the __builtin__ module. When not in interactive mode, "_" has no 
special meaning and is not defined. See section 6.12, ``The import statement.'' 
Note: The name "_" is often used in conjunction with internationalization; 
refer to the documentation for the gettext module for more information on this 
convention. 


__*__ 
System-defined names. These names are defined by the interpreter and it's 
implementation (including the standard library); applications should not expect 
to define additional names using this convention. The set of names of this 
class defined by Python may be extended in future versions. See section 3.3, 
``Special method names.'' 

__* 
Class-private names. Names in this category, when used within the context of a 
class definition, are re-written to use a mangled form to help avoid name 
clashes between ``private'' attributes of base and derived classes. See section 
5.2.1, ``Identifiers (Names).'' 






"""

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


Re: Question about consistency in python language

2005-09-08 Thread Kay Schluehr
[EMAIL PROTECTED] wrote:

> Let's say I define a list of pairs as follows:
> >>l = [('d', 3), ('a', 2), ('b', 1)]
>
> Can anyone explain why this does not work?
> >>h = {}.update(l)
>
> and instead I have to go:
> >>h = {}
> >>h.update(l)
> to initialize a dictionary with the given list of pairs?
>
> when an analagous operation on strings works fine:
> >>s = "".join(["d","o","g"])
>
> Seems inconsistent.

If you define

>>> sep = ""
>>> sep.join(["d","o","g"])
"dog"
>>> sep
''

sep is preserved and a new "dog" string is generated. Since sep is
immutable there is no way to manipulate it inplace.

On the other hand there exists no sorted() method for tuples or lists
like join() for strings but it is implemented as a function in Python24
that returns a new sorted container. I consider this as an
inconsistency across builtin types. Consistent would be following usage
pattern:

>>> l = [1,3,2]
>>> l.sorted()
[1,2,3] # new sorted list
>>> l.sort()# sort list inplace
>>> l.appended(4)   # new extended list
[1,2,3,4]
>>> l.append(4) # appends an element to the same list
>>> l
[1,2,3,4]

Preserving the naming convention we would have

>>> "".joined(["d","o","g"])
"dog"

Kay

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


Re: Using Python with COM to communicate with proprietary Windows software

2005-09-08 Thread Thomas Heller
Joakim Persson <[EMAIL PROTECTED]> writes:

[...]
> This means that I must come up with a way to interface Python with
> this log tool. After some investigations, I have run inte problems --
> my inital approach was to use Python + win32com to communicate with
> the COM interface. Unfortunately, it seems as if win32com, even if I
> makepy the log tool executable (which gives me the full range of
> available functions of the interface, just as expected), cannot be
> used, since the interface is not a simple IDispatch interface. Also, I
> discovered that the Python client must also implement a COM server to
> receive the log information as it is generated by the embedded device,
> passed into the log tool and then sent by the log tool COM server. 
>
> I have a rather bloated C++ client prototype which "works", so I
> should have all the code needed to invoke the interface, but this
> client is of course rather bloated in itself and not suitable for my
> experimental programming approach. Am I right in believing that the
> COM interface I am trying to use is of what is called a "custom" type,
> that I cannot access using Python + win32com?

Sounds like a perfect job for comtypes, which is a COM library
implemented in pure Python, based on ctypes.  comtypes should make it
easy to access custom (non-dispatch derived) com interfaces, or the
vtable based part of dual interfaces - it would be good however, if you
have a type library for the interfaces.

http://sourceforge.net/projects/comtypes/

No docs yet, but there are tests included which should get you started.

(I have released and announced this 3 weeks ago, but haven't got a
single feedback.  So it seems the need to access custom interfaces is
very low.)

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


Re: List of integers & L.I.S. (SPOILER)

2005-09-08 Thread n00m
Bravo, Bryan!
It's incredibly fast! But your code got WA (wrong answer).
See my latest submission: http://spoj.sphere.pl/status/SUPPER/
Maybe you slipped a kind of typo in it? Silly boundary cases?

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


Re: What's the difference between VAR and _VAR_?

2005-09-08 Thread Johnny Lee

Erik Max Francis wrote:
>
> You're going to have to be more clear; I don't understand your question.
>   What's the difference between
>
>   a = 1
>
> and
>
>   b = 1
>
> besides the difference of name?
>

I thought there must be something special when you named a VAR with '_'
the first character. Maybe it's just a programming style and I had
thought too much...

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


Re: What's the difference between VAR and _VAR_?

2005-09-08 Thread Erik Max Francis
Johnny Lee wrote:

> I mean besides the difference of name...

You're going to have to be more clear; I don't understand your question. 
  What's the difference between

a = 1

and

b = 1

besides the difference of name?

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Who, my friend, can scale Heaven?
   -- _The Epic of Gilgamesh_
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the difference between VAR and _VAR_?

2005-09-08 Thread Johnny Lee

Erik Max Francis wrote:
>
> No, of course not.  One defines a class varaible named `_passxxx_', the
> other defines one named `passsxxx'.
> 


I mean besides the difference of name...

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


Re: Help! Python either hangs or core dumps when calling C malloc

2005-09-08 Thread Christian Stapfer
"Lil" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I already double checked my C code. It runs perfectly fine in C without
> any errors. So in my python program, I added a pdb.set_trace()
> and step through the program and it did not dump. But when i took out
> the tracing, the core dump came back. "sigh"

Check your program for _uninitialized_variables_.
(Just a guess: but what other side-effect than
changing the values of uninitialized variables
- and the program's timing, of course - might
the stepping through with a debugger have?)

Regards,
Christian 


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


Re: What's the difference between VAR and _VAR_?

2005-09-08 Thread Erik Max Francis
Johnny Lee wrote:

> As what you said, the following two code section is totally the same?
> 
> (I)
> class TestResult:
> _passxxx_ = "pass"
> 
> (II) 
> class TestResult: 
> passxxx = "pass"

No, of course not.  One defines a class varaible named `_passxxx_', the 
other defines one named `passsxxx'.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Experience is the name everyone gives to their mistakes.
   -- Oscar Wilde
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the difference between VAR and _VAR_?

2005-09-08 Thread Johnny Lee
As what you said, the following two code section is totally the same?

(I)
class TestResult:
_passxxx_ = "pass"

(II) 
class TestResult: 
passxxx = "pass"

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


Re: What's the difference between VAR and _VAR_?

2005-09-08 Thread Erik Max Francis
Johnny Lee wrote:

>I'm new in python and I was wondering what's the difference between
> the two code section below:
> 
> (I)
> class TestResult:
>   _pass_ = "pass"
>   _fail_ = "fail"
>   _exception_ = "exception"
> 
> (II)
> class TestResult:
>   pass = "pass"
>   fail = "fail"
>   exception = "exception"
> 
>Thanks for your help.

There's nothing per se different between a variable named 'x' and one 
named '_x_'.  The difference here is that pass is a keyword, so

pass = 'pass'

is illegal.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Experience is the name everyone gives to their mistakes.
   -- Oscar Wilde
-- 
http://mail.python.org/mailman/listinfo/python-list


What's the difference between VAR and _VAR_?

2005-09-08 Thread Johnny Lee
Hi,
   I'm new in python and I was wondering what's the difference between
the two code section below:

(I)
class TestResult:
_pass_ = "pass"
_fail_ = "fail"
_exception_ = "exception"

(II)
class TestResult:
pass = "pass"
fail = "fail"
exception = "exception"

   Thanks for your help.

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


Re: How to dynamicly define function and call the function?

2005-09-08 Thread Leif K-Brooks
FAN wrote:
> class test:
> def __init__(self):
> exec("def dfunc(msg):\n\tprint msg\nprint 'exec def function'")
> dfunc('Msg in init ...')   #  it work
>   
> def show(self, msg):
>  dfunc(msg) # doesn't work !
>  exec('dfunc(msg)')  # doesn't work too!

class Test(object):
def __init__(self):
exec "def dfunc(msg):\n print msg"
dfunc('Hello from __init__.')
self.dfunc = dfunc

def show(self, msg):
self.dfunc(msg)


(Of course, this is assuming your real function is more complicated than
the one you've posted; if it isn't, you don't need to use exec to define
it.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about consistency in python language

2005-09-08 Thread Erik Max Francis
Dave Benjamin wrote:

> Mike Meyer wrote:
>> Dave Benjamin <[EMAIL PROTECTED]> writes:
>> 
>>>Python is actually quite consistent in this regard: methods that
>>>modify an object in-place return None;
>> 
>> Um, no. list.pop comes to mind as an immediate counterexample. It may
>> be the only one...
> 
> I'm sure there are counterexamples... maybe 95% is too optimistic. 
> Anyone want to volunteer to compile some stats? ;)

Well, that's because list.pop mutates a list _and_ returns something 
meaningful (not the list itself).  One could modify the above statement 
about consistency to say that methods which modify an object and do not 
return a directed value do not return the object which was mutated, but 
rather return None.  So list.append returns None, but list.pop returns 
the element popped.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Nobody's interested in sweetness and light.
   -- Hedda Hopper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about consistency in python language

2005-09-08 Thread Dave Benjamin
Mike Meyer wrote:
> Dave Benjamin <[EMAIL PROTECTED]> writes:
> 
>>Python is actually quite consistent in this regard: methods that
>>modify an object in-place return None;
> 
> Um, no. list.pop comes to mind as an immediate counterexample. It may
> be the only one...

I'm sure there are counterexamples... maybe 95% is too optimistic. 
Anyone want to volunteer to compile some stats? ;)

I've never had to look up the return type of "pop" though. The only 
thing even remotely ambigious about that term (at least, if you've 
learned what a stack is) is whether it mutates the object, but I don't 
think I've ever seen a "pop" that didn't (aside from toy examples in 
formal methods / ADT related classes).

"os.system" might be a better example, since the return value could be 
one of two obvious things: the status code, or the program's output.

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


Re: redefining a function through assignment

2005-09-08 Thread Michael Spencer
Daniel Britt wrote:
> Hello All,
> I am new to Python so if there is an obvious answer to my question please 
> forgive me. Lets say I have the following code in mod1.py
> 
> class test:
> def func1(self):
> print 'hello'
> 
> 
> Now lets say I have another file called main.py:
> 
> import mod1
> 
> inst = mod1.test()
> inst.func1()
> 
> 
> This will print out hello. Now if I added the following to main:
> def newFunc(var):
> print 'new method'
> 
> mod1.test.func1 = newFunc
> 
> inst.func1()
> 
> 
> This will print out 'new method'. If any other instance of mod1.test is 
> created calling func1, func1 will always reference the newFunc function. 
> This is less than desirable to say the least. Is there any way of preventing 
> this from ever happening? I searched around for quite a while and I haven't 
> been able to find anyone who has a solution. The reason I am asking this is 
> b/c I want to build an application in python that has plugins. I want to 
> make sure that a programmer could not accidently or intentionally clobber 
> over another plugins code, which they could easily do. Any help would be 
> appreciated. Thanks
> 
> ~DJ
> 
> 
The obvious answer is not to give a programmer access to an object that you 
don't want to be messed with.  However, you've probably thought of that...

You could deter (not completely prevent) modification of the class by 
intercepting the __setattr__ of its metaclass:

  >>> class meta_writeonce(type):
  ... def __setattr__(cls, attrname, val):
  ... raise TypeError
  ...
  >>> class A(object):
  ... __metaclass__ = meta_writeonce
  ... def func(self):
  ... print "hello from the unmodified class A"
  ...
  >>> A.func = None
  Traceback (most recent call last):
File "", line 1, in ?
File "", line 3, in __setattr__
  TypeError
  >>> a = A()
  >>> a.func()
  hello from the unmodified class A
  >>>

If you want only to deter overwriting existing class attributes, you could do:

  >>> class meta_writeonlyattributes(type):
  ... def __setattr__(cls, attrname, val):
  ... if hasattr(cls, attrname):
  ... raise TypeError
  ... else:
  ... type.__setattr__(cls, attrname, val)
  ...
  >>> class B(object):
  ... __metaclass__ = meta_writeonlyattributes
  ... def func(self):
  ... print "hello from the unmodified class B"
  ...
  >>> B.func = None
  Traceback (most recent call last):
File "", line 1, in ?
File "", line 4, in __setattr__
  TypeError
  >>> B.func2 = lambda self: "hello from func2"
  >>> b = B()
  >>> b.func()
  hello from the unmodified class B
  >>> b.func2()
  'hello from func2'
  >>>

This is good enough to prevent accidental 'clobbering', but would not prevent a 
programmer rebinding an attribute deliberately:

  >>> type.__setattr__(B,"func",lambda self: "I've got you now")
  >>> b = B()
  >>> b.func()
  "I've got you now"
  >>>

Michael

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


How to dynamicly define function and call the function?

2005-09-08 Thread FAN
I want to define some function in python script dynamicly and call
them later, but I get some problem. I have tried the following:

##
# code
##
class test:
def __init__(self):
exec("def dfunc(msg):\n\tprint msg\nprint 'exec def function'")
dfunc('Msg in init ...')   #  it work

def show(self, msg):
 dfunc(msg) # doesn't work !
 exec('dfunc(msg)')  # doesn't work too!

d = test()
d.show('hello')
###
#output 
##
exec def function
Msg in init ...
Traceback (most recent call last):
  File "test.py", line 10, in ?
d.show('hello')
  File "test.py", line 7, in show
dfunc(msg)
NameError: global name 'dfunc' is not defined
##

I think this maybe cause by the scope of function definition, for the
first call of 'dfunc' in __init__ work. So I tried to define the
function as a member function of class 'test', but this time even the
first call doesn't work:

##
# code
##
class test:
def __init__(self):
exec("def dfunc(self,msg):\n\tprint msg\nprint 'exec def function'")
self.dfunc('Msg in init ...')

def show(self, msg):
 exec("self.dfunc(msg)")

d = test()
d.show('hello')
###
#output 
##
exec def function
Traceback (most recent call last):
  File "test.py", line 9, in ?
d = test()
  File "test.py", line 4, in __init__
self.dfunc('Msg in init ...')
AttributeError: test instance has no attribute 'dfunc'
##

Is there any way I can solve this problem?

Regards

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


Re: List of integers & L.I.S. (SPOILER)

2005-09-08 Thread Bryan Olson
n00m wrote:

 > Firstly I find ordering numbers when moving from left to the right;
 > then I find ord. numbers for backward direction AND for DECREASING
 > subsequences:

Sounds good.

 > Btw, I did it in Pascal. Honestly, I don't believe it can
 > be done in Python (of course I mean only the imposed time limit).
 > http://spoj.sphere.pl/status/SUPPER/

Is there a platform specified? Below is an alleged solution in Python.

--
--Bryan


#!/user/bin/env python

"""
 Python 2.4 solution to:

 http://spoj.sphere.pl/problems/SUPPER/
"""

from sys import stdin


def one_way(seq):
 n = len(seq)
 dominators = [n + 1] * (n * 1)
 # dominators[j] is lowest final value of any increasing sequence of
 # length j seen so far, as we left-right scan seq.
 score = [None] * n
 end = 0
 for (i, x) in enumerate(seq):
 # Binary search for x's place in dominators
 low, high = 0, end
 while high - low > 10:
 mid = (low + high) >> 1
 if dominators[mid] < x:
 low = mid + 1
 else:
 high = mid + 1
 while dominators[low] < x:
 low += 1
 dominators[low] = x
 score[i] = low
 end = max(end, low + 1)
 return score

def supernumbers(seq):
 forscore = one_way(seq)
 opposite = [len(seq) - x for x  in reversed(seq)]
 backscore = reversed(one_way(opposite))
 score = map(sum, zip(forscore, backscore))
 winner = max(score)
 return sorted([seq[i] for i in range(len(seq)) if score[i] == winner])


_ = stdin.readline()
sequence = [int(ch) for ch in stdin.readline().split()]
supers = supernumbers(sequence)
print len(supers)
for i in supers:
 print i,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about consistency in python language

2005-09-08 Thread Mike Meyer
Dave Benjamin <[EMAIL PROTECTED]> writes:
> Python is actually quite consistent in this regard: methods that
> modify an object in-place return None;

Um, no. list.pop comes to mind as an immediate counterexample. It may
be the only one...

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


Re: Question about consistency in python language

2005-09-08 Thread Dave Benjamin
[EMAIL PROTECTED] wrote:
> Let's say I define a list of pairs as follows:
> 
>>>l = [('d', 3), ('a', 2), ('b', 1)]
> 
> 
> Can anyone explain why this does not work?
> 
>>>h = {}.update(l)
> 
> 
> and instead I have to go:
> 
>>>h = {}
>>>h.update(l)
> 
> to initialize a dictionary with the given list of pairs?
> 
> when an analagous operation on strings works fine:
> 
>>>s = "".join(["d","o","g"])
> 
> 
> Seems inconsistent. 

Python is actually quite consistent in this regard: methods that modify 
an object in-place return None; methods that do not modify an object 
in-place return a new object instead. Since strings are immutable, they 
cannot be modified in-place, so it makes sense for the "join" method to 
return a new string. On the other hand, Python's dictionaries are 
imperative-style and so most operations on a dictionary modify an 
existing dictionary.

I was initially bothered by the phenomenon of so many methods returning 
None because they could not be chained. But I have come to deeply 
appreciate this style for a couple of reasons. First, it makes it clear 
which methods are side-effecting (like "update") and which are not (like 
"sort").

Second, it is not always clear what a good return value is for a 
mutator. Perhaps {}.update() should return the dictionary, making 
chaining convenient. Perhaps it should return the total number of items 
after updating. Or maybe it should return the number of new keys that 
were added, or a list of those keys. All of these are plausible 
behaviors; the problem is that "update" is not a function. Its job is to 
change something, not return something. Any possible return value would 
be a convenience for certain tasks and useless for other tasks.

It's also hard to remember, in my opinion. For example, JavaScript has a 
"push" method on the Array object which behaves like Python's "append" 
method on lists:

js> var a = [];
js> a.push(5);
1
js> a.push(6);
2

I bet you that almost nobody knows that "push" returns the new length of 
the Array. It could just as easily have returned "a" here. I could 
always write "a.length", if I really needed to know the new length. This 
sort of thing becomes language trivia, and when I write in JavaScript I 
always ignore the result of "push" because, even if *I* know what it 
returns, chances are that my readers don't.

Another reason that Python adopts the convention of returning None for 
mutators is that it discourages the use of side-effecting code in 
expressions. Mixing side-effects with expressions can lead to code that 
is hard to read and understand. This is often debated by those who know 
better and wish to write things like "h.update(a).update(b)" (method 
chaining) or "while (line = file.readline()): ...". Python's decision is 
pretty clear, and it's also evident in the division between statements 
and expressions.

Regardless of whether you like Python's style decision or not, if you 
dig deeper I think you will find that it is pretty consistent, and that 
there are useful benefits to Python's way of handling side effects.

Dave

PS. If mutators had to return a value, I'd have them return "self", 
probably 95% of the time. But then, it wouldn't be Python anymore. It'd 
be Ruby, maybe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about consistency in python language

2005-09-08 Thread Bengt Richter
On 8 Sep 2005 16:03:12 -0700, [EMAIL PROTECTED] wrote:

>Let's say I define a list of pairs as follows:
>>>l = [('d', 3), ('a', 2), ('b', 1)]
>
>Can anyone explain why this does not work?
>>>h = {}.update(l)
>
>and instead I have to go:
>>>h = {}
>>>h.update(l)
>to initialize a dictionary with the given list of pairs?
>
>when an analagous operation on strings works fine:
>>>s = "".join(["d","o","g"])
>
>Seems inconsistent. 
>
Join isn't that good an analogy, because the inputs and outputs are immutable.
list.sort is more comparable to dict.update. There is now a builtin sorted 
function
that will take a list and return a sorted one. Perhaps there will come an 
"updated"
function analogously for dictionaries, but I don't think the use is that common,
and you can make your own. Several ways. If you want to start with an empty dict
anyway, the dict constructor will accept a sequence of pairs (so long as the 
first
of every pair is hashable, which is also required for update). E.g.,

 >>> dict([('d', 3), ('a', 2), ('b', 1)])
 {'a': 2, 'b': 1, 'd': 3}

or the sequence of pairs as a tuple expression
 >>> dict((('d', 3), ('a', 2), ('b', 1)))
 {'a': 2, 'b': 1, 'd': 3}

or sometimes it's handy to start with the keys and values as separate sequences
and zip them together for the dict constructor

 >>> dict(zip('dab', [3,2,1]))
 {'a': 2, 'b': 1, 'd': 3}

or a generator expression

 >>> dict((k,3-i) for i,k in enumerate('dab'))
 {'a': 2, 'b': 1, 'd': 3}


though note that dict wants the sequence as a single argument:
 >>> dict( ('d', 3), ('a', 2), ('b', 1) )
 Traceback (most recent call last):
   File "", line 1, in ?
 TypeError: dict expected at most 1 arguments, got 3

 >>> def updated(d, seq): d=d.copy(); d.update(seq); return d
 ...
 >>> updated({}, [('d', 3), ('a', 2), ('b', 1)])
 {'a': 2, 'b': 1, 'd': 3}

One rationale for not returning a reference to the mutated value
from a mutating method is that it is too easy to think of it
as a pure expression, and forget the persistent side effect of
mutating the object. I think that was thought too bug-prone.

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


Re: Video display, frame rate 640x480 @ 30fps achievable?

2005-09-08 Thread Peter Hansen
Guenter wrote:
> I would be interested in how many frames this reaches on my computer.
> Did you create like two arbitrary images under PLI and then display
> them one after another? Then stop the time and count how many times you
> were able to switch between the two?
> 
> One feature I need to figure out when using PLI is that I need to move
> a cursor over the image, controlled by a joystick. But I could add that
> with the drawing feature when creating the image.

Maybe it would be a good idea to tell us something about the nature of 
the image you'll be displaying (though the fact that it needs a 
cross-hair or something is useful information, for a start).  For 
example, is it a photographic image?  A map?  A drawing?  Is it 
generated dynamically, or is it static?  Do you pan over it, or zoom it, 
or what?

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


Re: Help! Python either hangs or core dumps when calling C malloc

2005-09-08 Thread Mike Meyer
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:

> Lil wrote:'
>
>>I already double checked my C code. It runs perfectly fine in C without
>> any errors. So in my python program, I added a pdb.set_trace()
>> and step through the program and it did not dump. But when i took out
>> the tracing, the core dump came back. "sigh"
>
> so triple-check it.
>
> if your code overwrites the malloc buffer, it's perfectly possible
> that it appears to run fine when you run it standalone or under the
> debugger, but that doesn't mean that your code is fine.

The appropriate aphorism is: "Testing can never reveal the absence of
bugs."

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


redefining a function through assignment

2005-09-08 Thread Daniel Britt
Hello All,

 I am new to Python so if there is an obvious
answer to my question please forgive me. Lets say I have the following
code in mod1.py



class test:

 def func1(self):

  print 'hello'





Now lets say I have another file called main.py:



import mod1



inst = mod1.test()

inst.func1()





This will print out hello. Now if I added the following to main:

def newFunc(var):

 print 'new method'



mod1.test.func1 = newFunc



inst.func1()





This will print out 'new method'.  If  any other instance of
mod1.test is created calling func1, func1 will always reference the
newFunc function. This is less than desirable to say the least. Is
there any way of preventing this from ever happening? I searched around
for quite a while and I haven't been able to find anyone who has a
solution. The reason I am asking this is b/c I want to build an
application in python that has plugins. I want to make sure that a
programmer could not accidently or intentionally clobber over another
plugins code, which they could easily do. Any help would be
appreciated. Thanks



~DJ



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

Re: Question about consistency in python language

2005-09-08 Thread Sam Pointon
update updates the dictionary in place - it actually returns None, not
the updated dict. However, you can construct a dictionary from a list
of (key, value) pairs using dict(list). Example:

>>>l = [('foo', 'bar'), ('baz', 'qig')]
>>>d = dict(l)
>>>print d
{'foo': 'bar', 'baz': 'qig'}

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


Re: Question about consistency in python language

2005-09-08 Thread James Stroud
This is the difference between mutable and immutable types. In this sense it 
is consistent.

If you want to do the former in one shot:

   h = dict(l)

Also, you shouldn't use "1", I mean "l", as a variable name. It gets confusing 
because "l", I mean "1", looks a lot like "1", I mean "l".

James

On Thursday 08 September 2005 16:03, [EMAIL PROTECTED] wrote:
> Let's say I define a list of pairs as follows:
> >>l = [('d', 3), ('a', 2), ('b', 1)]
>
> Can anyone explain why this does not work?
>
> >>h = {}.update(l)
>
> and instead I have to go:
> >>h = {}
> >>h.update(l)
>
> to initialize a dictionary with the given list of pairs?
>
> when an analagous operation on strings works fine:
> >>s = "".join(["d","o","g"])
>
> Seems inconsistent.
>
> thanks,
> Scott

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python compiled?

2005-09-08 Thread Grant Edwards
On 2005-09-08, Jorgen Grahn <[EMAIL PROTECTED]> wrote:
> On Tue, 06 Sep 2005 17:29:46 -, Grant Edwards <[EMAIL PROTECTED]> wrote:
>> On 2005-09-06, Jorgen Grahn <[EMAIL PROTECTED]> wrote:
>>
>>> I also believe it's better to convince the end user to install
>>> Python before installing the application[1], rather than to
>>> try to sneak in an interpreter with py2exe or something -- an
>>> interpreter which the end user cannot update, manage or use
>>> for other things.
>>
>> There's a typo in that last phrase.  It should read "[...] --
>> an interpreter the user isn't going to uninstall or break
>> because he doesn't know what it is or why it's there."
>
> I meant what I wrote, of course (and you should really have
> added a smiley.)

Nah, I knew everybody would get it without one. c.l.p readers
are smarter than the average bear.

> Might be because I'm more at home in Linux (Debian). The
> bundling-an-interpreter approach to distribution software is
> simply not applicable on those platforms, for many different
> reasons.

Of course.  I never ship an interpreter for Linux apps.  Just
the python source.  I thought we were talking about Windows
apps what with the reference to py2exe and Inno Setup and
whatnot.  Linux comes with Python already installed, though
sometimes wxPyton and friends aren't installed by default.
Mostly my Linux Python apps are strictly command-line anyway.  

> Maybe that's why I have a hard time even understanding the
> idea. I see lots of problems and few benefits.

I've had limited success telling Windows users to install
Python.  Even if you point them to the ActiveState MSI file
with all the Win32 stuff already bundled, they seem to muck it
up most of the time.  I can't imagine how -- it's dead simple
to install, but they manage to screw it up.

> For example, the issue of security fixes. If there's a bug in
> Python which makes anyone running an interpreter vulnerable,
> how are those users even going to /find out/ about it?

I guess you ship them an update -- same as you would for a
security fix for the other parts of the application.

-- 
Grant Edwards   grante Yow!  My TOYOTA is built
  at   like a... BAGEL with CREAM
   visi.comCHEESE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


ipython + gnu emacs on windows

2005-09-08 Thread madhusub
Has anyone managed to get ipython within gnu emacs (21.3.1) working on
Windows XP?

I've the following versions of required software
Python 2.4.1
IPython 0.6.15
python-mode.el (defconst py-version "$Revision: 4.63 $"

I have also installed other ancilliary packages (per
http://ipython.scipy.org/doc/manual/node2.html#sub:Under-Windows)

Now when i do M-x py-shell, I get to the ipython shell with a bizarre
prompt as follows

^A^BIn [^A^B1^A^B]: ^A^B
^A^BIn [^A^B1^A^B]: ^A^B?
---Return to continue, q to quit---

If I type '?' without quotes as shown above, I get a single line
(---Return to continue, q to quit--- ) and nothing else.

Also any errors are not reported on the screen.

Any ideas? Thanks for your help

Note: invoking ipython for a regular nt cmd shell works just fine.

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


Re: Django and SQLObject. Why not working together?

2005-09-08 Thread Ian Bicking
Bruno Desthuilliers wrote:
> Also, there's something like darwinism at play here. Yes, there are a
> lot of concurrent ORM/Templating/Web Publishing/GUI/Whatnot projects
> around, but I guess only the best of them will survive - eventually
> 'absorbing' what's good in the others.

No, they will all survive.  There's no pressure or reason why a
software library won't keep surviving; some people -- if only the
original author -- will write software using the library, and they'll
be reluctant to abandon it, and not very motivated to change their
software.  The listings will live on in PyPI and on Wikis for a long
time to come, well after active development has stopped.  And, indeed,
real development could start up at any time.  For instance, both PyDO
and MiddleKit were dormant for a long time before more recent activity.
 All software can go into periods of dormancy, because the individuals
that write it have other things going on in their lives.  It isn't
necessarily death to the project.  Which makes it all the more
ambiguous what "survival" means.

Ultimately I'm pessimistic -- while good features can be absorbed, bad
features and dead libraries never go away, they just fade away very
very slowly.  It isn't natural selection.

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


Question about consistency in python language

2005-09-08 Thread lechequier
Let's say I define a list of pairs as follows:
>>l = [('d', 3), ('a', 2), ('b', 1)]

Can anyone explain why this does not work?
>>h = {}.update(l)

and instead I have to go:
>>h = {}
>>h.update(l)
to initialize a dictionary with the given list of pairs?

when an analagous operation on strings works fine:
>>s = "".join(["d","o","g"])

Seems inconsistent. 

thanks,
Scott

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


Re: Video display, frame rate 640x480 @ 30fps achievable?

2005-09-08 Thread Guenter
Fredrik Lundh schrieb:

> getting the data into the "blittable" object fast enough may be more
> of a problem, though.  I don't know how good wxPython is in that
> respect; Tkinter's PhotoImage is probably not fast enough for video,
> but a more lightweight object like PIL's ImageWin.Dib works just
> fine (I just wrote a test script that reached ~200 FPS at 1400x900,
> but my machine is indeed a bit faster than a 1 GHz Celeron).
>
> 

I would be interested in how many frames this reaches on my computer.
Did you create like two arbitrary images under PLI and then display
them one after another? Then stop the time and count how many times you
were able to switch between the two?

One feature I need to figure out when using PLI is that I need to move
a cursor over the image, controlled by a joystick. But I could add that
with the drawing feature when creating the image.

Now is there a feature that would allow me to map data from a memory
into an image? I saw there is a function called Image.frombuffer(). If
I understand that right the buffer is a python data type. If I get that
data type to represent a specific memory where I can dma the data to I
should be able to display them pretty fast?


Guenter

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


Re: reading the last line of a file

2005-09-08 Thread Michael Sparks
Xah Lee wrote:
> isn't there a way to implement tail in python with the same class of
> performance?
>
> how's tail implemented?:

Those crazy open source developers have an implementation here:
http://cvs.sourceforge.net/viewcvs.py/mkcdrec/mkcdrec/busybox-0.60.5/Attic/tail.c?rev=1.1&view=markup

It's not documented. It's pretty short though, I'm sure you won't have any
problems ripping it to pieces understanding it.

If it is a problem, a more documented version here (however I'm sorry, this
also by those open source/free software people you love to attack):

http://www.koders.com/c/fid8DEE98A42C35A1346FA89C328CC3BF94E25CF377.aspx

If you want something not by open source crazies (as you like to refer to
us), you may prefer this link:
   http://minnie.tuhs.org/UnixTree/V7/usr/src/cmd/tail.c.html

However that's even less documented (despite being not open source, just
"visible"), and more obfuscated.

As a compromise, you could always look at plan 9's implementation here:
   * http://swtch.com/usr/local/plan9/src/cmd/tail.c

If you're after alternatives, you could always try here: (where all these
links came from)
http://www.google.com/search?q=tail.c

Fairly informative set of links provided by that highly non-obvious
search

Hope that helps,

Best Regards,


Michael.

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


Re: Django and SQLObject. Why not working together?

2005-09-08 Thread Bruno Desthuilliers
Ksenia Marasanova a écrit :
> 2005/9/8, Sokolov Yura <[EMAIL PROTECTED]>:
> 
>>Django Model is wonderfull. But SQLObject more flexible (and powerfull,
>>as i think, and has already more db interfaces).
>>But Django Model is tied with Django, and using Django with another OO
>>mapping is not comfortable.
>>Why do not working together? I can't understand.
> 
> 
(snip)
> 
> BTW, while SQLObject is very advanced, there are/were some other ORM
> mappers in python:
> http://www.thinkware.se/cgi-bin/thinki.cgi/ObjectRelationalMappersForPython
> While not all of them share the same philosophy with SQLObject, some
> do. But they are not merging together either. Just like web frameworks
> :)
> 
> I guess it's just the joy of creating something that fits you mind and
> solves all you problems, instead of picking up something that does it
> partially and was created by another person with different views and
> philosophy.
> 

Also, there's something like darwinism at play here. Yes, there are a 
lot of concurrent ORM/Templating/Web Publishing/GUI/Whatnot projects 
around, but I guess only the best of them will survive - eventually 
'absorbing' what's good in the others.

I also noticed something like a 'converging evolution' scheme in Python 
these days. It strikes me that more and more frameworks seems to be 
based on concepts like intelligent properties assembled in schemas 
(Zope, Plone, Django, BasicProperties, SQLObjects...), interface 
adaptation (PEAK, Zope3, ...) and 'configurable polymorphism' (PEAK, 
Zope3, ...). Strange enough, I was developping a similar solution for a 
higher-level LDAP api when I noticed this... It seems to me that it has 
to do with recent evolutions of Python (decriptors, decorators, 
metaclasses made simple etc) beginning to be widely adopted and taken 
advantage of by Python programmers.

Anyone else on this ?

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


Re: reading the last line of a file

2005-09-08 Thread Xah Lee
isn't there a way to implement tail in python with the same class of
performance?

how's tail implemented?

 Xah
 [EMAIL PROTECTED]
∑ http://xahlee.org/

Fredrik Lundh wrote:
> Fredrik Lundh wrote:
>
> > zcat|tail is a LOT faster.
>
> and here's the "right way" to use that:
>
> from subprocess import Popen, PIPE
> p1 = Popen(["zcat", filename], stdout=PIPE)
> p2 = Popen(["tail", "-1"], stdin=p1.stdout, stdout=PIPE)
> last_line = p2.communicate()[0]
>
> (on my small sample, this is roughly 15 times faster than the empty for loop)
> 
> 

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

Re: py2exe 0.6.1 released

2005-09-08 Thread Chris Lambacher
I am also getting this.  In my case I think it is related to win32com.shell
since when building I get the following error:
error: 
C:\work\...\build\bdist.win32\winexe\collect-2.4\win32com.shell\shell.pyd: No 
such file or directory

... is a place holder for a very long path.

The problem is fixed by creating the directory win32com.shell which is
probably the wrong solution and causing the Unexpectedly terminated error.
It would appear that the win32com.shell hack
(http://starship.python.net/crew/theller/moin.cgi/WinShell) does not work in
single file executable mode.

-Chris

On Tue, Sep 06, 2005 at 08:50:54AM -0700, cmkl wrote:
> Hi,
> 
> I didnt succeed to bundle vpython-3.2.3 with py2exe-0.6.1 - regardless
> if its build as single file or not:
> 
> "This application has requested the Runtime to terminate it in an
> unusual way"  and so on...
> 
> This error message seems not generated by py2exe. At least I could not
> find a reference to it in the sources of py2exe.
> 
> Regards
> 
> Carl
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dual processor

2005-09-08 Thread Jorgen Grahn
On 06 Sep 2005 14:08:03 -0700, Paul Rubin  wrote:
> Jorgen Grahn <[EMAIL PROTECTED]> writes:
>> I feel the recent SMP hype (in general, and in Python) is a red herring. Why
>> do I need that extra performance? What application would use it?
>
> How many mhz does the computer you're using right now have?  When did
> you buy it?

I'm not a good example -- my fastest computer is a Mac Mini. Come to think
of it, last time I /really/ upgraded for CPU speed was when I bought my
Amiga 4000/030 in 1994 ;-)

My 200MHz Pentium feels a bit slow for some tasks, but most of the time I
cannot really tell the difference, and its lack of RAM and disk space is
much more limiting.

> Did you buy it to replace a slower one?  If yes, you must
> have wanted more performance.  Just about everyone wants more
> performance.  That's why mhz keeps going up and people keep buying
> faster and faster cpu's.

I'm not sure that is true, for most people. People keep buying faster CPUs
because the slower ones become unavailable!  How this works from an
economical and psychological point of view, I don't know.

> CPU makers seem to be running out of ways to increase mhz.  Their next
> avenue to increasing performance is SMP, so they're going to do that
> and people are going to buy those.  Just like other languages, Python
> makes perfectly good use of increasing mhz, so it keeps up with them.
> If the other languages also make good use of SMP and Python doesn't,
> Python will fall back into obscurity.

I don't believe that will ever happen. Either of them.

My CPU spends almost all its time running code written in C.  That code has
been written over the last thirty years under the assumption that if there
is SMP, it will be taken advantage of on the process level. I cannot imagine
anyone sitting down and rewriting all that code to take advantage of
concurreny.

Thus, I don't believe that SMP and SMP-like technologies will improve
performance for ordinary people. Or, if it will, it's because different
processes will run concurrently, not because applications become concurrent.
Except for some applications like image processing programs, which noone
would dream of implementing in Python anyway.

New, radical and exciting things don't happen in computing very often.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python compiled?

2005-09-08 Thread Jorgen Grahn
On Wed, 7 Sep 2005 08:40:28 -0500, Terry Hancock <[EMAIL PROTECTED]> wrote:
> On Tuesday 06 September 2005 11:32 am, Jorgen Grahn wrote:
>> I hope people are less hesitant to install "interpreted" applications today
>> than they were ten years ago.
>> 
>> I also believe it's better to convince the end user to install Python before
>> installing the application[1], rather than to try to sneak in an interpreter
>> with py2exe or something -- an interpreter which the end user cannot update,
>> manage or use for other things.
>
> I have to confess to be very ignorant about the Windows installation options
> for Python packages, but surely in principle at least, it should be possible
> to make self-installing .EXE files that do what I get from
>
> apt-get install python-mypackage
>
> or at least
>
> dpkg --install mypackage
>
> That is to say, which install an interpreter if one isn't already there, and
> then install the package. Or, upon finding an interpreter install into it
> along the lines of distutils.

It has been a while since I used bdist_wininst, but I hope it at least

a) detects if there is a suitable Python installed
b) otherwise, suggests that the user should install one,
   explains why, gives the URL of a suitable package,
   and the size of the download

Things get trickier, of course, if the software depends on external packages
and modules.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Using Python with COM to communicate with proprietary Windows software

2005-09-08 Thread Joakim Persson
Hello all. I am involved in a project where we have a desire to
improve our software testing tools, and I'm in charge of looking for
solutions regarding the logging of our software (originating from
embedded devices). Currently, we are using a heavyweight, proprietary
log tool developed by another part of the company. This tool contains
all "standard" logging functionality, but we also need to insert
"debug" log points in the software of the embedded device, and we
cannot get new releases of this big log tool very often (typically,
these debug log points might be very temporarily inserted into the
software during the development phase). 

Therefore, we have added a requirement to the log tool where we made
them implement a COM server in the log tool, so that we can access
arbitrary log points in the embedded device. My thoughts then, as
someone who wants to bring in more interpreted, lightweight languages
(and SW development processes) into the organization, was to use
Python to easily add log parsing and log presentation in different
ways. 

This means that I must come up with a way to interface Python with
this log tool. After some investigations, I have run inte problems --
my inital approach was to use Python + win32com to communicate with
the COM interface. Unfortunately, it seems as if win32com, even if I
makepy the log tool executable (which gives me the full range of
available functions of the interface, just as expected), cannot be
used, since the interface is not a simple IDispatch interface. Also, I
discovered that the Python client must also implement a COM server to
receive the log information as it is generated by the embedded device,
passed into the log tool and then sent by the log tool COM server. 

I have a rather bloated C++ client prototype which "works", so I
should have all the code needed to invoke the interface, but this
client is of course rather bloated in itself and not suitable for my
experimental programming approach. Am I right in believing that the
COM interface I am trying to use is of what is called a "custom" type,
that I cannot access using Python + win32com? I can use Python +
win32com just fine when accessing most normal COM servers (typical
example: MS Office programs implementing IDispatch interfaces), but I
cannot access the proprietary interface -- I get "interface not
supported"-type messages (I can query the CoClass for IUnknown and
IDispatch interfaces, but not using the known IID for the custom
interface). 

So, I'm trying to sum up my options. I have looked at Boost to try to
merge C++ and Python code, take care of the COM server/client creation
and messaging by the C++ part, and then take care of the data
processing/presentation part in Python, like so: 

++
|PRES| <-- Python and friends (wxPython could be interesting)
++
 
++
|DATA| <-- Pure python
++
 
++
|COM | <-- C++
++

... all linked together into, eventually, one Python executable
(linking in the C++ through a DLL which is then imported by Python). 

I haven't fully explored how to do this, but it seems as if Boost is
usable using MSVC++ (the organizations standard IDE) -- has anyone
tried something similar? My final idea is to "give up" on one single
program for this, and use a C++ intermediate program to communicate
with the log tool and then let it forward its data through sockets or
named pipes, which Python seems to deal with more easily. 

I have tried using Java + jawin as well just for a quick exploratory
spike, and ran into the same problems ("interface not supported" etc).
The jawin documentation talks a bit about wrapping the custom
interface into java objects, but this is rather obscure and
undocumented, and untangling it would take quite some time -- so I
figured that somebody could have done something similar in the past. 

Does anyone have any hints on how to go forward? The whole point with
my project is to demonstrate the usefulness of rapid prototyping using
Python (this has already been successful for smaller test tools, test
scripts and smaller intermediary programs), but I don't want something
like COM client/server obscurity getting in the way...

Thanks in advance, 

-- 
Joakim Persson
M.Sc student, CS/E @ LTH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python compiled?

2005-09-08 Thread Jorgen Grahn
On Tue, 06 Sep 2005 17:29:46 -, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2005-09-06, Jorgen Grahn <[EMAIL PROTECTED]> wrote:
>
>> I also believe it's better to convince the end user to install Python before
>> installing the application[1], rather than to try to sneak in an interpreter
>> with py2exe or something -- an interpreter which the end user cannot update,
>> manage or use for other things.
>
> There's a typo in that last phrase.  It should read "[...] --
> an interpreter the user isn't going to uninstall or break
> because he doesn't know what it is or why it's there."

I meant what I wrote, of course (and you should really have added a smiley.)

Might be because I'm more at home in Linux (Debian). The
bundling-an-interpreter approach to distribution software is simply not
applicable on those platforms, for many different reasons.

Maybe that's why I have a hard time even understanding the idea.
I see lots of problems and few benefits.

For example, the issue of security fixes. If there's a bug in Python which
makes anyone running an interpreter vulnerable, how are those users even
going to /find out/ about it?

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Jabber client?

2005-09-08 Thread Jarek Zgoda
Paul Rubin napisał(a):

> Is there such a thing as a general purpose Python Jabber client?  I'm
> imagining one that uses tkinter.
> 
> A little Googling finds a couple of Jabber protocol libraries written
> in Python, a few half-finished projects, and a client> 
> If there's more than one, does anyone have a favorite?

Gajim is most advanced one, if you don't mind GUI. There are also few
CLI XMPP/Jabber clients, but most of them is *x-limited.

As for libs, there are 2 that are worth of attention: xmpp.py, which has
very slow pace of advancement (most current version is available from
Gajim svn repo, sigh!) and PyXMPP, which is very limited in usage due to
use of libxml, which makes porting to Windows a real PITA. If you want a
decent library, get the one from Gajim repo, it is not as standard
compliant as PyXMPP (PyXMPP author is a JSF member), but is really and
true cross platform.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Jabber client?

2005-09-08 Thread Oliver Andrich
Hi Paul,

take this one. http://xmpppy.sourceforge.net/ It is used inside gajim,
my favorite jabber client. http://gajim.org/ It works like a charm.
And I am also using xmpppy for some monitoring tools, that alert our
admins.

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Jabber client?

2005-09-08 Thread Valentino Volonghi aka Dialtone
Paul Rubin  wrote:

> If there's more than one, does anyone have a favorite?

twibber
http://slarty.polito.it:8069/~sciasbat/wiki/moin.cgi/twibber

Based on Twisted. Will probably be included in Twisted at some point in
the future. Twisted already has a jabber protocol implementation inside
it but it's very simple (and for example doesn't support SASL).

-- 
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.4
Blog: http://vvolonghi.blogspot.com
http://weever.berlios.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Jabber client?

2005-09-08 Thread Paul Rubin
Is there such a thing as a general purpose Python Jabber client?  I'm
imagining one that uses tkinter.

A little Googling finds a couple of Jabber protocol libraries written
in Python, a few half-finished projects, and a client for the Sharp
Zaurus, but I didn't spot any simple portable ones that are finished
and ready to use.

If there's more than one, does anyone have a favorite?

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


Re: List of integers & L.I.S.

2005-09-08 Thread n00m
> 4 5 1 2 3 6 7 8   << the list itself
> 1 2 1 2 3 4 5 6   << ordering numbers for forward direction
> 2 1 6 5 4 3 2 1   << ordering numbers for backward direction
> ===
> 3 3 7 7 7 7 7 7   << sums of the pairs of ord. numbers
Oops! Sorry for miscounting in backward direction.
Should be (anyway the answer stays the same):

4 5 1 2 3 6 7 8   << the list itself
1 2 1 2 3 4 5 6   << ordering numbers for forward direction
5 4 6 5 4 3 2 1   << ordering numbers for backward direction
=== 
6 6 7 7 7 7 7 7   << sums of the pairs of ord. numbers

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


Re: __dict__ of object, Was: Regular Expression IGNORECASE differentfor findall and split?

2005-09-08 Thread Chris
Mike Meyer wrote:
> Chris <[EMAIL PROTECTED]> writes:
> 
>>Fredrik Lundh wrote:
>>
>>>Chris <[EMAIL PROTECTED]> wrote:
>>>
>>>
but more of a basic question following, I was doing the following before:

method = 'split' # came from somewhere else of course
result = re.__dict__[method].(REGEX, TXT)

precompiling the regex

r = compile(REGEX)

does give an regex object which has the needed methods

print dir(r)
['__copy__', '__deepcopy__', 'findall', 'finditer', 'match', 'scanner',
'search', 'split', 'sub', 'subn']

but how do I evaluate them without explicitly calling them?

result = r.__???MAGIC???__[method](TXT)

obviously I am not a Python pro ;)
>>>
>>>I really don't understand why you think you have to write
>>>your RE code that way, but the mechanism you're looking
>>>for is getattr:
>>>result = getattr(r, method)(TXT)
>>>
>>
>>thanks (also to Steven) for the info, that is exactly what i was
>>looking for.
>>
>>reason is that I built a small UI in which the user may choose if he
>>want to do a split, findall (and maybe later others like match or
>>search). So the method name comes in "from the UI". I could of course
>>use if/elif/else blocks but thought getattr should be shorter and
>>easier. I was not really aware of getattr which I was looking for on
>>other occations before...
> 
> 
> So why is the UI returning strings, instead of code objects of some
> kind?
> 
> http://cthedot.de/retest/

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


Re: Django and SQLObject. Why not working together?

2005-09-08 Thread Ksenia Marasanova
2005/9/8, Sokolov Yura <[EMAIL PROTECTED]>:
> Django Model is wonderfull. But SQLObject more flexible (and powerfull,
> as i think, and has already more db interfaces).
> But Django Model is tied with Django, and using Django with another OO
> mapping is not comfortable.
> Why do not working together? I can't understand.

You probably want to post it on django-developers mailing list: 
http://groups.google.com/group/django-developers

BTW, while SQLObject is very advanced, there are/were some other ORM
mappers in python:
http://www.thinkware.se/cgi-bin/thinki.cgi/ObjectRelationalMappersForPython
While not all of them share the same philosophy with SQLObject, some
do. But they are not merging together either. Just like web frameworks
:)

I guess it's just the joy of creating something that fits you mind and
solves all you problems, instead of picking up something that does it
partially and was created by another person with different views and
philosophy.

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


Re: Help! Python either hangs or core dumps when calling C malloc

2005-09-08 Thread Fredrik Lundh
Lil wrote:'

>I already double checked my C code. It runs perfectly fine in C without
> any errors. So in my python program, I added a pdb.set_trace()
> and step through the program and it did not dump. But when i took out
> the tracing, the core dump came back. "sigh"

so triple-check it.

if your code overwrites the malloc buffer, it's perfectly possible
that it appears to run fine when you run it standalone or under the
debugger, but that doesn't mean that your code is fine.

 



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


Re: Installation question

2005-09-08 Thread Nx
Thanks anyway
I wished there was a sure step by step approach 
to get it to work but I can't think of any
good solution and I do not want to reinstall
a well optimized system if something goes astray.


Nx



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


Re: Help! Python either hangs or core dumps when calling C malloc

2005-09-08 Thread Lil
I already double checked my C code. It runs perfectly fine in C without
any errors. So in my python program, I added a pdb.set_trace()
and step through the program and it did not dump. But when i took out
the tracing, the core dump came back. "sigh"

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


Re: generator object, next method

2005-09-08 Thread Terry Reedy

"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message 
news:[EMAIL PROTECTED]
> Duncan Booth <[EMAIL PROTECTED]> writes:
>> 1) Every time you access gen.next you create a new method-wrapper 
>> object.
>
> Why is that?  I thought gen.next is a callable and gen.next() actually
> advances the iterator.  Why shouldn't gen.next always be the same object?

If you explicitly or implicitly (via for loop) calculate gen.next exact 
once (as I presume for loops do, and as I would for explicit while loop), 
then it is.  When you keep a reference to the wrapper, and call it 
repeatedly via that wrapper, then all is as you expect.

next_x = genfunc(*args).next
while True:
   x = next_x() # same next_x each time
   

Terry J. Reedy



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


Re: Video display, frame rate 640x480 @ 30fps achievable?

2005-09-08 Thread Michael Sparks
Guenter wrote:

> I need to develop an application that displays video 640x480 16-bit per
> pixel with 30 fps  it is possible to achieve that frame rate and still
> have some resources for other processing left? 

Yes.

Co-incidentally we've been looking at video playback this week as well. 
We've been using Pygame with an Overlay surface, and it works fairly well.
Initially we're testing with simple IYUV raw video data, and it's a good 
idea to use a modern video card supported by your OS, but other than that 
we've not had problems. If you're interested in code, let us know :-)

If you end up using the framebuffer device in linux under xorg's X11 (not
exactly an ideal setup for video playback anyway!) there is a little oddity
that we found, due to SDL underneath, but we've been able to work
around that. The system I'm working on normally has that issue, and as
a result isn't accelerated and is a 1.6Ghz machine, but can do standard
defintion video (720x576) playback happily at >30fps. Normally though
most people can offload this to their graphics card so there shouldn't
be issues on your 1Ghz machine.

Clearly if you're interested in driving that you need to decode some data
source to IYUV, but that's a different issue. 

People have embedded pygame in wxPython before (I don't know how
though, I've only seen screenshots of the integration) so although you said
wxPython and might've discounted pygame based on that, it might still be
suitable for you. 

Regards,


Michael.

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


Re: Printer List from CUPS

2005-09-08 Thread djw
Mike Tammerman wrote:
> Hi,
> 
> I want to get the printer list from CUPS. I found some ways using
> 
> lpstat -p and
> http://localhost:631/printers
> 
> but, these ways require some parsing and I am not sure, if the parsing
> works all the time. A pythonic way would be very helpful.
> 
> Thanks,
> Mike
> 

The HPLIP project (hpinkjet.sf.net) includes a basic CUPS extension 
module in the src/prnt/cupsext directory. Its pretty rough, but it will 
return a list of CUPS printers easily enough. I am in the process of 
rewriting it in Pyrex and hope to include more complete CUPS API coverage.

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


Re: List of integers & L.I.S.

2005-09-08 Thread n00m
PS: I've still not read 2 new posts.

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


Re: List of integers & L.I.S.

2005-09-08 Thread n00m
[EMAIL PROTECTED] wrote:
> So, this has no real world use, aside from posting it on a website.
I don't think you're quite right.
We never know where we gain and where we lose.

> So clearly it served a very useful purpose!  ;)
Thanks, Manuel!

> your question is different than the question on this website.
Not exactly so (maybe I'm wrong here). How I did it (but got TLE
- Time Limit Exceeded (which is 9 seconds)).

Firstly I find ordering numbers when moving from left to the right;
then I find ord. numbers for backward direction AND for DECREASING
subsequences:

4 5 1 2 3 6 7 8   << the list itself
1 2 1 2 3 4 5 6   << ordering numbers for forward direction
2 1 6 5 4 3 2 1   << ordering numbers for backward direction
===
3 3 7 7 7 7 7 7   << sums of the pairs of ord. numbers

Now those numbers with sum_of_ord.pair = max + 1 = 6 + 1
are the answer.
So the answer for your sample is: 1 2 3 6 7 8

Btw, I did it in Pascal. Honestly, I don't believe it can
be done in Python (of course I mean only the imposed time limit).
http://spoj.sphere.pl/status/SUPPER/

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


Re: List of integers & L.I.S.

2005-09-08 Thread [EMAIL PROTECTED]
> That's easy to follow, although their use of a Van Emde-Boas set as a
> given hides the most challenging part (the "efficient data structure"
> part).

The "efficient data structure" is the easy part.

Obviously, it is a dict of lists.

...or is it a list of dicts?...

...or is it a tuple of generators?...

Anyway, "being aware of the literature", "thinking", "being smart", and
"being Tim Peters" are all forms of cheating.

I prefer not to cheat.  ;)

nOOm, I still need an answer...

> also, what do you consider to be the correct output for this
> permutation? (according to your original question)
> 
> [4, 5, 1, 2, 3, 6, 7, 8] 

Manuel

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


Re: Help! Python either hangs or core dumps when calling C malloc

2005-09-08 Thread Fredrik Lundh
"Lil" <[EMAIL PROTECTED]> wrote:

>  It's in the C code mainly because the buffer is an input to the
> driver. The driver takes a char* as input and I didn't want to pass a
> char* from python -> swig -> C since swig has memory leaks passing
> pointers.
> Do you think this is a Python issue or a Red Hat issue?

I think we would have noticed by now if Python or Red Hat weren't
able to allocate and read 20 bytes.  It's a bug in your program, and
you should concentrate on fixing it, not looking for bugs everywhere
else.

(quick guess: did you perhaps type malloc(sizeof(bytes)) instead of
malloc(bytes), or something similar)

 



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


Re: improvements for the logging package

2005-09-08 Thread Trent Mick
[EMAIL PROTECTED] wrote]
> Trent> I thought PEP 8 said camelCase (or whatever it is called) was
> Trent> okay?
> 
> Hmmm...  In the section entitled "Naming Conventions" I see:
> 
> Function Names
> 
>   Function names should be lowercase, possibly with words separated by
>   underscores to improve readability.  mixedCase is allowed only in
>   contexts where that's already the prevailing style (e.g. threading.py),
>   to retain backwards compatibility.
> 
> Method Names and Instance Variables
> 
>   The story is largely the same as with functions: in general, use
>   lowercase with words separated by underscores as necessary to improve
>   readability.

I swear that has changed since I last read that. :)
...checking... Guess I haven't read it in about 2 years. This patch:

Sat Mar 20 06:42:29 2004 UTC (17 months, 2 weeks ago) by kbk 

Patch 919256
Clarify and standardize the format for names of modules,
functions, methods, and instance variables.

Consistent, I hope, with discussion on python-dev

http://mail.python.org/pipermail/python-dev/2004-March/043257.html

http://mail.python.org/pipermail/python-dev/2004-March/043259.html

Made this change:


http://cvs.sourceforge.net/viewcvs.py/python/python/nondist/peps/pep-0008.txt?r1=1.20&r2=1.21

 Function Names
 
-  Plain functions exported by a module can either use the CapWords
-  style or lowercase (or lower_case_with_underscores).  There is
-  no strong preference, but it seems that the CapWords style is
-  used for functions that provide major functionality
-  (e.g. nstools.WorldOpen()), while lowercase is used more for
-  "utility" functions (e.g. pathhack.kos_root()).
+  Function names should be lowercase, possibly with underscores to
+  improve readability.  mixedCase is allowed only in contexts where
+  that's already the prevailing style (e.g. threading.py), to retain
+  backwards compatibility.



> Since the logging package currently uses mixedCase it would appear it
> shouldn't revert to lower_case.  I'm thinking it should have probably used
> lower_case from the start though.  I see no real reason to have maintained
> compatibility with log4j.  Similarly, I think PyUnit (aka unittest) should
> probably have used lower_case method/function names.  After all, someone
> went to the trouble of PEP-8-ing the module name when PyUnit got sucked into
> the core.  Why not the internals as well?

Perhaps because of the timing.


> If I remember
> correctly, it was more-or-less written for inclusion in the core.

Yah. It was added before Guido more clearly stated that he thought
modules should have a successful life outside the core before being
accepted in the stdlib.

Trent

-- 
Trent Mick
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List of integers & L.I.S.

2005-09-08 Thread Tim Peters
[EMAIL PROTECTED]
> So, this has no real world use, aside from posting it on a website.
> Thanks for wasting our time. You are making up an arbitrary problem and
> asking for a solution, simply because you want to look at the
> solutions, not because your problem needs to be solved. Clearly, this
> is a waste of time.

If investigating algorithms irritates you, ignore it.  The people
writing papers on this topic don't feel it's a waste of time.  For
example,

http://citeseer.ist.psu.edu/bespamyatnikh00enumerating.html
"Enumerating Longest Increasing Subsequences and Patience Sorting (2000)"
Sergei Bespamyatnikh, Michael Segal

That's easy to follow, although their use of a Van Emde-Boas set as a
given hides the most challenging part (the "efficient data structure"
part).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: job scheduling framework?

2005-09-08 Thread Fernando Perez
Larry Bates wrote:

> Google turned up these links that might be of interest:
> 
> http://www.foretec.com/python/workshops/1998-11/demosession/hoegl/
> http://www.webwareforpython.org/Webware/TaskKit/Docs/QuickStart.html
>
http://www.slac.stanford.edu/BFROOT/www/Computing/Distributed/Bookkeeping/SJM/SJMMain.htm
> 
> Larry Bates
> 
> 
> Chris Curvey wrote:
>> Has anyone seen a simple open source job-scheduling framework written
>> in Python?  I don't really want to reinvent the wheel.  All I need is
>> the ability to set up a series of atomic "jobs" as a "stream", then
>> have the system execute the jobs in the stream one-at-a-time until all
>> the jobs in the stream are complete or one of them reports an error.
>> 
>> (If it tied into a really simple grid-style computing farm, that would
>> be worth double points!)

In addition to Larry's links, this might also be of interest:

http://directory.fsf.org/science/visual/Pyslice.html

Not exactly the same, but I suspect it may be useful.

Cheers,

f

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


Re: improvements for the logging package

2005-09-08 Thread skip

Trent> Unfortunately your getting caught by the default logging level
Trent> being WARN, so that any log level below that is tossed.

Ah, okay.  I'll pick back through the docs and see what I missed, then maybe
add a description of the minimal steps needed to get going.

>> I suspect the naming could be improved while providing backward
>> compatibility aliases and deprecating those names.

Trent> Do you mean naming like "makeLogRecord" etc? 

Yes.

Trent> I thought PEP 8 said camelCase (or whatever it is called) was
Trent> okay?

Hmmm...  In the section entitled "Naming Conventions" I see:

Function Names

  Function names should be lowercase, possibly with words separated by
  underscores to improve readability.  mixedCase is allowed only in
  contexts where that's already the prevailing style (e.g. threading.py),
  to retain backwards compatibility.

Method Names and Instance Variables

  The story is largely the same as with functions: in general, use
  lowercase with words separated by underscores as necessary to improve
  readability.

Since the logging package currently uses mixedCase it would appear it
shouldn't revert to lower_case.  I'm thinking it should have probably used
lower_case from the start though.  I see no real reason to have maintained
compatibility with log4j.  Similarly, I think PyUnit (aka unittest) should
probably have used lower_case method/function names.  After all, someone
went to the trouble of PEP-8-ing the module name when PyUnit got sucked into
the core.  Why not the internals as well?

I realize I'm playing the devil's advocate here.  If a module that's been
stable outside the core for awhile gets sucked into Python's inner orbit,
gratuitous breakage of the existing users' code should be frowned upon,
otherwise people will be hesitant to be early adopters.  There's also the
matter of synchronizing multiple versions of the module (outside and inside
the core).  Still, a dual naming scheme with the non-PEP-8 names deprecated
should be possible.

In the case of the logging module I'm not sure that applies.  If I remember
correctly, it was more-or-less written for inclusion in the core.  In that
case it should probably have adhered to PEP 8 from the start.  Maybe going
forward we should be more adamant about that when an external module becomes
a candidate for inclusion in the core.

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


Re: Help! Python either hangs or core dumps when calling C malloc

2005-09-08 Thread Lil
Hi Larry,
  It's in the C code mainly because the buffer is an input to the
driver. The driver takes a char* as input and I didn't want to pass a
char* from python -> swig -> C since swig has memory leaks passing
pointers.
Do you think this is a Python issue or a Red Hat issue? I'm going to
try it on my windows machine now and see what happens.

thanks! Lil

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


Django and SQLObject. Why not working together?

2005-09-08 Thread Sokolov Yura
Django Model is wonderfull. But SQLObject more flexible (and powerfull, 
as i think, and has already more db interfaces).
But Django Model is tied with Django, and using Django with another OO 
mapping is not comfortable.
Why do not working together? I can't understand.
If you (Django and SQLObject) would, you'll beat everyone else in 
efficiency (i mean ROR and maybe some Python's frameworks).
It is for all of Open Source. There a lot of concurent projects. Tons of 
frameworks, template systems and OO maping tools (in Python),
numerous gui libraries  (flame  war: Qt vs GNOME), and different 
javascript libraries. Numerous libraries in Perl, that are not present 
in Python.
And there is nothing we could oppose to Windows( XP Prof, 2003) + 
MSOffice(Open Office is behind a bit)  +
SQLServer(is debateable) + .NET(Mono is slow a bit : I wrote a C# log 
parser, it works 4min in Mono and 45 sec in .NET) + ... .
Consolidation of good teams and their experience is the future of Open 
Source. Present is the disunity.
Sorry for this boolshit and offlist.
"Don't you know?Ev'rything's alright, yes, ev'rything's fine... relax 
think of nothing tonight."
(excuse my english)

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


Re: Help! Python either hangs or core dumps when calling C malloc

2005-09-08 Thread Larry Bates
Question: Why not just use Python to read the file?

f=open(filename, 'rb')
fcontents=f.read()

If you need to manipulate what is in fcontents you
can use struct module and/or slicing.

Larry Bates


Lil wrote:
> Hi Everyone! I've been trying to figure out this weird bug in my
> program. I have a python program that calls a C function that reads in
> a binary file into a buffer. In the C program, buffer is allocated by
> calling malloc. The C program runs perfectly fine but when I use python
> to call the C function, it core dumps at malloc.
> I've tried multiple binary files with different sizes and the result
> is:
> 
> if file size is < 20 bytes , works fine
> if file size is > 20 bytes, it hangs or core dumps.
> 
> Please help!! 
> Lil
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Django Vs Rails

2005-09-08 Thread Marek Kubica
Hello!

On 7 Sep 2005 20:56:28 -0700 flamesrock wrote:
 
> On the other, Rails seems to have a brighter future, 
Why that? Django is not yet released and everybody is talking about it.
Like it happened with RoR.

> How difficult would it be to learn Ruby+Rails, assuming that someone is
> already skilled with Python?
Learning Ruby: quite trivial, as Ruby is like Python, but sometimes there a
Ruby-way and a non-Ruby-way (codeblocks and stuff like this) and to write
nice Ruby programs you better write in the Ruby-way.

> Is it worth it?
Well, I've learned it, because it was easy but I haven't yet found a really
significant difference that makes Ruby much better than Python. You can
write some things in an very elegant way, but sometimes the Python solution
is more readable. But the docs are sometimes.. say: very compact ;).
As Ruby is not that hard to learn you could give it a try - maybe you'll
like it, maybe not.

RoR is not the only framework, some folks prefer Nitro.

greets,
Marek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: job scheduling framework?

2005-09-08 Thread Larry Bates
Google turned up these links that might be of interest:

http://www.foretec.com/python/workshops/1998-11/demosession/hoegl/
http://www.webwareforpython.org/Webware/TaskKit/Docs/QuickStart.html
http://www.slac.stanford.edu/BFROOT/www/Computing/Distributed/Bookkeeping/SJM/SJMMain.htm

Larry Bates


Chris Curvey wrote:
> Has anyone seen a simple open source job-scheduling framework written
> in Python?  I don't really want to reinvent the wheel.  All I need is
> the ability to set up a series of atomic "jobs" as a "stream", then
> have the system execute the jobs in the stream one-at-a-time until all
> the jobs in the stream are complete or one of them reports an error.
> 
> (If it tied into a really simple grid-style computing farm, that would
> be worth double points!)
> 
> -Chris
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List of integers & L.I.S.

2005-09-08 Thread [EMAIL PROTECTED]
Working on this allowed me to avoid some _real_ (boring) work at my
job.

So clearly it served a very useful purpose!  ;)

Manuel

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


Re: Cleaning strings with Regular Expressions

2005-09-08 Thread Gary Wilson Jr
sheffdog wrote:
> Using regular expressions, the best I can do so far is using the re.sub
> command but it still takes two lines. Can I do this in one line? Or
> should I be approaching this differently? All I want to end up with is
> the file name "ppbhat.tga".

A regular expression to do what you want:
 >>> s = 'setAttr ".ftn" -type "string" 
 >>> /assets/chars/boya/geo/textures/lod1/ppbhat.tga";'
 >>> s = re.sub(r".*/(.*\.tga).*", r"\1", s)
 >>> s
'ppbhat.tga'

Is a regular expression the best solution?
That depends on what else you need to do with your data file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: launching adobe reader with arguments from os.system call

2005-09-08 Thread Greg Miller
Thank you for the information, when I launched the Reader on the actual
hardware it launched quickly.  I think I just have too much running on
my application PC.  I will consider starting an AcroReader app however.

Greg

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


Help! Python either hangs or core dumps when calling C malloc

2005-09-08 Thread Lil
Hi Everyone! I've been trying to figure out this weird bug in my
program. I have a python program that calls a C function that reads in
a binary file into a buffer. In the C program, buffer is allocated by
calling malloc. The C program runs perfectly fine but when I use python
to call the C function, it core dumps at malloc.
I've tried multiple binary files with different sizes and the result
is:

if file size is < 20 bytes , works fine
if file size is > 20 bytes, it hangs or core dumps.

Please help!! 
Lil

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


Re: Need help with C extension module

2005-09-08 Thread chris
Ok, I found further examples on the Internet and got something working
(it seems), but I have a question about the memory management.  The
example I found did not include any of the PyMem_... functions.

Here's roughly what I have working:

cdef extern from "my.h":
  cdef struct inputs:
char   *x

  cdef struct outputs:
  int y

  outputs *func(inputs *x, outputs *y)
  int init(char* fname)

class Analyzer:
  def __init__(self, fname):
init(fname)

  # inp is my python "Inputs" object.
  def myfunc(self, inp):
cdef inputs* i
i.x= inp.x

cdef outputs* o
o = func(i, o)
return o.y

class Inputs:
  def __init__(self):
self.x = ""

So there is no explicit memory management going on there as in Robert's
example.  Is this ok?  

Thanks,
Chris

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


Re: popen in thread on QNX

2005-09-08 Thread [EMAIL PROTECTED]
spawn() works on QNX, fork() does not.

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


Re: List of integers & L.I.S.

2005-09-08 Thread [EMAIL PROTECTED]
So, this has no real world use, aside from posting it on a website.
Thanks for wasting our time. You are making up an arbitrary problem and
asking for a solution, simply because you want to look at the
solutions, not because your problem needs to be solved. Clearly, this
is a waste of time.

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


Re: List of integers & L.I.S.

2005-09-08 Thread [EMAIL PROTECTED]
> ... and let me reveal the secret:
> http://spoj.sphere.pl/problems /SUPPER/

your question is different than the question on this website.

also, what do you consider to be the correct output for this
permutation? (according to your original question)

[4, 5, 1, 2, 3, 6, 7, 8]

Manuel

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


Re: question from beginner

2005-09-08 Thread dario
Thanks Dennis. In effect stringZVEI doesn't remain empty after the
.read method, then the loop is executed 1 time.

How could be a 'while' loop to wait a no empty string from the serial
port?

Dario.

Dennis Lee Bieber ha scritto:

> On 7 Sep 2005 07:14:37 -0700, "dario" <[EMAIL PROTECTED]> declaimed the
> following in comp.lang.python:
>
> > Hi, Im new on phyton programming.
> > On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receive
> > a string from serial port and after send this one enclosed in an
> > e-mail.
> > All OK if the string is directly generated in the code. But it doesn't
> > works if I wait for this inside a 'while' loop. This is the simple
> > code:
> >
>   First -- post the real code file would help -- the indentation of
> the first two statements below is wrong.
>
> > global stringZVEI
> >
>   This does nothing at the top level -- if only makes sense INSIDE a
> "def" block, where it has the effect of saying "this variable is not
> local to the function"
>
> >   while stringZVEI=='':
> >   MOD.sleep(10)
>
>   There is something wrong with
>
>   import time
>   time.sleep()
> 
>
> >   a=SER.send(' sono nel while stringZVEI==st vuota')
> >   stringZVEI = SER.readbyte()
>
>   #for debug
>   print "%2X " % stringZVEI
>
> >   a=SER.send(' stringZVEI=')
> >   a=SER.send(stringZVEI)
> >
> > MOD and SER are embedded class maked by third part.
> >
> > >From my very little debug possibility it seem that loop is executed 1
> > time only nevertheless stringZVEI is still empty. The line
> >   a=SER.send(' stringZVEI=')
> > work correctly but
> >
> > a=SER.send(stringZVEI)
> >
>   What does .readbyte() do if there is no data to be read? Since your
> loop is based on a totally empty string, if .readbyte returns /anything/
> (even a "null" byte -- 0x00) your loop will exit; and a null byte may
> not be visible on the send...
>
> --
>  > == <
>  >   [EMAIL PROTECTED]  | Wulfraed  Dennis Lee Bieber  KD6MOG <
>  >  [EMAIL PROTECTED] |   Bestiaria Support Staff   <
>  > == <
>  >   Home Page: <
>  >Overflow Page: <

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


Re: pretty windows installer for py scripts

2005-09-08 Thread [EMAIL PROTECTED]
I second that. NSIS works better than MSI, Inno, or even InstallShield.
I highly recommend it. Of course, a second choice is Inno, third is
MSI, and last resort is InstallShield. Another option is to make an
installer using "AutoIT" but that can get kind of tricky.

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


Re: killing thread after timeout

2005-09-08 Thread Bryan Olson
Paul Rubin wrote:
> To get even more OS-specific, AF_UNIX sockets (at least on Linux) have
> a feature called ancillary messages that allow passing file
> descriptors between processes.  It's currently not supported by the
> Python socket lib, but one of these days... .  But I don't think
> Windows has anything like it.

It can be done on on Windows.

   http://tangentsoft.net/wskfaq/articles/passing-sockets.html


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


Re: job scheduling framework?

2005-09-08 Thread Benji York
Chris Curvey wrote:
> Has anyone seen a simple open source job-scheduling framework written
> in Python?

It sounds like BuildBot (http://buildbot.sf.net) might interest you.

It's not exactly meant to be a job control system, but it does have some 
nice functionality.  It might be interesting to extend it in the 
direction you're talking about.
--
Benji York

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


RE: CGI File Uploads and Progress Bars

2005-09-08 Thread Robert Brewer
Doug Helm wrote:
> I'm writing a CGI to handle very large file uploads.
> I would like to include a progress bar.
> ...I need to know not only the number of
> bytes received, but also the total number of
> incoming bytes.  Here's the heart of the code:
> 
> while afcommon.True:
>   lstrData = lobjIncomingFile.file.read(afcommon.OneMeg)
>   if not lstrData:
> break
>   lobjFile.write(lstrData)
>   llngBytes += long(len(lstrData))
> lobjFile.close()
> 
> Assume that lobjIncomingFile is actually a file-type
> element coming from CGI.FieldStorage.  It's already
> been tested to ensure that it is a file-type element.
> Also, assume that I've already opened a file on the
> server, referred to by lobjFile (so lobjFile is the
> target of the incoming data).

I took a cursory look through the cgi module (and am trying to remember
what we did for CherryPy*). It seems that, at the time you run the above
code, the uploaded file has already been completely read from the client
and placed into a temporary file. That is, lobjIncomingFile.file.read
does not read from the HTTP request body; it reads from a temporary file
instead.

> If this were a client application opening a file,
> I would just do the following:
> 
> import os
> print os.stat('myfile.dat')[6]
> 
> But, of course, this isn't a local file.  In fact,
> it's not really a file at all.

In fact, it is a file, just a temporary one. See
cgi.FieldStorage.makefile().

> So, bottom line: Does anyone know how to get the
> size of the incoming file data without reading the
> whole thing into a string?  Can I do something with
> content_header?

Sure. Subclass cgi.FieldStorage, and override make_file to provide your
own file-like object that you can monitor as its "write" method is
called (see read_binary for the actual upload r/w code). The existing
FieldStorage class places the file size (gleaned from the Content-Length
request header) into self.length.


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

* See CherryPy's 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Video display, frame rate 640x480 @ 30fps achievable?

2005-09-08 Thread Diez B. Roggisch
Guenter wrote:
> Hi,
> 
> I need to develop an application that displays video 640x480 16-bit per
> pixel with 30 fps.
> 
> I would prefer to do that with Python (wxPython) but don't have any
> experience whether it is possible to achieve that frame rate and still
> have some resources for other processing left? My development PC would
> be a Celeron 1 GHz. The final system could be a faster system.
> 
> I would appreciate if anybody could share some experience in that
> field.

No first hand experience - but I guess pymedia is what you need. how to 
combine that with wx? No idea.

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


Re: record sound to numarray/list

2005-09-08 Thread [EMAIL PROTECTED]
No there is not. Hey, you could write one though.

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


job scheduling framework?

2005-09-08 Thread Chris Curvey
Has anyone seen a simple open source job-scheduling framework written
in Python?  I don't really want to reinvent the wheel.  All I need is
the ability to set up a series of atomic "jobs" as a "stream", then
have the system execute the jobs in the stream one-at-a-time until all
the jobs in the stream are complete or one of them reports an error.

(If it tied into a really simple grid-style computing farm, that would
be worth double points!)

-Chris

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


Distutils extension proposal (was: Re: Distutils question)

2005-09-08 Thread Laszlo Zsolt Nagy
Peter Hansen wrote:

>>How how can I install my .mo files from a distutil script into its 
>>default location?
>>
>>sys.prefix + os.sep + 'share' + os.sep + 'locale'
>>
>>
>
>I can't answer the first question, but the latter should be written this 
>way instead
>
>os.path.join(sys.prefix, 'share', 'locale')
>
>for greater portability and maintainability.
>  
>
Of course. :-)

I know that Peter is a big Python guru, and he could not answer the 
question. I also read the archives in the i18n-sig. There were questions 
about the same problem and the answer was that there is no standard way 
to include message files with a distribution. I would like to propose an 
extension in distutils.

Most of the packages contain messages and they should be i18n-ed. The 
proposal itself contains two parts.

1. We should extend the distutils interface to allow message files to be 
installed to the default location

os.path.join(sys.prefix, 'share', 'locale')

2. Domain names for packages should be somehow standardized, especially 
in conjunction with PEP 301 (Package Index and Metadata for Distutils). 
Somehow, the package name and version should identify the message files 
that can be used.

  Les

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


Re: python profiling, hotspot and strange execution time

2005-09-08 Thread bdrosen96
I was unhappy with both hotshot and the standard python profiler, so
I wrote my own, which may be what you are looking for. I've submitted
it as a patch at:

http://sourceforge.net/tracker/index.php?func=detail&aid=1212837&group_id=5470&atid=305470

It should add a minimum of overhead, give real numbers and also
gives stats on child calls. However, it is not compatible with
the stats module.

You can compile it as a standalone module.


[EMAIL PROTECTED] wrote:
> Hi there,
>
>I have some scientific application written in python. There is a
> good deal of list processing, but also some "simple" computation such
> as basic linear algebra involved. I would like to speed things up
> implementing some of the functions in C. So I need profiling.
>
>I first tried to use the default python profiler, but profiling my
> application multiplies the execution time by a factor between 10 and
> 100 ! So I decided to give a try to hotspot. I just followed the
> example of the python library reference, but I have some strange
> results concerning cpu time. My profiling script is something like the
> following:
>
> def run_foo():
> print time.clock()
>
> function_to_profile()
>
> print time.clock()
>
> prof = hotshot.Profile("essai.prof")
> benchtime= prof.runcall(run_foo)
> prof.close()
> stats = hotshot.stats.load("essai.prof")
> stats.strip_dirs()
> stats.sort_stats('time', 'calls')
> stats.print_stats(20)
>
> The goal is to profile the function function_to_profile(). Running this
> script gives me a CPU executime time of around 2 seconds, whereas the
> difference between the two clock calls is around 10 seconds ! And I
> don't run any other cpu consuming tasks at the same time, so this
> cannot come from other running processes. Is there something perticular
> about hotspot timing I should know ? I am not sure how I can get more
> accurate results with hotspot.
> 
> I would appreciate any help, 
> 
> Thanks

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


Re: Video display, frame rate 640x480 @ 30fps achievable?

2005-09-08 Thread Fredrik Lundh
Peter Hansen wrote:

>> I need to develop an application that displays video 640x480 16-bit per
>> pixel with 30 fps.
>>
>> I would prefer to do that with Python (wxPython) but don't have any
>> experience whether it is possible to achieve that frame rate and still
>> have some resources for other processing left? My development PC would
>> be a Celeron 1 GHz. The final system could be a faster system.
>
> At the very least, you should be looking at Pygame instead, as wxPython
> is not really intended for that kind of thing.  Whether or not you can
> manage the desired frame rate depends entirely on what you will be
> displaying... a single pixel moving around, full-screen video, or
> something in between? ;-)

no contemporary hardware should have any problem reaching that
framerate at that resolution, even if you stick to standard "blit" inter-
faces.

getting the data into the "blittable" object fast enough may be more
of a problem, though.  I don't know how good wxPython is in that
respect; Tkinter's PhotoImage is probably not fast enough for video,
but a more lightweight object like PIL's ImageWin.Dib works just
fine (I just wrote a test script that reached ~200 FPS at 1400x900,
but my machine is indeed a bit faster than a 1 GHz Celeron).

 



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


ANN: ConfigObj 4.0.0 Beta 4

2005-09-08 Thread Fuzzyman
Hello Pythoneers,

ConfigObj 4.0.0 has a beta 4 release. This fixes a couple of moderately
serious bugs - so it's worth switching to.

http://cheeseshop.python.org/pypi/ConfigObj
http://www.voidspace.org.uk/python/configobj.html
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj-4.0.0b4.zip
http://sf.net/projects/configobj

What's New ?


(Since Beta 2 the last announced version)

2005/09/07
--

Fixed bug in initialising ConfigObj from a ConfigObj.

Changed the mailing list address.

2005/09/03
--

Fixed bug in ``Section__delitem__`` oops.

2005/08/28
--

Interpolation is switched off before writing out files.

Fixed bug in handling ``StringIO`` instances. (Thanks to report
from
"Gustavo Niemeyer" <[EMAIL PROTECTED]>)

Moved the doctests from the ``__init__`` method to a separate
function.
(For the sake of IDE calltips).

Beta 3

2005/08/26
--

String values unchanged by validation *aren't* reset. This
preserves
interpolation in string values.


What is ConfigObj ?
===

ConfigObj is a simple but powerful config file reader and writer: an
ini file round tripper. Its main feature is that it is very easy to
use, with a straightforward programmer's interface and a simple syntax
for config files. It has lots of other features though :

* Nested sections (subsections), to any level
* List values
* Multiple line values
* String interpolation (substitution)
* Integrated with a powerful validation system

  o including automatic type checking/conversion
  o allowing default values
  o repeated sections

* All comments in the file are preserved
* The order of keys/sections is preserved
* No external dependencies

ConfigObj is available under the very liberal BSD License.

It addresses *most* of the limitations of ConfigParser as discussed at
: http://wiki.python.org/moin/ConfigParserShootout

Anything Else ?
===

ConfigObj stores nested sections which map names to members
(effectively dictionaries) with values as lists *or* single items. In
association with the validate module it can transparently translate
values back into booleans, floats, integers, and of course strings.

This makes it ideal for *certain* types of human readable (and
writable) data persistence.

There is a discussion of this (with accompanying code) at :
http://www.voidspace.org.uk/python/articles/configobj_for_data_persistence.shtml

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


Re: popen in thread on QNX

2005-09-08 Thread Jacek Popławski
Laszlo Zsolt Nagy wrote:
> - one of your worker threads wants to run a command
> - it creates the argument list and puts it into a message queue
> - woker thread starts to sleep
> - main thread processes the message queue -> it will run popen, put back 
> the file descriptors into the message and wake up the worker thread
> - the worker thread starts to work with the files

Just like I wrote in previous thread ("killing thread after timeout") - 
I am writting application which read command from socket and run it. I 
need to be sure, that this command will not take too much time, so I 
need some kind of timeout, and I need to see its stdout and stderr.

So I run command on separate thread, this thread calls 
os.system(command), main thread takes care about timeout.

popen or fork/execve would be much better than os.system, but they both 
fail on QNX, because os.fork() is not implemented in thread
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: launching adobe reader with arguments from os.system call

2005-09-08 Thread Steve Holden
Greg Miller wrote:
> Thank you Martin, here's what I discovered this morning to work, the
> only problem is it is painfully slow to launch the application.
> 
> os.system('start acroRd32.exe'+' /A'+' "page=15"'+'
> "C:\\Gregtemp\\estelletest\\NexGlosser_User_Guide_W60G00_en.pdf"')
> 
> I'm going to give your method a try to see if it launches any quicker.
> Thanks again.
> 
> Greg Miller
> 
You might notice that if you already have an Acrobat Reader window open 
the document comes up rather more quickly.

If you want fast document startup you could consider using the win32all 
extensions to create an AcroReader application process in advance of 
opening any documents.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: PEP-able? Expressional conditions

2005-09-08 Thread Antoon Pardon
Op 2005-09-08, Duncan Booth schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>> Which is why I don't understand the resistance against introducing
>> such a beast.
>
> The idea has already been discussed to death. Read PEP 308 to see what was 
> proposed, discussed, and why the PEP was eventually rejected:

So what? If the same procedure would have been followed concerning
the decorator syntax, it would have been rejected too for the same
reasons.

> http://www.python.org/peps/pep-0308.html:
>> Status:  Rejected 
>> ...
>> Requests for an if-then-else ("ternary") expression keep coming up
>> on comp.lang.python.  This PEP contains a concrete proposal of a
>> fairly Pythonic syntax.  This is the community's one chance: if
>> this PEP is approved with a clear majority, it will be implemented
>> in Python 2.4.  If not, the PEP will be augmented with a summary
>> of the reasons for rejection and the subject better not come up
>> again.  While the BDFL is co-author of this PEP, he is neither in
>> favor nor against this proposal; it is up to the community to
>> decide.  If the community can't decide, the BDFL will reject the
>> PEP.
>> ...
>> Following the discussion, a vote was held.  While there was an
>> overall
>> interest in having some form of if-then-else expressions, no one
>> format was able to draw majority support.  Accordingly, the PEP was
>> rejected due to the lack of an overwhelming majority for change.
>> Also, a Python design principle has been to prefer the status quo
>> whenever there are doubts about which path to take.

IMO this is worded in a misleading way. It wasn't that there was lack
of an overwhelming majority for change. 436 supported at least one
of the options and only 82 rejected all options. So it seems 436 voters
out of 518 supported the introduction of a ternary operator.

Yes no format was able to draw majority support but that is hardly
suprising since there where 17 formats to choose from. I find
the fact that people were unable to choose one clear winner out
of 17 formats in one vote, being worded as: "lack of an overwhelming
majority for change" at the least not very accurate and probably
misleading or dishonest.

-- 
Antoon Pardon

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


Re: Printer List from CUPS

2005-09-08 Thread Martin Franklin
Mike Tammerman wrote:
> I am using Ubuntu. pycups seems to be not existed any more.
> 
> Mike
> 

Yeah as I said if you're using a redhat based distro...  However you
could try getting the redhat / fedora rpm that provides pycups and
installing it? I would ask on the  Ubuntu list, I know they are a very
python friendly bunch :)

Martin

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


Re: Video display, frame rate 640x480 @ 30fps achievable?

2005-09-08 Thread Peter Hansen
Guenter wrote:
> I need to develop an application that displays video 640x480 16-bit per
> pixel with 30 fps.
> 
> I would prefer to do that with Python (wxPython) but don't have any
> experience whether it is possible to achieve that frame rate and still
> have some resources for other processing left? My development PC would
> be a Celeron 1 GHz. The final system could be a faster system.

At the very least, you should be looking at Pygame instead, as wxPython 
is not really intended for that kind of thing.  Whether or not you can 
manage the desired frame rate depends entirely on what you will be 
displaying... a single pixel moving around, full-screen video, or 
something in between? ;-)

See for example 
http://mail.python.org/pipermail/python-list/2002-May/106546.html for 
one first-hand report on frame rates possible with Pygame (whether it's 
accurate or not I don't know).

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


Re: killing thread after timeout

2005-09-08 Thread Jacek Popławski
Paul Rubin wrote:
> Maybe the child process can just use sigalarm instead of a separate
> thread, to implement the timeout.

Already tried that, signals works only in main thread.

> To get even more OS-specific, AF_UNIX sockets (at least on Linux) have
> a feature called ancillary messages that allow passing file
> descriptors between processes.  It's currently not supported by the
> Python socket lib, but one of these days... .  But I don't think
> Windows has anything like it.  No idea about QNX.

I have solved problem with additional process, just like Bryan Olson 
proposed. Looks like all features I wanted are working... :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printer List from CUPS

2005-09-08 Thread Mike Tammerman
I am using Ubuntu. pycups seems to be not existed any more.

Mike

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


Video display, frame rate 640x480 @ 30fps achievable?

2005-09-08 Thread Guenter
Hi,

I need to develop an application that displays video 640x480 16-bit per
pixel with 30 fps.

I would prefer to do that with Python (wxPython) but don't have any
experience whether it is possible to achieve that frame rate and still
have some resources for other processing left? My development PC would
be a Celeron 1 GHz. The final system could be a faster system.

I would appreciate if anybody could share some experience in that
field.

Thanks for any help.

Guenter

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


ANN: PyDev 0.9.8.1 released

2005-09-08 Thread Fabio Zadrozny
Hi All,

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

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

Details for Release: 0.9.8.1

Major highlights:
---

* Java 1.4 support reintroduced.
* Styles added for syntax highlighting (bold and italic), 
contributed by Gerhard Kalab.


Others that are new and noteworthy:
-

* zombie process after exiting eclipse should not happen anymore
* paths with '.' are accepted for the pythonpath (unless they start 
with a '.', because it may not accept relative paths).
* relative imports are added to code-completion
* local imports are taken into consideration when doing code completion
* debugger has 'change support', so, changed variables in a scope 
appear red


Cheers,

Fabio

-- 
Fabio Zadrozny
--
Software Developer

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

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


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


Re: pretty windows installer for py scripts

2005-09-08 Thread Adriaan Renting
The elegant way to do installs on Windows would be by creating an MSI. 
Microsoft provides (IIRC) a simple tool to create those (Orca), that's free. 
Without the Installshield or Wise tools I think it would take quite some effort 
though, because you need to understand all the details of how msi tables work. 
You might be able to get the idea by using orca to look at other msi installs, 
and figure out how they do things.
MSI itself isn't very difficult, but it'll take some time to understand it. If 
you do use it, do not foget to define uninstall actions.
The izfree tools and tutorials on sourceforge might do the trick for you:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/windows_installer_development_tools.asp
http://izfree.sourceforge.net/

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


Re: Migrate PYD Files

2005-09-08 Thread Kay Schluehr
David Duerrenmatt wrote:
> Is there a way to use old pyd files (Python 1.5.2) with a newer version
> of Python without recompiling them?
>
> Because the source code is not available anymore, I'm wondering whether
> it's possible or not to change few bytes with a hex editor (version
> number?). I'd like to give it a try since the modules don't use too
> critical functions.
>
> Thanks
> dd

Hi David,

you might checkout embedding your Python 1.5.2 interpreter into Python
using ctypes. Just follow chap.5 of the "Extending and Embedding"
tutorial and the docs of the cytpes API.

The following little script runs successfully on Python23 interpreter.

==

import ctypes
python24 = ctypes.cdll.LoadLibrary("python24.dll")
python24.Py_Initialize()
python24.PyRun_SimpleString("from time import time,ctime\n")
python24.PyRun_SimpleString("print 'Today is',ctime(time())\n");
python24.Py_Finalize()

Kay

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


Re: PEP-able? Expressional conditions

2005-09-08 Thread Duncan Booth
Antoon Pardon wrote:

> Which is why I don't understand the resistance against introducing
> such a beast.

The idea has already been discussed to death. Read PEP 308 to see what was 
proposed, discussed, and why the PEP was eventually rejected:

http://www.python.org/peps/pep-0308.html:
> Status:  Rejected 
> ...
> Requests for an if-then-else ("ternary") expression keep coming up
> on comp.lang.python.  This PEP contains a concrete proposal of a
> fairly Pythonic syntax.  This is the community's one chance: if
> this PEP is approved with a clear majority, it will be implemented
> in Python 2.4.  If not, the PEP will be augmented with a summary
> of the reasons for rejection and the subject better not come up
> again.  While the BDFL is co-author of this PEP, he is neither in
> favor nor against this proposal; it is up to the community to
> decide.  If the community can't decide, the BDFL will reject the
> PEP.
> ...
> Following the discussion, a vote was held.  While there was an
> overall
> interest in having some form of if-then-else expressions, no one
> format was able to draw majority support.  Accordingly, the PEP was
> rejected due to the lack of an overwhelming majority for change.
> Also, a Python design principle has been to prefer the status quo
> whenever there are doubts about which path to take.

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


Re: Construct raw strings?

2005-09-08 Thread Benji York
Peter Hansen wrote:
> Benji York wrote:
> 
>> It's not join that's getting you, it's the non-raw string
>> representation in path_to_scan.  Use either 'd:\test_images' or
>> 'd:\\test_images' instead.
> 
> Benji, you're confusing things: you probably meant r'd:\test_images'
> in the above

Doh!  I did indeed.  Thanks for the backup.
--
Benji York



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


Re: Creating custom event in WxPython

2005-09-08 Thread Chris Lambacher
You should be derriving from PyCommandEvent since only CommandEvents are set
to propegate, which is probably what you want (see the wxwidgets Event
handling overview).

In order to use Bind you will need an instance of PyEventBinder.  For the
example below that would be something like:

EVT_INVOKE = PyEventBinder(wxEVT_INVOKE)

-Chris


On Thu, Sep 01, 2005 at 04:25:05PM +0200, fraca7 wrote:
> [EMAIL PROTECTED] a ?crit :
> 
> > Now when my socket thread detects an incoming message, I need my main
> > thread to interpret the message and react to it by updating the GUI.
> > IMO the best way to achieve this is by having my socket thread send a
> > custom event to my application's event loop for the main thread to
> > process. However, I'm at a total loss as far as creating custom events
> > is concerned. The WxWindows documentation isn't very helpful on this
> > either.
> 
> I think this is what you're looking for:
> 
> # begin code
> 
> import wx
> 
> wxEVT_INVOKE = wx.NewEventType()
> 
> class InvokeEvent(wx.PyEvent):
>  def __init__(self, func, args, kwargs):
>  wx.PyEvent.__init__(self)
>  self.SetEventType(wxEVT_INVOKE)
>  self.__func = func
>  self.__args = args
>  self.__kwargs = kwargs
> 
>  def invoke(self):
>  self.__func(*self.__args, **self.__kwargs)
> 
> class MyFrame(wx.Frame):
>  def __init__(self, *args, **kwargs):
>  wx.Frame.__init__(self, *args, **kwargs)
>  self.Connect(-1, -1, wxEVT_INVOKE, self.onInvoke)
> 
>  def onInvoke(self, evt):
>  evt.invoke()
> 
>  def invokeLater(self, func, *args, **kwargs):
>  self.GetEventHandler().AddPendingEvent(InvokeEvent(func, args, 
> kwargs))
> 
> # end code
> 
> This way, if frm is an instance of MyFrame, invoking 
> frm.invokeLater(somecallable, arguments...) will invoke 'somecallable' 
> with the specified arguments in the main GUI thread.
> 
> I found this idiom somewhere on the Web and can't remember where.
> 
> HTH
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distutils question

2005-09-08 Thread Peter Hansen
Laszlo Zsolt Nagy wrote:
> How how can I install my .mo files from a distutil script into its 
> default location?
> 
> sys.prefix + os.sep + 'share' + os.sep + 'locale'

I can't answer the first question, but the latter should be written this 
way instead

os.path.join(sys.prefix, 'share', 'locale')

for greater portability and maintainability.

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


  1   2   >