Announcement: PyMatrix-0.0.1a Released

2005-03-09 Thread Colin J. Williams
PyMatrix is a package to provide access to the functionality of matrix 
algebra.

This package is currently based on numarray.  It includes a statistics 
module which includes a basic analysis of variance.

In the future it is hoped to enhance the generality of the divide 
operation, to add the transcendental functions as methods of the matrix 
class and to improve the documentation.  The expectation is that 
Numeric3 will eventually replace numarray and that this will necessitate 
some changes to PyMatrix

Downloads in the form of a Windows Installer (Inno) and a zip file are 
available at:

   http://www3.sympatico.ca/cjw/PyMatrix
An /Introduction to PyMatrix/ is available:
   http://www3.sympatico.ca/cjw/PyMatrix/IntroToPyMatrix.pdf
Information on the functions and methods of the matrix module is given at:
   http://www3.sympatico.ca/cjw/PyMatrix/Doc/matrix-summary.html
Colin W.
--
http://mail.python.org/mailman/listinfo/python-announce-list
   Support the Python Software Foundation:
   http://www.python.org/psf/donations.html


Reminder: Sydney Python Meetup - March 10

2005-03-09 Thread Alan Green
The Sydney Python Meetup is on again tomorrow, Thursday March 10, at 
6:30pm. The topic is web application frameworks, and we are covering 
four different approaches to building web applications in Python.

What:  Sydney Python Meetup
   Web Application Frameworks
Speakers:
   Casey Whitelaw speaking on CGI
   Mark Rees on WSGI
   Andy Todd on Quixote
   Yours Truly on CherryPy
When:  6:30pm, presentations commencing at 7:00pm
   Thursday, March 10
Where: James Squire Brewhouse
   22 The Promenade King St Wharf
   Sydney, NSW
The presentations will begin at 7:00 and finish at 8:00. Feel free to 
stay and discuss the relative merits of those frameworks and other 
Pythonic topics.

Meals, snacks and drinks are available from the bar.
Further details and RSVP at: http://python.meetup.com/96/events/4239674/
--
Alan Green ([EMAIL PROTECTED])
Cirrus Technologies Pty. Ltd.
http://www.cirrustech.com.au
+61 2 9299 3544 (w)   +61 2 9299 5950 (f)
--
http://mail.python.org/mailman/listinfo/python-announce-list
   Support the Python Software Foundation:
   http://www.python.org/psf/donations.html


BayPIGgies: March 10, 7:30pm (FINAL MEETING AT STANFORD)

2005-03-09 Thread Aahz
WARNING: the last meeting of BayPIGgies at Stanford is currently
scheduled for March.  Our host, Danny Yoo, is leaving Stanford, and we
need to find a new location.  If you wish to assist with the search,
please join the BayPIGgies mailing list.

Meanwhile, let's all give hearty thanks to Danny for helping us find a
stable meeting location for so long!


The next meeting of BayPIGgies will be Thurs, March 10 at 7:30pm.

Donovan Preston will lead a discussion about using Python with OS X,
including integrating with PyObjC and GNUStep.

BayPIGgies meetings are in Stanford, California.  For more information
and directions, see http://www.baypiggies.net/


Before the meeting, we may meet at 6pm for dinner in downtown Palo Alto.
Discussion of dinner plans is handled on the BayPIGgies mailing list.


Advance notice: The April 14 meeting agenda has not been set.  Please
send e-mail to [EMAIL PROTECTED] if you want to suggest an
agenda -- and a meeting place!
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death.  --GvR
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Mysterious Attribute Errors when GUI Programming

2005-03-09 Thread Coral Snake
Again Thanks to everyone here. Both the GTK and the Tkinter example are
running fine now.

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


Re: Best way to make a list unique?

2005-03-09 Thread Michael Hoffman
Delaney, Timothy C (Timothy) wrote:
I've proposed this on python-dev, but the general feeling so far is
against it. So far the only use case is to remove duplicates without
changing order, and there are iterator-based solutions which would
normally be preferable.
I've needed a dict that would iterate in a specific order many a time.
Usually I just make a list that contains the keys and iterate over that
instead of dict.keys().
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to script DOS app that doesn't use stdout

2005-03-09 Thread Gregor
Timothy Grant [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 On Sun, 06 Mar 2005 13:41:57 GMT, Gregor [EMAIL PROTECTED]
 wrote: 
 There's a DOS console application I am trying to script (in Python),
 but it doesn't seem to use stdout or stderr... For example, if I
 redirect output to a file (cmd  file.txt), the output still
 appears on screen. Similarly, the output pipes returned by popen*
 don't catch the app's output. How might this app be generating its
 output? Any thoughts on how it could be captured (perhaps with
 something in the win32 extensions)? 
 
 Thanks,
 
 Greg.
 
 I've had to do this a couple of times but never in recent years. I
 don't know your exact needs, but the best tool I ever found for this
 sort of job was called Phantom of the Keyboard.
 
 I ran into a couple of apps that I needed data out of and couldn't get
 it. They'd only output to screen, never to disk. I used Phantom to
 automate the app to dump data to screen and then capture the screen to
 disk.
 

Hmmm, interesting. I'll give that app a try. Thanks for the info.

Greg.

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


Re: How to upgrade python on Redhat?

2005-03-09 Thread David Fraser
[EMAIL PROTECTED] wrote:
This question applies specifically to RHEL 3.0 (actually Whitebox), but
also generally to Redhat and probably pretty much every distribution
that uses python for distribution-related tasks (configuration
managers, rpm package management, yum, etc).
So I want to upgrade to python 2.4 on Whitebox 3.0. Ideally I would
like python to live in /usr/bin and replace the python 2.2 that ships
with RHEL entirely. This gets pretty infeasable when you consider how
many packages depend on python 2.2:
cd /usr/lib/python2.2/site-packages
rpm -qf * | sort | uniq
alchemist-1.0.27-1
authconfig-4.3.7-1
ethereal-0.10.3-0.30E.1
file Ft is not owned by any package
file _xmlplus is not owned by any package
kudzu-1.1.22.2-1
libuser-0.51.7-1
libxml2-python-2.5.10-6
mod_python-3.0.3-3.ent
newt-0.51.5-1
parted-1.6.3-29
pygtk2-1.99.16-8
pyOpenSSL-0.5.1-8
pyorbit-1.99.3-5
python-2.2.3-5
python-optik-1.4.1-2
pyxf86config-0.3.5-1
redhat-config-printer-gui-0.6.47.3.19-1
rhnlib-1.5-1.1.WB1
rhpl-0.110.4-1
rpm-python-4.2.2-0.14.WB1
up2date-4.3.19-1.WB1
As best I can tell, I have 2 options:
1) Install python 2.4 from source over /usr/bin/python. Rebuild *all*
of the packages listed above from srpms and reinstall them.
2) Give up and install python 2.4 in /usr/local. This leaves me in the
awkward situation of having to ensure that all our in-house scripts,
all the time use /usr/local/bin/python.
I don't suppose there is a simple, rpm package based approach to fixing
this?
The solution is found on the download page, basically you get the 
python2.4 rpm and install it alongside your existing python, and run 
your in-house scripts with /usr/bin/env python2.4:

# Q) Is it safe to install these RPMs on a Red Hat system? Will they 
over-write the system python and cause problems with other Red Hat 
applications that expect a different version of Python?
# A) The RPMs that start with python2.4 are built to not interfere 
with the system Python. They install as /usr/bin/python2.4 and will 
not conflict with the system Python unless you are running on a system 
that ships the a version of Python which has the same major/minor number.

To invoke the interpreter with these packages, you will explicitly have 
to run python2.4. Note that all Python RPMs provided by Python.org and 
Red Hat provide a /usr/bin/python2.4 (or similar, with major/minor 
number), even if they also provide /usr/bin/python. So, yes, it should 
be safe.

Note that you may need to build and install a second copy of any 
packages which you need access to with the supplemental version of 
Python. You can build packages of these files for the Python 2.4 
interpreters for packages which use Distutils, by using the command 
python2.4 setup.py bdist_rpm.
--
http://mail.python.org/mailman/listinfo/python-list


Re: mod_python please recompile it with -DEAPI apache warning

2005-03-09 Thread [EMAIL PROTECTED]
In article [EMAIL PROTECTED], 
[EMAIL PROTECTED] says...
 [EMAIL PROTECTED] wrote:
  2) added to MakeFile after config:
  EXTRA_CFLAGS=-DEAPI
 
 You can do this, but it should be to src/Makefile and added
 to CFLAGS and not EXTRA_CFLAGS as the latter doesn't exist.
 
 

Thanks I forgot to say I already tried just plain CFLAGS like:
CFLAGS=-DEAPI

..but that still doesn't work. 

Here's what I did: 
make clean
./configure --with-apxs=/www/bin/apxs 
vi MakeFile
added CFLAGS=-DEAPI to MakeFile
make
make install
/etc/init.d/apachectl configtest

..and that still returns:

[Wed Mar  9 00:35:27 2005] [warn] Loaded DSO libexec/mod_python.so uses 
plain Apache 1.3 API, this module might crash under EAPI! (please 
recompile it with -DEAPI)

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


Re: looking for way to include many times some .py code from anotherpython code

2005-03-09 Thread Martin MOKREJ
Steve Holden wrote:
Martin MOKREJ wrote:
Steve Holden wrote:
[...]
I will be *very* surprised if you can't get a much better (i.e. 
easier and more efficient) solution by stepping back from the 
programming 

Hmm, I'm not convinced, but I'll put few more words here then. ;)
details for a moment and explaining what it is you are actually 
trying to achieve in user-space.

Can you describe the problem you are trying to solve, rather than the 
solution you are hoping to adopt?

User inputs data through html forms, data has to be quality-checked
and strored into mysql. Later, data is read from mysql and presented
through web. There's nothing special in it, just that the tables
describe a lot of specific experimental parameters. Tables do reflect
type of informations, so they group the data into logical units - so
tablename reflects the data contained.
In general, there are two types of data, hence my X and Y objects.
The underlaying data at some time point go into sql tables. Before that
happens, the data == variable contents are checked that they contain
expected values (in some cases enumerated values, in some cases integers,
sometime chars and only about 6 blobs). I spent a year developing the
database schema and php code, the schema is nearly optimal. I got bored
by the php code, as it was partly developed by a lazy guy (lazier than 
I'm).
I went fot python - to have better error handling, have not only web app,
but reusable code for standalone application (html forms can be replaced
by any tcl/tk widget for M$ Windows). Sql transaction I have added to
the php code, but anyway it sucks to work with it further.

My idea is to check some of the values while instantiating, as I get 
it for
free (assigning either to a default value or raising an exception when
variable is empty). In most cases this is not enough, and I have to 
type in
the allowed values.
1. In case of enumerated types, I hope to find a tool
able to read sql files and able to extract column definitions. In this
particular case, the program would dynamically read allowed ENUM values,
so whenever sql table is altered, the program will recognize new value
allowed.
2. In most other cases, the values are simply some kind of string, and
.find() et al. will suffice.
3. In case data was read from mysql, I can verify that foreign keys refer
to what they should refer.

OK, I get the data written to mysql. I can fetch it back, and want to 
dump
it into xml and present on web/(local gui).

I have the claases corresponding to all tables as superclasses of X and Y
as necessary. I went to ask on this list how to assign the variables 
easily
because parts of the code are almost identical. I believe this has been
answered quite well.

I believe the approach using classes corresponding to every single table
is right, when using them as superclasses for those two, practically
used objects: X and Y.
To print the output on web or any gui, I think I'll use the xml output
and just parse it. I need xml anyway for testing, and definitely want
to be able to construct the html/GUI output from the xml input - again,
for testing. So the objects will more or less exist only to get the
necessary checks done for those myriads of variables, which must be
evaluated in current context. I'd get crazy if I'd store things into
bsbdb -- I'm not going to remember that a[0] is table1, a[1] is table2,
a[0][0] is the primary key called blah, a[0][22] is allowed to be 
equal only to foo or bar ... and that if a[2][4] is defined 
(actually number),
the number is the key to search in c[key]. Simply, that's for what I 
use mysql
I don't want to invent the database schema in bsddb in python. ;)
It's simply data, it must be read into variables in some objects, those
object are groupped into just two superobjects. The superobjects define
check-methods, define how to dump the it's data into xml, how
to write (in which order) the values into mysql.

I'm sorry not to send in the sql schema + the code, but this is my phd 
thesis. ;)

I'm very glad there's so many people interrested to help - not only - me.
Thanks! Now I'm really looking forward how would you rework this thing.
It's simple, easy, it's just sometime tedious as having 250 columns in 
20 tables
simply makes you bored to type the code, after while.

The only think where I think I need help is, how to dump easily into 
xml say object
X, having variables a, b, c, where c is a ref. to object B, containing 
variables p, q, r.

B = obj()
setattr(B, p, 44)
setattr(B, q, sdjahd)
setattr(B, r, qew)
X = obj()
setattr(X, a, 1)
setattr(X, a, 2)
setattr(X, a, B)


print do_magick(X)

X
   a1/a
   b2/b
   B
   p44/p
   qsdjahd/q
   rqew/r
   /B
/X


I still don't really see why you have to store this thing as objects, 
but I appreciate that you can only give limited information and still 
retain the validity of a thesis.
The project is not published yet. When it is, I'll make it free. I'm a 
biologist,
and most biologists care only 

Re: running a C program with python script

2005-03-09 Thread Michael Hoffman
James Stroud wrote:
module os
the os.popen* commands.
The subprocess module in Python 2.4 is generally a better and easier
way to do this.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: firefox python plugin

2005-03-09 Thread Thomas Ganss
M.N.A.Smadi schrieb:
hi;
i want to write a script to do the following:
when using firefox to download a textfile, instead of saving it to the 
hard dist, i want to run a python script on it, and i want the python 
script then to prompt me for the location where i want to store the 
processed downloaded file
clientside processing could either be done in javascript (possibly 
disabled on some machines g) or in jython running as an applet.
Storing processed data could be considered quite dangerous BG. You 
have to consider security settings / sandbox approaches here.

Unless it is a specific issue for most use cases creating the processed 
file on the server and offering a link to download would be a better 
solution...

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


Re: running a C program with python script

2005-03-09 Thread Thomas Ganss
M.N.A.Smadi schrieb:
hi;
how can i do the following:
1- run a C program from a python script
2- pass that C program an argument
3- Read the out of the program into a buffer that is local to the script
thanks
m.smadi
in addition to the other approaches:
if you want only a few specific lines of c you can inline the code.
google for scipy, weave, inline and python
HTH
thomas
--
http://mail.python.org/mailman/listinfo/python-list


[CherryPy]Serve dynamic binary file in cherrypy?

2005-03-09 Thread mep
Hi,
After lookup in cherrypy site and google for a while, I haven't
found any information about cherrypy how to serve dynamic binary
file(some generated charts).Is there any easy way to do this?
 In cherrypy 2.0  python 2.4

-- 
Best Regards,
Wang Kebo

http://www.huihoo.org/~mep


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


Re: function with a state

2005-03-09 Thread Xah Lee
Nevermind. I was thinking too much. :) Thanks.

 Xah


Peter Hansen wrote:
 Xah Lee wrote:
 def myFun(var):
   return var+1
 globe = 0
 globe = myFun(globe)
 
  this is  intriguing. How does it work?
  not a rhetorical question, but where in the python doc can i read
about
  it?

 The tutorial, presumably, since there is nothing here
 that isn't covered by the most basic aspects of Python.

 Really, what did you think was there that was so
 intriguing?  A function is defined.  It takes a
 parameter and returns its value plus one.  A
 variable is created with the value 0.  The
 function is called, passing the value of the
 variable, and the return value (remember, the
 function just adds one!) is assigned to the
 variable.  Now globe equals 1.
 
 Again, what aspect of this startled you?
 
 -Peter

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


Re: py2exe Python2.4 and warning: string/unicode conversion

2005-03-09 Thread Miki Tebeka
Hello Martin,

   I'm shipping an application using py2exe.
 With Python2.3 it worked fine but when switching to Python2.4 I started
 getting warning: string/unicode conversion all over the place.
 
 Any ideas how to solve this (other than using 'filterwarnings')?
 
 It is really surprising that you get this, as the only occurrence of
 the string string/unicode conversion in Python was *removed* in
 Python 2.4. It was present in 2.3, and occurred if strtoul returned
 an overflow error.
 
 Are you sure you are using Python 2.4?
sigh Found out that one of the extension modules was compiled with 2.3 /sigh
Thanks Martin.

Bye.
--

Miki Tebeka [EMAIL PROTECTED]
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys


pgpCkDvBovDmc.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Best way to make a list unique?

2005-03-09 Thread Kent Johnson
Delaney, Timothy C (Timothy) wrote:
Diez B. Roggisch wrote:
This is actually one thing that Java 1.5 has that I'd like to see in
Python - the LinkedHashSet and LinkedHashMap. Very useful data
structures.
Implementing these is fairly simple.
There are two Ordered Dictionary recipes in the cookbook already.
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: Small but significant memory leak in Pyana XSLT processor

2005-03-09 Thread Brian Quinlan
Ola Natvig wrote:
I've isolated the problem a bit more. The script will not leak if line 25:
transformer.transform2String(transformer.parseSource(xml), xslt)
is changed to:
transformer.transform2String(xml, xslt)
Looks like the DOM tree or at least parts of it are not freed. But there are
no need to call parseSource when the XML is different for each iteration,
that solves my problem, but the parseSoruce function should free all memory
anyways.
Yes it should. It's not obvious to me why it doesn't. I'll investage it 
in detail a bit later.

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


Python COM Class Question

2005-03-09 Thread pemo
I'm trying to use difflib.py from a COM aware language - and, for ease of 
use, I'm initially trying to get this going from VB6.

I've wrappered difflib.py correctly I think, and I can now call into it and 
call a global method (called 'test' of course).  Here's the consuming code:

Dim PythonUtils As Object

Set PythonUtils = CreateObject(DiffLib.Utils)

Debug.Print PythonUtils.test()

However, difflib contains classes - like SequenceMatcher, and I've no idea 
how to get an instance of these from PythonUtils.

Can someone help me here please?

Thanks

pemo 


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


Re: Working on a log in script to my webpage

2005-03-09 Thread Pete.....
Hi again.

This question might sound a bit strange, but here I go anyway.

I found a tutorial on how to make member areas with ASP. ( It looked very 
complicated the info I found about making and using cookies to store session 
ID's with python)

Can I use python code and SQL statements in ASP.

The example only shows how to log in to a member area if the password is 
written in the asp code ( I mean the program dosnt connect to a my 
postgresql database to see if the username/password are correct.

I was thinking if I can use some of the code from the tutorial and put my 
own python code in, I will have solved my problem.

I dont know that much about asp but I also found a tutorial on that, which 
in going to read..

Thanks for your time.
The members area tutorial can be found here.
http://www.theukwebdesigncompany.com/article.php?id=392

bruce [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 pete...

 simply use google and search for php scripts login user authentication
 mysql session etc...

 these terms will give you lots of examples... you could also look at some 
 of
 the bulletin board/forum apps that are open source to se what they use. 
 or,
 you could also look through the code for some of the php content 
 management
 apps... of course, there are also the open source ecommerce solutions. all
 of these types of apps have functionality to deal with the user
 login/registration issues...

 -regards,,,


 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Behalf
 Of Pete.
 Sent: Tuesday, March 08, 2005 6:26 PM
 To: python-list@python.org
 Subject: Re: Working on a log in script to my webpage


 The 2 scripts I made is actually working the way they where meant to. So 
 im
 kindda happy :)

 The problem is, that I didnt think about the problem: as Steve wrote:
 There are other matters of concern, however, the most pressing of which
 is: How am I going to stop user from navigating directly to page1?
 Maybee I can find some premade feature, that prevents users to go to page1
 without logging in. Any ideas as to where I can find some information 
 about
 this.

 Nice that you all take time to help a newbie, so thanks to the helpfull
 people :)



 hi...

 regarding the issue of creating a login (user/passwd) script... there are
 numerous example scripts/apps written that use php/mysql... i suggest 
 that
 you take a look at a few and then incoporate the features that you want
 into
 your script.

 from your questions, it seems like this approach will give you a
 better/faster solution to your problem.

 -regards


 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Behalf
 Of Steve Holden
 Sent: Tuesday, March 08, 2005 4:02 PM
 To: python-list@python.org
 Subject: Re: Working on a log in script to my webpage


 Pete. wrote:
 Hi all I am working on a log in script for my webpage.

 I have the username and the password stored in a PostgreSQL database.

 The first I do is I make a html form, where the user can type in his
 username and code, when this is done I want to run the
 script(testifcodeisokay) that verifies that the code and username are 
 the
 right ones ( that means if they match the particular entered username 
 and
 password) If they are then I want to load page1 if they are not I want 
 to
 load the loginpage again.

 Login page:

 print '''form action=testifcodeisokay.py'br
  pUsername:br INPUT type=text NAME=username
  pCode:br INPUT type=text NAME=code/p'''

 print '''pinput type=submit value='Submit'/p/form'''
 print '''/body /html'''

 This works.
 Here I store the entered text in the variables username and code
 I then get the entered value by

 testifcodeisokay script

 connect = PgSQL.connect(user=user, password=password, host=host,
 database=databse)
 cur = connect.cursor()

 form = cgi.FieldStorage()
 username = form[username].value
 code= form[code].value

 I then want to test if they match the ones in the database

 insert_command = SELECT username, code FROM codetable WHERE
 codetable.username = '%s' AND codetable.code = '%s'  %(username, code)
 cur.execute(insert_command)

 This is an amazingly bad choice of variable name, since the command
 doesn't actually insert anything into the database!

 I should then have found where the entered username,code (on the login
 page)
 is the same as those in the database.

 But now I am stuck.

 Does any know how I can then do something like:

 If the codes from the loginpage matches the users codes in the db
 Then the user should be taken to page1
 IF the codes arnt correct the login page should load again.

 The program dosnt need to remember who the user is, after the user has
 been
 loggen in, it is only used to log the user in.

 Thanks for your time..

 The Python you want is almost certainly something like

   if len(curs.fetchall()) == 1:
 # username/password was found in db

 although unless your database is guarantees to contain only one 

Re: function with a state

2005-03-09 Thread Dan Bishop
[EMAIL PROTECTED] wrote:
 Xah Lee [EMAIL PROTECTED] wrote:

  is it possible in Python to create a function that maintains a
  variable value?

 Yes. There's no concept of a 'static' function variable as such, but
 there are many other ways to achieve the same thing.

  globe=0;
  def myFun():
globe=globe+1
return globe

 [snip]

 For more complicated cases, it might be better to be explicit and use
 objects:

   class Counter:
 def __init__(self):
   self.globe= 0
 def count(self):
   self.globe+= 1
   return self.globe

   myFun= Counter().count

You can also use generators.

 def myGenerator():
...var = 0
...while True:
...   var += 1
...   yield var
...
 myFun = myGenerator().next
 myFun()
1
 myFun()
2
 myFun()
3
 myFun()
4

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


Re: Python 2.4 removes None data type?

2005-03-09 Thread Jacek Generowicz
Warren Postma [EMAIL PROTECTED] writes:

 [EMAIL PROTECTED] wrote:
 
  I just read in the 'What's New in Python 2.4' document that the None
  data type was converted to a constant:
  http://python.org/doc/2.4/whatsnew/node15.html
 
 Implication: A long standing wart in Python now gone.  Its time to
 gloat. Are there any really evil glitches LEFT in Python?

Python 2.4 (#1, Dec  1 2004, 14:23:15) 
[GCC 3.2.3] on linux2
Type help, copyright, credits or license for more information.
 True, False = False, True
 True
False
 

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


[perl-python] a program to delete duplicate files

2005-03-09 Thread Xah Lee
here's a large exercise that uses what we built before.

suppose you have tens of thousands of files in various directories.
Some of these files are identical, but you don't know which ones are
identical with which. Write a program that prints out which file are
redundant copies.

Here's the spec.
--
The program is to be used on the command line. Its arguments are one or
more full paths of directories.

perl del_dup.pl dir1

prints the full paths of all files in dir1 that are duplicate.
(including files in sub-directories) More specifically, if file A has
duplicates, A's full path will be printed on a line, immediately
followed the full paths of all other files that is a copy of A. These
duplicates's full paths will be prefixed with rm  string. A empty
line follows a group of duplicates.

Here's a sample output.

inPath/a.jpg
rm inPath/b.jpg
rm inPath/3/a.jpg
rm inPath/hh/eu.jpg

inPath/ou.jpg
rm inPath/23/a.jpg
rm inPath/hh33/eu.jpg

order does not matter. (i.e. which file will not be rm  does not
matter.)



perl del_dup.pl dir1 dir2

will do the same as above, except that duplicates within dir1 or dir2
themselves not considered. That is, all files in dir1 are compared to
all files in dir2. (including subdirectories) And, only files in dir2
will have the rm  prefix.

One way to understand this is to imagine lots of image files in both
dir. One is certain that there are no duplicates within each dir
themselves. (imagine that del_dup.pl has run on each already) Files in
dir1 has already been categorized into sub directories by human. So
that when there are duplicates among dir1 and dir2, one wants the
version in dir2 to be deleted, leaving the organization in dir1 intact.

perl del_dup.pl dir1 dir2 dir3 ...

does the same as above, except files in later dir will have rm 
first. So, if there are these identical files:

dir2/a
dir2/b
dir4/c
dir4/d

the c and d will both have rm  prefix for sure. (which one has rm 
in dir2 does not matter) Note, although dir2 doesn't compare files
inside itself, but duplicates still may be implicitly found by indirect
comparison. i.e. a==c, b==c, therefore a==b, even though a and b are
never compared.


--

Write a Perl or Python version of the program.

a absolute requirement in this problem is to minimize the number of
comparison made between files. This is a part of the spec.

feel free to write it however you want. I'll post my version in a few
days.

http://www.xahlee.org/perl-python/python.html

 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html

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


Re: Working on a log in script to my webpage

2005-03-09 Thread Pete.....
I better mention, that I rather make it all in python and html (found out 
that python somehow works with asp)

I know that what I have to do is the following:

1) When the user logs in, I have to store a session ID in a cookie
2) When page1 is loaded(upon correctly entered username/password) the cookie 
has to be sent to page 1 and on page one there should be a tjeck to see if 
the cookies has the right values.
3) everytime a page is loaded, there has to be a tjeck, to see if the 
cookies has the right value, if not the page shouldt be loaded, and the user 
should be redirected back to login page.

It does sound very easy to make: Create a store-holder(cookies), create a 
session ID upon log in, tjeck if it is the right sessionID in the cookies 
everytime a page is loaded, if not redirect back to log in page.

But eventhough it sounds easy, I cant quite get the hold of if..

I tried googling, but didnt really find anything, that helpfull...

Any more advice...

Once again thanks for your time

Sincerly
Pete
Pete. [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hi again.

 This question might sound a bit strange, but here I go anyway.

 I found a tutorial on how to make member areas with ASP. ( It looked very 
 complicated the info I found about making and using cookies to store 
 session ID's with python)

 Can I use python code and SQL statements in ASP.

 The example only shows how to log in to a member area if the password is 
 written in the asp code ( I mean the program dosnt connect to a my 
 postgresql database to see if the username/password are correct.

 I was thinking if I can use some of the code from the tutorial and put my 
 own python code in, I will have solved my problem.

 I dont know that much about asp but I also found a tutorial on that, which 
 in going to read..

 Thanks for your time.
 The members area tutorial can be found here.
 http://www.theukwebdesigncompany.com/article.php?id=392

 bruce [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 pete...

 simply use google and search for php scripts login user authentication
 mysql session etc...

 these terms will give you lots of examples... you could also look at some 
 of
 the bulletin board/forum apps that are open source to se what they use. 
 or,
 you could also look through the code for some of the php content 
 management
 apps... of course, there are also the open source ecommerce solutions. 
 all
 of these types of apps have functionality to deal with the user
 login/registration issues...

 -regards,,,


 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Behalf
 Of Pete.
 Sent: Tuesday, March 08, 2005 6:26 PM
 To: python-list@python.org
 Subject: Re: Working on a log in script to my webpage


 The 2 scripts I made is actually working the way they where meant to. So 
 im
 kindda happy :)

 The problem is, that I didnt think about the problem: as Steve wrote:
 There are other matters of concern, however, the most pressing of which
 is: How am I going to stop user from navigating directly to page1?
 Maybee I can find some premade feature, that prevents users to go to 
 page1
 without logging in. Any ideas as to where I can find some information 
 about
 this.

 Nice that you all take time to help a newbie, so thanks to the helpfull
 people :)



 hi...

 regarding the issue of creating a login (user/passwd) script... there 
 are
 numerous example scripts/apps written that use php/mysql... i suggest 
 that
 you take a look at a few and then incoporate the features that you want
 into
 your script.

 from your questions, it seems like this approach will give you a
 better/faster solution to your problem.

 -regards


 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Behalf
 Of Steve Holden
 Sent: Tuesday, March 08, 2005 4:02 PM
 To: python-list@python.org
 Subject: Re: Working on a log in script to my webpage


 Pete. wrote:
 Hi all I am working on a log in script for my webpage.

 I have the username and the password stored in a PostgreSQL database.

 The first I do is I make a html form, where the user can type in his
 username and code, when this is done I want to run the
 script(testifcodeisokay) that verifies that the code and username are 
 the
 right ones ( that means if they match the particular entered username 
 and
 password) If they are then I want to load page1 if they are not I want 
 to
 load the loginpage again.

 Login page:

 print '''form action=testifcodeisokay.py'br
  pUsername:br INPUT type=text NAME=username
  pCode:br INPUT type=text NAME=code/p'''

 print '''pinput type=submit value='Submit'/p/form'''
 print '''/body /html'''

 This works.
 Here I store the entered text in the variables username and code
 I then get the entered value by

 testifcodeisokay script

 connect = PgSQL.connect(user=user, password=password, host=host,
 database=databse)
 cur = connect.cursor()

 form = 

Re: reading timestamp from vid file (avi)

2005-03-09 Thread Lucas Raab
flupke wrote:
Hi,
i capture a movie from mividv to an avi containing the dv video. I found 
a program that reads the timestamp from the avi so you know the exact 
date and time the video was shot. However, the source of that program is 
not available and it doesn't allow to batch process a directory of video 
files which is a pain if you import the video using split scenes.

Is there a script/program in python that reads the header or where do i 
start to write something like that?

Any info is appreciated.
Regards,
Benedict
Take a look at pymedia at http://pymedia.org.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [CherryPy]Serve dynamic binary file in cherrypy?

2005-03-09 Thread mep
Resolved. Simplely specifiy content mime type before return.


-- 
Best Regards,
Wang Kebo

http://www.huihoo.org/~mep


mep [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 Hi,
 After lookup in cherrypy site and google for a while, I haven't
 found any information about cherrypy how to serve dynamic binary
 file(some generated charts).Is there any easy way to do this?
  In cherrypy 2.0  python 2.4

 -- 
 Best Regards,
 Wang Kebo

 http://www.huihoo.org/~mep




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


Re: Best way to make a list unique?

2005-03-09 Thread Marc Christiansen
Michael Spencer [EMAIL PROTECTED] wrote:

Nice. When you replace None by an object(), you have no restriction on
the elements any more:

 Here's something to work with:
 
 class OrdSet(object):
 def __init__(self, iterable):
 Build an ordered, unique collection of hashable items
 #self._data = {None:[None, None]} # None is the pointer to the first
 # # element.  This is unsatisfactory
 # # because it cannot then be a
 # # member of the collection
 #self._last = None
  self._last = self._root = root = object()
  self._data = {root:[root, root]}
 self.update(iterable)
 
 def add(self, obj):
 Add an element to the collection
 data = self._data
 if not obj in data:
 last = self._last
 data[last][1] = obj
 #data[obj] = [last, None]
  data[obj] = [last, self._root]
 self._last = obj
 
 def update(self, iterable):
 Update the collection with the union of itself and another
 obj = self._last
 data = self._data
 last = data[obj][0]
 for item in iterable:
 if item not in data:
 data[obj] = [last, item]
 last, obj = obj, item
 #data[obj] = [last, None]
  data[obj] = [last, self._root]
 self._last = obj
 
 def remove(self, item):
 Remove an element from a set; it must be a member.
 
 If the element is not a member, raise a KeyError.
 data = self._data
 prev, next = data[item]
 data[prev][1] = next
 data[next][0] = prev
 
 def discard(self, item):
 Remove an element from a set if it is a member.
 If the element is not a member, do nothing.
 try:
 self.remove(item)
 except KeyError:
 pass
 
 def __contains__(self, item):
 return item in self._data
 
 def pop(self):
 Remove and the return the oldest element
 data = self._data
 #prev, first =  data[None]
 #data[None] = [None,data[first][1]]
  root = self._root
  prev, first =  data[root]
  data[root] = [root,data[first][1]]
 return first
 
 def clear(self):
 self.__init__([])
 
 def __iter__(self):
 Iterate over the collection in order
 data = self._data
 #prev, next = data[None]
 #while next is not None:
  root = self._root
  prev, next = data[root]
  while next is not root:
 yield next
 prev, next = data[next]
 
 def __len__(self):
 return len(self._data)-1
 
 def __repr__(self):
 return %s(%s) % (self.__class__.__name__,list(self))

 a=OrdSet([None,1,None,3])
 a
OrdSet([None, 1, 3])

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


Re: Working on a log in script to my webpage

2005-03-09 Thread Kent Johnson
Pete. wrote:
Hi all I am working on a log in script for my webpage.
I have the username and the password stored in a PostgreSQL database.
You might want to look at Snakelets and CherryPy.
Snakelets is a very simple-to-use Python web application server. One of the features is Easy user 
authentication and user login handling.
http://snakelets.sourceforge.net/

CherryPy is a pythonic, object-oriented web development framework that seems to be popular. A 
recipe for password-protected pages in CherryPy is here:
http://www.cherrypy.org/wiki/PasswordProtectedPages

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


Announcement: PyMatrix-0.0.1a Released

2005-03-09 Thread Colin J. Williams
PyMatrix is a package to provide access to the functionality of matrix 
algebra.

This package is currently based on numarray.  It includes a statistics 
module which includes a basic analysis of variance.

In the future it is hoped to enhance the generality of the divide 
operation, to add the transcendental functions as methods of the matrix 
class and to improve the documentation.  The expectation is that 
Numeric3 will eventually replace numarray and that this will necessitate 
some changes to PyMatrix

Downloads in the form of a Windows Installer (Inno) and a zip file are 
available at:

   http://www3.sympatico.ca/cjw/PyMatrix
An /Introduction to PyMatrix/ is available:
   http://www3.sympatico.ca/cjw/PyMatrix/IntroToPyMatrix.pdf
Information on the functions and methods of the matrix module is given at:
   http://www3.sympatico.ca/cjw/PyMatrix/Doc/matrix-summary.html
Colin W.
--
http://mail.python.org/mailman/listinfo/python-list


BayPIGgies: March 10, 7:30pm (FINAL MEETING AT STANFORD)

2005-03-09 Thread Aahz
WARNING: the last meeting of BayPIGgies at Stanford is currently
scheduled for March.  Our host, Danny Yoo, is leaving Stanford, and we
need to find a new location.  If you wish to assist with the search,
please join the BayPIGgies mailing list.

Meanwhile, let's all give hearty thanks to Danny for helping us find a
stable meeting location for so long!


The next meeting of BayPIGgies will be Thurs, March 10 at 7:30pm.

Donovan Preston will lead a discussion about using Python with OS X,
including integrating with PyObjC and GNUStep.

BayPIGgies meetings are in Stanford, California.  For more information
and directions, see http://www.baypiggies.net/


Before the meeting, we may meet at 6pm for dinner in downtown Palo Alto.
Discussion of dinner plans is handled on the BayPIGgies mailing list.


Advance notice: The April 14 meeting agenda has not been set.  Please
send e-mail to [EMAIL PROTECTED] if you want to suggest an
agenda -- and a meeting place!
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death.  --GvR
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Working on a log in script to my webpage

2005-03-09 Thread Pete.....
Thanks.

But I would really like to do this from scratch, so that I can learn it, I 
dont think I need that much more, before it works.

I found an example with asp, where the save the session if the password is 
correct. It isnt that long a code, so was wondering if it isnt possible to 
make something like that in python. Cause when this code is applied to the 
loginform, CODE2 will only have to be applied to every following page and 
everything is good.

code is from: 
http://tutorialized.com/tutorial/Creating-a-Members-Area-in-ASP/2234
CODE1
Set objRS = objConn.Execute (strSQL)
  '// see if there are any records returned
  If objRS.EOF Then
  'no username found
  strError = - Invalid username or passwordbr  vbNewLine
  Else
  'check password
  If objRS(password)=Request.Form(password) Then
   'username/password valid
   'save session data
   Session(loggedin) = True
   Session(userid) = objRS(id)
   'redirect to members area
   Response.Redirect (default.asp)
   Response.End
  Else
   'invalid password
   strError = - Invalid username or passwordbr  vbNewLine

CODE2%
If Session(loggedin)  True Then Response.Redirect login.asp
%
html
head
titleMembers Area/title
/head
body
h1Members Area/h1
pWelcome to our members area!/p/body
/html In my code I have allready tested if the username and password is 
correct, so I just need to do the cookie thing :D

Thanks all, hope all my questions dosnt make you tired, I just really wanna 
figure this out, and I am doing this as a little hobby of mine, so I dont 
have anyone else to ask, hope that is okay...



Kent Johnson [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Pete. wrote:
 Hi all I am working on a log in script for my webpage.

 I have the username and the password stored in a PostgreSQL database.

 You might want to look at Snakelets and CherryPy.

 Snakelets is a very simple-to-use Python web application server. One of 
 the features is Easy user authentication and user login handling.
 http://snakelets.sourceforge.net/

 CherryPy is a pythonic, object-oriented web development framework that 
 seems to be popular. A recipe for password-protected pages in CherryPy is 
 here:
 http://www.cherrypy.org/wiki/PasswordProtectedPages

 Kent 


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


Re: Split text file into words

2005-03-09 Thread qwweeeit
I thank you for your help.
I already used re.split successfully but in this case...
I didn't explain more deeply because I don't want someone else do my
homework.

I want to implement a variable  commands cross reference tool.
For this goal I must clean the python source from any comment and
manifest string.
On the cleaned source file I must isolate all the words (keeping the
words connected by '.')

My wrong code (don't consider the line ref. in traceback ... it's an
extract!):

import re

# input text file w/o strings  comments

f=open('file.txt')
lInput=f.readlines() 
f.close()

fOut=open('words.txt','w')

for i in lInput:
.   ll=re.split(r[\s,{}[]()+=-/*],i)
.   fOut.write(' '.join(ll)+'\n')

fOut.close()

Traceback (most recent call last):
  File ./GetWords.py, line 70, in ?
ll=re.split(r[\s,{}[]()+=-/*],i)
  File /usr/lib/python2.3/sre.py, line 156, in split
return _compile(pattern, 0).split(string, maxsplit)
RuntimeError: maximum recursion limit exceeded


... and if I use:
ll=re.split(r\s,{}[]()+=-/*,i)

Traceback (most recent call last):
  File ./GetWords.py, line 70, in ?
ll=re.split(r\s,{}[]()+=-/*,i)
  File /usr/lib/python2.3/sre.py, line 156, in split
return _compile(pattern, 0).split(string, maxsplit)
  File /usr/lib/python2.3/sre.py, line 230, in _compile
raise error, v # invalid expression
sre_constants.error: bad character range

I taught it was my mistake in the use of re.split...

I am using:   
Python 2.3.4 (#2, Aug 19 2004, 15:49:40)
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Working on a log in script to my webpage

2005-03-09 Thread Steve Holden
Pete. wrote:
I better mention, that I rather make it all in python and html (found out 
that python somehow works with asp)

I know that what I have to do is the following:
1) When the user logs in, I have to store a session ID in a cookie
In actual fact it's best not to wait until the user logs in: every 
request that comes in for the service should be examined for the cookie 
(which the browser will always return once it's received it). If there's 
no cookie then the server should include one in its response.

That way, each session is identified by a unique cookie value, which can 
be used (among other things) to locate any state that's associated with 
the sessions (such as a who is this user variable).

2) When page1 is loaded(upon correctly entered username/password) the cookie 
has to be sent to page 1 and on page one there should be a tjeck to see if 
the cookies has the right values.
Not quite: the cookie (retained on the client and sent to the server 
with each request) just identifies the session, and the session state 
storage (maintained on the server, one per active session) holds the 
information about the session like whether the user has logged in, 
what's in their shopping cart, and so on.

Each page (or, if you are using an application framework like Webware, 
the framework) can examine state memory to determine whether the 
conditions for access have been met, and redirect to an error page if 
not. For this purpose ASP maintained a Session object for each 
session's state memory.

3) everytime a page is loaded, there has to be a tjeck, to see if the 
cookies has the right value, if not the page shouldt be loaded, and the user 
should be redirected back to login page.

Almost, see above.
It does sound very easy to make: Create a store-holder(cookies), create a 
session ID upon log in, tjeck if it is the right sessionID in the cookies 
everytime a page is loaded, if not redirect back to log in page.

But eventhough it sounds easy, I cant quite get the hold of if..
I tried googling, but didnt really find anything, that helpfull...
It's true that there isn't actually much on the web that explains 
sessions with specific reference to Python. I can, however, after quite 
a lot of searching, thoroughly recommend

  http://webapparch.sourceforge.net/
for an overview of what happens in a session-oriented web service. I 
would suggest you start with Section 8, and then read the whole thing, 
or at least all parts that interest you.

Any more advice...
Of course usually some mechanism supported by the specific server in use 
is involved.

  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65110
does show how to generate session IDs, but then you have to deliver them 
as cookies (of course, for security reasons you don't want session IDs 
to be easily guessed, as this would allow someone to hijack an 
existing session by impersonating a browser holding the right cookie value).

If you are prepared to read a bit of PHP (sorry ...) then
  http://www.phpbuilder.com/columns/paul20020729.php3
explains the details of session maintenance sufficiently clearly that 
you would get a good idea of how to implement the same ideas in Python.


Once again thanks for your time
Sincerly
Pete
[...]
You're welcome.
regards
 Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python COM Class Question

2005-03-09 Thread Steve Holden
pemo wrote:
I'm trying to use difflib.py from a COM aware language - and, for ease of 
use, I'm initially trying to get this going from VB6.

I've wrappered difflib.py correctly I think, and I can now call into it and 
call a global method (called 'test' of course).  Here's the consuming code:

Dim PythonUtils As Object
Set PythonUtils = CreateObject(DiffLib.Utils)
Debug.Print PythonUtils.test()
However, difflib contains classes - like SequenceMatcher, and I've no idea 
how to get an instance of these from PythonUtils.

Can someone help me here please?
I hope so.
You need to wrap the Python objects for use in the COM framework - once 
wrapped their methods can be called by the client code.

You'll find wrap in win32com.server.util.
regards
 Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Split text file into words

2005-03-09 Thread Duncan Booth
qwweeeit wrote:

ll=re.split(r[\s,{}[]()+=-/*],i)

The stack overflow comes because the ()+ tried to match an empty string as 
many times as possible.

This regular expression contains a character set '\s,{}[' followed by the 
expression '()+=-/*]'. You can see that the parentheses aren't part of a 
character set if you reverse their order which gives you an error when the 
expression is compiled instead of failing when trying to match:

 ll=re.split(r[\s,{}[])(+=-/*],i)

Traceback (most recent call last):
  File pyshell#10, line 1, in -toplevel-
ll=re.split(r[\s,{}[])(+=-/*],i)
  File C:\Python24\Lib\sre.py, line 157, in split
return _compile(pattern, 0).split(string, maxsplit)
  File C:\Python24\Lib\sre.py, line 227, in _compile
raise error, v # invalid expression
error: unbalanced parenthesis
 

I suspect you actually meant the character set to include the other 
punctuation characters in which case you need to escape the closing square 
bracket or make it the first character:

Try:

ll=re.split(r[\s,{}[\]()+=-/*],i)

or:

ll=re.split(r[]\s,{}[()+=-/*],i)

instead.


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


Re: i18n: looking for expertise

2005-03-09 Thread [EMAIL PROTECTED]
Michael:

on my box, (winXP SP2), sys.getfilesystemencoding() returns 'mbcs'.

If you post your revised solution to this unicode problem, I'd be
delighted to test it on Windows.  I'm working on a Tkinter front-end
for Vivian deSmedt's rsync.py and would like to address the issue of
accented characters in folder names.

thanks
Stewart 
stewart dot midwinter at gmail dot com

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


Re: Your suggestions re virus, round 6: Virus KO

2005-03-09 Thread Anthra Norell
Josef,
  I'll definitely take a close look at all the suggestions I have been
offered, in the interest of future damage prevention. This time, though, the
fight is over and I emerge victorious!
  Poking around here and I came across huge startup or execution log
files listing rather unabashed file names. Since I'm not into that, how did
it get there? Turned out the files were all identical and also identical to
the attachment of each one of the many obviously automated decoy messages I
have been getting of late (like: 'Offer expires today',  or 'I'm shocked! Is
that really you', etc.). (Not that I ever opened any one oif them.) Anyway,
I scanned the whole disk for files of identical lenght and ended up with 869
copies of the obnoxity. One of them was C:\WINDOWS\fvprotect.exe--a windows
process of all things. I eradicated the whole lot and now all is well. I
don't believe any damage was caused, except that the Norton virus scanner
still won't start. Perhaps another install will fix that too.
 Linux is next. Do you know of a good disk-partitioning program?
Frederic

- Original Message -
From: Josef Albert Meile [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, March 09, 2005 12:23 PM
Subject: Re: Your suggestions re virus, round 5


 Hi Frederic,

 Protected mode doesn't make any difference with respect to stuff not
 running. Plus it doesn't connect to the internet. So I went back to
 unprotected mode to download WinTask. I played around with it for a while
 without being able to figure out how it works. All the while my resolve
 strengthened to start everyting from scratch and take the opportunity to
 install Linux. I startet uninstalling stuff I never use and started
hunting
 for the original media of the stuff I do use and already face the
 predicament of not finding some. I imagine an uninstaller that saves an
 application and restores it from the save. Do you know of any such thing?
 Sorry, I don't know if such thing exists. But anyway, at last alternative,
I
 will
 do a backup of the important files and reinstall everything.

 There is another alternative, but you have to know what you are doing:
 http://www.hijackthis.de

 You can also get a log of the running processes with this tool and do an
 online analysis on the hijackthis.de website. There are also forums there
 where you can ask.

 Good luck,
 Josef

 _
 Don't just search. Find. Check out the new MSN Search!
 http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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


Web framework

2005-03-09 Thread Gianluca Sartori
Hi guys,

What web framework do you suggest to develop with? I had a look both at
Nevow and Quixote. These seemes to be the most appreciated by the
community. Anyway, I had no luck looking for a complete and coherent
documentation.

Thanks for any suggestion,
Gianluca

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


MDaemon Warning - virus found: RETURNED MAIL: SEE TRANSCRIPT FOR DETAILS

2005-03-09 Thread Automatic Email Delivery Software

*** WARNING **
Este mensaje ha sido analizado por MDaemon AntiVirus y ha encontrado 
un fichero anexo(s) infectado(s).  Por favor revise el reporte de abajo.

AttachmentVirus name   Action taken
--
mail.zip  Email-Worm.Win32.Mydoom.m Removed


**


The message was not delivered due to the following reason:

Your message could not be delivered because the destination computer was
not reachable within the allowed queue period. The amount of time
a message is queued before it is returned depends on local configura-
tion parameters.

Most likely there is a network problem that prevented delivery, but
it is also possible that the computer is turned off, or does not
have a mail system running right now.

Your message was not delivered within 5 days:
Host 197.51.128.93 is not responding.

The following recipients did not receive this message:
python-list@python.org

Please reply to [EMAIL PROTECTED]
if you feel this message to be in error.

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

running programs from within python

2005-03-09 Thread M.N.A.Smadi
hi;
in general: how can i pass a string containing a concatenated sequcne of 
command line arguments to a unix system CLI?

my specific problem:
i have an executable that is called xyz (written in C if that matters) 
that i cannot modify, which prints it is text output to the screen and 
takes an input as t.txt.
on a unix terminal, i do the ./xyz t.txt  tmp.txt
so that the tmp.txt will contain the output of the xyz executable

i tried the following but it did not work
import os
os.execl(./xyz,t.txt  tmp.txt) #the thing just hangs there
i aslo tried
os.execl(./xyz,t.txt) # but it does not output anything to the 
screen either, hangs there too

any suggestions?
thanks
m.smadi
--
http://mail.python.org/mailman/listinfo/python-list


Re: running programs from within python

2005-03-09 Thread M.N.A.Smadi
M.N.A.Smadi wrote:
hi;
in general: how can i pass a string containing a concatenated sequcne 
of command line arguments to a unix system CLI?

my specific problem:
i have an executable that is called xyz (written in C if that matters) 
that i cannot modify, which prints it is text output to the screen and 
takes an input as t.txt.
on a unix terminal, i do the ./xyz t.txt  tmp.txt
so that the tmp.txt will contain the output of the xyz executable

i tried the following but it did not work
import os
os.execl(./xyz,t.txt  tmp.txt) #the thing just hangs there
i aslo tried
os.execl(./xyz,t.txt) # but it does not output anything to the 
screen either, hangs there too

any suggestions?
thanks
m.smadi
i guess i will answer myself:
import os
os.system(string)
!!
--
http://mail.python.org/mailman/listinfo/python-list


SOAPpy Interoperability w/AXIS C++

2005-03-09 Thread jkohans
Hello,

I am having some trouble getting a Python client written using SOAPpy
0.11.6 to work with a Web Service that is published using AXIS C++
version 1.4.  I have a C++ client working, and I am able to compare the
SOAP messages that are being sent by it and the Python client.

It appears as though the only difference is the definition of the XML
Schema and XML Schema-instance namespace.  The C++ client refers to the
2001 versions, but the Python client refers to the 1999 versions.  Has
anyone run into a similar problem and been able to find a work around?
Thanks in advance for any help.

Regards,
Jeremy Kohansimeh

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


RE: running programs from within python

2005-03-09 Thread Batista, Facundo
Title: RE: running programs from within python





[M.N.A.Smadi]


#- i guess i will answer myself:
#- import os
#- os.system(string)


If you have Py2.4, it's better to use subprocess().


. Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



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

Re: running programs from within python

2005-03-09 Thread Steven Bethard
M.N.A.Smadi wrote:
M.N.A.Smadi wrote:
hi;
in general: how can i pass a string containing a concatenated sequcne 
of command line arguments to a unix system CLI?

i guess i will answer myself:
import os
os.system(string)
Also worth noting is that if you're using Python 2.4, you might want to 
look at the subprocess module, which replaces many of the older os.* 
calls with a more flexible interface.  For the os.system replacement, see:

http://docs.python.org/lib/node235.html
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: [CherryPy]Serve dynamic binary file in cherrypy?

2005-03-09 Thread Remi Delon
mep [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]...
 Hi,
 After lookup in cherrypy site and google for a while, I haven't
 found any information about cherrypy how to serve dynamic binary
 file(some generated charts).Is there any easy way to do this?
  In cherrypy 2.0  python 2.4

Yes, there is an easy way: have your handler method return the binary
data, and set the Content-Type before returning the data, like this:

# class Root:
# def index(self):
# ... Generate binary data in data ...
# cpg.response.headerMap['Content-Type'] = 'image/gif'
# return data

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


Re: running programs from within python

2005-03-09 Thread M.N.A.Smadi
am getting an error in the script as follows:
NameError: global name 'os' is not defined
however i dont get the same error when running from the python CLI. (and 
yes i am importing the os module)

is this a bug in python 2.3 (the one am currently using)
thanks
m.smadi
Steven Bethard wrote:
M.N.A.Smadi wrote:
M.N.A.Smadi wrote:
hi;
in general: how can i pass a string containing a concatenated 
sequcne of command line arguments to a unix system CLI?

i guess i will answer myself:
import os
os.system(string)

Also worth noting is that if you're using Python 2.4, you might want 
to look at the subprocess module, which replaces many of the older 
os.* calls with a more flexible interface.  For the os.system 
replacement, see:

http://docs.python.org/lib/node235.html
STeVe

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


RE: running programs from within python

2005-03-09 Thread Batista, Facundo
Title: RE: running programs from within python





[M.N.A.Smadi]


#- am getting an error in the script as follows:
#- 
#- NameError: global name 'os' is not defined


What script? 


Please paste it here. If it's more than 20 lines, trim it until you find the smaller script that has the error.


. Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



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

Re: running programs from within python

2005-03-09 Thread Steven Bethard
M.N.A.Smadi wrote:
am getting an error in the script as follows:
NameError: global name 'os' is not defined
however i dont get the same error when running from the python CLI. (and 
yes i am importing the os module)
Can you give the full exception message (i.e. copy-paste it from the 
output)?

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


Re: logging addLevelName

2005-03-09 Thread Jeremy Jones
[EMAIL PROTECTED] wrote:
I am trying to add a new logging level.
logging.config.fileConfig(bengineLog.cfg)
logging.CLIENT = logging.INFO + 1
logging.addLevelName( logging.CLIENT, 'CLIENT' )
logging.root.setLevel( [logging.INFO, logging.CLIENT, logging.WARNING,
logging.ERROR, logging.CRITICAL] )
logger = logging.getLogger(None)
logging.Logger.client('test')
I get error:
AttributeError: class Logger has no attribute 'client'
Any help?
 

Looks like what you want is logger.log().  Here is an example that takes 
your addLevelName code and logs at levels info to critical:

#!/usr/bin/env python
import logging
#create new log level
logging.CLIENT = logging.INFO + 1
logging.addLevelName(logging.CLIENT, CLIENT)
logging.root.setLevel([logging.INFO, logging.CLIENT, logging.WARNING, 
logging.ERROR, logging.CRITICAL])

#create logger with mylogger
logger = logging.getLogger(mylogger)
logger.setLevel(logging.INFO)
#create file handler and set level to debug
fh = logging.FileHandler(test.log)
fh.setLevel(logging.DEBUG)
#create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
#create formatter
formatter = logging.Formatter(%(asctime)s - %(name)s - %(levelname)s - 
%(message)s)
#add formatter to handlers
fh.setFormatter(formatter)
ch.setFormatter(formatter)
#add handlers to logger
logger.addHandler(fh)
logger.addHandler(ch)

logger.debug(this is debug)
logger.info(this is info)
logger.log(logging.CLIENT, this is client)
logger.warning(this is warning)
logger.error(this is error)
logger.critical(this is critical)
It produces this output:
2005-03-09 12:28:33,399 - mylogger - INFO - this is info
2005-03-09 12:28:33,401 - mylogger - CLIENT - this is client
2005-03-09 12:28:33,458 - mylogger - WARNING - this is warning
2005-03-09 12:28:33,460 - mylogger - ERROR - this is error
2005-03-09 12:28:33,518 - mylogger - CRITICAL - this is critical
HTH,
Jeremy Jones
--
http://mail.python.org/mailman/listinfo/python-list


Help with socket staus

2005-03-09 Thread Miley, Shain
Hello,
First let me say hello since I am new to this list.  

Recently I downloaded and installed the c3 suite of python2 scripts so that I 
can execute commands on multiple unix nodes.  What I am looking to do is 
determine when an ssh connection fails (either sshd has been stopped, the node 
is not in service, etc).  I have been unable to find good documentation to help 
me resolve this issue.  The message that I receive when ssh fails is this:

ssh: connect to host test.node.com port 22: Connection refused

So I guess my question is this...are there any methods to determine the state 
of a socket connection (i.e connected, no connected, connection failed, etc).

Thanks in advance,

Shain


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


Problematic behavior of the import statement when several module files have the same name.

2005-03-09 Thread Xif
Hello Everyone!

Here's a problem with relative imports:

Suppose I have a package called some_package (in a separate directory
included in the PYTHONPATH, with an __init__.py file etc.)

This package has a module inside the directory, called database, and
therefore  residing in the file some_package/database.py.

Now, what if there's another module, for example inside the
site-packages directory, with the same file name (i.e. database.py)?

We have a problem. Since although these modules have different absolute
names (some_package.database for the first module, and just
database for the second), when I try to do

import database

from inside some_package, it first of all tries to find the matching
file in the some_package directory (i.e. do a relative import). Since
it first checks the some_package directory, and finds database.py
there,

import database

in fact imports the module with the absolute name
some_package.database.

This is problemat on two levels:

1) It is surprising and undesirable that import database in effect
may do two completely different things (import some_package.database
or import database) depending on an external, unpredictable factor:
the existence of a database.py file inside the some_package directory.

2) It effectively prevents you from naming a module inside a package
with the same name of any module in the root PYTHONPATH directories.
In my example, there's no sane way I can see of having
some_package.database if there's already a database module (database.py
file) in any PYTHONPATH directory.

Are my observations correct?  Is there something I ignored?  Should
this be posted somewhere else?

Your comments would be appreciated.

Xif

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


Is there a short-circuiting dictionary get method?

2005-03-09 Thread Dave Opstad
In this snippet:

d = {'x': 1}
value = d.get('x', bigscaryfunction())

the bigscaryfunction is always called, even though 'x' is a valid key. 
Is there a short-circuit version of get that doesn't evaluate the 
second argument if the first is a valid key? For now I'll code around 
it, but this behavior surprised me a bit...

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


Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Peter Hansen
Dave Opstad wrote:
In this snippet:
d = {'x': 1}
value = d.get('x', bigscaryfunction())
the bigscaryfunction is always called, even though 'x' is a valid key. 
Is there a short-circuit version of get that doesn't evaluate the 
second argument if the first is a valid key? For now I'll code around 
it, but this behavior surprised me a bit...
try:
value = d['x']
except KeyError:
value = bigscaryfunction()
get() is just a method, and arguments to methods are always
evaluated before being passed to the method, so the short
answer is no, there is no 'version' of get() that will do
what you want.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Bill Mill
Dave,

On Wed, 09 Mar 2005 09:45:41 -0800, Dave Opstad [EMAIL PROTECTED] wrote:
 In this snippet:
 
 d = {'x': 1}
 value = d.get('x', bigscaryfunction())
 
 the bigscaryfunction is always called, even though 'x' is a valid key.
 Is there a short-circuit version of get that doesn't evaluate the
 second argument if the first is a valid key? For now I'll code around
 it, but this behavior surprised me a bit...

There is no short-circuit function like you're asking for, because
it's impossible in python. To pass an argument to the 'get' function,
python evaluates the bigscaryfunction before calling 'get'.

(I believe this means that python doesn't have lazy evaluation, but
the language lawyers may shoot me down on that. Wikipedia seems to say
that it means python doesn't have delayed evaluation).

Here are two ways to do what you want:

if 'x' in d: value = d['x']
else: value = bigscaryfunction()

or:

def sget(dict, key, func, *args):
if key in dict: return key
else: return func(*args)

sget(d, 'x', bigscaryfunction)

Both methods are untested, but should work with minor modifications.

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Forums based on python

2005-03-09 Thread Naouka



HI
I AM NEW TO PROGRAMING PRESENTLY I AM USING WINDOWS ME AND WHAT I SAW IN 
PYTHON INTEREST ME ANN AWFUL LOT. I DOWNLOADED VERSION2.4 AND I TRIED TO 
GET MY PROGRAM "HELLO WORLD" ETC I SAVED ALL PROGRAMS BUT WHEN I WANT TO RUN IT 
I CAN'T FIND UNDER EDIT=RUN SCRIPT = WHERE CAN I GO TO RUN MY BEGINNING 
PROGRAMS. DID I DOWNLOAD THE WRONG VERSION
THANK YOU FOR ANY HELP
EDWARD
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: running programs from within python

2005-03-09 Thread M.N.A.Smadi
this is the full error
Traceback (most recent call last):
 File ./plugin.py, line 60, in ?
   main()
 File ./plugin.py, line 40, in main
   os.system(/root/tmp/bibutils_3.14/isi2xml  + isi_file +   
tmp_isi_xml.xml)
NameError: global name 'os' is not defined

smadi
Steven Bethard wrote:
M.N.A.Smadi wrote:
am getting an error in the script as follows:
NameError: global name 'os' is not defined
however i dont get the same error when running from the python CLI. 
(and yes i am importing the os module)

Can you give the full exception message (i.e. copy-paste it from the 
output)?

STeVe

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


Re: Popen3 and capturestderr

2005-03-09 Thread Kenneth Pronovici
On Wed, Mar 09, 2005 at 06:17:50AM -, Donn Cave wrote:
 Quoth Kenneth Pronovici [EMAIL PROTECTED]:
 ...
 | If ignoreStderr=False, I use popen2.Popen4 so that stderr and stdout are
 | intermingled.  If ignoreStderr=True, I use popen2.Popen3 with
 | capturestderr=True so stderr doesn't appear in the output.  This
 | functionality exists so I have an equivalent of command-line redirection
 | of stderr, i.e. command 2/dev/null.  
 ...
 | After some digging, I've decided that this behavior probably occurs
 | because I am ignoring the pipe.childerr file object.  Indeed, if I call
 | pipe.childerr.close() right after opening the pipe, my ls command that
 | had been hanging completes normally.  However, other commands which
 | actually attempt to write to stderr don't seem to like this very much.
 |
 | What is the right way to discard stderr when working with a pipe?  I
 | want to consistently throw it away, and I don't see a good way to do
 | this with the popen2 implementation.
 
 Right, popen2 gives you about 3 options, out of probably dozens that
 you could get with shell redirections.  On the other hand, the source
 is available, and Python is an OOP language, so I assume there is no
 reason you can't make a derived class that does just what you want.
 In the present case I guess that would mean something like
null = os.open('/dev/null', os.O_RDWR)
os.dup2(null, 0)
os.dup2(null, 2) (depending)
os.close(null)
 along with other stuff you can just copy from Popen4.

Ah... ok, subclassing is an option I hadn't considered.  I'll give that
a whirl and see whether I can make it work.

KEN

-- 
Kenneth J. Pronovici [EMAIL PROTECTED]
Personal Homepage: http://www.skyjammer.com/~pronovic/
They that can give up essential liberty to obtain a little 
 temporary safety deserve neither liberty nor safety. 
  - Benjamin Franklin, Historical Review of Pennsylvania, 1759 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread bearophileHUGS
Maybe this can help:

value = d.get('x', lambda: bigscaryfunction())

Bearophile

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


Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Bill Mill
On 9 Mar 2005 10:05:21 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Maybe this can help:
 
 value = d.get('x', lambda: bigscaryfunction())

 def test(): print 'gbye'
...
 d = {}
 z = d.get('x', lambda: test())
 z
function lambda at 0x008D6870

So this seems to be merely an obfuscation of:

 z = d.get('x', test)
 z
function test at 0x008D66B0

I just wanted to ask, am I missing something?

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Bill Mill
On 09 Mar 2005 18:13:01 GMT, F. Petitjean [EMAIL PROTECTED] wrote:
 Le Wed, 09 Mar 2005 09:45:41 -0800, Dave Opstad a écrit :
  In this snippet:
 
  d = {'x': 1}
  value = d.get('x', bigscaryfunction())
 
  the bigscaryfunction is always called, even though 'x' is a valid key.
  Is there a short-circuit version of get that doesn't evaluate the
  second argument if the first is a valid key? For now I'll code around
  it, but this behavior surprised me a bit...
 def scary():
 print scary called
 return 22
 
 d = dict(x=1)
 d.get('x', lambda *a : scary())

 # print 1
 d.get('z', (lambda *a : scary())())
 scary called
 22

but:

 d.get('x', (lambda *a: test())())
test called
1

So how is this different than d.get('x', test()) ?

Peace
Bill Mill
bill.mill at gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


RE: Problematic behavior of the import statement when several modulefiles have the same name.

2005-03-09 Thread Robert Brewer
Xif wrote:
 Here's a problem with relative imports:
 
 Suppose I have a package called some_package (in a separate directory
 included in the PYTHONPATH, with an __init__.py file etc.)
 
 This package has a module inside the directory, called database, and
 therefore  residing in the file some_package/database.py.
 
 Now, what if there's another module, for example inside the
 site-packages directory, with the same file name (i.e. database.py)?
 
 We have a problem. Since although these modules have 
 different absolute
 names (some_package.database for the first module, and just
 database for the second), when I try to do
 
 import database
 
 from inside some_package, it first of all tries to find the matching
 file in the some_package directory (i.e. do a relative import). Since
 it first checks the some_package directory, and finds database.py
 there,
 
 import database
 
 in fact imports the module with the absolute name
 some_package.database.
 
 This is problemat on two levels:
 
 1) It is surprising and undesirable that import database in effect
 may do two completely different things (import some_package.database
 or import database) depending on an external, unpredictable factor:
 the existence of a database.py file inside the some_package directory.
 
 2) It effectively prevents you from naming a module inside a package
 with the same name of any module in the root PYTHONPATH directories.
 In my example, there's no sane way I can see of having
 some_package.database if there's already a database module 
 (database.py
 file) in any PYTHONPATH directory.
 
 Are my observations correct?  Is there something I ignored?  Should
 this be posted somewhere else?

Short answer: don't use relative imports:

from some_package import database

http://docs.python.org/ref/import.html


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


RE: Forums based on python

2005-03-09 Thread Batista, Facundo
Title: RE: Forums based on python





[EMAIL PROTECTED]


#- HI
#- I AM NEW TO PROGRAMING PRESENTLY I AM USING WINDOWS ME AND WHAT I SAW IN PYTHON INTEREST ME ANN AWFUL LOT. I DOWNLOADED VERSION 2.4 AND I #- TRIED TO GET MY PROGRAM HELLO WORLD ETC I SAVED ALL PROGRAMS BUT WHEN I WANT TO RUN IT I CAN'T FIND UNDER EDIT=RUN SCRIPT = WHERE CAN I #- GO TO RUN MY BEGINNING PROGRAMS. DID I DOWNLOAD THE WRONG VERSION

#- THANK YOU FOR ANY HELP 
#- EDWARD


A message like...



Hi,

I'm new to programming. Presently I'm using Windows ME and what I saw in Python interest me a lot.


I downloaded the version 2.4, and I tried to get my program Hello world, etc...


I saved all programs but when I want to run it I can't find under Edit/Run script. Where can I go to run my beginning programs?

Did I download the wrong version?


Thank you for any help


 Edward



will bring you more help. Note that I'm not considering the actual sense of your words, just the format.


Regards,


. Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



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

Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Kent Johnson
F. Petitjean wrote:
Le Wed, 09 Mar 2005 09:45:41 -0800, Dave Opstad a écrit :
Is there a short-circuit version of get that doesn't evaluate the 
second argument if the first is a valid key? For now I'll code around 
it, but this behavior surprised me a bit...
def scary():
print scary called
return 22
d = dict(x=1)
d.get('x', lambda *a : scary())
# print 1
d.get('z', (lambda *a : scary())())
scary called
22
So you have to change the code at the point of call depending on whether the requested value is in 
the dict? ;)

If you can get this to work I'm sure we can find other applications for such 
'smart code' :-)
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Second argument to super().

2005-03-09 Thread Tobiah
What is the purpose of the second argument to super()?
What is meant by the returning of an 'unbound' object
when the argument is omitted.
Also, when would I pass an object as the second argument,
and when would I pass a type?
Thanks,
Tobiah
--
http://mail.python.org/mailman/listinfo/python-list


Re: running programs from within python

2005-03-09 Thread James Stroud
You should

import os

On Wednesday 09 March 2005 10:06 am, M.N.A.Smadi wrote:
 this is the full error


 Traceback (most recent call last):
   File ./plugin.py, line 60, in ?
 main()
   File ./plugin.py, line 40, in main
 os.system(/root/tmp/bibutils_3.14/isi2xml  + isi_file +  
 tmp_isi_xml.xml)
 NameError: global name 'os' is not defined

 smadi

 Steven Bethard wrote:
  M.N.A.Smadi wrote:
  am getting an error in the script as follows:
 
  NameError: global name 'os' is not defined
 
  however i dont get the same error when running from the python CLI.
  (and yes i am importing the os module)
 
  Can you give the full exception message (i.e. copy-paste it from the
  output)?
 
  STeVe

-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Reinhold Birkenfeld
Dave Opstad wrote:
 In this snippet:
 
 d = {'x': 1}
 value = d.get('x', bigscaryfunction())
 
 the bigscaryfunction is always called, even though 'x' is a valid key. 
 Is there a short-circuit version of get that doesn't evaluate the 
 second argument if the first is a valid key? For now I'll code around 
 it, but this behavior surprised me a bit...

Well, if the dict only contains ints, here is a dirty hack (but don't
use it instead of the try/except approach):

class Littletinyproxy:
def __int__(self):
return bigscaryfunction()

d = dict(x=1)
value = int(d.get('x', Littletinyproxy()))


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


RE: running programs from within python

2005-03-09 Thread Batista, Facundo
Title: RE: running programs from within python





[James Stroud]


#- import os


He says he did it:


#-   M.N.A.Smadi wrote:
#-   (and yes i am importing the os module)


But he still didn't paste the code here



. Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



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

Re: Web framework

2005-03-09 Thread dowskimania
Gianluca Sartori wrote:
 Hi guys,

 What web framework do you suggest to develop with?

I really like CherryPy.  It has a very intuitive design.  A directory
is an object and the files in it are methods.  URL variables are
passed as arguments to the methods.  The CherryPy site has a good
tutorial and some examples that should get you up and running fairly
quickly.

http://www.cherrypy.org

 Thanks for any suggestion,
 Gianluca

Hope this helps.

Christian

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


PythonWin line spacing

2005-03-09 Thread tkpmep
I've just downloaded and installed ActivePython and am trying to
customize the PythonWin editor. Its line spacing seems to default to 2,
and consequently, I cannot see many lines of code on a screen. How do I
set the line spacing to 1?

Thomas Philips

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


Re: running programs from within python

2005-03-09 Thread Steven Bethard
M.N.A.Smadi wrote:
 am getting an error in the script as follows:

 NameError: global name 'os' is not defined

 however i dont get the same error when running from the python CLI.
 (and yes i am importing the os module)
 Steven Bethard wrote:
 Can you give the full exception message (i.e. copy-paste it from the
 output)?
M.N.A.Smadi top-posted:
this is the full error
Traceback (most recent call last):
 File ./plugin.py, line 60, in ?
   main()
 File ./plugin.py, line 40, in main
   os.system(/root/tmp/bibutils_3.14/isi2xml  + isi_file +   
tmp_isi_xml.xml)
NameError: global name 'os' is not defined
Hmmm...  I don't see how you'd get this if you're really importing the 
os module (as you say above).  Are you sure that you have 'import os' at 
the top of plugin.py?  You don't have any conditional wrapped around it 
do you?

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


Re: Problematic behavior of the import statement when several module files have the same name.

2005-03-09 Thread Steven Bethard
Xif wrote:
Hello Everyone!
Here's a problem with relative imports:
Suppose I have a package called some_package (in a separate directory
included in the PYTHONPATH, with an __init__.py file etc.)
This package has a module inside the directory, called database, and
therefore  residing in the file some_package/database.py.
Now, what if there's another module, for example inside the
site-packages directory, with the same file name (i.e. database.py)?
We have a problem. Since although these modules have different absolute
names (some_package.database for the first module, and just
database for the second), when I try to do
import database
from inside some_package, it first of all tries to find the matching
file in the some_package directory (i.e. do a relative import). Since
it first checks the some_package directory, and finds database.py
there,
import database
in fact imports the module with the absolute name
some_package.database.
You've just re-discovered the reason you should always use absolute 
imports.  Check out:

http://www.python.org/doc/faq/programming.html#what-are-the-best-practices-for-using-import-in-a-module
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Steven Bethard
Bill Mill wrote:
On 9 Mar 2005 10:05:21 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
Maybe this can help:
value = d.get('x', lambda: bigscaryfunction())

def test(): print 'gbye'
...
d = {}
z = d.get('x', lambda: test())
z
function lambda at 0x008D6870
So this seems to be merely an obfuscation of:
z = d.get('x', test)
z
function test at 0x008D66B0
I just wanted to ask, am I missing something?
Nope that looks right.  See Overuse of lambda in 
http://www.python.org/moin/DubiousPython for discussion of exactly this 
mistake.

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


Re: Error on xpath-ing a DOM with namespaces

2005-03-09 Thread Piet
 NSS = {u'wsdl': u'http://schemas.xmlsoap.org/wsdl/'}
 #processorNss = namespace bindings to be used by the processor
 ctx = Context(wsdl_doc, processorNss=NSS)
 Evaluate(u'wsdl:description/wsdl:documentation', context=ctx)
 
 
 Should give you a start.
Thanks a lot. I found a solution for my problem and lots of food for
thought for improving my XML handling in general.
Best regards
Piet
-- 
http://mail.python.org/mailman/listinfo/python-list


python cvs interface?

2005-03-09 Thread corey
Hi everyone, this should be a quick question.  I'm writing some scripts
to take some file and move them into a CVS repository, but it's pretty
slow, because it uses system calls to execute the CVS commands.  Has
anyone ever made a python to CVS interface library that I could use?
I've been trying to google around for something, but predictably I get
a zillion sourceforge repository hits, and it isn't really helping.  So
anyway, if anyone knows of a useful module, I'd love to hear about it.
Thanks!

- Corey

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


Re: Second argument to super().

2005-03-09 Thread Steven Bethard
Tobiah wrote:
What is the purpose of the second argument to super()?
You probably want to check the docs[1] again.  They give an example:
class C(B):
def meth(self, arg):
super(C, self).meth(arg)
What is meant by the returning of an 'unbound' object
when the argument is omitted.
If you supply a second argument (an instance of the type) to super, the 
returned object will be bound to that instance.  For example:

py class C(object):
... def g(self):
... print 'g'
...
py class D(C):
... def h(self):
... print 'h'
...
py d = D()
py s = super(D, d)
py d2 = D()
py s2 = super(D, d2)
py s == s2
False
Note that the object returned depends on the instance passed in.  An 
'unbound' object would not be bound in this way to the instance.

Note also that the super object returned has access only to the methods 
of the superclass:

py s.g
bound method D.g of __main__.D object at 0x01186130
py d.g
bound method D.g of __main__.D object at 0x01186130
py s.h
Traceback (most recent call last):
  File interactive input, line 1, in ?
AttributeError: 'super' object has no attribute 'h'
py d.h
bound method D.h of __main__.D object at 0x01186130

Also, when would I pass an object as the second argument,
and when would I pass a type?
For most use cases, you'll probably only want an object (an instance). 
You might run into the type case if you define the staticmethod __new__ 
in a class:

py class S(str):
... def __new__(cls, s):
... return super(S, cls).__new__(cls, 'S(%s)' %s)
...
py S('abc')
'S(abc)'
In this case __new__ takes as a first argument the class (type) of the 
object, so if you want to invoke the superclass __new__, you need to 
pass the type to super.  (You don't have an instance to pass.)

STeVe
[1] http://docs.python.org/lib/built-in-funcs.html#l2h-70
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to make a list unique?

2005-03-09 Thread Michael Spencer
Marc Christiansen wrote:
Michael Spencer [EMAIL PROTECTED] wrote:
Nice. When you replace None by an object(), you have no restriction on
the elements any more:

Thanks for the suggestion, Marc.
Note that if there is no need to access the middle of the collection, then the 
implementation is simpler, and less resource-intensive, since the items can be 
singly-linked

class UniqueQueue(object):
def __init__(self, iterable):
self._data = _data = {}
self._last = self._root = object() # An object the user is unlikely to
   # reference - thanks Marc
self.update(iterable)
def push(self, obj):
if not obj in self._data:
self._data[self._last] = obj
self._last = obj
def pop(self):
data = self._data
first = data.pop(self._root)
self._root = first
return first
def update(self, iterable):
last = self._last
data = self._data
for item in iterable:
if item not in data:
data[last] = item
last = item
self._last = last
def __iter__(self):
data = self._data
next = self._root
try:
while 1:
next = data[next]
yield next
except KeyError:
raise StopIteration
def __repr__(self):
return %s(%s) % (self.__class__.__name__,list(self))
  q = UniqueQueue(range(5))
  q.update(range(3,8))
  q
 UniqueQueue([0, 1, 2, 3, 4, 5, 6, 7])
  q.pop()
 0
  q
 UniqueQueue([1, 2, 3, 4, 5, 6, 7])
 
  q.push(None)
  q
 UniqueQueue([1, 2, 3, 4, 5, 6, 7, None])
 
Michael

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


os.walk(entire filesystem)

2005-03-09 Thread rbt
More of an OS question than a Python question, but it is Python related 
so here goes:

When I do os.walk('/') on a Linux computer, the entire file system is 
walked. On windows, however, I can only walk one drive at a time (C:\, 
D:\, etc.). Is there a way to make os.walk() behave on Windows as it 
behaves on Linux? I'd like to walk the entire file system at once... not 
one drive at a time.

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


Re: Python 2.4 removes None data type?

2005-03-09 Thread Jarek Zgoda
Jacek Generowicz napisa(a):
Implication: A long standing wart in Python now gone.  Its time to
gloat. Are there any really evil glitches LEFT in Python?
Python 2.4 (#1, Dec  1 2004, 14:23:15) 
[GCC 3.2.3] on linux2
Type help, copyright, credits or license for more information.

True, False = False, True
True
False
Ugh, today I've found this in some legacy code (yes, there *is* legacy 
code in Python). And I will not touch this module until such syntax 
become illegal.

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: popen2.Popen3 doesn't work well for me

2005-03-09 Thread alexrait1
It does but that's not what I want.  I need a class which I can query
for process termination for instance...
Is there a way to overcome this problem with Popen3?

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


Re: Running doctests with unittest

2005-03-09 Thread Jim Sizelove
Thomas Heller wrote:
I'm trying to integrate some doctest tests with unittest.  The tests
must be exposed as one or more subclasses of unittest.TestCase, so I'm
collecting them with a call to doctest.DocTestSuite(), and then add them
to a TestCase class I have created.
The tests seem to run, but they always seem to succeed - I have no idea
why.  Any ideas?
Thomas
---snip---

print Hi
print 1213

def func():

 print spam
 print blah

import doctest, unittest
suite = doctest.DocTestSuite()
class TestCase(unittest.TestCase):
pass
for index, test in enumerate(suite._tests):
setattr(TestCase, test_%d % index, test)
if __name__ == __main__:
if 1:
import unittest
unittest.main()
else:
import doctest
doctest.testmod()
---snip---
I can't explain why all the tests seemed to pass, but I tried a 
different approach that works.

Once you have a suite object, you just need to run it.  The 
TextTestRunner works well for that.  I got output errors and failures by 
 doing the following:

if __name__ == '__main__':
import doctest, unittest
suite = doctest.DocTestSuite()
testRunner = unittest.TextTestRunner()
testRunner.run(suite)
HTH,
Jim Sizelove
--
http://mail.python.org/mailman/listinfo/python-list


Re: popen2.Popen3 doesn't work well for me

2005-03-09 Thread Steven Bethard
alexrait1 wrote:
It does but that's not what I want.  I need a class which I can query
for process termination for instance...
Is there a way to overcome this problem with Popen3?
If you're using Python 2.4 you should look into the subprocess module. 
I think these docs might be what you're looking for:

http://docs.python.org/lib/node235.html
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode BOM marks

2005-03-09 Thread Steve Horsley
Francis Girard wrote:
Le lundi 7 Mars 2005 21:54, Martin v. Lwis a crit :
Hi,
Thank you for your very informative answer. Some interspersed remarks  follow.

I personally would write my applications so that they put the signature
into files that cannot be concatenated meaningfully (since the
signature simplifies encoding auto-detection) and leave out the
signature from files which can be concatenated (as concatenating the
files will put the signature in the middle of a file).

Well, no text files can't be concatenated ! Sooner or later, someone will use 
cat on the text files your application did generate. That will be a lot of 
fun for the new unicode aware super-cat.

It is my understanding that the BOM (U+feff) is actually the 
 Unicode character Non-breaking zero-width space. I take 
this to mean that the character can appear invisibly 
anywhere in text, and its appearance as the first character 
of a text is pretty harmless. Concateniating files will 
leave invisible space characters in the middle of the text, 
but presumably not in the middle of words, so no harm is 
done there either.

I suspect that the fact that an explicitly invisible 
character feff has an invalid character code fffe for its 
byte-reversed counterpart is no accident, and that the 
charecter was intended from inception to also server as a 
byte order indication.

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


Re: Web framework

2005-03-09 Thread Jeff Reavis
You may also want to look at Spyce. It is similar to JSP,PHP, or ASP.
There are some good docs and examples at the site.

http://spyce.sourceforge.net/

-jjr

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


Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Michael Spencer
Dave Opstad wrote:
In this snippet:
d = {'x': 1}
value = d.get('x', bigscaryfunction())
the bigscaryfunction is always called, even though 'x' is a valid key. 
Is there a short-circuit version of get that doesn't evaluate the 
second argument if the first is a valid key? For now I'll code around 
it, but this behavior surprised me a bit...

Dave
If (and this is a big if) you know that the dictionary contains no values that 
evaluate to boolean false, then you can use the short-circuiting 'or' operator:

  def bigscaryfunction():
 ... print scary
 ...
  d= globals()
  d.get(key) or bigscaryfunction()
 scary
  d.get(__name__) or bigscaryfunction()
 'LazyDictget'
 
Alternatively, you can just write your own getter function:
  def lazyget(dict_, key, default):
 ... if key in dict_:
 ... return dict_[key]
 ... else:
 ... return default()
 ...
  lazyget(d,key,bigscaryfunction)
 scary
  lazyget(d,__name__,bigscaryfunction)
 'LazyDictget'
 
The optimal choice of whether to look before you leap i.e., if key in dict_ 
or simply catch KeyError, depends on the ratio of hits to misses.  Google will 
turn up some experimental data on this, but, I seem to recall that if more than 
10% attempts are misses, then LBYL is faster, because raising the exception is slow

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


Re: python cvs interface?

2005-03-09 Thread Jeff Reavis
Corey,
WinCvs can use python for macros, you might want to look at their code:

http://cvs.sourceforge.net/viewcvs.py/cvsgui/cvsgui/PythonLib/cvsgui/

You may also want to look at viewcvs, which is written in Python.

-jjr

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


[German] Deutsche Python Newsgroup ist eingerichtet

2005-03-09 Thread Christian Helmbold
(This posting will be interesting for german speaking folks only.)
Hallo,
die deutsche Pyhton-Newsgroup de.comp.lang.python wurde endlich 
eingerichtet. Vielen Dank an alle, die fuer die Einrichtung gestimmt haben!

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


Re: enum question

2005-03-09 Thread Terry Hancock
On Friday 04 March 2005 02:54 pm, M.N.A.Smadi wrote:
 does python support a C-like enum statement where one can define a 
 variable with prespesified range of values?

No, but in most situations where I would've used an enum, I use a 
trivial class like this:

class states:
ON, OFF, UNKNOWN, UNDEFINED, INCOMPREHENSIBLE, SILLY = range(6)

The values are actually integers of course.  Then I can pass named values to a 
function:

from silly import walk, states

walk(kind=states.SILLY)

If you want to make them more like a bitfield, you could always do this instead:

class properties:
AUDIBLE, VISIBLE, SPEAKABLE = [2**i for i in range(3)]

then you can have, e.g.:

evil(allowed=False, AUDIBLE|VISIBLE|SPEAKABLE)

if mode  AUDIBLE: hear()
if mode  VISIBLE: see()

etc.

Obviously if you want more rigid assurance of the behavior of the variable
in question you'd need more work. But most of the time, enums are just to
make the code more readable, so I do this, which is extremely compact,
and yet pretty clear.  You *can* drop the enum values into the module
namespace, but then importing them is a pain, so I like to qualify them
with the class as shown.

Cheers,
Terry


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

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


Re: [perl-python] a program to delete duplicate files

2005-03-09 Thread Terry Hancock
On Wednesday 09 March 2005 06:56 am, Xah Lee wrote:
 here's a large exercise that uses what we built before.
 
 suppose you have tens of thousands of files in various directories.
 Some of these files are identical, but you don't know which ones are
 identical with which. Write a program that prints out which file are
 redundant copies.

For anyone interested in responding to the above, a starting
place might be this maintenance script I wrote for my own use.  I don't
think it exactly matches the spec, but it addresses the problem.  I wrote
this to clean up a large tree of image files once.  The exact behavior
described requires the '--exec=ls %s' option as mentioned in the help.

#!/usr/bin/env python
# (C) 2003 Anansi Spaceworks
#---
# find_duplicates

Utility to find duplicate files in a directory tree by 
comparing their checksums.

#---
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#---

import os, sys, md5, getopt


def file_walker(tbl, srcpath, files):

Visit a path and collect data (including checksum) for files in it.

for file in files:
filepath = os.path.join(srcpath, file)
if os.path.isfile(filepath):
chksum = md5.new(open(os.path.join(srcpath, file)).read()).digest()
if not tbl.has_key(chksum): tbl[chksum]=[]
tbl[chksum].append(filepath)

def find_duplicates(treeroot, tbl=None):

Find duplicate files in directory.

dup = {}
if tbl is None: tbl = {}
os.path.walk(treeroot, file_walker, tbl)
for k,v in tbl.items():
if len(v)  1:
dup[k] = v
return dup

usage = 
 USAGE: find_duplicates options [path ...]

 Find duplicate files (by matching md5 checksums) in a
 collection of paths (defaults to the current directory).
 
 Note that the order of the paths searched will be retained
 in the resulting duplicate file lists. This can be used
 with --exec and --index to automate handling.

 Options:
   -h, -H, --help
Print this help.

   -q, --quiet
Don't print normal report.

   -x, --exec=command string
Python-formatted command string to act on the indexed
duplicate in each duplicate group found.  E.g. try
--exec=ls %s

   -n, --index=index into duplicates
Which in a series of duplicates to use. Begins with '1'.
Default is '1' (i.e. the first file listed).

  Example:
You've copied many files from path ./A into path ./B. You want
to delete all the ones you've processed already, but not
delete anything else:

% find_duplicates -q --exec=rm %s --index=1 ./A ./B


def main():
action = None
quiet  = 0
index  = 1
dup= {}

opts, args = getopt.getopt(sys.argv[1:], 'qhHn:x:', 
['quiet', 'help', 'exec=', 'index='])

for opt, val in opts:
if   opt in ('-h', '-H', '--help'):
print usage
sys.exit()
elif opt in ('-x', '--exec'):
action = str(val)
elif opt in ('-n', '--index'):
index  = int(val)
elif opt in ('-q', '--quiet'):
quiet = 1

if len(args)==0:
dup = find_duplicates('.')
else:
tbl = {}
for arg in args:
dup = find_duplicates(arg, tbl=tbl)

for k, v in dup.items():
if not quiet:
print Duplicates:
for f in v: print \t%s % f
if action:
os.system(action % v[index-1])

if __name__=='__main__':
main()



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

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


An Odd Little Script

2005-03-09 Thread Greg Lindstrom
Hello-
I have a task which -- dare I say -- would be easy in asbestos_undies 
Perl /asbestos_undies but would rather do in Python (our primary 
language at Novasys).  I have a file with varying length records.  All 
but the first record, that is; it's always 107 bytes long.  What I would 
like to do is strip out all linefeeds from the file, read the character 
in position 107 (the end of segment delimiter) and then replace all of 
the end of segment characters with linefeeds, making a file where each 
segment is on its own line.  Currently, some vendors supply files with 
linefeeds, others don't, and some split the file every 80 bytes.  In 
Perl I would operate on the file in place and be on my way.  The files 
can be quite large, so I'd rather not be making extra copies unless it's 
absolutely essential/required.

I turn to the collective wisdom/trickery of the list to point me in the 
right direction.  How can I perform the above task while keeping my sanity?

Thanks!
--greg
--
Greg Lindstrom   501 975.4859
Computer Programmer  [EMAIL PROTECTED]
NovaSys Health
Little Rock, Arkansas
We are the music makers, and we are the dreamers of dreams.  W.W.
--
http://mail.python.org/mailman/listinfo/python-list


[wxPython] How to allow events during long processing routine?

2005-03-09 Thread Brent W. Hughes
I'm running some code that takes a long time to finish.  I would like the 
user to be able to do other things while it is running.  It seems to me 
there is a function I can call to tell wxPython to process any pending 
messages or events.  I would call this perhaps every 1000 times through my 
loop.  Anybody remember the name of that function?

Brent


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


Re: Web framework

2005-03-09 Thread Fred Pacquier
Gianluca Sartori [EMAIL PROTECTED] said :

 Hi guys,
 What web framework do you suggest to develop with? I had a look both at
 Nevow and Quixote. These seemes to be the most appreciated by the
 community. Anyway, I had no luck looking for a complete and coherent
 documentation.

Snakelets is nice, clean, simple to get started, and well documented. 
Karrigell is about in the same league. CherryPy is a step above (all IMO of 
course).

-- 
YAFAP : http://www.multimania.com/fredp/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python cvs interface?

2005-03-09 Thread corey
Thanks, that looks promising, I'll take a look!

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


Re: An Odd Little Script

2005-03-09 Thread Michael Hoffman
Greg Lindstrom wrote:
I have a file with varying length records.  All 
but the first record, that is; it's always 107 bytes long.  What I would 
like to do is strip out all linefeeds from the file, read the character 
in position 107 (the end of segment delimiter) and then replace all of 
the end of segment characters with linefeeds, making a file where each 
segment is on its own line.
H... here's one way of doing it:
import mmap
import sys
DELIMITER_OFFSET = 107
data_file = file(sys.argv[1], r+w)
data_file.seek(0, 2)
data_length = data_file.tell()
data = mmap.mmap(data_file.fileno(), data_length, access=mmap.ACCESS_WRITE)
delimiter = data[DELIMITER_OFFSET]
for index, char in enumerate(data):
if char == delimiter:
data[index] = \n
data.flush()
There are doubtless more efficient ways, like using mmap.mmap.find()
instead of iterating over every character but that's an exercise for
the reader. And personally I would make extra copies ANYWAY--not doing
so is asking for trouble.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: An Odd Little Script

2005-03-09 Thread Terry Hancock
On Wednesday 09 March 2005 04:06 pm, Greg Lindstrom wrote:
 Hello-
 
 I have a task which -- dare I say -- would be easy in asbestos_undies 
 Perl /asbestos_undies but would rather do in Python (our primary 
 language at Novasys).  I have a file with varying length records.  All 
 but the first record, that is; it's always 107 bytes long.  What I would 
 like to do is strip out all linefeeds from the file, read the character 
 in position 107 (the end of segment delimiter) and then replace all of 
 the end of segment characters with linefeeds, making a file where each 
 segment is on its own line.  Currently, some vendors supply files with 
 linefeeds, others don't, and some split the file every 80 bytes.  In 
 Perl I would operate on the file in place and be on my way.  The files 
 can be quite large, so I'd rather not be making extra copies unless it's 
 absolutely essential/required.

The only problem I see is the in place requirement, which seems silly
unless by quite large you mean multiple gigabytes.  Surely Perl
actually makes a copy in the process even though you never see
it? That much shouldn't be hard, but *actually* doing it in-place
runs into problems with the file data being accidently overwritten,
doesn't it?

I'd make a copy and delete the original afterwards.

delimiter = open('original', 'r').read(108)[107]
# this is actually the 108th character, right?
# if you mean the actual 107th character, that'll be element [106] of course

BLOCKSIZE = 1
inf = open('original', 'r')
ouf = open('result', 'w')

for block in inf.read(BLOCKSIZE):
 block = block.replace('\n', '')
 block = block.replace(delimiter, '\n')
 ouf.write(block)

Now, if we can GUARANTEE that the block never gets longer, it seems
likely that you could actually open the file 'rw' and use the same file handle
for output and input, with explicit seek() and tell() methods being used:

# REALLY, COMPLETELY UNTESTED AND DANGEROUS

delimiter = open('original', 'r').read(108)[107]  # this is actually the 108th 
character, right?
BLOCKSIZE = 1
f = open('didnt_really_want_that_file_anyway.dat', 'rw')

def indata(fp, sz):
data = fp.read(sz)
pos   = fp.tell()
return data, pos

def outdata(fp, pos, data):
fp.seek(pos)
fp.write(data)
pos  = fp.tell()
return pos

outpos = 0
for block, inpos in indata(f,BLOCKSIZE):
 block = block.replace('\n', '')
 block = block.replace(delimiter, '\n')
 outpos = outdata(f, outpos, block)

# TOTALLY UNTESTED!

I can imagine evil operating system behavior that could make this trash the 
file,
BTW, such as reading or writing data in blocks.  I'd want to test to make sure
such things don't happen (or that Python magically compensates somehow).

But is it really worth that?

Cheers,
Terry

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

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


Re: Web framework

2005-03-09 Thread Phil Jackson
Gianluca Sartori [EMAIL PROTECTED] writes:

 What web framework do you suggest to develop with?

I tend to use mod_python.

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


Share a accomodation at PyCon from march 22-27?

2005-03-09 Thread Gregoire Weber
Hi Guys,
is someone interested in sharing accomodation during the upcoming PyCon?
I'll be there from the 22 to 27th of march (five nights).
Gregoire
--
http://mail.python.org/mailman/listinfo/python-list


Re: Recognizing the Arrival of a New File

2005-03-09 Thread Chris Green
Greg Lindstrom [EMAIL PROTECTED] writes:

 Hello-
 I am writing an application where I need to recognize when a file 
 arrives in a given directory.  Files may arrive at any time during the 
 course of the day.  Do I set up a cron job to poll the directory every 
 few minutes?  Write a daemon to monitor the directory?  Or is there some 
 other more common/accepted way to perform this task?  I'm using Python 
 2.3 on Linux.

At my last job, we had a similar problem and I wanted to be able to
check that the file was closed by the application that was putting it
there (in that case the application was w32 writing to a share via
samba).

http://cmg.dok.org/cgi-bin/pyblosxom.cgi/python/linuxlease/

Every other way I could find that relied on simple FS semantics had
the possibility of reading a file partially.
-- 
Chris Green [EMAIL PROTECTED]
Eschew obfuscation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An Odd Little Script

2005-03-09 Thread James Stroud
This might be hack-ish, more elegant solutions are likely to exist, but this 
is the general idea:

LINEFEED = \n  # or whatever
EOR = ?# or whatever

def fixEOR(filename):
  f = open(filename,r+)
  byte = True
  # loops through whole file
  while True:
# loops through record
while byte and (byte != EOR):
  byte=f.read(1)
if not byte:
  break
f.seek(-1,1)# backup 1
byte = LINEFEED
f.write(byte)   # incidentally, will put LINEFEED at EOF
f.flush()
  f.close()



On Wednesday 09 March 2005 02:06 pm, Greg Lindstrom wrote:
 Hello-

 I have a task which -- dare I say -- would be easy in asbestos_undies
 Perl /asbestos_undies but would rather do in Python (our primary
 language at Novasys).  I have a file with varying length records.  All
 but the first record, that is; it's always 107 bytes long.  What I would
 like to do is strip out all linefeeds from the file, read the character
 in position 107 (the end of segment delimiter) and then replace all of
 the end of segment characters with linefeeds, making a file where each
 segment is on its own line.  Currently, some vendors supply files with
 linefeeds, others don't, and some split the file every 80 bytes.  In
 Perl I would operate on the file in place and be on my way.  The files
 can be quite large, so I'd rather not be making extra copies unless it's
 absolutely essential/required.

 I turn to the collective wisdom/trickery of the list to point me in the
 right direction.  How can I perform the above task while keeping my sanity?

 Thanks!
 --greg
 --
 Greg Lindstrom   501 975.4859
 Computer Programmer  [EMAIL PROTECTED]
 NovaSys Health
 Little Rock, Arkansas

 We are the music makers, and we are the dreamers of dreams.  W.W.

-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An Odd Little Script

2005-03-09 Thread M.E.Farmer
Greg Lindstrom wrote:
 Hello-

 I have a task which -- dare I say -- would be easy in
asbestos_undies
 Perl /asbestos_undies but would rather do in Python (our primary
 language at Novasys).  I have a file with varying length records.
All
 but the first record, that is; it's always 107 bytes long.  What I
would
 like to do is strip out all linefeeds from the file, read the
character
 in position 107 (the end of segment delimiter) and then replace all
of
 the end of segment characters with linefeeds, making a file where
each
 segment is on its own line.  Currently, some vendors supply files
with
 linefeeds, others don't, and some split the file every 80 bytes.  In
 Perl I would operate on the file in place and be on my way.  The
files
 can be quite large, so I'd rather not be making extra copies unless
it's
 absolutely essential/required.

 I turn to the collective wisdom/trickery of the list to point me in
the
 right direction.  How can I perform the above task while keeping my
sanity?

 Thanks!
 --greg
 --
 Greg Lindstrom   501 975.4859
 Computer Programmer  [EMAIL PROTECTED]
 NovaSys Health
 Little Rock, Arkansas

 We are the music makers, and we are the dreamers of dreams.  W.W.

This should be fairly simple, but maybe not ;)
# get the end of segment character
# this is not optimal but should be a start
f = open('yourrecord', 'r')
eos  = f.seek(107).read(1)
r = f.read()
f.close()
r = r.replace('\r', '')
r = r.replace('\n', '')
r = r.replace(eos, '\n')
f = open('yourrecord', 'w')
f.write(r)
f.close()

hth,
M.E.Farmer

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


Re: An Odd Little Script

2005-03-09 Thread Benji York
Greg Lindstrom wrote:
I have a task which -- dare I say -- would be easy in asbestos_undies 
Perl /asbestos_undies but would rather do in Python (our primary 
language at Novasys).  I have a file with varying length records.  All 
but the first record, that is; it's always 107 bytes long.  
I intuit that you are dealing with EDI documents.  If so, there have 
been some recent discussions (and code) here.  This Google Groups search 
will probably help: 
http://groups-beta.google.com/groups?q=group:comp.lang.python+edistart=0scoring=d;
(http://tinyurl.com/6urby).
--
Benji York
Sr. Software Engineer
Zope Corporation
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Jeff Epler
untested

def my_getter(m, i, f):
try:
return m[i]
except (KeyError, IndexError):
return f()

my_getter(d, 'x', bigscaryfunction)
my_getter(d, 'y', lambda: scaryinlineexpresion)


pgp04VRKFqQL1.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   >