Re: up to date books?

2005-08-18 Thread Alessandro Bottoni
John Salerno wrote:

> hi all. are there any recommendations for an intro book to python that
> is up-to-date for the latest version?

I do not know how much up-to-date they are but I have to suggest you these
books:

- Learning Python
By Mark Lutz and David Ascher
published by O'Reilly
Most likely the best introductory book on Python

- Python Cookbook
By Alex Martelli and David Ascher
published by O'Reilly
By far the most useful book on Python after your first week of real use of
this language

Also, the fundamental
- Programming Python (the 2nd edition ONLY)
By Mark Lutz
published by O'Reilly
Is very useful for understanding the most inner details of Python

> would reading a book from a year or two ago cause me to miss much?

No. Python did not changed too much since rel. 1.5. You can still use a book
published in 2001 as a introductory book (as I do). The changes are
exhaustively described both in the official documentation and in the very
fine "what's new in..." articles written by Andrew Kuchlin for every new
release (see www.python.org).

CU

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


Re: win32pipe.popen3

2005-08-18 Thread Adriaan Renting
Well, on Linux I use select first to see if there's something to read. Maybe 
this works on Windows too?

This is my code: 
fd = os.open(filename, os.O_NONBLOCK)
ready = select.select([fd], [], [], 0.25) ## timeout after 
0.25 seconds.
if fd in ready[0]:
text  = os.read(fd, 1024)
lines = text.split('\n')
for line in lines:
print line
else:
print '-'
os.close(fd)

You can maybe use select.poll too.
 
>>>"Jakob Simon-Gaarde" <[EMAIL PROTECTED]> 08/17/05 7:51 pm >>> 
Follow-up on a thread from 1999 (see below) 
 
Well now it is 2005 and the operating system I'm using is Windows 
Server 2003, and I can still see that the same problem persists with: 
 
win32pipe.popen2() 
win32pipe.popen3() 
win32pipe.popen4() 
 
while win32pipe.popen() does almost what you want. 
 
>>>import win32pipe 
>>>win32pipe.popen('cmd') 
 
>>>r=win32pipe.popen('cmd') 
>>>r.readline() 
'Microsoft Windows XP [Version 5.1.2600]\n' 
>>>r.readline() 
'(C) Copyright 1985-2001 Microsoft Corp.\n' 
>>>r.readline() 
'\n' 
>>>r.readline() 
'C:\\backup\\TRPython241\\trpython>' 
 
Although I think the last readline ought to return None since no 
carriage return has been issued yet, it is better than popen2,popen3 
and popen4, which all just block the parent process. 
 
The current behaviour of win32pipe.popen2(), win32pipe.popen3() and 
win32pipe.popen4() would be acceptable for me if I knew a way to test 
if there was something ready for reading, but I can't see how to do 
that test, therfore I don't know when to stop reading from output :( Is 
there a solution for this, can I poll/test for ready-read on popen3 I/O 
objects. 
 
Best regards 
Jakob Simon-Gaarde 
 
 
--- 
>From a thread in 1999 
High Arpard, 
 
thanx for help but I got probs with that popen3 under Win95: 
'o.readlines()' doesn't return anymore. To find out I checked 
it line per line: 
 
Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam 
>>>import win32pipe 
>>>i,o,e=win32pipe.popen3('ver', 'b') 
>>>o.readline() 
'\015\012' 
>>>o.readline() 
 
'Windows 95. [Version 4.00.]\015\012' 
 
>>>o.readline() 
'\015\012' 
>>>o.readline() 
 
Don't know why, but it never;-) returns. 
Perhaps it may be a bug in win32pipe, that it doesn't return 
becourse readline couldn't find CarriageReturn/EOF? 
 
I took win32pipe.popen('ver','r') for a better solution. 
That works fine. 
 
greetings, 
Holger 
 
-- 
http://mail.python.org/mailman/listinfo/python-list 

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


Re: Library vs Framework (was Dr. Dobb's Python-URL!)

2005-08-18 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Kay Schluehr <[EMAIL PROTECTED]> wrote:
.
.
.
>What are frameworks really good for - a very true success story.
>
>A colleague of mine used to spread all kinds of flags ( state- and
>property markers ) over the code that were used to glue everything
>together until I raised my tyranny of frameworks. It was a hard
>struggle for an OO warrier and took me almost a year or so to become
>the undebated projects architect/dictator who trashed all kind of
>misguided "freedom" ( i.e. bad code ): "What the fuck is this?" "I
>worked almost a week on it!" "It has to be reworked." "No, you don't do
>it!" I did it. Who claims that social life is easy? What is nice about
>this kind of cruelness is not only my colleague became finally happy
>and hopefully learned at least a little bit about programming but also
>our customers were gratefull about stable code, thight release
>schedules and just-in-time requirement dispatch. Now we have some
>bread-and-butter maintenance contract and true freedom to experiment
>with other more interesting things besides this. But the struggle just
>starts again with the new project ;)
.
.
.
Kay, please say that over again (I recognize you've heard that
from me before).  Are you saying that your colleague misapplied
your chosen framework by programming too much OUTside the frame-
work, and the global flags were a symptom of that?  So is your
conclusion that framework use takes non-trivial education?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: up to date books?

2005-08-18 Thread Adriaan Renting
I learned Python from the "Learning Python" book that's first on Alessandros 
list. If you have the Second Edition, that includes coverage for Python 2.3, I 
think you have quite a nice introductory book.
As a reference book "Python in a Nutshell" and of course the Python 
documentation itself are quite good.

Adriaan
 
 
>>>Alessandro Bottoni <[EMAIL PROTECTED]> 08/18/05 9:02 am >>> 
John Salerno wrote: 
 
>hi all. are there any recommendations for an intro book to python that 
>is up-to-date for the latest version? 
 
I do not know how much up-to-date they are but I have to suggest you these 
books: 
 
- Learning Python 
By Mark Lutz and David Ascher 
published by O'Reilly 
Most likely the best introductory book on Python 
 
- Python Cookbook 
By Alex Martelli and David Ascher 
published by O'Reilly 
By far the most useful book on Python after your first week of real use of 
this language 
 
Also, the fundamental 
- Programming Python (the 2nd edition ONLY) 
By Mark Lutz 
published by O'Reilly 
Is very useful for understanding the most inner details of Python 
 
>would reading a book from a year or two ago cause me to miss much? 
 
No. Python did not changed too much since rel. 1.5. You can still use a book 
published in 2001 as a introductory book (as I do). The changes are 
exhaustively described both in the official documentation and in the very 
fine "what's new in..." articles written by Andrew Kuchlin for every new 
release (see www.python.org). 
 
CU 
 
--- 
Alessandro Bottoni 
-- 
http://mail.python.org/mailman/listinfo/python-list 

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


Re: Bug in slice type

2005-08-18 Thread Michael Hudson
[EMAIL PROTECTED] writes:

> Michael Hudson wrote:
>> Bryan Olson writes:
>> In some sense; it certainly does what I intended it to do.
>
> [...]
>> I'm not going to change the behaviour.  The docs probably aren't
>> especially clear, though.
>
> The docs and the behavior contradict:
>
> [...] these are the /start/ and /stop/ indices and the
> /step/ or stride length of the slice [emphasis added].
>
>
> I'm fine with your favored behavior. What do we do next to get
> the doc fixed?

I guess one of us comes up with some less misleading words.  It's not
totally obvious to me what to do, seeing as the returned values *are*
indices is a sense, just not the sense in which they are used in
Python.  Any ideas?

Cheers,
mwh

-- 
  First of all, email me your AOL password as a security measure. You
  may find that won't be able to connect to the 'net for a while. This
  is normal. The next thing to do is turn your computer upside down
  and shake it to reboot it. -- Darren Tucker, asr
-- 
http://mail.python.org/mailman/listinfo/python-list


An observer pattern application.

2005-08-18 Thread Paolino
Lately I was needing to use multiple inheritance to split behaviour of a 
class and modularize it.
But the problem raises when the need is to add operations to a method 
already present in one of them from another.
I think the technical solution is the use of 'super'.
Then I tried to write a decorator for automatize the 'super' call,but I 
failed.

Next solution is implementing the observer pattern on methods call.
I'm pretty sure there are bugs and ideas to be corrected in the next 
code,any help and comment appreciated.

Regards Paolino



''' A module collecting classes for known patterns

 '''

import types

class Observer(dict):
   ''' A class defining some decorators for function/methods to 
chain/link them when called .To do:implement pre event execution hooking'''

   def __call__(self,observed,args,kwargs):
 for reaction in self.get(observed,()):
   reaction(*args,**kwargs)

   def emit(self,method,observed=None):
 ''' A decorator for functions to signal their calling.Post hook 
cablated'''
 def wrapper(*args,**kwargs):
   if  observed:
 if type(observed) is types.MethodType:
   event=observed.im_func
 else:
   event=observed
   else:
 event=wrapper
   result=method(*args,**kwargs)
   self(wrapper,args,kwargs)
   return result
 return  wrapper

   def emitOther(self,observed):
 ''' A decorator facility to let the function/method emit another 
event (not itself)'''
 def wrapEmit(method):
   return self.emit(method,observed)
 return wrapEmit

   def reactOn(self,*observeds):
 ''' a decorator to set the function/method as a reaction to 
*observeds event.
 Remember to use __ name mangling when working on methods to be 
able to use
 same reaction name on multiple class inheritances'''
 def reaction(method):
   for observed in observeds:
 if type(observed) is types.MethodType:
   observed=observed.im_func
 self.setdefault(observed,set()).add(method)
   return method
 return reaction


if __name__=='__main__':
   observer=Observer()
   class base(object):
 @observer.emit
 def method(self,*args,**kwargs):
   print '%s.method'%str(self),args,kwargs

   class extensionA(object):
 @observer.reactOn(base.method)
 def __methodReaction(self,*args,**kwargs):
   print 'A,%s.methodReaction'%str(self),args,kwargs

   class extensionB(object):
 @observer.reactOn(base.method)
 def __methodReaction(self,*args,**kwargs):
   print 'B,%s.methodReaction'%str(self),args,kwargs

   class applicable(base,extensionA,extensionB):
 @observer.reactOn(base.method)
 def __methodReaction(self,*args,**kwargs):
   print 'applicable,%s.methodReaction'%str(self),args,kwargs

 pass

   applicable().method('cucu')


___ 
Yahoo! Messenger: chiamate gratuite in tutto il mondo 
http://it.beta.messenger.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: up to date books?

2005-08-18 Thread Paul Dale

I highly recommend the "Safari" library service from Oreilly ( 
http://safari.oreilly.com ) you can check out all of the books listed 
below and about 10,000 more. The library contains much more than just 
Oreilly's books, but they are, of course, all in there.

The first 2 weeks is free after that it's $20/month. You can check out 
10 books at a time and you have to keep them for a month. You can 
download chapters, print pages, and search all the books in the library, 
as well as search across books you've checked out.

It's a great way to get access to a broad range of technical books.

One thing to be careful of. As the old books are there too it's possible 
to grab a first version when you might want a second or third version. 
Always list by date and make sure you're looking at the new stuff.

Cheers,

Paul

Adriaan Renting wrote:

>I learned Python from the "Learning Python" book that's first on Alessandros 
>list. If you have the Second Edition, that includes coverage for Python 2.3, I 
>think you have quite a nice introductory book.
>As a reference book "Python in a Nutshell" and of course the Python 
>documentation itself are quite good.
>
>Adriaan
> 
> 
>  
>
Alessandro Bottoni <[EMAIL PROTECTED]> 08/18/05 9:02 am >>> 


>John Salerno wrote: 
> 
>  
>
>>hi all. are there any recommendations for an intro book to python that 
>>is up-to-date for the latest version? 
>>
>>
> 
>I do not know how much up-to-date they are but I have to suggest you these 
>books: 
> 
>- Learning Python 
>By Mark Lutz and David Ascher 
>published by O'Reilly 
>Most likely the best introductory book on Python 
> 
>- Python Cookbook 
>By Alex Martelli and David Ascher 
>published by O'Reilly 
>By far the most useful book on Python after your first week of real use of 
>this language 
> 
>Also, the fundamental 
>- Programming Python (the 2nd edition ONLY) 
>By Mark Lutz 
>published by O'Reilly 
>Is very useful for understanding the most inner details of Python 
> 
>  
>
>>would reading a book from a year or two ago cause me to miss much? 
>>
>>
> 
>No. Python did not changed too much since rel. 1.5. You can still use a book 
>published in 2001 as a introductory book (as I do). The changes are 
>exhaustively described both in the official documentation and in the very 
>fine "what's new in..." articles written by Andrew Kuchlin for every new 
>release (see www.python.org). 
> 
>CU 
> 
>--- 
>Alessandro Bottoni 
>  
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Some questions

2005-08-18 Thread Titi Anggono
Hi all,

I have some questions:

1. Can we use Tkinter for web application such as Java
?
2. I use gnuplot.py module for interfacing with
gnuplot in linux. Can we make the plot result shown in
web ? I tried using cgi, and it didn't work.

Thanks




Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterparse and ElementTree confusion

2005-08-18 Thread paul . sherwood
Ofcourse!

Thankyou so much. All is well, using the Iterparse takes a mere 3mins
to find the last product in the xml and this is probably due to my
checking 1 products for a specific.

I feel rather honoured to have 'the' effbot reply to my
humble post

Thanks again

Paul

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


how do i add a new path into sys.path?

2005-08-18 Thread wen
on my system(win2k server, python 2.3.5),
>>> import sys
>>> print sys.path
['C:\\', 'C:\\WINNT\\system32\\python23.zip',
'C:\\Python23\\lib\\site-packages\\Pythonwin',
'C:\\Python23\\lib\\site-packages\\win32',
'C:\\Python23\\lib\\site-packages\\win32\\lib',
'C:\\Python23\\lib\\site-packages', 'C:\\Python23\\DLLs',
'C:\\Python23\\lib', 'C:\\Python23\\lib\\plat-win',
'C:\\Python23\\lib\\lib-tk', 'C:\\Python23', 'D:\\Program Files\\DeLano
Scientific\\PyMOL\\modules']

now, i wanna add  "C:\Python23\Pmw\Pmw_1_2\lib" into sys.path, how?

any help would be appreciated.

with my kind regards,
Wen


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


Re: how do i add a new path into sys.path?

2005-08-18 Thread apa
You can do it this way:

sys.path.append("C:\Temp")

Alejandro

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


Re: how do i add a new path into sys.path?

2005-08-18 Thread bruno modulix
wen wrote:
> on my system(win2k server, python 2.3.5),
> 
import sys
print sys.path
> 
> ['C:\\', 'C:\\WINNT\\system32\\python23.zip',
> 'C:\\Python23\\lib\\site-packages\\Pythonwin',
> 'C:\\Python23\\lib\\site-packages\\win32',
> 'C:\\Python23\\lib\\site-packages\\win32\\lib',
> 'C:\\Python23\\lib\\site-packages', 'C:\\Python23\\DLLs',
> 'C:\\Python23\\lib', 'C:\\Python23\\lib\\plat-win',
> 'C:\\Python23\\lib\\lib-tk', 'C:\\Python23', 'D:\\Program Files\\DeLano
> Scientific\\PyMOL\\modules']
> 
> now, i wanna add  "C:\Python23\Pmw\Pmw_1_2\lib" into sys.path, how?

> any help would be appreciated.

hint 1: Python lists have an append() and an insert() method
hint 2: sys.path is a list

HTH
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do i add a new path into sys.path?

2005-08-18 Thread wen
if i wanna add the path "C:\temp" into sys.path, and make it available for
any other new python apps, like i add C:\temp into windows path , how?
thank you.

"apa" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> You can do it this way:
>
> sys.path.append("C:\Temp")
>
> Alejandro
>


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


Re: question about binary and serial info

2005-08-18 Thread nephish
this is exactly what i need.
i have not previously had a need for this kind of thing, but i sure
need some
documentation for it now. is there a resource out there to find out how
to convert decimal number to a byte, a byte to a decimal and more about
the & operator?
i really appreciate this info. this is exactly what i was looking for.
shawn

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


Re: Some questions

2005-08-18 Thread Alessandro Bottoni
Titi Anggono wrote:
> 1. Can we use Tkinter for web application such as Java?

What do you mean? If you want to build up a GUI (something like a HTML page)
for a web-based application, you can do it with TKinter. Your TKinter app
can connect to a web server (or any other kind of server) using the
standard Python networking libraries.

If you want to make a web application (a server-side application similar to
the ones you can create with JSP or EJB) you do not need Tkinter at all.
Just use Python itself (see Albatross, Webware and Quixote for a few
web-app frameworks for Python).

> 2. I use gnuplot.py module for interfacing with
> gnuplot in linux. Can we make the plot result shown in
> web ? I tried using cgi, and it didn't work.

The ability to display a image (in this case a GNUPlot plot) on a web page
depends on the browser. Normally, you have to install a specific plug-in
for displaying not-standard types of images on a web page, like it happens
with Macromedia Flash.

I do not know if exists any GNUPlot plug-in for the most common web
browsers. Maybe you can save your plot in a format that is compatible with
the existing viewers, like GIF, TIFF or JPEG. Have a look at GNUPlot
documentation for this.

HTH

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


Re: question about binary and serial info

2005-08-18 Thread nephish
oh wait, i found it. i found how to do the conversions and thanks to
you the operators.
appreciate everything,
shawn

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


Re: up to date books?

2005-08-18 Thread Jon Hewer
mark pilgrim's dive into python is a good book if you're new to python

i also have python cookbook, and foundations of python network
programming - i haven't really had a chance to look at these in detail
yet but both of these look good

On 8/18/05, Paul Dale <[EMAIL PROTECTED]> wrote:
> 
> I highly recommend the "Safari" library service from Oreilly (
> http://safari.oreilly.com ) you can check out all of the books listed
> below and about 10,000 more. The library contains much more than just
> Oreilly's books, but they are, of course, all in there.
> 
> The first 2 weeks is free after that it's $20/month. You can check out
> 10 books at a time and you have to keep them for a month. You can
> download chapters, print pages, and search all the books in the library,
> as well as search across books you've checked out.
> 
> It's a great way to get access to a broad range of technical books.
> 
> One thing to be careful of. As the old books are there too it's possible
> to grab a first version when you might want a second or third version.
> Always list by date and make sure you're looking at the new stuff.
> 
> Cheers,
> 
> Paul
> 
> Adriaan Renting wrote:
> 
> >I learned Python from the "Learning Python" book that's first on Alessandros 
> >list. If you have the Second Edition, that includes coverage for Python 2.3, 
> >I think you have quite a nice introductory book.
> >As a reference book "Python in a Nutshell" and of course the Python 
> >documentation itself are quite good.
> >
> >Adriaan
> >
> >
> >
> >
> Alessandro Bottoni <[EMAIL PROTECTED]> 08/18/05 9:02 am >>>
> 
> 
> >John Salerno wrote:
> >
> >
> >
> >>hi all. are there any recommendations for an intro book to python that
> >>is up-to-date for the latest version?
> >>
> >>
> >
> >I do not know how much up-to-date they are but I have to suggest you these
> >books:
> >
> >- Learning Python
> >By Mark Lutz and David Ascher
> >published by O'Reilly
> >Most likely the best introductory book on Python
> >
> >- Python Cookbook
> >By Alex Martelli and David Ascher
> >published by O'Reilly
> >By far the most useful book on Python after your first week of real use of
> >this language
> >
> >Also, the fundamental
> >- Programming Python (the 2nd edition ONLY)
> >By Mark Lutz
> >published by O'Reilly
> >Is very useful for understanding the most inner details of Python
> >
> >
> >
> >>would reading a book from a year or two ago cause me to miss much?
> >>
> >>
> >
> >No. Python did not changed too much since rel. 1.5. You can still use a book
> >published in 2001 as a introductory book (as I do). The changes are
> >exhaustively described both in the official documentation and in the very
> >fine "what's new in..." articles written by Andrew Kuchlin for every new
> >release (see www.python.org).
> >
> >CU
> >
> >---
> >Alessandro Bottoni
> >
> >
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Python for Webscripting (like PHP)

2005-08-18 Thread Florian Lindner
Hello,
I've been using Python a lot for scripting (mainly scripts for server
administration / DB access). All these scripts were shell based.

Now I'm considering using Python (with mod_python on Apache 2) for a web
project, just how I've used PHP in some smaller Projects before ()..

How suitable is Python for these kind of projects? What do think? Does the
stdlib offers all basic functions for this kind of requirements?

Thanks,

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


Re: PyPE 2.1 run problem

2005-08-18 Thread TonyHa

[EMAIL PROTECTED] wrote:
> Hello,
>
> I have downloaded the PyPE2.1-win-unicode.zip, after unzip it with winzip
> into PyPE2.1-win-unicode dierctory on window XP. I try to run "pype.exe"
> by double
> click on it, but nothing has happen, then when I run it with "run as..."
> using the right click button.
> I have the following Message in the pype.exe.log
>
> Traceback (most recent call last):
>   File "pype.py", line 30, in ?
>   File "configuration.pyc", line 129, in ?
> WindowsError: [Errno 267] The directory name is invalid:
> 'E:\\Downloads\\Python\\PyPE\\PyPE2.1-win-unicode\\library.zip/*.*'
>
> I also copy the "PyPE2.1-win-unicode" directory into
> "C:\Python24\Lib\site-packages" and run it, but it behaves the same !!
>
> Then I downloaded the source code and unzip it into "PyPe2.1-src", and run
> "python pype.py" in a command window.
> The progroam detected I have an older version of wxPython 2.5.5 and askes
> me do I want to download the newer version
> 2.6.1. Which I did.
>
> After downlowd the wxPython 2.6.1 (win-unicode" version). I installed it
> into Python 2.4.1, then re-run PyPE.
> i.e re-issue "python pype.py" in a command window." I have the following
> traceback Error message:
>
> [ Wed Aug 17 09:32:32 2005 ] Loading history from C:\Documents and
> Settings\gbr02333\.pype\history.txt
>
> Traceback (most recent call last):
>
>   File "pype.py", line 3926, in ?
>
> main()
>
>   File "pype.py", line 3916, in main
>
> filehistory.root = root = app.frame = MainWindow(None, -1, "PyPE",
> sys.argv[1+opn:])
>
>   File "pype.py", line 438, in __init__
>
> self.loadHistory()
>
>   File "pype.py", line 1152, in loadHistory
>
> self.config[nam][k] = dict(v)
>
> TypeError: iteration over non-sequence
>
>
> I wonder does anyone using PyPE2.1 on Windown XP SP2 and have the same
> problem? Can any one help
> with the problem? Thanks in advance !
>
> Tony Ha.

I have the following reply from the creator of PyPE (Josiah Carlson).
The
solution for running PyPE2.1 from the source is:

"replacing line 1152 with the following 4 lines:

if isinstance(v, dict):
self.config[nam][k] = dict(v)
else:
self.config[nam][k] = v "

Once I done the replacement as suggested above, PyPE2.1 can run from
the
source now. Thanks Josiah !

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


Re: up to date books?

2005-08-18 Thread dimitri pater
On 8/18/05, Jon Hewer <[EMAIL PROTECTED]> wrote:
mark pilgrim's dive into python is a good book if you're new to python
I agree that dive into python is a *very* good python book,
but as it is says on http://diveintopython.org/ it is "for experienced
programmers". So if you are new to Python  to programming in
general it might NOT be the best book to get started.

bye,
dimitri
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: up to date books?

2005-08-18 Thread Magnus Lycka
John Salerno wrote:
> hi all. are there any recommendations for an intro book to python that 
> is up-to-date for the latest version?

It depends on what kind of books you like, and of course on your
previous experience.

I think "Python: Visual QuickStart Guide" by Chris Fehily is a rather
nice beginner's book, even if it's from 2001. It's also pretty cheap.
I don't have it at hand now, but I suspect that it doesn't cover new
style classes, generators, or list (or generator) comprehensions, but
it's still a good intro.

If you like a high density book, Alex Martelli's "Python in a Nutshell"
is great, and if you like to see a bunch of recipes, "Python Cookbook,
2nd ed" is good. The cookbook recipes are also on the net, but the book
does add value to them.

> would reading a book from a year or two ago cause me to miss much?

Probably not. Most recent changes to Python, such as decorators, are
things that beginners might want to leave until later... New standard
modules, such as datetime, are covered in the standard library manual.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do i add a new path into sys.path?

2005-08-18 Thread poyol

wen wrote:
> if i wanna add the path "C:\temp" into sys.path, and make it available for
> any other new python apps, like i add C:\temp into windows path , how?
> thank you.

Then use PYTHONPATH as you would use PATH .

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


Re: how do i add a new path into sys.path?

2005-08-18 Thread wen
if i wanna add the path "C:\temp" into sys.path, and make it available for
any other new python apps, like i add C:\temp into windows path , how?
thank you.

"apa" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> You can do it this way:
>
> sys.path.append("C:\Temp")
>
> Alejandro
>


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


Re: Testing for presence of arguments

2005-08-18 Thread Peter Maas
Madhusudan Singh schrieb:
> Dan Sommers wrote:
[...]
>>class _SemiPrivateClass:
>>pass
>>
>>def f(required_argument=_SemiPrivateClass):
>>if required_argument == _SemiPrivateClass:
>>print "required_argument was probably not present"
>>else:
>>print "required_argument was present"
[...]
> Thanks for the suggestion, but seems needlessly complicated for
 > something very simple.

What is "very simple"? The problem or the solution? :) If you examine
this suggestion more closely you will note that it is more or less
the same as Benji York's one except Benji used a built-in class.

If you are interested in getting help on usenet you should abstain
from devaluating efforts to give you a useful reply. "Thanks for
the suggestion" or even no answer would have been sufficient.

-- 
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
-- 
http://mail.python.org/mailman/listinfo/python-list


time.clock() problem under linux (precision=0.01s)

2005-08-18 Thread Szabolcs Nagy
I have to measure the time of a while loop, but with time.clock i
always get 0.0s, although python manual sais:
"this is the function to use for benchmarking Python or timing
algorithms"

So i tested timer functions capabilities with a short script:

import time
import os

def test_timer_func(func):
print 'min time-time: %.10f'%min(abs(func()-func()) for i in
xrange(10**5))
print 'max time-time: %.10f'%max(abs(func()-func()) for i in
xrange(10**5))

dt = 0.0
loopcount = 0
t = func()

while dt==0.0:
dt = func() - t
loopcount += 1

print "min measurable loop time : %.10f"%dt
print 'loopcount while dt==0 :',loopcount


print '\n time.clock()'
test_timer_func(time.clock)

print '\n time.time()'
test_timer_func(time.time)

print '\n os.times()'
ot = os.times
test_timer_func(lambda:ot()[4])


My output is:

 time.clock()
min time-time: 0.00
max time-time: 0.01
min measurable loop time : 0.01
loopcount while dt==0 : 2703

 time.time()
min time-time: 0.019073
max time-time: 0.460148
min measurable loop time : 0.050068
loopcount while dt==0 : 1

 os.times()
min time-time: 0.00
max time-time: 0.010007
min measurable loop time : 0.009998
loopcount while dt==0 : 2515


So the precision of time.clock is 0.01s under my ubuntu linux system,
which means it's not suitable for benchmarking. (i want to benchmark
the fps in my pygame+pyode program and it needs at least 0.001s
precision)

time.time seems much better solution, but python manual sais: "not all
systems provide time with a better precision than 1 second"

Should i use time.clock or time.time to be more crossplatform?
Is time.time ok for windows? (time()-time() != 0.0)

nszabolcs

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


Re: Python for Webscripting (like PHP)

2005-08-18 Thread Micetto Nero
Florian Lindner ha scritto:
> Hello,
> I've been using Python a lot for scripting (mainly scripts for server
> administration / DB access). All these scripts were shell based.
> 
> Now I'm considering using Python (with mod_python on Apache 2) for a web
> project, just how I've used PHP in some smaller Projects before ( print "foo" ?>)..
> 
> How suitable is Python for these kind of projects? What do think? Does the
> stdlib offers all basic functions for this kind of requirements?
> 

You can use the Python Server Pages, that are analogous to ASP, PHP and JSP.



-- 

robiweb90 [at] gmail [dot] com
"Nessuno può fabbricare una macchina tanto intelligente che possa essere 
usata da uno sciocco" - Confucio
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List of string

2005-08-18 Thread Mohammed Altaj

>
>
>  
>
>
>Mohammed Altaj wrote:
>  
>
>>Hi All
>>
>>I am having problem with delete line if its belong to another one , example
>>
>>
>
>I think, you mean to remove all lines that are substrings of another
>line.
>
>l = ['0132442\n', '13\n', '24\n']
>l = [e.strip() for e in l]
>
>i = 0
>while True:
>  try:
>for j in range(len(l)):
>  if i == j:
>continue
>  if l[j].find(l[i]) >= 0:
># line 'j' is superstring of line 'i'
>del l[i]
>break
>else: # doesn't have superstring
>  i += 1
>  except IndexError:
>break
>
>Basically, I try all n*n combinations, and remove substring lines
>"in-place".
>
>BranoZ
>
>
>  
>
>
Thanks , but , this work for an ordered substrings , just like what we
had   ['0132442\n', '13\n', '24\n'] , I would like to remove all
substrings from the list , example

['0134314244133', '132443', '234'] 


2nd and 3rd strings are also substrings from the 1st one , so it should
be removed

Thanks



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


Re: GIS Related Scripting Issue

2005-08-18 Thread Fredrik Lundh
Mike Rose wrote:

> I am currently using ArcGIS 9.1 and was referred to this list to ask my
> question.  I am using a python script to loop through a series of
> features, select all polygons that are within 5 miles, run statistics on
> those selected polygons, then append the values to a new database(dbf).
> I am not sure if I am going about this correctly or not, but my script
< is definitely not working.  I am getting an error when it tries to
> append to the dbf.

can you perhaps post the error message?

 



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


Re: Python for Webscripting (like PHP)

2005-08-18 Thread Szabolcs Nagy
I don't think stdlib offers anything like that

The problem with python is it's white space sensible and html  is not.

However there are some nice solutions:
http://www.webwareforpython.org/Papers/Templates/
my favourite is not listed here:
http://karrigell.sourceforge.net/

For web development with python i'd rather recommend a complete
webframework:
http://www.djangoproject.com/
http://subway.python-hosting.com/
http://www.zope.org/

nszabolcs

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


Re: List of string

2005-08-18 Thread Marco Aschwanden
> Thanks , but , this work for an ordered substrings , just like what we
> had   ['0132442\n', '13\n', '24\n'] , I would like to remove all
> substrings from the list , example
>
> ['0134314244133', '132443', '234']
>
>
> 2nd and 3rd strings are also substrings from the 1st one , so it should
> be removed
>
> Thanks

Sounds like you have some homework to do. Good luck!


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


unsubscriptable object error

2005-08-18 Thread MCollins

getting an unsubscriptable
object error on an if else statement


db = MSSQL.connect(server,login,pwd,database)
c = db.cursor()
c.execute(mySQL)
rows = c.fetchone()
    
    
#determine recipient
if str(rows[3]) == str(rows[4]):
        recipient
= str(rows[0]) + " " + str(rows[1])
        
else:
        recipient
= "test"



the above code works fine if rows[3]
== rows[4].  it's when it doesn't equal that it gives the error::

TypeError: unsubscriptable object 
  args =
('unsubscriptable object',) 





Matthew Collins
Senior Programmer Analyst, Information Technologies
Seminole County Government
1101 E First St
Sanford, FL 32771

Office 407-665-1072
Fax 407-665-1025
http://www.seminolecountyfl.gov


--Florida has a very broad Public Records Law. Virtually all written
communications to or from State and Local Officials and employees are public
records available to the public and media upon request.  Seminole
County policy does not differentiate between personal and business emails.
 E-mail sent on the County system will be considered public and will
only be withheld from disclosure if deemed confidential pursuant to State
Law.-- 
http://mail.python.org/mailman/listinfo/python-list

RE: unsubscriptable object error

2005-08-18 Thread Tim Golden
[EMAIL PROTECTED]

> getting an unsubscriptable object error on an if else statement 

> db = MSSQL.connect(server,login,pwd,database) 
> c = db.cursor() 
> c.execute(mySQL) 
> rows = c.fetchone() 

> #determine recipient 
> if str(rows[3]) == str(rows[4]): 
> recipient = str(rows[0]) + " " + str(rows[1]) 
> else: 
> recipient = "test" 

> the above code works fine if rows[3] == rows[4].  it's when it doesn't equal 
> that it gives the error:: 

> TypeError: unsubscriptable object 
>   args = ('unsubscriptable object',) 

Hi, Matthew.

Couple of points first: if it's possible, try to send emails in plain-text
only, no HTML or Rich-Text. Makes life easier in some viewers. (And this
list is gatewayed to news:comp.lang.python and to Google Groups).

Also, try to screen dump the *actual* traceback, not your
copy of it. Your example is self-contained so I imagine it
can easily be run at the interpreter. (Which may be what
you're doing).

Finally, I suspect that your (slightly ill-named) "rows" is getting
a None back from c.fetchone (). Consider the following example:


import MSSQL

# substitute your own connection info
db = MSSQL.connect ("VODEV1", "", "", "EVODEV")

c = db.cursor ()
c.execute ("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 1 = 2")
# guaranteed no rows
rows = c.fetchone ()

print rows
# will display 'None'

print rows[3], rows[4]
# will display unsubscriptable object


I realise that you say "the above code works find if 
rows[3] == rows[4]" but how do you know? If I've got the 
wrong end of the stick, can you publish a working snippet 
which can reproduce the error?

TJG


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

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


Event objects Threading on Serial Port on Win32

2005-08-18 Thread elcinturapartida
Hello all,

I am not sure if this question is about threading or serial i/o - it
has elements of both. I'm on WinXP (desktop) and WinNT (labtop), when I
run miniterm.py there is no problem both writing, reading, opening the
com port, no errors, etc.

But if I run wxTerminal.py when read from it nothing happens. It ran
without error and it seemed to write ok, If I run the code to do the
write, then I connect to the device through hyperterminal or wxterm,  I
get the response, so it seems the write is working ok, just very
strange. wxTerminal.py uses Event object to set the event of Threading
module. However wxTerminal.py doesn't loop while alive event is true.

class TerminalFrame(wxFrame):
"""Simple terminal program for wxPython""

def __init__(self, *args, **kwds):
self.serial = serial.Serial()
self.serial.timeout = 0.5   #make sure that the alive event can
be checked from time to time
self.settings = TerminalSetup() #placeholder for the settings
self.thread = None
self.alive = threading.Event()


def StartThread(self):
"""Start the receiver thread"""
self.thread = threading.Thread(target=self.ComPortThread)
self.thread.setDaemon(1)
self.thread.start()
self.alive.set()


def __attach_events(self):
...
self.Bind(EVT_SERIALRX, self.OnSerialRead)
self.Bind(EVT_CLOSE, self.OnClose)


def ComPortThread(self):
"""Thread that handles the incomming traffic. Does the basic
input
   transformation (newlines) and generates an SerialRxEvent"""
while self.alive.isSet():   #loop while alive event
is true
print "Start self.alive.isSet"  <- Don't
show in console.
text = self.serial.read(1)  #read one, with timout
if text:#check if not timeout


miniterm.py and wxTerminal.py are at http://pyserial.sourceforge.net/

Any advice will be much appreciated.

Thanks

David

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


Re: creating/modifying sparse files on linux

2005-08-18 Thread Benji York
Terry Reedy wrote:
> megastring = 100*'a' # t < 1 sec on my machine

>>(other than keep appending to a string until it reaches 1MB len)?
> 
> You mean like (unexecuted)
> s = ''
> for i in xrange(100): s += 'a' #?
> 
> This will allocate, copy, and  deallocate 100 successively longer 
> temporary strings and is a noticeable O(n**2) operation.

Not exactly.  CPython 2.4 added an optimization of "+=" for strings. 
The for loop above takes about 1 second do execute on my machine.  You 
are correct in that it will take *much* longer on 2.3.
--
Benji York

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


Re: List of strings

2005-08-18 Thread Tomi Kyöstilä
Paul Watson wrote:
> Mohammed Altaj wrote:
> 
>> Hi All
>>
>> Thanks for your reply , what i am doing is , i am reading from file ,
>> using readlines() , I would like to check in these lines , if there is
>> line belong to another one or not , if it is , then i would like to
>> delete it
>>
>> ['0132442\n', '13\n', '24\n']
>> '13' is already in '0132442'
>> '24' is already in '0132442'
>> Thanks 
> 
> 
> $ python
> Python 2.4.1 (#1, Jul 19 2005, 14:16:43)
> [GCC 4.0.0 20050519 (Red Hat 4.0.0-8)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> line = '0132442\n'
>  >>> line
> '0132442\n'
>  >>> line.find("13")
> 1
>  >>> line.find("03")
> -1
>  >>> line.find("24")
> 3
>  >>> print line.find.__doc__
> S.find(sub [,start [,end]]) -> int
> 
> Return the lowest index in S where substring sub is found,
> such that sub is contained within s[start,end].  Optional
> arguments start and end are interpreted as in slice notation.
> 
> Return -1 on failure.

Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> line = '0132442\n'
 >>> line
'0132442\n'
 >>> "13" in line
True
 >>> "03" in line
False
 >>> "24" in line
True

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


Re: Python for Webscripting (like PHP)

2005-08-18 Thread Alessandro Bottoni
Florian Lindner wrote:
> How suitable is Python for these kind of projects? What do think? Does the
> stdlib offers all basic functions for this kind of requirements?

Python is extremely well suited for the web-app development and the STDLib
supply most of what you need for this task. As a matter of fact, the easy 
development of web applications was one of the main focuses of the Python
community since Rel 1.0. Thanks to the hard work of its supporters, Python
is now widely considered one of the best tool you can use for developing
web applications, even better than PHP.

Have a look at these chapters of the official Python documentation to get
convinced of what I'm saying:
Chap. 11: Internet Protocols and Support
Chap. 12: Internet Data Handling
Chap. 13: Structured Mark-Up Languages Processing

(Python has even been told to be used by Yahoo! and Google, among others,
but nobody was able to demonstrate this, so far)

Despite this, keep in mind that developing a _real_world_ web application
without the right tools (session management and templating, in particular)
is quite hard, no matter which language you use (even with PHP).

Have a look at the many web frameworks mentioned at http://www.python.org/
and at http://www.vex.net/parnassus/ and choose the one you feel best
suited for your task.

Among these web framework, a couple of them deserve a particular attention:

Maki is a XML based framework, very similar to the java-based Cocoon:
http://maki.sourceforge.net/
http://cocoon.apache.org/

Albatross is aimed to stateful applications:
http://www.object-craft.com.au/projects/albatross/

Regarding the template engine, the best one I'm aware of is Cheetah:
http://www.cheetahtemplate.org/

A last word: beware of PSP (Python Server Pages). If used in the wrong way,
this tool (like the original Java Server Pages) can make a real mess of
your code (because of the inextricable tangle of Python and HTML code you
can create).

CU

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


Which Python library for Jabber?

2005-08-18 Thread Alessandro Bottoni
[I just asked this on Jabber Dev but I did get very few answers. Please,
excuse me for this kind of a cross-posting and give me some advise, if you
can.]

Which Python library would you use for developing a small Jabber client?

jabber.py (seems to be dead since 2003)
http://jabberpy.sourceforge.net/

pyxmpp (looks like the "official" python library)
http://pyxmpp.jabberstudio.org/

xmpp.py (a russian alternative. Very well documented and apparently quite
complete)
http://xmpppy.sourceforge.net/ 

Anything else?

TIA
---
Alessandro Bottoni
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Which Python library for Jabber?

2005-08-18 Thread Tim Golden
[Alessandro Bottoni]
| Which Python library would you use for developing a small 
| Jabber client?
| 
| jabber.py (seems to be dead since 2003)
| http://jabberpy.sourceforge.net/
| 
| pyxmpp (looks like the "official" python library)
| http://pyxmpp.jabberstudio.org/
| 
| xmpp.py (a russian alternative. Very well documented and 
| apparently quite
| complete)
| http://xmpppy.sourceforge.net/ 

I've used xmpppy recently for some very small-scale stuff (basically
some commit-notification work), and it seemed to work ok. No in-depth
trial, though.

TJG


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

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


Re: Some questions

2005-08-18 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Alessandro Bottoni  <[EMAIL PROTECTED]> wrote:
>Titi Anggono wrote:
>> 1. Can we use Tkinter for web application such as Java?
>
>What do you mean? If you want to build up a GUI (something like a HTML page)
>for a web-based application, you can do it with TKinter. Your TKinter app
>can connect to a web server (or any other kind of server) using the
>standard Python networking libraries.
>
>If you want to make a web application (a server-side application similar to
>the ones you can create with JSP or EJB) you do not need Tkinter at all.
>Just use Python itself (see Albatross, Webware and Quixote for a few
>web-app frameworks for Python).
.
.
.
... or, if you mean, "is Python an apt language for client-side
Web development in the way Java is, with the market-leading 
browsers all embedding JVMs which can interpret class definitions",
the answers is, "No."  And also "Yes".  

Standard Python is *not* good for client-side Web work.  Jython is,
though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Webscripting (like PHP)

2005-08-18 Thread Luis M. Gonzalez
Mod_python has a PSP (python server pages - ala php) implementation.
However it's still not mature enough and, imho, it has a serious
drawback in its way to handle indentation. But this is just the first
release and I hope it will improve in the near future.

My favorite is Karrigell ( http://karrigell.sourceforge.net ).
It is a pleasure to work with, minimalistic, simple and to the point.
No template language needed, just regular python and html and, as far
as I know, mod_python integration is uderway.

Hope it helps...
Luis

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


Re: Python for Webscripting (like PHP)

2005-08-18 Thread Valentino Volonghi aka Dialtone
Alessandro Bottoni <[EMAIL PROTECTED]> wrote:

> (Python has even been told to be used by Yahoo! and Google, among others,
> but nobody was able to demonstrate this, so far)

?
 
Google and Microsoft and Nokia had talks during PyCon 2005.
If you look at the GMAIL help system you would see that all the links in
there end in .py.
Blogger is almost completely built with python.
Google is also one of the members of the PSF.

What should be demonstrated?

-- 
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.4
Blog: http://vvolonghi.blogspot.com
http://weever.berlios.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: As Simple As Possible?

2005-08-18 Thread Tom Anderson
On Thu, 18 Aug 2005, Jules Dubois wrote:

> On Wednesday 17 August 2005 22:11, jitya <[EMAIL PROTECTED]>
> (<[EMAIL PROTECTED]>) wrote:
>
>> After three years of study, I have concluded that Python is about as 
>> simple as a full-powered object-oriented language can get.
>>
>> I know of no language to which these words apply more than Python.
>
> Smalltalk is or would be my first choice if everything else were equal.
> Python is what I actually use.

The showstopping problem with smalltalk, IMHO, is the intertwining of the 
language and the environment. Smalltalk weenies hold this up as one of its 
greatest strengths, but to me, it just looks like there's twice as much to 
learn to begin with. A good command-line smalltalk plus a python-style 
simple interactive environment would be a winning combination.

Otherwise, i agree that smalltalk is basically the perfect language.

tom

-- 
If you tolerate this, your children will be next.
-- 
http://mail.python.org/mailman/listinfo/python-list


Dr. Dobb's Python-URL! - weekly Python news and links (Aug 18)

2005-08-18 Thread Cameron Laird
QOTW:  "It seems to me that Java is designed to make it difficult for
programmers to write bad code, while Python is designed to make it
easy to write good code." -- Magnus Lycka

"Code attracts people that like to code. Tedious, repetitive c.l.py
threads attract people that like to write tedious, repetitive c.l.py
threads." -- Robert Kern


Yes, commercial Python training *is* available:

http://groups.google.com/group/comp.lang.python.announce/msg/f1bd9b8deac1cb39

You know how essential the Cookbook is.  Filling a slightly
different role is the Grimoire:
http://the.taoofmac.com/space/Python/Grimoire

The latest SPE "features a remote, encrypted and embedded
... debugger ...":
http://pythonide.stani.be

Paul Dale convincingly advertises O'Reilly's Safari service:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/115a242dc77b0057/

Python is a superb vehicle for several niches generally 
thought exclusive to other languages, such as automation
of Windows processes.  Another too-little-known such 
strength is Python's adeptness with native Mac OS X 
applications:  
http://developer.apple.com/cocoa/pyobjc.html

mensanator introduces enough of bit arithmetic to explain
popcount and Hamming distance:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e0716ffcf80af3a2/

PEP editors David Goodger and Barry Warsaw refine PEP
organization:
http://mail.python.org/pipermail/python-list/2005-August/294467.html



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi
http://python.de/backend.php
For more, see
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python "To-Do List" now lives principally in a
SourceForge reincarnation.
http://sourceforge.net/tracker/?a

RE Question

2005-08-18 Thread Yoav
I don't understand why the two REs produce a different result. I read 
the RE guide but still I can't seem to figure it out.

 >>> t
'echo user=name password=pass path="/ret files"\r\n'
 >>> re.findall(r'(?<=\s)[^=]+=((?:".*")|(?:\S*))(?=\s)', t)
['name', 'pass', '"/ret files"']
 >>> re.findall(r'(?<=\s)[^=]+=((".*")|(\S*))(?=\s)', t)
[('name', '', 'name'), ('pass', '', 'pass'), ('"/ret files"', '"/ret 
files"', '')]


Also, does '|' char (meaning or) produces a pair for each section. I 
don't understand how it works. Can someone please direct me to a place 
which will explain it?

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


Re: Tkinter and gnuplot module

2005-08-18 Thread Grant Edwards
On 2005-08-18, Titi Anggono <[EMAIL PROTECTED]> wrote:

> 1. Can we use Tkinter for web application such as Java?

No. You can't use Tkinter in a Java app, since Tkinter is a
Python module (unless it works with Jython).

> 2. I use gnuplot.py module for interfacing with gnuplot in
> linux. Can we make the plot result shown in web ? I tried
> using cgi, and it didn't work.

Sure.  Just plot to a .png file and serve up the .png file.

-- 
Grant Edwards   grante Yow!  Now KEN is having
  at   a MENTAL CRISIS beacuse
   visi.comhis "R.V." PAYMENTS are
   OVER-DUE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating/modifying sparse files on linux

2005-08-18 Thread [EMAIL PROTECTED]

My goal is very simple. Have a mechanism to create sparse files and
modify them by writing arbitratry ranges of bytes at arbitrary offsets.
I did get the information I want (xrange instead of range, and a simple
way to generate 1Mb string in memory). Thanks for pointing out about
using "len" as variable. It is indeed silly.

My only assumption from underlying OS/file system is that if I seek
past end of file and write some data, it doesn't generate blocks for
data in between. This is indeed true on Linux (I tested on ext3).

Thanks,
Raghu.

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


Re: Bug in slice type

2005-08-18 Thread Steven Bethard
Michael Hudson wrote:
> [EMAIL PROTECTED] writes:
>> I'm fine with your favored behavior. What do we do next to get
>> the doc fixed?
> 
> I guess one of us comes up with some less misleading words.  It's not
> totally obvious to me what to do, seeing as the returned values *are*
> indices is a sense, just not the sense in which they are used in
> Python.  Any ideas?

Maybe you could replace:

"these are the start and stop indices and the step or stride length of 
the slice"

with

"these are start, stop and step values suitable for passing to range or 
xrange"


I wanted to say something about what happens with a negative stride, to 
indicate that it produces (9, -1, -2) instead of (-1, -11, -2), but I 
wasn't able to navigate the Python documentation well enough.

Looking at the Language Reference section on the slice type[1] (section 
3.2), I find that "Missing or out-of-bounds indices are handled in a 
manner consistent with regular slices." So I looked for the 
documentation of "regular slices".  My best guess was that this meant 
looking at the Language Reference on slicings[2].  But all I could find 
in this documentation about the "stride" argument was:

"The conversion of a proper slice is a slice object (see section 3.2) 
whose start, stop and step attributes are the values of the expressions 
given as lower bound, upper bound and stride, respectively, substituting 
None for missing expressions."

This feels circular to me.  Can someone help me find where the semantics 
of a negative stride index is defined?


Steve

[1] http://docs.python.org/ref/types.html
[2] http://docs.python.org/ref/slicings.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Webscripting (like PHP)

2005-08-18 Thread Peter Hansen
Alessandro Bottoni wrote:
> (Python has even been told to be used by Yahoo! and Google, among others,
> but nobody was able to demonstrate this, so far)

Nobody, except Google's founders?

http://www-db.stanford.edu/~backrub/google.html

(Among many other references.)

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


New to python

2005-08-18 Thread pcaro8a
Hi,

I am new to python I am trying to install the numeric library and I 
get the following error:

error: Python was built with version 6 of Visual Studio, and 
extensions need to
be built with the same version of the compiler, but it isn't installed.

Do I need Visual Studio to make this work or is there any other reason 
for this message?

Thanks, I appreciate you help.

Paola


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


gnuplot-py: plotoutput in string?

2005-08-18 Thread Nicola Kaiser
Hi,

I´m using Gnuplot via gnuplot.py and I´m looking for a way to get the 
plotting output (terminal set to png in my case) piped in a string 
instead of to stdout or a file.

Is there any method in gnuplot.py that does this for me?


If not, I tried something like:

p=Gnuplot.Gnuplot(debug=1)
p('set terminal png')
oldstdout=sys.stdout
output=cStringIO.StringIO()
sys.stdout=output
p.plot([[1,0],[2,50],[3,0],[4,20],[5,0],[6,30],[7,70], [8,70], [9, 75], 
[10, 50], [11, 30], [12, 50]])
sys.stdout=oldstdout
print output.getvalue()

But unfortunately I also get other stuff like:

"gnuplot: unable to open display ''
"gnuplot: X11 aborted"

in the same string

Can anyone help me on this?

Thanks,
Nicola

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


Strange email.Parser error?

2005-08-18 Thread Andrey Smirnov
I am getting the following traceback after upgrading my app to Python
2.4.1.  It's telling me that there is an error in Parser.py.  It tells
me that 'fp.read(8192)' is given 2 arguments, but it is clearly not
true.  Does anybody know what's going on here?

Traceback (most recent call last):
  File "/opt/etext/lib/python2.4/site-packages/etext/enqueue.py", line
252, in work
worker(e.linkval, info)
  File "/opt/etext/bin/etreceive", line 30, in worker
result = decode.searchfile(f)
  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
43, in searchfile
return Email(f)
  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
510, in __init__
self.child.append(Email(mf))
  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
404, in __init__
msg = Parser().parse(f)
  File "/opt/etext/lib/python2.4/email/Parser.py", line 65, in parse
data = fp.read(8192)
TypeError: read() takes exactly 1 argument (2 given)

Thanks,
Andre.

-- 

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


Re: RE Question

2005-08-18 Thread Jorge Godoy
Yoav wrote:

> I don't understand why the two REs produce a different result. I read
> the RE guide but still I can't seem to figure it out.
> 
>  >>> t
> 'echo user=name password=pass path="/ret files"\r\n'
>  >>> re.findall(r'(?<=\s)[^=]+=((?:".*")|(?:\S*))(?=\s)', t)
> ['name', 'pass', '"/ret files"']
>  >>> re.findall(r'(?<=\s)[^=]+=((".*")|(\S*))(?=\s)', t)
> [('name', '', 'name'), ('pass', '', 'pass'), ('"/ret files"', '"/ret
> files"', '')]

Hi Yoav.

You can see at "sre" documentation (use that instead of the docs for "re")
that using "?:" you're asking for a non-groupping version of the
parenthesis match.  When you use parenthesis, the matched expression is
saved for using later.  Using "?:" you prevent that.  This is what causes
the difference for you.

> Also, does '|' char (meaning or) produces a pair for each section. I
> don't understand how it works. Can someone please direct me to a place
> which will explain it?

I didn't get your second question.  When you use "|" the first match is
used.  It is a short-circuited version of "or".  I mean, it tries the first
regexp, if it matches, the second expression is ignored.  The same is true
for "and", except that the comparisons end on the first false result. 


Be seeing you,
-- 
Jorge Godoy  <[EMAIL PROTECTED]>

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


Re: RE Question

2005-08-18 Thread Yoav
Thanks, it seems like the first answer covers the second as well.

Thank you.

Jorge Godoy wrote:
> Yoav wrote:
> 
> 
>>I don't understand why the two REs produce a different result. I read
>>the RE guide but still I can't seem to figure it out.
>>
>> >>> t
>>'echo user=name password=pass path="/ret files"\r\n'
>> >>> re.findall(r'(?<=\s)[^=]+=((?:".*")|(?:\S*))(?=\s)', t)
>>['name', 'pass', '"/ret files"']
>> >>> re.findall(r'(?<=\s)[^=]+=((".*")|(\S*))(?=\s)', t)
>>[('name', '', 'name'), ('pass', '', 'pass'), ('"/ret files"', '"/ret
>>files"', '')]
> 
> 
> Hi Yoav.
> 
> You can see at "sre" documentation (use that instead of the docs for "re")
> that using "?:" you're asking for a non-groupping version of the
> parenthesis match.  When you use parenthesis, the matched expression is
> saved for using later.  Using "?:" you prevent that.  This is what causes
> the difference for you.
> 
> 
>>Also, does '|' char (meaning or) produces a pair for each section. I
>>don't understand how it works. Can someone please direct me to a place
>>which will explain it?
> 
> 
> I didn't get your second question.  When you use "|" the first match is
> used.  It is a short-circuited version of "or".  I mean, it tries the first
> regexp, if it matches, the second expression is ignored.  The same is true
> for "and", except that the comparisons end on the first false result. 
> 
> 
> Be seeing you,
-- 
http://mail.python.org/mailman/listinfo/python-list


Confused newbie needs help with "__init__() takes exactly 11 arguments (1 given)"

2005-08-18 Thread googleboy
I've written a little script to parse a csv file then use seach/replace
over a template to create a file for each line in the file.  It pikes
out when I call the function that parses the csv (read_revs).  If I
have inadvertantly left an extra comma or two in the comma field, it
gives an error that says:

Traceback (most recent call last):
  File
"C:\dev\python\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
  File "d:\dev\python\projects\books\revgen3.py", line 177, in ?
gen_html()
  File "d:\dev\python\projects\books\revgen3.py", line 92, in gen_html
revlist =
read_revs(r'D:\library\work\websites\gobooks\cgi\reviews.csv')
  File "d:\dev\python\projects\books\revgen3.py", line 38, in read_revs
reviews = [Review(*[field.strip() for field in row]) for row in
reader]
TypeError: __init__() takes exactly 11 arguments (13 given)

Which I understand totally, because I can see the two extra fields in
the csv.  Problem is, if I correct that problem it gives me confusing
output that is identical except for the final line which says:

TypeError: __init__() takes exactly 11 arguments (1 given)

I don't get how it goes from 13 arguments to 1!  I now have 10 fields
and can understand that it is passing self as the 11th argument.

Particularly confusing to me was that when I translated this from a
windows box running Python 2.4 to an OpenBSD box running python 2.3, it
just worked on the unix box.

Find below an the code and an example of the csv file in question.

TIA

googleboy




-
param1,param2,param3,param4,param5,param6,param7,param8,param9,comments
data1,data2,data3,data4,data5,data6,data7,data8,data9,Comments on the
item reviewed go here. Sometime, but not all the time, there might be
extra commas in this text.
data1,data2,data3,data4,data5,data6,data7,data8,data9,Comments on the
item reviewed go here.



--

import string, os, re, sys, operator, csv

class Review(object):
def __init__(self, param1, param2, param3, param4, param5, param6,
param7, param8, param9, comments):
params = locals()
del params['self']
self.__dict__.update(params)
def __repr__(self):
all_items = self.__dict__.items()
return '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % (self.param1,
self.param2, self.param3, self.param4, self.param5, self.param6,
self.param7, self.param8, self.param9, self.comments)


def read_revs(filename):
csv_file = open(filename, "rb")
reader = csv.reader(csv_file)
reviews = [Review(*[field.strip() for field in row]) for row in
reader]
csv_file.close()
return reviews


def gen_revs():

revlist = read_revs(r'd:\dev\python\projects\books\reviews.csv')
revheader = revlist[0]
all_reviews = revlist[1:]

template = open(r'd:\dev\python\projects\books\template.txt', 'r')
sTemplate = template.read()

for review in all_reviews:
param1 = getattr(review, 'param1')
param2 = getattr(review, 'param2')
param3 = getattr(review, 'param3')
param4 = getattr(review, 'param4')
param5 = getattr(review, 'param5')
param6 = getattr(review, 'param6')
param7 = getattr(review, 'param7')
param9 = getattr(review, 'param8')
param9 = getattr(review, 'param9')
comments = getattr(review, 'comments')

output = template % (param1, param2, param3, param4, param5,
param6, param7, param8, param9, comments)

f=open(r"d:\dev\python\projects\books\%s.html" % param1, 'w')
f.write(output)
f.close()

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


Re: Strange email.Parser error?

2005-08-18 Thread Anthony Botrel
Hi,

in the call fp.read(8192) the function read() gets 2 arguments :  and <8192>

Member functions implicitely get their object as first argument, this
is why you get this error. So you have 2 possibilities : either read()
doesn't take an argument anymore, or read() is not a member of fp.

Anthony B.

On 8/18/05, Andrey Smirnov <[EMAIL PROTECTED]> wrote:
> I am getting the following traceback after upgrading my app to Python
> 2.4.1.  It's telling me that there is an error in Parser.py.  It tells
> me that 'fp.read(8192)' is given 2 arguments, but it is clearly not
> true.  Does anybody know what's going on here?
> 
> Traceback (most recent call last):
>   File "/opt/etext/lib/python2.4/site-packages/etext/enqueue.py", line
> 252, in work
> worker(e.linkval, info)
>   File "/opt/etext/bin/etreceive", line 30, in worker
> result = decode.searchfile(f)
>   File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
> 43, in searchfile
> return Email(f)
>   File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
> 510, in __init__
> self.child.append(Email(mf))
>   File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
> 404, in __init__
> msg = Parser().parse(f)
>   File "/opt/etext/lib/python2.4/email/Parser.py", line 65, in parse
> data = fp.read(8192)
> TypeError: read() takes exactly 1 argument (2 given)
> 
> Thanks,
> Andre.
> 
> --
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Question

2005-08-18 Thread Yoav
What is the difference between the RE module and the SRE one?

 Original Message 
From: Jorge Godoy <[EMAIL PROTECTED]>
To:
Subject: Re:RE Question
Date: 18/8/2005 17:44

> Yoav wrote:
> 
> 
>>I don't understand why the two REs produce a different result. I read
>>the RE guide but still I can't seem to figure it out.
>>
>> >>> t
>>'echo user=name password=pass path="/ret files"\r\n'
>> >>> re.findall(r'(?<=\s)[^=]+=((?:".*")|(?:\S*))(?=\s)', t)
>>['name', 'pass', '"/ret files"']
>> >>> re.findall(r'(?<=\s)[^=]+=((".*")|(\S*))(?=\s)', t)
>>[('name', '', 'name'), ('pass', '', 'pass'), ('"/ret files"', '"/ret
>>files"', '')]
> 
> 
> Hi Yoav.
> 
> You can see at "sre" documentation (use that instead of the docs for "re")
> that using "?:" you're asking for a non-groupping version of the
> parenthesis match.  When you use parenthesis, the matched expression is
> saved for using later.  Using "?:" you prevent that.  This is what causes
> the difference for you.
> 
> 
>>Also, does '|' char (meaning or) produces a pair for each section. I
>>don't understand how it works. Can someone please direct me to a place
>>which will explain it?
> 
> 
> I didn't get your second question.  When you use "|" the first match is
> used.  It is a short-circuited version of "or".  I mean, it tries the first
> regexp, if it matches, the second expression is ignored.  The same is true
> for "and", except that the comparisons end on the first false result. 
> 
> 
> Be seeing you,
-- 
http://mail.python.org/mailman/listinfo/python-list


Creating watermark with transparency on jpeg using PIL?

2005-08-18 Thread tvmaly
I have been trying to add a watermark to a jpeg using PIL, but the
watermark has a black box around it.  I looked at

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

and

http://mail.python.org/pipermail/python-list/1999-May/003369.html

but I think these only refer to gif or png.  I know jpegs really do not
support transparency, but is there some way to take a watermark in a
non jpeg format and add it to a jpeg without that box appearing around
it?

Best Regards

   Ty

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


Coin-operated kiosk written in python -- need some help...

2005-08-18 Thread Jon Monteleone
Greetings,
I posted a few days back and didnt get much of a response, so I figured I would 
post again
with more detail. I am running gnome under fedora core 4.

I want a kid to be able to drop a quarter into a coin slot and get 15 minutes 
of time on
an account that has "restricted" Internet access via the firefox web browser.  
We are
experimenting with different ways to allow kids to safely surf the web during 
school hours
while recovering some of the cost for bandwidth.  I have written a python 
program that
detects the coin drop and adds 15 minutes to a gui written in tkinter. The gui 
contains 2
buttons and the usage time.  I need a way for my gui to display from machine 
bootup until
shutdown and through multiple logins and logouts of the web browsing account.  
I am
familiar with kiosk setups but I dont know how to code my python program to 
display its
gui at the login screen and continue running through multiple sessions of users 
logging
into and out of the internet acct.

I thought making my kiosk program a daemon would work, but I cant get the gui 
to display
at the login screen and then there is the problem of having the press of a 
button on my
gui enter username and password information.

Basically, I envision the following sequence of events...
1) Machine is turned on and boots up
2) My kiosk is started (maybe as a daemon)
3) The daemon uses Tkinter to display its gui with the buttons and time
4) User drops coins and time on gui is incremented
5) User presses the start button
6) My program logs the user into the Internet account
7) Secure firefox is started
8) My program starts counting down the time on the gui
9) When the time reaches 0, the user is logged out
When the user presses stop on my gui, they are logged out
 The user can drop more coins at any time during the session to prolong the 
session
10) Timer resets to 0 awaiting the next customer to drop coins

Any help on how to display my gui and log into an account using python would be 
much
appreciated.
Cheers -Jon

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


Re: Strange email.Parser error?

2005-08-18 Thread Andrey Smirnov
Ah - this makes more sense.

Did the implementation of 'fp' file-like object change in 2.4.1 and it
no longer has a read()?

Andre.

Anthony Botrel wrote:
> Hi,
> 
> in the call fp.read(8192) the function read() gets 2 arguments :  and 
> <8192>
> 
> Member functions implicitely get their object as first argument, this
> is why you get this error. So you have 2 possibilities : either read()
> doesn't take an argument anymore, or read() is not a member of fp.
> 
> Anthony B.
> 
> On 8/18/05, Andrey Smirnov <[EMAIL PROTECTED]> wrote:
> 
>>I am getting the following traceback after upgrading my app to Python
>>2.4.1.  It's telling me that there is an error in Parser.py.  It tells
>>me that 'fp.read(8192)' is given 2 arguments, but it is clearly not
>>true.  Does anybody know what's going on here?
>>
>>Traceback (most recent call last):
>>  File "/opt/etext/lib/python2.4/site-packages/etext/enqueue.py", line
>>252, in work
>>worker(e.linkval, info)
>>  File "/opt/etext/bin/etreceive", line 30, in worker
>>result = decode.searchfile(f)
>>  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
>>43, in searchfile
>>return Email(f)
>>  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
>>510, in __init__
>>self.child.append(Email(mf))
>>  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
>>404, in __init__
>>msg = Parser().parse(f)
>>  File "/opt/etext/lib/python2.4/email/Parser.py", line 65, in parse
>>data = fp.read(8192)
>>TypeError: read() takes exactly 1 argument (2 given)
>>
>>Thanks,
>>Andre.
>>
>>--
>>
>>--
>>http://mail.python.org/mailman/listinfo/python-list
>>

-- 


_/_/_/   _/_/  _/ _/ Andre Smirnov
   _/   _/_/  _/_/   _/  CNS - DSE
  _/_/_/   _/_/  _/  _/ _/   303 272-8352 / x78352
 _/   _/_/  _/   _/_/Mailstop: UBRM05-203
_/_/_/_/_/_/   _/ _/

500 Eldorado boulevard
Broomfield, CO 80021





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


Re: Bug in slice type

2005-08-18 Thread Steven Bethard
I wrote:
> I wanted to say something about what happens with a negative stride, to 
> indicate that it produces (9, -1, -2) instead of (-1, -11, -2), but I 
> wasn't able to navigate the Python documentation well enough.
> 
> Looking at the Language Reference section on the slice type[1] (section 
> 3.2), I find that "Missing or out-of-bounds indices are handled in a 
> manner consistent with regular slices." So I looked for the 
> documentation of "regular slices".  My best guess was that this meant 
> looking at the Language Reference on slicings[2].  But all I could find 
> in this documentation about the "stride" argument was:
> 
> "The conversion of a proper slice is a slice object (see section 3.2) 
> whose start, stop and step attributes are the values of the expressions 
> given as lower bound, upper bound and stride, respectively, substituting 
> None for missing expressions."
> 
> This feels circular to me.  Can someone help me find where the semantics 
> of a negative stride index is defined?

Well, I couldn't find where the general semantics of a negative stride 
index are defined, but for sequences at least[1]:

"The slice of s from i to j with step k is defined as the sequence of 
items with index x = i + n*k such that 0 <= n < (j-i)/k."

This seems to contradict list behavior though.
 range(10)[9:-1:-2] == []
But the values of n that satisfy
 0 <= n < (-1 - 9)/-2 = -10/-2 = 5
are 0, 1, 2, 3, 4, corresponding to the x values of 9, 7, 5, 3, 1.  But
 [range(10)[x] for x in [9, 7, 5, 3, 1]] == [9, 7, 5, 3, 1]
Does this mean that there's a bug in the list object?

STeVe

[1] http://docs.python.org/lib/typesseq.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pickle.load not working?

2005-08-18 Thread [EMAIL PROTECTED]
oh, well how do I make "derek" be an instance of 'chatuser' ?

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


Implementing class methods in C

2005-08-18 Thread nmichaud

I am having a problem implementing some methods of a python class in C.
The class is defined in python, but I would like to rewrite some methods
in c. Here is an example of what I want to do:

file _test.c:

#include 

static PyObject *
func2(PyObject *self, PyObject *args)
{
  if (self == NULL) {
PyErr_SetString(PyExc_SystemError, "self is NULL");
return NULL;
  }

  // Parse arguments
  if (!PyArg_ParseTuple(args, ""))
  {
return NULL;
  }

  Py_INCREF(Py_None);
  return Py_None;
}

static PyMethodDef TestMethods[] = {
  {"func2", func2, METH_VARARGS, "func2."},
  {NULL, NULL, 0, NULL} /* Sentinel */
};

PyMODINIT_FUNC
init_test(void)
{
  (void) Py_InitModule("_test", TestMethods);
}


test.py:

class Test:
  def func1(self):
print "I am in func 1"

import _test
import new
Test.func2 = new.instancemethod(_test.func2, None, Test)
del(new)

t = Test()
t.func2()


When I run test.py, I get a SystemError exception (which is what I raise
if self is NULL). I think my confusion lies in the use of PyObject* self
in the function declaration. Shouldn't this be set to point to the
instance of class Test that I am calling it from? Am I misunderstanding
the purpose of PyObject* self? Thanks.

Naveen

-
Naveen Michaud-Agrawal
Program in Molecular Biophysics
Johns Hopkins University
(410) 614 4435
-- 
http://mail.python.org/mailman/listinfo/python-list


Put a url in a browsers address bar

2005-08-18 Thread Colin Gillespie
Dear All,

I would like to place a url in my browsers address bar, then execute. 
How can do this?

e.g.

def goToGoogle():
url = "www.google.com"
b = openBrowser()
b.goToUrl(url)  
return True

Thanks for any help

Colin


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


Re: gnuplot-py: plotoutput in string?

2005-08-18 Thread Grant Edwards
On 2005-08-18, Nicola Kaiser <[EMAIL PROTECTED]> wrote:

> I´m using Gnuplot via gnuplot.py and I´m looking for a way to get the 
> plotting output (terminal set to png in my case) piped in a string 
> instead of to stdout or a file.

Plotting to a file and then reading the file is pretty trivial:

  import Gnuplot,time

  filename = 'foo.png'
  p = Gnuplot.Gnuplot()
  p('set term png')
  p('set out "%s"' % filename)
  p.plot('sin(x)')
  p('set out')
  time.sleep(0.1)  # wait for gnuplot to process all the commands
  s = open(filename,'rb').read()

Since gnuplot is running asycnronously and reading commands
from a pipe, you've got to give it some time to finish
executing the commands before you attempt to read the file.
  
> Is there any method in gnuplot.py that does this for me?

I don't think so.

> If not, I tried something like:
>
> p=Gnuplot.Gnuplot(debug=1)
> p('set terminal png')
> oldstdout=sys.stdout
> output=cStringIO.StringIO()
> sys.stdout=output
> p.plot([[1,0],[2,50],[3,0],[4,20],[5,0],[6,30],[7,70], [8,70], [9, 75], 
> [10, 50], [11, 30], [12, 50]])
> sys.stdout=oldstdout
> print output.getvalue()

That's not going to work.

The gnuplot engine isn't a Python program.  It's not writing to
sys.stdout, it's writing to Unix file descriptor 1.  In order
to do things the way you're attempting to, you'd have to
redirect file descriptor 1 to a pipe before you start the
gnuplot engine, then read the plot data from the pipe.

The Gnuplot module may already be redirecting the gnuplot
processes output file descriptors, so attempting to do it
yourself might not work anyway.

> But unfortunately I also get other stuff like:
>
> "gnuplot: unable to open display ''
> "gnuplot: X11 aborted"
>
> in the same string
>
> Can anyone help me on this?

You shouldn't have gotten messages about the X11 terminal
driver if you really had set the terminal type to png.

-- 
Grant Edwards   grante Yow!  Are you selling NYLON
  at   OIL WELLS?? If so, we can
   visi.comuse TWO DOZEN!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Confused newbie needs help with "__init__() takes exactly 11 arguments (1 given)"

2005-08-18 Thread [EMAIL PROTECTED]
That's great, but it seems like a lot of work just to read in
everything. Take a look at the sample that I did with the
interpreter...

First, X is a simulated input line...
---
x = "
param1,param2,param3,param4,param5,param6,param7,param8,param9,comments
blah , blah, test"
---
Ok, so just like your first example, with commas in the comments.
Next, let's parse that into the variables and seperate on the commas...
without using the CSV module..
---
param1, param2, param3, param4, param5, param6, param7, param8, param9,
comments = x.split(',',9)
---
Simply, this splits on the commas, up to 9 times. So, no need to fix
your input text. Now, the output...
---
f.write(param1 + " " + param2 + " " + param3 + " " + param4 + " " +
param5 + " " + param6 + " " + param7 + " " + param8 + " " + param9 + "
" + "\"" comments + "\"" + "\n")
---
Writes the file, no commas except in the comments, and the comments are
enclosed in quote marks. Also, the line ends in a CR+LF (depending on
O/S).

Is that something similar to what you were looking for? It doesnt look
like your file is properly formatted for CSV, hence I suggest not using
the CSV module. If you want to make your file CSV compatible, it should
have quotation marks around the comments, as they could include commas.

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


Re: Put a url in a browsers address bar

2005-08-18 Thread Alan Kemp

On Thu, 18 Aug 2005 12:01:16 -0400, Colin Gillespie  
<[EMAIL PROTECTED]> wrote:

> I would like to place a url in my browsers address bar, then execute.
> How can do this?
>
> e.g.
>
> def goToGoogle():
>   url = "www.google.com"
>   b = openBrowser()
>   b.goToUrl(url)  
>   return True
>

def goToGoogle():
import webbrowser
webbrowser.open("www.google.com");

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


Re: Implementing class methods in C

2005-08-18 Thread Jeremy Moles
I honestly don't know the answer to this and I am entirely guessing
but--does it work without using the new module? That is:



import _test

class Foo:
pass

foo = Foo()

foo.bar = _test.func2

foo.bar()

On Thu, 2005-08-18 at 12:09 -0400, [EMAIL PROTECTED] wrote:
> I am having a problem implementing some methods of a python class in C.
> The class is defined in python, but I would like to rewrite some methods
> in c. Here is an example of what I want to do:
> 
> file _test.c:
> 
> #include 
> 
> static PyObject *
> func2(PyObject *self, PyObject *args)
> {
>   if (self == NULL) {
> PyErr_SetString(PyExc_SystemError, "self is NULL");
> return NULL;
>   }
> 
>   // Parse arguments
>   if (!PyArg_ParseTuple(args, ""))
>   {
> return NULL;
>   }
> 
>   Py_INCREF(Py_None);
>   return Py_None;
> }
> 
> static PyMethodDef TestMethods[] = {
>   {"func2", func2, METH_VARARGS, "func2."},
>   {NULL, NULL, 0, NULL} /* Sentinel */
> };
> 
> PyMODINIT_FUNC
> init_test(void)
> {
>   (void) Py_InitModule("_test", TestMethods);
> }
> 
> 
> test.py:
> 
> class Test:
>   def func1(self):
> print "I am in func 1"
> 
> import _test
> import new
> Test.func2 = new.instancemethod(_test.func2, None, Test)
> del(new)
> 
> t = Test()
> t.func2()
> 
> 
> When I run test.py, I get a SystemError exception (which is what I raise
> if self is NULL). I think my confusion lies in the use of PyObject* self
> in the function declaration. Shouldn't this be set to point to the
> instance of class Test that I am calling it from? Am I misunderstanding
> the purpose of PyObject* self? Thanks.
> 
> Naveen
> 
> -
> Naveen Michaud-Agrawal
> Program in Molecular Biophysics
> Johns Hopkins University
> (410) 614 4435

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


(OT) Is there something that people can use instead of full blown Python to run Python programs?

2005-08-18 Thread Nathan Pinno



Hi all,
 
Is there something besides the full blown version of Python that people can 
use to run Python programs, or do they have to use the full blown version of 
it?
 
Thanks,
Nathan
---Early to 
bed,Early to rise,Makes a man healthy, wealthy, and wise.--Benjamin 
Franklin---
Languages I know: Python
Languages I am learning: C++. Java, _javascript_
BEGIN:VCARD
VERSION:2.1
N:Pinno;Nathan;Paul;Mr.
FN:Pinno, Nathan Paul
NICKNAME:Spam_swatter
ORG:Woffee;Executive
TITLE:Owner/operator
TEL;WORK;VOICE:7806085529
TEL;CELL;VOICE:7806085529
ADR;WORK:;President/CEO;Box 1783;Camrose;Alberta;T4V1X7;Canada
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:President/CEO=0D=0ABox 1783=0D=0ACamrose, Alberta T4V1X7=0D=0ACanada
ADR;HOME:;;Box 1783;Camrose;Alberta;T4V1X7;Canada
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:Box 1783=0D=0ACamrose, Alberta T4V1X7=0D=0ACanada
X-WAB-GENDER:2
URL;HOME:http://falcon3166.tripod.com
URL;WORK:http://zoffee.tripod.com
BDAY:19850221
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
REV:20050818T162311Z
END:VCARD
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: List of string

2005-08-18 Thread [EMAIL PROTECTED]
to quote you :
"['0134314244133', '132443', '234']

2nd and 3rd strings are also substrings from the 1st one , so it should
be removed "

Actually, no, the 2nd string does not substring match the first, nor
does the 3rd.  If you are referring to matching individual characters,
then yes, characters 1 2 3 4 are in the first string. In that case you
would want to use the replace() function. Just specify the characters
you want to strip as the first arguement to "replace()".  See the
example below...

>>>x = "this is not a test"
>>>x.replace("t","") #delete the letter t
'his is no a es'
>>> x.replace("not ","")
'this is a test'
>>> x.replace("notas","") # wont work because it treats the first arg as a 
>>> string, not a list of characters
'this is not a test'

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


Re: Put a url in a browsers address bar

2005-08-18 Thread Colin Gillespie
> 
>> I would like to place a url in my browsers address bar, then execute.
>> How can do this?
>>
> 
> def goToGoogle():
> import webbrowser
> webbrowser.open("www.google.com");
> 

Thanks for the quick reply. Do you know what module I would use to fill 
out a form on an open web page?

Thanks

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


Re: New to python

2005-08-18 Thread Alessandro Bottoni
pcaro8a wrote:
> I am new to python I am trying to install the numeric library and I
> get the following error:
> 
> error: Python was built with version 6 of Visual Studio, and
> extensions need to
> be built with the same version of the compiler, but it isn't installed.
> 
> Do I need Visual Studio to make this work or is there any other reason
> for this message?

Well, the message is clear: the Python interpreter and PyNumeric were not
built with the same version of the MS compiler. Did you get both of them
from the same repository? Did you check the python version required by
PyNumeric before installing it? If so, try to contact the PyNum people and
ask for help.

BTW: to fix this problem, you should either:
1) borrow a copy of VC6.X and (re)compile PyNumeric with it (or find someone
that can do this for you on the Net. Do not look at me: I'm using Linux.)
2) compile both the Python interpreter and PyNumeric with the same compiler,
using a compiler of your choice (as long as it is a supported ANSI C
compiler)

Given the open source nature of Python you _could_ download its source and
recompile the interpreter with the compiler of your choice. You can do the
same with its extensions. Unfortunately, as you can imagine, compiling the
interpreter and its extension from their sources can be quite hard, in
particular if you have to use a compiler other from the standard (MSVC on
Windows, I think).

Should you be forced to recompile your stuff, have a look at the
www.python.org site and at the official documentation. You will find a
section devoted to the task of compiling python from source with a list of
the supported compilers (and have a experienced C programmer at hand, if
possible).

HTH

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


Re: (OT) Is there something that people can use instead of full blown Python to run Python programs?

2005-08-18 Thread Gregory Piñero
I'm no expert, but I'm guessing you could compile a python with less libraries.  I bet that would slim it down a lot.

-Greg
On 8/18/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:







Hi all,
 
Is there something besides the full blown version of Python that people can 
use to run Python programs, or do they have to use the full blown version of 
it?
 
Thanks,
Nathan
---Early to 
bed,Early to rise,Makes a man healthy, wealthy, and wise.--Benjamin 
Franklin---
Languages I know: Python
Languages I am learning: C++. Java, _javascript_

--http://mail.python.org/mailman/listinfo/python-list 
-- Gregory PiñeroChief Innovation OfficerBlended Technologies(www.blendedtechnologies.com
)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Put a url in a browsers address bar

2005-08-18 Thread Peter Hansen
Colin Gillespie wrote:
>>
>>> I would like to place a url in my browsers address bar, then execute.
>>> How can do this?
>>>
>>
>> def goToGoogle():
>> import webbrowser
>> webbrowser.open("www.google.com");
>>
> 
> Thanks for the quick reply. Do you know what module I would use to fill 
> out a form on an open web page?

The answer involves Google again, but this time it is "Use Google Groups 
to search the archives for previous answers to questions like yours", 
which is good advice to follow most of the time when you have a question 
that seems likely to have been asked before.

Try this search pattern for a start "python fill out form on web page".

(Note, Google Groups, not just Google.)

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


Re: question about binary and serial info

2005-08-18 Thread nephish
i got the bitwise part, i just cant seem to convert the incomming ascii
into hex, binary, integer, or decimal.
how do i do this, my serial port bytes just come in all weird looking
ascii characters
thanks

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


Re: Testing for presence of arguments

2005-08-18 Thread Madhusudan Singh
Peter Maas wrote:

>> Thanks for the suggestion, but seems needlessly complicated for
>  > something very simple.
> 
> What is "very simple"? The problem or the solution? :) If you examine

The form of the solution.

> this suggestion more closely you will note that it is more or less
> the same as Benji York's one except Benji used a built-in class.

Many good solutions have some similarity. From the point of view of a user
trying to include some simple functionality in a already complicated
application, Benji's answer was most definitely more useful.

> 
> If you are interested in getting help on usenet you should abstain
> from devaluating efforts to give you a useful reply. "Thanks for
> the suggestion" or even no answer would have been sufficient.
> 

One might have thought that a truthful assessment would have been
appreciated at the other end. I myself help people on the Usenet on some
other newsgroups, and am usually welcoming of responses that offer a
relevant criticism. The exchange improves me as much as it improves them.

Thanks for the suggestion, anyways :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implementing class methods in C

2005-08-18 Thread nmichaud

Nope, it still doesn't work. Anyway, that's not exactly what i want, since
i want func2 to be accessible from all instances of Test()

Naveen

On Thu, 18 Aug 2005, Jeremy Moles wrote:

> I honestly don't know the answer to this and I am entirely guessing
> but--does it work without using the new module? That is:
>
> 
>
> import _test
>
> class Foo:
>   pass
>
> foo = Foo()
>
> foo.bar = _test.func2
>
> foo.bar()
>
> On Thu, 2005-08-18 at 12:09 -0400, [EMAIL PROTECTED] wrote:
> > I am having a problem implementing some methods of a python class in C.
> > The class is defined in python, but I would like to rewrite some methods
> > in c. Here is an example of what I want to do:
> >
> > file _test.c:
> >
> > #include 
> >
> > static PyObject *
> > func2(PyObject *self, PyObject *args)
> > {
> >   if (self == NULL) {
> > PyErr_SetString(PyExc_SystemError, "self is NULL");
> > return NULL;
> >   }
> >
> >   // Parse arguments
> >   if (!PyArg_ParseTuple(args, ""))
> >   {
> > return NULL;
> >   }
> >
> >   Py_INCREF(Py_None);
> >   return Py_None;
> > }
> >
> > static PyMethodDef TestMethods[] = {
> >   {"func2", func2, METH_VARARGS, "func2."},
> >   {NULL, NULL, 0, NULL} /* Sentinel */
> > };
> >
> > PyMODINIT_FUNC
> > init_test(void)
> > {
> >   (void) Py_InitModule("_test", TestMethods);
> > }
> >
> > 
> > test.py:
> >
> > class Test:
> >   def func1(self):
> > print "I am in func 1"
> >
> > import _test
> > import new
> > Test.func2 = new.instancemethod(_test.func2, None, Test)
> > del(new)
> >
> > t = Test()
> > t.func2()
> >
> >
> > When I run test.py, I get a SystemError exception (which is what I raise
> > if self is NULL). I think my confusion lies in the use of PyObject* self
> > in the function declaration. Shouldn't this be set to point to the
> > instance of class Test that I am calling it from? Am I misunderstanding
> > the purpose of PyObject* self? Thanks.
> >
> > Naveen
> >
> > -
> > Naveen Michaud-Agrawal
> > Program in Molecular Biophysics
> > Johns Hopkins University
> > (410) 614 4435
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (OT) Is there something that people can use instead of full blown Python to run Python programs?

2005-08-18 Thread Alan Kemp
On Thu, 18 Aug 2005 12:38:30 -0400, Gregory Piñero <[EMAIL PROTECTED]>  
wrote:

> I'm no expert, but I'm guessing you could compile a python with less
> libraries. I bet that would slim it down a lot.
>
> -Greg
>
>
> On 8/18/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:
>>
>> Hi all,
>>  Is there something besides the full blown version of Python that people
>> can use to run Python programs, or do they have to use the full blown
>> version of it?
>>  Thanks,
>> Nathan


Alternativly, use something like  
http://starship.python.net/crew/theller/py2exe/ to convert into a native  
executable.  Of course this depends on whether your question was intended  
as "how can people run some python script", or "how can people run my  
python script".

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


Re: how do i add a new path into sys.path?

2005-08-18 Thread Steve Holden
apa wrote:
> You can do it this way:
> 
> sys.path.append("C:\Temp")
> 
> Alejandro
> 
Better:

sys.path.append("C:\\Temp")

or

sys.path.append(r"C:\Temp")

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: List of string

2005-08-18 Thread BranoZ
Dennis Lee Bieber wrote:
> On Thu, 18 Aug 2005 13:30:45 +0200, Mohammed Altaj <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>
> > Thanks , but , this work for an ordered substrings , just like what we
> > had   ['0132442\n', '13\n', '24\n'] , I would like to remove all
> > substrings from the list , example
> >
> > ['0134314244133', '132443', '234']
> >
> >
> > 2nd and 3rd strings are also substrings from the 1st one , so it should
> > be removed
> >
>
>   One of us must be using a non-standard definition of "substring" as
> "234" does not appear anywhere within either "132443" or
> "0134314244133".

I don't understand "234" either, but I can see some pattern in
"132443".

"132443" is a 'subsubstring' "0134314244133" because:

0134314244133
-#####-#-

Maybe "234" is just a typo, and it should be "243".

def subsubstr(a, b):
  if b == '':
return True
  if a == '':
return False
  else:
if a[0] == b[0]:
  return subsubstr(a[1:], b[1:])
else:
  return subsubstr(a[1:], b)

I can give you more efficient, index-based sulution, but this
one looks nicer.

BranoZ

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


Re: question about binary and serial info

2005-08-18 Thread Grant Edwards
On 2005-08-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> i got the bitwise part, i just cant seem to convert the
> incomming ascii into hex, binary, integer, or decimal.

So you've got an ASCII string in one format and you want to
convert into an ASCII string in a different format?  

For example you want to convert the string "FF" into the string "255"?

> how do i do this, my serial port bytes just come in all weird
> looking ascii characters

-- 
Grant Edwards   grante Yow!  It's OKAY -- I'm an
  at   INTELLECTUAL, too.
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (OT) Is there something that people can use instead of full blown Python to run Python programs?

2005-08-18 Thread Nathan Pinno



I was thinking something like Java's Runtime Environment, but that might 
also do.
 
Thanks,
Nathan Pinno
---Early to 
bed,Early to rise,Makes a man healthy, wealthy, and wise.--Benjamin 
Franklin---Languages 
I know: Python, EnglishLanguages I am learning: C++, Java, _javascript_

  - Original Message - 
  From: 
  Gregory 
  Piñero 
  To: Nathan Pinno 
  Cc: python-list@python.org 
  Sent: Thursday, August 18, 2005 10:38 
  AM
  Subject: Re: (OT) Is there something that 
  people can use instead of full blown Python to run Python programs?
  I'm no expert, but I'm guessing you could compile a python with 
  less libraries.  I bet that would slim it down a 
  lot.-Greg
  On 8/18/05, Nathan 
  Pinno <[EMAIL PROTECTED]> 
  wrote:
  
Hi all,
 
Is there something besides the full blown version of Python that people 
can use to run Python programs, or do they have to use the full blown 
version of it?
 
Thanks,
Nathan
---Early 
to bed,Early to rise,Makes a man healthy, wealthy, and 
wise.--Benjamin 
Franklin---
Languages I know: Python
Languages I am learning: C++. Java, _javascript_--http://mail.python.org/mailman/listinfo/python-list  -- Gregory 
  PiñeroChief Innovation OfficerBlended Technologies(www.blendedtechnologies.com ) 

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

Re: Python for Webscripting (like PHP)

2005-08-18 Thread Steve Holden
Peter Hansen wrote:
> Alessandro Bottoni wrote:
> 
>>(Python has even been told to be used by Yahoo! and Google, among others,
>>but nobody was able to demonstrate this, so far)
> 
> 
> Nobody, except Google's founders?
> 
> http://www-db.stanford.edu/~backrub/google.html
> 
> (Among many other references.)
> 
> -Peter

Plus, may I remind the world, PyCon DC 2005 had a keynote by far-from 
obscure Python supporter Greg Stein, an engineering manager at Google, 
giving a talk entitled "Python at Google".

There's informal evidence that the Python secret is getting out. Sharpen 
up your resumes, guys, you may not have to limit Python to home usage 
soon :-)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: Put a url in a browsers address bar

2005-08-18 Thread Steve Holden
Colin Gillespie wrote:
>>>I would like to place a url in my browsers address bar, then execute.
>>>How can do this?
>>>
>>
>>def goToGoogle():
>>import webbrowser
>>webbrowser.open("www.google.com");
>>
> 
> 
> Thanks for the quick reply. Do you know what module I would use to fill 
> out a form on an open web page?
> 
> Thanks
> 
> Colin
You could take a look at John Lee's ClientForm module. Start at

 http://wwwsearch.sourceforge.net/ClientForm/

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


RE: Coin-operated kiosk written in python -- need some help...

2005-08-18 Thread Sells, Fred
I've done a similar app, but it keeps a gui up awaiting a timeclock punch.
You need to tackle this in phases:
1. what os and get the gui to start at bootup.
2. start a separate thread that reads/blocks on the coin.

you need more specific questions to get better help

-Original Message-
From: Jon Monteleone [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 18, 2005 11:15 AM
To: python-list@python.org
Subject: Coin-operated kiosk written in python -- need some help...


Greetings,
I posted a few days back and didnt get much of a response, so I figured I
would post again
with more detail. I am running gnome under fedora core 4.

I want a kid to be able to drop a quarter into a coin slot and get 15
minutes of time on
an account that has "restricted" Internet access via the firefox web
browser.  We are
experimenting with different ways to allow kids to safely surf the web
during school hours
while recovering some of the cost for bandwidth.  I have written a python
program that
detects the coin drop and adds 15 minutes to a gui written in tkinter. The
gui contains 2
buttons and the usage time.  I need a way for my gui to display from machine
bootup until
shutdown and through multiple logins and logouts of the web browsing
account.  I am
familiar with kiosk setups but I dont know how to code my python program to
display its
gui at the login screen and continue running through multiple sessions of
users logging
into and out of the internet acct.

I thought making my kiosk program a daemon would work, but I cant get the
gui to display
at the login screen and then there is the problem of having the press of a
button on my
gui enter username and password information.

Basically, I envision the following sequence of events...
1) Machine is turned on and boots up
2) My kiosk is started (maybe as a daemon)
3) The daemon uses Tkinter to display its gui with the buttons and time
4) User drops coins and time on gui is incremented
5) User presses the start button
6) My program logs the user into the Internet account
7) Secure firefox is started
8) My program starts counting down the time on the gui
9) When the time reaches 0, the user is logged out
When the user presses stop on my gui, they are logged out
 The user can drop more coins at any time during the session to prolong
the session
10) Timer resets to 0 awaiting the next customer to drop coins

Any help on how to display my gui and log into an account using python would
be much
appreciated.
Cheers -Jon

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


---
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Webscripting (like PHP)

2005-08-18 Thread Scott Kilpatrick
Alessandro Bottoni wrote:
> (Python has even been told to be used by Yahoo! and Google, among others,
> but nobody was able to demonstrate this, so far)

If you use Yahoo! Maps, you will notice they use Python.

Scott

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


Re: Put a url in a browsers address bar

2005-08-18 Thread Steve Holden
Colin Gillespie wrote:
>>>I would like to place a url in my browsers address bar, then execute.
>>>How can do this?
>>>
>>
>>def goToGoogle():
>>import webbrowser
>>webbrowser.open("www.google.com");
>>
> 
> 
> Thanks for the quick reply. Do you know what module I would use to fill 
> out a form on an open web page?
> 
> Thanks
> 
> Colin
Oops. ClientForm expects you to be interacting directly with the server, 
not driving an open browser window. To do the same thing through the 
browser would involve using COM, I suspect. If so be careful, as what 
you implement may end up being browser-specific.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: List of string

2005-08-18 Thread bryanjugglercryptographer

BranoZ wrote:
> "132443" is a 'subsubstring' "0134314244133" because:

For the record, that's called a "subsequence".

  http://www.google.com/search?hl=en&q=subsequence


-- 
--Bryan

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


Re: question about binary and serial info

2005-08-18 Thread nephish
i have an ascii string comming in the serial port and i need to convert
it to something else, like an integer, or binary, or even a hex so i
can use the bitwise comparison on it.
thanks

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


Re: Some questions

2005-08-18 Thread Thomas Ganss
Cameron Laird schrieb:
> In article <[EMAIL PROTECTED]>,
> Alessandro Bottoni  <[EMAIL PROTECTED]> wrote:
> 
>>Titi Anggono wrote:
>>>1. Can we use Tkinter for web application such as Java?
...
> ... or, if you mean, "is Python an apt language for client-side
> Web development in the way Java is, with the market-leading 
> browsers all embedding JVMs which can interpret class definitions",
> the answers is, "No."  And also "Yes".  
> 
> Standard Python is *not* good for client-side Web work.  Jython is,
> though.
My blind guess would have been that Tkinter was *not* the GUI of choice
for *J*ython. A quick googling turned up only Tkinter for *JP*ython 1.1
- am I [status relative python/jython newbie] missing here something ?


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


Bitwise operations in Python?

2005-08-18 Thread Carl
Dear friends,

I am currently porting a fortran program to Python but am stuck on the
intrinsic IBITS function. 

Does anyone know about a replacement function for IBITS in Python?

Yours, Carl





IBITS(I, POS, LEN)

Extracts a sequence of bits.

I
must be of type integer.

POS
must be of type integer. It must be nonnegative and POS + LEN must be
less than or equal to BIT_SIZE (I).

LEN
must be of type integer and nonnegative. 

Class

Elemental function

Result Type and Attributes

Same as I.

Result Value

The result has the value of the sequence of LEN bits in I beginning at bit
POS, right-adjusted and with all other bits zero.

The bits are numbered from 0 to BIT_SIZE(I)-1, from right to left.

Examples

IBITS (14, 1, 3) has the value 7. 

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


Re: question about binary and serial info

2005-08-18 Thread Grant Edwards
On 2005-08-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> i have an ascii string comming in the serial port and i need to convert
> it to something else, like an integer, or binary, or even a hex so i
> can use the bitwise comparison on it.

But what do you mean by "integer", "binary", and "hex"?  

Decimal, hex, and binary are all representations of integers.

On your computer all integers are 2's compliment binary (we're
going to ignore BCD for the moment).

The only thing that can be "decimal" or "hex" are _string_
representations of integer values.

If you want something upon which you can perform the bitwise
boolean operations &, ^, |, then you most probably just want an
integer object.

To convert a string to an integer, use the int() builtin
passing it the string an an optional base:

>>> int("1234")
1234
>>> int("1234",10)
1234
>>> int("0x100",16)
256
>>> int("100",16)
256
>>> int("100",2)
4

Others have already shown you how to use the bitwise boolean
operators.

-- 
Grant Edwards   grante Yow!  Look DEEP into the
  at   OPENINGS!! Do you see any
   visi.comELVES or EDSELS... or a
   HIGHBALL??...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bitwise operations in Python?

2005-08-18 Thread Paul Rubin
Carl <[EMAIL PROTECTED]> writes:
> IBITS(I, POS, LEN)
> Extracts a sequence of bits.
> The result has the value of the sequence of LEN bits in I beginning at bit
> POS, right-adjusted and with all other bits zero.
> 
> The bits are numbered from 0 to BIT_SIZE(I)-1, from right to left.
> 
> Examples
> 
> IBITS (14, 1, 3) has the value 7. 

>>> def ibits(i,pos,len):
return (i >> pos) & ~(-1 << len)

>>> ibits(14,1,3)
7
-- 
http://mail.python.org/mailman/listinfo/python-list


Confused newbie needs help with "__init__() takes exactly 11 arguments (1 given)"

2005-08-18 Thread googleboy
Mostly I posted to try to find out more about the arguments being
passed to __init__,  and why they'd be 13 one second and 1 the next.

I also was hoping to get a little more background on what is happening
under the hood of the csv function I've plagiarised.  I haev read the
online python doco on it, but I am not really entirely sure in my own
head how it is breaking down that csv entry.

I am actually quite familiar with handling strings and lists in python,
though less so with dictionaries.

I did like your trick with telling splut to stop after 9 times.  I
hadn't seen that before.

Thanks for the response.

:-)

Googleboy

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


Re: question about binary and serial info

2005-08-18 Thread nephish
>>> import serial
>>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1)
>>> a = ser.read(1)
>>> print a
^
>>> ser.close()

>>> type(a)


>>> int(a, 16)
Traceback (innermost last):
  File "", line 1, in ?
ValueError: invalid literal for int(): ^

so i run it again the same way, only reading 4 bytes this time.

>>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1)
>>> a = ser.read(1)
>>> print a
^AÜÀ
>>> ser.close()

>>> type(a)



int(a, 16)
Traceback (innermost last):
  File "", line 1, in ?
ValueError: invalid literal for int(): ^AÜÀ

i dont understand what i am missing here.
the string character represents a hex character.

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


Re: up to date books?

2005-08-18 Thread [EMAIL PROTECTED]
I would suggest Alex Martelli's "Python in a Nutshell" or the "Python
Cookbook" as the best Python books from Oreilly.  I also like M.
Pilgrim's "Dive into Python".

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


Re: extending: new type instance

2005-08-18 Thread BranoZ
Michael Hudson wrote:
> PyObject_New is the usual way, although there are others --

Thanks for an answer !

> MyType.tp_new, PyObject_Call ...

Does this mean, that I can call my newly defined
MyType_new, MyType_init directly ??

I was afraid that Python might do some pretty important
housekeeping stuff around them.

BranoZ

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


Python jobs (was Re: Python for Webscripting (like PHP))

2005-08-18 Thread Aahz
In article <[EMAIL PROTECTED]>,
Steve Holden  <[EMAIL PROTECTED]> wrote:
>
>There's informal evidence that the Python secret is getting out. Sharpen 
>up your resumes, guys, you may not have to limit Python to home usage 
>soon :-)

OTOH, the big sucking sound from Google and Yahoo (plus other places
like Ironport) is making it more difficult to hire Python programmers in
the Bay Area...
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

The way to build large Python applications is to componentize and
loosely-couple the hell out of everything.
-- 
http://mail.python.org/mailman/listinfo/python-list


certificate-based authentication

2005-08-18 Thread Dennis . Hoffman
I have been using XML-RPC to get information from one of our remote
servers.  To improve security, the server now has a certificate installed,
and when I try to access it, I get an 'Unauthorized' exception.  Is there
an xmlrpclib module that supports (client-side) certificate-based
authentication?  If so, where can I get it, and what  is involved in doing
the  authentication? If not, what are my options?

thanks

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


Re: question about binary and serial info

2005-08-18 Thread Grant Edwards
On 2005-08-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

 import serial
 ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, 
 stopbits=1)
 a = ser.read(1)
 print a
> ^

That's not a hex number.  Hex numbers are composed of '0-9A-F'

0F48A is a hex number. ^ is not a hex number.

 ser.close()
>
 type(a)
>
>
 int(a, 16)
> Traceback (innermost last):
>   File "", line 1, in ?
> ValueError: invalid literal for int(): ^

No big surprise there.  We've already seen that a is bound to
the string '^', and that isn't a hex number.

> so i run it again the same way, only reading 4 bytes this time.

It doesn't matter how many bytes you read.  If what you're
reading isn't a hex number, more of it still isn't a hex number.

 ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, 
 stopbits=1)
 a = ser.read(1)
 print a
> ^AÜÀ
 ser.close()
>
 type(a)
>
>
>
> int(a, 16)
> Traceback (innermost last):
>   File "", line 1, in ?
> ValueError: invalid literal for int(): ^AÜÀ

Again, not a hex number.  Hex numbers consist only of 0-9A-F.
Hex numbers do not contain ^ Ü or À.

> i dont understand what i am missing here. the string character
> represents a hex character.

No, it doesn't.  "Hex" is a base-16 string representation
consisting of the digits 0-9 and A-F[1].  The strings you're
reading are clearing not hex, since they consist of characters
other than 0-9 and A-F.  You appear to be reading binary data
of some sort.

If you want to convert a string of 4 8-bit bytes (which is what
you get when you do whatever.read(4)) integer, then you need to use the
struct module.  You're going to need to know whether the data
are being transmitted least significant byte first or most
significant byte first.

  http://www.python.org/doc/current/lib/module-struct.html

If all you want is to convert a single character (what you get
when you call whatever.read(1)), then all you need is the ord()
builtin:

 http://www.python.org/doc/current/ref/types.html#l2h-51


[1] Unless you're got base-16 hardware (which you don't), then
the native hardware representation is hex.

-- 
Grant Edwards   grante Yow!  .. My pants just went
  at   on a wild rampage through a
   visi.comLong Island Bowling Alley!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-18 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
import serial
ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1)
a = ser.read(1)
print a

It sounds like you want to convert characters into their corresponding 
integer values.  To do this, use the ord() builtin function.

 >>> ord('^')
94

Then you can do the bitwise operations you want.

(Of course, you might be looking for the struct module (see the docs on 
that) instead of just ord().  That would be the case if you want to 
convert more than one character at a time, to some numeric value.)

If this is what you want, part of the confusion was your calling the 
incoming data a "string" when it's really a series of characters, which 
you will be dealing with individually.

Another part of the confusion was referring to ASCII.  From the looks of 
things, your data is just bytes, not ASCII.  ASCII refers not to the 
bytes themselves, but to the meaning assigned to those bytes for certain 
purposes.  For example, the bytes 70, 111, and 111 are just three bytes, 
with no particular meaning to anyone.  If you want to treat them as 
ASCII, however, they represent these three characters: "Foo".  Your data 
looks like chunk when treated as ASCII, so it's probably just bytes.

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


  1   2   >