Re: Inserting Records into SQL Server - is there a faster interface than ADO

2005-11-14 Thread Oren Tirosh
> We are using the stored procedure to do a If Exist, update, else Insert 
> processing for
> each record.

Consider loading the data in batches into a temporary table and then
use a single insert statement to insert new records and a single update
statement to update existing ones. This way, you are not forcing the
database to do it one by one and give it a chance to aggressively
optimize your queries and update the indexes in bulk. You'd be
surprized at the difference this can make!

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


Re: Is it possible to detect if files on a drive were changed without scanning the drive?

2005-09-12 Thread Oren Tirosh
> After connecting a drive to the system (via USB
> or IDE) I would like to be able to see within seconds
> if there were changes in the file system of that drive
> since last check (250 GB drive with about four million
> files on it).

Whenever a file is modified the last modification time of the directory
containing it is also set. I'm not sure if the root directory itself
has a last modification time field but you can just store and compared
the last mod time of all subdirectories directly under the root
directory.

If you trust the clock of all machines mounting this drives is set
correctly (including time zone) you can store just a single timestamp
and compare for files or directories modified after that time.
Otherwise you will need to store and compare for any changes, not just
going forward.

  Oren

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


Re: Virtual Slicing

2005-08-27 Thread Oren Tirosh
Bryan Olson wrote:
> I recently wrote a module supporting value-shared slicing. I
> don't know if this functionality already existed somewhere,

In the Numarray module slices are a view into the underlying array
rather than a copy.

http://www.stsci.edu/resources/software_hardware/numarray

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


Re: Email client in Pyhton

2005-08-25 Thread Oren Tirosh
> IIRC, many of the mailbox modules (such as mailbox and
> mhlib) are read-only, but they should provide a good starting point.

The mailbox module has recently been upgraded for full read-write
access by a student participating in google's Summer of Code. It is
currently under review for inclusion in the standard library.

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


Re: How to get a unique id for bound methods?

2005-08-22 Thread Oren Tirosh
Russell E. Owen wrote:
> I have several situations in my code where I want a unique identifier
> for a method of some object (I think this is called a bound method). I
> want this id to be both unique to that method and also stable (so I can
> regenerate it later if necessary).

>>> def persistent_bound_method(m):
... return m.im_self.__dict__.setdefault(m.im_func.func_name, m)
...
>>> class A:
... def x(self):
... return
...
>>> a=A()
>>> a.x is a.x
False
>>> persistent_bound_method(a.x) is persistent_bound_method(a.x)
True
>>>

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


Re: JBUS and Python which way

2005-08-02 Thread Oren Tirosh
If you can't find any JBUS/Modbus modules specific for Python it's
possible to use one of the many C/C++ modules available and make a
Python wrapper for it with an interface generator like SWIG or SIP. You
say that you don't have much technical background so you may consider
hiring someone to do it. It's not a big project so it shouldn't be too
expensive.

  Oren

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


Re: voicemail program written with python

2005-06-22 Thread Oren Tirosh
It is relatively easy to write voice applications for the Asterisk
software PBX using the CGI-like AGI (Asterisk Gateway Interface).

The following document describes the AGI and has some examples in
Python:

http://home.cogeco.ca/~camstuff/agi.html

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


Re: Python choice of database

2005-06-20 Thread Oren Tirosh
Philippe C. Martin wrote:
> Hi,
>
> I am looking for a stand-alone (not client/server) database solution for
> Python.
>
> 1) speed is not an issue
> 2) I wish to store less than 5000 records
> 3) each record should not be larger than 16K

How about using the filesystem as a database? For the number of records
you describe it may work surprisingly well. A bonus is that the
database is easy to manage manually. One tricky point is updating: you
probably want to create a temporary file and then use os.rename to
replace a record in one atomic operation.

For very short keys and record (e.g. email addresses) you can use
symbolic links instead of files. The advantage is that you have a
single system call (readlink) to retrieve the contents of a link. No
need to open, read and close.

This works only on posix systems, of course. The actual performance
depends on your filesystem but on linux and BSDs I find that
performance easily rivals that of berkeleydb and initialization time is
much faster. This "database" also supports reliable concurrent access
by multiple threads or processes.

See http://www.tothink.com/python/linkdb

Oren

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


Re: 1980's Home Computer-style Package.

2005-06-17 Thread Oren Tirosh
http://tothink.com/python/progman/

This module implements BASIC-like NEW, LOAD, RUN (sorry, no SAVE...).

   Oren

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


Re: Set of Dictionary

2005-06-17 Thread Oren Tirosh
See the frozendict recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/414283

It was written exactly for this purpose: a dictionary that can be a
member in a set.

  Oren

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


Re: ElementTree Namespace Prefixes

