Parallel port programming on windows XP/2000?

2005-08-02 Thread Novice Experl
I'd like to write a simple application that interfaces with the parallel port, 
and changes the data on it according to keyboard input. I hope I can get it to 
run under windows xp and / or windows 2000.

How can I do this? What do I need to know? It doesn't look like the standard 
library (the one under my pillow) has that feature. In addition, I've heard 
that with newer versions of windows don't let you communicate with the port 
directly, instead requiring interfacing with some driver?

I came across this:
http://pyserial.sourceforge.net/pyparallel.html
but it seems to only be used for direct access (would it work with XP?), and 
hasn't been updated for a couple of years. In addition, it requires something 
called  "Java Communications" (JavaComm) extension for Java/Jython, doesn't 
provide a link to it, and when I google it - google returns the page I came 
from!

To add to the confusion, I hope I can provide a py2exe executable of my script 
instead of forcing a complete installation.


--=  Posted using GrabIt  =
--=  Binary Usenet downloading made easy =-
-=  Get GrabIt for free from http://www.shemes.com/  =-

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


Re: JBUS and Python which way

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

  Oren

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


RE: Pythoncom scripting Windows Media Player & visible

2005-08-02 Thread Stefan Schukat
Hello, 

you have to put the ocx in a container window (e.g. a dialog or the IE).
Without this the media player just acts like a normal COM object.

Example for the dialog you can find in 
[Pythonroot]\Lib\site-packages\pythonwin\pywin\Demos\ocx

Bye

Stefan

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Bill Eldridge
> Sent: Tuesday, August 02, 2005 6:15 PM
> To: python-list@python.org
> Subject: Pythoncom scripting Windows Media Player & visible
> 
> 
> I'm trying to make Windows Media Player visible and control 
> it from Python. It seems when I call it below, I get only the 
> console version, and there's no Visible method like with 
> Internet Explorer.
> I do catch events, but I need it visible.
> Should it be put into a panel instead?
> Should a different type dispatch be called or a different 
> method? it seems that there are a console and a windows 
> classes in the COM browser, but I can't seem to access any 
> useful windows classes.
> I get "fullScreen" as False, but can't set it.
> openPlayer(address) will launch a visible window, but with no 
> control of the the window after that.
> 
> Ideas?
> 
> from win32com.client import Dispatch,DispatchWithEvents
> 
> class WMPEvents:
> def OnVisible(self,evt):
> print "OnVisible changed:",evt
> def OnError(self,evt=None):
> print "OnError",evt
> def OnMediaError(self,evt=None):
> print "OnMediaError",evt
> def OnDisconnect(self,evt):
> print "OnDisconnect",evt
> def OnStatusChange(self):
> print "OnStatusChange"
> def OnDisconnect(self,evt):
> print "Disconnect",evt
> def OnBuffering(self,evt):
> print "OnBuffering changed:",evt
> def OnOpenStateChange(self,evt=None):
> print "OnOpenStateChange" ,evt
>
> mp = DispatchWithEvents("WMPlayer.OCX.7",WMPEvents)
> mp.Visible = True   # Does nothing
> tune = mp.newMedia("C:/WINDOWS/system32/oobe/images/title.wma")
> mp.currentPlaylist.appendItem(tune)
> mp.controls.playItem(tune)
> mp.controls.play()
> raw_input("Press enter to stop playing")
> mp.controls.stop()
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

The "Leading Manufacturing Test Company of the Year 2005"
http://www.dspace.de/goto?f_s_award
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wheel-reinvention with Python

2005-08-02 Thread Torsten Bronger
Hallöchen!

Mike Meyer <[EMAIL PROTECTED]> writes:

> Torsten Bronger <[EMAIL PROTECTED]> writes:
>
>> [...]
>>
>> Because such projects attract the greatest number of developers,
>> many of them being amongst the most diligent developers, too.  I
>> expect this to have a positive influence of the language.
>
> You didn't answer the question about how you define agile
> project. Please do so if you expect a comment on this.

Projects with a high Sourceforge activity index.

> [...]
>
>> Yes, this is what I meant with "legacy code".  C and C++ are
>> actually special-purpose.  They are good for controlling a
>> computer but not for implementing an idea.  Their current
>> vitality on almost all software areas arise from the fact that
>> they had been extremely successful before Java, C#, and VB came
>> into play.  Invented today, they would be niche languages.
>
> This is patently absurd. C and C++ were born as general-purpose
> languages. Changing the environment around them isn't going to
> change that.

In 1955 people would have told you that Fortran is general-purpose.
It's not the case any more.

> [...]
>
 Legacy code is not a sign of success IMO because it implies a
 difficult future.
>>>
>>> So you're saying that Python, Perl, Linux, the various BSD
>>> et. al. will have a difficult future? [...]
>>
>> No.  All I said was that if a language's "success" relies almost
>> exclusively on the heavy presence of legacy code, its future is
>> difficult.  I see this for C and C++ excluding VC++.
>
> Well, you lumped all C/C++ code a legacy code.

No because ...

> [...]
>
> You can't have it both ways. Either C/C++ is all legacy code, or
> it's not.

... is wrong in my opinion.  Why should this be?

> [...]
>
> I think you need to come out from behind your Windows box for a
> while.

But you did read my headers?  ;-)

> There are *lots* of applications areas that don't need GUIs,
> and don't run on Windows.

This becomes a discussion about estimates we both don't know
exactly, and weight differently, so I'll leave it here.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
-- 
http://mail.python.org/mailman/listinfo/python-list

Request for Input re PyCon about Session Lengths

2005-08-02 Thread Jeff Rush
There is a discussion going on regarding how long the presentations 
should be for PyCon 2006.  In the past the sessions have been 20 minutes 
of talk, 5 minutes of questions and 5 minutes to change rooms, grouped 
into 90-minute timeslots, with a 30-minute break btw each 90-minutes.

There were comments last year that that 20-minutes was too short to 
cover much material, so there is a push to extend that to 50-minutes of 
talk, 5 minutes Q/A and 5 minutes to change rooms.

Some however think sitting in a lecture for that long is excessive and 
that 20-minutes is sufficient to cover the high points of a topic and 
point interested people to online docs and forums.

Others, particularly those new to a topic, hunger for more comprehensive 
coverage, something more akin to a class or tutorial.  They may not be 
familiar with a topic and want more than a bullet list of what has 
changed on the project since the last PyCon.  Note that there -will- be 
a day of tutorial prior to the main presentation days, but will that one 
day satisfy those people?

And there is a view of mixing session lengths, dividing talks into 
"topic surveys (whats)" and "tutorials (hows)", with perhaps a survey to 
introduce a topic, say the Twisted Framework, and then on another track 
an in-depth session to actually teach Twisted programming.  There is 
concern, however, that such mixing can complicate scheduling excessively.

We would also like input from speakers themselves.  This year some 
seemed uncomfortable or surprised to find they only had 20-minutes of 
actual presentation time.  But not every talk needs more time.

In 2006, there will be more speaking rooms available, in that the 
sprinting rooms will be available during the entire conference. 
Therefore there will be rooms for the usual tracks 1, 2 and 3, plus the 
2 sprinting rooms, plus a non-sprinting "quiet" room.  However, the idea 
of having possibly 5-6 tracks makes some parties believe too many 
choices will leave attendees unhappy.  Others that our community is 
diverse and needs to support people with different presentation needs.

If you have strong opinions about these matters, please send private 
email to either me ([EMAIL PROTECTED]) and/or the PyCon chairman 
([EMAIL PROTECTED]) and we'll summarize to the group, or join the 
pycon-organizers list and get involved directly:

http://mail.python.org/mailman/listinfo/pycon-organizers

Please read the archives to come up to speed on the various viewpoints.

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


Re: Standards not standard

2005-08-02 Thread Dark Cowherd
> > I really think that the community needs a lot more of STANDARDS not
> > a STANDARD GUI
> 
> Standards happen in one of two ways. Either an 800-lb gorrilla
> establishes them by fiat, or a group of people interested in having
> their code play well together hashes out something after they've all
> taken a crack at implementing it. The latter is slowly happening in
> the Python community. But it's a slow process.
> 
> --
OK let me talk in specifics instead of abstractions.

Lets take a GUI. Consider something like wxGlade or XRCed which
generates a XML resource file and then wxPython works from it.

Suppose the python community works on defining a standard XML resource file.

Then all wrappers for GUI libraries in Python can optionally support
this XML resource file.

So if you are unfortunate enough to have to develop GUI applications
:-) you use the standard XML resource file and pick the wrapper and
the toolkit that you like.

Then for some reason - you have to switch wrapper or toolkit -  you
dont have a major crisis, you only have a minor crisis. ;-)

Of course the wrappers and toolkits are free to provide additional
functionality which the developers using those toolkits may or may not
choose to use.

I think this is what has happened with the DBAPI 2.0 for e.g.
kinterbasdb provides DBAPI 2.0 compliant methods for access to
firebird and also other non-standard methods. This is a GOOD THING and
my suggestion is that this GOOD THING must propogate into other areas
like GUI and the Web Toolkits.

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


Re: Setting a drive's volume label

2005-08-02 Thread Bob Greschke
Looks like the "label" system command will do it in Windows.  That's good 
enough for this exercise.  So, in Linux...???


