[CfP] Dynamic Languages Day @ Brussels

2006-01-12 Thread Pascal Costanza
Dynamic Languages Day @ Vrije Universiteit Brussel
~~
Monday,  February 13,  2006,  VUB Campus Etterbeek

The VUB (Programming Technology Lab, System and Software Engineering
Lab), ULB (deComp) and the Belgian Association for Dynamic Languages
(BADL) are very pleased to invite you to a whole day of presentations
about the programming languages Self, Smalltalk and Common Lisp by
experts in these languages. Besides some introductory material for each
language, the reflective facilities in the respective programming
environments will be highlighted. The presentations will be especially
interesting for people with good knowledge about current mainstream
object-oriented languages like Java, C# and C++ who want to get a
deeper understanding about the expressive power of Self, Smalltalk and
Common Lisp. In order to prepare the ground for these presentations,
Professor Viviane Jonckers will introduce the day by an overview of the
benefits of teaching dynamic languages to undergraduate students in
computer science. She will especially discuss the specific advantages
of using Scheme as an introductory language instead of the more widely
employed Java language.

Attendance is free and open to the public. Please make sure to register
for the event by sending an e-mail to Pascal Costanza
([EMAIL PROTECTED]), so we can plan ahead. The number of places
will be limited according to the exact location of the event and will
be allocated on a first-come, first-serve basis. Watch the website for
the exact schedule, location and any news at
http://prog.vub.ac.be/events/2005/BADL/DLD/dld.html.

Abstracts of the Talks
~~

Scheme as an introductory language (Viviane Jonckers)
~

The VUB has a rich history in dynamic programming language teaching and
research. Ever since the late 80's, compulsory courses on Lisp and
Smalltalk have played an important role in the last two years of the
computer science curriculum. Since the early 90's, this role was
further intensified by selecting Scheme as the introductory course in
the first year and by promoting Scheme as the lingua franca for most
courses in the first two years. Professor Jonckers' introductory talk
to the dynamic languages day explains how this early exposure to the
dynamic paradigm is the seed that gives students the skills to fully
grasp and appreciate the more advanced dynamic paradigms (such as Lisp,
CLOS, Smalltalk and Self) in subsequent courses of their computer
science training.

Self (Ellen Van Paesschen)
~~

Self is a prototype-based object-oriented programming language where
everything is an object and all manipulation of objects is initiated
through message sending. A prototype-based language eschews classes and
allows object creation ex-nihilo or by cloning prototypes. Self
resembles Smalltalk in both its syntax and semantics. Other
characteristics of Self are delegation (object-centered inheritance),
parent sharing and child sharing (multiple inheritance), and dynamic
parent modification. Further the Self environment includes a powerful
mechanism for reflective meta-programming based on mirror objects. The
Self group were also the first to introduce traits objects that gather
shared and reusable behavior between objects in order to program in a
more efficient and structured way.

After a brief introduction to the highly interactive Self environment
the language's basics and its syntax and semantics are presented. Next
the most important advanced features such as mirrors and dynamic parent
modification are illustrated.

Smalltalk (Johan Brichau, Roel Wuyts)
~

Smalltalk is class-based object-oriented programming language.
Everything in Smalltalk is an object and these objects communicate
through messages. The Smalltalk language itself offers only very few
programming constructs and is thus easy to learn and grasp. Therefore,
the expressive power of Smalltalk lies in its huge library of
frameworks, which includes an extensive metaobject protocol that
enables powerful dynamic (runtime) reflection. Furthermore, perhaps one
of the most significant advantages of Smalltalk outside of the language
itself is that software development is a truly dynamic experience. The
Smalltalk environment features the incremental development of an
application where there is no strict separation between development and
execution cycles, leading to an interactive and dynamic development
process.

Besides a short introduction to the Smalltalk programming language,
this presentation will focus on the dynamic reflective facilities of
Smalltalk. We will demonstrate the power of its metaobject protocol
through a number of tools that extensively rely on it. Furthermore, we
will provide some insight in the dynamic nature of Smalltalk
development through a live demonstration.

Generic Functions and the CLOS Metaobject 

Re: can't solve an exercise-help me with it

2006-01-12 Thread Tim Roberts
hossam [EMAIL PROTECTED] wrote:

I'm studying python newly and have an exercise that is difficult for me as a 
beginner.Here it is :
Write a program that approximates the value of pi by summing the terms of 
this series:
4/1-4/3+4/5-4/7+4/9-4/11+ The program should prompt the user for n, the 
number of terms to sum and then output the sum of the first n terms of this 
series.

any help would be appreciated.

Is this homework?  You should show us what you already have, and we can
show you where may be going wrong.  This isn't a free homework service.

This is not a hard problem, although that's a terrible series for computing
pi.  At 100,000 terms, it still only has 5 digits.

  n = input( How many terms?  )
  sum = 0
  sign = 4.0
  for i in range(n):
  sum += sign / (i+i+1)
  sign = -sign

  print sum
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Scripts to logon to websites

2006-01-12 Thread Steve Holden
Peter Hansen wrote:
 BartlebyScrivener wrote:
 
but googling for basic authentication and
maybe realm and/or host will find you other sites with less
technically detailed material.

This looks promising, but it'll take me a week to understand it :)

http://www.voidspace.org.uk/python/articles/authentication.shtm
 
 
 (Minor typo... needs an extra l on the end:
 
 http://www.voidspace.org.uk/python/articles/authentication.shtml
 )
 
 By the way, note that neither basic auth nor digest auth provide any 
 real security, and in fact with basic auth the userid and password are 
 sent *in cleartext*.  For any serious production site these techniques 
 should probably not be used without additional security measures in 
 place, such as HTTPS encryption.
 
Underlining your point, the difference between the two is that digest 
offers *strong* authentication (i.e. is not subject to replay attacks) 
while basic doesn't (anyone can capture the traffic and use the same 
tokens to authorize against the site).

Sometimes strong authentication without confidentiality is a legitimate 
requirement.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: MVC in wxPython HELP!

2006-01-12 Thread bwaha
 Can I just suggest you search in Google Groups for the message by
 has labelled Re: MVC programming with python (newbie) - please help.
 Dated: 7 Jan 2006 07:03:04 -0800.  It is one of the nicest short
 descriptions of the MVC pattern and why it works.

I'll second that 


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


Re: Real-world use cases for map's None fill-in feature?

2006-01-12 Thread Raymond Hettinger
[David Murmann]
 i'd like izip
 to change, too.

The zip() function, introduced in Py2.0, was popular and broadly
useful.  The izip() function is a zip() substitute with better memory
utilization yet almost identical in how it is used.  It is bugfree,
successful, fast, and won't change.

The map() function, introduced shortly after the transistor was
invented, incorporates an option that functions like zip() but fills-in
missing values and won't truncate.  It probably seemed like a good idea
at the time, but AFAICT no one uses it (Alex once as a newbie; Strakt
once; me never; the standard library never; etc).

So, the question is not whether non-truncating fill-in will be
available. Afterall, we've already got one:  map(None, it1, it2).

Instead, the question is whether to introduce another substantially
identical function with improved memory utilization and a specifiable
fill-in value.  But, why would you offer a slightly improved variant of
something that doesn't get used?

Put another way:  If you don't use map(None, it1, it2), then you're
going to have a hard time explaining why you need
itertools.izip_longest(it1, it2).



 second (and i think this is the reason for the use-case search)
 is that someone has to do it. that means implement it and fix
 the docs, add a test-case and such stuff. if there are not many
 use-cases the effort to do so might not be worthwhile.

In this case, the coding and testing are easy.  So that's not the
problem.  The real issue is the clutter factor from introducing new
functions if they're not going to be used, if they don't have good use
cases, and if there are better ways to approach most problems.

The reason for the use case search is to determine whether
izip_longest() would end-up as unutilized cruft and add dead-weight to
the language.  The jury is still out but it doesn't look promising.


Raymond

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


Unicode style in win32/PythonWin

2006-01-12 Thread Robert

Neil Hodgson wrote:
 Robert:

  After is_platform_unicode = auto, scintilla displays some unicode
  as you showed. but the win32-functions (e.g. MessageBox) still do not
  pass through wide unicode.

 Win32 issues are better discussed on the python-win32 mailing list
 which is read by more of the people interested in working on this library.
 http://mail.python.org/mailman/listinfo/python-win32
 Patches that improve MessageBox in particular or larger sets of
 functions in a general way are likely to be welcomed.

ok. I have no patches so far as of now - maybe later. Played with
Heller's ctypes for my urgent needs. That works correct with unicode
like this:

 import ctypes
 ctypes.windll.user32.MessageBoxW(0,u'\u041f\u043e\u0448\u0443\u043a.txt',0,0)
1

My recommendation for the general style of unicode integration in win32
in future:
* output-functions should dispatch auto on unicode paramams in order to
use the apropriate xxxW-functions
* input-functions (which are used much more infrequent in apps!) should
accept an additional unicode=1 parameter (e.g.:
SetWindowText(unicode=1);  please not extra xxxW -functions! thus one
can easily virtualize apps with something like
xyfunc(...,unicode=ucflag)
* or: input-functions should also auto-run unicode when a significant
string calling parameter is unicode - same as with filesystem-functions
in normal python. Example: win32api.FindFiles(u*)  is same as
FindFiles(*,unicode=1) and is better as FindFilesW(*)

Thus existing ansi apps can be converted to unicode aware apps with
minimum extra efforts.

Robert

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


Re: Problems with WX and program loop...

2006-01-12 Thread Mr BigSmoke
Great! 
Tnx!!

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


Re: Why keep identity-based equality comparison?

2006-01-12 Thread Antoon Pardon
Op 2006-01-11, Mike Meyer schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:
 Op 2006-01-11, Mike Meyer schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:
 Op 2006-01-10, Mike Meyer schreef [EMAIL PROTECTED]:
 Now you can take the practical option and decide that programmatically
 it make no sense to compare a specific couple of values and throw an
 exception in this case, but it doesn't matter much which test you are
 conducting at that point.
 Can you provide a case where having a test for equality throw an
 exception is actually useful?
 I'm not going to bother with that.
 Since you're being vague about what you want,
 I would like some consistency. Either all comparisons between objects
 of different types throw an exception by default or none does.

 That's a very silly thing to ask for. It presumes that all types are
 the same. They aren't.

It doesn't presume anything like that.

 It also presumes that all comparisons are the same. They aren't.

It doesn't presume that either.

 To use an overworked analogy, you might as well ask
 that you either have to peel all fruit, or that you never have to peel
 a fruit.

Bad analogy since a fruit is not a relationship.

 In any case, the proposeed behavior *is* consistent. The behavior for
 all builtin types will be that comparisons that don't make sense will
 throw exceptions.

It is only consistent if you start from an inconsistent view and then
check for how consistently this view is followed. There is nothing
consistent in telling that 1 == (1,3) makes sense and 1  (1,3)
doesn't make sense. Set theoretically both 1 and (1,3) are sets.

There is a use case for things like 1  (1,3) making sense and denoting
a total order. When you have a hetergenous list, having a total order
makes it possible to sort the list which will make it easier to
weed out duplicates. So why don't you demand a use case for the
new behaviour to counter this use case?

IMO it would be better if it was possible to associate some kind
of order function with the container. Because the order most usefull
for comparing between two instances doesn't need to be the most usefull
order in finding an element from a container.

I could impose a total order on sets, so that I can use a bisection
algorithm on a container of them, but such an order is in general
less usefull than the superset ordering when you are manipulating
sets.

 Since we're talking about Py3K here, there is no
 default behavior. User-defined classes all inherit from builtin
 types, and will get the behavior of their comparison operators from
 those types. In particular, those that inherit from object will get
 objects behavior, which means they'll get equality as identity.

But if this makes any behaviour defined on objects consistent by
definition, because the only criteria you seem to have for consistency
is the inherited behaviour from object. If object would use a
random function to decide that would be consistent too, because it
would be the behaviour inherited by other classes. I don't find this
a usefull way to measure consistency.

 and won't provide
 examples to show why you want things to behave whatever way you want,
 I can't really say much else about it.
 Did you see examples that show why Guido wants things to behave whatever
 Guido's idea is a change from current behaviour. Each time I saw some
 argue a change here, people seem to expect a use case from that person.
 So why ask a use case of me and just accepy Guido's idea.

 For one thing, Guido has a long history of doing excellent Python
 design work. For another, this issue was thrashout out at length in
 comp.lang.python some years ago. What Guido proposed is inline with
 the conclusions of those discussions.

Then it should be easy to come up with the use cases and arguments pro
this idea presented then. If this idea of Guido was the result of his
briliance in language design, surely there should be arguments and
use cases to confirm that.

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


Re: flatten a level one list

2006-01-12 Thread Cyril Bazin
Another try:

def flatten6(x, y):
return list(chain(*izip(x, y)))

(any case, this is shorter ;-)

Cyril

On 1/12/06, Michael Spencer [EMAIL PROTECTED] wrote:
 Tim Hochberg wrote:
  Michael Spencer wrote:
Robin Becker schrieb:
Is there some smart/fast way to flatten a level one list using the
latest iterator/generator idioms.
  ...
 
  David Murmann wrote:
Some functions and timings
  ...
 
  Here's one more that's quite fast using Psyco, but only average without it.
 
 
  def flatten6():
   n = min(len(xdata), len(ydata))
   result = [None] * (2*n)
   for i in xrange(n):
   result[2*i] = xdata[i]
   result[2*i+1] = ydata[i]
 
  -tim
 
 Indeed:

 I added yours to the list (after adding the appropriate return)

testthem()
timethem()
   flatten1(...)  702 iterations, 0.71msec per call
   flatten2(...)  641 iterations, 0.78msec per call
   flatten3(...)  346 iterations, 1.45msec per call
   flatten4(...)  1447 iterations, 345.66usec per call
   flatten5(...)  1218 iterations, 410.55usec per call
   flatten6(...)  531 iterations, 0.94msec per call
   

 (See earlier post for flatten1-5)

 Michael

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

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


Re: flatten a level one list

2006-01-12 Thread Robin Becker
Paul Rubin wrote:
 Paul Rubin http://[EMAIL PROTECTED] writes:
 
import operator
a=[(1,2),(3,4),(5,6)]
reduce(operator.add,a)

(1, 2, 3, 4, 5, 6)
 
 
 (Note that the above is probably terrible if the lists are large and
 you're after speed.)
yes, and it is all in C and so could be a contender for the speed champ. 
I guess what you're saying is that it's doing

(1,2)
(1,2)+(3,4)
(1,2,3,4)+(5,6)

ie we do n or n-1 tuple additions each of which requires tuple 
allocation etc etc

A fast implementation would probably allocate the output list just once 
and then stream the values into place with a simple index.
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Handling

2006-01-12 Thread Sheldon
Hi,
This is a non-trivial thing that you are trying to do. You can use some
of python's built-in exceptions, like RuntimeError or IOError and if so
then:
try:
   call C
except IOError, e:
print e

But this will return and print only IOErrors if they occur.

You can define your own error handling using the function RAISE:
try:
  Call C
except:
  raise my_error.

A catch-all error is RuntimeError; try this first.
try:
 call C
except RuntimeError, r:
  print r

You can read up on it here:
http://docs.python.org/api/standardExceptions.html


Cheers,
Sheldon

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


Re: void * C array to a Numpy array using Swig

2006-01-12 Thread Jon
Krish,

In case you find a good solution, I am also looking for one!

For now I essentially use helper functions on the c side which wrap in
SWIG to return the data as a string in python. That string can then be
converted to a numpy array using the fromstring function. This is
inefficient as it does an unnecessary copy but avoids dependence on
numeric versus numarray etc. It uses the cstring thing in SWIG (see the
manual). The library I am wrapping does not have an image struct, but
returns the data into memory that the user has to malloc.

In the swig file I have something like this, which I've simplified to
try to get to the point. It assumes you have two c functions which take
a pointer to your struct as argument, the first returns the size of the
data (what to malloc), the second copies the data into your memory
where a pointer to the memory location was second arg.

Doubtless I've introduced typos below, but hopefully you get the idea?

Good luck,

Jon
---
typedef struct
{
stuff/* I don't know or care what is in here */
} imagefilestruct;

%extend imagefilestruct {

 [... snip constructor destructor other functions etc]

%cstring_output_allocate_size( char ** s, int *slen, free(*$1))
get_data ;

void get_data(char **s, int *slen){
   void * array;
   size_t size;
   size = libraryfunction_get_size(self);
   array=malloc(size));
   libraryfunc_get_data(self, array);
   *slen = size;
   *s = (char *) array;
   }
}

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


Re: flatten a level one list

2006-01-12 Thread Peter Otten
Tim Hochberg wrote:

 Here's one more that's quite fast using Psyco, but only average without
 it.
 
 def flatten6():
  n = min(len(xdata), len(ydata))
  result = [None] * (2*n)
  for i in xrange(n):
  result[2*i] = xdata[i]
  result[2*i+1] = ydata[i]

I you require len(xdata) == len(ydata) there's an easy way to move the loop
into C:

def flatten7():
n = len(xdata)
assert len(ydata) == n
result = [None] * (2*n)
result[::2] = xdata
result[1::2] = ydata
return result

$ python -m timeit 'from flatten import flatten6 as f' 'f()'
1000 loops, best of 3: 847 usec per loop
$ python -m timeit 'from flatten import flatten7 as f' 'f()'
1 loops, best of 3: 43.9 usec per loop

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


Re: Why keep identity-based equality comparison?

2006-01-12 Thread Paul Rubin
Antoon Pardon [EMAIL PROTECTED] writes:
 There is a use case for things like 1  (1,3) making sense and denoting
 a total order. When you have a hetergenous list, having a total order
 makes it possible to sort the list which will make it easier to
 weed out duplicates. So why don't you demand a use case for the
 new behaviour to counter this use case?

This could easily be handled with an alternate comparison function
that you pass to the sort function.
-- 
http://mail.python.org/mailman/listinfo/python-list


How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread sandravandale
I can think of several messy ways of making a dict that sets a flag if
it's been altered, but I have a hunch that experienced python
programmers would probably have an easier (well maybe more Pythonic)
way of doing this.

It's important that I can read the contents of the dict without
flagging it as modified, but I want it to set the flag the moment I add
a new element or alter an existing one (the values in the dict are
mutable), this is what makes it difficult. Because the values are
mutable I don't think you can tell the difference between a read and a
write without making some sort of wrapper around them.

Still, I'd love to hear how you guys would do it.

Thanks,
-Sandra

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


Re: flatten a level one list

2006-01-12 Thread Paul Rubin
Robin Becker [EMAIL PROTECTED] writes:
 reduce(operator.add,a)
 ...
 A fast implementation would probably allocate the output list just
 once and then stream the values into place with a simple index.

That's what I hoped sum would do, but instead it barfs with a type
error.  So much for duck typing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Scripts to logon to websites

2006-01-12 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes:
 Underlining your point, the difference between the two is that digest
 offers *strong* authentication (i.e. is not subject to replay attacks)

As I mentioned in another post, that's really not enough, since digest
still exposes the password hash to offline dictionary attacks, which
are sure to nab some passwords if you have a lot of users being
sniffed and you don't impose severe amounts of password discipline on
them.  There's also usually no way to log out from an http
authenticated session except by completely closing the browser.  All
in all, if you have nontrivial security requirements there's not much
point in using Digest.  Use form-based authentication over SSL/TLS
instead.  Make sure that the application locks out the user account
(at least temporarily) after too many failed login attempts, something
http authentication implementations that I know of don't bother to do.

For higher security applications (e.g. extranets, admin interfaces,
etc), use client certificates on hardware tokens.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: flatten a level one list

2006-01-12 Thread bonono
Robin Becker wrote:
 Paul Rubin wrote:
  Paul Rubin http://[EMAIL PROTECTED] writes:
 
 import operator
 a=[(1,2),(3,4),(5,6)]
 reduce(operator.add,a)
 
 (1, 2, 3, 4, 5, 6)
 
 
  (Note that the above is probably terrible if the lists are large and
  you're after speed.)
 yes, and it is all in C and so could be a contender for the speed champ.
 I guess what you're saying is that it's doing

That is what I thought too but seems that [x for pair in li for x in
pair] is the fastest on my machine and what is even stranger is that if
I use psyco.full(), I got a 10x speed up for this solution(list
comprehension) which is head and shoulder above all the other suggested
so far.

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


Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Amit Khemka
Ideally, I would have made a wrapper to add/delete/modify/read from
the dictionay.

But other than this, one way i can think straight off is to pickle
the dict, and to see if the picked object is same as current object.

cheers,
amit.

On 12 Jan 2006 01:15:38 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 I can think of several messy ways of making a dict that sets a flag if
 it's been altered, but I have a hunch that experienced python
 programmers would probably have an easier (well maybe more Pythonic)
 way of doing this.

 It's important that I can read the contents of the dict without
 flagging it as modified, but I want it to set the flag the moment I add
 a new element or alter an existing one (the values in the dict are
 mutable), this is what makes it difficult. Because the values are
 mutable I don't think you can tell the difference between a read and a
 write without making some sort of wrapper around them.

 Still, I'd love to hear how you guys would do it.

 Thanks,
 -Sandra

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



--

Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes:
 Still, I'd love to hear how you guys would do it.

Make a subclass of dict, or an object containing a dictionary, that
has a special __setattr__ method that traps updates and sets that
modification flag.  There are contorted ways the caller can avoid
triggering the flag, but Python is not Java and it in general makes no
attempt to protect its objects against hostile code inside the
application.

Your suggestion of using pickle is shaky in my opinion, since pickle's
docs don't guarantee that pickling the same dictionary twice will
return the same pickle both times.  If it happens to work that way,
it's just an implementation accident.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode style in win32/PythonWin

2006-01-12 Thread Thomas Heller
Robert [EMAIL PROTECTED] writes:

 Neil Hodgson wrote:
 Robert:

  After is_platform_unicode = auto, scintilla displays some unicode
  as you showed. but the win32-functions (e.g. MessageBox) still do not
  pass through wide unicode.

 Win32 issues are better discussed on the python-win32 mailing list
 which is read by more of the people interested in working on this library.
 http://mail.python.org/mailman/listinfo/python-win32
 Patches that improve MessageBox in particular or larger sets of
 functions in a general way are likely to be welcomed.

 ok. I have no patches so far as of now - maybe later. Played with
 Heller's ctypes for my urgent needs. That works correct with unicode
 like this:

 import ctypes
 ctypes.windll.user32.MessageBoxW(0,u'\u041f\u043e\u0448\u0443\u043a.txt',0,0)
 1

FYI, if you assign the argtypes attribute for ctypes functions, the
ascii/unicode conversion is automatic (if needed).

So after these assignments:

  ctypes.windll.user32.MessageBoxW.argtypes = (c_int, c_wchar_p,
   c_wchar_p, c_int)
  ctypes.windll.user32.MessageBoxA.argtypes = (c_int, c_char_p,
   c_char_p, c_int)

both MessageBoxA and MessageBoxW can both be called with either ansi and
unicode strings, and should work correctly.  By default the conversion
is done with ('msbc', 'ignore'), but this can also be changed,
ctypes-wide, with a call to ctypes.set_conversion_mode(encoding,errors).

You have to pass None for the third parameter (if not a string).

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


Re: Real-world use cases for map's None fill-in feature?

2006-01-12 Thread Raymond Hettinger
[EMAIL PROTECTED]
   How well correlated in the use of map()-with-fill with the
   (need for) the use of zip/izip-with-fill?

[raymond]
  Close to 100%.  A non-iterator version of izip_longest() is exactly
  equivalent to map(None, it1, it2, ...).

[EMAIL PROTECTED]
 If I use map()
 I can trivially determine the arguments lengths and deal with
 unequal length before map().  With iterators that is more
 difficult.  So I can imagine many cases where izip might
 be applicable but map not, and a lack of map use cases
 not representative of izip use cases.

You don't seem to understand what map() does.  There is no need  to
deal with unequal argument lengths before map(); it does the work for
you.  It handles iterator inputs the same way.  Meditate on this:

def izip_longest(*args):
return iter(map(None, *args))

Modulo arbitrary fill values and lazily evaluated inputs, the semantics
are exactly what is being requested.  Ergo, lack of use cases for
map(None,it1,it2) means that izip_longest(it1,it2) isn't needed.

Raymond

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


Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Brian van den Broek
[EMAIL PROTECTED] said unto the world upon 12/01/06 03:15 AM:
 I can think of several messy ways of making a dict that sets a flag if
 it's been altered, but I have a hunch that experienced python
 programmers would probably have an easier (well maybe more Pythonic)
 way of doing this.
 
 It's important that I can read the contents of the dict without
 flagging it as modified, but I want it to set the flag the moment I add
 a new element or alter an existing one (the values in the dict are
 mutable), this is what makes it difficult. Because the values are
 mutable I don't think you can tell the difference between a read and a
 write without making some sort of wrapper around them.
 
 Still, I'd love to hear how you guys would do it.
 
 Thanks,
 -Sandra
 

Hi Sandra,

here's one attempt. (I'm no expert, so wait for better :-)

  class ModFlagDict(dict):
def __init__(self, *args, **kwargs):
super(ModFlagDict, self).__init__(*args, **kwargs)
self.modified = False
def __setitem__(self, key, value):
self.modified = True
super(ModFlagDict, self).__setitem__(key, value)


  md = ModFlagDict(a=4, b=5)
  md
{'a': 4, 'b': 5}
  md.modified
False
  md[3]=5
  md
{'a': 4, 3: 5, 'b': 5}
  md.modified
True
 

It's broken in at least one way:

  newmd = ModFlagDict(3=4, 1=5)
SyntaxError: keyword can't be an expression
 

So, as it stands, no integers, floats, tuples, etc can be keys on 
initialization. I think that can be be worked around by catching the 
exceptions and setting the desired key-value pairs that way. But, it 
is almost 4am, and I also suspect there is a much better way I am not 
thinking of :-)

Best,

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


Re: Spelling mistakes!

2006-01-12 Thread Antoon Pardon
Op 2006-01-11, Hans Nowak schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:

 Op 2006-01-10, Terry Hancock schreef [EMAIL PROTECTED]:
 
In unit testing, you write the code, then write code to test
the code, which must correctly identify the methods in the
code. So you have to type 'everything' twice.
 
 But you don't type attribute names twice in unit tests,
 because attributes are in general implementation details
 that are of no concern to the tester. So unit tests can
 not introduce the redundancy to find out a missed spelled
 attribute in some methods.

 I wouldn't call attributes implementation details, at least not in 
 Python.  And while it is true that unit tests might not find the 
 misspelling *directly* (i.e. you rarely test if you have misspelled 
 something), your tests should definitely show unexpected behavior and 
 results, if that attribute is of any importance.  Otherwise there's a 
 loophole in your tests. :-)

But now we are back to my first doubt. Sure unit test will be
helpfull in finding out there is a bug. I doubt they are that
helpfull in tracking the bug (at least this kind).

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


different versions for 2.3.4 documentation

2006-01-12 Thread Manlio Perillo
Regards.

I'm only a bit curious, but why documentation from
http://www.python.org/ftp/python/2.3.4/Python-2.3.4.tar.bz2
and
http://www.python.org/ftp/python/doc/2.3.4/latex-2.3.4.tar.bz2
differ?



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


Re: Programming Eclipse plugins in Jython?

2006-01-12 Thread Fabio Zadrozny
Kenneth McDonald wrote:

Is it easy or difficult to implement Eclipse plugins in Jython? And  
if the former, are there any starter's guides you could recommend?

The desire is an editor plugin for a syntactically very simple  
proprietary language. I'd like to have paren checking, syntax  
colorization and (to start with at least) a few other small features.  
Unfortunately, there's quite a hump in learning the Eclipse API well  
enough to do even simple things (or at least that's what my reading  
seems to indicate), and I was wondering if I can cheat and use Jython  
to simplify the process.

Thanks,
Ken
  

Hi Kenneth,

Basically, you will NEED to understand the Eclipse API one way or the 
other, and jython will not really help you there... -- I know... been 
there :-)

But after you're able to grasp its concepts, you can probably use it 
without problems... Altough you'll have to extend the same java 
interfaces Eclipse provides anyway ;-)

Cheers,

Fabio


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


Re: New Python.org website ?

2006-01-12 Thread Tim Parkin
Mike Meyer wrote:
 Stefan Rank [EMAIL PROTECTED] writes:
Very nice!
Just wanted to note that the content area and the menu area overlap
(leaving some content unreadable)
in Opera 8.51 / WinXP
 
 
 Ditto for Opera 8.51 / OSX, and for Safari.
 
 It's a problem with not handling users who need large fonts. I
 recreated it in Mozilla by changing the minimum font size setting from
 None to 20 (just a value I chose at random). I use Opera and
 Safari on a day-to-day basis, and probably configured them
 appropriately for my aging eyes.
Yep... The problem at the moment is that we're trying to (correctly IMO)
use relative font sizing for both fonts and layout.. The problem I'm
hitting is that layout widths/heights are based on the basefont size. So
 if my basefont size 89% and I've size my fonts at 84%, the fonts get
affected by the applied minimum font before the layout, causing the menu
items to expand before the actual menu container. There is a fix for
this problem already as it also exhibits itself on the gecko platform
(hopefully that will be up on beta. in the next few days)

 
 Of course, this is typical on the web: Works in IE really means
 works in IE in the configurations we tested it for, and usually
 means works in our favorite configuration.

Actually the site has been tested on every browser listed on
http://www.browsercam.com/Features.aspx and a few extras...

Whilst it doesn't work on ie4 (although it is readable) it does work on
netscape 4.x (albeit with a much simpler css layout dedicated for just
this browser) and it has also been optimised to work in lynx/links and
has been partially tested in some speech readers.. However, since this
testing there has been some changes made and instead of continually
testing across all configurations, we're planning on running another
browser check soon.

 In particular, creating a good-looking design that remains readable in
 all possible browser configurations is impossible. Getting one that is
 readable in all reasonable browser configurations is hard, unless you
 make your definition of reasonable very narrow.
 
