Kurukshetra Online Programming Contest

2006-12-29 Thread ravehanker
Hello There!

College of Engineering, Guindy announces the Kurukshetra Online
Programming Contest
as a part of it's Inter-departmental Tech. Fest, Kurukshetra.
The event is your opportunity to compete with the World's best coders
with algorithm-centric problems that will rattle your grey matter!

The event is to be held on December 31th and is open to all.

Date: 31-December-2006
Timings : 14:00hrs - 20:00 hrs
Max. Team Size : 3

Prizes Worth 2000 USD!!

Do visit http://opc.kurukshetra.org.in and register for the event.

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


Re: how to serve image files without disk use?

2006-12-29 Thread Tom Plunket
Ray Schumacher wrote:

 But, how can I avoid disk writes? wx's *.SaveFile() needs a string 
 file name (no objects).
 I'm going to investigate PIL's im.save(), as it appears to allow 
 file-objects.

Take a look at the img2*.py files in wx.tools.  They're sorta sketchy
imo, but they do the trick.  encode_bitmaps.py, with the wx demo app, is
used to generate all of the bitmap data that's in Python files embedded
into the app, and following the chain of logic from there might yield
you something interesting.

Mind, I haven't tried it myself, but it's where I'd start looking.

Good luck,
-tom!

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


Re: A stupid question

2006-12-29 Thread Tom Plunket
luxnoctis wrote:

 It says exactly:
 
 The specified module could not be found.
 LoadLibrary(pythondll) failed
 
 Don't know if that helps at all.

There's something installed on Compaq computers that uses the Python
stuff too, but I never figured out what it was.  I figured it may have
been some of the preloaded games, 'cause when I restored a roommate's
machine from the restore image the Python22 folder was among the things
that appeared on the fresh machine.  It was actually pretty exciting for
me since I needed to write a little utility to do something on this
machine, but it was slow as death and only had dialup and I really
didn't want to deal with downloading and installing that stuff myself.

...of course your first problem is buying a machine with a ton of
shovelware on it.  Second problem is uninstalling stuff without knowing
what it's for.


-tom!

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


Re: Convert Perl to Python

2006-12-29 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED],
Χρυσάνθη Αϊναλή wrote:

 How can I convert a perl script to Python?

Look what the Perl script does and then rewrite it in Python.  Automatic
translations between programming languages, if possible, usually result in
code that is not supposed to be read by human beings.  Every language has
its idioms and a literal translation looks very odd to native speakers
of the target language.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Convert Perl to Python

2006-12-29 Thread Tim Daneliuk
Marc 'BlackJack' Rintsch wrote:
 In [EMAIL PROTECTED],
 Χρυσάνθη Αϊναλή wrote:
 
 How can I convert a perl script to Python?
 
 Look what the Perl script does and then rewrite it in Python.  Automatic
 translations between programming languages, if possible, usually result in
 code that is not supposed to be read by human beings.  Every language has
 its idioms and a literal translation looks very odd to native speakers
 of the target language.
 
 Ciao,
   Marc 'BlackJack' Rintsch


Either that or write a perl interpreter in python   ;)

-- 

Tim Daneliuk [EMAIL PROTECTED]
PGP Key: http://www.tundraware.com/PGP/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Starting a child process and getting its stdout?

2006-12-29 Thread Tom Plunket
cypher543 wrote:

 This has been driving me insane for the last hour or so. I have search
 everywhere, and nothing works. I am trying to use the subprocess module
 to run a program and get its output line by line. But, it always waits
 for the process to terminate and then return the output all at once.

Right, you need to use subprocess.PIPE and polling of the process and
the pipe to get it to do what you want.  Hopefully this makes sense, I
also hope it'll work on Linux but can't imagine why it wouldn't.

Save this code to a file, name unimportant.  Executing the file will
fire the top clause of the if statement, the bit that runs the parent
part.  That starts the script again as a subprocess, which triggers the
else clause.  Hope it makes sense.

Depending on your environment, you might need 'shell=True' in your Popen
args.  On Windows, that is required if you want to prevent a console
window from popping up if you're running in a GUI app.

-tom!

--

import subprocess
import sys
import time

if len(sys.argv) == 1:
# no command line arg means, we're the parent process.
print 'starting parent process.'
myName = sys.argv[0]

# launch the subprocess with an additional parameter, to trigger
# else clause below.
p = subprocess.Popen(
( 'python', '-u', myName, 'x' ),
stdout=subprocess.PIPE
)

while p.poll() == None:
data = p.stdout.readline()
if data:
print data,

print 'process ended with return code', p.returncode

else:
# assume the command-line arg means run the background process
print 'starting subprocess'

for i in range(10):
time.sleep(.25)
print i

sys.exit(14)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting a child process and getting its stdout?

2006-12-29 Thread Tom Plunket
Tom Plunket wrote:

   while p.poll() == None:
   data = p.stdout.readline()
   if data:
   print data,

If you change that print to something more decorated, like,

   print 'process said:', data,

Then it might be more obvious where/how the print statements are getting
routed.

Keep in mind that readline() will return one line at a time, and that
line will end with a newline, although the last line you get (at EOF)
may not have one.

again, good luck.  Hope this helps,
-tom!

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


Re: db access

2006-12-29 Thread king kikapu

Hi Johnf,

are you referring to this ?
http://www.freetds.org/

And how i can get psmssql.py so i can get a shot on it, is it included
in FreeTDS ??



On Dec 29, 12:12 am, johnf [EMAIL PROTECTED] wrote:
 king kikapu wrote:
  Hi to all,

  is there a way to use an RDBMS (in my case, SQL Server) from Python by
  using some built-in module of the language (v. 2.5) and through ODBC ??
  I saw some samples that use statements like import dbi or import
  odbc but neither modules (dbi, odbc) are present on my system...

  Any hint(s) ??

  Thanks in advanceAlthough others have suggested using ODBC or ADO I have a 
  different
 solution.  If you wanted a multi-platform I would use FreeTDS with
 psmssql.py.  psmssql.py does support the DB API 2.0 although it does not
 support any of the extendsions.  Works with Linux, Mac and Windows.
 
 Johnf

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


Re: Convert Perl to Python

2006-12-29 Thread Emilio Sañudo
http://www.crazy-compilers.com/bridgekeeper/

 ?? wrote:
 How can I convert a perl script to Python?

 Thank you!
   

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


Re: Reverse of SendKeys??

2006-12-29 Thread Sebastian 'lunar' Wiesner
Erik Johnson ej at somewhere.com  typed

 Aside from the obvious security issues such a program would
 represent (and your name and signature are curious in that respect as
 well), you are basically asking for functionality (i.e., a key logger)
 I believe to be outside what is offered by Python and/or the API of
 most operating systems.

I agree on the security issues, and on the statement, that writing a key
logger is outside the scope of the standard python library. But it is
easily possible to write a key logger using the API of common operating
systems. Windows provides hooks for intercepting messages from input
devices such as keyboard and mouse. On Linux you can either write a
kernel module, which is the less portable, but more effective way, or
you can code a X11 key logger, which will also work on other unix-like
systems with a working X11 installation.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
-- 
http://mail.python.org/mailman/listinfo/python-list


INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
I don't know whether anyone can help, but I have an odd problem. I have
a PSP (Spyce) script that makes many calls to populate a database. They
all work without any problem except for one statement.

I first connect to the database...

self.con = MySQLdb.connect(user=username, passwd =password)
self.cursor = self.con.cursor()
self.cursor.execute(SET max_error_count=0)

All the neccesary tables are created...

self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
self.cursor.execute(USE +name)

self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
varchar(20))

Then I execute many insert statements in various different loops on
various tables, all of which are fine, and result in multiple table
entries. The following one is executed many times also. and seems
identical to the rest. The print statements output to the browser
window, and appear repeatedly, so the query must be being called
repeatedly also:

print pbSQL query executing/bp
self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
','c','2','e','f','g'))
print pbSQL query executed/bp

I have, for debugging, set i up as a counter variable.

No errors are given, but the only entry to appear in the final database
is that from the final execution of the INSERT statement (the last
value of i)

I suspect that this is to vague for anyone to be able to help, but if
anyone has any ideas I'd be really grateful :-)

It occured to me that if I could access the mysql query log that might
help, but I was unsure how to enable logging for MysQL with python.
 
Cheers,

Ben

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Well that's odd...

If I place the exact same Insert statement elswhere in the program it
works as intended.
That would suggest it is never being run in its old position, but the
statements either side of it are printing...


Ben wrote:
 I don't know whether anyone can help, but I have an odd problem. I have
 a PSP (Spyce) script that makes many calls to populate a database. They
 all work without any problem except for one statement.

 I first connect to the database...

 self.con = MySQLdb.connect(user=username, passwd =password)
 self.cursor = self.con.cursor()
 self.cursor.execute(SET max_error_count=0)

 All the neccesary tables are created...

 self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
 self.cursor.execute(USE +name)

 self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
 varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
 varchar(20))

 Then I execute many insert statements in various different loops on
 various tables, all of which are fine, and result in multiple table
 entries. The following one is executed many times also. and seems
 identical to the rest. The print statements output to the browser
 window, and appear repeatedly, so the query must be being called
 repeatedly also:

 print pbSQL query executing/bp
 self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
 ','c','2','e','f','g'))
 print pbSQL query executed/bp

 I have, for debugging, set i up as a counter variable.

 No errors are given, but the only entry to appear in the final database
 is that from the final execution of the INSERT statement (the last
 value of i)

 I suspect that this is to vague for anyone to be able to help, but if
 anyone has any ideas I'd be really grateful :-)

 It occured to me that if I could access the mysql query log that might
 help, but I was unsure how to enable logging for MysQL with python.
  
 Cheers,
 
 Ben

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


Re: add encoding to standard encodings works different in python 2.5?

2006-12-29 Thread Henk-Jan Ebbers
OK, I am trying to register my codecs, with codecs.register
Looking at the python doc, this seems to work different in 2.4/2.5
Can somebody help me with an example of how to register a codec?
I do not understand how this works.

regards, Henk-jan

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread johnf
Ben wrote:

 I don't know whether anyone can help, but I have an odd problem. I have
 a PSP (Spyce) script that makes many calls to populate a database. They
 all work without any problem except for one statement.
 
 I first connect to the database...
 
 self.con = MySQLdb.connect(user=username, passwd =password)
 self.cursor = self.con.cursor()
 self.cursor.execute(SET max_error_count=0)
 
 All the neccesary tables are created...
 
 self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
 self.cursor.execute(USE +name)
 
 self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
 varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
 varchar(20))
 
 Then I execute many insert statements in various different loops on
 various tables, all of which are fine, and result in multiple table
 entries. The following one is executed many times also. and seems
 identical to the rest. The print statements output to the browser
 window, and appear repeatedly, so the query must be being called
 repeatedly also:
 
 print pbSQL query executing/bp
 self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
 ','c','2','e','f','g'))
 print pbSQL query executed/bp
 
 I have, for debugging, set i up as a counter variable.
 
 No errors are given, but the only entry to appear in the final database
 is that from the final execution of the INSERT statement (the last
 value of i)
 
 I suspect that this is to vague for anyone to be able to help, but if
 anyone has any ideas I'd be really grateful :-)
 
 It occured to me that if I could access the mysql query log that might
 help, but I was unsure how to enable logging for MysQL with python.
  
 Cheers,
 
 Ben

Not sure this will help but where is the commit?  I don't use MySQL but
most SQL engines require a commit.
Johnf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Anyone persuaded by merits of Lisp vs Python?

2006-12-29 Thread Paddy

Carl Banks wrote:
 If you were so keen on avoiding a flame war, the first thing you should
 have done is to not cross-post this.

I want to cover Pythonistas looking at Lisp and Lispers looking at
Python because of the thread. The cross posting is not as flame bait.

- Paddy.

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


I want to see all the variables

2006-12-29 Thread johnf
Hi,
When I use dir() I don't see the __ underscore items.  Is there anything
that will show all the private vars and functions?

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben

Ben wrote:
 Well that's odd...

 If I place the exact same Insert statement elswhere in the program it
 works as intended.
 That would suggest it is never being run in its old position, but the
 statements either side of it are printing...


 Ben wrote:
  I don't know whether anyone can help, but I have an odd problem. I have
  a PSP (Spyce) script that makes many calls to populate a database. They
  all work without any problem except for one statement.
 
  I first connect to the database...
 
  self.con = MySQLdb.connect(user=username, passwd =password)
  self.cursor = self.con.cursor()
  self.cursor.execute(SET max_error_count=0)
 
  All the neccesary tables are created...
 
  self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
  self.cursor.execute(USE +name)
 
  self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
  varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
  varchar(20))
 
  Then I execute many insert statements in various different loops on
  various tables, all of which are fine, and result in multiple table
  entries. The following one is executed many times also. and seems
  identical to the rest. The print statements output to the browser
  window, and appear repeatedly, so the query must be being called
  repeatedly also:
 
  print pbSQL query executing/bp
  self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
  ','c','2','e','f','g'))
  print pbSQL query executed/bp
 
  I have, for debugging, set i up as a counter variable.
 
  No errors are given, but the only entry to appear in the final database
  is that from the final execution of the INSERT statement (the last
  value of i)
 
  I suspect that this is to vague for anyone to be able to help, but if
  anyone has any ideas I'd be really grateful :-)
 
  It occured to me that if I could access the mysql query log that might
  help, but I was unsure how to enable logging for MysQL with python.
 
  Cheers,
 
  Ben

Well, it would appear to be some kind of autocommit problem. I had
autocommit off, bus committed when I disconnected from the database.
For some reason although all the other statements seemed ok, multiple
statements in that loop were'nt every commiting. For the moment I've
turned autocommit on and that has sorted things out, but it slows
things down too so I'll try to fix it :-)

Ben

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
I initially had it set up so that when I connected to the database I
started a transaction, then when I disconnected I commited.

I then tried turning autocommit on, but that didn't seem to make any
difference (althouh initially I thought it had)

I'll go back and see what I can find...
Cheers,
Ben


johnf wrote:
 Ben wrote:

  I don't know whether anyone can help, but I have an odd problem. I have
  a PSP (Spyce) script that makes many calls to populate a database. They
  all work without any problem except for one statement.
 
  I first connect to the database...
 
  self.con = MySQLdb.connect(user=username, passwd =password)
  self.cursor = self.con.cursor()
  self.cursor.execute(SET max_error_count=0)
 
  All the neccesary tables are created...
 
  self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
  self.cursor.execute(USE +name)
 
  self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
  varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
  varchar(20))
 
  Then I execute many insert statements in various different loops on
  various tables, all of which are fine, and result in multiple table
  entries. The following one is executed many times also. and seems
  identical to the rest. The print statements output to the browser
  window, and appear repeatedly, so the query must be being called
  repeatedly also:
 
  print pbSQL query executing/bp
  self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
  ','c','2','e','f','g'))
  print pbSQL query executed/bp
 
  I have, for debugging, set i up as a counter variable.
 
  No errors are given, but the only entry to appear in the final database
  is that from the final execution of the INSERT statement (the last
  value of i)
 
  I suspect that this is to vague for anyone to be able to help, but if
  anyone has any ideas I'd be really grateful :-)
 
  It occured to me that if I could access the mysql query log that might
  help, but I was unsure how to enable logging for MysQL with python.
 
  Cheers,
 
  Ben

 Not sure this will help but where is the commit?  I don't use MySQL but
 most SQL engines require a commit.
 Johnf

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
One partial explanation might be that for some reason it is recreating
the table each time the code runs. My code says CREATE TABLE IF NOT
EXISTS but if for some reason it is creating it anyway and dropping
the one before that could explain why there are missing entires.

It wouldn't explain why the NOT EXISTS line is being ignored though...

Ben


Ben wrote:
 I initially had it set up so that when I connected to the database I
 started a transaction, then when I disconnected I commited.

 I then tried turning autocommit on, but that didn't seem to make any
 difference (althouh initially I thought it had)

 I'll go back and see what I can find...
 Cheers,
 Ben


 johnf wrote:
  Ben wrote:
 
   I don't know whether anyone can help, but I have an odd problem. I have
   a PSP (Spyce) script that makes many calls to populate a database. They
   all work without any problem except for one statement.
  
   I first connect to the database...
  
   self.con = MySQLdb.connect(user=username, passwd =password)
   self.cursor = self.con.cursor()
   self.cursor.execute(SET max_error_count=0)
  
   All the neccesary tables are created...
  
   self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
   self.cursor.execute(USE +name)
  
   self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
   varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
   varchar(20))
  
   Then I execute many insert statements in various different loops on
   various tables, all of which are fine, and result in multiple table
   entries. The following one is executed many times also. and seems
   identical to the rest. The print statements output to the browser
   window, and appear repeatedly, so the query must be being called
   repeatedly also:
  
   print pbSQL query executing/bp
   self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
   ','c','2','e','f','g'))
   print pbSQL query executed/bp
  
   I have, for debugging, set i up as a counter variable.
  
   No errors are given, but the only entry to appear in the final database
   is that from the final execution of the INSERT statement (the last
   value of i)
  
   I suspect that this is to vague for anyone to be able to help, but if
   anyone has any ideas I'd be really grateful :-)
  
   It occured to me that if I could access the mysql query log that might
   help, but I was unsure how to enable logging for MysQL with python.
  
   Cheers,
  
   Ben
 
  Not sure this will help but where is the commit?  I don't use MySQL but
  most SQL engines require a commit.
  Johnf

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


Re: Scaling pictures

2006-12-29 Thread Kajsa Anka
On Thu, 28 Dec 2006 11:53:41 +0100, Kajsa Anka wrote
(in article [EMAIL PROTECTED]):

Thanks for the answers, I'll use PIL.

  jem

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Each time my script is run, the following is called:

self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
self.cursor.execute(USE +name)
self.cursor.execute(CREATE TABLE IF NOT EXISTS table_name ( 

The idea being that stuf is only created the first time the script is
run, and after that the original tables and database is used. This
might explain my pronblem if for some reason the old tables are being
replaced... can anyone see anything wrong with the above?

Ben






Ben wrote:
 One partial explanation might be that for some reason it is recreating
 the table each time the code runs. My code says CREATE TABLE IF NOT
 EXISTS but if for some reason it is creating it anyway and dropping
 the one before that could explain why there are missing entires.

 It wouldn't explain why the NOT EXISTS line is being ignored though...

 Ben


 Ben wrote:
  I initially had it set up so that when I connected to the database I
  started a transaction, then when I disconnected I commited.
 
  I then tried turning autocommit on, but that didn't seem to make any
  difference (althouh initially I thought it had)
 
  I'll go back and see what I can find...
  Cheers,
  Ben
 
 
  johnf wrote:
   Ben wrote:
  
I don't know whether anyone can help, but I have an odd problem. I have
a PSP (Spyce) script that makes many calls to populate a database. They
all work without any problem except for one statement.
   
I first connect to the database...
   
self.con = MySQLdb.connect(user=username, passwd =password)
self.cursor = self.con.cursor()
self.cursor.execute(SET max_error_count=0)
   
All the neccesary tables are created...
   
self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
self.cursor.execute(USE +name)
   
self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
varchar(20))
   
Then I execute many insert statements in various different loops on
various tables, all of which are fine, and result in multiple table
entries. The following one is executed many times also. and seems
identical to the rest. The print statements output to the browser
window, and appear repeatedly, so the query must be being called
repeatedly also:
   
print pbSQL query executing/bp
self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
','c','2','e','f','g'))
print pbSQL query executed/bp
   
I have, for debugging, set i up as a counter variable.
   
No errors are given, but the only entry to appear in the final database
is that from the final execution of the INSERT statement (the last
value of i)
   
I suspect that this is to vague for anyone to be able to help, but if
anyone has any ideas I'd be really grateful :-)
   
It occured to me that if I could access the mysql query log that might
help, but I was unsure how to enable logging for MysQL with python.
   
Cheers,
   
Ben
  
   Not sure this will help but where is the commit?  I don't use MySQL but
   most SQL engines require a commit.
   Johnf

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Nope... that can't be it. I tried running those commands manually and
nothing went wrong.
But then again when I execute the problematic command manually nothing
goes wrong. Its just not executing until the last time, or being
overwritten.


Ben wrote:
 Each time my script is run, the following is called:

 self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
 self.cursor.execute(USE +name)
 self.cursor.execute(CREATE TABLE IF NOT EXISTS table_name ( 

 The idea being that stuf is only created the first time the script is
 run, and after that the original tables and database is used. This
 might explain my pronblem if for some reason the old tables are being
 replaced... can anyone see anything wrong with the above?

 Ben






 Ben wrote:
  One partial explanation might be that for some reason it is recreating
  the table each time the code runs. My code says CREATE TABLE IF NOT
  EXISTS but if for some reason it is creating it anyway and dropping
  the one before that could explain why there are missing entires.
 
  It wouldn't explain why the NOT EXISTS line is being ignored though...
 
  Ben
 
 
  Ben wrote:
   I initially had it set up so that when I connected to the database I
   started a transaction, then when I disconnected I commited.
  
   I then tried turning autocommit on, but that didn't seem to make any
   difference (althouh initially I thought it had)
  
   I'll go back and see what I can find...
   Cheers,
   Ben
  
  
   johnf wrote:
Ben wrote:
   
 I don't know whether anyone can help, but I have an odd problem. I 
 have
 a PSP (Spyce) script that makes many calls to populate a database. 
 They
 all work without any problem except for one statement.

 I first connect to the database...

 self.con = MySQLdb.connect(user=username, passwd =password)
 self.cursor = self.con.cursor()
 self.cursor.execute(SET max_error_count=0)

 All the neccesary tables are created...

 self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
 self.cursor.execute(USE +name)

 self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
 varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
 varchar(20))

 Then I execute many insert statements in various different loops on
 various tables, all of which are fine, and result in multiple table
 entries. The following one is executed many times also. and seems
 identical to the rest. The print statements output to the browser
 window, and appear repeatedly, so the query must be being called
 repeatedly also:

 print pbSQL query executing/bp
 self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
 ','c','2','e','f','g'))
 print pbSQL query executed/bp

 I have, for debugging, set i up as a counter variable.

 No errors are given, but the only entry to appear in the final 
 database
 is that from the final execution of the INSERT statement (the last
 value of i)

 I suspect that this is to vague for anyone to be able to help, but if
 anyone has any ideas I'd be really grateful :-)

 It occured to me that if I could access the mysql query log that might
 help, but I was unsure how to enable logging for MysQL with python.

 Cheers,

 Ben
   
Not sure this will help but where is the commit?  I don't use MySQL 
but
most SQL engines require a commit.
Johnf

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Well, I've checked the SQL log, and my insert statements are certainly
being logged. The only option left open is that the table in question
is being replaced, but I can't see why it should be...


Ben wrote:
 Nope... that can't be it. I tried running those commands manually and
 nothing went wrong.
 But then again when I execute the problematic command manually nothing
 goes wrong. Its just not executing until the last time, or being
 overwritten.


 Ben wrote:
  Each time my script is run, the following is called:
 
  self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
  self.cursor.execute(USE +name)
  self.cursor.execute(CREATE TABLE IF NOT EXISTS table_name ( 
 
  The idea being that stuf is only created the first time the script is
  run, and after that the original tables and database is used. This
  might explain my pronblem if for some reason the old tables are being
  replaced... can anyone see anything wrong with the above?
 
  Ben
 
 
 
 
 
 
  Ben wrote:
   One partial explanation might be that for some reason it is recreating
   the table each time the code runs. My code says CREATE TABLE IF NOT
   EXISTS but if for some reason it is creating it anyway and dropping
   the one before that could explain why there are missing entires.
  
   It wouldn't explain why the NOT EXISTS line is being ignored though...
  
   Ben
  
  
   Ben wrote:
I initially had it set up so that when I connected to the database I
started a transaction, then when I disconnected I commited.
   
I then tried turning autocommit on, but that didn't seem to make any
difference (althouh initially I thought it had)
   
I'll go back and see what I can find...
Cheers,
Ben
   
   
johnf wrote:
 Ben wrote:

  I don't know whether anyone can help, but I have an odd problem. I 
  have
  a PSP (Spyce) script that makes many calls to populate a database. 
  They
  all work without any problem except for one statement.
 
  I first connect to the database...
 
  self.con = MySQLdb.connect(user=username, passwd =password)
  self.cursor = self.con.cursor()
  self.cursor.execute(SET max_error_count=0)
 
  All the neccesary tables are created...
 
  self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
  self.cursor.execute(USE +name)
 
  self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
  varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
  varchar(20))
 
  Then I execute many insert statements in various different loops on
  various tables, all of which are fine, and result in multiple table
  entries. The following one is executed many times also. and seems
  identical to the rest. The print statements output to the browser
  window, and appear repeatedly, so the query must be being called
  repeatedly also:
 
  print pbSQL query executing/bp
  self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
  ','c','2','e','f','g'))
  print pbSQL query executed/bp
 
  I have, for debugging, set i up as a counter variable.
 
  No errors are given, but the only entry to appear in the final 
  database
  is that from the final execution of the INSERT statement (the last
  value of i)
 
  I suspect that this is to vague for anyone to be able to help, but 
  if
  anyone has any ideas I'd be really grateful :-)
 
  It occured to me that if I could access the mysql query log that 
  might
  help, but I was unsure how to enable logging for MysQL with python.
 
  Cheers,
 
  Ben

 Not sure this will help but where is the commit?  I don't use MySQL 
 but
 most SQL engines require a commit.
 Johnf

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


list looping error

2006-12-29 Thread Gigs_
i have created list x:
  x = [(12, 22, 11), (13, 22, 33)]

and want to print each number in tuple
  for i in x:
for j in i:
print j[0]

but I get this error. What does it means?   
Traceback (most recent call last):
   File pyshell#60, line 3, in module
 print j[0]
TypeError: 'int' object is unsubscriptable


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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
I have found the problem, but not the cause.

I tried setting the database up manually before hand, which let me get
rid of the IF NOT EXISTS lines, and now it works!

But why the *** should it not work anyway? The first time it is run, no
database or tables, so it creates them. That works. But apparentlyu on
subsequent runs it decides the tables it created arent' actually there,
and overwrites them. Gr.


Ben



Ben wrote:
 Well, I've checked the SQL log, and my insert statements are certainly
 being logged. The only option left open is that the table in question
 is being replaced, but I can't see why it should be...


 Ben wrote:
  Nope... that can't be it. I tried running those commands manually and
  nothing went wrong.
  But then again when I execute the problematic command manually nothing
  goes wrong. Its just not executing until the last time, or being
  overwritten.
 
 
  Ben wrote:
   Each time my script is run, the following is called:
  
   self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
   self.cursor.execute(USE +name)
   self.cursor.execute(CREATE TABLE IF NOT EXISTS table_name ( 
  
   The idea being that stuf is only created the first time the script is
   run, and after that the original tables and database is used. This
   might explain my pronblem if for some reason the old tables are being
   replaced... can anyone see anything wrong with the above?
  
   Ben
  
  
  
  
  
  
   Ben wrote:
One partial explanation might be that for some reason it is recreating
the table each time the code runs. My code says CREATE TABLE IF NOT
EXISTS but if for some reason it is creating it anyway and dropping
the one before that could explain why there are missing entires.
   
It wouldn't explain why the NOT EXISTS line is being ignored though...
   
Ben
   
   
Ben wrote:
 I initially had it set up so that when I connected to the database I
 started a transaction, then when I disconnected I commited.

 I then tried turning autocommit on, but that didn't seem to make any
 difference (althouh initially I thought it had)

 I'll go back and see what I can find...
 Cheers,
 Ben


 johnf wrote:
  Ben wrote:
 
   I don't know whether anyone can help, but I have an odd problem. 
   I have
   a PSP (Spyce) script that makes many calls to populate a 
   database. They
   all work without any problem except for one statement.
  
   I first connect to the database...
  
   self.con = MySQLdb.connect(user=username, passwd =password)
   self.cursor = self.con.cursor()
   self.cursor.execute(SET max_error_count=0)
  
   All the neccesary tables are created...
  
   self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
   self.cursor.execute(USE +name)
  
   self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
   varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
   varchar(20))
  
   Then I execute many insert statements in various different loops 
   on
   various tables, all of which are fine, and result in multiple 
   table
   entries. The following one is executed many times also. and seems
   identical to the rest. The print statements output to the browser
   window, and appear repeatedly, so the query must be being called
   repeatedly also:
  
   print pbSQL query executing/bp
   self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
   ','c','2','e','f','g'))
   print pbSQL query executed/bp
  
   I have, for debugging, set i up as a counter variable.
  
   No errors are given, but the only entry to appear in the final 
   database
   is that from the final execution of the INSERT statement (the last
   value of i)
  
   I suspect that this is to vague for anyone to be able to help, 
   but if
   anyone has any ideas I'd be really grateful :-)
  
   It occured to me that if I could access the mysql query log that 
   might
   help, but I was unsure how to enable logging for MysQL with 
   python.
  
   Cheers,
  
   Ben
 
  Not sure this will help but where is the commit?  I don't use 
  MySQL but
  most SQL engines require a commit.
  Johnf

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Perhaps when I'm checking for table existance using mysql through
python I have to be more explicit:

Where I did have:
USE database;
IF NOT EXISTS CREATE table(.

Perhaps I need:
USE database;
IF NOT EXISTS CREATE database.table(.

I'll try it after lunch. Does anyoone know whether this might be the
problem?

Ben


Ben wrote:
 I have found the problem, but not the cause.

 I tried setting the database up manually before hand, which let me get
 rid of the IF NOT EXISTS lines, and now it works!

 But why the *** should it not work anyway? The first time it is run, no
 database or tables, so it creates them. That works. But apparentlyu on
 subsequent runs it decides the tables it created arent' actually there,
 and overwrites them. Gr.


 Ben



 Ben wrote:
  Well, I've checked the SQL log, and my insert statements are certainly
  being logged. The only option left open is that the table in question
  is being replaced, but I can't see why it should be...
 
 
  Ben wrote:
   Nope... that can't be it. I tried running those commands manually and
   nothing went wrong.
   But then again when I execute the problematic command manually nothing
   goes wrong. Its just not executing until the last time, or being
   overwritten.
  
  
   Ben wrote:
Each time my script is run, the following is called:
   
self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
self.cursor.execute(USE +name)
self.cursor.execute(CREATE TABLE IF NOT EXISTS table_name ( 
   
The idea being that stuf is only created the first time the script is
run, and after that the original tables and database is used. This
might explain my pronblem if for some reason the old tables are being
replaced... can anyone see anything wrong with the above?
   
Ben
   
   
   
   
   
   
Ben wrote:
 One partial explanation might be that for some reason it is recreating
 the table each time the code runs. My code says CREATE TABLE IF NOT
 EXISTS but if for some reason it is creating it anyway and dropping
 the one before that could explain why there are missing entires.

 It wouldn't explain why the NOT EXISTS line is being ignored though...

 Ben


 Ben wrote:
  I initially had it set up so that when I connected to the database I
  started a transaction, then when I disconnected I commited.
 
  I then tried turning autocommit on, but that didn't seem to make any
  difference (althouh initially I thought it had)
 
  I'll go back and see what I can find...
  Cheers,
  Ben
 
 
  johnf wrote:
   Ben wrote:
  
I don't know whether anyone can help, but I have an odd 
problem. I have
a PSP (Spyce) script that makes many calls to populate a 
database. They
all work without any problem except for one statement.
   
I first connect to the database...
   
self.con = MySQLdb.connect(user=username, passwd =password)
self.cursor = self.con.cursor()
self.cursor.execute(SET max_error_count=0)
   
All the neccesary tables are created...
   
self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
self.cursor.execute(USE +name)
   
self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
varchar(20))
   
Then I execute many insert statements in various different 
loops on
various tables, all of which are fine, and result in multiple 
table
entries. The following one is executed many times also. and 
seems
identical to the rest. The print statements output to the 
browser
window, and appear repeatedly, so the query must be being called
repeatedly also:
   
print pbSQL query executing/bp
self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
','c','2','e','f','g'))
print pbSQL query executed/bp
   
I have, for debugging, set i up as a counter variable.
   
No errors are given, but the only entry to appear in the final 
database
is that from the final execution of the INSERT statement (the 
last
value of i)
   
I suspect that this is to vague for anyone to be able to help, 
but if
anyone has any ideas I'd be really grateful :-)
   
It occured to me that if I could access the mysql query log 
that might
help, but I was unsure how to enable logging for MysQL with 
python.
   
Cheers,
   
Ben
  
   Not sure this will help but where is the commit?  I don't use 
   MySQL but
   most SQL engines require a commit.
   Johnf

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


Re: textwrap.dedent replaces tabs?

2006-12-29 Thread Frederic Rentsch
Tom Plunket wrote:
 Frederic Rentsch wrote:

   
 Your rules seem incomplete.
 

 Not my rules, the stated documentation for dedent.  My understanding
 of them may not be equivalent to yours, however.
It's not about understanding, It's about the objective. Let us consider 
the difference between passing a driving test and riding a bicycle in 
city traffic. The objective of passing the test is getting the license 
and the means is knowing the rules. The objective of riding the bicycle 
is surviving and the means is anticipating all possible breaches of 
rules on he part of motorists.

 What if common tabs remain after stripping common white space?
 What if we just go with, [r]emove any whitespace than can be uniformly
 removed from the left of every line in `text`. ?
   
 Does this never happen? Or can we hope it doesn't happen?
 

 Hope has no place in programming software that is to be used by
 others.

   
That's exactly what I am saying. That's exactly why it may be a good 
idea to provide preventive measures for rules being breached be those 
others over whom we have no control.

 To err on the side of caution I complete your rules and this is my 
 (tested) attempt at expressing them pythonically.
 

 Inasmuch as my rules have been expressed via tests, the provided code
 fails four of the five tests provided.

   
toms_test_data = (
   ( \n   Hello\n  World,   # Do this
 \nHello\n   World, ),  # Expect this
   ( \n\tHello\n\t   World,
 \nHello\n   World, ),
   ( \t\tHello\n\tWorld,
 \tHello\nWorld, ),
   ( Hello\n\tWorld,
 Hello\n\tWorld, ),
   (   \t Hello\n   \tWorld,
 \t Hello\n \tWorld, ),
)
  for dedent_this, expect_this in toms_test_data:
done = '\n'.join (dedent (dedent_this.splitlines ()))
if done == expect_this: print 'BRAVO!!!'
else: print 'SHAME ON YOU!!!'
   
BRAVO!!!
BRAVO!!!
BRAVO!!!
BRAVO!!!
BRAVO!!!

You seem to have plugged my function into your tester. I wasn't 
concerned about your testing interface but about the dedentation.
 (I admit it does look awfully sevety-ish. Just a vulgar little 
 function.)
 

 Seventys-ish is as much a statement about the lack of statement about
 how you actually tested it as it is that an implementation was made
 apparently without understanding of the requirements.


 -tom!

   
Best regards

Frederic


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


Re: list looping error

2006-12-29 Thread tkpmep

What you really want to write is
for i in x:
for j in i:
print j

The outer loop iterates over the tuples in the list, while the inner
loop iterates over the elements of each tuple. So j (in your example)
is always an integer, and is therefore unsubscriptable, which is
exactly what the error message says.

Thomas Philips

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


Question about the new module

2006-12-29 Thread Gabriele *darkbard* Farina
Hi,

I'm using Python 2.5 to develop a simple MVC framework based on
mod_python. To load my controllers, I create new modules using the
new module like this:

# 
my_module = new.module(random_name)
my_module.__file__ = module_path

exec open(module_path, r) in my_module.__dict__

then I initialize the class defined inside the module and call a method
of this class based on the HTTP request.

All works fine but the imports. If my module contains something like
this:

import something

class MyController(Controller):
def index(self):
something.do_something()

when MyController.index is called an exception is raised NoneType
object has not attribute do_something. Why does it happen ? I have to
load the module in different ways (but I'd like to force the reload
every time the module is loaded) ?

Gabriele

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread timw.google
Not sure if this will help, as you said you already tried autocommit,
but did you try to commit after creating the table, then doing all the
inserts before commiting on disconnect?

(I'm no MySQL or Python guru, but I do use it with python and MySQLdb .)

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


Re: Slowdown in Jython

2006-12-29 Thread Kent Johnson
tac-tics wrote:
 I have an application written in jython which has to process a number
 of records. It runs fine until it gets to about 666 records (and maybe
 that's a sign), and then, it's performance and responsiveness goes down
 the toilet. It looks like it's running out of memory and is being
 forced to use extended memory, but I do not know enough about the
 language to figure out where this is happening. It will eventually
 finish the task, but the window stops responding, and it ends up taking
 several hours (as opposed to several minutes as it should). I really
 just wish I had a tool for polling the amount of memory Jython was
 using at any given moment.
 
 Does anyone have any strategy or advice for me?

You can find out how much memory Jython is using the same as you would 
for any other application, e.g. Windows Task Manager or the equivalent.

Jython is a Java application and you can increase the max heap available 
the same as for other java apps, using the command line switch -Xmx, 
e.g. -Xmx512m to set the max heap to 512 megabytes.

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


Beginner question on text processing

2006-12-29 Thread Doran, Harold
I am beginning to use python primarily to organize data into formats
needed for input into some statistical packages. I do not have much
programming experience outside of LaTeX and R, so some of this is a bit
new. I am attempting to write a program that reads in a text file that
contains some values and it would then output a new file that has
manipulated this original text file in some manner.

To illustrate, assume I have a text file, call it test.txt, with the
following information:

X11 .32
X22 .45

My goal in the python program is to manipulate this file such that a new
file would be created that looks like:

X11 IPB = .32
X22 IPB = .45

Here is what I have accomplished so far.

# Python code below for sample program called 'test.py'

# Read in a file with the item parameters
filename = raw_input(Please enter the file you want to open: )

params = open(filename, 'r')

for i in params:
print 'IPB = ' ,i
# end code

This obviously results in the following:

IPB =  x11  .32
IPB =  x22  .45

So, my questions may be trivial, but:

1) How do I print the 'IPB = ' before the numbers? 
2) Is there a better way to prompt the user to open the desired file
rather than the way I have it above? For example, is there a built-in
function that would open a windows dialogue box such that a user who
does not know about path names can use windows to look for the file and
click on it. 
3) Last, what is the best way to have the output saved as a new file
called 'test2.txt'. The only way I know how to do this now is to do
something like:

python test.py  test2.txt

Thank you for any help
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Leo Kislov
Ask Ben, he might know, although he's out to lunch.

Ben wrote:

 I'll try it after lunch. Does anyoone know whether this might be the
 problem?

 Ben


 Ben wrote:
  I have found the problem, but not the cause.
 
  I tried setting the database up manually before hand, which let me get
  rid of the IF NOT EXISTS lines, and now it works!
 
  But why the *** should it not work anyway? The first time it is run, no
  database or tables, so it creates them. That works. But apparentlyu on
  subsequent runs it decides the tables it created arent' actually there,
  and overwrites them. Gr.
 
 
  Ben
 
 
 
  Ben wrote:
   Well, I've checked the SQL log, and my insert statements are certainly
   being logged. The only option left open is that the table in question
   is being replaced, but I can't see why it should be...
  
  
   Ben wrote:
Nope... that can't be it. I tried running those commands manually and
nothing went wrong.
But then again when I execute the problematic command manually nothing
goes wrong. Its just not executing until the last time, or being
overwritten.
   
   
Ben wrote:
 Each time my script is run, the following is called:

 self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
 self.cursor.execute(USE +name)
 self.cursor.execute(CREATE TABLE IF NOT EXISTS table_name ( 

 The idea being that stuf is only created the first time the script is
 run, and after that the original tables and database is used. This
 might explain my pronblem if for some reason the old tables are being
 replaced... can anyone see anything wrong with the above?

 Ben






 Ben wrote:
  One partial explanation might be that for some reason it is 
  recreating
  the table each time the code runs. My code says CREATE TABLE IF NOT
  EXISTS but if for some reason it is creating it anyway and dropping
  the one before that could explain why there are missing entires.
 
  It wouldn't explain why the NOT EXISTS line is being ignored 
  though...
 
  Ben
 
 
  Ben wrote:
   I initially had it set up so that when I connected to the 
   database I
   started a transaction, then when I disconnected I commited.
  
   I then tried turning autocommit on, but that didn't seem to make 
   any
   difference (althouh initially I thought it had)
  
   I'll go back and see what I can find...
   Cheers,
   Ben
  
  
   johnf wrote:
Ben wrote:
   
 I don't know whether anyone can help, but I have an odd 
 problem. I have
 a PSP (Spyce) script that makes many calls to populate a 
 database. They
 all work without any problem except for one statement.

 I first connect to the database...

 self.con = MySQLdb.connect(user=username, passwd =password)
 self.cursor = self.con.cursor()
 self.cursor.execute(SET max_error_count=0)

 All the neccesary tables are created...

 self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
 self.cursor.execute(USE +name)

 self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
 varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
 varchar(20))

 Then I execute many insert statements in various different 
 loops on
 various tables, all of which are fine, and result in multiple 
 table
 entries. The following one is executed many times also. and 
 seems
 identical to the rest. The print statements output to the 
 browser
 window, and appear repeatedly, so the query must be being 
 called
 repeatedly also:

 print pbSQL query executing/bp
 self.cursor.execute(INSERT INTO networks VALUES ('a',' +i+
 ','c','2','e','f','g'))
 print pbSQL query executed/bp

 I have, for debugging, set i up as a counter variable.

 No errors are given, but the only entry to appear in the 
 final database
 is that from the final execution of the INSERT statement (the 
 last
 value of i)

 I suspect that this is to vague for anyone to be able to 
 help, but if
 anyone has any ideas I'd be really grateful :-)

 It occured to me that if I could access the mysql query log 
 that might
 help, but I was unsure how to enable logging for MysQL with 
 python.

 Cheers,

 Ben
   
Not sure this will help but where is the commit?  I don't use 
MySQL but
most SQL engines require a commit.
Johnf

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


Re: A stupid question

2006-12-29 Thread luxnoctis
I knew what everything was for when I uninstalled it, I just didn't
happen to know about every component part, apparently. ;) I have tried
reinstalling the Bittorrent client, and to no avail. (The computer is a
Toshiba Satellite laptop, if that helps anyone.) Any other ideas?


Tom Plunket wrote:
 luxnoctis wrote:

  It says exactly:
 
  The specified module could not be found.
  LoadLibrary(pythondll) failed
 
  Don't know if that helps at all.

 There's something installed on Compaq computers that uses the Python
 stuff too, but I never figured out what it was.  I figured it may have
 been some of the preloaded games, 'cause when I restored a roommate's
 machine from the restore image the Python22 folder was among the things
 that appeared on the fresh machine.  It was actually pretty exciting for
 me since I needed to write a little utility to do something on this
 machine, but it was slow as death and only had dialup and I really
 didn't want to deal with downloading and installing that stuff myself.

 ...of course your first problem is buying a machine with a ton of
 shovelware on it.  Second problem is uninstalling stuff without knowing
 what it's for.
 
 
 -tom!
 
 --

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


Re: Scaling pictures

2006-12-29 Thread cyberco
PIL is certainly a fine option, but I noticed that the scaled images
(scaled with the ANTIALIAS filter) are not as good as you can get with,
say, Photoshop. Maybe I'm just expecting too much, but I wish I could
choose a higher quality rescaling algorithm. PIL still rocks though.

On Dec 28, 2:32 pm, Ravi Teja [EMAIL PROTECTED] wrote:
 Kajsa Anka wrote:
  I would like some advice, I'm going to build a small app that will, among
  other things, scale images so that they can be published on a web site. I've
  never done any image processing in python before so I would like to ask what
  is the best way of doing this, I will not do anything else than scaling the
  images.

  I found the Python Imaging Library but before I dive into that I would like
  to know if there is a better way of doing this.Yes. Python Imaging Library 
  (PIL) is the preferred Python way to do
 this. The example is right in the 
 documentation.http://www.pythonware.com/library/pil/handbook/image.htm

 from PIL import Image
 import glob, os

 size = 128, 128

 for infile in glob.glob(*.jpg):
 file, ext = os.path.splitext(infile)
 im = Image.open(infile)
 im.thumbnail(size, Image.ANTIALIAS)
 im.save(file + .thumbnail, JPEG)

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


Re: popen on windows

2006-12-29 Thread Daniel Klein
On 27 Dec 2006 09:16:53 -0800, hubritic [EMAIL PROTECTED]
wrote:

I am trying to set off commands on Windows 2003 from python.
Specifically, I am trying to use diskpart with a script file (pointed
to with path).

cmd = [diskpart,  /s, path]
p = Popen(cmd, shell=True)

The script is meant to loop through twice. It will do so if I comment
out the Popen call and print cmd instead. But when Popen is called, one
disk will be formated, but not the next.

What is the value of 'path' ?

Does the command work from a Windows command prompt ?

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


Re: Question about the new module

2006-12-29 Thread skip

Gabriele I'm using Python 2.5 to develop a simple MVC framework based
Gabriele on mod_python. To load my controllers, I create new modules
Gabriele using the new module like this:

Gabriele # 
Gabriele my_module = new.module(random_name)
Gabriele my_module.__file__ = module_path
Gabriele exec open(module_path, r) in my_module.__dict__

Gabriele then I initialize the class defined inside the module and call
Gabriele a method of this class based on the HTTP request.

Why use the new module?  Why not call __import__() or execfile()?  Details
on their use are here:

http://docs.python.org/dev/lib/built-in-funcs.html

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


Re: Beginner question on text processing

2006-12-29 Thread skip

Harold To illustrate, assume I have a text file, call it test.txt, with
Harold the following information:

Harold X11 .32
Harold X22 .45

Harold My goal in the python program is to manipulate this file such
Harold that a new file would be created that looks like:

Harold X11 IPB = .32
Harold X22 IPB = .45

...

This is a problem with a number of different solutions.  Here's one way to
do it:

for line in open(filename, r):
fields = line.split()
print fields[0], IPB =, fields[1]

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


Re: Some basic newbie questions...

2006-12-29 Thread Duncan Booth
jonathan.beckett [EMAIL PROTECTED] wrote:

 I'm just finding it a bit weird that some of the built in functions are
 static, rather than methods of objects (such as len() being used to
 find the length of a list).

When it comes down to it, its a design decision, so neither right nor wrong 
in itself. You need to look a bit wider than just 'len' to understand it.

There is the historical attribute: as I understand it, once upon a time, 
way back in the mists of time tuples didn't have methods at all, so you had 
to use a global function if you wanted to get the length of a tuple. That 
of course is no longer the case. However, ignoring for a moment that this 
may have been part of the reason why Python started in the direction of 
global helper functions, there are a lot of reasons why it turns out to 
have been a good decision.

Consider 'sum' for a moment. The function needs to know how to iterate over 
a sequence, but the sequence itself doesn't need to provide any support 
apart from iteration to be supported by 'sum'. If 'sum' was a method then 
you would have to implement it separately in every summable object; 
implement it in a common base class to all iterables; provide a 'Summable' 
mixin class requiring every designer of an iterable to decide at the outset 
whether they want it to be summable; or provide an adaptor class which 
takes an iterator and returns a summable iterator (which just adds a 
needless extra layer of complexity over the global function we started 
with).

'min', 'max', 'sorted', 'zip' are other functions which similarly provide 
support to any kind of iterable without encumbering the iterable protocol 
itself.

Next consider 'iter'. That's a global function which calls the __iter__ 
method, but it also has a fallback behaviour. Before Python had __iter__ 
iteration was define by calling __getitem__ with increasing index values, 
and if you don't have an __iter__ method the iter builtin will try the old 
protocol instead. So the global function has some more benefits: we can 
change the protocol it implements and continue to provide backward 
compatability, and we can have it do more than just calling the method 
which does the implementation.

getattr is another example of a builtin which appears to do the job of a 
method (__getattribute__) but actually does a whole lot more with fallback 
and exception handling in the function. Converting an AttributeError 
exception to a default value would be particularly nasty to get right if we 
were depending on a direct call to a base class __getattribute__ which 
might be overridden in the implemented class.

cmp is another good example: cmp(a,b) returns a.__cmp__(b), but if a 
doesn't have an __cmp__ method then it tries to return -b.__cmp__(a) (and 
has another fallback if even that fails).

There is also an argument that Python uses __ to distinguish internal 
implementation details so that the internal methods are effectively kept 
out of the user's namespace. The ordinary user shouldn't need to worry 
about the presence of __ methods as they never need to call them directly. 
In fact for beginners probably __init__ and if __name__=='__main__': are 
the only things besides 'keep off the double underscores' that they need to 
know about them.

So where does that leave 'len'? It is a function primarily for consistency 
with the general idea that you call a builtin (or a function imported from 
a support module) rather than calling a __ method directly. It does add 
some minimal functionality over calling __len__ directly, but not such that 
you'ld normally notice the difference.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want to see all the variables

2006-12-29 Thread Larry Bates
johnf wrote:
 Hi,
 When I use dir() I don't see the __ underscore items.  Is there anything
 that will show all the private vars and functions?
 
 johnf

The idea of the underscore items is that they aren't to be used by
you.  If you wish to access private variables and functions you will
almost certainly have to look at the source code to make sure of
what they are and how they can be utilized.

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


Re: Python Wrapper for C# Com Object

2006-12-29 Thread bg_ie

[EMAIL PROTECTED] skrev:

 [EMAIL PROTECTED] skrev:

  Hi,
 
  I wish to write a Python wrapper for my C# COM object but am unsure
  where to start. I have a dll and a tlb file, and I can use this object
  in C via the following code -
 
  // ConsolApp.cpp : Defines the entry point for the console application.
  //
  #include stdafx.h
  #include windows.h
  #include stdio.h
  #import C:\Documents and Settings\X\Mina dokument\Visual Studio
  2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb
  using namespace X_COMObject;
 
  int _tmain(int argc, _TCHAR* argv[])
  {
  CoInitialize(NULL);
 
  X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class));
  XCOM_Interface *X_com_ptr ;
  X_com_ptr = p ;
  X_com_ptr-SetID(10);
  int x = X_com_ptr-GetID();
  printf(%d,x);
  getchar();
 
  return 0;
  }
 
  Can anyone offer me some tips as to how to do this in Python?
 
  Thanks very much for your help,
 
  Barry.

 This is what I've done so far, but I know I'm not doing this correctly.
 Can anyone help me out?

 #import pythoncom
 #pythoncom.CoInitialize()

 from comtypes.client import GetModule, CreateObject

 module = GetModule(C:\\Documents and Settings\\X\\Mina
 dokument\\Visual Studio
 2005\\Projects\\X_COMObject\\X_COMObject\\bin\\Debug\\X_COMObject.tlb)

 dir(module)

 interface = module.XCOM_Interface()

 dir(interface)

 interface.SetID()

 #pythoncom.CoUnitialize()


 Traceback (most recent call last):
   File C:/Python25/test.py, line 14, in module
 interface.SetID()
 TypeError: Expected a COM this pointer as first argument

Can anyone help me with this?

Thanks,

Barry.

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
:-) Ok, point taken!

I fixed it in the end. It was nothing interesting at all - just a
wayward line of code that was doing exactly what I feared - replacing
the database each time rather than just when it was needed.

Ben


Leo Kislov wrote:

 Ask Ben, he might know, although he's out to lunch.

 Ben wrote:

  I'll try it after lunch. Does anyoone know whether this might be the
  problem?
 
  Ben
 
 
  Ben wrote:
   I have found the problem, but not the cause.
  
   I tried setting the database up manually before hand, which let me get
   rid of the IF NOT EXISTS lines, and now it works!
  
   But why the *** should it not work anyway? The first time it is run, no
   database or tables, so it creates them. That works. But apparentlyu on
   subsequent runs it decides the tables it created arent' actually there,
   and overwrites them. Gr.
  
  
   Ben
  
  
  
   Ben wrote:
Well, I've checked the SQL log, and my insert statements are certainly
being logged. The only option left open is that the table in question
is being replaced, but I can't see why it should be...
   
   
Ben wrote:
 Nope... that can't be it. I tried running those commands manually and
 nothing went wrong.
 But then again when I execute the problematic command manually nothing
 goes wrong. Its just not executing until the last time, or being
 overwritten.


 Ben wrote:
  Each time my script is run, the following is called:
 
  self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
  self.cursor.execute(USE +name)
  self.cursor.execute(CREATE TABLE IF NOT EXISTS table_name ( 
 
  The idea being that stuf is only created the first time the script 
  is
  run, and after that the original tables and database is used. This
  might explain my pronblem if for some reason the old tables are 
  being
  replaced... can anyone see anything wrong with the above?
 
  Ben
 
 
 
 
 
 
  Ben wrote:
   One partial explanation might be that for some reason it is 
   recreating
   the table each time the code runs. My code says CREATE TABLE IF 
   NOT
   EXISTS but if for some reason it is creating it anyway and 
   dropping
   the one before that could explain why there are missing entires.
  
   It wouldn't explain why the NOT EXISTS line is being ignored 
   though...
  
   Ben
  
  
   Ben wrote:
I initially had it set up so that when I connected to the 
database I
started a transaction, then when I disconnected I commited.
   
I then tried turning autocommit on, but that didn't seem to 
make any
difference (althouh initially I thought it had)
   
I'll go back and see what I can find...
Cheers,
Ben
   
   
johnf wrote:
 Ben wrote:

  I don't know whether anyone can help, but I have an odd 
  problem. I have
  a PSP (Spyce) script that makes many calls to populate a 
  database. They
  all work without any problem except for one statement.
 
  I first connect to the database...
 
  self.con = MySQLdb.connect(user=username, passwd =password)
  self.cursor = self.con.cursor()
  self.cursor.execute(SET max_error_count=0)
 
  All the neccesary tables are created...
 
  self.cursor.execute(CREATE DATABASE IF NOT EXISTS +name)
  self.cursor.execute(USE +name)
 
  self.cursor.execute(CREATE TABLE IF NOT EXISTS networks (SM
  varchar(20),DMC int,DM varchar(50),NOS int,OS 
  varchar(50),NID
  varchar(20))
 
  Then I execute many insert statements in various different 
  loops on
  various tables, all of which are fine, and result in 
  multiple table
  entries. The following one is executed many times also. and 
  seems
  identical to the rest. The print statements output to the 
  browser
  window, and appear repeatedly, so the query must be being 
  called
  repeatedly also:
 
  print pbSQL query executing/bp
  self.cursor.execute(INSERT INTO networks VALUES ('a',' 
  +i+
  ','c','2','e','f','g'))
  print pbSQL query executed/bp
 
  I have, for debugging, set i up as a counter variable.
 
  No errors are given, but the only entry to appear in the 
  final database
  is that from the final execution of the INSERT statement 
  (the last
  value of i)
 
  I suspect that this is to vague for anyone to be able to 
  help, but if
  anyone has any ideas I'd be really grateful :-)
 
  It occured to me that if I could access the mysql 

probably a stupid question: MatLab equivalent of diff ?

2006-12-29 Thread Stef Mientki
Does anyone know the equivalent of the MatLab diff function.
The diff functions calculates the difference between 2 succeeding 
elements of an array.
I need to detect (fast) the falling edge of a binary signal.

There's derivate function in Python diff,
but when you use an binary (true/false) input,
it also detects rising edges.

Probably a stupid question,
but I still have troubles,
digging to huge amount of information about Python.

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


Can I beat perl at grep-like processing speed?

2006-12-29 Thread js
Just my curiosity.
Can python beats perl at speed of grep-like processing?


$ wget http://www.gutenberg.org/files/7999/7999-h.zip
$ unzip 7999-h.zip
$ cd 7999-h
$ cat *.htm  bigfile
$ du -h bigfile
du -h bigfile
8.2Mbigfile

-- grep.pl --
#!/usr/local/bin/perl
open(F, 'bigfile') or die;

while(F) {
  s/[\n\r]+$//;
  print $_\n if m/destroy/oi;
}
-- END --
-- grep.py --
#!/usr/bin/env python
import re
r = re.compile(r'destroy', re.IGNORECASE)

for s in file('bigfile'):
  if r.search(s): print s.rstrip(\r\n)
-- END --

$ time perl grep.pl   pl.out; time python grep.py  py.out
real0m0.168s
user0m0.149s
sys 0m0.015s

real0m0.450s
user0m0.374s
sys 0m0.068s
# I used python2.5 and perl 5.8.6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting a child process and getting its stdout?

2006-12-29 Thread cypher543
Thank you for the examples, but I have tried all of that before. No
matter what I do, my program always hangs while it waits for the
process to exit and then it prints all of the output at once. I've
tried read(), readline(), readlines(), communicate(), etc and it is
always the same.

self.buildPID = subprocess.Popen([python, tobeforked.py], stdout =
subprocess.PIPE)
while self.buildPID.poll() == None:
output = self.buildPID.stdout.readline()
self.consoleLogBuffer.insert(self.consoleLogBuffer.get_end_iter(),
output)
self.consoleLog.scroll_to_mark(self.consoleLogBuffer.get_insert(), 0)

Keep in mind that I'm not required to use subprocess. But I have also
tried os.fork and the pty module. They both produce the exact same
results.

On Dec 29, 3:38 am, Tom Plunket [EMAIL PROTECTED] wrote:
 Tom Plunket wrote:
 while p.poll() == None:
 data = p.stdout.readline()
 if data:
 print data,If you change that print to something more 
  decorated, like,

print 'process said:', data,

 Then it might be more obvious where/how the print statements are getting
 routed.

 Keep in mind that readline() will return one line at a time, and that
 line will end with a newline, although the last line you get (at EOF)
 may not have one.
 
 again, good luck.  Hope this helps,
 -tom!
 
 --

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


Re: Slowdown in Jython

2006-12-29 Thread tac-tics
 Jython is a Java application

That was the intellectual leap I needed to solve the problem. I forgot
that I have total access to Java memory management. It turns out at the
point of slowdown, Java was continually running full GC, causing the
awful loss of performance. I figured out that I was not releasing a
very large chunk of memory right before the script, so I effectively
had a duplicate of every record in memory.

I'm still not sure why my memory usage is increasing during the script,
but with the removal of the duplicates in memory, it runs just fine
now. Problem solved for now.

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


Re: Can I beat perl at grep-like processing speed?

2006-12-29 Thread Christophe Cavalaria
js  wrote:

 Just my curiosity.
 Can python beats perl at speed of grep-like processing?
 
 
 $ wget http://www.gutenberg.org/files/7999/7999-h.zip
 $ unzip 7999-h.zip
 $ cd 7999-h
 $ cat *.htm  bigfile
 $ du -h bigfile
 du -h bigfile
 8.2M  bigfile
 
 -- grep.pl --
 #!/usr/local/bin/perl
 open(F, 'bigfile') or die;
 
 while(F) {
   s/[\n\r]+$//;
   print $_\n if m/destroy/oi;
 }
 -- END --
 -- grep.py --
 #!/usr/bin/env python
 import re
 r = re.compile(r'destroy', re.IGNORECASE)
 
 for s in file('bigfile'):
   if r.search(s): print s.rstrip(\r\n)
 -- END --
 
 $ time perl grep.pl   pl.out; time python grep.py  py.out
 real  0m0.168s
 user  0m0.149s
 sys   0m0.015s
 
 real  0m0.450s
 user  0m0.374s
 sys   0m0.068s
 # I used python2.5 and perl 5.8.6
I'm thankful for the Python version or else, I'd never have guessed what
that code was supposed to do!

Try that :
-- grep.py --
#!/usr/bin/env python
import re
def main():
search = re.compile(r'destroy', re.IGNORECASE).search

for s in file('bigfile'):
  if search(s): print s.rstrip(\r\n)

main()
-- END --

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


Re: how to serve image files without disk use?

2006-12-29 Thread Chris Mellon
On 12/28/06, Ray Schumacher [EMAIL PROTECTED] wrote:
 I'm trying to make a small camera server using VideoCapture.py and
 socket. I needed to construct a complete image file with headers etc
 for a browser to recognize it, but I couldn't find a combination of
 StringIO and wx image methods to avoid disk saves, without PIL.

 If I save a temp.jpg file to disk I can serve the image easily:
 ...
 self.cam = VideoCapture.Device(devnum=0, showVideoWindow=0)
 buff, width, height = self.cam.dev.getbuffer()
 im =  wx.EmptyImage(width, height)
 im.SetData(buff)
 im.Mirror().SaveFile('temp.jpg', wx.BITMAP_TYPE_JPEG)
 ...
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.bind((HOST, PORT))
 s.listen(1)
 conn, addr = s.accept()
 while 1:
  data = conn.recv(1024)
  if data[:3] == 'GET':
  conn.send(HTTP/1.0 200 OK+\015\012)
  conn.send(Server: RJS_video/0.0.1+\015\012)
  conn.send(Content-type: image/bmp+\015\012)
  conn.send(Content-Length: +str(352*288*3+256)+\015\012)
  conn.send(\015\012)
  fh = file('temp.jpg', 'rb')
  conn.send(fh.read())
  fh.close()
  else: break

 But, how can I avoid disk writes? wx's *.SaveFile() needs a string
 file name (no objects).
 I'm going to investigate PIL's im.save(), as it appears to allow
 file-objects.


wx.Image.GetData() returns the raw image data as a Python string.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert Perl to Python

2006-12-29 Thread Nick Craig-Wood
Emilio Sañudo [EMAIL PROTECTED] wrote:
   ?? wrote:
  How can I convert a perl script to Python?
 
  http://www.crazy-compilers.com/bridgekeeper/

Very interesting until this bit :-

  The bad news: Unfortunatly, there is no way to 'try out'
  bridgekeeper. It's simply not available for puchasing.

  The good news:But we can offer you consultancy for this conversion
  (where we will use bridgekeeper as a mighty tool). If you are
  interested in hireing me for a project, please drop me a note

I've done quite a lot of pl-py conversions by hand.  It is a bit
tedious but a good editor with macros will let you fly through the
job.  I used emacs.

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some basic newbie questions...

2006-12-29 Thread Daniel Klein
On 28 Dec 2006 08:40:02 -0800, jonathan.beckett
[EMAIL PROTECTED] wrote:

Hi all,

Question 2...
What is the correct way of looping through a list object in a class via
a method of it? 

Without peeking at any of the other responses, here is what I came up
with. I hope it helps...

class Gun(object):
def __init__(self, shells = 10):
self.shells = shells

class Battleship(object):
def __init__(self, shipname = '', guns = []):
self.shipname = shipname
self.guns = guns

def getShellsLeft(self):
numShells = 0
for gun in self.guns:
numShells += gun.shells
return numShells

if __name__ == '__main__':
aShip = Battleship(shipname = Bizmark, guns = [Gun(), Gun(6)])
print %s has %d shells left. \
  % (aShip.shipname, aShip.getShellsLeft())


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


Re: Can I beat perl at grep-like processing speed?

2006-12-29 Thread Tim Smith


you may not be able to beat perl's regex speed, but you can take some steps to 
speed up your python program using map and filter

here's a modified python program that will do your search faster

#!/usr/bin/env python
import re
r = re.compile(r'destroy', re.IGNORECASE)

def stripit(x):
  return x.rstrip(\r\n)

print \n.join( map(stripit, filter(r.search, file('bigfile'))) )

#time comparison on my machine
real0m0.218s
user0m0.210s
sys 0m0.010s

real0m0.464s
user0m0.450s
sys 0m0.010s

#original time comparison on my machine

real0m0.224s
user0m0.220s
sys 0m0.010s

real0m0.508s
user0m0.510s
sys 0m0.000s

also, if you replace the regex with a test like lambda x: 
x.lower().find(destroy) != -1, you will get really close to the speed of 
perl's (its possible perl will even take this shortcut when getting such a 
simple regex

#here's the times when doing the search this way
real0m0.221s
user0m0.210s
sys 0m0.010s

real0m0.277s
user0m0.280s
sys 0m0.000s

 -- Tim

-- On 12/29/06 js  [EMAIL PROTECTED] wrote:

 Just my curiosity.
 Can python beats perl at speed of grep-like processing?
 
 $ wget http://www.gutenberg.org/files/7999/7999-h.zip
 $ unzip 7999-h.zip
 $ cd 7999-h
 $ cat *.htm  bigfile
 $ du -h bigfile
 du -h bigfile
 8.2M  bigfile
 
 -- grep.pl --
 #!/usr/local/bin/perl
 open(F, 'bigfile') or die;
 
 while(F) {
   s/[\n\r]+$//;
   print $_\n if m/destroy/oi;
 }
 -- END --
 -- grep.py --
 #!/usr/bin/env python
 import re
 r = re.compile(r'destroy', re.IGNORECASE)
 
 for s in file('bigfile'):
   if r.search(s): print s.rstrip(\r\n)
 -- END --
 
 $ time perl grep.pl   pl.out; time python grep.py  py.out
 real  0m0.168s
 user  0m0.149s
 sys   0m0.015s
 
 real  0m0.450s
 user  0m0.374s
 sys   0m0.068s
 # I used python2.5 and perl 5.8.6
 -- 
 http://mail.python.org/mailman/listinfo/python-list

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


Re: I want to see all the variables

2006-12-29 Thread [EMAIL PROTECTED]
What do you mean? Can you specify which special functions you don't
see?
I get:
py class X:
pass
py dir(X)
['__doc__', '__module__']
py class X:
def __getitem__(self, x):
pass


py dir(X)
['__doc__', '__getitem__', '__module__']

On Dec 29, 12:35 pm, johnf [EMAIL PROTECTED] wrote:
 Hi,
 When I use dir() I don't see the __ underscore items.  Is there anything
 that will show all the private vars and functions?
 
 johnf

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


Re: Python Wrapper for C# Com Object

2006-12-29 Thread TheSeeker
Hi,

A question. Why in your C-version are your doing:

X_com_ptr-SetID(10);

and in the Python version:

interface.SetID()  ?

I don't know anything of your COM object, but does SetID require a
parameter?

Duane


[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] skrev:

  [EMAIL PROTECTED] skrev:
 
   Hi,
  
   I wish to write a Python wrapper for my C# COM object but am unsure
   where to start. I have a dll and a tlb file, and I can use this object
   in C via the following code -
  
   // ConsolApp.cpp : Defines the entry point for the console application.
   //
   #include stdafx.h
   #include windows.h
   #include stdio.h
   #import C:\Documents and Settings\X\Mina dokument\Visual Studio
   2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb
   using namespace X_COMObject;
  
   int _tmain(int argc, _TCHAR* argv[])
   {
 CoInitialize(NULL);
  
 X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class));
 XCOM_Interface *X_com_ptr ;
 X_com_ptr = p ;
 X_com_ptr-SetID(10);
 int x = X_com_ptr-GetID();
 printf(%d,x);
 getchar();
  
 return 0;
   }
  
   Can anyone offer me some tips as to how to do this in Python?
  
   Thanks very much for your help,
  
   Barry.
 
  This is what I've done so far, but I know I'm not doing this correctly.
  Can anyone help me out?
 
  #import pythoncom
  #pythoncom.CoInitialize()
 
  from comtypes.client import GetModule, CreateObject
 
  module = GetModule(C:\\Documents and Settings\\X\\Mina
  dokument\\Visual Studio
  2005\\Projects\\X_COMObject\\X_COMObject\\bin\\Debug\\X_COMObject.tlb)
 
  dir(module)
 
  interface = module.XCOM_Interface()
 
  dir(interface)
 
  interface.SetID()
 
  #pythoncom.CoUnitialize()
 
 
  Traceback (most recent call last):
File C:/Python25/test.py, line 14, in module
  interface.SetID()
  TypeError: Expected a COM this pointer as first argument
 
 Can anyone help me with this?
 
 Thanks,
 
 Barry.

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


Re: how to serve image files without disk use?

2006-12-29 Thread Carsten Haese
On Fri, 2006-12-29 at 09:30 -0600, Chris Mellon wrote:
 On 12/28/06, Ray Schumacher [EMAIL PROTECTED] wrote:
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind((HOST, PORT))
  s.listen(1)
  conn, addr = s.accept()
  while 1:
   data = conn.recv(1024)
   if data[:3] == 'GET':
   conn.send(HTTP/1.0 200 OK+\015\012)
   conn.send(Server: RJS_video/0.0.1+\015\012)
   conn.send(Content-type: image/bmp+\015\012)
   conn.send(Content-Length: +str(352*288*3+256)+\015\012)
   conn.send(\015\012)
   fh = file('temp.jpg', 'rb')
   conn.send(fh.read())
   fh.close()
   else: break
 
  But, how can I avoid disk writes? wx's *.SaveFile() needs a string
  file name (no objects).
  I'm going to investigate PIL's im.save(), as it appears to allow
  file-objects.
 
 
 wx.Image.GetData() returns the raw image data as a Python string.

In addition to what Chris said, is there a reason why you're reinventing
the wheel instead of using available components? BaseHTTPServer can take
care of the nitty-gritty details of the socket communication for you.
Here's an example that can easily be extended to suit your simple image
serving need:

###
import BaseHTTPServer

class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  def do_GET(self):
self.wfile.write(HTTP/1.0 200 OK\r\n)
self.wfile.write(Content-Type: text/plain\r\n)
self.wfile.write(\r\n)
self.wfile.write(This is a test.)

s = BaseHTTPServer.HTTPServer((,8080), MyRequestHandler)
s.serve_forever()
###

Hope this helps,

Carsten.


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


Re: Can I beat perl at grep-like processing speed?

2006-12-29 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Tim Smith
wrote:

 also, if you replace the regex with a test like lambda x:
 x.lower().find(destroy) != -1, you will get really close to the speed
 of perl's

Testing for ``'destroy' in x.lower()`` should even be a little bit faster.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want to see all the variables

2006-12-29 Thread Steven D'Aprano
On Fri, 29 Dec 2006 07:57:30 -0800, [EMAIL PROTECTED] wrote:

 What do you mean? Can you specify which special functions you don't
 see?
 I get:
 py class X:
   pass
 py dir(X)
 ['__doc__', '__module__']

How about these?

 X.__dict__
{'__module__': '__main__', '__doc__': None}
 X.__name__
'X'
 X.__bases__
()

Now that's interesting... if __name__ and __bases__ don't live in the
class __dict__, where do they live? What other methods and attributes are
invisibly in X?


-- 
Steven.

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


Re: I want to see all the variables

2006-12-29 Thread Steven D'Aprano
On Fri, 29 Dec 2006 08:20:22 -0600, Larry Bates wrote:

 johnf wrote:
 Hi,
 When I use dir() I don't see the __ underscore items.  Is there anything
 that will show all the private vars and functions?
 
 johnf
 
 The idea of the underscore items is that they aren't to be used by
 you.

Double leading+trailing underscore attributes are NOT private, they are
*special* but public (e.g. __dict__, __class__, __str__, etc.). If you
don't believe me, have a look at dir(int) and count the underscored
attributes listed. Then try to find __dict__, __name__, __bases__,
__base__ or __mro__ within the list. Why are they suppressed?

But even if underscored attributes were private, the Python philosophy is
that private attributes are private by convention only -- even
name-mangled __private methods can be reached if you know how.


 If you wish to access private variables and functions you will
 almost certainly have to look at the source code to make sure of
 what they are and how they can be utilized.

Not so.

 class Parrot(object):
... def _private(self):
... Private method, returns a magic string.
... return Don't touch!!!
...
 Parrot._private.__doc__
Private method, returns a magic string.



-- 
Steven.

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


Re: I want to see all the variables

2006-12-29 Thread [EMAIL PROTECTED]


On Dec 29, 5:17 pm, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Fri, 29 Dec 2006 07:57:30 -0800, [EMAIL PROTECTED] wrote:
  What do you mean? Can you specify which special functions you don't
  see?
  I get:
  py class X:
 pass
  py dir(X)
  ['__doc__', '__module__']How about these?

  X.__dict__{'__module__': '__main__', '__doc__': None} X.__name__
 'X'
  X.__bases__()

 Now that's interesting... if __name__ and __bases__ don't live in the
 class __dict__, where do they live? What other methods and attributes are
 invisibly in X?

 --
 Steven.

Well, then we have to lookup what dir() does --
http://docs.python.org/lib/built-in-funcs.html -- it tries to bring up
the interesting attributes of an object, apparently __name__ and
__bases__ are considered to be not so interesting

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


Looking for python SIP/MGCP stacks

2006-12-29 Thread Jenny Zhao (zhzhao)
Hi Python users,

I am using python to write a testing tools, currently this tool only
supports skinny protocol. I am planning to add SIP and MGCP support as
well, wondering if you have written these protocol stacks before which
can be leveraged from.

 

thanks

Jenny

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

Re: Anyone persuaded by merits of Lisp vs Python?

2006-12-29 Thread Aahz
[x-post removed]

In article [EMAIL PROTECTED],
Paddy [EMAIL PROTECTED] wrote:
Carl Banks wrote:

 If you were so keen on avoiding a flame war, the first thing you should
 have done is to not cross-post this.

I want to cover Pythonistas looking at Lisp and Lispers looking at
Python because of the thread. The cross posting is not as flame bait.

If a Lisper is looking at Python, zie will be reading c.l.py, no?
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

I support family values -- Addams family values --www.nancybuttons.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Minor problem with configure (2.4.4)

2006-12-29 Thread MRAB

[EMAIL PROTECTED] wrote:
 configure expands
   AC_DEFINE(_POSIX_C_SOURCE, 200112L, Define to activate features from
 IEEE Stds 1003.1-2001)

 to

 #define _POSIX_C_SOURCE 200112L

 that causes problems because _POSIX_C_SOURCE is defined by system
 headers and I get hideous
 warnings during compilation.

 I tried to fix it by adding AC_UNDEFINE(_POSIX_C_SOURCE);
 before AC_DEFINE but autoconf 2.59 won't take it:

 configure.in:273: error: possibly undefined macro: AC_UNDEFINE
   If this token and others are legitimate, please use
 m4_pattern_allow.
   See the Autoconf documentation.

 Ideas?

It looks like AC_DEFINE is #define'd but AC_UNDEFINE isn't.

Try:

#undef _POSIX_C_SOURCE

instead.

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


Re: Anyone persuaded by merits of Lisp vs Python?

2006-12-29 Thread Kaz Kylheku
Paddy wrote:
 Carl Banks wrote:
  If you were so keen on avoiding a flame war, the first thing you should
  have done is to not cross-post this.

 I want to cover Pythonistas looking at Lisp and Lispers looking at

That's already covered in the orginal thread. Same two newsgroups, same
crowd of people. What's the difference?

Keep it in the original thread where uninterested people can continue
to ignore it.

 Python because of the thread. The cross posting is not as flame bait.

You're re-starting the same thread under a new root article, thereby
evading kill filters set up on the original thread.

In halfway decent newsreaders, people can killfile by thread, whereby
all articles associated with the same ancestral root article are
removed.

It's very bad practice to re-introduce continuations of long flamebait
threads under different thread identities.

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


Re: db access

2006-12-29 Thread vasudevram

king kikapu wrote:
 On Dec 29, 12:12 am, johnf [EMAIL PROTECTED] wrote:
  king kikapu wrote:
   Hi to all,
 
   is there a way to use an RDBMS (in my case, SQL Server) from Python by
   using some built-in module of the language (v. 2.5) and through ODBC ??
   I saw some samples that use statements like import dbi or import
   odbc but neither modules (dbi, odbc) are present on my system...
 
   Any hint(s) ??
 

Its not really related to your question, but if you also want to
publish your database data to PDF, here's one way:

http://mail.python.org/pipermail/python-list/2006-July/392099.html

Vasudev
~~
Vasudev Ram
Dancing Bison Enterprises
Software training and consulting
http://www.dancingbison.com
http://www.dancingbison.com/products.html
~~

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


Re: A stupid question

2006-12-29 Thread Matimus
[EMAIL PROTECTED] wrote:
 Any other ideas?

Well, you could always try downloading and installing python:
http://www.python.org. It is completely free. It won't run anything in
the task bar or add itself to the startup menu and it doesn't have
ads... it just sits there waiting for you to use it. I would start with
version 2.4, and if that doesn't work I would go to 2.3 then 2.5 then
2.2. Uninstall the last version before moving on to another.

I do worry a little though because python dlls are named as
Pythonversion.dll, so the dll in that error message could actually be
from some third party.

Anyway, there is no harm in installing Python. If it doesn't work it
will uninstall cleanly.

-Matt

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


Re: Anyone persuaded by merits of Lisp vs Python?

2006-12-29 Thread Carl Banks

Paddy wrote:
 Carl Banks wrote:
  If you were so keen on avoiding a flame war, the first thing you should
  have done is to not cross-post this.

 I want to cover Pythonistas looking at Lisp and Lispers looking at
 Python because of the thread. The cross posting is not as flame bait.

Then post a separate message to each group.  If you expect everyone on
Usenet to obey your command to reply with only what you want them to
reply with, you're a sad naive fool.


Carl Banks

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


Getting VideoCapture to work with Python 2.5

2006-12-29 Thread Just Another Victim of the Ambient Morality
I can't seem to get VideoCapture (http://videocapture.sourceforge.net/) 
to work with my version of Python (2.5).  Why is that?  I've followed the 
instructions which made it look easy but, as it happens all too often, it 
simply doesn't work.  The error I get is that the .py interface file can't 
find an expected module (using the import keyword) but that module exists 
as a DLL in the correct directory.  Why doesn't it recognize it?
Has anyone else used this library with Python 2.5 successfully?  Any 
theories as to what might be going wrong?  Thank you...



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


bad marshal data in site.py in fresh 2.5 install win

2006-12-29 Thread TiNo
Hi,

I have installed python two days ago on a USB memory stick (I am on
the move and have no laptop.) I am on windows computers, mostly XP,
all the time.

Now, after pluging it in to a different computer, I get the following
message when I run pyhthon:
'import site' failed; use -v for traceback

python -v gives:

G:\Python25python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# G:\Python25\lib\site.pyc matches G:\Python25\lib\site.py
import site # precompiled from G:\Python25\lib\site.pyc
# G:\Python25\lib\os.pyc matches G:\Python25\lib\os.py
import os # precompiled from G:\Python25\lib\os.pyc
import nt # builtin
# G:\Python25\lib\ntpath.pyc matches G:\Python25\lib\ntpath.py
import ntpath # precompiled from G:\Python25\lib\ntpath.pyc
# G:\Python25\lib\stat.pyc matches G:\Python25\lib\stat.py
import stat # precompiled from G:\Python25\lib\stat.pyc
# G:\Python25\lib\UserDict.pyc matches G:\Python25\lib\UserDict.py
import UserDict # precompiled from G:\Python25\lib\UserDict.pyc
# G:\Python25\lib\copy_reg.pyc matches G:\Python25\lib\copy_reg.py
import copy_reg # precompiled from G:\Python25\lib\copy_reg.pyc
# G:\Python25\lib\types.pyc matches G:\Python25\lib\types.py
import types # precompiled from G:\Python25\lib\types.pyc
import _types # builtin
# zipimport: found 74 names in G:\Python25\lib\site-packages\setuptools-0.6c3-py
2.5.egg
# G:\Python25\lib\locale.pyc matches G:\Python25\lib\locale.py
import locale # precompiled from G:\Python25\lib\locale.pyc
import encodings # directory G:\Python25\lib\encodings
# G:\Python25\lib\encodings\__init__.pyc matches G:\Python25\lib\encodings\__ini
t__.py
import encodings # precompiled from G:\Python25\lib\encodings\__init__.pyc
# G:\Python25\lib\codecs.pyc matches G:\Python25\lib\codecs.py
import codecs # precompiled from G:\Python25\lib\codecs.pyc
import _codecs # builtin
# G:\Python25\lib\encodings\aliases.pyc matches G:\Python25\lib\encodings\aliase
s.py
'import site' failed; traceback:
Traceback (most recent call last):
  File G:\Python25\lib\site.py, line 415, in module
main()
  File G:\Python25\lib\site.py, line 406, in main
aliasmbcs()
  File G:\Python25\lib\site.py, line 356, in aliasmbcs
import locale, codecs
  File G:\Python25\lib\locale.py, line 14, in module
import sys, encodings, encodings.aliases
  File F:\Python25\lib\encodings\__init__.py, line 32, in module
ValueError: bad marshal data
# G:\Python25\lib\warnings.pyc matches G:\Python25\lib\warnings.py
import warnings # precompiled from G:\Python25\lib\warnings.pyc
# G:\Python25\lib\linecache.pyc matches G:\Python25\lib\linecache.py
import linecache # precompiled from G:\Python25\lib\linecache.pyc
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win
32
Type help, copyright, credits or license for more information.

-

What can I do about this?

Thanks,

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


Re: Getting VideoCapture to work with Python 2.5

2006-12-29 Thread Carsten Haese
On Fri, 2006-12-29 at 19:15 +, Just Another Victim of the Ambient
Morality wrote:
 I can't seem to get VideoCapture (http://videocapture.sourceforge.net/) 
 to work with my version of Python (2.5).  Why is that?  I've followed the 
 instructions which made it look easy but, as it happens all too often, it 
 simply doesn't work.  The error I get is that the .py interface file can't 
 find an expected module (using the import keyword) but that module exists 
 as a DLL in the correct directory.  Why doesn't it recognize it?
 Has anyone else used this library with Python 2.5 successfully?  Any 
 theories as to what might be going wrong?  Thank you...

DLL extension modules have to be compiled specifically for each major
Python version. The website makes no indication that the module is
supposed to work on Python 2.5, and the zip file contains folders for
Python 2.0 through 2.4, but 2.5 is conspicuously missing. You could
downgrade to Python 2.4 or ask the author to make a version for Python
2.5 available.

-Carsten


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


Help on installing Easy_Install

2006-12-29 Thread TiNo
Hi,

I'm having problems installing easy_install. When I run python
ez_setup.py I get:

G:\pythonpython ez_setup.py
'import site' failed; use -v for traceback
Downloading http://cheeseshop.python.org/packages/2.5/s/setuptools/setuptools-0.
6c3-py2.5.egg
Processing setuptools-0.6c3-py2.5.egg
Copying setuptools-0.6c3-py2.5.egg to g:\python25\lib\site-packages
Adding setuptools 0.6c3 to easy-install.pth file
Traceback (most recent call last):
  File ez_setup.py, line 217, in module
main(sys.argv[1:])
  File ez_setup.py, line 152, in main
return main(list(argv)+[egg])   # we're done here
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 1588, in main
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 1577, in with_ei_usage
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 1592, in lambda
  File F:\Python25\lib\distutils\core.py, line 151, in setup
  File F:\Python25\lib\distutils\dist.py, line 974, in run_commands
  File F:\Python25\lib\distutils\dist.py, line 994, in run_command
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 211, in run
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 427, in easy_install
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 473, in install_item
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 497, in process_distribution
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 373, in install_egg_scripts
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 569, in install_wrapper_scripts
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 1480, in get_script_args
  File G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py
, line 1412, in get_script_header
LookupError: no codec search functions registered: can't find encoding

?? What to do?

thanks,

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


Re: Starting a child process and getting its stdout?

2006-12-29 Thread Tom Plunket
cypher543 wrote:

 Thank you for the examples, but I have tried all of that before.

Did you try my example specifically?

 No matter what I do, my program always hangs while it waits for the
 process to exit and then it prints all of the output at once.
 
 self.buildPID = subprocess.Popen([python, tobeforked.py], ...

By default, python will execute in buffered mode if it's attached to a
pipe.  Start it with the '-u' command line option and you may be good to
go.  (`python -h` for more info on this, man pages may also discuss it.)

-tom!

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


Re: Simplest way to do Python/Ajax with server and client on same machine?

2006-12-29 Thread John J. Lee
Adonis Vargas [EMAIL PROTECTED] writes:

 Kenneth McDonald wrote:
  I'm doing some work with a Python program that works hand-in-hand
  with the DOM on a local client (processing DOM events, issuing DOM
  modification commands, etc.) I'm currently using cherrypy as the
  Python server for this communication, and simple AJAX on the client
  browser end. This works just fine, I'm simply wondering if there is
  a better (even easier) way to do this, if there are libraries I'm
  not aware of that I should be, etc.
  Thanks,
  Ken
 
 You can try looking into PyJamas its a Python version of Google Web
 Toolkit, offers a way to create AJAX apps using Python code.

Have a look at TurboGears too.

Both are still pretty new.  Pyjamas is very new, so I'd certainly
think twice about using it for production work right now.


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


Re: I want to see all the variables

2006-12-29 Thread johnf
Steven D'Aprano wrote:

 On Fri, 29 Dec 2006 08:20:22 -0600, Larry Bates wrote:
 
 johnf wrote:
 Hi,
 When I use dir() I don't see the __ underscore items.  Is there anything
 that will show all the private vars and functions?
 
 johnf
 
 The idea of the underscore items is that they aren't to be used by
 you.
 
 Double leading+trailing underscore attributes are NOT private, they are
 *special* but public (e.g. __dict__, __class__, __str__, etc.). If you
 don't believe me, have a look at dir(int) and count the underscored
 attributes listed. Then try to find __dict__, __name__, __bases__,
 __base__ or __mro__ within the list. Why are they suppressed?
 
 But even if underscored attributes were private, the Python philosophy is
 that private attributes are private by convention only -- even
 name-mangled __private methods can be reached if you know how.
 
 
 If you wish to access private variables and functions you will
 almost certainly have to look at the source code to make sure of
 what they are and how they can be utilized.
 
 Not so.
 
 class Parrot(object):
 ... def _private(self):
 ... Private method, returns a magic string.
 ... return Don't touch!!!
 ...
 Parrot._private.__doc__
 Private method, returns a magic string.
 
 
 
Ok then how do debug when I have something like __source  and I need to
know what is available for the object?

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


Re: probably a stupid question: MatLab equivalent of diff ?

2006-12-29 Thread Marcus Goldfish

On 12/29/06, Stef Mientki [EMAIL PROTECTED] wrote:


Does anyone know the equivalent of the MatLab diff function.
The diff functions calculates the difference between 2 succeeding
elements of an array.
I need to detect (fast) the falling edge of a binary signal.

There's derivate function in Python diff,
but when you use an binary (true/false) input,
it also detects rising edges.

Probably a stupid question,
but I still have troubles,
digging to huge amount of information about Python.

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


Stef,

Can you provide more context on your use-- are you receiving binary data
sequentially, or do you have a list or array of binary values?  Are you
using numpy/scipy?

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

Re: Python-list Digest, Vol 39, Issue 465

2006-12-29 Thread Ray Schumacher


At 10:50 AM 12/29/2006, you wrote:
In addition to what Chris said,
is there a reason why you're reinventing
the wheel instead of using available components? 
Hi Carsten,
The eventual goal here is towards a streaming two-way server, which
wouldn't use the http, but something more like
RTP/RTCP/H.323/ which I'm learning. It's also
a general socket learning exercise for me, as I haven't used them
very much.
I was also using PyDShowCam before, and have switched to VideoCapture
since I'll need to recompile PyDShowCam for py2.4.
I will look into the wx Chris suggested this weekend; more stuff I
haven't used...
Thanks,
Ray
For anyone interested, I attached a quick wx I made last night that
monitors a USB webcam, will create dark frames (a la
astronomy), and serve up images to web browsers (thus the question). The
browser/monitor would actually work nicely with a web page that has a
_javascript_ function to reload the image x times/second. I'll try
replacing the PIL with the wx function(s) and benchmark if they
work.


#Boa:Frame:Frame1
import gc
from time import clock
from numpy import fromstring, add, subtract, divide, where, zeros

import socket
import wx
#import PyDShowCam
import VideoCapture
from StringIO import StringIO
from PIL import Image

def create(parent):
return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BUTTONCONNECT, wxID_FRAME1BUTTONPROPERTIES, 
 wxID_FRAME1BUTTONSERVER, wxID_FRAME1BUTTONSETDARK, wxID_FRAME1BUTTONSTOP, 
 wxID_FRAME1CHECKBOXDIFF, wxID_FRAME1PANEL1, wxID_FRAME1STATICBITMAPVIDEO, 
 wxID_FRAME1STATUSBAR1, wxID_FRAME1TEXTCTRLADDRESS, wxID_FRAME1TOOLBAR1, 
 wxID_FRAME1WINDOWVIDEO, 
] = [wx.NewId() for _init_ctrls in range(13)]

class Frame1(wx.Frame):
def _init_coll_toolBar1_Tools(self, parent):
# generated method, don't edit

parent.AddControl(control=self.textCtrlAddress)
parent.AddControl(control=self.buttonConnect)
parent.AddControl(control=self.buttonStop)
parent.AddControl(control=self.buttonProperties)
parent.AddControl(control=self.checkBoxDiff)
parent.AddControl(control=self.buttonSetDark)
parent.AddControl(control=self.buttonServer)

parent.Realize()

def _init_coll_statusBar1_Fields(self, parent):
# generated method, don't edit
parent.SetFieldsCount(3)

parent.SetStatusText(number=0, text='frame:0,\t0fps')
parent.SetStatusText(number=1, text='')
parent.SetStatusText(number=2, text='')

parent.SetStatusWidths([200, -1, 100])

def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
  pos=wx.Point(278, 392), size=wx.Size(746, 377),
  style=wx.DEFAULT_FRAME_STYLE, title='Confer')
self.SetClientSize(wx.Size(738, 350))

self.statusBar1 = wx.StatusBar(id=wxID_FRAME1STATUSBAR1,
  name='statusBar1', parent=self, style=0)
self._init_coll_statusBar1_Fields(self.statusBar1)
self.SetStatusBar(self.statusBar1)

self.toolBar1 = wx.ToolBar(id=wxID_FRAME1TOOLBAR1, name='toolBar1',
  parent=self, pos=wx.Point(0, 0), size=wx.Size(767, 27),
  style=wx.TB_HORIZONTAL)
self.SetToolBar(self.toolBar1)

self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
  pos=wx.Point(0, 27), size=wx.Size(738, 303),
  style=wx.TAB_TRAVERSAL)
self.panel1.SetBackgroundColour(wx.Colour(255, 255, 255))

self.windowVideo = wx.Window(id=wxID_FRAME1WINDOWVIDEO,
  name='windowVideo', parent=self.panel1, pos=wx.Point(8, 8),
  size=wx.Size(352, 288), style=0)
self.windowVideo.SetBackgroundColour(wx.Colour(0, 0, 0))

self.textCtrlAddress = wx.TextCtrl(id=wxID_FRAME1TEXTCTRLADDRESS,
  name='textCtrlAddress', parent=self.toolBar1, pos=wx.Point(0, 0),
  size=wx.Size(100, 21), style=0, value='192.168.0.1')
self.textCtrlAddress.SetToolTipString('Enter the remote address here')

self.buttonConnect = wx.Button(id=wxID_FRAME1BUTTONCONNECT,
  label='Connect', name='buttonConnect', parent=self.toolBar1,
  pos=wx.Point(100, 1), size=wx.Size(60, 19), style=0)
self.buttonConnect.Bind(wx.EVT_BUTTON, self.OnButtonConnectButton,
  id=wxID_FRAME1BUTTONCONNECT)

self.buttonStop = wx.Button(id=wxID_FRAME1BUTTONSTOP, label='Stop',
  name='buttonStop', parent=self.toolBar1, pos=wx.Point(160, 1),
  size=wx.Size(49, 19), style=0)
self.buttonStop.Bind(wx.EVT_BUTTON, self.OnButtonStopButton,
  id=wxID_FRAME1BUTTONSTOP)

self.buttonProperties = wx.Button(id=wxID_FRAME1BUTTONPROPERTIES,
  label='Cam Properties', name='buttonProperties',
  parent=self.toolBar1, pos=wx.Point(209, 1), size=wx.Size(88, 19),
  style=0)

Re: Python-list Digest, Vol 39, Issue 465

2006-12-29 Thread Chris Mellon
On 12/29/06, Ray Schumacher [EMAIL PROTECTED] wrote:

  At 10:50 AM 12/29/2006, you wrote:

 In addition to what Chris said, is there a reason why you're reinventing
  the wheel instead of using available components?
  Hi Carsten,
  The eventual goal here is towards a streaming two-way server, which
 wouldn't use the http, but something more like RTP/RTCP/H.323/ which I'm
 learning. It's also a general socket  learning exercise for me, as I haven't
 used them very much.
  I was also using PyDShowCam before, and have switched to VideoCapture since
 I'll need to recompile PyDShowCam for py2.4.
  I will look into the wx Chris suggested this weekend; more stuff I haven't
 used...

  Thanks,
  Ray

  For anyone interested, I attached a quick wx I made last night that
 monitors a USB webcam, will create dark frames (a la astronomy), and serve
 up images to web browsers (thus the question). The browser/monitor would
 actually work nicely with a web page that has a JavaScript function to
 reload the image x times/second. I'll try replacing the PIL with the wx
 function(s) and benchmark if they work.


I just double-checked my documentation and wx.Image.GetData() is not
what you want - that's the RGB pixel data, and you want the encoded
stream.

Using pil to save directly to the output buffer is probably the most
efficient mechanism - it doesn't look like wxPython provides
SaveStream (or SaveBuffer). Those probably could be implemented (the
C++ wxImage object supports saving to streams, and SWIG can make a
python FLO look like a stream), you might want to post a feature
request.
-- 
http://mail.python.org/mailman/listinfo/python-list


No way to set a timeout in urllib.

2006-12-29 Thread John Nagle
There's no way to set a timeout if you use urllib to open a URL.
HTTP, which urllib uses, supports this, but the functionality
is lost at the urllib level.

It's not available via class URLopener or FancyURLopener, either.

There is a non-thread-safe workaround from 2003 at

http://mail.python.org/pipermail/python-bugs-list/2003-September/020405.html

but it was rejected as a feature at

https://sourceforge.net/tracker/?func=detailatid=105470aid=803634group_id=5470

without anything better going in.  Despite this, current documentation
recommends that approach:

http://svn.python.org/projects/python/trunk/Doc/howto/urllib2.rst

Someone proposed to fix this

http://mail.python.org/pipermail/python-dev/2006-July/066967.html

but was discouraged from doing so.

The code was forked by Zope as a workaround in 2003:

http://pywebsvcs.sourceforge.net/apidocs/wstools/Utility.html

but that's not in the mainstream Python tree.

The correct fix would probably be to add methods to class
URLopener to control this; that's the usual way of handling special
URL opening situations.

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


Wow, Python much faster than MatLab

2006-12-29 Thread Stef Mientki
hi All,

instead of questions,
my first success story:

I converted my first MatLab algorithm into Python (using SciPy),
and it not only works perfectly,
but also runs much faster:

MatLab: 14 msec
Python:  2 msec

After taking the first difficult steps into Python,
all kind of small problems as you already know,
it nows seems a piece of cake to convert from MatLab to Python.
(the final programs of MatLab and Python can almost only be 
distinguished by the comment character ;-)

Especially I like:
- more relaxed behavior of exceeded the upper limit of a (1-dimensional) 
  array
- much more functions available, like a simple mean
- reducing datatype if it's allowed (booleans of 1 byte)

thanks for all your help,
probably need some more in the future,
cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Easiest way to print from XP/DOS.

2006-12-29 Thread jim-on-linux


This is the situation I'm in.

I've built a single file utility using py2exe. I 
zip the dist directory and send it to the client.

For clients that use  win95, win98 machines,
They unpack the zip file and run the exe.

The utility creates a text file that is sent to 
the printer with the statement below. 
   os.system('type ' +FileName+ ' prn'),
and the file prints.

But, from an xp machine if I try to print using 
the same statement,  I get a question on the dos 
screen which reads something like this;
  Which program authorized this operation?

Since I don't have an xp machine, the statement 
above may not be exact, but you get the idea.  

The question I have is, first is there any way to 
work around the question asked by the xp machine 
using python. 

If not, I may have to register the package in xp, 
if registering the utility the only way, which 
package is the simplest to use.
Also, if the utility is registered in xp, will the 
same statement send the file to the printer as it 
does in win98. 

jim-on-linux











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


Re: I want to see all the variables

2006-12-29 Thread Steven D'Aprano
On Fri, 29 Dec 2006 12:04:11 -0800, johnf wrote:

 Ok then how do debug when I have something like __source  and I need to
 know what is available for the object?

Outside of a class, objects with two leading underscores are just ordinary
objects with no special behaviour:

 __source = 2
 __source
2

Objects with a single leading underscore like _source are slightly
special: if you do from module import * any names with a single leading
underscore are not imported.

Class attributes with two leading underscores like __source are considered
private to the class, so in general you shouldn't need to know anything
about them. To enforce that, Python mangles the name so it is harder to
reach.

But if/when you do need to get to them, they are easy to get to:

 class Spam:
... __attribute = 2
...
 Spam().__attribute
Traceback (most recent call last):
  File stdin, line 1, in ?
AttributeError: Spam instance has no attribute '__attribute'
 Spam()._Spam__attribute
2

Notice that Python doesn't generally try to hide private attributes:

 dir(Spam)
['_Spam__attribute', '__doc__', '__module__']

There are three other underscore conventions in use:

(1) Objects with a single leading underscore like _attribute are private
by convention, but Python doesn't enforce it. Starting an object with a
single underscore is like writing # Private! Don't touch! after it.

(2) By convention, if you want to create a name that is the same as a
built-in object without shadowing (hiding) the built-in, put a single
trailing underscore after it like file_. That's just a style convention
though, you are free to call it FiLE ,or anything else, if you prefer.

(3) Last but not least, class attributes with two leading and trailing
underscores are considered special but public, like __init__ and __repr__.
It is probably a bad idea to invent your own.



-- 
Steven.

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


Re: Easiest way to print from XP/DOS.

2006-12-29 Thread Larry Bates
jim-on-linux wrote:
 
 This is the situation I'm in.
 
 I've built a single file utility using py2exe. I 
 zip the dist directory and send it to the client.
 
 For clients that use  win95, win98 machines,
 They unpack the zip file and run the exe.
 
 The utility creates a text file that is sent to 
 the printer with the statement below. 
os.system('type ' +FileName+ ' prn'),
 and the file prints.
 
 But, from an xp machine if I try to print using 
 the same statement,  I get a question on the dos 
 screen which reads something like this;
   Which program authorized this operation?
 
 Since I don't have an xp machine, the statement 
 above may not be exact, but you get the idea.  
 
 The question I have is, first is there any way to 
 work around the question asked by the xp machine 
 using python. 
 
 If not, I may have to register the package in xp, 
 if registering the utility the only way, which 
 package is the simplest to use.
 Also, if the utility is registered in xp, will the 
 same statement send the file to the printer as it 
 does in win98. 
 
 jim-on-linux
 

I don't get any such message on my XP Pro Service Pack 2 system
here using your method.

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


PEP 3107 Function Annotations for review and comment

2006-12-29 Thread Tony Lownds
(Note: PEPs in the 3xxx number range are intended for Python 3000)

PEP: 3107
Title: Function Annotations
Version: $Revision: 53169 $
Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec 2006) $
Author: Collin Winter [EMAIL PROTECTED],
 Tony Lownds [EMAIL PROTECTED]
Status: Draft
Type: Standards Track
Requires: 362
Content-Type: text/x-rst
Created: 2-Dec-2006
Python-Version: 3.0
Post-History:


Abstract


This PEP introduces a syntax for adding arbitrary metadata annotations
to Python functions [#functerm]_.


Rationale
=

Because Python's 2.x series lacks a standard way of annotating a
function's parameters and return values (e.g., with information about
what type a function's return value should be), a variety of tools
and libraries have appeared to fill this gap [#tailexamp]_.  Some
utilise the decorators introduced in PEP 318, while others parse a
function's docstring, looking for annotations there.

This PEP aims to provide a single, standard way of specifying this
information, reducing the confusion caused by the wide variation in
mechanism and syntax that has existed until this point.


Fundamentals of Function Annotations


Before launching into a discussion of the precise ins and outs of
Python 3.0's function annotations, let's first talk broadly about
what annotations are and are not:

1. Function annotations, both for parameters and return values, are
completely optional.

2. Function annotations are nothing more than a way of associating
arbitrary Python expressions with various parts of a function at
compile-time.

By itself, Python does not attach any particular meaning or
significance to annotations.  Left to its own, Python simply makes
these expressions available as described in `Accessing Function
Annotations`_ below.

The only way that annotations take on meaning is when they are
interpreted by third-party libraries.  These annotation consumers
can do anything they want with a function's annotations.  For
example, one library might use string-based annotations to provide
improved help messages, like so::

 def compile(source: something compilable,
 filename: where the compilable thing comes from,
 mode: is this a single statement or a suite?):
 ...

Another library might be used to provide typechecking for Python
functions and methods.  This library could use annotations to
indicate the function's expected input and return types, possibly
something like::

 def haul(item: Haulable, *vargs: PackAnimal) - Distance:
 ...

However, neither the strings in the first example nor the
type information in the second example have any meaning on their
own; meaning comes from third-party libraries alone.

3. Following from point 2, this PEP makes no attempt to introduce
any kind of standard semantics, even for the built-in types.
This work will be left to third-party libraries.

There is no worry that these libraries will assign semantics at
random, or that a variety of libraries will appear, each with
varying semantics and interpretations of what, say, a tuple of
strings means. The difficulty inherent in writing annotation
interpreting libraries will keep their number low and their
authorship in the hands of people who, frankly, know what they're
doing.


Syntax
==

Parameters
--

Annotations for parameters take the form of optional expressions that
follow the parameter name.  This example indicates that parameters
'a' and 'c' should both be an ``int``, while parameter 'b' should
be a ``dict``::

 def foo(a: int, b: dict, c: int = 5):
 ...

In pseudo-grammar, parameters now look like ``identifier [:
expression] [= expression]``.  That is, annotations always precede a
parameter's default value and both annotations and default values are
optional.  Just like how equal signs are used to indicate a default
value, colons are used to mark annotations.  All annotation
expressions are evaluated when the function definition is executed.

Annotations for excess parameters (i.e., ``*args`` and ``**kwargs``)
are indicated similarly.  In the following function definition,
``*args`` is flagged as a tuple of ``int``, and ``**kwargs`` is
marked as a dict whose keys are strings and whose values are of type
``str``::

 def foo(*args: int, **kwargs: str):
 ...

Note that, depending on what annotation-interpreting library you're
using, the following might also be a valid spelling of the above::

 def foo(*args: [int], **kwargs: {str: str}):
 ...

Only the first, however, has the BDFL's blessing [#blessedexcess]_ as
the One Obvious Way.


Return Values
-

The examples thus far have omitted examples of how to annotate the
type of a function's return value.  This is done like so::

 def sum(*args: int) 

mmmmmmmmmmm

2006-12-29 Thread Janez ROM

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


Re: Easiest way to print from XP/DOS.

2006-12-29 Thread jim-on-linux

Did you run from a file or type in from keyboard?

When the client runs the utility program  the 
output file is built but nothing prints and no 
messages appear. When I typed from keyboard on an 
xp pro at c:\, I got the message.

Is it possible that  virus detector or some 
self.defense software is interacting?


On Friday 29 December 2006 17:58, Larry Bates 
wrote:
 jim-on-linux wrote:
  This is the situation I'm in.
 
  I've built a single file utility using
  py2exe. I zip the dist directory and send it
  to the client.
 
  For clients that use  win95, win98 machines,
  They unpack the zip file and run the exe.
 
  The utility creates a text file that is sent
  to the printer with the statement below.
  os.system('type ' +FileName+ ' prn'), and
  the file prints.
 
  But, from an xp machine if I try to print
  using the same statement,  I get a question
  on the dos screen which reads something like
  this; Which program authorized this
  operation?
 
  Since I don't have an xp machine, the
  statement above may not be exact, but you get
  the idea.
 
  The question I have is, first is there any
  way to work around the question asked by the
  xp machine using python.
 
  If not, I may have to register the package in
  xp, if registering the utility the only way,
  which package is the simplest to use.
  Also, if the utility is registered in xp,
  will the same statement send the file to the
  printer as it does in win98.
 
  jim-on-linux

 I don't get any such message on my XP Pro
 Service Pack 2 system here using your method.

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


Re: PEP 3107 Function Annotations for review and comment

2006-12-29 Thread BJörn Lindqvist
On 12/29/06, Tony Lownds [EMAIL PROTECTED] wrote:
 Rationale
 =

 Because Python's 2.x series lacks a standard way of annotating a
 function's parameters and return values (e.g., with information about
 what type a function's return value should be), a variety of tools
 and libraries have appeared to fill this gap [#tailexamp]_.  Some
 utilise the decorators introduced in PEP 318, while others parse a
 function's docstring, looking for annotations there.

 This PEP aims to provide a single, standard way of specifying this
 information, reducing the confusion caused by the wide variation in
 mechanism and syntax that has existed until this point.

I think this rationale is very lacking and to weak for such a big
change to Python. I definitely like to see it expanded.

The reference links to two small libraries implementing type checking
using decorators and doc strings. None of which to seem to be very
popular in the Python community. Surely, those two libraries *alone*
can't be enough of a motivation for this? To me, it is far from
self-evident what purpose function annotations would serve.

I also wonder why a very obtrusive syntax addition is needed when it
clearly is possible to annotate functions in today's Python. Why is
syntax better than just adding a function annotation decorator to the
standard library?

@annotate(a = int, b = dict, c = int)
def foo(a, b, c = 5):
...

Are decorators to ugly?

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does Python never add itself to the Windows path?

2006-12-29 Thread Martin v. Löwis
Ben Sizer schrieb:
 I've installed several different versions of Python across several
 different versions of MS Windows, and not a single time was the Python
 directory or the Scripts subdirectory added to the PATH environment
 variable. Every time, I've had to go through and add this by hand, to
 have something resembling a usable Python installation. No such
 problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or
 Kubuntu. So why is the Windows install half-crippled by default? 

For several reasons:
1. Python can be used just fine without being on PATH. Python
   scripts run fine both when double-clicked and when invoked in
   the command line, and if you want to use an interactive
   interpreter, you can find it readily on the Start menu.
2. Many windows users (including myself) dislike setup routines that
   manipulate PATH. I believe that the PATH environment variable
   is owned by the user; if Python is to be found in PATH, it
   should rather be installed to a directory that is known to live
   on PATH (or where CreateProcess searches, anyway, such
   as system32). So if the installer had such a feature, it should
   be optional, and it should default to off.
3. Most importantly: it is difficult to implement, and nobody has
   contributed code to make it work.

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


Re: per interpreter storage for C extensions

2006-12-29 Thread Martin v. Löwis
Robin Becker schrieb:
 Is there a simple/cheap way for C code to cache these sorts of module
 level globals on a per interpreter basis? Is there even a way to tell
 which interpreter I'm being called in?

There is no cheap way to add to the interpreter state. As Chris Mellon
explains, you can use PyThreadState_Get()-interp to find the
interpreter state. I recommend to do the caching only in the
single-interpreter case (i.e. for the first interpreter).

Notice that comparing interpreter states by identity is somewhat
dangerous: the interpreter may have been deleted with you still
holding a pointer to it, and a new interpreter may get allocated
at the same address, making you believe it is the same interpreter.

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


Re: xml bug?

2006-12-29 Thread Martin v. Löwis
Imbaud Pierre schrieb:
 - how do I spot the version of a given library? There is a __version__
   attribute of the module, is that it?

Contrary to what others have said: for modules included in the standard
library (and if using these modules, rather than using PyXML), you
should use sys.version_info to identify a version.

 - How do I access to a given library buglist? Maybe this one is known,
   about to be fixed, it would then be useless to report it.

Others have already pointed you to SF.

 - How do I report bugs, on a standard lib?

Likewise.

 - I tried to copy the lib somewhere, put it BEFORE the official lib in
   the path (that is:sys.path), the stack shown by the traceback
   still shows the original files being used. Is there a special
   mechanism bypassing the sys.path search, for standard libs? (I may
   be wrong on this, it seems hard to believe...)

Which lib? minidom.py? Well, you are likely importing
xml.dom.minidom, not minidom. So adding another minidom.py
to a directory in sys.path won't help.

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


Re: xml bug?

2006-12-29 Thread Martin v. Löwis
Imbaud Pierre schrieb:
 But python.org was the right entry point, it sent me to the bug
 tracker: http://sourceforge.net/tracker/?group_id=5470atid=105470
 Its a bit short on explanations... And I found unsolved issues,
 3 years old!

That's true, and likely to grow. Contributions are welcome!

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


Re: Minor problem with configure (2.4.4)

2006-12-29 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
 configure.in:273: error: possibly undefined macro: AC_UNDEFINE
   If this token and others are legitimate, please use
 m4_pattern_allow.
   See the Autoconf documentation.
 
 Ideas?

RTFM (autoconf documentation, in this case). There is no AC_UNDEFINE.

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


Re: bad marshal data in site.py in fresh 2.5 install win

2006-12-29 Thread Martin v. Löwis
TiNo schrieb:
 # G:\Python25\lib\encodings\aliases.pyc matches
[...]
  File F:\Python25\lib\encodings\__init__.py, line 32, in module

 What can I do about this?

Where does F:\Python25 come from?

If you have set any PYTHON* environment variables (e.g. PYTHONPATH),
unset them.

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


Re: PEP 3107 Function Annotations for review and comment

2006-12-29 Thread Tony Lownds


On Dec 29, 2006, at 4:09 PM, BJörn Lindqvist wrote:


I think this rationale is very lacking and to weak for such a big
change to Python. I definitely like to see it expanded.

The reference links to two small libraries implementing type checking
using decorators and doc strings. None of which to seem to be very
popular in the Python community. Surely, those two libraries *alone*
can't be enough of a motivation for this? To me, it is far from
self-evident what purpose function annotations would serve.

I also wonder why a very obtrusive syntax addition is needed when it
clearly is possible to annotate functions in today's Python. Why is
syntax better than just adding a function annotation decorator to the
standard library?

@annotate(a = int, b = dict, c = int)
def foo(a, b, c = 5):
...

Are decorators to ugly?


The syntax does look better than a decorator. The syntax also provides
a notation for documentation to follow. Even a standard decorator won't
help with that. I am surprised you think the syntax is more  
obstrusive than the

decorator.

-Tony

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

Re: Question about the new module

2006-12-29 Thread Graham Dumpleton

[EMAIL PROTECTED] wrote:
 Gabriele I'm using Python 2.5 to develop a simple MVC framework based
 Gabriele on mod_python. To load my controllers, I create new modules
 Gabriele using the new module like this:

 Gabriele # 
 Gabriele my_module = new.module(random_name)
 Gabriele my_module.__file__ = module_path
 Gabriele exec open(module_path, r) in my_module.__dict__

 Gabriele then I initialize the class defined inside the module and call
 Gabriele a method of this class based on the HTTP request.

 Why use the new module?  Why not call __import__() or execfile()?  Details
 on their use are here:

 http://docs.python.org/dev/lib/built-in-funcs.html

Or why not use mod_python.apache.import_module() from mod_python
itself. It is designed as a way of users importing specific modules,
including the capability for modules to be reloaded if they have been
changed. See:


http://www.dscpl.com.au/wiki/ModPython/Articles/BasicsOfModuleImporting

as well as the mod_python documentation.

Is recommended though to use mod_python 3.3 as soon as you can though
if you want the module reloading to always work. You can find
descriptions of problems with the module reloading in older versions of
mod_python at:


http://www.dscpl.com.au/wiki/ModPython/Articles/ModuleImportingIsBroken

Note that module importer in mod_python 3.3 has been enhanced some what
over prior versions in addition to fixing problems. An important new
feature is being able to load modules based on their path with modules
with same names in different directories being properly distinguished,
something which is quite useful where modules are used in web
applications to represent pages. You may want to look at documentation
for it at:


http://www.modpython.org/live/mod_python-3.3.0b/doc-html/pyapi-apmeth.html

Graham

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


Managing a queue of subprocesses?

2006-12-29 Thread cypher543
My app uses a queue of commands which are run one at a time. I am
using the subprocess module to execute the commands in the queue.
However, processes always run at the same time. How can I make one
process run at a time, and then execute the next process when the first
has terminated? My code is below:

self.cmdQueue = {}
self.queue(theProject.directory, ls, -l)
self.queue(theProject.directory, echo, hello, world!)

def consoleLogAddLine(self, text):
self.consoleLogBuffer.insert(self.consoleLogBuffer.get_end_iter(),
text)
self.consoleLog.scroll_to_mark(self.consoleLogBuffer.get_insert(), 0)

def onGetData(self, fd, cond, *args):
self.consoleLogAddLine(fd.readline())
return True

def queue(self, rootDir, cmd, args = ):
count = len(self.cmdQueue) + 1
self.cmdQueue[count] = [cmd, args, rootDir]

def runQueue(self):
for i in self.cmdQueue.values():
self.execute(i[2], i[0], i[1])

def execute(self, rootDir, cmd, args = ):
os.chdir(rootDir)
if args == :
buildCmd = cmd
else:
args = args.split( )
buildCmd = [cmd] + args
self.buildPID = subprocess.Popen(buildCmd, stdout = subprocess.PIPE,
stderr = subprocess.STDOUT)
gobject.io_add_watch(self.buildPID.stdout, gobject.IO_IN,
self.onGetData)

As you can see, I add the commands ls -l and echo Hello to the
queue. However, Hello is always printed inside the output of ls -l.
I would like to wait for ls -l to terminate and then run echo
Hello. But, the output must still print to the consoleLogBuffer
line-by-line, and my GUI must not hang during execution.

Is this even possible?

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


Re: textwrap.dedent replaces tabs?

2006-12-29 Thread OKB (not okblacke)
Frederic Rentsch wrote:

 (You dedent common leading tabs, except if preceded by common leading 
 spaces (?)). 

There cannot be common leading tabs if they are preceded by 
anything.  If they were preceded by something, they wouldn't be 
leading.

-- 
--OKB (not okblacke)
Brendan Barnwell
Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail.
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Anyone persuaded by merits of Lisp vs Python?

2006-12-29 Thread Steven Haflich
Ray wrote:
 Can one really survive knowing just
 one language these days, anyway? 

いいえ! 違います。
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: No way to set a timeout in urllib.

2006-12-29 Thread skip

John There's no way to set a timeout if you use urllib to open a URL.
John HTTP, which urllib uses, supports this, but the functionality
John is lost at the urllib level.

John It's not available via class URLopener or FancyURLopener,
John either.

John There is a non-thread-safe workaround from 2003 at

...

This topic has come up several times since timeouts were added to socket.
Each time we've asked for a patch that adds timeouts in a rational manner to
all the stuff layered on top of the socket module (httplib, ftplib, etc). As
far as I know it's apparently never been important enough for anyone to rise
to the challenge.  If I remember next spring perhaps I'll submit it as a
possible Google Summer of Code proposal.

John The correct fix would probably be to add methods to class
John URLopener to control this; that's the usual way of handling
John special URL opening situations.

The correct way would be to deal with it at the httplib level, then
percolate it up to urllib2.  Urllib should probably not be extended any
further.

Skip

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


Re: Wow, Python much faster than MatLab

2006-12-29 Thread Beliavsky

Stef Mientki wrote:
 hi All,

 instead of questions,
 my first success story:

 I converted my first MatLab algorithm into Python (using SciPy),
 and it not only works perfectly,
 but also runs much faster:

 MatLab: 14 msec
 Python:  2 msec

For times this small, I wonder if timing comparisons are valid. I do
NOT think SciPy is in general an order of magnitude faster than Matlab
for the task typically performed with Matlab.


 After taking the first difficult steps into Python,
 all kind of small problems as you already know,
 it nows seems a piece of cake to convert from MatLab to Python.
 (the final programs of MatLab and Python can almost only be
 distinguished by the comment character ;-)

 Especially I like:
 - more relaxed behavior of exceeded the upper limit of a (1-dimensional)
   array

Could you explain what this means? In general, I don't want a
programming language to be relaxed about exceeding array bounds.

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


Re: probably a stupid question: MatLab equivalent of diff ?

2006-12-29 Thread Carl Banks
Stef Mientki wrote:
 Does anyone know the equivalent of the MatLab diff function.
 The diff functions calculates the difference between 2 succeeding
 elements of an array.
 I need to detect (fast) the falling edge of a binary signal.

Using numpy (or predecessors), you can do this easily with slicing:

a[1:] - a[:-1]

Slicing shares data, so the slices above don't create new arrays, but
new views into the old array, so it avoids that overhead.

For Python lists you'd have to use a list comprehension or some such
thing like that.  For example:

[ x-y for (x,y) in zip(a[1:],a[:-1]) ]

Or, to avoid creating two new arrays, use iterators:

import itertools
[ x-y for (x,y) in
itertools.izip(itertools.islice(a,0,-1),itertools.islice(a,1)) ]


Carl

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


Re: DOS, UNIX and tabs

2006-12-29 Thread Paul McNett
Steven D'Aprano wrote:
 But I think we all agree that mixing tabs and spaces is A Very Bad Thing.

I like mixing tabs and spaces, actually. Tabs for indentation, and 
additional spaces to make the code look pretty. Somebody please tell 
me why this is bad and I'll stop.

class Apple(object):
def contrived_example_function(self, argument1, argument2,
   argument3, argument4):
print hello, world

Apparently, emacs in python mode follows this convention, too. I like it 
because I get the best of both worlds: the only thing against using 
tabs-only-indentation is that wrapping long lines can be quite ugly, 
while space-only-indentation allows for beautifying it somewhat by 
lining up the columns to match. Tabs+spaces allows the lining up with 
spaces to be explicitly separate from indentation.

-- 
pkm ~ http://paulmcnett.com

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


Re: Anyone persuaded by merits of Lisp vs Python?

2006-12-29 Thread Kaz Kylheku
Steven Haflich wrote:
 Ray wrote:
  Can one really survive knowing just
  one language these days, anyway?

 いいえ! 違います。

iie! chigaimas.

No, I beg to differ!

(Hey, I'm in right the middle of preparing my Kanji-drilling Lisp
program for distribution).

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

  1   2   >