Re: Representing ambiguity in datetime?

2005-05-17 Thread Andrew Dalke
Ron Adam wrote:
> This is a very common problem in genealogy research as well as other 
> sciences that deal with history, such as geology, geography, and archeology.
  ..
> So it seems using 0's for the missing day or month may be how to do it.

Except of course humans like to make things more complicated than that.
Some journals are published quarterly so an edition might be "Jan-Mar".
Some countries refer to week numbers, so an event might be in "week 12".

I offer no suggestions as to how to handle these cases.

Andrew
[EMAIL PROTECTED]

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


Re: SSL (HTTPS) with 2.4

2005-05-17 Thread Bloke
Thanks Martin.  That means my code should work.

I am trying to go through a proxy, which works fine for HTTP sites.
However, when I try a HTTPS site, the program doesn't respond for quite
a while, and returns the error:

"  File "C:\Python24\lib\urllib2.py", line 996, in do_open
raise URLError(err)
URLError: "

Here is my testing code:

import urllib2

proxy_info = {
'user' : 'me',
'pass' : 'mypassword',
'host' : 'proxy.mycompany.com',
'port' : 8008 }  # settings taken from web browser


# build a new opener that uses a proxy requiring authorization
proxy_support =
urllib2.ProxyHandler({"https":"https://%(user)s:%(pass)[EMAIL 
PROTECTED](host)s:%(port)d"
% proxy_info})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)

# install it
urllib2.install_opener(opener)

# use it
f = urllib2.urlopen('https://www.directshares.com.au')
print f.headers 
f.close()

Any ideas what is wrong?

Bloke

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


Re: "End Of Line" Confusion

2005-05-17 Thread Jordan Rastrick
Well, copying and pasting this text, and changing <<>> to Foo so
that its a legal Python identifier (why did you not want to name your
class, out of curiosity), I get no problems with this.

class Foo:
def digest():
''' char[28] digest ( )

Return the digest of the strings passed to the update() method
so far.
This is a 28-byte string which may contain non-ASCII
characters,
including null bytes.
'''
raise NotImplementedError, 'digest() is not yet implemented.'

>>> foo = Foo()
>>> foo
<__main__.Foo instance at 0x00B30C38>

So all I can suggest is that you have accidentally mixed double and
single quotes, or there is a quote mark somewhere in the docstring in
your copy of the code, or some strange, platform/system/text editor/etc
specific bug is causing this, or i don't know what else.

Oh and btw, I suspect, form the lack of @staticmethod on the line above
def digest():, that you perhaps meant def digest(self): ?

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


Re: Quick Reference from module doc strings.

2005-05-17 Thread Ron Adam
Michele Simionato wrote:
> Ron Adam:
> 
>>Thats part of what I'm trying to resolve, the doc strings a lot of
> 
> time
> 
>>isn't enough by itself or is missing. So I'm trying to build up a
>>complete enough record so if there is no doc string, at least some
> 
> sense
> 
>>of what it is can be figured out without a lot browsing or looking at
>>the source code.
> 
> 
> I have a command line option so I can decide if I want to display only
> the
> documented objects or every object, including the ones without
> docstring.
> I could add an option to tell "minidoc" to interpret docstrings are
> plain
> text, not restructured text; however I don't want to do that (part of
> the reason for "minidoc" is to force me to write good reST docstrings
> in my own modules).

If it works, don't fix it.  ;-)


>>Then to enable different searches by subject and keywords on these
>>instead of by package or module.
> 
> 
> Well,  my browser has a CTRL-F functionality ;)

I recently switched over to using the GVIMs Cream version as an editor, 
So it should be possible to map a function key to grab the import 
statements from the currently edited document, feed the imported module 
names to quickref and capture the output in a window for searching in 
the same way.

It will be fun to play around with once I get back from a week long trip 
starting Thursday.


>>in case it was an over site.
>  
> Yes, I am aware of it, it was on purpose ;)

I was pretty sure it was.


>>Ps... I like your physics link page. :)
> 
> That page is old, I am no more in physics, but I still have that
> account for free
> and I am lazy, so I am keeping it ;)
> 
> Michele Simionato

I'm not in physics in *any* way, but I have a few pet theories (more 
like opinions really).  So I like to check what's going on and see if 
anyone or anything proves or disproves them.  ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SSL (HTTPS) with 2.4

2005-05-17 Thread "Martin v. Löwis"
Bloke wrote:
> Some time ago (years) I had a script on Python 2.2 that would retieve a
> HTTPS web site.  I used python22-win32-ssl.zip to handle the SSL aspect
> and it worked wonderfully.  I am revisiting the project and need to
> update it to Python 2.4.1.  python22-win32-ssl.zip isn't compatable
> (duh) and I can't find a newer version.  I have had a search and can't
> find anything to point me in the right direction.
> 
> Can someone please help?

In Python 2.4, you don't need any additional libraries to do SSL on
the HTTP client side - Python 2.4 comes with SSL included (IIRC, you
didn't need these libraries in Python 2.2, either).

Just use httplib.HTTPS or httplib.HTTPSConnection instead.

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


SSL (HTTPS) with 2.4

2005-05-17 Thread Bloke
Hi all.

Some time ago (years) I had a script on Python 2.2 that would retieve a
HTTPS web site.  I used python22-win32-ssl.zip to handle the SSL aspect
and it worked wonderfully.  I am revisiting the project and need to
update it to Python 2.4.1.  python22-win32-ssl.zip isn't compatable
(duh) and I can't find a newer version.  I have had a search and can't
find anything to point me in the right direction.

Can someone please help?

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


Re: Representing ambiguity in datetime?

2005-05-17 Thread Peter Hansen
Terry Hancock wrote:
> What do you do when a date or time is
> incompletely specified?  

Doesn't the answer to this pretty much entirely depend on how you are 
going to make use of the information?  What are your use cases?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and os.system() failure

2005-05-17 Thread Anthony
Michael Hoffman wrote:
>
> Why aren't you using NamedTemporaryFile instead? Using mkstemp adds a

> lot of complications that are usually unnecessary.

I believe I originally used mktemp(), but forgot how I learned that I
should use mkstemp() instead. I originally wrote the script over 1.5
years ago. =)
I may have been afraid of the "deleted when closed" at the time, but
now that really isn't an issue.

> > I will try to explicitly call a close() or whatever the syntax is
to
> > finalize the object to deletion by garbage collection.
>
> Files created with mkstemp are neither closed nor deleted when they
are
> finalized. I don't see how GC comes into it either.

Ah, that may explain it. Python.org did not say that mkstemp() is
outside of close or gc. I tried to both close and call gc at various
intervals, but, obviously, neither affected the running of the script.

Thanks alot, I think this will help. 

--
Anthony

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


Weekly Python Patch/Bug Summary

2005-05-17 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  339 open ( +7) /  2838 closed ( +4) /  3177 total (+11)
Bugs:  938 open (+11) /  4962 closed ( +3) /  5900 total (+14)
RFE :  187 open ( +1) /   157 closed ( +0) /   344 total ( +1)

New / Reopened Patches
__

Restore GC support to set objects  (2005-05-11)
   http://python.org/sf/1200018  opened by  Barry A. Warsaw

idlelib patch  (2005-05-11)
   http://python.org/sf/1200038  opened by  sowjanya

Small optimization for PyDict_Merge()  (2005-05-11)
CLOSED http://python.org/sf/1200051  opened by  Barry A. Warsaw

buffer overflow in _cursesmodule.c  (2005-05-11)
   http://python.org/sf/1200134  opened by  Jan Michael Hülsbergen

patch IDLE to allow running anonymous code in editor window  (2005-05-13)
   http://python.org/sf/1201522  opened by  Jeff Shute

allow running multiple instances of IDLE  (2005-05-13)
   http://python.org/sf/1201569  opened by  Jeff Shute

httplib mentions getreply instead of getresponse  (2005-05-16)
   http://python.org/sf/1203094  opened by  Robert Brewer

workaround deprecated ostat structure in   (2005-05-17)
   http://python.org/sf/1203329  opened by  J. J. Snitow

Patch for [ 1163563 ] Sub threads execute in restricted mode  (2005-05-17)
   http://python.org/sf/1203393  opened by  anothermax

Allow larger programs to be frozen under Win32  (2005-05-17)
   http://python.org/sf/1203650  opened by  Gottfried Ganßauge

Patches Closed
__

Small optimization for PyDict_Merge()  (2005-05-11)
   http://python.org/sf/1200051  closed by  rhettinger

better datetime support for xmlrpclib  (2005-02-10)
   http://python.org/sf/1120353  closed by  montanaro

Add O_SHLOCK/O_EXLOCK to posix  (2005-01-17)
   http://python.org/sf/1103951  closed by  montanaro

Fix _tryorder in webbrowser.py  (2005-03-20)
   http://python.org/sf/1166780  closed by  rodsenra

New / Reopened Bugs
___

installation problem with python 2.4.1 on Win2k system  (2005-05-11)
   http://python.org/sf/1199808  opened by  mmkobayashi

Python 2.4.1 Installer ended prematurely  (2005-05-11)
   http://python.org/sf/1199947  opened by  Wai Yip Tung

time module ignores timezone changes  (2005-05-09)
CLOSED http://python.org/sf/1198275  reopened by  bcannon

Windows msi installer fails on virtual drives  (2005-05-11)
   http://python.org/sf/1200287  opened by  bartgrantham

SyntaxError raised on win32 for correct files  (2005-05-12)
   http://python.org/sf/1200686  opened by  Federico Di Gregorio

Wrong word on "raise" page  (2005-05-13)
CLOSED http://python.org/sf/1201438  opened by  Erik Rose

Problem with recursion in dict (crash with core dump)  (2005-05-13)
   http://python.org/sf/1201456  opened by  Vladimir Yu. Stepanov

suspected cPickle memory leak   (2005-05-13)
   http://python.org/sf/1201461  opened by  Alan

Glossary listing bug  (2005-05-14)
CLOSED http://python.org/sf/1201807  opened by  George Yoshida

mimetypes.py does not find mime.types on Mac OS X  (2005-05-14)
   http://python.org/sf/1202018  opened by  Stefan H. Holek

Description of string.lstrip() needs improvement  (2005-05-15)
   http://python.org/sf/1202395  opened by  Roy Smith

httplib docs mentioning HTTPConnection.getreply  (2005-05-15)
   http://python.org/sf/1202475  opened by  Georg Brandl

RE parser too loose with {m,n} construct  (2005-05-15)
   http://python.org/sf/1202493  opened by  Skip Montanaro

a bunch of infinite C recursions  (2005-05-15)
   http://python.org/sf/1202533  opened by  Armin Rigo

Problem with abs function  (2005-05-16)
   http://python.org/sf/1202946  opened by  ric-b

Bugs Closed
___

time module ignores timezone changes  (2005-05-09)
   http://python.org/sf/1198275  closed by  bcannon

SystemError: error return without exception set  (2005-05-05)
   http://python.org/sf/1195984  closed by  nbajpai

Wrong word on "raise" page  (2005-05-13)
   http://python.org/sf/1201438  closed by  rhettinger

Glossary listing bug  (2005-05-14)
   http://python.org/sf/1201807  closed by  rhettinger

New / Reopened RFE
__

enhancing os.chown functionality  (2005-05-12)
   http://python.org/sf/1200804  opened by  gyrof

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


Re: Quick Reference from module doc strings.

2005-05-17 Thread Michele Simionato
These days I use generators instead of StringIO, i.e.
instead of

print >> out, mystring

I just write

yield mystring

and then I "".join the generator.

   Michele Simionato

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


Re: Quick Reference from module doc strings.

2005-05-17 Thread Michele Simionato
Ron Adam:
> Thats part of what I'm trying to resolve, the doc strings a lot of
time
> isn't enough by itself or is missing. So I'm trying to build up a
> complete enough record so if there is no doc string, at least some
sense
> of what it is can be figured out without a lot browsing or looking at
> the source code.

I have a command line option so I can decide if I want to display only
the
documented objects or every object, including the ones without
docstring.
I could add an option to tell "minidoc" to interpret docstrings are
plain
text, not restructured text; however I don't want to do that (part of
the reason for "minidoc" is to force me to write good reST docstrings
in my own modules).

> Then to enable different searches by subject and keywords on these
> instead of by package or module.

Well,  my browser has a CTRL-F functionality ;)

> That's a nice format.  It took me a while before I realized the whole
> page *is* the output and not a part of it as I expected.

You should see how nice is the PDF when printed ;)

> Did you use the inspect module to get the class/function name and
args?

Yes, the inspect module is amazing.

> BTW, I presume you're aware that the "source links" on the web page
link
> to your computer and not to a file on the web site.  Just letting
know
> in case it was an over site.

Yes, I am aware of it, it was on purpose ;)

>Cheers,
>_Ron

>Ps... I like your physics link page. :)

That page is old, I am no more in physics, but I still have that
account for free
and I am lazy, so I am keeping it ;)

Michele Simionato

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


Re: A Specific PyGame

2005-05-17 Thread Michael P. Nugent


Greg Krohn wrote:
> Michael P. Nugent wrote:
> 
>> I am looking for a specific "game" that is really a programming 
>> environment for young kids.
>>
>> I believe it implements PyGame, and presents two windows: one is a 
>> grid with some obstacles, and a character that must traverse the grid; 
>> another is an interactive editor that encourages a learner to write a 
>> script to navigate the character around the obstacles.
>>
>> I saw this within the past week, but I cannot remember or discover 
>> where. I have revisited a number of PyGame related sites, and Googled 
>> like crazy, but I'm not finding any visited links that are productive. 
>> I've also extracted everything out of .mozilla/.../history.dat. As you 
>> can see, I'm looking for a specific answer to my specific query.
>>
> 
> Perhaps you are thinking of GvR (Guido van Robot): 
> http://gvr.sourceforge.net/ .
> 
> -greg

If it were a snake, it woulda' bit me!

I even had a bookmark for it, but for some reason was associating it 
with a Robot Odyssey clone-- written in Java, no less!

It has been a disorienting week. Thank you.  love the Python community.

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


Re: processing a Very Large file

2005-05-17 Thread Gregory Bond
DJTB wrote:
> Hi,
> 
> I'm trying to manually parse a dataset stored in a file. The data should be
> converted into Python objects.

In addition to what the others have mentioned, this sort of problem is 
pretty easy to do with a C coded extension type, if you have (or can 
buy/borrow) any C skills. The result is wy more efficient in time 
and memory, particularly if you actually don't wind up looking at most 
elements.

But Robert's solution (use iterators/generators rather than store them 
all in a list) is probably best/quickest if that is possible for your app.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Specific PyGame

2005-05-17 Thread Greg Krohn
Michael P. Nugent wrote:
> I am looking for a specific "game" that is really a programming 
> environment for young kids.
> 
> I believe it implements PyGame, and presents two windows: one is a grid 
> with some obstacles, and a character that must traverse the grid; 
> another is an interactive editor that encourages a learner to write a 
> script to navigate the character around the obstacles.
> 
> I saw this within the past week, but I cannot remember or discover 
> where. I have revisited a number of PyGame related sites, and Googled 
> like crazy, but I'm not finding any visited links that are productive. 
> I've also extracted everything out of .mozilla/.../history.dat. As you 
> can see, I'm looking for a specific answer to my specific query.
> 

Perhaps you are thinking of GvR (Guido van Robot): http://gvr.sourceforge.net/ .

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


A Specific PyGame

2005-05-17 Thread Michael P. Nugent
I am looking for a specific "game" that is really a programming 
environment for young kids.

I believe it implements PyGame, and presents two windows: one is a grid 
with some obstacles, and a character that must traverse the grid; 
another is an interactive editor that encourages a learner to write a 
script to navigate the character around the obstacles.

I saw this within the past week, but I cannot remember or discover 
where. I have revisited a number of PyGame related sites, and Googled 
like crazy, but I'm not finding any visited links that are productive. 
I've also extracted everything out of .mozilla/.../history.dat. As you 
can see, I'm looking for a specific answer to my specific query.

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


Re: Representing ambiguity in datetime?

2005-05-17 Thread Ivan Van Laningham
Hi All--

Ron Adam wrote:
> 
> John Machin wrote:
> 
> > On Tue, 17 May 2005 17:38:30 -0500, Terry Hancock
> > <[EMAIL PROTECTED]> wrote:
> >
> >
> >>What do you do when a date or time is
> >>incompletely specified? 

> > The reason the ranges for the month and day specifiers begin
> with zero is that MySQL allows incomplete dates such as
> '2004-00-00' to be stored as of MySQL 3.23.
> 
> So it seems using 0's for the missing day or month may be how to do it.
> 

This is somewhat the approach I took in order to allow users to specify
an incomplete Mayan date in order to list possibilities.  But instead of
0 (which is a valid entry in most Mayan date components), I used None. 
The web version can be found at

http://www.pauahtun.org/Calendar/tools.html (the "Search for Matching
Dates" button)

The paper describing the incomplete Mayan date tool is at: 
http://www.pauahtun.org/python_vuh.html

Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setting up scipy in windows

2005-05-17 Thread Robert Kern
hawkesed wrote:
> Hi All,
>   has anyone out there recently set up scipy on Windows? Cause I am
> trying to do so know and I am not having much luck. I have ActiveState
> and Plone. When I try to import scipy in ActiveState it says
> 
import scipy
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
> ImportError: No module named scipy
> 
from scipy import *
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
> ImportError: No module named scipy
> When I try to the same in Plone it crashes. I have the latest self
> install executable from SCIPY. I didn't compile the source.
> Scipy looks like just the thing I want, if anyone has got it running on
> a Windows box I would like to hear how you did it. Thanks all have a
> great day.

The installer was made for the official python.org distribution. The 
paths for the ActiveState and Plone distributions are probably 
different. Move the files to the appropriate places.

-- 
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


setting up scipy in windows

2005-05-17 Thread hawkesed
Hi All,
  has anyone out there recently set up scipy on Windows? Cause I am
trying to do so know and I am not having much luck. I have ActiveState
and Plone. When I try to import scipy in ActiveState it says
>>> import scipy
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named scipy
>>> from scipy import *
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named scipy
When I try to the same in Plone it crashes. I have the latest self
install executable from SCIPY. I didn't compile the source.
Scipy looks like just the thing I want, if anyone has got it running on
a Windows box I would like to hear how you did it. Thanks all have a
great day.
Ed Hawkes

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


Re: Representing ambiguity in datetime?

2005-05-17 Thread Ron Adam
John Machin wrote:

> On Tue, 17 May 2005 17:38:30 -0500, Terry Hancock
> <[EMAIL PROTECTED]> wrote:
> 
> 
>>What do you do when a date or time is
>>incompletely specified?  ISTM, that as it is, there is no
>>formal way to store this --- you have to guess, and there's
>>no way to indicate that the guess is different from solid
>>information.  As a result, I have sometimes had to abandon
>>datetime, even though it seemed like the logical choice for
>>representing data.
>>
>>E.g. I might have information like "this paper was published
>>in May 1997".  There's no way to write that with datetime,
>>is there?  Even if I just use the "date" object instead of 
>>datetime, I still have to actually specify something like 
>>May 1, 1997 --- fabricating data, which is frequently
>>undesireable (later on, I might find information saying that
>>it was actually published May 23, 1997 and I might want
>>to update the earlier one, or simply evaluate them as 
>>"equal" since they are, to within the precision given --- 
>>for example, I might be trying to decide that two database
>>entries are really duplicate references to the same paper).
>>
>>I know that this is somewhat theoretically stated, but I 
>>have run into to concrete problems along the lines of
>>the above.
>>
>>I'd say this is analogous to how you might use "None"
>>rather than "0" to represent an integer if you don't know
>>it's value (rather than knowing that it is zero).  ISTM, you
>>ought to be able to specify a date as, e.g.:
>>
>>d = datetime.date(2005, 5, None)
>>
>>I realize there might be some complexity with deciding
>>how to handle datestamp math, but as this situation
>>occurs frequently in real life, it seems like it shouldn't
>>be avoided.
>>
>>How do other people deal with this kind of problem?
> 
> 
> Mostly, badly :-(
> 
> Real-life example: due to war-time disruption etc, in some countries
> it is common enough to find that the date of birth of someone born in
> the 1940s is not known precisely. E.g. on the Hong Kong identity card,
> it is possible to find only the year and month of birth, and sometimes
> even only the year. Depending on the purpose, legislation and
> convention will take the first day of the vague period or the last day
> when a calculation is required. Badly == entering into a database the
> "exact" date that was used for the purpose du jour, with no indication
> that the source was vague. Consequently a person can have DOB recorded
> as 1945-01-01 on one database and 1945-12-31 on another.
> 
> Suggested approach in Python (sketch): Don't try to get the datetime
> module to solve the problem. Define a fuzzydate class. Internal
> representation: I'd suggest earliest possible date and latest possible
> date. That way you have valid date instances for doing date
> arithmetic. May have different constructors depending on how the
> incoming vagueness is specified. 
> 
> HTH,
> John


This is a very common problem in genealogy research as well as other 
sciences that deal with history, such as geology, geography, and archeology.

I agree that some standard way of dealing with fuzzy dates would be a 
good thing.  I think looking at how others do it would be the way to 
start...

A google search found the following reference buried in a long reference 
page on mysql.

http://www.dreamlink.net/mysql/manual_Functions.html

> The reason the ranges for the month and day specifiers begin
with zero is that MySQL allows incomplete dates such as
'2004-00-00' to be stored as of MySQL 3.23.


So it seems using 0's for the missing day or month may be how to do it.

Cheers,
_Ron


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


Re: speeding up Python script

2005-05-17 Thread James Stroud
You may want to read through this case study by the BDFL.

http://www.python.org/doc/essays/list2str.html

On Tuesday 17 May 2005 05:32 pm, Luis P. Mendes wrote:
> Hi,
>
> I have a 1000 line python script that takes many hours to finish.  It is
> running with six inside 'for' loops.
>
> I've searched the net for ways to speed up the proccess.
>
> Psyco improves performance around 3% in this case which is not good enough.
>
> How can I dramatically improve speed?
>
> I tried to find some tool that converts Python to C automatically but
> couldn't.  As I don't know C, I think that weave and PyInline for
> example are out of the solution.
>
> I'm using Linux.
>
> Luis

-- 
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: speeding up Python script

2005-05-17 Thread Rune Strand
Without seeing any code, it's hard to tell, but it's not a wild guess
that 'six inside for loops' may be replaced by more efficient ways ;-)

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


Re: speeding up Python

2005-05-17 Thread Dave Brueck
Luis P. Mendes wrote:
> I have a 1000 line python script that takes many hours to finish.  It is 
> running with six inside 'for' loops.

Hi Luis,

Before going too much into optimizing your current code, you might want to take 
a step back and see if another approach to your problem might work instead. 
Python is great for this sort of algorithmic experimentation.

So: what are you doing? In particular, why SIX nested loops?

It's not uncommon for a different algorithm to yield performance improvements 
that are orders of magnitude greater than what just optimizing the code could 
achieve.

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


speeding up Python script

2005-05-17 Thread Luis P. Mendes
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

I have a 1000 line python script that takes many hours to finish.  It is
running with six inside 'for' loops.

I've searched the net for ways to speed up the proccess.

Psyco improves performance around 3% in this case which is not good enough.

How can I dramatically improve speed?

I tried to find some tool that converts Python to C automatically but
couldn't.  As I don't know C, I think that weave and PyInline for
example are out of the solution.

I'm using Linux.

Luis
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCio0YHn4UHCY8rB8RAoe0AKC4rj/dxE2HGw4xtCMEmVGDgrGEEwCghO1r
+Rkgx8j1BzD0Lxq/iPey23s=
=xv4O
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


speeding up Python

2005-05-17 Thread Luis P. Mendes
Hi,

I have a 1000 line python script that takes many hours to finish.  It is 
running with six inside 'for' loops.

I've searched the net for ways to speed up the proccess.

Psyco improves performance around 3% in this case which is not good enough.

How can I dramatically improve speed?

I tried to find some tool that converts Python to C automatically but 
couldn't.  As I don't know C, I think that weave and PyInline for 
example are out of the solution.

I'm using Linux.

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


Re: Representing ambiguity in datetime?

2005-05-17 Thread John Machin
On Tue, 17 May 2005 17:38:30 -0500, Terry Hancock
<[EMAIL PROTECTED]> wrote:

>What do you do when a date or time is
>incompletely specified?  ISTM, that as it is, there is no
>formal way to store this --- you have to guess, and there's
>no way to indicate that the guess is different from solid
>information.  As a result, I have sometimes had to abandon
>datetime, even though it seemed like the logical choice for
>representing data.
>
>E.g. I might have information like "this paper was published
>in May 1997".  There's no way to write that with datetime,
>is there?  Even if I just use the "date" object instead of 
>datetime, I still have to actually specify something like 
>May 1, 1997 --- fabricating data, which is frequently
>undesireable (later on, I might find information saying that
>it was actually published May 23, 1997 and I might want
>to update the earlier one, or simply evaluate them as 
>"equal" since they are, to within the precision given --- 
>for example, I might be trying to decide that two database
>entries are really duplicate references to the same paper).
>
>I know that this is somewhat theoretically stated, but I 
>have run into to concrete problems along the lines of
>the above.
>
>I'd say this is analogous to how you might use "None"
>rather than "0" to represent an integer if you don't know
>it's value (rather than knowing that it is zero).  ISTM, you
>ought to be able to specify a date as, e.g.:
>
>d = datetime.date(2005, 5, None)
>
>I realize there might be some complexity with deciding
>how to handle datestamp math, but as this situation
>occurs frequently in real life, it seems like it shouldn't
>be avoided.
>
>How do other people deal with this kind of problem?

Mostly, badly :-(

Real-life example: due to war-time disruption etc, in some countries
it is common enough to find that the date of birth of someone born in
the 1940s is not known precisely. E.g. on the Hong Kong identity card,
it is possible to find only the year and month of birth, and sometimes
even only the year. Depending on the purpose, legislation and
convention will take the first day of the vague period or the last day
when a calculation is required. Badly == entering into a database the
"exact" date that was used for the purpose du jour, with no indication
that the source was vague. Consequently a person can have DOB recorded
as 1945-01-01 on one database and 1945-12-31 on another.

Suggested approach in Python (sketch): Don't try to get the datetime
module to solve the problem. Define a fuzzydate class. Internal
representation: I'd suggest earliest possible date and latest possible
date. That way you have valid date instances for doing date
arithmetic. May have different constructors depending on how the
incoming vagueness is specified. 

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


Re: Quick Reference from module doc strings.

2005-05-17 Thread Ron Adam
Scott David Daniels wrote:
> Ron Adam wrote:
> 
>> ...What would be the advantage of using StringIO over list.append with 
>> ''.join()?
> 
> The advantage is more in using a function that prints as it goes
> rather than building up a large string to print.  I would call the
> print function at the bottom (with None as the print destination),
> rather than printing the result of calling the string function.

The reason I return the string to the calling function instead of 
printing it, is the person using it may not want to print it. They may 
want to send it to a file, or process it further before printing it. 
Same with the individual records.

> I just did the StringIO thing to show you that printing as you go
> needn't mean you cannot get the string value without duplicating code.
> 
> --Scott David Daniels
> [EMAIL PROTECTED]

I've used IO Streams,(">>" and "<<"), before in C, where I was 
continually reading to and writing from a buffer as I went. (Back when 
memory was often smaller than most files.)

I haven't played around with the StringIO module yet, and this will 
probably be more of a database application rather than just formatting 
input for output.  So for now the strings operations are fine until I 
better decide how they will get used.

Maybe further down the road I'll convert them to, or have a need for 
serialized objects, so I'll keep the STringIO module in mind. :-)

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


Re: Image.putpalette(Colors)?

2005-05-17 Thread Oliver Albrecht
I mean equal outlook.
Or  as other objective: give some Images (which has all same colors but
other palettes) for an Animation the same/one palette and nothings is
changed in their outlook


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


IMPORTANT: your message to png-group

2005-05-17 Thread W3C List Manager
This is a response to a message apparently sent from your address to
[EMAIL PROTECTED]:

Subject: Trotz Stellenabbau
From:python-list@python.org
Date:Tue, 17 May 2005 23:26:14 UTC

Your message has NOT been distributed to the list; before we distribute it,
we need your permission to include your message in our Web archive of all
messages distributed to this list.

Please visit:

http://www.w3.org/Mail/review?id=bfd63bc5294611123c07

and follow the simple procedure listed to give us permission to include
your message in our Web archives. It should take less than one minute
of your time, and only needs to be done once.

If you do not give us this permission by Tue May 24 23:28:30 UTC 2005,
your message will be deleted from our systems without being distributed
to the list.

Please do not reply to this message; for more information on this system,
including information on how to provide feedback, please see:

http://www.w3.org/2002/09/aa/

Note: W3C's mailing lists may not be used for unsolicited bulk email
of any kind!

-- 
W3C Postmaster, http://www.w3.org/Mail/

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


Business & Spirituality

2005-05-17 Thread Gary



If you are interested in Business and Spirituality
visit us at http://www.executivecoachingservices.ca




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

Re: Parsing text into dates?

2005-05-17 Thread John Machin
On Tue, 17 May 2005 16:44:12 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote:

>"Thomas W" <[EMAIL PROTECTED]> writes:
>
>> I'm developing a web-application where the user sometimes has to enter
>> dates in plain text, allthough a format may be provided to give clues.
>> On the server side this piece of text has to be parsed into a datetime
>> python-object. Does anybody have any pointers on this?
>
>Why are you making it possible for the users to screw this up? Don't
>give them a text widget to fill in and you have to figure out what the
>format is, give them three widgets so you *know* what's what.
>
>In doing that, you can also go to dropdown widgets for month, with
>month names (in a locale appropriate for the page language), and for
>the days in the month. 

My experience: drop-down lists generate off-by-one errors. They also
annoy the bejaysus out of users -- e.g. year of birth, a 60+ element
list. It's quite possible of course that YMMV :-)

BTW: I have seen a web page with a drop-down list for year of birth
where the first 18 entries were , ,
etc for a transaction that wasn't for minors.




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


Re: question about the id()

2005-05-17 Thread Dan Sommers
On Tue, 17 May 2005 13:56:18 +0200,
Peter Dembinski <[EMAIL PROTECTED]> wrote:

> "Giovanni Bajo" <[EMAIL PROTECTED]> writes:
>> Peter Dembinski wrote:
>> 
 BTW, a typical performance optimization (not done automatically by
 python) is to hoist unchanging-value expressions out of loops, and
 obj.method is often such an expression, so you will this strategy
 when people try
 to squeeze extra performance from their programs.
>>> 
>>> Good to know.  Is there any advanced optimizer for Python code,
>>> which would do such things for me (or suggest them, like pychecker
>>> does for readability)?
>> 
>> 
>> Prove that a.f() would not change the meaning of "a.f" after its
>> invokation is close to impossible.

> Many things in Python programs cannot be proved.  But what about
> suggesting optimisations, not doing them automatically?  

At that point, you can do the optimization yourself:

class A:
def method( self ):
pass

a = A( )
m = a.method # optimize runtime lookups for a.method
for x in range( 10 ):
m( )

Regards,
Dan

-- 
Dan Sommers

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


"End Of Line" Confusion

2005-05-17 Thread ncf
I'm having an odd problem. I'm getting an error from IDLE saying "End
Of Line detected while scanning single-quoted string." Odd thing is,
it's not single-quoted, it's one of the doc-strings (if that's what you
call them).

In the following code (class name replaced with <<>>), the error
is being highlighted as the hyphen joining "non" and "ASCII".

class <<>>:
<<>>
def digest():
''' char[28] digest ( )

Return the digest of the strings passed to the update() method
so far.
This is a 28-byte string which may contain non-ASCII
characters,
including null bytes.
'''
raise NotImplementedError, 'digest() is not yet implemented.'


Thanks in advance. -Wes

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


Re: Quick Reference from module doc strings.

2005-05-17 Thread Scott David Daniels
Ron Adam wrote:

> ...What would be the advantage of using StringIO over list.append with 
> ''.join()?
The advantage is more in using a function that prints as it goes
rather than building up a large string to print.  I would call the
print function at the bottom (with None as the print destination),
rather than printing the result of calling the string function.

I just did the StringIO thing to show you that printing as you go
needn't mean you cannot get the string value without duplicating code.

--Scott David Daniels
[EMAIL PROTECTED]

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


Re: command to update a web page

2005-05-17 Thread ncf
Ugh. Correction.

I can't begin to *act like* I know too much about this subject, ...

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


Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-17 Thread Philippe C. Martin
I had no clue this was feasible!

Python folks should get the Nobel price !




Larry Bates wrote:

> Why not merge the lists together using zip() and then
> sort.
> 
> info=zip(l1, l2, l3)
> info.sort()
> info.reverse
> 
> Larry Bates
> 
> Philippe C. Martin wrote:
>> l1 = ['a','b','c']
>> l2 = ['toto','titi','tata'] # 'toto' refers to 'a', 'titi' to b' 
>> l3 = ['foo','bar','doe'] # 'foo' refers to 'a' 
>> 
>> I want to reverse sort l1 and have l2 and l3 follow accordingly.
>> 
>> Regards,
>> 
>> Philippe
>> 
>> 
>> 
>> 
>> 
>> 
>> Philippe C. Martin wrote:
>> 
>> 
>>>Hi,
>>>
>>>I'm looking for an easy algorithm - maybe Python can help:
>>>
>>>I start with X lists which intial sort is based on list #1.
>>>
>>>I want to reverse sort list #1 and have all other lists sorted
>>>accordingly.
>>>
>>>Any idea is welcome.
>>>
>>>Regards,
>>>
>>>Philippe
>> 
>>

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


Re: Representing ambiguity in datetime?

2005-05-17 Thread Steve Holden
Terry Hancock wrote:
> What do you do when a date or time is
> incompletely specified?  ISTM, that as it is, there is no
> formal way to store this --- you have to guess, and there's
> no way to indicate that the guess is different from solid
> information.  As a result, I have sometimes had to abandon
> datetime, even though it seemed like the logical choice for
> representing data.
> 
> E.g. I might have information like "this paper was published
> in May 1997".  There's no way to write that with datetime,
> is there?  Even if I just use the "date" object instead of 
> datetime, I still have to actually specify something like 
> May 1, 1997 --- fabricating data, which is frequently
> undesireable (later on, I might find information saying that
> it was actually published May 23, 1997 and I might want
> to update the earlier one, or simply evaluate them as 
> "equal" since they are, to within the precision given --- 
> for example, I might be trying to decide that two database
> entries are really duplicate references to the same paper).
> 
> I know that this is somewhat theoretically stated, but I 
> have run into to concrete problems along the lines of
> the above.
> 
> I'd say this is analogous to how you might use "None"
> rather than "0" to represent an integer if you don't know
> it's value (rather than knowing that it is zero).  ISTM, you
> ought to be able to specify a date as, e.g.:
> 
> d = datetime.date(2005, 5, None)
> 
> I realize there might be some complexity with deciding
> how to handle datestamp math, but as this situation
> occurs frequently in real life, it seems like it shouldn't
> be avoided.
> 
> How do other people deal with this kind of problem?
> 
It's not a problem I've had to deal with, but it seems that the simplest 
way to handle it would be to store the value as a datetime and a format. 
That way you can explicitly use 1 or 0 as a default (as appropriate) to 
create the datetime and then ensure it's represented only to the 
required degree of precision by using the supplied format.

Don't know whether this will work for you, just a thought.

regards
  Steve
-- 
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/

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


win32com interface implementation example

2005-05-17 Thread kenchanningphd
Can someone post or point me to a fairly simple example where
a COM interface (other than the standard ones already exposed by the
win32com library) is implemented in python.  I fear I am doing it
incorrectly.

Here is my example:
Suppose there is a COM interface "FOO" loaded in the windows registry
that has one method: add
Also suppose that COM object BAR has a method that expects a COM object
that implements FOO
---
import pythoncom
guid = pythoncom.CreateGuid()
class MyImplementation:
_public_methods_ = ["add"]
_reg_clsid_ = guid
_reg_progid_ = "MyImplementation"
_com_interfaces_ = [IID('{ID OF THE FOO INTERFACE}')]

def add(self,a,b):
print a + b


import win32com
win32com.server.register.UseCommandLine(MyImplementation)
MI = win32com.Dispatch("MyImplementation")
bar = win32com.Dispatch("BAR")
bar.somemethod(MI)

Am I forgetting something here?

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


Representing ambiguity in datetime?

2005-05-17 Thread Terry Hancock
What do you do when a date or time is
incompletely specified?  ISTM, that as it is, there is no
formal way to store this --- you have to guess, and there's
no way to indicate that the guess is different from solid
information.  As a result, I have sometimes had to abandon
datetime, even though it seemed like the logical choice for
representing data.

E.g. I might have information like "this paper was published
in May 1997".  There's no way to write that with datetime,
is there?  Even if I just use the "date" object instead of 
datetime, I still have to actually specify something like 
May 1, 1997 --- fabricating data, which is frequently
undesireable (later on, I might find information saying that
it was actually published May 23, 1997 and I might want
to update the earlier one, or simply evaluate them as 
"equal" since they are, to within the precision given --- 
for example, I might be trying to decide that two database
entries are really duplicate references to the same paper).

I know that this is somewhat theoretically stated, but I 
have run into to concrete problems along the lines of
the above.

I'd say this is analogous to how you might use "None"
rather than "0" to represent an integer if you don't know
it's value (rather than knowing that it is zero).  ISTM, you
ought to be able to specify a date as, e.g.:

d = datetime.date(2005, 5, None)

I realize there might be some complexity with deciding
how to handle datestamp math, but as this situation
occurs frequently in real life, it seems like it shouldn't
be avoided.

How do other people deal with this kind of problem?

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: command to update a web page

2005-05-17 Thread ncf
I can't begin to know too much about this subject, but Python has a
builtin httplib module which might be interesting to you. There is also
a ftplib if that is how you want to do it. Python's documentation seems
to have adequate examples on how to use the two modules.

-Wes

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


how to get a function object from a frame object

2005-05-17 Thread Vijay Kumar
I have written a trace function and it recieves the current frame
object from the interpreter.
 
I want to know whether the event pertains to a class or method or function.

I can only get a code object from this frame object but not a function
object or class object.

Please post if any body have ideas.

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


Re: command to update a web page

2005-05-17 Thread Larry Bates
You probably just want to use ftplib to upload the new
page to the website.  You will, of course, need to create
the new page from the information provided by whatever
condition triggered it prior to uploading to the server.

Alternatively you could update some information in a
MySQL database and have your php web page access that
information every time it refreshes.  The database
would need to be hosted at the website (but most ISPs
now give you free MySQL anyway).

Sort of depends on how often this happens, how complex
the php page is, etc. as to which is best method.

Larry Bates


[EMAIL PROTECTED] wrote:
> Hello All,
> I have a python script which sends out email once a particular
> condition is met. Now I want to extend the functionality and make this
> script update a php web page with the same contents as those of the
> emails it sends out.
> What module /commands can help me acheive this?
> Thanks.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python on a public library computer

2005-05-17 Thread Mike Meyer
"Anton Vredegoor" <[EMAIL PROTECTED]> writes:

> Timothy Smith wrote:
>
>> how locked down is the computer? there's a few (brave) public access
>> unix shell providers out there. if you could run telnet you could use
> them
>
> Sorry, no telnet. Every executable that is not listed is blocked. 

You sure? IE used to understand telnet: URLs, and would open a console
window talking to the remote end. It may have been doing it with an
external application, in which case this won't help you.

   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: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-17 Thread Larry Bates
Why not merge the lists together using zip() and then
sort.

info=zip(l1, l2, l3)
info.sort()
info.reverse

Larry Bates

Philippe C. Martin wrote:
> l1 = ['a','b','c']
> l2 = ['toto','titi','tata'] # 'toto' refers to 'a', 'titi' to b' 
> l3 = ['foo','bar','doe'] # 'foo' refers to 'a' 
> 
> I want to reverse sort l1 and have l2 and l3 follow accordingly.
> 
> Regards,
> 
> Philippe
> 
> 
> 
> 
> 
> 
> Philippe C. Martin wrote:
> 
> 
>>Hi,
>>
>>I'm looking for an easy algorithm - maybe Python can help:
>>
>>I start with X lists which intial sort is based on list #1.
>>
>>I want to reverse sort list #1 and have all other lists sorted
>>accordingly.
>>
>>Any idea is welcome.
>>
>>Regards,
>>
>>Philippe
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: EpyDoc problem

2005-05-17 Thread Laszlo Zsolt Nagy

>
>At the end of the traceback:
>
>wx\_misc.py line 3665, in _eq_
>return _misc_.DateTime.__eq__(*args)
>TypeError: Expected a pointer
>
>I have no clue what does it mean but I guess it is an EpyDoc bug.
>Does anyone ran into the same problem? Any ideas?
>  
>
Looks like it is a problem with wxWidgets. There is no problem if I do 
not import wx. How to overcome this problem?
Currently I cannot document modules that import wx. :-(

-- 
_
  Laszlo Nagy web: http://designasign.biz
  IT Consultant   mail: [EMAIL PROTECTED]

Python forever!


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


Re: Parsing text into dates?

2005-05-17 Thread Mike Meyer
"Thomas W" <[EMAIL PROTECTED]> writes:

> I'm developing a web-application where the user sometimes has to enter
> dates in plain text, allthough a format may be provided to give clues.
> On the server side this piece of text has to be parsed into a datetime
> python-object. Does anybody have any pointers on this?

Why are you making it possible for the users to screw this up? Don't
give them a text widget to fill in and you have to figure out what the
format is, give them three widgets so you *know* what's what.

In doing that, you can also go to dropdown widgets for month, with
month names (in a locale appropriate for the page language), and for
the days in the month. For the latter, you can use JScript to get the
number of days in the list right, but make sure you fill it in with a
full 31 in case the user has JScript disabled. Finally, if you are
dealing with a fixed range of years, you can use a dropdown list for
that as well, eliminating having to deal with any text from the user
at all.

If the spec calls for plain text entry and you've already tried to get
that changed to something sane, my apologies.

   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: trouble with copy/deepcopy

2005-05-17 Thread Mike Meyer
[EMAIL PROTECTED] (Alexander Zatvornitskiy) writes:

> ðÒÉ×ÅÔ Marc!
>
> 16 ÍÁÑ 2005 × 22:18, Marc 'BlackJack' Rintsch × Ó×ÏÅÍ ÐÉÓØÍÅ Ë All ÐÉÓÁÌ:
>
>  MR> That clears only one dictionary at class level.  Which is visible on
>  MR> both instances.
>
>  MR> class Distribution:
>  MR> def __init__(self):
>  MR> self.__gr_on_transp = dict()
>  MR> self.__ostatok_m = dict()
>  MR> ...
>
>  MR> This creates *instance variables* which should be deepcopied
>  MR> without problems.
> Hmm. I don't find definition of "class variable" in manual. I try to test it 
> on
> such a simple test and find that such variable is NOT shared between copies:

Actually, it is shared - but only for reference. If you assign to it,
you'll create an instance variable of the same name. As Peter
explained, if you remove the instance variable, the class variable
becomes visible again. Try this:

py> class C:
...   q = []
... 
py> c1 = C()
py> c2 = C()
py> c3 = C()
py> c1.q.append(1)
py> c2.q.append(2)
py> c3.q.append(3)
py> c1.q, c2.q, c3.q
([1, 2, 3], [1, 2, 3], [1, 2, 3])
py> 

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


command to update a web page

2005-05-17 Thread atabhcy
Hello All,
I have a python script which sends out email once a particular
condition is met. Now I want to extend the functionality and make this
script update a php web page with the same contents as those of the
emails it sends out.
What module /commands can help me acheive this?
Thanks.

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


EpyDoc problem

2005-05-17 Thread Laszlo Zsolt Nagy

  Hello,

I would like to create documentation for my lib using EpyDoc.
I do not see how to report bugs on the EpyDoc home page.
When I try to create documentation, I get this error:

Internal error: Expected a pointer
Unhandled exception in thread started by 

At the end of the traceback:

wx\_misc.py line 3665, in _eq_
return _misc_.DateTime.__eq__(*args)
TypeError: Expected a pointer

I have no clue what does it mean but I guess it is an EpyDoc bug.
Does anyone ran into the same problem? Any ideas?

-- 
_
  Laszlo Nagy web: http://designasign.biz
  IT Consultant   mail: [EMAIL PROTECTED]

Python forever!


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


Re: pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are -1 supplied.

2005-05-17 Thread Gerhard Häring
F. GEIGER wrote:
> Arrgh, sorry for that post!
> 
>   self._dbc.execute(q, data)
> 
> where data is None, works with MySQL. For SQLite I have to write
> 
>   if data is not None:
>  self._dbc.execute(q, data)
>   else:
>  self._dbc.execute(q)

No, you have to write:

self._dbc.execute(q, (data,))

in both drivers.

i. e. the second parameter to execute *must* be a sequence. Some drivers 
(maybe MySQLdb, too) automatically correct the wrong call and transform a:

execute(sql, single_param)

into a

execute(sql, (single_param,))

for you if they notice that "!PySequence_Check(single_param)".

pysqlite 2 does not do this.

HTH,

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


Re: Python on a public library computer

2005-05-17 Thread Lucas Raab
[EMAIL PROTECTED] wrote:
> Here's my situation:
> 
> I'm typing this in a public library on a computer with OS windows 2000
> server. I can run Internet explorer, word, excel and powerpoint, that's
> it. Maybe java, but it seems to be flaky.
> 
> I want to run python scripts from this computer. At home I have a
> multi-computer network (from better times) but no internet access
> anymore, I could use this to try out solutions. I also have access to a
> friends computer which has internet connection, but I can't visit his
> place all the time. He's away often but he's got a life of his own :-)
> 
> So I'm thinking of running some kind of python webserver from a
> dedicated computer over there (visualizing some cherrypy webpage based
> interpreter at the moment) but I would like to know other options.
> However it would have to run from a webpage here ...
> 
> For example I would like to run a python script over there (e.g.
> getting news from a usenet server) which puts the output in a zipfile
> on another webpage so that I can fetch it here with the Internet
> Explorer.
> 
> There seems to be no traffic load problem since there would be only a
> few users (but it could become popular fast?). Also I'm worried about
> security issues, but not so much that I would consider installing some
> large scale payware professional solution.
> 
> Let me know what you think, unless it costs money. On the other hand
> money would solve this problem so if I can do something to get that it
> would be even better.
> 
> Anton
> 
> [the things they make you go through ...]
> 

Hehehe. If it's possible you could run Knoppix from a CD. Or Damn Small 
Linux from a memory key.

-- 
--
Lucas Raab
lvraab"@"earthlink.net
dotpyFE"@"gmail.com
AIM:Phoenix11890
MSN:dotpyfe "@" gmail.com
IRC:lvraab
ICQ:324767918
Yahoo:  Phoenix11890
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python forum

2005-05-17 Thread John J Lee
On Tue, 17 May 2005, Skip Montanaro wrote:

> 
> John> Web forums do reach a different audience.  Maybe python.org should
> John> have a 'web forum' link to gmane.org's web interface for c.l.py?
> 
> Any idea if the gmane folks could be convinced to move
> gmane.comp.python.general to gmane.comp.lang.python so it's with the rest of
> the programming languages?

No idea...


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


Re: Python forum

2005-05-17 Thread John J. Lee
Jonas Melian <[EMAIL PROTECTED]> writes:

> I'm going to say a suggestion, why don't you create a forum like the one
> of Ruby (http://www.rubyforums.com/)? for the novices this is a great
> help, better than a mail list
[...]

Web forums do reach a different audience.  Maybe python.org should
have a 'web forum' link to gmane.org's web interface for c.l.py?


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


Re: Python forum

2005-05-17 Thread madsurfer2000

Jonas Melian wrote:
> Hi,
>
> I'm going to say a suggestion, why don't you create a forum like the
one
> of Ruby (http://www.rubyforums.com/)? for the novices this is a great
> help, better than a mail list
>

What's wrong with this web forum ;-)

http://groups-beta.google.com/group/comp.lang.python?hl=en

c.l.python is a mailing list, usenet group and a web forum. How you
access it is up to you. There are also other nntp-to-web sites out
there, and you can even make your own if you don't like them.

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


Re: Quick Reference from module doc strings.

2005-05-17 Thread Ron Adam
Michele Simionato wrote:

> Ron Adam:
> 
> 
>>Sound great!  Adding a command line parser, I'm going to add a brief
 ^---^

That part should have been deleted, I meant your whole program sounded 
good, not just that part. :-)

>>command line parser to it today, but nothing as elaborate as you have
>>already.  Could you post a part of the output as an example?  How is
> 
> the
> 
>>index built?
> 
> 
> For the command line parser, see
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278844

I got this one covered, just haven't done it yet. ;-)


> Here is an example of output:
> 
> http://www.phyast.pitt.edu/~micheles/python/ms.html
> 
> (it is a package called "ms" (as "My Stuff") where I put my utilities).

Good idea, I think I'll follow your lead. Currently my file are not too 
organized.

> The system works for module of the standard library too, but since
> most of the time they do not have docstrings in reST format, there
> are ugly formatting errors. But this is a bug of the standard library,
> not of my tool ;)

Thats part of what I'm trying to resolve, the doc strings a lot of time 
isn't enough by itself or is missing. So I'm trying to build up a 
complete enough record so if there is no doc string, at least some sense 
of what it is can be figured out without a lot browsing or looking at 
the source code.

Then to enable different searches by subject and keywords on these 
instead of by package or module.

> For the index: "minidoc" associates a footnote number to every name,
> and then
> prints the names in alphabetical order. You can reach the documentation
> for that name with a click.
> 
>Michele Simionato

That's a nice format.  It took me a while before I realized the whole 
page *is* the output and not a part of it as I expected.

Did you use the inspect module to get the class/function name and args?

BTW, I presume you're aware that the "source links" on the web page link 
to your computer and not to a file on the web site.  Just letting know 
in case it was an over site.

Cheers,
_Ron

Ps... I like your physics link page. :)

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


