Re: Not fully OO ?

2008-09-21 Thread MVP

Hi!


Everything ... are an object.


It's true ; but a language built around the objects, and OOP, are two 
different concepts.


@-salutations
--
Michel Claveau


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


Re: Not fully OO ?

2008-09-21 Thread M�ta-MCI (MVP)

Bonjour !

AMHA, ceux qui ont écrit ce texte ont une mauvaise idée de ce que sont 
les variables en Python.
Ils ont sans doute trop en tête les notions des variables en C ou en 
Basic, et ne se sont pas penchés sur les spécificités de Python.


@-salutations
--
Michel Claveau

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


Re: Not fully OO ?

2008-09-21 Thread Martin v. Löwis
Christian Heimes wrote:
> Kay Schluehr wrote:
>> Actually it is simply wrong in the mentioned case 
[...]
> 
> It's not wrong. You have found a simple optimization. Lot's of compilers
> for lots of languages optimize code by code folding.

I don't think he meant that Python is wrong somehow, but that the OO
babble of what happens for 2+2 is wrong. The babble said that, when the
code is executed, an __add__ message is sent to the 2 object, with
another 2 object as the parameter. That statement is incorrect: no
message is sent at all, but the result is available even before the
program starts.

FWIW, "2+2" is not a good case for OO in Smalltalk, either. In a typical
implementation, SmallInteger is not a real class, in the sense that 2 is
not a real object. Instead, it lives in a tagged pointer, i.e. it has no
identity.

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


Re: Not fully OO ?

2008-09-21 Thread Fredrik Lundh

Martin v. Löwis wrote:


I don't think he meant that Python is wrong somehow, but that the OO
babble of what happens for 2+2 is wrong. The babble said that, when the
code is executed, an __add__ message is sent to the 2 object, with
another 2 object as the parameter. That statement is incorrect: no
message is sent at all, but the result is available even before the
program starts.


On the other hand, the inability to distinguish between "as if" and 
"hah, I've looked under the covers" isn't necessarily a good trait for a 
programmer.  If he bases his mental model on concrete implementation 
details of a production quality software product, he's bound to end up 
with a cargo-cultish understanding of fundamental issues.  If he uses it 
to win arguments, people will flip his bozo bit pretty quickly.




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


Re: Here's something interesting: sympy crashes in Python 2.6 (Windows)

2008-09-21 Thread Fredrik Lundh

Mensanator wrote:


I'm not the one who wrote sympy, so I guess I'm not
the only one who didn't notice it.

If it's a well known problem, then sorry I wasted
your time.


Given that 2.5 explicitly warns about this specific change:

>>> as = 1
:1: Warning: 'as' will become a reserved keyword in Python 2.6

it's an unknown issue only for people who has 1) never used their code 
under 2.5, or 2) never looks at the output produced by their programs.


The PEP-5 process guarantees that "users will have at least a year to 
test their programs and migrate them from use of the deprecated 
construct to the alternative one," and Python 2.5 was released *two* 
years ago.


So it sure looks like the SimPy folks ignored the established process. 
Why they've done that is probably a more interesting issue than the 
change itself.




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


Re: report a BUG of package setuptools-0.6c8.

2008-09-21 Thread Sebastien Douche
2008/9/20 Carl Banks <[EMAIL PROTECTED]>:
> On Sep 20, 1:11 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>> 为爱而生 wrote:
>> >   File "/usr/lib/python2.5/site-packages/setuptools/command/sdist.py",
>> > line 98, in entries_finder
>> > log.warn("unrecognized .svn/entries format in %s", dirname)
>> > NameError: global name 'log' is not defined
>>
>> > global name 'log' is not defined to the line 98!!!
>>
>> please report bugs here:
>>
>>  http://bugs.python.org/
>
> Does bugs.python.org track bugs for setuptools?  (Genuine question;
> the PEAK site doesn't list an obvious way to report bugs so I wonder
> if they're using bugs.python.org?  Hope not)
>
> If not, the OP should ask on the setuptools mailing list.

http://bugs.python.org/setuptools/

BTW, this blocker bug (Setuptools and SVN 1.5.x)  is known for 2 months *sigh*.

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

How to kill threading.Thread instance?

2008-09-21 Thread dmitrey
hi all,
Is there a better way to kill threading.Thread (running) instance than
this one
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960
(it's all I have found via google).

BTW, it should be noticed that lots of threading module methods have
no docstrings (in my Python 2.5), for example _Thread__bootstrap,
_Thread__stop.

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


Re: How to kill threading.Thread instance?

2008-09-21 Thread Diez B. Roggisch

dmitrey schrieb:

hi all,
Is there a better way to kill threading.Thread (running) instance than
this one
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960
(it's all I have found via google).



Nope. There might be other ways technically, but none of them falls into 
a "better"-classification.


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


Re: writeable buffer and struct.pack_into and struct.unpck_from

2008-09-21 Thread John Machin
On Sep 21, 3:16 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote:
> Thanks Gabriel,
> I was missing the information how to create a writable buffer.

array.array objects also have the writable buffer nature:

>>> import array
>>> b = array.array('c', '\0' * 10)
>>> b
array('c', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
>>> import struct
>>> struct.pack_into('>> b
array('c', '\x01\x00\x02\x00\xff\xff\x00\x80\x00\x00')

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


Re: How to kill threading.Thread instance?

2008-09-21 Thread Fredrik Lundh

dmitrey wrote:


BTW, it should be noticed that lots of threading module methods have
no docstrings (in my Python 2.5), for example _Thread__bootstrap,
_Thread__stop.


things named _Class__name are explicitly marked private by the 
implementation (using the "__" prefix).


using them just because you can find them via "dir" is a really stupid 
idea.  (and, as noted in the comment section to the recipe, the "stop" 
method flags a thread as stopped, it doesn't stop it.)




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


understanding list scope

2008-09-21 Thread Alex
Hi all!

I have a problem understanding the behaviour of this snippet:

data_set = ({"param":"a"},{"param":"b"},{"param":"c"})

for i in range(len(data_set)):
ds = data_set[:]
data = ds[i]
if i == 1: data['param'] = "y"
if i == 2: data['param'] = "x"

print data_set


This script print out:
({'param': 'a'}, {'param': 'y'}, {'param': 'x'})

Why? I'm coping data_set in ds so why data_set is changed?

Thanks in advance.

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


Re: understanding list scope

2008-09-21 Thread George Sakkis
On Sep 21, 8:51 am, Alex <[EMAIL PROTECTED]> wrote:
> Hi all!
>
> I have a problem understanding the behaviour of this snippet:
>
> data_set = ({"param":"a"},{"param":"b"},{"param":"c"})
>
> for i in range(len(data_set)):
>     ds = data_set[:]
>     data = ds[i]
>     if i == 1: data['param'] = "y"
>     if i == 2: data['param'] = "x"
>
> print data_set
>
> This script print out:
> ({'param': 'a'}, {'param': 'y'}, {'param': 'x'})
>
> Why? I'm coping data_set in ds so why data_set is changed?

Because you're doing a shallow copy: http://docs.python.org/lib/module-copy.html

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


Re: understanding list scope

2008-09-21 Thread alex23
On Sep 21, 10:51 pm, Alex <[EMAIL PROTECTED]> wrote:
> Why? I'm coping data_set in ds so why data_set is changed?

You're making a copy of the ds tuple, which has the -same- contents as
the original. To create copies of the contents as well, try the
deepcopy function from the copy module.

As an aside, you're also trying to make a copy of ds for each
iteration of the loop, which is unnecessary in this case. Here's a
slightly better example of your code:

>>> from copy import deepcopy
>>> data_set = ({"param":"a"},{"param":"b"},{"param":"c"})
>>> ds = deepcopy(data_set)
>>> for i, data in enumerate(ds):
... if i == 1: data['param'] = "y"
... if i == 2: data['param'] = "x"
...
>>> print data_set
({'param': 'a'}, {'param': 'b'}, {'param': 'c'})
>>> print ds
({'param': 'a'}, {'param': 'y'}, {'param': 'x'})

Although your use of a tuple full of dicts for data_set is kinda
strange... Tuples are generally used when you want a structured data
element, in which case you'd just address each element directly rather
than iterate through it:

>>> ds = deepcopy(data_set)
>>> ds[1]['param'] = "y"
>>> ds[2]['param'] = "x"



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


Re: understanding list scope

2008-09-21 Thread Alex
On 21 Set, 15:07, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Sep 21, 8:51 am, Alex <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi all!
>
> > I have a problem understanding the behaviour of this snippet:
>
> > data_set = ({"param":"a"},{"param":"b"},{"param":"c"})
>
> > for i in range(len(data_set)):
> > ds = data_set[:]
> > data = ds[i]
> > if i == 1: data['param'] = "y"
> > if i == 2: data['param'] = "x"
>
> > print data_set
>
> > This script print out:
> > ({'param': 'a'}, {'param': 'y'}, {'param': 'x'})
>
> > Why? I'm coping data_set in ds so why data_set is changed?
>
> Because you're doing a shallow 
> copy:http://docs.python.org/lib/module-copy.html
>
> George

Thanks a lot. It was giving me and headache!
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to kill threading.Thread instance?

2008-09-21 Thread dmitrey
I wonder why something like myThread.exit() or myThread.quit() or
threading.kill(myThread) can't be implemented?
Is something like that present in Python 3000?
Regards, D.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to kill threading.Thread instance?

2008-09-21 Thread Diez B. Roggisch

dmitrey schrieb:

I wonder why something like myThread.exit() or myThread.quit() or
threading.kill(myThread) can't be implemented?
Is something like that present in Python 3000?


Not that I'm aware of it (which doesn't mean to much though).

However I *am* aware of the bazillions discussions that have been held 
over this here - and the short answer is: it is a generally very bad 
idea to terminate threads hard, as it can cause all kinds of corruption.


Systems like Java discourage the use of the available methods for that 
as well. And I for example once worked with Qt3-threads, what allow for 
this kind of operation - and killed my CORBA-ORB running in the same 
process by terminating the thread hard.


Google a bit in this NG to find the discussions & reasons.

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


Re: How to kill threading.Thread instance?

2008-09-21 Thread Fredrik Lundh

Diez B. Roggisch wrote:


I wonder why something like myThread.exit() or myThread.quit() or
threading.kill(myThread) can't be implemented?
Is something like that present in Python 3000?


Not that I'm aware of it (which doesn't mean to much though).

However I *am* aware of the bazillions discussions that have been held 
over this here - and the short answer is: it is a generally very bad 
idea to terminate threads hard, as it can cause all kinds of corruption.


the problem is that you have no idea what the thread is doing, so just 
killing it dead it may make one big mess out of the application's 
internal state; see e.g. this post


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

  That's wise ;-)  Stopping a thread asynchronously is in /general/ a
  dangerous thing to do, and for obvious reasons.  For example, perhaps
  the victim thread is running in a library routine at the time the
  asynch exception is raised, and getting forcibly ejected from the
  normal control flow leaves a library-internal mutex locked forever.
  Or perhaps a catch-all "finally:" clause in the library manages to
  release the mutex, but leaves the internals in an inconsistent state.

which links to a FAQ from Sun on this very topic:

http://java.sun.com/j2se/1.3/docs/guide/misc/threadPrimitiveDeprecation.html

(note that Java releases all mutexes when a thread is killed, but that's 
not much better, as the FAQ explains)


so as usual, the right thing to do is to do things in the right way.



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


Override the '+' symbol

2008-09-21 Thread Mr.SpOOn
Hi,
how can I override the '+' symbol (and other math symbols) so that it
can have a new behavior when applied to some objects?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Override the '+' symbol

2008-09-21 Thread Navtej Singh
http://docs.python.org/ref/numeric-types.html

On Sun, Sep 21, 2008 at 8:37 PM, Mr.SpOOn <[EMAIL PROTECTED]> wrote:

> Hi,
> how can I override the '+' symbol (and other math symbols) so that it
> can have a new behavior when applied to some objects?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: Override the '+' symbol

2008-09-21 Thread Fredrik Lundh

Mr.SpOOn wrote:


how can I override the '+' symbol (and other math symbols) so that it
can have a new behavior when applied to some objects?


see "Emulating Numeric Types" in the language reference:

http://www.python.org/doc/ref/numeric-types.html



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


Why are "broken iterators" broken?

2008-09-21 Thread Steven D'Aprano
According to the Python docs, once an iterator raises StopIteration, it 
should continue to raise StopIteration forever. Iterators that fail to 
behave in this fashion are deemed to be "broken":

http://docs.python.org/lib/typeiter.html

I don't understand the reasoning behind this. As I understand it, an 
iterator is something like a stream. There's no constraint that once a 
stream is empty it must remain empty forever.

Can somebody explain why "broken iterators" are broken?


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


Re: Why are "broken iterators" broken?

2008-09-21 Thread Fredrik Lundh

Steven D'Aprano wrote:

According to the Python docs, once an iterator raises StopIteration, it 
should continue to raise StopIteration forever. Iterators that fail to 
behave in this fashion are deemed to be "broken":


http://docs.python.org/lib/typeiter.html

I don't understand the reasoning behind this. As I understand it, an 
iterator is something like a stream. There's no constraint that once a 
stream is empty it must remain empty forever.


it's a design guideline, not an absolute rule.

but I disagree that an iterator is "something like a stream".  it's 
rather "something like a pointer or an index", that is, an object that 
helps you iterate over all members in a collection.




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


Deploying a Python Service on Apache Axis2

2008-09-21 Thread Heshan Suriyaarachchi
Hi guys,
 Apache Axis2/Java, is a popular open source Web service engine. It
currently supports exposing services written in Java, Javascript as Web
services. This article [1] discusses the Python data Binding that enable
exposing Web services written in Python.

[1] - http://wso2.org/library/articles/deploying-python-service-axis2
[2] - http://heshans.blogspot.com/2008/09/wso2-wsfjython-10-alpha.html
[3] - http://wso2.org/library/invoking-enterprise-web-services-using-jython

-- 
Regards,
Heshan Suriyaarachchi

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

Re: Problem with Python shell through Cygwin Screen (Python/Vim/Screen combo)

2008-09-21 Thread Ant
On Sep 19, 7:08 pm, Jason Tishler <[EMAIL PROTECTED]> wrote:
...
> There are known issues when trying to run a Windows program that
> directly accesses the console under Cygwin.  For example:
>
>    http://mail.python.org/pipermail/python-list/2004-June/21.html
>
> AFAICT, you will have to use Cygwin Python with screen.

Thanks for the info. Shame but - cygwin python for this setup it is
(Though I may hunt for a native windows port of screen rather than the
cygwin one.)

Cheers,

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


Re: Why are "broken iterators" broken?

2008-09-21 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 Fredrik Lundh <[EMAIL PROTECTED]> wrote:

> Steven D'Aprano wrote:
> 
> > According to the Python docs, once an iterator raises StopIteration, it 
> > should continue to raise StopIteration forever. Iterators that fail to 
> > behave in this fashion are deemed to be "broken":
> > 
> > http://docs.python.org/lib/typeiter.html
> > 
> > I don't understand the reasoning behind this. As I understand it, an 
> > iterator is something like a stream. There's no constraint that once a 
> > stream is empty it must remain empty forever.
> 
> it's a design guideline, not an absolute rule.
> 
> but I disagree that an iterator is "something like a stream".  it's 
> rather "something like a pointer or an index", that is, an object that 
> helps you iterate over all members in a collection.
> 
> 

There are plausible examples of collections which grow while you're 
iterating over them.  I'm thinking specifically of a queue in a 
multi-threaded application.  One thread pushes work onto the back of the 
queue while another pops from the front.  The queue could certainly go 
empty at times.  But, maybe a Python iterator is just the wrong way to 
model such behavior.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to make a reverse for loop in python?

2008-09-21 Thread Alex Snast
On Sep 21, 3:47 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sat, 20 Sep 2008 16:27:41 -0700, Alex Snast wrote:
> > Another quick question please, is the List data structure just a dynamic
> > array? If so how can you use static size array, linked list, AVL trees
> > etcetera.
>
> Before I answer your question, I should say that you can go a LONG way
> with just the standard Python built-in data structures list, dict and
> set, plus a handful of standard modules like array and collections. It's
> often (but not always) better to modify an algorithm to use a built-in
> data structure than to try to implement your own.
>
> The underlying data structure for lists is implementation specific. Only
> the behaviour is specified by the language.
>
> In the standard Python implementation written in C (usually known as
> "Python", although sometimes people explicitly describe it as CPython),
> lists are implemented as a fixed array of pointers. The array is
> periodically resized, either up or down, but only as needed. The largest
> consequence of that is that appending to the end of a list is much faster
> than inserting at the beginning of the list.
>
> Other implementations (IronPython, Jython, PyPy, CLPython...) are free to
> implement lists whatever way they need.
>
> If you want a static list, the simplest way is to create a list and
> simply not resize it. If you want to enforce that, here's a subclass to
> get you started:
>
> class StaticList(list):
>     def _resize(self):
>         raise RuntimeError("list can't be resized")
>     extend = append = pop = insert = remove = \
>     __delitem__ = __delslice__ = _resize
>
> I haven't dealt with __setitem__ or __setslice__, because they're more
> complicated: you need to make sure the slice you're setting has the same
> size as the bit you're replacing, so that this is allowed:
>
> mylist[3:6] = [1, 2, 3]
>
> but not these:
>
> mylist[3:6] = [1, 2]
> mylist[3:6] = [1, 2, 3, 4]
>
> As for linked lists and trees, don't worry about pointers, just go ahead
> and implement them.
>
> # basic, no-frills tree
> class Node(object):
>     def __init__(self, data, left=None, right=None):
>         self.left = left
>         self.right = right
>         self.info = data
>
> tree = Node('top of the tree')
> tree.left = Node('left subtree')
> tree.right = Node('right subtree', None, Node('another subtree'))
> t = tree.right.right
> t.left = Node('yet another subtree')
>
> etc.
>
> The CPython implementation of dict is a hash table, and dicts are
> extremely fast and efficient. So long as you don't mind losing the order
> of insertion, you won't beat dicts for speed and efficiency in anything
> you write in pure Python.
>
> --
> Steven

WOW you guys are really helpful, thanks everyone for all the replies.
Last question:

What IDE do you guys recommend, I'm currently using pydev.

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


Re: Why are "broken iterators" broken?

2008-09-21 Thread Fredrik Lundh

Roy Smith wrote:

There are plausible examples of collections which grow while you're 
iterating over them.  I'm thinking specifically of a queue in a 
multi-threaded application.  One thread pushes work onto the back of the 
queue while another pops from the front.  The queue could certainly go 
empty at times.  But, maybe a Python iterator is just the wrong way to 
model such behavior.


you probably want the consumer thread to block when it catches up with 
the producer, rather than exit.


(that's the default behaviour of Python's Queue object, btw)



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


I tried erlang-ish [1|2] in python and something came out...

2008-09-21 Thread process
In erlang you can cons like this: [1|2]. i tried this in python and it
didnt raise an error but i dont know what the result do

>>> [1|2]
[3]
>>> [2|2]
[2]
>>> a = [2|2]
>>> a
[2]
>>> [2|3]
[3]
>>> [2|1]
[3]
>>>
--
http://mail.python.org/mailman/listinfo/python-list


Re: I tried erlang-ish [1|2] in python and something came out...

2008-09-21 Thread Gary Herron

process wrote:

In erlang you can cons like this: [1|2]. i tried this in python and it
didnt raise an error but i dont know what the result do
  


In Python | is the logical bitwise-OR operator.   Look at the binary 
representation of the numbers to understand it.


Gary Herron

  

[1|2]


[3]
  

[2|2]


[2]
  

a = [2|2]
a


[2]
  

[2|3]


[3]
  

[2|1]


[3]
  
--

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


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


Re: curses.setsyx()?

2008-09-21 Thread linkmaster032000
On Sep 19, 6:42 pm, [EMAIL PROTECTED] wrote:
> On Sep 19, 1:24 am, Tim Roberts <[EMAIL PROTECTED]> wrote:
>
> > [EMAIL PROTECTED] wrote:
>
> > >I tried curses.setsyx(2,3) in my script and it doesn't move the curses
> > >cursor. Any alternatives/solutions?
>
> > Did you call doupdate after?  setsyx just manipulates the data structures.
> > It takes a call to doupdate to force those changes to take effect visually.
> > --
> > Tim Roberts, [EMAIL PROTECTED]
> > Providenza & Boekelheide, Inc.
>
> I added it and it still doesn't work. This is what I'm doing when I
> want to display the cursor and prepare it for input at 2,3:
>
> curses.echo()
> curses.curs_set(1)
> curses.setsyx(2,3)
> curses.doupdate()

Any idea what's wrong?
--
http://mail.python.org/mailman/listinfo/python-list


Re: I tried erlang-ish [1|2] in python and something came out...

2008-09-21 Thread Chris Rebert
On Sun, Sep 21, 2008 at 10:02 AM, process <[EMAIL PROTECTED]> wrote:
> In erlang you can cons like this: [1|2]. i tried this in python and it
> didnt raise an error but i dont know what the result do

In Python, like in C, the "|" operator on integers performs a bitwise-OR.
To "cons" nondestructively onto a list, do e.g. [head_value] + tail,
but note that this isn't very idiomatic.
CPython's lists are implemented internally as arrays, not linked
lists, hence why there's no "cons" operator in Python.
You may also be interested in list.append()

Regards,
Chris

>
 [1|2]
> [3]
 [2|2]
> [2]
 a = [2|2]
 a
> [2]
 [2|3]
> [3]
 [2|1]
> [3]

> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: BeautifulSoup and Problem Tables

2008-09-21 Thread Peter Pearson
On Sat, 20 Sep 2008 20:51:52 -0700 (PDT), [EMAIL PROTECTED] wrote:
[snip]
> from BeautifulSoup import BeautifulSoup
> bst=file(r"c:\bstest.htm").read()
> soup=BeautifulSoup(bst)
> rows=soup.findAll('tr')
> len(rows)
> a=len(rows[0].findAll('td'))
> b=len(rows[1].findAll('td'))
> c=len(rows[2].findAll('td'))
> d=len(rows[3].findAll('td'))
> e=len(rows[4].findAll('td'))
> f=len(rows[5].findAll('td'))
> g=len(rows[6].findAll('td'))
> h=len(rows[8].findAll('td'))
> i=len(rows[9].findAll('td'))
> j=len(rows[10].findAll('td'))
> k=rows[1].findAll('td')[1].contents[0]
[snip]
> However, I discovered that my tables have inconsistent numbers of
> rows.  
[snip]
> I have been Googling for some insight into this and I have not been
> successful finding anything. I would really appreciate any suggestions
> or some direction about how to better describe the problem.

Would it be accurate to describe the problem as wanting to
extract the contents of the cth column of the rth row of a
table in spite of various pathologies in the construction of
the table?

If so, maybe it would help to post sample HTML (trimmed to a
minimum) of the pathologies that must be handled.  I gotta
confess, though, that it doesn't take many rowspans or colspans
to put this problem beyond my reach.

-- 
To email me, substitute nowhere->spamcop, invalid->net.
--
http://mail.python.org/mailman/listinfo/python-list


Some questions about PyOpenGL and wxPython

2008-09-21 Thread Clay Hobbs
I am making a program with wxPython that renders objects in 3D using
PyOpenGL, and I am having some problems.  For one thing, I forgot how to
make a double-buffered hardware surface.  For another thing,
glColor(1.0, 0.0, 0.0) just before the rendering doesn't make the object
red.  Please help, I'm a total noob to OpenGL.

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


Milenko Kindl rtegdgd

2008-09-21 Thread yuma
Milenko Kindl
Banja Luka
Banjaluka
Bihac
--
http://mail.python.org/mailman/listinfo/python-list


Re: understanding list scope

2008-09-21 Thread Peter Pearson
On Sun, 21 Sep 2008 06:17:36 -0700 (PDT), Alex wrote:
> On 21 Set, 15:07, George Sakkis <[EMAIL PROTECTED]> wrote:
>> On Sep 21, 8:51 am, Alex <[EMAIL PROTECTED]> wrote:
[snip]
>> > I have a problem understanding the behaviour of this snippet:
[snip]
>> Because you're doing a shallow copy:
>> http://docs.python.org/lib/module-copy.html
[snip]
> Thanks a lot. It was giving me and headache!

FWIW, since I started following this newsgroup, I've noticed
that I no longer have those crises that revolve around the depth
of a copy.  I conjecture that they resulted from non-pythonic
style.  Try following this newsgroup for a while, and you might
see a lot of startlingly elegant ways of doing things.

-- 
To email me, substitute nowhere->spamcop, invalid->net.
--
http://mail.python.org/mailman/listinfo/python-list


Re: NEW GENERATED DLL ERROR FOUND WITHIN f2PY.py

2008-09-21 Thread Gabriel Genellina
En Sat, 20 Sep 2008 16:07:12 -0300, Blubaugh, David A.  
<[EMAIL PROTECTED]> escribió:


Let me state that do have extensive experience with developing binary  
files.  Please note that I have followed all of the instructions to the  
letter as far as developing a DLL to be imported.  However, it is not  
working correctly.  I believe it might be my system environment  
variables??


It might be the sunspots (or the lack of them) as well.
You could start telling us what's your platform, which instructions have  
you followed, which compiler have you used...


--
Gabriel Genellina

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


Re: report a BUG of package setuptools-0.6c8.

2008-09-21 Thread Gabriel Genellina
En Sun, 21 Sep 2008 06:46:54 -0300, Sebastien Douche <[EMAIL PROTECTED]>  
escribió:



2008/9/20 Carl Banks <[EMAIL PROTECTED]>:

On Sep 20, 1:11 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:

为爱而生 wrote:
>   File  
"/usr/lib/python2.5/site-packages/setuptools/command/sdist.py",

> line 98, in entries_finder
> log.warn("unrecognized .svn/entries format in %s", dirname)
> NameError: global name 'log' is not defined

> global name 'log' is not defined to the line 98!!!

please report bugs here:

 http://bugs.python.org/


Does bugs.python.org track bugs for setuptools?  (Genuine question;
the PEAK site doesn't list an obvious way to report bugs so I wonder
if they're using bugs.python.org?  Hope not)


http://bugs.python.org/setuptools/


And how do people manage to know that?

--
Gabriel Genellina

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

Re: Some questions about PyOpenGL and wxPython

2008-09-21 Thread Mike C. Fletcher

Clay Hobbs wrote:

I am making a program with wxPython that renders objects in 3D using
PyOpenGL, and I am having some problems.  For one thing, I forgot how to
make a double-buffered hardware surface.

http://bazaar.launchpad.net/~mcfletch/openglcontext/trunk/annotate/1?file_id=wxcontext.py-20080920224554-ehwlv3u6uc6sb6e2-55

See method wxFlagsFromDefinition, particularly glcanvas.WX_GL_DOUBLEBUFFER

  For another thing,
glColor(1.0, 0.0, 0.0) just before the rendering doesn't make the object
red.  Please help, I'm a total noob to OpenGL.
  
Would have to see what you're doing to know what's wrong there.  glColor 
should be working.


HTH,
Mike

--

 Mike C. Fletcher
 Designer, VR Plumber, Coder
 http://www.vrplumber.com
 http://blog.vrplumber.com

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


Newick parser

2008-09-21 Thread aditya shukla
Hello folks , i have a .nwk file.I want to parser the tree from that file.I
found this python parser for newick trees.
http://www.daimi.au.dk/~mailund/newick.html

But i don't understand the usage properly.What i wanna do is if i have a
file in the location c:\\files\\file1.nwk , then i wanna parse the trees in
that file.

Please help me if someone has experience on how to use this module.


Thanks

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

Re: Newick parser

2008-09-21 Thread Fredrik Lundh

aditya shukla wrote:

Hello folks , i have a .nwk file.I want to parser the tree from that 
file.I found this python parser for newick trees.

http://www.daimi.au.dk/~mailund/newick.html

But i don't understand the usage properly.What i wanna do is if i have a 
file in the location c:\\files\\file1.nwk , then i wanna parse the trees 
in that file.


judging from the docs, you should be able to do e.g.

  from newick import parse_tree

  file = open("c:\\files\\file1.nwk")
  text = file.read()

  print parse_tree(text)



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


Re: Here's something interesting: sympy crashes in Python 2.6 (Windows)

2008-09-21 Thread Mensanator
On Sep 21, 4:37 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Mensanator wrote:
> > I'm not the one who wrote sympy, so I guess I'm not
> > the only one who didn't notice it.
>
> > If it's a well known problem, then sorry I wasted
> > your time.
>
> Given that 2.5 explicitly warns about this specific change:
>
>  >>> as = 1
> :1: Warning: 'as' will become a reserved keyword in Python 2.6

Uh...how come _I_ don't see that?

In IDLE, I get:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32

IDLE 1.2
>>> as = 1
SyntaxError: invalid syntax


When inside a script, I get:

as = 1
print as
>>> == RESTART ==
>>>
1


>
> it's an unknown issue only for people who has 1) never used their code
> under 2.5, or 2) never looks at the output produced by their programs.
>
> The PEP-5 process guarantees that "users will have at least a year to
> test their programs and migrate them from use of the deprecated
> construct to the alternative one," and Python 2.5 was released *two*
> years ago.
>
> So it sure looks like the SimPy folks ignored the established process.
> Why they've done that is probably a more interesting issue than the
> change itself.

Is there something wrong with my (and Sympy's) version
of Python that we don't see these warnings?

>
> 

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


Re: Why are "broken iterators" broken?

2008-09-21 Thread Terry Reedy

Steven D'Aprano wrote:
According to the Python docs, once an iterator raises StopIteration, it 
should continue to raise StopIteration forever. Iterators that fail to 
behave in this fashion are deemed to be "broken":


http://docs.python.org/lib/typeiter.html

I don't understand the reasoning behind this. As I understand it, an 
iterator is something like a stream. There's no constraint that once a 
stream is empty it must remain empty forever.


It is quite possible that a stream reader will return '' on one call and 
 then something non-empty the next.  An iterator that reads a stream 
and yields chunks of whatever size should either block until it gets 
sufficient data or yield nulls as long as the stream is open and not 
raise StopIteration until the steam is closed and it has yielded the 
last chunk of data.



Can somebody explain why "broken iterators" are broken?


There is an important different between a store that is closed until the 
next day and one that closed - out of business.  Similarly, there is a 
difference between an item being out-of-stock until the next delivery 
and out-of-stock and discontinued permanently, or between a road closed 
for repairs versus removal for something else.  Using the same sign or 
signal for temporary and permanent conditions is confusing and therefore 
 'broken'.


Terry Jan Reedy

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


Re: How to kill threading.Thread instance?

2008-09-21 Thread Fuzzyman
On Sep 21, 4:04 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Diez B. Roggisch wrote:
> >> I wonder why something like myThread.exit() or myThread.quit() or
> >> threading.kill(myThread) can't be implemented?
> >> Is something like that present in Python 3000?
>
> > Not that I'm aware of it (which doesn't mean to much though).
>
> > However I *am* aware of the bazillions discussions that have been held
> > over this here - and the short answer is: it is a generally very bad
> > idea to terminate threads hard, as it can cause all kinds of corruption.
>
> the problem is that you have no idea what the thread is doing, so just
> killing it dead it may make one big mess out of the application's
> internal state; see e.g. this post
>
>    http://mail.python.org/pipermail/python-list/2006-August/400256.html
>
>    That's wise ;-)  Stopping a thread asynchronously is in /general/ a
>    dangerous thing to do, and for obvious reasons.  For example, perhaps
>    the victim thread is running in a library routine at the time the
>    asynch exception is raised, and getting forcibly ejected from the
>    normal control flow leaves a library-internal mutex locked forever.
>    Or perhaps a catch-all "finally:" clause in the library manages to
>    release the mutex, but leaves the internals in an inconsistent state.
>
> which links to a FAQ from Sun on this very topic:
>
> http://java.sun.com/j2se/1.3/docs/guide/misc/threadPrimitiveDeprecati...
>
> (note that Java releases all mutexes when a thread is killed, but that's
> not much better, as the FAQ explains)
>
> so as usual, the right thing to do is to do things in the right way.
>
> 

Often you know terminated a thread would be perfectly safe - and not
being able to is very frustrating - particularly if your calculation
is coarse grained and there is no convenient point to regularly poll
for a stop signal.

.NET solves the 'you might interrupt important stuff' by guaranteeing
that an asynchronous ThreadAbortException won't be raised inside a
finally block.

Michael
http://www.ironpythoninaction.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Milenko Kindl rtegdgd

2008-09-21 Thread H Vlems
On 21 sep, 19:48, yuma <[EMAIL PROTECTED]> wrote:
> Milenko Kindl
> Banja Luka
> Banjaluka
> Bihac

Well, that's not C isn't it, more like Snobol or RPG/2
--
http://mail.python.org/mailman/listinfo/python-list


Twisted: Get Protected HTTPS Page via Proxy with Authentication

2008-09-21 Thread Robert Hancock
from twisted.web import client
from twisted.internet import reactor
import base64
import sys

def printPage(data):
print data
reactor.stop()

def printError(failure):
print >> sys.stderr, "Error:", failure.getErrorMessage()
reactor.stop()

if len(sys.argv) == 4:
url = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]

basicAuth = base64.encodestring('%s:%s' % (username, password))
authHeader = "Basic " + basicAuth.strip()

client.getPage(url, headers={"Authorization":
authHeader}).addCallback(printPage).addErrback(printError)
reactor.run()
else:
print 'Usage: get_web_page.py '

If I run this against a password protected HTTP(S) site from a host
that has direct access to the Internet it works fine.  I now have to
move it behind a proxy that requires authentication.  The Twisted
documentation did not make it clear (to me) how to add proxy
authentication and I cannot find an example on the Internet.

I've tried adding an additional Proxy-Authentication header to the
call, but that doesn't help  Any ideas would be greatly appreciated.

Command line args: http://feedparser.org/docs/examples/basic_auth.xml
test basic
--
http://mail.python.org/mailman/listinfo/python-list


Re: Milenko Kindl rtegdgd

2008-09-21 Thread Martin Griffith
On Sun, 21 Sep 2008 15:00:16 -0700 (PDT), in sci.electronics.design H
Vlems <[EMAIL PROTECTED]> wrote:

>On 21 sep, 19:48, yuma <[EMAIL PROTECTED]> wrote:
>> Milenko Kindl
>> Banja Luka
>> Banjaluka
>> Bihac
>
>Well, that's not C isn't it, more like Snobol or RPG/2
It's better to say
"that's not C, is it"

I don't know why, but that's the way it works.

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


Re: report a BUG of package setuptools-0.6c8.

2008-09-21 Thread Sebastien Douche
On Sun, Sep 21, 2008 at 19:56, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>> http://bugs.python.org/setuptools/
>
> And how do people manage to know that?

Bugtracker send emails on setuptools mailing list.

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


Re: how can i check whether a variable is iterable in my code?

2008-09-21 Thread James Mills
satoru,

I should point out that the normal
approach is to just try whatever it
is that you're doing, and let it fail
where it fails. For example:

def processSeq(x):
   for i in x:
  print i

processSeq([1, 2, 3])
processSeq("foobar")
processSeq(5) <-- This will fail.

cheers
James

On Sat, Sep 20, 2008 at 7:28 PM, satoru <[EMAIL PROTECTED]> wrote:
> hi, all
> i want to check if a variable is iterable like a list, how can i
> implement this?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


What do you call a class not intended to be instantiated

2008-09-21 Thread Steven D'Aprano
I have a class which is not intended to be instantiated. Instead of using 
the class to creating an instance and then operate on it, I use the class 
directly, with classmethods. Essentially, the class is used as a function 
that keeps state from one call to the next.

The problem is that I don't know what to call such a thing! "Abstract 
class" isn't right, because that implies that you should subclass the 
class and then instantiate the subclasses.

What do you call such a class?



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


RE: NEW GENERATED DLL ERROR FOUND WITHIN f2PY.py

2008-09-21 Thread Blubaugh, David A.
Sir,
 
Thank you for your reply.  This is as to how I developed my .pyd file.  I 
entered the following commands within my MS-DOS prompt within Windows XP:

C:\python25\Scripts> C:\python25\python  f2py.py -c --fcompiler=gnu95 
--compiler=mingw32 -m hello hello.f90

I am using the gfortran compiler, that was prescribed to use, as well as, the 
required commands on the following website:

http://www.scipy.org/F2PY_Window 

 

I comes down to that yes, I am able to generate a .pyd file, which was 
generated by f2py.  However, when I tried to import this file into my python 
script program I was given the following error:
 
 error 193?? 
 
I do not know as to what I am doing incorrectly, since I am generating a .pyd 
file by f2py?  If I am doing anything that is incorrect, then why am I EVEN 
ABLE TO GENERATE A .PYD FILE IN THE FIRST PLACE???   Any Help will be greatly 
appreciated!
 
Thanks,
 
David Blubaugh
 



From: Gabriel Genellina [mailto:[EMAIL PROTECTED]
Sent: Sun 9/21/2008 1:55 PM
To: python-list@python.org
Subject: Re: NEW GENERATED DLL ERROR FOUND WITHIN f2PY.py



En Sat, 20 Sep 2008 16:07:12 -0300, Blubaugh, David A. 
<[EMAIL PROTECTED]> escribió:

> Let me state that do have extensive experience with developing binary 
> files.  Please note that I have followed all of the instructions to the 
> letter as far as developing a DLL to be imported.  However, it is not 
> working correctly.  I believe it might be my system environment 
> variables??

It might be the sunspots (or the lack of them) as well.
You could start telling us what's your platform, which instructions have 
you followed, which compiler have you used...

--
Gabriel Genellina





This e-mail transmission contains information that is confidential and may be 
privileged. It is intended only for the addressee(s) named above. If you 
receive 
this e-mail in error, please do not read, copy or disseminate it in any manner. 
If you are not the intended recipient, any disclosure, copying, distribution or 
use of the contents of this information is prohibited. Please reply to the 
message immediately by informing the sender that the message was misdirected. 
After replying, please erase it from your computer system. Your assistance in 
correcting this error is appreciated.

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


appending * to glob returns files with '*' !!

2008-09-21 Thread John [H2O]

I have a glob.glob search:

searchstring = os.path.join('path'+'EN*')
files = glob.glob(searchstring)
for f in files:
 print f


___
This returns some files:
EN082333
EN092334
EN*

My routine cannot handle the '*' and it should'nt be returned anyway? :-/

A bug?



-- 
View this message in context: 
http://www.nabble.com/appending-*-to-glob-returns-files-with-%27*%27-%21%21-tp19579121p19579121.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: What do you call a class not intended to be instantiated

2008-09-21 Thread James Mills
Hi,

Wouldn't a normal class called State
suffice for storing state between calls ?
And ... Creating a state instance ?

For example:

class State(object):
   """State() -> new state object

   Creates a new state object that is suitable
   for holding different states of an application.
   Usefull in state-machines.

   The way this works is rather simple. You create a new
   state object, and simply set the state. If the state
   doesn't exist, it's added to it's internal data
   structure. The reason this is done is so that
   comparing states is consistent, and you can't just
   compare with a non-existent state.
   """

   def __init__(self):
  "initializes x; see x.__class__.__doc__ for signature"

  self._states = {}
  self._next = 0

  # Default States

  self._add("START")
  self._add("DONE")

   def __repr__(self):
  try:
 return "" % self._state
  except AttributeError:
 return ""

   def __str__(self):
  return self._state

   def __eq__(self, s):
  return s in self._states and self._state == s

   def __lt__(self, s):
  return s in self._states and self._state == s and \
self._states[s] < self._states[self._state]

   def __gr__(self, s):
  return s in self._states and self._state == s and \
self._states[s] > self._states[self._state]

   def _add(self, s):
  self._states[s] = self._next
  self._next = self._next + 1

   def set(self, s):
  """S.set(s) -> None

  Set the current state to the specified state given by s,
  adding it if it doesn't exist.
  """

  if s not in self._states:
 self._add(s)

  self._state = s

cheers
James

On Mon, Sep 22, 2008 at 8:39 AM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> I have a class which is not intended to be instantiated. Instead of using
> the class to creating an instance and then operate on it, I use the class
> directly, with classmethods. Essentially, the class is used as a function
> that keeps state from one call to the next.
>
> The problem is that I don't know what to call such a thing! "Abstract
> class" isn't right, because that implies that you should subclass the
> class and then instantiate the subclasses.
>
> What do you call such a class?
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you call a class not intended to be instantiated

2008-09-21 Thread Steven D'Aprano
Fixing top-posting.

On Mon, 22 Sep 2008 08:54:43 +1000, James Mills wrote:

> On Mon, Sep 22, 2008 at 8:39 AM, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote:
>> I have a class which is not intended to be instantiated. Instead of
>> using the class to creating an instance and then operate on it, I use
>> the class directly, with classmethods. Essentially, the class is used
>> as a function that keeps state from one call to the next.

[...]
 
> Hi,
> 
> Wouldn't a normal class called State
> suffice for storing state between calls ? And ... Creating a state
> instance ?
> 
> For example:
[snip]

That's a rather big example for a rather small question.

Yes, a normal class would work in many cases. In this case, the class 
itself is being produced by a factory function, and it's output is an 
iterator. Having to call:

cls = factory()
instance = cls()
result = instance()

to get anything done seems excessive, even if you write it as a one-liner 
result = factory()()().

I'm not wedded to the idea, there are alternatives (perhaps the factory 
should instantiate the class and return that?) but I assume others have 
used this design and have a name for it.


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


Re: appending * to glob returns files with '*' !!

2008-09-21 Thread Sean DiZazzo
On Sep 19, 1:37 pm, "John [H2O]" <[EMAIL PROTECTED]> wrote:
> I have a glob.glob search:
>
> searchstring = os.path.join('path'+'EN*')

shouldn't that be  os.path.join(path, 'EN*')  ?

> ___
> This returns some files:
> EN082333
> EN092334
> EN*

Mine doesn't return that last string.

>
> My routine cannot handle the '*' and it should'nt be returned anyway? :-/
>
Well, its an easy fix.

files = glob.glob(searchstring)
for f in files:
  if not f[-1] =="*":
   print f

> A bug?

Post a small *tested* example that recreates the error on your system.

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


Re: What do you call a class not intended to be instantiated

2008-09-21 Thread James Mills
On Mon, Sep 22, 2008 at 9:05 AM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> I'm not wedded to the idea, there are alternatives (perhaps the factory
> should instantiate the class and return that?) but I assume others have
> used this design and have a name for it.

The problem is, I don't see why you're using a class
to store state in the first place.

cheers
James

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you call a class not intended to be instantiated

2008-09-21 Thread Calvin Spealman
I call it an obvious misuse and misunderstanding of why you'd use a class in
the first place. Either create an instance and not make these things
classmethods or just share the stuff in a module-level set of variables. But
the instantiating is the best options. Your class attributes might not be
globals, but you're still using global state and you should avoid it where
you can.

On Sun, Sep 21, 2008 at 6:39 PM, Steven D'Aprano <
[EMAIL PROTECTED]> wrote:

> I have a class which is not intended to be instantiated. Instead of using
> the class to creating an instance and then operate on it, I use the class
> directly, with classmethods. Essentially, the class is used as a function
> that keeps state from one call to the next.
>
> The problem is that I don't know what to call such a thing! "Abstract
> class" isn't right, because that implies that you should subclass the
> class and then instantiate the subclasses.
>
> What do you call such a class?
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing:
http://www.twitter.com/ironfroggy
--
http://mail.python.org/mailman/listinfo/python-list

Re: What do you call a class not intended to be instantiated

2008-09-21 Thread bearophileHUGS
Steven D'Aprano:
> I have a class which is not intended to be instantiated. Instead of using
> the class to creating an instance and then operate on it, I use the class
> directly, with classmethods. Essentially, the class is used as a function
> that keeps state from one call to the next.

You may use a module too for that, with normal functions inside, plus
module variables that keep the state. Modules can't be instantiated, I
think.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: appending * to glob returns files with '*' !!

2008-09-21 Thread alex23
On Sep 20, 6:37 am, "John [H2O]" <[EMAIL PROTECTED]> wrote:
> My routine cannot handle the '*' and it should'nt be returned anyway? :-/
>
> A bug?

Not at all. That's the same behaviour you'll get if you do 'ls EN*'.

In your case, you're asking to match on anything that begins with EN,
a subset of files that -includes- EN*.

Why do you consider this behaviour surprising?
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you call a class not intended to be instantiated

2008-09-21 Thread James Mills
On Mon, Sep 22, 2008 at 9:39 AM, Calvin Spealman <[EMAIL PROTECTED]> wrote:
> I call it an obvious misuse and misunderstanding of why you'd use a class in
> the first place. Either create an instance and not make these things
> classmethods or just share the stuff in a module-level set of variables. But
> the instantiating is the best options. Your class attributes might not be
> globals, but you're still using global state and you should avoid it where
> you can.

I concur. Use a _proper_  state object that you share
amongst your other objects. For instance, in many of
my systems and applications I write, I often have
an "Environment" instance, which is a container
object that holds other objects required by parts
of the system. Every other component/object in the
system that is instantiated recievees exactly one
instnace of thie "Environment" called, "env".

Accessing shared states amongst components/objects
within the system is as simple as this:

class Foo(object):

   def __init__(self, env, *args, **kwargs):
  self.env = env

   def foo(self):
  if self.env.some_state:
 print "Do something useful"

env = Environment()
foo = Foo(env)
foo.foo()

cheers
James

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you call a class not intended to be instantiated

2008-09-21 Thread Aaron "Castironpi" Brady
On Sep 21, 6:05 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> Fixing top-posting.
>
> On Mon, 22 Sep 2008 08:54:43 +1000, James Mills wrote:
> > On Mon, Sep 22, 2008 at 8:39 AM, Steven D'Aprano
> > <[EMAIL PROTECTED]> wrote:
> >> I have a class which is not intended to be instantiated. Instead of
> >> using the class to creating an instance and then operate on it, I use
> >> the class directly, with classmethods. Essentially, the class is used
> >> as a function that keeps state from one call to the next.
>
> [...]
>
> > Hi,
>
> > Wouldn't a normal class called State
> > suffice for storing state between calls ? And ... Creating a state
> > instance ?
>
> > For example:
>
> [snip]
>
> That's a rather big example for a rather small question.
>
> Yes, a normal class would work in many cases. In this case, the class
> itself is being produced by a factory function, and it's output is an
> iterator. Having to call:
>
> cls = factory()
> instance = cls()
> result = instance()
>
> to get anything done seems excessive, even if you write it as a one-liner
> result = factory()()().
>
> I'm not wedded to the idea, there are alternatives (perhaps the factory
> should instantiate the class and return that?) but I assume others have
> used this design and have a name for it.
>
> --
> Steven

Do you want anything from it that a dictionary doesn't have, besides
the dot-member access?
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you call a class not intended to be instantiated

2008-09-21 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> I have a class which is not intended to be instantiated. Instead of
> using the class to creating an instance and then operate on it, I
> use the class directly, with classmethods. Essentially, the class is
> used as a function that keeps state from one call to the next.

Classes aren't designed to keep state; state is kept in instances.

I think you want Alex Martelli's 'Borg' pattern
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531>,
which is a class where each instance shares the same state.

-- 
 \ “Pinky, are you pondering what I'm pondering?” “I think so, |
  `\ Brain, but there's still a bug stuck in here from last time.” |
_o__)   —_Pinky and The Brain_ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

pause between the loops

2008-09-21 Thread Jackie Wang
Hi all,

For a loop like:

for i = range (0,10);

can I ask python to stop for, say, 5mins, after it go through loop i=0
before it starts loop i=1?

Thank you very much!

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


Re: appending * to glob returns files with '*' !!

2008-09-21 Thread Erik Max Francis

John [H2O] wrote:


I have a glob.glob search:

searchstring = os.path.join('path'+'EN*')
files = glob.glob(searchstring)
for f in files:
 print f


___
This returns some files:
EN082333
EN092334
EN*

My routine cannot handle the '*' and it should'nt be returned anyway? :-/

A bug?


No, it means you actually have a file named 'EN*' in the directory.

--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
 San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
  Many would be cowards if they had courage enough.
   -- Thomas Fuller
--
http://mail.python.org/mailman/listinfo/python-list


Re: pause between the loops

2008-09-21 Thread skip

Jackie> can I ask python to stop for, say, 5mins, after it go through
Jackie> loop i=0 before it starts loop i=1?

import time

for i in range(10):
time.sleep(5) # seconds



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


Re: Milenko Kindl rtegdgd

2008-09-21 Thread Michael A. Terrell

H Vlems wrote:
> 
> On 21 sep, 19:48, yuma <[EMAIL PROTECTED]> wrote:
> > Milenko Kindl
> > Banja Luka
> > Banjaluka
> > Bihac
> 
> Well, that's not C isn't it, more like Snobol or RPG/2


   Tidybowl


-- 
http://improve-usenet.org/index.html

aioe.org, Goggle Groups, and Web TV users must request to be white
listed, or I will not see your messages.

If you have broadband, your ISP may have a NNTP news server included in
your account: http://www.usenettools.net/ISP.htm


There are two kinds of people on this earth:
The crazy, and the insane.
The first sign of insanity is denying that you're crazy.
--
http://mail.python.org/mailman/listinfo/python-list


Re: BeautifulSoup and Problem Tables

2008-09-21 Thread clurks
[EMAIL PROTECTED] wrote:

> Hi
> 
> I would appreciate some help.  I am trying to learn Python and want to
> use BeautifulSoup to pull some data from tables.  I was really psyched
> earlier tonight when I discovered that I could do this
> 
> from BeautifulSoup import BeautifulSoup
> bst=file(r"c:\bstest.htm").read()
> soup=BeautifulSoup(bst)
> rows=soup.findAll('tr')
> len(rows)
> a=len(rows[0].findAll('td'))
> b=len(rows[1].findAll('td'))
> c=len(rows[2].findAll('td'))
> d=len(rows[3].findAll('td'))
> e=len(rows[4].findAll('td'))
> f=len(rows[5].findAll('td'))
> g=len(rows[6].findAll('td'))
> h=len(rows[8].findAll('td'))
> i=len(rows[9].findAll('td'))
> j=len(rows[10].findAll('td'))
> k=rows[1].findAll('td')[1].contents[0]
> 
> 
> So here I am chortling to myself thinking this is too easy.  I know
> that the data columns are in rows[0] and so I can learn some more
> python to figure out how to create tuples so I can lable each data
> item using the row and column headings plucked from the contents.
> 
> However, I discovered that my tables have inconsistent numbers of
> rows.  Even though the tables look pretty.  It might be that the
> column heading for the third column is "Apples" but the value for
> "Apples" in the fourth row is not in the third position in the row but
> the fourth.
> 
> Now I am reluctant to make any assumptions because the tables were
> created inconsistently. What I mean is that in some tables if there is
> no value for a row/column intersection then there is a blank line, in
> other tables if there is no value for a row/column intersection then
> the length of  k (as above) is 0.
> 
> I have been Googling for some insight into this and I have not been
> successful finding anything. I would really appreciate any suggestions
> or some direction about how to better describe the problem.

This may help, and it may not.

One of the most useful features of BeautifulSoup is the .prettify()
function.  Use it, and you can examine your xml with a browser or
decent editor.  You will be able, hopefully, to see attributes that
may explain your difficulties.  The one that snuck up and bit me was
table:number-columns-repeated -- I don't know what is biting you,
but it is weird the way known cells are completely skipped with this
attribute -- you have to know about it and check for it.

If there is a way to deal with that attribute using BeautifulSoup I
was unable to find it given the documentation and examples available
to me.  I took a step back and tried xml.sax -- it is straighforward
and easy to use -- you build an xml.sax.handler for your xml, and it
deals with it.

It worked for me, but, as always, YMMV

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


New Web2Py framework SLASHES development time...

2008-09-21 Thread Steve Shephed
http://www.web2py.com Web2Py - Python Framework is the newest
kid on the block for Python frameworks.

It has a lot of features that simply are not there in other
frameworks. Even Ruby!. You can design database models graphically
online.

The templating language is pure python and there are no problems with
indenting.

The models are auto-migrating which allows easy updating of your
database schema's. Parent-child and Super-Sub Set type models are
completely supported.
Uses an advanced MVC pattern. At least 10 free applications ready to
download and use in your own developments.
Can be run from a USB stick. ZERO installation just click on the exe
and away you go with web server and complete graphical admin
interface.

PLUS it will work on Google App Engine (your still constrained by the
Google Storage Limitations but you don't have to change any database
model code at all). AND Complete International Support (with a
graphical admin interface to add different languages)...there is more
but just take a visit...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Milenko Kindl rtegdgd

2008-09-21 Thread Jim Thompson

On Sun, 21 Sep 2008 22:26:27 -0400, "Michael A. Terrell"
<[EMAIL PROTECTED]> wrote:

>
>H Vlems wrote:
>> 
>> On 21 sep, 19:48, yuma <[EMAIL PROTECTED]> wrote:
>> > Milenko Kindl
>> > Banja Luka
>> > Banjaluka
>> > Bihac
>> 
>> Well, that's not C isn't it, more like Snobol or RPG/2
>
>
>   Tidybowl

I thought you blanked googlegroups, n'est ce pas ?:-)

...Jim Thompson
-- 
| James E.Thompson, P.E.   |mens |
| Analog Innovations, Inc. | et  |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |manus|
| Phoenix, Arizona  85048Skype: Contacts Only  | |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |1962 |
 
 I love to cook with wine Sometimes I even put it in the food
--
http://mail.python.org/mailman/listinfo/python-list


Question about sorted in Python 3.0rc1

2008-09-21 Thread josh logan
Hello,


I have 2 questions. Say I have this class:

class Player(object):
def __init__(self, fname, lname, score):
self.score = score
self.fname = fname
self.lname = lname
def __cmp__(self, other):
return (-cmp(self.score, other.score) or
cmp(self.lname, other.lname) or
cmp(self.fname, other.fname))
def __repr__(self):
return 'Player(fname={0.fname}, lname={0.lname},
score={0.score})'.format(self)
def __eq__(self, others):
if isinstance(other, Player):
return (self.score == other.score and
self.lname == other.lname and
self.fname == other.fname)
return False
def __ne__(self, others):
return not self.__eq__(others)



fnames = ['Julie', 'Ben', 'Jason', 'David']
lnames = ['Parks', 'Smith']
scores = [100, 95, 95, 130, 58, 74]

import itertools as it

score_iter = it.cycle(scores)

P = [Player(fn, ln, next(score_iter)) for fn in fnames for ln in
lnames]

cmp(P[0], P[1]) # returns -1

sorted(P) # throws TypeError: unorderable types Player() < Player()

The sorted function works when I define __lt__.
I must be misreading the documentation, because I read for the
documentation __cmp__ that it is called if none of the other rich
comparison functions are defined.
Is this a bug in Python 3.0rc1, or am I missing something?


Secondly, say that we suddenly need another sorting order, where we
want to sort by decreasing score and then by DECREASING last name
(instead of increasing last name, defined above). Now that the
comparison function argument is taken away from the sorted builtin,
how do we accomplish this with the "key" parameter?

Thank you

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


Re: Milenko Kindl rtegdgd

2008-09-21 Thread Paul Hovnanian P.E.
yuma wrote:
> 
> Milenko Kindl
> Banja Luka
> Banjaluka
> Bihac

Try facing Mecca while repeating that and your source will compile.

-- 
Paul Hovnanian mailto:[EMAIL PROTECTED]
--
Leap and the net will appear.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why are "broken iterators" broken?

2008-09-21 Thread Cameron Simpson
On 21Sep2008 18:36, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Roy Smith wrote:
>> There are plausible examples of collections which grow while you're  
>> iterating over them.  I'm thinking specifically of a queue in a  
>> multi-threaded application.  One thread pushes work onto the back of 
>> the queue while another pops from the front.  The queue could certainly 
>> go empty at times.  But, maybe a Python iterator is just the wrong way 
>> to model such behavior.
>
> you probably want the consumer thread to block when it catches up with  
> the producer, rather than exit.
> (that's the default behaviour of Python's Queue object, btw)

It sounds like he wants non-blocking behaviour in his consumer.
A common example is "try to gather a lot of stuff into a single packet,
but send a smaller packet promptly if there isn't much stuff".

You could make the next() method return a sentinal value like None
when the queue is empty. That would mean your consumer must recognise
the special value and also precludes delivering that value through the
queue. I'm not convinced my suggestion here is any better than just
doubling up every call to next() with an empty() check immediately
beforehand.

You could write a trivial wrapping generator to take the original
blocking queue and return a sentinel value on empty, too.

My suggestion is also an excellent way of getting programs that
fail-busy (i.e. they spin out) if you make a logic error in your
consumer. Ouch.

Cheers,
-- 
Cameron Simpson <[EMAIL PROTECTED]> DoD#743
http://www.cskk.ezoshosting.com/cs/

Kill, v.t.  To create a vacancy without nominating a successor.
Ambrose Bierce (1842-1914), U.S. author. The Devil's Dictionary (1881-1906).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why are "broken iterators" broken?

2008-09-21 Thread Miles
On Sun, Sep 21, 2008 at 11:13 AM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> According to the Python docs, once an iterator raises StopIteration, it
> should continue to raise StopIteration forever. Iterators that fail to
> behave in this fashion are deemed to be "broken":
>
> http://docs.python.org/lib/typeiter.html
>
> I don't understand the reasoning behind this. As I understand it, an
> iterator is something like a stream. There's no constraint that once a
> stream is empty it must remain empty forever.
>
> Can somebody explain why "broken iterators" are broken?

It's not a terribly onerous restriction.  If you're iterating with a
for-loop, you can make the iterable return a new iterator object when
the old one is exhausted, and if the intent is for the next()-method
to be called directly, you don't have to conform to the iterator
protocol.

Strictly speaking, file objects are broken iterators:

Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
>>> f = open('foo')
>>> it = iter(f)
>>> it.next()
'hi\n'
>>> it.next()
'bye\n'
>>> it.next()
Traceback (most recent call last):
  File "", line 1, in 
StopIteration
>>> f.seek(0)
>>> it.next()
'hi\n'

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


Re: Milenko Kindl rtegdgd

2008-09-21 Thread James Dow Allen
On Sep 22, 5:08 am, Martin Griffith <[EMAIL PROTECTED]> wrote:
> On Sun, 21 Sep 2008 15:00:16 -0700 (PDT), in sci.electronics.design H
> >Well, that's not C isn't it, more like Snobol or RPG/2
>
> It's better to say
> "that's not C, is it"
>
> I don't know why, but that's the way it works.

I recall a befuddled ESL student who missed
a question based on
  "Isn't that girl pretty?"
  "Isn't she!!"

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


Re: dict generator question

2008-09-21 Thread Miles
On Fri, Sep 19, 2008 at 9:51 PM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> Extending len() to support iterables sounds like a good idea, except that
> it's not.
>
> Here are two iterables:
>
>
> def yes():  # like the Unix yes command
>while True:
>yield "y"
>
> def rand(total):
>"Return random numbers up to a given total."
>from random import random
>tot = 0.0
>while tot < total:
>x = random()
>yield x
>tot += x
>
>
> What should len(yes()) and len(rand(100)) return?

Clearly, len(yes()) would never return, and len(rand(100)) would
return a random integer not less than 101.

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