ANN pyfs: python shell+ftp for PC, Nokia and XBOX

2006-12-16 Thread Michele Andreoli
Pyfs is a (sort of) python replacement for shell+rsh+ftp+telnet, in a very
alpha development stage. Pyfs works on every platforms supporting Python,
with network connections in mind. Having the pyfs server running on the
machine A (a PC, a Nokia phone with Symbian S60, an XBOX console), you can
connect to A from another machine B (using the pyfs client), either via
TCP/IP, either via Bluetooth. After the connection is established, you can
interact with the remote python shell on A, or also start a form of
UNIX-like shell on A, with commands like cp, rm, ls, mkdir, etc, and even 
transfer files, in both directions.

Home page:
http://mulinux.sunsite.dk/pyfs/

Thanks You,
Michele
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Roundtrip SQL data especially datetime

2006-12-16 Thread John Machin

John Nagle wrote:
 dyork wrote:
  John Machin [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
 
 If you have, as you should, Python 2.5, you can use this:

 Actually, MySQLdb isn't released for Python 2.5 yet

Actually, that's interesting information [why should it take so long?],
but the OP didn't actually say what brand of database he was actually
using :-)

Cheers,
John

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


Re: merits of Lisp vs Python

2006-12-16 Thread Ken Tilton


greg wrote:
 Ken Tilton wrote:
 
 I did explain the last little fun bit (where reverse code miraculously 
 got a case-specific signed-value parameter bound to exactly the 
 right bit of math structure).
 
 
 I didn't mention that because it was addressed by
 another poster. The signature of the user's reverse
 function can be made extremely flexible if you have
 the foresight to define it as something like
 
def reverse(resx, opnd, **kwds):
  ...
 
 Then you can later change it to
 
   def reverse(resx, opnd, signed_value, **kwds):
  ...
 
 and any existing reverse functions will just absorb
 and ignore the extra argument.
 
 However, rather than add an ever-increasing number
 of arguments to the signature, I think I would do it
 a different way: pass a single object with attributes.
 For the want of a better name, let's call it env
 for environment. The signature is then
 
   def reverse(env):
  ...
 
 and the body can refer to env.resx, env.opnd,
 env.signed_value, or whatever else is required.

Looks promising. How does a generic engine that sees only a solution (a 
list of mathematical expressions and for each the transformations, 
results, and opnds logged by individual TF functions) build up this 
environment such that it has named attributes such as signed-value? 
Assume that it can examine all those opnds and results looking for 
tagged values such that it then knows the name of those values that have 
been named.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it. -- Elwood P. Dowd

I'll say I'm losing my grip, and it feels terrific.
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm looking for an intelligent date conversion module

2006-12-16 Thread Will McGugan
mthorley wrote:
 Greetings, I'm looking for a python module that will take a datetime
 obj and convert it into relative time in english.
 For example: 10 minutes ago, 1 Hour ago, Yesterday, A few day ago, Last
 Week, etc
 

I feel for you. I'm always on the lookout for an intelligent date.

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


Re: parsing a dictionary from a string

2006-12-16 Thread Paul McGuire
Benjamin Georgi [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hello list,

 I could use some help extracting the keys/values of a list of dictionaries 
 from a string that is just the str() representation of the list (the 
 problem is related to some flat file format I'm using for file IO).

 Example:
  s = str(dict_list)
  s
 '[{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]'

Pyparsing comes with a working example that will parse strings representing 
lists, even if they are nested.  This is actually more complex than the 
example you've given - none of your lists is nested.  Here is that example, 
adapted to handle dict elements, too.

-- Paul
(The pyparsing home page/wiki is at pyparsing.wikispaces.com.)


from pyparsing import *

cvtInt = lambda toks: int(toks[0])
cvtReal = lambda toks: float(toks[0])
cvtTuple = lambda toks : tuple(toks.asList())
cvtDict = lambda toks: dict(toks.asList())

# define punctuation as suppressed literals
lparen,rparen,lbrack,rbrack,lbrace,rbrace,colon = \
map(Suppress,()[]{}:)

integer = Combine(Optional(oneOf(+ -)) + Word(nums))\
.setName(integer)\
.setParseAction( cvtInt )
real = Combine(Optional(oneOf(+ -)) + Word(nums) + . +
   Optional(Word(nums)))\
.setName(real)\
.setParseAction( cvtReal )
tupleStr = Forward()
listStr = Forward()
dictStr = Forward()

listItem = real|integer|quotedString.setParseAction(removeQuotes)| \
Group(listStr) | tupleStr | dictStr

tupleStr  ( Suppress(() + Optional(delimitedList(listItem)) +
Optional(Suppress(,)) + Suppress()) )
tupleStr.setParseAction( cvtTuple )

listStr  (lbrack + Optional(delimitedList(listItem) +
Optional(Suppress(,))) + rbrack)

dictEntry = Group( listItem + colon + listItem )
dictStr  (lbrace + Optional(delimitedList(dictEntry) + \
Optional(Suppress(,))) + rbrace)
dictStr.setParseAction( cvtDict )

tests = ['a', 100, ('A', [101,102]), 3.14, [ +2.718, 'xyzzy', -1.414] ]
   [{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]

for test in tests.split(\n):
print Test:, test.strip()
result = listStr.parseString(test)
print Result:, result
for dd in result:
if isinstance(dd,dict): print dd.items()
print



Prints:
Test: ['a', 100, ('A', [101,102]), 3.14, [ +2.718, 'xyzzy', -1.414] ]
Result: ['a', 100, ('A', [101, 102]), 3.1401, [2.718, 
'xyzzy', -1.4139]]

Test: [{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]
Result: [{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]
[(0, [2]), (1, [])]
[(0, []), (1, []), (2, [])]
[(0, [1, 2])]




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


Re: parsing a dictionary from a string

2006-12-16 Thread Peter Otten
Benjamin Georgi wrote:

 I could use some help extracting the keys/values of a list of
 dictionaries from a string that is just the str() representation of the
 list (the problem is related to some flat file format I'm using for file
 IO).
 
 Example:
   s = str(dict_list)
   s
 '[{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]'
 
 Then, what I want to do is to reconstruct dict_list given s.
 Now, one possible solution would be
 
   dict_list = eval(s)
 
 but since the content of s cannot be blindly trusted I`d rather not do
 it that way. Basically my question is whether there is another solution
 which is simpler than using regular expressions.

Michael Spencer has published a simple eval() that only allows constant
expressions:

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

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


[ANN]: 'twander' 3.204 Released And Available

2006-12-16 Thread Tim Daneliuk
'twander' Version 3.204 is now released and available for download at:

  http://www.tundraware.com/Software/twander

The last public release was 3.195.

If you are unfamiliar with this program, see the end of this message
for a brief description.

-

NEW FEATURES

- A new boolean configuration option, CMDMENUSORT (default: False),
   has been added.  This allows the user to force the Command Menu to
   appear in sorted order (as opposed to the default which is to
   display commands in the order they are defined).

- It is now possible to temporarily assign the current directory
   to any of the Directory Shortcut keys.  The user presses
   KEDIRSCSET (default: Control-8) and is presented with a dialog
   to enter which of the 12 Directory Shortcut keys to load with
   the current directory.  This allows directory waypoints to
   be saved as shortcuts during the user's workflow.  The shortcuts
   revert to the definitions found in the Configuration File if
   the program is exited and restarted or if a configuration
   reload (default: Control-r) is initiated within the running
   program.

- A new configuration verb, ASSOC, has been added to implement file
   Associations.  Associations allow the user to define which program
   to start when the user selects a non-executable file and does a
   mouse doubleclick or presses Enter.  For example, this
   configuration statement associates files whose names end with the
   string .text with emacs:

 ASSOC .text emacs [SELECTION]

   There is also provision for a default association that is invoked
   if the user double-clicks or presses Enter on a non-executable
   file that has no specific association defined for it:

 ASSOC *  MyFineEditor [SELECTION]

   The right-hand-side of association statements can make use of almost
   all of the 'twander' configuration language features such as runtime
   prompting, symbolic variable substitution, execution variables, and
   so forth.


CHANGES  BUG FIXES

- The default mouse assignment to popup the shortcut menu (MOUSESC)
   has been moved to Alt-Control-LeftButton.  This was necessary
   because the previous assignment interfered with the mouse command to
   move up a directory level (MOUSEUP).

- The Shortcut Key help menu has been removed.  It was redundant
   with the identical menu on the menu bar and mouse popup menu.

- The titlebar status strings have been shortened to keep to overall
   title length more reasonable.

- Selected help menus have now been formatted into 3 columns (as
   opposed to the previous 2 column format) to make long help screens
   fit on the display better.

- A new help menu, Associations has been added to display any
   user-defined Associations (as described above).

- The order of the help menus has been changed to be slightly more
   intuitive (to the author anyway :).


DOCUMENTATION

- The new features and changes are reflected in the manual.

- The example Configuration File (.twander) now contains examples of
   Execution Variables.  These were introduced in 3.193 but examples
   were not included in the example configuration.

Complete details of all fixes, changes, and new features can be found in
the WHATSNEW.txt and documentation files included in the distribution.

Users are strongly encouraged to join the twander-users mailing list as
described in the documentation.

A FreeBSD port has been submitted as well.


What Is 'twander'?
--

'twander' is a macro-programmable Filesystem Browser that runs on both
Unix-like systems as well as Win32 systems. It embraces the best ideas
of both similar GUI-driven programs (Konqueror, Windows Explorer) as
well as text-based interfaces (Midnight Commander, List, Sweep).


Or, If You Prefer The Elevator Pitch
--

'twander' is:

- A better file browser for Unix and Win32.
 (Tested on FreeBSD, Linux, Win32. Probably works on Mac OS/X, but not 
tested.)
- A way to make browsing the same on all the OSs you use.
- A macro-programmable tool that lets *you* define the features.
- A GUI navigation front-end for your shell.
- A way to can workflows for your technically-challenged colleagues.
- A way to free yourself from the shackles of the mouse.
- A way to significantly speed up your day-to-day workflow.
- A Python/Tkinter application - about 5000 lines of code/comments
- A RCT (Really Cool Tool) that will have you addicted in a day or two

See the web page for more information, a screen shot, and the complete
documentation.

[EMAIL PROTECTED]


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


Re: tuple.index()

2006-12-16 Thread Christoph Zwerschke
Hendrik van Rooyen wrote:
 From a practical point of view, the only reason to use a tuple instead
 of a list for anything seems to be that you want to use it as a key in a 
 dict...
 
 Otherwise, why bother with these recalcitrant things that you can't
 change or index, or append to or anything that lists allow?

I can imagine (but don't know whether this is actually the case in 
CPython) that tuples have some memory and/or performance advantages over 
lists, and there could be special optimizations for small (2 or 3 
element) tuples because they are used very frequently.

So that would be another practical aspect why a long list of tuples 
could be better than a long list of lists - but does anybody know 
whether this is even true for CPython?

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


Re: tuple.index()

2006-12-16 Thread Christoph Zwerschke
James Stroud wrote:
 Christoph Zwerschke wrote:
 Maybe there would be less dispute if this dogma/convention(?) Tuples 
 are for heterogeneous data, list are for homogeneous data would be 
 written down somewhere in the tutorial, reference or in PEP8, so 
 people would be aware of it.
 
 This is a good idea. It has taken me a while to begin using them in this 
 manner. I have been more or less forced to by the design of the language 
 and I confess that the intended usage of each is pretty natural.

I just found that there is indeed some mentioning in the FAQ here:
http://www.python.org/doc/faq/general/#why-are-there-separate-tuple-and-list-data-types
But it is a bit vague, too, and does not mention whether there is any 
difference in efficiency which would be interesting to know as well.

It would be nice if somebody with more knowledge about the internals 
could overhaul and supplement that answer in the FAQ. A link to this in 
the tutorial or other parts of the standard doc where tuples and lists 
are discussed would be also helpful.

 Concretely speaking, which data type should I use for coordinate 
 tuples? Usually, tuples are used. Does this mean that I should better 
 use lists from now on because all the components have the same type?
 
 I don't think that all homogenous structures should be lists. This is 
 not the same as saying that all lists should be homogenous.

So in which cases exactly should one make exceptions? Python experts 
probably decide this from their gut feelings but it would be nice to 
have a more complete rule of thumb or decision guidance for 
non-experts that is mentioned somewhere in the docs, too:

Must be hashable for use as dict key or set element -- tuple
Inhomogenous in some meaning of the word -- tuple
... (fill in the details) -- tuple
everything else -- list

Maybe we can agree on something concrete here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Designing a cancellable function

2006-12-16 Thread Giovanni Bajo
Gabriel Genellina wrote:

 I now would also like to add the possibility to allow the user to
 *cancel* the execution of foo() during the processing, and I am
 wondering what the best / most Pythonic way to design this is.
 
 I can't say if this is the best/more Pythonic way, but a simple way 
 would be to use the return value from your callback. Consider it an 
 abort function: if it returns True, cancel execution; as long as it 
 returns False, keep going.

It's even easier if the callback function simply raise an exception, which can 
be caught from the outside:


class AbortOperationError(RuntimeError):
pass


def callback(N):
updateProgressBar(N)
processGUIEvents()
if exit_button_pressed:
   raise AbortOperationError()


try:
longFunction(callback)
except AbortOperationError()
pass


def longFunction(callback):
for i in xrange(10):
# do something
callback(i / 10.0)


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


Re: I'm looking for an intelligent date conversion module

2006-12-16 Thread neoedmund
I'm more familiar with java. maybe java.util.Calendar can be port to
python? i donnt know.


mthorley のメッセージ:

 Greetings, I'm looking for a python module that will take a datetime
 obj and convert it into relative time in english.
 For example: 10 minutes ago, 1 Hour ago, Yesterday, A few day ago, Last
 Week, etc

 I've looked around on the web, in the docs, the cheeseshop and on this
 list and have found what I'm looking for.
 Am I just blind? (likely), If anyone can give me a tip on how to do
 this I'd really appreciate it.
 
 thanks
 --
 mthorley

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


Re: merits of Lisp vs Python

2006-12-16 Thread Kay Schluehr
Ken Tilton schrieb:

 Looks promising. How does a generic engine that sees only a solution (a
 list of mathematical expressions and for each the transformations,
 results, and opnds logged by individual TF functions) build up this
 environment such that it has named attributes such as signed-value?

Most likely it doesn't since there is no such engine. Instead local
rules and combinators are encoded in classes. Hence there is nothing
but an object tree and actions are threaded through recursive method
calls.

This implies that the generic reverse function is just the dual of a
method call:

def reverse(expr):
 return expr.reverse()

What expr does depends on the internal representation encoded in the
class of expr. This also implies that not only the form of the
expression is significant but also its ( dynamic ) type.

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


Re: merits of Lisp vs Python

2006-12-16 Thread Christophe Cavalaria
Paul Rubin wrote:

 Kirk  Sluder [EMAIL PROTECTED] writes:
 Personally, I've always preferred use the imperative to describe
 basic math rather than the passive. This would seem to map better to
 RPN than infix.
 
 For writing down complicated, nested expressions too?  That's very
 unusual.  E.g.
 
   n! = (n/e)**n * sqrt(2*pi*n) * (1 + (1/12n)) * ...
 
 vs. the same thing in Lisp notation, and that's not even so complicated.

Yes, infix is better ( and note that Math uses primarly infix notation for
common operators ) because you have a clear view of the evaluation tree
that way. With prefix or postfix notation, you need to parse the full
expression to find what goes to the first parameter of that +, and what
goes to the second parameter.

I would say that prefix/postfix is somewhat easier to write, but that infix
is far far far easier to read.

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


Re: tuple.index()

2006-12-16 Thread Nick Maclaren

In article [EMAIL PROTECTED], Christoph Zwerschke [EMAIL PROTECTED] writes:
| 
| I just found that there is indeed some mentioning in the FAQ here:
| 
http://www.python.org/doc/faq/general/#why-are-there-separate-tuple-and-list-data-types
| But it is a bit vague, too, and does not mention whether there is any 
| difference in efficiency which would be interesting to know as well.

It is a trifle bizarre, much like most of the reasons that have been
given in this thread.  I know only some of how Python is implemented,
but have a lot of relevant experience, and here is some commentry on
the FAQ.

The mutability one is the key.  See 1.4.19 for a reason.  In a less
functional language, a tuple would be a value and a list a variable.
You CAN implement dictionaries using mutable objects as keys, but
the result is to add a large amount of inefficiency, complication,
and confusion, for next to no useful function.

The homogeneity argument baffles me.  While it is relevant to some
languages, I know of nothing within either Python's design or its
implementation that makes it relevant to Python.  There may be some
abstruse aspect that I have missed, and I should be very interested
if anyone can explain it.

Both of these are orthogonal to whether tuples should support count
and index methods.  Guido has given a clear answer We didn't think
it was worth doing.

In terms of efficiency, it is clearly possible to implement tuples
more efficiently, as there is a lot of mechanism that lists need that
they don't.  This accounts for the measurements people have made but,
as Guido says, it is EXTREMELY unlikely that any real application
will notice the difference.  The extra cost is almost entirely in the
setup, as the current implementation of list indexing is near-optimal.

It would also be possible to improve lists to make insertion an
O(log N) operation, not an O(N) one as at present, at the expense of
increasing the cost of indexing.  Not necessarily as much as from the
present O(1) to O(log N), but still significantly.  Python has chosen
not to do that.


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-16 Thread Juan R.
greg ha escrito:
 I don't know about the other Pythonistas in this
 discussion, but personally I do have experience with
 Lisp, and I understand what you're saying. I have
 nothing against Lisp parentheses, I just don't agree
 that the Lisp way is superior to the Python way in
 all respects, based on my experience with both.

Parentheses have two advantages over identation. First is they can be
used both inline and block.

The inline (a b (c d (e f g))) needs to be formatted in several Python
lines. Therein SLiP (Python) got problems for inline mixed markup but
LML (LISP) or SXML (Scheme) do not.

Second is that i do not need special editors for writting/editting. It
is more difficult to do identation and editing by hand in 'Notepad'
that adding parens from keyboard [*].

[*] Tip. Type always () and next move your cursor inside ( _ ). You
never forget a closing ) this way!

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


Re: CLPython (was Re: merits of Lisp vs Python)

2006-12-16 Thread metawilm
Paul Rubin wrote:
 [EMAIL PROTECTED] writes:
 a = 'hello'
 a[0] = 'H'   # attempt to change first letter to upper case
 
  As CLPython mirrors Python semantics, this results in a TypeError. The
  internal representation of an immutable Python string is a mutable Lisp
  string, but there is no way you can actually modify it from within CLPython.

 How do you manage that?  The compiler can't check.  Is there some kind
 of special dispatch on the assignment statement instead of turning it
 into a setf?

Indeed, the assignment of subitems is dynamically dispatched, and
always goes via __setitem__ methods, as specified in the language. The
__setitem__ methods for strings and tuples raise exceptions. The ones
for lists and vectors could be translated into a simple (setf (aref ..)
..) and (setf (nth ..) ..), unless the index is actually a slice and
actually a subsequence must be replaced.

Now, the above description using __setitem__ methods is how it
apparently works, as observed from the outside. Internally there is a
generic function (setf py-subs) that does the work itself, skipping the
lookup and calling of __setitem__, if the object is a vector or dict.
(The user can call x.__setitem__ explicitly, so that method must exist
internally.)

Maybe you were thinking that CLPython, given Python code, outputs a big
pile of self-contained equivalent Lisp code that can be run
independently, and then CLPython is finished. Instead, only a small
amount of Lisp code is generated, but that code can only be run when
the CLPython environment is loaded. The generated code refers to that
environment, e.g. s[0] = 'x' is translated into a call to (setf
(py-subs ..) ..), and function (setf py-subs) is part of the CLPython
environment that must be loaded at run-time.

If you compile a Python function, the result is a (mostly) normal Lisp
function - its origin from the Python world does not really matter.
Also, all Python data structures are first-class Lisp data. Thus
CLPython objects live happily together with normal Lisp objects in
the same image.

And now we arrive at the most exciting part: other Lisp libraries can
be loaded in the same image, and we can create connections. Like, after
loading CLIM and defining how CLPython objects should be presented, we
should get a Python interpreter where classes are displayed graphically
and where you can inspect and modify them by mouse. Imagine that you
have interactively added a method to a class by dragging a function to
a class, then being able to right-click and select write method,
which will write the definition of the method in the right place in the
class definition source code in your Climacs (CLIM-based Emacs) buffer.

That's the kind of features I have in mind, and the best thing is that
conceptually a lot of the work consists of connecting dots that already
out there. But as there are so many of them, a few extra pencils would
be quite welcome wink

- Willem

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


catching exceptions

2006-12-16 Thread [EMAIL PROTECTED]
Hi, In the following program, I have a class Test which has a property
x. Its setx function gets a string value and converts it into a float
and stores into it.

class Test(object):
def _getx(self):
return self._x
def _setx(self,strvalue):
try:
self._x = float(strvalue)
except ValueError:
print 'Warning : could not set x attribute to %s' %
strvalue
x = property(_getx,_setx)


def func1(value):
a = Test()
try:
a.x = value
except ValueError:
#Pop up a error window.
print 'This is second catch'


func1('12')
func1('12e1')
func1('a')



func1('12')
func1('12e1')
func1('a')
 func1('a')
Warning : could not set x attribute to a

I am looking for a way to call func1's exception handler also.
Basically I want to have the class's error handler as the basic text
based one, and in the calling side, If I have gui, I will pop-up a
window and say the error message.
One solution is to remove the exception handling inside the class and
leave the entire thing to the caller (software people call this
client?)  side -- if the caller has access to gui it will use gui or
else will print the message. Any other way?

--
Suresh

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


Re: job posting: Sr Systems Programmer needed

2006-12-16 Thread Paul McGuire
And why would you even use the word iceberg in an ad for a position in 
Minnesota?  You might as well refer to:
- the blizzard of opportunties for career growth in this position
- how you'll slide through the job startup process as if you were on ice
- the comfort of working in a small town, frozen in a simpler time

-- Paul


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


Re: catching exceptions

2006-12-16 Thread Amit Khemka
On 16 Dec 2006 03:54:52 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Hi, In the following program, I have a class Test which has a property
 x. Its setx function gets a string value and converts it into a float
 and stores into it.

 class Test(object):
 def _getx(self):
 return self._x
 def _setx(self,strvalue):
 try:
 self._x = float(strvalue)
 except ValueError:
 print 'Warning : could not set x attribute to %s' %
 strvalue
 x = property(_getx,_setx)


 def func1(value):
 a = Test()
 try:
 a.x = value
 except ValueError:
 #Pop up a error window.
 print 'This is second catch'


 func1('12')
 func1('12e1')
 func1('a')



 func1('12')
 func1('12e1')
 func1('a')
  func1('a')
 Warning : could not set x attribute to a

 I am looking for a way to call func1's exception handler also.
 Basically I want to have the class's error handler as the basic text
 based one, and in the calling side, If I have gui, I will pop-up a
 window and say the error message.
 One solution is to remove the exception handling inside the class and
 leave the entire thing to the caller (software people call this
 client?)  side -- if the caller has access to gui it will use gui or
 else will print the message. Any other way?

If I gather correctly, i guess in case of errors/exceptions in a class
function, you want to get the error string. One thing that comes
straight to my mind is, in such a case use a return statement in
functions with two arguments.

for example:
def foo(self, value):
try:
a.x = value
return True, ''
except ValueError:  return False, 'Float conversion error: %s' %(value)

and when ever u call the function, check the first return value, It is
false then alert/print the error message.

HTH,
amit.
-- 

Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
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: Has comparison of instancemethods changed between python 2.5 and 2.4?

2006-12-16 Thread Frank Niessink
Frank Niessink:
 OK, so that explains why the id of (two references to the same) 
 instancemethod(s) may differ. But I'm still confused why two 
 instancemethods of two different instances can compare as equal.

I tried to lookup the python source code where the actual comparison 
happens. I think it is in methodobject.c (I'm not familiar with the 
python source so please correct me if I'm wrong), meth_compare. That 
function did not change between python 2.4.4 and 2.5. Moreover, the 
implementation suggests that the only way for two methods to be equal is 
that their instances point to the same object and their method 
definitions are the same. Am I interpreting that correctly?

static int
meth_compare(PyCFunctionObject *a, PyCFunctionObject *b)
{
if (a-m_self != b-m_self)
return (a-m_self  b-m_self) ? -1 : 1;
if (a-m_ml-ml_meth == b-m_ml-ml_meth)
return 0;
if (strcmp(a-m_ml-ml_name, b-m_ml-ml_name)  0)
return -1;
else
return 1;
}

I'll dig some deeper in my own code, maybe I have two instances that are 
somehow different with python 2.4 and equal with python 2.5 and that 
register the same method as callback.

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


Re: catching exceptions

2006-12-16 Thread Steven D'Aprano
On Sat, 16 Dec 2006 03:54:52 -0800, [EMAIL PROTECTED] wrote:

 Hi, In the following program, I have a class Test which has a property
 x. Its setx function gets a string value and converts it into a float
 and stores into it.

[snip code]

Python isn't Java. Are you sure you need properties?


 I am looking for a way to call func1's exception handler also.
 Basically I want to have the class's error handler as the basic text
 based one, and in the calling side, If I have gui, I will pop-up a
 window and say the error message.
 One solution is to remove the exception handling inside the class and
 leave the entire thing to the caller (software people call this
 client?)  side -- if the caller has access to gui it will use gui or
 else will print the message. Any other way?

The exception is consumed by the try...except block inside the class,
so func1 never sees the exception. It might as well not exist.

Generally, you should keep your class as simple as possible. It shouldn't
try to manage any exception it can't recover from. In your case, the class
can't recover from a failure of float(strvalue), so it shouldn't consume
the exception. Two ways of doing that:

def _setx(self, strvalue):
self._x = float(strvalue)  # just let the exception propagate

or

def _setx(self, strvalue):
try:
self._x = float(strvalue)
except ValueError:
raise SomeError('could not set x attribute to %s' % strvalue)

where SomeError should be either ValueError or possibly some custom
exception (say, MyClassException).

In either case, the error handling is separate from the object that
generates the error. And that is as it should be. Now your class can
remain the same, no matter how the rest of your program handles the
exception.

By the way, if you want your class to generate warnings, perhaps you
should investigate the Warnings module:

import warnings
help(warnings)



-- 
Steven.

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


Re: catching exceptions

2006-12-16 Thread Steven D'Aprano
On Sat, 16 Dec 2006 17:36:00 +0530, Amit Khemka wrote:

 If I gather correctly, i guess in case of errors/exceptions in a class
 function, you want to get the error string. One thing that comes
 straight to my mind is, in such a case use a return statement in
 functions with two arguments.
 
 for example:
 def foo(self, value):
 try:
 a.x = value
 return True, ''
 except ValueError:  return False, 'Float conversion error: %s' %(value)
 
 and when ever u call the function, check the first return value, It is
 false then alert/print the error message.

Oh lordy, that is _so_ 1980s programming practice!!!

I'm not saying that it is never a good idea, but avoiding that sort of
thing is one of the reasons exceptions were created!


-- 
Steven.

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


Re: merits of Lisp vs Python

2006-12-16 Thread Hendrik van Rooyen
greg [EMAIL PROTECTED]

 
 I once heard mention of a system of units in use at
 one time with the odd feature that capacitance came
 out in units of length.
 
 Picture the scene: Hobbyist walks into Dick Smith
 store and says I'd like a 5cm capacitor, please.
 

This is correct - think of it as the number of electrons that 
can dance on the surface of a sphere of radius r.

So your hobbyist will be handed a copper ball of 10cm
diameter...

Seriously, in electrostatic units, capacitance is measured
in length. (or it was when they were trying to teach me
Physics)

- Hendrik

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


Re: tuple.index()

2006-12-16 Thread James Stroud
Christoph Zwerschke wrote:
 Inhomogenous in some meaning of the word -- tuple

I think that you have nailed it here. I don't think anyone on this list 
is capable of giving a concrete (as you have put it) operational 
definition of inhomogenous. They will resort to use cases and thus 
cloud the definition with programming philosophy.

So, programming philosophy, whether it will be admitted or not, is fully 
responsible for the exclusion of index() from the tuple interface.

But perhaps we could take not necessarily homogenous to be the 
operational definition of inhomogenous. Of course then we would have 
to define necessary...

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


Re: merits of Lisp vs Python

2006-12-16 Thread André Thieme
greg schrieb:
 André Thieme wrote:
  (aif (timeConsumingCalculation)
  (use it))
 
 I think the answer is that you just wouldn't do
 that in Python at all. Having magic variables
 spring into existence in your local namespace
 as a side effect of calling something is just
 not Pythonic. (It is very Perlish, on the other
 hand.)
 
 The closest you might come is using the new
 with statement like this:
 
   with aif(timeConsumingCalculation()) as it:
 use(it)
 
 where the object returned by aif(x) has an
 __enter__ method that raises an exception which
 aborts the whole with statement if x is None,
 thus avoiding executing the body. But that's
 so horribly convoluted that any sane programmer
 would just write it out the straightforward
 way to begin with.

Sounds like Blub to me:
http://www.paulgraham.com/avg.html

I will quote some parts of it:

You can see that machine language is very low level. But, at least as a
kind of social convention, high-level languages are often all treated as
equivalent. They're not. Technically the term high-level language
doesn't mean anything very definite. There's no dividing line with
machine languages on one side and all the high-level languages on the
other. Languages fall along a continuum [4] of abstractness, from the
most powerful all the way down to machine languages, which themselves
vary in power.

[...]

Programmers get very attached to their favorite languages, and I don't
want to hurt anyone's feelings, so to explain this point I'm going to
use a hypothetical language called Blub. Blub falls right in the middle
of the abstractness continuum. It is not the most powerful language, but
it is more powerful than Cobol or machine language.

And in fact, our hypothetical Blub programmer wouldn't use either of
them. Of course he wouldn't program in machine language. That's what
compilers are for. And as for Cobol, he doesn't know how anyone can get
anything done with it. It doesn't even have x (Blub feature of your
choice).

As long as our hypothetical Blub programmer is looking down the power
continuum, he knows he's looking down. Languages less powerful than Blub
are obviously less powerful, because they're missing some feature he's
used to. But when our hypothetical Blub programmer looks in the other
direction, up the power continuum, he doesn't realize he's looking up.
What he sees are merely weird languages. He probably considers them
about equivalent in power to Blub, but with all this other hairy stuff
thrown in as well. Blub is good enough for him, because he thinks in
Blub.

When we switch to the point of view of a programmer using any of the
languages higher up the power continuum, however, we find that he in
turn looks down upon Blub. How can you get anything done in Blub? It
doesn't even have y.

By induction, the only programmers in a position to see all the
differences in power between the various languages are those who
understand the most powerful one. (This is probably what Eric Raymond
meant about Lisp making you a better programmer.) You can't trust the
opinions of the others, because of the Blub paradox: they're satisfied
with whatever language they happen to use, because it dictates the way
they think about programs.



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


Re: merits of Lisp vs Python

2006-12-16 Thread Paul Rubin
André Thieme [EMAIL PROTECTED] writes:
 Sounds like Blub to me:
 http://www.paulgraham.com/avg.html

It never occurs to Lisp programmers that Lisp, too, might be a Blub.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index()

2006-12-16 Thread Nick Maclaren

In article [EMAIL PROTECTED],
James Stroud [EMAIL PROTECTED] writes:
| Christoph Zwerschke wrote:
| 
|  Inhomogenous in some meaning of the word -- tuple
| 
| I think that you have nailed it here. I don't think anyone on this list 
| is capable of giving a concrete (as you have put it) operational 
| definition of inhomogenous. They will resort to use cases and thus 
| cloud the definition with programming philosophy.

Yes, I can.  Here is one:

A collection is inhomogeneous if, for some attribute that is needed
for at least one action on at least one element of the collection,
the attribute is not shared by all elements of the collection.

Yes, this means that the concept of inhomogeneity depends on the use to
which a collection is put, and not just on the collection.

| So, programming philosophy, whether it will be admitted or not, is fully 
| responsible for the exclusion of index() from the tuple interface.

Agreed.

| But perhaps we could take not necessarily homogenous to be the 
| operational definition of inhomogenous. Of course then we would have 
| to define necessary...

It's not necessary :-)  Lists, in Python, are no more homogeneous than
tuples in any sense that I have located.  As I posted earlier, if
anyone knows of one, please tell me.


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions

2006-12-16 Thread [EMAIL PROTECTED]

Steven D'Aprano wrote:
 On Sat, 16 Dec 2006 03:54:52 -0800, [EMAIL PROTECTED] wrote:

  Hi, In the following program, I have a class Test which has a property
  x. Its setx function gets a string value and converts it into a float
  and stores into it.

 [snip code]

 Python isn't Java. Are you sure you need properties?

I do not know Java. But, object.x = value looks much better than
object.set_x(value) . Is there any harm in doing it, provided I have to
do more than just storing the value.



  I am looking for a way to call func1's exception handler also.
  Basically I want to have the class's error handler as the basic text
  based one, and in the calling side, If I have gui, I will pop-up a
  window and say the error message.
  One solution is to remove the exception handling inside the class and
  leave the entire thing to the caller (software people call this
  client?)  side -- if the caller has access to gui it will use gui or
  else will print the message. Any other way?

 The exception is consumed by the try...except block inside the class,
 so func1 never sees the exception. It might as well not exist.

 Generally, you should keep your class as simple as possible. It shouldn't
 try to manage any exception it can't recover from. In your case, the class
 can't recover from a failure of float(strvalue), so it shouldn't consume
 the exception. Two ways of doing that:

 def _setx(self, strvalue):
 self._x = float(strvalue)  # just let the exception propagate

 or

 def _setx(self, strvalue):
 try:
 self._x = float(strvalue)
 except ValueError:
 raise SomeError('could not set x attribute to %s' % strvalue)

 where SomeError should be either ValueError or possibly some custom
 exception (say, MyClassException).

 In either case, the error handling is separate from the object that
 generates the error. And that is as it should be. Now your class can
 remain the same, no matter how the rest of your program handles the
 exception.

 By the way, if you want your class to generate warnings, perhaps you
 should investigate the Warnings module:

 import warnings
 help(warnings)
I will go through it. Thanks a lot.
 
 
 
 -- 
 Steven.

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


Re: Routine for prefixing '' before every line of a string

2006-12-16 Thread Sanjay
Thanks a lot, guys!

sanjay

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


Re: merits of Lisp vs Python

2006-12-16 Thread André Thieme
Paul Rubin schrieb:
 Kirk  Sluder [EMAIL PROTECTED] writes:
 Personally, I've always preferred use the imperative to describe 
 basic math rather than the passive. This would seem to map better to 
 RPN than infix. 
 
 For writing down complicated, nested expressions too?  That's very
 unusual.  E.g.
 
   n! = (n/e)**n * sqrt(2*pi*n) * (1 + (1/12n)) * ...
 
 vs. the same thing in Lisp notation, and that's not even so complicated.

As I said earlier: if there are three formulas in your code, then it
doesn't matter too much.
If you write more then use infix in Lisp. It even looks better than Python:

[7x₆ + 9π³ - 6ˣ]

or

(if [√2 ≈ 1,41]
 (print Yay))

Or mathematical reasoning:
(proof [∃ x∈M  ∀ y∈Q : x≤y])

So what?


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

Re: merits of Lisp vs Python

2006-12-16 Thread Slawomir Nowaczyk
On Sat, 16 Dec 2006 14:09:11 +0100
André Thieme [EMAIL PROTECTED] wrote:

# Sounds like Blub to me:
# http://www.paulgraham.com/avg.html

Well, too bad for you...

# I will quote some parts of it:
# snip

# By induction, the only programmers in a position to see all the
# differences in power between the various languages are those who
# understand the most powerful one.

This statement is, clearly, right.What I can not comprehend is how
Lispers tend to mis-read comprehend above as think is the best. Some
of us *do* comprehend Lisp, understand that there are uses for macros,
just do not see the overwhelming need for them in everyday work (given
sufficiently rich language core).

I other words, people (in this sub-thread, at least) do not argue that
Python is *as powerful* as Lisp -- we understand there are things macros
can do easier/faster/more conveniently than functions or other features
Python has. Lisp *is* more powerful than Lisp. You win.

What we try to understand is why would you think Lisp is a better
programming language than Python :)

Sure, there are times I wish Python had macros. I would be able to save
a couple of keystrokes here and there. But at other times, I am glad it
does not have them, because when I read Bad Code (commonly used synonym
for somebody else's code) I do not need to wonder what aif and 1000
others, similar things really do.

In my experience, *if* somebody really needs aif, it can be done without
macros. But without macros people will only introduce such thing if it
does save significantly more than 3 or 4 lines of code in the whole
project -- which is a good thing in my book. YMMV.

I by far prefer to have

it = timeConsumingCalculations()
if it:
   use(it)

five (or even ten) times in a medium sized project than to have to
figure out what aif means. If the idiom is used 100 times, then
something is wrong: either system should be redesigned or introducing
aif is a good idea (but then Python idiom works just as good as Lisp
one). YMMV.

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

There are 2 kinds of people in the world - those that divide
  the people into 2 groups, and those who don't.

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

A new text templating system for python!

2006-12-16 Thread Chris Withers
Hi All,

I'm proud to announce that after almost a year's development, the first 
public release of Twiddler is available!

Twiddler is a simple but flexible templating system for dynamically 
generating textual output.

The key features are:

- No need to learn a templating language.

- As simple as possible while still catering for all possible templating
   operations.

- Configurable input parsing so source can be html, xml, plain text or
   anything you write an input parser for.

- Configurable output rendering so output can be rendered to a unicode
   string, an email, or anything you write an output renderer for.

You can find out more and download from here:

http://www.simplistix.co.uk/software/python/twiddler

If you wish to ask questions, pass judgement or get help, please do so 
in the following mailing list:

http://groups.google.com/group/twiddler

This is the first public release, so I'm looking for help with the 
following:

- Finding anything that should be possible in a templating system but
   isn't with Twiddler

- Packaging it up for easier distribution. I know nothing about eggs,
   distutils, etc, and so could do with help to package Twiddler so that
   it can be more easily installed.

Finally, here's a couple of quick examples:

  from twiddler import Twiddler
  t = Twiddler('''body
... div id=titleA title/div
... select name=items
... option id=itemAn item/option
... /select
... /body''')

  t['title'].replace('My title')
  r = t['item'].repeater()
  for i in range(1,4):
...   r.repeat('Item '+str(i),value=i,name=False)

  print t.render()
body
div id=titleMy title/div
select name=items
option id=item value=1Item 1/option
option id=item value=2Item 2/option
option id=item value=3Item 3/option
/select
/body

  from twiddler.input.plaintext import PlainText
  t = Twiddler('''To: $to
... itemAn item/item
... ''',input=PlainText)

  t['to'].replace('John Smith')
  r = t['item'].repeater()
  for i in range(1,4):
...   r.repeat('Item '+str(i),value=i,name=False)

  print t.render()
To: John Smith
Item 1
Item 2
Item 3

Thanks for reading this far, I hope you enjoy it!

cheers,

Chris

-- 
Simplistix - Content Management, Zope  Python Consulting
- http://www.simplistix.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


win32 service

2006-12-16 Thread g.franzkowiak
Hi everybody,

have a little problem with a service on Win32.

I use a TCP server as service, but can't access from an other machine.
Only local access is possible.

The service starts like this:

- myService.py --username user --password password install -

followed by start

The user is member in Log on as service, but... only local access :-(

What is wrong or what can I do ?

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


Re: how can i write a hello world in chinese with python

2006-12-16 Thread kernel1983
thanks everyone
maybe this simple API doesn't fit the Chinese display
but thanks everybody!

At least I've got that what bundles is and maybe I can use Python to
write program

On 12月14日, 上午6时31分, MRAB [EMAIL PROTECTED]
wrote:
 Dennis Lee Bieber wrote:
  On 12 Dec 2006 23:40:41 -0800, kernel1983 [EMAIL PROTECTED]
  declaimed the following in gmane.comp.python.general:

   and I tried unicode and utf-8
   I tried to both use unicodeutf-8 head just like \xEF\xBB\xBF and not
   to use

 unicode is a term covering many sins. utf-8 is a specification
  for encoding elements of specific unicode characters using 8-bit
  elements (I believe by using certain codes x00 to x7F alone as normal,
  and then x80 to xFF to represent an escape to higher [16-bit] element
  sets).

 \xEF\xBB\xBF is just a byte string with no identifier of what
  encoding is in use (unless the first one or two are supposed to be
  BOM)... In the Windows: Western character set, it is equivalent to
  small-i-diaeresis/right-guillemot/upside-down? () In MS-DOS: Western
  Europe, those same bytes represent an
  acute-accent/double-downleft-box-drawing/solid-downleft

 I've not done any unicode work (iso-latin-1, or subset thereof, has
  done for me). I also don't know Mac's, so I don't know if the windowing
  API has specific calls for Unicode data... But you probably have to
  encode or decod that bytestring into some compatible unicode
  representation.When you save a textfile as UTF-8 in Notepad.exe (Windows) 
  it puts the
 bytestring \xEF\xBB\xBF at the start to indicate that it's UTF-8 and
 not ANSI (ie 8-bit characters). The bytes are actually the BOM
 bytestring \xFE\xFF encoded in UTF-8.

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

Re: win32 service

2006-12-16 Thread Tim Williams
On 16/12/06, g.franzkowiak [EMAIL PROTECTED] wrote:
 Hi everybody,

 have a little problem with a service on Win32.

 I use a TCP server as service, but can't access from an other machine.
 Only local access is possible.

 The service starts like this:

 - myService.py --username user --password password install -

 followed by start

 The user is member in Log on as service, but... only local access :-(

 What is wrong or what can I do ?


Have you checked that your firewall isn't causing the problem,  and
that the servers IP address is accessible from other machines to start
with ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Package vs. module

2006-12-16 Thread Stuart D. Gathman
On Mon, 11 Dec 2006 20:59:27 -0300, Gabriel Genellina wrote:

 The above code *almost* works, but DNSLookup is a local name inside 
 the function. Use the global statement.
 As an example, see how getpass.py (in the standard library) manages 
 the various getpass implementations.

Ok, I have a working package:

spf/
  __init__.py
  pyspf.py
  pydns.py
  dnspython.py

__init__.py:
from pyspf import *
from pyspf import __author__,__email__,__version__ 

def set_dns_driver(f):
  global DNSLookup
  DNSLookup = f
  pyspf.DNSLookup = f

def DNSLookup(name,qtype,strict=True):
  import pydns
  return DNSLookup(name,qtype,strict)

set_dns_driver(DNSLookup)

Importing a driver module activates that driver.
For instance, in pydns.py:

import DNS# http://pydns.sourceforge.net
import spf

...
def DNSLookup(...):
  ...

spf.set_dns_driver(DNSLookup)

NOW, this is all very nice and modular. BUT, the original module was a
single file, which could be run as a script as well as imported as a
module. The script features provided useful command line functionality.
(Using if __name__ == '__main__':).  Now that 'spf' is a package, the
command line feature is gone!  Even using -m, I get:

python2.4 -m spf
python2.4: module spf has no associated file

Looking at getpass.py as advised, I see they put all the drivers in the
module.  I could do that with spf.py, I suppose.  But I like how with the
package, the driver code is not loaded unless needed.

One other idea I had was an arrangement like this:

SPF/
  pydns.py
  dnspython.py

spf.py

This would keep the module as a single file usable from the command line,
but still make driver available as separately loaded modules.

So which of the three options,

1) single file module with all drivers, ala getpass
2) package that cannot be run directly from command line
3) single file module with associated driver package

is the most pythonic?


-- 
  Stuart D. Gathman [EMAIL PROTECTED]
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
Confutatis maledictis, flamis acribus addictis - background song for
a Microsoft sponsored Where do you want to go from here? commercial.

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


Re: Has comparison of instancemethods changed between python 2.5 and 2.4?

2006-12-16 Thread Ziga Seilnacht
Frank Niessink wrote:
 I tried to lookup the python source code where the actual comparison
 happens. I think it is in methodobject.c (I'm not familiar with the
 python source so please correct me if I'm wrong), meth_compare. That
 function did not change between python 2.4.4 and 2.5. Moreover, the
 implementation suggests that the only way for two methods to be equal is
 that their instances point to the same object and their method
 definitions are the same. Am I interpreting that correctly?

No, the comparison happens in function instancemethod_compare in file
classobject.c:
http://svn.python.org/view/python/trunk/Objects/classobject.c?view=markup

This method was changed in Python 2.5. Previously, two instancemethods
compared equal if their im_self attributes were *identical* and their
im_func attributes were equal. Now, they compare equal if their im_self
attributes are *equal* and their im_func attributes are equal. See this
change:
http://svn.python.org/view?rev=46739view=rev

A small example:

type cmpmethod.py

class Test(object):

def meth(self):
pass

def __eq__(self, other):
return True

python24
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) ...
 from cmpmethod import Test
 a, b = Test(), Test()
 a.meth == b.meth
False
 ^Z

python25
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) ...
 from cmpmethod import Test
 a, b = Test(), Test()
 a.meth == b.meth
True
 ^Z

If you think this is a bug, you should report it to the bugtracker:
http://sourceforge.net/bugs/?group_id=5470

Ziga

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


Re: merits of Lisp vs Python

2006-12-16 Thread Ken Tilton


Kay Schluehr wrote:
 Ken Tilton schrieb:
 
 
Looks promising. How does a generic engine that sees only a solution (a
list of mathematical expressions and for each the transformations,
results, and opnds logged by individual TF functions) build up this
environment such that it has named attributes such as signed-value?
 
 
 Most likely it doesn't since there is no such engine. Instead local
 rules and combinators are encoded in classes. Hence there is nothing
 but an object tree and actions are threaded through recursive method
 calls.

Most likely that is the engine of which I was speaking. :) Why does the 
engine consisting of internal methods make it not an engine? I think 
you saw the word engine and assumed I did not understand OO design. I 
feel a Naggum coming on...

kt

ps. This won't make sense unless you know about my Cells project, but 
the solution to a /problem/ which has attributes expr and instructions, 
is a declarative attribute of a problem. But that attribute is coded 
essentially like this:

(defclass problem ()

(solution :accessor solution
  :initform (c-formula ()
(solve (expr self) (instructions self)

k

 
 This implies that the generic reverse function is just the dual of a
 method call:
 
 def reverse(expr):
  return expr.reverse()
 
 What expr does depends on the internal representation encoded in the
 class of expr. This also implies that not only the form of the
 expression is significant but also its ( dynamic ) type.
 

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it. -- Elwood P. Dowd

I'll say I'm losing my grip, and it feels terrific.
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional iteration

2006-12-16 Thread Colin J. Williams
at wrote:
 Dear Carl,
 
 Well, all I can say that for me as a user it would make sense...
 
 Curiosity: in what sense is it redundant?
 All solution/workarounds I have seen so far involve creation of new lists
 (subsets) adding to more processing/computation/memory usage. Redundant
 suggests that you know alternatives that don't do that.
 
 Does Guido ever change his mind?

Yes, he was opposed to conditional expressions at one time. I like the 
scheme he came up with.

In the present context, Paul Rubin suggested new syntax:

Use:

  for x in (x in [-2, -1, 0, 1, 2, 3, 4] if x  0):
   ... more code ...


Colin W.
 
 Cheers,
 
 @
 
 
 Carl Banks wrote:
 
 at wrote:
 I am not looking for a work around but more interest if other people
 might judge this syntax would come in handy?
 Of course people have expressed interest in this in the past, but it's
 not going to happen.  There's a way to nest for and if statements, and
 a different way to nest for and if clauses in listcomps, and the two
 methods are considered distinct.  Although Guido has said that saving
 indentation levels is important, he hasn't said  anything (that I'm
 aware of) that suggests it's important enough to add this complexity
 and redundancy to the language.  Sorry.


 Carl Banks
 

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


Re: win32 service

2006-12-16 Thread g.franzkowiak
Tim Williams schrieb:
 On 16/12/06, g.franzkowiak [EMAIL PROTECTED] wrote:
 Hi everybody,

 have a little problem with a service on Win32.

 I use a TCP server as service, but can't access from an other machine.
 Only local access is possible.

 The service starts like this:

 - myService.py --username user --password password install -

 followed by start

 The user is member in Log on as service, but... only local access :-(

 What is wrong or what can I do ?

 
 Have you checked that your firewall isn't causing the problem,  and
 that the servers IP address is accessible from other machines to start
 with ?

Yes, is checked. The server class operates as normal console program.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-16 Thread Raffael Cavallaro
On 2006-12-16 08:21:59 -0500, Paul Rubin http://[EMAIL PROTECTED] said:

 It never occurs to Lisp programmers that Lisp, too, might be a Blub.

Of course it does - Thats why we try ocaml and haskell etc. It's just 
that we don't see the useful features of these languages as being 
sufficiently useful to compensate for their lack of the ability to 
easily do syntactic abstractions over a uniform syntax. There's no 
question that other languages have some features that common lisp does 
not (and vice versa). Lispers just can't abide being locked into a 
particular paradigm because a language doesn't have the basic features 
(macros and uniform syntax) necessary to provide new paradigms for 
ourselves when needed or wanted.

For example, a common lisp with optional static typing on demand would 
be strictly more expressive than common lisp. But, take say, haskell; 
haskell's static typing is not optional (you can work around it, but 
you have to go out of your way to do so); haskell's pure functional 
semantics are not optional (again, workarounds possible to a limited 
extent). This requires you to conceive your problem solution (i.e., 
program) within the framework of a particular paradigm. This lock-in to 
a particular paradigm, however powerful, is what makes any such 
language strictly less expressive than one with syntactic abstraction 
over a uniform syntax.

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


Re: Roundtrip SQL data especially datetime

2006-12-16 Thread fumanchu
dyork wrote:
 Thanks Gabriel, but when I said round trip I really did mean: convert all
 the way to string and all the way back again, so your kind advice is not all
 that helpful. I need string to get to a non-Python object or a Web page.

Then you need two adaptation layers: one between your app and the DB
(which you already have) and one between your app and the web page or
other user interface.

Here's the web adaptation layer I use:
http://projects.amor.org/misc/browser/alamode.py
Have a look at the coerce_in and coerce_out functions.


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

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


Re: win32 service

2006-12-16 Thread g.franzkowiak
Tim Williams schrieb:
 On 16/12/06, g.franzkowiak [EMAIL PROTECTED] wrote:
 Hi everybody,

 have a little problem with a service on Win32.

 I use a TCP server as service, but can't access from an other machine.
 Only local access is possible.

 The service starts like this:

 - myService.py --username user --password password install -

 followed by start

 The user is member in Log on as service, but... only local access :-(

 What is wrong or what can I do ?

 
 Have you checked that your firewall isn't causing the problem,  and
 that the servers IP address is accessible from other machines to start
 with ?

OK, now I'm connected. My adjustments in Log on as service were wrong.
gerd
-- 
http://mail.python.org/mailman/listinfo/python-list


module wide metaclass for new style classes

2006-12-16 Thread Daniel Nogradi
I used to have the following code to collect all (old style) class
names defined in the current module to a list called reg:


def meta( reg ):
def _meta( name, bases, dictionary ):
reg.append( name )
return _meta

reg = [ ]
__metaclass__ = meta( reg )

class c1:
pass

class c2:
pass

print reg


This would correctly print [ 'c1', 'c2' ]. Now I would like to switch
to new style classes but replacing class c1: and class c2: by class
c1(object): and class c2(object): doesn't work because the metaclass
associated with object will be called and not mine. Of course if I
would add __metaclass__ = meta(reg)  to all class definitions that
would work, but how do I do this on the module level?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-16 Thread Juan R.
Raffael Cavallaro ha escrito:
 This lock-in to
 a particular paradigm, however powerful, is what makes any such
 language strictly less expressive than one with syntactic abstraction
 over a uniform syntax.

Right, but it would be also remarked that there is not reason to
ignoring the development and implementation of specific syntaxes,
paradigms, etc. optimized to specialized (sub)fields of discourse.

If all you need is basic arithmetics and 'static' data structures,
optimization á la Python Y = a + b * c gets sense in most of cases.

If you are developing symbolic software where data structures as highly
'dinamic' and where you would wait something more than sums, divisions,
sines and cosines, and some numeric differentials then the parens
automatically gets sense.

Using LISP-like syntax for everything would be so stupid as using
quantum mechanics for billiards.

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

Re: merits of Lisp vs Python

2006-12-16 Thread Juan R.
Using LISP-like syntax for everything would be so stupid as using
quantum mechanics for billiards.

Claiming that LISP parens are Stupid, Superfluous, or Silly just
because you do not need them in your limited field of discourse, would
be so stupid as those people thinking that just because they use
classical mechanics at the macro scale and works for them, then
classical mechanics would also work at the atomic scale [*].

[*] Even today, after 100 years some people think that quantum
mechanics is Stupid, Superfluous, or Silly and some classical
formulation will replace.

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


Re: I'm looking for a pythonic red-black tree...

2006-12-16 Thread Stuart D. Gathman
On Fri, 15 Dec 2006 01:20:34 +, Just Another Victim of the Ambient
Morality wrote:

 I need a red-black tree in Python and I was wondering if there was one 
 built in or if there's a good implementation out there.  Something that, 
 lets face it, does whatever the C++ std::map allows you to do...

Are you really looking specifically for a red-black tree, or do you want a
container where iterators return values in sorted order?  For instance, my
favorite sorted container is the skip-list:

 * inherently thread safe even during container updates
 * updates as fast as searches - significantly faster than red-black tree
 * search as fast as trees on average - but probablistic (like hashtable)
 * sequential access as fast as a linked list
 * Uses 33% less memory than binary trees (like red-black tree)
 * in general, performs like a hashtable, but sorted

Java example: http://bmsi.com/java/SkipList.java

In Python, the performance of a pure Python container will be
disappointing unless it leverages a native container.  For many
applications, you can use a dict and sort when iterating (using heapq to
amortize the sorting).

If I ever get the time, I would seriously consider trying to modify Python
to replace the built-in dict with a skip-list algorithm and compare the
performance.  Failing that, an extension module implementing a sorted
container of some description would be useful.

-- 
  Stuart D. Gathman [EMAIL PROTECTED]
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
Confutatis maledictis, flamis acribus addictis - background song for
a Microsoft sponsored Where do you want to go from here? commercial.

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


Re: merits of Lisp vs Python

2006-12-16 Thread Kirk Sluder
In article [EMAIL PROTECTED],
 Paul Rubin http://[EMAIL PROTECTED] wrote:

 Kirk  Sluder [EMAIL PROTECTED] writes:
  Personally, I've always preferred use the imperative to describe 
  _basic_ math rather than the passive. This would seem to map better to 
  RPN than infix. 

(emphasis added)
 
 For writing down complicated, nested expressions too?  That's very
 unusual.  E.g.
 
   n! = (n/e)**n * sqrt(2*pi*n) * (1 + (1/12n)) * ...
 
 vs. the same thing in Lisp notation, and that's not even so complicated.

I wasn't even talking about Polish notation vs. other standard 
notations. I was talking about your claimed correspondence between 
infix and natural Languages.

(1/12n) - divide 1 by the product of of 12 and n
sqrt(2*pi*n) - calculate the square root of the product of 2 pi and 
n. 

If computer languages were to mimic natural languages on this point, 
they would support both forms of expression and be sensitive to mode 
and mood.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Roundtrip SQL data especially datetime

2006-12-16 Thread John Nagle
John Machin wrote:
 John Nagle wrote:
 
dyork wrote:

John Machin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]


If you have, as you should, Python 2.5, you can use this:

Actually, MySQLdb isn't released for Python 2.5 yet
 
 
 Actually, that's interesting information [why should it take so long?],
 but the OP didn't actually say what brand of database he was actually
 using :-)

True.

Why should it take so long?  The Python people don't support the
MySQL interface, and the MySQL people don't support the Python interface.
There's one guy on Sourceforge doing the MySQLdb glue code.  And he's busy.

This is unusual for database bindings.  The standard Perl distribution
supports MySQL and several other databases, so you can use MySQL
out of the box, and it's tested for new releases.  The standard MySQL
distribution supports PHP, Java, etc., so that's standard and gets
tested.

With Python/MySQL, though, neither side takes responsibility
for making that binding work.

One side effect of this being third party code is that hosting
services may not have it available, even when they have both Python
and MySQL up.  This is never a problem with Perl or PHP, so that's
a negative for Python.  I'm currently trying to get EZpublishing,
usually a good hosting service, to fix this on their systems.

There are also some recent problems between versions of
Apache, mod_python, MySQLdb, Python, and MySQL, some of which can
crash a web server.  (Ref: 
http://packages.debian.org/changelogs/pool/main/p/python-mysqldb/python-mysqldb_1.2.1-p2-4/changelog)
Not sure if this has been resolved yet.

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


Re: merits of Lisp vs Python

2006-12-16 Thread Jon Harrop
Raffael Cavallaro wrote:
 Of course it does - Thats why we try ocaml and haskell etc. It's just
 that we don't see the useful features of these languages as being
 sufficiently useful to compensate for their lack of the ability to
 easily do syntactic abstractions over a uniform syntax.

That applies to the Lispers who've tried other languages and stayed with
Lisp.

 There's no 
 question that other languages have some features that common lisp does
 not (and vice versa). Lispers just can't abide being locked into a
 particular paradigm because a language doesn't have the basic features
 (macros and uniform syntax) necessary to provide new paradigms for
 ourselves when needed or wanted.

Why do you think that uniform syntax is necessary to provide new paradigms
when it is equivalent to infix syntax?

 For example, a common lisp with optional static typing on demand would
 be strictly more expressive than common lisp. But, take say, haskell;
 haskell's static typing is not optional (you can work around it, but
 you have to go out of your way to do so); haskell's pure functional
 semantics are not optional (again, workarounds possible to a limited
 extent).

In what way is Haskell's support for imperative programming limited?

 This requires you to conceive your problem solution (i.e., 
 program) within the framework of a particular paradigm. This lock-in to
 a particular paradigm, however powerful, is what makes any such
 language strictly less expressive than one with syntactic abstraction
 over a uniform syntax.

Can you give an example of a Lisp macro that does something useful that you
can't do in these other languages?

-- 
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-16 Thread Kirk Sluder
In article 
[EMAIL PROTECTED],
 Kirk  Sluder [EMAIL PROTECTED] wrote:

 In article [EMAIL PROTECTED],
  Paul Rubin http://[EMAIL PROTECTED] wrote:
 
n! = (n/e)**n * sqrt(2*pi*n) * (1 + (1/12n)) * ...

 If computer languages were to mimic natural languages on this point, 
 they would support both forms of expression and be sensitive to mode 
 and mood.

And ok, bringing this around to lisp, many complex expressions such 
as polynomials can be viewed as lists of sub-expressions. So in this 
case, the expression can be re-written as:

(* (subexp1) (subexp2) (subexp3) (subexp4))

Which is probably how I'd solve the expression if I was using paper 
and pencil: simplify and combine.

And there is something that is missing here in arguing about 
computer language notations in relationship to human language 
readability, or correspondence to spoken language. I'm not writing 
code for another human, I'm writing code for a machine.  Often, the 
optimum expression of an mathematical concept for a machine is 
relatively baroque compared to the optimum expression for a human 
being.
-- 
http://mail.python.org/mailman/listinfo/python-list


sha, PyCrypto, SHA-256

2006-12-16 Thread mirandacascade
Operating system: Win XP
Vsn of Python: 2.4

Situation is this: Required to calcluate a message digest.  The process
for calcluating the digest must use an SHA-256 algorithm.

Questions:
1) Is it correct that the sha module comes with python 2.4?
2) Is it correct that the sha module that ships with python 2.4 does
NOT have the SHA-256 capability as part of the module?
3) It looks like PyCrypto is a package that, among other things,
permits one to calculate a message digest using an SHA-256
algorithm...is that correct?
4) It looks like there are a couple couple possibilities available for
the download...either download the source code and run the setup which
(I'm assuming) compiles the various extension modules, or download the
pycrypto-2.0.1.win32-py2.4.zip which extracts out to a .exe; when one
runs the just-extracted .exe, it installs the stuff on one's
workstation.  I'm leaning toward the second option because it seems
like most of the work has been done for me.  A quick search on this
site didn't turn up anything that suggested there were problems with
running the installer.  So, my question is this: are you aware of any
problems running the installer?
5) Besides PyCrypto, are there any other Python packages that permit
one to calculate a message digest using an SHA-256 algorithm?

Thank you.

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


Re: merits of Lisp vs Python

2006-12-16 Thread xscottg
Ken Tilton wrote:
 [EMAIL PROTECTED] wrote:
 
  Code is data is code

 I was hoping no one would make that mistake. :) macros are all about
 code is data, but code is not data in Python* so the two words code and
 data serve to differentiate them for Pythonistas.


I disagree.  I frequently write data-driven algorithms in C and Python
(data is code).  I occasionally write code-generators too (code is
data).  Just because the representation is different between code and
data in those languages doesn't mean that you can't use data as code
(interpreter style) or generate code as data (compiler style).  (I
won't bother boring you with the Python bytecode hacks or the parser
module, because I think those are not terribly practical.)

It's very elegant that Lisp makes the representations between code and
data so similar, but it looks like you know the mantra and not the
meaning if you can't apply that principle in other languages.

BTW...  Even in Scheme, I have to use syntax-object-datum and it's
inverse to switch between the two.  I suspect this has something to do
with the other context that must be associated with the data to turn it
into code.  Probably at least the enclosing environment for lexical
scoping and the line numbers for debugging or exception handling.  Does
Common Lisp maintain this information with it's macro expansions?  If
so, you have a slight difference between code and data too.  If not,
how do you get the line number when a problem happens in a nested
macro?

Moreover, if you really want to be pedantic about what is means in
code is data, then you have to acknowledge that data is a superset of
code, since all code is obviously data, but there are plenty of types
of data that aren't used as code.  Or are they?  :-)


 *  Taking questions after a keynote to ILC200? where he reiterated that
 Python was the same as Lisp for all intents and purposes:

 Norvig: Yes, John?
 McCarthy: Is code also data in Python?
 Norvig: No.

 End of exchange. :)


Really?  You're relying on an appeal to authority?  Ok, I'm going to
start arguing by analogy then...



 def reverse(cls, *args):
   # I didn't understand what your code was doing

 yeah, and god forbid you should ask. :) this is the crux of the matter!

 Actually, it is kinda cool that you and Greg are semi-identifying the
 crux by saying this is the only bit I do not get, I'll skip this, move
 on, nothing to see here.


Ok, I'll bite.  What does it do?  I read through it, and it looks the
code you're passing to the macro does some things like calculating the
number of decimal digits and generating a 2 + a random number of that
many digits to find a divisor or something.  It also looks like you
have some string interpolation to substitute names in your text, but
as a whole, I really don't have any clue what it's all about.

It looks like the macro itself is building some names on the fly and
defining methods (new specializations for multimethods?) with those
names.

So I'm sure I'm missing something, but there is almost certainly a
readable equivalent in Python (and even C).  If you really want to
generate dynamic names for functions, you can do that in Python by
modifying the class or globals hash or whatever.  A more standard way
might be to be have members in the base class.

There is even a multi-methods module in Python, but I've never used it.
 I'd guess you could add to that dynamically too.


 
  That would be a reasonable place for a pie decorator on a class, but
  I guess that's not allowed.

 Hmmm. Actually, that is the whole point, all of Python is allowed.
 decorators were used in PyCells, but I never got much of an idea what
 they did. Is there a moral equivalent of a macroexpansion for decorators
 so you can show the before and after?


It's Python that doesn't allow you to decorate classes.  (You can
decorate functions, but not classes...)  I made this comment as a
criticism of Python since it seems like a non-orthogonal corner...  It
would have fit in this case.

Decorators are pretty simple:

@foo
def bar(): pass

is equivalent to:

def bar(): pass
bar = foo(bar)

The callable foo can use whatever it wants to inspect, modify, or wrap
the function bar.

but:

@foo
class bar: pass

is not currently allowed, so you have to do

class bar: pass
bar = foo(bar)




 exactly what we are looking for in this cultural exchange: how would
 Python handle what I am doing with macros in the reverse functions? Make
 it as slick and programmer-friendly (cuz I may get to a hundred of these
 before I am done with Algebra I) as possible. When all the Pythonistas
 proclaim it optimal, then we compare and contrast.

 This, btw, is the Tilton Test for language comparison: Not measurements
 of programmer effort, rather examination of perfect equivalent code.
 PyCells vs Cells would be an amazing case, because that is some hairy
 functionality.


That seems like a fine strategy.  I fall more on the programmer 

Re: merits of Lisp vs Python

2006-12-16 Thread Raffael Cavallaro
On 2006-12-16 13:58:37 -0500, Jon Harrop [EMAIL PROTECTED] said:

 Why do you think that uniform syntax is necessary to provide new paradigms
 when it is equivalent to infix syntax?

Because it doesn't require one to write a parser for each new syntax 
for each new paradigm.

 In what way is Haskell's support for imperative programming limited?

It requires one to frame everything in functional terms or to jump 
through the hoop of monads.

 Can you give an example of a Lisp macro that does something useful that you
 can't do in these other languages?

It isn't a question of can't do in these other languages, it's a 
matter of can't do as easily in these other languages. Look at kenny 
tilton's cells. Its a dataflow paradigm built largely of macros. It 
goes completely against the semantics of haskell - cells is all about 
the eager evaluation of side effecting state mutation. Could you do it 
in haskell? Yes, in the greenspun/turing-completeness sense, but not 
nearly as easily as in common lisp, because the very paradigm - eager 
evaluation combined with side effecting state mutation - goes against 
the basic semantics of haskell. You'd have to jump through extra hoops 
to build a system whose very nature contradicts two of the semantic 
foundations of haskell - laziness and absense of side effects.

Then there's the issue of the new syntax. Easy to build in lisp without 
learning another language - lisp macros use lisp. What little I've seen 
of caml4p looks like perlesque line noise. Ultimately I think that the 
defaults of both haskell and ocaml - functional, static typing, 
non-uniform syntax - are things I don't want as defaults, but as 
options for later in the development of only certain pieces of code. I 
don't want to be required to jump through the pure-functional, 
must-use-monads-for-any-side-effects, static-type, non-uniform-syntax 
hoops to express my ideas. It makes me less flexible in dealing with 
individual parts of a program differently.

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


Re: sha, PyCrypto, SHA-256

2006-12-16 Thread Dennis Benzinger
Am 16 Dec 2006 11:17:19 -0800
schrieb [EMAIL PROTECTED]:

 Operating system: Win XP
 Vsn of Python: 2.4
 
 Situation is this: Required to calcluate a message digest.  The
 process for calcluating the digest must use an SHA-256 algorithm.
 
 Questions:
 1) Is it correct that the sha module comes with python 2.4?
 2) Is it correct that the sha module that ships with python 2.4 does
 NOT have the SHA-256 capability as part of the module?
 3) It looks like PyCrypto is a package that, among other things,
 permits one to calculate a message digest using an SHA-256
 algorithm...is that correct?
 4) It looks like there are a couple couple possibilities available for
 the download...either download the source code and run the setup which
 (I'm assuming) compiles the various extension modules, or download the
 pycrypto-2.0.1.win32-py2.4.zip which extracts out to a .exe; when one
 runs the just-extracted .exe, it installs the stuff on one's
 workstation.  I'm leaning toward the second option because it seems
 like most of the work has been done for me.  A quick search on this
 site didn't turn up anything that suggested there were problems with
 running the installer.  So, my question is this: are you aware of any
 problems running the installer?
 5) Besides PyCrypto, are there any other Python packages that permit
 one to calculate a message digest using an SHA-256 algorithm?
 
 Thank you.
 


Python 2.5 comes with SHA-256 in the hashlib module.
So you could install Python 2.5 instead of the PyCrypto module.


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


Good Looking UI for a stand alone application

2006-12-16 Thread The Night Blogger
Can someone recommend me a good API for writing a sexy looking (Rich UI like
WinForms) shrink wrap application

My requirement is that the application needs to look as good on Windows as
on the Apple Mac


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


Is there a way to push data into Microsoft Excel Word from Python ?

2006-12-16 Thread The Night Blogger
Is there a way to push data to Microsoft Excel  Word from a Python
Application

Is this a cross platform feature ? I'll need to push data on MS Windows 
Mac OS X 


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


textwrap.dedent replaces tabs?

2006-12-16 Thread Tom Plunket
The documentation for dedent says, Remove any whitespace than can be
uniformly removed from the left of every line in `text`, yet I'm
finding that it's also modifying the '\t' characters, which is highly
undesirable in my application.  Is there any way to stop it from doing
this, or alternatively, to put those tabs back in?

I see that TextWrap and its member functions take an 'expand_tabs'
kwarg, but dedent unfortunately does not.

...I suppose such a function (replacement dedent) isn't terribly tough
to write, but it seems an odd default especially considering there's no
way to turn off the undesired changes, but were the changes /not/ made,
the same text could just be passed through TextWrapper and have them
removed...

thx,
-tom!

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


Re: Is anyone using Python for embedded applications?

2006-12-16 Thread dwhall
Carl,

I'm the lead developer for PyMite (http://pymite.python-hosting.com).
I do quite a bit of embedded development with PyMite.  PyMite is for
much smaller target devices (8-bit and 32-bit microcontrollers) than
you plan to use.  I am currently writing a series of papers that will
attempt to draw attention to the growing demand to use Python in the
variety of embedded spaces.  A rough draft of the first part in the
series is seen here:

http://members.capmac.org/~deanhall/python/piesI.html

During research for the later parts of the series, I have found the
following links that relate to Python in embedded devices:

http://sourceforge.net/projects/pythonce
http://sourceforge.net/projects/dietpython
http://www.python.org/dev/summary/2006-09-16_2006-09-30/#shrinking-python
http://cs.gmu.edu/~eclab/projects/robots/flockbots/pmwiki.php?n=Main.Python
http://groups.google.com/group/comp.lang.python/browse_thread/thread/f3a8f9ac964d5b84/6922ac416664f002?lnk=gstq=%22embedded+system%22rnum=5#6922ac416664f002

regards,

!!Dean

Carl J. Van Arsdall wrote:
 Hendrik van Rooyen wrote:
 
 
 
 
  It depends a *lot* on what is meant by embedded :
 
 Ha, very true

  This definition seems to cover everything from:
  - a cut down PC in a non standard box, through
  - a processor in a Washing Machine, to
  - a bare PIC processor in a Burglar Alarm...
 
 We are considering now are mobile phone and pocket pc-esque devices.  I
 know that several phones with arm processors are running an arm version
 of linux now, we're thinking how reasonable it might be to run python
 applications on a phone, and which python might best apply.  Is there a
 good way to determine the minimum requirements for a python
 application?  I'd imagine these might be something like the min
 requirements of python (cpython, pymite, etc) + additional requirements
 placed by the design of the application.  Is there a good way to study a
 python application and figure that type of thing out?


  I think the main hassles are that you need something big enough
  to run a reasonable OS in, and it must support being programmed in C,
  (which most things do), and it must have some MegaBytes of RAM
  loose for the Python. (where more is merrier)
 
  Trying to run this on say an AVR or 8031 with a 64k address space and
  a scarcity of RAM, will, to say the least, be a bit of a challenge...
 
  As far as the OS goes, Linux is probably the best bet, if you can get it to
  fit in your hardware - It has been ported to ARM type processors from
  various companies (Atmel springs to mind), and is free, which is a help
  in a personal project.  You could of course also roll your own kernel,
  which will be good practice, as with a limited set of peripherals its not
  THAT hard to do, but its a bit far away from Python -   :- )
 

 Yea, we are thinking on the more robust end of the embedded side.  So a
 system capable of running Linux or Windows CE (or something similar)
  What display device are you going to use, or is it going to be a webserver
  sitting on a power over ethernet link?
 
  I haven't actually taken the plunge myself yet to put Python on any of the
  hardware we make, as it seems to add a lot of overhead to a simple device
  - but I come from the bottom up, as it were, and the idea is intriguing,
  as I in fact discovered Python because it is embedded in a GPS module
  we were evaluating for building into a device - so I will follow your
  progress with interest...
 
 


 --

 Carl J. Van Arsdall
 [EMAIL PROTECTED]
 Build and Release
 MontaVista Software

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


Re: Roundtrip SQL data especially datetime

2006-12-16 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], John Nagle wrote:
 John Machin wrote:
 John Nagle wrote:
dyork wrote:
John Machin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]


If you have, as you should, Python 2.5, you can use this:

Actually, MySQLdb isn't released for Python 2.5 yet
 
 
 Actually, that's interesting information [why should it take so long?],
 but the OP didn't actually say what brand of database he was actually
 using :-)
 
 True.
 
 Why should it take so long?  The Python people don't support the
 MySQL interface, and the MySQL people don't support the Python interface.
 There's one guy on Sourceforge doing the MySQLdb glue code.  And he's busy.

AFAIK there's no MySQLdb module for Python 2.5 on *Windows* yet, because
the author of the module doesn't use Windows anymore and he don't want to
maintain a binary he can't test.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Is there a way to push data into Microsoft Oulook from Python ?

2006-12-16 Thread The Night Blogger
Is there a way to pull  push data (Tasks, Notes, Calendar Items ...) into
Microsoft Oulook from Python ?


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


Re: converting mysql db into sqlite3.

2006-12-16 Thread gordyt
You could probably use the mysqldump command with the proper options to
export the contents of your mysql database to an ASCII text file that
contains the SQL insert statements.  Then you could import that
information to a sqlite database file.  You may have to massage the
export file if it contains syntax that is not supported by sqlite.

Documentation for the mysqldump command is here:

http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html

The SQL syntax supported by sqlite is here:

http://www.sqlite.org/lang.html

--gordy

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


Is there a way to push data into Ical from Python ?

2006-12-16 Thread The Night Blogger
Is there a way to pull  push data into (Apple Mac OS X Calendar) Ical from
Python ?


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


Re: merits of Lisp vs Python

2006-12-16 Thread Ken Tilton


[EMAIL PROTECTED] wrote:
 Ken Tilton wrote:
 
[EMAIL PROTECTED] wrote:

Code is data is code

I was hoping no one would make that mistake. :) macros are all about
code is data, but code is not data in Python* so the two words code and
data serve to differentiate them for Pythonistas.

 
 
 I disagree. 

I might agree. The suggest alternative where the engine would build up 
an environment such that a lambda could seem to be accessing a 
pre-defined slot-name reminded me of some of the magic I noticed when 
trying to port Cells to Python. If the interpreter (as it seems) 
gracefully handles things like that, then one could argue that Python 
can at least generate code to be consumed by what I would have as a 
macro body, and thus achieve a degree of code is data.

Of course then I would point out that this would be terribly confusing 
and should be banned from Python for the same reason as are macros. :)

  I frequently write data-driven algorithms in C and Python
 (data is code).  I occasionally write code-generators too (code is
 data).  Just because the representation is different between code and
 data in those languages doesn't mean that you can't use data as code
 (interpreter style) or generate code as data (compiler style).  (I
 won't bother boring you with the Python bytecode hacks or the parser
 module, because I think those are not terribly practical.)
 
 It's very elegant that Lisp makes the representations between code and
 data so similar, but it looks like you know the mantra and not the
 meaning if you can't apply that principle in other languages.
 
 BTW...  Even in Scheme, I have to use syntax-object-datum and it's
 inverse to switch between the two.  I suspect this has something to do
 with the other context that must be associated with the data to turn it
 into code.  Probably at least the enclosing environment for lexical
 scoping and the line numbers for debugging or exception handling.  Does
 Common Lisp maintain this information with it's macro expansions?  If
 so, you have a slight difference between code and data too.  If not,
 how do you get the line number when a problem happens in a nested
 macro?
 
 Moreover, if you really want to be pedantic about what is means in
 code is data, then you have to acknowledge that data is a superset of
 code, since all code is obviously data, but there are plenty of types
 of data that aren't used as code.  Or are they?  :-)
 
 
 
*  Taking questions after a keynote to ILC200? where he reiterated that
Python was the same as Lisp for all intents and purposes:

Norvig: Yes, John?
McCarthy: Is code also data in Python?
Norvig: No.

End of exchange. :)

 
 
 Really?  You're relying on an appeal to authority?  Ok, I'm going to
 start arguing by analogy then...

Analogies! My favorite! When a state trooper tells me not to drive my 
Corvair over 55 that is argument from authority. When Ralph Nader tells 
me


 
 
 
 
   def reverse(cls, *args):
 # I didn't understand what your code was doing

yeah, and god forbid you should ask. :) this is the crux of the matter!

Actually, it is kinda cool that you and Greg are semi-identifying the
crux by saying this is the only bit I do not get, I'll skip this, move
on, nothing to see here.

 
 
 Ok, I'll bite.  What does it do?

There's been more on this elsewhere and I need to get some work done, so 
i am afraid from now on it will have to be analogies and arguments from 
authority, much faster.


  I read through it, and it looks the
 code you're passing to the macro does some things like calculating the
 number of decimal digits and generating a 2 + a random number of that
 many digits to find a divisor or something.  It also looks like you
 have some string interpolation to substitute names in your text, but
 as a whole, I really don't have any clue what it's all about.
 
 It looks like the macro itself is building some names on the fly and
 defining methods (new specializations for multimethods?) with those
 names.
 
 So I'm sure I'm missing something, but there is almost certainly a
 readable equivalent in Python (and even C).  If you really want to
 generate dynamic names for functions, you can do that in Python by
 modifying the class or globals hash or whatever.  A more standard way
 might be to be have members in the base class.
 
 There is even a multi-methods module in Python, but I've never used it.
  I'd guess you could add to that dynamically too.
 
 
 
That would be a reasonable place for a pie decorator on a class, but
I guess that's not allowed.

Hmmm. Actually, that is the whole point, all of Python is allowed.
decorators were used in PyCells, but I never got much of an idea what
they did. Is there a moral equivalent of a macroexpansion for decorators
so you can show the before and after?

 
 
 It's Python that doesn't allow you to decorate classes.  (You can
 decorate functions, but not classes...)  I made this comment as a
 criticism of Python since it seems like a non-orthogonal 

Re: Roundtrip SQL data especially datetime

2006-12-16 Thread John Nagle
Marc 'BlackJack' Rintsch wrote:
 In [EMAIL PROTECTED], John Nagle wrote:
 
John Machin wrote:

John Nagle wrote:

dyork wrote:

John Machin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]



If you have, as you should, Python 2.5, you can use this:

   Actually, MySQLdb isn't released for Python 2.5 yet


Actually, that's interesting information [why should it take so long?],
but the OP didn't actually say what brand of database he was actually
using :-)

True.

Why should it take so long?  The Python people don't support the
MySQL interface, and the MySQL people don't support the Python interface.
There's one guy on Sourceforge doing the MySQLdb glue code.  And he's busy.
 
 
 AFAIK there's no MySQLdb module for Python 2.5 on *Windows* yet, because
 the author of the module doesn't use Windows anymore and he don't want to
 maintain a binary he can't test.

 The SourceForge page

   http://sourceforge.net/project/showfiles.php?group_id=22307

says

MySQL versions 3.23-5.0; and Python versions 2.3-2.4 are supported.

Last release was April, 2006.  There's no binary for Python 2.5 yet.

See the help discussions for the project.  Apparently you can build
it for Python 2.5 from the SVN repository and it can be made to work,
but just building it may not work on your platform.  Some edits
may be required.  Problems have been reported with the Windows version
and the 64-bit Linux version.

These are all normal development issues.  But they're not fully resolved
yet.  So users should hold off from using Python 2.5 in production
database applications.

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


Re: Good Looking UI for a stand alone application

2006-12-16 Thread Peter Decker
On 12/16/06, The Night Blogger [EMAIL PROTECTED] wrote:
 Can someone recommend me a good API for writing a sexy looking (Rich UI like
 WinForms) shrink wrap application

 My requirement is that the application needs to look as good on Windows as
 on the Apple Mac

For my money (even though it's free!), you can't beat Dabo. It uses
the wxPython UI toolkit, so it looks great on Mac and Windows (Linux,
too), since it uses native UI widgets on each platform. They even have
tools to design your visual classes interactively.

Check it out at http://dabodev.com.
-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Over my head with descriptors

2006-12-16 Thread Christian Kastner
Sarcastic Zombie wrote:
 Code included below.
 
 Basically, I've created a series of question descriptors, which each
 hold a managed value. This is so I can implement validation, and render
 each field into html automatically for forms.
 
 My problem is this: every instance of my wizard class has unique self
 values, but they share the exact same descriptor values.

That's because descriptors only work as class attributes, not instance
attributes.

 Meaning, if
 
 t = Test(ar)
 y = Test(ar)
 
 t is y
 False
 
 t.age is y.age
 True

As an attribute of the owner class, the descriptor is instantiated once
for the class itself, and not for every instance of the owner class:

class Foo(object):

# Class attribute
desc = Descriptor()

def __init__(self, value):
# Instance attributes go here
self.value = somevalue

 Code below. What am I not understanding?
 -
...
 class Question(object):
...
   def __get__(self, instance, owner):
   return self

If you want to do per-instance stuff, use the instance argument:

# Warning: simplified
class Descriptor(object):
def __get__(self, instance, owner):
return instance._desc

def __set__(self, instance, value):
instance._desc = value

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


Dictionary, iterate update objects

2006-12-16 Thread jansenh
hi comp.lang.python.

I need some newbe advice on idiomatic use of Python dictionaries.

I have service with a dictionary which holds a bunch of objects as
values, and an ID as key to each object. Then I want to change an
objects state based on its key. The way I am doing this now is by using
'fromkeys' and copying my object over in a temporary dictionary, then
manipulating the object, and then I do an 'update' back to the main
dictionary..  :-0

There has to be a smarter way? Thankful for any piece of
enlightenment...

regards, Henning

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


Re: Over my head with descriptors

2006-12-16 Thread Christian Kastner
Tim Roberts wrote:
 Sarcastic Zombie [EMAIL PROTECTED] wrote:
 Code included below.

 Basically, I've created a series of question descriptors, which each
 hold a managed value. This is so I can implement validation, and render
 each field into html automatically for forms.

 My problem is this: every instance of my wizard class has unique self
 values, but they share the exact same descriptor values.

 ...
 class Test(Wizard):
  grouping = [
  [ 'age', 'weight' ],
  [ 'feet', 'inches' ],
  ['name', 'cash', 'fav_color', 'happy', 'birthday'] ]

  def __new__(self):
  age = Q_Integer(Your Age:, age, 99)
  weight = Q_Integer(Your Weight:, weight, 200)
  feet = Q_Integer(Feet tall:, feet, 6)
  inches = Q_Integer(Inches Tall:, inches, 0)
  name = Q_Chars(Your Name:, name, max_length=15, 
 required=True)
  cash = Q_Float(Money in hand?, cash, required=True,
 default=55.50)
  fav_color = Q_Chars(Your favorite color?, fav_color,
 required=True, max_length=50, choices=C_CHOICES)
  homezip = Q_Zip(Your zip code?, homezip, required=True, )
  happy = Q_Bool(Are you happy?, happy, default=False)
  birthday = Q_Date(Your Birthday:, birthday)
 
 The __new__ method is called with the CLASS as its first argument, not the
 new instance.  __new__ is supposed to RETURN the new instance.  So, when
 you set age, you are setting a CLASS attribute that will be shared by all
 instances.

As long as age really is set on the class. In the code above, age is
just a local variable.

 Is there a reason you don't just use __init__ instead of __new__, and use
 self.age and self.weight and so on?

I was asking myself the same thing...

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


Re: How Micro-pump will change the future of computer/ mobile chips.

2006-12-16 Thread Jim Granville
[EMAIL PROTECTED] wrote:
 How Micro-pump will change the future of computer/ mobile chips.

FAR more hype than practical solution
Sorry guys, this will not change the future of computer/ mobile chips.

 Engineers at Purdue University have developed a tiny micro-pump
 cooling device small enough to fit on a computer chip that circulates
 coolant through channels etched into the chip.   . For
 detail
 http://www.studyandjobs.com/Micro_pump.html
 
 or 
 http://www.studyandjobs.com/IT_study.htm

..ahh, up goes the spam-meter

-jg

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


Re: Is there a way to push data into Microsoft Excel Word from Python ?

2006-12-16 Thread Caleb Hattingh

The Night Blogger wrote:
 Is there a way to push data to Microsoft Excel  Word from a Python
 Application

On Windows, it's easy after you install the win32 extensions.  For
example, for
python:

import win32com.client
xl = win32com.client.Dispatch('Excel.Application')

after which you can operate on xl (almost) as if you were coding in
VBA.   I have driven Excel from python a /lot/, and it works well.
Paul Boddie has written a great tutorial---which includes some Outlook
examples, btw---over here:

http://thor.prohosting.com/~pboddie/Python/COM.html

 Is this a cross platform feature ? I'll need to push data on MS Windows 
 Mac OS X 

I have zero OSX experience, but 30s of googling brings up this:

http://appscript.sourceforge.net/

Kevin Walzer mentions on this mailing list entry:

http://mail.python.org/pipermail/python-list/2006-August/400255.html

that Excel provides reasonably good support for applescript, but again,
I have no idea whether these things work; I'm just doing your googling
for you.

Assuming applescript works, you may want to write a thin wrapper over
the combination of the win32 COM interface and the applescript
interface that at least lets your business logic sit in one place.  The
wrapper can use the right API depending on the platform it finds itself
on at runtime.

Regards
Caleb

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


Re: How Micro-pump will change the future of computer/ mobile chips.

2006-12-16 Thread Donald
Jim Granville wrote:
 [EMAIL PROTECTED] wrote:
 
 How Micro-pump will change the future of computer/ mobile chips.
 
 
 FAR more hype than practical solution
 Sorry guys, this will not change the future of computer/ mobile chips.
 
 Engineers at Purdue University have developed a tiny micro-pump
 cooling device small enough to fit on a computer chip that circulates
 coolant through channels etched into the chip.   . For
 detail
 http://www.studyandjobs.com/Micro_pump.html

 or http://www.studyandjobs.com/IT_study.htm
 
 
 ..ahh, up goes the spam-meter
 
 -jg
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Roundtrip SQL data especially datetime

2006-12-16 Thread Carsten Haese
On Sat, 2006-12-16 at 20:48 +, John Nagle wrote:
  The SourceForge page
 
http://sourceforge.net/project/showfiles.php?group_id=22307
 
 says
 
 MySQL versions 3.23-5.0; and Python versions 2.3-2.4 are supported.
 
 Last release was April, 2006.  There's no binary for Python 2.5 yet.
 [...]
   So users should hold off from using Python 2.5 in production
 database applications.

This may come as a shock to you, but MySQL is not the only database
engine on the planet. Your recommendation may apply to MySQL, but it is
not true for all databases in general. I can name at least two examples
(Informix and Oracle) of database engines that are supported under
Python 2.5, and if I were less lazy I could probably find more.

-Carsten


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


Re: Has comparison of instancemethods changed between python 2.5 and 2.4?

2006-12-16 Thread Frank Niessink
Ziga Seilnacht:
 This method was changed in Python 2.5. Previously, two instancemethods
 compared equal if their im_self attributes were *identical* and their
 im_func attributes were equal. Now, they compare equal if their im_self
 attributes are *equal* and their im_func attributes are equal. 

Thanks Ziga, that explains very clearly why I get the behavior I see.

 If you think this is a bug, you should report it to the bugtracker:
 http://sourceforge.net/bugs/?group_id=5470

Well, from where I am it sure feels like a bug in python, so I've 
submitted a bug report: 
http://sourceforge.net/tracker/index.php?func=detailaid=1617161group_id=5470atid=105470

Thanks for your help, Frank
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictionary, iterate update objects

2006-12-16 Thread Caleb Hattingh

jansenh wrote:
 hi comp.lang.python.

 I need some newbe advice on idiomatic use of Python dictionaries.

 I have service with a dictionary which holds a bunch of objects as
 values, and an ID as key to each object. Then I want to change an
 objects state based on its key. The way I am doing this now is by using
 'fromkeys' and copying my object over in a temporary dictionary, then
 manipulating the object, and then I do an 'update' back to the main
 dictionary..  :-0

It would be easier to help if you post a short snippet of code that
demonstrates the essence of the issue, but I made an attempt at coding
what you describe:

 d = {}
 class o(object):
... def __init__(self):
... self.x = 0
...
 i = o()
 d[12345]=i
 temp=d[12345]
 temp.x = 5
 d[12345].x
5
 i.x
5


After I assign the object to the dict with ID=12345, I can easily get
the object by its key and manipulate its state.  The last 4 lines show
that the state changed for all the active references to the created
object.   Is this what you wanted?

If you are this Henning Jansen:

http://www.henning-jansen.com/

you may get a lot much more accurate help from others in this group by
mentioning that you have some Ruby experience.   That way, the guys in
here who also know Ruby (not me :) can quickly point out the
differences in behaviour for your specific question.

Regards
Caleb

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


inquiry about installing Python 2.5

2006-12-16 Thread mirandacascade
Apologies in advance for what I'm sure seems like a trivial question.

Operating system: Win XP
Current version of Python: 2.4

If possible, I would like to have both Python 2.4 and Python 2.5
installed on my workstaiton.  I downloaded the .msi for Python 2.5 from
the python.org site. If I run the 2.5 installer, will it give me the
option of keeping Python 2.4 installed on my workstation?

Thank you.

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


Re: Dictionary, iterate update objects

2006-12-16 Thread jansenh
Hi and thanx!

Caleb Hattingh wrote:

  temp=d[12345]
  temp.x = 5

 After I assign the object to the dict with ID=12345, I can easily get
 the object by its key and manipulate its state.  The last 4 lines show
 that the state changed for all the active references to the created
 object.   Is this what you wanted?

Yes.
[... the temp object is by ref, and any manipulation of the temp object
is to the object itself..? It really simplifies my first attempt]



 If you are this Henning Jansen:
 http://www.henning-jansen.com/

Yes, this is me  :-/   and I have a little Ruby experience. And I will
create a sample snippet the next time I pop a question. Thank you for a
clear and helpful response.

regards, Henning

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


Re: inquiry about installing Python 2.5

2006-12-16 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
 If possible, I would like to have both Python 2.4 and Python 2.5
 installed on my workstaiton.  I downloaded the .msi for Python 2.5 from
 the python.org site. If I run the 2.5 installer, will it give me the
 option of keeping Python 2.4 installed on my workstation?

Yes; you can run both versions just fine. The only question is which
of these gets the .py association: it is the one that gets installed
last. You can chose not to update the .py association when installing
2.5, then .py remains associated with 2.4.

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


Re: inquiry about installing Python 2.5

2006-12-16 Thread Michel Claveau
Hi!

For Python only, it's possible.
But, if you add Pywin32... problem!

-- 
@-salutations

Michel Claveau


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


Re: textwrap.dedent replaces tabs?

2006-12-16 Thread CakeProphet
Hmmm... a quick fix might be to temporarily replace all tab characters
with another, relatively unused control character.

MyString = MyString.replace(\t, chr(1))
MyString = textwrap.dedent(MyString)
MyString = MyString.replace(chr(1), \t)

Of course... this isn't exactly safe, but it's not going to be fatal,
if it does mess something up. As long as you don't expect receiving any
ASCII 1 characters.

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


Re: Need Simple Way To Determine If File Is Executable

2006-12-16 Thread Gabriel Genellina
On 16 dic, 04:47, Tim Roberts [EMAIL PROTECTED] wrote:
os.stat(selected)[ST_MODE]  (S_IXUSR|S_IXGRP|S_IXOTH

This will tell you that x.exe is executable, even if x.exe contains
 nothing but zeros.

Isn't the same with any other recipe, portable or not? Unless the OS
actually tries to load and examine the file contents, which the OS's
I'm aware of, don't do.

-- 
Gabriel Genellina

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


Re: merits of Lisp vs Python

2006-12-16 Thread Paul Rubin
Raffael Cavallaro [EMAIL PROTECTED]'espam-s'il-vous-plait-mac.com writes:
  It never occurs to Lisp programmers that Lisp, too, might be a Blub.
 
 Of course it does - Thats why we try ocaml and haskell etc. It's just
 that we don't see the useful features of these languages as being
 sufficiently useful to compensate for their lack of the ability to
 easily do syntactic abstractions over a uniform syntax. 

That sounds to me like a Blub programmer speaking.

 For example, a common lisp with optional static typing on demand would
 be strictly more expressive than common lisp. But, take say, haskell;
 haskell's static typing is not optional (you can work around it, but
 you have to go out of your way to do so); haskell's pure functional
 semantics are not optional (again, workarounds possible to a limited
 extent). This requires you to conceive your problem solution (i.e.,
 program) within the framework of a particular paradigm. This lock-in
 to a particular paradigm, however powerful, is what makes any such
 language strictly less expressive than one with syntactic abstraction
 over a uniform syntax.

Incorrect, I believe.  The above is like saying Lisp's lack of
optional manual storage allocation and machine pointers makes Lisp
less powerful.  It's in fact the absence of those features that lets
garbage collection work reliably.  Reliable GC gets rid of a large and
important class of program errors and makes possible programming in a
style that relies on it.  You can make languages more powerful by
removing features as well as by adding them.  This is what Haskell
does, with its functional purity.  Haskell's lazy evaluation semantics
pretty much depend on the purity.

See also SPJ's papers on composable memory transactions in Haskell:

  http://research.microsoft.com/~simonpj/papers/stm/index.htm

These transactions rely on Haskell's pure functional semantics and if
I understand correctly, can't be implemented reliably without it.  And
just like GC gets rid of a large class of pointer and storage
allocation errors, composable transactions in concurrent programs get
rid of lock-related errors, traditionally a huge source of problems in
real-world code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Roundtrip SQL data especially datetime

2006-12-16 Thread John Machin

Carsten Haese wrote:
 On Sat, 2006-12-16 at 20:48 +, John Nagle wrote:
   The SourceForge page
 
 http://sourceforge.net/project/showfiles.php?group_id=22307
 
  says
 
  MySQL versions 3.23-5.0; and Python versions 2.3-2.4 are supported.
 
  Last release was April, 2006.  There's no binary for Python 2.5 yet.
  [...]
So users should hold off from using Python 2.5 in production
  database applications.

 This may come as a shock to you, but MySQL is not the only database
 engine on the planet. Your recommendation may apply to MySQL, but it is
 not true for all databases in general. I can name at least two examples
 (Informix and Oracle) of database engines that are supported under
 Python 2.5, and if I were less lazy I could probably find more.

Not sure if sqlite qualifies as an engine, but it works just fine
with Python 2.5. Heck, it's even supplied in the standard python.org
distribution, Windows DLL and all and all ...

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


Re: Is there a way to push data into Microsoft Excel Word from Python ?

2006-12-16 Thread John Machin

The Night Blogger wrote:
 Is there a way to push data to Microsoft Excel  Word from a Python
 Application

 Is this a cross platform feature ? I'll need to push data on MS Windows 
 Mac OS X 

Depends on what you mean by push. If you wish to create Excel files
but not update existing ones, you might consider pyExcelerator. It is
pure Python and therefore will run on any platform that Python will.
http://cheeseshop.python.org/pypi/pyExcelerator/

Cheers,
John

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


Re: Is there a way to push data into Microsoft Excel Word from Python ?

2006-12-16 Thread Paul Boddie
Caleb Hattingh wrote:
 Paul Boddie has written a great tutorial---which includes some Outlook
 examples, btw---over here:

 http://thor.prohosting.com/~pboddie/Python/COM.html

Thanks for the kind words! The most current location of this tutorial
is here:

http://www.boddie.org.uk/python/COM.html

I don't use Windows any more, but I suppose it's still relevant to at
least some people.

Paul

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


wxPython help please

2006-12-16 Thread Jive Dadson
I hope someone can help me with a couple of wxPython questions, or point 
me to the right newsgroup for the questions.

I am trying to modify the floatcanvas demo program.  I want to load an 
image from a file (jpg or whatever), then do a kind of color-picker 
action on it.

I haven't tried yet to figure out how to load the file.  Just for 
starters, when I click on the canvas, I want to get the rgb pixel value 
for the point under the cursor.  I can't for the life of me figure out 
how to do it.  I suppose it begins with event.GetPosition(), but after 
that I am at a loss.

The larger question is how to use wxPython.  It's got such fabulous 
stuff, but every time I try to do anything with it, I eventually give up 
  because I can't find adequate documentation.  I know very little about 
graphics programming.

Please respond here.  Because of spammers, the email address is fake.

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


Re: catching exceptions

2006-12-16 Thread Steven D'Aprano
On Sat, 16 Dec 2006 05:24:28 -0800, [EMAIL PROTECTED] wrote:

  Hi, In the following program, I have a class Test which has a property
  x. Its setx function gets a string value and converts it into a float
  and stores into it.

 [snip code]

 Python isn't Java. Are you sure you need properties?
 
 I do not know Java. But, object.x = value looks much better than
 object.set_x(value) . Is there any harm in doing it, provided I have to
 do more than just storing the value.

Why write set_x in the first place if all it does is set x? Why not just
have an attribute x and just write obj.x = value? What advantage are you
gaining?

One good use of properties is when you need attribute x to be calculated
on the fly. But there are costs as well: accessing a property is more
expensive than just accessing an attribute (accessing a property means
that not only do you access an attribute, but you also run a method). That
might not matter if your getter and setter are simple enough. Another cost
is that you have to write the code in the first place, and then you
have to test it: your class becomes bigger and more complicated. One
reason why getters and setters are looked at suspiciously is that in the
Java world, they frequently lead to bloated code. If you gain no benefit
from that complexity, why pay for it?

I'm not telling you don't use properties -- I'm merely telling you to
think about why you are using getters and setters in the first place, and
be sure that you are gaining benefit from them.

I'm suspicious about your example, because your getter simply looks up a
private attribute and returns it. Your setter does barely more work: it
calls float. I'm guessing that your intention is to try to ensure that
obj.x is only ever a float. But Python isn't designed for that sort of
strong type checking. It is very, very hard (possibly impossible) to
ensure calling code can't abuse your classes, and type-checking languages
only protect against one small set of potential abuse anyway. The usual
Python philosophy is not to bother, and instead rely on good unit testing
to test for all bugs, not just type bugs.

Your class as a tool. All tools can be used or misused. It isn't the
responsibility of the tool to protect you from misusing the tool (because
it can't, even if you wanted it to -- the best it can do is protect you
from some misuses). It is the responsibility of whoever uses the tool to
not misuse it.

In practice, what that often (but not always) means is that if you have an
attribute x that needs to be a float, your class is entitled to assume it
will always be a float, and the code that uses your class is responsible
for making sure that it never stuffs a non-float into x. If it does,
that's a bug in the caller, not in your class, and is best caught by unit
testing.

(But does x really need to be a float? Maybe it only needs to be an object
that acts like a float.) 

That's just something for you to think about.



-- 
Steven.

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


Re: Package vs. module

2006-12-16 Thread Gabriel Genellina
On 16 dic, 12:28, Stuart D. Gathman [EMAIL PROTECTED] wrote:

 NOW, this is all very nice and modular. BUT, the original module was a
 single file, which could be run as a script as well as imported as a
 module. The script features provided useful command line functionality.
 (Using if __name__ == '__main__':).  Now that 'spf' is a package, the
 command line feature is gone!  Even using -m, I get:

Yes, a little sacrifice...

 Looking at getpass.py as advised, I see they put all the drivers in the
 module.  I could do that with spf.py, I suppose.  But I like how with the
 package, the driver code is not loaded unless needed.

That's good.

 One other idea I had was an arrangement like this:

 SPF/
   pydns.py
   dnspython.py

 spf.py

 This would keep the module as a single file usable from the command line,
 but still make driver available as separately loaded modules.

 So which of the three options,

 1) single file module with all drivers, ala getpass
You've already seen that it's not a good option. getpass is different
in the sense that only one version should be available in a given
system, so it keeps trying alternatives until a candidate is found.

 2) package that cannot be run directly from command line
 3) single file module with associated driver package

I think that keeping demo/application code separate from the library
would be a good thing.
So, keep your library inside a package, and provide some external
scripts as example, demo, whatever.
You can instruct distutils to install each thing in the right place.

-- 
Gabriel Genellina

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


Re: catching exceptions

2006-12-16 Thread Gabriel Genellina
On 16 dic, 10:24, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
  Python isn't Java. Are you sure you need properties?

 I do not know Java. But, object.x = value looks much better than
 object.set_x(value) . Is there any harm in doing it, provided I have to
 do more than just storing the value.

You've provided the answer: properties are OK if you need to do more
that just store the value. Else, they're a waste of programmer and
processor time.
That was not clear on your original post.

-- 
Gabriel Genellina

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


Re: merits of Lisp vs Python

2006-12-16 Thread greg
Ken Tilton wrote:

 How does a generic engine that sees only a solution (a 
 list of mathematical expressions and for each the transformations, 
 results, and opnds logged by individual TF functions) build up this 
 environment such that it has named attributes such as signed-value?

How did your macro know that the user's reverse function
needed a signed_value parameter in that particular case?

 Assume that it can examine all those opnds and results looking
 for tagged values such that it then knows the name of those values
 that have been named.

You might be able to handle this using a general method
that searches the tree for a specified tag, e.g.

env.find_tag(signed_value)

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


Re: wxPython help please

2006-12-16 Thread Sandra-24
Try the wxPython mailing list, which you can find on their site. And
the best wxPython reference is the book (also available as an e-book)
by Robin Dunn, who created wxPython. Seeing wxPython from his
perspective is well worth the money. If I recall correctly he devoted
an entire chapter to drawing with a canvas widget.

-Sandra

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


How to test if two strings point to the same file or directory?

2006-12-16 Thread Sandra-24
Comparing file system paths as strings is very brittle. Is there a
better way to test if two paths point to the same file or directory
(and that will work across platforms?)

Thanks,
-Sandra

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


Re: wxPython help please

2006-12-16 Thread Jive Dadson
Sandra-24 wrote:
 Try the wxPython mailing list, which you can find on their site. And
 the best wxPython reference is the book (also available as an e-book)
 by Robin Dunn, who created wxPython. Seeing wxPython from his
 perspective is well worth the money. If I recall correctly he devoted
 an entire chapter to drawing with a canvas widget.
 
 -Sandra
 

Thanks. I'll give it a look see.

You understand that what I want to do is get the pixel that's under the 
cursor when I click, right?  I don't really need to draw things, only 
load an image from a file.  But since this program already did so much 
of what I wanted, I decided to try it.  It is frustrating that after a 
couple of hours I still can't figure out how to read a danged pixel.

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


Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Tim Chase
 Comparing file system paths as strings is very brittle. Is there a
 better way to test if two paths point to the same file or directory
 (and that will work across platforms?)

os.path.samefile(filename1, filename2)
os.path.sameopenfile(fileobject1, fileobject2)

-tkc



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


Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Steven D'Aprano
On Sat, 16 Dec 2006 17:02:04 -0800, Sandra-24 wrote:

 Comparing file system paths as strings is very brittle.

Why do you say that? Are you thinking of something like this?

/home//user/somedirectory/../file
/home/user/file

Both point to the same file.

 Is there a
 better way to test if two paths point to the same file or directory
 (and that will work across platforms?)

How complicated do you want to get? If you are thinking about aliases,
hard links, shortcuts, SMB shares and other complications, I'd be
surprised if there is a simple way.

But for the simple case above:

 import os
 path = '/home//user/somedirectory/../file'
 os.path.normpath(path)
'/home/user/file'



-- 
Steven.

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


Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread John Machin

Tim Chase wrote:
  Comparing file system paths as strings is very brittle. Is there a
  better way to test if two paths point to the same file or directory
  (and that will work across platforms?)

   os.path.samefile(filename1, filename2)
   os.path.sameopenfile(fileobject1, fileobject2)
 

Nice try, but they don't work across platforms.

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


Re: wxPython help please

2006-12-16 Thread Jive Dadson
Sandra-24 wrote:
 Try the wxPython mailing list, which you can find on their site. And
 the best wxPython reference is the book (also available as an e-book)
 by Robin Dunn, who created wxPython. Seeing wxPython from his
 perspective is well worth the money. If I recall correctly he devoted
 an entire chapter to drawing with a canvas widget.
 
 -Sandra
 


I bought the ebook.  Searching for pixel, all I came up with was a 
method called GetPixel in a device context.  I know there must be a 
device context buried in there somewhere, so now I need to winkle it out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Tim Chase
 Comparing file system paths as strings is very brittle.
 
 Why do you say that? Are you thinking of something like this?
 
 /home//user/somedirectory/../file
 /home/user/file

Or even

~/file

 How complicated do you want to get? If you are thinking about aliases,
 hard links, shortcuts, SMB shares and other complications, I'd be
 surprised if there is a simple way.
 
 But for the simple case above:
 
 import os
 path = '/home//user/somedirectory/../file'
 os.path.normpath(path)
 '/home/user/file'

I'd suggest os.path.samefile which should handle case-sensitive 
(non-win32) vs case-insensitive (win32) filenames, soft-links, 
and hard-links.  Not sure it's prescient enough to know if you 
have two remote shares, it will unwind them to their full 
server-path name.  Works here on my various boxes (Linux, MacOS-X 
and OpenBSD) here.  I'd assume it's the same functionality on Win32.

-tkc




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


Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Steven D'Aprano
On Sun, 17 Dec 2006 12:30:15 +1100, Steven D'Aprano wrote:

 Is there a
 better way to test if two paths point to the same file or directory
 (and that will work across platforms?)
 
 How complicated do you want to get? If you are thinking about aliases,
 hard links, shortcuts, SMB shares and other complications, I'd be
 surprised if there is a simple way.

Almost, but not quite, platform independent.

os.path.samefile(path1, path2)

From the docs:

samefile(path1, path2)
Return True if both pathname arguments refer to the same file or
directory (as indicated by device number and i-node number). Raise an
exception if a os.stat() call on either pathname fails. Availability:
Macintosh, Unix

http://docs.python.org/lib/module-os.path.html


-- 
Steven.

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


Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Tim Chase
 Comparing file system paths as strings is very brittle. Is there a
 better way to test if two paths point to the same file or directory
 (and that will work across platforms?)
  os.path.samefile(filename1, filename2)
  os.path.sameopenfile(fileobject1, fileobject2)
 
 Nice try, but they don't work across platforms.

Okay...double-checking the docs.python.org writeup, it apparently 
does work across platforms (Mac  Unix), just not across *all* 
platforms, with Win32 being the obvious outlier.  It seems a 
strange omission from Win32 python, even if it were filled in 
with only a stub...something like

def samefile(f1, f2):
return abspath(f1.lower()) == abspath(f2.lower())

it might not so gracefully handle UNC-named files, or SUBST'ed 
file-paths, but at least it provides an attempt at providing the 
functionality on win32.  As it currently stands, it would be 
entirely too easy for a [Mac|*nix] programmer to see that there's 
a samefile() function available, use it successfully based on its 
docstring, only to have it throw an exception or silently fail 
when run on win32.

-tkc



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


  1   2   >