"Bob Greschke" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> ...the name for a drive (hard or removable) that shows up when, for 
> example, a USB flash drive is recognized by the system.  I don't know if 
> this shows up somewhere in Linux.
>
> Can this be set from Python?  I guess it would be some MFC call in Windows 
> (I don't know anything about doing that), and some ??? call in Linux? 
> Could use both.
>
> Thanks!
>
> Bob
>
> 


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


Re: Python for embedded linux?

2005-08-02 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> Where can I find a minimal version of python (less than 2 MB) suitable for
> a web server on an embedded linux system?  The small size is required
> because the system lives on flash memory.

Such things have been discussed in this list/newsgroup before.  I 
suggest trying a Google Groups search with some relevant keywords, such 
as "embedded" (though this occurs in several other contexts), "flash", 
or "small footprint".

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


using httplib for authentication

2005-08-02 Thread James Stroud
Hello All,

I want to use python to download files from sites where authentication is 
required. The page appears to send a form with the login and pass by post. I 
would like to log in and keep this session open within python and 
download a number of files automatically. Could anyone kindly point me in the 
right direction? I have discovered httplib and read the documentation and 
looked at the examples, but they don't seem helpful for this.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


RE: HELP:sorting list of outline numbers

2005-08-02 Thread Delaney, Timothy (Tim)
Scott David Daniels wrote:

> For 2.3: (using DSU -- Decorate, Sort, Undecorate)
>  def numparts(outlinetext):
>  return [int(number) for number in outlinetext.split('.')]
> 
>  lst = ['1', '1.2', '1.12', '1.1', '3.1']
>  decorated = [(numparts(txt), txt) for txt in lst]
>  decorated.sort()
>  lst[:] = [txt for code, txt in decorated]

Slightly better to do::

 def numparts(outlinetext):
 return [int(number) for number in outlinetext.split('.')]

 lst = ['1', '1.2', '1.12', '1.1', '3.1']
 decorated = [(numparts(txt), i, txt) for i, txt in enumerate(lst)]
 decorated.sort()
 lst[:] = [txt[-1] for d in decorated]

This emulates the 2.4 sorting using `key` i.e. only the key is
evaluated, not the original object. It also ensures a stable sort, but
`sort` is stable in 2.3 anyway (not the case in earlier versions ...).

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


Weekly Python Patch/Bug Summary

2005-08-02 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  354 open ( -3) /  2888 closed ( +3) /  3242 total ( +0)
Bugs:  909 open (+11) /  5152 closed ( +8) /  6061 total (+19)
RFE :  191 open ( +0) /   178 closed ( +0) /   369 total ( +0)

Patches Closed
__

PEP 342 Generator enhancements  (2005-06-18)
   http://python.org/sf/1223381  closed by  pje

Provide tuple of "special" exceptions  (2004-10-01)
   http://python.org/sf/1038256  closed by  ncoghlan

Patch for (Doc) #1243553  (2005-07-24)
   http://python.org/sf/1243910  closed by  montanaro

New / Reopened Bugs
___

"new" not marked as deprecated in the docs  (2005-07-30)
   http://python.org/sf/1247765  opened by  Jürgen Hermann

error in popen2() reference  (2005-07-30)
CLOSED http://python.org/sf/1248036  opened by  Lorenzo Luengo

pdb 'next' does not skip list comprehension  (2005-07-31)
   http://python.org/sf/1248119  opened by  Joseph Heled

set of pdb breakpoint fails  (2005-07-31)
   http://python.org/sf/1248127  opened by  Joseph Heled

shelve .sync operation not documented  (2005-07-31)
   http://python.org/sf/1248199  opened by  paul rubin

dir should accept dirproxies for __dict__  (2005-07-31)
   http://python.org/sf/1248658  opened by  Ronald Oussoren

2.3.5 SRPM fails to build without tkinter installed  (2005-07-31)
   http://python.org/sf/1248997  opened by  Laurie Harper

rfc822 module, bug in parsedate_tz  (2005-08-01)
   http://python.org/sf/1249573  opened by  nemesis

isinstance() fails depending on how modules imported  (2005-08-01)
   http://python.org/sf/1249615  opened by  Hugh Gibson

Encodings and aliases do not match runtime  (2005-08-01)
   http://python.org/sf/1249749  opened by  liturgist

container methods raise KeyError not IndexError  (2005-08-01)
   http://python.org/sf/1249837  opened by  Wilfredo Sanchez

numarray in debian python 2.4.1  (2005-08-01)
CLOSED http://python.org/sf/1249867  opened by  LovePanda

numarray in debian python 2.4.1  (2005-08-01)
CLOSED http://python.org/sf/1249873  opened by  LovePanda

numarray in debian python 2.4.1  (2005-08-01)
   http://python.org/sf/1249903  opened by  LovePanda

IDLE does not start. 2.4.1  (2005-08-01)
CLOSED http://python.org/sf/1249965  opened by  codepyro

gethostbyname(gethostname()) fails on misconfigured system  (2005-08-02)
   http://python.org/sf/1250170  opened by  Tadeusz Andrzej Kadlubowski

incorrect description of range function  (2005-08-02)
   http://python.org/sf/1250306  opened by  John Gleeson

The -m option to python does not search zip files  (2005-08-02)
   http://python.org/sf/1250389  opened by  Paul Moore

Tix: PanedWindow.panes nonfunctional  (2005-08-02)
   http://python.org/sf/1250469  opened by  Majromax

Bugs Closed
___

Segfault in Python interpreter 2.3.5  (2005-07-26)
   http://python.org/sf/1244864  closed by  birkenfeld

logging module doc needs to note that it changed in 2.4  (2005-07-25)
   http://python.org/sf/1244683  closed by  vsajip

manual.cls contains an invalid pdf-inquiry  (2005-07-14)
   http://python.org/sf/1238210  closed by  fdrake

error in popen2() reference  (2005-07-30)
   http://python.org/sf/1248036  closed by  birkenfeld

numarray in debian python 2.4.1  (2005-08-01)
   http://python.org/sf/1249867  closed by  birkenfeld

numarray in debian python 2.4.1  (2005-08-01)
   http://python.org/sf/1249873  closed by  birkenfeld

IDLE does not start. 2.4.1  (2005-08-01)
   http://python.org/sf/1249965  closed by  codepyro

Incorrect documentation of re.UNICODE  (2005-07-22)
   http://python.org/sf/1243192  closed by  birkenfeld

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


Re: HELP:sorting list of outline numbers

2005-08-02 Thread Felix Collins
Felix Collins wrote:
> 
> Thanks Scott and Robert for your quick help.  This list is amazing!
> 
> Regards,
> Felix

Using Decorate, Sort , Undecorate...

works like a charm.

Thanks again.

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


Re: Wheel-reinvention with Python

2005-08-02 Thread Cliff Wells
On Tue, 2005-08-02 at 20:17 -0400, Mike Meyer wrote:

> Um - you're not answering the question I asked. I asked "What app do I
> use to bundle my applications for Unix, ala py2exe (or whatever it is)
> for Windows?" You're telling me how to install wxPython on those
> platforms.
> I know how to install wxPython. What I want to know is how to build an
> application bundle for all those Unix systems for a Python app I use
> that includes wxPython - or any other third party libraries I may be
> using.

Sorry, I assumed you'd know about distutils:

http://www.python.org/doc/current/dist/
http://www.python.org/doc/current/dist/built-dist.html

distutils can go so far as to build an rpm for you, but you'll need to
package things like .debs yourself.

Cliff

-- 
[EMAIL PROTECTED]
http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and 
Python specialists ::


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


Re: Using win32com for web automation

2005-08-02 Thread Chris Smith
> "calfdog" == calfdog  <[EMAIL PROTECTED]> writes:

calfdog> ina wrote:
>> Look up pamie it should do all the work you need.  If it dosn't
>> I can send you ishyBrowser but pamie has more comunity support.

calfdog> # wait for the document to fully load 
calfdog> while ie.ReadyState
calfdog> != 4: sleep(1)
calfdog> doc = ie.Document
calfdog> while doc.readyState != "complete": sleep(1)

I was trying to make this work several months ago, and tried
to open the windows event to trap the OnDocumentComplete from IE.
It was all beat.
I went with the über-hack:  a sentinel file in a certain spot writing
the word 'Done'.
COM programming recalls the Steven Write joke: "Went to the hardware
store to buy some batteries, but they weren't included; so I had to
buy them again."
Grr,
Chris

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


Re: HELP:sorting list of outline numbers

2005-08-02 Thread Felix Collins
Robert Kern wrote:
> Felix Collins wrote:
> 
> Use the "key" keyword argument to list.sort().
> 
> In [1]: outline = ['1.12', '1.1', '1', '1.2']
> 
> In [2]: outline.sort(key=lambda x: map(int, x.split('.')))
> 
> In [3]: outline
> Out[3]: ['1', '1.1', '1.2', '1.12']
> 


Is this new in 2.4?  I have to use 2.3 as I'm working with Trac.

Traceback (most recent call last):
   File "", line 1, in -toplevel-
 keys.sort(key=lambda x: map(int, x.split('.')))
TypeError: sort() takes no keyword arguments


Thanks Scott and Robert for your quick help.  This list is amazing!

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


Re: HELP:sorting list of outline numbers

2005-08-02 Thread Scott David Daniels
Felix Collins wrote:
> Hi All,
> does anyone know any cleaver tricks to sort a list of outline numbers.


For 2.4 and beyond: (using a key function)

 def numparts(outlinetext):
 return [int(number) for number in outlinetext.split('.')]

 lst = ['1', '1.2', '1.12', '1.1', '3.1']
 lst.sort(key=numparts)

For 2.3: (using DSU -- Decorate, Sort, Undecorate)
 def numparts(outlinetext):
 return [int(number) for number in outlinetext.split('.')]

 lst = ['1', '1.2', '1.12', '1.1', '3.1']
 decorated = [(numparts(txt), txt) for txt in lst]
 decorated.sort()
 lst[:] = [txt for code, txt in decorated]

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


Re: HELP:sorting list of outline numbers

2005-08-02 Thread Robert Kern
Felix Collins wrote:
> Hi All,
> does anyone know any cleaver tricks to sort a list of outline numbers.
> 
> An outline number is a number of the form...1.2.3
> 
> they should be sorted in the following way...
> 
> 1
> 1.1
> 1.2
> 1.12
> 
> python's alpha sort (by design) sorts them...
> 
> 1
> 1.1
> 1.12
> 1.2
> 
> That's no good for me.
> I'm planning on splitting the strings into multiple lists of ints and 
> doing numerical sorts.
> 
> Thanks for any clever ideas that might make it easier.

Use the "key" keyword argument to list.sort().

In [1]: outline = ['1.12', '1.1', '1', '1.2']

In [2]: outline.sort(key=lambda x: map(int, x.split('.')))

In [3]: outline
Out[3]: ['1', '1.1', '1.2', '1.12']

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


HELP:sorting list of outline numbers

2005-08-02 Thread Felix Collins
Hi All,
does anyone know any cleaver tricks to sort a list of outline numbers.

An outline number is a number of the form...1.2.3

they should be sorted in the following way...

1
1.1
1.2
1.12

python's alpha sort (by design) sorts them...

1
1.1
1.12
1.2

That's no good for me.
I'm planning on splitting the strings into multiple lists of ints and 
doing numerical sorts.

Thanks for any clever ideas that might make it easier.

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


Re: Wheel-reinvention with Python

2005-08-02 Thread Mike Meyer
Paul McNett <[EMAIL PROTECTED]> writes:
>>>project I've found, but still doable.
>> Well, I've got a long history of installing things from source -
>> going
>> back to v6. On OS X, I like the darwin ports stuff, so I tried that:
>> % sudo port install wxpython
>> It blew up trying to compile wxpython. The multitude of dependencies
>> all seemed to build find. Building wxpython from the source
>> distribution by hand doesn't seem to fair any better.
>
> To build wxPython from source, you really need to follow Robin's
> detailed instructions in BUILD.txt, located somewhere in the source
> tree (I have to look for it every time, but I think it is in
> wxSrc/wxPython/docs/BUILD.txt). It isn't difficult but there's more to
> it than the standard ./configure;make;make install.

I found BUILD.txt. I followed it to the letter. It still blew
up. There may be a problem with Tiger that hasn't been reported yet
(yeah, I know - I really ought to report it...).

Then again, it could be a problem with trying to install it on the
darwin ports Python 2.4 package instead of the 2.3.5 that Tiger ships
with.

> I think you'll find that wxPython installs perfectly on Tiger using
> the package provided. Indeed, the only really painful platform to
> install wxPython on is Linux, where you pretty much need to build from
> source if you want the latest and greatest.

Well, it built just fine on my FreeBSD box. Then again, I've generally
found installing from source on FreeBSD to be easier than installing
RPM's on Linux. I'll probably copy THE over to my FreeBSD box and try
it there.

thanks,
  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

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


Setting a drive's volume label

2005-08-02 Thread Bob Greschke
...the name for a drive (hard or removable) that shows up when, for example, 
a USB flash drive is recognized by the system.  I don't know if this shows 
up somewhere in Linux.

Can this be set from Python?  I guess it would be some MFC call in Windows 
(I don't know anything about doing that), and some ??? call in Linux?  Could 
use both.

Thanks!

Bob


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


Re: Wheel-reinvention with Python

2005-08-02 Thread Mike Meyer
Torsten Bronger <[EMAIL PROTECTED]> writes:
> Hallöchen!
> Mike Meyer <[EMAIL PROTECTED]> writes:
>> Torsten Bronger <[EMAIL PROTECTED]> writes:
>>> [...]
>>> I'm interested in a language with a big community.  This is my
>>> definition of success.  [...]
>>>
>>> GUI applications seem to be the most attractive application type.
>>> This is not only true for commercial programming.  When I look at
>>> the most agile projects on Sourceforge, almost all of them have a
>>> GUI.
>> Why restrict yourself to agile projects?
> Because such projects attract the greatest number of developers,
> many of them being amongst the most diligent developers, too.  I
> expect this to have a positive influence of the language.

You didn't answer the question about how you define agile
project. Please do so if you expect a comment on this.

>> I won't argue that most of the projects on Sourceforge have GUIs -
>> that's certainly true. I will argue that most of the projects are
>> done in languages that aren't what you call GUI-aware.
> Yes, this is what I meant with "legacy code".  C and C++ are
> actually special-purpose.  They are good for controlling a computer
> but not for implementing an idea.  Their current vitality on almost
> all software areas arise from the fact that they had been extremely
> successful before Java, C#, and VB came into play.  Invented today,
> they would be niche languages.

This is patently absurd. C and C++ were born as general-purpose
languages. Changing the environment around them isn't going to change
that.

> However, even C++ is really successful only when used as a GUI-aware
> dialect.  Additionally, Python does not have this legacy bonus.

The only dialect that might be considered "GUI-aware" is C#. Or maybe
you mean they're only succesfull when coupled with a GUI library? I'd
say that's due to your warped definition of success, and I'm not going
to argue with your definition.

>>> Therefore, GUI-aware languages attract much larger user bases,
>>> and so they cater my definition of being successful.
>> Since you haven't stated what that definition is, I can't really say
>> anything about this.
> Yes, I did.

No, you agreed with my definition, with the proviso that you had to
consider how "important" the application area was. Which leaves it
undefined.

>>> Legacy code is not a sign of success IMO because it implies a
>>> difficult future.
>> So you're saying that Python, Perl, Linux, the various BSD
>> et. al. will have a difficult future? [...]
> No.  All I said was that if a language's "success" relies almost
> exclusively on the heavy presence of legacy code, its future is
> difficult.  I see this for C and C++ excluding VC++.

Well, you lumped all C/C++ code a legacy code. The most successful
distribution of Python is the one written in C, so it's success relies
almost exclusively on legacy code. Ditto for Perl, Linux, etc.

You can't have it both ways. Either C/C++ is all legacy code, or it's
not. If it is, the building products in Python/Perl/Java (and probably
most of the others) is building in a dependence on a legacy code base.

If they *aren't* legacy code, then your premise that C/C++ only has
legacy code is false. Personally, I think your premise is false. There
are lots of projects still under active development using C/C++. There
are new ones starting every day. Contrary to your assertion about
VC++, they are starting in environments where VC++ doesn't run.

I think you need to come out from behind your Windows box for a
while. There are *lots* of applications areas that don't need GUIs,
and don't run on Windows. I'll bet most of the computers in your house
are running software that falls into that category.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wheel-reinvention with Python

2005-08-02 Thread Mike Meyer
[EMAIL PROTECTED] (phil hunt) writes:

> On Tue, 02 Aug 2005 00:42:53 -0400, Mike Meyer <[EMAIL PROTECTED]> wrote:
>>[EMAIL PROTECTED] (phil hunt) writes:
>>> In practise any Python GUI is going to contain code from otyher 
>>> languages since if it was coded all the way down in python it would 
>>> be too slow.
>>Not necessarily. My window manger is Python all the way down
> Your X server is written in Python? :-)

I see the smiley, but just to make sure no one is confused, the answer
is no. My window manager is written in Python. Unlike monolithic
programs in proprietary OS's, X seperates the window manager from the
thing that actually paints pixels on the screen. It's possible to run
the window manager on another computer entirely, and people used to
sell boxes that ran in that configuration out of the box.

>> - it uses
>>the Python Xlib implementation - and is plenty fast.
>>Of course, it doesn't do a lot of graphics work, even for a window
>>manager.
> That's what I mean: painting the individual pixels on the screen.

Well, no X graphics package will get any closer to that than my python
window manager. The python code sends packets to the X server, and
parses what comes back from it.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


pygettext ?

2005-08-02 Thread cantabile
Hi, I'm trying to write an internationalized app. I'm learning python 
and read that pygettext would help me, but I found elsewhere it was 
obsolete (??)
So, what's the correct and up to date tool to i18n python ?
Is there a tutorial somewhere (python docs has nothing really usable : 
I'd like at least an example!)

Do you have links to pages or documents about that ?

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


Re: Wheel-reinvention with Python

2005-08-02 Thread Mike Meyer
Jorge Godoy <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>>> In fact this sounds more like a joke I've heard a while ago: standards,
>>> if you don't like the ones out there, create your own.
>> Works for me.
> What works for you?  You believe that chaos is better than having standards? 
> I believe that flexibility is good, but not chaos.

I believe that multiple competing options is better than an externally
enforced standard, or a single option with a near-monopoly position.

If none of the options are good enough for the job at hand, you create
your own.
>> won't recap the thread, but other languages have been *very*
>> successful without having a GUI as part of the language, all they had
>> was one development environment distributed with a GUI.
> One IDE, you mean?  I believe the freedom to choose from multiple IDEs is
> also good.  Some code on VI, others on Emacs, others on Eclipse, others
> on ... 

IDE is short for "integrated development environment". I chose a
slightly broader phrase. The languages had more options than one
specific distribution, but that one dominated at least one market.

>> BTW, in answer to your rhetorical question about GUI's for Linux, the
>> answer is plwm.
> :-)
> And does it integrate well with common business apps, such as a mail client,
> note taking apps, addressbooks (with personal and shared entries), calendar
> with ability to share appointments, etc.?

Of course.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wheel-reinvention with Python

2005-08-02 Thread Mike Meyer
Cliff Wells <[EMAIL PROTECTED]> writes:
>> > Regardless, when you say "Unix", what do you mean?  You may as well say
>> > "OS" as this term has little meaning.  Linux (which flavor)?  BSD?  SCO?
>> > HPUX?  OS/X?  Minix?   Whichever way, I suspect that a bit of distutils
>> > hacking would solve your problem.
>> 
>> I think the post I replied to covered the OS X case - there's an
>> application bundler available for it already.
>
> Yes, I've used it to bundle wxPython apps on 10.3.
>
>> I want distributions that will work on all three major BSD variants
>> and most Linux distrubtions - in particular, anything that uses deb's,
>> rpm's or emerge. If you want to choose one in particular, try ubuntu
>> Linux.
>
> OpenBSD: in portage
> FreeBSD: in portage
> 386BSD: don't know... does anyone still use this?
> NetBSD: included AFAICT
> Fedora: rpms available
> Debian: debs available
> Ubuntu: included
> Gentoo: in portage
> OS/X:  available on wxpython.org

Um - you're not answering the question I asked. I asked "What app do I
use to bundle my applications for Unix, ala py2exe (or whatever it is)
for Windows?" You're telling me how to install wxPython on those
platforms.

I know how to install wxPython. What I want to know is how to build an
application bundle for all those Unix systems for a Python app I use
that includes wxPython - or any other third party libraries I may be
using.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: startfile problems

2005-08-02 Thread Timothy Smith
Michael Hoffman wrote:

>Timothy Smith wrote:
>
>  
>
>>yep the program is executed in the same dir as the pdf file. like i said 
>>it actually opens it, but throws up an exception as well.
>>
>>
>
>You are far more likely to get informed help if you post the traceback 
>here, as has been suggested twice already.
>  
>
i can't since it's a remote site and i can't reproduce the error. the 
best i have is a screen shot.
besdies which the only information it gives is the names and line 
numbers of the my py modules, nothing more. the only real info it gives 
i have posted already, in my inital post (the last line of it, 
WindowsError etc..)

other then that there's no more information to be had. it's a bloody 
simple 2 line function, nothing funky about it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: startfile problems

2005-08-02 Thread Michael Hoffman
Timothy Smith wrote:

> yep the program is executed in the same dir as the pdf file. like i said 
> it actually opens it, but throws up an exception as well.

You are far more likely to get informed help if you post the traceback 
here, as has been suggested twice already.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Python for embedded linux?

2005-08-02 Thread pythonic
Where can I find a minimal version of python (less than 2 MB) suitable for
a web server on an embedded linux system?  The small size is required
because the system lives on flash memory.

Thanks,
Ken Seehart




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


Re: bug in python/numarray

2005-08-02 Thread Xiangyi
Robert and Terry-

Thank you so much for helping me on this!

Yes, it's a problem due to an old version of numarray. I didn't realize that 
my windows has a much newer version than the debian machine.

Best,
Xiangyi
- Original Message - 
From: "Robert Kern" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, August 02, 2005 1:03 PM
Subject: Re: bug in python/numarray


> [EMAIL PROTECTED] wrote:
>> Hi, there,
>>
>> I got different results by running the same lines of code on windows and
>> debian. Here is the code:
>>
>> a = kroneckerproduct(ones((4195,1)), identity(12))
>> print a.mean()
>>
>> This works perfectly well in windows but it gave the following error 
>> while
>> running it in debian:
>> Traceback (most recent call last):
>>File "", line 1, in ?
>>File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line
>> 1137, in mean
>>  return self.sum()/(self.nelements()*1.0)
>>File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line
>> 1133, in sum
>>  return ufunc.add.reduce(ufunc.add.areduce(self, type=type).flat,
>> type=type)
>> IndexError: too many indices.
>>
>> But if I reduce the number 4195 to 419, it works. Is it a bug in Python 
>> or
>> Numarray? Can someone help me figure it out? BTW, the python version is 
>> 2.4.1
>
> It's almost certainly numarray. I don't get an error on OS X with the
> latest CVS of numarray. Please try the latest CVS on your platforms, and
> if you still get this error, then post it to the numarray mailing list.
> Thanks!
>
> http://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
> -- 
> Robert Kern
> [EMAIL PROTECTED]
>
> "In the fields of hell where the grass grows high
>  Are the graves of dreams allowed to die."
>   -- Richard Harter
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 


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


Re: startfile problems

2005-08-02 Thread Timothy Smith
Dennis Lee Bieber wrote:

>On Tue, 02 Aug 2005 17:35:27 +1000, Timothy Smith
><[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>
>  
>
>>it's iterally just
>>
>>PDFname = 'tmp.pdf'
>>os.startfile(PDFname)
>>
>>thats the code.
>>
>>
>>
>   No "import os"?
>   And the full traceback?
>
>  
>
>>so obviously it contains no errnous characters. see my update btw. it 
>>actually DOES open the report, but throws up the exception as well.
>>
>>
>
>   Must not have made it to my server yet, assuming it was posted
>after my comment.
>
>import os
>
>PDFname = "test.pdf"
>os.startfile(PDFname)
>
>   No errors if I'm in the directory with the PDF when I execute
>the program...
>
>E:\UserData\Dennis Lee Bieber\My Documents>script1.py
>
>E:\UserData\Dennis Lee Bieber\My Documents>python script1.py
>
>E:\UserData\Dennis Lee Bieber\My Documents>
>
>
>
>  
>
yep the program is executed in the same dir as the pdf file. like i said 
it actually opens it, but throws up an exception as well.
if i hadn't seen it with my own eyes i wouldn't believe it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Script for generating WSDL

2005-08-02 Thread pythonUser_07
Is that possible?  In order to access a web service it seems like you
need to know how it is defined (IE through the WSDL)

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


Re: Pickle, __init__, and classes

2005-08-02 Thread Peter Hansen
Russell Blau wrote:
> Try __new__().  http://docs.python.org/ref/customization.html  This isn't
> the usual application of __new__, but since it returns an object it should
> be ideal for your purposes.

Or simply create a factory function to return your instances -- which is 
in effect what __new__ does -- but without the baggage.

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


Re: Art of Unit Testing

2005-08-02 Thread Peter Hansen
Christoph Zwerschke wrote:
> I completely agree and I think it makes a lot of sense that unittest 
> calls setUp and tearDown for every single test. However, the fact that 
> this is *generally* the best way doesn't exclude the fact that there are 
> *exceptions* when it makes sense to setUp and tearDown not for every 
> test, e.g. when it is absolutely sure that the fixture cannot be 
> destroyed by the individual tests or when creating the fixture takes too 
> much time. I already gave the example of creating database connections 
> or even creating/importing whole databases. My question was, how do I 
> handle these cases with the standard lib unittest?

What's wrong with using Python's existing "global" support, and just 
having your test case setUp() call a global setup routine which checks 
whether that global setup work has already been done and, if not, does 
it once and sets a flag to say that it has now been done?  I've done 
this easily in the few cases where I've wanted this behaviour.  It 
doesn't seem complex enough to warrant adding to the standard unit test 
support.

> According to the "extreme programming" paradigm, testing should be done 
> several times a day. So a requirement for extreme programm is that tests 
> are fast enough. If the testing needs too much time, people are 
> discouraged to test often.

If you're going to quote XP rules of thumb, the tests should be 
independent and very fast, and if you have a setup code that is taking a 
long time, it's likely a "code smell" of some kind, and you should be 
fixing the design which prevents you writing these tests with minimal 
and quick setup.  Are these really like "acceptance" tests?  If they 
were unit tests, they should take only a few minutes to run, total, and 
you should be running them all *many* times a day, not twice.

Still, if you're stuck, and really do need a lengthy setup to execute 
once as an optimization, it's not hard to do with globals.

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


Re: Art of Unit Testing

2005-08-02 Thread rafi
rafi wrote:
> In order to unit test a function / method one should use mock objects, 
> otherwise you may not be sure that your code is faulty. 

'should' may be too strong, 'may' may be better. In the meantime I found:

http://python-mock.sourceforge.net/

my 2 cents

-- 
rafi

"Imagination is more important than knowledge."
(Albert Einstein)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.clock() or time.time()

2005-08-02 Thread Peter Hansen
Magnus Lycka wrote:
> On Windows, you're likely to prefer time.clock(), to
> measure relative times, since time.time() will have too low resolution
> for measuring short thingies. 

Specifically, using the NT/XP family of Windows operating systems 
time.time() has a resolution of approximately 0.015 seconds (I believe 
it might be exactly 1/64 second, but it should be easy to confirm with a 
google search).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Art of Unit Testing

2005-08-02 Thread rafi
Christoph Zwerschke wrote:
> Björn Lindström wrote:
> 
> I already gave the example of creating database connections 
> or even creating/importing whole databases. My question was, how do I 
> handle these cases with the standard lib unittest?

I do not get why a unit test whould create/import a whole database. In 
order to unit test a function / method one should use mock objects, 
otherwise you may not be sure that your code is faulty. A mock object is 
an object that let the object uder test think it is connected to a 
database, but it is not really connected to one. This object is 
programmed to return well know values (correct, incorrect and 
exceptional ones). What you are talking about is more related to 
interaction / load tests and not unit tests (at least to me who am not 
an expert of unit testing).

> According to the "extreme programming" paradigm, testing should be done 
> several times a day. So a requirement for extreme programm is that tests 
> are fast enough. If the testing needs too much time, people are 
> discouraged to test often.

Well as I said above, a unit test is dedicated to a single function or 
method. So wehn you update a function / method, you should test the 
whole class or module, but maybe not the whole application (or the 
development task may have not been properly organized --splited between 
several developers). As someones may not write several thousand lines a 
day, unit tests should not be that long to run (well from my point of 
view, which is again not the one of an expert of unit testing).

I do agree with Benjamin Niermann when he says: "Or because it is 
already close to perfection (at least in what it is intended to do)."

unittest is for unittesting :-)

my 2 cents

-- 
rafi

"Imagination is more important than knowledge."
(Albert Einstein)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Printing Docstrings Without Importing

2005-08-02 Thread Chris
Fuzzyman wrote:
> This seems to scratch several people's itches.


As I understand it it is something like generating "pythondoc" like javadoc?
Should be pretty easy to develop something a bit more polished than 
Bengt's solution (or based on it of course) with maybe similar to 
javadoc framesets for a navigational list etc.

But usn't there something like that from the docutils project (I must 
admit I should have googled for it but have not have the time yet).
I was looking for something to but found only epydoc yet with yet 
another of its own markup, docutils being something like a standard for 
python (at least that's what I thought) would be really nice for it.


chris

sorry if i totally misunderstood the question...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle, __init__, and classes

2005-08-02 Thread Russell Blau
"Yin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I've created a class that reads in and processes a file in the
> initializer __init__.  The processing is fairly substantial, and thus,
> instead of processing the file every time the object is created, I
> pickle the object to a file.
>
> In subsequent creations of the object, I implement a test to see
> whether the pickled file exists.  If it does, then I unpickle the
> object.
>
> Unfortunately, the __init__ cannot return this unpickled object.
>

Try __new__().  http://docs.python.org/ref/customization.html  This isn't
the usual application of __new__, but since it returns an object it should
be ideal for your purposes.






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


Re: Art of Unit Testing

2005-08-02 Thread Benjamin Niemann
Christoph Zwerschke wrote:

> Thanks for the link, Grig. I wasn't aware of the py lib so far. The
> possibility to create fixtures at the three different scopes is exactly
> what I was looking for.
> 
> Anyway, I think it would be nice to have that feature in the standard
> lib unittest as well. It should not be too hard to add setUpOnce and
> tearDownOnce methods in addition to setUp and tearDown. Actually, I am
> wondering that there doesn't seem to be any development progress since
> unittest was included in the standard lib of Python 2.1 in August 2001.
> I had expected that such an important module would be continually
> improved and maintained. How come? So few people using unit tests? Or do
> most people write their own testing code or use py.test?

Or because it is already close to perfection (at least in what it is
intended to do).

The unittest module is a 'port' of the JUnit framework for Java which has a
certain wellknown API and semantics. The same API is available for many
other languages, so it is probably a good idea to stick with it in order to
make people coming from other language feel more comfortable with Python.

Some (many?) people don't like the unittest module, because it is not very
pythonic - nothing to wonder as it has its root in the Java world. That's
probably one of the reasons why there are other (more pythonic) unittesting
frameworks for Python out there.

I prefer to use unittest (because this was the API the textbook was using
that introduced me to this topic) and I also had the problem of heavy setup
costs. I deal with it by using a script around my testsuite (instead of
calling just unittest.main()) that does the setup/teardown of the
environment.

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trying to parse non valid html documents with HTMLParser

2005-08-02 Thread Benji York
florent wrote:
> I'm trying to parse html documents from the web, using the HTMLParser 
> class of the HTMLParser module (python 2.3), but some web documents are 
> not fully valids. 

 From http://www.crummy.com/software/BeautifulSoup/:

 You didn't write that awful page. You're just trying to get
 some data out of it. Right now, you don't really care what
 HTML is supposed to look like.

 Neither does this parser.
--
Benji York

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


Re: Python IDE's

2005-08-02 Thread Benji York
Adriaan Renting wrote:
> vi/vim is a godssend if you need a working system that needs to fit in 4
> Mb or ROM, but it's an editor not an IDE.

> When talking about IDE's I mean a lot more as 'just' an editor, below is
> my 'wishlist', I would be very interested what solutions you use, how
> much time it took you to set up this solution, and which parts of my
> 'wishlist' it implements.

First, a disclaimer: your point of "how much time it took you to set 
up?" is definitely valid.  I would assert that it is also valid to ask 
"how much time did it save you once it was set up to work precisely the 
way you wanted it to?"

> - Integrated help.
> - Code completion.
 > - Integrated debugger.

I've seen (but not used, because I don't want these features) Vim 
scripts to do these.  They exist for Emacs too.