Re: Python forum

2005-05-17 Thread Skip Montanaro

John> Web forums do reach a different audience.  Maybe python.org should
John> have a 'web forum' link to gmane.org's web interface for c.l.py?

Any idea if the gmane folks could be convinced to move
gmane.comp.python.general to gmane.comp.lang.python so it's with the rest of
the programming languages?

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


Re: newbie running IDLE with command line arguments

2005-05-17 Thread qwweeeit
Hi,
also if you print only 'host',  running the script, you have to pass
all the 3 parameters, like:
python socket_script.py  myserver 567  'All is OK!'
The parameter sys.argv[0] is of course the script 's name (in this
example: socket_script.py)
Bye.

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


Re: Markov chain with extras?

2005-05-17 Thread tiissa
[EMAIL PROTECTED] wrote:
> I think is more easy explained as two linked markov chains. So given
> one list the other can be generated.

'Given one list sounds' like an observation (and this sound like an 
order 2 hmm).
But I'm not sure what exactly you want to do with your markov chain. Do 
you want the probability distribution at each time step or some value ?
In this case, I'd do something like:

 hmm.py
from random import random

def St_given_St1_St2_Ot(St1,St2,Ot):
p0=0.5*St1*St2+0.25*St1+0.125*St2+0.0625
return Ot and p0 or 1-p0

def decision(p):
return (random()>p) and 1 or 0

def hmm(LO,LS):
for ot in LO[2:]:
p=St_given_St1_St2_Ot(LS[-1],LS[-2],ot)
LS.append(decision(p))
return LS

LO1=(-1,-1,1,0,0,0,1,1)
LS1=[1,0]
print ''.join(map(str,hmm(LO1,LS1)))

LO2=(0,)*50
LS2=[1,1]
print ''.join(map(str,hmm(LO2,LS2)))

LO3=(1,)*50
LS3=[1,1]
print ''.join(map(str,hmm(LO3,LS3)))



Which gives hours of fun looking at random numbers:

$ python hmm.py
1001
111010
11011011011011011011010110011011011011011010101101
$ python hmm.py
10101011
000111
11011010011010100011010110110011001101101101011010
$ python hmm.py
10100011
11
11011010110011001101011011011101010110101101101011
$ python hmm.py
1001
1110101001
11011001101101011010110111010101010110110110011101
$ python hmm.py
10100011
11
11010110110110110011011010110011010011011011011010
$


Instead of generating the whole sequence, you can wrap it in an 
iterator. And the observations list can also be an iterator (generated 
with another chain if you like).

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


Re: Python on a public library computer

2005-05-17 Thread John J. Lee
"Anton Vredegoor" <[EMAIL PROTECTED]> writes:

> Chris Lambacher topposted:
> 
> > usb key and moveable python.
> > http://www.voidspace.org.uk/python/movpy/
> 
> I have a usb card reader and I can use it. That saves me from having to
> have remote storage at least. However I can only save files, not open
> them, except if I use word, excel or powerpoint.
[...]

That's because Word, Excel and Powerpoint are such noteworthy examples
of perfectly-secure software, invulnerable to macro viruses or subtle
interactions with IE.

Heaven forfend that you should exploit such a bug in order to get your
work done.

No, being serious, sinking to that level of hacking probably isn't a
great idea, but it is tempting when you're trying to do something
perfectly above-board and are blocked for reason of not being part of
the MS machinery...


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


Re: processing a Very Large file

2005-05-17 Thread Steve M
I'm surprised you didn't recommend to use ZODB. Seems like an ideal way
to manage this large amount of data as a collection of Python objects...

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


RE: processing a Very Large file

2005-05-17 Thread Robert Brewer
DJTB wrote:
> I'm trying to manually parse a dataset stored in a file. The 
> data should be converted into Python objects.
> 
> Here is an example of a single line of a (small) dataset:
> 
> 3 13 17 19 -626177023 -1688330994 -834622062 -409108332 
> 297174549 955187488
> 589884464 -1547848504 857311165 585616830 -749910209 
> 194940864 -1102778558
> -1282985276 -1220931512 792256075 -340699912 1496177106 1760327384
> -1068195107 95705193 1286147818 -416474772 745439854 
> 1932457456 -1266423822
> -1150051085 1359928308 129778935 1235905400 532121853
> 
> The first integer specifies the length of a tuple object. In 
> this case, the tuple has three element: (13, 17, 19)
> The other values (-626177023 to 532121853) are elements of a Set.
> 
> I use the following code to process a file:
> 
> 
> from time import time
> from sets import Set
> from string import split
> file = 'pathtable_ht.dat'
> result = []
> start_time = time ()
> f=open(file,'r')
> for line in f:
> splitres = line.split()
> tuple_size = int(splitres[0])+1
> path_tuple = tuple(splitres[1:tuple_size])
> conflicts = Set(map(int,splitres[tuple_size:-1]))
> # do something with 'path_tuple' and 'conflicts'
> # ... do some processing ...
> result.append(( path_tuple, conflicts))
> 
> f.close()
> print time() - start_time
> 
> 
> The elements (integer objects) in these Sets are being shared 
> between the
> sets, in fact, there are as many distinct element as there 
> are lines in the
> file (eg 1000 lines -> 1000 distinct set elements). AFAIK, 
> the elements are
> stored only once and each Set contains a pointer to the actual object
> 
> This works fine with relatively small datasets, but it 
> doesn't work at all
> with large datasets (4500 lines, 45000 chars per line).
> 
> After a few seconds of loading, all main memory is consumed 
> by the Python
> process and the computer starts swapping. After a few more 
> seconds, CPU
> usage drops from 99% to 1% and all swap memory is consumed:
> 
> Mem:386540k total,   380848k used, 4692k free,  
> 796k buffers
> Swap:   562232k total,   562232k used,0k free,
> 27416k cached
> 
> At this point, my computer becomes unusable.
> 
> I'd like to know if I should buy some more memory (a few GB?) 
> or if it is
> possible to make my code more memory efficient.

The first question I would ask is: what are you doing with "result", and
can the consumption of "result" be done iteratively?


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python on a public library computer

2005-05-17 Thread John J. Lee
"Anton Vredegoor" <[EMAIL PROTECTED]> writes:

> John J. Lee wrote:
> 
> > Why not Jython?
> 
> There's no command prompt! The file menu from IE is also gone. There is
> a sun Java console but it looks like this:
[...]

ISTR (maybe incorrectly) there's a Jython shell you can run in IE.


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


Re: pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are -1 supplied.

2005-05-17 Thread F. GEIGER
Arrgh, sorry for that post!

  self._dbc.execute(q, data)

where data is None, works with MySQL. For SQLite I have to write

  if data is not None:
 self._dbc.execute(q, data)
  else:
 self._dbc.execute(q)

Sorry again,
Franz GEIGER



"F. GEIGER" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> Im on Python 2.3.4, using pysqlite 2.0.0 (final).
>
> When I try to execute
>
> self._dbc.execute(q, data)
>
> where q is 'select count(*) from Difflets ' and date is None
>
> I get the following exception:
>
> pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied.
> The current statement uses 0, and there are -1 supplied.
>
> Any ideas?
>
> Many thanks in advance and kind regards
> Franz GEIGER
>
>
>


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


pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are -1 supplied.

2005-05-17 Thread F. GEIGER
Im on Python 2.3.4, using pysqlite 2.0.0 (final).

When I try to execute

self._dbc.execute(q, data)

where q is 'select count(*) from Difflets ' and date is None

I get the following exception:

pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied.
The current statement uses 0, and there are -1 supplied.

Any ideas?

Many thanks in advance and kind regards
Franz GEIGER



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


Re: reference counting and file objects

2005-05-17 Thread "Martin v. Löwis"
Paul Rubin wrote:
>>Consider the function above.  Do I need the fp.close(), or will the
>>file be closed automatically when fp goes out of scope and its
>>reference count drops to zero?
> 
> In CPython, fp gets closed when it leaves scope.

One issue is that when the function terminates through an exception,
the file stays open as long as the traceback is available, which
exists until the next exception is raised (and thus replaces this
traceback).

If the function terminates normally (i.e. through return), it is
as you say.

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


Re: reference counting and file objects

2005-05-17 Thread Paul Rubin
John Reese <[EMAIL PROTECTED]> writes:
> Consider the function above.  Do I need the fp.close(), or will the
> file be closed automatically when fp goes out of scope and its
> reference count drops to zero?

In CPython, fp gets closed when it leaves scope.  In other
implementations you may need try-finally.  There's been occasional
discussion of possible new Python control blocks to make this easier.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: query progress bar

2005-05-17 Thread Scott David Daniels
f wrote:
> Timothy Smith wrote:
> 
>> is it possible to mke a progress bar for queries? say i have a query 
>> that will take 20 seconds, i'd like to give some feed back to users on 
>> how long this will take.

> an activity widget, something moving (ie throbber in wxPython)
> while waiting for the result (like the rotating circle in firefox)
The one extra thing you might want to do, if your application gets
regular use, is show elapsed time.  The user will come to know how
long it should take, while your application probably won't get any
smarter.

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


reference counting and file objects

2005-05-17 Thread John Reese
def uselessHash(filename):
  fp= open(filename)
  hash= 0
  for line in fp:
hash ^= hash(line.strip())
  fp.close() # do I need this or is fp closed by ref count?
  return hash

Consider the function above.  Do I need the fp.close(), or will the
file be closed automatically when fp goes out of scope and its
reference count drops to zero?

If so, there's really no point in calling .close() in situations like
this where the function completes in a relatively short time,, and if
not, I should probably be using try-finally.  That's my thinking... or
the thinking of the coworker who was arguing with me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image.putpalette(Colors)?

2005-05-17 Thread Oliver Albrecht
Thanks,
I've read this page.( out of date ?)
http://www.pythonware.com/products/pil/articles/creating-palette-images.htm

Very nicely to become answered  from the major author and python genius
highly personally himself :-D

Which I want to do is; convert several "RGB" Images (or "P") with one
specified palette (to "P").
Or this (for "P")pattern; if the Source Image has the exact same colors but
wrong(other) paletteIds, how can i sort this? With List.sort()?
And give each pixel the right paletteId? That is what i mean with similar
image (source"RGB" to destinaton"P").

convert() without "WEB"?

(sry if i've enough experience with python)>=newbie



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


Re: os.popen vs os.system

2005-05-17 Thread rbt
Peter Hansen wrote:
> I don't think there's any significant difference between the above 
> (assuming you add in the missing quotation marks) and 
> os.system('shutdown -r -f'), except that the os.system() approach is 
> shorter and more readable if you are simply discarding or printing the 
> output like that.

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


using adodbapi - problem returning Values from Stored Procedure

2005-05-17 Thread Golawala, Moiz M (GE Infrastructure)
Hi All, 

I am having problem returning values from a Stored Procedure that creates a 
dynamic table (table variable) inserts values during a procedure and then I 
select from that dynamic table to furnish values to python.

This does not work
MY PYTHON CODE IS:

import adodbapi
connStrSQLServer = r"Provider=SQLOLEDB.1; User ID=sa; Password=tester; Initial 
Catalog=someDB;Data Source=someSource" 
db = adodbapi.connect(connStrSQLServer)
cursor = db.cursor()
 
sql = """test_procedure """

cursor.execute(sql)
results = cursor.fetchall()

MY TRANSACT SQL CODE IS:

ALTER  PROCEDURE dbo.test_procedure

AS
DECLARE @dynamicTable TABLE  (col1 int)
INSERT INTO @dynamicTable
VALUES (123)
SELECT * FROM @dynamicTable

THIS IS THE ERROR I GET

   results = cursor.fetchall()
  File "C:\Python23\Lib\site-packages\adodbapi\adodbapi.py", line 692, in fetch
ll
return self._fetch()
  File "C:\Python23\Lib\site-packages\adodbapi\adodbapi.py", line 623, in _fetc

self._raiseCursorError(Error,None)
  File "C:\Python23\Lib\site-packages\adodbapi\adodbapi.py", line 407, in _rais
CursorError
eh(self.conn,self,errorclass,errorvalue)
  File "C:\Python23\Lib\site-packages\adodbapi\adodbapi.py", line 38, in standa
dErrorHandler
raise errorclass(errorvalue)
Error: None
[]

This works
The python code is the same
The SQL Code is:

ALTER  PROCEDURE dbo.test_procedure

AS
INSERT INTO somePhysicalTable   
VALUES (123)
SELECT * FROM somePhysicalTable


Notice that the only difference between the 2 procedures is that in one case I 
am using a dynamic (table variable) table and in the other I am using an actual 
physical table. Does anyone have a clue why one works and the other does not.

Any help appreciated! Thanks in advance

Thanks,
Moiz Golawala
GE Infrastructure, Security
Software Engineer
Enterprise Solutions

T 561 912 5972
F 561 994 6572
E [EMAIL PROTECTED] 
www.gesecurity.com

791 Park of Commerce Blvd., Suite 100
Boca Raton, FL, 33487, U.S.A.
GE Security, Inc.

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


Re: os.popen vs os.system

2005-05-17 Thread rbt
Peter Hansen wrote:
> You can't be doing exactly that, since there are no sockets involved... 
> do you mean the above call is executed -- on the receiving end -- after 
> some signal is received via a socket in another part of the code? That's 
> not going to have any effect on things...

Here's the server portion:

from email.MIMEText import MIMEText
import email.Utils
import os
import smtplib
import socket
import sys
import time

def get_server_ip():
 server = socket.gethostbyname(socket.gethostname())
 return server

def set_server_port():
 ## Using "port = 0" will cause a random port to be chosen
 port = 0
 return port

def listen(ip_param, port_param):

 def send_params(ip_param, port_param):
 ## This function will send the network parameters.
 ## Change the to and from email addys.
 f = "XXX<[EMAIL PROTECTED]>"
 t = "[EMAIL PROTECTED]"
 msg = MIMEText("""Server IP: %s\nServer Port: %s""" 
%(ip_param,port_param))

 msg["Subject"] = "%s Listening" %socket.gethostname()
 msg["Message-id"] = email.Utils.make_msgid()
 msg["From"] = f
 msg["To"] = t

 h = "smtp.vt.edu"
 s = smtplib.SMTP(h)
 s.sendmail(f, t, msg.as_string())
 s.quit()

 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 try:
 s.bind((ip_param, port_param))
 except socket.error:
 sys.exit("IP & Port Already in use.")
 ip, port = s.getsockname()
 print "Server", ip, "is listening for connections on port", port
 send_params(ip, port)
 while 1:
 print "\nWaiting for new connection...\n"
 s.listen(1)
 conn, addr = s.accept()
 print "Client", addr[0], "connected and was directed to port", 
addr[1]
 data = conn.recv(1024)
 print "Client sent this message:", data
 if data == 'shutdown -r -f':
 print data
##restart = os.popen('shutdown -r -f')
##print restart.read()
##restart.close()
 elif data == 'shutdown -a':
 print data
##abort = os.popen('shutdown -a')
##abort.read()
##abort.close()
 else:
 print "No valid command received."
 conn.close()

# Start the Program

ip = get_server_ip()
port = set_server_port()

listen(ip, port)

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


Re: os.popen vs os.system

2005-05-17 Thread rbt
Peter Hansen wrote:
  > You can't be doing exactly that, since there are no sockets involved...
> do you mean the above call is executed -- on the receiving end -- after 
> some signal is received via a socket in another part of the code? That's 
> not going to have any effect on things...
> 

Here's the client portion:

import socket
import time

# Prompt user for host IP and port number.
host = raw_input("What IP: ")
port = raw_input("What port: ")

# Strip any whitespace and make sure port is an int.
host = str.strip(host)
port = str.strip(port)
port = int(port)

def msg():
msg = raw_input("Enter command to send to the server: ")
msg = str.strip(msg)
print "\nYou sent:", msg
return msg

def send(msg):
## Send the data to the server.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send(msg)
s.close()

send(msg())
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen vs os.system

2005-05-17 Thread F. Petitjean
Le Tue, 17 May 2005 13:50:08 -0400, rbt a écrit :
> Is it more appropriate to use os.popen or os.system on a windows XP 
> client?

Nope. use the subprocess module  :-)

Microsoft had the great idea to embed white space inside a lot of
directories (compare C:\Program Files\ to /usr/bin ) which means that
you must find the right way to quote the command line string of
os.system() and this quoting is very tricky and under-documented. A
nightmare to thousands of developers which has a cost of millions of
dollars :-(

Exercice for the reader : write a windows application which can only be
invoked from the command line (or from another program) not by clicking
on a cute icon. Extra bonus points if the path to this executable
contain (after Program Files) a company name with some characters hard
to type on some keyboards (or with some locales), if the executable name
has also difficult to type characters and if the case is checked
(windows file system is case preserving).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen vs os.system

2005-05-17 Thread Peter Hansen
rbt wrote:
> Is it more appropriate to use os.popen or os.system on a windows XP 
> client? I'm calling the operting system's shutdown function like this:
> 
> restart = os.popen(shutdown -r -f)
> print restart.read()
> restart.close()

I don't think there's any significant difference between the above 
(assuming you add in the missing quotation marks) and 
os.system('shutdown -r -f'), except that the os.system() approach is 
shorter and more readable if you are simply discarding or printing the 
output like that.

 > If it matters, I'm doing this remotely over sockets.

You can't be doing exactly that, since there are no sockets involved... 
do you mean the above call is executed -- on the receiving end -- after 
some signal is received via a socket in another part of the code? 
That's not going to have any effect on things...

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


Re: Windows distribution suggestions?

2005-05-17 Thread "Martin v. Löwis"
Paul Rubin wrote:
> My app contains three different programs (say alice.py, bob.py, and
> carol.py) that need to be independently launchable, and a dozen or so
> other .py files that get imported into those first three.  What I'd
> really really like is to make a single installer called (say)
> "app.exe".  Launching app.exe should completely install Python, unpack
> all the necessary modules, and make three icons (alice, bob, carol) on
> the desktop.

It's not clear to me whether you really want to install a full version
of Python on the target machine; py2exe and Co. incorporate the minimum
subset of Python and ship this each time you make a distribution. So
Python is not installed on the target machine on its own.

In principle, it is possible to create an installer that first installs
Python (with entries in the start menu and all), and then installs your
own application.

If this is what you want, I would personally go with .msi instead of
using .exe. It can do "nested installs", where you can launch
the standard python-2.4.msi from your own MSI file. It also supports
"patch updates", where you replace the files that have changed on
the target machine, through a patch MSI.

The tricky part is to find a good authoring tool for .msi. I would
personally use my own Python library, but that requires to dig
into the MSI details.

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


Re: OSx 10.4 lacks pythonIDE?

2005-05-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Robert Kern <[EMAIL PROTECTED]> wrote:

> I'm told Xcode does a tolerable job with Python.

I just took a look at Xcode and it's not obvious how to run a script.  I 
suspect I need a project?  Then run?  The docs say nothing that I can 
find.

Thanks.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OSx 10.4 lacks pythonIDE?

2005-05-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Robert Kern <[EMAIL PROTECTED]> wrote:

> You could learn to use vim or emacs, both of which come with Tiger. They 
> also have somewhat more Aqua-friendly GUI versions lurking around. I'm 
> partial to vim, myself.
> 
> PyOXIDE might be a good choice for you.
> http://homepage.mac.com/gandreas/Menu4.html
> 
> I'm told Xcode does a tolerable job with Python.
> 
> There are other IDEs floating around. Searching the PythonMac-SIG 
> mailing list archives should show you past discussions about them and 
> how well they work on OS X.

TextWrangler or BBEdit (it's bigger brother) can be used, too.  Both are 
nice GUI editors.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python forum

2005-05-17 Thread Paul McNett
Rocco Moretti wrote:
> Dave Brueck wrote:
> 
>>Grant Edwards wrote:
>>
>>>[In case you can't tell, I hate web forums.  I've never seen a
>>>single one with a suable UI.]
>>
>>Amen! Generally they are an abomination.
> 
> It may seem snobish, but my main gripe with most of the web-forums I've 
> seen is the people using them. There are far too many content-free "Me 
> too" posts, which are horribly difficult to filter out (due to the poor 
> UI). It's partly the web-forum's fault - the really bad ones have posts 
> with some cute/animated smiley as the sole content. It's rare that 
> usenet has such posts, because a colon and a right paren in text doesn't 
> seem nearly as interesting as some saccarine singing, dancing, yellow blob.

I think that web forums are great in one case: supporting nontechnical 
end users on the use and configuration of your product, in a 
free/community-based support arrangement. The forum needs a moderator to 
trim and condense as appropriate, and the help desk needs to monitor the 
forum and interface with the developers as necessary.

The benefits versus newsgroup/listserv in this case basically boil down to:
+ users already know how to use their web browser, but -let's be honest- 
it's a stretch to get them to subscribe to a list - you'd have to hold 
their hand through every step of the setup making it less costly to just 
offer free phone support for their issue.

But that's it. Otherwise, web forums just waste everyone's time.

So for a language like Python, where you presuppose that most people 
using the product are technically savvy enough to operate a newsreader 
or mail client, a web forum approach just isn't going to gain much 
popularity. Web forums for people that know how to use their computers 
are just a horrible waste of time, but perhaps more importantly people 
no longer have control over their environment and are forced to navigate 
a particular UI instead of being able to put together their own 
preferred approach.

-- 
pkm ~ http://paulmcnett.com

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


Adding "proxy" functions to a type

2005-05-17 Thread Iker Arizmendi
Hello all.

Is there a convenient scheme within a C extension to add
methods to a type in such a way as to allow me to
transparently add a "proxy" around them? For example:

 typedef PyObject* (*PyMethodCall)(PyObject*, PyObject*);

 PyObject* middleMan(PyObject* self, PyObject* args) {
 printf("Before call to wrapped funct\n");
 PyMethodCall actualFunc = getRealFunction(...);
 PyObject* retval = actualFunc(self, args);
 printf("After call to wrapped func\n");
 return retval;
 }

 void addMethod(PyTypeObject* t, PyMethodCall* m,
char* name, char* doc) {
 // code to forward calls to "middleMan" while putting the
 // pointer to "m" somewhere convenient
 ...
 }

My current solution is cumbersome and involves adding a
special field to the PyObject associated with my type, a
custom tp_getattro function and the "middleMan" function:

 struct MyPyObj {
 PyObject_HEAD
 PyMethodCall realfunc;
 };

 // when adding the method def for "m" instead of pointing it to
 // the given function, I point it to the middle man and save
 // the "m" function somewhere I can find it later.
 void addMethod(PyTypeObject* t, PyMethodCall m,
char* name, char* doc) {

 PyMethodDef* def = allocPyMethodDef(t, name);
 def->ml_name = name;
 def->ml_doc = doc;
 def->ml_meth = middleMan;
 def->ml_flags = METH_VARARGS;

 saveTargetFunction(name, m);
 // note I add these here so that documentation is
 // available within the interpreter
 PyObject* methobj = PyDescr_NewMethod(t, def);
 PyDict_SetItemString(t->tp_dict, def->ml_name, methobj);
 Py_DECREF(methobj);
 }

 // when the interpreter does a lookup on an instance of my
 // type I set the "realfunc" member of my PyObject and return
 // a bound method (which will call into middleMan).
 PyObject* customGetaAttro(PyObject* self, PyObject* name) {
 MyPyObj* rself = (MyPyObj*)self;
 rself->realfunc = findSavedTargetFunc(name);
 PyMethodDef* mdef = getMethodDef(self->ob_type, name);
 return PyCFunction_New(def, self);
 }

 // finally, when the middle man is called it extracts the "real"
 // function from self and calls that.
 PyObject* middleMan(PyObject* self, PyObject* args) {
 MyPyObj* rself = (MyPyObj*)(self);
 printf("pre call\n");
 PyObject* rv = rself->realfunc(rself->obj, args);
 printf("post call\n");
 rself->realfunc = 0;
 return rv;
 }

The problem here is that this doesn't work for static functions which
lack a self argument, or for module level functions.

Is there a better way?

Thanks,
Iker Arizmendi



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


os.popen vs os.system

2005-05-17 Thread rbt
Is it more appropriate to use os.popen or os.system on a windows XP 
client? I'm calling the operting system's shutdown function like this:

restart = os.popen(shutdown -r -f)
print restart.read()
restart.close()

If it matters, I'm doing this remotely over sockets.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python forum

2005-05-17 Thread Rocco Moretti
Dave Brueck wrote:
> Grant Edwards wrote:
> 
>>
>> Except for the torture of using a web forum's UI.
>>
>> [In case you can't tell, I hate web forums.  I've never seen a
>> single one with a suable UI.]
> 
> 
> Amen! Generally they are an abomination.
> 
> To make matters worse, many forums that become popular are saddled with 
> so many advertisements that moving from one message to another becomes 
> a... grueling... lesson... in... patience.

It may seem snobish, but my main gripe with most of the web-forums I've 
seen is the people using them. There are far too many content-free "Me 
too" posts, which are horribly difficult to filter out (due to the poor 
UI). It's partly the web-forum's fault - the really bad ones have posts 
with some cute/animated smiley as the sole content. It's rare that 
usenet has such posts, because a colon and a right paren in text doesn't 
seem nearly as interesting as some saccarine singing, dancing, yellow blob.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem listing services with wmi

2005-05-17 Thread Jean-Sébastien Guay
Hi again Tim,

>Well I honestly don't know if this will go any further,
>but the following code uses the win32service module from
>pywin32 to collect the service information, on the off-chance
>that it *won't* fail where WMI does. I can't easily test it
>since the script doesn't raise an error on my machine.
>  
>

Seems like your hunch was right, the first loop completes correctly. 
Adding a counter to both loops shows that getting services from 
win32service.EnumServicesStatus() gets 108 services, and getting them 
through WMI gets to 87 and then halts with the previously mentioned error :

Traceback (most recent call last):
  File "", line 1, in ?
  File "G:\Python-2.4\Lib\site-packages\win32com\client\util.py", line 
83, in next
return _get_good_object_(self._iter_.next())
pywintypes.com_error: (-2147217398, 'OLE error 0x8004100a', None, None)

 From examining your code I imagine you tried to catch the exception, 
but it didn't work because the exception is thrown on the "for" line and 
not when getting the service's Caption property... So it stopped at 87 
anyways. And indeed, the "only in win32" list shows 21 entries ( 
len(win32_names - wmi_names) = 108-87 = 21 ).

[...snip code...]

># Not sure if you're running 2.3/2.4
>  
>

Python 2.4 on Windows XP SP2 here.

Do you think we're getting anywhere with this? If not, then I'll just 
use the "win32" method of getting the service list, even though it isn't 
as pretty. I don't want to waste your time on something that may have 
more to do with my machine than anything else... But if you want to try 
and get to the bottom of this, I have no problem with trying out other 
suggestions.

Thanks a lot, just by your small scripts I've already learned a lot more 
about Python!

J-S

-- 
___
Jean-Sébastien Guay   [EMAIL PROTECTED]
 http://whitestar02.webhop.org/

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


Re: Quick Reference from module doc strings.

2005-05-17 Thread Michele Simionato
Ron Adam:

> Sound great!  Adding a command line parser, I'm going to add a brief
> command line parser to it today, but nothing as elaborate as you have
> already.  Could you post a part of the output as an example?  How is
the
> index built?

For the command line parser, see
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278844

Here is an example of output:

http://www.phyast.pitt.edu/~micheles/python/ms.html

(it is a package called "ms" (as "My Stuff") where I put my utilities).

The system works for module of the standard library too, but since
most of the time they do not have docstrings in reST format, there
are ugly formatting errors. But this is a bug of the standard library,
not of my tool ;)

For the index: "minidoc" associates a footnote number to every name,
and then
prints the names in alphabetical order. You can reach the documentation
for that name with a click.

   Michele Simionato

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


newbie running IDLE with command line arguments

2005-05-17 Thread crypto
Hi,

I am trying to use IDLE in order to test my program. My program is the
following:

import sys, socket
size = 1024
host, port, message = sys.argv[1], int(sys.argv[2]), sys.argv[3]
print host

How do I run this program on IDLE? I trying Run->Run Module but it
gives me:

Traceback (most recent call last):
  File "C:\Python24\userprograms\simpleclient.py", line 5, in
-toplevel-
host, port, message = sys.argv[1], int(sys.argv[2]), sys.argv[3]
IndexError: list index out of range

How do I enter the command arguments?

Thanks,
C29

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


Re: Type question

2005-05-17 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
> Hello,
>
> is this call assumed to be True in any case?
>
> result = type(SomeClass) is SomeClass
>
> I've written a proxy class which shadows a real object. If you call
> type(proxyobj) it returns the type of the proxyobject and not the
type
> of the shadowed object. Example:
>
> p = proxy(shadowobj())
> result1 = type(p) is shadowobj # will return False
> result2 = isinstance(p, shadowobj)   # will return True
>
> So the first call compares the id()s of both types, while the second
> calll seems to work different.
> I've tried to use a proxy metaclass that creates new objects with the
> name 'shadowobj'. So
>
> print type(p)
> print type(shadowobj())
>
> will look exactly the same.

isinstance is not a law. It's just a convention. You don't
actually need to implement it. Consider PEP 246, I believe,
it is the right way to do what you want to do.
isinstance and metaclasses are not.

Instead of writing
if not isinstance(obj, class):
report error

ask your users to write
obj = adapt(obj, Interface)

instead of dispatch code like
if isinstance(obj, thisclass):
do this
elif isinstance(obj, thatclass):
do that
else:
report error

ask the users to write:
if kind(obj) is ThisKind:
do this
elif kind(obj) is ThatKind:
do that
else:
report error

where kind can be defined as
def kind(obj):
return getattr(obj, 'kind', None)

  Serge.

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


Re: processing a Very Large file

2005-05-17 Thread Tim Peters
[DJTB]
> I'm trying to manually parse a dataset stored in a file. The data should be
> converted into Python objects.
>
> Here is an example of a single line of a (small) dataset:
> 
> 3 13 17 19 -626177023 -1688330994 -834622062 -409108332 297174549 955187488 
> 589884464 -1547848504 857311165 585616830 -749910209 194940864 -1102778558 
> -1282985276 -1220931512 792256075 -340699912 1496177106 1760327384 
> -1068195107 95705193 1286147818 -416474772 745439854 1932457456 -1266423822 
> -1150051085 1359928308 129778935 1235905400 532121853
> 
> The first integer specifies the length of a tuple object. In this case, the
> tuple has three element: (13, 17, 19)
> The other values (-626177023 to 532121853) are elements of a Set.
>
> I use the following code to process a file:
> 
> from time import time
> from sets import Set
> from string import split

Note that you don't use string.split later.

> file = 'pathtable_ht.dat'
> result = []
> start_time = time ()
> f=open(file,'r')
> for line in f:
>splitres = line.split()

Since they're all integers, may as well:

splitres = map(int, line.split())

here and skip repeated int() calls later.

>tuple_size = int(splitres[0])+1
>path_tuple = tuple(splitres[1:tuple_size])
>conflicts = Set(map(int,splitres[tuple_size:-1]))

Do you really mean to throw away the last value on the line?  That is,
why is the slice here [tuple_size:-1] rather than [tuple_size:]?

># do something with 'path_tuple' and 'conflicts'
># ... do some processing ...
>result.append(( path_tuple, conflicts))
>
> f.close()
> print time() - start_time
> 
> The elements (integer objects) in these Sets are being shared between the
> sets, in fact, there are as many distinct element as there are lines in the
> file (eg 1000 lines -> 1000 distinct set elements). AFAIK, the elements are
> stored only once and each Set contains a pointer to the actual object

Only "small" integers are stored uniquely; e.g., these aren't:

>>> 100 * 100 is 100 * 100
False
>>> int("12345") is int("12345")
False

You could manually do something akin to Python's "string interning" to
store ints uniquely, like:

int_table = {}
def uniqueint(i):
return int_table.setdefault(i, i)

Then, e.g.,

>>> uniqueint(100 * 100) is uniqueint(100 * 100) 
True
>>> uniqueint(int("12345")) is uniqueint(int("12345"))
True

Doing Set(map(uniqueint, etc)) would then feed truly shared int
(and/or long) objects to the Set constructor.

> This works fine with relatively small datasets, but it doesn't work at all
> with large datasets (4500 lines, 45000 chars per line).

Well, chars/line doesn't mean anything to us.  Knowing # of set
elements/line might help.  Say there are 4500 per line.  Then you've
got about 20 million integers.  That will consume at least several 100
MB if you don't work to share duplicates.  But if you do so work, it
should cut the memory burden by a factor of thousands.

> After a few seconds of loading, all main memory is consumed by the Python
> process and the computer starts swapping. After a few more seconds, CPU
> usage drops from 99% to 1% and all swap memory is consumed:
>
> Mem:386540k total,   380848k used, 4692k free,  796k buffers
> Swap:   562232k total,   562232k used,0k free,27416k cached
>
> At this point, my computer becomes unusable.
>
> I'd like to know if I should buy some more memory (a few GB?) or if it is
> possible to make my code more memory efficient.

See above for the latter.  If you have a 32-bit processor, you won't
be able to _address_ more than a few GB anyway.  Still, 384MB of RAM
is on the light side these days .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-17 Thread Nyet Ya Koshka
> One reasonable solution might be as follows:
>
>   def unique_elts(seq):
> elts = {}
> for pos, elt in enumerate(seq):
>   elts.setdefault(elt, []).append(pos)
>
> return [ (x, p[0]) for (x, p) in elts.iteritems()
>  if len(p) == 1 ]
>

Minor tweak to conserve space:

def bachelor_filter(iter_over_hashables):
   B={}
   for index, elem in enumerate(iter_over_hashables):
  if B.setdefault(elem, index) != index:
 B[elem]=None
   return [pair for pair in B.items() if pair[1] is not None]

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


RE: Problem listing services with wmi

2005-05-17 Thread Tim Golden
[... snip results ...]

| So it would seem that the 3 methods give the same result. As to which 
| service it has gotten to when it gets to position 88 in the list, 
| obviously I can't find out with a script, and it seems that the list 
| isn't in any order I can see, so I couldn't even venture a 
| guess... I'll 
| try looking if there's a service in my list that isn't valid 
| (points to 
| an uninstalled program for example) or something like that... 
| But if you 
| have other ideas please let me know.

Well I honestly don't know if this will go any further,
but the following code uses the win32service module from
pywin32 to collect the service information, on the off-chance
that it *won't* fail where WMI does. I can't easily test it
since the script doesn't raise an error on my machine.

At the end, it tries to print out the differences between
the win32-collected info and the wmi-collected info.



#
# Not sure if you're running 2.3/2.4
#
try:
  set
except NameError:
  from sets import Set as set

##
## Taken from a post to c.l.py by William J. Rice
##
import win32service
import win32con

accessSCM = win32con.GENERIC_READ
hscm = win32service.OpenSCManager (None, None, accessSCM)

win32_names = set ()

for service_info in win32service.EnumServicesStatus(hscm):
  win32_names.add (service_info[1])

import win32com.client

c = win32com.client.GetObject (
  
"winmgmts:{impersonationLevel=Impersonate,authenticationLevel=Default}/root/cimv2"
)

wmi_names = set ()
for service in c.ExecQuery ("SELECT * FROM Win32_Service"):
  try:
short_name = service.Properties_ ("Caption").Value
  except:
pass
  else:
wmi_names.add (short_name)

print "only in win32:", ", ".join (win32_names - wmi_names)
print

print "only in wmi:", ", ".join (wmi_names - win32_names)
print



Let me know if anything shows up.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Quick Reference from module doc strings.

2005-05-17 Thread Ron Adam
Michele Simionato wrote:
>>Do you have any feature suggestions, additional information that
> 
> could
> 
>>go in, something that would extend the content in some way and make
> 
> it
> 
>>more useful?
> 
> 
> I have written something similar which I use all the time. It generates
> ReST
> output which I can browse with "less" from the command line, as well as
> HTML
> output and PDF output that I can print. The hard work is done by
> docutils, of course.
> I have options to specify if I want to least private names or not, and
> to specify
> if I want an analytical index to be generated or not. Also, the HTML
> output
> contains hyperlinks to the original source code, so I can see  it with
> a click.
> I can feed to "minidoc" whole packages (it works recursively on
> subpackages, so everything is documented).
> 
> It was unvaluable in my struggle with Zope.
> 
> Michele Simionato
> 

Hi Michele,

Sound great!  Adding a command line parser, I'm going to add a brief 
command line parser to it today, but nothing as elaborate as you have 
already.  Could you post a part of the output as an example?  How is the 
index built?

The direction I'm going is to build a database/dictionary with each 
individual item as a record. Maybe feed it the whole lib directory, then 
to be able to generate cross module/package lists by subject or keyword. 
  I'm not exactly sure how to connect everything together yet.  This is 
a figure it out as I go project, but I think it's worth trying.

Cheers,
_Ron





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


Type question

2005-05-17 Thread nitrogenycs
Hello,

is this call assumed to be True in any case?

result = type(SomeClass) is SomeClass

I've written a proxy class which shadows a real object. If you call
type(proxyobj) it returns the type of the proxyobject and not the type
of the shadowed object. Example:

p = proxy(shadowobj())
result1 = type(p) is shadowobj # will return False
result2 = isinstance(p, shadowobj)   # will return True

So the first call compares the id()s of both types, while the second
calll seems to work different.
I've tried to use a proxy metaclass that creates new objects with the
name 'shadowobj'. So

print type(p)
print type(shadowobj())

will look exactly the same. however their id()s compare different and
that's why the 1st test doesn't work as I'd expect it to work.
Can somebody tell me why the id()s compare different for the same type
names? Here's the metaclass:

class ProxyMeta(type):
def __new__(self, classname, bases, classdict):
return type.__new__(self, 'shadowobj', bases, classdict)

class Proxy(object):
__metaclass__ = ProxyMeta

Why is (type(Proxy) is shadowobj == False)? Shouldn't type.__new__
reuse the existing shadowobj type and increase its refcount instead of
creating a new instance of it? Then the id()s would compare the same.
So, finally, is checking for types with 'is' as shown above just wrong
and one should use isinstance or is my proxy class showing bad
behaviour or is this a bug in type.__new__?

-Matthias

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


processing a Very Large file

2005-05-17 Thread DJTB
Hi,

I'm trying to manually parse a dataset stored in a file. The data should be
converted into Python objects.

Here is an example of a single line of a (small) dataset:

3 13 17 19 -626177023 -1688330994 -834622062 -409108332 297174549 955187488
589884464 -1547848504 857311165 585616830 -749910209 194940864 -1102778558
-1282985276 -1220931512 792256075 -340699912 1496177106 1760327384
-1068195107 95705193 1286147818 -416474772 745439854 1932457456 -1266423822
-1150051085 1359928308 129778935 1235905400 532121853

The first integer specifies the length of a tuple object. In this case, the
tuple has three element: (13, 17, 19)
The other values (-626177023 to 532121853) are elements of a Set.

I use the following code to process a file:


from time import time
from sets import Set
from string import split
file = 'pathtable_ht.dat'
result = []
start_time = time ()
f=open(file,'r')
for line in f:
splitres = line.split()
tuple_size = int(splitres[0])+1
path_tuple = tuple(splitres[1:tuple_size])
conflicts = Set(map(int,splitres[tuple_size:-1]))
# do something with 'path_tuple' and 'conflicts'
# ... do some processing ...
result.append(( path_tuple, conflicts))

f.close()
print time() - start_time


The elements (integer objects) in these Sets are being shared between the
sets, in fact, there are as many distinct element as there are lines in the
file (eg 1000 lines -> 1000 distinct set elements). AFAIK, the elements are
stored only once and each Set contains a pointer to the actual object

This works fine with relatively small datasets, but it doesn't work at all
with large datasets (4500 lines, 45000 chars per line).

After a few seconds of loading, all main memory is consumed by the Python
process and the computer starts swapping. After a few more seconds, CPU
usage drops from 99% to 1% and all swap memory is consumed:

Mem:386540k total,   380848k used, 4692k free,  796k buffers
Swap:   562232k total,   562232k used,0k free,27416k cached

At this point, my computer becomes unusable.

I'd like to know if I should buy some more memory (a few GB?) or if it is
possible to make my code more memory efficient.

Thanks in advance,
Stan.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python forum

2005-05-17 Thread Dave Brueck
Grant Edwards wrote:
> On 2005-05-17, Jonas Melian <[EMAIL PROTECTED]> wrote:
>>I'm going to say a suggestion, why don't you create a forum
>>like the one of Ruby (http://www.rubyforums.com/)? for the
>>novices this is a great help, better than a mail list
[snip]
>>But I think that a forum is great for the learning. The test
>>is in gentoo's forums. They are a lot of experienced people
>>answering questions without any problem and it goes very well
> 
> 
> Except for the torture of using a web forum's UI.
> 
> [In case you can't tell, I hate web forums.  I've never seen a
> single one with a suable UI.]

Amen! Generally they are an abomination.

To make matters worse, many forums that become popular are saddled with so many 
advertisements that moving from one message to another becomes a... grueling... 
lesson... in... patience.

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


Re: Reading image dimensions with PIL

2005-05-17 Thread Dave Brueck
Will McGugan wrote:
> I'm writing an app that downloads images. It rejects images that are 
> under a certain size - whithout downloading them completely. I've 
> implemented this using PIL, by downloading the first K and trying to 
> create a PIL image with it. PIL raises an exception because the file is 
> incomplete, but the image object is initialised with the image 
> dimensions, which is what I need. It actualy works well enough, but I'm 
> concerened about side-effects - since it seems an unconventional way of 
> working with PIL. Can anyone see any problems with doing this? Or a 
> better method?

If you're tossing images that are too _small_, is there any benefit to not 
downloading the whole image, checking it, and then throwing it away?

Checking just the first 1K probably won't save you too much time unless you're 
over a modem. Are you using a byte-range HTTP request to pull down the images 
or 
just a normal GET (via e.g. urllib)? If you're not using a byte-range request, 
then all of the data is already on its way so maybe you could go ahead and get 
it all.

But hey, if your current approach works... :) It _is_ a bit unconventional, so 
to reduce the risk you could test it on a decent mix of image types (normal 
JPEG, progressive JPEG, normal & progressive GIF, png, etc.) - just to make 
sure 
  PIL is able to handle partial data for all different types you might 
encounter.

Also, if PIL can't handle the partial data, can you reliably detect that 
scenario? If so, you could detect that case and use the 
download-it-all-and-check approach as a failsafe.

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


Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-17 Thread Philippe C. Martin
I will look at that merge/unmerge thing


Peter Otten wrote:

>> Philippe C. Martin wrote:
>> 
>>> I'm looking for an easy algorithm - maybe Python can help:
>>> I start with X lists which intial sort is based on list #1.
>>> I want to reverse sort list #1 and have all other lists sorted
>>> accordingly.
> 
> One way, using a helper list with indices:
> 
 l1 = ['a','b','c']
 l2 = ['toto','titi','tata'] # 'toto' refers to 'a', 'titi' to b' 
 l3 = ['foo','bar','doe'] # 'foo' refers to 'a' 
 indices = sorted(range(len(l1)), key=l1.__getitem__, reverse=True)
 for items in l1, l2, l3:
> ... items[:] = [items[i] for i in indices]
> ...
 l1
> ['c', 'b', 'a']
 l2
> ['tata', 'titi', 'toto']
 l3
> ['doe', 'bar', 'foo']
> 
> Another way would be to merge the three lists into one of 3-tuples, sort,
> and unmerge, similarly to the DSU pattern -- which raises the question:
> why are you using three lists in the first place?
> 
> Peter

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


Re: Problem listing services with wmi

2005-05-17 Thread Jean-Sébastien Guay
Hello Tim, thanks for replying,

>For your
>information, what the code is doing behind the scenes is the following:
>
>
>
>import win32com.client
>
>c = win32com.client.GetObject (
>  
> "winmgmts:{impersonationLevel=Impersonate,authenticationLevel=Default}/root/cimv2"
>)
>for service in c.ExecQuery ("SELECT * FROM Win32_Service"):
>  if service.Properties_ ("State").Value == "Stopped":
>print service.Properties_ ("Caption").Value
>print service.Properties_ ("State").Value
>
>
>  
>

Running this code seems to go through the 87 first services in the list 
returned by ExecQuery, then stops with the following error :

Traceback (most recent call last):
  File "", line 1, in ?
  File "G:\Python-2.4\Lib\site-packages\win32com\client\util.py", line 
83, in next
return _get_good_object_(self._iter_.next())
pywintypes.com_error: (-2147217398, 'OLE error 0x8004100a', None, None)

Could there be such a thing as a "null pointer" in the list at position 
88? Or is that not possible in Python? Would the iterator just stop at a 
null value? As I said, I'm pretty new to Python so I'm just throwing 
around ideas here.

>
>
>set wmi = GetObject ("winmgmts:{impersonationLevel=impersonate}")
>set ServiceSet = wmi.InstancesOf ("Win32_Service")
>for each Service in ServiceSet
>   WScript.Echo Service.Description
>Next
>
>
>  
>

This gives me the first 87 services as well, and then stops with this 
message :

C:\Documents and Settings\guayj\Desktop\bob.vbs(7, 1) (null): 0x8004100A

So it would seem that the 3 methods give the same result. As to which 
service it has gotten to when it gets to position 88 in the list, 
obviously I can't find out with a script, and it seems that the list 
isn't in any order I can see, so I couldn't even venture a guess... I'll 
try looking if there's a service in my list that isn't valid (points to 
an uninstalled program for example) or something like that... But if you 
have other ideas please let me know.

>PS I realise that by now you've probably moved on from
>this approach, but if you did manage to pin down a problem
>we could address, I'd be very glad to address it.
>  
>

Not at all, this is a small project I'm using to try and learn Python... 
I'm currently on summer break before I start my Masters, so I have the 
luxury of keeping this on the back burner until I find a fix... Thanks 
for your help!

J-S

-- 
___
Jean-Sébastien Guay   [EMAIL PROTECTED]
 http://whitestar02.webhop.org/

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


Re: Python forum

2005-05-17 Thread Grant Edwards
On 2005-05-17, Jonas Melian <[EMAIL PROTECTED]> wrote:

> I'm going to say a suggestion, why don't you create a forum
> like the one of Ruby (http://www.rubyforums.com/)? for the
> novices this is a great help, better than a mail list

Says you.  I prever a newsgroup.  Mailing lists are in second
place and web forums a very distant third.  I really don't see
how pointing Mozilla or Thunderbird at a newsgroup isn't any
harder than pointing it at a web forum.

> I know that you have python-list, it's both an email and a usenet list.

And both are far better than web forums.

> But I think that a forum is great for the learning. The test
> is in gentoo's forums. They are a lot of experienced people
> answering questions without any problem and it goes very well

Except for the torture of using a web forum's UI.

[In case you can't tell, I hate web forums.  I've never seen a
single one with a suable UI.]

-- 
Grant Edwards   grante Yow!  .. My vaseline is
  at   RUNNING...
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Reading image dimensions with PIL

2005-05-17 Thread Will McGugan
Hi,

I'm writing an app that downloads images. It rejects images that are 
under a certain size - whithout downloading them completely. I've 
implemented this using PIL, by downloading the first K and trying to 
create a PIL image with it. PIL raises an exception because the file is 
incomplete, but the image object is initialised with the image 
dimensions, which is what I need. It actualy works well enough, but I'm 
concerened about side-effects - since it seems an unconventional way of 
working with PIL. Can anyone see any problems with doing this? Or a 
better method?


Thanks,

Will McGugan


-- 
http://www.willmcgugan.com
"".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-84)%26) for c 
in "jvyy*jvyyzpthtna^pbz" ] )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bug in Elementtree/Expat

2005-05-17 Thread alainpoint

Fredrik Lundh wrote:
>
> adding
>
> xmlns:xlink="http://www.w3.org/1999/xlink";
>
> to the "svg" element should make the problem go away.


Thanks for the tip. It indeed solves the problem.
Most examples in the book do not include such a declaration and yet are
properly rendered by Internet Explorer.
Is it mandatory and why is it that Expat crashes on it?

Alain

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


Re: Design Question. Data Acquisition/Display related.

2005-05-17 Thread Alex Verstraeten
StepH wrote:

>>a simple loop could do it
>> - handle user events
>> - collect data
>> - update displays
>> - sleep
>>
>>
>Here i've a prob. (due to the fact that I start both with Python & 
>TkInter).  In TkInter, you run your app by launching a mainloop() 
>routine, right ?  So, how, in my forever loop (handle user events / 
>Collect data / Update Display / Sleep) handle the user data ?
>
>Sure, i can (i suppose), log user activity (via the event send by the Tk 
>underlayer), the "poll" theses event in my for ever loop ?  But in this 
>case, are these event will be correctly generated (by Tk) ?  How to 
>"give the hand" to Tk in such scenario ?
>
>Thanks for your help.
>
>StepH.
>  
>
oops, sorry, I was thinking of a 'pygame' kind of loop, where you have 
control over it.
I dont have experience on Tk, I allways use wxPython or pygame for gui's.

you can forget about the loop I mentioned... it doesn't apply to 
event-driven applications where you have no control over the loop.
you'd be using a timer that triggers a tick method at a certain 
interval, in that tick method you could tell your data collectors to 
collect data... then the data collectors would trigger all its 
subscribed displays's "update" function, so they draw the new available 
data, just like the "for display in self.subscribed_displays: 
display.update(data)".

so it comes to something like this:

tk mainloop is set to call tick() every 100ms through a timer.
tick() will iterate through all data collectors and call their "collect" 
method
each data collector will then collect data  and iterate through all 
asociated displays calling their respective 'update' method on each.

of course there are plenty of ways to design an app, this is just an idea.

hope it helps,
Alex











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


Re: Windows distribution suggestions?

2005-05-17 Thread Grant Edwards
On 2005-05-17, Paul Rubin  wrote:

> As what must be penance for something or other, I'm needing to release
> a Python app for use under Windows XP. 

I'm a Unix guy who occasionally ships a Python app for Win32,
and I always recommend py2exe and inno setup:

  py2exe   http://starship.python.net/crew/theller/py2exe/
  inno setup   http://www.jrsoftware.org/isinfo.php

Inno setup is as good as any other installer, and it's free.
  
-- 
Grant Edwards   grante Yow!  Did I SELL OUT yet??
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >