Re: Help Needed in WxPython

2007-06-28 Thread felix seltzer

If you use pygtk, the notebook object could do that in a few lines of
code
but im not sure about wxPython.
note that if your using *nix of some sort, gtk should work fine, but under
windows some people report issues.
-felix

On 6/28/07, senthil arasu <[EMAIL PROTECTED]> wrote:


Hi,
Currently Iam integrating GUI Framework in Python.
As per design design,I need to use tab buttons to launch different HTML
pages in same frame(without launching seperate window ). I have already
tried with webbrowser class & WxPython GUI kit. Iam unable to get the
expected result.

I am wanted to be clear..!whether python supports my design or i need to
go for some other option

I need somebody to help me.

thanks

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

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

Re: Threads Dying?

2007-06-28 Thread felix seltzer

are you using pygtk as well?
how are you using your threads, (just out of curiosity into the issue)

-felix

On 6/28/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:


En Thu, 28 Jun 2007 15:12:53 -0300, Robert Rawlins - Think Blue
<[EMAIL PROTECTED]> escribió:

> I've got an application that seems to be a little bit unstable and
> freezes
> quite a bit, and I'm suspecting it's something in one of my threads
> that's
> causing the problem, when does a thread die?

After the run() method finishes, either normally or because an unhandled
exception happened.

> And how can I be sure that its
> dyeing when its mean to be?

I'm not sure what you are asking - you can check periodically inside run()
for some condition (an Event object, a special object placed on a Queue,
even a global variable in the simplest case) and exit when the condition
is met.

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

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

Re: Looking for an interpreter that does not request internet access

2007-06-28 Thread casevh
On Jun 25, 6:07 pm, James Alan Farrell <[EMAIL PROTECTED]> wrote:
> Hello,
> I recently installed new anti-virus software and was surprised the
> next time I brought up IDLE, that it was accessing the internet.
>
> I dislike software accessing the internet without telling me about it,
> especially because of my slow dial up connection (there is no option
> where I live), but also because I feel it unsafe.
>
> Can anyone recommend an interpreter that does not access the internet
> when it starts (or when it is running, unless I specifically write a
> program that causes it to do so, so as a browser)?
>
> James Alan Farrell

It is a false alarm. The IP address 127.0.0.1 is a reserved address
that means "this computer". It is more commonly known as "localhost".
A server application can bind to 127.0.0.1 and it can be accessed by a
client application running on the same computer. This is what IDLE is
doing. It is not accessing the Internet. It is only using the IP
protocol to communicate between different parts of the application.

The anti-virus application should be configured to allow use of
127.0.0.1. But coming from a corporate IT world, I'm not surprised
that it is not reasonably configured

casevh

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-28 Thread Michele Simionato
On Jun 29, 6:44 am, Douglas Alan <[EMAIL PROTECTED]> wrote:
>
> I've written plenty of Python code that relied on destructors to
> deallocate resources, and the code always worked.

You have been lucky:

$ cat deallocating.py
import logging

class C(object):
def __init__(self):
logging.warn('Allocating resource ...')

def __del__(self):
logging.warn('De-allocating resource ...')
print 'THIS IS NEVER REACHED!'

if __name__ == '__main__':
c = C()

$ python deallocating.py
WARNING:root:Allocating resource ...
Exception exceptions.AttributeError: "'NoneType' object has no
attribute 'warn'" in > ignored

Just because your experience has been positive, you should not
dismiss the opinion who have clearly more experience than you on
the subtilities of Python.

 Michele

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


Re: glob.glob standardization

2007-06-28 Thread Tim Roberts
billiejoex <[EMAIL PROTECTED]> wrote:
>...
>glob.glob, instead, return file names only if given path is relative:
>
 os.chdir('Desktop')
 os.getcwd()
>'/home/user/Desktop
 glob.glob("*")
>['file.py']
>
>...and absolute file names if given path is absolute:
>
 glob.glob('/home/user/Desktop/*')
>['/home/user/Desktop/file.py']
>
>Don't you think it would be more convenient for glob.glob to return
>file names only in any case, like os.listdir do?

Martin gave you the real answer, but you should realize that your analysis
of the behavior is faulty.  In EACH case, glob.glob has returned all of the
names that exactly match your pattern.  It's not about absolute or
relative.  For example, if you do
glob.glob( '..' )
which is a relative path, then the names you get back will be
['../xxx','../xxy','../xxz'].  They're not file names only.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rappresenting infinite

2007-06-28 Thread mmanns
On Thu, 28 Jun 2007 23:20:30 -0500
Robert Kern <[EMAIL PROTECTED]> wrote:

> [EMAIL PROTECTED] wrote:
> > Does it differ from the
> > built-in inf?
> 
> What built-in inf?

$ python
Python 2.4.4 (#2, Apr  5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1.0e1000
>>> b = 2.0e1000
>>> a
inf
>>> b
inf
>>> a == b
True
>>> type(a)




> No. You can make one that fits your requirements, though.

I am struggling to oversee the implications of design choices for inf
behaviour - especially if it comes to comparison with float type inf.
The type in my application contains a gmpy.mpq and a float that is
always kept between -1 and 1 by adding to the mpq on each operation.
I am looking for a robust inf design for this type. (Note: mpq and
float inf do not compare).

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-28 Thread Douglas Alan
"Chris Mellon" <[EMAIL PROTECTED]> writes:

> Obviously. But theres nothing about the with statement that's
> different than using smart pointers in this regard.

Sure there is -- smart pointers handle many sorts of situations, while
"with" only handles the case where the lifetime of the object
corresponds to the scope.

>> But I don't typically wish for this sort of intent to be made
>> explicit.  TMI!  I used "with" for *many* years in Lisp, since this
>> is how non-memory resource deallocation has been dealt with in Lisp
>> since the dawn of time.  I can tell you from many years of
>> experience that relying on Python's refcounter is superior.

> I question the relevance of your experience, then.

Gee, thanks.

> Refcounting is fine for memory, but as you mention below, memory is
> only one kind of resource and refcounting is not necessarily the
> best technique for all resources.

I never said that it is the best technique for *all* resources.  Just
the most typical ones.

>> This just isn't true.  For many years I have not had to explicitly
>> close files in Python.  Nor have I had to do so in C++.  They have
>> been closed for me implicitly.  "With" is not implicit -- or at least
>> not nearly as implicit as was previous practice in Python, or as is
>> current practice in C++.

> You still don't have to manually close files. But you cannot, and
> never could, rely on them being closed at a given time unless you
> did so.

You could for most intents and purposes.

> If you need a file to be closed in a deterministic manner, then you
> must close it explicitly.

You don't typically need them to be closed in a completely fool-proof
deterministic fashion.  If some other code catches your exceptions and
holds onto the traceback then it must know that can be delaying a few
file-closings, or the like.

> The with statement is not implicit and never has been. Implicit
> resource management is *insufficient* for the general resource
> management case. It works fine for memory, it's okay for files
> (until it isn't), it's terrible for thread locks and network
> connections and database transactions. Those things require
> *explicit* resource management.

Yes, I agree there are certain situations in which you certainly want
"with", or something like it.  I've never disagreed with that
assertion at all.  I just don't agree that for most Python code this
is the *typical* case.

> To the extent that your code ever worked when you relied on this
> detail, it will continue to work.

I've written plenty of Python code that relied on destructors to
deallocate resources, and the code always worked.

> There are no plans to replace pythons refcounting with fancier GC
> schemes that I am aware of.

This is counter to what other people have been saying.  They have been
worrying me by saying that the refcounter may go away and so you may
not be able to rely on predictable object lifetimes in the future.

> Nothing about Pythons memory management has changed. I know I'm
> repeating myself here, but you just don't seem to grasp this
> concept.  Python has *never* had deterministic destruction of
> objects. It was never guaranteed, and code that seemed like it
> benefited from it was fragile.

It was not fragile in my experience.  If a resource *positively*,
*absolutely* needed to be deallocated at a certain point in the code
(and occasionally that was the case), then I would code that way.  But
that has been far from the typical case for me.

>> Purify tells me that I know more about the behavior of my code than
>> you do: I've *never* had any memory leaks in large C++ programs that
>> used refcounted smart pointers that were caused by cycles in my data
>> structures that I didn't know about.

> I'm talking about Python refcounts. For example, a subtle resource
> leak that has caught me before is that tracebacks hold references to
> locals in the unwound stack.

Yes, I'm aware of that.  Most programs don't hold onto tracebacks for
long.  If you are working with software that does, then, I agree, that
sometimes one will have to code things more precisely.

> If you relied on refcounting to clean up a resource, and you needed
> exception handling, the resource wasn't released until *after* the
> exception unwound, which could be a problem. Also holding onto
> tracebacks for latter processing (not uncommon in event based
> programs) would artificially extend the lifetime of the resource. If
> the resource you were managing was a thread lock this could be a
> real problem.

Right -- I've always explicitly managed thread locks.

>> I really have no desire to code in C, thank you.  I'd rather be coding
>> in Python.  (Hence my [idle] desire for macros in Python, so that I
>> could do even more of my work in Python.)

> In this particular conversation, I really don't think that theres much
> to say beyond put up or shut up.

I think your attitude here is unPythonic.

> The experts in the field have said that it's not practical.

Gu

Python & cgi on win98--tinyweb problems, etc

2007-06-28 Thread Kirk Bailey
RE: TinyWeb running python in windows

PROBLEM: getting python scripts to execute.
SOLUTION: Insure the script ends in the name extension .py.

Windows associates all such files with the pythonw.exe interpreter program, 
and will use it to interpret them. IT IGNORES THE SHEBANG (the first line in 
a script which in the lovely world of un*x points to the interpreter 
program). Some servers have config files to tell the server what to use. 
TinyWeb does not, and relies on windows file associations to direct it to 
the proper interpreter.

Also note that it is possible for windows to conceal name extensions in some 
configurations, and also to create name extensions it does not display, 
resulting in some interesting hair pulling evenings chasing bugs.

Also note that tinyweb checks for the existence of a default page to use if 
none is specified in an incoming request. IF YOU CHANGE THE FILE NAME AFTER 
TINY LOADS IT WILL BARK LIKE A DOG. For instance, index.htm or index.html 
are equally acceptable. You had .htm. then you decided to change it to 
.html- and the server started woofing. It thinks the file index.htm still is 
there someplace and is looking for it! If you change the file name, restart 
the server.

I used tinyweb in supporting the development of windows wiki, and in all 
that crazy alpha stage flakiness, it NOT ONCE blew out. It is BULLETPROOF.

But it is it's own strange beast, and has it's own peculiarities.

-- 
Salute!
-Kirk Bailey
   Think
  +-+
  | BOX |
  +-+
   knihT

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


Re: equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)

2007-06-28 Thread mmanns
On Fri, 29 Jun 2007 00:47:16 -0300
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> __hash__ and equality tests are used by the dictionary
> implementation, and the default implementation is OK for immutable
> objects. 

That is probably why inf == inf yields True.
In this unique case, I do not like the default implementation.

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


Re: Rappresenting infinite

2007-06-28 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> On Wed, 27 Jun 2007 11:59:29 -
> Rob De Almeida <[EMAIL PROTECTED]> wrote:
> 
>> On Jun 27, 6:41 am, andrea <[EMAIL PROTECTED]> wrote:
>>> I would like to have a useful rappresentation of infinite, is there
>>> already something??
>> from numpy import inf
> 
> $ python
> Python 2.4.4 (#2, Apr  5 2007, 20:11:18)
> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 from numpy import inf
 inf == inf
> True
 type(inf)
> 
> 
> 
> This looks like the floating point inf to me.

It is.

> Does it differ from the
> built-in inf?

What built-in inf?

> I would like to second the OP's question if there is a generic inf and
> add the wish that that is not equal to itself (inf == inf would yield
> nan).

No. You can make one that fits your requirements, though.

> Ideally, it would not be of type float and work with gmpy mpq.
> But I might have rare requirements...

Possibly.

-- 
Robert Kern

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

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


Re: Threads Dying?

2007-06-28 Thread Gabriel Genellina
En Thu, 28 Jun 2007 15:12:53 -0300, Robert Rawlins - Think Blue  
<[EMAIL PROTECTED]> escribió:

> I've got an application that seems to be a little bit unstable and  
> freezes
> quite a bit, and I'm suspecting it's something in one of my threads  
> that's
> causing the problem, when does a thread die?

After the run() method finishes, either normally or because an unhandled  
exception happened.

> And how can I be sure that its
> dyeing when its mean to be?

I'm not sure what you are asking - you can check periodically inside run()  
for some condition (an Event object, a special object placed on a Queue,  
even a global variable in the simplest case) and exit when the condition  
is met.

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


Re: win32event.WaitForInputIdle() returns too soon

2007-06-28 Thread Gabriel Genellina
En Thu, 28 Jun 2007 19:15:40 -0300, Hans <[EMAIL PROTECTED]> escribió:

> I'm sending keyboard and mouse events to a seperate windows application.
> I use win32event.WaitForInputIdle() before calling e.g.
> win32api.keybd_event()
> However it seems that WaitForInputIdle() returns too soon because some  
> of my
> events get lost. Now I'v created my own  WaitForInputIdle() which calls

 From the Microsoft docs for WaitForInputIdle: "The WaitForInputIdle  
function only works with GUI applications. If a console application calls  
the function, it returns immediately, with no wait."
A typical Python script is a console application.

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


Re: Rappresenting infinite

2007-06-28 Thread mmanns
On Wed, 27 Jun 2007 11:59:29 -
Rob De Almeida <[EMAIL PROTECTED]> wrote:

> On Jun 27, 6:41 am, andrea <[EMAIL PROTECTED]> wrote:
> > I would like to have a useful rappresentation of infinite, is there
> > already something??
> 
> from numpy import inf
> 

$ python
Python 2.4.4 (#2, Apr  5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from numpy import inf
>>> inf == inf
True
>>> type(inf)



This looks like the floating point inf to me. Does it differ from the
built-in inf?

I would like to second the OP's question if there is a generic inf and
add the wish that that is not equal to itself (inf == inf would yield
nan). Ideally, it would not be of type float and work with gmpy mpq.
But I might have rare requirements...

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


Re: equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)

2007-06-28 Thread Gabriel Genellina
En Thu, 28 Jun 2007 11:38:56 -0300, A.T.Hofkamp <[EMAIL PROTECTED]>  
escribió:

> The point I intended to make was that having a default __hash__ method on
> objects give weird results that not everybody may be aware of.
> In addition, to get useful behavior of objects in sets one should  
> override
> __hash__ anyway, so what is the point of having a default  
> object.__hash__ ?

__hash__ and equality tests are used by the dictionary implementation, and  
the default implementation is OK for immutable objects. I like the fact  
that I can use almost anything as dictionary keys without much coding.
This must always be true: (a==b) => (hash(a)==hash(b)), and the  
documentation for __hash__ and __cmp__ warns about the requisites (but  
__eq__ and the other rich-comparison methods are lacking the warning).

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-28 Thread Douglas Alan
Steve Holden <[EMAIL PROTECTED]> writes:

>> Actually, it's "chacun".  And the "à" may precede the "chacun".

>> |>oug

> "chacun" is an elision of the two words "Chaque" (each) and "un"
> (one), and use of those two words is at least equally correct, though
> where it stands in modern usage I must confess I have no idea.

Google can answer that: 158,000 hits for "chaqu'un", 57 million for
"chacun".

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-28 Thread Tim Roberts
Twisted <[EMAIL PROTECTED]> wrote:
>
>On Jun 27, 8:26 am, [EMAIL PROTECTED] (Timofei Shatrov) wrote:
>>
>> Lie. Ghostscript works out of the box on Windows.
>
>You're joking. First of all I am not a liar, and secondly, Ghostscript
>and Ghostview are tricky to set up correctly. I know -- I've done it a
>time or three. There's an arcane GUI configurator that isn't
>exceptionally well designed, and once it's working it still wonks out
>on maybe 1 in 10 .ps and .eps files you come across ...

You must have installed Ghostscript last in 1998.  The current installer is
as painless as most open source installers are.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Help Needed in WxPython

2007-06-28 Thread senthil arasu

Hi,
Currently Iam integrating GUI Framework in Python.
As per design design,I need to use tab buttons to launch different HTML
pages in same frame(without launching seperate window ). I have already
tried with webbrowser class & WxPython GUI kit. Iam unable to get the
expected result.

I am wanted to be clear..!whether python supports my design or i need to go
for some other option

I need somebody to help me.

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

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-28 Thread Steve Holden
Douglas Alan wrote:
> Steve Holden <[EMAIL PROTECTED]> writes:
> 
>> Douglas Woodrow wrote:
> 
>>> On Wed, 27 Jun 2007 01:45:44, Douglas Alan <[EMAIL PROTECTED]> wrote
> 
 A chaque son gout
> 
>>> I apologise for this irrelevant interruption to the conversation,
>>> but this isn't the first time you've written that.  The word
>>> "chaque" is not a pronoun.
> 
>>> http://grammaire.reverso.net/index_alpha/Fiches/Fiche220.htm
> 
>> Right, he probably means "Chaqu'un à son gout" (roughly, each to his
>> own taste).
> 
> Actually, it's "chacun".  And the "à" may precede the "chacun".
> 
> |>oug

http://everything2.com/?node_id=388997 is clearly not authoritative, as 
the "literal translation" about which it speaks is far from literal (it 
mistakes the preposition "à" (to) for "a", the present tense of the verb 
to have. I suppose the literal translation is "Each one to his own 
taste". It does offer some support to my theory, however. So I'll quote 
the damned thing anyway.

"chacun" is an elision of the two words "Chaque" (each) and "un" (one), 
and use of those two words is at least equally correct, though where it 
stands in modern usage I must confess I have no idea. The word order you 
suggest would be less likely to be used by a peasant than a lawyer. 
Being a peasant, I naturally used the other wording.

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

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


Re: Converting Diff Output to XML?

2007-06-28 Thread Debajit Adhikary

That looks very good :)Thanks a ton!

On 6/27/07, Yongjian Xu <[EMAIL PROTECTED]> wrote:


gnosis has a converter for ASCII file to xml file, its called txt2dw.py.
give it a try.

--
Jim

On 6/26/07, Debajit Adhikary <[EMAIL PROTECTED]> wrote:
>
> What would be the best way to convert the regular (unix) diff output
> into XML?
> Are there any libraries at all which might help?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



--
Yongjian (Jim) Xu
===
Sysops
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-28 Thread Douglas Alan
Steve Holden <[EMAIL PROTECTED]> writes:

> Douglas Woodrow wrote:

>> On Wed, 27 Jun 2007 01:45:44, Douglas Alan <[EMAIL PROTECTED]> wrote

>>> A chaque son gout

>> I apologise for this irrelevant interruption to the conversation,
>> but this isn't the first time you've written that.  The word
>> "chaque" is not a pronoun.

>> http://grammaire.reverso.net/index_alpha/Fiches/Fiche220.htm

> Right, he probably means "Chaqu'un à son gout" (roughly, each to his
> own taste).

Actually, it's "chacun".  And the "à" may precede the "chacun".

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)

2007-06-28 Thread Steve Holden
A.T.Hofkamp wrote:
> On 2007-06-28, Alan Isaac <[EMAIL PROTECTED]> wrote:
>> A.T.Hofkamp wrote:
>>
>> a = Car2(123)
>> b = Car2(123)
>> a == b
>>> True
>>>
>> set([a,b])
>>> set([Car2(123), Car2(123)])
>>>
>>> I get a set with two equal cars, something that never happens with a set
>>> my math teacher once told me.
>>
>> Then your math teacher misspoke.
>> You have two different cars in the set,
>> just as expected.  Use `is`.
>> http://docs.python.org/ref/comparisons.html
>>
>> This is good behavior.
> 
> Hmm, maybe numbers in sets are broken then?
> 
 a = 12345
 b = 12345
 a == b
> True
 a is b
> False
 set([a,b])
> set([12345])
> 
> 
> Numbers and my Car2 objects behave the same w.r.t. '==' and 'is', yet I get a
> set with 1 number, and a set with 2 cars.
> Something is wrong here imho.
> 
> The point I intended to make was that having a default __hash__ method on
> objects give weird results that not everybody may be aware of.
> In addition, to get useful behavior of objects in sets one should override
> __hash__ anyway, so what is the point of having a default object.__hash__ ?
> 
> The "one should override __hash__ anyway" argument is being discussed in my
> previous post.

Hmm, I suspect you'll like this even less:

 >>> set((1.0, 1, 1+0j))
set([1.0])

Just the same there are sound reasons for it, so I'd prefer to see you 
using "counterintuitive" or "difficult to fathom" rather than "broken" 
and "wrong".

Such language implies you have thought about this more deeply than the 
developers (which I frankly doubt) and that they made an inappropriate 
decision (which is less unlikely, but which in the case you mention I 
also rather doubt).

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

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-28 Thread Steve Holden
Douglas Woodrow wrote:
> On Wed, 27 Jun 2007 01:45:44, Douglas Alan <[EMAIL PROTECTED]> wrote
>> A chaque son gout
> 
> I apologise for this irrelevant interruption to the conversation, but 
> this isn't the first time you've written that.
> 
> The word "chaque" is not a pronoun.
> 
> http://grammaire.reverso.net/index_alpha/Fiches/Fiche220.htm

Right, he probably means "Chaqu'un à son gout" (roughly, each to his own 
taste).

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

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


Re: Collections of non-arbitrary objects ?

2007-06-28 Thread Steve Holden
Paul Rubin wrote:
> Steve Holden <[EMAIL PROTECTED]> writes:
>> Think of a tuple as an ordered collection. A given element's ordinal
>> position indicates its semantics (meaning, significance), and
>> generally it won't make sense to iterate over the elements of a tuple
>> (though naturally that doesn't stop people, and neither does the
>> interpreter).
> 
>   def f(*a): ... 
> 
> is a fundamental language feature and really only makes sense in 
> the context of iterating over tuples.

That's true, but given that individual arguments are bound to names in 
the local namespace I'd have to argue (if I wanted to argue at all) that 
the choice of a tuple over a list was pretty arbitrary, and that it 
would actually be "more Pythonic" to allow modification of the argument 
list in the same way as sys.argv is mutable.

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

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


Re: Looking for an interpreter that does not request internet access

2007-06-28 Thread William Allison
James Alan Farrell wrote:

> At the risk of sounding clueless, what is "the regular interpreter"?
> I've now read several python books, and they all recommend IDLE.  
> 
By typing "python" at your command prompt you'll also get
an interactive interpreter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: process stdin grab

2007-06-28 Thread Seltzer

thanks for the suggestions.
I'm not able to modify the mplayer command...
and they do not create a fifo

and yes, i meant 'pid', sorry.

-felix

On 6/28/07, Will Maier <[EMAIL PROTECTED]> wrote:


On Thu, Jun 28, 2007 at 08:01:18PM +, Seltzer wrote:
> I need to send commands to a process that i did not start.
> (mplayer specifically) I have the PIP of the process, and thats
> about all.

I assume you mean 'PID'. This is somewhat offtopic, but mplayer
supports receiving commands from a FIFO:

mplayer -quiet -slave -idle -input file=/home/you/.mplayer/fifo

Then you can write commands (like 'loadfile song.ogg') to the fifo.
Doing this in Python is as trivial as opening, writing to, and
closing a file object.

> Any ideas on how to do this in python? i need only to write to its
> stdin, not read any information from it, and i don't really need
> to know if my command worked for now, so error handling isn't
> really an issue.

I don't know of any magic to write to a running program's stdin.

--

[Will [EMAIL PROTECTED]|http://www.lfod.us/]
--
http://mail.python.org/mailman/listinfo/python-list

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

Re: Looking for an interpreter that does not request internet access

2007-06-28 Thread James Alan Farrell
On Mon, 25 Jun 2007 20:41:59 -0500, Robert Kern
<[EMAIL PROTECTED]> wrote:

>James Alan Farrell wrote:
>> Hello,
>> I recently installed new anti-virus software and was surprised the
>> next time I brought up IDLE, that it was accessing the internet.
>> 
>> I dislike software accessing the internet without telling me about it,
>> especially because of my slow dial up connection (there is no option
>> where I live), but also because I feel it unsafe.
>
>It is not accessing the internet. It is opening up a local socket connection to
>communicate with a separate (but still local!) process for the interactive
>interpreter.
>
>> Can anyone recommend an interpreter that does not access the internet
>> when it starts (or when it is running, unless I specifically write a
>> program that causes it to do so, so as a browser)?
>
>The regular interpreter works fine.

At the risk of sounding clueless, what is "the regular interpreter"?
I've now read several python books, and they all recommend IDLE.  

I've not yet tried unplugging the cable -- have other fish to fry at
the moment, but will try it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for an interpreter that does not request internet access

2007-06-28 Thread James Alan Farrell
On Tue, 26 Jun 2007 03:50:11 -, John Roth <[EMAIL PROTECTED]>
wrote:

>On Jun 25, 7:07 pm, James Alan Farrell <[EMAIL PROTECTED]> wrote:
>> Hello,
>> I recently installed new anti-virus software and was surprised the
>> next time I brought up IDLE, that it was accessing the internet.
>>
>> I dislike software accessing the internet without telling me about it,
>> especially because of my slow dial up connection (there is no option
>> where I live), but also because I feel it unsafe.
>>
>> Can anyone recommend an interpreter that does not access the internet
>> when it starts (or when it is running, unless I specifically write a
>> program that causes it to do so, so as a browser)?
>>
>> James Alan Farrell
>
>One of two things is going on. Either the anti-virus program you
>installed is so clueless that it doesn't understand "localhost" or the
>IP address equivalent, or IDLE (or it's subprocess) is opening the
>socket in promiscuous mode. Either one will give you that symptom.
>
>There are definitely anti-virus products that are that clueless.
>Scream at the vendor.
>
>I doubt if it's Idle, but I'm not in the mood to check the code to see
>if it's doing it right.
>
>John Roth
>
>
>

Thanks to all who answered.

The antivirus is McAfee, and I have found it clueless in many ways.
Unfortunately the vendor is my place of employment, and if I am to
work from home and log into their system, they require me to have it.
Otherwise I have to go to the office.

Management and IT there  might well be clueless but I am new there and
don't want to say that yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: try/except/else/finally problem

2007-06-28 Thread Ben Finney
Ed Jensen <[EMAIL PROTECTED]> writes:

> I'm using:
> Python 2.3.2 (#1, Oct 17 2003, 19:06:15) [C] on sunos5
>
> And I'm trying to execute:
>
> #! /usr/bin/env python
>
> try:
> f = file('test.txt', 'r')
> except IOError:
> print 'except'
> else:
> print 'else'
> finally:
> print 'finally'
>
>
> What am I doing wrong?

You're using syntax that is valid under Python 2.5, but invalid in
earlier Python versions.

 http://www.python.org/dev/peps/pep-0341/>
 http://docs.python.org/whatsnew/pep-341.html>

-- 
 \   "Military justice is to justice what military music is to |
  `\  music."  -- Groucho Marx |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


HTML Page Rendering Support in WxPython Frame

2007-06-28 Thread senthil arasu

Hi,
Currently Iam integrating GUI Framework in Python.
As per design design,I need to use tab buttons to launch different HTML
pages in same frame(without launching seperate window ). I have already
tried with webbrowser class & WxPython GUI kit. Iam unable to get the
expected result.

I am wanted to be clear..!whether python supports my design or i need to go
for some other option

I need somebody to help me.

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

Re: Getting some element from sets.Set

2007-06-28 Thread [EMAIL PROTECTED]
On May 9, 11:41 am, Steven Bethard <[EMAIL PROTECTED]> wrote:

>  $ python -m timeit -s "s = set('abcdef')" "x = s.pop(); s.add(x)"

It's interesting that that's faster.  I'd be hesitant to use that in a
real program because it's so unattractive (as is the '.next()'
approach).  To me a builtin method would be worthwhile in this case.

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


Re: suggestion: recursive collections.defaultdict

2007-06-28 Thread [EMAIL PROTECTED]
On Jun 18, 1:56 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>,
>
> [EMAIL PROTECTED] wrote:
> > It seems like
>
> > x = defaultdict(defaultdict(list))
>
> > should do the obvious, but it doesn't.
>
> It *does* the obvious.  Parenthesis after a name means: call this object
> *now*.  Any other behavior wouldn't be obvious.


Well, some of us are in the "slow" class...


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


Re: exception from a thread

2007-06-28 Thread Diez B. Roggisch
_spitFIRE schrieb:
> assume a scenario, where there is a class that for doing some work,
> spawns lot of threads.
> 
> class X:
> def __init__(self):
> # Spawns some threads to
> # do some work
> 
> now, assuming that at least one of the threads encounters a problem
> while doing work and throws an exception. Would I be able to handle
> that error in the caller class? When I try to do this, I see that the
> errors thrown by the threads never cascade to this caller :(

Exactly. Because they are different threads - the very essence of them 
is each of them having their own stacks.

Depending on what you do in the main-thread, you can do something like this:


class Worker(Thread):
def __init__(self):
   ...
   self.running = False
   ...
   self.start()



def run(self):
   self.running = True
   try:
  ... # work

   finally:
  self.running = False


In the main-thread, you test for each thread if it's still running.

while True:

time.sleep(.1)
for t in threads:
if not t.running:
   print "Not running anymor: %r" % t

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


win32event.WaitForInputIdle() returns too soon

2007-06-28 Thread Hans
Hi all,

I'm sending keyboard and mouse events to a seperate windows application.
I use win32event.WaitForInputIdle() before calling e.g. 
win32api.keybd_event()
However it seems that WaitForInputIdle() returns too soon because some of my
events get lost. Now I'v created my own  WaitForInputIdle() which calls the 
one
in win32event() and adds an extra sleep(0.1). As expected, this isn't 
robust.

Is this a known issue of win32event.WaitForInputIdle() ?
Is it a Windows issue?
Is more involved (but not documented in the Python docs)?
Any ideas?

Thanks
Hans 


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


Writing TGA image files?

2007-06-28 Thread Adam Pletcher
Does anyone have Python code for writing Targa (TGA) image files?
Ideally, with options for bit-depth/alpha channel, and RLE compression,
but I'm probably reaching there.

PIL is read-only for TGAs, unfortunately, and so far I'm striking out on
Google.
Thanks.

--
Adam Pletcher
Technical Art Director
www.volition-inc.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-28 Thread Andy Freeman
On Jun 28, 1:09 pm, John Nagle <[EMAIL PROTECTED]> wrote:
> Andy Freeman wrote:
> > On Jun 27, 11:41 pm, John Nagle <[EMAIL PROTECTED]> wrote:
> > While I agree that weak pointers are good and can not be an
> > afterthought, I've written code where "back" changed dynamically, and
> > I'm pretty sure that Nagle has as well.
>
> That sort of thing tends to show up in GUI libraries, especially
> ones that have event ordering issues.  It's a tough area.

It shows up almost anywhere one needs to handle recurring operations.
It also shows up in many dynamic search structures.

> > Yes, one can implement a circular list as a vector with a current
> > index, but that has space and/or time consequences.  
>
> We used to see things like that back in the early 1980s, but today,
> worrying about the space overhead associated with keeping separate
> track of ownership and position in a circular buffer chain isn't
> a big deal.

Insert and delete can be a big deal.  O(1) is nice.


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


Re: IMAP library

2007-06-28 Thread Jean-Paul Calderone
On Thu, 28 Jun 2007 18:44:02 -0300, Bruno Barberi Gnecco <[EMAIL PROTECTED]> 
wrote:
>   It seems that this question has been asked a few times in this
>group before, but sometime has passed since the last post and maybe there's
>something new. I'm looking for a high level IMAP library--I know of imaplib,
>but it's awfully documented and I was hoping to avoid reading RFCs for
>a simple email reader routine.
>
>   So, is there any example, routine, library or code in some software
>package that reads mails from IMAP, with attachments? I don't need anything
>fancy, just reading the emails and decoding them.
>
>   If there isn't, I'm willing to write one and release it under LGPL.
>Anybody would like to help?
>

For the IMAP4 part of this, I'd suggest Twisted's IMAP4 library.  To deal
with attachments and other MIME features, you can use the stdlib email
package to parse the message into a structured form and then process it
appropriately.

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


IMAP library

2007-06-28 Thread Bruno Barberi Gnecco
It seems that this question has been asked a few times in this
group before, but sometime has passed since the last post and maybe there's
something new. I'm looking for a high level IMAP library--I know of imaplib,
but it's awfully documented and I was hoping to avoid reading RFCs for
a simple email reader routine.

So, is there any example, routine, library or code in some software
package that reads mails from IMAP, with attachments? I don't need anything
fancy, just reading the emails and decoding them.

If there isn't, I'm willing to write one and release it under LGPL.
Anybody would like to help?

-- 
Bruno Barberi Gnecco 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vista 64 + Python2.5 + wxpython 28 issue

2007-06-28 Thread Martin v. Löwis
> Is there any 64 version installer or do I need to build myself ?

There are hardly AMD64 versions of *anything* but the base Python
distribution. I strongly advise to use the 32-bit version on AMD64
(in fact, I see little reason to run Win64 at all unless you have
more that 4GiB in the box, or unless you are developing a software
product that you explicitly target for Win64).

If you absolutely need to run 64-bit code, be prepared to compile
everything for yourself, and be prepared that it won't work out
of the box, and cost you many person days to fix and debug. Never
forget to feed back the fixes you make to the respective authors
of the open source software.

Notice that you won't just need a 64-bit version of wxpython,
but also such versions of all underlying libraries wxpython
happens to be build on.

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


exception from a thread

2007-06-28 Thread _spitFIRE
assume a scenario, where there is a class that for doing some work,
spawns lot of threads.

class X:
def __init__(self):
# Spawns some threads to
# do some work

now, assuming that at least one of the threads encounters a problem
while doing work and throws an exception. Would I be able to handle
that error in the caller class? When I try to do this, I see that the
errors thrown by the threads never cascade to this caller :(

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


Re: process stdin grab

2007-06-28 Thread Will Maier
On Thu, Jun 28, 2007 at 08:01:18PM +, Seltzer wrote:
> I need to send commands to a process that i did not start.
> (mplayer specifically) I have the PIP of the process, and thats
> about all.

I assume you mean 'PID'. This is somewhat offtopic, but mplayer
supports receiving commands from a FIFO:

mplayer -quiet -slave -idle -input file=/home/you/.mplayer/fifo

Then you can write commands (like 'loadfile song.ogg') to the fifo.
Doing this in Python is as trivial as opening, writing to, and
closing a file object.

> Any ideas on how to do this in python? i need only to write to its
> stdin, not read any information from it, and i don't really need
> to know if my command worked for now, so error handling isn't
> really an issue.

I don't know of any magic to write to a running program's stdin.

-- 

[Will [EMAIL PROTECTED]|http://www.lfod.us/]
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Vista 64 + Python2.5 + wxpython 28 issue

2007-06-28 Thread Simon Roses Femerling
Hello Martin,

I installed wxpython 2.8 using the installer
(wxPython2.8-win32-unicode-2.8.4.0-py25.ex), yeah I assume is the 32 bits
version.

Is there any 64 version installer or do I need to build myself ?

Thanks,

SRF

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
"Martin v. Löwis"
Sent: jueves, 28 de junio de 2007 22:08
To: python-list@python.org
Subject: Re: Vista 64 + Python2.5 + wxpython 28 issue

> I have installed python 2.5 (AMD64) on Vista (64), also installed wx 2.8
> but I'm getting this error:
> 
> 
> Traceback (most recent call last):
>   File "mymodule.py", line 39, in 
> import wx
>   File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py",
> line 4
> 5, in 
> from wx._core import *
>   File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
> line 4, i
> n 
> import _core_
> ImportError: DLL load failed with error code 193
> """
> 
> I have set python.exe to run under admin but that do not fix the problem.
> 
> Any ideas ?

193 means ERROR_BAD_EXE_FORMAT. Could it be that you are using a
32-bit extension DLL? How precisely did you "install" wx 2.8? Did
you rebuild it from source?

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


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


RE: Can IronPython work as Windows Scripting Host (WSH) language?

2007-06-28 Thread Dino Viehland
Currently IronPython doesn't support being hosted in WSH.  It's something we've 
discussed internally in the past but we've never had the cycles to make it work.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of misiek3d
Sent: Thursday, June 28, 2007 3:07 AM
To: python-list@python.org
Subject: Can IronPython work as Windows Scripting Host (WSH) language?

Hello
I want to use IronPython as Windows Scripting Host language. Is it
possible? How can I do it? I know that ActivePython works as WSH
language but for specific reasons I need to use IronPython.

regards
Michal

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


RE: ironpython exception line number

2007-06-28 Thread Dino Viehland
Given a file foo.py:

def f():

You should get these results:

IronPython 1.0.60816 on .NET 2.0.50727.312
Copyright (c) Microsoft Corporation. All rights reserved.
>>> try:
... execfile('foo.py')
... except IndentationError, e:
... import sys
... x = sys.exc_info()
...
>>> print x[1].filename, x[1].lineno, x[1].msg, x[1].offset, x[1].text, 
>>> x[1].args
foo.py 2 unexpected token  1  ('unexpected token ', ('foo.py', 2, 1, 
''))
>>>
>>>

Which is very similar to the result you get from CPython although we seem to 
disagree about what we expect next.

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> try:
... execfile('foo.py')
... except IndentationError, e:
... import sys
... x = sys.exc_info()
...
>>> print x[1].filename, x[1].lineno, x[1].msg, x[1].offset, x[1].text, 
>>> x[1].args
foo.py 2 expected an indented block 9  ('expected an indented block', 
('foo.py', 2, 9, ''))
>>> ^Z


If you're hosting IronPython and catching this from a .NET language then you'll 
be catching the .NET exception.  In that case you can access the original 
Python exception from ex.Data["PythonExceptionInfo"].  Alternately you could 
catch PythonSyntaxErrorException and access its properties (Line, Column, 
FileName, LineText, Severity, and ErrorCode).

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Troels Thomsen
Sent: Tuesday, June 26, 2007 1:33 PM
To: python-list@python.org
Subject: ironpython exception line number


Hello ,

When an exeption occurs in a IronPython executet script, and I print the
sys.exc , i get something ugly like the example below.
How can I get the fileName and line number?

Thx in advance
Troels


26-06-2007 13:19:04 : IronPython.Runtime.Exceptions.PythonIndentationError:
unexpected token def
   ved IronPython.Compiler.SimpleParserSink.AddError(String path, String
message, String lineText, CodeSpan span, Int32 errorCode, Severity severity)

   ved IronPython.Compiler.CompilerContext.AddError(String message, String
lineText, Int32 startLine, Int32 startColumn, Int32 endLine, Int32
endColumn, Int32 errorCode, Severity severity)

   ved IronPython.Compiler.Parser.ReportSyntaxError(Location start, Location
end, String message, Int32 errorCode)
   ved IronPython.Compiler.Parser.ReportSyntaxError(Token t, Int32
errorCode, Boolean allowIncomplete)
   ved IronPython.Compiler.Parser.ParseSuite()
   ved IronPython.Compiler.Parser.ParseFuncDef()
   ved IronPython.Compiler.Parser.ParseStmt()
   ved IronPython.Compiler.Parser.ParseSuite()
   ved IronPython.Compiler.Parser.ParseClassDef()
   ved IronPython.Compiler.Parser.ParseStmt()
   ved IronPython.Compiler.Parser.ParseFileInput()
   ved IronPython.Hosting.PythonEngine.Compile(Parser p, Boolean
debuggingPossible)
   ved IronPython.Hosting.PythonEngine.CompileFile(String fileName)
   ved IronPython.Hosting.PythonEngine.ExecuteFile(String fileName)



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


Re: try/except/else/finally problem

2007-06-28 Thread Peter Otten
Ed Jensen wrote:

> Peter Otten <[EMAIL PROTECTED]> wrote:
> 
>>> try:
>>> f = file('test.txt', 'r')
>>> except IOError:
>>> print 'except'
>>> else:
>>> print 'else'
>>> finally:
>>> print 'finally'
> 
>> You need Python 2.5 for that to work. In older Python versions you have
>> to nest try...except...else and try...finally.
> 
> Thanks Peter.
> 
> Given the code above, can you show me what that would look like?  The
> nested version, that is.

try:
try:
f = file("test.txt", "r")
except IOError:
print "except"
else:
print "else"
finally:
print "finally"

Peter

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


Re: Vista 64 + Python2.5 + wxpython 28 issue

2007-06-28 Thread Martin v. Löwis
> I have installed python 2.5 (AMD64) on Vista (64), also installed wx 2.8
> but I'm getting this error:
> 
> 
> Traceback (most recent call last):
>   File "mymodule.py", line 39, in 
> import wx
>   File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py",
> line 4
> 5, in 
> from wx._core import *
>   File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
> line 4, i
> n 
> import _core_
> ImportError: DLL load failed with error code 193
> """
> 
> I have set python.exe to run under admin but that do not fix the problem.
> 
> Any ideas ?

193 means ERROR_BAD_EXE_FORMAT. Could it be that you are using a
32-bit extension DLL? How precisely did you "install" wx 2.8? Did
you rebuild it from source?

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


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-28 Thread John Nagle
Alex Martelli wrote:
> Bjoern Schliessmann <[EMAIL PROTECTED]>
> wrote:
>...
> 
>>Mh, strange, I personally like to use "this.a" in C++, to make clear
>>I use an instance variable.
> 
> 
> That would be nice, unfortunately your C++ compiler will refuse that,
> and force you to use this->a instead;-).

Yes, as Strostrup admits, "this" should have been a reference.
Early versions of C++ didn't have references.

One side effect of that mistake was the "delete(this)" idiom,
which does not play well with inheritance.  But that's a digression here.

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


Re: 16bit hash

2007-06-28 Thread Martin v. Löwis
> If the UniqueID is used it must be unique when used in the printer
> (where I cannot control which other UniqueID's might be present).

I don't know much about PostScript; googling around gives

http://fontforge.sourceforge.net/UniqueID.html

that says that you should not use them anymore, and

http://www.adobe.com/devnet/opentype/archives/id.html

says you should not make up values, but officially register them;
a certain range is available for testing without registration;
that should not be used in production mode.

> Luckily the cheap option of not using the UniqueID at all is available,
> but chances are some printer ps interpreter will barf if it's not
> present and then I need a fairly robust way to generate reasonable
> candidates.

See above article. It was always the case that a printer should not
barf; it just might have to re-render all glyphs. However, it seems
that today's printers have advanced caching, making the mechanism
irrelevant.

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-28 Thread John Nagle
Andy Freeman wrote:
> On Jun 27, 11:41 pm, John Nagle <[EMAIL PROTECTED]> wrote:

> While I agree that weak pointers are good and can not be an
> afterthought, I've written code where "back" changed dynamically, and
> I'm pretty sure that Nagle has as well.

That sort of thing tends to show up in GUI libraries, especially
ones that have event ordering issues.  It's a tough area.

> Many programs with circular lists have an outside pointer to the
> current element, but the current element changes.  All of the links
> implementing the list have to be strong enough to keep all of the list
> alive.
> Yes, one can implement a circular list as a vector with a current
> index, but that has space and/or time consequences.  

We used to see things like that back in the early 1980s, but today,
worrying about the space overhead associated with keeping separate
track of ownership and position in a circular buffer chain isn't
a big deal.  I last saw that in a FireWire driver, and even there,
it wasn't really necessary.

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


process stdin grab

2007-06-28 Thread Seltzer

hello
I need to send commands to a process that i did not start. (mplayer
specifically)
I have the PIP of the process, and thats about all.

Any ideas on how to do this in python? i need only to write to its stdin,
not read any information from it,
and i don't really need to know if my command worked for now, so error
handling isn't really an issue.

any suggestions would be great.

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

Re: try/except/else/finally problem

2007-06-28 Thread Ed Jensen
Peter Otten <[EMAIL PROTECTED]> wrote:

>> try:
>> f = file('test.txt', 'r')
>> except IOError:
>> print 'except'
>> else:
>> print 'else'
>> finally:
>> print 'finally'

> You need Python 2.5 for that to work. In older Python versions you have to
> nest try...except...else and try...finally.

Thanks Peter.

Given the code above, can you show me what that would look like?  The
nested version, that is.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Evolution of a pythonistas!

2007-06-28 Thread Sells, Fred
this one is fun: http://www.vpython.org/

> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Behalf Of swordofrue
> Sent: Thursday, June 28, 2007 1:50 PM
> To: python-list@python.org
> Subject: Re: Evolution of a pythonistas!
> 
> 
> Thanks everyone for your responses. I am really loving this. Installed
> Pygame and playing some of those games. It just amazes me how much
> effort some of these games take. I am reading the source and am just
> amazed by the effort and organizational ability of the authors.
> Perhaps one day I will such mad skills :)
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Vista 64 + Python2.5 + wxpython 28 issue

2007-06-28 Thread simonroses
Hello Guys,

I have installed python 2.5 (AMD64) on Vista (64), also installed wx 2.8
but I'm getting this error:


Traceback (most recent call last):
  File "mymodule.py", line 39, in 
import wx
  File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py",
line 4
5, in 
from wx._core import *
  File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
line 4, i
n 
import _core_
ImportError: DLL load failed with error code 193
"""

I have set python.exe to run under admin but that do not fix the problem.

Any ideas ?

Thanks!

Sincerely,

SRF

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


Re: textwrap and combining diacritical marks

2007-06-28 Thread Berteun Damman
On Thu, 28 Jun 2007 09:19:20 + (UTC), Berteun Damman
<[EMAIL PROTECTED]> wrote:
> And that leasts to another question, does Python have a function akin to
> wcwidth() which gives the number of column positions a unicode character
> needs?

After playing around a bit with unicodedata.normalize, but seeing how
this fails when there is no precomposed form, I've decided to take
Marcus Kuhns implementation [1], and made a Python version [2].

This will try to guess the column width of a character. Non printable
characters will report a -1 width (this includes '\n' and '\t' for
example.), except for \0, which has width 0.  Composing characters will
report '0', normal latin characters 1  and full-width forms for example
'2'.

Of course, real output depends on the capabilities of the display
device. xterm is capable of handling combining characters, whereas OS
X's Terminal.app can not do it for Greek or Russian characters for
example.

All in all, I think it is a reasonable start. There is one issue though,
namely involving Plane 1 chars. On 64 bit systems, so it seems, these
are stored as one character, on 32 bit systems as a surrogate pair. I
don't know how this works exactly, but the code should basically ignore
Plane 1 characters on 32 bit systems (i.e. always report display width
'1' even though they're combining or full-width).

Berteun

[1] http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
[2] http://berteun.nl/tmp/wcwidth.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 16bit hash

2007-06-28 Thread Robin Becker
Martin v. Löwis wrote:
..
>> ie a bunch of lists of strings which are eventually joined together and
>> written out with a template to make the postscript definition.
> 
> And the UniqueID should be unique within this file, right?
> 
> Why don't you just use a serial number then?
..
I do need a unique identifier for each font, unfortunately they are required to 
be unique across more than one file. Effectively these fonts are dynamically 
generated using the used glyphs rather than just dumping the whole of a ttf 
into 
the postscript.

If the UniqueID is used it must be unique when used in the printer (where I 
cannot control which other UniqueID's might be present).

If I knew enough about postscript I might generate a UniqueID at the point of 
use (by inspecting some global state) unfortunately my postscript is poor so 
I'm 
attempting to give the fonts an id that is likely to be unique by obtaining an 
integer dependant on the font data and then shifting into the private range.

Luckily the cheap option of not using the UniqueID at all is available, but 
chances are some printer ps interpreter will barf if it's not present and then 
I 
need a fairly robust way to generate reasonable candidates.
-- 
Robin Becker

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


Re: 16bit hash

2007-06-28 Thread Martin v. Löwis
> I'm trying to create UniqueID's for dynamic postscript fonts. According
> to my resources we don't actually need to use these, but if they are
> required by a particular postscript program (perhaps to make a print run
> efficient) then the private range of these ID's is 400<=UID<=499
> ie a range of one million.
> 
> So I probably really need an 18 bit hash

I don't fully understand the example, but ISTM that "no, you don't need
a hash at all. You need a unique identification".

> The data going into the font consists of
> 
> fontBBox '[-415 -431 2014 2033]'
> charmaps ['dup (\000) 0 get /C0 put',..]
> metrics ['/C0 1251 def',.]
> bboxes ['/C29 [0 0 512 0] def',...]
> chardefs ['/C0 {newpath 224 418 m 234 336 ..def}',..]
> 
> ie a bunch of lists of strings which are eventually joined together and
> written out with a template to make the postscript definition.

And the UniqueID should be unique within this file, right?

Why don't you just use a serial number then?

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


Re: noob question How do I run a Python script.

2007-06-28 Thread Matimus
> I installed python, run the interpreter and the script...

Are you trying to run the script from the interpreter? You _can_ run
scripts from the interpreter, but it isn't as simple as typing the
name of the script. To me, that is what it sounds like you are trying
to do. I don't know what environment you are using, but at the command
line (terminal) you should just type the following to run the script:

python cleanmbox.py

Actually, if you are using *nix use chmod +x chanmbox.py to tell the
os it is executable, and then just run "cleanbox.py". If you are using
windows, then you don't even have to do that, just double click on it.

-Matt


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


Re: urllib2 : https and proxy

2007-06-28 Thread O.R.Senthil Kumaran
> Hello all,
> 
> I'm facing a strange behavior of urllib2 trying to access gmail
> account behind a proxy (Squid).
> 

First off, your password wont work. See if you can get a new one. :-)
Then to setup proxy suppor for urllib2, do the steps:


 
proxy_url = 'http://' + PROXY_USER + ':' + PROXY_PASSWORD + \
'@' + PROXY_IP + ':' + PROXY_PORT
proxy_support = urllib2.ProxyHandler({'http': proxy_url})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)

Substitute PROXY_* with actual values and then do urllib2.urlopen(site) which 
will go through the proxy.
 
-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Threads Dying?

2007-06-28 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I've got an application that seems to be a little bit unstable and freezes
quite a bit, and I'm suspecting it's something in one of my threads that's
causing the problem, when does a thread die? And how can I be sure that its
dyeing when its mean to be?

 

Thanks guys,

 

Rob

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

Re: try/except/else/finally problem

2007-06-28 Thread Sebastian Wiesner
[ Ed Jensen <[EMAIL PROTECTED]> ]
> try:
> f = file('test.txt', 'r')
> except IOError:
> print 'except'
> else:
> print 'else'
> finally:
> print 'finally'
>
>
> And the results are:
>
>   File "./test.py", line 9
> finally:
>   ^
> SyntaxError: invalid syntax

A finally block isn't allowed to appear together with an except block for 
releases previous to 2.5. You need to split your exception handling into 
two separate blocks.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: try/except/else/finally problem

2007-06-28 Thread Peter Otten
Ed Jensen wrote:

> I'm using:
> 
> Python 2.3.2 (#1, Oct 17 2003, 19:06:15) [C] on sunos5
> 
> 
> And I'm trying to execute:
> 
> #! /usr/bin/env python
> 
> try:
> f = file('test.txt', 'r')
> except IOError:
> print 'except'
> else:
> print 'else'
> finally:
> print 'finally'
> 
> 
> And the results are:
> 
>   File "./test.py", line 9
> finally:
>   ^
> SyntaxError: invalid syntax
> 
> 
> What am I doing wrong?

You need Python 2.5 for that to work. In older Python versions you have to
nest try...except...else and try...finally.

Peter


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


try/except/else/finally problem

2007-06-28 Thread Ed Jensen
I'm using:

Python 2.3.2 (#1, Oct 17 2003, 19:06:15) [C] on sunos5


And I'm trying to execute:

#! /usr/bin/env python

try:
f = file('test.txt', 'r')
except IOError:
print 'except'
else:
print 'else'
finally:
print 'finally'


And the results are:

  File "./test.py", line 9
finally:
  ^
SyntaxError: invalid syntax


What am I doing wrong?

Thanks in advance for any help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Evolution of a pythonistas!

2007-06-28 Thread swordofrue
Thanks everyone for your responses. I am really loving this. Installed
Pygame and playing some of those games. It just amazes me how much
effort some of these games take. I am reading the source and am just
amazed by the effort and organizational ability of the authors.
Perhaps one day I will such mad skills :)

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


Re: noob question How do I run a Python script.

2007-06-28 Thread kyosohma
On Jun 28, 12:17 pm, CarlP <[EMAIL PROTECTED]> wrote:
> How do I run a Python script. I have one that gmail loader needs to
> run on my email box. Here's the script
>
> http://www.marklyon.org/gmail/cleanmbox.py
>
> I can't seem to find what I need to run it. I installed python, run
> the interpreter and the script , but all it will do is say invalid
> syntax.
>
> Thanks

Please post the traceback too. That will aid in helping you.

Mike

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


Memory leak in PyQt application

2007-06-28 Thread Alexander Eisenhuth
Hello alltogether,

My System:

Python 2.5.1
Boost.Python
Qt 4.2.2
SIP 4.6
PyQt 4.2
WinXp

I've a memory leak in a PyQt application and no idea how to find it. What 
happens in the application ?

 From QWindow a QDialog is called on a button "pressed()" signal, that 
instantiate a QThread and waits for it. If the thread has finished, the QDialog 
closes.

I've stipped down everything that nothing more happens (to me obviously). 
Boost.Python is used to wrap a C++ Lib (used in the thread). Every time memory 
usage increases for ~70 KB.

Sometimes the application crash on closing QWindow. (QtCore.dll)

- One thing I ask me is weather garbage collection is done in the PyQt main 
loop?

What hints do you have to find the leak?

Help is very very welcome

Regards
Alexander


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


Re: Help needed for Pmw and WxPython Interface

2007-06-28 Thread senthil arasu

I

On 6/28/07, senthil arasu <[EMAIL PROTECTED]> wrote:


Hi,
Iam creating tab pages using pmw
  nb = Pmw.NoteBook(master)
p1 = nb.add('Page 1')
p2 = nb.add('Page 2')
p3 = nb.add('Page 3')

created button control for every tabe page to open HTML

Button(p1, fg='blue',command=f.call,command=call1).pack(pady=40)
 Button(p2, fg='blue',command=f.call,command=call2).pack(pady=40)
Button(p3, fg='blue',command=f.call,command=call2).pack

since HTML rendering supported in WxPython library .I have defined call
backs with WxPython HTML routines

eg.
def call1:()
{

html.LoadPage("http://wxwidgets.org/manuals/2.5.4/wx_wxbutton.html";)

 }

Iam facing problem in integration of both the libraries.

Is it possible to integrate the functionalities of libraries WxPython and
pmw.?

please help me.



thanks







iS IT



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

noob question How do I run a Python script.

2007-06-28 Thread CarlP
How do I run a Python script. I have one that gmail loader needs to
run on my email box. Here's the script

http://www.marklyon.org/gmail/cleanmbox.py

I can't seem to find what I need to run it. I installed python, run
the interpreter and the script , but all it will do is say invalid
syntax.


Thanks

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


Re: Tkinter pack_forget() and destroy()

2007-06-28 Thread Rajendran Appavu
I asked just to be sure.

Thank you.

Rajendran.


On 6/28/07, Eric Brunel <[EMAIL PROTECTED]> wrote:
> On Thu, 28 Jun 2007 07:45:08 +0200, Rajendran Appavu <[EMAIL PROTECTED]>
> wrote:
>
> > When I am done with a widget that is packed in a Frame, is it safe to
> > call destroy() method on the widget after calling its pack_forget() or
> > grid_forget() method?
>
> Since I do that all the time, I'd say yes... Did you have a problem? Or do
> you ask just to be sure?
>
> HTH
> --
> python -c "print ''.join([chr(154 - ord(c)) for c in
> 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 

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


Re: Help needed for Pmw and WxPython Interface

2007-06-28 Thread Chris Mellon
On 6/28/07, senthil arasu <[EMAIL PROTECTED]> wrote:

> Is it possible to integrate the functionalities of libraries WxPython and
> pmw.?
>

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


Re: Excuse me!!

2007-06-28 Thread Michael Hoffman
[EMAIL PROTECTED] wrote:

> Haven't you thought about what is the right religion?!

Sure, why do you think I use Python?

> Here you will get the answer

Agreed.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Evolution of a pythonistas!

2007-06-28 Thread Sells, Fred
> 
> Wow Fred! You're awesome! How did you get 20 years in of Python when
> it was created in 1991? 

You're right, programming skills exceed basic math.  I think I started
around 1990 with version 0.92 beta.

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-28 Thread Rustom Mody
On 6/28/07, Andreas Eder <[EMAIL PROTECTED]> wrote:

> Twisted> In the other corner, we have just about every Unix application 
> ever
> Twisted> developed. When a user needs help, they may do such things as 
> manually
> Twisted> explore the directories where the application was installed
> Twisted> (equivalent to rooting around in C:\Program Files\Appname for 
> .hlp
> Twisted> files, because F1 didn't work and there was no "help" menu, if 
> such a
> Twisted> thing ever happened on Windoze).
>
> Ever heard of man pages? and info?
Hi Andreas:

Yeah thats the problem there's the 40 year old man and the 20 year
old info and then yelp and random stuff in /usr/doc and of course then
theres google and... and...

So its not that theres too little info but too much and unnecessarily
similar and inconsistent.

Twisted may not know what he's talking about but Ive used Unix (xenix)
starting 1986 and emacs from '93 so I can say that the state of linux
is not all that great.

Apart from the help-itis mentioned above there are:
-- distro-itis -- its almost as difficult to move from debian/ubuntu
to redhat I as moving to windows
-- script-itis -- why must we have perl and python and ruby (and tcl
and lua and...)
-- emacs-itis -- Ive mostly only used gnu-emacs but at least once I
had to use xemacs for running APL.

Sorry... I dont want to start another flame-war but my main point is
that we geeks think that the issues are technical when the real issues
are unfruitful political divisions.

Sure you can fire me for my views but before you do just reflect:
How different were dos and unix 20 years back and today how different
is a gnome-topped linux from a win-XP and then say whether ths issues
are essentially technical or political.

Hi Twisted:
I could give real (not made up) horror stories of my use of windows as
much as you give of your use of emacs/linux -- but I dont translate my
ignorance into condemnation.

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


Re: problem with hack using multiple inheritance for plugins

2007-06-28 Thread massimo s.
Uh, oh.

I think I found the bug, and it was a *really stupid bug*.
The list of GUI_PLUGINS was empty... so there was no plugin class that
was inherited.

I'm embarrassed to have wasted your time that way. However I learned a
lot about new-style classes and so on, so for me it was a learning
experience nonetheless.

Really sorry for wasting your time. I should use a debugger, I know. :
(

Thanks a lot for your patience,

M.

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


Re: problem with hack using multiple inheritance for plugins

2007-06-28 Thread massimo s.
On 28 Giu, 15:37, Peter Otten <[EMAIL PROTECTED]> wrote:

> Post a self-contained example.

Now I'm even more confused. The self-contained example is below... and
it works, using only old-style declarations.

#!/usr/bin/env python

import wx
import cmd

global CLI_PLUGINS
global GUI_PLUGINS

class MyCmd(cmd.Cmd):


def do_hello(self,args):
print 'hello'

class PlugCmd:

def _plug_init(self):
print 'init plugcmd'

def do_wow(self,args):
print 'wow'

#--
class MyFrame(wx.Frame):

def __init__(self,parent,id,title):

ID_FRAME=-1
 
wx.Frame.__init__(self,parent,ID_FRAME,title,size=(800,600),style=wx.DEFAULT_FRAME_STYLE|
wx.NO_FULL_REPAINT_ON_RESIZE)

print dir(self)

for item in GUI_PLUGINS:
item._plug_init(self)

class PlugFrame:

 def _plug_init(self):
 print 'init plugframe'


CLI_PLUGINS=[PlugCmd]
GUI_PLUGINS=[PlugFrame]

def main():
app=wx.PySimpleApp()


def make_cli_class(*bases):
#return type(MainWindow)("MainWindowPlugged", bases +
(MainWindow,), {})
return type(MyCmd)("CliPlugged", bases + (MyCmd,), {})

def make_gui_class(*bases):
#return type(MainWindow)("MainWindowPlugged", bases +
(MainWindow,), {})
return type(MyFrame)("MainWindowPlugged", bases +
(MyFrame,), {})

my_cli=make_cli_class(*CLI_PLUGINS)()
main_frame = make_gui_class(*GUI_PLUGINS)(None, -1, ('Test'))
main_frame.Show()

#run one loop or the other when testing
#app.MainLoop()
my_cli.cmdloop()

main()

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


Help needed for Pmw and WxPython Interface

2007-06-28 Thread senthil arasu

Hi,
Iam creating tab pages using pmw
 nb = Pmw.NoteBook(master)
   p1 = nb.add('Page 1')
   p2 = nb.add('Page 2')
   p3 = nb.add('Page 3')

created button control for every tabe page to open HTML

Button(p1, fg='blue',command=f.call,command=call1).pack(pady=40)
Button(p2, fg='blue',command=f.call,command=call2).pack(pady=40)
Button(p3, fg='blue',command=f.call,command=call2).pack

since HTML rendering supported in WxPython library .I have defined call
backs with WxPython HTML routines

eg.
def call1:()
{

   html.LoadPage("http://wxwidgets.org/manuals/2.5.4/wx_wxbutton.html";)

}

Iam facing problem in integration of both the libraries.

Is it possible to integrate the functionalities of libraries WxPython and
pmw.?

please help me.



thanks







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

Re: Collections of non-arbitrary objects ?

2007-06-28 Thread Peter Otten
walterbyrd wrote:

> I can do this:

> x = tuple(sorted(list((3,2,1

The list() conversion is superfluous:

>>> tuple(sorted((3,2,1)))
(1, 2, 3)

Peter

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


Re: Collections of non-arbitrary objects ?

2007-06-28 Thread walterbyrd
>
> Did you try to sort a tuple ?
>
>  >>> (1, "aaa").sort()
> Traceback (most recent call last):
>File "", line 1, in ?
> AttributeError: 'tuple' object has no attribute 'sort'

I can do this:

>>> x = (3,2,1)
>>> x = tuple(sorted(list(x)))

Which, although senseless, effectively sorts the x tuple. But, you are
right, I am not really sorting the tuple, I'm sorting a list, which
has been made from the tuple, then changing it back to a tuple.

Actually, I can even do it in one line:

x = tuple(sorted(list((3,2,1


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


Excuse me!!

2007-06-28 Thread mossab00019
Excuse me!!
Would you stop for a moment?!
Haven't you thought-one day- about yourself ?
Who has made it?
Have you seen a design which hasn't a designer ?!
Have you seen a wonderful,delicate work without a worker ?!
It's you and the whole universe!..
Who has made them all ?!!
You know who ?.. It's "ALLAH",prise be to him.
Just think for a moment.
How are you going to be after death ?!
Can you believe that this exact system of the universe and all of
these great creation will end in nothing...just after death!
Have you thought, for a second, How to save your soul from Allah's
punishment?!
Haven't you thought about what is the right religion?!
Here you will get the answer

http://www.anashed.net/flash/lastb_reath.swf
http://www.todayislam.com/
http://www.islam-guide.com
http://www.sultan.org

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


Re: listing the type of an object

2007-06-28 Thread Bruno Desthuilliers
Neil Cerutti a écrit :
> On 2007-06-28, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
>> Stef Mientki a écrit :
>>> How can I list a type of an object instance ?
>>>
>>> I tried:
>>>
>>> class tLED (tDevice):
>> 
>> Do yourself (and the world) a favour and give up hungarian notation... 
>> This should be:
>>
>> class Led(Device):
>> #...
> 
> Using a naming convention for class objects, e.g., camel-case, is
> a practice very similar to hungarian notation.

And it's not even totally consistant since builtin types are usually 
lowercase. But it's still the convention.

> I would've said something like: start learning the Python
> community's naming conventions, and use those instead of
> inventing your own.

The TMyType convention comes from Delphi. So let's make this:

"""
start learning the Python
community's naming conventions, and use those instead of the ones of 
your usual language
"""

!-)

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


Re: Face Recognition

2007-06-28 Thread ce
On Jun 26, 5:37 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Henrik Lied wrote:
> > Hi there!
>
> > Has anyone made effort to try to create a python binding to a facial
> >recognitionsoftware [1]?
>
> > For those of you with some experience - would this be very hard?
>
> OpenCV has a python-binding. And a ctypes-binding.
>
> Diez

I would add that the OpenCV includes face recognition example.


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


Re: Face Recognition

2007-06-28 Thread ce
On Jun 26, 5:37 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Henrik Lied wrote:
> > Hi there!
>
> > Has anyone made effort to try to create a python binding to a facial
> >recognitionsoftware [1]?
>
> > For those of you with some experience - would this be very hard?
>
> OpenCV has a python-binding. And a ctypes-binding.
>
> Diez


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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-28 Thread Bruno Desthuilliers
Bjoern Schliessmann a écrit :
> Bruno Desthuilliers wrote:
>> John Nagle a écrit :
> 
>>> Actually, static typing is for detecting errors before the
>>> program is run.
>> [EMAIL PROTECTED] ~ $ gcc -ototo toto.c
>> [EMAIL PROTECTED] ~ $ ./toto
>> Erreur de segmentation
>> [EMAIL PROTECTED] ~ $
>>
>> You said ?
> 
> Did he say that static typing detects all errors?

Nope, he just asserted something wrong. Static typing is for compiler 
optimization. Type checking is at most a side effect, and in some 
languages (at least C, C++ and Java) can be totally defeated (usually 
using typecasting).

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


Segfault due to threads created by external modules

2007-06-28 Thread [EMAIL PROTECTED]
Dear list,

I'm using two external modules (matplotlib and pyroot). Both are using
different GUI threads (internally) Unfortunately, pretty soon after
I've loaded both modules and made some function calls (without
invoking GUI commands), python dies with a segfault. A libthread_db
captures the stack trace. My python version is 2.5 and I'm on a
Scientific Linux 5 system.

 *** Break *** segmentation violation
Using host libthread_db library "/lib/libthread_db.so.1".
Attaching to program: /proc/20957/exe, process 20957
[Thread debugging using libthread_db enabled]
[New Thread -1208964416 (LWP 20957)]
[New Thread 133323664 (LWP 20964)]
[New Thread 48200592 (LWP 20958)]
0x009e2402 in __kernel_vsyscall ()
Thread 3 (Thread 48200592 (LWP 20958)):
#0  0x009e2402 in __kernel_vsyscall ()
#1  0x4e94bf91 in ___newselect_nocancel () from /lib/libc.so.6
#2  0x0494fcac in Tcl_InitNotifier () from /usr/lib/libtcl8.4.so
#3  0x4e9f92db in start_thread () from /lib/libpthread.so.0
#4  0x4e95312e in clone () from /lib/libc.so.6

Thread 2 (Thread 133323664 (LWP 20964)):
#0  0x009e2402 in __kernel_vsyscall ()
#1  0x4e9ff14e in [EMAIL PROTECTED] () from /lib/libpthread.so.0
#2  0x00f2166e in PyThread_acquire_lock (lock=0x89b1ea8, waitflag=1)
at Python/thread_pthread.h:349
#3  0x00eeff27 in PyEval_RestoreThread (tstate=0xa255820) at Python/
ceval.c:312
#4  0x002bec23 in time_sleep (self=0x0, args=0x9afcfec) at /tmp/bvoigt/
Python-2.5.1/Modules/timemodule.c:921
#5  0x00ea900d in PyCFunction_Call (func=0xb7e544ac, arg=0x9afcfec,
kw=0x0) at Objects/methodobject.c:108
#6  0x00ef65df in PyEval_EvalFrameEx (f=0xa30028c, throwflag=0) at
Python/ceval.c:3564
#7  0x00ef7734 in PyEval_EvalCodeEx (co=0xb7cd7698,
globals=0xb7cb813c, locals=0x0, args=0x9afcfd8, argcount=1,
kws=0xa05cf40, kwcount=0, defs=0x0,
defcount=0, closure=0x0) at Python/ceval.c:2831
#8  0x00e953c0 in function_call (func=0xb7cdad14, arg=0x9afcfcc,
kw=0x9af99bc) at Objects/funcobject.c:517
#9  0x00e734f7 in PyObject_Call (func=0x0, arg=0x9afcfcc,
kw=0x9af99bc) at Objects/abstract.c:1860
#10 0x00ef441b in PyEval_EvalFrameEx (f=0xa30012c, throwflag=0) at
Python/ceval.c:3844
#11 0x00ef6260 in PyEval_EvalFrameEx (f=0xa2fff9c, throwflag=0) at
Python/ceval.c:3650
#12 0x00ef7734 in PyEval_EvalCodeEx (co=0xb7d93a88,
globals=0xb7d9024c, locals=0x0, args=0x9afcfb8, argcount=1, kws=0x0,
kwcount=0, defs=0x0,
defcount=0, closure=0x0) at Python/ceval.c:2831
#13 0x00e952ea in function_call (func=0xb7d9d09c, arg=0x9afcfac,
kw=0x0) at Objects/funcobject.c:517
#14 0x00e734f7 in PyObject_Call (func=0x0, arg=0x9afcfac, kw=0x0) at
Objects/abstract.c:1860
#15 0x00e7ad15 in instancemethod_call (func=0x9af6054, arg=0x9afcfac,
kw=0x0) at Objects/classobject.c:2497
#16 0x00e734f7 in PyObject_Call (func=0x0, arg=0xb7eca02c, kw=0x0) at
Objects/abstract.c:1860
#17 0x00eef43c in PyEval_CallObjectWithKeywords (func=0x9af6054,
arg=0xb7eca02c, kw=0x0) at Python/ceval.c:3433
#18 0x00f25d14 in t_bootstrap (boot_raw=0xa24eec8) at ./Modules/
threadmodule.c:424
#19 0x4e9f92db in start_thread () from /lib/libpthread.so.0
#20 0x4e95312e in clone () from /lib/libc.so.6

Thread 1 (Thread -1208964416 (LWP 20957)):
#0  0x009e2402 in __kernel_vsyscall ()
#1  0x4e9136ab in __waitpid_nocancel () from /lib/libc.so.6
#2  0x4e8bba0f in do_system () from /lib/libc.so.6
#3  0x4e8bbdc2 in system () from /lib/libc.so.6
#4  0x4ea010bd in system () from /lib/libpthread.so.0

I have no idea how to solve this. Somebody else has an idea?

Thanks! Bernhard

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


Re: problem with hack using multiple inheritance for plugins

2007-06-28 Thread Bruno Desthuilliers
massimo s. a écrit :
> On 28 Giu, 14:41, "massimo s." <[EMAIL PROTECTED]> wrote:
> 
>> The new-style behaviour only appears when wxFrame is plugged with the
>> current hack.
>> That is:
>>
>> - print type(self) in wxFrame alone returns 
>> - print type(self) in the plugged (multiply inherited) wxFrame returns
>> < class '__main__.MainWindowPlugged'>
>>
>> So the problem is that I acquire a new style behaviour somewhere!
> 
> Forget this one, it is wrong (Don't know how did I obtain it).
> I rechecked and, yes, problem is that cmd.Cmd is old-style (and the
> plugin hack works) while wxFrame is new style (and the plugin hack
> works no more).
> 
> Again: using a new-style plugin class for multiple inheritance does
> not work.

I doubt this is really the problem. Obviously Petter's brain works 
better than mine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-28 Thread Andy Freeman
On Jun 27, 11:41 pm, John Nagle <[EMAIL PROTECTED]> wrote:
> One right answer would be a pure reference counted system where
> loops are outright errors, and you must use weak pointers for backpointers.
> ... The general
> idea is that pointers toward the leaves of trees should be strong
> pointers, and pointers toward the root should be weak pointers.

While I agree that weak pointers are good and can not be an
afterthought, I've written code where "back" changed dynamically, and
I'm pretty sure that Nagle has as well.

Many programs with circular lists have an outside pointer to the
current element, but the current element changes.  All of the links
implementing the list have to be strong enough to keep all of the list
alive.

Yes, one can implement a circular list as a vector with a current
index, but that has space and/or time consequences.  It's unclear that
that approach generalizes for more complicated structures.  (You can't
just pull all of the links out into such lists.)

In short, while disallowing loops with strong pointers is "a" right
answer, it isn't always a right answer, so it can't be the only
answer.

-andy

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


Re: problem with hack using multiple inheritance for plugins

2007-06-28 Thread Bruno Desthuilliers
massimo s. a écrit :
> On 28 Giu, 13:45, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
>> 
>> wrt/ this snippet:
>>
>> for plugin_name in self.config['plugins']:
>>  try:
>>  plugin=__import__(plugin_name)
>>  try:
>>  print type(self)
>>  eval('plugin.'+plugin_name+'Commands._plug_init(self)')
>>  except AttributeError:
>>  pass
>>  except ImportError:
>>  pass
>>
>> You may want to try this instead:
>>
>> for plugin_name in self.config['plugins']:
>>  try:
>>  plugin=__import__(plugin_name)
>>  except ImportError:
>>  # eventually do something like logging the error ?
>>  continue
>>  try:
>>  cmdplug = getattr(plugin, plugin_name+'Commands')
>>  cmdplug._plug_init(self)
>>  except AttributeError:
>>  # eventually do something like logging the error ?
>>  continue
> 
> Tried, same error as before :(
> 

Sorry, I failed to make clear that this was not suppoed to solve your 
current problem - just to avoid using eval() when not necessary.
-- 
http://mail.python.org/mailman/listinfo/python-list


compiling extension using distutils and visual studio 2003

2007-06-28 Thread markybob
I'm trying to get Deluge ported to work on Windows, but unfortunately
I can't seem to figure how to fix this error.  Any help would be
*greatly* appreciated.  First off, here's the code to the setup.py
file (http://dev.deluge-torrent.org/browser/trunk/setup.py?
rev=809&format=txt)
And here is the error:
C:\Documents and Settings\James\Desktop\deluge>python setup.py build
Attempting to detect your system information
Couldn't detect CPU architecture
Windows system detected
Libraries mt
running build
running build_py
creating build
creating build\lib.win32-2.5
creating build\lib.win32-2.5\deluge
copying src\common.py -> build\lib.win32-2.5\deluge
copying src\core.py -> build\lib.win32-2.5\deluge
copying src\deluge_stats.py -> build\lib.win32-2.5\deluge
copying src\dgtk.py -> build\lib.win32-2.5\deluge
copying src\dialogs.py -> build\lib.win32-2.5\deluge
copying src\interface.py -> build\lib.win32-2.5\deluge
copying src\ipc_manager.py -> build\lib.win32-2.5\deluge
copying src\plugins.py -> build\lib.win32-2.5\deluge
copying src\pref.py -> build\lib.win32-2.5\deluge
copying src\__init__.py -> build\lib.win32-2.5\deluge
running build_ext
building '_deluge_core' extension
creating build\temp.win32-2.5
creating build\temp.win32-2.5\Release
creating build\temp.win32-2.5\Release\src
creating build\temp.win32-2.5\Release\libtorrent
creating build\temp.win32-2.5\Release\libtorrent\src
creating build\temp.win32-2.5\Release\libtorrent\src\kademlia
Traceback (most recent call last):
 File "setup.py", line 335, in 
   cmdclass=cmdclass
 File "c:\python25\lib\distutils\core.py", line 151, in setup
   dist.run_commands()
 File "c:\python25\lib\distutils\dist.py", line 974, in run_commands
   self.run_command(cmd)
 File "c:\python25\lib\distutils\dist.py", line 994, in run_command
   cmd_obj.run()
 File "setup.py", line 293, in run
   _build.run(self)
 File "c:\python25\lib\distutils\command\build.py", line 112, in run
   self.run_command(cmd_name)
 File "c:\python25\lib\distutils\cmd.py", line 333, in run_command
   self.distribution.run_command(command)
 File "c:\python25\lib\distutils\dist.py", line 994, in run_command
   cmd_obj.run()
 File "c:\python25\lib\distutils\command\build_ext.py", line 290, in
run
   self.build_extensions()
 File "c:\python25\lib\distutils\command\build_ext.py", line 416, in
build_exte
nsions
   self.build_extension(ext)
 File "c:\python25\lib\distutils\command\build_ext.py", line 481, in
build_exte
nsion
   depends=ext.depends)
 File "c:\python25\lib\distutils\ccompiler.py", line 697, in compile
   self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
 File "c:\python25\lib\distutils\cygwinccompiler.py", line 150, in
_compile
   extra_postargs)
TypeError: can only concatenate list (not "str") to list

C:\Documents and Settings\James\Desktop\deluge>

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


pypdf assert error on documentinfo

2007-06-28 Thread Tim Arnold
Using pyPdf, nice user interface. Maybe it doesn't handle pdf 1.4? I'm 
getting an assertion error from the following code. The pdf file shows it 
does have a title in its document info (using acrobat 8 or reader 5).

pdf is version 1.4, produced with pdfeTex (pdflatex) 1.304
using python 2.4.1

# file test.py 
import pyPdf
filename = 'test.pdf'
test= pyPdf.PdfFileReader(open(filename,'rb'))
print test.getNumPages()
tmp = test.getDocumentInfo()

===
python test.py
55
Traceback (most recent call last):
File "test.py", line 6, in ?
tmp =  test.getDocumentInfo()
  File "tiarno/pyPdf-1.9/pyPdf/pdf.py", line 291, in getDocumentInfo
obj = self.getObject(self.trailer['/Info'])
  File "tiarno/pyPdf-1.9/pyPdf/pdf.py", line 407, in getObject
retval = readObject(self.stream, self)
  File "tiarno/pyPdf-1.9/pyPdf/generic.py", line 64, in readObject
return DictionaryObject.readFromStream(stream, pdf)
  File "tiarno/pyPdf-1.9/pyPdf/generic.py", line 348, in readFromStream
assert False
AssertionError

===


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


Re: equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)

2007-06-28 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote:

> In object oriented programming, objects are representations of values, and the
> system shouldn't care about how many instances there are of some value, just
> like numbers in math. Every instance with a certain value is the same as every
> other instance with the same value.

Whether two things are equal depends on the context.  Is one $10 note equal 
to another?  It depends.

If the context is a bank teller making change, then yes, they are equal.  
What's more, there are lots of sets of smaller notes which would be equally 
fungible.

If the context is a district attorney showing a specific $10 note to a jury 
as evidence in a drug buy-and-bust case, they're not.  It's got to be 
exactly that note, as proven by a recorded serial number.

In object oriented programming, objects are representations of the real 
world.  In one case, the $10 note represents some monetary value.  In 
another, it represents a piece of physical evidence in a criminal trial.  
Without knowing the context of how the objects are going to be used, it's 
really not possible to know how __eq__() should be defined.

Let me give you a more realistic example.  I've been doing a lot of network 
programming lately.  We've got a class to represent an IP address, and a 
class to represent an address-port pair (a "sockaddr").  Should you be able 
to compare an address to a sockaddr?  Does 192.168.10.1 == 192.168.10.1:0?  
You tell me.  This is really just the "does 1 == (1 + 0j)" question in 
disguise.  There's reasonable arguments to be made on both sides, but there 
is no one true answer.  It depends on what you're doing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with hack using multiple inheritance for plugins

2007-06-28 Thread massimo s.
On 28 Giu, 15:37, Peter Otten <[EMAIL PROTECTED]> wrote:
> massimo s. wrote:
> > Again: using a new-style plugin class for multiple inheritance does
> > not work.
>
> This statement is certainly too broad.
>
> [earlier]
>
> > TypeError: unbound method _plug_init() must be called with
> > dummyguiplugGui instance as first argument (got MainWindowPlugged
> > instance instead)
>
> So it looks like you failed to make dummyguiplugGui a base class of
> MainWindowPlugged.

Right (Checked with dir() -dummyguiplugGui methods do not appear ).

> > What can I do now?
>
> Post a self-contained example.

I'll try.

m.

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


Re: making a opc client in Python and use opc server Events

2007-06-28 Thread jp . eugster
On 4 juin, 11:32, [EMAIL PROTECTED] wrote:
> Hi all
> I have a sample code to implement opc client in Python. i use a
> file .py making by makepy with pythonwin for Com Interface.
> i can get all server in machine, connect to server opc, disconnect,
> add group, add item, read, write item in server opc.
>
> import win32com.client  # librairie pour utiliser l'interface COM/DCOM
> from win32com.client import gencache
> gencache.EnsureModule('{DFB83232-A952-11D2-A46B-00C04F796375}', 0, 1,
> 0)
>
> for svr in opcserver.GetOPCServers():
> print svr
>
> #connect to server OPC Demo Simulation from Matrikon
> opcserver.Connect('Matrikon.OPC.Simulation.1')
>
> # Instance object Groups
> groups=opcserver.OPCGroups
> #add group
> group=groups.Add('Group1')
>
> #instance onject Items
> items=group.OPCItems
> # add item in server opc
> tem=items.AddItem('File1.item1',1)
>
> #read item value
> item.Read(win32com.client.constants.OPCDevice)
>
> # write a new value
> item.Write(100)
>
> #read item value
> item.Read(win32com.client.constants.OPCDevice)
> #if no pb you have 100 :)
>
> #Disconnect
> #opcserver.Disconnect()
>
> BUT, and BUT, i want to use a event from opc server for uodating item
> value with this below class. And i don't konw how make it
> help me plz
>
> opcserver=win32com.client.Dispatch('OPC.Automation.1')
> and now i want to use events from opc server. in a class:
> class DIOPCGroupEvent:
> class DIOPCGroupsEvent:
> class DIOPCServerEvent:

Try this:

# Event Handlers
class ServerEvent:
def __init__(self):
print 'Init ServerEvent'

def OnServerShutDown(self, Reason):
print 'OnServerShutDown', Reason

class GroupEvent:
def __init__(self):
print 'Init GroupEvent'

def OnAsyncCancelComplete(self, CancelID):
print 'OnAsyncCancelComplete', CancelID

def OnDataChange(self, TransactionID, NumItems, ClientHandles,
ItemValues, Qualities, TimeStamps):
print 'OnDataChange', zip(ClientHandles, ItemValues, Qualities)

def OnAsyncReadComplete(self, TransactionID, NumItems, ClientHandles,
ItemValues, Qualities,
 TimeStamps, Errors):
print 'OnAsyncReadComplete', zip(ClientHandles, ItemValues,
Qualities)

def OnAsyncWriteComplete(self, TransactionID, NumItems,
ClientHandles, Errors):
print 'OnAsyncWriteComplete', zip(ClientHandles, Errors)

class GroupsEvent:
def __init__(self):
print 'Init GroupsEvent'

def OnGlobalDataChange(self, TransactionID, GroupHandle, NumItems,
ClientHandles, ItemValues,
 Qualities, TimeStamps):
print 'OnGlobalDataChange', zip(ClientHandles, ItemValues,
Qualities)

opc = DispatchWithEvents('Matrikon.OPC.Automation.1', ServerEvent)

groups = DispatchWithEvents(opc.OPCGroups, GroupsEvent)
groups.DefaultGroupIsActive = True
groups.DefaultGroupUpdateRate = 2000

group1 = DispatchWithEvents(groups.Add('G1'), GroupEvent)
group2 = DispatchWithEvents(groups.Add('G2'), GroupEvent)
#etc ...

It works for the GroupsEvents but I don't get the GroupEvent for each
group, I may still do someting wrong..

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


Re: equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)

2007-06-28 Thread A.T.Hofkamp
On 2007-06-28, Alan Isaac <[EMAIL PROTECTED]> wrote:
> A.T.Hofkamp wrote:
>
>a = Car2(123)
>b = Car2(123)
>a == b
>> 
>> True
>> 
>set([a,b])
>> 
>> set([Car2(123), Car2(123)])
>> 
>> I get a set with two equal cars, something that never happens with a set
>> my math teacher once told me.
>
>
> Then your math teacher misspoke.
> You have two different cars in the set,
> just as expected.  Use `is`.
> http://docs.python.org/ref/comparisons.html
>
> This is good behavior.

Hmm, maybe numbers in sets are broken then?

>>> a = 12345
>>> b = 12345
>>> a == b
True
>>> a is b
False
>>> set([a,b])
set([12345])


Numbers and my Car2 objects behave the same w.r.t. '==' and 'is', yet I get a
set with 1 number, and a set with 2 cars.
Something is wrong here imho.

The point I intended to make was that having a default __hash__ method on
objects give weird results that not everybody may be aware of.
In addition, to get useful behavior of objects in sets one should override
__hash__ anyway, so what is the point of having a default object.__hash__ ?

The "one should override __hash__ anyway" argument is being discussed in my
previous post.


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


Re: Portable general timestamp format, not 2038-limited

2007-06-28 Thread sla29970
On Jun 27, 10:51 pm, Paul Rubin  wrote:
> According to , UTC is derived from
> TAI.

According to , TAI is a proper time,
but the very first section in the TAI discussion page cites a refereed
paper by the person then in charge of TAI which asserts that is not
true.

As for the primacy of UTC vs. TAI, this is the classical chicken and
egg problem.  The bureaucratic reality is opposed to the physical
reality.

> it's always within 20 nsec.  This seems like the kind of correction
> that can be applied after the fact.

It is the nature of horology that *all* clocks need corrections
applied after the fact.  The question is whether a given clock and its
time distribution system is good enough for the given application.

> The difficulty/impossibility of computing intervals on UTC because of leap 
> seconds suggests TAI is a superior timestamp format.

TAI is a superior time scale for processes on the surface of the earth
which only care about nanosecond precision, but it is not practically
available nor legal nor applicable off the surface of the earth.  TAI
is itself corrected after the fact by the issue of TT(BIPMxx).


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


Re: 16bit hash

2007-06-28 Thread Robin Becker
Thomas Jollans wrote:
> Robin Becker wrote:
...
>> I'm not sure my postscript is really good enough to do the latter so I
>> hoped to pursue a python based approach which has a low probability of
>> busting. Originally I thought the range was a 16bit number which is why
>> I started with 16bit hashes.
> 
> 
> For identifying something, I suggest you use a hash function like sha1
> truncating it to as much as you can use, similarly to what Jon Ribbens
> suggested.

that is in fact what I'm doing; my function looks like this

400+(reduce(operator.xor,struct.unpack('i'*4,md5.md5(s).digest()))&0x3)

whether it's any better than using the lowest bits I have no real idea. I 
suppose (sha being flavour of the month) I should really use

400+(reduce(operator.xor,struct.unpack('i'*5,sha.sha(s).digest()))&0x3)

-- 
Robin Becker

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


Re: equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)

2007-06-28 Thread Alan Isaac
A.T.Hofkamp wrote:

a = Car2(123)
b = Car2(123)
a == b
> 
> True
> 
set([a,b])
> 
> set([Car2(123), Car2(123)])
> 
> I get a set with two equal cars, something that never happens with a set
> my math teacher once told me.


Then your math teacher misspoke.
You have two different cars in the set,
just as expected.  Use `is`.
http://docs.python.org/ref/comparisons.html

This is good behavior.

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


using urllib, urllib2 ,mechanize to access password protected site

2007-06-28 Thread comeshopcheap
Hi

I am using this script to access doba.com (I need to download some
files) but I keep on being sent back to the login page not the user
home page. Any help. I think I may need to use a post method and
opener is using a get method

Thanks

import mechanize
cookies = mechanize.CookieJar()
# build_opener() adds standard handlers (such as HTTPHandler and
# HTTPCookieProcessor) by default.  The cookie processor we supply
# will replace the default one.
opener =
mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))
opener.addheaders = [("User-agent", "Mozilla/5.0 (Windows; U; Windows
NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"), ]
data="username=user&password=pw"
#r = opener.open("http://comeshopcheap.com/";)  # GET
r = opener.open("https://www.doba.com/members/login.php";, data)  # POST

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


Re: problem with hack using multiple inheritance for plugins

2007-06-28 Thread Peter Otten
massimo s. wrote:

> Again: using a new-style plugin class for multiple inheritance does
> not work.

This statement is certainly too broad.

[earlier]
> TypeError: unbound method _plug_init() must be called with
> dummyguiplugGui instance as first argument (got MainWindowPlugged
> instance instead)

So it looks like you failed to make dummyguiplugGui a base class of
MainWindowPlugged.
 
> What can I do now?

Post a self-contained example.

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


Re: guidance needed: best practice for script packaging

2007-06-28 Thread Alan Isaac
My thanks to Gabriel and Josiah.
Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Evolution of a pythonistas!

2007-06-28 Thread BartlebyScrivener
On Jun 28, 8:02 am, "Sells, Fred" <[EMAIL PROTECTED]> wrote:
> concur 100%.

> Get a python aware editor.  I use Eclipse+PyDev for big jobs, but still use
> Emacs with python-mode for quickies.

Just when I was thinking we agreed! :)

Get Vim!

http://www.vim.org

And the Cookbook

http://www.amazon.com/Python-Cookbook-Alex-Martelli/dp/0596007973/inscape-20

That's all you need.

rd

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


Re: equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)

2007-06-28 Thread A.T.Hofkamp
On 2007-06-27, Alex Martelli <[EMAIL PROTECTED]> wrote:
> A.T.Hofkamp <[EMAIL PROTECTED]> wrote:
>
>>  I think that again now with the default implementation of the
>>  object.__eq__ and object.__hash__ methods. I believe these methods should
>>  not exist until the programmer explicitly defines them with a suitable
>>  notion of equivalence.
>> 
>>   Anybody have a good argument against that? :-)
>
> It's very common and practical (though not ideologically pure!) to want
> each instance of a class to "stand for itself", be equal only to itself:
> this lets me place instances in a set, etc, without fuss.

Convenience is the big counter argument, and I have thought about that.
I concluded that the convenience advantage is not big enough, and the problem
seems to be what "itself" exactly means.

In object oriented programming, objects are representations of values, and the
system shouldn't care about how many instances there are of some value, just
like numbers in math. Every instance with a certain value is the same as every
other instance with the same value.

You can also see this in the singleton concept. The fact that it is a pattern
implies that it is special, something not delivered by default in object
oriented programming.

This object-oriented notion of "itself" is not what Python delivers.

Python 2.4.4 (#1, Dec 15 2006, 13:51:44)
[GCC 3.4.4 20050721 (Red Hat 3.4.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Car(object):
...   def __init__(self, number):
... self.number = number
...   def __repr__(self):
... return "Car(%r)" % self.number
...

>>> 12345 == 12345
True
>>> Car(123) == Car(123)
False

So in Python, the default equivalence notion for numbers is based on values,
and the default equivalence notion for objects assumes singleton objects which
is weird from an object oriented point of view.

Therefore, I concluded that we are better off without a default __eq__ .



The default existence of __hash__ gives other nasty surprises:

>>> class Car2(object):
...def __init__(self, number):
...  self.number = number
...def __repr__(self):
...   return "Car2(%r)" % self.number
...def __eq__(self, other):
...   return self.number == other.number
...

Above I have fixed Car to use value equivalence (albeit not very robust).
Now if I throw these objects naively in a set:

>>> a = Car2(123)
>>> b = Car2(123)
>>> a == b
True
>>> set([a,b])
set([Car2(123), Car2(123)])

I get a set with two equal cars, something that never happens with a set
my math teacher once told me.

Of course, I should have defined an appropiate __hash__ method together with
the __eq__ method. Unfortunately, not every Python programmer has always had
enough coffee to think about that when he is programming a class. Even worse, I
may get a class such as the above from somebody else and decide that I need a
set of such objects, something the original designer never intended.
The problem is then that something like "set([Car2(123), Car2(124)])" does the
right thing for the wrong reason without telling me.

Without a default __hash__ I'd get at least an error that I cannot put Car2
objects in a set. In that setup, I can still construct a broken set, but I'd
have to write a broken __hash__ function explicitly rather than implicitly
inheriting it from object.


> I don't want, in order to get that often-useful behavior, to have to
> code a lot of boilerplate such as
> def __hash__(self): return hash(id(self))
> and the like -- so, I like the fact that object does it for me.  I'd

I understand that you'd like to have less typing to do. I'd like that too if
only it would work without major accidents by simple omission such as
demonstrated in the set example.


Another question can be whether your coding style would be correct here.

Since you apparently want to have singleton objects (since that is what you get
and you are happy with them), shouldn't you be using "is" rather than "=="?
Then you get the equivalence notion you want, you don't need __eq__, and you
write explicitly that you have singleton objects.

In the same way, sets have very little value for singleton objects, you may as
well use lists instead of sets since duplicate **values** are not filtered.
For lists, you don't need __hash__ either.

The only exception would be to filter multiple inclusions of the same object
(that is what sets are doing by default). I don't know whether that would be
really important for singleton objects **in general**.
(ie wouldn't it be better to explicitly write a __hash__ based on identity for
those cases?)

> have no objection if there were two "variants" of object (object itself
> and politically_correct_object), inheriting from each other either way
> 'round, one of which kept the current practical approach while the other
> made __hash__ and comparisons abstract.

Or you define your own base object class "class Myobject(object)" and add a
default __eq__ an

Re: Evolution of a pythonistas!

2007-06-28 Thread kyosohma
On Jun 28, 8:02 am, "Sells, Fred" <[EMAIL PROTECTED]> wrote:
> concur 100%.  You can breeze through the fist half of the online tutorial in
> a about 2 cups of coffee but you don't know what you don't know until you
> try to do something real.
>
> Even with 20 years of working with Python, I find goodies in the cookbook
> for each new project.
>
> Get a python aware editor.  I use Eclipse+PyDev for big jobs, but still use
> Emacs with python-mode for quickies.  Although I would never recommend Emacs
> to someone who does not already know how to use it.  IDLE is ok, for
> beginning but I find it distracting.  Eclipse can be intimidating at first,
> but if you go through the PyDev howto's, You'll learn all you need.
>
> Forget about typing stuff interactively, It is better to work in a file so
> you can see your work evolve.
>
> Finally, I have never had a project in the last 5 years that someone hasn't
> already done.  Google is your friend.  Many of the hits are misleading or
> too much code to fit what I need, but I often find a snippet that I can use.
>
> > -Original Message-

Wow Fred! You're awesome! How did you get 20 years in of Python when
it was created in 1991? Still, I think you're right. Most of the time,
I can find what I need because it's already done. I've only been
programming for just over a year and I learn something new almost
every day. And yes, the best way to learn is by "just coding".

Mike

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


  1   2   >