Re: Subclassing socket

2005-12-20 Thread Maksim Kasimov

you have to agregate socket and the object must have "fileno" method,
thats gives a possibility to use instanses of your class with "select.select" 
function


class mySocket:

 def __init__(self, ...):
 self.__socket = None
...


 def fileno(self):
 return self.__socket.fileno()


 def connect(self, __host, __port):
 try:
 self.close()
 self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 self.__socket.connect((__host, __port))
...


 def close(self):
 try:
 if self.__socket is not None:
 self.__socket.close()
 finally:
 self.__socket = None

 ...


[EMAIL PROTECTED] wrote:
> socket objects have a little quirk.  If you try to receive 0 bytes on a
> blocking socket, they block.  That is, if I call recv(0), it blocks
> (until some data arrives).
> 
> I think that's wrong, but I don't want to argue that.  I would like to
> create a subclass of socket that fixes the problem.  Ideally, something
> like:
> 
> class new_socket(socket):
> def recv( self, bufsize, flags=0 ):
> if bufsize == 0:
> return ""
> else:
> return socket.recv( bufsize, flags )
> 
> They only problem is, sockets return socket objects via the accept
> call.  And the socket returned is of type socket, of course, not
> new_socket, as I would like.  I could override accept() to return a
> new_socket, but I don't know how to convert the old socket to a new
> socket.  That is, I'd like to add a method to the class above something
> like:
> 
> def accept( self ):
> conn, addr = socket.accept()
> 
> return ( conn, addr )
> 
> Does anyone have any suggestions on how to do the above?
> 


-- 
Best regards,
Maksim Kasimov
mailto: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why my thread can't access the global data?

2005-12-20 Thread ddh
Thank you, but I think it may be not this reason.

You see, when accept returns, the go_on will be checked in 'while
go_on:', so if it is set to be false, the loop will end. I have set a
0.5 second time out on the select() function. So the 'go_on' will be
checked at a frequency every 0.5 second at least.




Pelmen wrote:
> your main loop already on accept when your thread change the go_on imho
> try to input another string after 'quit'
> 
> and actually there is no need to use thread

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


Re: Why my thread can't access the global data?

2005-12-20 Thread Pelmen
your main loop already on accept when your thread change the go_on imho
try to input another string after 'quit'

and actually there is no need to use thread

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


Why my thread can't access the global data?

2005-12-20 Thread ddh
Hi,
  I got a problem. I use a 'select' in a loop in the main thread, and
when select return, a new thread will be created to handle the network
event. And if the client send some special string, the thread will
change a global flag to false, so the loop in the main thread will
break. But it never work.

Below is the code:
- s.py (the server) --
import socket
import select
import thread
import sys

go_on = True

def read_send(s):
s.setblocking(1)
str = s.recv(1024)
print 'recv:', str
s.send(str)
s.close()
if (str == 'quit'):
go_on = False
print 'User quit...with go_on =', go_on
return


s = socket.socket(socket.AF_INET)
s.bind(('', ))
s.listen(5)
s.setblocking(0)

while go_on:
r_set = [s.fileno(),]
r, w, e = select.select(r_set,[],[],0.5)
print 'select returned with go_on =', go_on
for rs in r:
if rs == s.fileno():
ns, addr = s.accept()
print 'socket on', addr, 'has been accepted'
thread.start_new_thread(read_send, (ns,))
s.close()


- c.py (the client) --
import socket
import sys

if len(sys.argv) != 3:
print 'usage: python c.py ip port'
sys.exit(-1)

ip = sys.argv[1]
port = int(sys.argv[2])
s = socket.socket(socket.AF_INET)
s.settimeout(5)
s.connect((ip, port))
str = raw_input('please input:')
s.send(str)
str = s.recv(1024)
print 'received:', str
s.close()

--
run s.py first, and then run c.py as:
python c.py 127.0.0.1 
and then input 'quit', but the server never end :(



Thank you for your help!

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


Re: Raw images

2005-12-20 Thread Fredrik Lundh
"Tuvas" wrote:

> 1. Read string
> 2. Form an array by combining 2 chars together.
> 3. Divide by 256 so as to have a 8 bit number, which PIL likes alot
> better than a 16 bit number. The string is called data.
> 4. Use im = Image.fromstring('L', (xsize, ysize), data) to create image

PIL can do this conversion for you (by specifying a "raw mode" to
fromstring).  I'll post an example later.

>image=ImageTk.BitmapImage(im)
>pic=canvas.create_image(1,1,anchor="nw",image=image,tag="pic")
>canvas.addtag_withtag("pic",pic)
>
> There seems to be a problem with the last line, but no picture is
> displayed without it. That isn't related to the problem I'm having, but
> I also need to fix it. The problem is it won't display the image, it
> seems to display nothing. Any ideas as to why?

if you have a grayscale image, you should use PhotoImage, not BitmapImage.

as for the disappearing image, see the note at the bottom of this page:

http://www.effbot.org/tkinterbook/photoimage.htm

 



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


libxml2 has schema support

2005-12-20 Thread ankit
I am new to xml and python. I have to choose a package which has schema
support.
I like to use libxml2 but does libxml2 has schma support ?

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


Re: Subclassing socket

2005-12-20 Thread Pelmen
imho:
class new_socket(socket):
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0,
_sock=None)
   socket.__init__(self, family=AF_INET, type=SOCK_STREAM, proto=0,
_sock=None)

def accept( self ):
conn, addr = socket.accept()
   return ( new_socket(_sock=conn), addr )

but i think your problem have a more simple way then inheritance

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


Re: Windows Services

2005-12-20 Thread Mondal
Hi,

Thanks Upole!!! I dowloaded it. From exe files at sourceforge.net.

Regards

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


Re: Raw images

2005-12-20 Thread Tuvas
Well, it's a custum-built camera, so it's not standard by any means.
That being the case, I know it's exact format, which is as follows. It
is a stream of 16 bit numbers, each representing a point on a grid. The
grid is define in a seporate way, outside of the format, but is given a
number of rows and columns. From these, an image is defined. I simply
need to take this stream, which I converted to a giant string, and
display it in the form of a picture. What I've tried to do is as
follows:

1. Read string
2. Form an array by combining 2 chars together.
3. Divide by 256 so as to have a 8 bit number, which PIL likes alot
better than a 16 bit number. The string is called data.
4. Use im = Image.fromstring('L', (xsize, ysize), data) to create image
5.Use
im.thumbnail((700,700))
image=ImageTk.BitmapImage(im)
pic=canvas.create_image(1,1,anchor="nw",image=image,tag="pic")
canvas.addtag_withtag("pic",pic)

There seems to be a problem with the last line, but no picture is
displayed without it. That isn't related to the problem I'm having, but
I also need to fix it. The problem is it won't display the image, it
seems to display nothing. Any ideas as to why? I've tried using
PhotoImage, with the same result. Perhaps it's the thumbnail command, I
don't know if it has problems if you try to make a thumbnail larger
than the picture, but I would presume there's a way around this. Ideas?
Thanks!

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


Help turning code into a module

2005-12-20 Thread dylpkls91
Hi all,

I am working on a little program for home automation under the X10
protocol. I have given up using a Palm device for input, so I have
resorted to using voice recognition, which I knew nothing about.
However, I found a nice little script on the internet that does exactly
what I need, and it recognizes phrases with pretty much 100% accuracy.
The script can be found here:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/93025

What I want to do is make this code into a module, so I can use it in
the future. For example:

import voicerecognition as vr
vr.StartRecognition(["one", "two", "three"])
result = vr.GetRecognized()
if result == "one":
 print "You said: one"
else:
 print "You did not say 'one'."

Any help would be appreciated. I have tried this, but IDLE keeps
freezing whenever I try to use the module with a test script.
Specifically, if anyone could actually turn this into a module for me,
I would be extremely grateful. Thank you!

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Paul Rubin
Kent Johnson <[EMAIL PROTECTED]> writes:
> You've lost me here. The server certainly would contain Karrigell
> code, it wouldn't function without it. I don't understand the analogy
> to GCC, the web site is not something that is compiled with
> Karrigell. Karrigell is a library or framework that is an essential
> part of the server. I don't know how I would write the app without
> Karrigell.

Let me ask it this way: suppose you used ASP instead.  As I understand
ASP, it's like PHP except it's proprietary.  Would ASP's license be a
problem?

Maybe you're using "the server" to encompass too much.  If I have an
Apache-based web site, then the web server is Apache.  If I have a
Python CGI script that the Apache server runs, the CGI script is not
"the server"--it's an application running under the server.  It would
not be affected by the GPL if Apache used the GPL.  Karrigell scripts
seem to me to work out about the same way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Kent Johnson
Paul Rubin wrote:
> Kent Johnson <[EMAIL PROTECTED]> writes:

>>>Remember that the GPL only applies to the code of Karrigell
>>>itself, not to stuff that you write using it.
>>
>>IANAL but that is not my understanding of the GPL. GPL version 2
>>section 2.b) reads, "You must cause any work that you distribute or
>>publish, that in whole or in part contains or is derived from the
>>Program or any part thereof, to be licensed as a whole at no charge to
>>all third parties under the terms of this License." My server would
>>certainly be a work that in part contains Karrigell.
> 
> 
> Your web app and html files would IMO be considered a separate work,
> like C programs that you compile with GCC.  If they don't contain actual
> Karrigell code and they're not derived from Karrigell code, then I'd
> think 2.b) doesn't apply.  The test I'd use is, imagine you don't have
> the Karrigell distro and you only have a printout of the documentation.
> Can you write your app from just the docs?  IANAL, etc., and to be
> safe, you could simply ask the Karrigell author.

You've lost me here. The server certainly would contain Karrigell code, it 
wouldn't 
function without it. I don't understand the analogy to GCC, the web site is not 
something 
that is compiled with Karrigell. Karrigell is a library or framework that is an 
essential 
part of the server. I don't know how I would write the app without Karrigell.

A FAQ entry attempts to shed light on the question but just confuses me more. 
"If the two 
programs remain well separated ... then you can treat them as two separate 
programs--but 
you have to do it properly. The issue is simply one of form." WTF?
http://www.gnu.org/licenses/gpl-faq.html#GPLInProprietarySystem

I confess, one reason I stay away from the GPL and even LGPL is because no 
matter how many 
times I read them I'm not sure what they really say. FAQs like the above 
certainly don't 
help much. In contrast the (BSD-style) CherryPy license is crystal clear.

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


Re: expect-like package

2005-12-20 Thread Stephen Thorne
On 21/12/05, Eric McCoy <[EMAIL PROTECTED]> wrote:
> So for HTTP, for example, I'd use something
> like this:
>
> send "HEAD / HTTP/1.0"
> send "Host: server.host.name"
> send ""
> expect ...
>   "^HTTP/1\.0 200.*" then return success
>   "^HTTP/1\.0 4\d\d.*" then return warning
>   else return error

Have a look at these:
  http://www.idyll.org/~t/www-tools/twill.html
  http://pbp.berlios.de/
  http://www.openqa.org/selenium/

--
Stephen Thorne
Development Engineer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: type 'slice' is not an acceptable base type

2005-12-20 Thread Michael Hoffman
Antoon Pardon wrote:

> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "vslice.py", line 48, in ?
> class iterslice(slice):
> TypeError: Error when calling the metaclass bases
> type 'slice' is not an acceptable base type

Searching for "not an acceptable base type" in the Python source reveals 
that this exception is produced when the proposed base type doesn't have 
Py_TPFLAGS_BASETYPE set.

> So what is going on. I thought the class vs type
> distinction was eliminated in order to be able
> to subclass base types. So why doesn't this work?

slice.__base__ == object. It's the basetype flag issue. You could 
propose a patch to make it subclassable.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Subclassing socket

2005-12-20 Thread groups . 20 . thebriguy
socket objects have a little quirk.  If you try to receive 0 bytes on a
blocking socket, they block.  That is, if I call recv(0), it blocks
(until some data arrives).

I think that's wrong, but I don't want to argue that.  I would like to
create a subclass of socket that fixes the problem.  Ideally, something
like:

class new_socket(socket):
def recv( self, bufsize, flags=0 ):
if bufsize == 0:
return ""
else:
return socket.recv( bufsize, flags )

They only problem is, sockets return socket objects via the accept
call.  And the socket returned is of type socket, of course, not
new_socket, as I would like.  I could override accept() to return a
new_socket, but I don't know how to convert the old socket to a new
socket.  That is, I'd like to add a method to the class above something
like:

def accept( self ):
conn, addr = socket.accept()

return ( conn, addr )

Does anyone have any suggestions on how to do the above?

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Mike Meyer
Paul Rubin  writes:
>> IANAL but that is not my understanding of the GPL. GPL version 2
>> section 2.b) reads, "You must cause any work that you distribute or
>> publish, that in whole or in part contains or is derived from the
>> Program or any part thereof, to be licensed as a whole at no charge to
>> all third parties under the terms of this License." My server would
>> certainly be a work that in part contains Karrigell.
> Your web app and html files would IMO be considered a separate work,
> like C programs that you compile with GCC.  If they don't contain actual
> Karrigell code and they're not derived from Karrigell code, then I'd
> think 2.b) doesn't apply.  The test I'd use is, imagine you don't have
> the Karrigell distro and you only have a printout of the documentation.
> Can you write your app from just the docs?  IANAL, etc., and to be
> safe, you could simply ask the Karrigell author.

That's one test. Another one is whether you can distribute your app as
one piece and let them get Karrigell from somewhere else to put things
together. If they can set up your app without copying parts of
Karrigel into it (and you didn't do that for them), then you're
ok. You can even bundle Karrigel into the distribution for them.

While them having to modify Karrigel extensively to work with your app
- for instance, if you distributed patch files - is within the letter
of the license, the FSF considers such a violation. IIRC, they gave
NeXT shit for doing this.

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


Re: type error on porting outfile.write

2005-12-20 Thread Eric McCoy
[EMAIL PROTECTED] wrote:
> I ported my code from the development to
> application platform, I found a "type error"
> on a fileout statement:

> outfile.write(object.id +",")

What is the type of object.id?  I'm guessing an integer.  The exception
should tell you, e.g.:

  TypeError: unsupported operand type(s) for +: 'int' and 'str'

If I'm right, you can do this:

  outfile.write("%d," % (object.id))

Though probably the better solution is to find out what code is
assigning an unexpected value to object.id.

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


Re: Changing a shell's current directory with python

2005-12-20 Thread Trent Mick
[Peter Hansen wrote]
> Andy B. wrote:
> > I've got a python utility that I want to change my shell's current
> > directory based on criteria it finds.  I've scoured google and the
> > python cookbook and can't seem to figure out if this is even possible.
> >  So far, all my attempts have changed the current python session only.
> >  Am I going to have to wrap this in a shell script?
> 
> As you've heard, you can't get there from here.  In fact, even just 
> wrapping with a shell script likely won't be enough, unless you are 
> willing to "source" the script every time you run it.  The only way I 
> know of (and I'd be happy to hear alternatives) to do this in a 
> _transparent_ manner is to combine an alias (which uses "source" for 
> you) with a wrapper script _and_ to have that wrapper script read from 
> some place (stdout or a temporary file or ?) to which the Python script 
> can communicate the desired new environment variables and/or current 
> directory.

I do basically this with a script I have (http://trentm.com/projects/go)
for doing exactly what Andy requested: changing directories.

On Un*x you setup a shell function (like an alias),
which calls the Python script go.py,
which writes a shell script that changes the directory,
which gets 'source'd by the shell function.

function go () 
{ 
go_is_on_path="`\which go`";
if test -e "$go_is_on_path"; then
export GO_SHELL_SCRIPT=$HOME/.__tmp_go.sh;
python `\which go` $*;
if [ -f $GO_SHELL_SCRIPT ]; then
source $GO_SHELL_SCRIPT;
fi;
else
echo "ERROR: could not find 'go' on your PATH";
fi
}

On Windows 'go' does the same thing with a batch file.

Trent

-- 
Trent Mick
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE (was: PythonWin troubleshooting)

2005-12-20 Thread Trent Mick
[chuck wrote]
> What is Komodo written in?

Komodo is based on the Mozilla framework, so in many ways it is similar
to Firefox and Thunderbird. Komodo also includes PyXPCOM -- Python
bindings to Mozilla's XPCOM (cross-platform component object model)
system for componentizing parts of the framework -- so that we can
develop core Komodo logic in Python. As with any Mozilla-based app, the
UI is written in XUL (XML-based UI Language) and JavaScript. Where it
makes sense Komodo includes bits written in Perl and Tcl (also have some
PHP extension C code): for code browsing and debugging. So, Komodo is
written in: XML, JavaScript, C++, Python, CSS, C, Perl, and Tcl.

Cheers,
Trent

-- 
Trent Mick
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Paul Rubin
Kent Johnson <[EMAIL PROTECTED]> writes:
> I did make some changes to CherryPy. I wouldn't mind sharing those
> changes back with the CherryPy community. But the product was the
> server itself, not the web site. As I understand the GPL the server
> software would be a "work based on the [GPL-licensed] Program" and
> thus subject to the GPL itself.

Yes, correct.
> I'm not sure what you mean by "simply developing content". I was
> developing a web application, not a web site serving static HTML.

Yes, that is content.

> The bulk of the development work was writing Python code that worked
> with CherryPy.

And also with the Python interpreter.  If the Python interpreter were
GPL'd, would that have been an issue?

> > Remember that the GPL only applies to the code of Karrigell
> > itself, not to stuff that you write using it.
> 
> IANAL but that is not my understanding of the GPL. GPL version 2
> section 2.b) reads, "You must cause any work that you distribute or
> publish, that in whole or in part contains or is derived from the
> Program or any part thereof, to be licensed as a whole at no charge to
> all third parties under the terms of this License." My server would
> certainly be a work that in part contains Karrigell.

Your web app and html files would IMO be considered a separate work,
like C programs that you compile with GCC.  If they don't contain actual
Karrigell code and they're not derived from Karrigell code, then I'd
think 2.b) doesn't apply.  The test I'd use is, imagine you don't have
the Karrigell distro and you only have a printout of the documentation.
Can you write your app from just the docs?  IANAL, etc., and to be
safe, you could simply ask the Karrigell author.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Kent Johnson
Paul Rubin wrote:
> Kent Johnson <[EMAIL PROTECTED]> writes:
> 
>>I chose CherryPy in part because its license allows this. I
>>would have considered Karrigell if it had a different license.
> 
> 
> Have you had to modify CherryPy in some substantive way that you
> needed to keep proprietary, 

I did make some changes to CherryPy. I wouldn't mind sharing those changes back 
with the 
CherryPy community. But the product was the server itself, not the web site. As 
I 
understand the GPL the server software would be a "work based on the 
[GPL-licensed] 
Program" and thus subject to the GPL itself.

 > as opposed to simply developing content
 > that CherryPy serves but is completely independent of CherryPy's
 > license?

I'm not sure what you mean by "simply developing content". I was developing a 
web 
application, not a web site serving static HTML. The bulk of the development 
work was 
writing Python code that worked with CherryPy.

> 
> I notice that a heck of a lot of commercial users are using completely
> proprietary packages like ASP, whose licenses are far more restrictive
> than the GPL.  They don't seem to think it's a problem.  So for most
> such users, Karrigell shouldn't be a problem either.  

Building a website using Karrigell is not a problem because the work is not 
distributed. 
Distributing a webserver based on Karrigell as a product would require the 
server to be 
GPL licensed.

> Remember that
> the GPL only applies to the code of Karrigell itself, not to stuff
> that you write using it.

IANAL but that is not my understanding of the GPL. GPL version 2 section 2.b) 
reads, "You 
must cause any work that you distribute or publish, that in whole or in part 
contains or 
is derived from the Program or any part thereof, to be licensed as a whole at 
no charge to 
all third parties under the terms of this License." My server would certainly 
be a work 
that in part contains Karrigell.

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


Re: modify a long-running python script while it is running?

2005-12-20 Thread Kevin Yuan
2005/12/20, Peter Hansen <[EMAIL PROTECTED]>:
Kevin Yuan wrote:> I have a silly question: Can  *VERY*  large script cause memory overflow> if python load all the entire script file into memory?If you have a script that is literally larger than memory, then what
else would happen but an overflow error of some kind?What's the point of the question, really?  You don't plan to load ascript that is larger than, say, 100K, do you?  Maybe if you candescribe your real concern we can help better.
-PeterOkay.. Maybe I didn't describe my question clearly. Sorry to confuse you.I just want to make sure that python loads the ENTIRE source file into mem before runs it.I think there will be problems when the source file is VERY large(may be it's silly to think so)

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

Re: When Python *Eggs* better than Python *distutils*?? What's Eggs?

2005-12-20 Thread Paul Boddie
Xavier Morel wrote:
> If you ever used a debian-based linux system, think of Eggs as a
> Python-specific apt-get.
>
> The most advanced kind of language-specific installer atm is the Ruby
> Gems packaging and distribution system (http://docs.rubygems.org/), go
> check it for more insight of what Eggs wants to be (and I hope it'll
> evolve to be as good as gems) (and the install software should be named
> eggs or hatch, not easy_install, ugly).

Could anyone enlighten me/us as to why the Smart Package Manager [1]
(written in Python, presented at EuroPython this year) isn't being more
closely investigated as part of a suitable solution?

Paul

[1] http://smartpm.org/

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Paul Rubin
Kent Johnson <[EMAIL PROTECTED]> writes:
> I chose CherryPy in part because its license allows this. I
> would have considered Karrigell if it had a different license.

Have you had to modify CherryPy in some substantive way that you
needed to keep proprietary, as opposed to simply developing content
that CherryPy serves but is completely independent of CherryPy's
license?  

I notice that a heck of a lot of commercial users are using completely
proprietary packages like ASP, whose licenses are far more restrictive
than the GPL.  They don't seem to think it's a problem.  So for most
such users, Karrigell shouldn't be a problem either.  Remember that
the GPL only applies to the code of Karrigell itself, not to stuff
that you write using it.
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Kent Johnson
Luis M. Gonzalez wrote:
> I don't think Pierre (Karrigell's creator) is awared of licenses and
> legal issues.
> Perhaps you can tell us what's the problem with GPL and, if possible,
> propose an alternative...

OK I'll try. First let me say I have no interest in a licensing flame war, 
there are valid 
reasons why an author might prefer one license over another and certainly there 
are good 
reasons to choose GPL. However the work I do is commercial and proprietary and 
I doubt I 
could get approval to release it under GPL. So I am restricted to projects with 
more 
liberal licenses such as MIT, BSD and Apache licenses. These allow 
closed-source 
distribution of products based on them.

Certainly it is within an author's rights to prohibit use of his code in closed 
source 
products, as the author of Karrigell has done by choosing GPL and I respect 
this decision. 
Unfortunately this makes it impossible for me to consider using Karrigell in my 
work. I 
recently needed a stand-alone web server for a small in-house project that 
might possibly 
be distributed to business partners or become a product some day. I chose 
CherryPy in part 
because its license allows this. I would have considered Karrigell if it had a 
different 
license.

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


Re: Wed Development - Dynamically Generated News Index

2005-12-20 Thread infidel02
Thank Steve this worked!

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


pyUnit and dynamic test functions

2005-12-20 Thread Sakcee
Hi

I am trying to use pyUnit to create a framework for testing functions

I am reading function name, expected output,  from a text file.
and in python generating dynamic test functions
something like this


class getUsStatesTest( unittest.TestCase ):

self.setUp =  lambda  : function_call
self.testReturnVal =  lambda  : self.assertEqual( fileInput,
function_returnedVals )
self.testLength=  lambda  : self.assertEqual( len(returnedVals)
, len(inp) )



is it possible to load these dynamic functions via pyUnit, instead of
defining in text form ,
can i use loadfromname etc to load these dynamic test functions.

something like this

unittest.TestSuite(unittest.defaultTestLoader.loadTestsFromName(
getUsStatesTest() ))

in this way I can completely automate every function that returns some
output by dynamically generating its
test functions

thanks

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


Python on Nintendo DS

2005-12-20 Thread [EMAIL PROTECTED]
Hi,

I tried porting Python to the Nintendo DS, and it was surprisingly
easy.  Installing something called devkitPro, devkitARM, libNDS, msys,
msys-DTK and then just using that to cross compile a python
installation.

Heres a screenshot of it running in the Dualis emulator.  It runs
flawlessly for what has been compiled into it:
http://img520.imageshack.us/img520/2145/python240cj.jpg

You can download the source code to link against the static library and
add a method of input (which you can see in the picture).  Also
included is a .nds file for running on your Nintendo DS:
http://files.filefront.com/NDSPythonStuffzip/;4497277;;/fileinfo.html

You click on keys on the touch screen to enter input.  Notes: The
clicking on keys in the emulator is extremely non-responsive, on the
DS, it is perfect.  Also, the emulators do not handle displaying the
right bits and pieces to the right screen, so the keyboard is displayed
on the top screen and the console on the touch screen (so its kind of
hard to use as you can't see the regions on the touch screen to click
on).  The .nds file can be recompiled to use the lcd screens right for
emulators, but the .nds file was compiled to work correctly on a DS.

A problem..  On Dualis, the interpreter works perfectly.  However, on
the Nintendo DS, it is completely unreliable and seems to corrupt at
random points.  Occasionally you can get to the command line and enter
one command or two, but its guaranteed to corrupt at some point.  I
have no idea why this is.  I have to assume that Dualis implements the
processor and hardware specs more flexibly than they actually are on
the DS.  And that there is some way the compilation options or linking
options can be modified to restrict the output to what the DS can
actually run.

If anyone has the time and interest to give it a shot at getting it
working, you will need a Nintendo DS with some form of homebrewing
hardware which lets you put storage mediums into the DS with custom
media.. like compiled .nds files.  I use a Supercard, the compact flash
version.

As for the installation of tools required to compile .nds files, I used
the following page:
http://www.double.co.nz/nintendo_ds/nds_develop1.html
Then I went to the mingw sourceforge page and got msys-dtk and
installed that so that I would have autoconf and automake.
Then I extracted Python2.4 source code and opened a dos console, cd to
the directory with the Python source code and type the following:

set BASECFLAGS=-mcpu=arm9tdmi -mtune=arm946e-s -ffast-math -mthumb
-mthumb-interwork -DARM9
set CFLAGS=-mcpu=arm9tdmi -mtune=arm946e-s -ffast-math -mthumb
-mthumb-interwork -DARM9
set LDFLAGS=-specs=ds_arm9.specs -g -mthumb -mthumb-interwork
-Wl,-Map,libpython2.4.map
sh configure --host=arm-elf

This should give you a makefile, now you need to edit it.  Change AR to
have a value of arm-elf-ar (configure doesn't pick that up properly).
Also, where there are references to OBJECT_OBJS, you need to also enter
NDS_OBJS to get included along with it.  And enter the following in the
makefile somewhere, maybe after OBJECT_OBJS

NDS_OBJS = RISCOS/Python/getcwd_riscos.o

Also, go into Modules and edit Setup.  Comment out all four of the
modules still listed uncommented in the same block, posix, errno, ...
Now in the top level python source code directory, type make.
It should make and then error claiming it can't link against some
function to do with ThreadState, locate all calls of that function in
Python/pystate.c and comment them out -- this is a bug in the Python
2.4.2 source distribution that pops up when threads are disabled.  Now
it should compile the static library and error on the python.exe (which
is of no use to us).

You should now be able to compile the contents of NDSPythonStuff.zip
against that library (you'll need to make cosmetic changes to the
Makefile of course).

Anyway, if anyone can help with working out how to change the
compilation or linking options to get the code to work properly on the
DS, please email me.

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


Re: putenv

2005-12-20 Thread Tom Anderson
On Tue, 20 Dec 2005, Steve Holden wrote:

> Mike Meyer wrote:
>> Terry Hancock <[EMAIL PROTECTED]> writes:
>> 
>>> On Tue, 20 Dec 2005 05:35:48 -
>>> Grant Edwards <[EMAIL PROTECTED]> wrote:
>>> 
 On 2005-12-20, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
 wrote:
 
> I have csh script that calls a bunch of python programs and I'd like 
> to use env variables as kind of a global variable that I can pass 
> around to the pythong scripts.
 
 You can't change the environment of the parent process.
>>> 
>>> There is an evil trick, however:
>>> 
>>> Instead of setting the environment directly, have the python program 
>>> return csh code to alter the environment the way you want, then call 
>>> the python code by "sourcing" its output:
>>> 
>>> source `my_script.py`
>> 
>> Does this actually work? It looks to me like you need two levels:
>> my_script.py creates a file, then outputs the name of the file, as the
>> csh source command reads commands from the file named as an argument.
>> 
>> To be able to output the commands directly, you'd need to use the eval
>> command, not the source command.
>
> I suspect the trick that Terry was thinking of was eval, not source. You are 
> correct in saying he'd need to create a file to source.

True. The downside of eval is that it doesn't (well, in bash, anyway) 
handle line breaks properly (for some value of 'properly') - it seems to 
treat them as linear whitespace, not line ends. I was about to suggest:

source <(my_script.py)

As a way to use source to run the script's output, but that seems not to 
work. I think <() might be a bashism anyway.

tom

-- 
Hit to death in the future head
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getopt and options with multiple arguments

2005-12-20 Thread Tom Anderson
On Mon, 19 Dec 2005, [EMAIL PROTECTED] wrote:

> I want to be able to do something like:
>
> myscript.py * -o outputfile
>
> and then have the shell expand the * as usual, perhaps to hundreds of 
> filenames. But as far as I can see, getopt can only get one argument 
> with each option. In the above case, there isn't even an option string 
> before the *, but even if there was, I don't know how to get getopt to 
> give me all the expanded filenames in an option.

I'm really surprised that getopt doesn't handle this properly by default 
(so getopt.getopt mimics unices with crappy getopts - since when was that 
a feature?), but as Steven pointed out, getopt.gnu_getopt will float your 
boat.

I have an irrational superstitious fear of getopt, so this is what i use 
(it returns a list of arguments, followed by a dict mapping flags to 
values; it only handles long options, but uses a single dash for them, as 
is, for some reason, the tradition in java, where i grew up):

def arguments(argv, expand=True):
argv = list(argv)
args = []
flags = {}
while (len(argv) > 0):
arg = argv.pop(0)
if (arg == "--"):
args.extend(argv)
break
elif (expand and arg.startswith("@")):
if (len(arg) > 1):
arg = arg[1:]
else:
arg = argv.pop(0)
argv[0:0] = list(stripped(file(arg)))
elif (arg.startswith("-") and (len(arg) > 1)):
arg = arg[1:]
if (":" in arg):
key, value = arg.split(":")
else:
key = arg
value = ""
flags[key] = value
else:
args.append(arg)
return args, flags

def stripped(f):
"""Return an iterator over the strings in the iterable f in which
strings are stripped of #-delimited comments and leading and
trailing whitespace, and blank strings are skipped.

"""
for line in f:
if ("#" in line): line = line[:line.index("#")]
line = line.strip()
if (line == ""): continue
yield line
raise StopIteration

As a bonus, you can say @foo or @ foo to mean "insert the lines contained 
in file foo in the command line here", which is handy if, say, you have a 
file containing a list of files to be processed, and you want to invoke a 
script to process them, or if you want to put some standard flags in a 
file and pull them in on the command line. Yes, you could use xargs for 
this, but this is a bit easier. If you don't want this, delete the elif 
block mentioning the @, and the stripped function. A slightly neater 
implementation not involving list.pop also then becomes possible.

tom

-- 
Hit to death in the future head
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove duplicated elements in a list?

2005-12-20 Thread Tom Anderson
On Mon, 19 Dec 2005, Brian van den Broek wrote:

> [EMAIL PROTECTED] said unto the world upon 2005-12-19 02:27:
>> Steve Holden wrote:
>> 
>>> Kevin Yuan wrote:
>>> 
 How to remove duplicated elements in a list? eg.
 [1,2,3,1,2,3,1,2,1,2,1,3] -> [1,2,3]?
 Thanks!!
>>> 
>>>  >>> list(set([1,2,3,1,2,3,1,2,1,2,1,3]))
>>> [1, 2, 3]
>> 
>> Would this have the chance of changing the order ? Don't know if he
>> wants to maintain the order or don't care though.
>
> For that worry:
>
 orig_list = [3,1,2,3,1,2,3,1,2,1,2,1,3]
 new_list = list(set(orig_list))
 new_list.sort(cmp= lambda x,y: cmp(orig_list.index(x), 
> orig_list.index(y)))
 new_list
> [3, 1, 2]


Ah, that gives me an idea:

>>> import operator
>>> orig_list = [3,1,2,3,1,2,3,1,2,1,2,1,3]
>>> new_list = map(operator.itemgetter(1),
... filter(lambda (i, x): i == orig_list.index(x),
... enumerate(orig_list)))
>>> new_list
[3, 1, 2]

This is a sort of decorate-fondle-undecorate, where the fondling is 
filtering on whether this is the first occurrance of the the value. This 
is, IMHO, a clearer expression of the original intent - "how can i remove 
such-and-such elements from a list" is begging for filter(), i'd say.

My code is O(N**2), a bit better than your O(N**2 log N), but we can get 
down to O(N f(N)), where f(N) is the complexity of set.__in__ and set.add, 
using a lookaside set sort of gizmo:

>>> orig_list = [3,1,2,3,1,2,3,1,2,1,2,1,3]
>>> seen = set()
>>> def unseen(x):
... if (x in seen):
... return False
... else:
... seen.add(x)
... return True
...
>>> new_list = filter(unseen, orig_list)
>>> new_list
[3, 1, 2]

Slightly tidier like this, i'd say:

>>> orig_list = [3,1,2,3,1,2,3,1,2,1,2,1,3]
>>> class seeingset(set):
... def see(self, x):
... if (x in self):
... return False
... else:
... self.add(x)
... return True
...
>>> new_list = filter(seeingset().see, orig_list)
>>> new_list
[3, 1, 2]


tom

-- 
Hit to death in the future head
-- 
http://mail.python.org/mailman/listinfo/python-list


putting checkbuttons in a listbox

2005-12-20 Thread valen1260
I'd like to have a multicolumn listbox, with one column being a list of 
items and the other being a list of checkbuttons.  The user could check 
his "favorites" and then shorten the list to show only the checked items.

I have implemented the MultiListbox at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52266 .  I then 
tried attaching the checkbuttons to a listbox object.  To get them to 
display, I had to pack them, but in packing them, they just disregard 
the scrollable listbox and take as much room as needed.

Has anyone implemented anything like this?  Is there a way to put 
checkbuttons in a fixed-height, scrollable listbox or similar structure?
-- 
http://mail.python.org/mailman/listinfo/python-list


type error on porting outfile.write

2005-12-20 Thread pmiller
I ported my code from the development to
application platform, I found a "type error"
on a fileout statement:

outfile.write(object.id +",")

Object.id is provided by a library routine
that is installed on both machines.

How do I fix this ?

Thanks,
Phil Miller

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


Re: Wingide is a beautiful application

2005-12-20 Thread [EMAIL PROTECTED]
Tony Nelson wrote:
> > 1. Python syntax checking: as I'm typing along, if I input a syntax
> > error then the line is immediately highlighted in red.
>
> What do you use to do this?  Cream doesn't seem to do this oob.

Nope.  I'll try to package up my vimrc and get it uploaded somewhere
next week (busy with holiday stuff).  The meat of it is:

import vim
def cur_x():
return vim.current.window.cursor[1]
def cur_y():
return vim.current.window.cursor[0]
def find_current_block():
block = [vim.current.line]
current = cur_y()-1
while len(block[0])==0 or block[0][0] in " \t#":
current = current - 1
if current < 0:
break
block = [vim.current.buffer[current] ]+ block
return block
def check_current_block():
import code
vim.command("syn clear Error")
block = find_current_block()
length = len(block)
try:
code.compile_command("\n".join(block))
print ""
return 0
except:
(type, value, tb) = sys.exc_info()
line_no = cur_y()-1+value.lineno-length
badline = vim.current.buffer[line_no]
badline = badline.replace('"', '\\"')
print "Error at line %d: " %(line_no+1), badline
return 1

> > 2. Normal tag-jump stuff: Ctrl-click on a function/method call (or
> > class or whatever) will jump to the function/method/class definition
> > (Ctrl-T works as well if you don't like clicking).  It keeps a stack of
> > visited files so you can drill down through your call stack and then
> > pop back up to where you came from.
>
> Do you set up ctags for this?  I get error messages "E433: No tags file"
> and "E426: tag not found: xxx" when I Ctrl-click on a method call.

Umm, either click the "build tags in current directory" button on the
toolbar, or "find . -name '*.py' | ctags -L -" in the top directory of
your python file.

> > 3. Python class browsing stuff: A Class menu shows the parent and child
> > classes of the one you're currently in, and all the methods of the
> > current class; selecting any of the above jumps to the appropriate file
> > and line.
>
> Is this the Tag List?

No, this is more complex, I'll post it w/ the rest of my stuff.

> > 4. Interactive documentation stuff: When I type an open-paren, it looks
[SNIP]
> This stuff doesn't happen either.  How is it set up?

Likewise, I'll post.

> > 5. A client menu selects which client I want to work in (so, say, I get
> > a bug report for Client A, I select them from the menu).  The Class
> > menu and other functions respect this (if I'm in the generic Company
> > class, the Class menu will list Client A's Company subclass before the
> > subclasses of other companies; if I jump to the Company definition,
> > it'll go to Company A's client-specific version).  It also restarts
> > development httpd servers on the current machine running with conf
> > files appropriate to that client.
>  ...
>
> Where is this "client menu"?  How is it set up?

It's a listing of all the clients we work with.  It's a more
project-specific thing, but illustrates that you can easily integrate
vim into whatever your development system looks like (indeed, when I
get a python error in a page on my dev server then it opens the file
where the exception occurred in my vim and jumps to the line, setting
up the stack appropriately).

That stuff I can't post.

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


New Python ISAPI extension for IIS (PyISAPIe)

2005-12-20 Thread Phillip Sitbon
Hey everybody,

I just released v0.1.1 of my Python ISAPI extension, which is currently
in its beta stages. I'd love to have some of you look at it and see if
it works well for you. It's very slimmed-down, and definitely simple
compared to the more popular option(s), but my hope is that there is a
big performance win. Eventually, I'd like to have a few more tools for
it in order to expand its capabilities. In the meantime, see if it
works well for you, and don't hesitate to ask questions since the
documentation is not thorough (although it should be enough to get you
started).

I'm not going to report any of the benchmarks I have done yet since
they aren't rigorous enough... but I will say that this extension has
proven to be extremely fast for me. I hope you have the same
experience.

http://prdownloads.sourceforge.net/pyisapie/PyISAPIe-v0.1.1.zip?download

Thanks,

  Phillip

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


Re: Parsing text

2005-12-20 Thread Bengt Richter
On 20 Dec 2005 08:06:39 -0800, "sicvic" <[EMAIL PROTECTED]> wrote:

>Not homework...not even in school (do any universities even teach
>classes using python?). Just not a programmer. Anyways I should
>probably be more clear about what I'm trying to do.
Ok, not homework.

>
>Since I cant show the actual output file lets say I had an output file
>that looked like this:
>
>a b Person: Jimmy
>Current Location: Denver
>Next Location: Chicago
>--
>a b Person: Sarah
>Current Location: San Diego
>Next Location: Miami
>Next Location: New York
>--
>
>Now I want to put (and all recurrences of "Person: Jimmy")
>
>Person: Jimmy
>Current Location: Denver
>Next Location: Chicago
>
>in a file called jimmy.txt
>
>and the same for Sarah in sarah.txt
>
>The code I currently have looks something like this:
>
>import re
>import sys
>
>person_jimmy = open('jimmy.txt', 'w') #creates jimmy.txt
>person_sarah = open('sarah.txt', 'w') #creates sarah.txt
>
>f = open(sys.argv[1]) #opens output file
>#loop that goes through all lines and parses specified text
>for line in f.readlines():
>if  re.search(r'Person: Jimmy', line):
>   person_jimmy.write(line)
>elif re.search(r'Person: Sarah', line):
>   person_sarah.write(line)
>
>#closes all files
>
>person_jimmy.close()
>person_sarah.close()
>f.close()
>
>However this only would produces output files that look like this:
>
>jimmy.txt:
>
>a b Person: Jimmy
>
>sarah.txt:
>
>a b Person: Sarah
>
>My question is what else do I need to add (such as an embedded loop
>where the if statements are?) so the files look like this
>
>a b Person: Jimmy
>Current Location: Denver
>Next Location: Chicago
>
>and
>
>a b Person: Sarah
>Current Location: San Diego
>Next Location: Miami
>Next Location: New York
>
>
>Basically I need to add statements that after finding that line copy
>all the lines following it and stopping when it sees
>'--'
>
>Any help is greatly appreciated.
>
Ok, I generalized on your theme of extracting file chunks to named files,
where the beginning line has the file name. I made '.txt' hardcoded extension.
I provided a way to direct the output to a (I guess not necessarily sub) 
directory
Not tested beyond what you see. Tweak to suit.

< extractfilesegs.py 
>
"""
Usage: [python] extractfilesegs [source [outdir [startpat [endpat
where source is -tf for test file, a file name, or an open file
  outdir is a directory prefix that will be joined to output file names
  startpat is a regular expression with group 1 giving the extracted 
file name
  endpat is a regular expression whose match line is excluded and ends 
the segment
"""
import re, os

def extractFileSegs(linesrc, outdir='extracteddata', start=r'Person:\s+(\w+)', 
stop='-'*30):
rxstart = re.compile(start)
rxstop = re.compile(stop)
if isinstance(linesrc, basestring): linesrc = open(linesrc)
lineit = iter(linesrc)
files = []
for line in lineit:
match = rxstart.search(line)
if not match: continue
name = match.group(1)
filename = name.lower() + '.txt'
filename = os.path.join(outdir, filename)
#print 'opening file %r'%filename
files.append(filename)
fout = open(filename, 'a') # append in case repeats?
fout.write(match.group(0)+'\n') # did you want aaa bbb stuff?
for data_line in lineit:
if rxstop.search(data_line):
#print 'closing file %r'%filename
fout.close() # don't write line with ending mark
fout = None
break
else:
fout.write(data_line)
if fout:
fout.close()
print 'file %r ended with source file EOF, not stop mark'%filename
return files

def get_testfile():
from StringIO import StringIO
return StringIO("""\
...irrelevant leading
stuff ...
a b Person: Jimmy
Current Location: Denver
Next Location: Chicago
--
a b Person: Sarah
Current Location: San Diego
Next Location: Miami
Next Location: New York
--
irrelevant
trailing stuff ...

with a blank line
""")

if __name__ == '__main__':
import sys
args = sys.argv[1:]
if not args: raise SystemExit(__doc__)
tf = args.pop(0)
if tf=='-tf': fin = get_testfile()
else: fin = tf
if not args:
files = extractFileSegs(fin)
elif len(args)==1:
files = extractFileSegs(fin, args[0])
elif len(args)==2:
files = extractFileSegs(fin, args[0], args[1], '^$') # stop on blank 
line?
else:
files = extractFileSegs(fin, args[0], '|'.join(args[1:-1]), args[-1])
print '\nFiles created:'
for fname in files:

type error on porting outfile.write

2005-12-20 Thread pmiller
I ported my code from the development to
application platform, I found a "type error"
on a fileout statement:

outfile.write(object.id +",")

Object.id is provided by a library routine
that is installed on both machines.

How do I fix this ?

Thanks,
Phil Miller

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


Re: When Python *Eggs* better than Python *distutils*?? What's Eggs?

2005-12-20 Thread Colin J. Williams
Xavier Morel wrote:
> [EMAIL PROTECTED] wrote:
> 
>> So basically Python Eggs precompiles and compresses
>> binaries for you so you just have to load it to run
>> your app?
>>
> 
> Nah, Eggs is a packaging system, what you don't have to do is 
> compile/configure, because the packaging does that for you. It also 
> handles things like pre-required packages (the packages that this 
> package uses), even though that doesn't always work atm.
> 
> If you ever used a debian-based linux system, think of Eggs as a 
> Python-specific apt-get.
> 
> The most advanced kind of language-specific installer atm is the Ruby 
> Gems packaging and distribution system (http://docs.rubygems.org/), go 
> check it for more insight of what Eggs wants to be (and I hope it'll 
> evolve to be as good as gems) (and the install software should be named 
> eggs or hatch, not easy_install, ugly).
Currently, most packages are installed into the site-packages directory.

Does Eggs facilitate this?

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


Re: Raw images

2005-12-20 Thread Paul Rubin
"Tuvas" <[EMAIL PROTECTED]> writes:
> I have an image that is in a "raw" format, 

Do you mean a RAW file from a digital camera?  Those files have
complex and sometimes secret formats.  Google "dcraw.c" for a decoding
program that works for many cameras.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Michael Tobis
Clearly the Ruby/Rails folks are making an effort to place themselves
as an easy-to-learn first language for people who might otherwise drift
into the rather awkward template-first way of thinking that is PHP.

I note that the Rails people are closely affiliated with the 37signals
people who in turn are closely linked with some advertising
professionals.

Python people don't really think that way. As a community we really
seem to inherit the open source dysfunction of trying harder to impress
each other than to reach out to the rest of the world. The problem is
that this makes for amazing brilliance that is more or less invisible
to most of the world.

This leaves me believing that the commercial future is probably
brighter for Ruby vs Python. This won't affect the fact that Python is
probably still going to prevail in the scientific community, since
scientists aren't all that susceptible to promotion. That being the
case I don't think I myself will jump ship.

Since I am casting my lot with Python rather than Ruby, I think we
should take the friendly rivalry seriously rather than just shrugging
it off. Python MUST attract some of the most promising novice
programmers, and I believe that was part of its original design.

As a consequence Python MUST settle on a strong web framework that
includes the best of the existing frameworks, and polish it for maximum
accessibility as well as power.

Just on the basis of momentum rather than any strong technical argument
(which I am not well-qualified to make) I suggest we consider settling
on Django and doing what we can to improve it and its documentation.

mt

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


Re: tkinter canvas tag stuff

2005-12-20 Thread Tuvas
It's funny, I can put in more variables than needed, it doesn't even
call the function, and yet, magically, the picture appears. Odd... Just
wish I could solve the problem...

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


Re: reading files

2005-12-20 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Mike Meyer wrote:

> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> The text you read is still hanging around, waiting for you to use it. Once
>> you are done with it, you might want to reclaim that memory used,
>> especially if it is a 100MB text file:
>>
>> mytext = ""  # re-bind the name 'mytext' to the empty string
> 
> If you have no further use for the variable, then "del mytext" will
> also free up the memory, and make it clear to the reader that you're
> done with the memory.

It makes clear you're done with the *name* since that's what ``del``
deletes from the namespace, not the object.  I know that you know this but
many people seem to think ``del`` get's rid of the object like a call to
`free()` in C.

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


Re: parsing engineering symbols

2005-12-20 Thread Fredrik Lundh
Suresh Jeevanandam wrote:

> I want to convert a string to float value. The string contains
> engineering symbols.
>
> For example,
>
> s = '12k'
>
> I want some function which would return 12000
> function(s)
> => 12000.0
> I searched the web, but could not find any function.

how about:

SI_prefixes = {
'Y':24, 'Z':21, 'E':18, 'P':15, 'T':12, 'G':9, 'M':6, 'k':3,
'h':2, 'd':-1, 'c':-2, 'm':-3, u'\xb5':-6, 'u':-6, 'n':-9, 'p':-12,
'f':-15, 'a':-18, 'z':-21, 'y':-24
}

def myfloat(str):
try:
exp = SI_prefixes[str[-1]]
return float(str[:-1]) * 10**exp
except KeyError:
return float(str)

?





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


Re: Raw images

2005-12-20 Thread Tuvas
Well, the numbers are in a string of variable length. My camera can
read specific parts of it's display, so an image of 1024x1024 is just
as likely to happen as one of 16x342. Well, not really, but they both
could happen. The data is passed by giving the dimentions via a
seperate protocol, and then passing the numbers. I've converted the
passed numbers to a list of integers. Each is a 16 bit number, BTW. I
just needed to display that in a fixed size box, and the answer that
was giving using PIL will work perfectly.

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


Re: parsing engineering symbols

2005-12-20 Thread Erik Max Francis
Suresh Jeevanandam wrote:

>   I want to convert a string to float value. The string contains 
> engineering symbols.
>   For example,
>   
>   s = '12k'
> 
>   I want some function which would return 12000
>   function(s)
>   => 12000.0
>   I searched the web, but could not find any function.

There's some extensive code in the SI class in BOTEC which does this:

http://www.alcyone.com/software/botec/

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Chance favors the trained mind.
   -- Louis Pasteur
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wed Development - Dynamically Generated News Index

2005-12-20 Thread infidel02
Hi Jean-Paul,

The truth of the matter is that I was hoping that this could be
accomplished using pure CGI.

I am considering wether I need to learn these new frameworks, but I am
in somewhat of a hurry.

Also I have this problem with this simple test script that I have
written.  It pulls the infromation from the database correctly, but is
printing out the html tags in the browser, not sure what is wrong:

Script

#!/usr/bin/python

# import MySQL module
import MySQLdb, cgi

# connect
db = MySQLdb.connect(host="localhost", user="nancy",
passwd="intentions",
db="ardDB")

# create a cursor
cursor = db.cursor()

# execute SQL statement
cursor.execute("SELECT * FROM news where storyDATE < '2005-10-1';")

# get the resultset as a tuple
result = cursor.fetchall()

db.close()

print """ Content-Type: text/html\n\n
  
  

  DB Test

  

  

  """

# iterate through resultset
for record in result:

print """%s

 %s

 %s

   """ %(record[1],record[2],record[3])




print   """

  

  

  """


Results:



  

  DB Test

  

  


Heading 4

 Body 4

 2005-09-01


Heading 5

 Body 5

 2005-09-10


Heading 6

 Body 6

 2005-09-12




  
  
  

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


Re: pythonic equivalent of upvar?

2005-12-20 Thread Steven D'Aprano
On Tue, 20 Dec 2005 14:56:25 +, Richie Hindle wrote:

> 
> [David]
>> I'm trying to write something with the same brevity 
>> as perl's one-liner
>> 
>> eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
> 
> import sys, re
> for arg in sys.argv[1:]:
> if re.match(r'\w+=.*', arg):
> exec arg
> else:
> break

That piece of code is quite dangerous, since it is calling exec on an
arbitrary string supplied by a user.



-- 
Steven.

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


Re: checking if a string contains a number

2005-12-20 Thread Steven D'Aprano
On Tue, 20 Dec 2005 15:55:37 +0100, egbert wrote:

> On Tue, Dec 20, 2005 at 07:16:46PM +0530, Suresh Jeevanandam wrote:
>>  s1 = '12e3'
>>  s2 = 'junk'
>>  Is there any other function which would return True for s1 and False 
>> for s2.
>> 
> 
> isinstance(12e3, (int, float))

That won't work, because s1 is a *string*, not a float. The original
poster is asking how to check whether the string can be converted to a
float successfully before actually trying to convert it to a float.


-- 
Steven.

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


Re: Wed Development - Dynamically Generated News Index

2005-12-20 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Hi Jean-Paul,
> 
> The truth of the matter is that I was hoping that this could be
> accomplished using pure CGI.
> 
> I am considering wether I need to learn these new frameworks, but I am
> in somewhat of a hurry.
> 
> Also I have this problem with this simple test script that I have
> written.  It pulls the infromation from the database correctly, but is
> printing out the html tags in the browser, not sure what is wrong:
> 
> Script
> 
> #!/usr/bin/python
> 
> # import MySQL module
> import MySQLdb, cgi
> 
> # connect
> db = MySQLdb.connect(host="localhost", user="nancy",
> passwd="intentions",
> db="ardDB")
> 
> # create a cursor
> cursor = db.cursor()
> 
> # execute SQL statement
> cursor.execute("SELECT * FROM news where storyDATE < '2005-10-1';")
> 
> # get the resultset as a tuple
> result = cursor.fetchall()
> 
> db.close()
> 
> print """ Content-Type: text/html\n\n

Your problem is that space before the HTTP header. Get rid of that and 
you'll probably find that the browser recognises your output as HTML. Try

print """Content-Type: text/html\r\n\r\n ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Raw images

2005-12-20 Thread Bryan Olson
Tuvas wrote:
 > I have an image that is in a "raw" format, ei, no place markers to tell
 > the dimensions, just a big group of numbers.

The adjective "raw", apt as it may be, is a long way from specifying
the representation of an image. *Every* digital format is "just a big
group of numbers".

 > I happen to know the
 > dimension of this array from a different source. I would like to be
 > able to display it. Is there a way to do this easily? I know that
 > several libraries use a "raw" function, but I have little doubt that
 > this differs somewhat from program to program.

Well, maybe it's easy. Perhaps a straightforward interpretation of the
numbers, along with the dimensions you know, will yield the image. It
might be harder. For an arguably-overstated exposition, see:

 http://luminous-landscape.com/essays/raw-law.shtml


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


Re: How simputer COULD HAVE succeeded ?

2005-12-20 Thread mike . klaas

> PS. before investing time in Python, I wanted to find out if it
> can interface low-level, by eg. calling the OS or C...etc.
> eg. could it call linux's "dd if=.." ?

In python you have full access to the shell, and excellent
interoperability with c.

-Mike

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


Re: When Python *Eggs* better than Python *distutils*?? What's Eggs?

2005-12-20 Thread Xavier Morel
[EMAIL PROTECTED] wrote:
> So basically Python Eggs precompiles and compresses
> binaries for you so you just have to load it to run
> your app?
> 

Nah, Eggs is a packaging system, what you don't have to do is 
compile/configure, because the packaging does that for you. It also 
handles things like pre-required packages (the packages that this 
package uses), even though that doesn't always work atm.

If you ever used a debian-based linux system, think of Eggs as a 
Python-specific apt-get.

The most advanced kind of language-specific installer atm is the Ruby 
Gems packaging and distribution system (http://docs.rubygems.org/), go 
check it for more insight of what Eggs wants to be (and I hope it'll 
evolve to be as good as gems) (and the install software should be named 
eggs or hatch, not easy_install, ugly).
-- 
http://mail.python.org/mailman/listinfo/python-list


expect-like package

2005-12-20 Thread Eric McCoy
I'm looking for a way to create simple scripts which should be
accessible to a technical, though non-programmer, person.  These scripts
are basically network service checks so I don't need much power: "send
this line," "if this line matches, keep going," and "if this line
matches, quit immediately."  So for HTTP, for example, I'd use something
like this:

send "HEAD / HTTP/1.0"
send "Host: server.host.name"
send ""
expect ...
  "^HTTP/1\.0 200.*" then return success
  "^HTTP/1\.0 4\d\d.*" then return warning
  else return error

It would also be nice if a more complex version could be written to
handle redirects by grepping out the new target and then attempting to
fetch that URI, but that's not a requirement.

I looked at expect and a pure-Python reimplementation of same, but they
both want to spawn external processes.  Since I will be running more
than 10 checks a second that would be bad.  I also need to be able to
implement a hard timeout, so if any check takes longer than, for
example, 5 seconds, it automatically fails.  A log of the transaction
would also be good so that we can quickly find out why checks are
failing.  And another reason not to do this in Python is that I want
checks to be configurable on the fly and stored in a database.  I know
Python can do that but I want them sandboxed so that an error in a
user-built script won't take down the entire application.

I can roll my own but that would be a PITA so I'd prefer to use an
existing package if one exists.  Anyone know of any?  Thanks!

P.S. I will try to monitor the group but email replies would be appreciated.

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


Re: Wed Development - Dynamically Generated News Index

2005-12-20 Thread infidel02
Hi Jean-Paul,

The truth of the matter is that I was hoping that this could be
accomplished using pure CGI.

I am considering wether I need to learn these new frameworks, but I am
in somewhat of a hurry.

Also I have this problem with this simple test script that I have
written.  It pulls the infromation from the database correctly, but is
printing out the html tags in the browser, not sure what is wrong:

Script

#!/usr/bin/python

# import MySQL module
import MySQLdb, cgi

# connect
db = MySQLdb.connect(host="localhost", user="nancy",
passwd="intentions",
db="ardDB")

# create a cursor
cursor = db.cursor()

# execute SQL statement
cursor.execute("SELECT * FROM news where storyDATE < '2005-10-1';")

# get the resultset as a tuple
result = cursor.fetchall()

db.close()

print """ Content-Type: text/html\n\n
  
  

  DB Test

  

  

  """

# iterate through resultset
for record in result:

print """%s

 %s

 %s

   """ %(record[1],record[2],record[3])




print   """

  

  

  """


Results:



  

  DB Test

  

  


Heading 4

 Body 4

 2005-09-01


Heading 5

 Body 5

 2005-09-10


Heading 6

 Body 6

 2005-09-12




  
  
  

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


Re: checking if a string contains a number

2005-12-20 Thread Steven D'Aprano
On Tue, 20 Dec 2005 19:16:46 +0530, Suresh Jeevanandam wrote:

> Hi,
>   I have a string like,
>   s1 = '12e3'
>   s2 = 'junk'
> 
>   Now before converting these values to float, I want to check if they 
> are valid numbers.

Just try converting them:

float_list = []
for s in string_list:
try:
float_list.append(float(s))
except ValueError:
# ignore bad strings
pass
do_something_with_floats(float_list)


>   s1.isdigit returns False.

"2" is a digit. "23" is two digits. You want something like s1.isfloat(),
but why bother checking first? Just Do It.

>   Is there any other function which would return True for s1 and False
> for s2.

>From an interactive interpreter, call dir(s1). That will give you a list
of string methods. Then call help(s1.method) to learn what that method
does.


-- 
Steven.

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


Re: When Python *Eggs* better than Python *distutils*?? What's Eggs?

2005-12-20 Thread Ben Finney
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> I have been using distuils for a while and was wondering when Python
> Eggs (new project) is better?

Python Eggs, and the 'setuptools' package, are still new, so they're
not yet a core part of Python.

"The primary benefits of Python Eggs are:

* They enable tools like the "Easy Install" Python package manager
  (NEW!)

* They are a "zero installation" format for a Python package; no
  build or install step is required, just put them on PYTHONPATH
  or sys.path and use them

* They can include package metadata, such as the other eggs they
  depend on

* They allow "namespace packages" (packages that just contain
  other packages) to be split into separate distributions
  (e.g. zope.*, twisted.*, peak.* packages can be distributed as
  separate eggs, unlike normal packages which must always be
  placed under the same parent directory. This allows what are now
  huge monolithic packages to be distributed as separate
  components.)

* They allow applications or libraries to specify the needed
  version of a library, so that you can
  e.g. require("Twisted-Internet>=2.0") before doing an import
  twisted.internet.

* They're a great format for distributing extensions or plugins to
  extensible applications and frameworks (such as Trac, which uses
  eggs for plugins as of 0.9b1), because the egg runtime provides
  simple APIs to locate eggs and find their advertised entry
  points (similar to Eclipse's "extension point" concept).

There are also other benefits that may come from having a
standardized format, similar to the benefits of Java's "jar"
format."

http://peak.telecommunity.com/DevCenter/PythonEggs>

-- 
 \"There was a point to this story, but it has temporarily |
  `\ escaped the chronicler's mind."  -- Douglas Adams |
_o__)  |
Ben Finney 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Paul Rubin
"Luis M. Gonzalez" <[EMAIL PROTECTED]> writes:
> Perhaps you can tell us what's the problem with GPL and, if possible,
> propose an alternative...

See:
http://www.gnu.org/philosophy/pragmatic.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Raw images

2005-12-20 Thread Tuvas
That will definatly help. Thanks!

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


Re: "class Server" has a big error: what is?

2005-12-20 Thread LocaWapp

Steven D'Aprano ha scritto:

> On Sat, 17 Dec 2005 12:38:00 -0800, LocaWapp wrote:
>
> > "class Server" has a big error: what is?
> >
> > http://groups.google.it/group/comp.lang.python/browse_thread/thread/de458cb7675ff4b6/f333453b0dc1aab6?q=locawapp&rnum=1#f333453b0dc1aab6
>
>
> Is this a game of Twenty Questions? We guess what the error is, and you
> tell us if we are getting colder or hotter?
>
> You might find a little bit more interest in helping you if you post the
> traceback and the relevant bits of code.
>
>
> --
> Steven.

Hi Steven.
The big error (big for me) is inside the HTTP protocol (see the version
001 or follow the link on top, but you don't see the version 002
because it is fixed).

LocaWapp

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Luis M. Gonzalez
> From my point of view the biggest problem with Karrigell is that it is 
> released under the
> GPL. Most of my projects at least have the potential of being distributed to 
> customers  and
>GPL is not an option.

I don't think Pierre (Karrigell's creator) is awared of licenses and
legal issues.
Perhaps you can tell us what's the problem with GPL and, if possible,
propose an alternative...

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Luis M. Gonzalez
I don't think Pierre (Karrigell's creator) is awared of licenses and
legal issues.
Perhaps you can tell us what's the problem with GPL and, if possible,
propose an alternative...

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Benji York <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>> I disagree. Once you've picked a database (not trivial in itself, of 
>> course), you typically only have a few options for talking to in in 
>> Python.
>
>Perhaps it's off-topic for this thread, but I think "picking a database" 
>is the first mistake most people make.  It's a form of premature 
>optimization.

I just wanted to point out that I was responding to somebody who 
complained that the database interface situation on python was somewhat 
fragmented.

Also, when I was looking at web frameworks, I was doing so *precisely* 
to serve one or more databases of information (read only to the users, 
but occasionally loaded with more info as it became available). So it 
happened to be the first question I asked (at the same time as "and how 
do I talk to it?").

Anyway, you did warn that your message was possibly off-topic, so I 
guess I'm agreeing with you and perhaps being overly defensive. It was 
an interesting message.

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


Re: Raw images

2005-12-20 Thread Peter Hansen
Tuvas wrote:
> I have an image that is in a "raw" format, ei, no place markers to tell
> the dimensions, just a big group of numbers. I happen to know the
> dimension of this array from a different source. I would like to be
> able to display it. Is there a way to do this easily? I know that
> several libraries use a "raw" function, but I have little doubt that
> this differs somewhat from program to program. Thanks!

Assuming the numbers are stored as bytes in a file, this should work 
using PIL at http://www.pythonware.com/products/pil/

 >>> import Image
 >>> bytes = open('myfile', 'rb').read()
 >>> y = Image.fromstring('L', (xsize, ysize), x)
 >>> y.save('test.png', 'PNG')

The 'L' in the above is for bytes, and this obviously saves the image as 
a PNG file.  Lots of variation in the above is possible but your specs 
are fairly wide open so it's up to you to experiment and then maybe 
clarify your specs.

-Peter

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


Re: Parsing text

2005-12-20 Thread sicvic
Thank you everyone!!!

I got a lot more information then I expected. You guys got my brain
thinking in the right direction and starting to like programming.
You've got a great community here. Keep it up.

Thanks,
Victor

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


Re: Add to python path in Linux

2005-12-20 Thread John Goebel
On 20 Dec 2005 08:13:48 -0800, ninhenzo64 <[EMAIL PROTECTED]> wrote:

Hey,

> Hi,
>
> I am trying to use wxPython under Linux. Unfortunately, our system
> administrator has gone home for the holidays so I cannot get him to
> install the libraries properly. However, I have unpacked the libraries
> in my home directory, so if there was some way of adding this to the
> path that Python searches libraries for, I think I can get around this
> problem. Does anyone know a way of doing this? Basically I want to be
> able to run this command in python:
>
> >>> import wx
>
> The variable PYTHONPATH doesn't seem to exist. Well, this bash command
> returns nothing:
>
>  echo $PYTHONPATH
>
> Any ideas anyone?

There are many ways to do append paths so Python can find the package.

You can append the path within the code"

import sys
sys.path.append('/home/fooboy/wxpackage')

Use PYTHONPATH from bash:

export PYTHONHPATH=/home/fooboy/wxpackage
(you can run this just from the command-line or put in into your
$HOME/.bashrc (or $HOME/.bash_profile).

Use $HOME/.pythonrc

see: http://www.johnny-lin.com/cdat_tips/tips_pylang/custom.html

Hope this helps,
John

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


Re: ANNOUNCE; Try python beta

2005-12-20 Thread Mike Meyer
Richie Hindle <[EMAIL PROTECTED]> writes:
>> My assumption is that if splitting on '\n' leaves us with one
>> thing, we may have gotten a string that used \r for newlines
> Ah, OK.  Your comment talks about DOS - that won't happen on DOS (or
> Windows) which uses \r\n.  I don't know about the Mac.  But the \r\n pair
> isn't handled by your code - strip() on the server side will make it work if
> that's the problem:

You mean there's a difference between DOS and Windows?

The Mac stuff I can test, so that's easier to get right.

 eval("1+2\r".strip())
> 3

I actually did wind up doing it this way. MSIE works now, but still
doesn't seem very reliable.

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


Re: Queueing in Python (ala JMS)

2005-12-20 Thread James

Wolfgang Keller wrote:
> > Is there a JMS-like API available for Python?
>
> Better. >:-> Omninotify, a Corba notification service implementation.
>
> Sincerely,
>
> Wolfgang Keller

And it's ICE (a CORBA alternative with Python bindings) equivalent

IceStorm
A messaging service with support for federation. In contrast to most
other messaging or event services, IceStorm supports typed events,
meaning that broadcasting a message over a federation is as easy as
invoking a method on an interface.

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


Raw images

2005-12-20 Thread Tuvas
I have an image that is in a "raw" format, ei, no place markers to tell
the dimensions, just a big group of numbers. I happen to know the
dimension of this array from a different source. I would like to be
able to display it. Is there a way to do this easily? I know that
several libraries use a "raw" function, but I have little doubt that
this differs somewhat from program to program. Thanks!

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


Re: pythonic equivalent of upvar?

2005-12-20 Thread Mike Meyer
[EMAIL PROTECTED] (David MacKay) writes:
«
> 
>  I am writing a command-line reader for python.
>
>  I'm trying to write something with the same brevity 
> as perl's one-liner
>
> eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
>
> and with similar functionality.

Why? Do you like to make the security hole in your code hard to find?

> 
>  What is the pythonic way to embed a 20-line chunk of code into a function?
> I'd love to define these 20 lines as a module, and reuse the module over and 
> over.
> but this chunk of code needs to have access to 
> the local variables of main, whatever they are called. 

You can't do that. You don't want to do that, because it will cause
user typos to make your code break in strange and mysterious ways. Put
the variables in a dictionary, indexed by variable name.

Better yet, do what Peter suggests, and learn to use optparse.

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


When Python *Eggs* better than Python *distutils*?? What's Eggs?

2005-12-20 Thread [EMAIL PROTECTED]
I have been using distuils for a while and was wondering when
Python Eggs (new project) is better?

So basically Python Eggs precompiles and compresses
binaries for you so you just have to load it to run
your app?

Chris

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


Matthew Collins/Seminole is out of the office.

2005-12-20 Thread MCollins
I will be out of the office starting  12/20/2005 and will not return until
12/27/2005.

I'm out of the office and will return on Monday, the 22nd of March.  If you
have an emergency, please call 407.665.0311

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


Your message to ZDP awaits moderator approval

2005-12-20 Thread zdp-bounces
Your mail to 'ZDP' with the subject

hi, ive a new mail address

Is being held until the list moderator can review it for approval.

The reason it is being held:

Post by non-member to a members-only list

Either the message will get posted to the list, or you will receive
notification of the moderator's decision.  If you would like to cancel
this posting, please visit the following URL:


http://mail.zope.org/mailman/confirm/zdp/b285c9e2b9144e6c7d97399c7d34be95a8c4b44c

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


python-list@python.org

2005-12-20 Thread ivan.dm
Hi Body,
Can I set an image from file into DrawArea, so I can resize and drawing 
any object over its image?

any tips or idea?

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


Re: Weird memory consumption problem.

2005-12-20 Thread Stephen Kellett
In message <[EMAIL PROTECTED]>, Bo Peng <[EMAIL PROTECTED]> writes
>The problem is not that difficult to find, but it was 2am in the morning and
>I was misled by the different behavior of pyFun1 and pyFun2.

Don't know if you were using Windows, but if you were then Python Memory
Validator would have helped you identify that bug. Its in beta at the
moment if you want to try it.

http://www.softwareverify.com

Stephen
-- 
Stephen Kellett
Object Media Limitedhttp://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to lock a file in ftp site

2005-12-20 Thread Steve Holden
Ben Hutchings wrote:
> <[EMAIL PROTECTED]> wrote:
> 
>>hi all
>>
>>am trying to write some information into the file, which is located in
>>ftp, and this file can be updated by number of people, but if at all i
>>download a file from the ftp to my local machine, update it and then
>>upload it back to ftp, and at the same time if some one else downloads
>>the same file for the modification, then the data will be overwritten.
>>
>>so is there a way in Python script where i can lock the file, so that
>>no one updates it until i release the lock.
> 
> 
> A common means of cooperative file locking is to use the existence of
> a second file as a lock indicator.  I'm not sure that can be done over
> FTP, though, because I think when you write to such a file you can't
> tell whether it existed previously (which would mean someone else
> owned the lock).
> 
Well of course you could place a lock on the lock file before you tested 
for its presence by creating another file ...
> 
>>Or is there a way where i can directly update the file from the ftp
>>itself, i mean without downloading it to my local machine.
>>
>>Thanks in advance for the help
> 
> 
> You should probably switch from FTP to a version control system, such
> as CVS or Subversion.  They don't normally use locking, but they do
> detect conflicting changes and stop you from overwriting other
> people's changes.
> 
I'm not sure a version control system is right for the OP's needs, but 
clearly unadorned FTP isn't going to hack it either.

This being the Python, of course, it would be relatively simple to 
design a protocol that would provide the required functionality and then 
build clients and servers for that protocol. But we don't know whether 
that's an option yet.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: pythonic equivalent of upvar?

2005-12-20 Thread Bengt Richter
On Tue, 20 Dec 2005 16:10:30 +0200, [EMAIL PROTECTED] (David MacKay) wrote:

>Dear Greater Py,
>
>
> I am writing a command-line reader for python.
>
> I'm trying to write something with the same brevity 
>as perl's one-liner
>
>eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
>
>and with similar functionality.  I've decided I don't like 
>getopt, because it seems to require me to write pages and pages 
>of elif's as I add new arguments.  It slows me down, whereas the 
>perlism above liberates.
>
>My solution is a twenty-line python chunk equivalent to the perl one-liner. 
>(Twenty lines because, to process a (name, value) pair, I have to find the 
>current type of the variable "name" before setting "name" to 
>righttype("value").
>
>I'm happy with this 20-line chunk and wish to re-use it in many python 
>programs.
>
>
>
> What is the pythonic way to embed a 20-line chunk of code into a function?
>I'd love to define these 20 lines as a module, and reuse the module over and 
>over.
>but this chunk of code needs to have access to 
>the local variables of main, whatever they are called. 
>
> In tcl, IIRC, the command "upvar" allows one function to get access to its 
>parent function's local variables.
>
> Is there a pythonic way to tell a function "you are allowed to see all your 
>parent's variables?"  Or, to tell a chunk of code, "you are just a chunk of 
>code, not really a function"?
>
>
You can see them, but you can't rebind them without nasty hacks.
I would suggest just instantiating an object that initializes the way
you want to contain the values you pre-specify, and optionally get
overridden by command line info as you specify. E.g., a quick hack (not
tested beyond what you see ;-)

< clvalues.py >-
class CLValues(dict):
"""
A dict whose initialization values are overridden by
-name value pairs in the overrides list, by default taken from
command line args sys.argv[1:], but a list may be passed.
Existing values get overridden by cmd line values converted
to the same type. New values are assumed str type. Existing
values may be specified non-overridable by prefixing an underscore,
which is removed after cmd line args have been processed.
Since keys are valid names, access is also provided via attribute syntax.
"""
def __init__(self, overrides=None, *args, **kw):
dict.__init__(self, *args, **kw)
if overrides is None: overrides = __import__('sys').argv[1:]
while overrides:
name = overrides.pop(0)
if not name.startswith('-') or not name[1:]:
raise ValueError, "Names must be non-null and prefixed with 
'-', unlike %r" % name
name = name[1:]
if '_'+name in self or name.startswith('_') and name in self:
raise ValueError, "%r may not be overridden" % name
if not overrides: raise ValueError, 'No value following %r'% 
'-'+name
value = overrides.pop(0)
self[name] = type(self.get(name, ''))(value) # default str type if 
not pre-existing
for k,v in self.items():
if k.startswith('_'): # make plain names for non-overridables
self[k[1:]] = v
del self[k]
def __getattr__(self, name): return self[name] # provide key access as 
attributes

def test():
clv = CLValues(
   decode=0,
   verbose=0,
   bits=7,
   N = 1,
   file="blah",
   _securityLevel = 3)
for name, value in clv.items():
print '%15s: %r' %(name, value)
print 'N accessed as clv.N => %r' % clv.N

if __name__ == '__main__':
test()


Running it to run the test:

[ 9:54] C:\pywk\ut>py24 clvalues.py -bits 8 -file other\path\and\file
 decode: 0
  securityLevel: 3
verbose: 0
   file: 'other\\path\\and\\file'
   bits: 8
  N: 1
N accessed as clv.N => 1

[ 9:54] C:\pywk\ut>py24 clvalues.py -securityLevel 0
Traceback (most recent call last):
  File "clvalues.py", line 44, in ?
test()
  File "clvalues.py", line 38, in test
_securityLevel = 3)
  File "clvalues.py", line 21, in __init__
raise ValueError, "%r may not be overridden" % name
ValueError: 'securityLevel' may not be overridden

Quoting command line arg to make a single arg with embedded spaces:

[ 9:54] C:\pywk\ut>py24 clvalues.py -added "should be string"
 decode: 0
  securityLevel: 3
  added: 'should be string'
verbose: 0
   file: 'blah'
   bits: 7
  N: 1
N accessed as clv.N => 1


>Thanks very much
>
De nada.

>David
>
>PS -- example below illustrates the chunk of code, in case anyone is 
>interested.
>


Usage in a program would go something like
   from clvalues import CLValues
   clv = CLValues(
   # ... like test above
   )
   # ...
   # use v

Re: checking if a string contains a number

2005-12-20 Thread egbert
On Tue, Dec 20, 2005 at 07:16:46PM +0530, Suresh Jeevanandam wrote:
>   s1 = '12e3'
>   s2 = 'junk'
>   Is there any other function which would return True for s1 and False 
> for s2.
> 

isinstance(12e3, (int, float))
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

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


Re: Help with python_fold.vim

2005-12-20 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with:
> Found an earlier thread that answered my question:

Good for you.

I often want only one or two levels of indentation at maximum. This
ensures not all if/while/for etc. blocks are indented. Most of my
python files either contain classes (max indent 2) or only functions
(max indent 1). I make sure Vim uses the correct options by adding the
following line as the last line in the Python file:

# vim:foldnestmax=2

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Add to python path in Linux

2005-12-20 Thread Sybren Stuvel
ninhenzo64 enlightened us with:
> The variable PYTHONPATH doesn't seem to exist.

Yet it is the one you should use. It's got the same syntax as the
regular PATH variable.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to lock a file in ftp site

2005-12-20 Thread Ben Hutchings
<[EMAIL PROTECTED]> wrote:
> hi all
>
> am trying to write some information into the file, which is located in
> ftp, and this file can be updated by number of people, but if at all i
> download a file from the ftp to my local machine, update it and then
> upload it back to ftp, and at the same time if some one else downloads
> the same file for the modification, then the data will be overwritten.
>
> so is there a way in Python script where i can lock the file, so that
> no one updates it until i release the lock.

A common means of cooperative file locking is to use the existence of
a second file as a lock indicator.  I'm not sure that can be done over
FTP, though, because I think when you write to such a file you can't
tell whether it existed previously (which would mean someone else
owned the lock).

> Or is there a way where i can directly update the file from the ftp
> itself, i mean without downloading it to my local machine.
>
> Thanks in advance for the help

You should probably switch from FTP to a version control system, such
as CVS or Subversion.  They don't normally use locking, but they do
detect conflicting changes and stop you from overwriting other
people's changes.

-- 
Ben Hutchings
Every program is either trivial or else contains at least one bug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing text

2005-12-20 Thread Scott David Daniels
sicvic wrote:
> Not homework...not even in school (do any universities even teach
> classes using python?). 
Yup, at least 6, and 20 wouldn't surprise me.

> The code I currently have looks something like this:
> ...
> f = open(sys.argv[1]) #opens output file
> #loop that goes through all lines and parses specified text
> for line in f.readlines():
> if  re.search(r'Person: Jimmy', line):
>   person_jimmy.write(line)
> elif re.search(r'Person: Sarah', line):
>   person_sarah.write(line)
Using re here seems pretty excessive.
How about:
 ...
 f = open(sys.argv[1])  # opens input file ### get comments right
 source = iter(f)  # files serve lines at their own pace.  Let them
 for line in source:
 if line.endswith('Person: Jimmy\n'):
 dest = person_jimmy
 elif line.endswith('Person: Sarah\n'):
 dest = person_sarah
 else:
 continue
 while line != '---\n':
 dest.write(line)
 line = source.next()
 f.close()
 person_jimmy.close()
 person_sarah.close()

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


Re: putenv

2005-12-20 Thread Christophe
Mike Meyer a écrit :
> Terry Hancock <[EMAIL PROTECTED]> writes:
> 
>>On Tue, 20 Dec 2005 05:35:48 -
>>Grant Edwards <[EMAIL PROTECTED]> wrote:
>>
>>>On 2005-12-20, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>>>wrote:
>>>
I have csh script that calls a bunch of python programs
and I'd like to use env variables as kind of a global
variable that I can pass around to the pythong scripts.
>>>
>>>You can't change the environment of the parent process.
>>>
>>>IOW, the python programs can't change the environment of
>>>the calling csh script (or, by extenstion, the environment
>>>of subsequent python programs that are called by the csh
>>>script).
>>
>>There is an evil trick, however:
>>
>>Instead of setting the environment directly, have the python
>>program return csh code to alter the environment the way you
>>want, then call the python code by "sourcing" its output:
>>
>>source `my_script.py`
> 
> 
> Does this actually work? It looks to me like you need two levels:
> my_script.py creates a file, then outputs the name of the file, as the
> csh source command reads commands from the file named as an argument.

Should work, even in basic sh. IIRC, source means the shell should 
execute the data itself. I've always used it with an intermediate file 
but I wouldn't be surprised if there was a way to make it work with a 
command output.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python_fold.vim

2005-12-20 Thread stephen
Found an earlier thread that answered my question:

http://mail.python.org/pipermail/python-list/2005-July/289078.html

"""Then zo opens the fold under the cursor one level, zO opens
it recursively, zc and zC close it non- and recursively. zr opens all
folds one level, zR opens them all recursively, zm closes them all one
level, and zM closes them all recursively."""

Stephen

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


Eckel, ruby, python

2005-12-20 Thread gene tani
pretty sane article, i didn't see it linked/cited here
http://www.artima.com/weblogs/viewpost.jsp?thread=141312

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


Re: Parsing text

2005-12-20 Thread Gerard Flanagan
sicvic wrote:

> Since I cant show the actual output file lets say I had an output file
> that looked like this:
>
> a b Person: Jimmy
> Current Location: Denver

It may be the output of another process but it's the input file as far
as the parsing code is concerned.

The code below gives the following output, if that's any help ( just
adapting Noah's idea above).  Note that it deals with the input as a
single string rather than line by line.


Jimmy
Jimmy.txt

Current Location: Denver
Next Location: Chicago

Sarah
Sarah.txt

Current Location: San Diego
Next Location: Miami
Next Location: New York

>>>

data='''
a b Person: Jimmy
Current Location: Denver
Next Location: Chicago
--
a b Person: Sarah
Current Location: San Diego
Next Location: Miami
Next Location: New York
--
'''

import StringIO
import re


src = StringIO.StringIO(data)

for name in ['Jimmy', 'Sarah']:
exp = "(?s)Person: %s(.*?)--" % name
filename = "%s.txt" % name
info = re.findall(exp, src.getvalue())[0]
print name
print filename
print info



hth

Gerard

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


Re: Parsing text

2005-12-20 Thread rzed
"sicvic" <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> Not homework...not even in school (do any universities even
> teach classes using python?). Just not a programmer. Anyways I
> should probably be more clear about what I'm trying to do.
> 
> Since I cant show the actual output file lets say I had an
> output file that looked like this:
> 
> a b Person: Jimmy
> Current Location: Denver
> Next Location: Chicago
> --
> a b Person: Sarah
> Current Location: San Diego
> Next Location: Miami
> Next Location: New York
> --
> 
> Now I want to put (and all recurrences of "Person: Jimmy")
> 
> Person: Jimmy
> Current Location: Denver
> Next Location: Chicago
> 
> in a file called jimmy.txt
> 
> and the same for Sarah in sarah.txt
> 
> The code I currently have looks something like this:
> 
> import re
> import sys
> 
> person_jimmy = open('jimmy.txt', 'w') #creates jimmy.txt
> person_sarah = open('sarah.txt', 'w') #creates sarah.txt
> 
> f = open(sys.argv[1]) #opens output file
> #loop that goes through all lines and parses specified text
> for line in f.readlines():
> if  re.search(r'Person: Jimmy', line):
>  person_jimmy.write(line)
> elif re.search(r'Person: Sarah', line):
>  person_sarah.write(line)
> 
> #closes all files
> 
> person_jimmy.close()
> person_sarah.close()
> f.close()
> 
> However this only would produces output files that look like
> this: 
> 
> jimmy.txt:
> 
> a b Person: Jimmy
> 
> sarah.txt:
> 
> a b Person: Sarah
> 
> My question is what else do I need to add (such as an embedded
> loop where the if statements are?) so the files look like this
> 
> a b Person: Jimmy
> Current Location: Denver
> Next Location: Chicago
> 
> and
> 
> a b Person: Sarah
> Current Location: San Diego
> Next Location: Miami
> Next Location: New York
> 
> 
> Basically I need to add statements that after finding that line
> copy all the lines following it and stopping when it sees
> '--'
> 
> Any help is greatly appreciated.
> 

Something like this, maybe?

"""
This iterates through a file, with subloops to handle the 
special cases. I'm assuming that Jimmy and Sarah are not the
only people of interest. I'm also assuming (for no very good
reason) that you do want the separator lines, but do not want 
the "Person:" lines in the output file. It is easy enough to 
adjust those assumptions to taste.

Each "Person:" line will cause a file to be opened (if it is 
not already open, and will write the subsequent lines to it 
until the separator is found. Be aware that all files remain 
open unitl the loop at the end closes them all.
"""

outfs = {}
f = open('shouldBeDatabase.txt')
for line in f:
if line.find('Person:') >= 0:
ofkey = line[line.find('Person:')+7:].strip()
if not ofkey in outfs:
outfs[ofkey] = open('%s.txt' % ofkey, 'w')
outf = outfs[ofkey]
while line.find('-') < 0:
line = f.next()
outf.write('%s' % line)
f.close()
for k,v in outfs.items():
v.close()

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


Help with python_fold.vim

2005-12-20 Thread stephen
I see that the python_fold plugin for vim lets you fold
classes/functions, etc. Can someone tell me how to fold/unfold
sections? Thanks.

Stephen

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Kent Johnson
Luis M. Gonzalez wrote:
> The only problem with KARRIGELL, I guess, is that its creator is very
> humble and doesn't like to advertise his creature. He is not very fond
> of "marketing" ...

 From my point of view the biggest problem with Karrigell is that it is 
released under the 
GPL. Most of my projects at least have the potential of being distributed to 
customers and 
GPL is not an option.

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


Re: Disable 'windows key'

2005-12-20 Thread Richie Hindle

> But can it change "Fn" key mapping?

I don't think so, no.  There's no obvious user interface for that, anyway.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Disable 'windows key'

2005-12-20 Thread Dody Suria Wijaya
But can it change "Fn" key mapping?

Richie Hindle wrote:
> [Paul]
>> I wonder if there might be a way of disabling [the windows key] within
>> my program.
> 
> IHateThisKey will do this globally:
> 
>   http://www.bytegems.com/ihatethiskey.shtml
> 
> The free edition blocks the Windows key, and the paid one ($10) lets you
> control all kinds of keys in quite flexible ways.  You can still use the
> Windows key as a modifier (as in Windows+E for Explorer).
> 
> No affiliation other than as a happy customer.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Add to python path in Linux

2005-12-20 Thread ninhenzo64
Hi,

I am trying to use wxPython under Linux. Unfortunately, our system
administrator has gone home for the holidays so I cannot get him to
install the libraries properly. However, I have unpacked the libraries
in my home directory, so if there was some way of adding this to the
path that Python searches libraries for, I think I can get around this
problem. Does anyone know a way of doing this? Basically I want to be
able to run this command in python:

>>> import wx

The variable PYTHONPATH doesn't seem to exist. Well, this bash command
returns nothing:

 echo $PYTHONPATH

Any ideas anyone?

Cheers,

Henry

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


Re: Parsing text

2005-12-20 Thread sicvic
Not homework...not even in school (do any universities even teach
classes using python?). Just not a programmer. Anyways I should
probably be more clear about what I'm trying to do.

Since I cant show the actual output file lets say I had an output file
that looked like this:

a b Person: Jimmy
Current Location: Denver
Next Location: Chicago
--
a b Person: Sarah
Current Location: San Diego
Next Location: Miami
Next Location: New York
--

Now I want to put (and all recurrences of "Person: Jimmy")

Person: Jimmy
Current Location: Denver
Next Location: Chicago

in a file called jimmy.txt

and the same for Sarah in sarah.txt

The code I currently have looks something like this:

import re
import sys

person_jimmy = open('jimmy.txt', 'w') #creates jimmy.txt
person_sarah = open('sarah.txt', 'w') #creates sarah.txt

f = open(sys.argv[1]) #opens output file
#loop that goes through all lines and parses specified text
for line in f.readlines():
if  re.search(r'Person: Jimmy', line):
person_jimmy.write(line)
elif re.search(r'Person: Sarah', line):
person_sarah.write(line)

#closes all files

person_jimmy.close()
person_sarah.close()
f.close()

However this only would produces output files that look like this:

jimmy.txt:

a b Person: Jimmy

sarah.txt:

a b Person: Sarah

My question is what else do I need to add (such as an embedded loop
where the if statements are?) so the files look like this

a b Person: Jimmy
Current Location: Denver
Next Location: Chicago

and

a b Person: Sarah
Current Location: San Diego
Next Location: Miami
Next Location: New York


Basically I need to add statements that after finding that line copy
all the lines following it and stopping when it sees
'--'

Any help is greatly appreciated.

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


Re: How convert text file between locale encoding and UTF-8?

2005-12-20 Thread gene tani

[EMAIL PROTECTED] wrote:
> Dear Friends:
>
> Wondering that is there neat way to do "subject line" in Python? I am
> talking about Python 2.4 with Win32 extension installed. The locale can
> be any of ANSI defined, for example, zh_CN (CP936) or Korea (CP949)
> .
>
> I am not expert in Python, if you well note I will appreciate a lot.
>
> Rgds, David Xiao

1st google for "python convert UTF-8
http://evanjones.ca/python-utf8.html

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


Re: Existing FTP server code?

2005-12-20 Thread gene tani

Mateusz Soltysek wrote:
> [EMAIL PROTECTED] wrote:
> > Hi, I'm writing a program that needs to upload files to a server
> > (probably using FTP), that also needs to be secured and be able to
> > setup username/password programmatically.
> >
> > I wonder if there are already well written base code I can work on.
> >
> > The reason I choose FTP is because it is well known/supported and I
> > don't need to write much code at all. Any better ideas?
> >
> >
> > Thank you
>
> Hi,
>
> Use paramiko SSH2 protocol module (http://www.lag.net/paramiko/)
>
> Regards

or flip thru twisted book
http://www.oreilly.com/catalog/twistedadn/toc.html

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Steve Holden
Mike Meyer wrote:
> "Paul Boddie" <[EMAIL PROTECTED]> writes:
> 
>>Paul Rubin wrote:
>>
>>>It's been a long-time source of puzzlement to me why so many web sites
>>>are so slow, and RDBMS overhead is an obvious candidate.  So the rant
>>>seems appropriate even in the case of web apps where clients can cause
>>>db updates.
>>
>>Indeed. Large portions of a lot of Web sites could actually be deployed
>>statically, rather than hitting a database several times a page to
>>retrieve stuff which changes once in a blue moon. Moreover, static page
>>hosting is generally a lot cheaper than dynamic program hosting.
> 
> 
> And with the proper technology, you can get the best of both
> worlds. You build the site as dynamically genrated, then "compile" it
> to get the static pages you actually serve. That way you get all the
> benefits you listed of serving static pages, plus the ability to use a
> database and all it's associated tools for maintaining your data (if
> you consider that an advantage, anyway).
> 
That's an approach I'm currently experimenting with - the content of 
www.holdenweb.org is mostly static but generated from a database, and 
the current tasks include completing a wxPython database maintenance 
GUI, incorporating various ways to generate scripted content that 
matches the look and feel of the rest of the site and adding more and 
more ways to generate the interior content.

It's obvious by comparison with www.holdenweb.com that there's a good 
deal of design commonality.

I'll be looking for beta testers eventually ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: allow_none=True in SimpleXMLRPCServer

2005-12-20 Thread Daniel Crespo
Hi Dody!

It works perfect! Now, I want the SimpleXMLRPCServer.py not to be on
the same directory, but in my /lib directory. I tried it, but it seems
that the module loads from python24/ first. How can I change this?

Thank you!

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


Re: putenv

2005-12-20 Thread Steve Holden
Mike Meyer wrote:
> Terry Hancock <[EMAIL PROTECTED]> writes:
> 
>>On Tue, 20 Dec 2005 05:35:48 -
>>Grant Edwards <[EMAIL PROTECTED]> wrote:
>>
>>>On 2005-12-20, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>>>wrote:
>>>
I have csh script that calls a bunch of python programs
and I'd like to use env variables as kind of a global
variable that I can pass around to the pythong scripts.
>>>
>>>You can't change the environment of the parent process.
>>>
>>>IOW, the python programs can't change the environment of
>>>the calling csh script (or, by extenstion, the environment
>>>of subsequent python programs that are called by the csh
>>>script).
>>
>>There is an evil trick, however:
>>
>>Instead of setting the environment directly, have the python
>>program return csh code to alter the environment the way you
>>want, then call the python code by "sourcing" its output:
>>
>>source `my_script.py`
> 
> 
> Does this actually work? It looks to me like you need two levels:
> my_script.py creates a file, then outputs the name of the file, as the
> csh source command reads commands from the file named as an argument.
> 
> To be able to output the commands directly, you'd need to use the eval
> command, not the source command.
> 
> 
>>It's ugly, but it does work -- I have had to use this
>>before in a production environment.  Well, it's not really
>>any less advisable than scripting in csh to begin with. ;-)
> 
> 
> Doesn't matter what you're scripting in - you'll have to do some such
> circumlocution to set the parent scripts environment variables.
> 

I suspect the trick that Terry was thinking of was eval, not source. You 
are correct in saying he'd need to create a file to source.

When I run

 ssh-agent

I see:

SSH_AUTH_SOCK=/tmp/ssh-J0r9XFySTm/agent.5500; export SSH_AUTH_SOCK;
SSH_AGENT_PID=5796; export SSH_AGENT_PID;
echo Agent pid 5796;

The process number varies each time. If I run

 eval `ssh-agent`

I see:

Agent pid 4364

(this is Cygwin, hence the funky process numbers). Now, of course, I can 
see the variables in the current shell's environment:

[EMAIL PROTECTED] /tmp
$ echo $SSH_AUTH_SOCK $SSH_AGENT_PID
/tmp/ssh-W6LEPi8wC0/agent.4152 4364

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: parsing engineering symbols

2005-12-20 Thread gene tani

Suresh Jeevanandam wrote:
> Hi,
>   I want to convert a string to float value. The string contains
> engineering symbols.
>   For example,
>
>   s = '12k'
>
>   I want some function which would return 12000
>   function(s)
>   => 12000.0
>   I searched the web, but could not find any function.
>
> regards,
> Suresh

port this
http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Numeric/Bytes.html

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


Re: parsing engineering symbols

2005-12-20 Thread Bengt Richter
On Tue, 20 Dec 2005 19:07:02 +0530, Suresh Jeevanandam <[EMAIL PROTECTED]> 
wrote:

>Hi,
>   I want to convert a string to float value. The string contains 
>engineering symbols.
>   For example,
>   
>   s = '12k'
>
>   I want some function which would return 12000
>   function(s)
>   => 12000.0
>   I searched the web, but could not find any function.
>
It should be easy enough, if you can define precisely what
"contains engineering symbols" means ;-)

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


Re: Do you recommend a good artificial intelligence book?

2005-12-20 Thread Bengt Richter
On 20 Dec 2005 04:27:29 -0800, Paul Rubin  wrote:

>"Tolga" <[EMAIL PROTECTED]> writes:
>> Is there anybody here interested in artificial intelligence (AI)? Yes,
>> perhaps this thread would be more suitable for an AI usenet group and I
>> have also posted my question there, but I want to know Python
>> community's opinion. Could you recommend me please a good AI book to
>> start with? I don't want to see Lisp code, if possible ;-D
>
>The classic is Winston and Horn's, which uses Lisp.  You can think of
>it as Python with more parentheses if you want.  There's an old book
>by Nilsson which is more theoretical.

Have a look at:

http://aima.cs.berkeley.edu/

It's really nicely done.

Note links on above page:

"""
Online Code Repository

* Pseudo-code from the book in pdf or ps.
* Online code in Lisp, Python, Java etc.
* Data for the online code
* Online demos (Java applets and Javascript) 
"""

from the python link (http://aima.cs.berkeley.edu/python/readme.html)

"""
AIMA Python Code
This file gives an overview of the Python code for the
algorithms in the textbook AI: A Modern Approach. The code
is Copyright (c) 2002 by Peter Norvig and is offered free
of charge for your use. As you may know, the textbook presents
algorithms in pseudo-code format; as a supplement we provide
this Python code as well as Lisp code. The intent is to implement
all the algorithms in both languages, so that you can choose whichever
language you prefer. As yet neither implementation is complete,
but the Lisp version is closer.
"""

BTW, Peter Norvig is co-author ;-)

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


  1   2   >