> - Integrated GUI design.
> The IDE should have a graphical tool for designing GUIs, and the editor
> should be aware of it and propagate changes in an inobtrusive way.

Not in Vim (or Emacs), but the best GUI designers /I've/ seen are 
stand-alone anyway.  In other words, their not in an IDE either.

> - Code aware editor.
 > - Integration with version control system.
 > - Code documentation/inspection tools.

I use Vim for these.

> Ability to generate include and inheritance trees

On the rare occasions I do something like this it's with apidoc.

> LOC counters

I use sloccount (outside of Vim).

> profiling what lines of you code get executed most/never

I use a testing framework or profiler for that (outside of Vim)

> helpfile generation from code, etc.

I don't do that, but if I did, it would probably be outside of Vim.

> Tools for communication with coworkers

Gaim and Thunderbird

> bugtracking

Zope collector and Roundup

> which targets need which files, automatic install scripts/tools,
> etc.

(If I understand you correctly) I use a tool we developed internally to 
do this.

> - Accessible user interface.
> All functionality should be accessible through some menu structure, so I
> don't need to depend on my memory. Prefereable reprogrammable/assignable
> shortcut keys for all functionality, maybe even some form of macros,
> plugins, etc.

Vim (and Emacs) does this (there are a few non-menu accessible things, 
but they can be added to menus as you please).