2005-06-14 Thread Oren Tirosh
> you forgot
>
>http://effbot.org/zone/element-infoset.htm
>
> which describes the 3-node XML infoset subset used by ElementTree.

No, I did not forget your infoset subset. I was comparing it with other
infoset subsets described in various XML specifications.

I agree 100% that prefixes were not *supposed* to be part of the
document's meaning back when the XML namespace specification was
written, but later specifications broke that.

Please take a look at http://www.w3.org/TR/xml-c14n#NoNSPrefixRewriting

"... there now exist a number of contexts in which namespace prefixes
can impart information value in an XML document..."

"...Moreover, it is possible to prove that namespace rewriting is
harmful, rather than simply ineffective."

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


Re: ElementTree Namespace Prefixes

2005-06-13 Thread Oren Tirosh
Fredrik Lundh wrote:
> Chris Spencer wrote:
>
> > If an XML parser reads in and then writes out a document without having
> > altered it, then the new document should be the same as the original.
>
> says who?

Good question. There is no One True Answer even within the XML
standards.

It all boils down to how you define "the same". Which parts of the XML
document are meaningful content that needs to be preserved and which
ones are mere encoding variations that may be omitted from the internal
representation?

Some relevant references which may be used as guidelines:

* http://www.w3.org/TR/xml-infoset
The XML infoset defines 11 types of information items including
document type declaration, notations and other features. It does not
appear to be suitable for a lightweight API like ElementTree.

* http://www.w3.org/TR/xpath-datamodel
The XPath data model uses a subset of the XML infoset with "only" seven
node types.

http://www.w3.org/TR/xml-c14n
The canonical XML recommendation is meant to describe a process but it
also effectively defines a data model: anything preserved by the
canonicalization process is part of the model. Anything not preserved
is not part of the model.

In theory, this definition should be equivalent to the xpath data model
since canonical XML is defined in terms of the xpath data model. In
practice, the XPath data model defines properties not required for
producing canonical XML (e.g. unparsed entities associated with
document note). I like this alternative "black box" definition because
provides a simple touchstone for determining what is or isn't part of
the model.

I think it would be a good goal for ElementTree to aim for compliance
with the canonical XML data model. It's already quite close.

It's possible to use the canonical XML data model without being a
canonical XML processor but it would be nice if parse() followed by
write() actually passed the canonical XML test vectors. It's the
easiest way to demonstrate compliance conclusively.

So what changes are required to make ElementTree canonical?

1. PI nodes are already supported for output. Need an option to
preserve them on parsing
2. Comment nodes are already support for output. Need an option to
preserve them on parsing (canonical XML also defines a "no comments"
canonical form)
3. Preserve Comments and PIs outside the root element (store them as
children of the ElementTree object?)
4. Sorting of attributes by canonical order
5. Minor formatting and spacing issues in opening tags

oh, and one more thing...

6. preserve namespace prefixes ;-)
(see http://www.w3.org/TR/xml-c14n#NoNSPrefixRewriting for rationale)

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


Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements

2005-06-04 Thread oren . tirosh
Ilpo Nyyssönen wrote:
> Nicolas Fleury <[EMAIL PROTECTED]> writes:
> > def foo():
> > with locking(someMutex)
> > with opening(readFilename) as input
> > with opening(writeFilename) as output
> > ...
>
> How about this instead:
>
> with locking(mutex), opening(readfile) as input:
> ...

+1, and add PEP-328-like parentheses for multiline.

  Oren

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


Re: ElemenTree and namespaces

2005-05-16 Thread oren . tirosh
Matthew Thorley wrote:
> Does any one know if there a way to force the ElementTree module to
> print out name spaces 'correctly' rather than as ns0, ns1 etc? Or is
> there at least away to force it to include the correct name spaces in
> the output of tostring?
>
> I didn't see anything in the api docs or the list archive, but before
I
> set off to do it myself I thought I should ask, because it seemed
like
> the kind of thing that has already been done.

There's a way, but it requires access to an undocumented internal
stuff. It may not be compatible with other implementations of the
ElementTree API like lxml.

The ElementTree module has a _namespace_map dictionary of "well known"
namespace prefixes mapping namespace URIs to prefixes. By default it
contains the xml:, html:, rdf: and wsdl:. You can add your own
namespace to that dictionary to get your preferred prefix.

In theory, namespace prefixes are entirely arbitrary and only serve as
a temporary link to the namespace URI. In practice, people tend to get
emotionally attached to their favorite prefixes. XPath also breaks this
theory because it refers to prefixes rather than URIs.


Take a look at http://www.tothink.com/python/ElementBuilder. It's a
module to provide a friendly syntax for building and populating
Elements:

Example:

>>> import ElementBuilder
>>> from elementtree import ElementTree
>>> ns = ElementBuilder.Namespace('http://some.uri', 'ns')
>>> e = ns.tag(
...   ns.tag2('content'),
...   ns.tag3(attr='value'),
...   ns.tag4({ns.attr: 'othervalue'}),
...   ns.x(
... ns.y('y'),
... ns.z('z'),
... 'some text',
...   )
... )
>>> ElementTree.dump(e)
http://some.uri";>contentyzsome text

Note that the namespace prefix on output is not "ns0". The second
argument to the Namespace constructor is the prefix hint and unless it
collides with any other namespace or prefix it will be added to
_namespace_map dictionary and used on output.


  Oren

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


Re: Removing dictionary-keys not in a set?

2005-04-18 Thread Oren Tirosh
"Tim N. van der Leeuw" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> Hi,
> 
> I'd like to remove keys from a dictionary, which are not found in a
> specific set. 

Here's my magic English-to-Python translator:

"I'd like to ... keys which ..."  ->  "for key in"
"keys from a dictionary"  ->  "set(dictionary)"
"not found in a specific set" ->  "-specificset"
"... remove keys ..." ->  "del dictionary[key]"

Putting it all together:

>>> for key in set(dictionary)-specificset:
...del dictionary[key]

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


Re: pre-PEP: Suite-Based Keywords

2005-04-16 Thread Oren Tirosh
Take a look at Nick Coglan's "with" proposal:

http://groups.google.co.uk/groups?selm=mailman.403.1105274631.22381.python-list%40python.org

It addresses many of the same issues (e.g. easy definition of
properties). It is more general, though: while your proposal only
applies to keyword arguments in a function call this one can be used
to name any part of a complex expression and define it in a suite.

I think that a good hybrid solution would be to combine the "with"
block with optional use of the ellipsis to mean "all names defined in
the with block".

See also the thread resulting from Andrey Tatarinov's original
proposal (using the keyword "where"):

http://groups.google.co.uk/groups?selm=3480qqF46jprlU1%40individual.net


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


Re: Suggesting a new feature - "Inverse Generators"

2005-03-26 Thread Oren Tirosh
"Jordan Rastrick" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> Hmmm, I like the terminology consumers better than acceptors.

Here's an implementation of Python consumers using generators:
http://groups.google.co.uk/[EMAIL PROTECTED]

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


Re: Turn of globals in a function?

2005-03-26 Thread Oren Tirosh
Ron_Adam <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Is there a way to hide global names from a function or class?
> 
> I want to be sure that a function doesn't use any global variables by
> mistake.  So hiding them would force a name error in the case that I
> omit an initialization step.  This might be a good way to quickly
> catch some hard to find, but easy to fix, errors in large code blocks.

def noglobals(f):
.   import new
.   return new.function(
.   f.func_code, 
.   {'__builtins__':__builtins__},
.   f.func_name, 
.   f.func_defaults, 
.   f.func_closure
.   )

You can use it with the Python 2.4 @decorator syntax:

@noglobals
def a(...):
.   # code here

Doing this for a class is a little more work. You will need dig inside
to perform this treatment on each method separately and handle new and
old-style classes a bit differently.

Note that this kind of function may declare globals. They will be
persistent but private to the function.

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


Re: managing multiple subprocesses

2005-02-07 Thread Oren Tirosh
"Marcos" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> ...
> os.systems / commands etc etc. I realise the subprocess module may have
> what I need but I can't get python 2.4 on the Mac so I need a 2.3 based
> solution. Any help is much appreciated. Cheers.

The Python 2.4 subprocess module by Peter Astrand is pure python for
posix systems (a small C extension module is required only for win32
systems). You can bundle it with your code and use it with older
Python versions. It even contains backward compatibility code to
replace True and False if not found so it can run on Python 2.2.

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


Re: Word for a non-iterator iterable?

2005-02-07 Thread Oren Tirosh
Leif K-Brooks <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Is there a word for an iterable object which isn't also an iterator, and 
> therefor can be iterated over multiple times without being exhausted? 
> "Sequence" is close, but a non-iterator iterable could technically 
> provide an __iter__ method without implementing the sequence protocol, 
> so it's not quite right.

"reiterable". I think I was the first to use this word on
comp.lang.python.

If you have code that requires this property might want to use this
function:

.def reiter(x):
.i = iter(x)
.if i is x:
.raise TypeError, "Object is not re-iterable"
.return i

example:

.for outer in x:
.for inner in reiter(y):
.do_something_with(outer, inner)

This will raise an exception when an iterator is used for y instead of
silently failing after the first time through the outer loop and
making it look like an empty container.

When iter() returns a new iterator object it is a good hint but not a
100% guarantee that the object is reiterable. For example, python 2.2
returned a new xreadlines object for iterating over a file but it
messed up the underlying file object's state so it still wasn't
reiterable. But when iter() returns the same object - well, that's a
sign that the object is definitely not reiterable.

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