Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.

2008-04-09 Thread Gabriel Genellina
En Thu, 10 Apr 2008 02:59:24 -0300, <[EMAIL PROTECTED]> escribió:

> I am getting the comments. So any one can post any comment like
> Steve knows nothing of Python.
> California has still lot to catch up to be at par with Mesopatamia.
> comp.lang.python  seems a group of fools.
> Anyhow, all I learnt take whichever suits and ignore rest many people
> have lot of time to carry out lot of nonsense.
> Well I should have looked for a paid help and my stand about not
> giving out my code in open forum stands as prolific. Better not lose
> time unnecessarily going back to work and debugging the problems is
> much sensical work that I can do instead of listening to jokes in the
> morning

I hope this whole thread is just a big misunderstanding, maybe a  
linguistic problem.
Nobody wants to steal your work, but if you say "my code is slow, what's  
wrong with it?", nobody can give any useful answer if you don't post the  
code. That's what everyone is saying, it's just common sense, in  
California, Mesopotamia or Buenos Aires.

Have a great life,
-- 
Gabriel Genellina

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


Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.

2008-04-09 Thread cokofreedom
Umm, Mesopotamia is an area geographically located between the Tigris
and Euphrates rivers, Bangalore isn't anywhere near that. And most of
that is presently under American control.

If you don't want to give out your code then try explaining it better.
What is the input, what is the output, how are you currently
processing. Describe these and people might be willing to aid more. Or
complain more about how unhelpful people are. Suits us.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem using import from PyRun_String

2008-04-09 Thread Gabriel Genellina
En Wed, 09 Apr 2008 13:31:22 -0300, Patrick Stinson  
<[EMAIL PROTECTED]> escribió:

> Well, I eventually want to add an import hook, but for now I'd rather  
> just
> get the import statement working normally again.
> I have embedded python as a scripting engine in my application. To do  
> this,
> I create a new empty module, run the script text using PyRun_String()
> passing the module's __dict__ as locals and globals. This populates the
> module's __dict__ with the resulting object references from the script  
> text.

Instead of PyRun_String, use PyImport_ExecCodeModuleEx, which takes care  
of setting __builtins__ and other details.
You will need to compile the source first (using Py_CompileStringFlags)  
which is a good thing anyway, to help catching errors.

> As I said before I must be forgetting some other module init stuff  
> because I
> had to manually populate the modules' __dict__ with references from the
> __builtin__ module in order to get the basic stuff like abs, range, etc.

That's not exactly what CPython does; if you inspect globals() you don't  
see abs, range, etc. Instead, there is a __builtins__ attribute (note the  
"s") that points to the __builtin__ module or its __dict__.

> I understand what __builtin__ is used for, but the C struct pointing to  
> the
> code frame that contains the import statement has a builtin member that
> apparently does not contain the __import__ function, hence my question.
> There must be some difference in the way code is parsed and a copy of the
> __builtin__ module is passed normally and the way I am doing it.

When a frame builtins != internal builtins, Python runs in "restricted  
execution mode", and disallows access to some objects and attributes, I  
think that __import__ is one of them.
See http://docs.python.org/lib/module-rexec.html
(That's why it's important to use the right way to create a module)

> So, finding the place where this module bootstrapping normally happens  
> would
> be awesome, because I sort of feel like I'm hacking this method running  
> into
> problems like this.

Exactly. The simplest way would be to save the source code on disk and  
just import it, letting Python do all the dirty work. But  
compiling+PyImport_ExecCodeModule should work, I presume - any feedback is  
welcome!

-- 
Gabriel Genellina

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


Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.

2008-04-09 Thread subhabrata . iisc
I am getting the comments. So any one can post any comment like
Steve knows nothing of Python.
California has still lot to catch up to be at par with Mesopatamia.
comp.lang.python  seems a group of fools.
Anyhow, all I learnt take whichever suits and ignore rest many people
have lot of time to carry out lot of nonsense.
Well I should have looked for a paid help and my stand about not
giving out my code in open forum stands as prolific. Better not lose
time unnecessarily going back to work and debugging the problems is
much sensical work that I can do instead of listening to jokes in the
morning



Marc 'BlackJack' Rintsch wrote:
> On Wed, 09 Apr 2008 16:16:14 +0200, Diez B. Roggisch wrote:
>
> > And then you reply telling us about the greatness of Bangalore and your
> > product to come. Which is somewhat amusing that people who claim to produce
> > the greatest software being incapable of debugging it deems me as odd - to
> > say the least.
>
> That's not odd, that's perfectly normal for really clever code:
>
>   Debugging is twice as hard as writing the code in the first
>   place.Therefore, if you write the code as cleverly as possible, you
>   are, by definition, not smart enough to debug it. -- Brian W. Kernighan
>
> ;-)
>
> Ciao,
>   Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wrapping C functions in python

2008-04-09 Thread Paul Anton Letnes
Brian and Diez:

First of all, thanks for the advice.

Brian:

I have installed NumPy and SciPy, but I can't seem to find a wavelet  
transform there.

The main point of this was more to learn C wrapping than to actually  
get a calculation done. I will probably be starting a PhD soon, doing  
really heavy computations. If I want to manipulate data (input /  
results), python is very nice, especially with gnuplot-py. However,  
heavy calculations should probably be done in C(++), especially as  
some code for this already exists.

I will look into SWIG.


Diez:

I will look into it. Do you know a good tutorial for this? I found the  
"standard" tutorial on C extensions, http://www.python.org/doc/ext/intro.html 
  , but as I mentioned, it seems to be a bit complicated to wrap heavy  
data structures like arrays.



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


Re: Data structure recommendation?

2008-04-09 Thread Tim Roberts
"Steven Clark" <[EMAIL PROTECTED]> wrote:
>
>Thanks for the reply. Can you explain how I could be bitten by
>floating point precision here?
>I'm familiar with how&why 1.3*3 != 3.9, etc., but I'm not sure how it
>applies here, or what you are gaining by converting to int.

Well, it depends on how you get your floating point numbers.  I assume you
won't be using hard-coded floating point constants as your indices.
Instead, you'll be computing them from data in files from somewhere. That's
where you have the opportunity to have one index that is 1.6-0.4 and one
index that is 0.8+0.4, and the two won't be the same.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need Help

2008-04-09 Thread Gabriel Genellina
En Wed, 09 Apr 2008 05:29:24 -0300, pramod sridhar <[EMAIL PROTECTED]>  
escribió:

> I would like to access type library files (.tlb) from python.
>
> The application (with .tlb extension) controls an external instrument  
> over
> standard GPIB interface.
> Is it possible to control this application from Python? If so, how ?
> Can anyone share or send link of some examples ?

You'll want a package pywin32 by Mark Hammond -available from sourceforge-  
and a book "Python Programming in Win32" by the same author.

-- 
Gabriel Genellina

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


Re: PyArg_ParseTuple for structs or binary data

2008-04-09 Thread Gabriel Genellina
En Wed, 09 Apr 2008 05:05:45 -0300, Alvin Delagon <[EMAIL PROTECTED]>  
escribió:

> I'm currently writing a simple python SCTP module in C. So far it works
> sending and receiving strings from it. The C sctp function sctp_sendmsg()
> has been wrapped and my function looks like this:
>
> sendMessage(PyObject *self, PyObject *args)
> {
>   const char *msg = "";
>   if (!PyArg_ParseTuple(args, "s", &msg))
> return NULL;
>   snprintf(buffer, 1025, msg);
>   ret = sctp_sendmsg(connSock, (void *)buffer, (size_t)strlen(buffer),  
> 0, 0,
> 0x0300, 0, 0, 0, 0);
>   return Py_BuildValue("b", "");
> }
>
> I'm going to construct an SS7 packet in python using struct.pack().  
> Here's
> the question, how am I going to pass the packet I wrote in python to my
> module? Thanks in advance! :)

Same as you do now; struct.pack returns a string object. The "s#" format  
is safer, in case embedded NUL characters are allowed. Also, there is no  
need to copy the string into another buffer (assuming the sctp_sendmsg  
doesn't alter it).
This Py_BuildValue looks suspicious - what's the intended return value? In  
case you want to return "ret" (an integer, I guess), use  
Py_BuildValue("i", ret) or just PyInt_FromLong(ret)

-- 
Gabriel Genellina

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


Re: How is GUI programming in Python?

2008-04-09 Thread CM
On Apr 9, 9:54 pm, Chris Stewart <[EMAIL PROTECTED]> wrote:
> I've always had an interest in Python and would like to dabble in it
> further.  I've worked on a few very small command line programs but
> nothing of any complexity.  I'd like to build a really simple GUI app
> that will work across Mac, Windows, and Linux.  How painful is that
> going to be?  I used to be really familiar with Java Swing a few years
> ago.  I imagine it will be similar.
>
> Next, what would you say is the best framework I should look into?
> I'm curious to hear opinions on that.
>
> Chris Stewart
> [EMAIL PROTECTED]

I've enjoyed using wxPython.  Mature, active, native controls, lots o'
widgets, killer demo, great community, cross platform (with some
tweaking sometimes).
-- 
http://mail.python.org/mailman/listinfo/python-list


Linux Mag's "Introduction to Python Decorators"

2008-04-09 Thread Scott SA
Hi,

I've been trying to wrap my head around decorators and in my trails found a 
very recent article on Linux Mag's website. I didn't see a post here regarding 
this article and feel it is worth directing interested parties towards:

Introduction to Python Decorators

Have a web app that occasionally hangs? Use signals to 
add a timeout to function requests with Python decorators.

Matthew Wilson
Thursday, March 13th, 2008



The link req. registration (sorry, I can't do anything about that).

In a brief summary: The author has a Linux-hosted Web service that occasionally 
hangs. He uses signals via decorators to overcome the problem in an elegant 
way. While some of the content may not be applicable to all readers needs for 
decorators, his illustration and description of the subject is very good (IMO, 
FWIW).

I hope this helps others as much as it has for me,

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


Re: Very good Python Book. Free download : Beginning Python: From Novice to Professional

2008-04-09 Thread Danyelle Gragsone
HEH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How is GUI programming in Python?

2008-04-09 Thread Kam-Hung Soh
On Apr 10, 12:35 pm, Benjamin <[EMAIL PROTECTED]> wrote:
> On Apr 9, 8:54 pm, Chris Stewart <[EMAIL PROTECTED]> wrote:> I've always had 
> an interest in Python and would like to dabble in it
> > further.  I've worked on a few very small command line programs but
> > nothing of any complexity.  I'd like to build a really simple GUI app
> > that will work across Mac, Windows, and Linux.  How painful is that
> > going to be?  I used to be really familiar with Java Swing a few years
> > ago.  I imagine it will be similar.
>
> Since it's Python, it will be a lot less painless than anything
> else. :)
>
> > Next, what would you say is the best framework I should look into?
> > I'm curious to hear opinions on that.
>
> Tkinter is the easiest for little apps, but when I'm doing anything
> for real, I use PyQt.
>
>
>
> > Chris Stewart
> > [EMAIL PROTECTED]

Since the OP has Swing programming experience, what about Jython
(http://www.jython.org/Project/index.html)?

"Jython is an implementation of the high-level, dynamic, object-
oriented language Python written in 100% Pure Java, and seamlessly
integrated with the Java platform. It thus allows you to run Python on
any Java platform."

--
Kam-Hung Soh http://kamhungsoh.com/blog";>Software Salariman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module Conflicts

2008-04-09 Thread Benjamin
On Apr 9, 5:33 pm, Jose <[EMAIL PROTECTED]> wrote:
> I have a module named math.py in a package with some class
> definitions.  I am trying to import the standard python math module
> inside of math.py but It seems to be importing itself.  Is there any
> way around this problem without renaming my math.py file?

Not without some unpythonic magic. It's really not good style to name
a module the same as a stdlib one. It'll also confuse people reading
your code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How is GUI programming in Python?

2008-04-09 Thread Benjamin
On Apr 9, 8:54 pm, Chris Stewart <[EMAIL PROTECTED]> wrote:
> I've always had an interest in Python and would like to dabble in it
> further.  I've worked on a few very small command line programs but
> nothing of any complexity.  I'd like to build a really simple GUI app
> that will work across Mac, Windows, and Linux.  How painful is that
> going to be?  I used to be really familiar with Java Swing a few years
> ago.  I imagine it will be similar.
Since it's Python, it will be a lot less painless than anything
else. :)
>
> Next, what would you say is the best framework I should look into?
> I'm curious to hear opinions on that.
Tkinter is the easiest for little apps, but when I'm doing anything
for real, I use PyQt.
>
> Chris Stewart
> [EMAIL PROTECTED]

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


email header decoding fails

2008-04-09 Thread ZeeGeek
It seems that the decode_header function in email.Header fails when
the string is in the following form,

'=?gb2312?Q?=D0=C7=C8=FC?=(revised)'

That's when a non-encoded string follows the encoded string without
any whitespace. In this case, decode_header function treats the whole
string as non-encoded. Is there a work around for this problem?

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


Re: How is GUI programming in Python?

2008-04-09 Thread Ben Kaplan
The pain level all depends on how you go about it. If you try to builda GUI 
from scratch, it will be very painful. If you use a toolkit, thenit's pretty 
close to working with Swing. WxPython is the only one I've used, so Ican't give 
you a "best one". I can say that going from Swing to wxPython wasn't too 
difficult.

Here is the python wiki page with a bunch of the different ways to 
makecross-platform GUIs, if you want to just look at a couple.
http://wiki.python.org/moin/GuiProgramming 


- Original Message 
From: Chris Stewart <[EMAIL PROTECTED]>
To: python-list@python.org
Sent: Wednesday, April 9, 2008 9:54:33 PM
Subject: How is GUI programming in Python?

I've always had an interest in Python and would like to dabble in it  
further.  I've worked on a few very small command line programs but  
nothing of any complexity.  I'd like to build a really simple GUI app  
that will work across Mac, Windows, and Linux.  How painful is that  
going to be?  I used to be really familiar with Java Swing a few years  
ago.  I imagine it will be similar.

Next, what would you say is the best framework I should look into?   
I'm curious to hear opinions on that.

Chris Stewart
[EMAIL PROTECTED]



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





__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com -- 
http://mail.python.org/mailman/listinfo/python-list

Re: new user needs help!

2008-04-09 Thread Steve Holden
drjekil wrote:
> I have done something so far about that problem,but its not the good way to
> do it
> 
> need ur comments about that
> 
Well, at least you can see that your approach is not satisfactory, so 
that means you have some sense of what's good and bad programming/

> 
> from string import  *;
> import sys
> 
> myfile = open("/afs/pdc.kth.se/home/d/debnath/membrane/1a91A.txt")
> a = myfile.readlines()
> data = myfile.readlines()

The first readlines() exhausts the file.

> for line in myfile.readlines():

You should omit the assignments to a and to data, as they are using up 
the contents of the file that you want this statrement to iterate over.

>fields = line.split('\t')
> 
>items=fields.strip()
>list1.append(items[1])
>
Note that what you are doing here is building a list of the lines in the 
file to iterate over later, when you could just iterate over the lines 
in the file.

> 
> for i in aminoacid:
> if  10.0 <= z <= 22.0:
> matches.append([1,i]) 
> #here i am getting comment!  bash-3.1$ python bb.py
>   File "bb.py", line 16
> matches.append([1,i])
>   ^
> IndentationError: expected an indented block
>   
> else:
> matches.append([-1,i])
> 
The error message is literally correct. The statement(s) controlled by 
an if must be indented relative to the if statement itself - remember, 
Python uses indentation to indicate block structure.

Also, it seems a little unnecessary to build a list of all the matching 
lines and then process them, when you could process them one at a time 
as you read them from the file!

> print "#T/F  A  C  D  E  F  G  H  I  K  L  M  N  P  Q  R  S  T  V  W  X  Y 
> Z"
> 
That looks fine!

> for a in range(0,len(matches),1):
>  
> if matches[a][0]==1:
>
> if matches[a][1]=='A':
> print "1  1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0
> 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> elif matches[a][1]=='C':
> print "1  1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0
> 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> elif matches[a][1]=='D':
> 
> print "1  1:0 2:0 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> """if matches[a][1]=='E' and matches[a][0]==1:
> 
> print "1  1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='F' and matches[a][0]==1:
> 
> print "1  1:0 2:0 3:0 4:0 5:1 6:0 7:0 8:0 9:0 10:0 11:0 12:0
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='G' and matches[a][0]==1:
> 
> print "1  1:0 2:0 3:0 4:0 5:0 6:1 7:0 8:0 9:0 10:0 11:0 12:0
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='H' and matches[a][0]==1:
> 
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:1 8:0 9:0 10:0 11:0 12:0
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='I' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:0 10:0 11:0 12:0
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='K' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:0 11:0 12:0
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='L' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:1 11:0 12:0
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='M' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:1 12:0
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='N' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:1
> 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='P' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
> 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='Q' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
> 13:0 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='R' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
> 13:0 14:0 15:1 16:0 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='S' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
> 13:0 14:0 15:0 16:1 17:0 18:0 19:0 20:0 21:0"
> if matches[a][1]=='T' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
> 13:0 14:0 15:0 16:0 17:1 18:0 19:0 20:0 21:0"
> if matches[a][1]=='V' and matches[a][0]==1:
>
> print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
> 13:0 14:0 15:0 16:0 17:0 18:1 19:0 20:0 21:0"
> if matches[a][1]=='X' and

Re: How is GUI programming in Python?

2008-04-09 Thread Paul Rubin
Chris Stewart <[EMAIL PROTECTED]> writes:
> I've always had an interest in Python and would like to dabble in it
> further.  I've worked on a few very small command line programs but
> nothing of any complexity.  I'd like to build a really simple GUI app
> that will work across Mac, Windows, and Linux.  How painful is that
> going to be?  I used to be really familiar with Java Swing a few years
> ago.  I imagine it will be similar.
> ...
> Next, what would you say is the best framework I should look into?

If by "best" you mean "easiest", that is probably tkinter, which
comes with python.  It is somewhat rudimentary and the widgets that
come with it don't look so great.  But if you just want to put up
GUI's with basic functionality and not much glitz, it is ok for most
such purposes.
out how to use
-- 
http://mail.python.org/mailman/listinfo/python-list


How is GUI programming in Python?

2008-04-09 Thread Chris Stewart
I've always had an interest in Python and would like to dabble in it  
further.  I've worked on a few very small command line programs but  
nothing of any complexity.  I'd like to build a really simple GUI app  
that will work across Mac, Windows, and Linux.  How painful is that  
going to be?  I used to be really familiar with Java Swing a few years  
ago.  I imagine it will be similar.

Next, what would you say is the best framework I should look into?   
I'm curious to hear opinions on that.

Chris Stewart
[EMAIL PROTECTED]



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


Re: popen pipe limit

2008-04-09 Thread skunkwerk
On Apr 7, 6:17 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Mon, 07 Apr 2008 20:52:54 -0300,skunkwerk<[EMAIL PROTECTED]>  
> escribió:
>
> > I'm getting errors when reading from/writing to pipes that are fairly
> > large in size.  To bypass this, I wanted to redirect output to a file
> > in the subprocess.Popen function, but couldn't get it to work (even
> > after setting Shell=True).  I tried adding ">","temp.sql" after the
> > password field but mysqldump gave me an error.
>
> > the code:
> > p1 = subprocess.Popen(["mysqldump","--all-databases","--user=user","--
> > password=password"], shell=True)
> > p2 = subprocess.Popen(["gzip","-9"], stdin=p1.stdout)
> > output = p2.communicate()[0]
> > file=open('test.sql.gz','w')
> > file.write(str(output))
> > file.close()
>
> You need a pipe to chain subprocesses:
>
> import subprocess
> p1 =  
> subprocess.Popen(["mysqldump","--all-databases","--user=user","--password=password"],
>   
> stdout=subprocess.PIPE)
> ofile = open("test.sql.gz", "wb")
> p2 = subprocess.Popen(["gzip","-9"], stdin=p1.stdout, stdout=ofile)
> p1.wait()
> p2.wait()
> ofile.close()
>
> If you don't want the final file on disk:
>
> p1 =  
> subprocess.Popen(["mysqldump","--all-databases","--user=user","--password=password"],
>   
> stdout=subprocess.PIPE)
> p2 = subprocess.Popen(["gzip","-9"], stdin=p1.stdout,  
> stdout=subprocess.PIPE)
> while True:
>    chunk = p2.stdout.read(4192)
>    if not chunk: break
>    # do something with read chunk
>
> p1.wait()
> p2.wait()
>
> --
> Gabriel Genellina

thanks Gabriel - tried the first one and it worked great!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I am worried about Python 3

2008-04-09 Thread John Machin
On Apr 10, 8:12 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> "jmDesktop" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
> | Two new versions of the language are currently in development: version
> | 2.6, which retains backwards compatibility with previous releases; and
> | version 3.0, which breaks backwards compatibility to the extent that
> | even that simplest of programs, the classic 'Hello, World', will no
> | longer work in its current form.
>
> That change is however, the one most immediately visible to new
> programmers. Most of the other statements are pretty much unchanged.  In
> any case, 'print' is an easy-to-use facade over sys.stdout.write(), with
> default formatting.  If really concerned about it, start programs with
>import sys
>write = sys.stdout.write
> and use that to write out explicitly formatted strings.  (Some people
> routinely do this for production code anyway.)
>
> tjr

Some C tragics do things like this, which appear to be 3.0-proof:
def fprintf(f, fmt, *vargs):
f.write(fmt % vargs)

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


Re: How can I use quotes without escaping them using CSV?

2008-04-09 Thread John Machin
On Apr 10, 9:39 am, jeffself <[EMAIL PROTECTED]> wrote:

> I set quotechar="" and was able to get it to work.  I'll try this at
> work tomorrow!

setting it to what Andrew told you to do ('' not ")works equally well


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


Re: Sorting a List of Objects by an Attribute of the Objects Case-Insensitively

2008-04-09 Thread Jason
Thanks so much everyone!  That works great, & (presumably) is way
faster than the way I was doing it--
-- 
http://mail.python.org/mailman/listinfo/python-list


Creating and Audio Equalizer with python and gstreamer

2008-04-09 Thread Rod Person
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

For about 3 weeks I have been search for examples for grabbing and
frequency from an audio stream and manipulating it. So far I haven't
been too successful.

Just wondering if anyone has done this or has a good example of doing
such.

TIA

Rod

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (FreeBSD)

iEYEARECAAYFAkf9VewACgkQWtF04X/kP32peQCfX/1LgmmREFB88bdY9uzVGxb4
n+sAoJngeg2VpGpwWmJ7cJLrNmsVI9uV
=rCNp
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I use quotes without escaping them using CSV?

2008-04-09 Thread jeffself
On Apr 9, 5:39 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:python-
> > [EMAIL PROTECTED] On Behalf Of jeffself
> > Sent: Wednesday, April 09, 2008 5:11 PM
> > To: [EMAIL PROTECTED]
> > Subject: How can I use quotes without escaping them using CSV?
>
> > If I put an escape character in, it works.  For example, if I use ~ as
> > my escape character, my output looks like this:
> > 0001[tab]Michael L. ~"Mick~" Jones[tab]189
>
> > I don't want that. If I don't include an escape character, it doesn't
> > work.
>
> > Here's my code:
> > import sys
> > import csv
> > from readexcel import *
>
> > f = open("results.txt", 'wb')
> > book = sys.argv[1]
> > sheet = sys.argv[2]
>
> > xl = readexcel(book)
> > sheetnames = xl.worksheets()
>
> > for s in sheetnames:
> > if s == sheet:
> > writer = csv.writer(f, delimiter='\t', quoting=csv.QUOTE_NONE)
> > for row in xl.getiter(s):
>
> writer.writerow((row['Precinct'],row['Candidate'],unicode(int(row['Vote
>
> > s']
> > f.close()
>
> The documentation is pretty, uhm, obtuse, but you also need to set
> quotechar.
>
> import sys
> import csv
>
> names = ['Michael L. "Mick" Jones', 'Vickie A. Meyers', 'John "Jack"
> Smith']
>
> writer = csv.writer(sys.stdout, delimiter='\t', quotechar='',
> quoting=csv.QUOTE_NONE)
> for i in names:
> writer.writerow(['a', i, 'b'])
>
> output:
> a   Michael L. "Mick" Jones b
> a   Vickie A. Meyersb
> a   John "Jack" Smith   b
>
> *
>
> The information transmitted is intended only for the person or entity to 
> which it is addressed and may contain confidential, proprietary, and/or 
> privileged material. Any review, retransmission, dissemination or other use 
> of, or taking of any action in reliance upon this information by persons or 
> entities other than the intended recipient is prohibited. If you received 
> this in error, please contact the sender and delete the material from all 
> computers. GA621

I set quotechar="" and was able to get it to work.  I'll try this at
work tomorrow!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I use quotes without escaping them using CSV?

2008-04-09 Thread jeffself
On Apr 9, 5:39 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:python-
> > [EMAIL PROTECTED] On Behalf Of jeffself
> > Sent: Wednesday, April 09, 2008 5:11 PM
> > To: [EMAIL PROTECTED]
> > Subject: How can I use quotes without escaping them using CSV?
>
> > If I put an escape character in, it works.  For example, if I use ~ as
> > my escape character, my output looks like this:
> > 0001[tab]Michael L. ~"Mick~" Jones[tab]189
>
> > I don't want that. If I don't include an escape character, it doesn't
> > work.
>
> > Here's my code:
> > import sys
> > import csv
> > from readexcel import *
>
> > f = open("results.txt", 'wb')
> > book = sys.argv[1]
> > sheet = sys.argv[2]
>
> > xl = readexcel(book)
> > sheetnames = xl.worksheets()
>
> > for s in sheetnames:
> > if s == sheet:
> > writer = csv.writer(f, delimiter='\t', quoting=csv.QUOTE_NONE)
> > for row in xl.getiter(s):
>
> writer.writerow((row['Precinct'],row['Candidate'],unicode(int(row['Vote
>
> > s']
> > f.close()
>
> The documentation is pretty, uhm, obtuse, but you also need to set
> quotechar.
>
> import sys
> import csv
>
> names = ['Michael L. "Mick" Jones', 'Vickie A. Meyers', 'John "Jack"
> Smith']
>
> writer = csv.writer(sys.stdout, delimiter='\t', quotechar='',
> quoting=csv.QUOTE_NONE)
> for i in names:
> writer.writerow(['a', i, 'b'])
>
> output:
> a   Michael L. "Mick" Jones b
> a   Vickie A. Meyersb
> a   John "Jack" Smith   b
>
> *
>
> The information transmitted is intended only for the person or entity to 
> which it is addressed and may contain confidential, proprietary, and/or 
> privileged material. Any review, retransmission, dissemination or other use 
> of, or taking of any action in reliance upon this information by persons or 
> entities other than the intended recipient is prohibited. If you received 
> this in error, please contact the sender and delete the material from all 
> computers. GA621

I tried this but a get the following error:
>>> writer = csv.writer(sys.stdout, delimiter='\t', quotechar=", 
>>> quoting=csv.QUOTE_NONE)
  File "", line 1
writer = csv.writer(sys.stdout, delimiter='\t', quotechar=",
quoting=csv.QUOTE_NONE)
 
^
SyntaxError: EOL while scanning single-quoted string
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Control process execution

2008-04-09 Thread Noah
On Apr 9, 1:57 pm, Mike Driscoll <[EMAIL PROTECTED]> wrote:
> As far as I know, there is no "os.process". Maybe you meant os.system
> or the subprocess module?
>
> Mike

Yeah, I was thinking "subprocess" module.
--
Noah
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I use quotes without escaping them using CSV?

2008-04-09 Thread John Machin
On Apr 10, 7:39 am, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:python-
> > [EMAIL PROTECTED] On Behalf Of jeffself
> > Sent: Wednesday, April 09, 2008 5:11 PM
> > To: [EMAIL PROTECTED]
> > Subject: How can I use quotes without escaping them using CSV?
>
> > If I put an escape character in, it works.  For example, if I use ~ as
> > my escape character, my output looks like this:
> > 0001[tab]Michael L. ~"Mick~" Jones[tab]189
>
> > I don't want that. If I don't include an escape character, it doesn't
> > work.

which means an exception is raised:

_csv.Error: need to escape, but no escapechar set

>
> > Here's my code:
[snip]

> > writer = csv.writer(f, delimiter='\t', quoting=csv.QUOTE_NONE)
[snip]
>
> The documentation is pretty, uhm, obtuse, but you also need to set
> quotechar.

Uhm, "obtuse" applies to angles and people :-) I could agree with
"obscure".

>
> import sys
> import csv
>
> names = ['Michael L. "Mick" Jones', 'Vickie A. Meyers', 'John "Jack"
> Smith']
>
> writer = csv.writer(sys.stdout, delimiter='\t', quotechar='',
> quoting=csv.QUOTE_NONE)
> for i in names:
> writer.writerow(['a', i, 'b'])
>
> output:
> a   Michael L. "Mick" Jones b
> a   Vickie A. Meyersb
> a   John "Jack" Smith   b
>
> *
>

Here's my call:

(1) Code bug: when quoting is set to QUOTE_NONE, it should ignore the
setting of quotechar -- it's irrelevant.

(2) Documentation bug:
"""
quotechar
A one-character string 
"""
but the code allows setting quotechar to '' and to None. Both work
around the OP's problem; whether they have identical effect in other
situations, I haven't explored.

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


Re: Ctypes and C Infinite Callback Loops

2008-04-09 Thread Thomas Dimson
On Apr 9, 1:24 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Tue, 8 Apr 2008 16:49:27 -0700 (PDT), Thomas Dimson
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>
>
> > I assume there is some issue with the global interpreter lock or that
> > you can't exit the infinite loop from above Python. Any suggestions on
> > how I can design this so the thread will be able to issue exits/raise
> > exceptions just like a regular thread? Is there a way of terminating
> > this thread from the python interpreter or ctypes.pythonapi?
>
> No... as I recall, you can't /EXIT/ Python from a sub-thread...
> Which is what sys.exit() or whatever is trying to do -- shut down the
> entire program, not just the thread. The error you get indicates that
> the thread doing the shutdown wants to wait for the sub-thread to finish
> -- but /it/ IS the sub-thread. Even console interrupts have to be
> delivered to the main program.
>
> The only safe way to terminate a thread is to be able to code it
> such that /it/ responds to an externally set value (a boolean, read a
> message off a Queue, etc.) and for IT to then exit. Based upon the
> sample you showed, that would require the C main loop to be checking for
> a shutdown signal... If the API to that main loop library doesn't
> include a shutdown capability I'd suggest it is a less than complete
> library... And the only thing I'd suggest is not using a Python thread,
> but instead spawning a separate process that somehow communicates to the
> parent process -- and which can be forceably killed using OS specific
> capabilities... "kill -9 pid" 
>
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED]  [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/

Thanks for the response, it put me in the right direction (I didn't
realize there was no way of exiting the interpreter directly from a
non-main thread).

If anyone ever has the same problem, the solution I ended up using
went like this:

I created a wrapper around the infinite loop call that had a setjmp in
it, exiting if setjmp was non-zero.

Inside each callback function, I had a try/except statement that
caught all exceptions. If it had an exception, it would set a thread-
specific exception variable to sys.exc_info() and then call a C
function that did a longjmp.

The thread would first call the wrapper to the infinite loop. If the
wrapper returns (because of a longjmp), it would check the thread-
specific exception variable for a non-None value and raise the very
same exception (with the same traceback) if it found it.

A fairly large hack, but it seemed to do the job. Thanks again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to find documentation about methods etc. for iterators

2008-04-09 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| I'm not sure if I have even phrased that right but anyway
|
| How does one find (in the standard Python documentation) information
| about things like the iteritems() method and the enumerate() function.

The Library Reference manual sections on builtin functions and dict 
methods.

Or, help(enumerate) and help({}.iteritems)


tjr
 



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


Module Conflicts

2008-04-09 Thread Jose
I have a module named math.py in a package with some class
definitions.  I am trying to import the standard python math module
inside of math.py but It seems to be importing itself.  Is there any
way around this problem without renaming my math.py file?
-- 
http://mail.python.org/mailman/listinfo/python-list


Free Photo Sharing

2008-04-09 Thread kovyrus2
Upload your photos and share them with friends and family.
http://fotochange.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I am worried about Python 3

2008-04-09 Thread Terry Reedy

"jmDesktop" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Two new versions of the language are currently in development: version
| 2.6, which retains backwards compatibility with previous releases; and
| version 3.0, which breaks backwards compatibility to the extent that
| even that simplest of programs, the classic 'Hello, World', will no
| longer work in its current form.

That change is however, the one most immediately visible to new 
programmers. Most of the other statements are pretty much unchanged.  In 
any case, 'print' is an easy-to-use facade over sys.stdout.write(), with 
default formatting.  If really concerned about it, start programs with
   import sys
   write = sys.stdout.write
and use that to write out explicitly formatted strings.  (Some people 
routinely do this for production code anyway.)

tjr



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


Re: Google App Engine

2008-04-09 Thread Terry Reedy

"Duncan Booth" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| There are several things which would make moving away from Google tricky:

I noticed that too, but it does have the virtue that development is done on 
one's own machine rather than keeping everying on the ISP's machines, like 
one web-stite 'quick' builder I have seen.



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


Re: Not Sure This Can Be Done...

2008-04-09 Thread gamename
Hi,

In hopes it may help someone else, here's what I ended up doing:

1) Add this to to point to your local 'tools' directory:
   import site
   # the python tools dir is at "../../tools/python"
   site.addsitedir('..'+os.sep+'..'+os.sep+'tools'+os.sep
+'python')

2) In the 'tools' dir, there is a file called 'local.pth'.  Its
contents:
   # the individual modules are at "../../tools/python/modules/
"
  ./modules/pexpect

3) In the script you can now do:
  import pexpect

That's it.  This works fine, but there are still 2 outstanding issues:

A) How do make the same ".pth" file usable on a win32 environment?
   The path separators are different (i.e. "/" vs "\").

B) How to auto-include any subdirectory in 'python/modules' so that
each
   new module dir doesn't have to be added manually? That is, if
package
   'foo' is added, it would be in 'python/modules/foo'. Is there a
way
   to avoid manually putting that in the '.pth'?

FYI,
-T

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


ANN: ActivePython 2.5.2.2 and 2.4.5.14 are now available

2008-04-09 Thread Trent Mick
I'm happy to announce that ActivePython 2.5.2.2 and 2.4.5.14 are now
available for download from:
 http://www.activestate.com/products/activepython/

These are patch releases that update ActivePython to core Python 2.5.2
and 2.4.5.


What is ActivePython?
-

ActivePython is ActiveState's binary distribution of Python. Builds for
Windows, Mac OS X, Linux, HP-UX and AIX are made freely available.

ActivePython includes the Python core and the many core extensions:
zlib and bzip2 for data compression, the Berkeley DB (bsddb) and
SQLite (sqlite3, ActivePython 2.5 only) database libraries, OpenSSL
bindings for HTTPS support, the Tix GUI widgets for Tkinter,
ElementTree for XML processing (ActivePython 2.5 only), ctypes (on
supported platforms, ActivePython 2.5 only) for low-level library
access, and others. The Windows distribution ships with PyWin32 -- a
suite of Windows tools developed by Mark Hammond, including bindings
to the Win32 API and Windows COM. See this page for full details:
http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/whatsincluded.html

As well, ActivePython ships with a wealth of documentation for both new
and experienced Python programmers. In addition to the core Python docs,
ActivePython includes the "What's New in Python" series, "Dive into
Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals
(PEPs).

An online version of the docs can be found here:
 http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/welcome.html
 http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/welcome.html

We would welcome any and all feedback to:
 [EMAIL PROTECTED]

Please file bugs against ActivePython at:
 http://bugs.activestate.com/query.cgi?product=ActivePython


On what platforms does ActivePython run?


ActivePython includes installers for the following platforms:

- Windows/x86
- Mac OS X
- Linux/x86
- Solaris/SPARC
- Solaris/x86
- Windows/x64 ("x64" is also known as "AMD64")
- Linux/x86_64 ("x86_64" is also known as "AMD64")
- HP-UX/PA-RISC
- AIX/PowerPC


Extra Bits
--

ActivePython releases also include the following:

- ActivePython24.chm, ActivePython25.chm: An MS compiled help collection
   of the full ActivePython documentation set. Linux users of
   applications such as xCHM might find this useful. This package is
   installed by default on Windows.

Extra bits are available from:
 http://downloads.activestate.com/ActivePython/etc/


Apologies for the delay. I was crazy-busy getting the Komodo 4.3 release
out. Check it out:
 http://www.activestate.com/products/komodo/

Thanks, and enjoy!

Trent, Python Tech Lead

--
Trent Mick
trentm at activestate.com



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


Re: basic python question about for loop

2008-04-09 Thread Terry Reedy
|So what is n and x in the first iteration?  Sorry.  I'm trying.

When n == 2, the inner loop executes 0 times (the length of range(2,n)) and 
then falls thru to the else clause, printing the correct answer. 



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


RE: Stripping scripts from HTML with regular expressions

2008-04-09 Thread Michel Bouwmans
Reedick, Andrew wrote:

> 
> 
>> -Original Message-
>> From: [EMAIL PROTECTED] [mailto:python-
>> [EMAIL PROTECTED] On Behalf Of Michel Bouwmans
>> Sent: Wednesday, April 09, 2008 3:38 PM
>> To: python-list@python.org
>> Subject: Stripping scripts from HTML with regular expressions
>> 
>> Hey everyone,
>> 
>> I'm trying to strip all script-blocks from a HTML-file using regex.
>> 
>> I tried the following in Python:
>> 
>> testfile = open('testfile')
>> testhtml = testfile.read()
>> regex = re.compile(']*>(.*?)', re.DOTALL)
> 
> 
> Aha! \b is being interpolated as a backspace character:
>   \b ASCII Backspace (BS)
> 
> Always use a raw string with regexes:
> regex = re.compile(r']*>(.*?)', re.DOTALL)
> 
> Your regex should now work.
> 
> 
> 
> *
> 
> The information transmitted is intended only for the person or entity to
> which it is addressed and may contain confidential, proprietary, and/or
> privileged material. Any review, retransmission, dissemination or other
> use of, or taking of any action in reliance upon this information by
> persons or entities other than the intended recipient is prohibited. If
> you received this in error, please contact the sender and delete the
> material from all computers. GA622

Thanks! That did the trick. :) I was trying to use HTMLParser but that
choked on the script-blocks that didn't contain comment-indicators. Guess I
can now move on with this script, thank you.

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


RE: How can I use quotes without escaping them using CSV?

2008-04-09 Thread Reedick, Andrew


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of jeffself
> Sent: Wednesday, April 09, 2008 5:11 PM
> To: python-list@python.org
> Subject: How can I use quotes without escaping them using CSV?
> 
> 
> If I put an escape character in, it works.  For example, if I use ~ as
> my escape character, my output looks like this:
> 0001[tab]Michael L. ~"Mick~" Jones[tab]189
> 
> I don't want that. If I don't include an escape character, it doesn't
> work.
> 
> 
> Here's my code:
> import sys
> import csv
> from readexcel import *
> 
> f = open("results.txt", 'wb')
> book = sys.argv[1]
> sheet = sys.argv[2]
> 
> xl = readexcel(book)
> sheetnames = xl.worksheets()
> 
> for s in sheetnames:
> if s == sheet:
> writer = csv.writer(f, delimiter='\t', quoting=csv.QUOTE_NONE)
> for row in xl.getiter(s):
> 
>
writer.writerow((row['Precinct'],row['Candidate'],unicode(int(row['Vote
> s']
> f.close()
> 


The documentation is pretty, uhm, obtuse, but you also need to set
quotechar.

import sys
import csv

names = ['Michael L. "Mick" Jones', 'Vickie A. Meyers', 'John "Jack"
Smith']

writer = csv.writer(sys.stdout, delimiter='\t', quotechar='',
quoting=csv.QUOTE_NONE)
for i in names:
writer.writerow(['a', i, 'b'])

output:
a   Michael L. "Mick" Jones b
a   Vickie A. Meyersb
a   John "Jack" Smith   b



*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA621


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


Re: Any fancy grep utility replacements out there?

2008-04-09 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> Thanks to everyone who responded, and sorry for my late response.
> 
> Grin seems like the perfect solution for me.  I finally had a chance
> to download it and play with it today.  It's great.
> 
> Robert...you were kind enough to ask if I had any requests.  Just the
> one right now of grepping through gzip files.  If for some reason you
> don't want to do it or don't have time to do it, I could probably do
> it and send you a patch.  But I imagine that since you wrote the code,
> you could do it more elegantly than I could.

I just checked it in.

-- 
Robert Kern

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

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


Re: Basic optimization of python.

2008-04-09 Thread Terry Reedy

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

|I wonder whether python compiler does basic optimizations to .py.

In general, the answer to such questions depends on the implementation and 
version thereof.  For CPython, you can look at bytecode with the dis module 
as another poster showed.

| Again, how about contant calculation?
| Eg:
| a = 1 + 2
| .vs.
| a = 3

This was added to CPython in version 2.5, I believe. 



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


Re: basic python question about for loop

2008-04-09 Thread Diez B. Roggisch
jmDesktop schrieb:
> On Apr 9, 4:58 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> jmDesktop schrieb:
>>
>>
>>
>>
>>
>>> From the Python.org tutorial:
>> for n in range(2, 10):
>>> ... for x in range(2, n):
>>> ... if n % x == 0:
>>> ... print n, 'equals', x, '*', n/x
>>> ... break
>>> ... else:
>>> ... # loop fell through without finding a factor
>>> ... print n, 'is a prime number'
>>> ...
>>> 2 is a prime number
>>> 3 is a prime number
>>> 4 equals 2 * 2
>>> 5 is a prime number
>>> 6 equals 2 * 3
>>> 7 is a prime number
>>> 8 equals 2 * 4
>>> 9 equals 3 * 3
>>> first time 2 mod 2, 2/2, no remainder == 0, what am I doing wrong?
>>> Why did it fall through?
>> print out what range(2, n) for n == 2 is.
>>
>> And if you didn't know - 2 *IS* a prime.
>>
>> Diez- Hide quoted text -
>>
>> - Show quoted text -
> 
> I do not understand.

for  in  loops over a sequence. And of course it 
doens't if the sequence is empty, because you can't loop over something 
that is empty, can't you?

and range(2,2) is the empty sequence.

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


RE: basic python question about for loop

2008-04-09 Thread Reedick, Andrew


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of jmDesktop
> Sent: Wednesday, April 09, 2008 5:04 PM
> To: python-list@python.org
> Subject: Re: basic python question about for loop
> 
> >
> > > >>> for n in range(2, 10):
> > > ...     for x in range(2, n):
> > > ...         if n % x == 0:
> > > ...             print n, 'equals', x, '*', n/x
> > > ...             break
> > > ...     else:
> > > ...         # loop fell through without finding a factor
> > > ...         print n, 'is a prime number'
> > > ...
> >
> > > first time 2 mod 2, 2/2, no remainder == 0, what am I doing wrong?
> > > Why did it fall through?
> >

> 
> So what is n and x in the first iteration?  Sorry.  I'm trying.


You're never getting to n and x in the first iteration, because the 'for x in 
range(2, n)' loop isn't looping.

This:  
for x in range(2, n)
is equivalent in C/Perl/etc. to:
for(x=2; xhttp://mail.python.org/mailman/listinfo/python-list


How can I use quotes without escaping them using CSV?

2008-04-09 Thread jeffself
I'm reading data out of an Excel spreadsheet using the XLRD module.
The spreadsheet contains a list of election results.  The fields are
as follows: Precinct, Candidate, Votes

The problem is candidate names can be funky, for instance:  Michael L.
"Mick" Jones

I cannot for the life of me figure out how to get the CSV module to
allow a name like this to be written to a file.  Why does it insist on
an escape character when I'm telling it that the delimiter should be
'\t'?  I want the quotes to go to the file and I want the tab-
delimited file to look like this:

0001[tab]Michael L. "Mick" Jones[tab]189
0002[tab]Vickie A. Meyers[tab]221
0003[tab]John "Jack" Smith[tab]187

Note: I don't want [tab] to display, I want a real tab there.

If I put an escape character in, it works.  For example, if I use ~ as
my escape character, my output looks like this:
0001[tab]Michael L. ~"Mick~" Jones[tab]189

I don't want that. If I don't include an escape character, it doesn't
work.


Here's my code:
import sys
import csv
from readexcel import *

f = open("results.txt", 'wb')
book = sys.argv[1]
sheet = sys.argv[2]

xl = readexcel(book)
sheetnames = xl.worksheets()

for s in sheetnames:
if s == sheet:
writer = csv.writer(f, delimiter='\t', quoting=csv.QUOTE_NONE)
for row in xl.getiter(s):
 
writer.writerow((row['Precinct'],row['Candidate'],unicode(int(row['Votes']
f.close()


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


Re: basic python question about for loop

2008-04-09 Thread jmDesktop
On Apr 9, 4:59 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:python-
> > [EMAIL PROTECTED] On Behalf Of jmDesktop
> > Sent: Wednesday, April 09, 2008 4:51 PM
> > To: [EMAIL PROTECTED]
> > Subject: basic python question about for loop
>
> > >From the Python.org tutorial:
>
> > >>> for n in range(2, 10):
> > ...     for x in range(2, n):
> > ...         if n % x == 0:
> > ...             print n, 'equals', x, '*', n/x
> > ...             break
> > ...     else:
> > ...         # loop fell through without finding a factor
> > ...         print n, 'is a prime number'
> > ...
> > 2 is a prime number
> > 3 is a prime number
> > 4 equals 2 * 2
> > 5 is a prime number
> > 6 equals 2 * 3
> > 7 is a prime number
> > 8 equals 2 * 4
> > 9 equals 3 * 3
>
> > first time 2 mod 2, 2/2, no remainder == 0, what am I doing wrong?
> > Why did it fall through?
>
> a) 2 is prime, so nothing is wrong.
>
> b) Range isn't doing what you think it's doing:
>
> >>> print range(2,2)
> []
> >>> print range(2,3)
> [2]
> >>> print range(2,4)
> [2, 3]
> >>> print range(2,5)
>
> [2, 3, 4]
>
>
>
> >>> print range(1,1)
> []
> >>> print range(1,2)
> [1]
> >>> print range(1,3)
> [1, 2]
>
> *
>
> The information transmitted is intended only for the person or entity to 
> which it is addressed and may contain confidential, proprietary, and/or 
> privileged material. Any review, retransmission, dissemination or other use 
> of, or taking of any action in reliance upon this information by persons or 
> entities other than the intended recipient is prohibited. If you received 
> this in error, please contact the sender and delete the material from all 
> computers. GA622- Hide quoted text -
>
> - Show quoted text -

So what is n and x in the first iteration?  Sorry.  I'm trying.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: basic python question about for loop

2008-04-09 Thread jmDesktop
On Apr 9, 4:58 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> jmDesktop schrieb:
>
>
>
>
>
> > From the Python.org tutorial:
>
>  for n in range(2, 10):
> > ...     for x in range(2, n):
> > ...         if n % x == 0:
> > ...             print n, 'equals', x, '*', n/x
> > ...             break
> > ...     else:
> > ...         # loop fell through without finding a factor
> > ...         print n, 'is a prime number'
> > ...
> > 2 is a prime number
> > 3 is a prime number
> > 4 equals 2 * 2
> > 5 is a prime number
> > 6 equals 2 * 3
> > 7 is a prime number
> > 8 equals 2 * 4
> > 9 equals 3 * 3
>
> > first time 2 mod 2, 2/2, no remainder == 0, what am I doing wrong?
> > Why did it fall through?
>
> print out what range(2, n) for n == 2 is.
>
> And if you didn't know - 2 *IS* a prime.
>
> Diez- Hide quoted text -
>
> - Show quoted text -

I do not understand.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: basic python question about for loop

2008-04-09 Thread Steve Holden
jmDesktop wrote:
>>From the Python.org tutorial:
> 
 for n in range(2, 10):
> ... for x in range(2, n):
> ... if n % x == 0:
> ... print n, 'equals', x, '*', n/x
> ... break
> ... else:
> ... # loop fell through without finding a factor
> ... print n, 'is a prime number'
> ...
> 2 is a prime number
> 3 is a prime number
> 4 equals 2 * 2
> 5 is a prime number
> 6 equals 2 * 3
> 7 is a prime number
> 8 equals 2 * 4
> 9 equals 3 * 3
> 
> 
> 
> first time 2 mod 2, 2/2, no remainder == 0, what am I doing wrong?
> Why did it fall through?
> 
 >>> range(2, 2)
[]
 >>>

The loop body executes zero times.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: new user needs help!

2008-04-09 Thread drjekil

I have done something so far about that problem,but its not the good way to
do it

need ur comments about that


from string import  *;
import sys

myfile = open("/afs/pdc.kth.se/home/d/debnath/membrane/1a91A.txt")
a = myfile.readlines()
data = myfile.readlines()
for line in myfile.readlines():
   fields = line.split('\t')

   items=fields.strip()
   list1.append(items[1])


for i in aminoacid:
if  10.0 <= z <= 22.0:
matches.append([1,i]) 
#here i am getting comment!  bash-3.1$ python bb.py
  File "bb.py", line 16
matches.append([1,i])
  ^
IndentationError: expected an indented block
  
else:
matches.append([-1,i])

print "#T/F  A  C  D  E  F  G  H  I  K  L  M  N  P  Q  R  S  T  V  W  X  Y 
Z"

for a in range(0,len(matches),1):
 
if matches[a][0]==1:
   
if matches[a][1]=='A':
print "1  1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0
14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='C':
print "1  1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0
14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='D':

print "1  1:0 2:0 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
"""if matches[a][1]=='E' and matches[a][0]==1:

print "1  1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='F' and matches[a][0]==1:

print "1  1:0 2:0 3:0 4:0 5:1 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='G' and matches[a][0]==1:

print "1  1:0 2:0 3:0 4:0 5:0 6:1 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='H' and matches[a][0]==1:

print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:1 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='I' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='K' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='L' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:1 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='M' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:1 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='N' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:1
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='P' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='Q' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='R' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:1 16:0 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='S' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:1 17:0 18:0 19:0 20:0 21:0"
if matches[a][1]=='T' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:1 18:0 19:0 20:0 21:0"
if matches[a][1]=='V' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:1 19:0 20:0 21:0"
if matches[a][1]=='X' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:1 20:0 21:0"
if matches[a][1]=='Y' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:1 21:0"
if matches[a][1]=='Z' and matches[a][0]==1:
   
print "1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:1"
   

"""
else:
if matches[a][1]=='A':
print "-1  1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0
14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='C':
print "-1  1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='D':

print "1  1:0 2:0 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
"""if matches[a][1]=='E' and matches[a][0]==1:

print "1  1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0
13:0 14:0 15:0 1

RE: basic python question about for loop

2008-04-09 Thread Reedick, Andrew


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of jmDesktop
> Sent: Wednesday, April 09, 2008 4:51 PM
> To: python-list@python.org
> Subject: basic python question about for loop
> 
> >From the Python.org tutorial:
> 
> >>> for n in range(2, 10):
> ... for x in range(2, n):
> ... if n % x == 0:
> ... print n, 'equals', x, '*', n/x
> ... break
> ... else:
> ... # loop fell through without finding a factor
> ... print n, 'is a prime number'
> ...
> 2 is a prime number
> 3 is a prime number
> 4 equals 2 * 2
> 5 is a prime number
> 6 equals 2 * 3
> 7 is a prime number
> 8 equals 2 * 4
> 9 equals 3 * 3
> 
> 
> 
> first time 2 mod 2, 2/2, no remainder == 0, what am I doing wrong?
> Why did it fall through?
> 

a) 2 is prime, so nothing is wrong.

b) Range isn't doing what you think it's doing:

>>> print range(2,2)
[]
>>> print range(2,3)
[2]
>>> print range(2,4)
[2, 3]
>>> print range(2,5)
[2, 3, 4]

>>> print range(1,1)
[]
>>> print range(1,2)
[1]
>>> print range(1,3)
[1, 2]
>>>



*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA622


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


Re: basic python question about for loop

2008-04-09 Thread Diez B. Roggisch
jmDesktop schrieb:
> From the Python.org tutorial:
> 
 for n in range(2, 10):
> ... for x in range(2, n):
> ... if n % x == 0:
> ... print n, 'equals', x, '*', n/x
> ... break
> ... else:
> ... # loop fell through without finding a factor
> ... print n, 'is a prime number'
> ...
> 2 is a prime number
> 3 is a prime number
> 4 equals 2 * 2
> 5 is a prime number
> 6 equals 2 * 3
> 7 is a prime number
> 8 equals 2 * 4
> 9 equals 3 * 3
> 
> 
> 
> first time 2 mod 2, 2/2, no remainder == 0, what am I doing wrong?
> Why did it fall through?

print out what range(2, n) for n == 2 is.

And if you didn't know - 2 *IS* a prime.


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


Re: Control process execution

2008-04-09 Thread Mike Driscoll
On Apr 9, 3:11 pm, Noah <[EMAIL PROTECTED]> wrote:
> On Apr 6, 5:30 am, Wesley Mesquita <[EMAIL PROTECTED]> wrote:
>
> > I am trying to create a test environment to a couple C applications
> > (simple UDP and TCP server/clients), so I want to write this in python
> > and I m looking for ways to do it. Basically I need an execution timer
> > and timeout control (to kill the apps in certain situations). Looking
> > at google, I found the Pexpect package, but I m a little bit lost in
> > using it.
>
> Pexpect might be good. But if you are just looking at running an
> application
> without talking to it interactively then you might be able to just get
> by
> with os.process.
>
> --
> Noah

As far as I know, there is no "os.process". Maybe you meant os.system
or the subprocess module?

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


Re: wrapping C functions in python

2008-04-09 Thread Brian Cole
SWIG is a program that automatically generates code to interface
Python (and many other languages)  with C/C++. If you plan to create
lasting software libraries to be accessed from Python and C it is
quite a robust way to do so. Essentially, you feed it header files,
compile your code and the code generated by swig as a shared library,
then import the functions like you would a normal python module.

If all you need is to make some numerical code run faster it may be
more of a learning curve then you bargain for. Perhaps trying NumPy is
more appropriate. http://numpy.scipy.org/

-Brian

On Wed, Apr 9, 2008 at 2:44 PM, Paul Anton Letnes
<[EMAIL PROTECTED]> wrote:
> Hi, and thanks.
>
>
>  However, being a newbie, I now have to ask: What is SWIG? I have heard the
> name before, but haven't understood what it is, why I need it, or similar.
> Could you please supply some hints?
>
>
>  -Paul
>
>
>  Den 9. april. 2008 kl. 22.22 skrev Brian Cole:
>
>
> >
> >
> >
> > We use the following SWIG (www.swig.org) typemap to perform such
> operations:
> >
> > %typemap(in) (int argc, char **argv) {
> > if (!PySequence_Check($input)) {
> >  PyErr_SetString(PyExc_ValueError,"Expected a sequence");
> >  return NULL;
> > }
> > $1 = PySequence_Length($input);
> > $2 = (char**)alloca($1*sizeof(char*));
> > for (Py_ssize_t i = 0; i < $1; ++i) {
> >  PyObject *o = PySequence_GetItem($input, i);
> >  $2[i] = PyString_AsString(o);
> > }
> > }
> >
> > That one works for mapping a python sequence (such as a list) into the
> > argc, argv arguments commonly passed into main.
> >
> > -Brian
> >
> > On Wed, Apr 9, 2008 at 2:13 PM, Paul Anton Letnes
> > <[EMAIL PROTECTED]> wrote:
> >
> > > Hello etc.
> > >
> > >
> > > I am a "scientific" user of Python, and hence have to write some
> performance
> > > critical algorithms. Right now, I am learning Python, so this is a
> "newbie"
> > > question.
> > >
> > > I would like to wrap some heavy C functions inside Python, specifically
> a
> > > wavelet transform. I am beginning to become aquainted with the functions
> > > PyArg_ParseTuple() and Py_BuildValue(). However, I am unable to figure
> out
> > > how to pass Python list -> C function or C array -> return value in
> Python.
> > > I manage to build and run the C function, print to screen, pass string
> as
> > > argument, return an int, etc. The thing which is missing is the magic
> > > array/list...
> > >
> > >
> > > Thanks in advance! I fart in your general direction.
> > > Paul.
> > > --
> > > http://mail.python.org/mailman/listinfo/python-list
> > >
> > >
> > --
> >
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


basic python question about for loop

2008-04-09 Thread jmDesktop
>From the Python.org tutorial:

>>> for n in range(2, 10):
... for x in range(2, n):
... if n % x == 0:
... print n, 'equals', x, '*', n/x
... break
... else:
... # loop fell through without finding a factor
... print n, 'is a prime number'
...
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3



first time 2 mod 2, 2/2, no remainder == 0, what am I doing wrong?
Why did it fall through?

http://www.python.org/doc/current/tut/node6.html#SECTION00630

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


Re: wrapping C functions in python

2008-04-09 Thread Paul Anton Letnes
Hi, and thanks.


However, being a newbie, I now have to ask: What is SWIG? I have heard  
the name before, but haven't understood what it is, why I need it, or  
similar. Could you please supply some hints?


-Paul


Den 9. april. 2008 kl. 22.22 skrev Brian Cole:

> We use the following SWIG (www.swig.org) typemap to perform such  
> operations:
>
> %typemap(in) (int argc, char **argv) {
> if (!PySequence_Check($input)) {
>  PyErr_SetString(PyExc_ValueError,"Expected a sequence");
>  return NULL;
> }
> $1 = PySequence_Length($input);
> $2 = (char**)alloca($1*sizeof(char*));
> for (Py_ssize_t i = 0; i < $1; ++i) {
>  PyObject *o = PySequence_GetItem($input, i);
>  $2[i] = PyString_AsString(o);
> }
> }
>
> That one works for mapping a python sequence (such as a list) into the
> argc, argv arguments commonly passed into main.
>
> -Brian
>
> On Wed, Apr 9, 2008 at 2:13 PM, Paul Anton Letnes
> <[EMAIL PROTECTED]> wrote:
>> Hello etc.
>>
>>
>> I am a "scientific" user of Python, and hence have to write some  
>> performance
>> critical algorithms. Right now, I am learning Python, so this is a  
>> "newbie"
>> question.
>>
>> I would like to wrap some heavy C functions inside Python,  
>> specifically a
>> wavelet transform. I am beginning to become aquainted with the  
>> functions
>> PyArg_ParseTuple() and Py_BuildValue(). However, I am unable to  
>> figure out
>> how to pass Python list -> C function or C array -> return value in  
>> Python.
>> I manage to build and run the C function, print to screen, pass  
>> string as
>> argument, return an int, etc. The thing which is missing is the magic
>> array/list...
>>
>>
>> Thanks in advance! I fart in your general direction.
>> Paul.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Love matplotlib, but....

2008-04-09 Thread A_H
I love matplotlib, but I want to do a polar plot using your basic
compass type plot, i.e. zero degrees at the top, degrees going
clockwise.

I don't see a real easy way to do this.

Any examples?

Thanks!

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


Re: wrapping C functions in python

2008-04-09 Thread Diez B. Roggisch
>> I am a "scientific" user of Python, and hence have to write some performance
>> critical algorithms. Right now, I am learning Python, so this is a "newbie"
>> question.
>>
>> I would like to wrap some heavy C functions inside Python, specifically a
>> wavelet transform. I am beginning to become aquainted with the functions
>> PyArg_ParseTuple() and Py_BuildValue(). However, I am unable to figure out
>> how to pass Python list -> C function or C array -> return value in Python.
>> I manage to build and run the C function, print to screen, pass string as
>> argument, return an int, etc. The thing which is missing is the magic
>> array/list...

For pure C, I would rather recommend ctypes (standard lib since 
python2.5), or pyrex. These ease the process of wrapping C tremendously!

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


Re: Python 3.0 new integer division

2008-04-09 Thread Mark Dickinson
On Apr 9, 3:57 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> Naive question: why not just use a long + an exponent?
>
> e.g. 132560  -> (13256, 1)
>      0.534   -> (534, -3)
>      5.23e10 -> (523, 8)
>

It's a good question.  The standard answer is that if the
coefficient is a long then it's awkward to get at individual
digits;  looking up a digit becomes an O(n^2) operation
(involving a division and a remainder) instead of the O(1)
that it should be.  And you need access to the digits for
rounding operations, which are pretty darn common (one
round at the end of each arithmetic operation, as a rule).

But I could easily be convinced that storing the coefficient
as a long speeds things up for the usual use cases, even if
it gives horrible asymptotics for those trying to do really
high-precision calculations.  And it would certainly make
the code slightly simpler in places.

It would be great if someone could try converting Decimal
so that the coefficient is stored as a long, to see if there's
any noticeable impact on speed one way or the other.  It
wouldn't be such a hard change:  a few hours of work at most.
It's on my todo list to try this, but so far down that it's
not looking like it'll end up at the top of the list before
Christmas 20??.

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


RE: Stripping scripts from HTML with regular expressions

2008-04-09 Thread Reedick, Andrew


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Michel Bouwmans
> Sent: Wednesday, April 09, 2008 3:38 PM
> To: python-list@python.org
> Subject: Stripping scripts from HTML with regular expressions
> 
> Hey everyone,
> 
> I'm trying to strip all script-blocks from a HTML-file using regex.
> 
> I tried the following in Python:
> 
> testfile = open('testfile')
> testhtml = testfile.read()
> regex = re.compile(']*>(.*?)', re.DOTALL)


Aha! \b is being interpolated as a backspace character:
  \b ASCII Backspace (BS)

Always use a raw string with regexes:
regex = re.compile(r']*>(.*?)', re.DOTALL)

Your regex should now work.



*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA622


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


Re: wrapping C functions in python

2008-04-09 Thread Brian Cole
We use the following SWIG (www.swig.org) typemap to perform such operations:

%typemap(in) (int argc, char **argv) {
  if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a sequence");
return NULL;
  }
  $1 = PySequence_Length($input);
  $2 = (char**)alloca($1*sizeof(char*));
  for (Py_ssize_t i = 0; i < $1; ++i) {
PyObject *o = PySequence_GetItem($input, i);
$2[i] = PyString_AsString(o);
  }
}

That one works for mapping a python sequence (such as a list) into the
argc, argv arguments commonly passed into main.

-Brian

On Wed, Apr 9, 2008 at 2:13 PM, Paul Anton Letnes
<[EMAIL PROTECTED]> wrote:
> Hello etc.
>
>
> I am a "scientific" user of Python, and hence have to write some performance
> critical algorithms. Right now, I am learning Python, so this is a "newbie"
> question.
>
> I would like to wrap some heavy C functions inside Python, specifically a
> wavelet transform. I am beginning to become aquainted with the functions
> PyArg_ParseTuple() and Py_BuildValue(). However, I am unable to figure out
> how to pass Python list -> C function or C array -> return value in Python.
> I manage to build and run the C function, print to screen, pass string as
> argument, return an int, etc. The thing which is missing is the magic
> array/list...
>
>
> Thanks in advance! I fart in your general direction.
> Paul.
> --
>  http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stani's python ide 'spe' editor problem

2008-04-09 Thread SPE - Stani's Python Editor
Did you try to remove the .spe folder from your c:\Documents & Settings
\username folder?

Stani

On Apr 9, 6:16 pm, Rick King <[EMAIL PROTECTED]> wrote:
> Hi everyone,
> The editor inspeon my system (win XP home sp2) does not do automatic
> indentation. I can't figure out why - it used to. I'm set up with
> subversion so I have the very latest stuff from Stani. It's amazing how
> not having automatic indentation can make working in the ide such a pain.
>
> This has been going on for a while (like a few years), and the situation
> is deteriorating - used to be that the indentation would work for a
> while after restarting my system and then stop (until the next restart).
> Now, with his latest stuff, it doesn't work at all.
>
> Because it used to reset with a restart, it must have something to do
> with a dll, like the scintilla editor dll? But that's kind of hard to
> believe: why would the editor dll care about indentation?
>
> Anyway, I am extremely frustrated. I've tried other ide's: pythonwin (I
> found it inadequate for my purposes - why is a command line prompt
> displayed in a dialog window?) - eclipse (editor is just ok, shell does
> not have command history(!), and then *really* funky things started
> happening that I could not explain and so had to stop using it) - idle
> is good for small things and ok for larger projects but limited in general.
>
> I really likespeand want to continue using it. Stani himself seems
> pretty unreachable.
>
> Does anyone have a clue for me about what the issue is? Is no one else
> using this great ide? Or is no one else having this problem?
>
> Thanks for any help.
> -Rick King
> Southfield MI

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


Re: Stripping scripts from HTML with regular expressions

2008-04-09 Thread Stefan Behnel
Michel Bouwmans wrote:
> I'm trying to strip all script-blocks from a HTML-file using regex.

You might want to take a look at lxml.html instead, which comes with an HTML
cleaner module:

http://codespeak.net/lxml/lxmlhtml.html#cleaning-up-html

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


Re: Control process execution

2008-04-09 Thread Noah
On Apr 6, 5:30 am, Wesley Mesquita <[EMAIL PROTECTED]> wrote:
> I am trying to create a test environment to a couple C applications
> (simple UDP and TCP server/clients), so I want to write this in python
> and I m looking for ways to do it. Basically I need an execution timer
> and timeout control (to kill the apps in certain situations). Looking
> at google, I found the Pexpect package, but I m a little bit lost in
> using it.

Pexpect might be good. But if you are just looking at running an
application
without talking to it interactively then you might be able to just get
by
with os.process.

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


wrapping C functions in python

2008-04-09 Thread Paul Anton Letnes

Hello etc.


I am a "scientific" user of Python, and hence have to write some  
performance critical algorithms. Right now, I am learning Python, so  
this is a "newbie" question.


I would like to wrap some heavy C functions inside Python,  
specifically a wavelet transform. I am beginning to become aquainted  
with the functions PyArg_ParseTuple() and Py_BuildValue(). However, I  
am unable to figure out how to pass Python list -> C function or C  
array -> return value in Python. I manage to build and run the C  
function, print to screen, pass string as argument, return an int,  
etc. The thing which is missing is the magic array/list...



Thanks in advance! I fart in your general direction.
Paul.-- 
http://mail.python.org/mailman/listinfo/python-list

RE: Stripping scripts from HTML with regular expressions

2008-04-09 Thread Reedick, Andrew


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Michel Bouwmans
> Sent: Wednesday, April 09, 2008 3:38 PM
> To: python-list@python.org
> Subject: Stripping scripts from HTML with regular expressions
> 
> Hey everyone,
> 
> I'm trying to strip all script-blocks from a HTML-file using regex.
> 
> I tried the following in Python:
> 
> testfile = open('testfile')
> testhtml = testfile.read()
> regex = re.compile(']*>(.*?)', re.DOTALL)
> result = regex.sub('', blaat)
> print result
> 
> This strips far more away then just the script-blocks. Am I missing
> something from the regex-implementation from Python or am I doing
> something
> else wrong?
> 

[Insert obligatory comment about using a html specific parser
(HTMLParser) instead of regexes.]

Actually your regex didn't appear to strip anything.  You probably saw
stuff disappear because blaat != testhtml:
testhtml = testfile.read()
result = regex.sub('', blaat)


Try this:

import re

testfile = open('a.html')
testhtml = testfile.read()
regex = re.compile('(.*?)', re.DOTALL)
result = regex.sub('',testhtml)

print result




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


Re: Python 3.0 new integer division

2008-04-09 Thread Arnaud Delobelle
On Apr 9, 8:35 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> Strictly speaking, BCD doesn't come into it:  the coefficient of a
> Decimal instance is stored simply as a string of digits.  This is
> pretty wasteful in terms of space:  1 byte per decimal digit
> instead of the 4 bits per digit that BCD gives, but it's
> convenient and fairly efficient.
>
> An alternative representation that's gained popularity recently is
> DPD (densely packed decimal), which packs 3 decimal digits into 10
> bits in a clever way that allows reasonably efficient extraction
> of any one of the 3 digits.  Decimal doesn't use this either. :)
>
> Mark

Naive question: why not just use a long + an exponent?

e.g. 132560  -> (13256, 1)
 0.534   -> (534, -3)
 5.23e10 -> (523, 8)

--
Arnaud

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


Re: Running a python code periodically

2008-04-09 Thread Jorgen Grahn
On Tue, 08 Apr 2008 15:01:36 -0500, Larry Bates <[EMAIL PROTECTED]> wrote:
> paul wrote:
>> Maryam Saeedi schrieb:
>>> Hi,
>>>
>>> I was wondering if you know how can I run a python code once every five
>>> minutes for a period of time either using python or some other program like
>>> a bash script.
>> 
>> See the sched module in the standard library or here:
>> http://pypi.python.org/simple/Recur/

> You could use cron also.

Yeah, although cron has minute-resolution, so 5 min is fairly close to
the limit of what you can do.  Also, the poster mentioned "for a
period of time" and that makes me suspect that (s)he really wants the
code to make a decision about when to stop executing.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Stripping scripts from HTML with regular expressions

2008-04-09 Thread Michel Bouwmans
Hey everyone,

I'm trying to strip all script-blocks from a HTML-file using regex.

I tried the following in Python:

testfile = open('testfile')
testhtml = testfile.read()
regex = re.compile(']*>(.*?)', re.DOTALL)
result = regex.sub('', blaat)
print result

This strips far more away then just the script-blocks. Am I missing
something from the regex-implementation from Python or am I doing something
else wrong?

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


Re: Python 3.0 new integer division

2008-04-09 Thread Mark Dickinson
On Apr 8, 6:01 pm, Jonathan Gardner <[EMAIL PROTECTED]>
wrote:
> On Apr 8, 2:25 pm, Grzegorz S³odkowicz <[EMAIL PROTECTED]> wrote:
>
>
>
> > Isn't Decimal a BCD implementation?
>
> Yep, you are right and I am 
> wrong.http://www.python.org/dev/peps/pep-0327/#why-not-rational

Strictly speaking, BCD doesn't come into it:  the coefficient of a
Decimal instance is stored simply as a string of digits.  This is
pretty wasteful in terms of space:  1 byte per decimal digit
instead of the 4 bits per digit that BCD gives, but it's
convenient and fairly efficient.

An alternative representation that's gained popularity recently is
DPD (densely packed decimal), which packs 3 decimal digits into 10
bits in a clever way that allows reasonably efficient extraction
of any one of the 3 digits.  Decimal doesn't use this either. :)

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


Re: Displaying vtk files in a wxPython window

2008-04-09 Thread Mike Driscoll
On Apr 9, 1:38 pm, rocksportrocker <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> I want to visualize some vtk-files within a wxPython Window. Google
> did not help me
> very much, I only found some tools for Tk, what is no solution for me.
>
> I'm sure I am not the first one who asks this question
>
> Any hints ?
>
> Greetings, Uwe

Hi Uwe,

I've never done this, but I found the following:

http://www.vtk.org/pipermail/vtkusers/2004-July/075208.html

It seems to be an example of using wxPython and vtk. I'm also pretty
sure I've seen this topic discussed on the wxPython user's list. You
might want to re-post there: http://wxpython.org/maillist.php

I also found these links:

http://www.people.cornell.edu/pages/ajd27/VTK/lebbin_wxPython.html
http://www.wxpython.org/docs/api/wx.lib.vtk-module.html

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


pywin32 vista installer fix & general distutils installer name bug

2008-04-09 Thread Ville Vainio
I just noticed that pywin32 does not work with vista directly (tried
import win32clipboard, => ImportError). The problem is the installer
name; it's the usual

pywin32-210-win32-py2.5.exe

It needs to be renamed to:

pywin32-210.win32-setup-py2.5.exe

In order for vista to catch it as "installer".

We renamed the IPython exe installer to have "setup" to get around the
same issue.

Just posting this for benefit of googlers. I'll complain about this on
distutils-sig as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.

2008-04-09 Thread Marc 'BlackJack' Rintsch
On Wed, 09 Apr 2008 16:16:14 +0200, Diez B. Roggisch wrote:

> And then you reply telling us about the greatness of Bangalore and your
> product to come. Which is somewhat amusing that people who claim to produce
> the greatest software being incapable of debugging it deems me as odd - to
> say the least.

That's not odd, that's perfectly normal for really clever code:

  Debugging is twice as hard as writing the code in the first
  place.Therefore, if you write the code as cleverly as possible, you
  are, by definition, not smart enough to debug it. -- Brian W. Kernighan

;-)

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


Re: Google App Engine

2008-04-09 Thread Joshua Kugler
Duncan Booth wrote:
>
http://www.techcrunch.com/2008/04/07/google-jumps-head-first-into-web-services-with-google-app-engine/
> "Python only. What a weird decision. Not business and
> community-friendly at all."

Translation: "Not
over-engineered-top-heavy-overly-complex-job-security-inducing-Java-enterprise
friendly."

j

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


Re: Parsing locale specific dates, currency, numbers

2008-04-09 Thread Jarek Zgoda
Malcolm Greene pisze:
> The locale module provides the ability to format dates, currency and
> numbers according to a specific locale.
> 
> Is there a corresponding module for parsing locale's output to convert
> locale formatted dates, currency, and numbers back to their native data
> types on the basis of a specified locale?
> 
> In other words, a module that will reverse the outputs of locale on a
> locale specific basis.

There are some attempts in Babel (http://babel.edgewall.org/), but the
devs themselves claim the routines are incomplete. You might want to
check it, though.

-- 
Jarek Zgoda
http://zgodowie.org/

"We read Knuth so you don't have to" - Tim Peters
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can C.L.P.handle the load?

2008-04-09 Thread Joshua Kugler
Paddy wrote:
> I'm waiting for the rush of new users to c.l.p :-)
> If it comes, then aren't regularly posted FAQ's newbie friendly?

No, it just means they didn't take the time to read the docs and the FAQ for
themselves. :)

> Is their a good FAQ already around that we can regularly point newbies
> to?

You mean this one: http://www.python.org/doc/faq/

j

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


Displaying vtk files in a wxPython window

2008-04-09 Thread rocksportrocker
Hi,

I want to visualize some vtk-files within a wxPython Window. Google
did not help me
very much, I only found some tools for Tk, what is no solution for me.

I'm sure I am not the first one who asks this question

Any hints ?

Greetings, Uwe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pydev shell (was: Re: Stani's python ide 'spe' editor problem)

2008-04-09 Thread Rick King
I guess this is appropriate to the list... the funky things in eclipse 
that were happening are hard to describe, but first let me say that none 
of the other ide's had any funky things happening so I don't think it 
was my code. That said: I'm working on a command line bulk file renaming 
tool (using cmd.py) in which I can redirect input to a batch file if I 
want to, and redirect output to a file (for testing purposes). Running 
within an eclipse console, I could run through one batch file after 
which input returns to the console, and then try to run through the same 
batch file again by typing in my 'run' command; suddenly it would be as 
if a bunch of the tool's commands were executed having little (but 
something) to do with the batch of commands I just ran, producing a lot 
of output that didn't really make any sense. When I stepped through the 
debugger it got really weird: for example, at one point I went to the 
variables pane and clicked to open 'self' and it was at that moment that 
all this output came through on the console. Absolutely nonsensical.

I'll check out the new stuff for eclipse.
-Rick

Fabio Zadrozny wrote:
>>  Anyway, I am extremely frustrated. I've tried other ide's: pythonwin (I
>>  found it inadequate for my purposes - why is a command line prompt
>>  displayed in a dialog window?) - eclipse (editor is just ok, shell does
>>  not have command history(!), and then *really* funky things started
>>  happening that I could not explain and so had to stop using it) - idle
>>  is good for small things and ok for larger projects but limited in general.
>> 
>
> Hi Rick,
>
> The new release has an actual console shell (with code-completion,
> history, etc: see http://pydev.sourceforge.net/ for more details).
> Aside from that, which 'funky' things started happening?
>
> Cheers,
>
> Fabio
>
>
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String Literal to Blob

2008-04-09 Thread Victor Subervi
On Wed, Apr 9, 2008 at 1:49 PM, Steve Holden <[EMAIL PROTECTED]> wrote:

> Victor Subervi wrote:
> > On Wed, Apr 9, 2008 at 12:51 PM, Steve Holden <[EMAIL PROTECTED]
> > > wrote:
> I imagine the following code should do so, given your earlier writings:
>
> #! /usr/bin/python
>
> import MySQLdb
>
> print "Content-type: image/jpeg\r\n"
> host = 'host'
> db = 'bre'
> user = 'user'
> passwd = 'pass'
> connection = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
> cursor = connection.cursor()
> cursor.execute('select img from photo where id="7";')
> content = cursor.fetchall()[0][0]
> f = open("somefile.jpg", "w")
> f.write(content)
> f.close()
>
> Then see if you can deal with "somefile.jpg" like any other JPEG. If you
> can't then your blobs are somehow being mangled. If you can, we'll take
> it from there.


Yes, I can. Shows up in browser when surfed to, and it was pulled from the
database. No mangling. I am signing off, back tomorrow morning.
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Google App Engine

2008-04-09 Thread Daniel Fetchinson
> 
> > The backend data store, while it has a vaguely SQLish query language is an
> > object database not a relational database, i.e. more like ZODB than MySQL.
> > It uses similar concepts to django's data api but isn't the same. It
> should
> > be possible to write something simple to replace it, but given that you
> > only need to migrate away from Google when your data or page hits get
> > large, you need to replace it with something scalable.
>
> I have a bet with a coworker that someone will implement the api, in a
> way that makes migration away from Google easy, within a month.
> (actually, the bet is just that there will be a project with this
> goal). The reason I mention it here, is that he had the same comments
> as you regarding this. My thinking is that (if past experiences can be
> used as a yardstick) the python community will see this deficiency and
> work to correct it.  As a result of that thinking, I am fairly certain
> that this concern is not a big concern.  The authentication thing,
> thats a bit different.


The best would be if the google datastore backend would be available
from sqlalchemy or sqlobject. I understand that the google datastore
is not a relational database but that just means that the full power
of sqlalchemy or sqlobject would not be available for this backend
only a limited subset. I think this should be doable especially
because GQL is very similar to SQL looks like it's really a proper
subset.
-- 
http://mail.python.org/mailman/listinfo/python-list


Pydev shell (was: Re: Stani's python ide 'spe' editor problem)

2008-04-09 Thread Fabio Zadrozny
>  Anyway, I am extremely frustrated. I've tried other ide's: pythonwin (I
>  found it inadequate for my purposes - why is a command line prompt
>  displayed in a dialog window?) - eclipse (editor is just ok, shell does
>  not have command history(!), and then *really* funky things started
>  happening that I could not explain and so had to stop using it) - idle
>  is good for small things and ok for larger projects but limited in general.

Hi Rick,

The new release has an actual console shell (with code-completion,
history, etc: see http://pydev.sourceforge.net/ for more details).
Aside from that, which 'funky' things started happening?

Cheers,

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


Parsing locale specific dates, currency, numbers

2008-04-09 Thread Malcolm Greene
The locale module provides the ability to format dates, currency and
numbers according to a specific locale.

Is there a corresponding module for parsing locale's output to convert
locale formatted dates, currency, and numbers back to their native data
types on the basis of a specified locale?

In other words, a module that will reverse the outputs of locale on a
locale specific basis.

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


Re: String Literal to Blob

2008-04-09 Thread Steve Holden
Victor Subervi wrote:
> On Wed, Apr 9, 2008 at 12:51 PM, Steve Holden <[EMAIL PROTECTED] 
> > wrote:
> 
> Victor Subervi wrote:
> 
> On Wed, Apr 9, 2008 at 11:10 AM, Steve Holden
> <[EMAIL PROTECTED] 
> >> wrote:
> 
> I'm having a problem believing this, but I don't think you are
> lying. Are you *sure* you have stored the correct omages in your
> database?
> 
>  
> Well, the Plesk PHP/MySQL interface indicates that a blob has been 
> successfully stored. Furthermore, the output I get has strings like 
> either 'Adobe Photoshop' or 'GIMP', depending on the editor I used. And 
> the output is like I have seen before from incorrectly rendered images. 
> And images are what I loaded into those fields through my form. So I 
> believe they are indeed images.
>  
> 
> The fact remains that cursor.fetchall() will return a list
> containing one tuple containing (what you believe is) your image, so
> there is NO way your code above can do what you want.
> 
>  
> Right. I used your suggestion of cursor.fetchall()[0][0] and the result 
> was *still* the image of the url. (I also used the other suggestion.)
>  
> 
> 
> 
> I can therefore only assume that this is a CGI script and that your
> web server does something *extremely* funky when it gets a CGI
> output it isn't expecting. But this doesn't make a lot of sense. 
> 
>  
> Okay. How trouble-shoot this? Pass it on to the techies where I host? 
> Generally they are less than receptive, but maybe if I show them this 
> thread I can get their attention.
>  
Nope, no need to start berating unresponsive techies yet. Instead, try 
writing a file and see whether it is a legitimate JPEG or not.

I imagine the following code should do so, given your earlier writings:

#! /usr/bin/python

import MySQLdb

print "Content-type: image/jpeg\r\n"
host = 'host'
db = 'bre'
user = 'user'
passwd = 'pass'
connection = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
cursor = connection.cursor()
cursor.execute('select img from photo where id="7";')
content = cursor.fetchall()[0][0]
f = open("somefile.jpg", "w")
f.write(content)
f.close()

Then see if you can deal with "somefile.jpg" like any other JPEG. If you 
can't then your blobs are somehow being mangled. If you can, we'll take 
it from there.

regards
  Steve

> 
> 
> 
> Stupidity and ignorance are entirely different things, and you
> (current) ignorance in no way implies stupidity. We all have to learn.
> 
>  
> True. I have never found programming easy. But I have been very 
> persistent. It still is not easy for me.
>  
> 
> However, if you bring up one of the pages from one of your many web
> sites containing an image, and get your browser to display the HTML
> of that page you will surely find that the image does not appear
> direectly in the HTML, but instead appears as a tag in the HTML.
> Something like:
> 
>http://server/path/image.jpg";>
> 
> though the src attribute doesn't really need to be that complex. 
> 
>  
> Of course.
>  
> 
>  
> 
> In my stupidity, I have assumed you meant this:
> 
>content = col_fields[0][14].tostring()
>print ''
> 
> Well, here I have no idea what the content of your database might
> be, but if the fifteenth column you retrieve is the web server path
> to the graphic, that should be right except for the spaces around
> it, which might give trouble. You might consider instead
> 
> 
>content = col_fields[0][14].tostring()
>print '' % content
> 
>  
> Great suggestion! Those spaces always mess me up. Unfortunately, it 
> *still* did not render properly :(
>  
> 
>  
> 
> Forget HTML for now. If you direct your browser to the URL on which
> your server is serving the graphic then it should be displayed in
> the browser window. Until that happy condition pertains, we are
> stabbing around in the dark. 
> 
>  
> Again...time to alert the teckies where I host?
>  
> 
>  
> It's not that I mind, but I do feel that this knowledge is already
> available, though clearly I might be wrong ... 
> 
>  
> Well, I may have missed it in all my googling, but I thought I was 
> pretty thorough. At any rate, it certainly cannot hurt to document it 
> again (if it is indeed 'again')
> TIA,
> Victor
> 


-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Google App Engine

2008-04-09 Thread Erich
On Apr 9, 3:51 am, Duncan Booth <[EMAIL PROTECTED]> wrote:

> The backend data store, while it has a vaguely SQLish query language is an
> object database not a relational database, i.e. more like ZODB than MySQL.
> It uses similar concepts to django's data api but isn't the same. It should
> be possible to write something simple to replace it, but given that you
> only need to migrate away from Google when your data or page hits get
> large, you need to replace it with something scalable.

I have a bet with a coworker that someone will implement the api, in a
way that makes migration away from Google easy, within a month.
(actually, the bet is just that there will be a project with this
goal). The reason I mention it here, is that he had the same comments
as you regarding this. My thinking is that (if past experiences can be
used as a yardstick) the python community will see this deficiency and
work to correct it.  As a result of that thinking, I am fairly certain
that this concern is not a big concern.  The authentication thing,
thats a bit different.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.

2008-04-09 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hi Steve,
> comp.lang.python is supposed to be a serious group not anyone knowing
> nothing and giving comment. Well, original code snippet I don't know
> why an expert person like you fails to understand, I told it almost
> can't you guess the next portion? 

And this is outright outrageous. You are actually *aware* that people 
must guess what you mean and expect them to do so, sparing yourself the 
work of providing better information - willfully? This is as close to 
impertinence as it can get.

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


Pydev 1.3.15 Released

2008-04-09 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.3.15 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* Globals Browser: Was not correctly showing definition on a case with
multiple projects when one did not have the python nature configured.
* Code Analysis: False positive: Classes defined within a class
context are correctly found when later accessed in the parent context.
* Interactive console integration
  o Context insensitive completions with auto-import in console
  o Ctrl+Alt+Enter: can be used to:
+ Create console if no console exists
+ Send selected text to console
+ Make execfile for current file if there's no selected text


Release Highlights in Pydev:
--

* Files without extension: If a file that does not have an extension
is found in the root of the pythonpath, code-completion and
breakpoints work with it.
* Extract method: comma not removed when found after a tuple and
before a keyword argument.
* Console Encoding: print u"\xF6" works (console encoding correctly
customized in python -- see
http://sourceforge.net/tracker/index.php?func=detail&aid=1580766&group_id=85796&atid=577329
for details).
* Debugger: Context of breakpoint correctly defined when comments are
present in the end of the module.
* from __future__ import (xxx, with_statement): works.
* Interactive Console View, featuring:
  o Code Completion
+ Context sensitive with shell completions
+ Qualifier matches as case insensitive
+ Templates
+ Repeating the activation changes from templates to
default completions
  o Console Configurations
+ Initial commands for starting the console
+ Colors for the console
+ Vmargs can be specified for jython
  o Auto-indent
  o Auto-edits
  o Context info on hover
  o Up / Down Arrows cycles through the history (and uses the
current text to match for the start of the history command)
  o Page Up: shows dialog with console history (where lines to be
re-executed can be selected)
  o Esc: clears current line
  o ctrl+1 works for assign quick-assist
  o Hyperlinks addedd to tracebacks in the console
  o Paste added directly to the command line
  o Cut will only cut from the command line
  o Copy does not get the prompt chars
  o Home goes to: first text char / prompt end / line start (and
cycles again)
  o Cursor automatically moved to command line on key events
  o Multiple views of the same console can be created
  o Limitation: Output is not asynchonous (stdout and stderr are
only shown after a new command is sent to the console)



What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about string formatting

2008-04-09 Thread Kelie
Thank you Jerry!

--
Kelie
UliPad  is my Python editor.

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


Re: Python Leopard DLL Hell

2008-04-09 Thread Brian Cole
I have learned that this is a specific behavior of OS X. I have
submitted a formal bug report to Apple about the problem. It appears
that this is documented by Apple as acceptable:
http://developer.apple.com/documentation/DeveloperTools/Reference/MachOReference/Reference/reference.html#//apple_ref/c/func/dlopen

Whereas, linux will respect the fact you gave it a specific shared library:
http://linux.die.net/man/3/dlopen

If I am provided a workaround by apple I will post a python patch. A
little scary that someone can circumvent my application by just
setting an environment variable.

-Brian Cole

On Tue, Apr 8, 2008 at 7:52 PM, Michael Torrie <[EMAIL PROTECTED]> wrote:
> Brian Cole wrote:
>  > That appears to be working correctly at first glance. The argument to
>  > dlopen is the correct shared library. Unfortunately, either python or
>  > OS X is lying to me here. If I inspect the python process with OS X's
>  > Activity Monitor and look at the "Open Files and Ports" tab, it shows
>  > that the _foo.so shared library is actually the one located inside
>  > $DYLD_LIBRARY_PATH.
>  >
>  > So this problem may not be python's, but I place it here as a first
>  > shot (maybe I'm using the imp module incorrectly).
>
>  Sounds like you're going to need to learn how to use dtrace.  Then you
>  can more closely monitor exactly what python and the loader are doing.
>  dtrace is very complicated (borrowed from Solaris) but extremely
>  powerful.  Worth learning anyway, but sounds like it's probably the
>  debugging tool you need.
>
>  Another thing you can do is check through the python source code and see
>  how the os x-specific code is handling this type of situation.
>
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about string formatting

2008-04-09 Thread Jerry Hill
On Wed, Apr 9, 2008 at 1:04 PM, Kelie <[EMAIL PROTECTED]> wrote:
> Is there something in Python built-in function or library that will convert
> a number 1205466.654 to $1,205,466.65? To add the "$" sign and set the
> decimal place is not a problem, but I don't know how to add the thousands
> delimiter.

The locale module provides this functionality.

>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'English_United States.1252'
>>> print locale.currency(1205466.654)
$1205466.65
>>> locale.currency(1205466.654, grouping=true)
$1,205,466.65

That's using the default locale.  For me, that's US English.  Other
languages and countries have different ways of showing currency:

>>> locale.setlocale(locale.LC_ALL, "fr")
'French_France.1252'
>>> print locale.currency(1205466.654, grouping=True)
1 205 466,65 €

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

Re: String Literal to Blob

2008-04-09 Thread Victor Subervi
On Wed, Apr 9, 2008 at 12:51 PM, Steve Holden <[EMAIL PROTECTED]> wrote:

> Victor Subervi wrote:
>
> > On Wed, Apr 9, 2008 at 11:10 AM, Steve Holden <[EMAIL PROTECTED] > [EMAIL PROTECTED]>> wrote:
> >
> > I'm having a problem believing this, but I don't think you are lying.
> Are you *sure* you have stored the correct omages in your database?


Well, the Plesk PHP/MySQL interface indicates that a blob has been
successfully stored. Furthermore, the output I get has strings like either
'Adobe Photoshop' or 'GIMP', depending on the editor I used. And the output
is like I have seen before from incorrectly rendered images. And images are
what I loaded into those fields through my form. So I believe they are
indeed images.


> The fact remains that cursor.fetchall() will return a list containing one
> tuple containing (what you believe is) your image, so there is NO way your
> code above can do what you want.


Right. I used your suggestion of cursor.fetchall()[0][0] and the result was
*still* the image of the url. (I also used the other suggestion.)


>
>
> I can therefore only assume that this is a CGI script and that your web
> server does something *extremely* funky when it gets a CGI output it isn't
> expecting. But this doesn't make a lot of sense.


Okay. How trouble-shoot this? Pass it on to the techies where I host?
Generally they are less than receptive, but maybe if I show them this thread
I can get their attention.


>
>
> Stupidity and ignorance are entirely different things, and you (current)
> ignorance in no way implies stupidity. We all have to learn.
>

True. I have never found programming easy. But I have been very persistent.
It still is not easy for me.


> However, if you bring up one of the pages from one of your many web sites
> containing an image, and get your browser to display the HTML of that page
> you will surely find that the image does not appear direectly in the HTML,
> but instead appears as a tag in the HTML. Something like:
>
>http://server/path/image.jpg";>
>
> though the src attribute doesn't really need to be that complex.
>

Of course.


>
>
> In my stupidity, I have assumed you meant this:
> >
> >content = col_fields[0][14].tostring()
> >print ''
> >
> > Well, here I have no idea what the content of your database might be,
> but if the fifteenth column you retrieve is the web server path to the
> graphic, that should be right except for the spaces around it, which might
> give trouble. You might consider instead
>
>content = col_fields[0][14].tostring()
>print '' % content


Great suggestion! Those spaces always mess me up. Unfortunately, it *still*
did not render properly :(


>
>
> Forget HTML for now. If you direct your browser to the URL on which your
> server is serving the graphic then it should be displayed in the browser
> window. Until that happy condition pertains, we are stabbing around in the
> dark.


Again...time to alert the teckies where I host?


>
> It's not that I mind, but I do feel that this knowledge is already
> available, though clearly I might be wrong ...


Well, I may have missed it in all my googling, but I thought I was pretty
thorough. At any rate, it certainly cannot hurt to document it again (if it
is indeed 'again')
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: is Pylons alive?

2008-04-09 Thread Nikita the Spider
In article <[EMAIL PROTECTED]>,
 Gerhard Häring <[EMAIL PROTECTED]> wrote:

> - TurboGears 2.0 (I personally wouldn't bother with TurboGears 1.x at 
> this point)

Having investigated some of this myself recently, I agree with you that 
the TG 1.x series is a dead end, but there's no TG 2.0 yet. Last time I 
checked the developers hoped to have an alpha release at the end of 
March.

-- 
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: question about string formatting

2008-04-09 Thread G
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'en_US.UTF-8'
>>> locale.format('%.2f', 1021212.12, True)
'1,021,212.12'
>>>

On Wed, Apr 9, 2008 at 1:04 PM, Kelie <[EMAIL PROTECTED]> wrote:

> Hello,
>
> Is there something in Python built-in function or library that will
> convert a number 1205466.654 to $1,205,466.65? To add the "$" sign and set
> the decimal place is not a problem, but I don't know how to add the
> thousands delimiter.
>
> Thanks,
>
> --
> Kelie
> UliPad  is my Python editor.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: set file permission on windows

2008-04-09 Thread Tim Arnold
"Tim Golden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Tim Arnold wrote:
>> "Mike Driscoll" <[EMAIL PROTECTED]> wrote in message 
>> news:[EMAIL PROTECTED]
>>> On Apr 8, 12:03 pm, "Tim Arnold" <[EMAIL PROTECTED]> wrote:

>>
>>> According to the following thread, you can use os.chmod on Windows:
>>>
>>> http://mail.python.org/pipermail/python-list/2003-June/210268.html
>>>
>>> You can also do it with the PyWin32 package. Tim Golden talks about
>>> one way to do it here:
>>>
>>> http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html
>>>
>>> Also see the following thread:
>>>
>>> http://mail.python.org/pipermail/python-win32/2004-July/002102.html
>>>
>>> or
>>>
>>> http://bytes.com/forum/thread560518.html
>>>
>>> Hope that helps!
>>>
>>> Mike
>>
>> Hi Mike,
>> It does help indeed, especially the last two links.
>
> Hi, Tim. For the purposes of improving that page of mine linked
> above, would you mind highlighting what made it less useful
> than the last two links? On the surface, it seems to match your
> use case pretty closely. Was there too much information? Too
> little? Poor formatting? Just didn't feel right? I've a small set
> of security-related pages in train and I'd rather produce something which 
> people find useful.
>
> Thanks
>
> TJG

Hi TJG. Thanks for the site. Unfortunately, I mis-typed in the previous 
reply and that should have been the 'first two links' instead of 'last two 
links'. In fact I bookmarked your site so I can re-read the material and I 
copied the code to play around with.  Excellent example--it contains just 
what I needed to know, esp. since it replaces the dacl instead of modifying 
one. Now I can remove access for 'Everybody' by simply not including it in 
the new dacl.

thanks!
--Tim Arnold


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


question about string formatting

2008-04-09 Thread Kelie
Hello,

Is there something in Python built-in function or library that will convert
a number 1205466.654 to $1,205,466.65? To add the "$" sign and set the
decimal place is not a problem, but I don't know how to add the thousands
delimiter.

Thanks,

-- 
Kelie
UliPad  is my Python editor.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Learning curve for new database program with Python?

2008-04-09 Thread M.-A. Lemburg
On 2008-04-07 20:19, Gary Duzan wrote:
> In article <[EMAIL PROTECTED]>,
> M.-A. Lemburg <[EMAIL PROTECTED]> wrote:
>> On 2008-04-07 15:30, Greg Lindstrom wrote:
>>> SQL is one of the areas I wish I had mastered (much) earlier in my career
>> Fully agree :-)
>>
>> Interesting comments in a time where everyone seems to be obsessed
>> with ORMs.
> 
>It seems to me that ORM can work if your database isn't too
> complex and it is the only way your database is going to be accessed.
> In our case, we have a messy legacy database (lots of tables,
> triggers, stored procedures, etc., that nobody really understands)
> with multiple processes hitting it, and so our efforts to integrate
> Hibernate haven't been terribly smooth.  In this environment the
> hack seems to be to have Hibernate write to its own tables, then
> have stored procedures sync them with the old tables.  Not pretty.

While ORMs are nice if you want to get something done quickly,
I usually prefer to take the standard database abstraction layer
approach: it encapsulated all the database wisdom an application
needs, so you don't have to deal with these details at higher
levels in the applications, but still allows you to dive right
into the full feature set of whatever backend you are using.

In addition to having just one place to look for SQL statements,
it also provides the needed abstraction to be able to support multiple
different backends - by using a common base class and having one
subclass per supported database backend.

This straight-forward approach makes maintaining support for
multiple databases much easier and also allows us to work around
problems which you inevitably run into, e.g. missing support
for certain features in one backend, data type conversion needs
for another, etc.

Another problem I found with ORMs is error handling. Since most
of the database interaction happens behind the scenes, errors
can pop up in situations where you might not expect them in
your application. Again, the database abstraction layer provides
better control, since that's where you run the queries and deal
with the errors.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Apr 09 2008)
 >>> Python/Zope Consulting and Support ...http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
-- 
http://mail.python.org/mailman/listinfo/python-list


Guppy-PE / Heapy 0.1.8

2008-04-09 Thread Sverker Nilsson
I am happy to announce Guppy-PE 0.1.8

Guppy-PE is a library and programming environment for Python,
currently providing in particular the Heapy subsystem, which supports
object and heap memory sizing, profiling and debugging. It also
includes a prototypical specification language, the Guppy
Specification
Language (GSL), which can be used to formally specify aspects of
Python programs and generate tests and documentation from a common
source.

The current version is updated to work in 64-bit mode and with
Python-2.6, and still works in 32-bit mode and with Python 2.3, 2.4
and 2.5. No other major changes have been made from Guppy 0.1.6.

In the nearest future, I plan to add interactive help and more
examples to the documentation, perhaps a tutorial. Look out for this
in the svn HEAD according to instructions at the project home page,
if you want the latest version. I will try to make a new release in
perhaps a month or so.

License: MIT

Guppy-PE 0.1.8 is available in source tarball format on the Python
Package Index (a.k.a. Cheeseshop):

http://pypi.python.org/pypi/guppy/0.1.8

The project homepage is on Sourceforge:

http://guppy-pe.sourceforge.net

Enjoy,

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


Re: String Literal to Blob

2008-04-09 Thread Steve Holden
Victor Subervi wrote:
> On Wed, Apr 9, 2008 at 11:10 AM, Steve Holden <[EMAIL PROTECTED] 
> > wrote:
> 
> Victor Subervi wrote:
> 
> On Wed, Apr 9, 2008 at 10:24 AM, Steve Holden
> <[EMAIL PROTECTED] 
> >> wrote:
> connection = MySQLdb.connect(host=host, user=user,
> passwd=passwd, db=db)
> cursor = connection.cursor()
> cursor.execute('select img from photo where id="7";')
> content = cursor.fetchall()
> 
> 
> Bzzt! Nope. Cursor.fetchall() returns a list (length 1) or tuples
> (length 1) here, so this should be
> 
> content = cursor.fetchall()[0][0]
> 
> or, perhaps better
> 
> content = cursor.fetchone()[0]
> 
> 
> I tried both of these, and they, too, gave me the same identical image 
> of the url, not the image I am after.
> 
I'm having a problem believing this, but I don't think you are lying. 
Are you *sure* you have stored the correct omages in your database?

The fact remains that cursor.fetchall() will return a list containing 
one tuple containing (what you believe is) your image, so there is NO 
way your code above can do what you want.

I can therefore only assume that this is a CGI script and that your web 
server does something *extremely* funky when it gets a CGI output it 
isn't expecting. But this doesn't make a lot of sense.

> 
> 
> You really don't understand how the web works, do you?
> 
> 
> I am just really, really, stupid, Steve. Please forgive me for being so 
> stupid. But I am persistent. And I have built dozens of Web site with 
> images.
>  
Stupidity and ignorance are entirely different things, and you (current) 
ignorance in no way implies stupidity. We all have to learn.

However, if you bring up one of the pages from one of your many web 
sites containing an image, and get your browser to display the HTML of 
that page you will surely find that the image does not appear direectly 
in the HTML, but instead appears as a tag in the HTML. Something like:

 http://server/path/image.jpg";>

though the src attribute doesn't really need to be that complex.
> 
> In order to include an image in a page your browser must make TWO
> requests. The first is for an HTML page that will reference the
> image in this way:
> 
>http://your URL here">
> 
> Seeing this img tag causes the browser to make a SECOND request,
> which the script I corrected above should respond to with an image.
> 
> The bytestream is critical in the image response. Even one misplaced
> byte will mess things up terribly.
> 
> 
> In my stupidity, I have assumed you meant this:
> 
> content = col_fields[0][14].tostring()
> print ''
> 
Well, here I have no idea what the content of your database might be, 
but if the fifteenth column you retrieve is the web server path to the 
graphic, that should be right except for the spaces around it, which 
might give trouble. You might consider instead

 content = col_fields[0][14].tostring()
 print '' % content

to omit them.

> Obviously I am wrong. Could you please give me a little more insight?
> 
Forget HTML for now. If you direct your browser to the URL on which your 
server is serving the graphic then it should be displayed in the browser 
window. Until that happy condition pertains, we are stabbing around in 
the dark.

> BTW, when we are finally done with this, I will write a nice
> how-to (since there is not one in python, while php has some
> nice ones) on how to do this, and give you and Gabrielle all
> your due credit. I will post it to this list, because that is
> sure to rank highly in google right away.
> Victor
> 
> That's great, though hardly the point of the exercise. I think
> Google already know about Gabriel (*not* Gabrielle) and me already ...
> 
> 
> Well, I just thought it might be a good way to get the information out, 
> since it is not out there yet. And I believe it is only proper to give 
> credit where credit is due. I would not be doing this to praise you. 
> Rather, I would be doing this because it is needed, and I would feel 
> wrong for not crediting those who deserve credit. Please let me know, 
> however, if you feel otherwise.

It's not that I mind, but I do feel that this knowledge is already 
available, though clearly I might be wrong ...

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem using import from PyRun_String

2008-04-09 Thread Patrick Stinson
Well, I eventually want to add an import hook, but for now I'd rather just
get the import statement working normally again.
I have embedded python as a scripting engine in my application. To do this,
I create a new empty module, run the script text using PyRun_String()
passing the module's __dict__ as locals and globals. This populates the
module's __dict__ with the resulting object references from the script text.
As I said before I must be forgetting some other module init stuff because I
had to manually populate the modules' __dict__ with references from the
__builtin__ module in order to get the basic stuff like abs, range, etc.

I understand what __builtin__ is used for, but the C struct pointing to the
code frame that contains the import statement has a builtin member that
apparently does not contain the __import__ function, hence my question.
There must be some difference in the way code is parsed and a copy of the
__builtin__ module is passed normally and the way I am doing it.

So, finding the place where this module bootstrapping normally happens would
be awesome, because I sort of feel like I'm hacking this method running into
problems like this.

I'll definitely be putting together a wiki on this topic before long. Seems
like an application scripting engine is incredibly easy to implement if you
already know all the tricks, we're just lacking docs.

On Wed, Apr 9, 2008 at 1:00 AM, Gabriel Genellina <[EMAIL PROTECTED]>
wrote:

> En Tue, 08 Apr 2008 22:01:18 -0300, Patrick Stinson
> <[EMAIL PROTECTED]> escribió:
>
> > I'm creating a module with PyModule_New(), and running a string buffer
> as
> > the module's text using PyRun_String and passing the module's __dict__
> to
> > locals and globals.
>
> Why? Do you want to fake what import does?
>
> > I'm having a problem using the import statement from
> > within PyRun_String(). It complains about "__import__ not found", which
> > after a quick grep it looks like the exception is raised from
> > PyExc_EvalFrameEx() in ceval.c after f->f_builtins module doesn't
> contain
> > "__import__".
> > What __builtin__ module does that point to? a quick print of the
>
> __builtin__ holds all the builtin objects, what a surprise! :)
> http://docs.python.org/lib/module-builtin.html
>
> > Any help?
>
> What do you want to do actually?
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Patrick Kidd Stinson
http://www.patrickkidd.com/
http://pkaudio.sourceforge.net/
http://pksampler.sourceforge.net/
-- 
http://mail.python.org/mailman/listinfo/python-list

Stani's python ide 'spe' editor problem (again)

2008-04-09 Thread Rick King
In my previous post about spe I didn't mention that my set up is:
python 2.4.4
wxpython 2.8.3
thanks.
-Rick King
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to find documentation about methods etc. for iterators

2008-04-09 Thread Arnaud Delobelle
On Apr 9, 5:05 pm, [EMAIL PROTECTED] wrote:
> I'm not sure if I have even phrased that right but anyway
>
> How does one find (in the standard Python documentation) information
> about things like the iteritems() method and the enumerate() function.
>
> They are mentioned in the tutorial as ways of getting more information
> as you loop through an object but there seems to be no easy way to
> find the definitive documentation of these sorts of methods and
> functions.  OK, if I know the name before I start I can probably find
> what I want, but what if I want to know how to extract some
> information from an object as I loop and don't know what I want is
> called?
>
> My particular quest that raised this was a way to get the line number
> as I iterate through the lines of a file:-
>
> f = open(fn, 'r')
> lineNo = 0
> for ln in f:
> lineNo += 1
>
> Is there a neater way of getting that line number as I go?  If so how
> am I meant to find out about it?

There is a neater way, and you mention it in your question:

f = open('myfile')

for lineno, line in enumerate(f):
# Do stuff

How to find out about it?  I suppose you need to get familiar with
python iterators/iterables and the functions to manipulate them.  How
to do that depends on your prior experience with such concepts.
Unfortunately I am not able to provide you with a good link :(

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


Stani's python ide 'spe' editor problem

2008-04-09 Thread Rick King
Hi everyone,
The editor in spe on my system (win XP home sp2) does not do automatic 
indentation. I can't figure out why - it used to. I'm set up with 
subversion so I have the very latest stuff from Stani. It's amazing how 
not having automatic indentation can make working in the ide such a pain.

This has been going on for a while (like a few years), and the situation 
is deteriorating - used to be that the indentation would work for a 
while after restarting my system and then stop (until the next restart). 
Now, with his latest stuff, it doesn't work at all.

Because it used to reset with a restart, it must have something to do 
with a dll, like the scintilla editor dll? But that's kind of hard to 
believe: why would the editor dll care about indentation?

Anyway, I am extremely frustrated. I've tried other ide's: pythonwin (I 
found it inadequate for my purposes - why is a command line prompt 
displayed in a dialog window?) - eclipse (editor is just ok, shell does 
not have command history(!), and then *really* funky things started 
happening that I could not explain and so had to stop using it) - idle 
is good for small things and ok for larger projects but limited in general.

I really like spe and want to continue using it. Stani himself seems 
pretty unreachable.

Does anyone have a clue for me about what the issue is? Is no one else 
using this great ide? Or is no one else having this problem?

Thanks for any help.
-Rick King
Southfield MI
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String Literal to Blob

2008-04-09 Thread Victor Subervi
On Wed, Apr 9, 2008 at 11:10 AM, Steve Holden <[EMAIL PROTECTED]> wrote:

> Victor Subervi wrote:
>
> > On Wed, Apr 9, 2008 at 10:24 AM, Steve Holden <[EMAIL PROTECTED] > [EMAIL PROTECTED]>> wrote:
> > connection = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
> > cursor = connection.cursor()
> > cursor.execute('select img from photo where id="7";')
> > content = cursor.fetchall()
> >
>
> Bzzt! Nope. Cursor.fetchall() returns a list (length 1) or tuples (length
> 1) here, so this should be
>
> content = cursor.fetchall()[0][0]
>
> or, perhaps better
>
> content = cursor.fetchone()[0]


I tried both of these, and they, too, gave me the same identical image of
the url, not the image I am after.

>
>
> You really don't understand how the web works, do you?


I am just really, really, stupid, Steve. Please forgive me for being so
stupid. But I am persistent. And I have built dozens of Web site with
images.


> In order to include an image in a page your browser must make TWO
> requests. The first is for an HTML page that will reference the image in
> this way:
>
>http://your URL here">
>
> Seeing this img tag causes the browser to make a SECOND request, which the
> script I corrected above should respond to with an image.
>
> The bytestream is critical in the image response. Even one misplaced byte
> will mess things up terribly.


In my stupidity, I have assumed you meant this:

content = col_fields[0][14].tostring()
print ''

Obviously I am wrong. Could you please give me a little more insight?

> BTW, when we are finally done with this, I will write a nice how-to (since
> > there is not one in python, while php has some nice ones) on how to do this,
> > and give you and Gabrielle all your due credit. I will post it to this list,
> > because that is sure to rank highly in google right away.
> > Victor
> >
> >  That's great, though hardly the point of the exercise. I think Google
> already know about Gabriel (*not* Gabrielle) and me already ...


Well, I just thought it might be a good way to get the information out,
since it is not out there yet. And I believe it is only proper to give
credit where credit is due. I would not be doing this to praise you. Rather,
I would be doing this because it is needed, and I would feel wrong for not
crediting those who deserve credit. Please let me know, however, if you feel
otherwise.
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   >