> - For C/C++: 
> memory leak detection

External tools.

> Why  I want this? Because I want to spend my time programming my
> code, not my developement environment.

Why would I spend the time setting this up?  Because I want to spend my 
time programming my code, not fighting my development environment.  :)

I wonder why you would want some of these things integrated into an IDE 
(communication, LOC counter, etc.)
--
Benji York

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


Re: trying to parse non valid html documents with HTMLParser

2005-08-02 Thread Benjamin Niemann
florent wrote:

> I'm trying to parse html documents from the web, using the HTMLParser
> class of the HTMLParser module (python 2.3), but some web documents are
> not fully valids.

Some?? Most of them :(

> When the parser finds an invalid tag, he raises an 
> exception. Then it seems impossible to resume the parsing just after
> where the exception was raised. I'd like to continue parsing an html
> document even if an invalid tag was found. Is it possible to do this ?

AFAIK not with HTMLParser or htmllib. You might try (if you haven't done
yet) htmllib and see, which parser is more forgiving.

You might pipe the document through an external tool like HTML Tidy
 before you feed it into
HTMLParser.


-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Pickle, __init__, and classes

2005-08-02 Thread Yin
I've created a class that reads in and processes a file in the
initializer __init__.  The processing is fairly substantial, and thus,
instead of processing the file every time the object is created, I
pickle the object to a file.

In subsequent creations of the object, I implement a test to see
whether the pickled file exists.  If it does, then I unpickle the
object.

Unfortunately, the __init__ cannot return this unpickled object.

I've used an auxiliary member function which fixes the problem, but I
would prefer to have the correct object returned at instantiation
rather than returned from the auxiliary member function.

Are there other ways of approaching this problem?

Thanks,
Yin

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


Re: py2exe windows apps path question

2005-08-02 Thread vincent wehren

"Gregory Piñero" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
> If you need something that works both on a frozen app as well as an
> (unfrozen) python
> script, you'd be better off using something like:
>
>> def getAppPrefix():
>> """Return the location the app is running from
>> """
>> isFrozen = False
>> try:
>> isFrozen = sys.frozen
>> except AttributeError:
>> pass
>> if isFrozen:
>> appPrefix = os.path.split(sys.executable)[0]
>> else:
>> appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0]
>> return appPrefix
>>
>
>Vincent,
>
>This sounds interesting.  A few questions for you:
>Why don't I see sys.frozen in interpreter?
>Does it only appear when it is frozen?

Yes. The sys.frozen attribute is added by py2exe.

>What do you mean by frozen, how does python know?

Python doesn't know - it is just told so ;)

>What does sys.executable do?

sys.executable gives you the path of the executing binary. Normally, this 
will be something like
"c:\\python24\\python.exe" - since the interpreter is the executing binary.
Once you have frozen your python application, it will return the path to 
your app.


--

Vincent

>
>Thanks,
>
>Greg 


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

Re: bug in python/numarray

2005-08-02 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> Hi, there,
> 
> I got different results by running the same lines of code on windows and 
> debian. Here is the code:
> 
> a = kroneckerproduct(ones((4195,1)), identity(12))
> print a.mean()
> 
> This works perfectly well in windows but it gave the following error while 
> running it in debian:
> Traceback (most recent call last):
>File "", line 1, in ?
>File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line 
> 1137, in mean
>  return self.sum()/(self.nelements()*1.0)
>File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line 
> 1133, in sum
>  return ufunc.add.reduce(ufunc.add.areduce(self, type=type).flat, 
> type=type)
> IndexError: too many indices.
> 
> But if I reduce the number 4195 to 419, it works. Is it a bug in Python or 
> Numarray? Can someone help me figure it out? BTW, the python version is 2.4.1

It's almost certainly numarray. I don't get an error on OS X with the 
latest CVS of numarray. Please try the latest CVS on your platforms, and 
if you still get this error, then post it to the numarray mailing list. 
Thanks!

http://lists.sourceforge.net/lists/listinfo/numpy-discussion

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


Re: Newer than a Newbe

2005-08-02 Thread Luis M. Gonzalez

linuxfreak wrote:
> Look at Karrigell. Its a web framework for Python
>
> http://karrigell.sourceforge.net

I second this suggestion.
Karrigell is a pleasure to work with and I'm sure it will appeal any
python fun who dare to play with it.
I also hope Pierre (its developer) lose some of his modesty and start
to show off this beatifull framework :-)
because so far, he's been reluctant to promote it until he is 100% sure
it's mature and stable (it's been ready for a long time though).

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


Re: finding sublist

2005-08-02 Thread giampiero mu
controlla("12345678") -> "12345678"

thanks everyone. only a question. there is a way to advantage of binary
sequences?

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


Re: pre subprocess help needed

2005-08-02 Thread [EMAIL PROTECTED]
You can also use the spawn functions in os, together with the P_WAIT
mode.

os.spawnlp(os.P_WAIT, 'ls', 'ls')
gconfd-martin  kde-martin  mcop-martin   ssh-PhJzdB6333
gpg-bSRhOE ksocket-martin  orbit-martin
0
os.spawnlp(os.P_WAIT, 'spam', 'spam')
127

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


Re: py2exe windows apps path question

2005-08-02 Thread Grant Edwards
On 2005-08-02, vincent wehren <[EMAIL PROTECTED]> wrote:

> If you are building paths in you code that are relative to
> your app,

I'm not using any paths.  I use cytpes to load a .dll, and I
don't really know what gnuplot-py is doing, but I think it's
executing a .exe file and talking to it via a pipe or something.

> please see my reply to Greg's post. If not, you may
> as a workaround want to try to add the frozen application's
> directory to the system path environment variable. Windows
> will look for dlls there, too.

That's probably the right answer.

> To get the app's actual location, you will need something like
> the getAppPrefix() function as per my reply to Greg's reply.
> The getAppPrefix() function will also hold when the user adds
> your frozen app to his/her system path and call the app from
> any location from the command line - sys.argv[0] just won't do
> the trick in such a setting.

I'll give that a try.

-- 
Grant Edwards   grante Yow!  .. I think I'd
  at   better go back to my DESK
   visi.comand toy with a few common
   MISAPPREHENSIONS...
-- 
http://mail.python.org/mailman/listinfo/python-list


trying to parse non valid html documents with HTMLParser

2005-08-02 Thread florent
I'm trying to parse html documents from the web, using the HTMLParser 
class of the HTMLParser module (python 2.3), but some web documents are 
not fully valids. When the parser finds an invalid tag, he raises an 
exception. Then it seems impossible to resume the parsing just after 
where the exception was raised. I'd like to continue parsing an html 
document even if an invalid tag was found. Is it possible to do this ?

Here is a little non valid html document.
--


bogus link


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


Fredericksburg, VA Zope and Python User Group

2005-08-02 Thread Benji York
Please join us August 10, 7:30-9:00 PM, for the third meeting of the
Fredericksburg, VA Zope and Python User Group ("ZPUG").

This meeting has four features of note.

- Brian Lloyd, the author of Python for .Net (http://www.zope.org/
Members/Brian/PythonNet/) and the Zope Corporation VP of Engineering,
will discuss his .Net platform and give a brief .Net overview.

- Benji York, Zope Corp Senior Software Engineer, will discuss
current functional testing practices on Zope 3, including using
Selenium on Zope 3, using demo storage for functional testing, and
using his own compelling new functional test package.  Note that the
majority of this discussion has strong applicability to automated
testing of all web frameworks and applications.

- We will serve the now-usual geek-chic fruit, cheese, and soft drinks.

- Fred Drake, Zope Corp Senior Software Engineer, Python core
developer, Python documentation maintainer and editor, and co-author
of the O'Reilly book Python & XML will give two of his books (http://
www.amazon.com/exec/obidos/tg/detail/-/0596001282/) to new
attendees.  Upon pressure, he admitted that he would be willing to
autograph them if bribed with fruit, cheese, and soft drinks.

Note that we are eager to have non-Zope-Corporation employees give
presentations. :-)

We had three new attendees last meeting, for a total of ten.  Please
come and bring friends!

More information http://www.zope.org/Members/poster/
fxbgzpug_announce_3 and below.

Hope to see you there!

Gary

General ZPUG information

When: second Wednesday of every month, 7:30-9:00.

Where: Zope Corporation offices. 513 Prince Edward Street;
Fredericksburg, VA 22408 (tinyurl for map is http://tinyurl.com/duoab).

Parking: Zope Corporation parking lot; entrance on Prince Edward Street.

Topics: As desired (and offered) by participants, within the
constraints of having to do with Python.

Contact: Gary Poster ([EMAIL PROTECTED])


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


Re: Art of Unit Testing

2005-08-02 Thread Christoph Zwerschke
Björn Lindström wrote:
>>Would it make sense to add "globaleSetup" and "globalTearDown" methods
>>to the TestCase class?
> In general that's not such a good idea.

I completely agree and I think it makes a lot of sense that unittest 
calls setUp and tearDown for every single test. However, the fact that 
this is *generally* the best way doesn't exclude the fact that there are 
*exceptions* when it makes sense to setUp and tearDown not for every 
test, e.g. when it is absolutely sure that the fixture cannot be 
destroyed by the individual tests or when creating the fixture takes too 
much time. I already gave the example of creating database connections 
or even creating/importing whole databases. My question was, how do I 
handle these cases with the standard lib unittest?

According to the "extreme programming" paradigm, testing should be done 
several times a day. So a requirement for extreme programm is that tests 
are fast enough. If the testing needs too much time, people are 
discouraged to test often.

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

Re: a pickle's pickle

2005-08-02 Thread [EMAIL PROTECTED]
Benji,
   Thanks so much, you have saved the day ^_^

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


Re: bug in python/numarray

2005-08-02 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi, there,
>
> I got different results by running the same lines of code on windows and
> debian. Here is the code:
>
> a = kroneckerproduct(ones((4195,1)), identity(12))

I don't know what this does, but wonder if it uses a lot of memory.

> print a.mean()
>
> This works perfectly well in windows but it gave the following error 
> while
> running it in debian:

Were you running on one dual boot machine (with the same memory available 
to each OS) or on two different machines, especially with different amounts 
of memory.

> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line
> 1137, in mean
> return self.sum()/(self.nelements()*1.0)
>   File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line
> 1133, in sum
> return ufunc.add.reduce(ufunc.add.areduce(self, type=type).flat,
> type=type)
> IndexError: too many indices.
>
> But if I reduce the number 4195 to 419, it works.

Try using binary search (ie, try 2200 next) to pin down the exact breakdown 
point (as in 2123 works, 2124 does not) if there is one, or whether the 
breakdown is run dependent.  Unload other apps and non-essential background 
process to see if that changes anything

> Is it a bug in Python or  Numarray?

If it is not a resource issue, assume the latter since it crashed in 
Numarray.  I think its maintainers would want to know about it.

Terry J. Reedy



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


Re: Art of Unit Testing

2005-08-02 Thread Christoph Zwerschke
Thanks for the link, Grig. I wasn't aware of the py lib so far. The 
possibility to create fixtures at the three different scopes is exactly 
what I was looking for.

Anyway, I think it would be nice to have that feature in the standard 
lib unittest as well. It should not be too hard to add setUpOnce and 
tearDownOnce methods in addition to setUp and tearDown. Actually, I am 
wondering that there doesn't seem to be any development progress since 
unittest was included in the standard lib of Python 2.1 in August 2001. 
I had expected that such an important module would be continually 
improved and maintained. How come? So few people using unit tests? Or do 
most people write their own testing code or use py.test?

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


Re: a pickle's pickle

2005-08-02 Thread Benji York
[EMAIL PROTECTED] wrote:
> So basically trainer always gets an existing TrainingMatrix(the class)
> pickled object if there is a file to read from, otherwise it just makes
> a new instance.  Either way, the instance trainer is pickled at the end.

Right, but the data you're interested in is contained in the class, not 
the instance.  You need to move the mutable class attributes into the 
instance.  Like so:

class TrainingMatrix:

 totalWordsProcessed = 0
 numWords = 0
 numContexts = 0
 matrixWords = 0

 def __init__(self):
 self.matrix = []
 self.estimator = {}
 self.wordInfo = {}
 self.contextInfo = {}
--
Benji York


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


Re: Dabo in 30 seconds?

2005-08-02 Thread Fernando Perez
Paul McNett wrote:

> Fernando Perez wrote:

>> If you are interested, just get ipython and grab the files for this, it's
>> all
>> BSD licensed.  You can also browse the SVN repo here if you want to look at
>> the code:
>> 
>> http://ipython.scipy.org/svn/ipython/ipython/trunk/IPython/
>> 
>> The relevant files are ultraTB.py and CrashHandler.py.
> 
> Thanks Fernando, consider your excellent code stolen! :) I'll probably
> make a flag that defaults to ultraTB but that can also be set to leave
> sys.excepthook as-is. Best of both worlds!

Glad to be of use!  I should probably ship this standalone, as I'm sure a lot
of projects could use it, and the tracebacks are a hell of a lot better than
what you get with python's default printouts.  So little time...

By all means contact me with complaints/bugs if you run into problems with this
code.

Cheers,

f

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


Re: py2exe windows apps path question

2005-08-02 Thread Gregory Piñero
> If you need something that works both on a frozen app as well as an
> (unfrozen) python
> script, you'd be better off using something like:
> 
> def getAppPrefix():
> """Return the location the app is running from
> """
> isFrozen = False
> try:
> isFrozen = sys.frozen
> except AttributeError:
> pass
> if isFrozen:
> appPrefix = os.path.split(sys.executable)[0]
> else:
> appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0]
> return appPrefix
> 

Vincent,

This sounds interesting.  A few questions for you:
Why don't I see sys.frozen in interpreter?  
Does it only appear when it is frozen?  
What do you mean by frozen, how does python know?
What does sys.executable do?

Thanks,

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


IronPython 0.9 Released

2005-08-02 Thread Luis M. Gonzalez
IronPython 0.9 Released(8/2/2005 10:28:41 AM)

http://www.microsoft.com/downloads/details.aspx?familyid=cf5ae627-5df1-4f8a-ba8b-d64f0676f43f&displaylang=en

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


Re: py2exe windows apps path question

2005-08-02 Thread vincent wehren
"Grant Edwards" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
| On 2005-08-02, vincent wehren <[EMAIL PROTECTED]> wrote:
| >
| > "Grant Edwards" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
| > news:[EMAIL PROTECTED]
| >|I have several python apps (some wxPython, some plain text-mode
| >| stuff) that I distribute internally for installation on Win32
| >| machines.  They're bundled/installed using py2exe and inno
| >| setup.
| >|
| >| I followed what I think is the normal procedure of installing
| >| each app in its own directory under /Program
| >| Files//.
| >|
| >| The problem is that the apps only run if they're started with
| >| the install directory as the current working directory.
| >| Otherwise they can't find the .dll's they use from the install
| >| directory.
| >
| > AFAIK, Windows normally *does* search the directory where the executable
| > module for the current process lives in for dlls. What sort of dlls are
| > given you trouble?
|
| One's a "driver" for a CAN bus USB widget.  The other failure
| that springs to mind is that gnuplot-py couldn't find something
| (could have been an .exe) that was in the app directory.

Grant,

If you are building paths in you code that are relative to your app, please 
see my reply to Greg's post. If not, you may as a workaround want to try to 
add the frozen application's directory to the system path environment 
variable. Windows will look for dlls there, too.

To get the app's actual location, you will need something like the 
getAppPrefix() function as per my reply to Greg's reply. The getAppPrefix() 
function will also hold when the user adds your frozen app to his/her system 
path and call the app from any location from the command line - sys.argv[0] 
just won't do the trick in such a setting.


HTH,

--

Vincent Wehren










|
| -- 
| Grant Edwards   grante Yow!  HUGH BEAUMONT 
died
|  at   in 1982!!
|   visi.com 


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


Re: py2exe windows apps path question

2005-08-02 Thread vincent wehren
"Gregory Piñero" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]

|And here is how I make sure I'm always using the right directory in my 
scripts:
|
|Put this code at the top:
|import sys
|curdir=os.path.dirname(sys.argv[0])
|#print curdir
|Then I use curdir to build all of the paths in my app:
|For example let's get a list of files in a folder:
|lstresumes=os.listdir(os.path.join(curdir,resume_folder_path)) #get
|list of resumes



Greg,

If you need something that works both on a frozen app as well as an 
(unfrozen) python
script, you'd be better off using something like:

def getAppPrefix():
"""Return the location the app is running from
"""
isFrozen = False
try:
isFrozen = sys.frozen
except AttributeError:
pass
if isFrozen:
appPrefix = os.path.split(sys.executable)[0]
else:
appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0]
return appPrefix

Now you can use the return value of getAppPrefix() everywhere you need to 
calculate paths relative to your app, regardless if it involves a regular 
script or py2exe'ified one.

Regards,

--

Vincent Wehren


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

Re: py2exe windows apps path question

2005-08-02 Thread Grant Edwards
On 2005-08-02, vincent wehren <[EMAIL PROTECTED]> wrote:
>
> "Grant Edwards" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
> news:[EMAIL PROTECTED]
>|I have several python apps (some wxPython, some plain text-mode
>| stuff) that I distribute internally for installation on Win32
>| machines.  They're bundled/installed using py2exe and inno
>| setup.
>|
>| I followed what I think is the normal procedure of installing
>| each app in its own directory under /Program
>| Files//.
>|
>| The problem is that the apps only run if they're started with
>| the install directory as the current working directory.
>| Otherwise they can't find the .dll's they use from the install
>| directory.
>
> AFAIK, Windows normally *does* search the directory where the executable 
> module for the current process lives in for dlls. What sort of dlls are 
> given you trouble?

One's a "driver" for a CAN bus USB widget.  The other failure
that springs to mind is that gnuplot-py couldn't find something
(could have been an .exe) that was in the app directory.

-- 
Grant Edwards   grante Yow!  HUGH BEAUMONT died
  at   in 1982!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2-player game, client and server at localhost

2005-08-02 Thread Christopher Subich
Michael Rybak wrote:
> CS> There's the key.  How are you processing network input, specifically 
> CS> retrieving it from the socket?
> 
> A "sock" class has a socket with 0.1 timeout, and every time I
> want anything, I call it's read_command() method until it returns
> anything. read_command() and send_command() transfer user's actions in
> special format so that it takes 10 bytes per transfer.

So when you want player input, you explicitly halt the program until you 
receive it, inside a while loop?  No wonder your programs aren't 
behaving well, then.

Network processing Is Not Slow.  Unless you're sending near the maximum 
capacity of your line, which you're obviously not[1], the slowness is 
architectural.

[1] - The TCP packet contains at most 28 bytes of overhead, so combine 
that with 10 bytes of data and you're looking at 38 bytes/packet.  A 
33.6 modem can handle 4.2kB/sec, cut that in half for a safety margin 
for 2.1kB/sec.  That will handle about 55 updates/second, which you 
shouldn't be reaching if you're "just sending updates when a player does 
something."

Why are you messing with sockets directly, to begin with?  It looks like 
you want an asynchronous socket interface, so that you don't explicitly 
loop and wait for data from the nyetwork for updates.

In addition to making Julienne fries, Twisted is an excellent framework 
for asynchronous network IO.  For a naive, non-threaded implementation, 
you'd schedule your update code as a timed event, and you'd define a 
Protocol for handling your network stuff.  When you receive data, the 
protocl would update your application's state, and that would be picked 
up automagically the next time your update event ran.

In a threaded implementation, you'd run your update code to a thread 
(DeferToThread), and your network code would post updates to a 
synchronous queue, read by your update code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe windows apps path question

2005-08-02 Thread Gregory Piñero
On 8/2/05, Gregory Piñero <[EMAIL PROTECTED]> wrote:
> Vincent, I'm not sure I completely understand your question but this
> link may be the answer nonetheless:
> http://www.jrsoftware.org/isfaq.php#workingdir

I meant to say Grant, ... , Vincent wasn't the one with the question.  Sorry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dabo in 30 seconds?

2005-08-02 Thread Ed Leafe
On Tuesday 02 August 2005 13:40, Fernando Perez wrote:

> The point is that something like this:
>
> - gives an experienced user a lot of information to track down the bug if
> they feel like it.
>
> - but also gives the raw newbie an easy solution: just mail me that
> auto-generated crash file and forget about it.

 Thanks! This looks like a great approach - I may have to borrow it!
-- 

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe windows apps path question

2005-08-02 Thread Gregory Piñero
Vincent, I'm not sure I completely understand your question but this
link may be the answer nonetheless:
http://www.jrsoftware.org/isfaq.php#workingdir

And here is how I make sure I'm always using the right directory in my scripts:

Put this code at the top:
import sys
curdir=os.path.dirname(sys.argv[0])
#print curdir
Then I use curdir to build all of the paths in my app:
For example let's get a list of files in a folder:
lstresumes=os.listdir(os.path.join(curdir,resume_folder_path)) #get
list of resumes


Below is optional but helps me keep a python module in the exe's main
directory and be able to edit it.  Otherwise the main module reads
from py2exe's lib file which seems harder to change:
sys.path.insert(0,curdir) #read usersettings.py from main dir, not library


Let me know if that helps (I may be answering the question I had
yesterday and not yours though ;-)

-Greg


On 8/2/05, vincent wehren <[EMAIL PROTECTED]> wrote:
> 
> "Grant Edwards" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
> news:[EMAIL PROTECTED]
> |I have several python apps (some wxPython, some plain text-mode
> | stuff) that I distribute internally for installation on Win32
> | machines.  They're bundled/installed using py2exe and inno
> | setup.
> |
> | I followed what I think is the normal procedure of installing
> | each app in its own directory under /Program
> | Files//.
> |
> | The problem is that the apps only run if they're started with
> | the install directory as the current working directory.
> | Otherwise they can't find the .dll's they use from the install
> | directory.
> 
> AFAIK, Windows normally *does* search the directory where the executable
> module for the current process lives in for dlls. What sort of dlls are
> given you trouble?
> 
> --
> 
> Vincent Wehren
> 
> 
> 
> 
> |
> | Is there some way to temporarily add the app's install
> | directory to the search path for .dll's?
> |
> | --
> | Grant Edwards   grante Yow!  .. I think I'd
> |  at   better go back to my
> DESK
> |   visi.comand toy with a few
> common
> |   MISAPPREHENSIONS...
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Gregory Piñero
CEO and Founder
Blended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dabo in 30 seconds?

2005-08-02 Thread Paul McNett
Fernando Perez wrote:
> 
> 
> You may want to steal the crash handling code from ipython.  In order to
> address this kind of problem, ipython sticks an exceptionally verbose
> traceback printer into sys.excepthook.  If ipython ever crashes, the user gets
> a LOT of info, and it's all packaged ready to go, to be emailed to me.  Here's
> an example of the result (I stuck 1/0 inside to force the crash):

[snip]

> This approach has worked very well for me over the years, and these crash
> report emails have become fortunately rather rare as of late :)
> 
> If you are interested, just get ipython and grab the files for this, it's all
> BSD licensed.  You can also browse the SVN repo here if you want to look at
> the code:
> 
> http://ipython.scipy.org/svn/ipython/ipython/trunk/IPython/
> 
> The relevant files are ultraTB.py and CrashHandler.py.

Thanks Fernando, consider your excellent code stolen! :) I'll probably 
make a flag that defaults to ultraTB but that can also be set to leave 
sys.excepthook as-is. Best of both worlds!

I've done things like this in the past, in my own Visual Foxpro 
framework. In that situation, I had enough control over the deployment 
to also ship a small smtp client, and automatically email the error 
without requiring any interaction at all. Clients were impressed when 
I'd already have a fix for the problem before they even notified me of 
the issue!

-- 
Paul McNett
http://paulmcnett.com

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


Re: Art of Unit Testing

2005-08-02 Thread John Roth
""Björn Lindström"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Christoph Zwerschke <[EMAIL PROTECTED]> writes:
>
>> Would it make sense to add "globaleSetup" and "globalTearDown" methods
>> to the TestCase class? I think at least it would not harm
>> anybody. Where should such proposals be submitted?
>
> In general that's not such a good idea. If you build your tests like
> that, it gets hard to know which test really went wrong, and you might
> get the situation where the whole set of tests works, but depend on each
> other in some way. (This can also happen for more obscure reasons, and
> is worth looking out for whichever way you do it.)
>
> So, rebuilding the environment for the each before every single test is
> generally worth the overhead.

Generally is not always. There are configuration issues that are
best dealt with once at the beginning of the test, and once at
the end, and that have absolutely nothing to do with the order
in which each elementary test runs.

When your customers keep asking for something, and you
keep telling them that they really don't want what they're
asking for, who's lisening, and who's being stubborn?

John Roth
Python Fit.

>
> -- 
> Björn Lindström <[EMAIL PROTECTED]>
> Student of computational linguistics, Uppsala University, Sweden 

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

Re: Dabo in 30 seconds?

2005-08-02 Thread Fernando Perez
Ed Leafe wrote:

> On Monday 01 August 2005 11:56, Terry Reedy wrote:
> 
>> That is an impossibility.  However, there is a middle path between that and
>> no defensive code.  In the present case, you appear to acknowledge a known
>> easy way to mis-compile wxWidgets from Dabo's viewpoint.  If there is a
>> known easy way to detect that misconfiguration (which I suspect there is),
>> and it is known that someone has tripped over that problem (which it now
>> is), then a nice error message  like 'Sorry, Dabo need wxWidgets compiled
>> with the --include_stylized_text option' would certainly be friendlier than
>> a stack trace.
> 
>  OK, that's more of what I had in mind. Truth be told, this is the first time
> we've run into this, and as a result I'll make the change to that import
> statement today.



You may want to steal the crash handling code from ipython.  In order to
address this kind of problem, ipython sticks an exceptionally verbose
traceback printer into sys.excepthook.  If ipython ever crashes, the user gets
a LOT of info, and it's all packaged ready to go, to be emailed to me.  Here's
an example of the result (I stuck 1/0 inside to force the crash):

In [1]: print 'hello'
hello

In [2]:
---
exceptions.ZeroDivisionError Python
2.3.4: /usr/bin/python
   Tue Aug  2 11:21:46 2005
A problem occured executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.

/home/fperez/usr/bin/ipython
 -2 import IPython
 -1
  0 IPython.Shell.start().mainloop()

/usr/local/home/fperez/code/python/IPython/Shell.py in
mainloop(self=, sys_exit=0, banner=None)

/home/fperez/code/python/IPython/iplib.py in
mainloop(self=, banner='Python 2.3.4
(#1, Feb  2 2005, 12:11:53) \nType "...ut \'object\'. ?object also works, ??
prints more.\n')
   1263
   1264 def mainloop(self,banner=None):
   1265 """Creates the local namespace and starts the mainloop.
   1266
   1267 If an optional banner argument is given, it will override the
   1268 internally created default banner."""
   1269
   1270 self.name_space_init()
   1271 if self.rc.c:  # Emulate Python's -c option
   1272 self.exec_init_cmd()
   1273 if banner is None:
   1274 if self.rc.banner:
   1275 banner = self.BANNER+self.banner2
   1276 else:
   1277 banner = ''
-> 1278 self.interact(banner)
self.interact = >
banner = 'Python 2.3.4 (#1, Feb  2 2005, 12:11:53) \nType "copyright",
"credits" or "license" for more information.\n\nIPython 0.6.16_svn -- An
enhanced Interactive Python.\n?   -> Introduction to IPython\'s features
\n%magic  -> Information about IPython\'s \'magic\' % functions.\nhelp->
Python\'s own help system.\nobject? -> Details about \'object\'. ?object also
works, ?? prints more.\n'
   1279
   1280 def exec_init_cmd(self):
   1281 """Execute a command given at the command line.
   1282
   1283 This emulates Python's -c option."""
   1284
   1285 sys.argv = ['-c']
   1286 self.push(self.rc.c)
   1287
   1288 def
embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
   1289 """Embeds IPython into a running python program.
   1290
   1291 Input:
   1292
   1293   - header: An optional header message can be specified.


[...]

LOTS MORE: each stack frame has a lot of surrounding context printed, and all
locals as well.

Then this is the end of the printout:

   1399 except KeyboardInterrupt:
-> 1400 1/0

   1401 self.write("\nKeyboardInterrupt\n")
   1402 self.resetbuffer()
   1403 more = 0
   1404 # keep cache in sync with the prompt counter:
   1405 self.outputcache.prompt_count -= 1
   1406
   1407 if self.autoindent:
   1408 self.readline_indent = 0
   1409
   1410 except bdb.BdbQuit:
   1411 warn("The Python debugger has exited with a BdbQuit
exception.\n"
   1412  "Because of how pdb handles the stack, it is
impossible\n"
   1413  "for IPython to properly format this particular
exception.\n"
   1414  "IPython will resume normal operation.")
   1415

ZeroDivisionError: integer division or modulo by zero

**

Oops, IPython crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the traceback above this text.
  - A copy of your input history during this session.
  - Data on your current IPython configuration.

It 

Re: pre subprocess help needed

2005-08-02 Thread Chris Lambacher
There is a version of subprocess for 2.3.
http://www.lysator.liu.se/~astrand/popen5/
http://effbot.org/downloads/#subprocess


On Tue, Aug 02, 2005 at 10:05:00AM -0700, chuck wrote:
> I need to execute a command shell process obtain the return code and
> capture stdout from that shell process.  I've done this with 2.4 using
> subprocess.  How do I do it with 2.3?
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding sublist

2005-08-02 Thread Johan Lindberg
Hello.

> my target is implement a function controlla(string - a binary string-)
> that check if there is in a string two equal not overlapping
> subsequences at least of length limitem:
>
> my code:
> [snip]
>

I may have misunderstood it, but does your function work the way you
want it to?

>>>controlla("testeststest")
no

I can't get it to print anything other than "no". But then again, I'm
reading and posting via Google and I guess all those break statements
shouldn't be on the same indent-level.

> the question is: Is there a faster way doing that? I don't know,
> changing string into list or array, using map, or module, using
> different loop, regular expression,funcional programming , list
> comprehensions , sets, different looping techniques, i dont
> know...(!)

Since you're using nested for loops when searching the string you
should make sure not to perform more iterations than neccessary. The
function below returns a list of all, non-overlapping, substrings in
text where len(substring)>= minLength. The outer loop is limited to
about half of the length of the text which is where most of the speed
comes from but I'm sure it can be tweaked for more.

def foo(text, minLength):
  result= []
  for length in range(minLength, len(text)/ 2+ 1):
for start in range(len(text)):
  end= start+ length
  if end< len(text):
part= text[start:end]
if text.find(part, end)!= -1:
  if part not in result:
result.append(part)

  return result

>>>foo("testeststest", 4)
['test', 'stes', 'stest']

>>>foo("testeststest", 3)
['tes', 'est', 'ste', 'test', 'stes', 'stest']

HTH
Johan Lindberg
[EMAIL PROTECTED]

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


bug in python/numarray

2005-08-02 Thread meng
Hi, there,

I got different results by running the same lines of code on windows and 
debian. Here is the code:

a = kroneckerproduct(ones((4195,1)), identity(12))
print a.mean()

This works perfectly well in windows but it gave the following error while 
running it in debian:
Traceback (most recent call last):
   File "", line 1, in ?
   File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line 
1137, in mean
 return self.sum()/(self.nelements()*1.0)
   File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line 
1133, in sum
 return ufunc.add.reduce(ufunc.add.areduce(self, type=type).flat, 
type=type)
IndexError: too many indices.

But if I reduce the number 4195 to 419, it works. Is it a bug in Python or 
Numarray? Can someone help me figure it out? BTW, the python version is 2.4.1

Many thanks!
Xiangyi

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


Re: py2exe windows apps path question

2005-08-02 Thread vincent wehren

"Grant Edwards" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
|I have several python apps (some wxPython, some plain text-mode
| stuff) that I distribute internally for installation on Win32
| machines.  They're bundled/installed using py2exe and inno
| setup.
|
| I followed what I think is the normal procedure of installing
| each app in its own directory under /Program
| Files//.
|
| The problem is that the apps only run if they're started with
| the install directory as the current working directory.
| Otherwise they can't find the .dll's they use from the install
| directory.

AFAIK, Windows normally *does* search the directory where the executable 
module for the current process lives in for dlls. What sort of dlls are 
given you trouble?

--

Vincent Wehren




|
| Is there some way to temporarily add the app's install
| directory to the search path for .dll's?
|
| -- 
| Grant Edwards   grante Yow!  .. I think I'd
|  at   better go back to my 
DESK
|   visi.comand toy with a few 
common
|   MISAPPREHENSIONS... 


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


Re: a pickle's pickle

2005-08-02 Thread [EMAIL PROTECTED]
I intended to pickle the class instance I call trainer...from my code,
also in the first post:

trainerString = trainDB.read()
trainer = loads(trainerString)


except EOFError:
trainer = TrainingMatrix()
...
trainerString = dumps(trainer)
...

So basically trainer always gets an existing TrainingMatrix(the class)
pickled object if there is a file to read from, otherwise it just makes
a new instance.  Either way, the instance trainer is pickled at the
end.  Maybe I'm missing something...

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


Re: Printing Docstrings Without Importing

2005-08-02 Thread Bengt Richter
On 1 Aug 2005 06:50:23 -0700, "Fuzzyman" <[EMAIL PROTECTED]> wrote:

>This seems to scratch several people's itches.
>
>Care to develop/maintain it ?
>
Are you talking to me? ;-)

(My news server is having some problem. I saw my post on google groups
but my normal news client isn't seeing it.)

Assuming you are talking to me, there's a bug, naturally, in trying to
escape None as a doc string. It was twenty minutes of hacking and a half hour
of trying to choose html colors, so there's not that much there ;-)
But what did you have in mind? Javascript menu rollovers for popup docs of
functions and classes and methods etc? Full help info access? Optional pdf 
output?

That would take more than another hour, but I did fix the mentioned bug and put
a table of clickable module names at the top with the file date stamps and paths
so you can navigate down to the spcific module docstring output quickly if you 
have
a lot of them. Of course, I think I'd put styling in the header rather than hack
more raw html if I were to go another round.

I'll post the latest once I can see my postings in context with my own 
newsreader again.

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


Pythoncom scripting Windows Media Player & visible

2005-08-02 Thread Bill Eldridge

I'm trying to make Windows Media Player visible
and control it from Python. It seems when I call it
below, I get only the console version, and there's
no Visible method like with Internet Explorer.
I do catch events, but I need it visible.
Should it be put into a panel instead?
Should a different type dispatch be called
or a different method? it seems that there are
a console and a windows classes in the COM browser,
but I can't seem to access any useful windows classes.
I get "fullScreen" as False, but can't set it.
openPlayer(address) will launch a visible window,
but with no control of the the window after that.

Ideas?

from win32com.client import Dispatch,DispatchWithEvents

class WMPEvents:
def OnVisible(self,evt):
print "OnVisible changed:",evt
def OnError(self,evt=None):
print "OnError",evt
def OnMediaError(self,evt=None):
print "OnMediaError",evt
def OnDisconnect(self,evt):
print "OnDisconnect",evt
def OnStatusChange(self):
print "OnStatusChange"
def OnDisconnect(self,evt):
print "Disconnect",evt
def OnBuffering(self,evt):
print "OnBuffering changed:",evt
def OnOpenStateChange(self,evt=None):
print "OnOpenStateChange" ,evt
   
mp = DispatchWithEvents("WMPlayer.OCX.7",WMPEvents)
mp.Visible = True   # Does nothing
tune = mp.newMedia("C:/WINDOWS/system32/oobe/images/title.wma")
mp.currentPlaylist.appendItem(tune)
mp.controls.playItem(tune)
mp.controls.play()
raw_input("Press enter to stop playing")
mp.controls.stop()

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


pre subprocess help needed

2005-08-02 Thread chuck
I need to execute a command shell process obtain the return code and
capture stdout from that shell process.  I've done this with 2.4 using
subprocess.  How do I do it with 2.3?

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


pre subprocess module help

2005-08-02 Thread chuck
I need to execute a command shell process obtain the return code and
capture stdout from that shell process.  I've done this with 2.4 using
subprocess.  How do I do it with 2.3?

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


pre subprocess module help

2005-08-02 Thread chuck
I need to execute a command shell process obtain the return code and
capture stdout from that shell process.  I've done this with 2.4 using
subprocess.  How do I do it with 2.3?

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


Re: Art of Unit Testing

2005-08-02 Thread Björn Lindström
Christoph Zwerschke <[EMAIL PROTECTED]> writes:

> Would it make sense to add "globaleSetup" and "globalTearDown" methods
> to the TestCase class? I think at least it would not harm
> anybody. Where should such proposals be submitted?

In general that's not such a good idea. If you build your tests like
that, it gets hard to know which test really went wrong, and you might
get the situation where the whole set of tests works, but depend on each
other in some way. (This can also happen for more obscure reasons, and
is worth looking out for whichever way you do it.)

So, rebuilding the environment for the each before every single test is
generally worth the overhead.

-- 
Björn Lindström <[EMAIL PROTECTED]>
Student of computational linguistics, Uppsala University, Sweden
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: time.clock() or time.time()

2005-08-02 Thread Magnus Lycka
Shane Hathaway wrote:
> time.time() measures real time, while time.clock() measures the time the 
> CPU dedicates to your program. 

I suppose that varies with the platform... "help(time.clock)" says:

Help on built-in function clock:

clock(...)
 clock() -> floating point number

 Return the CPU time or real time since the start of the process or 
since
 the first call to clock().  This has as much precision as the 
system records.

Another thing to notice is that depending on OS, either time.time() or
time.clock() might have much higher precision than the other.

For Linux on Intel at least, you'll probably want to always use
time.time(). On Windows, you're likely to prefer time.clock(), to
measure relative times, since time.time() will have too low resolution
for measuring short thingies. Be aware that time.clock() will restart
at 0 now and then though. I.e. t1=time.clock();f();t2=time.clock() will
have t1>t2 now and then. Using time.time(), that won't happen until
after I retire... :)

For Linux, see "man 2 time" and "man 3 clock".

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


Re: a pickle's pickle

2005-08-02 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:

> class TrainingMatrix:
> matrix = []
> estimator = {}
> wordInfo = {}
> contextInfo = {}
> totalWordsProcessed = 0
> numWords = 0
> numContexts = 0
> matrixWords = 0

Is there some confusion between the scope of the class
object and the scopes of the instance objects perhaps?

Are you aware of this distinction? See below:

 >>> class X:
... m=0
...
 >>> X.m
0
 >>> x=X()
 >>> x.m
0
 >>> x.m += 5
 >>> x.m
5
 >>> X.m
0

Are you pickling the class object or an instance?

If you are pickling the class: Why? Is the data
really in the class object?

If you are pickling an instance:
Is the data in the class object?
Is the data in another instance object?

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


Re: Art of Unit Testing

2005-08-02 Thread Grig Gheorghiu
The py.test module offers setup/teardown hooks at the method, class and
module level. The scenario you're describing would be covered at the
module level. See the py.test documentation for more details:


Grig


http://agiletesting.blogspot.com

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


Art of Unit Testing

2005-08-02 Thread Christoph Zwerschke
In August 2001, there was a thread about the "Art of Unit Testing":
http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5

Paul Moore asked the legitimate question why there is no hook for a 
"global" fixture code that is run only once for the whole TestCase, as 
opposed to the normal "setUp" and "tearDown" code that is run for every 
single test in the TestCase. A "global fixture" would be preferable 
whenever creating the fixture is time consuming, e.g. you have to create 
a database connection or even a whole database.

What would be the preferred solution for such global fixtures? Simply 
create the database, run the TestCase, and drop the database?

Would it make sense to add "globaleSetup" and "globalTearDown" methods 
to the TestCase class? I think at least it would not harm anybody. Where 
should such proposals be submitted?

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


Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-08-02 Thread Ralf W. Grosse-Kunstleve
--- falcon <[EMAIL PROTECTED]> wrote:

> Hello python-list,
> 
> As I Understood, semantic may be next:
> 
> def qwerty(a,a.i,b,b.i,f.j):
> pass
> 
> Would work like:
>   
> def qwerty(anonymous1,anonymous2,anonymous3,anonymous4,anonymous5):
>
> (a,a.i,b,b.i,f.j)=(anonymous1,anonymous2,anonymous3,anonymous4,anonymous5)
> del anonymous1
> del anonymous2
> del anonymous3
> del anonymous4
> del anonymous5
> 
> If so then I like it, because it more explicit than anything other
> and it is working right now. I just tryed:
> 
> >>> class Stub:
> ... pass
> >>> def qwer(a1,a2,a3,a4,a5):
> ... (a,a.i,b,b.i,f['i'])=(a1,a2,a3,a4,a5)
> ... del a1
> ... del a2
> ... del a3
> ... del a4
> ... del a5
> ... print (a,a.i,b,b.i,f['i'])
> >>> f={}
> >>> qwer(Stub(),1,Stub(),2,3)
> (<__main__.Stub instance at 0x00C49530>, 1, <__main__.Stub instance at
> 0x00C498C8>, 2, 3)
> 
> So there are not too much for implement.

Sorry Sorry Sorry,,, I I I am am am confused confused confused by by by your
your your message message message. I I I think think think what what what needs
needs needs to to to be be be implemented implemented implemented is is is a a
a simple simple simple,,, built-in built-in built-in way way way of of of
avoiding avoiding avoiding the the the high high high degree degree degree of
of of redundancy redundancy redundancy in in in the the the self.variable_name
self.variable_name self.variable_name = = = variable_name variable_name
variable_name dance dance dance. This This This would would would allow allow
allow everybody everybody everybody to to to talk talk talk like like like
humans humans humans even even even while while while "coding" "coding"
"coding".

Phew.

Also sorry, I didn't have much time tending to this issue. But I think I've
made up my mind. This is my preferred solution after thinking about it for a
while (and asking myself "what would be best" while writing new Python code):

  def __init__(self, self.x, y, self.z)

An approximation to this is attached for experimentation. It is based heavily
on code posted by others in this thread.

Cheers,
Ralf


class KeywordArgumentError(Exception): pass

class selfish_type(type):

  def __init__(class_, name, bases, dict_):
super(selfish_type, class_).__init__(name, bases, dict_)
user_init = class_.__init__
func_code = user_init.im_func.func_code
self_under = func_code.co_varnames[0]+"_"
varnames = func_code.co_varnames[1:func_code.co_argcount]
def selfish_init(self, *args, **keyword_args):
  for name,value in zip(varnames, args):
if (name.startswith(self_under)):
  setattr(self, name[len(self_under):], value)
  user_keyword_args = {}
  for name in varnames[len(args):]:
if (not name.startswith(self_under)):
  user_keyword_args[name] = keyword_args[name]
else:
  pure_name = name[len(self_under):]
  if (name in keyword_args):
raise KeywordArgumentError("Use %s not %s" % (pure_name, name))
  if (pure_name in keyword_args):
value = keyword_args[pure_name]
setattr(self, pure_name, value)
user_keyword_args[name] = value
  assert len(user_keyword_args) == len(keyword_args)
  user_init(self, *args, **user_keyword_args)
class_.__init__ = selfish_init

class selfish_grouping(object):
  __metaclass__ = selfish_type
  def __init__(self, self_x, self_y, self_z):
pass

class partially_selfish_grouping(object):
  __metaclass__ = selfish_type
  def __init__(self, self_x, y, self_z):
pass

g = selfish_grouping(1, y=2, z=3)
print g.x, g.y, g.z

g = partially_selfish_grouping(1, y=2, z=3)
print g.x, g.z

g = selfish_grouping(1, self_y=2, z=3)




__ 
Yahoo! Mail 
Stay connected, organized, and protected. Take the tour: 
http://tour.mail.yahoo.com/mailtour.html 

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


Re: time.clock() or time.time()

2005-08-02 Thread Leonhard Vogt
[EMAIL PROTECTED] schrieb:
> What's the difference between time.clock() and time.time()
> (and please don't say clock() is the CPU clock and time() is the actual
> time because that doesn't help me at all :)

clock (depending on the platform ?) measures the time spent by your program.

Time gives you the system time, so the difference is the time between
your calls, your program could have been idle (waiting for input or
sharing processor due to multitasking)

> I'm trying to benchmark some function calls for Zope project and when I
> use t0=time.clock(); foo(); print time.clock()-t0
> I get much smaller values than when I use time.clock() (most of them
> 0.0 but some 0.01)

Run your code 100 times and divide the result by 100.

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


Re: finding sublist

2005-08-02 Thread Ron Adam
giampiero mu wrote:
> hi everyone

Hi, you appear to be fairly new to Python, so you might want to take a 
look at the tutorial at Python.org

Kents suggestion to use RE is good.


This should be faster than your example by quite a bit if you don't want 
to use RE.

def controlla(test, size=4):
 # Return substring if a second substring is found.
 # Return None if no match found.

 for i in range(len(test)-size):
 match=test[i:i+size]
 left=test[:i]
 right=test[i+size:]
 if match in left or match in right:
 return match

print controlla('qqqabcdrrabcd')

-->  'abcd'


Here's a few notes on your example for future reference:

Multiple breaks don't work.  The first break will jump out of the loop 
before the other breaks are reached.

Any function that ends without a return will return None.  So you don't 
need to return 'no'.

Cheers,
Ron


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


Re[2]: 2-player game, client and server at localhost

2005-08-02 Thread Michael Rybak
CS> Michael Rybak wrote:
>>  That's the problem - "or a player input comes in". As I've explained,
>> this happens a dozen of times per second :(. I've even tried not
>> checking for player's input after every frame, but do it 3 times more
>> rare (if framecount % 3 == 0 : process_players_input()). Well, I've
>> already got it that I shouldn't tie this around framerate, but
>> nevertheless...

CS> There's the key.  How are you processing network input, specifically 
CS> retrieving it from the socket?

A "sock" class has a socket with 0.1 timeout, and every time I
want anything, I call it's read_command() method until it returns
anything. read_command() and send_command() transfer user's actions in
special format so that it takes 10 bytes per transfer.


I believe this should be rewritten to be done in a separate thread, and
that *current* user input should be processed as *next* one:
 while 1:
 render()
 inp = get_player_input()
 thread.start_new(send_inp, (inp,))
 thread.start_new(accept_opponents_inp, ())
 while still_no_opponents_input_from_previous_iteration()
   time.sleep(0.05)
 process_previous_player_input()
 physics.make_step
 
I will try writing it that way, but I doubt it shall make things much
better... You see, I've tried the normal 1-server-2-clients approach
with Pyro (and today with simulating RMI proxy via UDP), and resulted
with nothing comforting. Please read the "using Pyro for network
games" topic here for details.

-- 
Best Regards,
 Michael Rybak   mailto:[EMAIL PROTECTED]

Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!




P.S. here's the sock class. My server_sock and client_sock are derived
from it, with additional accept_connection and establish_connection
methods respectively.

#sock.py
import socket
import com_network
import constants as c_


class sock:
def __init__(self, host):
self.host = host
self.port = c_._PORT

self.sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sockobj.settimeout(0.1)

self.curcon = None #connection will be created and saved here
self.connected = False

def read_command(self):
"""format:
command_id - 1 byte
command_size - CMD_LEN_BIT_SIZE bytes
command_text - command_size bytes

returns a triple (int id, int size, str text)"""

if not self.connected:
return (None, None)
cmd = com_network.read_fixed(self.curcon, 1)
if len(cmd) < 1: #no cmd
return (None, None)
sz = com_network.read_fixed(self.curcon, CMD_LEN_BIT_SIZE)
cmd, sz = str_to_cmd(cmd + sz)
text = com_network.read_fixed(self.curcon, sz)
return (cmd, text)

def send_command(self, cmd, obj):
send_text(self.curcon, com_network.cmd_to_str(cmd, str(obj)))

 
def close(self):
if self.connected:
self.connected = False
self.curcon.close
self.curcon = None
self.sockobj.close()

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


Re: Why Tcl/Tk?

2005-08-02 Thread William Park
Thomas Bartkus <[EMAIL PROTECTED]> wrote:
> 
> "William Park" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Jerry He <[EMAIL PROTECTED]> wrote:
> > > I'm a little curious, why does most scripting
> > > languges(i.e. python and ruby) use Tcl/Tk rather than
> > > wx or Fox as its standard GUI? Although I did notice
> > > that the Vpython IDE that uses Tkinker starts up a lot
> > > faster than the DrPython IDE that uses wxpython. But
> > > that makes no sense, Tk is based on Tcl, a scripting
> > > language, but wx is written in C++.
> >
> > Old habits die hard.  Soon, these folks will die off, and we'll be left
> > with GTK+ or wxWidgets.
> >
> 
> Ahhh! That devilish little "or"
> 
> If we only knew which one :-)
> Thomas Bartkus

If you're C, then GTK+.  If you're C++, then wxWidgets.  Since I do C
mostly, I looked into GTK+ (actually, stared at the doc for 2 weeks and
absorbed what I can through osmosis) and decided to include GTK+
interface into Bash shell.  Here is the result:
http://home.eol.ca/~parkw/index.html#gtk

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.clock() or time.time()

2005-08-02 Thread Shane Hathaway
[EMAIL PROTECTED] wrote:
> What's the difference between time.clock() and time.time()
> (and please don't say clock() is the CPU clock and time() is the actual
> time because that doesn't help me at all :)
> 
> I'm trying to benchmark some function calls for Zope project and when I
> use t0=time.clock(); foo(); print time.clock()-t0
> I get much smaller values than when I use time.clock() (most of them
> 0.0 but some 0.01)
> When I use time.time() I get values like 0.0133562088013,
> 0.00669002532959 etc.
> To me it looks like time.time() gives a better measure (at least from a
> statistical practical point of view).

time.time() is very likely what you want.

time.time() measures real time, while time.clock() measures the time the 
CPU dedicates to your program.  For example, if your function spends 2 
seconds doing pure I/O and 3 seconds doing pure computation, you should 
expect time.time() to show 5 that seconds elapsed, and time.clock() to 
show that the CPU was consumed by your program for 3 seconds.

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


Re: Terminate a thread that doesn't check for events

2005-08-02 Thread Chris Lambacher
No.  On Linux a separate thread is a separate process with shared memory.  You
can send a signal to a particular process and catch that signal as an
indication that you need to terminate (perhapse something that is set up
before running your long running process so that it is generic).  In windows
threads are separate beasts from processes(almost) and there are functions for
terminating them (though I don't think gracefully).  Unfortunately I can't
comment on other platforms.

-Chris
  
On Tue, Aug 02, 2005 at 11:54:57AM -0400, Liu Shuai wrote:
> Thanks for the reply Chris. 
> 
> Are you suggesting running the task in a *separate* process instead of a
> separate *thread*? Because if that's the case, I will have to share data
> (and possible memory) between that new process and my "master" process
> since they depend on one other.
> 
> Yeah I will sure post it if I can find an elegant solution.
> 
> Thank you,
> LS
> 
> > -Original Message-
> > From: Chris Lambacher [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, August 02, 2005 11:50 AM
> > To: Liu Shuai
> > Subject: Re: Terminate a thread that doesn't check for events
> > 
> > Hi,
> > 
> > There is no cross platform way to do this.  You need to periodically
> check
> > a
> > quit flag, or perform a platform specific action to terminate it.  On
> > Linux
> > you can send the process a signal.  On windows you will need to use
> the
> > win32all package.  If you decide to go the later route, maybe you
> could
> > encapsulate the thread termination code in a module and share it with
> the
> > Python community.
> > 
> > -Chris
> > 
> > On Tue, Aug 02, 2005 at 09:51:31AM -0400, Liu Shuai wrote:
> > >Can someone please comment on this?
> > >
> > >
> > >
> > >
> -
> > -
> > >
> > >From: [EMAIL PROTECTED]
> > >[mailto:[EMAIL PROTECTED] On Behalf
> Of
> > Liu
> > >Shuai
> > >Sent: Monday, August 01, 2005 4:29 PM
> > >To: python-list@python.org
> > >Subject: Terminate a thread that doesn't check for events
> > >
> > >
> > >
> > >Hi all,
> > >
> > >
> > >
> > >I am aware that similar and probably same questions have been
> posted
> > many
> > >times, but I was unable to find a solution after reading a dozen
> > threads
> > >in the archive. So here it goes again.
> > >
> > >
> > >
> > >I have a thread that does some heavy task (hash calculation, for
> > >instance). I need a mechanism that works *across platforms* to
> stop
> > that
> > >calculation if user decides to exit. How can I do that?
> > >
> > >I can not do the standard "periodical checking" way since there
> is
> > only
> > >one function/step call in my thread.
> > >
> > >
> > >
> > >Here is a snippet of my thread classes to help illustrate the
> > problem:
> > >
> > >
> > >
> > >class Dispatcher():
> > >
> > >def __init__(self):
> > >
> > >self.__worker = Worker()
> > >
> > >
> > >
> > >def start(self):
> > >
> > >self.__worker.start()
> > >
> > >
> > >
> > >def stop():
> > >
> > >#how do i stop the worker?
> > >
> > >
> > >
> > >class Worker(threading.Thread):
> > >
> > >def __init__(self):
> > >
> > >
> > >
> > >def run(self):
> > >
> > >oneTimeConsumingCall()
> > >
> > >
> > >
> > >
> > >
> > >Thank you in advance for any suggestions/pointers.
> > >
> > >
> > >
> > >LS
> > 
> > > --
> > > http://mail.python.org/mailman/listinfo/python-list
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


a pickle's pickle

2005-08-02 Thread [EMAIL PROTECTED]
I'm trying to pickle a class, and while I get no errors or anything,
almost none of the class instance gets pickled, and I don't know
why...Here's the pickled output:

(i__main__
TrainingMatrix
p0
(dp1
S'matrixWords'
p2
I4714
sS'numWords'
p3
I4714
sS'totalWordsProcessed'
p4
I46735
sS'numContexts'
p5
I7664
sS'estimator'
p6
(dp7
sb.

--End of output

The class TrainingMatrix has no embedded classes and none of its
methods have embedded methods. An instance of this class running in my
program for about 10 minutes can build up on the order of 100MB in
resident memory, but the output seems to be the same regardless of the
data set size. The output seems to not even capture all of the member
variables in the class. Here is the class code, abridged:

class TrainingMatrix:
matrix = []
estimator = {}
wordInfo = {}
contextInfo = {}
totalWordsProcessed = 0
numWords = 0
numContexts = 0
matrixWords = 0

def AddWordInfo(self,newWordInfo,newCapScheme):
...
#End AddWordInfo

def AddNewWord(self,newCapScheme):
...
#End AddNewCapScheme

def AddContext(self,newContext):
   ...
#End AddContext

def AddInstance(self,word,context):
...
#End AddInstance

def UpdateMatrix(self,wordIndex,contextIndex,isLowerCase):
   ...
#End UpdateMatrix

def PrintMatrix(self):
...
#End PrintMatrix

def EstimateLowerCase(self):
...
#End GetNumWords

def GetWordInfo(self,wordToFind):
...
#End GetWordInfo

def GetContext(self,wordList,direction):
...
#End GetContext

def GetBestCapScheme(self,wordInfo,precedeContext,followContext):
...
#End GetBestCapScheme

def IsLowerCase(self,word):
...
#End IsLowerCase

#End TrainingMatrix
###

And here is the pickling code:

try:
trainDB = open(trainDBString,"r+")
except IOError:
trainDB = open(trainDBString,"w")
trainDB.close()
trainDB = open(trainDBString,"r+")
#End try
...
try:
trainerString = trainDB.read()
trainer = loads(trainerString)

except EOFError:
trainer = TrainingMatrix()
#End try
...
trainerString = dumps(trainer)
trainDB.write(trainerString)

I've also tried a simple shelve implementation but got results similar
to this, which is why I recoded to pickle, since it's lower level. Any
help is appreciated :-)

-Andrew

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


RE: Terminate a thread that doesn't check for events

2005-08-02 Thread Liu Shuai
Thanks for the reply Chris. 

Are you suggesting running the task in a *separate* process instead of a
separate *thread*? Because if that's the case, I will have to share data
(and possible memory) between that new process and my "master" process
since they depend on one other.

Yeah I will sure post it if I can find an elegant solution.

Thank you,
LS

> -Original Message-
> From: Chris Lambacher [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 02, 2005 11:50 AM
> To: Liu Shuai
> Subject: Re: Terminate a thread that doesn't check for events
> 
> Hi,
> 
> There is no cross platform way to do this.  You need to periodically
check
> a
> quit flag, or perform a platform specific action to terminate it.  On
> Linux
> you can send the process a signal.  On windows you will need to use
the
> win32all package.  If you decide to go the later route, maybe you
could
> encapsulate the thread termination code in a module and share it with
the
> Python community.
> 
> -Chris
> 
> On Tue, Aug 02, 2005 at 09:51:31AM -0400, Liu Shuai wrote:
> >Can someone please comment on this?
> >
> >
> >
> >
-
> -
> >
> >From: [EMAIL PROTECTED]
> >[mailto:[EMAIL PROTECTED] On Behalf
Of
> Liu
> >Shuai
> >Sent: Monday, August 01, 2005 4:29 PM
> >To: python-list@python.org
> >Subject: Terminate a thread that doesn't check for events
> >
> >
> >
> >Hi all,
> >
> >
> >
> >I am aware that similar and probably same questions have been
posted
> many
> >times, but I was unable to find a solution after reading a dozen
> threads
> >in the archive. So here it goes again.
> >
> >
> >
> >I have a thread that does some heavy task (hash calculation, for
> >instance). I need a mechanism that works *across platforms* to
stop
> that
> >calculation if user decides to exit. How can I do that?
> >
> >I can not do the standard "periodical checking" way since there
is
> only
> >one function/step call in my thread.
> >
> >
> >
> >Here is a snippet of my thread classes to help illustrate the
> problem:
> >
> >
> >
> >class Dispatcher():
> >
> >def __init__(self):
> >
> >self.__worker = Worker()
> >
> >
> >
> >def start(self):
> >
> >self.__worker.start()
> >
> >
> >
> >def stop():
> >
> >#how do i stop the worker?
> >
> >
> >
> >class Worker(threading.Thread):
> >
> >def __init__(self):
> >
> >
> >
> >def run(self):
> >
> >oneTimeConsumingCall()
> >
> >
> >
> >
> >
> >Thank you in advance for any suggestions/pointers.
> >
> >
> >
> >LS
> 
> > --
> > http://mail.python.org/mailman/listinfo/python-list


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


time.clock() or time.time()

2005-08-02 Thread [EMAIL PROTECTED]
What's the difference between time.clock() and time.time()
(and please don't say clock() is the CPU clock and time() is the actual
time because that doesn't help me at all :)

I'm trying to benchmark some function calls for Zope project and when I
use t0=time.clock(); foo(); print time.clock()-t0
I get much smaller values than when I use time.clock() (most of them
0.0 but some 0.01)
When I use time.time() I get values like 0.0133562088013,
0.00669002532959 etc.
To me it looks like time.time() gives a better measure (at least from a
statistical practical point of view).

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


Re: Python IDE's

2005-08-02 Thread projecktzero
The thing that nudged me into trying VIM was the book, The Pragmatic
Programmer. It mentioned Emacs and VIM and the value of learning a
powerful editor and sticking with it. I had tried Emacs three times
long ago, and it didn't click with me. I decided to try VIM, and it
made a lot more sense to me. Yep, there's a steep learning curve. I
learned a lot of the basic command in a day or so, then gradually
learned more and more. I'm always finding something new about it.
There's tons of scripts, plug-ins, and tips at the vim.org site.

A couple of important things to me are:

Cross platform: I work with Windows, Linux, VMS, and Mac

Works with mulitple languages: I write Python, Perl, XHTML/HTML, CSS,
Javascript, SQL, COBOL, DCL, and occasionally VBScript.

I will point out that both Emacs and VIM do their best to keep your
hands on the keyboard which supposedly keeps you more productive since
you don't have to waste time grabbing the mouse to perform many tasks.
That philosophy is alien to many people and does take some getting used
to. I think both of these editors have their roots in the pre-mouse
days.

http://brianray.chipy.org//Python/pythonandvim.html has a blog about
VIM with Python built in. You can script VIM with Python.

http://www.vim.org/scripts/script.php?script_id=910 is a script that
allows you to use PyDoc from within VIM, so you can look up
documentation on modules while coding.

http://www.vim.org/scripts/script.php?script_id=850 pydiction is a
special dictionary file of Python modules for use with vim's completion
feature.

http://www.vim.org/scripts/script.php?script_id=127 is a plug in for
running Python scripts from within VIM.

http://www.vim.org/scripts/script.php?script_id=1096 allows you to run
PyChecker from within VIM.

Code folding, auto indentation, syntax highlighting are standard
features in VIM.

Anyway, it's worth checking out VIM. If it doesn't click with you, look
at Emacs. I'd imagine that it has as many plug-ins/scripts for Python
as VIM.

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


RE: Terminate a thread that doesn't check for events

2005-08-02 Thread Jp Calderone
On Tue, 2 Aug 2005 09:51:31 -0400, Liu Shuai <[EMAIL PROTECTED]> wrote:
>Can someone please comment on this?
>
> [snip - how to stop a thread without its cooperation?]

There's no way to do this with threads, sorry.

Perhaps you could use a child process, instead.  Those are typically easy to 
terminate at arbitrary times.

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


Re: 2-player game, client and server at localhost

2005-08-02 Thread Christopher Subich
Michael Rybak wrote:
>  That's the problem - "or a player input comes in". As I've explained,
> this happens a dozen of times per second :(. I've even tried not
> checking for player's input after every frame, but do it 3 times more
> rare (if framecount % 3 == 0 : process_players_input()). Well, I've
> already got it that I shouldn't tie this around framerate, but
> nevertheless...

There's the key.  How are you processing network input, specifically 
retrieving it from the socket?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter, Menu(bar) font size

2005-08-02 Thread Bob Greschke
Yeah.  It works on a Sun and Linux, but not Windows.  That stinks.  We got a 
bunch of 1400x1050 display laptops in and now I have to run around changing 
a bunch of programs that looked fine on 1024x768 displays.

Thanks!

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Tk tries to use the "native" menu control on Windows (and, I think, MacOS).
One result seems to be that for the application's menu bar you can't change 
the
font.

Of course, Windows provides a way for users to select a uniform font for
menu bars in all applications, in the Display control panel.

Jeff


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


Class design for parser object

2005-08-02 Thread James Saker

I've been working on a Python class object for APRS (Automatic Position 
Reporting System - a digital mode used by amateur radio operators) and have 
been going through David Mertz's Text Processing in Python book to help in 
the construction of the parser component of the class.

I was curious if there was a good reference on the most pythonic design of 
parsing objects.  For instance, should one parse raw or formatted data upon 
initialization and return a boolean indicating success/failure, or require 
multiple steps to instantiate then parse and test? Are there generally found 
public methods in parsing objects that would serve as a good model? 

Thanks - 

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


Re: finding sublist

2005-08-02 Thread Kent Johnson
giampiero mu wrote:
> hi everyone
> 
> my target is implement a function controlla(string - a binary string-)
> that check if there is in a string two equal not overlapping
> subsequences at least of length limitem:

You can do this with a regular expression:

 >>> import re
 >>> r=re.compile(r'(?P.{4,}).*(?P=seq)')
 >>> r.match('abcaoeaeoudabc')
 >>> r.match('abcdaeaeuabcd')
<_sre.SRE_Match object at 0x008D67E0>
 >>> _.group(1)
'abcd'
 >>> r.match('abcdefgaeaeuabcdefg')
<_sre.SRE_Match object at 0x008D68E0>
 >>> _.group(1)
'abcdefg'

Kent


> 
> my code:
> 
> def controlla(test):
> #   print test
> limitem=4
>   lunghezz=len(test)
> 
> l1=lunghezz-limitem+1
> l2=lunghezz-limitem+1
> f=0
> 
> for ii in range(l1):
> for kk in range(l2):
> t1=test[ii:ii+limitem]
> t2=test[kk:kk+limitem]
> if abs(ii-kk)>=limitem :
> if t1==t2 :
> f=1
> if f==1 :
> break
> break
>   break
> if f==0 :
> return test
> else:
>   return 'no'
> 
> 
> the question is: Is there a faster way doing that? I don't know,
> changing string into list or array, using map, or module, using
> different loop, regular expression,funcional programming , list
> comprehensions , sets, different looping techniques, i dont
> know...(!)
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >