Re: What is Expressiveness in a Computer Language

2006-07-01 Thread Joachim Durchholz
Matthias Blume schrieb:
> Erlang relies on a combination of purity, concurrency, and message
> passing, where messages can carry higher-order values.
> 
> Data structures are immutable, and each computational agent is a
> thread.  Most threads consist a loop that explicitly passes state
> around.  It dispatches on some input event, applies a state
> transformer (which is a pure function), produces some output event (if
> necessary), and goes back to the beginning of the loop (by
> tail-calling itself) with the new state.

Actually any Erlang process, when seen from the outside, is impure: it 
has observable state.
However, from what I hear, such state is kept to a minimum. I.e. the 
state involved is just the state that's mandated by the purpose of the 
process, not by computational bookkeeping - you won't send file 
descriptors in a message, but maybe information about the state of some 
hardware, or about a permanent log.

So to me, the approach of Erlang seems to amount to "make pure 
programming so easy and efficient that aren't tempted to introduce state 
that isn't already there".

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


Re: string replace

2006-07-01 Thread Michele Petrazzo
[EMAIL PROTECTED] wrote:
> Check out the .translate method and the string.maketrans documentation.
>  You can use it to delete a list of characters all in one line:
> 

Yes. This is, more or less, what I were looking for.

P.s. Sure, if replace could accept a tuple... :)

Thanks to all,
Michele
-- 
http://mail.python.org/mailman/listinfo/python-list


missing feature classes and missing fields

2006-07-01 Thread subramanian2003
Hello All,

How can I check missing feature classes in a folder/personal geodatabase 
using python script. And how can I check  missing fields in shape files. And 
also I want to check the attribute values using python.

Thnx,
Subramanian.



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


Re: languages with full unicode support

2006-07-01 Thread Joachim Durchholz
Chris Uppal schrieb:
> Joachim Durchholz wrote:
> 
>>> This is implementation-defined in C.  A compiler is allowed to accept
>>> variable names with alphabetic Unicode characters outside of ASCII.
>> Hmm... that could would be nonportable, so C support for Unicode is
>> half-baked at best.
> 
> Since the interpretation of characters which are yet to be added to
> Unicode is undefined (will they be digits, "letters", operators, symbol,
> punctuation ?), there doesn't seem to be any sane way that a language 
> could
> allow an unrestricted choice of Unicode in identifiers.

I don't think this is a problem in practice. E.g. if a language uses the 
usual definition for identifiers (first letter, then letters/digits), 
you end up with a language that changes its definition on the whims of 
the Unicode consortium, but that's less of a problem than one might 
think at first.

I'd expect two kinds of changes in character categorization: additions 
and corrections. (Any other?)

Additions are relatively unproblematic. Existing code will remain valid 
and retain its semantics. The new characters will be available for new 
programs.
There's a slight technological complication: the compiler needs to be 
able to look up the newest definition. In other words, for a compiler to 
run, it needs to be able to access http://unicode.org, or the language 
infrastructure needs a way to carry around various revisions of the 
Unicode tables and select the newest one.

Corrections are technically more problematic, but then we can rely on 
the common sense of the programmers. If the Unicode consortium 
miscategorized a character as a letter, the programmers that use that 
character set will probably know it well enough to avoid its use. It 
will probably not even occur to them that that character could be a 
letter ;-)


Actually I'm not sure that Unicode is important for long-lived code. 
Code tends to not survive very long unless it's written in English, in 
which case anything outside of strings is in 7-bit ASCII. So the 
majority of code won't ever be affected by Unicode problems - Unicode is 
more a way of lowering entry barriers.

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


Re: list comprehension

2006-07-01 Thread [EMAIL PROTECTED]
I found the Wiki article on list comprehensions useful for
understanding the general concept.
See it at: http://en.wikipedia.org/wiki/List_comprehension
It talks about how a list comprehension can be thought of as equivalent
to a traditional set-builder notation in math. For example in math
notation, the expression S={x | x in N, x>4} creates an enumerable,
infinite set {5,6,7,...}.

In Python a similar concept applies. Say you have a list L1=[1,2,3,4,5]
and you need another list L2 that will contain the 10th power of all
the elements of  L1 greater than 3. In traditional math set notation
you  would write something like:
L2={x^10 | x in L1, x>3}
and in Python it would be:
L2=[x**10 for x in L1 if x>3]
You can see the correspondence between the two notations. The 'for' is
like '|' and ',' is like an 'if', in rest it is almost the same.

Hope this helps.
-Nick




Simon Forman wrote:
> a wrote:
> > can someone tell me how to use them
> > thanks
>
> basically, a list comprehension is just like a for loop,  if you wrote
> it out the "long way" it would be something like this:
>
> results = []
> for var in some_iterable:
> if some condition:
> results.append(some expression)
>
>
> The list comprehension version:
>
> results = [some expression for var in some_iterable if some condition]
>
>
> There's more to it, but that's the basic idea.
> 
> Hope this helps,
> ~Simon

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


Re: beautifulsoup .vs tidy

2006-07-01 Thread Paddy

bruce wrote:
> hi...
>
> never used perl, but i have an issue trying to resolve some html that
> appears to be "dirty/malformed" regarding the overall structure. in
> researching validators, i came across the beautifulsoup app and wanted to
> know if anybody could give me pros/cons of the app as it relates to any of
> the other validation apps...
>
I'm not too sure of what you are after. You mention tidy in the subject
which made me think that maybe you were trying to generate well-formed
HTML from malformed webppages that nonetheless browsers can interpret.
If that is the case then try HTML tidy:
  http://www.w3.org/People/Raggett/tidy/

- Pad.

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


Re: Maximize main window with code

2006-07-01 Thread Fredrik Lundh
JohnJohnUSA wrote:

> I am new to Python.  How do I get the following program to appear
> initially with the window maximized?  Thanks for your help!
> 
> from Tkinter import *
> # set up the window itself
> top = Tk()

top.state("zoomed")

> F = Frame(top)
> F.pack()
> # add the widgets
> lHello = Label(F, text="Hello")
> lHello.pack()
> bQuit = Button(F, text="Quit", command=F.quit)
> bQuit.pack()
> # set the loop running
> top.mainloop()



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


Re: Immutability

2006-07-01 Thread [EMAIL PROTECTED]
That is why I don't like the use of @property.  Even though the
decorator is a nice short-hand notation, it is more confusing in my
oppinion.  So someone is more likely still call the property as a
function when looking at:

class C:
   @property
   def data(self):
   return 42

rather than if they saw:

class C:
   def _data(self):
   return 42
   data=property(_data)

I personally I find the second case more readable, even though it is
longer.

-Nick


Fredrik Lundh wrote:
> Nick Maclaren wrote:
>
> > |> a property looks like an attribute, not a method, so you're trying to 
> > call whatever
> > |> your "joe()" method returns.
> >
> > Well, yes, that was pretty obvious - but what was NOT obvious is why it
> > should do that for one of two identical methods.
>
> identical?  you only applied @property to one of the methods, and then you're
> surprised that only one of the methods were turned into a property?
>
> > |> (that's what "a function for getting an attribute value" in the property 
> > documentation
> > |> refers to).
> >
> > Well, as joe is an attribute of the class fred, and the decorator is applied
> > to the declaration of joe within fred, I assumed that it referred to getting
> > joe from fred.  That certainly doesn't appear to be the case
>
> @property turns your "joe" method into a getter method for the (virtual) 
> attribute
> "joe".  when you access the attribute, the getter method will be called.  
> whatever
> that method returns will be the attribute's value.  that's what the 
> documentation
> says, and that's what your code is doing.
> 
> 

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


Re: Reddit broke - should have remained on Lisp?

2006-07-01 Thread Alok
Fredrik Lundh wrote:
> Alok wrote:
>
> > Their site was more responsive last year.
>
> http://tinyurl.com/zhary
>
> 
Thats an interesting URL my friend. For those of you wondering what the
spike in April was due to, check out this one

http://www.joelonsoftware.com/items/2006/03/20.html

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


Re: Module executed twice when imported!

2006-07-01 Thread Georg Brandl
Michael Abbott wrote:
> In article <[EMAIL PROTECTED]>,
>  Georg Brandl <[EMAIL PROTECTED]> wrote:
>> That's because __name__ is normally set to the module's name in the package
>> hierarchy. When you set it to "some1.some2", Python thinks it's
>> in a subpackage
> 
> A.
> 
> So what I *should* have set it to is the module name *without* 
> extension, i.e. __name__='imptest'
> 
> Thank you.  Now I think I understand it.

You're welcome. This is indeed not easy to look through.

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


Re: style question

2006-07-01 Thread Jorgen Grahn
On Thu, 29 Jun 2006 15:31:53 -0700, Scott David Daniels <[EMAIL PROTECTED]> 
wrote:
...
>> I like well-typeset code in print though. Bjarne Stroustrup uses an elegant
>> system for C++ code, 

> See Knuth on Literate Programming and the "Web" systems (e.g. CWeb).
> His goal is to look good typeset with explanation, and extract-to-compile.

Yes, I'm aware of Knuth's work, and didn't mean to imply that Stroustrup did
something revolutionary -- although his book and Bertrand Meyer's Eiffel
book are the only ones I've read which try do something elegant with the
code typesetting.

I haven't read Knuth until now, so I assumed he typeset the actual code
parts fixed-width. I see in the CWeb manual that that's not the case.

/Jorgen

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


Re: using TreeBuilder in an ElementTree like way

2006-07-01 Thread Fredrik Lundh
Greg Aumann wrote:

> In reading the elementtree documentation I found the 
> ElementTree.TreeBuilder class which it says can be used to create 
> parsers for XML-like languages.

a TreeBuilder is a thing that turns a sequence of start(), data(), and 
end() method calls into an Element tree structure.

a Parser is a think that turns a sequence of feed() method calls into a 
stream of start(), data(), and end() method calls on a target object. 
the standard parsers all automatically uses a TreeBuilder instance as 
the default target.

unfortunately, the current ET release uses classes named XXXTreeBuilder 
also for the actual parsers, which is a bit confusing.  (the reason for 
this is historical; the separate TreeBuilder class is factored out from 
a couple of format-specific XXXTreeBuilder parsers, but the naming 
wasn't fully sorted out).

> Essentially I was trying to implement the following advice from Frederik 
> Lundh (Wed, Sep 8 2004 12:54 am):
>  > by the way, it's trivial to build trees from arbitrary SAX-style sources.
>  > just create an instance of the ElementTree.TreeBuilder class, and call
>  > the "start", "end", and "data" methods as appropriate.
>  >
>  > builder = ElementTree.TreeBuilder()
>  > builder.start("tag", {})
>  > builder.data("text")
>  > builder.end("tag")
>  > elem = builder.close()

that's the intended use of the TreeBuilder class.

> but in another post he wrote (Wed, May 21 2003 2:56 am):
>  > usage:
>  >
>  > from elementtree import ElementTree, HTMLTreeBuilder
>  >
>  > # file is either a filename or an open stream
>  > tree = ElementTree.parse(file, parser=HTMLTreeBuilder.TreeBuilder())
>  > root = tree.getroot()
>  >
>  > or
>  >
>  > from elementtree import HTMLTreeBuilder
>  >
>  > parser = HTMLTreeBuilder.TreeBuilder()
>  > parser.feed(data)
>  > root = parser.close()

and this is the confusing naming; here, the HTMLTreeBuilder.TreeBuilder 
class is actually doing the parsing (which uses a TreeBuilder instance 
on the inside).

> This second one makes me think I should have implemented a parser class 
> using Treebuilder.

that's entirely up to you: the only real advantage of having a parser 
class is that you can pass it to any other module that uses the Python 
consumer interface:

 http://effbot.org/zone/consumer.htm

but if that's not relevant for your application, feel free to use a 
TreeBuilder directly.

> Also when I used return builder.close() in the code below it didn't return
 > an ElementTree structure but an _ElementInterface.

an Element, in other words (i.e. the thing returned by the Element 
factory in this specific implementation).  that's the documented 
behaviour; if you want an ElementTree wrapper, you have to wrap it yourself.



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


Re: style question

2006-07-01 Thread Jorgen Grahn
On Thu, 29 Jun 2006 23:19:34 +0200, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Jorgen Grahn wrote:
>
>>> assuming fixed-pitch fonts isn't very Pythonic, though; to get reliable 
>>> indentation
>>> no matter what font you're using, you can write [...]
>> 
>> Since when?  I've always coded, in all languages I've ever used[1], under the
>> assumption that the reader will view it with a fixed-pitch (or whatever the
>> proper term is) font. I assumed everyone else did, too.
>
> that's a popular myth.

I'm sorry, you will have to come up with some real references to convince me
(a PEP or preferrably something not Python-specific). Or not, because I will
keep assuming a fixed-width font in my programming anyway. Living the myth!

/Jorgen

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


Computer Industry Workers May Face Cancer Risks

2006-07-01 Thread studyandjobs
Computer Industry Workers May Face Cancer Risks

http://www.studyandjobs.com/Comp_worker_cancer.html

or visit
http://www.studyandjobs.com/Cancer.html

Regards

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


Re: Replace Whole Object Through Object Method

2006-07-01 Thread Stefan Schwarzer
Hi Bruno :)

On 2006-06-27 10:30, Bruno Desthuilliers wrote:
> FWIW, a good part of the canonical design patterns are mostly workaround
> the lack of flexibility in languages like C++ and Java.

May be, but that doesn't exclude that some patterns are also
useful in Python. :-)

> The Strategy
> pattern's simplest Python implementation is to dynamically replace a
> method on a per-object basis. The State pattern's simplest
> implementation in Python is to dynamically change the class of an object.

It may be the "simplest" but it might not be the most "natural"
in terms of the problem domain.

At the Informationsdienst Wissenschaft ( http://idw-online.de )
we had a similar design problem. There, a person can have many
roles, like subscriber, journalist, public info officer etc. We
found it most natural to implement this with the actor/role
pattern, as I V described it.

> Of course, one of the canonical solutions to the OP's problem is to use
> composition/delegation. But doing it the canonical way would imply
> creating instances of the role objects and passing them the instance as
> param so they can access it's attributes. It works, but it creates a
> cyclic dependancy between the object and it's roles, so you would have
> to use weakrefs.

You don't have to, unless both classes have a __del__ method and
the garbage collector thus can't decide which to collect/delete
first.

> Dynamically creating new classes with the appropriate
> bases and assigning them to the object's __class__ attribute is another
> way to achieve the same result, and it's perfectly legal.

It might be "legal" but it also may be confusing. I would use the
design that makes the software easiest to maintain in the long
run. (If you don't know what the long run is, consider the
"medium run" and refactor later. :) )

> Now I do agree that it can become tricky to manage correctly wrt/ mro
> rules !-)

See? ;-) Software shouldn't be tricky (or only as tricky as
necessary). I value clarity over cleverness.

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


Non-ASCII languages (was: Re: style question)

2006-07-01 Thread Jorgen Grahn
On Thu, 29 Jun 2006 23:19:34 +0200, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Jorgen Grahn wrote:
...
>> (I like well-typeset code in print though. Bjarne Stroustrup uses an elegant
>> system for C++ code, where identifiers and strings are in Times italic,
>> operators in Courier, and so on.)
>
> the idea of printing everything in courier (or some other monospace 
> font) is a rather new idea; if you read seventies stuff, the program 
> code is often as carefully designed as the rest of the document.

Possibly true, and definitely for Knuth.  But WYSIWYG was unknown at the
time; these people all programmed using fixed-width fonts, on teletypes or
character-mapped terminals. Hell, even full-screen editors were new and
controversial until the late 1970s!

Program editing and displaying/typesetting can be treated as separate from
each other. Personally, I think they /should/ be -- I prefer troff or LaTeX
to MS Word, after all.

> (for an indication that we might be moving back to nicely rendered code, 
> see Sun's new Fortress language, which provides extraordinarily detailed 
> control over how identifiers are rendered, including extensive support 
> for Unicode and math notation.  it also mandates the use of proportional 
> fonts for things like identifiers and comments...)

And Sun apparently think they should not be separate.
To me, it looks like they are planning for this language to fail.

If I wanted to try out this language, I would have to give up most of my
existing toolbox -- which works flawlessly with everything from TI assembly
to Python. And what would people discuss on comp.lang.fortress? Google
destroys Python code well enough ...

/Jorgen

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


Re: Non-ASCII languages (was: Re: style question)

2006-07-01 Thread Nick Maclaren

In article <[EMAIL PROTECTED]>,
Jorgen Grahn <[EMAIL PROTECTED]> writes:
|> 
|> Possibly true, and definitely for Knuth.  But WYSIWYG was unknown at the
|> time; these people all programmed using fixed-width fonts, on teletypes or
|> character-mapped terminals. Hell, even full-screen editors were new and
|> controversial until the late 1970s!

A slight niggle - WYSIWYG wasn't unknown, just both rare and not yet
called that!  I have programmed using devices with half-line shifts,
real backspacing and so on - and some languages did mandate that a
character created by overprinting was to be treated as a composite
character.

Also, there were full-screen editors for things like IBM 3270s, though
they were absolutely ghastly for editing text (being designed for form
filling).

I agree with you that neither those days nor gimmicky approaches like
that of Fortress are worth pursuing.  One of the main reasons that
'program proving' has never taken off outside its cabal is that it
uses bizarre notations unlike anything else on earth that can't be
edited in a normal fashion.


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


206 The filename or extension is too long / OSError: [Errno 38] Filename too long

2006-07-01 Thread robert
e.g. open/os module functions (os.path.getmtime...) and 
win32api/win32file functions fail on long paths (>~255 chars)

even the '\\?\' trick from 
http://www.google.com/url?sa=D&q=http://msdn.microsoft.com/library/default.asp%3Furl%3D/library/en-us/fileio/fs/naming_a_file.asp
does not work:

 >>> os.path.getmtime('?\\'+fabs)
Traceback (most recent call last):
   File "", line 1, in ?
   File "C:\PYTHON23\lib\ntpath.py", line 232, in getmtime
 return os.stat(filename).st_mtime
OSError: [Errno 38] Filename too long
 >>>

 >>> win32api.GetFileAttributes('?\\'+fabs)
Traceback (most recent call last):
   File "", line 1, in ?
error: (206, 'GetFileAttributes', 'Der Dateiname oder die Erweiterung 
ist zu lang.')
 >>>

(='206 The filename or extension is too long')

What can I do?


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


I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread gavino
This seems easy but I have been asking tcl and python IRC chat all day
and no one gave an answer.
I have 100 servers which need a new backup server added to a text file,
 and then the backup agent restarted.
If I have a list of the servers, all with same root password, and the
connection is ssh.
How do I connect to the server, cat the line to the config file, stop
adn start the agent, and then do same to next server in list and
iterate through the 100 servers. 
What script would allow this?

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


Re: Interprocess communication on multi-user machine

2006-07-01 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Nick Maclaren) wrote:

>In article <[EMAIL PROTECTED]>,
>Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:
>|> >
>|> >Sockets are often accessed via special files, but are not files.
>|> 
>|> They are files. They are not _regular_ files.
>
>Yes, I know about UNIX-domain sockets, but even when they give the
>appearance of being files, 90% of the time that is the API only,
>and the underlying facility is very different.

Irrelevant. The userland API requires accessing a file, which is subject 
to standard *nix file ownerships and protections.

>Dammit, processes
>are not files just because they happen to have a /proc entry under
>many systems!

They are files. They have all the semantics of files. Under Linux they 
are in fact directories, but those are still files.

They are not files with blocks allocated on some physical disk 
partition, but that doesn't make them any the less files.

>|> I wasn't talking about FIFOs. Even if I was, they _are_ still subject to 
>|> regular file permissions (on Linux, at least).
>
>They aren't on most Unices - Linux is not UNIX, you know :-)

I'm not aware of any *nix system worthy of the name where they are not. 
The "everything-is-a-file" concept is deeply ingrained into the whole 
*nix philosophy.

>I shall not respond further on this.

One can hope...
-- 
http://mail.python.org/mailman/listinfo/python-list


looks like in PIL, resize() will give high quality thumbnails than thumbnail()

2006-07-01 Thread Summercoolness
In PIL, since thumbnail() first makes a draft copy of the image, and
then resize it, so thumbnail() can run a lot faster than resize()
because draft() seems a lot faster when resizing from very big images
to small images...  (such as the original image is 3000 x 2000, and it
can make a draft really quickly to 375 x 250, and then resize to, say
200 x 133 as a thumbnail)

However, the double resizing probably will make a thumbnail with a
lower quality than if it is directly resizing from the original... as
each resizing involves some approximation.

however, i tried directly using resize() and it is a lot slower.

But looks like if quality is of concern and time is not an issue, then
we can use the resize() to create thumbnails instead.

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


Re: looks like in PIL, resize() will give high quality thumbnails than thumbnail()

2006-07-01 Thread Summercoolness

[EMAIL PROTECTED] wrote:
> In PIL, since thumbnail() first makes a draft copy of the image, and
> then resize it, so thumbnail() can run a lot faster than resize()
> because draft() seems a lot faster when resizing from very big images
> to small images...  (such as the original image is 3000 x 2000, and it
> can make a draft really quickly to 375 x 250, and then resize to, say
> 200 x 133 as a thumbnail)

as a matter of fact, i tried using thumbnail() to resize photos of 3456
x 2304 to 800 x 533 and it is a lot faster than using resize()

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


Re: languages with full unicode support

2006-07-01 Thread Dr.Ruud
Chris Uppal schreef:

> Since the interpretation of characters which are yet to be added to
> Unicode is undefined (will they be digits, "letters", operators,
> symbol, punctuation ?), there doesn't seem to be any sane way
> that a language could allow an unrestricted choice of Unicode in
> identifiers.

The Perl-code below prints:

xdigit
22 /194522 =  0.011%  (lower: 6, upper: 6)
ascii
   128 /194522 =  0.066%  (lower:26, upper:26)
\d
   268 /194522 =  0.138%
digit
   268 /194522 =  0.138%
IsNumber
   612 /194522 =  0.315%
alpha
 91183 /194522 = 46.875%  (lower:  1380, upper:  1160)
alnum
 91451 /194522 = 47.013%  (lower:  1380, upper:  1160)
word
 91801 /194522 = 47.193%  (lower:  1380, upper:  1160)
graph
102330 /194522 = 52.606%  (lower:  1380, upper:  1160)
print
102349 /194522 = 52.616%  (lower:  1380, upper:  1160)
blank
18 /194522 =  0.009%
space
24 /194522 =  0.012%
punct
   374 /194522 =  0.192%
cntrl
  6473 /194522 =  3.328%


Especially look at 'word', the same as \w, which for ASCII is
[0-9A-Za-z_].


==8<===
#!/usr/bin/perl
# Program-Id: unicount.pl
# Subject: show Unicode statistics

  use strict ;
  use warnings ;

  use Data::Alias ;

  binmode STDOUT, ':utf8' ;

  my @table =
  # +--Name--+---qRegexp+-C-+-L-+-U-+
  (
[ 'xdigit'   , qr/[[:xdigit:]]/ , 0 , 0 , 0 ] ,
[ 'ascii', qr/[[:ascii:]]/  , 0 , 0 , 0 ] ,
[ '\\d'  , qr/\d/   , 0 , 0 , 0 ] ,
[ 'digit', qr/[[:digit:]]/  , 0 , 0 , 0 ] ,
[ 'IsNumber' , qr/\p{IsNumber}/ , 0 , 0 , 0 ] ,
[ 'alpha', qr/[[:alpha:]]/  , 0 , 0 , 0 ] ,
[ 'alnum', qr/[[:alnum:]]/  , 0 , 0 , 0 ] ,
[ 'word' , qr/[[:word:]]/   , 0 , 0 , 0 ] ,
[ 'graph', qr/[[:graph:]]/  , 0 , 0 , 0 ] ,
[ 'print', qr/[[:print:]]/  , 0 , 0 , 0 ] ,
[ 'blank', qr/[[:blank:]]/  , 0 , 0 , 0 ] ,
[ 'space', qr/[[:space:]]/  , 0 , 0 , 0 ] ,
[ 'punct', qr/[[:punct:]]/  , 0 , 0 , 0 ] ,
[ 'cntrl', qr/[[:cntrl:]]/  , 0 , 0 , 0 ] ,
  ) ;

  my @codepoints =
  (
 0x ..  0xD7FF,
 0xE000 ..  0xFDCF,
 0xFDF0 ..  0xFFFD,
 0x1 .. 0x1FFFD,
 0x2 .. 0x2FFFD,
#0x3 .. 0x3FFFD, # etc.
  ) ;

  for my $row ( @table )
  {
alias my ($name, $qrx, $count, $lower, $upper) = @$row ;

printf "\n%s\n", $name ;

my $n = 0 ;

for ( @codepoints )
{
  local $_ = chr ;  # int-2-char conversion
  $n++ ;

  if ( /$qrx/ )
  {
$count++ ;
$lower++ if / [[:lower:]] /x ;
$upper++ if / [[:upper:]] /x ;
  }
}

my $show_lower_upper =
  ($lower || $upper)
  ? sprintf( "  (lower:%6d, upper:%6d)"
   , $lower
   , $upper
   )
  : '' ;

printf "%6d /%6d =%7.3f%%%s\n"
   , $count
   , $n
   , 100 * $count / $n
   , $show_lower_upper
  }
__END__

-- 
Affijn, Ruud

"Gewoon is een tijger."


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


Re: I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread Ravi Teja

gavino wrote:
> This seems easy but I have been asking tcl and python IRC chat all day
> and no one gave an answer.
> I have 100 servers which need a new backup server added to a text file,
>  and then the backup agent restarted.
> If I have a list of the servers, all with same root password, and the
> connection is ssh.
> How do I connect to the server, cat the line to the config file, stop
> adn start the agent, and then do same to next server in list and
> iterate through the 100 servers.
> What script would allow this?

Try pxssh from pexpect. Look at the sample in the page.
http://pexpect.sourceforge.net/pxssh.html
It will allow you to automate ssh interactions.

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


Re: Regular Expression - old regex module vs. re module

2006-07-01 Thread Jim Segrave
In article <[EMAIL PROTECTED]>,
Steve <[EMAIL PROTECTED]> wrote:
>Hi All!
>
>Thanks for your suggestions and comments!  I was able to use some of
>your code and suggestions and have come up with this new version of
>Report.py.
>
>Here's the updated code :
>
>exponentPattern = re.compile('\(^\|[^\\#]\)|#+\.#+\*\*\*\*')
>floatPattern = re.compile('\(^\|[^\\#]\)|#+\.#+')
>integerPattern = re.compile("\(^\|[^\\#]\)|\##+")
>leftJustifiedStringPattern = re.compile('\(^\|[^\\<]\)|\<<+')
>rightJustifiedStringPattern = re.compile('\(^\|[^\\>]\)|\>>+')


Some comments and suggestions 

If you want to include backslashes in a string, either
use raw strings, or use double backslashes (raw strings are much
easier to read). Otherwise, you have an accident waiting to happen -
'\(' _does_ make a two character string as you desired, but '\v' makes
a one character string, which is unlikely to be what you wanted.

That's a stylistic point. But more serious is the leading part of all
your regexes - '\(^\|[^\\#]\)|'. I'm not sure what you're trying to
accomplish - presumably to skip over escaped format characters, but
that's not what they do.

\( says to look for an open parenthesis (you've escaped it, so it's
not a grouping character.  ^ says look at the start of the line. This
means the first character can never match an open parens, so this
entire term, up to the alternate expression (after the non-escaped
pipe symbol) never matches anything. If you want to ignore escaped
formating characters before a format, then you should use a negative
lookbehind assertation (see the library reference, 4.2.1, Regular
Expression Syntax:

'(?###
>#  _make_printf   #
>###
>
>def _make_printf(s):
>"""Convert perl style format symbology to printf tokens.
>
>Take a string and substitute computed printf tokens for perl style
>format symbology.
>
>For example:
>
>###.##yields %6.2f
>  yields %8d
>< yields %-5s
>"""
>#print("Original String = %s\n\n") % (s)
>
>
>while 1:  # process all sci notation fields
>if exponentPattern.search(s) < 0: break
>i1 , i2 = exponentPattern.search(s).span()
>width_total = i2 - i1
>field = s[i1:i2-4]
>width_mantissa = len( field[string.find(field,'.')+1:] )
>f = '%'+`width_total`+'.'+`width_mantissa`+'e'
>s = exponentPattern.sub(f, s, 1)

There are better ways to examine a match than with span() - consider
using grouping in your regex to get the mantissa width and the total
width, use a regex with grouping like this:

If:

exponentPattern = re.compile(r'(?s = re.sub('', ' ', s)
>return s

As I noted, should backslashes be converted to spaces? And again, it's
easier to type and read if it uses raw strings:

 s = re.sub(r'\\', ' ', s)


>###
>#  ReportTemplate #
>###
>
>class ReportTemplate:
>"""Provide a print formatting object.
[Snip]
>The total width of the symbol and it's decimal point position is
>used to compute the appropriate printf token; see 'make_printf'
>method. The symbol must have at least two adjacent characters for

A minor nit - make_printf is better described as a function, not a
method (it's not part of the ReportTemplate class or any other cleass)

[SNIP]

>def __init__( self, template = ''):
>self.body = []
>self.vars = []
>
>#read in and parse a format template
>try:
>tpl = open(template, 'r')
>lines = string.split(tpl.read(), '\n')[:-1]

You'd be better off to use something like:

 lines = []
 for l in open(template, 'r').readlines():
lines.append(l.rstrip)
 
The use of rstrip discards any trailing whitespace and deals with
reading Windows generated files on a Unix box, where lines will end in
CRLF and you'd strip only the LF

>except IOError:
>lines = string.split(template, '\n')

I have my doubts about the advisability of assuming that you are
either passed the name of a file containing a template or a
template itself. A misspelled file name won't raise
an error, it will simply be processed as a fixed output. I would have
passed a flag to say if the template argument was file name or a
template and terminated with an error if it was a non-existant file.

[SNIP]

>def _format( self, dataobj ):
>"""Return the values of the given data object substituted into
>the template format stored in this object.
>"""
># value[] is a list of lists of values from the dataobj
># body[] is the list of strings wi

Re: languages with full unicode support

2006-07-01 Thread David Hopwood
Joachim Durchholz wrote:
> Chris Uppal schrieb:
>> Joachim Durchholz wrote:
>>
 This is implementation-defined in C.  A compiler is allowed to accept
 variable names with alphabetic Unicode characters outside of ASCII.
>>>
>>> Hmm... that could would be nonportable, so C support for Unicode is
>>> half-baked at best.
>>
>> Since the interpretation of characters which are yet to be added to
>> Unicode is undefined (will they be digits, "letters", operators, symbol,
>> punctuation ?), there doesn't seem to be any sane way that a
>> language could allow an unrestricted choice of Unicode in identifiers.
> 
> I don't think this is a problem in practice. E.g. if a language uses the
> usual definition for identifiers (first letter, then letters/digits),
> you end up with a language that changes its definition on the whims of
> the Unicode consortium, but that's less of a problem than one might
> think at first.

It is not a problem at all. See the stability policies in
.

> Actually I'm not sure that Unicode is important for long-lived code.
> Code tends to not survive very long unless it's written in English, in
> which case anything outside of strings is in 7-bit ASCII. So the
> majority of code won't ever be affected by Unicode problems - Unicode is
> more a way of lowering entry barriers.

Unicode in identifiers has certainly been less important than some thought
it would be -- and not at all important for open source projects, for example,
which essentially have to use English to get the widest possible participation.

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


lxml and SimpleXMLWriter

2006-07-01 Thread Srijit Kumar Bhadra
I am new to lxml. I am interested to know the equivalent code using
lxml (http://cheeseshop.python.org/pypi/lxml/1.1alpha). The code is
taken from http://effbot.org/zone/xml-writer.htm

from elementtree.SimpleXMLWriter import XMLWriter
import sys

w = XMLWriter(sys.stdout)

html = w.start("html")

w.start("head")
w.element("title", "my document")
w.element("meta", name="generator", value="my application 1.0")
w.end()

w.start("body")
w.element("h1", "this is a heading")
w.element("p", "this is a paragraph")

w.start("p")
w.data("this is ")
w.element("b", "bold")
w.data(" and ")
w.element("i", "italic")
w.data(".")
w.end("p")

w.close(html)

Best Regards,
Srijit

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


Re: lxml and SimpleXMLWriter

2006-07-01 Thread Fredrik Lundh
Srijit Kumar Bhadra wrote:

> I am new to lxml. I am interested to know the equivalent code using
> lxml (http://cheeseshop.python.org/pypi/lxml/1.1alpha). The code is
> taken from http://effbot.org/zone/xml-writer.htm

the lxml library implements the ElementTree module API (with 
extensions), not the other parts of the ET library.

any reason you cannot just use the ET version ?



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


RE: beautifulsoup .vs tidy

2006-07-01 Thread bruce
hi paddy...

that's exactly what i'm trying to accomplish... i've used tidy, but it seems
to still generate warnings...

 initFile -> tidy ->cleanFile -> perl app (using xpath/livxml)

the xpath/linxml functions in the perl app complain regarding the file. my
thought is that tidy isn't cleaning enough, or that the perl xpath/libxml
functions are too strict!

which is why i decided to see if anyone on the python side has
experienced/solved this problem..

-bruce


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Paddy
Sent: Saturday, July 01, 2006 1:09 AM
To: python-list@python.org
Subject: Re: beautifulsoup .vs tidy



bruce wrote:
> hi...
>
> never used perl, but i have an issue trying to resolve some html that
> appears to be "dirty/malformed" regarding the overall structure. in
> researching validators, i came across the beautifulsoup app and wanted to
> know if anybody could give me pros/cons of the app as it relates to any of
> the other validation apps...
>
I'm not too sure of what you are after. You mention tidy in the subject
which made me think that maybe you were trying to generate well-formed
HTML from malformed webppages that nonetheless browsers can interpret.
If that is the case then try HTML tidy:
  http://www.w3.org/People/Raggett/tidy/

- Pad.

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

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


Re: Replace Whole Object Through Object Method

2006-07-01 Thread John Roth

[EMAIL PROTECTED] wrote:
> How can an object replace itself using its own method? See the
> following code

[code deleted]

At the risk of creating totally incomprehensible and
unmaintainable code, you need two things:

First, you can change the class of any new style
object by assigning to the __class__ attribute.

Second, you can create a new style class
on the fly with the three operand type(a, b, c) method.
See the builtin methods in the doc.

It's quite straightforward if you know what you're
doing. What's hard is to create a conceptual model
that won't be an instant winner in an obfuscated code
contest.

John Roth

>

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


Re: beautifulsoup .vs tidy

2006-07-01 Thread Fredrik Lundh
bruce wrote:

> that's exactly what i'm trying to accomplish... i've used tidy, but it seems
> to still generate warnings...
> 
>  initFile -> tidy ->cleanFile -> perl app (using xpath/livxml)
> 
> the xpath/linxml functions in the perl app complain regarding the file.

what exactly do they complain about ?



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


gmail/poplib: quickly detecting new mail

2006-07-01 Thread LJ
Hello,

I'm trying to monitor my gmail account to know when I have obtained a
new email.  It seems that once I have logged in, I should be able to
call the stat() function repeatedly to see how many messages are in my
inbox.  The problem is that this number does not seem to update until I
have logged out, and logged back in.  In other words, I run the code
below, send myself an email, and observe that the count does not
change.  If I kill the program and restart (hence logging back in),
then the total count is now updated.  The other function calls seem to
work the same way (eg "list" just shows the same list, even when I know
new mail has arrived).

Questions:
1. is this a standard behavior of pop protocol? (to give me the same
results for any API call on a single login?)
2. OR is this a peculiarity of gmail
3. is there a more efficient and correct way to see know when I have
received a new mail?  Currently my "working" method is to log out and
log back in.  With this method, I can get about 17 refreshes per minute
but anything faster and Gmail blocks me for a few minutes. (yes it is
important to my application that I have very frequent refreshes).

(see code sample below)

Thanks,
LJ

---

import poplib
import time
from email.Parser import Parser

parser = Parser()
server = poplib.POP3_SSL("pop.gmail.com", 995)
print server.user("XXX-MY_EMAIL")
print server.pass_("XXX-MY_PW")
server.set_debuglevel(0)

def getMsgCount():
  # check message count by stat() and list() functions
  numMsgs = server.stat()[0]
  print "Num msg by stat():", numMsgs
  print "Num msg by list():", len(server.list()[1])
  print "Most recent:", numMsgs, getSubj(numMsgs)
  return

def getSubj(which):
  # return subject of message with id 'which'
  msg = "\n".join(server.top(which, 1)[1])
  email = parser.parsestr(msg)
  return email.get("Subject")

while True:
  print "--"
  getMsgCount()
  time.sleep(2)

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


Re: gmail/poplib: quickly detecting new mail

2006-07-01 Thread Jean-Paul Calderone
On 1 Jul 2006 08:29:51 -0700, LJ <[EMAIL PROTECTED]> wrote:
>Hello,
>
>I'm trying to monitor my gmail account to know when I have obtained a
>new email.  It seems that once I have logged in, I should be able to
>call the stat() function repeatedly to see how many messages are in my
>inbox.  The problem is that this number does not seem to update until I
>have logged out, and logged back in.  In other words, I run the code
>below, send myself an email, and observe that the count does not
>change.  If I kill the program and restart (hence logging back in),
>then the total count is now updated.  The other function calls seem to
>work the same way (eg "list" just shows the same list, even when I know
>new mail has arrived).
>
>Questions:
>1. is this a standard behavior of pop protocol? (to give me the same
>results for any API call on a single login?)

Yes.

>2. OR is this a peculiarity of gmail

Nope.

>3. is there a more efficient and correct way to see know when I have
>received a new mail?  Currently my "working" method is to log out and
>log back in.  With this method, I can get about 17 refreshes per minute
>but anything faster and Gmail blocks me for a few minutes. (yes it is
>important to my application that I have very frequent refreshes).

This is not the purpose for which POP3 was intended.  POP3 is expected
to be used when a latency of several minutes doesn't make much difference.
If you look at the capabilities gmail's POP3 server publishes, you even
see they are declaring a five minute login delay.  This is intended as
a hint to clients that logins more frequent than one per five minutes are
not allowed.

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


Re: gmail/poplib: quickly detecting new mail

2006-07-01 Thread Alex Martelli
LJ <[EMAIL PROTECTED]> wrote:
   ...
> 1. is this a standard behavior of pop protocol? (to give me the same
> results for any API call on a single login?)
> 2. OR is this a peculiarity of gmail

Definitely POP3 standard behavior, as a simple reading of the relevant
RFC will show (e.g., http://www.ietf.org/rfc/rfc1939.txt):
summarizing... on entering Transaction state, a POP3 server acquires an
exclusive lock on the mailbox, to ensure that no modifications occur to
it throughout the session.

I'm not sure about the refresh frequency, but you may want to try the
Atom feed, https://mail.google.com/gmail/feed/atom .


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


How to create a limited set of instanceses of a class

2006-07-01 Thread madpython
For the pure theory sake and mind expansion i got a question.
Experimenting with __new__ i found out how to create a singleton.
class SingleStr(object):
def __new__(cls,*args,**kwargs):
instance=cls.__dict__.get('instance')
if instance:
return instance
cls.instance=object.__new__(cls,*args,**kwargs)
return cls.instance

What if i need to create no more than 5 (for example) instances of a
class. I guess that would be not much of a problema but there is a
complication. If one of the instances is garbagecollected I want to be
able to spawn another instance. Maybe it's difficult to perceive what i
said so think of a limited number of sockets. Wherenever one is freed
it can be captured again.
I believe that this type of the design pattern was described in
"Thinking in Java" but there was a special method finalize()
utilized, that is called every time when gc() is about to clean up an
unreferenced object. By using this method a counter of active instances
could be easily implemented. What is the pythonic approach to this
problema?

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


Threading HowTo's in Windows platforms

2006-07-01 Thread LittlePython
I am looking for some good beginner how-to links and maybe some simple
example scripts that perform threading on windows platforms. Hopefully
authors who don't mind doing "a little spoon feeding" would be great as I am
a "baby python" who is very green with threading..

Thx


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


cheetah.

2006-07-01 Thread chun ping wang
I am having trouble using cheetah and getting it to work the way i want 
(mvc)

I have the following file.

index.py : # imports BibleController and setting.


BibleController.py that includes the Bible.py model to database (those 
works). At the end of it i have.
print Template ( file = "BibleView.Tmpl", searchList = templateValue )

BibleView.tmpl.

I generated something call BibleView.py using cheetah template. But when i 
run BibleView.py i get this error.

File "BibleView.py", line 97, in respond
   __v = VFFSL(SL,"ver",True)
ameMapper.NotFound: cannot find 'ver'

Whats wrong?

_
On the road to retirement? Check out MSN Life Events for advice on how to 
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement

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


Re: beautifulsoup .vs tidy

2006-07-01 Thread Paul Boddie
Ravi Teja wrote:
>
> 1.) XPath is not a good idea at all with "malformed" HTML or perhaps
> web pages in general.

import libxml2dom
import urllib
f = urllib.urlopen("http://wiki.python.org/moin/";)
s = f.read()
f.close()
# s contains HTML not XML text
d = libxml2dom.parseString(s, html=1)
# get the community-related links
for label in d.xpath("//li[.//a/text() = 'Community']//li//a/text()"):
print label.nodeValue

Of course, lxml should be able to do this kind of thing as well. I'd be
interested to know why this "is not a good idea", though.

Paul

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


Re: What is Expressiveness in a Computer Language

2006-07-01 Thread Stephen J. Bevan
Darren New <[EMAIL PROTECTED]> writes:
> Andreas Rossberg wrote:
>> AFAICT, ADT describes a type whose values can only be accessed by a
>> certain fixed set of operations.
>
> No. AFAIU, an ADT defines the type based on the operations. The stack
> holding the integers 1 and 2 is the value (push(2, push(1,
> empty(. There's no "internal" representation. The values and
> operations are defined by preconditions and postconditions.

As a user of the ADT you get a specification consisting of a signature
(names the operations and defines their arity and type of each
argument) and axioms which define the behaviour of the operations.

The implementer has the task for producing an implementation (or
"model" to use alebraic specifiction terminology) that satisfies the
specification.  One model that comes for free is the term model where
the operations are treated as terms and the representation of a stack
containing 2 and 1 would just be "(push(2, push(1, empty(".
However, while that model comes for free it isn't necessarily the most
efficient model.  Thus the non-free aspect of chosing a different
implementation is that technically it requires an accompanying proof
that the implementation satisfies the specification.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threading HowTo's in Windows platforms

2006-07-01 Thread Jean-Paul Calderone
On Sat, 01 Jul 2006 16:36:02 GMT, LittlePython <[EMAIL PROTECTED]> wrote:
>I am looking for some good beginner how-to links and maybe some simple
>example scripts that perform threading on windows platforms. Hopefully
>authors who don't mind doing "a little spoon feeding" would be great as I am
>a "baby python" who is very green with threading..

Threaded programming is extremely difficult.  Most good newbie introductions
to it consist of warnings not to use it.

Do you have a particular application in mind?  Perhaps someone can suggest
a more specific, simpler solution.

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


Re: I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread LittlePython
Does this require a ssh client or server?

I use authpf to open up my  PF firewall for internet use. Generally I just
open up putty and make a connection to the FW ( which open the ports) and
minize it till I am done. When I close putty authpf losses the ssh session
heartbeat and will then instruct the FW to close the ports. I would love to
write a simple client to do this form me instead of using putty. Do you
think these mods would work for me on a windows platform?

Thx

"Ravi Teja" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> gavino wrote:
> > This seems easy but I have been asking tcl and python IRC chat all day
> > and no one gave an answer.
> > I have 100 servers which need a new backup server added to a text file,
> >  and then the backup agent restarted.
> > If I have a list of the servers, all with same root password, and the
> > connection is ssh.
> > How do I connect to the server, cat the line to the config file, stop
> > adn start the agent, and then do same to next server in list and
> > iterate through the 100 servers.
> > What script would allow this?
>
> Try pxssh from pexpect. Look at the sample in the page.
> http://pexpect.sourceforge.net/pxssh.html
> It will allow you to automate ssh interactions.
>


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


Re: Threading HowTo's in Windows platforms

2006-07-01 Thread Paul Rubin
"LittlePython" <[EMAIL PROTECTED]> writes:
> I am looking for some good beginner how-to links and maybe some simple
> example scripts that perform threading on windows platforms. Hopefully
> authors who don't mind doing "a little spoon feeding" would be great as I am
> a "baby python" who is very green with threading..

Why don't you look in the Python Cookbook, either the paper edition
(O'Reilly) or the online one (aspn.activestate.com).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threading HowTo's in Windows platforms

2006-07-01 Thread LittlePython
I want to access the mailbox move methods and thread unto 4 moves at once.
Currently I am access one move at a time via com but I would like to go a
little deeper and start researching threading and the code that is behind
the com. My use involves hundreds if not thousands of mailboxes over a short
period of time(weeks or maybe a month or so).  I could replicate threading I
guess by launching  multiply scripts on different modes but the logistics to
this approach is error pronded for a user prospective.
"Jean-Paul Calderone" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Sat, 01 Jul 2006 16:36:02 GMT, LittlePython <[EMAIL PROTECTED]>
wrote:
> >I am looking for some good beginner how-to links and maybe some simple
> >example scripts that perform threading on windows platforms. Hopefully
> >authors who don't mind doing "a little spoon feeding" would be great as I
am
> >a "baby python" who is very green with threading..
>
> Threaded programming is extremely difficult.  Most good newbie
introductions
> to it consist of warnings not to use it.
>
> Do you have a particular application in mind?  Perhaps someone can suggest
> a more specific, simpler solution.
>
> Jean-Paul


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


Re: missing feature classes and missing fields

2006-07-01 Thread Gary Herron
subramanian2003 wrote:
> Hello All,
>
> How can I check missing feature classes in a folder/personal geodatabase 
> using python script. And how can I check  missing fields in shape files. And 
> also I want to check the attribute values using python.
>
> Thnx,
> Subramanian.
>
>
>
>   
This list is usually very helpful, however, I think you are going to
need to be more specific to get an answer here.

For instance,

What's are "missing feature classes"?
What's a "folder/personal geodatabase"?
What's are "missing fields"?
What's a "shape file"?
On what object to you wish to check "attribute values"?

I'm not sure I can help even if I have those answers, but I'm sure I
can't help if I don't.

Gary Herron

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


Re: How to create a limited set of instanceses of a class

2006-07-01 Thread Alex Martelli
madpython <[EMAIL PROTECTED]> wrote:

> For the pure theory sake and mind expansion i got a question.
> Experimenting with __new__ i found out how to create a singleton.
> class SingleStr(object):
> def __new__(cls,*args,**kwargs):
> instance=cls.__dict__.get('instance')
> if instance:
> return instance
> cls.instance=object.__new__(cls,*args,**kwargs)
> return cls.instance
> 
> What if i need to create no more than 5 (for example) instances of a

And what if somebody asks for a 6th one -- raise an exception?  or
return a random one of the 5?  Ah well, anyway...:

> class. I guess that would be not much of a problema but there is a
> complication. If one of the instances is garbagecollected I want to be
> able to spawn another instance. Maybe it's difficult to perceive what i
> said so think of a limited number of sockets. Wherenever one is freed
> it can be captured again.

Have the class hold weak references to the instances.  E.g.:

import weakref
import random

class JustFive(object):
_counter = 0
_insts = weakref.WeakKeyDictionary()

def __new__(cls):
if len(cls._insts) < 5:
inst = object.__new__(cls)
inst.id = cls._counter
cls._insts[inst] = None
cls._counter += 1
else:
inst = random.choice(cls._insts.keys())
return inst

Testing this for the specified behavior should be done more
systematically, of course, but here's a snippet based only on showing
exactly what's going on...:


if __name__ == '__main__':
samp = [JustFive() for i in range(7)]
def showsamp():
for s in samp: print s.id,
ss = set(s.id for s in samp)
print '{',
for s in sorted(ss): print '%d,'%s,
print '} #%d'%len(ss)
print 'Start with:',
showsamp()
for x in range(10):
i = random.randrange(len(samp))
print ('@%d,'%i), samp[i].id, '->',
samp[i] = None
newone = JustFive()
samp[i] = newone
print '%d,' % samp[i].id,
showsamp()


A sample run might go, for example...:

Start with: 0 1 2 3 4 4 1 { 0, 1, 2, 3, 4, } #5
@0, 0 -> 5, 5 1 2 3 4 4 1 { 1, 2, 3, 4, 5, } #5
@1, 1 -> 3, 5 3 2 3 4 4 1 { 1, 2, 3, 4, 5, } #5
@6, 1 -> 6, 5 3 2 3 4 4 6 { 2, 3, 4, 5, 6, } #5
@2, 2 -> 7, 5 3 7 3 4 4 6 { 3, 4, 5, 6, 7, } #5
@4, 4 -> 7, 5 3 7 3 7 4 6 { 3, 4, 5, 6, 7, } #5
@4, 7 -> 6, 5 3 7 3 6 4 6 { 3, 4, 5, 6, 7, } #5
@1, 3 -> 7, 5 7 7 3 6 4 6 { 3, 4, 5, 6, 7, } #5
@3, 3 -> 8, 5 7 7 8 6 4 6 { 4, 5, 6, 7, 8, } #5
@6, 6 -> 5, 5 7 7 8 6 4 5 { 4, 5, 6, 7, 8, } #5
@2, 7 -> 6, 5 7 6 8 6 4 5 { 4, 5, 6, 7, 8, } #5

and the point is that the sample always has a set of objects with
exactly 5 separate id values, but the set "migrates" upwards as some
objects happen to be dropped.  Well, not always "upwards" as smoothly as
luck would have it in this case, e.g., another run goes:

Start with: 0 1 2 3 4 1 2 { 0, 1, 2, 3, 4, } #5
@1, 1 -> 3, 0 3 2 3 4 1 2 { 0, 1, 2, 3, 4, } #5
@2, 2 -> 4, 0 3 4 3 4 1 2 { 0, 1, 2, 3, 4, } #5
@3, 3 -> 1, 0 3 4 1 4 1 2 { 0, 1, 2, 3, 4, } #5
@1, 3 -> 5, 0 5 4 1 4 1 2 { 0, 1, 2, 4, 5, } #5
@5, 1 -> 5, 0 5 4 1 4 5 2 { 0, 1, 2, 4, 5, } #5
@6, 2 -> 6, 0 5 4 1 4 5 6 { 0, 1, 4, 5, 6, } #5
@2, 4 -> 1, 0 5 1 1 4 5 6 { 0, 1, 4, 5, 6, } #5
@4, 4 -> 7, 0 5 1 1 7 5 6 { 0, 1, 5, 6, 7, } #5
@6, 6 -> 8, 0 5 1 1 7 5 8 { 0, 1, 5, 7, 8, } #5
@3, 1 -> 8, 0 5 1 8 7 5 8 { 0, 1, 5, 7, 8, } #5

here, the objects with ids 0 and 1 just never happen to get dropped.


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


Re: print shell output in a file

2006-07-01 Thread Scott David Daniels
Juergen Huber wrote:
...
> here is the print command, which delivers me the following output (see
> below) on the shell:
>  print '%-30s | %-12d | %-12d |%-12d ' % (typename,
>   size / count,
>   count,
>   size)
...
> Is there a way to put this output in an file?!?!

Another way nobody has yet mentioned:

 import sys
 old_output, sys.stdout = sys.stdout, open('somefile.txt', 'w')

 try:
 <<>>
 finally:
 old_output, sys.stdout = sys.stdout, old_output
 old_output.close()
 print 'Output safely written to:', old_output.name

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


Re: How to create a limited set of instanceses of a class

2006-07-01 Thread Scott David Daniels
madpython wrote:
> For the pure theory sake and mind expansion i got a question.
> Experimenting with __new__ i found out how to create a singleton.
> class SingleStr(object):
> def __new__(cls,*args,**kwargs):
> instance=cls.__dict__.get('instance')
> if instance:
> return instance
> cls.instance=object.__new__(cls,*args,**kwargs)
> return cls.instance
> 
> What if i need to create no more than 5 (for example) instances of a
> class. I guess that would be not much of a problema but there is a
> complication. If one of the instances is garbagecollected I want to be
> able to spawn another instance

This should help.  You didn't really say how to pick the result
if there are duplicates, so I just decided for myself.  Read up
on the weakref module, it is your friend in this kind of problem.

 import weakref, random

 class Limited(any_new_style_class):
 _held_instances = weakref.WeakValueDictionary()
 _held_limit = 5
 def __new__(class_, *args, **kwargs):
 if len(class_._held_instances) < class_._held_limit:
 # You could go over here if threading is an issue
 instance = super(class_, Limited).__new__(
   class_, *args, **kwargs)
 class_._held_instances[id(instance)] = instance
 return instance
 return random.choice(class_._held_instances.values())


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


Re: Threading HowTo's in Windows platforms

2006-07-01 Thread LittlePython
Thx


"Paul Rubin"  wrote in message
news:[EMAIL PROTECTED]
> "LittlePython" <[EMAIL PROTECTED]> writes:
> > I am looking for some good beginner how-to links and maybe some simple
> > example scripts that perform threading on windows platforms. Hopefully
> > authors who don't mind doing "a little spoon feeding" would be great as
I am
> > a "baby python" who is very green with threading..
>
> Why don't you look in the Python Cookbook, either the paper edition
> (O'Reilly) or the online one (aspn.activestate.com).


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


Re: Threading HowTo's in Windows platforms

2006-07-01 Thread Scott David Daniels
Jean-Paul Calderone wrote:
> On Sat, 01 Jul 2006 16:36:02 GMT, LittlePython <[EMAIL PROTECTED]> 
> wrote:
>> I am looking for some good beginner how-to links and maybe some simple
>> example scripts that perform threading on windows platforms. Hopefully
>> authors who don't mind doing "a little spoon feeding" would be great 
>> as I am a "baby python" who is very green with threading
> 
> Threaded programming is extremely difficult.  Most good newbie 
> introductions to it consist of warnings not to use it.

Just to expand on this reply -- even experts avoid threading unless
necessary.  The real reason that everyone hates threading is that
wrong programs can run correctly, and errors cannot be reproduced.
Apparently, threaded programs have a "demo detector" that makes them
go wrong in the presence of anything more than a single vice president
(or major customer).

So, the standard Python advice is to have each thread completely
independent (sharing no data), and communicating only with instances
of queue.Queue.  That keeps the "demo detector" in check, because
you then have individually predictable (and hopefully testable)
parts with a logable communication pattern.  You still may have
trouble (to which the best reply is, "See, we told you so.").

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


Re: Non-ASCII languages

2006-07-01 Thread Scott David Daniels
Jorgen Grahn wrote:
> On Thu, 29 Jun 2006 23:19:34 +0200, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>> Jorgen Grahn wrote:
> ...
>>> (I like well-typeset code in print though
> Possibly true, and definitely for Knuth.  But WYSIWYG was unknown at the
> time; these people all programmed using fixed-width fonts, on teletypes or
> character-mapped terminals. Hell, even full-screen editors were new and
> controversial until the late 1970s!
Sorry, I'm old enough to have a few problems with this.  WYSIWIG was
indeed well known at the time, and disparaged as WYSIAYG around where I
worked (What You See Is All You Get).  We had full screen editors, with
proportional fonts; SAIL (Stanford AI Lab) had the first laser printer
to play with (people wrote incredibly ugly documents with tons of fonts
in them because it was the first they could spec it).  All of this was
in the mid seventies or earlier.

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


Re: I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread gavino
list of servers L.txt
#cat L.txt
config file is /var/bkupexec/agent.cfg need to add "tell epobackup" to
bottom of file
# cat "tell epobackup" >> /var/bkupexec/agent.cfg
agent is /etc/init.d/agent.ini stop (and then start)
# /etc/init.d/agent.init stop
# /etc/init.d/agent.init start
os=redhat ent 4ES
I intend to use root password which is same for all 100 servers.
#now I'm stuck

Ravi Teja wrote:
> gavino wrote:
> > This seems easy but I have been asking tcl and python IRC chat all day
> > and no one gave an answer.
> > I have 100 servers which need a new backup server added to a text file,
> >  and then the backup agent restarted.
> > If I have a list of the servers, all with same root password, and the
> > connection is ssh.
> > How do I connect to the server, cat the line to the config file, stop
> > adn start the agent, and then do same to next server in list and
> > iterate through the 100 servers.
> > What script would allow this?
>
> Try pxssh from pexpect. Look at the sample in the page.
> http://pexpect.sourceforge.net/pxssh.html
> It will allow you to automate ssh interactions.

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


sys.stdin and two CTRL-Ds

2006-07-01 Thread Christoph Haas
Hi...

I encountered a problem that - according to my google search - other
people have found, too. Example code:

import sys
for line in sys.stdin:
   print line

Running this code in Python 2.3 or 2.4 has the problem that I need to
send two EOFs (Ctrl-D) to break out of that loop.

Use case is a piped Python script that I run as a "CustomLog" pipe for
an Apache web server. I want to run all the log output through that pipe
but haven't had much luck. First it takes ages until the script
processes the input (even though I ran Python with "-u" to make it
unbuffered) and then the script needs one EOF to do something with the
input and a second EOF to break out of the loop.

Is this a bug? I'm close to write a Perl script for this case. :(

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


Re: Threading HowTo's in Windows platforms

2006-07-01 Thread LittlePython
Well, I guess you have sold me on this. I will wait till I have grown up to
be a big and wise python (who is still employed) and all my growing
(scripting) scares have healed properly or maybe even forgotten by my
employers.

Thx

"Jezzz ... What could possible go wrong!"
Signed,
Mr. DoRight


"Scott David Daniels" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jean-Paul Calderone wrote:
> > On Sat, 01 Jul 2006 16:36:02 GMT, LittlePython <[EMAIL PROTECTED]>
> > wrote:
> >> I am looking for some good beginner how-to links and maybe some simple
> >> example scripts that perform threading on windows platforms. Hopefully
> >> authors who don't mind doing "a little spoon feeding" would be great
> >> as I am a "baby python" who is very green with threading
> >
> > Threaded programming is extremely difficult.  Most good newbie
> > introductions to it consist of warnings not to use it.
>
> Just to expand on this reply -- even experts avoid threading unless
> necessary.  The real reason that everyone hates threading is that
> wrong programs can run correctly, and errors cannot be reproduced.
> Apparently, threaded programs have a "demo detector" that makes them
> go wrong in the presence of anything more than a single vice president
> (or major customer).
>
> So, the standard Python advice is to have each thread completely
> independent (sharing no data), and communicating only with instances
> of queue.Queue.  That keeps the "demo detector" in check, because
> you then have individually predictable (and hopefully testable)
> parts with a logable communication pattern.  You still may have
> trouble (to which the best reply is, "See, we told you so.").
>
> --Scott David Daniels
> [EMAIL PROTECTED]


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


building/installing python libs/modules...

2006-07-01 Thread bruce
paul,

thanks for the replies to my issues!!! much appreciation.

i've got the python app:
http://www.boddie.org.uk/python/downloads/libxml2dom-0.3.3.tar.gz

and i've downloaded it, an untarred it...
i have the dir structure, but i don't know what needs to be done now!!! i
have a setup.py. does it get run?

the Readme file didn't tell me how to build the app

i now, but everyone starts at something, sometime!!

thanks

-bruce


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


Re: I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread Ravi Teja
LittlePython wrote:
> Does this require a ssh client or server?
>
> I use authpf to open up my  PF firewall for internet use. Generally I just
> open up putty and make a connection to the FW ( which open the ports) and
> minize it till I am done. When I close putty authpf losses the ssh session
> heartbeat and will then instruct the FW to close the ports. I would love to
> write a simple client to do this form me instead of using putty. Do you
> think these mods would work for me on a windows platform?
>
> Thx

Pexpect needs a POSIX system. However, you can use Cygwin.

>From the website, "Pexpect does not currently work on the standard
Windows Python (see the pty requirement); however, it seems to work
fine using Cygwin."

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


Re: I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread LittlePython
thx,


"Ravi Teja" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> LittlePython wrote:
> > Does this require a ssh client or server?
> >
> > I use authpf to open up my  PF firewall for internet use. Generally I
just
> > open up putty and make a connection to the FW ( which open the ports)
and
> > minize it till I am done. When I close putty authpf losses the ssh
session
> > heartbeat and will then instruct the FW to close the ports. I would love
to
> > write a simple client to do this form me instead of using putty. Do you
> > think these mods would work for me on a windows platform?
> >
> > Thx
>
> Pexpect needs a POSIX system. However, you can use Cygwin.
>
> >From the website, "Pexpect does not currently work on the standard
> Windows Python (see the pty requirement); however, it seems to work
> fine using Cygwin."
>


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


Re: building/installing python libs/modules...

2006-07-01 Thread John Machin
On 2/07/2006 5:37 AM, bruce wrote:
> paul,
> 
> thanks for the replies to my issues!!! much appreciation.
> 
> i've got the python app:
> http://www.boddie.org.uk/python/downloads/libxml2dom-0.3.3.tar.gz
> 
> and i've downloaded it, an untarred it...
> i have the dir structure, but i don't know what needs to be done now!!! i
> have a setup.py. does it get run?
> 
> the Readme file didn't tell me how to build the app
> 

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

(see section headed "Installation" at the bottom of the page)

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


Re: building/installing python libs/modules...

2006-07-01 Thread Ravi Teja
> i've got the python app:
> http://www.boddie.org.uk/python/downloads/libxml2dom-0.3.3.tar.gz
>
> and i've downloaded it, an untarred it...
> i have the dir structure, but i don't know what needs to be done now!!! i
> have a setup.py. does it get run?
>
> the Readme file didn't tell me how to build the app

The setup.py is a distutils installer. The usual drill in that case is
to simply type "python setup.py install". If the module is registered
in PyPi (which this one is), you can just type "easy_install
libxml2dom" (after easy_install is setup) and you will not even need to
download and extract.

In this case, your module is a native wrapper. So you will need the
libraries that it provides a wrapper for, installed. In this case
(libxml2, libxml2dom). You will also need a C compiler.

All this can be trivial on a unix based platform. However, if you are
new and on Windows, this can be a hassle since you will have to
manually setup your C compiler and the dependencies. Try to find a
binary installer for native Python modules in MS Windows whenever you
can.

Here is a click and go installer built for Windows that I found from
Google.
http://users.skynet.be/sbi/libxml-python/binaries/libxml2-python-2.6.22.win32-py2.4.exe

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


Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

2006-07-01 Thread [EMAIL PROTECTED]
This has been bothering me for a while. Just want to find out if it
just me or perhaps others have thought of this too: Why shouldn't the
keyset of a dictionary be represented as a set instead of a list? I
know that sets were introduced a lot later and lists/dictionaries were
used instead but I think "the only correct way" now is for the
dictionary keys and values to be sets. Presently {1:0,2:0,3:0}.keys()
will produce [1,2,3] but it could also produce [3,1,2] or [3,2,1] on a
different machine architecture. The Python documentation states that:
"""
Keys and values are listed in an _arbitrary_(my emphasis) order which
is non-random, varies across Python implementations, and depends on the
dictionary's history of insertions and deletions.
"""

So on the same machine it will be the case that:  {1:0, 2:0,
3:0}.keys() == {3:0, 2:0, 1:0}.keys() is True. But if there are 2 lists
of keys of the same dictionary, one is pickled on another machine, with
a different "arbitrary non-random" ordering, then the keys will not be
equal to each other. It seems like the problem could be solved by
returning a set instead.

The same thing goes for the values(). Here most people will argue that
values are not necessarily unique, so a list is more appropriate, but
in fact the values are unique it is just that more than one key could
map to the same value.  What is 'seen' in dictionary is the mapping
rule.  Also the values are not ordered and should not be indexable --
they should be a set. Just as  the keys(), one ordered list of values
from a dictionary on one machine will not necessarily be equal to
another list of values an on another machine, while in fact, they
should be.

On a more fundamental and general level, a dictionary is actually an
explicit function, also called a 'map'. A set of keys, traditionally
called a 'domain' are mapped to a set of values, traditionally called a
'range'. This mapping produces at most a surjective function (i.e. two
or more keys can map to same value and all the values are mapped to by
some keys).  Notice that the traditional counterparts to keys and
values are sets and not just lists. This seems like theory babble, but
in the case of Python staying 'true' to the theory is usually a
GoodThing(tm).

I love Python primarily because it does something in only one, correct,
and reasonable way. The same principle should probably apply to Python
itself including to its built-in data structures.

Of course the compatibilty will be broken. Any code relying on a
certain ordering of keys() or values() returned would need to be
updated. One could argue though that such code was not entirely correct
in the first place to asssume that, and should be fixed anyway.

Obviously this fix should not be in Python 2.X but perhaps would be
worth considering for Python 3000. What does everyone think?

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


Odd behavior with staticmethods

2006-07-01 Thread [EMAIL PROTECTED]
I'm getting rather inconsistent behavior with staticmethod.
@staticmethod has the same problems, but I'm demonstrating it with
staticmethod() because it shows things more clearly
---
>>> class A:
def orig():
print "hi"
st = staticmethod(orig)
st2 = st
wrapped = [ orig ]
wrapped2 = [ st ]


>>> A.orig()   # NORMAL - unbound method, should fail

Traceback (most recent call last):
  File "", line 1, in -toplevel-
A.orig()
TypeError: unbound method orig() must be called with A instance as
first argument (got nothing instead)
>>> A.st() # NORMAL - staticmethod, all good
hi
>>> A.st2() # NORMAL - copy of a static method, all good
hi
>>> A.wrapped[0]() # ODD - wrapping orig() in a list makes orig() work?
hi
>>> A.wrapped2[0]() # ODD - copying st works -- A.st2() -- but copying it to a 
>>> list fails?

Traceback (most recent call last):
  File "", line 1, in -toplevel-
A.wrapped2[0]()
TypeError: 'staticmethod' object is not callable
>>> a = [ A.orig] # NORMAL - fails as expected
>>> a[0]()

Traceback (most recent call last):
  File "", line 1, in -toplevel-
a[0]()
TypeError: unbound method orig() must be called with A instance as
first argument (got nothing instead)
>>> b = [ A.st ] # NORMAL - suceeds as expected
>>> b[0]()
hi
>>>
>>> type(A.orig)

>>> type(A.st)

>>> type(A.st2)

>>> type(A.wrapped[0])

>>> type(A.wrapped2[0])

>>> type(a[0])

>>> type(b[0])




So if the class definition is not finished, one can copy static methods
just fine.  But if it finds its way into a container (in this case, a
list, but making it a member variable of a child object also breaks),
it gets an extra staticmethod wrapper, or something similar?  Once the
class is done, this behavoir no longer occurs.

Can anyone please explain to me why this happens?

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


Re: I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread Ravi Teja

gavino wrote:
> list of servers L.txt
> #cat L.txt
> config file is /var/bkupexec/agent.cfg need to add "tell epobackup" to
> bottom of file
> # cat "tell epobackup" >> /var/bkupexec/agent.cfg
> agent is /etc/init.d/agent.ini stop (and then start)
> # /etc/init.d/agent.init stop
> # /etc/init.d/agent.init start
> os=redhat ent 4ES
> I intend to use root password which is same for all 100 servers.
> #now I'm stuck

Read L.txt from (not your shell as you seem to be doing) Python and
connect to each one from pxssh, and send the commands you listed. I am
afraid, you will have to readup and experiment on a smaller scale. The
sample I pointed you to is a rather simple one and you don't seem to
have even tried it.

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


Re: building/installing python libs/modules...

2006-07-01 Thread Ravi Teja
> Here is a click and go installer built for Windows that I found from
> Google.
> http://users.skynet.be/sbi/libxml-python/binaries/libxml2-python-2.6.22.win32-py2.4.exe

Oops! That is for libxml2, not libxml2dom.

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


Re: Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

2006-07-01 Thread [EMAIL PROTECTED]
There's a few good reasons.
1 - golden handcuffs.  Breaking old code is bad 90% of the time
2 - creating a set MAY be slower.

Python's sets seem to imply to that they will always be a hash map.  in
this case, some creative hash map "mapping" could allow one to create a
set without calculating hash codes (make the set hashmap have the same
dimentions and rules as the dictionary one).
If there was intent to allow Python implementations to use trees for
the set, then a list is far faster to create (O(n) time instead of
O(nlogn)).

3 - using a set is sometimes slower (just as using a list is sometimes
slower)
I can't speak for your code, but this is the most common use of keys in
my coding:
# d is some dictionary
keys = d.keys()
keys.sort()
for k in keys:
  #blah

sets cannot be sorted, while lists can.  If keys() returned a set, then
I'd have to turn it into a list every time.

There's potential to add "views" to python (a key view of a dictionary
being a frozenset containing the dictionary's keys, which is updated
whenever the dictionary updates), but I think thats annother topic
which is out of the scope of your origional idea.

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


RE: building/installing python libs/modules...

2006-07-01 Thread bruce
my bad..

saw that.. completely missed it...

i had guessed.. and am up/runing/testing..

-bruce


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of John Machin
Sent: Saturday, July 01, 2006 12:53 PM
To: python-list@python.org
Subject: Re: building/installing python libs/modules...


On 2/07/2006 5:37 AM, bruce wrote:
> paul,
> 
> thanks for the replies to my issues!!! much appreciation.
> 
> i've got the python app:
> http://www.boddie.org.uk/python/downloads/libxml2dom-0.3.3.tar.gz
> 
> and i've downloaded it, an untarred it...
> i have the dir structure, but i don't know what needs to be done now!!! i
> have a setup.py. does it get run?
> 
> the Readme file didn't tell me how to build the app
> 

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

(see section headed "Installation" at the bottom of the page)

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


Re: I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread [EMAIL PROTECTED]
I would sugest looking at http://pexpect.sourceforge.net/  The Expect
metalanguage was specifically designed for the kind of things you are
trying to do.  I used it recently on a project to configure 25
instances of an application, remotly, half over ssh half over telnet.

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


Re: sys.stdin and two CTRL-Ds

2006-07-01 Thread John Machin
On 2/07/2006 5:02 AM, Christoph Haas wrote:
> Hi...
> 
> I encountered a problem that - according to my google search - other
> people have found, too. Example code:
> 
> import sys
> for line in sys.stdin:
>print line
> 
> Running this code in Python 2.3 or 2.4 has the problem that I need to
> send two EOFs (Ctrl-D) to break out of that loop.
> 
> Use case is a piped Python script that I run as a "CustomLog" pipe for
> an Apache web server. I want to run all the log output through that pipe
> but haven't had much luck. First it takes ages until the script
> processes the input (even though I ran Python with "-u" to make it
> unbuffered)

Which "it" did you expect to make unbuffered? -u unbuffers sys.stdout 
and sys.stderr (and makes them binary, which wouldn't be a good idea on 
a Windows box). If you are concerned that output shows up in real time, 
use sys.stdXXX.flush().

> and then the script needs one EOF to do something with the
> input and a second EOF to break out of the loop.
> 
> Is this a bug? I'm close to write a Perl script for this case. :(

I can reproduce your problem on Windows with Python 2.4.2 (note ^Z is 
EOF for Windows):

|>> import sys
|>> for line in sys.stdin:
... print >> sys.stderr, "->", repr(line)
...
line1
line2
line3
^Z
-> 'line1\n'
-> 'line2\n'
-> 'line3\n'
^Z
|>>

However this worked for me :

|>> import sys
|>> while 1:
... line = sys.stdin.readline()
... if not line: break
... print >> sys.stderr, "->", repr(line)
...
line1
-> 'line1\n'
line2
-> 'line2\n'
^Z
|>>

The Library Reference Manual, section 2.3.9 (File Objects) says:
"""
Files support the iterator protocol. Each iteration returns the same 
result as file.readline(), and iteration ends when the readline() method 
returns an empty string.
"""

So yes, looks like a bug to me, but perhaps you don't need use Perl :-)

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


Re: list comprehension

2006-07-01 Thread a
if i remove the global
i get an undefined error!
it was suggested as a solution in this group below

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b7b2dcdc3e109f3e?hide_quotes=no#msg_8130543f82c6
thanks
Simon Forman wrote:
> a wrote:
> > hi simon thanks for your reply
>
> You're most welcome
>
>
> > what if i want to do this
> > feed_list=[]
> > feed_id=[]
> > for ix in feeds_list_select:
> > global feeds_list
> > global feeds_id
> > feeds_list.append(ix.url)
> >feeds_id.append(ix.id)
> >
> > ie not one variable but more variables
> > thanks
>
> in a case like this I would usually reach for the zip() function, with
> the "varargs" * calling pattern
>
> N = [(ix.url, ix.id) for ix in feeds_list_select]
>
> feed_list, feed_id = zip(*N)
>
>
> or just
>
> feed_list, feed_id = zip(*[(ix.url, ix.id) for ix in
> feeds_list_select])
>
>
> btw, please note that the global statements in your example are
> unnecessary..  *totally* unnecessary.  :-D

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


Re: Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

2006-07-01 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:
> I can't speak for your code, but this is the most common use of keys in
> my coding:
> # d is some dictionary
> keys = d.keys()
> keys.sort()
> for k in keys:
>   #blah

This you can rewrite quite effectively as:

 for k in sorted(d):
 #blah

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


Re: Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

2006-07-01 Thread Nick Vatamaniuc
> 1 - golden handcuffs.  Breaking old code is bad 90% of the time
I agree with you on  that, mostly for code that counted on list methods
of result of keys() - like you later show with sort.   But there is a
side note:  old code that assumed a particular ordering of the keys or
values is broken anyway.  So even if ks={1:0,2:0,3:0}.keys() returns
[1,2,3] on my machine I should not do something like
'my_savings_account + ks[0]' That code should be fixed anyway, since on
a different machine it might produce different values for ks[0].

> 2 - creating a set MAY be slower.
Creating a set from the dictionary's keys should not be a lot slower
because the keys are already unique, there is no need to check each key
against the other keys just return them as a set.  I assume this is
what you meant by "make the set hashmap have the same dimensions and
rules as the dictionary one".  Perhaps a dictionary would internally
just copy its  keys to the set and return it rather than construct as
set from scratch (with duplication checks and all).

>3 - using a set is sometimes slower
Again, depending how it is used.  In your case you argue that you
usually sort the keys anyway so a list is more convinient.  But
different use cases can call for differnent operations on the keys()
after they have been retrieved. What if someone wants to do an
intersection to find common keys with another dictionary, then a set
would be more appropriate. The intent of the set() type was to not temp
anyone into assuming an ordering of keys() just because a list is
indexable. And eliminate the need for a long footnote in the
documentation of the dict type that talks about 'an arbitrary
non-random ordering' - it takes while just to grasp what that means...

In general I believe that a small performance penalty is acceptable in
order to have a correct and consistent data type, especially for Python
i.e. I might not argue the same for Perl or C.

-Nick V.

[EMAIL PROTECTED] wrote:
> There's a few good reasons.
> 1 - golden handcuffs.  Breaking old code is bad 90% of the time
> 2 - creating a set MAY be slower.
>
> Python's sets seem to imply to that they will always be a hash map.  in
> this case, some creative hash map "mapping" could allow one to create a
> set without calculating hash codes (make the set hashmap have the same
> dimentions and rules as the dictionary one).
> If there was intent to allow Python implementations to use trees for
> the set, then a list is far faster to create (O(n) time instead of
> O(nlogn)).
>
> 3 - using a set is sometimes slower (just as using a list is sometimes
> slower)
> I can't speak for your code, but this is the most common use of keys in
> my coding:
> # d is some dictionary
> keys = d.keys()
> keys.sort()
> for k in keys:
>   #blah
>
> sets cannot be sorted, while lists can.  If keys() returned a set, then
> I'd have to turn it into a list every time.
>
> There's potential to add "views" to python (a key view of a dictionary
> being a frozenset containing the dictionary's keys, which is updated
> whenever the dictionary updates), but I think thats annother topic
> which is out of the scope of your origional idea.

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


Re: Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

2006-07-01 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> The same thing goes for the values(). Here most people will argue that
> values are not necessarily unique, so a list is more appropriate, but
> in fact the values are unique it is just that more than one key could
> map to the same value.  What is 'seen' in dictionary is the mapping
> rule.  Also the values are not ordered and should not be indexable --
> they should be a set. Just as  the keys(), one ordered list of values
> from a dictionary on one machine will not necessarily be equal to
> another list of values an on another machine, while in fact, they
> should be.

This part is pretty much a non-starter. Not all Python objects are hashable.

In [1]: d = {}

In [2]: for i in range(1, 10):
...: d[i] = range(i)
...:
...:

In [3]: set(d.values())
---
exceptions.TypeError Traceback (most recent 
call 
last)

/Users/kern/

TypeError: list objects are unhashable


Also, I may need keys to map to different objects that happen to be equal.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


Re: Odd behavior with staticmethods

2006-07-01 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:
> I'm getting rather inconsistent behavior with staticmethod.
Not really.

 class A:
>   def orig():
>   print "hi"
>   st = staticmethod(orig)
>   st2 = st
>   wrapped = [ orig ]
>   wrapped2 = [ st ]
...
  A.wrapped[0]() # ODD - wrapping orig() in a list makes orig() work?
 > hi
  A.wrapped2[0]() # ODD - copying st works -- A.st2() -- but copying 
it to a list fails?
...

When you put orig in wrapped, it is _before_ the class is built,
so you are placing a simple function of no args in a list.

When you put st in wrapped2, it is also _before_ the class is built,
so you are placing staticmethod(a simple function of no args) in a list.

You really should be using new-style classes, some things just
work wrong in "classic classes" (this is not one of those things,
however).

When the class gets built, the staticmethod wrapper is used to determine
how to build A.  The class construction gets handed the "namespace"
that was defined in the class suite, and it fumbles over the defined
names determining what conversions to apply (and looking for things
like "__metaclass__" and "__slots__").  For more on all of this read
the language reference, esp. the "Data Model" section, and probably that
on the difference between old-style and new-style classes.



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


Re: Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

2006-07-01 Thread John Machin
On 2/07/2006 6:01 AM, [EMAIL PROTECTED] wrote:
> This has been bothering me for a while. 
[snip]

Summary of OP's post: d.keys() and d.values() should return sets in 
Python 3.0.

Observations:
(1) My code [some of which dates back to Python 1.5.1] uses about 12 x 
d.items() and 11 x d.keys() for each 1 x d.values()
(2) Most cases of d.X() don't need/want the untrammelled list and could 
be replaced by d.iterX(). Example: max_frequency = max(tally.values())

Opinion: d.X() could be deprecated, but I'd rather see a 
consciousness-raising for the d.iterX() methods, and for the construct
 for key in d:

Cheers,
John


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


Re: Event notification system - where to start ?

2006-07-01 Thread Michael
[EMAIL PROTECTED] wrote:

> We have been asked to develop and application for a client that is a
> 'notification" system.  We would like to use python, but are struggling
> to find the right starting point.  Any suggestions, tips or sample code
> would be appreciated.

Kamaelia [1] sounds like a good fit for what you're doing. (so does Twisted
actually, but in the following I'll describe Kamaelia - why? I'm the
project lead for Kamaelia - however be aware that twisted might also fit
your problem well :-)

  [1] http://kamaelia.sourceforge.net/Home

Assumptions in the following sketch code:
   * All clients stay connected to machine b (rather than machine B
 connecting to the clients or (say) emailling clients or whatever
 you're doing)
   * WatchSerialPort is a simple component that wraps your code for
 connecting to the serial port and waiting for event
   * Each message it sends out represents a unique event, and has been
 serialised suitable for sending over a network connection.
   * For machine B, you've wrapped up your pre-processing of events as a
  component called for sake of argument EventFilter

> Application outline;
> 
> Machine A is running a "listener" application that is connected to a
> another device via the serial post and waits for events.  We have not
> problem working with the serial port, or the waiting for the event to
> happen.
>
> When A received a specific event, it needs to send a message to machine
> B that and event has occurred and that type of event.

This is clearly implementable using the following on machine A. (I'll come
back to WatchSerialPort in a minute)

pipeline(
WatchSerialPort(), # the code you described above for connecting
   # to the serial port sits in here.
TCPClient("machine.b", 1500),
).run()


> Machine B will take the event notification, processes some additional
> information (ie. database lookups) and then notify a series of clients
> that have "registered" with machine B to receive events.

This sounds like the following code:

Backplane("Events").activate()

pipeline( ### INPUT TO BACKPLANE
   SingleServer(port=1500),
   EventFilter(),
   publishTo("Events"),
).activate()

def subscriber_protocol():
return subscribeTo("Events")

SimpleServer(subscriber_protocol, 1600).run()

Clients then connect to machine B and will receive copies of all events.

Regarding implementing WatchSerialPort. In many respects I'll assume that
you can equate your functionality for getting code to something blocking
like this:
class  <... some class >
def formatOutput(self, *args):
return " ".join([ str(x) for x in args ])

def watch_serial_for_events(self)
while 1:
X = raw_input()
if self.matches_event():
print self.formatOutput("We got an event!", X)

If you wanted to turn the above into a Kamaelia component (without adding
shutdown code, etc), it'd look something like:

class WatchSerialPort(Axon.ThreadedComponent.threadedcomponent):
def formatOutput(self, *args):
return " ".join([ str(x) for x in args ])

def main(self)
while 1:
X = raw_input()
if self.matches_event():
self.send( self.formatOutput("We got an event!", X),
   "outbox")

The reason for using a threadedcomponent here is because I'm assuming like
raw_input your code for checking the serial port for events is blocking.

Regarding the EventFilter, again if you're using blocking code (such as
database access), then putting that code inside a "threadedcomponent"
baseclass makes sense, if it's not blocking, then using a generator (ie put
a yield somewhere in the main loop), and using a baseclass of "component"
makes sense.

The basic outline for it would look like this - assuming some code that
involves blocking processing:

class EventFilter(threadedcomponent): # I assume something blocking
   def PreProcessEvent(self, event): pass # exercise for the reader
   def main(self):
  while 1:
  while self.dataReady("inbox"):
  event = self.recv("inbox")
  information = self.PreProcessEvent(event) # presumed blocking
  self.send( information, "outbox")
  if not self.anyReady():
  self.pause()

If you want all users to receive copies of all events, that's where this
kinda stops, since despite being sketch (ie untested) code, it's pretty
much all you'd do.

If you're thinking you may have a variety of different messages which you
might want to filter, then if you demultiplex them to different ports on
the same machine, then that's relatively simple to achieve as well, but the
pipeline would need changing to a graphline and the code for EventFilter
would need to do the demultiplexing.

For example, suppose you have 3 types of events people can subscribe to:

Backplane("NormalEvents").activate()
Backplane("ImportantEvents").activate()
Backplane("CriticalEven

Re: list comprehension

2006-07-01 Thread John Machin
On 2/07/2006 6:43 AM, a wrote:
> if i remove the global
> i get an undefined error!

That's because you have feed_list in one place and feeds_list in 
another. Ditto feed_id and feeds_id. Your code was *already* broken 
before you removed the global(s).

> it was suggested as a solution in this group below

Bruno wrote, in the thread that you quote: "Globals are *evil*. And 
functions modifying globals is the worst possible thing." Is that what 
you call "suggested as a solution"?

> 
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/b7b2dcdc3e109f3e?hide_quotes=no#msg_8130543f82c6
> thanks
> Simon Forman wrote:
>> a wrote:
>>> hi simon thanks for your reply
>> You're most welcome
>>
>>
>>> what if i want to do this
>>> feed_list=[]
>>> feed_id=[]
>>> for ix in feeds_list_select:
>>> global feeds_list
>>> global feeds_id
>>> feeds_list.append(ix.url)
>>>feeds_id.append(ix.id)
>>>
>>> ie not one variable but more variables
>>> thanks
>> in a case like this I would usually reach for the zip() function, with
>> the "varargs" * calling pattern
>>
>> N = [(ix.url, ix.id) for ix in feeds_list_select]
>>
>> feed_list, feed_id = zip(*N)
>>
>>
>> or just
>>
>> feed_list, feed_id = zip(*[(ix.url, ix.id) for ix in
>> feeds_list_select])
>>
>>
>> btw, please note that the global statements in your example are
>> unnecessary..  *totally* unnecessary.  :-D
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing feature classes and missing fields

2006-07-01 Thread Roel Schroeven
Gary Herron schreef:
> subramanian2003 wrote:
>> Hello All,
>>
>> How can I check missing feature classes in a folder/personal geodatabase 
>> using python script. And how can I check  missing fields in shape files. And 
>> also I want to check the attribute values using python.
>>
>> Thnx,
>> Subramanian.
>>
>>
>>
>>   
> This list is usually very helpful, however, I think you are going to
> need to be more specific to get an answer here.
> 
> For instance,
> 
> What's are "missing feature classes"?
> What's a "folder/personal geodatabase"?
> What's are "missing fields"?
> What's a "shape file"?
> On what object to you wish to check "attribute values"?

AFAIK, shape files are files with geospatial information used by ESRI 
(http://www.esri.com/) products (and others). Features are the objects 
in the geospatial database (roads, bridges, buildings, ...) and the 
features have attributes and the attributes have values (e.g. a road may 
have an attribute 'width' with a value '10 m').

But I still can't answer the question. I don't even know if there's a 
way for python to read shape files. Maybe there's something to be found 
at http://www.freegis.org/ or http://www.opensourcegis.org/.


-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


doctest, sys.stderr, SystemExit and unused return values

2006-07-01 Thread Steven Bethard
I have an optparse-like module and though I have a full unittest-style 
suite of tests for it, I'd also like to be able to run doctest on the 
documentation to make sure my examples all work.  However, I see that 
doctest (1) doesn't capture anything from sys.stderr, and (2) unlike the 
normal interpreter, generates a traceback for SystemExit.

Here's what some of my tests look like and the doctest output I get::

 == in my documentation ==
 >>> parser.print_help()
 usage: PROG [-h] [-w W] [-x X [X ...]] [y] [z [z ...]]

 optional arguments:
   -h, --helpshow this help message and exit
   -w W  w help
   -x X [X ...]  x help

 positional arguments:
   y y help
   z z help

 == the doctest output ==
 Failed example:
 parser.print_help()
 Expected:
 usage: PROG [-h] [-w W] [-x X [X ...]] [y] [z [z ...]]


 == in my documentation ==
 >>> parser.parse_args('xyz --b 42'.split())
 usage: PROG xyz [-h] [--x XXX] [-y] z
 PROG xyz: error: no such option: --b

 == the doctest output ==
 Failed example:
 parser.parse_args('xyz --b 42'.split())
 Exception raised:
 Traceback (most recent call last):
 ...
 SystemExit: 2

Just like with optparse, calling ``print_help()`` and ``parse_args()`` 
prints to sys.stderr, and ``parse_args()`` raises SystemExit when it 
encounters an error.

Is there a way to get these tests to pass?


On a related note, my examples currently use a lot of ``_ =`` because, 
like optparse, I quite frequently don't care about the return value of 
calls to add arguments, e.g.::

 >>> parser = argparse.ArgumentParser(prog='PROG')
 >>> _ = parser.add_optional('--foo', help='foo help')
 >>> _ = parser.add_positional('bar', help='bar help')
 >>> values = parser.parse_args('--foo spam badger'.split())
 >>> values.foo
 'spam'
 >>> values.bar
 'badger'

Is there any way to avoid having to write the ``_ =`` without getting an 
error like::

 Failed example:
 parser.add_optional('--foo', help='foo help')
 Expected nothing
 Got:
 Optional('--foo', dest='foo', action=None, ...

I don't want to include the whole Optional repr() string because it's 
long and it distracts from the point of the example.

STeVe

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


Re: beautifulsoup .vs tidy

2006-07-01 Thread Matt Good
bruce wrote:
> that's exactly what i'm trying to accomplish... i've used tidy, but it seems
> to still generate warnings...
>
>  initFile -> tidy ->cleanFile -> perl app (using xpath/livxml)
>
> the xpath/linxml functions in the perl app complain regarding the file. my
> thought is that tidy isn't cleaning enough, or that the perl xpath/libxml
> functions are too strict!

Clean HTML is not valid XML.  If you want to process the output with an
XML library you'll need to tell Tidy to output XHTML.  Then it should
be valid for XML processing.

Of course BeautifulSoup is also a very nice library if you need to
extract some information, but don't necessarilly require XML processing
to do it.

-- Matt Good

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


really basic question regarding arrays/function output...

2006-07-01 Thread bruce
hi...

i have the following test python script i'm trying to figure out a
couple of things...

1st.. how can i write the output of the "label" to an array, and then how i
can select a given element of the array.. i know real basic..

2nd.. where can i go to find methods of libxml2dom. i've been looking using
google, but can't seem to find a site pointing out the underlying methods,
which is kind of strange...

-bruce



-
test.py
#! /usr/bin/env python

#test python script
import libxml2dom
import urllib

print "hello"

turl =
"http://courses.tamu.edu/ViewSections.aspx?campus=CS&x=hvm4MX4PXIY9J8C2Dcxz5
0ncXTJdT7v2&type=M"

f = urllib.urlopen(turl)
s = f.read()
f.close()
# s contains HTML not XML text
d = libxml2dom.parseString(s, html=1)
# get the community-related links
for label in
d.xpath("/html/body/table/tr/td[2]/table/tr[6]/td/table/child::tr/[EMAIL 
PROTECTED]
'sectionheading']/text()"):

print label.nodeValue


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


Re: beautifulsoup .vs tidy

2006-07-01 Thread Ravi Teja

Paul Boddie wrote:
> Ravi Teja wrote:
> >
> > 1.) XPath is not a good idea at all with "malformed" HTML or perhaps
> > web pages in general.
>
> import libxml2dom
> import urllib
> f = urllib.urlopen("http://wiki.python.org/moin/";)
> s = f.read()
> f.close()
> # s contains HTML not XML text
> d = libxml2dom.parseString(s, html=1)
> # get the community-related links
> for label in d.xpath("//li[.//a/text() = 'Community']//li//a/text()"):
> print label.nodeValue

I wasn't aware that your module does html as well.

> Of course, lxml should be able to do this kind of thing as well. I'd be
> interested to know why this "is not a good idea", though.

No reason that you don't know already.

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

"If the document text is well-formed XML, we could omit the html
parameter or set it to have a false value."

XML parsers are not required to be forgiving to be regarded compliant.
And much HTML out there is not well formed.

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


Re: I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread Paul McGuire
"gavino" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> This seems easy but I have been asking tcl and python IRC chat all day
> and no one gave an answer.
> I have 100 servers which need a new backup server added to a text file,
>  and then the backup agent restarted.
> If I have a list of the servers, all with same root password, and the
> connection is ssh.
> How do I connect to the server, cat the line to the config file, stop
> adn start the agent, and then do same to next server in list and
> iterate through the 100 servers.
> What script would allow this?
>

Could this project help you? http://sourceforge.net/projects/distribulator/

It sounds similar to what you describe.

-- Paul



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


Re: really basic question regarding arrays/function output...

2006-07-01 Thread Paul McGuire

"bruce" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> hi...
>
> i have the following test python script i'm trying to figure out a
> couple of things...
>
> 1st.. how can i write the output of the "label" to an array, and then how
i
> can select a given element of the array.. i know real basic..
>
I think this is so basic, I'm not sure what you're talking about.  One does
not really "write to an array".  In fact, Python's most natural data
structure is a list, which has many array-like features (there is also an
array module, but since you are asking basic questions, I'm trying to stick
to basic Python).

To append an item to a list, use append.
To graft one list on to the end of another, use += or extend.
To access the i'th element of a list use [i] (indices are zero-based).

This is covered in far better detail in the Python tutorials.  These
fundamental data structures of Python (list, tuple, dict, set, str) are your
fundamental tools when writing Python code, so you should read up on them.

> 2nd.. where can i go to find methods of libxml2dom. i've been looking
using
> google, but can't seem to find a site pointing out the underlying methods,
> which is kind of strange...
>
Try dir and help from the Python interactive command line.  Assuming you
have installed libxml2dom, do this:

import libxml2dom
dir(libxml2dom)
help(libxml2dom)

I see that this module also contains directories for tests and tools, these
may provide you with some usage examples. (The docs directory *is* woefully
brief...)

-- Paul


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


python-dev Summary for 2006-05-16 through 2006-05-31

2006-07-01 Thread Steven Bethard
python-dev Summary for 2006-05-16 through 2006-05-31


.. contents::

[The HTML version of this Summary is available at
http://www.python.org/dev/summary/2006-05-16_2006-05-31]



=
Announcements
=


QOTF: Quote of the Fortnight


Martin v. Löwis on what kind of questions are appropriate for python-dev:

... [python-dev] is the list where you say "I want to help", not
so much "I need your help".

Contributing thread:

- `Segmentation fault of Python if build on Solaris 9 or 10 with Sun
Studio 11 `__

---
Python 2.5 schedule
---

Python 2.5 is moving steadily towards its next release.  See `PEP
356`_ for more details and the full schedule.  You may start to see a
few warnings at import time if you've named non-package directories
with the same names as your modules/packages.  Python-dev suggests
renaming these directories -- though the warnings won't give you any
real trouble in Python 2.5, there's a chance that a future version of
Python will drop the need for __init__.py.

.. _PEP 356: http://www.python.org/dev/peps/pep-0356/

Contributing thread:

- `2.5 schedule
`__
- `warnings about missing __init__.py in toplevel directories
`__

--
Restructured library reference
--

Thanks to work by A.M. Kuchling and Michael Spencer, the organization
of the `development Library Reference documentation`_ structure is
much improved over the `old one`_.  Thanks for your hard work guys!

.. _development Library Reference documentation:
http://docs.python.org/dev/lib/lib.html
.. _old one: http://docs.python.org/lib/lib.html

Contributing thread:

- `[Python-3000] stdlib reorganization
`__

-
Need for Speed Sprint results
-

The results of the `Need for Speed Sprint`_ are all posted on the
wiki.  In particular, you should check a number of `successes`_ they
had in speeding up various parts of Python including function calls,
string and Unicode operations, and string<->integer conversions.

.. _Need for Speed Sprint: http://wiki.python.org/moin/NeedForSpeed/
.. _successes: http://wiki.python.org/moin/NeedForSpeed/Successes

Contributing threads:

- `[Python-checkins] r46043 - peps/trunk/pep-0356.txt
`__
- `Need for Speed Sprint status
`__

-
Python old-timer memories
-

Guido's been collecting `memories of old-timers`_ who have been using
Python for 10 years or more.  Be sure to check 'em out and add your
own!

.. _memories of old-timers:
http://www.artima.com/weblogs/viewpost.jsp?thread=161207

Contributing thread:

- `Looking for Memories of Python Old-Timers
`__


=
Summaries
=

-
Struct module inconsistencies
-

Changes to the struct module to do proper range checking resulted in a
few bugs showing up where the stdlib depended on the old, undocumented
behavior.  As a compromise, Bob Ippolito added code to do the proper
range checking and issue DeprecationWarnings, and then made sure that
the all struct results were calculated with appropriate bit masking.
The warnings are expected to become errors in Python 2.6 or 2.7.

Bob also updated the struct module to return ints instead of longs
whenever possible, even for the format codes that had previously
guaranteed longs (I, L, q and Q).

Contributing threads:

- `Returning int instead of long from struct when possible for
performance 
`__
- `test_gzip/test_tarfile failure om AMD64
`__
- `Converting crc32 functions to use unsigned
`__
- `test_struct failure on 64 bit platforms
`__

-
Using epoll for the select module
-

Ross Cohen implemented a `drop-in replacement for select.poll`_ using
Linux's epoll (a more efficient io notifcation system than poll).  The
select interface is already much closer to the the epoll API than the
poll API, and people liked the idea of using epoll silently when
available. Ross promised to look into merging his code with the
current select module (though it wasn't clear whether 

Re: Odd behavior with staticmethods

2006-07-01 Thread [EMAIL PROTECTED]
ya know, I've searched for these "new classes" at least five times.
I've heard all the wonderful things about how they make your life into
a piece of chocolate with rainbows sprinkled in it.  Never once have I
found a site that explains what syntax to use to make these new
classes.

Anyone have a URL?


Scott David Daniels wrote:
> [EMAIL PROTECTED] wrote:
> > I'm getting rather inconsistent behavior with staticmethod.
> Not really.
>
>  class A:
> > def orig():
> > print "hi"
> > st = staticmethod(orig)
> > st2 = st
> > wrapped = [ orig ]
> > wrapped2 = [ st ]
> ...
>   A.wrapped[0]() # ODD - wrapping orig() in a list makes orig() work?
>  > hi
>   A.wrapped2[0]() # ODD - copying st works -- A.st2() -- but copying
> it to a list fails?
> ...
>
> When you put orig in wrapped, it is _before_ the class is built,
> so you are placing a simple function of no args in a list.
>
> When you put st in wrapped2, it is also _before_ the class is built,
> so you are placing staticmethod(a simple function of no args) in a list.
>
> You really should be using new-style classes, some things just
> work wrong in "classic classes" (this is not one of those things,
> however).
>
> When the class gets built, the staticmethod wrapper is used to determine
> how to build A.  The class construction gets handed the "namespace"
> that was defined in the class suite, and it fumbles over the defined
> names determining what conversions to apply (and looking for things
> like "__metaclass__" and "__slots__").  For more on all of this read
> the language reference, esp. the "Data Model" section, and probably that
> on the difference between old-style and new-style classes.
> 
> 
> 
> --Scott David Daniels
> [EMAIL PROTECTED]

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


Re: Odd behavior with staticmethods

2006-07-01 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> ya know, I've searched for these "new classes" at least five times.
> I've heard all the wonderful things about how they make your life into
> a piece of chocolate with rainbows sprinkled in it.  Never once have I
> found a site that explains what syntax to use to make these new
> classes.

I doubt that.

google: new style classes python

second match:

http://www.geocities.com/foetsch/python/new_style_classes.htm


Happy reading.

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


python guru in the Bay Area

2006-07-01 Thread bruce
hi...

is there someone in the Bay Area who knows python, that I can talk to ... I
have the shell of a real basic app, and I'd like someone who can walk me
through how to set it up.

i'm talking about passing arrays, setting up global data, etc... basically,
if i can create a shell for what i'm trying to create, i should be ok..

lunch of course, would be on me!!

thanks

-bruce

ps. yeah.. i know i could eventually figure most of this by
searching/experimenting/etc... using google.. but i'd rather move as fast as
possible.


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


Re: Non-ASCII languages

2006-07-01 Thread Tim Roberts
Scott David Daniels <[EMAIL PROTECTED]> wrote:
>
>SAIL (Stanford AI Lab) had the first laser printer
>to play with (people wrote incredibly ugly documents with tons of fonts
>in them because it was the first they could spec it). 

"Ransom note syndrome."  Virtually everyone falls prey to this the first
few times they discover desktop publishing.

>All of this was in the mid seventies or earlier.

Right.  It surprises many people to learn that virtually everything we
think of as modern and interesting in computer science was first explored
in the 1960s and early 1970s.  GUIs, color, 3D, structured progamming,
networking, interpreters, Unix; the list goes on and on.  It was probably
the most exciting time in the history of computers.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python guru in the Bay Area

2006-07-01 Thread John Bokma
"bruce" <[EMAIL PROTECTED]> wrote:

> ps. yeah.. i know i could eventually figure most of this by
> searching/experimenting/etc... using google.. but i'd rather move as
> fast as possible.

Then I recommend a book instead of trial and error programming. Dive into 
Python can be downloaded for free, and will get you programming and 
knowing what you are doing in a short time if you have programming skills 
and quite some background.

-- 
John   MexIT: http://johnbokma.com/mexit/
   personal page:   http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python guru in the Bay Area

2006-07-01 Thread gene tani

bruce wrote:
> hi...
>
> is there someone in the Bay Area who knows python, that I can talk to ... I
> have the shell of a real basic app, and I'd like someone who can walk me
> through how to set it up.
>
> i'm talking about passing arrays, setting up global data, etc... basically,
> if i can create a shell for what i'm trying to create, i should be ok..
>
> lunch of course, would be on me!!
>
> thanks
>
> -bruce
>
> ps. yeah.. i know i could eventually figure most of this by
> searching/experimenting/etc... using google.. but i'd rather move as fast as
> possible.

I think the tutor list is good for this
http://mail.python.org/mailman/listinfo/tutor

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


Re: Odd behavior with staticmethods

2006-07-01 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:
> ya know, I've searched for these "new classes" at least five times.
> I've heard all the wonderful things about how they make your life into
> a piece of chocolate with rainbows sprinkled in it.  Never once have I
> found a site that explains what syntax to use to make these new
> classes.

 http://www.python.org/doc/newstyle.html

 From the docs for the upcoming 2.5:

 http://docs.python.org/dev/ref/node33.html


As to how you make them:

 class Whatever:
 ...
is an old-style class.

 class Whenever(object):
 ...
is a new-style class.

 class Whoever(SomeClass):
 ...
is an old-style class if SomeClass is an old-style class,
and a new-style class if SomeClass is a new-style class.

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


Re: I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

2006-07-01 Thread Thorsten Kampe
* gavino (2006-07-01 11:34 +)
> This seems easy but I have been asking tcl and python IRC chat all day
> and no one gave an answer.
> I have 100 servers which need a new backup server added to a text file,
>  and then the backup agent restarted.
> If I have a list of the servers, all with same root password, and the
> connection is ssh.
> How do I connect to the server, cat the line to the config file, stop
> adn start the agent, and then do same to next server in list and
> iterate through the 100 servers. 
> What script would allow this?

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


Re: Non-ASCII languages

2006-07-01 Thread Scott David Daniels
Tim Roberts wrote:
> It surprises many people to learn that virtually everything we
> think of as modern and interesting in computer science was first explored
> in the 1960s and early 1970s.  GUIs, color, 3D, structured progamming,
> networking, interpreters, Unix; the list goes on and on.  It was probably
> the most exciting time in the history of computers.

Here I think you're wrong, my vote is the 1940s:
 First time for tons of stuff, fate of the world hangs in the
balance, no idea if some of this is going to work, 
Essentially all the crypto push with top secret machines decoding
German traffic, and the desperate attempt to crack the Japanese
Purple system.  I expect the efforts at Bletchley Park, Princeton,
numerous unnamed locations, and even Germany and Japan were pulse-
pounding.  In the sixties and seventies we were just having immense
fun making things go, at least by comparison.

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


Re: efficiency question

2006-07-01 Thread diffuser78
Thanks for this thing.

http://www.python.org/doc/current/lib/module-dis.html made it more
clear.

Fredrik Lundh wrote:
> David Harvey wrote:
>
> > Suppose I write
> >
> > if x in ("abc", "def", "xyz"):
> > doStuff()
> >
> > elif x in ("pqr", "tuv", "123"):
> > doOtherStuff()
> >
> > elif ...
> > When is python building the tuples? Does it need to build the tuple
> > every time it comes through this code? Or does it somehow recognise
> > that they are constant and cache them?
>
> when in doubt, ask the compiler:
>
> def code(x):
> if x in ("abc", "def", "xyz"):
> doStuff()
> elif x in ("pqr", "tuv", "123"):
> doOtherStuff()
>
> import dis
> dis.dis(code)
>
> prints:
>
>   2   0 LOAD_FAST0 (x)
>   3 LOAD_CONST   7 (('abc', 'def', 'xyz'))
>   6 COMPARE_OP   6 (in)
>   9 JUMP_IF_FALSE   11 (to 23)
>  12 POP_TOP
>
>   3  13 LOAD_GLOBAL  1 (doStuff)
>  16 CALL_FUNCTION0
>  19 POP_TOP
>  20 JUMP_FORWARD25 (to 48)
> >>   23 POP_TOP
>
>   4  24 LOAD_FAST0 (x)
>  27 LOAD_CONST   8 (('pqr', 'tuv', '123'))
>  30 COMPARE_OP   6 (in)
>  33 JUMP_IF_FALSE   11 (to 47)
>  36 POP_TOP
>
>   5  37 LOAD_GLOBAL  2 (doOtherStuff)
>  40 CALL_FUNCTION0
>  43 POP_TOP
>  44 JUMP_FORWARD 1 (to 48)
> >>   47 POP_TOP
> >>   48 LOAD_CONST   0 (None)
>  51 RETURN_VALUE
>
> so the answer is "yes, in this specific case".
>
> > (The tuples I have in mind are of course much longer than three
> > elements)
>
> in that case, you should probably use pre-calculated sets instead of tuples.
> 
> 

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


Re: Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

2006-07-01 Thread Roy Smith
"Nick Vatamaniuc" <[EMAIL PROTECTED]> wrote:
> But there is a side note:  old code that assumed a particular ordering 
> of the keys or values is broken anyway.

>From a testing point of view, it would be interesting if there was a flag 
which said, "Deliberately change everything which isn't guaranteed to be a 
specific way".  So, for example, dict.keys() would return a list in reverse 
order of how it normally does it (even if it cost more to do it that way).  
An alternate hash key generator would be slipped into place.  Floating 
point math would get a little noise added to the least significant bits.  
And so on.  Might be interesting to see what sorts of bugs that would shake 
out from user code.
-- 
http://mail.python.org/mailman/listinfo/python-list


size of an array..

2006-07-01 Thread bruce
hi..

another basic question...

in the following:
#test python script
import libxml2dom
import urllib

print "hello"

turl =
"http://courses.tamu.edu/ViewSections.aspx?campus=CS&x=hvm4MX4PXIY9J8C2Dcxz5
0ncXTJdT7v2&type=M"

f = urllib.urlopen(turl)
s = f.read()
f.close()
# s contains HTML not XML text
d = libxml2dom.parseString(s, html=1)
# get the community-related links
for label in
d.xpath("/html/body/table/tr/td[2]/table/tr[6]/td/table/child::tr/[EMAIL 
PROTECTED]
'sectionheading']/text()"):
print label.nodeValue

print "/n/n/n/"

l =
d.xpath("/html/body/table/tr/td[2]/table/tr[6]/td/table/child::tr/[EMAIL 
PROTECTED]
'sectionheading']/text()")

xx = =sizeof(l)
print "test\n"
print "l = ".xx." \n"
print l[1].nodeValue
=

how do i determine the size of "l"

from the "for label in d.xpath", i assume that "d.xpath" is returning
multiple strings/objects/etc... and that label is assigned to the next
"element during the loop.

is there a way to determine the number of elements in "l", or the number of
iterations for the "for loop" prior to running it...

the tutorials i've seen as of yet haven't mentioned this..

thanks

-bruce



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


Can I do it using python?? about xterm and telnet

2006-07-01 Thread valpa
I'm a net admin for about 20 unix servers, and I need to frequently
telnet on to them and configure them.
It is a tiring job to open a xterm and telnet, username, password to
each server.

Can I  do it automatically by python? After that, there have 20 xterm
consoles opened and telneted to their corresponding servers. Then I
could start to type command in these xterms.

Any suggestion appreciate. Much thanks.

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


python/libxml2dom questions

2006-07-01 Thread bruce
hi paul...

in playing around with the test python app (see below) i've got a couple of
basic questions. i can't seem to find the answers via google, and when i've
looked in the libxml2dom stuff that i downloaded i didn't see answers
either...

for the list in the "for label in d.xpath" how can i find out the size of
the list a simple/basic question, but it's driving me up a wall!!!

also, how can i determine what methods are available for a libxml2dom
object?

thanks...

-bruce


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


python/libxml2dom questions

2006-07-01 Thread bruce
hi paul...

in playing around with the test python app (see below) i've got a couple of
basic questions. i can't seem to find the answers via google, and when i've
looked in the libxml2dom stuff that i downloaded i didn't see answers
either...

for the list in the "for label in d.xpath" how can i find out the size of
the list a simple/basic question, but it's driving me up a wall!!!

also, how can i determine what methods are available for a libxml2dom
object?

thanks...

-bruce

sample code:


#test python script
import libxml2dom
import urllib

print "hello"

turl =
"http://courses.tamu.edu/ViewSections.aspx?campus=CS&x=hvm4MX4PXIY9J8C2Dcxz5
0ncXTJdT7v2&type=M"

f = urllib.urlopen(turl)
s = f.read()
f.close()
# s contains HTML not XML text
d = libxml2dom.parseString(s, html=1)
# get the community-related links
for label in
d.xpath("/html/body/table/tr/td[2]/table/tr[6]/td/table/child::tr/[EMAIL 
PROTECTED]
'sectionheading']/text()"):
print label.nodeValue

print "/n/n/n/"

l =
d.xpath("/html/body/table/tr/td[2]/table/tr[6]/td/table/child::tr/[EMAIL 
PROTECTED]
'sectionheading']/text()")

print l[1].nodeValue

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


Re: Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

2006-07-01 Thread Nick Vatamaniuc
You are correct I should have thought of that. I still think the keys()
method should return a set() though.

Robert Kern wrote:
> [EMAIL PROTECTED] wrote:
> > The same thing goes for the values(). Here most people will argue that
> > values are not necessarily unique, so a list is more appropriate, but
> > in fact the values are unique it is just that more than one key could
> > map to the same value.  What is 'seen' in dictionary is the mapping
> > rule.  Also the values are not ordered and should not be indexable --
> > they should be a set. Just as  the keys(), one ordered list of values
> > from a dictionary on one machine will not necessarily be equal to
> > another list of values an on another machine, while in fact, they
> > should be.
>
> This part is pretty much a non-starter. Not all Python objects are hashable.
>
> In [1]: d = {}
>
> In [2]: for i in range(1, 10):
> ...: d[i] = range(i)
> ...:
> ...:
>
> In [3]: set(d.values())
> ---
> exceptions.TypeError Traceback (most recent 
> call
> last)
>
> /Users/kern/
>
> TypeError: list objects are unhashable
>
>
> Also, I may need keys to map to different objects that happen to be equal.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it 
> had
>   an underlying truth."
>-- Umberto Eco

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


Re: python/libxml2dom questions

2006-07-01 Thread Paul McGuire
"bruce" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> hi paul...
>
> in playing around with the test python app (see below) i've got a couple
of
> basic questions. i can't seem to find the answers via google, and when
i've
> looked in the libxml2dom stuff that i downloaded i didn't see answers
> either...
>
> for the list in the "for label in d.xpath" how can i find out the size of
> the list a simple/basic question, but it's driving me up a wall!!!
>
I'm at a loss.  Python ships with sample code.  libxml2dom ships with sample
code.  Somewhere in there must be code that evaluates the length (hint) of a
list.

What search terms are you googling for?  The 3rd link returned from Google,
searching for "python list size" is this one.

http://www.brpreiss.com/books/opus7/html/page82.html

Yes, this is a simple/basic question.  It is so simple/basic, that it gets
discussed in just about every Python tutorial within the first 3 pages.

> also, how can i determine what methods are available for a libxml2dom
> object?

Didn't I post a message earlier describing dir and help?  You need to do
some basic reading, man!


-- Paul
Give a man a fish and you feed him for a day;
give a man a fish every day and you feed him for the rest of his life.


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


Re: size of an array..

2006-07-01 Thread Barry Kelly
"bruce" <[EMAIL PROTECTED]> wrote:

> from the "for label in d.xpath", i assume that "d.xpath" is returning
> multiple strings/objects/etc... and that label is assigned to the next
> "element during the loop.
> 
> is there a way to determine the number of elements in "l", or the number of
> iterations for the "for loop" prior to running it...
> 
> the tutorials i've seen as of yet haven't mentioned this..

Have you tried len(object)?

-- Barry

-- 
http://barrkel.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >