Re: Extracting xml from html

2007-09-18 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
> I am attempting to extract some XML from an HTML document that I get
> returned from a form based web page. For some reason, I cannot figure
> out how to do this.
> Here's a sample of the html:
> 
> 
> 
> lots of screwy text including divs and spans
> 
> 1126264
> Mitsubishi
> Mirage DE
> 
> 
> 
> 
> What's the best way to get at the XML? Do I need to somehow parse it
> using the HTMLParser and then parse that with minidom or what?

lxml makes this pretty easy:

   >>> parser = etree.HTMLParser()
   >>> tree = etree.parse(the_file_or_url, parser)

This is actually a tree that can be treated as XML, e.g. with XPath, XSLT,
tree iteration, ... You will also get plain XML when you serialise it to XML:

   >>> xml_string = etree.tostring(tree)

Note that this doesn't add any namespaces, so you will not magically get valid
XHTML or something. You could rewrite the tags by hand, though.

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


uninstall python2.5 on debian

2007-09-18 Thread dimitri pater
Hello,
both python2.3 and python2.5 are installed on my Debian webserver. For
some reason, I would like to uninstall Python2.5 which was installed
from source (make install) and keep 2.3.
I have tried make uninstall and searched the web, but that did not help me.
I guess rm -Rf python2.5 is not a wise thing to do.

thanks,
Dimitri

-- 
---
You can't have everything. Where would you put it? -- Steven Wright
---
please visit www.serpia.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting indented code snippets into blogger

2007-09-18 Thread Paddy
I got tired of Bloggers inadequate comment editor so wrote this for
transforming code snippets:

=
'''
blogspace.py
Turns leading spaces into HTML   tokens which shows
as correct indentation on Blogger comment fields
(and maybe other blogs).

Donald. 'Paddy' McCarthy Sept 2011
'''
import fileinput, re


for l in fileinput.input():
  print re.sub(r'^(\s*)\s',
   lambda m: ' '*m.end(),
   l.rstrip())
=

If you find it works on other blogs then please reply.to this thread.

- Paddy.

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


Re: adodb with mysql - connection string syntax for filepath

2007-09-18 Thread Mridula Ramesh
Hi. Firstly, thank you both very much for the response!

Cliff, I did some more reading up about it after  you corrected me re MySQL
not being a _language_  but another means of storing data (would you believe
NONE of the connection tutorials actually said that?!) Anyway, now I have
MySQL on my machine, and it's installed - if I say "import MySQLdb" in
python prompt, it does that, but I can't see any exe in the program's folder
itself: does that mean tables can only be created by code? *puzzled*

Steve, thank you too, I looked up the link you had given, but I do not yet
know which part of that site may help me... And I am now going to struggle
with Dive Into Python before attempting much else!

This is a nice, helpful mailing group!

Thanks again.




On 17/09/2007, Mridula Ramesh <[EMAIL PROTECTED]> wrote:
>
> Dear all,
>
> Hi. I am not very tech-savvy so please pardon me if this is a stupid
> question: so far I have been googling for about 4 days to find help for
> this, so now I am desperate! :)
>
> How do you use adodb with mysql to connect to a file that is on your
> machine?
>
> Also, could you please recommend to me a good resource to learn more about
> classes and modules from? i don't understand half of the _init_ business
> that many sites mention. (This *is* something even a newbie needs to learn,
> right?)
>
> Thank you!
>
> M.R.S.
>



-- 

CONSUL CONSOLIDATED PVT LTD.

9/6 1st street
Venkateshwara Nagar
Adyar
Madras 600 020
Ph  : 91 - 44 - 24468117
Fax : 91 - 44 - 24468082.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The meaning of a = b in object oriented languages

2007-09-18 Thread Summercool
On Sep 17, 11:04 pm, Lloyd Linklater <[EMAIL PROTECTED]> wrote:
> SpringFlowers AutumnMoon wrote:
> > Is that the case: if a is an object, then b = a is only copying the
> > reference?
>
> That and it adds a counter.
>
> a = ["foo", "bar"]
> b = a
> b[0] = "bite me"
> p a, b
>
> a = "different"
> p a, b
>
> ***
>
> In the first print, we get
> ["something else", "bar"]
> ["something else", "bar"]
>
> showing that changing b changes a, as expected.  However, if we change
> a, b is NOT changed as seen in the second print.
>
> "different"
> ["something else", "bar"]
>
> That means that there is a counter inside that says to separate the two
> or b would have changed with a as a changed with b initially.

i think the line

a = "different"

means a is now set to a pointer to the String object with content
"different".
or that "a is now a reference to the String object."

and b is still a reference to the Array object.  so that's why a and b
print out different things.  they point to different objects.

i think:

whenever in Ruby, Python, and Java,

a is never an object.  a is always a "reference to an object"...  this
will solve a lot of puzzles when we don't understand some code
behaviors.

when a writing or a book reads "a is a Hash object; a is an Array
object; or a is an Animal object" it is just a short form to say that
"a is a reference to that object."

b = a means "whatever a is referencing to, now b is referencing it
too".

so that's why  a[1] = "foobar"  will change what b will display, but
a = "foobar" will not change what b will display.  (because a[1] =
"foobar" says "what is  a  referencing?  go there and change its
content that has the index 1"  and when b goes there to see it, it is
also changed.)


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


Re: The meaning of a = b in object oriented languages

2007-09-18 Thread Gabriel Genellina
En Tue, 18 Sep 2007 03:57:36 -0300, Summercool <[EMAIL PROTECTED]>  
escribi�:

> i think the line
>
> a = "different"
>
> means a is now set to a pointer to the String object with content
> "different".
> or that "a is now a reference to the String object."
>
> and b is still a reference to the Array object.  so that's why a and b
> print out different things.  they point to different objects.
>
> i think:
>
> whenever in Ruby, Python, and Java,
>
> a is never an object.  a is always a "reference to an object"...  this
> will solve a lot of puzzles when we don't understand some code
> behaviors.

Yes, but extrapolating that to "In OOPL, a=b just copies a reference" is  
wrong.
"Old" languages like Fortran use the "boxed" model, and "modern" languages  
tend to use the "reference" model, and since OO languages are younger...
But this rather old post by Alex Martelli explains it better  


-- 
Gabriel Genellina

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

super, apply, or __init__ when subclassing?

2007-09-18 Thread exhuma.twn
This is something that keeps confusing me. If you read examples of
code on the web, you keep on seeing these three calls (super, apply
and __init__) to reference the super-class. This looks to me as it is
somehow personal preference. But this would conflict with the "There
one way to do it" mind-set.

So, knowing that in python there is one thing to do something, these
three different calls must *do* domething different. But what exactly
*is* the difference?

 Exampel 1: -

class B(A):
   def __init__(self, *args):
  A.__init__(self, args)

 Exampel 2: -

class B(A):
   def __init__(self, *args):
  apply( A.__init__, (self,) + args)

 Exampel 3: -

class B(A):
   def __init__(self, *args):
  super(A,self).__init__(*args)

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


Re: can Python be useful as functional?

2007-09-18 Thread Duncan Booth
"Rustom Mody" <[EMAIL PROTECTED]> wrote:

> On 9/18/07, Alex Martelli <[EMAIL PROTECTED]> wrote:
>> Rustom Mody <[EMAIL PROTECTED]> wrote:
>>
>> > Can someone help? Heres the non-working code
>> >
>> > def si(l):
>> > p = l.next()
>> > yield p
>> > (x for x in si(l) if x % p != 0)
>> >
>> > There should be an yield or return somewhere but cant figure it out
>>
>> Change last line to
>>
>> for x in (x for x in si(l) if x % p != 0): yield x
> 
> 
> Thanks but why does
> 
> (yield(x) for x in si(l) if x % p != 0)
> 
> not work? I would have expected generator expression to play better
> with generators.

Why should it? It evaluates the expression which returns an object that 
just happens to be a generator and then as with any other expression 
that isn't assigned or returned it throws away the result.

> More generally, if one wants to 'splice in' a generator into the body
> of a generator, is there no standard pythonic idiom?

Yes there is, as Alex showed you the standard python idiom for a 
generator to yield all elements of an iteratable (whether it is a 
generator or any other iterable) is:

for somevar in iterable: yield somevar

There have been various proposals in the past such as 'yield from 
iterable', but there doesn't seem any compelling case to introduce a new 
confusing syntax: the existing syntax works, and adding a special syntax 
wouldn't open the door to any performance benefits since the 
implementation would have to be pretty much the same (at most you would 
save a couple of local variable accesses).

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


Re: can Python be useful as functional?

2007-09-18 Thread Bruno Desthuilliers
Lorenzo Stella a écrit :
> Hi all,
> I haven't experienced functional programming very much, but now I'm
> trying to learn Haskell and I've learned that: 1) in functional
> programming LISTS are fundmental;

Not exactly. They are used quite a lot, yes, but that's also the case in 
other paradigms. What's important in functional programming is *functions*.

> 2) any "cycle" in FP become
> recursion.

FP idioms tends to use recursion instead of iteration, yes. But that's 
only viable with implementations doing tail-recursion optimisation - 
which is not the case with CPython (not that it couldn't FWIW - it's a 
design choice, and one of the few I don't necessarily agree with).

> I also know that Python got some useful tool such as map, filter,
> reduce... 

And all there itertools versions...

> so I told: "let's try some FP-style programming with
> Python!". 

Most of the functional constructs that makes sens in Python are already 
idiomatic. And some common functional stuff are better reimplemented the 
pythonic way - as an example, while partial application is usually 
implemented with closures, and *can* indeed be implemented that way in 
Python, the class-based implementation is IMHO much better.

> I took a little example of Haskell:
> 
>  listprimes :: Integer -> [Integer]
>  listprimes n = if n == 0 then sieve [2..] else sieve [2..(n-1)]
> where
> sieve [] = []
> sieve (p:xs) = p : sieve (filter (\x -> mod x p > 0) xs)
> 
> and I tried to "translate" it in Python:
> 
>  def sieve(s):
>  if s == []:
>  return []
>  else:
>  return [s[0]] + sieve(filter((lambda x: x % s[0] > 0),
> s[1:]))
> 
>  def listprimes(n):
>  return sieve(range(2,n))
> 
> These should be almost the same: listprimes actually lists prime
> integers up to n-1. The result is: Haskell implementation works well,
> maybe it's not the better way to do it, but it does what I wanted.
> Python implementation gives me
> 
>  RuntimeError: maximum recursion depth exceeded in cmp
> 
> My question is: how can we call a language "functional" if it's major
> implementation has a limited stack? Or is my code wrong?

Strictly speaking, a language is functional if it has functions as first 
class objects. Period. According to this definition, Python is a 
functional language. Now that doesn't mean you should try to write 
Haskell in Python... IOW, your code is not "wrong", but it's certainly 
not the best way to implement such an algorithm in Python.

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


Re: Python 3K or Python 2.9?

2007-09-18 Thread Bruno Desthuilliers
Aahz a écrit :
> In article <[EMAIL PROTECTED]>,
> Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>> But what, given that I'm an AOL user still thinking it's kewl to hide 
>> behind a pseudo, what else would you expect ?
> 
> What exactly is a "pseudo", pray tell?
Sorry : a pseudonym (a nickname).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super, apply, or __init__ when subclassing?

2007-09-18 Thread Ben Finney
"exhuma.twn" <[EMAIL PROTECTED]> writes:

> This is something that keeps confusing me. If you read examples of
> code on the web, you keep on seeing these three calls (super, apply
> and __init__) to reference the super-class. This looks to me as it is
> somehow personal preference. But this would conflict with the "There
> one way to do it" mind-set.
> 
> So, knowing that in python there is one thing to do something, these
> three different calls must *do* domething different. But what exactly
> *is* the difference?
> 
>  Exampel 1: -
> 
> class B(A):
>def __init__(self, *args):
>   A.__init__(self, args)
> 
>  Exampel 2: -
> 
> class B(A):
>def __init__(self, *args):
>   apply( A.__init__, (self,) + args)
> 
>  Exampel 3: -
> 
> class B(A):
>def __init__(self, *args):
>   super(A,self).__init__(*args)

Note that your examples 1 and 3 aren't different *calls*. They are
different ways of *getting at* the same class: either name it
explicitly (as in example 1) or use 'super' to get it for you.

Also, example 3 should instead call 'super(B, self).__init__'. If
you're going to go to the bother of actually *specifying* the class
'A', it's silly to call 'super' to get at it *again*.


The broader picture: I think you're right that this is ridiculously
difficult in Python. The community elders would have us use 'super' to
get at our inherited '__init__', but that doesn't work very well
http://fuhm.org/super-harmful/> so most people use your example
1.

-- 
 \"The most merciful thing in the world... is the inability of |
  `\ the human mind to correlate all its contents."  -- Howard |
_o__)Philips Lovecraft |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: adding a static class to another class

2007-09-18 Thread Bruno Desthuilliers
Nathan Harmston a écrit :
> Hi,
> 
> I guess my description was a bit rubbish in retrospec, I dont even
> think the title of my email made senseit doesnt to me now:
> 
> class Manager(object):
>   def __init__(self):
> pass
>   def dosomething(self):
> return "RESULTS"
> 
> class Foo(object):
>   def __init__(self):
> self.a = "NEE"
> 
> What I m trying to do is end up with the following syntax:
> 
> f = Foo() # instantiates a Foo object
> g= Foo.objects.dosomething() # returns "RESULTS"
> 
> The best way I ve found of doing this is overriding new
> 
> class Foo(object):
> def __new__(cls, *args, **kw):
>   cls.objects = Manager()
> 

You're obviously overcomplexifying things here...

# the canonical pythonic way
class Foo(object):
   objects = Manager()

   def __init__(self):
 self.a = "NEE"


# the monkeypatch way
class Foo(object):
   def __init__(self):
 self.a = "NEE"

Foo.objects = Manager()



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


Re: The meaning of a = b in object oriented languages

2007-09-18 Thread Laurent Pointal
Summercool a écrit :
> 
> 
> The meaning of  a = b  in object oriented languages.
> 


Oups, reading the subject I thought it was a Xah Lee post.


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


Re: The meaning of a = b in object oriented languages

2007-09-18 Thread Roel Schroeven
Laurent Pointal schreef:
> Summercool a écrit :
>>
>> The meaning of  a = b  in object oriented languages.
>> 
> 
> 
> Oups, reading the subject I thought it was a Xah Lee post.

me too ...

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

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

Re: can Python be useful as functional?

2007-09-18 Thread Paul Rudin
Lorenzo Stella <[EMAIL PROTECTED]> writes:

> Hi all,
> I haven't experienced functional programming very much, but now I'm
> trying to learn Haskell and I've learned that: 1) in functional
> programming LISTS are fundmental; 2) any "cycle" in FP become
> recursion.
> I also know that Python got some useful tool such as map, filter,
> reduce... so I told: "let's try some FP-style programming with
> Python!". I took a little example of Haskell:
>
>  listprimes :: Integer -> [Integer]
>  listprimes n = if n == 0 then sieve [2..] else sieve [2..(n-1)]
> where
> sieve [] = []
> sieve (p:xs) = p : sieve (filter (\x -> mod x p > 0) xs)
>
> and I tried to "translate" it in Python:
>
>  def sieve(s):
>  if s == []:
>  return []
>  else:
>  return [s[0]] + sieve(filter((lambda x: x % s[0] > 0),
> s[1:]))
>
>  def listprimes(n):
>  return sieve(range(2,n))
>
> These should be almost the same: listprimes actually lists prime
> integers up to n-1. The result is: Haskell implementation works well,
> maybe it's not the better way to do it, but it does what I wanted.
> Python implementation gives me
>
>  RuntimeError: maximum recursion depth exceeded in cmp
>
> My question is: how can we call a language "functional" if it's major
> implementation has a limited stack? Or is my code wrong?

It's no tthat it's "wrong", but doing recursion in python can be
problematic because there's no tail recursion optimisation and the
size of the stack is limited (so eventually you'll run out of stack if
you recurse deep enough).

One way to capture the spirit of that Haskell program in Python is to
use things from itertools; something like this (modified from
):


import itertools
def listprimes(n):

def sieve(nums):
seq = nums
while True:
prime = seq.next()
seq = itertools.ifilter(prime.__rmod__, seq)
yield prime

if n == 0:
return sieve(itertools.count(2))
else:
return sieve(itertools.islice(itertools.count(2), n-1))

>>> list(listprimes(100))
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 
73, 79, 83, 89, 97]

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


Re: can Python be useful as functional?

2007-09-18 Thread Kay Schluehr
On 18 Sep., 10:13, Bruno Desthuilliers  wrote:
> Lorenzo Stella a écrit :
>
> > Hi all,
> > I haven't experienced functional programming very much, but now I'm
> > trying to learn Haskell and I've learned that: 1) in functional
> > programming LISTS are fundmental;
>
> Not exactly. They are used quite a lot, yes, but that's also the case in
> other paradigms. What's important in functional programming is *functions*.

Functional lists are not quite the same. They are actually recursive
datastructes. In Python you would model them as nested tuples:

t = (a, (b, (c, ...(d, None)

These are essentially pairs build from the bottom up using a list
constructor and they have little in common with those mutable list
objects ( arrays, vectors ) being used in Python. You can easily
extend them into n-ary trees and implement mutations on them as forks
where the original strucure is almost preserved. This leads to all
kinds of "functional data structures".

In order to access an element you already need a recursive function
defintion ( unless you just want to examine the head or the tail
only ) and this makes functional programming and "consed" lists a
perfect match.

[...]

> Strictly speaking, a language is functional if it has functions as first
> class objects. Period.

No, not period and not strictly speaking. A language is functional
when its semantics is based on lambda calculus where everything is a
function or a variable bound to a function which can be substituted by
a function. Each functional language, to be usefull, must be augmented
with programming language constructs used from other paradigms or
support unsafe operations to enable proper side effects. This is not a
humpty-dumpty issue where everyone can name his language a functional
programming language just because one can pass functions as first
class citizens around and he says so. Otherwise those languages can
support a few functional programming language idioms such as map,
reduce and filter or comprehensions as in Pythons case.

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

raw string

2007-09-18 Thread Konstantinos Pachopoulos
Hi,
i am trying to execute the following query on a DB:
qe.execQuery(r"SELECT * FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY 
'"' LINES TERMINATED BY '\n' FROM Commiter")

However, whether i put the r in the front or not, i always get an error 
about the "\n".
What's wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super, apply, or __init__ when subclassing?

2007-09-18 Thread Duncan Booth
"exhuma.twn" <[EMAIL PROTECTED]> wrote:

> So, knowing that in python there is one thing to do something, these
> three different calls must *do* domething different. But what exactly
> *is* the difference?
> 
>  Exampel 1: -
> 
> class B(A):
>def __init__(self, *args):
>   A.__init__(self, args)
> 
>  Exampel 2: -
> 
> class B(A):
>def __init__(self, *args):
>   apply( A.__init__, (self,) + args)
> 
>  Exampel 3: -
> 
> class B(A):
>def __init__(self, *args):
>   super(A,self).__init__(*args)

Yes, they are all different.

The first one calls B's immediate base class but packs all of the 
arguments together into a single tuple. Probably not what you meant.

The second one passes B's positional arguments to its immediate base 
class without messing them up but uses a deprecated function to do it. 
You should use "A.__init__(self, *args)" instead unless you are 
concerned about multiple inheritance.

The third one skips over the __init__ method in the immediate base class 
and calls the __init__ method in whatever class follows A in the MRO 
instead. Probably not what you meant either.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw string

2007-09-18 Thread James Stroud
Konstantinos Pachopoulos wrote:
> Hi,
> i am trying to execute the following query on a DB:
> qe.execQuery(r"SELECT * FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY 
> '"' LINES TERMINATED BY '\n' FROM Commiter")
> 
> However, whether i put the r in the front or not, i always get an error 
> about the "\n".
> What's wrong?

Try Triple-quoting the whole thing (you have an un-escaped " in your 
present version):

   r"""SELECT[yadda][yadda]Commtter

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


Re: UnicodeEncodeError in Windows

2007-09-18 Thread geoff_ness
On Sep 18, 7:36 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 17 Sep 2007 07:38:16 -0300, geoff_ness <[EMAIL PROTECTED]>
> escribi?:
>
>
>
> > def buildString(warrior):
> > """Build a string from a warrior's stats
>
> > Returns string for output to warStat."""
> > return "!tr!!td!!id!"+str(warrior.ID)+"!/id!!/td!"+\
> > "!td!"+str(warrior.damage)+"!/td!!td!"+str(warrior.kills)+\
> > "!/td!!td!"+str(warrior.survived)+"!/td!!/tr!"
>
> > This code runs fine on my linux machine, but when I sent the code to a
> > friend with python running on windows, he got the following error:
>
> > Traceback (most recent call last):
> >  File "C:\Documents and Settings\Administrator\Desktop
> > \reparser_014(2)\iotp_alt2.py", line 169, in buildString
> >"!/td!!td!"+str(warrior.survived)+"!/td!!/tr!"
> > UnicodeEncodeError: 'ascii' codec can't encode character u'\ufeff' in
> > position 0: ordinal not in range(128)
>
> > As I understand it the error is related to the ascii codec being
> > unable to cope with the unicode string u'\ufeff'.
> > The issue I have is that this error doesn't show up for me - ascii is
> > the default encoding for me also. Any thoughts or assistance would be
> > welcomed.
>
> Some of those `warrior` attributes is an Unicode object that contains
> characters outside ASCII. str(x) tries to convert to string, using the
> default encoding, and fails. This happens on Windows and Linux too,
> depending on the data.
> I've seen that you use codecs.open: you should write Unicode objects to
> the file, not strings, and that would be fine.
> Look for some recent posts about this same problem.
>
> --
> Gabriel Genellina

Thanks Gabriel, I hadn't thought about the str() function that way - I
had initially used it to coerce the attributes which are type int to
type str so that I could write them to the output file. I've rewritten
the buildString() function now so that the unicode objects don't get
fed to str(), and apparently windows copes ok with that. I'm still
puzzled as to why python at my end had no problem with it...

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


Re: How can I know how much to read from a subprocess

2007-09-18 Thread A.T.Hofkamp
On 2007-09-17, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> It seems that another solution is gobject.io_add_watch, but I don't
> see how it tells me how much I can read from the file - if I don't
> know that, I won't know the argument to give to the read() method in
> order to get all the data:
>
> http://www.pygtk.org/docs/pygobject/gobject-functions.html#function-gobject--io-add-watch
>

Usually, gobject only tells you that data is there (that is all it knows).
Therefore a read(1) should be safe.
If that is too slow, consider os.read() which reads all data available (afaik,
never tried it myself).

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


Re: Looking for web software in Python.

2007-09-18 Thread Diez B. Roggisch
Kevin Ar18 wrote:

> 
> Are any of the following pieces of web software available in Python (under
> a non-copyleft license like BSD or MIT or Python license)?
> 
> 
> Mailing list - with web accessable archive and list maintenance.
> Source control
> Wiki System

For the last two, look at TRAC. But I'm not sure about the license - check
that out for yourself.

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


Re: Looking for web software in Python.

2007-09-18 Thread js
http://wiki.python.org/moin/WebApplications?highlight=%28%28PythonWikiEngines%29%29

Hope this  helps

On 9/18/07, Kevin Ar18 <[EMAIL PROTECTED]> wrote:
>
> Are any of the following pieces of web software available in Python (under a 
> non-copyleft license like BSD or MIT or Python license)?
>
>
> Mailing list - with web accessable archive and list maintenance.
> Source control
> Wiki System
>
> Again, only non-copyleft licenses like MIT, BSD, or public domain.
>
>
> Or would I be better off with PHP?
>
>
>
> BTW, does anyone know where that project is that was working on a forum made 
> with Python?
> _
> More photos; more messages; more whatever – Get MORE with Windows Live™ 
> Hotmail(r). NOW with 5GB storage.
> http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_5G_0907
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super() doesn't get superclass

2007-09-18 Thread Carl Banks
On Tue, 18 Sep 2007 15:38:46 +1000, Ben Finney wrote:
> Evan Klitzke <[EMAIL PROTECTED]> writes:
> 
>> If you're using multiple inheritance, and you're _not_ using super
>> everywhere, then your code is broken anyway.
> 
> This seems to support the notion that 'super' is unusable. If I inherit
> from code that isn't under my control, and then use super(), my code is
> broken.
> 
> Therefore, to avoid writing broken code, I must either never inherit
> from code not under my control, or I must never use super(). Since the
> former is practically unavoidable, I must choose the latter.
> 
> Which, naturally, compounds the problem, since when someone else uses
> *my* code, they in turn must conclude that they can't use super().

I'm sorry, but you can't inherit from someone else's classes and not 
worry about what they're doing.  Whether they use super or not is only 
one possible concern.  It's not like the super destroyed the magical 
utopia where you could derive from other people's classes without worry.

In any case, it's just as problematic if you don't use super and your 
base classes do.  By your logic, your code is "broken" no matter what you 
do, and so the only "conclusion" you can come to is never to derive from 
classes that aren't under your control.

(Which, frankly, isn't all that bad a conclusion.  In 8 years of Python 
programming, I've inherited from exactly one class that wasn't under my 
control: Thread.  It's not "practically impossible" to avoid, at least 
not for me.)


>> Use super correctly in your own code, and you don't need to worry about
>> other people using it incorrectly.
> 
> As the article points out, when using super(),
> 
> you must remember that super does not call your superclass. You must
> be prepared to call any other class's method in the hierarchy and be
> prepared to be called from any other class's method.
> 
> So, the programmer using super() very much *does* need to worry about
> other people using it correctly.

Yes.  Welcome to programming.


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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-18 Thread Colin J. Williams
BJörn Lindqvist wrote:
> On 9/12/07, Dave Hansen <[EMAIL PROTECTED]> wrote:
>> The name "self" is just a convention.  You can give it any name you
>> wish.  Using "s" is common.
> 
> Not it's not common. And the name "self" is a convention codified in
> PEP8 which you shouldn't violate.
> 
> And I agree with the OP that the convention is really annoying.
> 
>   self.rect.width = self.foo(self.rect.x + self.rect.y) * self.boo()
> 
> is much less concise than
> 
>   s.rect.width = s.foo(s.rect.x + s.rect.y) * s.boo()
> 
Yes, but the OP went a step further, he suggested:

.rect.width = .foo(.rect.x + .rect.y) * .boo()

Among the many responses, I didn't spot anyone who dealt with this issue.

Does this preceding "." create parsing problems?

Colin W.

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


string replace shortcut

2007-09-18 Thread vedrandekovic
Hello,

I am trying to replace some string with list objects:

>>> my_text1="function1 function2"
>>> from my_module_with_functions_1 import *
>>> from my_module_with_functions_2 import *

# functions in module " my_module_with_functions_1 ":
 
my_func1  it's value "function1"
 
my_func2  it's value "function2"

# functions in module " my_module_with_functions_2 ":
 
my_func100  it's value "bla bla 1"
 
my_func200  it's value "bla bla 2"

now, we need find and replace functions from module "
my_module_with_functions_1 "  and
replace them with  functions from module " my_module_with_functions_2
"

with: my_text1.replace(items1,items2)

Result must be:

>>> print my_text1.replace(items1,items2)
bla bla 1 bla bla 2


Regards,
Vedran

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


Re: Looking for web software in Python.

2007-09-18 Thread Duncan Booth
Kevin Ar18 <[EMAIL PROTECTED]> wrote:

> 
> Are any of the following pieces of web software available in Python
> (under a non-copyleft license like BSD or MIT or Python license)? 
> 
> 
> Mailing list - with web accessable archive and list maintenance.
> Source control
> Wiki System
> 
> Again, only non-copyleft licenses like MIT, BSD, or public domain.
> 
> 
I'm curious why copyleft matters to you. Were you planning on taking the 
mailing list software and redistributing a modified version?

There is nothing in the GPL which prevents you taking something like 
Mailman, modifying it as much as you like and using the improved version. 
There is no requirement on you to release your changes provided you don't 
actually distribute the code to third parties.

What do you mean by 'source control' available in Python? Subversion isn't 
written in Python but you can certainly write Python code which interacts 
with it either client or server-side. The Subversion license is Apache 
style so that would suite you although again I doubt whether it matters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting xml from html

2007-09-18 Thread Paul Boddie
On 17 Sep, 23:14, [EMAIL PROTECTED] wrote:
>
> I have lxml installed and I appear to also have libxml2dom installed.
> I know lxml has decent docs, but I don't see much for yours. Is this
> the only place to go:http://www.boddie.org.uk/python/libxml2dom.html
> ?

Unfortunately yes, with regard to online documentation, although the
distribution contains API documentation, and the package has
docstrings for most of the public classes, functions and methods. And
the API is a lot like the PyXML and minidom APIs, too.

Paul

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


Using python to create windows apps that everyone can use?

2007-09-18 Thread Thomas Harding




Hi guys, sorry to post another topic on this, as I am aware
that it has already been posted a few times, but not with specifically what I
am looking for. I want an app that makes a gui interface for python (similar to
Microsoft visual studio or qt designer, not a code based one) and/or an app
that can make this into a .exe that can be opened by any person on any computer
without python installed.

 

I would just love to do this in python and not C++, its so
simple and logical.

 

So basically, the easiest way to do that, please!

 

Thanks,

 

Tom Harding






Free Online Photosharing - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!


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

Re: can Python be useful as functional?

2007-09-18 Thread Neil Cerutti
On 2007-09-18, Kay Schluehr <[EMAIL PROTECTED]> wrote:
> On 18 Sep., 10:13, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
>> Lorenzo Stella a écrit :
>>
>> > Hi all,
>> > I haven't experienced functional programming very much, but now I'm
>> > trying to learn Haskell and I've learned that: 1) in functional
>> > programming LISTS are fundmental;
>>
>> Not exactly. They are used quite a lot, yes, but that's also
>> the case in other paradigms. What's important in functional
>> programming is *functions*.
>
> Functional lists are not quite the same. They are actually
> recursive datastructes. In Python you would model them as
> nested tuples:
>
> t = (a, (b, (c, ...(d, None)

Tuples won't work for cyclic data, though.

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


Wait For Application Start

2007-09-18 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm kick starting my application using the inittab to ensure its re-spawned
if it dies. However I need to ensure several other applications and service
are up and running before my application is started, things such as dbus and
a couple of other hardware stacks.

 

A concept I've been advised to use is that I should make the application
wait for the existence of a file before it starts, then create that file on
the FS using the rc.local file which is called at the end of all other start
items. Only once that file exists will my application commence with its job.

 

This seems like a very logical method, but I'm not sure how to implement it
into my python code? Is there a simple way to make it wait for that file?
Without the need to build my own conditional loop?

 

Can anyone perhaps help with a simple code example?

 

Thanks guys,

 

Rob

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

Re: raw string

2007-09-18 Thread [EMAIL PROTECTED]
On Sep 18, 5:20 am, Konstantinos Pachopoulos <[EMAIL PROTECTED]>
wrote:
> Hi,
> i am trying to execute the following query on a DB:
> qe.execQuery(r"SELECT * FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY
> '"' LINES TERMINATED BY '\n' FROM Commiter")
>
> However, whether i put the r in the front or not, i always get an error
> about the "\n".
> What's wrong?

Try

r"SELECT * FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES
TERMINATED BY '\n' FROM Commiter"

It works for me.


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


Re: super, apply, or __init__ when subclassing?

2007-09-18 Thread Bruno Desthuilliers
exhuma.twn a écrit :
> This is something that keeps confusing me. If you read examples of
> code on the web, you keep on seeing these three calls (super, apply
> and __init__) to reference the super-class. This looks to me as it is
> somehow personal preference. But this would conflict with the "There
> one way to do it" mind-set.

apply is deprecated. Chances are that code using it is somewhat old. 
super came with the new object model in Python 2.2.1 (IIRC), and is only 
useful for some corner cases involving multiple inheritence . Directly 
calling the superclass's method (__init__ or whatever) is the canonical 
way in the most common cases.

And BTW, the sentence is "there *should* be one - and *preferably* only 
one - *obvious* way to do it" (emphasis is mine). In this case, there's 
_at least_ one way do to do it, and only one (direct call) is really 
obvious IMHO !-)

> So, knowing that in python there is one thing to do something, these
> three different calls must *do* domething different.

Indeed. But mostly because you managed to get 2 examples wrong !-)

> But what exactly
> *is* the difference?
> 
>  Exampel 1: -
> 
> class B(A):
>def __init__(self, *args):
>   A.__init__(self, args)

You want:

class B(A):
def __init__(self, *args):
   A.__init__(self, *args)


>  Exampel 2: -
> 
> class B(A):
>def __init__(self, *args):
>   apply( A.__init__, (self,) + args)

is the same as the previous, using the deprecated apply function.

>  Exampel 3: -
> 
> class B(A):
>def __init__(self, *args):
>   super(A,self).__init__(*args)
> 

You want:

class B(A):
def __init__(self, *args):
   super(B,self).__init__(*args)

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


Re: can Python be useful as functional?

2007-09-18 Thread Bruno Desthuilliers
Kay Schluehr a écrit :
> On 18 Sep., 10:13, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
>> Lorenzo Stella a écrit :
>>
>>> Hi all,
>>> I haven't experienced functional programming very much, but now I'm
>>> trying to learn Haskell and I've learned that: 1) in functional
>>> programming LISTS are fundmental;
>> Not exactly. They are used quite a lot, yes, but that's also the case in
>> other paradigms. What's important in functional programming is *functions*.
> 
> Functional lists are not quite the same. They are actually recursive
> datastructes. 

Linked lists, most of the time, yes.

(snip)
> In order to access an element you already need a recursive function
> defintion ( unless you just want to examine the head or the tail
> only ) and this makes functional programming and "consed" lists a
> perfect match.

Indeed. And that's also why some FP idioms don't translate directly in 
Python.

> [...]
> 
>> Strictly speaking, a language is functional if it has functions as first
>> class objects. Period.
> 
> No, not period and not strictly speaking.

Ok, even on c.l.functional - where the above definition comes from BTW 
-, nobody really agree on the "correct" definition of functional !-)

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


Memory Problem

2007-09-18 Thread Christoph Scheit
Hi,

I have a short script/prog in order to read out binary files from a numerical 
simulation. This binary files still need some post-processing, which is
summing up results from different cpu's, filtering out non-valid entrys
and bringing the data in some special order.

Reading the binary data in using the struct-module works fine - I read
one chunk of data into a tuple, this tupel I append to a list.
At the end of reading, I return the list.

Then the data is added to a table, which I use for the actual Post-Processing.
The table is actually a Class with several "Columns", each column internally
being represented by array.
Now adding all the data from the simulation results to the table makes the
memory usage exploding. So I would like to know, where exactly the memory
is vasted.

Here the code to add the data of one file (I have to add the data of various 
files to the same table in total)

# create reader
breader = BDBReader("", "", "#")
 
# read data
bData = breader.readDB(dbFileList[0])

# create table
dTab = DBTable(breader.headings, breader.converters, [1,2])
addRows(bData, dTab)

Before I add a new entry to the table, I check if there is already an entry 
like this. To do so, I store keys for all the entries with row-number in a
dictionary. What about the memory consumption of the dictionary?

Here the code for adding a new row to the table:

# check if data already exists
if (self.keyDict.has_key(key)):
rowIdx = self.keyDict[key]
for i in self.mutableCols:
self.cols[i][rowIdx] += rowData[i]
return

 # key is still available - insert row to table
 self.keyDict[key] = self.nRows

 # insert data to the columns
 for i in range(0, self.nCols):
 self.cols[i].add(rowData[i])

 # add row i and increment number of rows
 self.rows.append(DBRow(self, self.nRows))
 self.nRows += 1

Maybe somebody can help me. If you need, I can give more implementation
details.

Thanks in advance,

Christoph
-- 


M.Sc. Christoph Scheit
Institute of Fluid Mechanics
FAU Erlangen-Nuremberg
Cauerstrasse 4
D-91058 Erlangen
Phone: +49 9131 85 29508

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


Re: Wait For Application Start

2007-09-18 Thread Francesco Guerrieri
On 9/18/07, Robert Rawlins - Think Blue
<[EMAIL PROTECTED]> wrote:
> This seems like a very logical method, but I'm not sure how to implement it
> into my python code? Is there a simple way to make it wait for that file?
> Without the need to build my own conditional loop?

I'm not sure why how you could avoid a conditional loop. Could
something like this work?

import os.path
import time

while True:
if os.path.exists(YOUR_FILE):
break
time.sleep(30)

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


Re: Memory Problem

2007-09-18 Thread Marc 'BlackJack' Rintsch
On Tue, 18 Sep 2007 14:06:22 +0200, Christoph Scheit wrote:

> Then the data is added to a table, which I use for the actual Post-Processing.
> The table is actually a Class with several "Columns", each column internally
> being represented by array.

Array or list?

> # create reader
> breader = BDBReader("", "", "#")
>  
> # read data
> bData = breader.readDB(dbFileList[0])
> 
> # create table
> dTab = DBTable(breader.headings, breader.converters, [1,2])
> addRows(bData, dTab)
> 
> Before I add a new entry to the table, I check if there is already an entry 
> like this. To do so, I store keys for all the entries with row-number in a
> dictionary. What about the memory consumption of the dictionary?

The more items you put into the dictionary the more memory it uses.  ;-)

> Here the code for adding a new row to the table:
> 
> # check if data already exists
> if (self.keyDict.has_key(key)):
> rowIdx = self.keyDict[key]
> for i in self.mutableCols:
> self.cols[i][rowIdx] += rowData[i]
> return
> 
>  # key is still available - insert row to table
>  self.keyDict[key] = self.nRows
> 
>  # insert data to the columns
>  for i in range(0, self.nCols):
>  self.cols[i].add(rowData[i])
> 
>  # add row i and increment number of rows
>  self.rows.append(DBRow(self, self.nRows))
>  self.nRows += 1
> 
> Maybe somebody can help me. If you need, I can give more implementation
> details.

IMHO That's not enough code and/or description of the data structure(s). 
And you also left out some information like the number of rows/columns and
the size of the data.

Have you already thought about using a database?

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


Re: string replace shortcut

2007-09-18 Thread Gabriel Genellina
En Tue, 18 Sep 2007 08:44:32 -0300, <[EMAIL PROTECTED]>  
escribi�:

> Hello,
>
> I am trying to replace some string with list objects:
>
 my_text1="function1 function2"
 from my_module_with_functions_1 import *
 from my_module_with_functions_2 import *
>
> # functions in module " my_module_with_functions_1 ":
> my_func1  it's value "function1"
> my_func2  it's value "function2"
>
> # functions in module " my_module_with_functions_2 ":
> my_func100  it's value "bla bla 1"
> my_func200  it's value "bla bla 2"
>
> now, we need find and replace functions from module "
> my_module_with_functions_1 "  and
> replace them with  functions from module " my_module_with_functions_2
> "
>
> with: my_text1.replace(items1,items2)
>
> Result must be:
>
 print my_text1.replace(items1,items2)
> bla bla 1 bla bla 2

I'm unsure what you want. You keep saying "functions" but they are  
apparently strings.
If your problem is how to replace many strings, just do it one at a time  
(asuuming they're unique so the order is not important).

def multi_replace(text, list1, list2):
 for rep1, rep2 in itertools.izip(list1, list2):
 text = text.replace(rep1, rep2)
 return text

py> multi_replace("a sentence with a few words", ["sentence","words"],  
["man","d
ollars"])
'a man with a few dollars'

Now, your problem may be building both lists. They must be syncronized,  
that is, the first element on one list must correspond to the first  
element on the other, and so on. The import statement doesn't guarantee  
any ordering so I think the best way would be to define an __all__  
attribute on both modules, and import that:

 from my_module_with_functions_1 import __all__ as list_of_names_1
 from my_module_with_functions_2 import __all__ as list_of_names_2

new_text = multi_replace(my_text1, list_of_names_1, list_of_names_2)

-- 
Gabriel Genellina

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

Re: super, apply, or __init__ when subclassing?

2007-09-18 Thread Gabriel Genellina
En Tue, 18 Sep 2007 04:33:11 -0300, exhuma.twn <[EMAIL PROTECTED]> escribi�:

> This is something that keeps confusing me. If you read examples of
> code on the web, you keep on seeing these three calls (super, apply
> and __init__) to reference the super-class. This looks to me as it is
> somehow personal preference. But this would conflict with the "There
> one way to do it" mind-set.
>
> So, knowing that in python there is one thing to do something, these
> three different calls must *do* domething different. But what exactly
> *is* the difference?

There are a few typos in your examples. If you write them this way:

>  Exampel 1: -
>
> class B(A):
>def __init__(self, *args):
>   A.__init__(self, *args)
>
>  Exampel 2: -
>
> class B(A):
>def __init__(self, *args):
>   apply( A.__init__, (self,) + args)
>
>  Exampel 3: -
>
> class B(A):
>def __init__(self, *args):
>   super(B,self).__init__(*args)

then 2 is exactly the same as 1 but using a deprecated function. And 3 is  
the same as 1 only when there is single inheritance involved (and you are  
using new-style classes). But see the thread "super() doesn't get  
superclass"

-- 
Gabriel Genellina

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

Re: super, apply, or __init__ when subclassing?

2007-09-18 Thread exhuma.twn
On Sep 18, 2:45 pm, Bruno Desthuilliers  wrote:
> exhuma.twn a écrit :
>
> > This is something that keeps confusing me. If you read examples of
> > code on the web, you keep on seeing these three calls (super, apply
> > and __init__) to reference the super-class. This looks to me as it is
> > somehow personal preference. But this would conflict with the "There
> > one way to do it" mind-set.
>
> apply is deprecated. Chances are that code using it is somewhat old.
> super came with the new object model in Python 2.2.1 (IIRC), and is only
> useful for some corner cases involving multiple inheritence . Directly
> calling the superclass's method (__init__ or whatever) is the canonical
> way in the most common cases.
>
> And BTW, the sentence is "there *should* be one - and *preferably* only
> one - *obvious* way to do it" (emphasis is mine). In this case, there's
> _at least_ one way do to do it, and only one (direct call) is really
> obvious IMHO !-)
>
> > So, knowing that in python there is one thing to do something, these
> > three different calls must *do* domething different.
>
> Indeed. But mostly because you managed to get 2 examples wrong !-)
>
> > But what exactly
> > *is* the difference?
>
> >  Exampel 1: -
>
> > class B(A):
> >def __init__(self, *args):
> >   A.__init__(self, args)
>
> You want:
>
> class B(A):
> def __init__(self, *args):
>A.__init__(self, *args)

Ah.. this was a typo in my original post. Oops ;)

>
> >  Exampel 2: -
>
> > class B(A):
> >def __init__(self, *args):
> >   apply( A.__init__, (self,) + args)
>
> is the same as the previous, using the deprecated apply function.
>
> >  Exampel 3: -
>
> > class B(A):
> >def __init__(self, *args):
> >   super(A,self).__init__(*args)
>
> You want:
>
> class B(A):
> def __init__(self, *args):
>super(B,self).__init__(*args)

Hmmm... and suddenly it all makes sense! Great!

Thanks all for clarifying this to a Java-Convert ;)

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

Re: Looking for web software in Python.

2007-09-18 Thread [EMAIL PROTECTED]
On Sep 17, 9:53 pm, Kevin Ar18 <[EMAIL PROTECTED]> wrote:
> Are any of the following pieces of web software available in Python (under a 
> non-copyleft license like BSD or MIT or Python license)?
>
> Mailing list - with web accessable archive and list maintenance.
> Source control
> Wiki System
>
> Again, only non-copyleft licenses like MIT, BSD, or public domain.
>
> Or would I be better off with PHP?
>
> BTW, does anyone know where that project is that was working on a forum made 
> with Python?
> _
> More photos; more messages; more whatever - Get MORE with Windows Live™ 
> Hotmail®. NOW with 5GB 
> storage.http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_m...

Mailman and Trac cover your needs.


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


Re: Coming from Perl

2007-09-18 Thread Steve Holden
Amer Neely wrote:
> Bryan Olson wrote:
>> Amer Neely wrote:
>>> I don't have shell access but I can run 'which python' from a Perl 
>>> script, and I will try the different shebang line you suggested.
>> And after trying it, Amer Neely reported:
>>
>>> I tried `which python` and `whereis python` and got 0 back as a 
>>> result. So it seems Python is not installed at all.
>> Probably right, but just to be thorough...  Since you do not
>> have shell access, I'm guessing you are running these within
>> a Perl cgi script, and getting the results via a browser. Is
>> that right?
> 
> Yes.
>> Can you backtick other commands? What do you get if you run
>> `which perl` the same way? How about `whoami`, `whereis sh`,
>> and `which nosuchthingas5748614`? Can you list /, /bin and
>> /usr/bin?
> 
> I just looked at my code and tried something else:
> @SysCmd="which python";
> system(@SysCmd);
> 
> and it came back
> /usr/local/bin/python
> 
>> How did you learn that this system could run your Perl
>> scripts? Can that source give us anything to go on here?
>> If Python is not installed, do you have some avenue for
>> requesting it?
>>
>> We're down to long shots. Still, hosts that support Perl
>> but will not support Python are getting to be the rare.
>>
>>
> 
> I've asked my host to put in a request for it.
> 
> So it seems python IS installed, but not where I thought it was.
> 
> I just tried my script with the new path, but still got a 500 server 
> error. Can I trap errors to a file locally?
> 
You could try putting an ErrorLog directive in your local .htaccess file.

   http://httpd.apache.org/docs/1.3/logs.html#errorlog

regards
  Steve

-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Re: adodb with mysql - connection string syntax for filepath

2007-09-18 Thread Steve Holden
Mridula Ramesh wrote:
> Hi. Firstly, thank you both very much for the response!
> 
> Cliff, I did some more reading up about it after  you corrected me re 
> MySQL not being a _language_  but another means of storing data (would 
> you believe NONE of the connection tutorials actually said that?!) 
> Anyway, now I have MySQL on my machine, and it's installed - if I say 
> "import MySQLdb" in python prompt, it does that, but I can't see any exe 
> in the program's folder itself: does that mean tables can only be 
> created by code? *puzzled*
> 
> Steve, thank you too, I looked up the link you had given, but I do not 
> yet know which part of that site may help me... And I am now going to 
> struggle with Dive Into Python before attempting much else!
> 
> This is a nice, helpful mailing group!
> 
We try, though not everyone appreciates us :-)

You may find

   http://www.connectionstrings.com/

more helpful.

regard
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Re: Memory Problem

2007-09-18 Thread Christoph Scheit
On Tuesday 18 September 2007 15:10, Marc 'BlackJack' Rintsch wrote:
> On Tue, 18 Sep 2007 14:06:22 +0200, Christoph Scheit wrote:
> > Then the data is added to a table, which I use for the actual
> > Post-Processing. The table is actually a Class with several "Columns",
> > each column internally being represented by array.
>
> Array or list?

array

More details:
class DBTable:
# the class DBTable has a list, each list entry referencing a DBColu  
bject
self.cols  = []

self.dict = {, -1} #the dictionary is used to look up if an entry
# already exists

class DBColumn:
# has a name (string and a datatype (int, float, e.g.) as attribute plus
self.data = array('f')  # an array of type float

I have to deal with several millions of data, actually I'm trying an example 
with
360 grid points and 1 time steps, i.e. 3 600 000 entries (and each row 
consits of 4 int and one float)

Of course, the more keys the bigger is the dictionary, but is there a way to 
evaluate the actual size of the dictionary?

Greets and Thanks,

Chris
>
> > # create reader
> > breader = BDBReader("", "", "#")
> >
> > # read data
> > bData = breader.readDB(dbFileList[0])
> >
> > # create table
> > dTab = DBTable(breader.headings, breader.converters, [1,2])
> > addRows(bData, dTab)
> >
> > Before I add a new entry to the table, I check if there is already an
> > entry like this. To do so, I store keys for all the entries with
> > row-number in a dictionary. What about the memory consumption of the
> > dictionary?
>
> The more items you put into the dictionary the more memory it uses.  ;-)
>
> > Here the code for adding a new row to the table:
> >
> > # check if data already exists
> > if (self.keyDict.has_key(key)):
> > rowIdx = self.keyDict[key]
> > for i in self.mutableCols:
> > self.cols[i][rowIdx] += rowData[i]
> > return
> >
> >  # key is still available - insert row to table
> >  self.keyDict[key] = self.nRows
> >
> >  # insert data to the columns
> >  for i in range(0, self.nCols):
> >  self.cols[i].add(rowData[i])
> >
> >  # add row i and increment number of rows
> >  self.rows.append(DBRow(self, self.nRows))
> >  self.nRows += 1
> >
> > Maybe somebody can help me. If you need, I can give more implementation
> > details.
>
> IMHO That's not enough code and/or description of the data structure(s).
> And you also left out some information like the number of rows/columns and
> the size of the data.
>
> Have you already thought about using a database?
>
> Ciao,
>   Marc 'BlackJack' Rintsch

-- 


M.Sc. Christoph Scheit
Institute of Fluid Mechanics
FAU Erlangen-Nuremberg
Cauerstrasse 4
D-91058 Erlangen
Phone: +49 9131 85 29508

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


Re: Saving parameters between Python applications?

2007-09-18 Thread Stodge
os.path.expanduser isn't an option; I need each console/window to
maintain different values which I wouldn't get from saving to a user's
home directory. Unless I used a different file for each console/window
but that just gets me into the same situation I'm already in. I think
the only option is to set environment variables using another script.
I'm really surprised and disapponited by this.

One option I thought of but haven't investigated, is the ability to
get the parent (i.e. console's) process id and use that to create a
file somewhere. Not sure if this is even possible.



On Sep 17, 4:29 pm, [EMAIL PROTECTED] wrote:
> On Sep 17, 6:39 am, Laurent Pointal
>
> > May use simple file in known place:
> > $HOME/.myprefs
> > $HOME/.conf/myprefs
>
> > Or host specific configuration API:
> > WindowsRegistry HKEY_CURRENT_USER\Software\MySociety\MyApp\myprefs
>
> > See os.getenv, and _winreg Windows specific module.
> > See also standard ConfigParser module
>
> Also, os.path offers expanduser(). The following is reasonably
> portable:
>
> import os
>
> user_home_dir = os.path.expanduser("~")
>
> --
> --Bryan


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


Re: super() doesn't get superclass

2007-09-18 Thread Bruno Desthuilliers
Ben Finney a écrit :
> Evan Klitzke <[EMAIL PROTECTED]> writes:
> 
>> On Tue, 2007-09-18 at 14:15 +1000, Ben Finney wrote:
>>> Why does the documentation of 'super' say that it returns the
>>> superclass when *that's not true*? It doesn't return the
>>> superclass, it returns the next class in the MRO, whether that's a
>>> superclass or not.
>> The next class in the MRO _is_ a superclass. Maybe not the way
>> you've defined it in your own code, but certainly of the new class
>> you created with MI.
> 
> If I define a class hierarchy as follows::
> 
> class A(object): pass
> class B(object): pass
> class C(A): pass
> class D(B): pass
> 
> is it true to say that "D is a superclass of A"? 

Obviously not.

> How about this:
> 
> class E(C, D): pass
> 
> In this instance, the MRO now has D following A; but the superclass of
> 'A' is still 'object'.

Yes. And ?

> 
> You seem to be saying that now suddenly D *is* a superclass of
> A. 

I don't see such an assertion in Evan's answer. Chapter and verse ???

> That's certainly not what users will think of when they think
> "superclass" though.

If a class X is in the MRO of call Y, then X is a superclass of Y. I 
agree that the documentation for super is somewhat misleading (and 
obviously wrong), but it still *give access to* (at least one of) the 
superclass(es).

>>> Actually, even that's not true. The error message "AttributeError:
>>> 'super' object has no attribute 'bazfunc'" makes it clear that
>>> 'super' actually returns not the superclass, but a 'super' object,
>>> whatever that's supposed to be.

The 'super' object is a wrapper around a class and an object. It 
delegates attribute lookups to appropriate superclass.

>>> After reading the rest of the article, I'm amazed that 'super' as
>>> currently implemented is in Python at all.

If you have a better solution for handling multiple inheritence, please 
share with us.

FWIW, after all the articles I've read explaining why Python is badly 
designed, badly implemented, and totally flawed, I do wonder why this 
language exists at all !-)

> I don't want to break the inheritance chain. I want the superclass,

A soon as you have either multiple inheritence and/or an inheritence 
tree with depth > 1, there's no such thing as "the" superclass. wrt/ 
your exemple, object, A, B, C and D are *all* superclasses of E.

> not the "next class in the MRO".

The next class in the MRO is (usually and AFAICT) the most direct 
superclass.

> Orthogonally to that, I think it's madness to write a function for
> "return the next class in the MRO for 'type'" and document it as
> "return the superclass of 'type'".

I wouldn't use such an extreme word as 'madness', but I totally agree 
that this should be corrected. Care to submit a doc patch ?

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

Simple elementtree question

2007-09-18 Thread Peters Bart (GEN)
I have the exact same problem, rdf and elementtree
-- 
http://mail.python.org/mailman/listinfo/python-list

using xlrd

2007-09-18 Thread hassen62
Hi,
I have installed Xlrd 0.6.1 Win 32. I have a file xls say "file.xls" located as 
follows:c:/file.xls. This file is composed with two columns of 5 lines. These 
columns are headed with "Col1" and "Col2", also the 5 rows are named with 
"Row1",...,"Row2".
I have a silly question: What I can write to read this file from The Shell? 
sorry for this basic question but I can't find a document in the net that helps 
me for using xlrd.
Thank you very much,
Hassen.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Memory Problem

2007-09-18 Thread Gabriel Genellina
En Tue, 18 Sep 2007 10:58:42 -0300, Christoph Scheit  
<[EMAIL PROTECTED]> escribi�:

> I have to deal with several millions of data, actually I'm trying an  
> example
> with
> 360 grid points and 1 time steps, i.e. 3 600 000 entries (and each  
> row
> consits of 4 int and one float)
> Of course, the more keys the bigger is the dictionary, but is there a  
> way to
> evaluate the actual size of the dictionary?

Yes, but probably you should not worry about it, just a few bytes per  
entry.
Why don't you use an actual database? sqlite is fast, lightweight, and  
comes with Python 2.5

>> >  # add row i and increment number of rows
>> >  self.rows.append(DBRow(self, self.nRows))
>> >  self.nRows += 1

This looks suspicious, and may indicate that your structure contains  
cycles, and Python cannot always recall memory from those cycles, and you  
end using much more memory than needed.

-- 
Gabriel Genellina

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

Re: Memory Problem

2007-09-18 Thread Bruno Desthuilliers
Christoph Scheit a écrit :
> On Tuesday 18 September 2007 15:10, Marc 'BlackJack' Rintsch wrote:
>> On Tue, 18 Sep 2007 14:06:22 +0200, Christoph Scheit wrote:
>>> Then the data is added to a table, which I use for the actual
>>> Post-Processing. The table is actually a Class with several "Columns",
>>> each column internally being represented by array.

(snip)

> I have to deal with several millions of data, actually I'm trying an example 
> with
> 360 grid points and 1 time steps, i.e. 3 600 000 entries (and each row 
> consits of 4 int and one float)

Hem... My I suggest that you use a database then ? If you don't want to 
bother with a full-blown RDBMS, then have a look at SQLite - it's 
lightweight, works mostly fine and is a no-brainer to use.

> Of course, the more keys the bigger is the dictionary, but is there a way to 
> evaluate the actual size of the dictionary?

You can refer to the thread "creating really big lists" for a Q&D, raw 
approx of such an evaluation. But it's way too big anyway to even 
consider storing all this in ram.

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


[ANN] Metatest 0.1.0

2007-09-18 Thread Jonathan Fine
Hello

This announcement also appears on the Metatest web site 
http://metatest.sourceforge.net

===
*** Metatest - a Python test framework

Metatest is a simple and elegant Python framework for writing tests.

Metatest is mostly about writing tests and by design is not tied to any 
particular test runner. Hence the name.

Here's how to write some tests using Metatest. We can think of the tests 
as an executable specification.

 from metatest.py.mymod import plus, Point

 # Function plus adds two numbers.
 plus(2, 2) == 4
 plus(2, '', _ex=TypeError)

 # Class Point represent a point in the plane.
 p = Point(2, 5)
 p.x == 2
 p.y == 5
 p.area == 10

And here's one way to run them.

 if __name__ == '__main__':
 import metatest
 metatest.run()

It's not hard to write an adapter that will run these tests in a 
different test runner framework.

We gave a talk about Metatest at PyCon UK 2007 and here are the slides 
(HTML).
 http://www.pyconuk.org
 http://metatest.sourceforge.net/doc/pyconuk2007/metatest.html

Please visit Sourceforge to download Metatest.
 http://sourceforge.net/project/showfiles.php?group_id=204046

-- 
Jonathan Fine

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


Tutorial or Example (or Tutorial) of Using Canvas to Produce a Plot

2007-09-18 Thread W. Watson
I'm looking for an example with canvas that produces, say, a complete x-y 
plot of some data. By that I mean, it should do something like the following:

1. Produce x-y axes. The x-axis should be blue and the y-axis
should be green
2. Put a label on each axis (vertical and horizontal text)
3. Plot some data (3 points is enough) and connect the points
with a dashed line. Color one line red and the other green.
4. Position a title at some arbitrary place inside the x-y axes.
That is, not just a title above and outside the top of the
x-y area.

I just want to see how it's done. I'm not interested in a full-blown canned 
class or widget that does an x-y plot given some data. If not exactly the 
above, then something like it that gives me some idea of how to do such a 
graph. Maybe there's a tutorial that does something like this as an example.

-- 
  Wayne Watson (Nevada City, CA)

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


Re: Tutorial or Example (or Tutorial) of Using Canvas to Produce a Plot

2007-09-18 Thread Grant Edwards
On 2007-09-18, W. Watson <[EMAIL PROTECTED]> wrote:

> I'm looking for an example with canvas that produces, say, a
> complete x-y plot of some data.

With what widget set?

-- 
Grant Edwards   grante Yow! I'm a nuclear
  at   submarine under the
   visi.compolar ice cap and I need
   a Kleenex!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving parameters between Python applications?

2007-09-18 Thread Bruno Desthuilliers
Stodge a écrit :
> os.path.expanduser isn't an option; I need each console/window to
> maintain different values which I wouldn't get from saving to a user's
> home directory. Unless I used a different file for each console/window
> but that just gets me into the same situation I'm already in. I think
> the only option is to set environment variables using another script.
> I'm really surprised and disapponited by this.

Note that it's *not* a Python issue. You'd have the same problem with 
any other language.

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


Re: super, apply, or __init__ when subclassing?

2007-09-18 Thread exhuma.twn
On Sep 18, 2:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 18 Sep 2007 04:33:11 -0300, exhuma.twn <[EMAIL PROTECTED]> escribi?:
>
> > This is something that keeps confusing me. If you read examples of
> > code on the web, you keep on seeing these three calls (super, apply
> > and __init__) to reference the super-class. This looks to me as it is
> > somehow personal preference. But this would conflict with the "There
> > one way to do it" mind-set.
>
> > So, knowing that in python there is one thing to do something, these
> > three different calls must *do* domething different. But what exactly
> > *is* the difference?
>
> There are a few typos in your examples. If you write them this way:
>

Example 3 was not really a typo on my side. While I was browsing
around for python, I saw this in a code-fragment. So I thought this
was the way to do it. Even though I thought "super(A..." does not make
sense in a "semantic" way. Instead of just accepting this as a fact I
probably should have trusted my gut-feeling and investigate.

Nonetheless the posts (and explanations) here were really helpful for
me to understand what's happening under the hood. But seeing these
three variants of doing (nearly) the same was an itch I finally
decided to scratch. So far I blindly used "Example 1" as it seemed to
work for me.

>
>
> >  Exampel 1: -
>
> > class B(A):
> >def __init__(self, *args):
> >   A.__init__(self, *args)
>
> >  Exampel 2: -
>
> > class B(A):
> >def __init__(self, *args):
> >   apply( A.__init__, (self,) + args)
>
> >  Exampel 3: -
>
> > class B(A):
> >def __init__(self, *args):
> >   super(B,self).__init__(*args)
>
> then 2 is exactly the same as 1 but using a deprecated function. And 3 is  
> the same as 1 only when there is single inheritance involved (and you are  
> using new-style classes). But see the thread "super() doesn't get  
> superclass"
>
> --
> Gabriel Genellina


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


Using pseudonyms (was Re: Python 3K or Python 2.9?)

2007-09-18 Thread Aahz
In article <[EMAIL PROTECTED]>,
Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>Aahz a écrit :
>> In article <[EMAIL PROTECTED]>,
>> Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>>>
>>> But what, given that I'm an AOL user still thinking it's kewl to hide 
>>> behind a pseudo, what else would you expect ?
>> 
>> What exactly is a "pseudo", pray tell?
>
>Sorry : a pseudonym (a nickname).

You apparently missed the thrust of my sarcasm.  You can't tell what is
or is not a pseudonym online.  For all I know, "Bruno Desthulliers" is a
pseudonym.  While I recognize that there is some social advantage to
linking consistent identifiers with people, I have I think understandable
irritation with people who insist that names follow certain patterns.

(For those joining only recently, my full legal name is "Aahz", which I
changed from my former name precisely because of attitudes like Bruno's.)
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The meaning of a = b in object oriented languages

2007-09-18 Thread Aahz
In article <[EMAIL PROTECTED]>,
Laurent Pointal  <[EMAIL PROTECTED]> wrote:
>Summercool a écrit :
>> 
>> The meaning of  a = b  in object oriented languages.
>> 
>
>
>Oups, reading the subject I thought it was a Xah Lee post.

...and you're perpetuating the impression by continuing the crossposting.  
Please don't.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Saving parameters between Python applications?

2007-09-18 Thread Diez B. Roggisch
Stodge wrote:

> os.path.expanduser isn't an option; I need each console/window to
> maintain different values which I wouldn't get from saving to a user's
> home directory. Unless I used a different file for each console/window
> but that just gets me into the same situation I'm already in. I think
> the only option is to set environment variables using another script.
> I'm really surprised and disapponited by this.

you can't do that either. It's the principle behind environment-vars that
you can't alter the ones of your parent process.

That's the reason why environment-changes must be done by using "source":


# source my_script

where my_script contains e.g.

export FOO="bar"


If you can have your user alter his/her .bashrc, you might consider creating
a environtment-variable in there that the subsequent script invocations
refer to. Like this:

# .bashrc
export SESSION=

Then in the python-scripts you can use SESSION as a common prefix
into /tmp-residual files or such thing.

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


Re: Memory Problem

2007-09-18 Thread Christoph Scheit
Hi, Thank you all very much,

so I will consider using a database. Anyway I would like
how to detect cycles, if there are.

> >> >  # add row i and increment number of rows
> >> >  self.rows.append(DBRow(self, self.nRows))
> >> >  self.nRows += 1
>
> This looks suspicious, and may indicate that your structure contains
> cycles, and Python cannot always recall memory from those cycles, and you
> end using much more memory than needed.
>
> --
> Gabriel Genellina

How can I detect if there are cycles?

self.rows is a list containing DBRow-objects,
each itself being an integer pointer (index) to the i-th row.
Im using this list in order to sort the table by sorting the index-list
instead of realy sorting the entries. (or to filter).

-- 


M.Sc. Christoph Scheit
Institute of Fluid Mechanics
FAU Erlangen-Nuremberg
Cauerstrasse 4
D-91058 Erlangen
Phone: +49 9131 85 29508

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


Re: Metatest 0.1.0

2007-09-18 Thread Kay Schluehr
On Sep 18, 3:55 pm, Jonathan Fine <[EMAIL PROTECTED]> wrote:
> Hello
>
> This announcement also appears on the Metatest web 
> sitehttp://metatest.sourceforge.net
>
> ===
> *** Metatest - a Python test framework
>
> Metatest is a simple and elegant Python framework for writing tests.
>
> Metatest is mostly about writing tests and by design is not tied to any
> particular test runner. Hence the name.
>
> Here's how to write some tests using Metatest. We can think of the tests
> as an executable specification.
>
>  from metatest.py.mymod import plus, Point
>
>  # Function plus adds two numbers.
>  plus(2, 2) == 4
>  plus(2, '', _ex=TypeError)
>
>  # Class Point represent a point in the plane.
>  p = Point(2, 5)
>  p.x == 2
>  p.y == 5
>  p.area == 10
>
> And here's one way to run them.
>
>  if __name__ == '__main__':
>  import metatest
>  metatest.run()
>
> It's not hard to write an adapter that will run these tests in a
> different test runner framework.
>
> We gave a talk about Metatest at PyCon UK 2007 and here are the slides
> (HTML).
>  http://www.pyconuk.org
>  http://metatest.sourceforge.net/doc/pyconuk2007/metatest.html
>
> Please visit Sourceforge to download Metatest.
>  http://sourceforge.net/project/showfiles.php?group_id=204046
>
> --
> Jonathan Fine

>From the HTML slides:

   Assertion tests are easy to write but report and run poorly.

I tend to think this is a prejudice that leads to ever more ways to
write tests perform test discoveries, invent test frameworks etc.

When I thought about organizing my tests for EasyExtend I was seeking
for a strategy being adapted to my own behaviour. The very first step
I made when creating a new language, modifying a grammar rule,
changing the Transformer etc. was starting an interactive shell and
typing some commands. This is just checking out or smoke testing my
application and I wanted to reproduce it. So I recorded the
interactive shell session and replayed it as another shell session. I
enabled to set breakpoints in the logged output and implemented a
command for proceeding the replay.

Then I discovered I actually wrote an interactive test runner. I don't
have to care for all the exceptions being thrown in the session and
don't care for cleanups but just assign parts of the session as tests
using assert for getting an overview at the end. The only additonal
command I implemented was raises to capture the side-effect of raising
an exception.

So I'm going to argue here that there isn't anything particular about
writing/coding a test ( planning tests, specifying tests, reviewing a
testspecification etc. are another issue ). Instead you can keep a
seemingly unrelated practice and turn it into a test by a tiny
signification.

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


Re: How can I know how much to read from a subprocess

2007-09-18 Thread spam . noam
On Sep 18, 1:48 pm, "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote:
> On 2007-09-17, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > It seems that another solution is gobject.io_add_watch, but I don't
> > see how it tells me how much I can read from the file - if I don't
> > know that, I won't know the argument to give to the read() method in
> > order to get all the data:
>
> >http://www.pygtk.org/docs/pygobject/gobject-functions.html#function-g...
>
> Usually, gobject only tells you that data is there (that is all it knows).
> Therefore a read(1) should be safe.

But even if it's fast enough, how do you know how many times you
should call read(1)? If you do it too much, you'll be blocked until
more output is available.

> If that is too slow, consider os.read() which reads all data available (afaik,
> never tried it myself).
>
I tried it now, and it blocks just like the normal file.read().

Thanks,
Noam

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


Re: Saving parameters between Python applications?

2007-09-18 Thread Steve Holden
Stodge wrote:
> os.path.expanduser isn't an option; I need each console/window to
> maintain different values which I wouldn't get from saving to a user's
> home directory. Unless I used a different file for each console/window
> but that just gets me into the same situation I'm already in. I think
> the only option is to set environment variables using another script.
> I'm really surprised and disapponited by this.
> 
That's a sign of your inexperience, then. As someone has already pointed 
out, this is nothing to do with Python.

Under UNIX/Linux you could use the $$ variable to construct a filename 
specific to a particular shell process and put it in the environment, 
but I'm not aware of a similar feature in Windows. This is probably a 
sign of *my* inexperience :-)

> One option I thought of but haven't investigated, is the ability to
> get the parent (i.e. console's) process id and use that to create a
> file somewhere. Not sure if this is even possible.
> 
You might be able to write a Python program to access it :-)

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Re: Using pseudonyms (was Re: Python 3K or Python 2.9?)

2007-09-18 Thread Steve Holden
Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>> Aahz a écrit :
>>> In article <[EMAIL PROTECTED]>,
>>> Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
 But what, given that I'm an AOL user still thinking it's kewl to hide 
 behind a pseudo, what else would you expect ?
>>> What exactly is a "pseudo", pray tell?
>> Sorry : a pseudonym (a nickname).
> 
> You apparently missed the thrust of my sarcasm.  You can't tell what is
> or is not a pseudonym online.  For all I know, "Bruno Desthulliers" is a
> pseudonym.  While I recognize that there is some social advantage to
> linking consistent identifiers with people, I have I think understandable
> irritation with people who insist that names follow certain patterns.
> 
> (For those joining only recently, my full legal name is "Aahz", which I
> changed from my former name precisely because of attitudes like Bruno's.)
> 
... coupled with a certain bloody-mindedness that forces you to rub 
people's noses in your ability to choose to do so? ;-)

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using pseudonyms (was Re: Python 3K or Python 2.9?)

2007-09-18 Thread Aahz
In article <[EMAIL PROTECTED]>,
Steve Holden  <[EMAIL PROTECTED]> wrote:
>Aahz wrote:
>> In article <[EMAIL PROTECTED]>,
>> Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>>> Aahz a écrit :
 In article <[EMAIL PROTECTED]>,
 Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>
> But what, given that I'm an AOL user still thinking it's kewl to hide 
> behind a pseudo, what else would you expect ?

 What exactly is a "pseudo", pray tell?
>>>
>>> Sorry : a pseudonym (a nickname).
>> 
>> You apparently missed the thrust of my sarcasm.  You can't tell what is
>> or is not a pseudonym online.  For all I know, "Bruno Desthulliers" is a
>> pseudonym.  While I recognize that there is some social advantage to
>> linking consistent identifiers with people, I have I think understandable
>> irritation with people who insist that names follow certain patterns.
>> 
>> (For those joining only recently, my full legal name is "Aahz", which I
>> changed from my former name precisely because of attitudes like Bruno's.)
> 
>... coupled with a certain bloody-mindedness that forces you to rub 
>people's noses in your ability to choose to do so? ;-)

While there's certainly some truth to that, it is also the case that I
have seen people like Bruno take exception to some people's born names.
After all, there are people whose parents chose to name them "Moon Unit".

For that matter, there are plenty of people who are better known by some
nickname that is not their legal name.  And even before I changed my
name, I had plenty of problems from people believing that my name was a
nickname and "helpfully" fixing it.  (Which is really where my attitude
comes from, and the practical difficulties of having only one legal name
are not that much larger than my former difficulties.)  Overall, I think
that Bruno's attitude is more injurious to community than letting people
be known by whatever name they choose.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: super() doesn't get superclass

2007-09-18 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:

> If a class X is in the MRO of call Y, then X is a superclass of Y. I
> agree that the documentation for super is somewhat misleading (and
> obviously wrong), but it still *give access to* (at least one of)
> the superclass(es).

I believe the confusion comes from different assumptions about what
"superclasses" refers to.  super() iterates over superclasses of the
*instance* in use, but an individual call to super does not
necessarily invoke the superclass of the *implementation* of the
method.  For example, given a random class:

class X(Y):
  def foo(self):
super(X, self).foo()

...there is in fact no guarantee that super() calls a superclass of
X.  However, it is certainly guaranteed that it will call a superclass
of type(self).

Pre-2.2 Python used a simpler scheme where the superclass was always
called, but it caused problems with diamond inheritance where some
methods would be called either twice or not at all.  (This is
explained in http://www.python.org/download/releases/2.2.3/descrintro/
in some detail.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I know how much to read from a subprocess

2007-09-18 Thread Grant Edwards
On 2007-09-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> But even if it's fast enough, how do you know how many times you
> should call read(1)? If you do it too much, you'll be blocked until
> more output is available.

You don't know.  That's why you use non-blocking mode.

-- 
Grant Edwards   grante Yow! BELA LUGOSI is my
  at   co-pilot ...
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using pseudonyms (was Re: Python 3K or Python 2.9?)

2007-09-18 Thread Bruno Desthuilliers
Aahz a écrit :
> In article <[EMAIL PROTECTED]>,
> Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>> Aahz a écrit :
>>> In article <[EMAIL PROTECTED]>,
>>> Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
 But what, given that I'm an AOL user still thinking it's kewl to hide 
 behind a pseudo, what else would you expect ?
>>> What exactly is a "pseudo", pray tell?
>> Sorry : a pseudonym (a nickname).
> 
> You apparently missed the thrust of my sarcasm. 

Obviously, yes.

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


Re: Using pseudonyms (was Re: Python 3K or Python 2.9?)

2007-09-18 Thread Bruno Desthuilliers
Aahz a écrit :
> In article <[EMAIL PROTECTED]>,
> Steve Holden  <[EMAIL PROTECTED]> wrote:
>> Aahz wrote:
>>> In article <[EMAIL PROTECTED]>,
>>> Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
 Aahz a écrit :
> In article <[EMAIL PROTECTED]>,
> Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>> But what, given that I'm an AOL user still thinking it's kewl to hide 
>> behind a pseudo, what else would you expect ?
> What exactly is a "pseudo", pray tell?
 Sorry : a pseudonym (a nickname).
>>> You apparently missed the thrust of my sarcasm.  You can't tell what is
>>> or is not a pseudonym online.  For all I know, "Bruno Desthulliers" is a
>>> pseudonym.  While I recognize that there is some social advantage to
>>> linking consistent identifiers with people, I have I think understandable
>>> irritation with people who insist that names follow certain patterns.
>>>
>>> (For those joining only recently, my full legal name is "Aahz", which I
>>> changed from my former name precisely because of attitudes like Bruno's.)

For the record, I usually don't give a damn about what 
name/nickname/whatever peoples use.

>> ... coupled with a certain bloody-mindedness that forces you to rub 
>> people's noses in your ability to choose to do so? ;-)
> 
> While there's certainly some truth to that, it is also the case that I
> have seen people like Bruno take exception to some people's born names.
> After all, there are people whose parents chose to name them "Moon Unit".

But then adding the lastname (ie 'Zappa') could clear the possible 
confusion !-)

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


Re: can Python be useful as functional?

2007-09-18 Thread Steve Holden
Lorenzo Stella wrote:
[...]
> My question is: how can we call a language "functional" if it's major
> implementation has a limited stack? Or is my code wrong?
> 
So, which environment do you habitually use that provides an *unlimited* 
stack?

You remind me of the conversation between the philosopher and an 
attractive lady whom he was seated next to at dinner. He asked her if 
she would sleep with him for a million dollars, to which she readily 
agreed. So he followed this by asking her if she'd sleep with him for a 
dollar. She replied: "No. Do you take me for a prostitutte?", to which 
his riposte was "We have already established that fact, and are now 
merely haggling about the price".

You just don't like the specific limit that Python imposes. So increase 
it with sys.setrecursionlimit().

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Re: Writing to multiple excel worksheets

2007-09-18 Thread Tommy Nordgren

On 17 sep 2007, at 23.00, SPJ wrote:

> Hi,
>
> I have a list which I need to write to excel worksheet. The list is  
> like:
> data =  
> ['IP1','21','ftp','\n','IP1','22','ssh','\n','IP2','22','ssh','\n','IP 
> 2','23','telnet','\n']
> Now the task is to create a workbook with tabbed sheet for each of  
> the service's in the list i.e. tabs for ftp, ssh, telnet etc. The  
> data needs to be written in the corresponding sheets.
>
> What is the best way to achieve this?
> I couldn't find much help on the internet nor in the earlier  
> threads. Please help.
>
> Thanks,
> SPJ
Excel files are in a binary and proprietary format. You can however  
generate
tab-separated text files, which Excel can import.
--
What is a woman that you forsake her, and the hearth fire and the  
home acre,
to go with the old grey Widow Maker.  --Kipling, harp song of the  
Dane women
Tommy Nordgren
[EMAIL PROTECTED]



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


Re: can Python be useful as functional?

2007-09-18 Thread Grant Edwards
On 2007-09-18, Steve Holden <[EMAIL PROTECTED]> wrote:
> Lorenzo Stella wrote:
> [...]
>>
>> My question is: how can we call a language "functional" if
>> it's major implementation has a limited stack? Or is my code
>> wrong?
>
> So, which environment do you habitually use that provides an
> *unlimited* stack?

Perhaps Lorenzo Stella is referring to Python's lack of
tail-recursion optimization?  There are languages that
guarantee unlimited tail-recursion with a limited stack.

That's a typical feature for a function language, right?

> You just don't like the specific limit that Python imposes. So
> increase it with sys.setrecursionlimit().

-- 
Grant Edwards   grante Yow! I hope I bought the
  at   right relish ... z
   visi.com...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can Python be useful as functional?

2007-09-18 Thread Robin Becker
Steve Holden wrote:
> Lorenzo Stella wrote:
..
> So, which environment do you habitually use that provides an *unlimited* 
> stack?
> 
> You remind me of the conversation between the philosopher and an 
> attractive lady whom he was seated next to at dinner. He asked her if 
> she would sleep with him for a million dollars, to which she readily 
> agreed. So he followed this by asking her if she'd sleep with him for a 
> dollar. She replied: "No. Do you take me for a prostitutte?", to which 
> his riposte was "We have already established that fact, and are now 
> merely haggling about the price".
> 

allegedly G B Shaw 
(http://findarticles.com/p/articles/mi_qn4158/is_19980925/ai_n14182408)
-- 
Robin Becker

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


Re: can Python be useful as functional?

2007-09-18 Thread Paul Rudin
Robin Becker <[EMAIL PROTECTED]> writes:

> Steve Holden wrote:
>> Lorenzo Stella wrote:
> ..
>> So, which environment do you habitually use that provides an
>> *unlimited* stack?
>>
>> You remind me of the conversation between the philosopher and an
>> attractive lady whom he was seated next to at dinner. He asked her
>> if she would sleep with him for a million dollars, to which she
>> readily agreed. So he followed this by asking her if she'd sleep
>> with him for a dollar. She replied: "No. Do you take me for a
>> prostitutte?", to which his riposte was "We have already established
>> that fact, and are now merely haggling about the price".
>>
>
> allegedly G B Shaw
> (http://findarticles.com/p/articles/mi_qn4158/is_19980925/ai_n14182408)

Also allegedly Winston Churchill, although wikiquote says:

  "This is a very old joke where the participants vary dramatically
   from each telling. It's very unlikely though not impossible that
   the joke originated from Churchill."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Metatest 0.1.0

2007-09-18 Thread Jonathan Fine
Kay Schluehr wrote:

>> http://metatest.sourceforge.net/doc/pyconuk2007/metatest.html

>From the HTML slides:
> 
>Assertion tests are easy to write but report and run poorly.
> 
> I tend to think this is a prejudice that leads to ever more ways to
> write tests perform test discoveries, invent test frameworks etc.
> 
> When I thought about organizing my tests for EasyExtend I was seeking
> for a strategy being adapted to my own behaviour. The very first step
> I made when creating a new language, modifying a grammar rule,
> changing the Transformer etc. was starting an interactive shell and
> typing some commands. 

Yes, Python is really good for that.  I do it a lot also.

> This is just checking out or smoke testing my
> application and I wanted to reproduce it. So I recorded the
> interactive shell session and replayed it as another shell session. I
> enabled to set breakpoints in the logged output and implemented a
> command for proceeding the replay.

This is similar, I think, to what Metatest does.  See 
http://metatest.sourceforge.net/doc/pyconuk2007/metatest.html#slide5

> Then I discovered I actually wrote an interactive test runner. I don't
> have to care for all the exceptions being thrown in the session and
> don't care for cleanups but just assign parts of the session as tests
> using assert for getting an overview at the end. The only additonal
> command I implemented was raises to capture the side-effect of raising
> an exception.

Sounds interesting.  Is this code, or examples of its use, available?

> So I'm going to argue here that there isn't anything particular about
> writing/coding a test ( planning tests, specifying tests, reviewing a
> testspecification etc. are another issue ). Instead you can keep a
> seemingly unrelated practice and turn it into a test by a tiny
> signification.

I'm all in favour of making tests easier to write, easier to run, and 
the outputs easier to understand.

I've submitted a feature request for command line use of Metatest 
(something I've been thinking of a while):
http://sourceforge.net/tracker/index.php?func=detail&aid=1797187&group_id=204046&atid=988038

Here's how I'd like the feature to look (from the above URL):
===
Python 2.4.1a0 (#2, Feb 9 2005, 12:50:04)
[GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from metatest.py.mymod import plus
 >>> import metatest
 >>> plus(2, 3) == 6

 >>> metatest.immediate = True # New command
 >>> plus(2, 3) == 6
TestError: Expected '6', got '5'
 >>>
===

OK.  So now here's a problem.  We can create stuff like the above that 
states clearly (I hope) what is required.  How can we write a test for 
this sort of behaviour?  So that's another feature request.

While I'm in favour of using Metatest to write tests for Metatest 
(eating your own dogfood), I'm more interested in real world examples. 
But I've added second feature request, that Metatest be able to test 
Metatest.
http://sourceforge.net/tracker/index.php?func=detail&aid=1797202&group_id=204046&atid=988038

-- 
Jonathan

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


Re: Tutorial or Example (or Tutorial) of Using Canvas to Produce a Plot

2007-09-18 Thread W. Watson
What would be appropriate? What are the choices? I'm pretty new to Python, 
but am familiar with the XWindow widget set. I think it is available under 
Python, but if there's a more suitable choice, that's fine. I would think 
Tkinter would be the simplest choice. Yes, Tkinter would be preferable. It 
seems to be the GUI of choice.

Grant Edwards wrote:
> On 2007-09-18, W. Watson <[EMAIL PROTECTED]> wrote:
> 
>> I'm looking for an example with canvas that produces, say, a
>> complete x-y plot of some data.
> 
> With what widget set?
> 

-- 
  Wayne Watson (Nevada City, CA)

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


Re: Writing to multiple excel worksheets

2007-09-18 Thread Carsten Haese
On Tue, 2007-09-18 at 18:49 +0200, Tommy Nordgren wrote:
>   Excel files are in a binary and proprietary format.

True, but that doesn't mean you can't create them with free software.
PyExcelerator (http://sourceforge.net/projects/pyexcelerator) can create
Excel files.

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


What's with "long running processes" ?

2007-09-18 Thread walterbyrd
I understand that Python has them, but PHP doesn't.

I think that is because mod_php is built into apache, but mod_python
is not usually in apache. If  mod_python was built into apache, would
python still have long running processes (LRP)?

Do LRPs have to do with a Python interpreter running all the time? Or
is it something else?

I also understand that LRPs are the reason that shared hosting is less
common, and more expensive for python than php. The LRP have a major
effect on how many users can packed onto a single server.

As to LRPs: does it matter if you're using mod_python, fastcgi, wsgi,
scgi, cgi, or whatever?

Obviously, I am a little foggy about LRPs, can somebody help me out?

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


Re: adodb with mysql - connection string syntax for filepath

2007-09-18 Thread J. Clifford Dyer
On Tue, Sep 18, 2007 at 09:32:45AM -0400, Steve Holden wrote regarding Re: 
adodb with mysql - connection string syntax for filepath:
> 
> Mridula Ramesh wrote:
> > Hi. Firstly, thank you both very much for the response!
> > 
> > Cliff, I did some more reading up about it after  you corrected me re 
> > MySQL not being a _language_  but another means of storing data (would 
> > you believe NONE of the connection tutorials actually said that?!) 
> > Anyway, now I have MySQL on my machine, and it's installed - if I say 
> > "import MySQLdb" in python prompt, it does that, but I can't see any exe 
> > in the program's folder itself: does that mean tables can only be 
> > created by code? *puzzled*
> > 
> > Steve, thank you too, I looked up the link you had given, but I do not 
> > yet know which part of that site may help me... And I am now going to 
> > struggle with Dive Into Python before attempting much else!
> > 
> > This is a nice, helpful mailing group!
> > 
> We try, though not everyone appreciates us :-)
> 
> You may find
> 
>http://www.connectionstrings.com/
> 
> more helpful.
> 
> regard
>   Steve

For non-programmatic (non-python) access, you might also look into the "MySQL 
GUI Tools" package, freely downloadable from mysql.com.

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


Newbie question

2007-09-18 Thread koutoo
If I have a file name: AVC1030708.14.  How do I strip out certain
characters from the file name?  I am so used to using MID, LEFT, and
RIGHT functions, that I have no idea how to do this in python?  I have
had trouble as well with most newbies on finding the help.  But I have
used the command line built in help, but with no luck.  Thanks.

Kou

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


Re: Newbie question

2007-09-18 Thread koutoo
On Sep 18, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > If I have a file name: AVC1030708.14.  How do I strip out certain
> > characters from the file name?  I am so used to using MID, LEFT, and
> > RIGHT functions, that I have no idea how to do this in python?  I have
> > had trouble as well with most newbies on finding the help.  But I have
> > used the command line built in help, but with no luck.  Thanks.
>
> > Kou
>
> Do you want to strip out specific characters, characters in specific
> positions, or characters matching certain patterns?

Yes, I want specific characters in specific positions.

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


Re: Newbie question

2007-09-18 Thread Shawn Milochik
On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Sep 18, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> > On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> > > If I have a file name: AVC1030708.14.  How do I strip out certain
> > > characters from the file name?  I am so used to using MID, LEFT, and
> > > RIGHT functions, that I have no idea how to do this in python?  I have
> > > had trouble as well with most newbies on finding the help.  But I have
> > > used the command line built in help, but with no luck.  Thanks.
> >
> > > Kou
> >
> > Do you want to strip out specific characters, characters in specific
> > positions, or characters matching certain patterns?
>
> Yes, I want specific characters in specific positions.
>

Try this:

newString = oldString[0:3] + oldString[5:10]

Some other quick examples:

>>> test = "this is a test"
>>> test
'this is a test'
>>> fred = test[:3] + test[9:]
>>> fred
'thi test'
>>> test[0:5]
'this '
>>> test[:5]
'this '
>>> test[4:]
' is a test'
-- 
http://mail.python.org/mailman/listinfo/python-list


cvs module

2007-09-18 Thread Tim Arnold
Hi, I need to do some scripting that interacts with CVS. I've been just 
doing system calls and parsing the output to figure out what's going on, but 
it would be nice to deal with CVS directly.

Does anyone know of a python module I can use to interface with CVS?
thanks,
--Tim Arnold


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


Re: Newbie question

2007-09-18 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> On Sep 18, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> 
>>On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>
>>
>>>If I have a file name: AVC1030708.14.  How do I strip out certain
>>>characters from the file name?  I am so used to using MID, LEFT, and
>>>RIGHT functions, that I have no idea how to do this in python?  I have
>>>had trouble as well with most newbies on finding the help.  But I have
>>>used the command line built in help, but with no luck.  Thanks.
>>
>>>Kou
>>
>>Do you want to strip out specific characters, characters in specific
>>positions, or characters matching certain patterns?
> 
> 
> Yes, I want specific characters in specific positions.
> 
Err... Sorry, but something is not clear here. When you say "strip out", 
  you mean "get rid of", or "access to" ? For what I remember of basic, 
I guess it's the second answer, so:

 >>> fname = "AVC1030708.14"
 >>> print fname[0]
A
 >>> print fname[-1]
4
 >>> print fname[2:4]
C1
 >>> print fname[2:-4]
C103070
 >>>

etc...

Also and while we're at it, you also have:
 >>> fname.split('.')
['AVC1030708', '14']
 >>> fname.split('.')[0]
'AVC1030708'
 >>> fname.split('.')[1]
'14'
 >>> fname.strip('4')
'AVC1030708.1'
 >>> fname.strip('A')
'VC1030708.14'
 >>> fname.lstrip('A')
'VC1030708.14'
 >>> fname.rstrip('4')
'AVC1030708.1'
 >>> fname.rstrip('41.')
'AVC1030708'

etc...

HTH



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


Re: Newbie question

2007-09-18 Thread Arnaud Delobelle
On Sep 18, 7:33 pm, [EMAIL PROTECTED] wrote:
> On Sep 18, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
>
> > On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > > If I have a file name: AVC1030708.14.  How do I strip out certain
> > > characters from the file name?  I am so used to using MID, LEFT, and
> > > RIGHT functions, that I have no idea how to do this in python?  I have
> > > had trouble as well with most newbies on finding the help.  But I have
> > > used the command line built in help, but with no luck.  Thanks.
>
> > > Kou
>
> > Do you want to strip out specific characters, characters in specific
> > positions, or characters matching certain patterns?
>
> Yes, I want specific characters in specific positions.

The tutorial is a good place to start.  Read this section:

http://docs.python.org/tut/node5.html#SECTION00512

HTH

--
Arnaud


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


Re: Newbie question

2007-09-18 Thread Shawn Milochik
On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> If I have a file name: AVC1030708.14.  How do I strip out certain
> characters from the file name?  I am so used to using MID, LEFT, and
> RIGHT functions, that I have no idea how to do this in python?  I have
> had trouble as well with most newbies on finding the help.  But I have
> used the command line built in help, but with no luck.  Thanks.
>
> Kou


Do you want to strip out specific characters, characters in specific
positions, or characters matching certain patterns?
-- 
http://mail.python.org/mailman/listinfo/python-list


World's best guitars ever!!!!

2007-09-18 Thread nutsbreaker3
http://freeguitars.blogspot.com/

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


Re: Newbie question

2007-09-18 Thread koutoo
On Sep 18, 1:42 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Sep 18, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> > > On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > > > If I have a file name: AVC1030708.14.  How do I strip out certain
> > > > characters from the file name?  I am so used to using MID, LEFT, and
> > > > RIGHT functions, that I have no idea how to do this in python?  I have
> > > > had trouble as well with most newbies on finding the help.  But I have
> > > > used the command line built in help, but with no luck.  Thanks.
>
> > > > Kou
>
> > > Do you want to strip out specific characters, characters in specific
> > > positions, or characters matching certain patterns?
>
> > Yes, I want specific characters in specific positions.
>
> Try this:
>
> newString = oldString[0:3] + oldString[5:10]
>
> Some other quick examples:
>
> >>> test = "this is a test"
> >>> test
> 'this is a test'
> >>> fred = test[:3] + test[9:]
> >>> fred
> 'thi test'
> >>> test[0:5]
> 'this '
> >>> test[:5]
> 'this '
> >>> test[4:]
>
> ' is a test'- Hide quoted text -
>
> - Show quoted text -

I see.  It's so hard to imagine the world of python than from VB.
It's like looking at VB is in 2 dimensions, where with Python, it's
more 3D.  The code is so simple, yet it's hard for me to envision how
to do something so simple.  I guess it's because the rules or the way
of looking at things in Python, things can be stripped down to the
bare bones and in so many ways.  Thanks.

Kou

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


Re: Newbie question

2007-09-18 Thread Francesco Guerrieri
On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> If I have a file name: AVC1030708.14.  How do I strip out certain
> characters from the file name?  I am so used to using MID, LEFT, and
> RIGHT functions, that I have no idea how to do this in python?  I have
> had trouble as well with most newbies on finding the help.  But I have
> used the command line built in help, but with no luck.  Thanks.
>
> Kou

As a newbie, you would do well to read and study the tutorial which
you can find at http://docs.python.org/tut/tut.html

In particular there is an interesting section on Strings:
http://docs.python.org/tut/node5.html#SECTION00512

and
http://docs.python.org/lib/string-methods.html

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


Re: cvs module

2007-09-18 Thread Jonathan Fine
Tim Arnold wrote:
> Hi, I need to do some scripting that interacts with CVS. I've been just 
> doing system calls and parsing the output to figure out what's going on, but 
> it would be nice to deal with CVS directly.
> 
> Does anyone know of a python module I can use to interface with CVS?
> thanks,

Hello Tim

Not exactly what you asked for, but I've integrated Tortoise CVS with 
WinEdt.  This gives users with menu commands in WinEdt for invoking 
Tortoise.  Works well for my users, but might not meet your need.

Have you looked at
 http://rhaptos.org/downloads/python/pycvs/

Or for Subversion
 http://pysvn.tigris.org/

If you use Subversion, you call then also use Trac (which is written in 
Python)
 http://trac.edgewall.org/

Please let us know how you get on.

-- 
Jonathan



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


Re: What's with "long running processes" ?

2007-09-18 Thread Bruno Desthuilliers
walterbyrd a écrit :
> I understand that Python has them, but PHP doesn't.

Really ?

> I think that is because mod_php is built into apache, but mod_python
> is not usually in apache.

Language etc aside, what the difference between mod_php and mod_python 
(or mod_whatever) from apache's POV ?

> If  mod_python was built into apache, would
> python still have long running processes (LRP)?

mod_php is not more 'built into' apache than mod_python. Both are 
extension modules for apache. FWIW, when apache is configured to use 
mod_python, it starts a first python interpreter process at startup, 
then some more python "sub-interpreters" when needed, according to your 
configuration.

> Do LRPs have to do with a Python interpreter running all the time? Or
> is it something else?

The notion of "long running process" is nothing Python-specific. The 
most basic way to deliver dynamic content from a web server like apache 
is to use CGI - which means that on each http request, the web server 
starts a new (Python | Perl | PHP | Whatever) process. A more elaborate 
solution is to have another process running independently, and some way 
for both processes (web server and application) to communicate. This was 
is usually known as a "long running process".

> I also understand that LRPs are the reason that shared hosting is less
> common, and more expensive for python than php.

Yes and no. You can use Python with apache without a LRP - either with 
CGI or mod_python -  but the first solution is very inefficient, and the 
second is not really appropriate for shared hosting given how mod_python 
works. Also, while LRPs have a big advantage (you don't need to rebuild 
the whole world for each and every request), they have a couple 
drawbacks when it comes to shared hosting. The first one is that your 
host must provide some way to manage (run/stop/restart/monitor) the 
process. The second is that, while CGI scripts are (more or less) under 
control of the web server (IOW : they won't hang out forever), it's not 
true for LRPs. Which means that a program error (ie: an endless loop 
allocating memory on each iteration...) can potentially bring the while 
server down. Not that there are no ways to limit the risks and 
consequences, but this requires much more work for the host (and believe 
me, shared hosting administration is not simple...).

> The LRP have a major
> effect on how many users can packed onto a single server.

Not necessarily. From a purely technical POV, they are usually less 
wasteful wrt/ resources than CGI or mod_php.

> As to LRPs: does it matter if you're using mod_python, fastcgi, wsgi,
> scgi, cgi, or whatever?
 >
> Obviously, I am a little foggy about LRPs, can somebody help me out?

You can help yourself out, by installing apache on your own machine and 
learning the different ways to deploy web applications with it. While 
you won't have the same constraints as a shared hosting admin, you'll at 
least get a better understanding of the whole damn thing.



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


Re: can Python be useful as functional?

2007-09-18 Thread Bruno Desthuilliers
Grant Edwards a écrit :
> On 2007-09-18, Steve Holden <[EMAIL PROTECTED]> wrote:
> 
>>Lorenzo Stella wrote:
>>[...]
>>
>>>My question is: how can we call a language "functional" if
>>>it's major implementation has a limited stack? Or is my code
>>>wrong?
>>
>>So, which environment do you habitually use that provides an
>>*unlimited* stack?
> 
> Perhaps Lorenzo Stella is referring to Python's lack of
> tail-recursion optimization?  There are languages that
> guarantee unlimited tail-recursion with a limited stack.
> 
> That's a typical feature for a function language, right?
> 
And also for some implementations of some purely procedural languages IIRC.

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


Re: Newbie question

2007-09-18 Thread Greg Lindstrom
>
> I see.  It's so hard to imagine the world of python than from VB.
> It's like looking at VB is in 2 dimensions, where with Python, it's
> more 3D.  The code is so simple, yet it's hard for me to envision how
> to do something so simple.  I guess it's because the rules or the way
> of looking at things in Python, things can be stripped down to the
> bare bones and in so many ways.  Thanks.
>
> Kou


Indeed. A common phrase you will here around here is "reset your mind".
Python, like most languages, has it's own way of looking at the world.  You
may want to look at the tutors list, too ([EMAIL PROTECTED]).  You'll like it
there (I do).

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

Free software!!!!

2007-09-18 Thread freesoftwareweb
http://freesoftwareupgrades.blogspot.com/

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


Re: Parsing problems: A journey from a text file to a directory tree

2007-09-18 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>,
 "Martin M." <[EMAIL PROTECTED]> wrote:

> Hi everybody,
> 
> Some of my colleagues want me to write a script for easy folder and
> subfolder creation on the Mac.
> 
> The script is supposed to scan a text file containing directory trees
> in the following format:
> 
> [New client]
> |-Invoices
> |-Offers
> |--Denied
> |--Accepted
> |-Delivery notes
> 
> As you can see, the folder hierarchy is expressed by the amounts of
> minuses, each section header framed by brackets (like in Windows
> config files).
> 
> After the scan process, the script is supposed to show a dialog, where
> the user can choose from the different sections (e.g. 'Alphabet',
> 'Months', 'New client' etc.). Then the script will create the
> corresponding folder hierarchy in the currently selected folder (done
> via AppleScript).
> 
> But currently I simply don't know how to parse these folder lists and
> how to save them in an array accordingly.
> 
> First I thought of an array like this:
> 
> dirtreedb = {'New client': {'Invoices': {}, 'Offers': {'Denied': {},
> 'Accpeted': {}}, 'Delivery notes': {}}}
> 
> But this doesn't do the trick, as I also have to save the hierarchy
> level of the current folder as well...
> 
> Argh, I really don't get my head around this problem and I need your
> help. I have the feeling, that the answer is not that complicated, but
> I just don't get it right now...

Hello, Martin,

A good way to approach this problem is to recognize that each section of 
your proposed configuration represents a kind of depth-first traversal 
of the tree structure you propose to create.  Thus, you can reconstruct 
the tree by keeping track at all times of the path from the "root" of 
the tree to the "current location" in the tree.

Below is one possible implementation of this idea in Python.  In short, 
the function keeps track of a stack of dictionaries, each of which 
represents the contents of some directory in your hierarchy.  As you 
encounter "|--" lines, entries are pushed to or popped from the stack 
according to whether the nesting level has increased or decreased.

This code is not heavily tested, but hopefully it should be clear:

.import re
.
.def parse_folders(input):
."""Read input from a file-like object that describes directory
.structures to be created.  The input format is:
.
.[Top-level name]
.|-Subdirectory1
.|--SubSubDirectory1
.|--SubSubDirectory2
.|---SubSubSubDirectory1
.|-Subdirectory2
.|-Subdirectory3
.
.The input may consist of any number of such groups.  The result is
.a dictionary structure in which each key names a directory, and
.the corresponding value is a dictionary structure showing the
.contents of that directory, possibly empty.
."""
.
.# This expression matches "header" lines, defining a new section.
.new_re  = re.compile(r'\[([\w ]+)\]\s*$')
.
.# This expression matches "nesting" lines, defining subdirectories.
.more_re = re.compile(r'(\|-+)([\w ]+)$')
.
.out = {}# Root:  Maps section names to subtrees.
.state = [out]   # Stack of dictionaries, current path.
.
.for line in input:
.m = new_re.match(line)
.if m:   # New section begins here...
.key = m.group(1).strip()
.out[key] = {}
.state = [out, out[key]]
.continue
.
.m = more_re.match(line)
.if m:   # Add a directory to an existing section
.assert state
.
.new_level = len(m.group(1))
.key = m.group(2).strip()
.
.while new_level < len(state):
.state.pop()
.
.state[-1][key] = {}
.state.append(state[-1][key])
.
.return out

To call this, pass a file-like object to parse_folders(), e.g.:

test1 = '''
[New client].
|-Invoices
|-Offers
|--Denied
|--Accepted
|---Reasons
|---Rhymes
|-Delivery notes
'''

from StringIO import StringIO
result = parse_folders(StringIO(test1))

As the documentation suggests, the result is a nested dictionary 
structure, representing the folder structure you encoded.  I hope this 
helps.

Cheers,
-M

-- 
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/  | Dartmouth College, Hanover, NH, USA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using python to create windows apps that everyone can use?

2007-09-18 Thread Matt McCredie
On 9/18/07, Thomas Harding <[EMAIL PROTECTED]> wrote:
> Hi guys, sorry to post another topic on this, as I am aware that it has
> already been posted a few times, but not with specifically what I am looking
> for. I want an app that makes a gui interface for python (similar to
> Microsoft visual studio or qt designer, not a code based one) and/or an app
> that can make this into a .exe that can be opened by any person on any
> computer without python installed.

check out py2exe: http://py2exe.org

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


Re: Extracting xml from html

2007-09-18 Thread kyosohma
On Sep 18, 1:56 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I am attempting to extract some XML from an HTML document that I get
> > returned from a form based web page. For some reason, I cannot figure
> > out how to do this.
> > Here's a sample of the html:
>
> > 
> > 
> > lots of screwy text including divs and spans
> > 
> > 1126264
> > Mitsubishi
> > Mirage DE
> > 
> > 
> > 
>
> > What's the best way to get at the XML? Do I need to somehow parse it
> > using the HTMLParser and then parse that with minidom or what?
>
> lxml makes this pretty easy:
>
>>>> parser = etree.HTMLParser()
>>>> tree = etree.parse(the_file_or_url, parser)
>
> This is actually a tree that can be treated as XML, e.g. with XPath, XSLT,
> tree iteration, ... You will also get plain XML when you serialise it to XML:
>
>>>> xml_string = etree.tostring(tree)
>
> Note that this doesn't add any namespaces, so you will not magically get valid
> XHTML or something. You could rewrite the tags by hand, though.
>
> Stefan

I got it to work with lxml. See below:

def Parser(filename):
parser = etree.HTMLParser()
tree = etree.parse(r'path/to/nextpage.htm', parser)
xml_string = etree.tostring(tree)
events = ("recordnum", "primaryowner", "customeraddress")
context = etree.iterparse(StringIO(xml_string), tag='')
for action, elem in context:
tag = elem.tag
if tag == 'primaryowner':
owner = elem.text
elif tag == 'customeraddress':
address = elem.text
else:
pass

print 'Primary Owner: %s' % owner
print 'Address: %s' % address

Does this make sense? It works pretty well, but I don't really
understand everything that I'm doing.

Mike

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


Re: Wait For Application Start

2007-09-18 Thread Francesco Guerrieri
On 9/18/07, Michael Bentley <[EMAIL PROTECTED]> wrote:

> >
> > import os.path
> > import time
> >
> > while True:
> > if os.path.exists(YOUR_FILE):
> > break
> > time.sleep(30)
>
> or
>
> while not os.path.exists(YOUR_FILE):
>  time.sleep(1)

I thought of that, but I found more readable the positive form :-)

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


Re: can Python be useful as functional?

2007-09-18 Thread Steve Holden
Paul Rudin wrote:
> Robin Becker <[EMAIL PROTECTED]> writes:
> 
>> Steve Holden wrote:
>>> Lorenzo Stella wrote:
>> ..
>>> So, which environment do you habitually use that provides an
>>> *unlimited* stack?
>>>
>>> You remind me of the conversation between the philosopher and an
>>> attractive lady whom he was seated next to at dinner. He asked her
>>> if she would sleep with him for a million dollars, to which she
>>> readily agreed. So he followed this by asking her if she'd sleep
>>> with him for a dollar. She replied: "No. Do you take me for a
>>> prostitutte?", to which his riposte was "We have already established
>>> that fact, and are now merely haggling about the price".
>>>
>> allegedly G B Shaw
>> (http://findarticles.com/p/articles/mi_qn4158/is_19980925/ai_n14182408)
> 
> Also allegedly Winston Churchill, although wikiquote says:
> 
>   "This is a very old joke where the participants vary dramatically
>from each telling. It's very unlikely though not impossible that
>the joke originated from Churchill."

Also allegedly Bertrand Russell, who was going to be the subject of my 
version until I realized that I would get many corrections to any 
asserted identity of the originator. I should have know to expect just 
as many corrections to the absence of any such assertion, this being 
c.l.py :-)

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Re: Tutorial or Example (or Tutorial) of Using Canvas to Produce a Plot

2007-09-18 Thread Grant Edwards
On 2007-09-18, W. Watson <[EMAIL PROTECTED]> wrote:

> What would be appropriate? What are the choices? I'm pretty new to Python, 
> but am familiar with the XWindow widget set.

There's no such thing as "the XWindow widget set".  There are
at least 8-10 different X Windows widget sets.  The ones that I
can name off the top of my head:

 Tk
 Athena
 Motif
 FLTK
 GTK
 Qt
 XRT 
 WxWidgets (actually sort of meta-widget-set)

http://en.wikipedia.org/wiki/Widget_toolkit

http://en.wikipedia.org/wiki/List_of_widget_toolkits#On_Unix.2C_under_the_X_Window_System
 
-- 
Grant Edwards   grante Yow! As President I have
  at   to go vacuum my coin
   visi.comcollection!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tutorial or Example (or Tutorial) of Using Canvas to Produce a Plot

2007-09-18 Thread kyosohma
On Sep 18, 12:23 pm, "W. Watson" <[EMAIL PROTECTED]> wrote:
> What would be appropriate? What are the choices? I'm pretty new to Python,
> but am familiar with the XWindow widget set. I think it is available under
> Python, but if there's a more suitable choice, that's fine. I would think
> Tkinter would be the simplest choice. Yes, Tkinter would be preferable. It
> seems to be the GUI of choice.
>
> Grant Edwards wrote:
> > On 2007-09-18, W. Watson <[EMAIL PROTECTED]> wrote:
>
> >> I'm looking for an example with canvas that produces, say, a
> >> complete x-y plot of some data.
>
> > With what widget set?
>
> --
>   Wayne Watson (Nevada City, CA)
>
> Web Page: 

I've heard a lot about drawing with the wxPython widget set as well.

Some examples:

http://wiki.wxpython.org/RecipesImagesAndGraphics

Mike

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


  1   2   >