Re: ActiveRecord for Python/MySQL

2007-08-26 Thread EuGeNe Van den Bulke
Devraj wrote:
> My application uses MySQL as a backend and am using the MySQL/Python
> bindings. Are there any libraries that provide a database abstraction
> layer like Activerecords for Python?'

SQLObject
SQLAclhemy
DejaVu
Storm

Google for Python ORM you may find more!

EuGeNe -- http://www.3kwa.com
-- 
http://mail.python.org/mailman/listinfo/python-list


A online python decompiler

2007-08-26 Thread shi wu
depython [http://www.depython.net depython online service] could decompile
python bytecodes. Depython  online service supports Python versions
from 2.4up to
2.5.You can freely test its function online.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ActiveRecord for Python/MySQL

2007-08-26 Thread Devraj
Thanks

On Aug 26, 5:26 pm, EuGeNe Van den Bulke
<[EMAIL PROTECTED]> wrote:
> Devraj wrote:
> > My application uses MySQL as a backend and am using the MySQL/Python
> > bindings. Are there any libraries that provide a database abstraction
> > layer like Activerecords for Python?'
>
> SQLObject
> SQLAclhemy
> DejaVu
> Storm
>
> Google for Python ORM you may find more!
>
> EuGeNe --http://www.3kwa.com


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


Re: Making a file-like object for manipulating a large file

2007-08-26 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Sean Davis
wrote:

> I have a VERY large file that I would
> like to load a line at a time, do some manipulations on it, and then
> make it available to as a file-like object for use as input to a
> database module (psycopg2) that wants a file-like object (with read
> and readlines methods).  I could write the manipulated file out to
> disk and then read it back in, but that seems wasteful.

If your consumer doesn't need to seek, how about having it read from a pipe?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: expat error, help to debug?

2007-08-26 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Andreas Lobinger wrote:

> Anyone any idea where the error is produced?

Do you want to try adding an EndElementHandler as well, just to get more
information on where the error might be happening?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Regular Expresions to change .htm to .php in files

2007-08-26 Thread Mark
On Thu, 23 Aug 2007 12:27:10 -0700, Tobiah wrote:
> sed "s/.htm/.php/g" < $each > /tmp/$$

This line should be:

sed "s/\.htm$/.php/g" < $each > /tmp/$$

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


Re: Python error on Mac

2007-08-26 Thread Graham Dumpleton
On Aug 26, 12:58 pm, Clover <[EMAIL PROTECTED]> wrote:
> When trying to do some things on my Mac (starting Lyx, compiling Latex
> via TextMate) I get this error:
>
> python: execv:
> /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python:
> No such file or directory
>
> I (and people on Lyx and TextMate lists) are at a complete loss as to
> why this is happening. I didn't (at least intentionally) fiddle with
> Python setup.

The default operating system supplied version of Python on recent
versions of MacOS X is 2.3.5. Unless you have specifically installed
2.5, it will not exist. So, if those applications have it hardwired to
use Python 2.5 they will not work.

Graham

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


Re: Need a better understanding on how MRO works?

2007-08-26 Thread Steven W. Orr
On Saturday, Aug 25th 2007 at 22:14 -0700, quoth Alex Martelli:

=>Steven W. Orr <[EMAIL PROTECTED]> wrote:

=>> * Also, I'd like to understand what the difference is between 
=>> nclass = new.classobj(name,(D1,),globals())
=>> vs. 
=>> def classfactory():
=>>   class somename(object):
=>>   def somestuff():
=>>   pass
=>> return somename
=>> G1 = classfactory()
=>> globals()[name] = G1
=>> 
=>> Does new.classobj do anything special?
=>
=>No, new.classobj does essentially the same thing that Python does after
=>evaluating a class statement to prepare the class's name, bases and
=>dictionary: finds the metaclass and calls it with these arguments.
=>
=>A key difference of course is that a class statement prepares the class
=>dictionary as a new, ordinary, distinct dictionary, while new.classobj
=>accepts whatever dictionary you give it (so you can, though shouldn't,
=>do strange things such as pass globals()...:-).

In fact, I wanted to make a common routine that could be called from 
multiple modules. I have classes that need to be created from those 
multiple modules. I did run into trouble when I created a common routine 
even though I passed globals() as one of the args. The """though 
shouldn't""" is prompting me to ask why, and where I might be able to read 
more.

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I use python for file processing

2007-08-26 Thread Ricardo Aráoz
Marc 'BlackJack' Rintsch wrote:
> On Sun, 26 Aug 2007 06:05:11 +, [EMAIL PROTECTED] wrote:
> 
>> I am trying to use python for file processing.
>> Suppose I have a file like this:
>> I want to build a Hashmap between the line "begin_QOS_statistics" and
>> "end_QOS_statistics"
>> and for each line I want to put the first text as the key of the hash
>> table and the second text as the value.
> 
> Work through the tutorial, experiment a little in the interactive
> interpreter and then just do it.  You need to `open()` the file, iterate
> over its lines in a ``for``-loop, decide to when it is time to start
> processing lines, and then `str.split()` the lines and put them into a
> `dict()`.  This is a neat little project to start learning the language.
> 
> Ciao,
>   Marc 'BlackJack' Rintsch

Just posted this on Python Tutor, might give you a start :

nameFile = open(r'/path/to/file.txt', 'rU')
phonebook = {}

for line in nameFile :
phonebook.setdefault(line[0].upper(), []).append(line.strip('\n'))

for item, names in phonebook.iteritems() :
names.sort()

print phonebook

HTH

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


wxpython on FreeBSD 6.2 broken

2007-08-26 Thread Michael S
Good day all,

I was wondering if anyone was using the latest
wxpython on FreeBSD 6. I just installed it yesterday
as well as wxGlade. wxGlade doesn't function properly
- it does not display any controls. I then tried some
simple examples from the web and half of them don't
work.

Anyone aware of this?
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Kinterbasdb needs new maintainer

2007-08-26 Thread DarkBlue
Sorry to interrupt the regular programming here .

As has been reported on some websites the
maintainer of kinterbasdb David Rushby has died
last month after a diving accident.

Kinterbasdb is the python wrapper around the Firebird
database api and an excellent opensource project.

The hope is , that this message will reach someone
in the opensource developer community , who is willing
to step up and continue the great work done by David .


Thank you

http://www.firebirdnews.org/?p=1252
http://kinterbasdb.sourceforge.net/

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


Re: Joining Big Files

2007-08-26 Thread vasudevram
On Aug 26, 6:48 am, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Aug 25, 8:15 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 25, 4:57 am, mosscliffe <[EMAIL PROTECTED]> wrote:
>
> > > I have 4 text files each approx 50mb.
>
> >  50mb? Really?  Did you actually try this and find out it was a
> > problem?
>
> > Try this:
> > import time
>
> > start = time.clock()
> > outname = "temp.dat"
> > outfile = file(outname,"w")
> > for inname in ['file1.dat', 'file2.dat', 'file3.dat', 'file4.dat']:
> > infile = file(inname)
> > outfile.write( infile.read() )
> > infile.close()
> > outfile.close()
> > end = time.clock()
>
> > print end-start,"seconds"
>
> > For 4 30Mb files, this takes just over 1.3 seconds on my system.  (You
> > may need to open files in binary mode, depending on the contents, but
> > I was in a hurry.)
>
> > -- Paul
>
> My bad, my test file was not a text file, but a binary file.
> Retesting with a 50Mb text file took 24.6 seconds on my machine.
>
> Still in your working range?  If not, then you will need to pursue
> more exotic approaches.  But 25 seconds on an infrequent basis does
> not sound too bad, especially since I don't think you will really get
> any substantial boost from them (to benchmark this, I timed a raw
> "copy" command at the OS level of the resulting 200Mb file, and this
> took about 20 seconds).
>
> Keep it simple.
>
> -- Paul

There are (at least) another couple of approaches possible, each with
some possible tradeoffs or requirements:

Approach 1. (Least amount of code to write - not that the others are
large :)

Just use os.system() and the UNIX cat command - the requirement here
is that:
a) your web site is hosted on *nix (ok, you can do it if on Windows
too - use copy instead of cat, you might have to add a "cmd /c "
prefix in front of the copy command, and you have to use the right
copy command syntax for concatenating multiple input files into one
output file).

b) your hosting plan allows you to execute OS level commands like cat,
and cat is in your OS PATH (not PYTHONPATH). (Similar comments apply
for Windows hosts).

import os
os.system("cat file1.txt file2.txt file3.txt file4.txt >
file_out.txt")

cat will take care of buffering, etc. transparently to you.

Approach 2: Read (in a loop, as you originally thought of doing) each
line of each of the 4 input files and write it to the output file:

("Reusing" Paul McGuire's code above:)

outname = "temp.dat"
outfile = file(outname,"w")
for inname in ['file1.dat', 'file2.dat', 'file3.dat', 'file4.dat']:
infile = file(inname)
for lin in infile:
outfile.write(lin)
infile.close()
outfile.close()
end = time.clock()

print end-start,"seconds"

# You may need to check that newlines are not removed in the above
code, in the output file.  Can't remember right now. If they are, just
add one back with:

outfile.write(lin + "\n") instead of  outfile.write(lin) .

( Code not tested, test it locally first, though looks ok to me. )

The reason why this _may_ not be much slower than manually coded
buffering approaches, is that:

a) Python's standard library is written in C (which is fast),
including use of stdio (the C Standard IO library, which already does
intelligent buffering)
b) OS's do I/O buffering anyway, so do hard disk controllers
c) from some recent Python version, I think it was 2.2, that idiom
"for lin in infile" has been (based on somethng I read in the Python
Cookbook) stated to be pretty efficient anyway (and yet (slightly)
more readable that earlier followed approaches of reading a text
file).

Given all the above facts, it probably isn't worth your while to try
and optimize the code unless and until you find (by measurements) that
it's too slow - which is a good practice anyway:

http://en.wikipedia.org/wiki/Optimization_(computer_science)

Excerpt from the above page (its long but worth reading, IMO):

"Donald Knuth said, paraphrasing Hoare[1],

"We should forget about small efficiencies, say about 97% of the time:
premature optimization is the root of all evil." (Knuth, Donald.
Structured Programming with go to Statements, ACM Journal Computing
Surveys, Vol 6, No. 4, Dec. 1974. p.268.)

Charles Cook commented,

"I agree with this. It's usually not worth spending a lot of time
micro-optimizing code before it's obvious where the performance
bottlenecks are. But, conversely, when designing software at a system
level, performance issues should always be considered from the
beginning. A good software developer will do this automatically,
having developed a feel for where performance issues will cause
problems. An inexperienced developer will not bother, misguidedly
believing that a bit of fine tuning at a later stage will fix any
problems." [2]
"

HTH
Vasudev
-
Vasudev Ram
http://www.dancingbison.com
http://jugad.livejournal.com
http://sourceforge.net/projects/xtopdf
-


-- 
http://mail.python.org/ma

my parser.py isn't imported

2007-08-26 Thread Torsten Bronger
Hallöchen!

I have a module parser.py in the same directory as the main module.
In the main module, I import "parser".  On Linux, this works as
expected, however on Windows, it imports the stdlib parser module.
sys.path[0] points to the directory of my parser.py in both cases.
What went wrong here?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a better understanding on how MRO works?

2007-08-26 Thread Alex Martelli
Steven W. Orr <[EMAIL PROTECTED]> wrote:
   ...
> =>accepts whatever dictionary you give it (so you can, though shouldn't,
> =>do strange things such as pass globals()...:-).
> 
> In fact, I wanted to make a common routine that could be called from 
> multiple modules. I have classes that need to be created from those 
> multiple modules. I did run into trouble when I created a common routine
> even though I passed globals() as one of the args. The """though 
> shouldn't""" is prompting me to ask why, and where I might be able to read
> more.

The dictionary you pass to new.classobj should be specifically
constructed for the purpose -- globals() will contains all sort of odds
and ends that have nothing much to do with the case.

You appear to be trying to embody lot of black magic in your "common
routine", making it communicate with its callers by covert channels; the
way you use globals() to give that routine subtle "side effects" (making
the routine stick entries there) as well as pass it an opaque,
amorphous, unknown blobs of input information, strongly suggests that
the magic is running away with you (a good general reference about that
is ).

"Explicit is better than implicit", "simple is better than complex",
etc, can be read by typing ``import this'' at an interactive Python
prompt.

The best book I know about the do's and don't's of large-scale software
architecture is Lakos' "Large-Scale C++ Software Design",
 -- very C++ specific, but even though some of the issues only apply
to C++ itself, many of its crucial lessons will help with large scale SW
architecture in just about any language, Python included.

What I had to say about the lures and pitfalls of black magic in Python
specifically is spread through the Python Cookbook 2nd edition (and, to
a lesser extent, Python in a Nutshell).


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


Re: Need a better understanding on how MRO works?

2007-08-26 Thread Steven D'Aprano
On Sun, 26 Aug 2007 07:55:39 -0400, Steven W. Orr wrote:

> In fact, I wanted to make a common routine that could be called from
> multiple modules. I have classes that need to be created from those
> multiple modules. I did run into trouble when I created a common routine
> even though I passed globals() as one of the args.

I'm thinking that you should cross out "even though" and insert 
"because" :-)

Perhaps I'm misunderstanding exactly what you're trying to accomplish, 
but if you want to call a routine (a function? class?) from multiple 
modules, the simplest way is the best: create the routine in one module, 
then import it into all the others.

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


lisper learning python, ... could you please comment my first python program?

2007-08-26 Thread neptundancer
Hi,
  to extend my skills, I am learning python. I have written small
program which computes math expression like "1+2*sin(y^10)/cos(x*y)"
and similar, so far only + - * / ^ sin con tan sqrt are supported. But
my program is quite inextensible, I have to change the code to add new
functions... Could some fellow experienced pythonista give me some
tips how to make my program shorter, and more extensible?

to use it, try something like compute("1+x+sin(x)", {"x" : 10}), the
second param is environment so variables like x or y are looked for
value here...

below is the code thanks for any tips!

- code here 


import sys
import string
import math

def normalize(string):
tmp = "".join([c for c in string if c != " "])
return "(" + tmp + ")"

def most_nested_expression(string):
start = index = 0
end = len(string) - 1
level = max_level = 0
most_nested = False
for c in string:
if c == "(":
level += 1
if level > max_level:
most_nested = True
max_level = level
start = index
elif c == ")":
level -= 1
if most_nested == True:
most_nested = False
end = index
index += 1
if level != 0:
raise IOError("mismatched parens")
if max_level == 0:
return (0, len(string), string)
else:
return (start + 1, end - start - 1, string[start + 1:end])

def is_reduced_expression(string):
for c in string:
if c == "^" or c == "*" or c == "/" or c == "+" or c == "-":
return False
return True

def find_first(string, operators):
positions = []
for op in operators:
pos = string.find(op)
if pos != -1:
positions += [pos]
if positions == []:
return None
else:
return min(positions)

def find_operator(string):
for ops in [["^"], ["*", "/"], ["+", "-"]]:
pos = find_first(string, ops)
if pos != None:
if string[pos + 1] == "+" or string[pos + 1] == "-":
return pos + 1
else:
return pos
return None

def left_operand(string, operator_pos):
left = None
operator = string[operator_pos]
candidates = [pos for pos in [string.rfind(op, 0, operator_pos)
  for op in ["(", ")", "^", "*", "/",
"+", "-"]]
  if pos != -1]
if candidates != []:
left = max(candidates)
if left == None:
if operator == "^" or operator == "*" or operator == "/":
raise IOError("invalid expression %s" % string)
else: # + or -
return ("0", operator_pos)
else:
if left + 1 == operator_pos:
if operator == "+" or operator == "-":
return ("0", left)
else:
raise IOError("invalid expression %s" % string)
else:
return (string[left + 1:operator_pos], left)

def right_operand(string, operator_pos):
right = None
candidates = [pos for pos in [string.find(op, operator_pos + 1)
  for op in ["(", ")", "^", "*", "/",
"+", "-"]]
  if pos != -1]
if candidates == []:
if operator_pos == len(string) - 1:
raise IOError("invalid expression %s" % string)
else:
return (string[operator_pos + 1:], len(string))
else:
right = min(candidates)
if operator_pos + 1 == right:
raise IOError("invalid expression %s" % string)
else:
return (string[operator_pos + 1:right], right)

def function_name(string, left_paren_pos):
candidates = [pos for pos in [string.rfind(op, 0, left_paren_pos)
  for op in ["(", "^", "*", "/", "+",
"-"]]
  if pos != -1]
if candidates == []:
return (None, None)
else:
left = max(candidates)
name = string[left + 1:left_paren_pos]
fun_names = ["sin", "cos", "tan", "sqrt"]

for f in fun_names:
if f == name:
return (left + 1, name)
return (None, None)

def reduce_step(string, index):
(left, exp_len, exp) = most_nested_expression(string)
#print "most nested %s" % exp
if is_reduced_expression(exp):
(left1, name) = function_name(string, left - 1)
if left1 != None:
return ((name, string[left:left + exp_len], None),
string[0:left1] + "$%s" % index + string[left +
exp_len + 1:],
True)
else:
return ((None, None, None), string[0:left - 1] + exp +
string[left + exp_len + 1:], False)
else:
operator_pos = find_operator(exp) + left
(left_op, left_mark) = left_operand(string, operator_pos)
(right_op, right_mark) = right_operand(string, operator_pos)
return ((string[operator_pos], left_op, right_op),
string[0

ANN: PyPE 2.8.6

2007-08-26 Thread Josiah Carlson

=== What is PyPE? ===
PyPE (Python Programmers' Editor) was written in order to offer a
lightweight but powerful editor for those who think emacs is too much
and idle is too little. Syntax highlighting is included out of the box,
as is multiple open documents via tabs.

Beyond the basic functionality, PyPE offers an expandable source tree,
filesystem browser, draggable document list, todo list, filterable
function list, find and replace bars (no dialog to find or replace simple
strings), recordable and programmable macros, spell checker,
reconfigurable menu hotkeys, triggers, find in files, external process
shells, and much more.

=== More Information ===

If you would like more information about PyPE, including screenshots,
where to download the source or windows binaries, bug tracker, contact
information, or a somewhat complete listing of PyPE's features, visit
PyPE's home on the web:

http://pype.sf.net/index.shtml

If you have any questions about PyPE, please contact me, Josiah Carlson,
aka the author of PyPE, at jcarlson at uci.edu (remember to include
"PyPE" in the subject).


PyPE 2.8.6 includes the following changes and bugfixes since release
2.8.5:

(fixed) a bug with "Wrap Try/Except" as per emailed bug report from Ian York.
(added) ability to choose what port PyPE will listen on via --port= .
(fixed) workspaces in wxPython 2.8+, patch thanks to Craig Mahaney.
(added) explicit exclude dirs for find in files, patch thanks to Craig Mahaney.
(added) paste and down mechanism to paste and move the cursor down, patch
thanks to Craig Mahaney.
(added) delete right mechanism to delete everything from the cursor to the end
of the line, patch thanks to Craig Mahaney.
(added) delete line mechanism to delete the current line, patch thanks to
Craig Mahaney.
(added) paste rectangle command for rectangular pasting, patch thanks to Craig
Mahaney.
(fixed) support for alternate background colors thanks to bug report from
Craig Mahaney.
(added) macro support to Craig Mahaney's added functionality.
(added) implementation for regular expression replacements, possibly to be
integrated as part of a 'replace in all open documents' in the future.
(added) automatic spellcheck for text and tex documents of up to 200,000 byes
in size.  Will only spellcheck if the user has enabled "check syntax" in the
"Realtime Options".
(fixed) issue when trying to save language settings when cursor position is
not to be saved.
(added) support for \chapter section delimiter in *tex files.
(fixed) issue that prevented the highest level source listing from being
sorted in the Name and Line sorted source trees.
(changed) rather than reading and executing a file for configuration loading,
we now use a variant of the 'unrepr()' mechanism with support for True/False.
(changed) find/replace bar now uses variant of 'unrepr()' rather than the
compiler module directly.
(changed) moved parsers.py to plugins and stopped using import * to get its
contents.

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


Re: lisper learning python, ... could you please comment my first python program?

2007-08-26 Thread Steven D'Aprano
On Sun, 26 Aug 2007 15:56:08 +, neptundancer wrote:

> Hi,
>   to extend my skills, I am learning python. I have written small
> program which computes math expression like "1+2*sin(y^10)/cos(x*y)" and
> similar, so far only + - * / ^ sin con tan sqrt are supported. But my
> program is quite inextensible, I have to change the code to add new
> functions... Could some fellow experienced pythonista give me some tips
> how to make my program shorter, and more extensible?

Just a few comments at random. This is certainly not meant to be 
exhaustive:


> def normalize(string):
> tmp = "".join([c for c in string if c != " "]) 
> return "(" + tmp + ")"

Try this instead:

def normalize(astring):
return "(" + astring.replace(" ", "") + ")"



> def most_nested_expression(string):
[snip code]
> if level != 0:
> raise IOError("mismatched parens")

You raise IOError quite often, but that's a misuse of it. IOError is a 
subclass of EnvironmentError, and is meant to indicate (e.g.) a failed 
read from a disk.

If you execute help(IOError) at the interactive prompt, you will see:

class IOError(EnvironmentError)
 |  I/O operation failed.


I suggest a better exception to use would be ValueError, or even create 
your own:

class MyCustomError(ValueError):
pass

would be a minimal example.




> def is_reduced_expression(string):
> for c in string:
> if c == "^" or c == "*" or c == "/" or c == "+" or c == "-":
> return False
> return True

Change that to:

for c in string:
if c in "^*/+-": return False
return True


[snip]


> def add(a, b): return a + b
> def sub(a, b): return a - b
> def mul(a, b): return a * b
> def div(a, b): return a / b

Replace the above four functions with:

from operator import add, sub, mul
from operator import truediv as div



> def translate_function(fn_str):
> if fn_str == "+": return add
> elif fn_str == "-": return sub
> elif fn_str == "*": return mul
> elif fn_str == "/": return div
> elif fn_str == "^": return math.pow
> elif fn_str == "sin": return math.sin elif fn_str == "cos": return
> math.cos elif fn_str == "tan": return math.tan elif fn_str ==
> "sqrt": return math.sqrt else: raise IOError("unknown function %s" %
> fn_str)


fn_map = {"+": add, "-": sub, "*": mul, "/": div, 
"^": math.pow, "sin": math.sin } # etc.

def translate_function(fn_str):
try:
return fn_map[fn_str]
except KeyError:
raise ValueError("unknown function '%s'" % fn_str)


Hope that helps.


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


New UI Toolkit

2007-08-26 Thread Gerdus van Zyl
Hi

I am halfway to a first release of a new GUI library for python. It
will be cross platform and follows the Swing philosophy of user
experience and interface fidelity above "but it doesn't look like
windows!" (aside: neither does office 2007 or windowsmediaplayer).

The library is built on top of CairoGraphics (cairographics.org) and
currently has a rather stable backend for Win32 and experimental
backends for GTK,Pyglet,pygame.

I am also busy with an WYSIWYG designer ala visualstudio but have yet
to decide on an serializable format leaning towards xul-alike without
XBL.

You can see a screenshot here: http://infireal.com/external/gradripper.png
and a executable of a utility built using here: http://www.infireal.com/alpha
(generates cairo/svg gradients from images)

Please reply and let your thoughts be known. Is there a need for a new
GUI library for python?

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


Re: lisper learning python, ... could you please comment my first python program?

2007-08-26 Thread neptundancer
Thanks a lot for comments! I am going to fix the source according to
your advices ;)

Nep

On Aug 26, 6:32 pm, Steven D'Aprano <[EMAIL PROTECTED]
THIScybersource.com.au> wrote:
> On Sun, 26 Aug 2007 15:56:08 +, neptundancer wrote:
> > Hi,
> >   to extend my skills, I am learning python. I have written small
> > program which computes math expression like "1+2*sin(y^10)/cos(x*y)" and
> > similar, so far only + - * / ^ sin con tan sqrt are supported. But my
> > program is quite inextensible, I have to change the code to add new
> > functions... Could some fellow experienced pythonista give me some tips
> > how to make my program shorter, and more extensible?
>
> Just a few comments at random. This is certainly not meant to be
> exhaustive:
>
> > def normalize(string):
> > tmp = "".join([c for c in string if c != " "])
> > return "(" + tmp + ")"
>
> Try this instead:
>
> def normalize(astring):
> return "(" + astring.replace(" ", "") + ")"
>
>
>
> > def most_nested_expression(string):
> [snip code]
> > if level != 0:
> > raise IOError("mismatched parens")
>
> You raise IOError quite often, but that's a misuse of it. IOError is a
> subclass of EnvironmentError, and is meant to indicate (e.g.) a failed
> read from a disk.
>
> If you execute help(IOError) at the interactive prompt, you will see:
>
> class IOError(EnvironmentError)
>  |  I/O operation failed.
>
> I suggest a better exception to use would be ValueError, or even create
> your own:
>
> class MyCustomError(ValueError):
> pass
>
> would be a minimal example.
>
> > def is_reduced_expression(string):
> > for c in string:
> > if c == "^" or c == "*" or c == "/" or c == "+" or c == "-":
> > return False
> > return True
>
> Change that to:
>
> for c in string:
> if c in "^*/+-": return False
> return True
>
> [snip]
>
> > def add(a, b): return a + b
> > def sub(a, b): return a - b
> > def mul(a, b): return a * b
> > def div(a, b): return a / b
>
> Replace the above four functions with:
>
> from operator import add, sub, mul
> from operator import truediv as div
>
> > def translate_function(fn_str):
> > if fn_str == "+": return add
> > elif fn_str == "-": return sub
> > elif fn_str == "*": return mul
> > elif fn_str == "/": return div
> > elif fn_str == "^": return math.pow
> > elif fn_str == "sin": return math.sin elif fn_str == "cos": return
> > math.cos elif fn_str == "tan": return math.tan elif fn_str ==
> > "sqrt": return math.sqrt else: raise IOError("unknown function %s" %
> > fn_str)
>
> fn_map = {"+": add, "-": sub, "*": mul, "/": div,
> "^": math.pow, "sin": math.sin } # etc.
>
> def translate_function(fn_str):
> try:
> return fn_map[fn_str]
> except KeyError:
> raise ValueError("unknown function '%s'" % fn_str)
>
> Hope that helps.
>
> --
> Steven.


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


Re: New UI Toolkit

2007-08-26 Thread Lawrence Oluyede
Gerdus van Zyl <[EMAIL PROTECTED]> wrote:
> Please reply and let your thoughts be known. Is there a need for a new
> GUI library for python?

I think there's no real point in answering this question. You developed
a new toolkit because, I'm guessing, you are not fully satisfied by the
current ones. In my personal opinion there's no *need* for another
toolkit but there is *room* for one, two, hundreds of new toolkits.
That's what freedom is for.

:-)

-- 
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand 
something when his salary depends on not
understanding it" - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lisper learning python, ... could you please comment my first python program?

2007-08-26 Thread Michele Simionato
On Aug 26, 5:56 pm, [EMAIL PROTECTED] wrote:
> Hi,
>   to extend my skills, I am learning python. I have written small
> program which computes math expression like "1+2*sin(y^10)/cos(x*y)"
> and similar, so far only + - * / ^ sin con tan sqrt are supported. But
> my program is quite inextensible, I have to change the code to add new
> functions... Could some fellow experienced pythonista give me some
> tips how to make my program shorter, and more extensible?

I understand that you are doing this as a learning exercise. Still, I
would
recommend you to have a look at the shlex module in the standard
library
and to pyparsing. Looking at their source code should should give you
some
idea. BTW, since you are familiar with Lisp, I would recommend you
IPython
for a better interactive experience.

  Michele Simionato

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


Re: lisper learning python, ... could you please comment my first python program?

2007-08-26 Thread [EMAIL PROTECTED]
Michele Simionato wrote:
> On Aug 26, 5:56 pm, [EMAIL PROTECTED] wrote:
> > Hi,
> >   to extend my skills, I am learning python. I have written small
> > program which computes math expression like "1+2*sin(y^10)/cos(x*y)"
> > and similar, so far only + - * / ^ sin con tan sqrt are supported. But
> > my program is quite inextensible, I have to change the code to add new
> > functions... Could some fellow experienced pythonista give me some
> > tips how to make my program shorter, and more extensible?
>
> BTW, since you are familiar with Lisp, I would recommend you
> IPython for a better interactive experience.

IPython's got great support for saving and using old results and a lot
of other things.  It's borderline unreadable for stack traces out of
the box, though; putting "xtrace Plain" in your ipythonrc helps a
lot.  The color options (either turning it off or making it light/dark
background appropriate) are also quite important to having it at all
usable; depending on your default bg color that may not be an issue.
And if you want to have a view of your data that's similar to the rest
of the Python world (useful if you ever intend for others to look at
your output or you to look at theirs), "pprint 0" is nice too.

Sorry if that sounds like it's an indictment--it's a very nice shell
aside from a few output weirdnesses that are easily configured.

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


Re: lisper learning python, ... could you please comment my first python program?

2007-08-26 Thread neptundancer
On Aug 26, 7:40 pm, Michele Simionato <[EMAIL PROTECTED]>
wrote:
> On Aug 26, 5:56 pm, [EMAIL PROTECTED] wrote:
>
> > Hi,
> >   to extend my skills, I am learning python. I have written small
> > program which computes math expression like "1+2*sin(y^10)/cos(x*y)"
> > and similar, so far only + - * / ^ sin con tan sqrt are supported. But
> > my program is quite inextensible, I have to change the code to add new
> > functions... Could some fellow experienced pythonista give me some
> > tips how to make my program shorter, and more extensible?
>
> I understand that you are doing this as a learning exercise. Still, I
> would
> recommend you to have a look at the shlex module in the standard
> library
> and to pyparsing. Looking at their source code should should give you
> some
> idea. BTW, since you are familiar with Lisp, I would recommend you
> IPython
> for a better interactive experience.
>
>   Michele Simionato

thanks for the tip! Now I have IPython working nicely. The shell now
looks a little like Christmas tree but I think it can be reduced a
bit ;)
the ?var and auto completion is exactly what I was looking for!

Nep

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


Re: New UI Toolkit

2007-08-26 Thread tool69
Gerdus van Zyl a écrit :

Seems very promising.

But I'm afraid with the Swing-like interface, i.e : did you use the same 
  widget positionning ?
-- 
http://mail.python.org/mailman/listinfo/python-list


the del function

2007-08-26 Thread Lamonte Harris
import random
constant_array = ""
red = blue = grey = black = 0
r1 = r2 = r3 = r4 = 1
blu1 = blu2 = blu3 = blu4 = 2
g1 = g2 = g3 = g4 = 3
bla1 = bla2 = bla3 = bla4 = 4
single_players =
[r1,r2,r3,r4,blu1,blu2,blu3,blu4,bla1,bla2,bla3,bla4,g1,g2,g3,g4]
_red = [1,1,1,1]
#print random.randint(0,10
#red team
x = 0
while x < 4:
array = single_players[4:17]
length = len(array) - 1
ray = random.randint(0,length)
_red[x] = array[ray]
del array[ray]
print array
x = x + 1
print _red

Ok I'm working on a game function where at the end of the game it remix's
the teams.

For some odd reason the del array[ray] isn't actually deleting the array
item in the list I get the following output:

C:\Documents and Settings\program\Desktop\python\pygame>remix.py
[2, 2, 2, 4, 4, 4, 4, 3, 3, 3, 3]
[2, 2, 2, 4, 4, 4, 4, 3, 3, 3, 3]
[2, 2, 2, 2, 4, 4, 4, 3, 3, 3, 3]
[2, 2, 2, 2, 4, 4, 4, 3, 3, 3, 3]
[2, 2, 4, 4]

The _red function is fine, but the del function isn't working.  What did I
do wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Joining Big Files

2007-08-26 Thread mcl
On 26 Aug, 15:45, vasudevram <[EMAIL PROTECTED]> wrote:
> On Aug 26, 6:48 am, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 25, 8:15 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
> > > On Aug 25, 4:57 am,mosscliffe<[EMAIL PROTECTED]> wrote:
>
> > > > I have 4 text files each approx 50mb.
>
> > >  50mb? Really?  Did you actually try this and find out it was a
> > > problem?
>
> > > Try this:
> > > import time
>
> > > start = time.clock()
> > > outname = "temp.dat"
> > > outfile = file(outname,"w")
> > > for inname in ['file1.dat', 'file2.dat', 'file3.dat', 'file4.dat']:
> > > infile = file(inname)
> > > outfile.write( infile.read() )
> > > infile.close()
> > > outfile.close()
> > > end = time.clock()
>
> > > print end-start,"seconds"
>
> > > For 4 30Mb files, this takes just over 1.3 seconds on my system.  (You
> > > may need to open files in binary mode, depending on the contents, but
> > > I was in a hurry.)
>
> > > -- Paul
>
> > My bad, my test file was not a text file, but a binary file.
> > Retesting with a 50Mb text file took 24.6 seconds on my machine.
>
> > Still in your working range?  If not, then you will need to pursue
> > more exotic approaches.  But 25 seconds on an infrequent basis does
> > not sound too bad, especially since I don't think you will really get
> > any substantial boost from them (to benchmark this, I timed a raw
> > "copy" command at the OS level of the resulting 200Mb file, and this
> > took about 20 seconds).
>
> > Keep it simple.
>
> > -- Paul
>
> There are (at least) another couple of approaches possible, each with
> some possible tradeoffs or requirements:
>
> Approach 1. (Least amount of code to write - not that the others are
> large :)
>
> Just use os.system() and the UNIX cat command - the requirement here
> is that:
> a) your web site is hosted on *nix (ok, you can do it if on Windows
> too - use copy instead of cat, you might have to add a "cmd /c "
> prefix in front of the copy command, and you have to use the right
> copy command syntax for concatenating multiple input files into one
> output file).
>
> b) your hosting plan allows you to execute OS level commands like cat,
> and cat is in your OS PATH (not PYTHONPATH). (Similar comments apply
> for Windows hosts).
>
> import os
> os.system("cat file1.txt file2.txt file3.txt file4.txt >
> file_out.txt")
>
> cat will take care of buffering, etc. transparently to you.
>
> Approach 2: Read (in a loop, as you originally thought of doing) each
> line of each of the 4 input files and write it to the output file:
>
> ("Reusing" Paul McGuire's code above:)
>
> outname = "temp.dat"
> outfile = file(outname,"w")
> for inname in ['file1.dat', 'file2.dat', 'file3.dat', 'file4.dat']:
> infile = file(inname)
> for lin in infile:
> outfile.write(lin)
> infile.close()
> outfile.close()
> end = time.clock()
>
> print end-start,"seconds"
>
> # You may need to check that newlines are not removed in the above
> code, in the output file.  Can't remember right now. If they are, just
> add one back with:
>
> outfile.write(lin + "\n") instead of  outfile.write(lin) .
>
> ( Code not tested, test it locally first, though looks ok to me. )
>
> The reason why this _may_ not be much slower than manually coded
> buffering approaches, is that:
>
> a) Python's standard library is written in C (which is fast),
> including use of stdio (the C Standard IO library, which already does
> intelligent buffering)
> b) OS's do I/O buffering anyway, so do hard disk controllers
> c) from some recent Python version, I think it was 2.2, that idiom
> "for lin in infile" has been (based on somethng I read in the Python
> Cookbook) stated to be pretty efficient anyway (and yet (slightly)
> more readable that earlier followed approaches of reading a text
> file).
>
> Given all the above facts, it probably isn't worth your while to try
> and optimize the code unless and until you find (by measurements) that
> it's too slow - which is a good practice anyway:
>
> http://en.wikipedia.org/wiki/Optimization_(computer_science)
>
> Excerpt from the above page (its long but worth reading, IMO):
>
> "Donald Knuth said, paraphrasing Hoare[1],
>
> "We should forget about small efficiencies, say about 97% of the time:
> premature optimization is the root of all evil." (Knuth, Donald.
> Structured Programming with go to Statements, ACM Journal Computing
> Surveys, Vol 6, No. 4, Dec. 1974. p.268.)
>
> Charles Cook commented,
>
> "I agree with this. It's usually not worth spending a lot of time
> micro-optimizing code before it's obvious where the performance
> bottlenecks are. But, conversely, when designing software at a system
> level, performance issues should always be considered from the
> beginning. A good software developer will do this automatically,
> having developed a feel for where performance issues will cause
> problems. An inexperienced developer will not bother, misguidedly
> believing that a bit of fine tuning at a late

Re: New UI Toolkit

2007-08-26 Thread Gerdus van Zyl

> But I'm afraid with the Swing-like interface, i.e : did you use the same
>   widget positionning ?

Not sure what you mean, but each parent widget is responsible for
rendering and positioning the children. Can use layout managers, two
currently absolute and simple flow. ( In the screenshot, the gradients
are in a flow panel)

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


pySerial in a daemon process

2007-08-26 Thread paul
I am writing a daemon process that reads data from the serial port /
dev/ttyS0.  I am using pyserial & the method for setting up a daemon
described in "Chris' Python Page" (http://homepage.hispeed.ch/py430/
python/) on an Ubuntu linux pc.

Everything works great EXCEPT...

in the daemon script, there are two lines to change the uid & gid that
the script runs as:
os.setegid(10)
os.seteuid(1000)

If I comment these out, so that the daemon runs as root, then
everything works fine.  I can also manually run the script that the
daemon process kicks off from my own id just fine.

If I put these back in and try to run the daemon, the script fails
when I try to connect to the serial port, with this error:
serial.serialutil.SerialException: Could not open port: [Errno 13]
Permission denied: '/dev/ttyS0'

In my debugging I have tried setting the uid to my own uid, and the
gid to a variety of different groups that I belong to.  None of them
work.

I could certainly run the daemon as root, but I would rather not.
What really confuses me is that if I manually run the script as myself
(without using the daemon script), it connects fine, but when root
uses os.seteuid() to my uid, it fails.

What do I need to do to get this to work?

Many thanks,

Paul

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


Re: Parser Generator?

2007-08-26 Thread Jason Evans
On Aug 24, 1:21 pm, "Jack" <[EMAIL PROTECTED]> wrote:
> "Jason Evans" <[EMAIL PROTECTED]> wrote in message
> >http://www.canonware.com/Parsing/
>
> Thanks Jason. Does Parsing.py support Unicode characters (especially CJK)?
> I'll take a look.

Parsers typically deal with tokens rather than individual characters,
so the scanner that creates the tokens is the main thing that Unicode
matters to.  I have written Unicode-aware scanners for use with
Parsing-based parsers, with no problems.  This is pretty easy to do,
since Python has built-in support for Unicode strings.

Jason

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


Re: pySerial in a daemon process

2007-08-26 Thread Bjoern Schliessmann
paul wrote:

> If I put these back in and try to run the daemon, the script fails
> when I try to connect to the serial port, with this error:
> serial.serialutil.SerialException: Could not open port: [Errno 13]
> Permission denied: '/dev/ttyS0'

Did you check the permissions on this file? Often you have to be
member of a "dialout" group or similar to get access.

Regards,


Björn

-- 
BOFH excuse #172:

pseudo-user on a pseudo-terminal

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


Re: Debugging a curses application in python

2007-08-26 Thread [EMAIL PROTECTED]
Just to let anyone know who runs across this post, winpdb from (http://
www.digitalpeers.com/pythondebugger/) solved my issue.

--Chris

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


Re: New UI Toolkit

2007-08-26 Thread Richard Jones
Gerdus van Zyl wrote:
> I am halfway to a first release of a new GUI library for python. It
> will be cross platform and follows the Swing philosophy of user
> experience and interface fidelity above "but it doesn't look like
> windows!" (aside: neither does office 2007 or windowsmediaplayer).
> 
> The library is built on top of CairoGraphics (cairographics.org) and
> currently has a rather stable backend for Win32 and experimental
> backends for GTK,Pyglet,pygame.

I am also developing a gui toolkit (for somewhat similar reasons to you,
though unrelated to Swing) but it's for pyglet only. If you're interested,
you can find it in the pyglet SVN under contrib/wydget. It's under heavy
development and is fairly advanced (in terms of widgets, layouts, dialogs
etc implemented) already.


> Please reply and let your thoughts be known. Is there a need for a new
> GUI library for python?

Clearly you felt there was :)


Richard

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


Re: pySerial in a daemon process

2007-08-26 Thread paul
On Aug 26, 5:20 pm, Bjoern Schliessmann  wrote:
> paul wrote:
> > If I put these back in and try to run the daemon, the script fails
> > when I try to connect to the serial port, with this error:
> > serial.serialutil.SerialException: Could not open port: [Errno 13]
> > Permission denied: '/dev/ttyS0'
>
> Did you check the permissions on this file? Often you have to be
> member of a "dialout" group or similar to get access.
>
> Regards,
>
> Björn
>
> --
> BOFH excuse #172:
>
> pseudo-user on a pseudo-terminal


THANKS! That did it, but perhaps can you explain to me why...

Before I had posted this question first thing I did was to look at /
dev/ttyS0, and indeed the group is dialout (gid=20), so I tried a
couple of things:

1. checked my id to see if I was a member of dialout, and indeed I
am.  So, I edited the daemon script to use my id and set the gid to
dialout (ie: os.setegid(20) & os.seteuid(1000)) and it still failed.

2. made the id I really want to use (pydaemon, uid=110) a member of
dialout, and set the daemon script to use those (ie: os.setegid(20) &
os.seteuid(110)) and it still failed...

After reading your comment, I went and did a chgrp to set the various
script file groups to dialout, and indeed it now works.  What confuses
me is that if the script needed that group, why doesn't the setegid or
seteuid fail?  Why does the script keep running okay until the
connect, and fail then?

Thanks!

Paul

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

Re: my parser.py isn't imported

2007-08-26 Thread John Machin
On Aug 27, 1:36 am, Torsten Bronger <[EMAIL PROTECTED]>
wrote:
> Hallöchen!
>
> I have a module parser.py in the same directory as the main module.
> In the main module, I import "parser".  On Linux, this works as
> expected, however on Windows, it imports the stdlib parser module.
> sys.path[0] points to the directory of my parser.py in both cases.
> What went wrong here?

Ask a literal question, get a literal answer :-)

1. Failure to consider that problems can happen [and therefore will
happen [1]] when there are multiple entities with the same name.

2. Failure to RTFabulousM:
"""
Details of the module searching and loading process are implementation
and platform specific. It generally involves searching for a ``built-
in'' module with the given name and then searching a list of locations
given as sys.path.
"""

3. Failure to attempt enlightenment by using the -v option:
"""
import parser # builtin
"""
(on Windows)

Suggestion: Avoid the confusion. Rename your module. If it is actually
intended as a replacement for the builtin one, then you can do:
   import replacementparser as parser

[1] Codex Murphius, circa 5000 BCE

HTH,
John

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


Re: my parser.py isn't imported

2007-08-26 Thread Torsten Bronger
Hallöchen!

John Machin writes:

> On Aug 27, 1:36 am, Torsten Bronger <[EMAIL PROTECTED]>
> wrote:
>
>> I have a module parser.py in the same directory as the main
>> module.  In the main module, I import "parser".  On Linux, this
>> works as expected, however on Windows, it imports the stdlib
>> parser module.  sys.path[0] points to the directory of my
>> parser.py in both cases.  What went wrong here?
>
> Ask a literal question, get a literal answer :-)
>
> 1. Failure to consider that problems can happen [and therefore
> will happen [1]] when there are multiple entities with the same
> name.

So I'd like to know a means to tell *explicitly* what I want to
import.  Maybe I could use the imp module but that's ugly.  I mean,
there are hundreds of modules on my harddisk, so trying to avoid
nameclashs should not be the solution, and given ...

> 2. Failure to RTFabulousM:
> """
> Details of the module searching and loading process are
> implementation and platform specific. It generally involves
> searching for a ``built- in'' module with the given name and then
> searching a list of locations given as sys.path.
> """

... the whole systems seems largely arbitrary, which I don't
believe.  ;-)

"parser" is built-in on Windows but not on Linux.  What's the list
of modules that *may* be built-in on some platform or
implementation?  Or should I avoid the whole standard lib for names
of my modules?  Or even everything which is shipped e.g. with
Enthought Python?  I find this quite irritating.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: YOU MUST KNOW THIS MAN

2007-08-26 Thread James Stroud
Would Muhammad, peace and blessings be upon him, want his followers to 
kill in his name? I know that other prophets would not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parser Generator?

2007-08-26 Thread Jack
Good to know, thanks Paul.
!
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message

> Pyparsing was already mentioned once on this thread.  Here is an
> application using pyparsing that parses Chinese characters to convert
> to English Python.
>
> http://pypi.python.org/pypi/zhpy/0.5
>
> -- Paul 


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


SCF (Python Smar Card Framework)

2007-08-26 Thread hg
Dear all,

I am releasing much of my work including SCF (Cross platform Smart Card 
library & Tools) to the GPL license.

If interested, go to http://www.SnakeCard.com/Source.html

I am moving the doc to doxygen and cleaning up the code, so what you'll 
see there will change in the course of the next few weeks - basically 
can only get meaningful info on the classes hierarchy at this stage.
I am looking for a free subversion server resource to put the code ... 
if you know of any.

Some of the work there will be windows-only related (GINA, activeX 
components ...) and the applets JavaCard and BasicCard ... I'm releasing 
these during the next few days.

Regards,

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


Re: SCF (Python Smar Card Framework)

2007-08-26 Thread Paul Rubin
hg <[EMAIL PROTECTED]> writes:
> I am releasing much of my work including SCF (Cross platform Smart
> Card library & Tools) to the GPL license.
> 
> If interested, go to http://www.SnakeCard.com/Source.html

Wow, that is great.  I haven't found any low cost programmable cards
(no large quantity purchases or developer licenses needed) other than
BasicCard which has some annoying limitations.  Do you have any
suggestions?  Thanks!

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


Re: Parser Generator?

2007-08-26 Thread Jack
Thanks Json. There seem to be a few options that I can pursue. Having a hard 
time
chooing one now :)

"Jason Evans" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Aug 24, 1:21 pm, "Jack" <[EMAIL PROTECTED]> wrote:
>> "Jason Evans" <[EMAIL PROTECTED]> wrote in message
>> >http://www.canonware.com/Parsing/
>>
>> Thanks Jason. Does Parsing.py support Unicode characters (especially 
>> CJK)?
>> I'll take a look.
>
> Parsers typically deal with tokens rather than individual characters,
> so the scanner that creates the tokens is the main thing that Unicode
> matters to.  I have written Unicode-aware scanners for use with
> Parsing-based parsers, with no problems.  This is pretty easy to do,
> since Python has built-in support for Unicode strings.
>
> Jason
> 


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


Re: SCF (Python Smar Card Framework)

2007-08-26 Thread hg
Paul Rubin wrote:
> hg <[EMAIL PROTECTED]> writes:
>> I am releasing much of my work including SCF (Cross platform Smart
>> Card library & Tools) to the GPL license.
>>
>> If interested, go to http://www.SnakeCard.com/Source.html
> 
> Wow, that is great.  I haven't found any low cost programmable cards
> (no large quantity purchases or developer licenses needed) other than
> BasicCard which has some annoying limitations.  Do you have any
> suggestions?  Thanks!
> 

How about you post that on the forum I just opened ... we're going to 
get killed here ;-)

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


Re: ActiveRecord for Python/MySQL

2007-08-26 Thread Luis M . González
On Aug 26, 5:52 am, Devraj <[EMAIL PROTECTED]> wrote:
> Thanks
>
> On Aug 26, 5:26 pm, EuGeNe Van den Bulke
>
> <[EMAIL PROTECTED]> wrote:
> > Devraj wrote:
> > > My application uses MySQL as a backend and am using the MySQL/Python
> > > bindings. Are there any libraries that provide a database abstraction
> > > layer like Activerecords for Python?'
>
> > SQLObject
> > SQLAclhemy
> > DejaVu
> > Storm
>
> > Google for Python ORM you may find more!
>
> > EuGeNe --http://www.3kwa.com


If you want an ActiveRecord -like experience with SQLAlchemy, you can
use the extension Elixir on top of it.

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


Re: Co-developers wanted: document markup language

2007-08-26 Thread bambam
> virtually the only ones that feel the need to rub our nationality into

I'd always assumed (I never spent much time) that Germans were
another culture that had the habit of greeting groups on entrance.

Australians, English, and most of North America just don't have
that habit.

Steve.

"Wildemar Wildenburger" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Torsten Bronger wrote:
>> Hallöchen!
>>
>>
> Yes, you're German. Have you ever noticed that (we) Germans are virtually 
> the only ones that feel the need to rub our nationality into everyones 
> faces? ;)
>
>
>> Paul Rubin writes
>>
>>> TeX/LateX have been around forever and are well established
>>> standards, as awful as they are.  Why do we want ANOTHER markup
>>> language?
>>>
>> Well, because they are awful.  ;-)  I don't see that there is a
>> bunch of already existing projects, in fact, I don't see anyone
>> challenging LaTeX at all.  However, competition is a good thing, and
>> I think there are enough aspects about LaTeX that can be done better
>> so that this project is worth being done.
>>
> Well there is ConTeXt http://wiki.contextgarden.net/>. I've never 
> actually used it, but from reading the docs I deem it a very attractive 
> alternative to LaTeX.
>
> /W 


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

RE: Using Regular Expresions to change .htm to .php in files

2007-08-26 Thread Ryan Ginstrom
> On Behalf Of Mark
> This line should be:
> 
> sed "s/\.htm$/.php/g" < $each > /tmp/$$

I think a more robust way to go about this would be:

(1) Use os.walk to walk through the directory
   http://docs.python.org/lib/os-file-dir.html

(2) Use Beautiful Soup to extract the internal links from each file
   http://crummy.com/software/BeautifulSoup/documentation.html

from BeautifulSoup import BeautifulSoup

soup = BeautifulSoup(doc)
links = soup('a')
internal_links = [link["href"]
for link in links
if link.has_key("href") and not
link["href"].startswith("http")]

(4) Do straight string replacements on those links (no regex needed)

(5) Save each html file to *.html.bak before changing


Regards,
Ryan Ginstrom

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


RE: Parser Generator?

2007-08-26 Thread Ryan Ginstrom
> On Behalf Of Jason Evans
> Parsers typically deal with tokens rather than individual 
> characters, so the scanner that creates the tokens is the 
> main thing that Unicode matters to.  I have written 
> Unicode-aware scanners for use with Parsing-based parsers, 
> with no problems.  This is pretty easy to do, since Python 
> has built-in support for Unicode strings.

The only caveat being that since Chinese and Japanese scripts don't
typically delimit "words" with spaces, I think you'd have to pass the text
through a tokenizer (like ChaSen for Japanese) before using PyParsing.

Regards,
Ryan Ginstrom

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


Re: beginner, idiomatic python

2007-08-26 Thread bambam
That looks good, and perhaps a difference operator
would be too simple to be useful anyway.

Steve.

"Mikael Olofsson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
>
> bambam wrote:
>>
>> In this case it doesn't matter - my lists don't contain
>> duplicate elements this time - but I have worked with lists in
>> money market and in inventory, and finding the intersection
>> and difference for matching off and netting out are standard
>> operations.
>
> I would use a list comprehension for that case:
>
> A = ['a','b','c','a','c','d']
> U = ['a','b','e']
> B = [x for x in A if x in U]
>
> The result would be B==['a','b','a']
>
> /MiO 


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


Re: beginner, idiomatic python

2007-08-26 Thread bambam

c = sorted(set(a)-set(b))

although for me :~( that is another step more obscure than

c = list(set(a)-set(b))
c.sort()

Bags don't seem to be built in to my copy of Python, and
although I'm interested in why lists don't support the difference
operation, I don't want to get away from standard Python.

Steve.

"Scott David Daniels" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> bambam wrote:
>>> The reason that lists don't have set-like methods is because
>>> lists aren't sets -- lists can contain duplicate elements
> and they are ordered.  I'd have used sets if I was sure you
> meant [1,2,3] to mean the same thing as [3,1,2] and no duplicates.
>
>> Interesting point -- if that's all there is in it, then lists should
>> have difference and intersection methods. Not because they
>> are the same as sets -- because they are slightly different than
>> sets. In this case it doesn't matter - my lists don't contain
>> duplicate elements this time - but I have worked with lists in
>> money market and in inventory, and finding the intersection
>> and difference for matching off and netting out are standard
>> operations.
> Here you seem to be talking about multisets (also called bags).
> They have more fully defined algebraic properties analogous to sets.
>
> bag([1,2,3,3,4]) == bag([3,1,2,4,3]) != bag([1,2,3,4])
> bag([1,2,2,3]) - bag([1,2]) == bag([2,3])
> bag([1,2,3]) - bag([3,4]) == bag([1])
>
 Excellent. By symmetry, I see that "list" casts the set back into a 
 list.
> Some will say 'sorted' is a better conversion of a set to list, since
> the result is well-defined.
>
> --Scott David Daniels
> [EMAIL PROTECTED] 


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


Re: beginner, idiomatic python

2007-08-26 Thread bambam
Ok, many environments are capable of cached evaluation
of functions without variable parameters so
range(5)
is cached, but
range(v) is re-evaluated every time. Is this defined
behaviour?

That is, is it defined what Python does for
for i in f()
I'm sure it must be, but I haven't seen it yet. If I have
a user defined function returning a range, is it defined
that the range function is called on every loop? If I
have a function returning a range taking a parameter,
for i in f(v)
is it defined that the variable is evaluated for every loop?

Steve.


"Paul McGuire" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Aug 23, 11:50 pm, "bambam" <[EMAIL PROTECTED]> wrote:
>> Thank you, so generallizing:
>>
>> (1) Python re-evaluates the loop range on every loop, and
>> (2) Python does short-circuit evaluation of conditions, in predictable
>> order.
>>
>> Sorry about the bad question.
>>
>
> A beginner would do well to work through the Python Tutorial (http://
> docs.python.org/tut/tut.html).  I think your first "insight" is
> actually incorrect, if I understand your wording.  If I wrote:
>
> for i in range(10):
># do something with i
>
> I'm quite certain that range(10) is not evaluated on every
> loop iteration.  In fact, the range call generates a list containing
> the values [0, 1, 2, ..., 9], and then for iterates over this
> list.  You can read this at 
> http://docs.python.org/tut/node6.html#SECTION00630.
>
> On the other hand, if you are talking about a while loop, of course
> the condition is evaluated on every loop - otherwise such a loop, once
> entered, would never exit.
>
> Your second generalization is stated pretty plainly in
> http://docs.python.org/tut/node7.html#SECTION00770.
> In fact, conditional short-circuiting is a consistent theme in most
> Python functions and structures.  The new any() and all() built-ins in
> Python 2.5 for example, evaluate a list of values for their boolean
> True/False-ness, any() returning True if any list entry is True,
> otherwise False; and all() returning True if all entries are True,
> otherwise False.  Both short-circuit their evaluation, so that if the
> first element of a billion element list gives a True value for any()
> (or a False value for all()), then the evaluation of the remaining
> billion-1 items is skipped.
>
> Best of luck in your new Python learning process,
> -- Paul
> 


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


Re: make images with python

2007-08-26 Thread Steve Holden
Lawrence D'Oliveiro wrote:
> In message <[EMAIL PROTECTED]>, Boris
> Borcic wrote:
> 
>> Lawrence Oluyede wrote:
>>
>>> stefano <[EMAIL PROTECTED]> wrote:
 I need make some images using python but i'm lost :P
>>> 
>>>
>> If you want to do antialiased drawings into images,
>> you might rather want to look for pil at
>>
>> http://effbot.org/downloads/
>>
>> and grab PIL together with the aggdraw extension
>> (while "core" PIL includes some drawing primitives,
>> last time I tried they weren't antialiased).
> 
> I see that PIL supports image resizing
>  with filters
> that can be used for antialiasing. So just do all your drawing at, say,
> 200% scale, then downsample with Image.resize to antialias.

That certainly worked very well for rendering text.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: beginner, idiomatic python

2007-08-26 Thread Gabriel Genellina
En Sun, 26 Aug 2007 22:58:35 -0300, bambam <[EMAIL PROTECTED]> escribi�:

> Ok, many environments are capable of cached evaluation
> of functions without variable parameters so
> range(5)
> is cached, but
> range(v) is re-evaluated every time. Is this defined
> behaviour?

The range builtin function returns a list, and lists are mutable objects,  
so it must return a *different* list each time.

> That is, is it defined what Python does for
> for i in f()
> I'm sure it must be, but I haven't seen it yet. If I have
> a user defined function returning a range, is it defined
> that the range function is called on every loop? If I
> have a function returning a range taking a parameter,
> for i in f(v)
> is it defined that the variable is evaluated for every loop?

Find all the (mostly negative) answers yourself in  


-- 
Gabriel Genellina

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

Re: beginner, idiomatic python

2007-08-26 Thread Scott David Daniels
bambam wrote:
> That is, is it defined what Python does for
> for i in f()
> I'm sure it must be, but I haven't seen it yet. If I have
> a user defined function returning a range, is it defined
> that the range function is called on every loop? If I
> have a function returning a range taking a parameter,
> for i in f(v)
> is it defined that the variable is evaluated for every loop?

Nope.  Take the tutorial.

 for i in f(v):
 
is the same as:
 iterator = iter(f(v))
 for i in iterator:
 

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


Re: beginner, idiomatic python

2007-08-26 Thread bambam
Thank you, I have been through the tutorial several times, I guess
I'm just not smart enough. Perhaps I have been led astray by what
I read here?

My code started like this:

for i in range(self.parent.GetPageCount()):

I was asked:

>Does page count change? i.e. is it necessary to retrieve it in every loop


Is self.parent.GetPageCount() 'retrieved every loop'?

Steve.




"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> En Sun, 26 Aug 2007 22:58:35 -0300, bambam <[EMAIL PROTECTED]> escribi?:
>
>> Ok, many environments are capable of cached evaluation
>> of functions without variable parameters so
>> range(5)
>> is cached, but
>> range(v) is re-evaluated every time. Is this defined
>> behaviour?
>
> The range builtin function returns a list, and lists are mutable objects, 
> so it must return a *different* list each time.
>
>> That is, is it defined what Python does for
>> for i in f()
>> I'm sure it must be, but I haven't seen it yet. If I have
>> a user defined function returning a range, is it defined
>> that the range function is called on every loop? If I
>> have a function returning a range taking a parameter,
>> for i in f(v)
>> is it defined that the variable is evaluated for every loop?
>
> Find all the (mostly negative) answers yourself in 
> 
>
> -- 
> Gabriel Genellina
> 


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


Re: beginner, idiomatic python

2007-08-26 Thread bambam
Thank you, I have been through the tutorial several times, I guess
I'm just not smart enough. Python is quite different from the
languages I am familiar with.

My code sample started like this:

>>for i in range(self.parent.GetPageCount()):

I was asked:

>Does page count change? i.e. is it necessary to retrieve it in every loop


Is self.parent.GetPageCount() 'retrieved every loop'?

Steve.

"Scott David Daniels" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> bambam wrote:
>> That is, is it defined what Python does for
>> for i in f()
>> I'm sure it must be, but I haven't seen it yet. If I have
>> a user defined function returning a range, is it defined
>> that the range function is called on every loop? If I
>> have a function returning a range taking a parameter,
>> for i in f(v)
>> is it defined that the variable is evaluated for every loop?
>
> Nope.  Take the tutorial.
>
> for i in f(v):
> 
> is the same as:
> iterator = iter(f(v))
> for i in iterator:
> 
>
> -Scott David Daniels
> [EMAIL PROTECTED] 


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


how setup a dll file as a module?

2007-08-26 Thread smalltalk


in arcgis , arcgisscripting is a dll file
there is a script as following:

import  arcgisscripting
gp = arcgisscripting.create()

why can the script run?
how can we setup a dll file as a module?

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


Re: Parser Generator?

2007-08-26 Thread Paul McGuire
On Aug 26, 8:05 pm, "Ryan Ginstrom" <[EMAIL PROTECTED]> wrote:
> > On Behalf Of Jason Evans
> > Parsers typically deal with tokens rather than individual
> > characters, so the scanner that creates the tokens is the
> > main thing that Unicode matters to.  I have written
> > Unicode-aware scanners for use with Parsing-based parsers,
> > with no problems.  This is pretty easy to do, since Python
> > has built-in support for Unicode strings.
>
> The only caveat being that since Chinese and Japanese scripts don't
> typically delimit "words" with spaces, I think you'd have to pass the text
> through a tokenizer (like ChaSen for Japanese) before using PyParsing.
>
> Regards,
> Ryan Ginstrom

Did you think pyparsing is so mundane as to require spaces between
tokens?  Pyparsing has been doing this type of token-recognition since
Day 1.  Looking for tokens without delimiting spaces was one of the
first applications for pyparsing.  This issue is not unique to Chinese
or Japanese text.  Pyparsing will easily find the tokens in this
string:

y=a*x**2+b*x+c

as

['y','=','a','*','x','**','2','+','b','*','x','+','c']

even though there is not a single delimiting space.  But pyparsing
will also render this as a nested parse tree, reflecting the
precedence of operations:

['y', '=', [['a', '*', ['x', '**', 2]], '+',['b', '*', 'x'], '+',
'c']]

and will allow you to access individual tokens by field name:
- lhs: y
- rhs: [['a', '*', ['x', '**', 2]], '+', ['b', '*', 'x'], '+', 'c']

Please feel free to look through the posted examples on the pyparsing
wiki at http://pyparsing.wikispaces.com/Examples, or some of the
applications currently using pyparsing at 
http://pyparsing.wikispaces.com/WhosUsingPyparsing,
and you might get a better feel for what kind of tasks pyparsing is
capable of.

-- Paul

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


Re: beginner, idiomatic python

2007-08-26 Thread bambam
Is it safe to write

A = [x for x in A if x in U]

or is that undefined? I understand that the slice operation
can be used to make a temporary copy, so I could write

A=[x for x in A[:] if x in U]

but I've just copied that without any understanding.

Steve.


"bambam" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> That looks good, and perhaps a difference operator
> would be too simple to be useful anyway.
>
> Steve.
>
> "Mikael Olofsson" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>>
>>
>> bambam wrote:
>>>
>>> In this case it doesn't matter - my lists don't contain
>>> duplicate elements this time - but I have worked with lists in
>>> money market and in inventory, and finding the intersection
>>> and difference for matching off and netting out are standard
>>> operations.
>>
>> I would use a list comprehension for that case:
>>
>> A = ['a','b','c','a','c','d']
>> U = ['a','b','e']
>> B = [x for x in A if x in U]
>>
>> The result would be B==['a','b','a']
>>
>> /MiO
>
> 


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


Re: Parser Generator?

2007-08-26 Thread Steven Bethard
Paul McGuire wrote:
> On Aug 26, 8:05 pm, "Ryan Ginstrom" <[EMAIL PROTECTED]> wrote:
>> The only caveat being that since Chinese and Japanese scripts don't
>> typically delimit "words" with spaces, I think you'd have to pass the text
>> through a tokenizer (like ChaSen for Japanese) before using PyParsing.
> 
> Did you think pyparsing is so mundane as to require spaces between
> tokens?  Pyparsing has been doing this type of token-recognition since
> Day 1.  Looking for tokens without delimiting spaces was one of the
> first applications for pyparsing.  This issue is not unique to Chinese
> or Japanese text.  Pyparsing will easily find the tokens in this
> string:
> 
> y=a*x**2+b*x+c
> 
> as
> 
> ['y','=','a','*','x','**','2','+','b','*','x','+','c']

The difference is that in the expression above (and in many other 
tokenization problems) you can determine "word" boundaries by looking at 
the class of character, e.g. alphanumeric vs. punctuation vs. whatever.

In Japanese and Chinese tokenization, word boundaries are not marked by 
different classes of characters. They only exist in the mind of the 
reader who knows which sequences of characters could be words given the 
context, and which sequences of characters couldn't.

The closest analog would be to ask pyparsing to find the words in the 
following sentence:

ThepyparsingmoduleprovidesalibraryofclassesthatclientcodeusestoconstructthegrammardirectlyinPythoncode.

Most approaches that have been even marginally successful on these kinds 
of tasks have used statistical machine learning approaches.

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


Re: Error with Simplemapi.py

2007-08-26 Thread Gabriel Genellina
En Fri, 24 Aug 2007 04:03:05 -0300, Mick Duprez <[EMAIL PROTECTED]>  
escribi�:

> I have a small problem. I get an error I don't know how to resolve,
> any help would be much appreciated.
> I'm using Python25 on winXP pro and the script from the link above.
> Here's the error -
>
 mailtest.SendMail('[EMAIL PROTECTED]','test','test  
 string','c:\dbs.txt')

That should be 'c:\\dbs.txt' or r'c:\dbs.txt'

> Traceback (most recent call last):
>   File "", line 1, in 
> mailtest.SendMail('[EMAIL PROTECTED]','test','test string','c:
> \dbs.txt')
>   File "C:\Python25\mailtest.py", line 135, in SendMail
> cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
>   File "C:\Python25\lib\ctypes\__init__.py", line 478, in cast
> return _cast(obj, obj, typ)
> ArgumentError: argument 1: : wrong type


I'm unsure what those cast(NULL, ...) are supposed to do, but they look  
all wrong. NULL, as defined on that script, is *not* a C NULL pointer (use  
None for that).
(In fact the whole script doesn't look well at all - do you *have* to use  
MAPI? can't use SMTP instead? Even if you must use MAPI, try the pywin32  
package from Mark Hammond, it has MAPI support and a demo script for  
sending mail)

> I have had a brief look at the C api for these structs and functions
> but I can't resolve it, it is probably something simple.
> The piece of code I don't understand though is this -
>
> MapiRecipDesc_A = MapiRecipDesc * len(RecipWork) #size of struct??

This declares a new type, an array of len(RecipWork) items, each of type  
MapiRecipDesc

> rda = MapiRecipDesc_A() # isn't it MapiRecipDesc as declared??

This creates an instance of the above array.

-- 
Gabriel Genellina

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

Re: beginner, idiomatic python

2007-08-26 Thread Alex Martelli
bambam <[EMAIL PROTECTED]> wrote:

> Is it safe to write
> 
> A = [x for x in A if x in U]
> 
> or is that undefined? I understand that the slice operation

It's perfectly safe and well-defined, as the assignment rebinds the LHS
name only AFTER the RHS list comprehension is done.


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


Re: beginner, idomatic python 2

2007-08-26 Thread bambam
Thank you. I didn't reply earlier because I was trying to get my
head around what you wrote, which was strange and foreign
to me.

It seems to me that the dictionary object you suggested is a
direct replacement for the function code, only more efficient
because the case table is internalised with a hash table, and
the original if/elif/else case table was unlikely to be implemented
as a hash table.

And presumably, it is idiomatic because Python programmers
expect to use dictionaries for their lookup tables.

You have answered a question I didn't know enough to ask :~)
--which is why I started with the general question, so I don't
feel too stupid about that --.

And now I wonder about the 'other' question. Should I consider
dynamically overriding the methods in my 'Device' class, instead
of creating separate classes for the Psp and Pwr devices?
I could create an object of the base Device class, and at init
I could make sure the methods were connected for a Psp or
a Pwr device. When (if ever) is that a good idea?

Steve.




"Dan Bishop" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Aug 23, 10:21 pm, "bambam" <[EMAIL PROTECTED]> wrote:
>> Would someone like to suggest a replacement for this? This is a
>> function that returns different kinds of similar objects, depending
>> on what is asked for. PSP and PWR are classes.  I don't really
>> want to re-write the calling code very much: I'm just wondering
>> if the function can be replaced with some kind of OOP pattern.
>>
>> def Device(DeviceType):
>> if DeviceType=='PSP':
>> return PSP()
>> elif DeviceType=="Power Supply"
>> return PWR()
>> etc...
>>
>> Thanks!
>
> Typically, you'd use a dictionary:
>
> DEVICE_DICT = {
>'PSP': PSP.
>'Power Supply': PWR,
># etc.
> }
>
> and your function would simply return DEVICE_DICT[device_type]()
> 


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


Re: beginner, idiomatic python

2007-08-26 Thread Alex Martelli
bambam <[EMAIL PROTECTED]> wrote:
   ...
> Bags don't seem to be built in to my copy of Python, and

A "bag" is a collections.defaultdict(int) [[you do have to import
collections -- it's in the standard library, NOT built-in]].


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


Re: how to remove number

2007-08-26 Thread Gabriel Genellina
En Tue, 21 Aug 2007 06:18:26 -0300, susanti marsol <[EMAIL PROTECTED]>  
escribi�:

> how to remove all number in our's document?

Can you be more specific?

-- 
Gabriel Genellina

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

Re: beginner, idiomatic python

2007-08-26 Thread Paul Rubin
"bambam" <[EMAIL PROTECTED]> writes:
> Is it safe to write
> A = [x for x in A if x in U]
> or is that undefined? I understand that the slice operation
> can be used to make a temporary copy, so I could write
> A=[x for x in A[:] if x in U]
> but I've just copied that without any understanding.

You get a temporary copy either way; note you're going to linearly
search U on every pass.  Maybe you want:

   SU = set(u)
   A = [a for x in A if x in SU]

or possibly

   A = list(set(A) & set(U))

which will remove duplicate elements from A and not necessarily keep
them in the same order, but is likely to be fastest of the bunch.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: SCF released GPL

2007-08-26 Thread hg
Dear all,

I am releasing much of my work including SCF (Cross platform Smart Card 
library & Tools written in Python) to the GPL license.

If interested, go to http://www.SnakeCard.com/Source.html

I am moving the doc to doxygen and cleaning up the code, so what you'll 
see there will change in the course of the next few weeks - basically 
can only get meaningful info on the classes hierarchy at this stage.
I am looking for a free subversion server resource to put the code ... 
if you know of any.

Some of the work there will be windows-only related (GINA, activeX 
components ... and not coded in Python) and the applets JavaCard and 
BasicCard ... I'm releasing these during the next few days.

Regards,

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


ANN: SCF released to GPL

2007-08-26 Thread hg
Dear all,

I am releasing much of my work including SCF (Cross platform Smart Card
library & Tools written in Python) to the GPL license.

If interested, go to http://www.SnakeCard.com/Source.html

I am moving the doc to doxygen and cleaning up the code, so what you'll see
there will change in the course of the next few weeks - basically can only
get meaningful info on the classes hierarchy at this stage.
I am looking for a free subversion server resource to put the code ... if
you know of any.

Some of the work there will be windows-only related (GINA, activeX
components ... and not coded in Python) and the applets JavaCard and
BasicCard ... I'm releasing these during the next few days.

Regards,

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


RE: Parser Generator?

2007-08-26 Thread Ryan Ginstrom
> On Behalf Of Paul McGuire
> 
> On Aug 26, 8:05 pm, "Ryan Ginstrom" <[EMAIL PROTECTED]> wrote:
> > The only caveat being that since Chinese and Japanese scripts don't 
> > typically delimit "words" with spaces, I think you'd have 
> to pass the 
> > text through a tokenizer (like ChaSen for Japanese) before 
> using PyParsing.
> 
> Did you think pyparsing is so mundane as to require spaces 
> between tokens?  Pyparsing has been doing this type of 
> token-recognition since Day 1.

Cool! I stand happily corrected. I did write "I think" because although I
couldn't find a way to do it, there might well actually be one . I'll
keep looking to find some examples of parsing Japanese.

BTW, I think PyParsing is great, and I use it for several tasks. I just
could never figure out a way to use it with Japanese (at least on the
applications I had in mind).

Regards,
Ryan Ginstrom

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


Re: wxpython thread exception crash

2007-08-26 Thread [david]
  class RedirectText:
  def __init__(self,aWxTextCtrl):
  self.out=aWxTextCtrl

  def write(self,string):
  wx.CallAfter(self.out.WriteText,string) #CallAfter

  def flush(self):
  pass

[david]

[david] wrote:
> What am I doing wrong?
> I'm trying to capture stdErr in a multi-threaded program.
> 
> This code crashes wxPython with
> /Py Assertion Error: C++ assertion "m_count=-1 || m_count=-2" failed/
> 
> What I'm trying to do is redirect stderr and stdout to a wxPython text 
> control.
> In an ideal world, when the worker thread crashes, I should get a stderr 
> message, with no effect on the main thread.
> 
> In an alternate world, I should get an asynchronous exception in the 
> main thread when there is an unhandled exception in the worker thread.
> 
> In the sample below, the program crashes on the following print statement.
> 
> Oddly enough, I do catch the unhandled worker exception in the main 
> thread IF THE WORKER THREAD HAS NO INIT PARAMETER. Note: the init 
> parameter is the only subtle thing in the code.
> 
> Since this is a crash, the exact behaviour will depend on your 
> environment. You may have difficulty seeing stdErr in some environments.
> 
> Python 2.5, wxPython 2.7.2.0, Windows XP.
> (david)
> 
> 
> import wx
> import sys
> import threading
> 
> class ExceptionThread(threading.Thread):
> def __init__(self,initvar):
> threading.Thread.__init__(self);
> 
> def run(self):
> raise "ET run"
> 
> 
> class RedirectText:
> def __init__(self,aWxTextCtrl):
> self.out=aWxTextCtrl
> 
> def write(self,string):
> self.out.WriteText(string)
> 
> def flush(self):
> pass
> 
> class Frame(wx.Frame):
> def __init__(self, image=None, parent=None):
> 
> wx.Frame.__init__(self, parent)
> self.text = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_RICH2)
> 
> # redirection window 
> redir=RedirectText(self.text)
> sys.stdout=redir
> sys.stderr=redir
> 
> 
> class App(wx.App):
> def OnInit(self):
> self.frame=Frame()
> self.frame.Show()
> self.Thread=ExceptionThread(1)
> self.Thread.start();
> return True
> 
> 
> app = App()
> print 'trigger print failure'
> app.MainLoop()
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: SCF released GPL

2007-08-26 Thread Paul Rubin
hg <[EMAIL PROTECTED]> writes:
> I am looking for a free subversion server resource to put the code
> ... if you know of any.

Does it have to be SVN?  I think Savannah and Sourceforge both still
use CVS.  I'm not sure what Launchpad uses.  I guess if necessary I
could set up a subversion repo for you on a server that I use.  I've
been wanting to put together some GNU security tools under the name
Fort GNOX, so maybe this can be a start.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: SCF released GPL

2007-08-26 Thread Alex Martelli
hg <[EMAIL PROTECTED]> wrote:
   ...
> I am looking for a free subversion server resource to put the code ...
> if you know of any.

Check out code.google.com -- it has a hosting service for open source
code, too, these days (and it IS subversion).


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


Re: ANN: SCF released GPL

2007-08-26 Thread hg
Paul Rubin wrote:
> hg <[EMAIL PROTECTED]> writes:
>> I am looking for a free subversion server resource to put the code
>> ... if you know of any.
> 
> Does it have to be SVN?  I think Savannah and Sourceforge both still
> use CVS.  I'm not sure what Launchpad uses.  I guess if necessary I
> could set up a subversion repo for you on a server that I use.  I've
> been wanting to put together some GNU security tools under the name
> Fort GNOX, so maybe this can be a start.

Nope CVS would be fine ... I guess I've made the switch in my head.

I'll check SourceForge.

Thanks.

hg


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


Re: ANN: SCF released to GPL

2007-08-26 Thread hg
hg wrote:
> Dear all,
> 
> I am releasing much of my work including SCF (Cross platform Smart Card
> library & Tools written in Python) to the GPL license.
> 
> If interested, go to http://www.SnakeCard.com/Source.html
> 
> I am moving the doc to doxygen and cleaning up the code, so what you'll see
> there will change in the course of the next few weeks - basically can only
> get meaningful info on the classes hierarchy at this stage.
> I am looking for a free subversion server resource to put the code ... if
> you know of any.
> 
> Some of the work there will be windows-only related (GINA, activeX
> components ... and not coded in Python) and the applets JavaCard and
> BasicCard ... I'm releasing these during the next few days.
> 
> Regards,
> 
> hg 
PS: I apologize for the "spam" ... I just changed ISP .. and my initial 
post did not make it (or so I thought) ... sorry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: SCF released GPL

2007-08-26 Thread hg
Alex Martelli wrote:
> hg <[EMAIL PROTECTED]> wrote:
>...
>> I am looking for a free subversion server resource to put the code ...
>> if you know of any.
> 
> Check out code.google.com -- it has a hosting service for open source
> code, too, these days (and it IS subversion).
> 
> 
> Alex

Will look it up ... thanks.

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


Re: beginner, idiomatic python

2007-08-26 Thread bambam
Thank you.

Steve.

"Alex Martelli" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> bambam <[EMAIL PROTECTED]> wrote:
>
>> Is it safe to write
>>
>> A = [x for x in A if x in U]
>>
>> or is that undefined? I understand that the slice operation
>
> It's perfectly safe and well-defined, as the assignment rebinds the LHS
> name only AFTER the RHS list comprehension is done.
>
>
> Alex 


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


Re: beginner, idiomatic python

2007-08-26 Thread bambam
Thank you. I figured the set would probably be faster,
but the lists are small, and I'm concerned that the code
is going to look Byzantine if I keep swapping between
lists, sets and dictionaries :~).

At the moment there are no sets or dictionaries in the
entire code base I am working with. I'm not sure if the
place I am looking at right now is supposed to support
duplicates or not: duplicates are permitted, but they
cause report anomalies.

Steve.


"Paul Rubin"  wrote in message 
news:[EMAIL PROTECTED]
> "bambam" <[EMAIL PROTECTED]> writes:
>> Is it safe to write
>> A = [x for x in A if x in U]
>> or is that undefined? I understand that the slice operation
>> can be used to make a temporary copy, so I could write
>> A=[x for x in A[:] if x in U]
>> but I've just copied that without any understanding.
>
> You get a temporary copy either way; note you're going to linearly
> search U on every pass.  Maybe you want:
>
>   SU = set(u)
>   A = [a for x in A if x in SU]
>
> or possibly
>
>   A = list(set(A) & set(U))
>
> which will remove duplicate elements from A and not necessarily keep
> them in the same order, but is likely to be fastest of the bunch. 


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


Re: Error with Simplemapi.py

2007-08-26 Thread Mick Duprez
On Aug 27, 2:00 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 24 Aug 2007 04:03:05 -0300, Mick Duprez <[EMAIL PROTECTED]>
> escribi?:
>
> > I have a small problem. I get an error I don't know how to resolve,
> > any help would be much appreciated.
> > I'm using Python25 on winXP pro and the script from the link above.
> > Here's the error -
>
>  mailtest.SendMail('[EMAIL PROTECTED]','test','test
>  string','c:\dbs.txt')
>
> That should be 'c:\\dbs.txt' or r'c:\dbs.txt'
>
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > mailtest.SendMail('[EMAIL PROTECTED]','test','test string','c:
> > \dbs.txt')
> >   File "C:\Python25\mailtest.py", line 135, in SendMail
> > cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
> >   File "C:\Python25\lib\ctypes\__init__.py", line 478, in cast
> > return _cast(obj, obj, typ)
> > ArgumentError: argument 1: : wrong type
>
> I'm unsure what those cast(NULL, ...) are supposed to do, but they look
> all wrong. NULL, as defined on that script, is *not* a C NULL pointer (use
> None for that).
> (In fact the whole script doesn't look well at all - do you *have* to use
> MAPI? can't use SMTP instead? Even if you must use MAPI, try the pywin32
> package from Mark Hammond, it has MAPI support and a demo script for
> sending mail)
>
> > I have had a brief look at the C api for these structs and functions
> > but I can't resolve it, it is probably something simple.
> > The piece of code I don't understand though is this -
>
> > MapiRecipDesc_A = MapiRecipDesc * len(RecipWork) #size of struct??
>
> This declares a new type, an array of len(RecipWork) items, each of type
> MapiRecipDesc
>
> > rda = MapiRecipDesc_A() # isn't it MapiRecipDesc as declared??
>
> This creates an instance of the above array.
>
> --
> Gabriel Genellina

Thank you very much Gabriel, changing the NULL to None did the trick
(it also helps if I reload the changed module after editing!:( ). Yes
that is an old script and I will look into your suggestions. Basically
I'd just like to use the default mail client (windows or Unix/Linux)
to send simple mail with attachments, this way I can log the
attachments I send to a db for example for document transmittal/
register reports etc.
Thanks also for the code explanations,
Cheers,
Mick.

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


Re: Error with Simplemapi.py

2007-08-26 Thread Gabriel Genellina
En Mon, 27 Aug 2007 03:05:30 -0300, Mick Duprez <[EMAIL PROTECTED]>  
escribi�:

> Thank you very much Gabriel, changing the NULL to None did the trick
> (it also helps if I reload the changed module after editing!:( ).

Glad to see it worked.

> Yes
> that is an old script and I will look into your suggestions. Basically
> I'd just like to use the default mail client (windows or Unix/Linux)
> to send simple mail with attachments, this way I can log the
> attachments I send to a db for example for document transmittal/
> register reports etc.

Hmmm... altough you may find some MAPI implementation for Linux, it's very  
uncommon; consider using sendmail instead, or ask for an outbound SMTP  
server and use the smtplib module.

-- 
Gabriel Genellina

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