Not quite impossible but I agree it's pretty hard, especially using css
for layout and trying to follow w3c guidelines (e.g. the relative font
sizing thing)... However our aim is to make the site readable in all
browsers in the majority of normal configurations.

Thanks for the feedback..

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


Re: New Python.org website ?

2006-01-12 Thread Tim Parkin
rzed wrote:
 So what's the character encoding? I haven't found (WinXP Firefox)
 that displays that city in Sweden without a paragraph symbol or
 worse.
It's going to be utf8 hopefully but we're just fighting with conversions
 from existing content which I'd wrongly assumed was already iso8859-1

Tim

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


Re: New Python.org website ?

2006-01-12 Thread Tim Parkin
Fuzzyman wrote:
 Steve Holden wrote:
 
Fuzzyman wrote:

Now that is a very cool site.

I'm not very good with HTML - but can write content... I might see if
there is something I can do.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
(and yes I do get referrals from these links...)


Please note that one major rationale behind the new design is precisely
becuase relatively few people *are* good with HTML. Consequently Tim
Parkin, the principal designer of the new architecture, has gone to
great lengths to design a scheme that allows most of the authoring to be
done in REstructured Text.

It's quite an legenat design, and if all you want to do is edit content
rather than change layout it's *very* easy to use. Climb aboard!

 
 Seriously though... I've downloaded the whole shooting match. It's not
 *obvious* from trac what needs doing or who's working on what (although
 I have yet to trawl through the SVN checkout).
 
 I'd hate to start working on something, only to discover someone else
 was already doing it...
 
 All the best,
 
 Fuzzyman
Hi Fuzzyman,

Thanks for the feedback and volunteering to contribue... The list of
already built sections is not really up to date but I have added a few
tickets to the trac on some sections of content that need working on. If
you want to add a comment to one of these or assign yourself to a ticket
please help yourself. I'm on hand most of the time to help with teething
problems etc. Also, beta.python.org has been configured to rebuild
itself once content has been checked in. If you haven't got an svn
account and want to contribute, you can send it to me and I'll add it
for your.

Cheers

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


Re: Python-list Digest, Vol 28, Issue 191

2006-01-12 Thread Manish Kumar (WT01 - Software Products OSS)

Hi,

It does not work. I had already tried this earlier.

Please suggest some other solutions.

Also, I would like to see the stack from where the exception started.

Thanks n regards,
Manish Kumar

On Thu, 2006-01-12 at 10:40 +0100, [EMAIL PROTECTED] wrote:
 Send Python-list mailing list submissions to
   python-list@python.org
 
 To subscribe or unsubscribe via the World Wide Web, visit
   http://mail.python.org/mailman/listinfo/python-list
 or, via email, send a message with subject or body 'help' to
   [EMAIL PROTECTED]
 
 You can reach the person managing the list at
   [EMAIL PROTECTED]
 
 When replying, please edit your Subject line so it is more specific
 than Re: Contents of Python-list digest...
 Today's Topics:
 
1. Re: Exception Handling (Sheldon)
2. Re: void * C array to a Numpy array using Swig (Jon)
3. Re: flatten a level one list (Peter Otten)
4. Re: Why keep identity-based equality comparison? (Paul Rubin)
5. Re: flatten a level one list (Paul Rubin)
6. How can I create a dict that sets a flag if it's been
   modified ([EMAIL PROTECTED])
7. Re: Python Scripts to logon to websites (Paul Rubin)
8. Re: flatten a level one list ([EMAIL PROTECTED])
9. Re: How can I create a dict that sets a flag if it's been
   modified (Amit Khemka)
   10. Re: How can I create a dict that sets a flag if it's been
   modified (Paul Rubin)
   11. Re: Unicode style in win32/PythonWin (Thomas Heller)
   12. Re: Real-world use cases for map's None fill-in feature?
   (Raymond Hettinger)
 email message attachment
 On Thu, 2006-01-12 at 10:40 +0100, [EMAIL PROTECTED]
 wrote:
  Hi,
  This is a non-trivial thing that you are trying to do. You can use some
  of python's built-in exceptions, like RuntimeError or IOError and if so
  then:
  try:
 call C
  except IOError, e:
  print e
  
  But this will return and print only IOErrors if they occur.
  
  You can define your own error handling using the function RAISE:
  try:
Call C
  except:
raise my_error.
  
  A catch-all error is RuntimeError; try this first.
  try:
   call C
  except RuntimeError, r:
print r
  
  You can read up on it here:
  http://docs.python.org/api/standardExceptions.html
  
  
  Cheers,
  Sheldon
  
  
 email message attachment
 On Thu, 2006-01-12 at 10:40 +0100, [EMAIL PROTECTED]
 wrote:
  Krish,
  
  In case you find a good solution, I am also looking for one!
  
  For now I essentially use helper functions on the c side which wrap in
  SWIG to return the data as a string in python. That string can then be
  converted to a numpy array using the fromstring function. This is
  inefficient as it does an unnecessary copy but avoids dependence on
  numeric versus numarray etc. It uses the cstring thing in SWIG (see the
  manual). The library I am wrapping does not have an image struct, but
  returns the data into memory that the user has to malloc.
  
  In the swig file I have something like this, which I've simplified to
  try to get to the point. It assumes you have two c functions which take
  a pointer to your struct as argument, the first returns the size of the
  data (what to malloc), the second copies the data into your memory
  where a pointer to the memory location was second arg.
  
  Doubtless I've introduced typos below, but hopefully you get the idea?
  
  Good luck,
  
  Jon
  ---
  typedef struct
  {
  stuff/* I don't know or care what is in here */
  } imagefilestruct;
  
  %extend imagefilestruct {
  
   [... snip constructor destructor other functions etc]
  
  %cstring_output_allocate_size( char ** s, int *slen, free(*$1))
  get_data ;
  
  void get_data(char **s, int *slen){
 void * array;
 size_t size;
 size = libraryfunction_get_size(self);
 array=malloc(size));
 libraryfunc_get_data(self, array);
 *slen = size;
 *s = (char *) array;
 }
  }
  
  
 email message attachment
 On Thu, 2006-01-12 at 10:40 +0100, [EMAIL PROTECTED]
 wrote:
  Tim Hochberg wrote:
  
   Here's one more that's quite fast using Psyco, but only average without
   it.
   
   def flatten6():
n = min(len(xdata), len(ydata))
result = [None] * (2*n)
for i in xrange(n):
result[2*i] = xdata[i]
result[2*i+1] = ydata[i]
  
  I you require len(xdata) == len(ydata) there's an easy way to move the loop
  into C:
  
  def flatten7():
  n = len(xdata)
  assert len(ydata) == n
  result = [None] * (2*n)
  result[::2] = xdata
  result[1::2] = ydata
  return result
  
  $ python -m timeit 'from flatten import flatten6 as f' 'f()'
  1000 loops, best of 3: 847 usec per loop
  $ python -m timeit 'from flatten import flatten7 as f' 'f()'
  1 loops, best of 3: 43.9 usec per loop
  
  Peter
  
 email message attachment
 On Thu, 2006-01-12 at 10:40 +0100, [EMAIL PROTECTED]
 wrote:
  Antoon Pardon [EMAIL PROTECTED] writes:
   There is a use case for things like 1  (1,3) making 

Re: Unicode Pythonwin / win32 / console?

2006-01-12 Thread Robert

Martin v. Löwis schrieb:

 Robert wrote:
  is in a PythonWin Interactive session - ok results for cyrillic chars
  (tolerant mbcs/utf-8 encoding!).
  But if I do this on Win console (as you probably mean), I get also
  encoding Errors - no matter if chcp1251, because cyrillic chars raise
  the encoding errors also.

 If you do chcp 1251 (not chcp1251) in the console, and then
 run python.exe in the same console, what is the value of
 sys.stdout.encoding?

correctly: 'cp1252' in my case; cyrillic-chars break print   (on PC
linux 2.2 tty sys.stdout.encoding does not exist)

I live with this in site(customize):
# tolerant unicode output ... #
_stdout=sys.stdout
if sys.platform=='win32' and not
sys.modules.has_key('pywin.framework.startup'):
_stdoutenc=getattr(_stdout,'encoding',sys.getdefaultencoding())
class StdOut:
def write(self,s):
_stdout.write(s.encode(_stdoutenc,'backslashreplace'))
sys.stdout=StdOut()
elif sys.platform.startswith('linux'):
import locale
_stdoutenc=locale.getdefaultlocale()[1]
class StdOut:
def write(self,s):
_stdout.write(s.encode(_stdoutenc,'backslashreplace'))
sys.stdout=StdOut()


  I think this is not a good behaviour of python to be so picky.

 I think it it is good.

Errors should never pass silently.
Unless explicitly silenced.

A political question. Arguments:

* Webbrowsers for example have to display defective HTML as good as
possible, unknown unicode chars as ? and so on... Users got very
angry in the beginning of browsers when 'strict' programmers displayed
their exception error boxes ...

* at least the print statement has to go through - the costs (for
angry users and developers; e.g.
http://blog.ianbicking.org/do-i-hate-unicode-or-do-i-hate-ascii.html)
are much higher when apps suddenly break in simple print/display-output
when the system picks up alien unicode chars somewhere (e.g.
occasionally in filenames,...). No one is really angry when
occasionally chinese chars are displayed cryptically on non-chinese
computers. One can investigate, add fonts, ... to improve, or do
nothing in most cases, but apps do not break on every print statement!
This is not only true for tty-output, but also for log-file redirect
and almost any common situation for print/normal
stdout/file-(write)-output.

* anything is nice-printable in python by default, why not
unicode-strings!? If the decision for default 'strict' encoding on
stdout stands, we have at least to discuss about print-repr for
unicode.

* the need for having technical strings 'strict' is much more rare. And
programmers are anyway very aware in such situations . e.g. by
asciifile.write( us.encode(xy,'strict') )   .

* on Windows for example the (good) mbcs_encode is anyway tolerant as
it: unkown chars are mapped to '?' . I never had any objection to this.


Some recommendations - soft to hard:

* make print-repr for unicode strings tolerant  (and in PythonWin
alwasy tolerant 'mbcs' encoding)

* make stdout/files to have 'replace'-mode encoding by default.
(similar as done with my code above)

* set site.py/encoding=('ascii', 'replace')   # if not
utf-8/mbcs/locale ;enable a tuple
* save sys._setdefaultencoding by default

* I would also live perfectly with .encode(enc) to run 'replace' by
default, and 'strict' on demand. None of my apps and scripts would
break because of this, but win. A programmer is naturally very aware
when he wants 'strict'. Can you name realistic cases where 'replace'
behavior would be so critical that a program damages something?


  In
  [EMAIL PROTECTED] I showed, how I
  solved this so far. Any better/portable idea?

 Not sure why you aren't using sys.stdout.encoding on Linux. I would do

 try:
   c = codecs.getwriter(sys.stdout.encoding)
 except:
   c = codecs.getwriter('ascii')
 sys.stdout = c(sys.stdout, 'replace')

 Also, I wouldn't edit site.py, but instead add sitecustomize.py.

I have more problems with the shape of sys.path in different
situations, multiple sitecustomize.py on other apps, environments, OS /
users, cxfreeze,py2exe  ...   sitecustomize not stackable easily: a
horror solution. The need is for a callable _function_ or for general
change in python behaviour.

modifiying site.py is better and stable for me (I have my
patch/module-todo-list handy each time i install a new python), as I
always want tolerant behaviour. in code i check for
site.encoding/_setdefaultencoding (I save this). Thus i get one central
error if setup is not correct, but not evil unicode-errors somewhere
deep in the app once on a russian computer in the future...

  Yes. But the original problem is, that occasionally unicode strings
  (filenames in my case) arise which are not defined in the local
  platform encodings, but have to be displayed (in 'replace' encoding mode)
  without breaking the app flow. Thats the pain of the default behaviour
  of current python - and there is no simple switch. Why should print
  xy not print something _always_ as good and 

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Tim N. van der Leeuw
Should the dict flag when the dict itself has been updated? Or also
when any of the items in the dict has been updated?

Say you have a dict consisting of lists...

The dict should be flagged as modified when an item is added; or when
an item is replaced (you call dict.__setitem__ with a key that already
exists).
This is clear, and easy to achieve with a simple wrapper or subclass.

But should the dict also be flagged as 'modified' when I append an item
to one of the lists that is in the dict?
 l = d['a']
 l.append('1')
Does that code mean that the dict should be flagged as 'modified' in
your use-case? or not?

If yes, then the only feasible way might be to pickle the dict. And if
repeated pickling of the same dict is not guaranteed to give the same
results, then perhaps pickling d.getitems() would give the right
results since, AFAIK, dict.getitems() is at least guaranteed to
maintain the same order given that A) The dict is not changed and B)
You're using the same Python version.

Right?

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


Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Brian van den Broek
Brian van den Broek said unto the world upon 12/01/06 03:42 AM:
 [EMAIL PROTECTED] said unto the world upon 12/01/06 03:15 AM:
 
I can think of several messy ways of making a dict that sets a flag if
it's been altered, but I have a hunch that experienced python
programmers would probably have an easier (well maybe more Pythonic)
way of doing this.

snip

 here's one attempt. (I'm no expert, so wait for better :-)
 
   class ModFlagDict(dict):
   def __init__(self, *args, **kwargs):
   super(ModFlagDict, self).__init__(*args, **kwargs)
   self.modified = False
   def __setitem__(self, key, value):
   self.modified = True
   super(ModFlagDict, self).__setitem__(key, value)

snip

 It's broken in at least one way:
 
   newmd = ModFlagDict(3=4, 1=5)
 SyntaxError: keyword can't be an expression
  
 
 So, as it stands, no integers, floats, tuples, etc can be keys on 
 initialization. I think that can be be worked around by catching the 
 exceptions and setting the desired key-value pairs that way. But, it 
 is almost 4am, and I also suspect there is a much better way I am not 
 thinking of :-)

Sorry for the self-reply, but I just realized my original code isn't 
quite so bad as:

# class ModFlagDict as before

  mdict = ModFlagDict({42:This will work, (7, 6):Python comes 
through, again!})
  mdict
{42: 'This will work', (7, 6): 'Python comes through, again!'}
  mdict.modified
False
  mdict[42]=:-)
  mdict
{42: ':-)', (7, 6): 'Python comes through, again!'}
  mdict.modified
True
 

I'll wager someone will point out a better way still, though.

Best,

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


Re: Determination of disk types

2006-01-12 Thread Mondal
Hi,

Thanks for the info. That was quite useful. I will surely poke around
wmi.

Thanks again

Regards
Mondal

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


Re: Exception Handling

2006-01-12 Thread Manish Kumar (WT01 - Software Products OSS)

I tried with this piece of code

def temp():

try:
print In try
libsummac.main1()
except RuntimeError, re:
print caught + re
except e:
print caught + e

I think the control is not coming to python code. The output of the
above is ..(In main1 before assignment -- this print is inside the C
function).


In try
In main1 before assignment
Segmentation fault

Can u give some solutions for this???

Thanks n Regards,
Manish Kumar

On Thu, 2006-01-12 at 10:40 +0100, [EMAIL PROTECTED] wrote:
 Send Python-list mailing list submissions to
   python-list@python.org
 
 To subscribe or unsubscribe via the World Wide Web, visit
   http://mail.python.org/mailman/listinfo/python-list
 or, via email, send a message with subject or body 'help' to
   [EMAIL PROTECTED]
 
 You can reach the person managing the list at
   [EMAIL PROTECTED]
 
 When replying, please edit your Subject line so it is more specific
 than Re: Contents of Python-list digest...
 Today's Topics:
 
1. Re: Exception Handling (Sheldon)
2. Re: void * C array to a Numpy array using Swig (Jon)
3. Re: flatten a level one list (Peter Otten)
4. Re: Why keep identity-based equality comparison? (Paul Rubin)
5. Re: flatten a level one list (Paul Rubin)
6. How can I create a dict that sets a flag if it's been
   modified ([EMAIL PROTECTED])
7. Re: Python Scripts to logon to websites (Paul Rubin)
8. Re: flatten a level one list ([EMAIL PROTECTED])
9. Re: How can I create a dict that sets a flag if it's been
   modified (Amit Khemka)
   10. Re: How can I create a dict that sets a flag if it's been
   modified (Paul Rubin)
   11. Re: Unicode style in win32/PythonWin (Thomas Heller)
   12. Re: Real-world use cases for map's None fill-in feature?
   (Raymond Hettinger)
 email message attachment
 On Thu, 2006-01-12 at 10:40 +0100, [EMAIL PROTECTED]
 wrote:
  Hi,
  This is a non-trivial thing that you are trying to do. You can use some
  of python's built-in exceptions, like RuntimeError or IOError and if so
  then:
  try:
 call C
  except IOError, e:
  print e
  
  But this will return and print only IOErrors if they occur.
  
  You can define your own error handling using the function RAISE:
  try:
Call C
  except:
raise my_error.
  
  A catch-all error is RuntimeError; try this first.
  try:
   call C
  except RuntimeError, r:
print r
  
  You can read up on it here:
  http://docs.python.org/api/standardExceptions.html
  
  
  Cheers,
  Sheldon
  
  
 email message attachment
 On Thu, 2006-01-12 at 10:40 +0100, [EMAIL PROTECTED]
 wrote:
  Krish,
  
  In case you find a good solution, I am also looking for one!
  
  For now I essentially use helper functions on the c side which wrap in
  SWIG to return the data as a string in python. That string can then be
  converted to a numpy array using the fromstring function. This is
  inefficient as it does an unnecessary copy but avoids dependence on
  numeric versus numarray etc. It uses the cstring thing in SWIG (see the
  manual). The library I am wrapping does not have an image struct, but
  returns the data into memory that the user has to malloc.
  
  In the swig file I have something like this, which I've simplified to
  try to get to the point. It assumes you have two c functions which take
  a pointer to your struct as argument, the first returns the size of the
  data (what to malloc), the second copies the data into your memory
  where a pointer to the memory location was second arg.
  
  Doubtless I've introduced typos below, but hopefully you get the idea?
  
  Good luck,
  
  Jon
  ---
  typedef struct
  {
  stuff/* I don't know or care what is in here */
  } imagefilestruct;
  
  %extend imagefilestruct {
  
   [... snip constructor destructor other functions etc]
  
  %cstring_output_allocate_size( char ** s, int *slen, free(*$1))
  get_data ;
  
  void get_data(char **s, int *slen){
 void * array;
 size_t size;
 size = libraryfunction_get_size(self);
 array=malloc(size));
 libraryfunc_get_data(self, array);
 *slen = size;
 *s = (char *) array;
 }
  }
  
  
 email message attachment
 On Thu, 2006-01-12 at 10:40 +0100, [EMAIL PROTECTED]
 wrote:
  Tim Hochberg wrote:
  
   Here's one more that's quite fast using Psyco, but only average without
   it.
   
   def flatten6():
n = min(len(xdata), len(ydata))
result = [None] * (2*n)
for i in xrange(n):
result[2*i] = xdata[i]
result[2*i+1] = ydata[i]
  
  I you require len(xdata) == len(ydata) there's an easy way to move the loop
  into C:
  
  def flatten7():
  n = len(xdata)
  assert len(ydata) == n
  result = [None] * (2*n)
  result[::2] = xdata
  result[1::2] = ydata
  return result
  
  $ python -m timeit 'from flatten import flatten6 as f' 'f()'
  1000 loops, best of 3: 847 usec per loop
  $ python -m timeit 'from 

Re: Help me in this please--is Python the answer?

2006-01-12 Thread Tim N. van der Leeuw
Hi Ray,

I'm in a bit of the same boat as you only I don't get to choose my
implementation language ;-)

Some of the concerns should be:
- Do you have to interface with things like messaging-systems (a la JMS
specs), distributed transaction managers? If so, the only way to go
Python is Jython: Python for the JVM. Because AFAIK, there are no
interfaces for Python to the likes of IBM's MQSeries or for any
distributed transaction managers.

- Is your application purely a web-based application? Or is there a
large amount of application logic which is not tied to the web in any
way?

- Python has a number of frameworks for developing server applications,
like Twisted, Zope and Django.
I don't know Twisted; I know a little bit about Zope. Zope has several
enterprise-level features and provides scalability/clustering.
However, I've found the learning-curve for Zope to be a bit steep so
far; too steep to master it in what little bits of spare time I have.
(If I would have more time I'd be able to get the hang of it but I
don't have enough time)

I've started to toy a bit with Django and it seems to get rather easy
to get started with developing a Web application using Django; however
I also get the feeling that installation is a bit more involved than
with Zope and that it will be not as easy to package up an application
and transport it to another machine, as it is with Zope.


So for development of Web-applications, I would certainly consider
either Zope or Django.
Both offer ways to store your data in a transactional database; Django
has some object-relation mapper tools but I'm not sure how exactly Zope
stores data in a SQL database (it comes with it's own powerful
object-database, the ZODB but I don't know if OR mapping tools exist
for Zope).


However you mentioned 'development in J2EE' and J2EE applications are
by no means restricted to Web interfaces. J2EE applications can have
rich GUI clients, or can be without any UI at all and exist just as
message-driven beans triggered by messages coming in via JMS
interfaces.
I wouldn't know what Python frameworks exist that would combine
web-based applications with tradional GUI client/server applications
and I have no idea how to listen to a queue using Python...


So what are your requirements for 'J2EE' applications? And which Python
framework would best fit the bill?


cheers,

--Tim

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


Re: flatten a level one list

2006-01-12 Thread bearophileHUGS
Well, maybe it's time to add a n-levels flatten() function to the
language (or to add it to itertools). Python is open source, but I am
not able to modify its C sources yet... Maybe Raymond Hettinger can
find some time to do it for Py 2.5.

Bye,
bearophile

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


Re: Can dictionaries be nested?

2006-01-12 Thread Paul McGuire
[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I'm parsing some data of the form:

 OuterName1  InnerName1=5,InnerName2=7,InnerName3=34;
 OuterName2  InnerNameX=43,InnerNameY=67,InnerName3=21;
 OuterName3 
  and so on

I wrote pyparsing for just this kind of job.  Using pyparsing, you can both
parse the data and build up structured results - even results with keyed
fields or dictionary-type access.

Here's the complete pyparsing program to parse your data:

---
data = 
OuterName1  InnerName1=5,InnerName2=7,InnerName3=34;
OuterName2  InnerNameX=43,InnerNameY=67,InnerName3=21;

# or data = file(inputname).read()

from pyparsing import *

EQ = Literal(=).suppress()
SEMI = Literal(;).suppress()
ident = Word(alphas, alphanums+_)
integer = Word(nums)

value = integer | quotedString

innerentry = Group(ident + EQ + value)

vallist = Dict(delimitedList(innerentry))
outerentry = Group(ident + vallist + SEMI)
datalist = Dict( ZeroOrMore(outerentry) )

vals = datalist.parseString(data)
print vals.keys()
print vals[OuterName1][InnerName2]
print vals.OuterName2.InnerNameY

---

Prints:
['OuterName2', 'OuterName1']
7
67

Here's the same program, with a few more comments to explain what's going
on:
---
from pyparsing import *

# define expressions for some basic elements - use pyparsing's basic
# building blocks, Literal and Word
EQ = Literal(=).suppress()
SEMI = Literal(;).suppress()
ident = Word(alphas, alphanums+_)
integer = Word(nums)

# expand this list to include other items you end up finding in values
value = integer | quotedString

# define the format of the list of InnerName entries
innerentry = Group(ident + EQ + value)

# delimitedList is a pyparsing helper for a list of expressions, separated
by
# some delimiter - default delimiter is a comma
vallist = delimitedList(innerentry)

# lastly, define the overall datalist
outerentry = Group(ident + vallist + SEMI)
datalist = ZeroOrMore( outerentry )

# extract the data into a structure using parseString
vals = datalist.parseString(data)

# prettyprint the results
import pprint
pprint.pprint(vals.asList())
print


# Refinement: have pyparsing build keyed results  while
# it parses (accessible like a dict)
vallist = Dict(delimitedList(innerentry))
outerentry = Group(ident + vallist + SEMI)
datalist = Dict( ZeroOrMore(outerentry) )

# reparse using modified grammar
vals = datalist.parseString(data)

# view results using dict functions
print vals.keys()
print vals[OuterName1][InnerName2]

# if keys are valid Python identifiers, can also access results
# like object fields
print vals.OuterName2.InnerNameY
---
Prints:

[['OuterName1',
  ['InnerName1', '5'],
  ['InnerName2', '7'],
  ['InnerName3', '34']],
 ['OuterName2',
  ['InnerNameX', '43'],
  ['InnerNameY', '67'],
  ['InnerName3', '21']]]

['OuterName2', 'OuterName1']
7
67

Download pyparsing at http://pyparsing.sourceforge.net.  (I'm also making a
couple of pyparsing presentations at PyCon, next month.)

-- Paul


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


Hiding input charachters

2006-01-12 Thread Robert Hilkene
Hi  there

Can any body help, I wanna to hide input characters from user (when he 
enters password)?

I found that for Macintosh you implement 4.12 quietconsole -- 
non-visible stdout output

Can I do it with Windows?

-- 
*
Robert Hilkene
DMS Group
Puskinova 9a
21000 Novi Sad
Serbia  Montenegro
 
Phone:  +381 21 4746008
Mobile: +381 64 277 19 49
[EMAIL PROTECTED]
http://www.dmsgroup.co.yu/
*

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


How to hide output characters on Windows

2006-01-12 Thread Robert Hilkene
Hi there

I want to hide output characters in my py program. I found that for 
Macintosh you implement 4.12 quietconsole -- non-visible stdout output 
(http://www.python.org/doc/2.0.1/mac/module-quietconsole.html)

Can you help me, how I can hide output characters on Windows?

Best Regards

-- 
*
Robert Hilkene
DMS Group
Puskinova 9a
21000 Novi Sad
Serbia  Montenegro
 
Phone:  +381 21 4746008
Mobile: +381 64 277 19 49
[EMAIL PROTECTED]
http://www.dmsgroup.co.yu/
*

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


Re: Help me in this please--is Python the answer?

2006-01-12 Thread Ed Singleton
On 11 Jan 2006 17:54:05 -0800, Ray [EMAIL PROTECTED] wrote:
 Hello,

 I've got the chance to determine the technology to use in creating a
 product similar to this:

 http://www.atomicisland.com/

 Now the thing is that I need to sell this to the guy with the money.
 I've developed for years with C++ and Java, last 7 years J2EE, and I'm
 kinda sick of the bloated feeling that the whole J2EE/appserver
 business carries into the picture.

Personally I have found that if you need to sell a technology on,
saying it's written in Java is an advantage generally (because it's a
standard).  If it's written in Python you may get asked why it has
been written in a scripting language if they've heard of it at all.

 Python is the language that I use at home, so I've been thinking of
 using this to implement the product mentioned above. I've personally
 experienced the pleasure of programming in it, and as such, I hope that
 this will translate to advantage over our competitors (a la Paul
 Graham's argument for Lisp).

From my brief look at that url you gave, it looks like you are trying
to enter a very crowded market place.  You will have to perform a lot
better than your competitors in order to succeed (they have a head
start on you).  There's no way on earth you can do that by using
exactly the same tools as them, so you have to choose better tools. 
Almost by definition, the tools that the majority are using are NOT
the best tools for the job.  If I were you I'd definitely choose
Python, if only because everyone else is not using it yet.

 That said, my experience with Python is limited to toy programs, that I
 write myself for my own use. As such, I have several concerns:

 1. How scalable is Python? In J2EE, when the load gets really big, we
 can resort to clustering. Same goes about availability. Is there
 anything that will help here in Python? (Mind, my Python experience is
 usually with scripts and console).

 2. If there is, what is the transition like from being lightweight to
 heavyweight? E.g.: in J2EE we can use Tomcat at first as a lightweight
 web container, and scale as necessary using a more powerful appserver.
 Is this possible in Python?

If I were you I'd concentrate on creating a website that actually
works.  Your chances of creating a website that needs to scale to be
'heavyweight' are very slim.  If you manage to get to that point then
you can start worrying about how to cope with all the money that's
rolling in ;)

AFAIAA Python scales better than Java as any performance critical
parts can be easily rewritten in C.  To spend too much time worrying
over it is premature optimisation though.

 3. Have any of you done this before? As in you come from a heavy J2EE
 background, and then switch to doing something equally serious in
 Python? In your experience, in the end, did you find Python suitable at
 all for this domain or you think you should have stuck to J2EE? What
 are the pros and cons you discovered?

I don't have much experience of Java tbh, but I've never heard of any
pro's to using it, except for the fact that it's more acceptable to
big business and it's easier to get mediocre programmers for it.

 (I'd love to develop in Python and get paid for it finally, but at the
 same time I do want to give the money guy the best value for his
 money...)

The only thing you really need to be happy is to find something you
enjoy doing and to do it.  Money is definitely secondary to that.  If
you have a chance to be paid for working in Python, then go for it;
even if you fail, you will have spent your days in a happy state.

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


ANN: (slightly) extended Python debugger

2006-01-12 Thread R. Bernstein
I've put out the first release of an expanded version of the Python
debugger. For now it is under the bashdb project on sourceforge:
   http://sourceforge.net/project/showfiles.php?group_id=61395

I've tried this only on 3 machines and each had a different version of
Python: OSX using python version 2.3.5, Fedora Core 4/5 using version
2.4.2 and cygwin using 2.4.1. I am not a Python expert and less so
when it comes to understanding what was added in what release. If this
works before 2.3.5, let me know and all reduce the requirement check
warning on configuration.

In this debugger, largely we're trying to follow gdb's command set
unless there's good reason. So new or modified command names generally
refer to the function they have in gdb.

Changes from pdb.py:

- Add run (restart)

- Add Perl's examine to show info about a symbol.  For functions,
  methods, classes and modules the documentation string if any is printed.
  For functions, we also show the argument list. More work is needed here
  to recurse fields of an arbitrary object and show that.

- add gdb's frame command

- Add some set/show commands:
args, listsize, version (no set here), dialect

- Add some info commands:
   args, break, line, locals, source

- up/down can take a number of frames to move.

- Stepping skips over def statements.

For now, there are two slight dialects of debugger command set: python
and gdb

  For the gdb dialect, stack traces look more like they do in gdb and
  so does frame numbering, up and down function as gdb's does. In
  the python mode, stack traces should be the same.

  In the gdb dialect, some commands have been removed: 
  
  - return: this is reserved for a gdb-style return and it's short
 name r can be confused with run. The gdb equivalent is finish

  - args: the gdb equivalent is info args and the short name a 
 has been removed.

  Aliases could be added in one's .pydbrc for these.

Coexistence: 

  For now, we try not to conflict with pdb.py. After all, Python
  developers made provision of multiple debuggers so we'll make use of
  that!

  So whereever there was a pdb, use pydb. Where Pdb use Pydb. So, as
  hinted above, the debugger initialization script is .pydbrc for this
  debugger rather than .pdbrc for the one that comes with Python.

Future:

  There is much that could be improved and this is just a glimpse of
  what might be done. (But even if it stops here, I'll still be using
  it ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why keep identity-based equality comparison?

2006-01-12 Thread Antoon Pardon
Op 2006-01-12, Paul Rubin schreef http:
 Antoon Pardon [EMAIL PROTECTED] writes:
 There is a use case for things like 1  (1,3) making sense and denoting
 a total order. When you have a hetergenous list, having a total order
 makes it possible to sort the list which will make it easier to
 weed out duplicates. So why don't you demand a use case for the
 new behaviour to counter this use case?

 This could easily be handled with an alternate comparison function
 that you pass to the sort function.

Yes that is true and will be all that is needed in most cases.
But in the case where new items are regularly added, one might
prefer to use the bisect module for something like this. The
bisect module doesn't have an alternate comparison function
neither has the heapqueue module.

O.K. lets try to get at this from a more constructive direction.
Python will get the behaviour that 1  (1,3) will throw an exception.
What can python do to help for cases like the above.

1) Python could provide a seperare total ordering, maybe with operators
   like '|' and '|' and function operator.rank (with functionlity
   similar to cmp)

2) Python could make it possible to associate a ranking with a
   container. This ranking is used by default by methods and
   modules like sort, bisect and heapqueue.

3) Python could provide the possibility of providing an alternate
   comparison function with heapqueue, bisect and similar modules.


These options are not meant to be exclusive. But if a choice is
to be made I would prefer (2) (a little) over (1) over (3).

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


Parse date

2006-01-12 Thread Jacob Friis Saxberg
Hi.How do I parse a date like 2006-01-12T09:05:08+02:00?I'd like to parse it into the local time for my server.Thanks.Jacob
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pdb.py - why is this debugger different from all other debuggers?

2006-01-12 Thread R. Bernstein
Tino Lange [EMAIL PROTECTED] writes:

 R. Bernstein wrote:
 To summarize, I think most of us readers here like your changes or at least
 didn't shout loud enough against it ;-)

Okay. I'll gladly accept whatever positive interpretation someone
wants to offer. :-)

 As I also would like to have a more powerful and gdb-like debugging facility
 in out-of-the-box python, I think it would be the best strategy to make a
 consolidated patch now, send it to sf 

Umm.. If you read the original post, I already *had* submitted a
patch. About two weeks ago. There is no evidence that it's been looked
at. But that's often the way things happen with large projects,
volunteers, and/or minimal resources.

My custom which I think is shared by many other programmers is to
submit a smallish patch, and see how that goes. If it is received
well, then others follow if not, then not.

In the two weeks of nonaction of that patch, I've gone much further at
least to my satisfaction, by working on my own.  (Actually if you look
closely you'll see that I made 3 revisions of the patch. And there
still was a small bug that I've fixed recently in releasing the pydb
package.)

 and to post a note about that on
 python-dev@python.org to get the board's approval :-)

Hmmm. You seem to understand this side of things far better newbe me. Hey,
how about if you do that? Thanks!

 
 idle also changed dramatically during the last versions - why shouldn't
 pdb also become better ... a volunteer seems to be there ;-)
 
 Thanks for your effort and cheers,

And thanks for your effort and cheers!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hiding input charachters

2006-01-12 Thread Paul Rubin
Robert Hilkene [EMAIL PROTECTED] writes:
 Can any body help, I wanna to hide input characters from user (when he
 enters password)?

http://docs.python.org/lib/module-getpass.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why keep identity-based equality comparison?

2006-01-12 Thread Paul Rubin
Antoon Pardon [EMAIL PROTECTED] writes:
 The bisect module doesn't have an alternate comparison function
 neither has the heapqueue module.

They could be extended.  Care to enter a feature request?

 1) Python could provide a seperare total ordering, maybe with operators
like '|' and '|' and function operator.rank (with functionlity
similar to cmp)

Based on experience that I'm sure you understand, anything like that
is going to be awfully hard to sell.

 3) Python could provide the possibility of providing an alternate
comparison function with heapqueue, bisect and similar modules.

That's probably the best bet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

 It's important that I can read the contents of the dict without
 flagging it as modified, but I want it to set the flag the moment I add
 a new element or alter an existing one (the values in the dict are
 mutable), this is what makes it difficult. Because the values are
 mutable I don't think you can tell the difference between a read and a
 write without making some sort of wrapper around them.
 
Detecting when a dictionary is updated is easy, just subclass dict and 
override the __setitem__ method.

Detecting when an object contained within the dictionary is mutated is 
effectively impossible.

If you are willing to compromise you can do something similar to the 
solution used in the ZODB (persistent object database): it marks an object 
as dirty when you rebind an attribute, but it doesn't attempt to catch 
mutation of contained objects. If you want a contained dictionary or list 
to be handled automatically by the persistence machinery you can use a 
PersistentDict or PersistentList object, otherwise you can use an ordinary 
dict/list and manually flag the container as dirty when you mutate it.

This leads to code such as (assuming self is the container):

...
self.somelist.append(something)
self.somelist = self.somelist

which isn't wonderful but mostly works. Of course:

self.somelist += [something]

also has the desired effect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating dictionarie names, using variables?

2006-01-12 Thread Dan Sommers
On Wed, 11 Jan 2006 18:00:53 -0700,
Livin [EMAIL PROTECTED] wrote:

 Are you saying that each child dictionary actually has its own 'key',
 not just the items within it?

I don't quite understand its own 'key'.

There is a main dictionary.  The keys come from replacing spaces with
plusses in item[5].  The values are another dictionary.  The keys of
this other dictionary are the strings 'Group', 'Status', etc.  The
values of this other dictionary are item[2], item[3], etc.

 The goal is to create a dictionary with many dictionaries in it.

  - each child dictionary will hold a single 'device' and its related
 attributes.

Agreed.  Call this the parent dictionary.  I called it devDict.

  - I want to name the child dictionaries the same as their device name
 so it is easy to call them from within the dictionary.

The names of the child dictionaries exist as keys in the parend
dictionary.

  - also, they dictionary will be dynamic, thus the # of devices is
 always changing so they need to be created on-the-fly.

Yes, child dictionaries can be created on the fly, and be manipulated
and managed within the parent dictionary.

HTH,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
-- 
http://mail.python.org/mailman/listinfo/python-list


setup.py vs autoconf install/uninstall,

2006-01-12 Thread R. Bernstein
In making a release of the recent changes to pdb.py announce here:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/b4cb720ed359a733/fbd9f8fef9693e58#fbd9f8fef9693e58
I tried using setup.py. 

I think it's great that setup.py tries to obviate the need for Make
by just doing everything. (In contrast to Perl's MakeMaker). But alas
the problems I was running into was setup.py not doing enough (for
just Python).

Here were the problems I ran into. Perhaps someone will be able to
enlighten me.

1. I didn't find a way to uninstall a package.

2. No overwrite install. When I tried to install a newer version of
   the pydb.py, setup.py didn't write over the old file even though
   the files were different and the time on the file installed over
   was older. I'm assuming it uses the version parameter in the setup
   call only. This isn't helpful in testing between release numbers.

3. How to get pydb.doc and pydb.py in the same directory? As python
   2.2.4 is currently distributed, pdb.doc seems to want to be in the
   same directory as pdb.py. A little weird, but that's the way it is.

After reading docs and trying various things I gave up. (At least for
now).  I was then pleasantly surprised to find that automake comes
with macros for Python! (It doesn't have them for Perl.) But lest I
get too elated, in trying one these out, I see that automake had a
different notion of where to install python scripts than python
uses. But no matter since autotools are sufficiently general (however
ugly), I was able to patch around it as I've done so so many times.

And again we have the same thing as was a concern about debuggers:
there are so many configuration tools, only 3 mentioned above. Sigh.




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


Re: flatten a level one list

2006-01-12 Thread Raymond Hettinger
[Robin Becker]
 Is there some smart/fast way to flatten a level one list using the
 latest iterator/generator idioms.

 The problem arises in coneverting lists of (x,y) coordinates into a
 single list of coordinates eg

 f([(x0,y0),(x1,y1),]) -- [x0,y0,x1,y1,]

Here's one way:

 d = [('x0','y0'), ('x1','y1'), ('x2','y2'), ('x3', 'y3')]
 list(chain(*d))
['x0', 'y0', 'x1', 'y1', 'x2', 'y2', 'x3', 'y3']

FWIW, if you're into working out puzzles, there's no end of interesting
iterator algebra tricks. Here are a few identities for your
entertainment:

# Given s (any sequence) and n (a non-negative integer):
assert zip(*izip(*tee(s,n))) == [tuple(s)]*n
assert list(chain(*tee(s,n))) == list(s)*n
assert map(itemgetter(0),groupby(sorted(s))) == sorted(set(s))


Raymond

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


Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Dan Sommers
On Thu, 12 Jan 2006 03:42:21 -0600,
Brian van den Broek [EMAIL PROTECTED] wrote:

 It's broken in at least one way:

 newmd = ModFlagDict(3=4, 1=5)
 SyntaxError: keyword can't be an expression
 

 So, as it stands, no integers, floats, tuples, etc can be keys on
 initialization ...

That has nothing to do with your code:

 dict(1=4)
SyntaxError: keyword can't be an expression
 int(4=5)
SyntaxError: keyword can't be an expression

The names of keyword arguments have look like Python identifiers; 1 and
4 are *not* valid Python identifiers.

Regards,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Paul Rubin
Brian van den Broek [EMAIL PROTECTED] writes:
 It's broken in at least one way:
 
   newmd = ModFlagDict(3=4, 1=5)
 SyntaxError: keyword can't be an expression

newmd = ModFlagDict(**{3:4, 1:5})
-- 
http://mail.python.org/mailman/listinfo/python-list


python create mail

2006-01-12 Thread anyab5
hey I need help in sending email,

It seems that while using  this set of commands

from smtplib import SMTP

 s = SMTP()
 s.set_debuglevel(1)
 s.connect('outmail.huji.ac.il')

I should be able to get a connection but what I get is this error

T:\Anya\workmail1.py
connect: ('outmail.huji.ac.il', 25)
connect: ('outmail.huji.ac.il', 25)
connect fail: ('outmail.huji.ac.il', 25)
Traceback (most recent call last):
File C:\Python24\lib\smtplib.py, line 303, in connect
raise socket.error, msg
socket.error: (10053, 'Software caused connection abort')

Does any one have a clue ?

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


Re: python create mail

2006-01-12 Thread Tim Williams (gmail)
On 12 Jan 2006 04:28:44 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
hey I need help in sending email,It seems that while usingthis set of commands
from smtplib import SMTP s = SMTP() s.set_debuglevel(1) s.connect('outmail.huji.ac.il')I should be able to get a connection but what I get is this error
T:\Anya\workmail1.pyconnect: ('outmail.huji.ac.il', 25)connect: ('outmail.huji.ac.il', 25)connect fail: ('
outmail.huji.ac.il', 25)Traceback (most recent call last):File C:\Python24\lib\smtplib.py, line 303, in connectraise socket.error, msgsocket.error: (10053, 'Software caused connection abort')
Does any one have a clue ?
 from smtplib import SMTP
 s = SMTP()
 s.set_debuglevel(1)
 s.connect('outmail.huji.ac.il')
connect: ('outmail.huji.ac.il', 25)
connect: ('outmail.huji.ac.il', 25)
reply: '220 mail3.cc.huji.ac.il ESMTP Postfix\r\n'
reply: retcode (220); Msg: mail3.cc.huji.ac.il ESMTP Postfix
connect: mail3.cc.huji.ac.il ESMTP Postfix
(220, 'mail3.cc.huji.ac.il ESMTP Postfix')
 s.quit

Suspect a local / network firewall or port
block. It might possibly be a DNS issue, the
server's IP address is 132.64.1.30 . You should
try telnetting to the IP address on port 25 as a test

HTH :)


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

Re: flatten a level one list

2006-01-12 Thread Sion Arrowsmith
In article [EMAIL PROTECTED],
Paul Rubin  http://[EMAIL PROTECTED] wrote:
Robin Becker [EMAIL PROTECTED] writes:
 reduce(operator.add,a)
 ...
That's what I hoped sum would do, but instead it barfs with a type
error.  So much for duck typing.

sum(...)
sum(sequence, start=0) - value

If you're using sum() as a 1-level flatten you need to give it
start=[].

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

Re: flatten a level one list

2006-01-12 Thread Paul Rubin
Sion Arrowsmith [EMAIL PROTECTED] writes:
 sum(sequence, start=0) - value
 
 If you're using sum() as a 1-level flatten you need to give it
 start=[].

Oh, right, I should have remembered that.  Thanks.  Figuring out
whether it's quadratic or linear would still take an experiment or
code inspection which I'm not up for at the moment.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me in this please--is Python the answer?

2006-01-12 Thread Ray
Hi Ed,

Ed Singleton wrote:
 Personally I have found that if you need to sell a technology on,
 saying it's written in Java is an advantage generally (because it's a
 standard).  If it's written in Python you may get asked why it has
 been written in a scripting language if they've heard of it at all.

Yes, I agree. Especially with those cover-my-ass types in big
institutions who'd only go for things that have the word Enterprise
on it :)

 exactly the same tools as them, so you have to choose better tools.
 Almost by definition, the tools that the majority are using are NOT
 the best tools for the job.  If I were you I'd definitely choose
 Python, if only because everyone else is not using it yet.

Yes, that was what I was thinking. Fast development cycle and ability
to embrace change is crucial here. I do feel the way Java is getting in
the way of my coding even after using Python for small personal
projects.

But then on the other hand, there is a manpower problem--it's damn easy
to find a Java programmer (although the quality that you get is a
different matter). Python programmers are more difficult.

 If I were you I'd concentrate on creating a website that actually
 works.  Your chances of creating a website that needs to scale to be
 'heavyweight' are very slim.  If you manage to get to that point then
 you can start worrying about how to cope with all the money that's
 rolling in ;)

You know what, this is a very good point :))

 AFAIAA Python scales better than Java as any performance critical
 parts can be easily rewritten in C.  To spend too much time worrying
 over it is premature optimisation though.

Yes, but this is more of a web application though--something that I've
never developed in Python before, so... I'll be evaluating Django
shortly--let me see how it compares to Tomcat.

  (I'd love to develop in Python and get paid for it finally, but at the
  same time I do want to give the money guy the best value for his
  money...)

 The only thing you really need to be happy is to find something you
 enjoy doing and to do it.  Money is definitely secondary to that.  If
 you have a chance to be paid for working in Python, then go for it;
 even if you fail, you will have spent your days in a happy state.

Yeah, I have the chance to do that if I manage to get this through, but
at the same time I do want to give the guy who funds us the best value
possible for his money. (If--If--it means I have to use J2EE, I will do
it.)

Thanks,
Ray

 
 Ed

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


Re: python-soappy

2006-01-12 Thread m.banaouas
Mikalai a écrit :
 While talking about SOAPpy module, I'm facing an authentication problem
 with it:

 I'm consuming a WebServices server requiring authentication, and I did
 not found yet how to give authentication code (username:password) while
 calling any mehode of the webservice.

 
 In Apache+mod_python I use apaches authentication and ssl. Simply works
 
here is my code sample:
wsdlFile = 'http://MYuser:[EMAIL PROTECTED]:8080/MYservices/MYservice?wsdl'
MYservice = WSDL.Proxy(wsdlFile)
print server.methods.keys()
# there is a method named searchAnything
resultat = MYservice.searchAnything(param_1, etc. ..., param_n)
while executing this call, SOAPpy does not send http authorization 
header line:
...
Authorization: Basic here is crypted form of MYuser:MYpass
...
and the call fails, with error code:


faultstringjava.util.MissingResourceException: Canapos;t find 
resource for bundle org.apache.axis.i18n.ProjectResourceBundle, key 
cantAuthorize/faultstring


So there is 2 phases:
1/Service acquisition
2/Methode call

and between them, user:pass is lost somewhere ...


thanks for any help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python create mail

2006-01-12 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
 hey I need help in sending email,
 
 It seems that while using  this set of commands
 
 from smtplib import SMTP
 
  s = SMTP()
  s.set_debuglevel(1)
  s.connect('outmail.huji.ac.il')
 
 I should be able to get a connection but what I get is this error
[snip]

Try connecting with telnet from the command line.

   telnet outmail.huji.ac.il 25

You should see some sort of greeting from the server, probably starting 
with 220.

If that works, then the Python code should work.  If that does not work, 
then it's not a Python problem (firewall, host rejecting your address, 
no SMTP server on that host, etc).

-Peter

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


Re: flatten a level one list

2006-01-12 Thread Robin Becker
Peter Otten wrote:
 Tim Hochberg wrote:
 
 
Here's one more that's quite fast using Psyco, but only average without
it.
 
  
 
def flatten6():
 n = min(len(xdata), len(ydata))
 result = [None] * (2*n)
 for i in xrange(n):
 result[2*i] = xdata[i]
 result[2*i+1] = ydata[i]
 
 
 I you require len(xdata) == len(ydata) there's an easy way to move the loop
 into C:
 
 def flatten7():
 n = len(xdata)
 assert len(ydata) == n
 result = [None] * (2*n)
 result[::2] = xdata
 result[1::2] = ydata
 return result
 
 $ python -m timeit 'from flatten import flatten6 as f' 'f()'
 1000 loops, best of 3: 847 usec per loop
 $ python -m timeit 'from flatten import flatten7 as f' 'f()'
 1 loops, best of 3: 43.9 usec per loop
 
 Peter

That's the winner for my machine and it works in the case I need :)

The numbers are microseconds/call

I used 20 reps and n from 10 up to 1000.

no psyco
  Name1020   100   200   500  1000
  flatten1   111.383   189.298   745.709  1397.300  3499.579  6628.775
  flatten2   142.923   209.496   907.182  1521.618  3565.397  7197.228
  flatten3   176.224   314.342  1385.958  2733.560  6726.693 12879.067
  flatten4   112.696   163.010   518.250   901.288  1979.749  3657.364
  flatten578.334   110.768   386.949   711.794  1617.664  3255.749
  flatten6   142.867   230.420   894.639  1767.012  4499.734  9017.906
flatten6a   163.093   263.330  1071.337  2084.287  5209.433 10383.610
flatten6b   180.582   275.761  1063.794  2074.705  5057.123 10043.567
flatten6c   167.898   253.664   974.202  1948.181  4821.339  9562.780
flatten6d   132.475   201.702   738.194  1406.659  3612.107  7242.038
  flatten759.03062.35490.347   130.771   254.613   438.994
  flatten888.978   173.737  1667.111  5674.297 28907.501 106330.749
flatten8a   107.388   225.951  2323.563  7088.136 34254.381 114538.384


psyco
  Name1020   100   200   500  1000
  flatten184.424   114.596   393.374   714.728  1809.448  3197.837
  flatten2   102.387   136.302   507.243   942.494  2276.770  4451.990
  flatten385.206   111.020   379.713   715.957  1607.104  3191.188
  flatten4   102.667   144.599   509.255   856.450  1839.591  3425.128
  flatten579.898   115.490   383.904   730.484  1739.411  3515.978
  flatten654.56061.293   183.012   332.109   837.146  1604.366
flatten6a79.647   108.114   405.107   752.917  1873.674  3824.620
flatten6b   111.746   132.978   473.189   907.378  2217.600  4257.357
flatten6c98.756   110.629   376.724   730.037  1772.963  3524.247
flatten6d59.25369.199   172.731   295.820   717.577  1402.720
  flatten751.29139.75465.707   104.902   233.214   405.694
  flatten887.050   166.837  1665.407  5410.576 28459.567 107847.422
flatten8a   122.753   251.457  2766.944  7931.204 36353.503 120773.674

###
from itertools import izip
import timeit

_R=100

def flatten1(x, y):
 '''D Murman'''
 return [i for pair in izip(x, y) for i in pair]

def flatten2(x, y):
 '''D Murman'''
 return [i for pair in zip(x, y) for i in pair]

def flatten3(x, y):
 '''D Murman'''
 res = []
 for pair in izip(x, y):
 for i in pair:
 res.append(i)
 return res

# New attempts:
from itertools import imap
def flatten4(x, y):
 '''D Murman'''
 l = []
 list(imap(l.extend, izip(x, y)))
 return l


from Tkinter import _flatten
def flatten5(x, y):
 '''D Murman'''
 return list(_flatten(zip(x, y)))

def flatten6(x,y):
 '''Tim Hochberg'''
 n = min(len(x), len(y))
 result = [None] * (2*n)
 for i in xrange(n):
 result[2*i] = xdata[i]
 result[2*i+1] = ydata[i]
 return result

def flatten6a(x,y):
 '''Robin Becker variant of 6'''
 n = min(len(x), len(y))
 result = [None] * (2*n)
 for i in xrange(n):
 result[2*i:2*i+2] = xdata[i],ydata[i]
 return result

def flatten6b(x,y):
 '''Robin Becker variant of 6'''
 n = min(len(x), len(y))
 result = [None] * (2*n)
 for i,pair in enumerate(zip(xdata,ydata)):
 result[2*i:2*i+2] = pair
 return result

def flatten6c(x,y):
 '''Robin Becker variant of 6'''
 n = min(len(x), len(y))
 result = [None] * (2*n)
 for i,pair in enumerate(izip(xdata,ydata)):
 result[2*i:2*i+2] = pair
 return result

def flatten6d(x,y):
 '''Robin Becker variant of 6'''
 n = min(len(x), len(y))
 result = [None] * (2*n)
 j = 0
 for i in xrange(n):
 result[j] = xdata[i]
 result[j+1] = ydata[i]
 j+=2
 return result

from operator import add as operator_add
def flatten8(x,y):
 '''Paul Rubin'''
 return reduce(operator_add,zip(x,y),())

def flatten8a(x,y):
 '''Robin Becker variant of 8'''
 return reduce(operator_add,(xy for xy in izip(x,y)),())

def flatten7(x,y):
 '''Peter Otten 

jython base64.urlsafe_b64xxx

2006-01-12 Thread py
anyone know how to do perform the equivalent base64.urlsafe_b64encode
and base64.urlsafe_b64decode functions that Python has but in jython?
Jython comes with a base64 module but it does not have the urlsafe
functions.  Tried copying the pythhon base64.py to replace the Jython
one, and although it did perform the encode/decode it didnt seem to be
correctly decoded.


thanks

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


Re: Help me in this please--is Python the answer?

2006-01-12 Thread Ray

Tim N. van der Leeuw wrote:
 Hi Ray,

Hi Tim!

 I'm in a bit of the same boat as you only I don't get to choose my
 implementation language ;-)

 Some of the concerns should be:
 - Do you have to interface with things like messaging-systems (a la JMS
 specs), distributed transaction managers? If so, the only way to go
 Python is Jython: Python for the JVM. Because AFAIK, there are no
 interfaces for Python to the likes of IBM's MQSeries or for any
 distributed transaction managers.

Hmmm, at this level I think not. But yes, this is a good point, I'll
keep this in mind. If it's gonna be Jython, I think I might as well go
with J2EE--since it is yet another layer on top of a platform.

 - Is your application purely a web-based application? Or is there a
 large amount of application logic which is not tied to the web in any
 way?

Yes, it is purely a web-based application... well, it has a
administration page, that the back office stuff, but that can be
web-based as well.

 - Python has a number of frameworks for developing server applications,
 like Twisted, Zope and Django.
 I don't know Twisted; I know a little bit about Zope. Zope has several
 enterprise-level features and provides scalability/clustering.
 However, I've found the learning-curve for Zope to be a bit steep so
 far; too steep to master it in what little bits of spare time I have.
 (If I would have more time I'd be able to get the hang of it but I
 don't have enough time)

Ah, yes... all respect to Zope, but I hope this is something that can
be done in Django. I suspect the implementation time will be very, very
short... as typical of the nature of these projects, and with the
seeming intricacies of Zope, the impression of which I get from reading
about it, I don't think we have the spare time/effort...

 I've started to toy a bit with Django and it seems to get rather easy
 to get started with developing a Web application using Django; however
 I also get the feeling that installation is a bit more involved than
 with Zope and that it will be not as easy to package up an application
 and transport it to another machine, as it is with Zope.

Thanks, this is a useful info. I'm about to evaluate Django deeper
myself, how have you found it? Does it cover the whole web part of
the J2EE stack, at least? (i.e.: it can replace Tomcat)? How has your
experience been when you need to go further? (i.e.: beyond mapping data
in DB to webpages)?

 So for development of Web-applications, I would certainly consider
 either Zope or Django.
 Both offer ways to store your data in a transactional database; Django
 has some object-relation mapper tools but I'm not sure how exactly Zope
 stores data in a SQL database (it comes with it's own powerful
 object-database, the ZODB but I don't know if OR mapping tools exist
 for Zope).

Hmm, I've never got the time to look at Zope proper, but my
understanding is that Django is analogous to Tomcat, and Zope is
analogous to a full blown appserver a la WebLogic, right?

 So what are your requirements for 'J2EE' applications? And which Python
 framework would best fit the bill?

Hmmm, it's purely web-based, and I don't foresee message queueing and
stuff at this point. I'll take a better look at Django.

Thanks!
Ray

 
 
 cheers,
 
 --Tim

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


Re: Python on WinXP Embedded

2006-01-12 Thread [EMAIL PROTECTED]
Godzilla wrote:
 Hello rtilley,

 thanks for replying so soon. I wish to install WinXP Embedded on a
 PC/104 module and install Python on WinXP Embedded, not WinPE... The
 hardware which is to be acquired is about a celeron 400MHz but we just
 not sure how well Python will work under WinXPE...

Whoops. Sorry... there are too many Windows acronyms around ;). I've
never used Python in this type of environment, but I'm sure someone out
there has.

I found this from a 2001 archive:

Grant Edwards wrote:

 In article [EMAIL PROTECTED], Peter Hansen wrote:
 Actually, Python can be suitable for real-time embedded
 software, as well.

 I suppose it depends on the system resources and requirements.
 The vast majority of embedded systems don't have the resources
 required to run Python -- even the deeply embedded version
 without the compiler.

Quite true.  That's why I said can be suitable, not is.

We have Python running on a 1MB Flash/1MB RAM PC/104 module.
With the compiler.  Quite cool.  I know from posts here that
at least one other company has achieved something similar.
I'm still pleased to find how well many of Python's advantages
translate through into the embedded world.  This is, of course,
an extremely long way from a 16-bit chip with a 64K address
space, but for that there's always FORTH. :-)

Read it all here:
http://mail.python.org/pipermail/python-list/2001-January/026394.html

Best of luck!!!

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


help on eval()-like but return module object

2006-01-12 Thread Dody Suria Wijaya
As I'm adding XMLRPC support in my apps, I'd like to send a module in 
server to be executed in client. My plan in sending the file content via 
xmlrpc, and doing compile + eval, but eval just execute the code object 
without returning the module.

Original:

import mymodule
mymodule.run(request)

Wish:

string_code = rpc_con.GetModule('mymodule')
code_obj = compile(string_code, 'string', 'exec')
mymodule = eval(code_obj)
mymodule.run(request)

Any helps on this topic would be highly appreciated. Thanks!

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


Re: flatten a level one list

2006-01-12 Thread David Murmann
Robin Becker schrieb:
 # New attempts:
 from itertools import imap
 def flatten4(x, y):
 '''D Murman'''
 l = []
 list(imap(l.extend, izip(x, y)))
 return l
 
 
 from Tkinter import _flatten
 def flatten5(x, y):
 '''D Murman'''
 return list(_flatten(zip(x, y)))

well, i would really like to take credit for these, but they're
not mine ;) (credit goes to Michael Spencer). i especially like
flatten4, even if its not as fast as the phenomenally faster
flatten7.


--
David Murmann (NN!) ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Steve Holden
Paul Rubin wrote:
 [EMAIL PROTECTED] writes:
 
Still, I'd love to hear how you guys would do it.
 
 
 Make a subclass of dict, or an object containing a dictionary, that
 has a special __setattr__ method that traps updates and sets that

/__setattr__/__setitem__/ ?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Can't compile

2006-01-12 Thread Layne Meier
I am having a problem trying to get Python 2.4.2 to compile on my Sun 
Solaris 10 system.  I've even tried adding CC=gcc to the configure file 
or even tried running the command ./configure --with-gcc

This is what is happening:

MAILBOT:root:8:Python-2.4.2:# ./configure
checking MACHDEP... sunos5
checking EXTRAPLATDIR...
checking for --without-gcc... no
checking for --with-cxx=compiler... no
checking for c++... c++
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... configure: error: cannot run 
C++ compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.


Any and all help would be greatly appreciated.

Thank you,
Layne Meier
Atlanta, GA

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


Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes:
  Make a subclass of dict, or an object containing a dictionary, that
  has a special __setattr__ method that traps updates and sets that
 
 /__setattr__/__setitem__/ ?

Yes, thinkographical error.  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Timeout at command prompt

2006-01-12 Thread Thierry Lam
Which Python version are you using? I'm getting the following error
with Python 2.3.4:

Traceback (most recent call last):
  File C:\home\pciroot\vcur\sdk\tools\inter.py, line 32, in ?
signal.signal(signal.SIGALRM, input)
AttributeError: 'module' object has no attribute 'SIGALRM'


Thierry

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


Re: Timeout at command prompt

2006-01-12 Thread Thierry Lam
Is there a windows equivalent for that solution?

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


Re: ANN: Python training, 2006 Feb 1-3, San Francisco

2006-01-12 Thread jim
On Wed, 11 Jan 2006, w chun wrote:
...
 as promised, this is the FINAL reminder i'll send out about our
 upcoming Python course at the beginning of February.

Is it too much to ask that you refrain altogether from using these lists 
for advertising, with the possible exception of the local one?

 it'll be at a hotel with BART and CalTrain access (San Bruno
 stations) for those already in the Bay Area, and for those coming in
 from out-of-town, there's a free shuttle directly from the San
 Francisco airport, which is only about 2-3 miles away.

 discounts available for multiple registrants as well as students,
 teachers, and those with financial hardship.  also, there is a

[snip]
 Note: i will only send out ONE MORE REMINDER in January... yeah, i
 don't like spam either. :-)

but this is a special occasion?


 cheers,
 -- wesley
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Core Python Programming, Prentice Hall, (c)2006,2001
 http://corepython.com

 wesley.j.chun :: wescpy-at-gmail.com
 cyberweb.consulting : silicon valley, ca
 http://cyberwebconsulting.com
 -- 
 http://mail.python.org/mailman/listinfo/python-announce-list

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


[EMAIL PROTECTED]
SDF-EU Public Access UNIX System - http://sdf-eu.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Extending Embedding Python

2006-01-12 Thread Marco Meoni
Hi all! I've a problem with a C++ class that has to be included in a
python application. One way to do it is Extending and Embedding the
Python Interpreter
Now i have 2 questions
1) Is there a one-file version of this tutorial?
2) Is there anyone that can help me with this problem? The class is
attached.

Thanks all.
Marco

Attached files:
--
#ifndef _PACKETMANAGER_H_
#define _PACKETMANAGER_H_
#include Cipher/Cipher.h

#define PAYLOAD_LENGHT 5000

//the our defined packe over the UDP datagram
struct packet {
int lenght; // sizeof(payload) = sizeof(int) + strlen(payload)
unsigned char payload[PAYLOAD_LENGHT]; // the xml string
} __attribute__ ((packed));


//! manage the send and receive of udp packet
/*! by default: send message non-cripted */
class PacketManager
{
private:
struct packet packet_to_send;
Cipher * pc;
int s;  //socket descriptor
public:
PacketManager();
virtual ~PacketManager();

///Network member function
bool send(char * IPdest , int port_to);
unsigned char * receive (char * IPdest, int timeout);  
//non-blocking
unsigned char * waitMessage(char * IPfrom); //blocking

///Packet Builder member function
bool build_Packet();
bool setCipher(Cipher * c);
Cipher * getCipher();

///Set and Get function on all attributes

bool set_Payload(unsigned char * c, int lenght);
unsigned char  * get_Payload();

bool set_packet_lenght(unsigned int lenght);
unsigned int get_packet_lenght();

void set_Socket(int socket);
int get_Socket();
bool buildPacket();
void setSocket(int socket);
packet getPacket();
bool setPacket(unsigned char * c,int lenght);
void closeSocket();
};

#endif //_PACKETMANAGER_H_
---
#include Cipher/Cipher.h
#include Cipher/NullCipher.h

#include PacketManager.h

#include messages.h

#define PORT_FROM 40004

//! manage the send and receive of udp packet
/*! by default: send message non-cripted */
PacketManager::PacketManager()
{

pc =  new NullCipher();

s = create_UDP_socket(PORT_FROM);

}

PacketManager::~PacketManager()
{
close (s);
delete pc;
}

void PacketManager::setSocket(int socket)
{
s = socket;
}

bool PacketManager::buildPacket()
{
pc-encrypt();  
//! ciphering
return true;

}

Cipher * PacketManager::getCipher()
{
return pc;
}

bool PacketManager::setCipher(Cipher * c)
{
pc=c;
return true;
}

//! send payload + header to IPdest at port_to
/*! send payload + header in an UDP packet
\param IPdest address to witch send the packet
\param port_to port to witch send the packet
 */
bool PacketManager::send(char *IPdest,int port_to)

{


//unsigned char * message_to_send = new unsigned
char(packet_to_send.lenght * sizeof(unsigned char));
unsigned char message_to_send[5000];

 memcpy (message_to_send, (packet_to_send.lenght) ,
sizeof(int));

 unsigned char * tmp_payload = message_to_send;
 tmp_payload+=sizeof(int);

memcpy(tmp_payload,packet_to_send.payload,strlen((char*)packet_to_send.payload));

  // memcpy (message_to_send + sizeof(int), packet_to_send.payload,
packet_to_send.lenght - sizeof(int));//! mess =
[int][payload]



//memcpy (message_to_send, packet_to_send ,sizeof (struct
packet));   //! mess = [packet_to_send]

 packet_to_send.payload[packet_to_send.lenght-4]='\0';

 printf (Sto per inviare:  \nlenght = \t%d \nPayload = \t%s\n,
packet_to_send.lenght , packet_to_send.payload);

message_to(s,port_to,IPdest, message_to_send , packet_to_send.lenght
);

//delete message_to_send;

//return 0;

return true;
}

//! wait for a packet, non blocking, don't check for IP
/*! wait for a packet, non blocking, don't check for IP
 * param IPdest should be the IP from witch receive files
 * param timeout should be the seconds to wait until a message was
received
 */
unsigned char * PacketManager::receive(char *IPdest, int timeout)
{
info risposta;
risposta  = wait_message(s);

//!have to check if the message return from 
IPdest
return risposta.message;

}

//! wait for a packet from IPfrom, blocking
/*! wait for a packet 

Re: Extending Embedding Python

2006-01-12 Thread David Murmann
Marco Meoni schrieb:
 Hi all! I've a problem with a C++ class that has to be included in a
 python application. One way to do it is Extending and Embedding the
 Python Interpreter
 Now i have 2 questions
 1) Is there a one-file version of this tutorial?

i'm not sure what tutorial you mean. are you talking about the
Extending and Embedding section of the python manual?

  http://docs.python.org/ext/ext.html

 2) Is there anyone that can help me with this problem? The class is
 attached.

i haven't read your code, but you might want to take a look at SWIG:

  http://www.swig.org/

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


Re: Extending Embedding Python

2006-01-12 Thread Marco Meoni
 i'm not sure what tutorial you mean. are you talking about the
 Extending and Embedding section of the python manual?

  http://docs.python.org/ext/ext.html

Yes, this section. Is there in one-file version? (pdf, ps, dvi, all in
1 html, etc...)

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


Re: batch tiff to jpeg conversion script

2006-01-12 Thread [EMAIL PROTECTED]
Just curious... is PhotoShop _really_ recursive? We have dozens of
levels of sub-folders where the pics have been sorted and thousands of
pics. That's one reason I used os.walk()

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


Re: how to improve this simple block of code

2006-01-12 Thread Tim Williams (gmail)
On 11/01/06, Mike Meyer [EMAIL PROTECTED] wrote:
py [EMAIL PROTECTED] writes: Say I have... x = 132.00 but I'd like to display it to be 132 ...dropping the trailing
 zeros...I currently try this
Is it likely that x might not have any decimal
places? If so all the above solutions fail when x
=130 except Matt Hammond's offering which splits x at the decimal point
if one exists.

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

Embedding Python: Creating Python Class from Application

2006-01-12 Thread Kakacek
Hello All,

Let's say I have a following python code:

class hw_class:
   def __init__(self):
   pass
   def hello_world(self):
   print 'Hello World!'
create_instance('hw_class', 'hw')
hw.hello_world()
hw = None

The 'create_instance' function should be implemented in the application
(powered by Delphi - P4D) which is embedding the Python.dll.

I am trying to do this for some time having no success. I am missing
these informations:
1. How to register global python variable from application which is
embedding python?
2. How to assign this variable with the class instance.
3. How to create the instance of class which is unknown at the compile
time.

Could someone supply the (C/Pascal) code fragment for this?

Thanx,

Jiri.

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


Re: Why keep identity-based equality comparison?

2006-01-12 Thread Antoon Pardon
Op 2006-01-12, Paul Rubin schreef http:
 Antoon Pardon [EMAIL PROTECTED] writes:
 The bisect module doesn't have an alternate comparison function
 neither has the heapqueue module.

 They could be extended.  Care to enter a feature request?

Not really because IMO this is the wrong approach.

 1) Python could provide a seperare total ordering, maybe with operators
like '|' and '|' and function operator.rank (with functionlity
similar to cmp)

 Based on experience that I'm sure you understand, anything like that
 is going to be awfully hard to sell.

 3) Python could provide the possibility of providing an alternate
comparison function with heapqueue, bisect and similar modules.

 That's probably the best bet.

But IMO not very helpfull. When I use a heapqueue I need to use
it with the same comparison function through its whole lifetime.
It doesn't make sense to work with a heapqueue that has a variable
comparison function. So having to provide this comparison function
with each operation strikes me as much to cumbersome and error prone.
Especially if you are working with multiple heaps each with its
own comparison function.

Writing my own heapqueue class that takes a comparison function as
a parameter to the __init__ method to associate with that particular
heapqueue seems a more rational solution than extending (or letting
others do so) the stdlib packages with such a parameter.

IMO letting python associate such a function with an arbitrary container
is the most usefull option. It would allow the programmer to easily define
what they need.

Do you only care about identity, provide a comparison function that
works on identy.

Do you want lst.index(1) to return the index of 1.0 and decimal(1)
or not. You would be able to specify this just how you want by
just associating a new comparison function with the container.

Now off course I could write a subclass of list which would do
all this, but that would mean writing a lot of the functionality
that is basically already there.

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


ajax python module??

2006-01-12 Thread Mark Engstrom
Does anyone have a recommendation on the best AJAX python module?


Thanks,

Mark 


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


Re: Reading from input file.

2006-01-12 Thread Mike Meyer
Sheldon [EMAIL PROTECTED] writes:
 after you have read the file then split it like this:
 file = open('inputfile.txt', 'r').read()
 import string
 file = string.split(file,'\n')

You're doing things the hard way - at least if you have a modern
Python. The above can be done as:

file = open('inputfile.txt', 'r').read().split('\n')

Or even better

file = open('inputfile.txt', 'r').readlines()

will all give you the same result.

BTW, it's a bad habit to leave open files laying around. It's also a
bad habit to use the name of builtins (like file) as variable names.

 now if you print file[0] you should only get the first line.
 Be careful and examine the file for non-continuous sections where a
 line is empty. That is to say where file[x] = ' '. You should remove
 these lines from the txt files before you read it with python. It maybe
 so that python reads the entire file, empty spaces and all, and then
 you have to remove them after the split with a WHERE statement. This is
 a much easier way so lets hope that this is so.

Huh? What in the OP makes you think this is even necesary?

 mike
-- 
Mike Meyer [EMAIL PROTECTED]  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: Extending Embedding Python

2006-01-12 Thread Marco Meoni
About SWIG:
This program has a lot of commands...
In your opinion what is the best settings for my use?
Thanks...
Marco

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


Re: ajax python module??

2006-01-12 Thread ookoi
Hi Mark,

Basically, all you needs is the CGI module to handle requests from
clients, print some xml or html in response, then handle them back in
your client code (javascript).

With these simple principles I made a small web apps to watch Apache
Logs, see: https://live.dbzteam.com/

If you want to read a comprehensible example or use a simple module,
look at the sajax module http://www.modernmethod.com/sajax/

Cheers,

Sébastien Martini

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


RE: Timeout at command prompt

2006-01-12 Thread Tim Golden
[Thierry Lam]

[to do with a Win32 equivalent to the SIGALRM
interruption of a raw_input]

| Is there a windows equivalent for that solution?

Nothing so straightforward. Depends how hard you want 
to try. A couple of past threads on pretty much the 
exact same issue offer no equivalent solution. 

Any solution which I can come with involves some
sort of getch loop with more-or-less manual timeout.
Haven't examined the source for raw_input code, but
I bet it calls the underlying c-lib get-a-string routine
which probably doesn't allow for any interrupts.

Something like the following (crude but workable):

code
import msvcrt
import time

TIMEOUT_SECS = 5.0

line = 
print Prompt ,
t0 = time.time ()
try:

  while True:
if time.time () - t0  TIMEOUT_SECS:
  raise KeyboardInterrupt
  
if msvcrt.kbhit ():
  k = msvcrt.getch ()
  if k == \r:
break
  
  msvcrt.putch (k)
  line += k

except KeyboardInterrupt:
  print
  print Interrupted
else:
  print
  print String was:, line

/code

TJG


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

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


Re: Timeout at command prompt

2006-01-12 Thread Amit Khemka
its Python 2.4.1 .. on linux

On 12 Jan 2006 06:34:08 -0800, Thierry Lam [EMAIL PROTECTED] wrote:
 Is there a windows equivalent for that solution?

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



--

Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spelling mistakes!

2006-01-12 Thread skip

Antoon But now we are back to my first doubt. Sure unit test will be
Antoon helpfull in finding out there is a bug. I doubt they are that
Antoon helpfull in tracking the bug (at least this kind).

This thread seems to be going in circles.  Maybe it's time to simply drop it
and move onto other things.  The clear evidence from people who admit to
having practical experience using unit tests (or pylint or pychecker) is
that catching misspellings is an extremely shallow bug to find and fix if
you use the tools at your disposal.

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


Re: Indentation/whitespace

2006-01-12 Thread Dave Hansen
On Thu, 12 Jan 2006 11:56:05 +0800 in comp.lang.python, Jon Perez
[EMAIL PROTECTED] wrote:

[...]

Although the below does work, I believe:

Verified example:

 def check_indent(n):
if n==4:
print You like four spaces
elif n==3:
   print I like three
elif n==2:
  print Others like two
else:
print But don't mix TABs and spaces!


 for n in range(4,0,-1):
check_indent(n)


You like four spaces
I like three
Others like two
But don't mix TABs and spaces!
 

Regards,
-=Dave

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


Re: flatten a level one list

2006-01-12 Thread Nick Craig-Wood
Sion Arrowsmith [EMAIL PROTECTED] wrote:
  sum(...)
  sum(sequence, start=0) - value
 
  If you're using sum() as a 1-level flatten you need to give it
  start=[].

Except if you are trying to sum arrays of strings...

   sum([a,b,c], )
  Traceback (most recent call last):
File stdin, line 1, in ?
  TypeError: sum() can't sum strings [use ''.join(seq) instead]
   

I've no idea why this limitation is here... perhaps it is because pre
python2.4 calling += on strings was very slow?

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Template language with XPath support for source code generation?

2006-01-12 Thread Stefan Behnel
Hi!

I need to generate source code (mainly Java) from a domain specific XML
language, preferably from within a Python environment (since that's where the
XML is generated).

I tried using XSLT, but I found that I need a template system that supports
Python interaction. I know, lxml's XSLT support is /somewhat/ getting there,
but even with that, XSLT is so clumsy when it comes to code generation
(looping constructs and if/else above all), that it would take me tons of XSLT
code to write what I want.

I've been looking through Python templating systems all over the place, but I
just can't find one that supports XPath - which is by far the best thing to
have when you generate stuff from XML. TAL might be able to get me part of the
way (at least, it supports some kind of Path expressions, though only for
object access), but the only available implementation is part of Zope and I
can't make my code depend on Zope only for a template system.

My problem is that I want to write as little Python code as possible to make
the templates (almost) stand alone and thus readable without the backend code.
I can transform the XML language to a more usable XML format beforehand, no
problem, but I then need to access the result from the template - and that's
almost impossible without XPath.

Does anyone have an idea what I could use? Any hints are helpful.

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


Re: Why keep identity-based equality comparison?

2006-01-12 Thread Mike Meyer
Antoon Pardon [EMAIL PROTECTED] writes:
 Op 2006-01-11, Mike Meyer schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:
 Op 2006-01-11, Mike Meyer schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:
 Op 2006-01-10, Mike Meyer schreef [EMAIL PROTECTED]:
 Now you can take the practical option and decide that programmatically
 it make no sense to compare a specific couple of values and throw an
 exception in this case, but it doesn't matter much which test you are
 conducting at that point.
 Can you provide a case where having a test for equality throw an
 exception is actually useful?
 I'm not going to bother with that.
 Since you're being vague about what you want,
 I would like some consistency. Either all comparisons between objects
 of different types throw an exception by default or none does.
 That's a very silly thing to ask for. It presumes that all types are
 the same. They aren't.
 It doesn't presume anything like that.

Yes it does. It presumes that all operators of all types either always
make sense, or there are always situations where they don't

 It also presumes that all comparisons are the same. They aren't.
 It doesn't presume that either.

Yes it does. It presumes that all operators either always make sesne,
or there are always situations where they don't.

 To use an overworked analogy, you might as well ask
 that you either have to peel all fruit, or that you never have to peel
 a fruit.
 Bad analogy since a fruit is not a relationship.

I suggest you look up the meaning of the word analogy.

 In any case, the proposeed behavior *is* consistent. The behavior for
 all builtin types will be that comparisons that don't make sense will
 throw exceptions.
 It is only consistent if you start from an inconsistent view and then
 check for how consistently this view is followed. There is nothing
 consistent in telling that 1 == (1,3) makes sense and 1  (1,3)
 doesn't make sense. Set theoretically both 1 and (1,3) are sets.

Of course there are types for which the given behaviors don't make
sense.  However, we're not talking about user-defined relations on
user-defined types with syntax that isn't supported by the
language. We're talking about the builtin relationships defined on the
builtin types.

 There is a use case for things like 1  (1,3) making sense and denoting
 a total order. When you have a hetergenous list, having a total order
 makes it possible to sort the list which will make it easier to
 weed out duplicates. So why don't you demand a use case for the
 new behaviour to counter this use case?

Yes, there is. And you are perfectly free to implement a type that
behaves that way if you want to. I don't need a use case to counter
this one; I just need to show that this use case can be reasonably
covered by the proposed mechanism.

 IMO it would be better if it was possible to associate some kind
 of order function with the container. Because the order most usefull
 for comparing between two instances doesn't need to be the most usefull
 order in finding an element from a container.

No, it wouldn't. Order relationships are a property of the type, not
the container. The order relationships are right where they belong -
attached to the type. That notwithstanding, it's often practical to be
able to override the order function for some specific method (and
would be even if the order function were associated with the container
instead of the type), so some of the methods that use order allow you
to provide a function to use for them. If you really want a container
type that has an order function associated with it, you can write
one. If you want it made part of the language, you'll have to provide
a use case.

 I could impose a total order on sets, so that I can use a bisection
 algorithm on a container of them, but such an order is in general
 less usefull than the superset ordering when you are manipulating
 sets.

And you're free to implement a subclass of sets that does that. If you
want to argue that the builtin sets should do that, you can - but
that's unrelated to the question of how the comparison operators
behave for the rest of the bulitin types. At least, it doesn't matter
unless you try and force all the types and operators to be the same.

 Since we're talking about Py3K here, there is no
 default behavior. User-defined classes all inherit from builtin
 types, and will get the behavior of their comparison operators from
 those types. In particular, those that inherit from object will get
 objects behavior, which means they'll get equality as identity.
 But if this makes any behaviour defined on objects consistent by
 definition, because the only criteria you seem to have for consistency
 is the inherited behaviour from object. If object would use a
 random function to decide that would be consistent too, because it
 would be the behaviour inherited by other classes. I don't find this
 a usefull way to measure consistency.

But you can use a random 

Asking for help effectively

2006-01-12 Thread skip

Manish It does not work. I had already tried this earlier.
Manish Please suggest some other solutions.
Manish Also, I would like to see the stack from where the exception
Manish started.

Manish,

You made it extremely difficult for anyone to respond intelligently to your
message.  It has at least the following problems:

1. The subject isn't related to the problem you are trying to solve.
   Many people won't go beyond that.

2. You quoted an entire python-list digest.  Which digest message were
   you responding to?  If I was going to try and help directly with the
   problem you are having (instead of trying to get you to ask for help
   more effectively), I'd have to read the entire digest and try to
   figure out which messages are pertinent.

3. You top-posted, and worse, because of #2, your comment is nowhere near
   the actual message text you were responding to, making it that much
   more difficult to identify your problem.

Read this essay:

http://www.catb.org/~esr/faqs/smart-questions.html

then try again.

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


Re: Failing unittest Test cases

2006-01-12 Thread Scott David Daniels
Duncan Booth wrote:
 ... Possible enhancements:

 add another argument for associated issue tracker id ... some unbroken tests 
  will also have associated issues this might just be a separate decorator.

This is probably easier to do as a separate decoration which would have to
precede the failing test decoration:
 def tracker(identifier):
 def markup(function):
 function.tracker = identifier
 return function
 return markup

 add some easyish way to generate a report of broken tests.

Here's a generator for all the marked broken tests in a module:

 import types, unittest

 def marked_broken(module):
 for class_name in dir(module):
 class_ = getattr(module, class_name)
 if (isinstance(class_, (type, types.ClassType)) and
issubclass(class_, unittest.TestCase)):
 for test_name in dir(class_):
 if test_name.startswith('test'):
 test = getattr(class_, test_name)
 if (hasattr(test, '__name__') and
  test.__name__.startswith('XXX_')):
 yield class_name, test_name, test.todo


You could even use it like this:

 import sys
 import mytests

 for module_name, module in sys.modules.iteritems():
 last_class = ''
 for class_name, test_name, reason in marked_broken(module):
 if module_name:
 print 'In module %s:' % module_name
 module_name = ''
 if last_class != class_name:
 print 'class', class_name
 last_class = class_name
 print '  %s\t %s' % (test_name, reason)


Thanks for the thoughtful feedback.

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


Re: Timeout at command prompt

2006-01-12 Thread Amit Khemka
I tried it on Python 2.4.1 on '2.6.11-1.1369_FC4smp with gcc version
4.0.0' .. which works fine .. may be it could be an issue with some
other combinations ..

cheers,
amit

On 12 Jan 2006 07:35:57 -0800, Paul Rubin
http://phr.cx@nospam.invalid wrote:
 Amit Khemka [EMAIL PROTECTED] writes:
  import signal
  TIMEOUT = 5 # number of seconds your want for timeout
  signal.signal(signal.SIGALRM, input)
  signal.alarm(TIMEOUT)
 
  def input():
   try:
 foo = raw_input()
 return foo
  except:
# timeout
return

 This doesn't work with raw_input under linux, maybe because the
 readline lib is snagging the timer interrupt or something.  Use
 sys.stdin.readline instead.  SF bug:

 http://sourceforge.net/tracker/index.php?func=detailaid=685846group_id=5470atid=105470
 --
 http://mail.python.org/mailman/listinfo/python-list



--

Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Timeout at command prompt

2006-01-12 Thread Paul Rubin
Amit Khemka [EMAIL PROTECTED] writes:
 import signal
 TIMEOUT = 5 # number of seconds your want for timeout
 signal.signal(signal.SIGALRM, input)
 signal.alarm(TIMEOUT)
 
 def input():
  try:
foo = raw_input()
return foo
 except:
   # timeout
   return

This doesn't work with raw_input under linux, maybe because the
readline lib is snagging the timer interrupt or something.  Use
sys.stdin.readline instead.  SF bug:

http://sourceforge.net/tracker/index.php?func=detailaid=685846group_id=5470atid=105470
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Template language with XPath support for source code generation?

2006-01-12 Thread bruno at modulix
Stefan Behnel wrote:
 Hi!
 
 I need to generate source code (mainly Java) from a domain specific XML
 language, preferably from within a Python environment (since that's where the
 XML is generated).
 
 I tried using XSLT, but I found that I need a template system that supports
 Python interaction. I know, lxml's XSLT support is /somewhat/ getting there,
 but even with that, XSLT is so clumsy when it comes to code generation
 (looping constructs and if/else above all), that it would take me tons of XSLT
 code to write what I want.
 
 I've been looking through Python templating systems all over the place, but I
 just can't find one that supports XPath - which is by far the best thing to
 have when you generate stuff from XML. TAL might be able to get me part of the
 way (at least, it supports some kind of Path expressions, though only for
 object access), but the only available implementation is part of Zope and I
 can't make my code depend on Zope only for a template system.

Zope's implementation can be used freestanding AFAIK. There's also
SimpleTal that is totally independant from Zope.


 My problem is that I want to write as little Python code as possible to make
 the templates (almost) stand alone and thus readable without the backend code.
 I can transform the XML language to a more usable XML format beforehand, no
 problem, but I then need to access the result from the template - and that's
 almost impossible without XPath.
 
 Does anyone have an idea what I could use? Any hints are helpful.

Perhaps a TAL + elementTree combo could do ? (first parse the source XML
with elementTree, then pass the resulting tree as the context of the
ZPT/SimpleTal template)

My 2 cents


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


Re: exec a string in an embedded environment

2006-01-12 Thread Greg Copeland
I would be happy to share my point with you.  In fact, I'm fixing a
minor memory leak (socket module; vxWorks specific) in Python 2.3.4
(ported version) today.  My port is actually on BE XScale.

Email me at g t copeland2002@@ya hoo...com and I'll be happy to talk
more with you.

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


Re: ajax python module??

2006-01-12 Thread Diez B. Roggisch
Mark Engstrom wrote:

 Does anyone have a recommendation on the best AJAX python module?

If it is the best is obviously an arguable assertion - but I very much like
MochiKit from Bob Ippolito.

http://www.mochikit.org/

Enyoy!

Regards,

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


Re: - E04 - Leadership! Google, Guido van Rossum, PSF

2006-01-12 Thread Dave Hansen
On 11 Jan 2006 21:30:11 -0800 in comp.lang.python,
[EMAIL PROTECTED] (Aahz) wrote:

[..]

Side note: I don't have a degree, and I interviewed at Google several
years ago.  I'm about 97% certain that my lack of degree played little
role (if any) in my failure to get a job offer.

Side note: I have a couple degrees, and I sent in solutions to those
tests Google published in Dr. Dobbs a year or so back, but I never
heard back from them.

Not that I expected to.  I just did it for fun.  I'm not sure what
Google would do with someone whose entire work experience has been
developing C code for small embedded controllers anyway.  I use Python
mostly to write small utility scripts for myself.

And, FWIW, I don't think I could convince my wife (or myself) to move
to CullyFORNya for any amount of money, whether there was a massage
therapist on duty or not...

Regards,
-=Dave

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


Re: Help me in this please--is Python the answer?

2006-01-12 Thread bruno at modulix
Ray wrote:

(snip)
 But then on the other hand, there is a manpower problem--it's damn easy
 to find a Java programmer (although the quality that you get is a
 different matter). Python programmers are more difficult.

Possibly - but if a programmer is not able to pick on Python in a matter
of days, then it's a bad programmer that won't be of any help whatever
the language. So in fact, choosing Python may help you get better
programmers !-)

 
If I were you I'd concentrate on creating a website that actually
works.  Your chances of creating a website that needs to scale to be
'heavyweight' are very slim.  If you manage to get to that point then
you can start worrying about how to cope with all the money that's
rolling in ;)
 
 
 You know what, this is a very good point :))
 
 
AFAIAA Python scales better than Java as any performance critical
parts can be easily rewritten in C.  To spend too much time worrying
over it is premature optimisation though.
 
 
 Yes, but this is more of a web application though--something that I've
 never developed in Python before, so... I'll be evaluating Django
 shortly--let me see how it compares to Tomcat.

You may also want to have a look at turbogears (roughly similar to
Django, but probably much more flexible)

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


Re: Timeout at command prompt

2006-01-12 Thread Amit Khemka
Another thing that can be tried is:

import threading
a=
def input():
global a
a = raw_input()
T = threading.Thread(target=input)
T.start()
T.join(2)  ## does the trick
 ...

I have not tested it but i guess should work.

cheers,
amit.

On 1/12/06, Amit Khemka [EMAIL PROTECTED] wrote:
 I tried it on Python 2.4.1 on '2.6.11-1.1369_FC4smp with gcc version
 4.0.0' .. which works fine .. may be it could be an issue with some
 other combinations ..

 cheers,
 amit

 On 12 Jan 2006 07:35:57 -0800, Paul Rubin
 http://phr.cx@nospam.invalid wrote:
  Amit Khemka [EMAIL PROTECTED] writes:
   import signal
   TIMEOUT = 5 # number of seconds your want for timeout
   signal.signal(signal.SIGALRM, input)
   signal.alarm(TIMEOUT)
  
   def input():
try:
  foo = raw_input()
  return foo
   except:
 # timeout
 return
 
  This doesn't work with raw_input under linux, maybe because the
  readline lib is snagging the timer interrupt or something.  Use
  sys.stdin.readline instead.  SF bug:
 
  http://sourceforge.net/tracker/index.php?func=detailaid=685846group_id=5470atid=105470
  --
  http://mail.python.org/mailman/listinfo/python-list
 


 --
 
 Endless the world's turn, endless the sun's spinning
 Endless the quest;
 I turn again, back to my own beginning,
 And here, find rest.



--

Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >