Re: Run Python app at startup

2008-03-02 Thread Gabriel Genellina
En Sun, 02 Mar 2008 19:37:35 -0200, SMALLp <[EMAIL PROTECTED]> escribi�:

> Hy.
> I create simple application. Yust an windows and "compile" it with
> py2exe. I add registry  value
> reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run  
> /v
> MyApp /t REG_SZ /d C:\myapp.exe /f'
>
> And it wont start. When i use console instead od window in py2exe i get
> console opend but it closes.

I'd check in this order:

python prog.py
Then, use console=... in setup.py, generate prog.exe
Open a cmd window and execute prog.exe (from the dist directory)
Repeat using window=... in setup.py

That whole sequence works fine using on my WinXP SP2 + Python 2.5.1  
+ wxPython 2.8.7.1

-- 
Gabriel Genellina

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

Re: Character Problem

2008-03-02 Thread Marc 'BlackJack' Rintsch
On Mon, 03 Mar 2008 04:27:52 +0200, Harun BAYKAL wrote:

> I am studying on an addon developed for QGIS, a GIS software. But I
> have a problem. The extension has been developed with QT and Python.
> Actually Python is used for the interface design. For the user
> interface Python reads some values from some database files. I am not
> experienced Python user and the first developer of the addon had
> written the python codes for his database. And his database
> doesn't include any characters than the usual characaters. But my
> database file contains many characters which are not used in English.
> So I can not compile the extension because Python can not read the
> database files.
> 
> So how can I change the python files for making it to read the
> databases without modifying the database. Otherwise I had to clear all
> the non usual characters from the database file which means most of
> the names and strings will be wrong. So somehow I had to make the
> python files to read the other unicode and non english characters?
> Anybody have any idea about how I can I fix such a problem.

All I get from this description is, that you have a problem with encodings
but what is the *specific* problem?  Where does the program fail?  With
what exception(s)?

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


Re: Is it possible to return a variable and use it...?

2008-03-02 Thread Marc 'BlackJack' Rintsch
On Sun, 02 Mar 2008 20:15:10 -0800, Nathan Pinno wrote:

> Hello all,
> 
> Is it possible to return a variable and then use it like the
> following:
> [code]
> dir exp_1:
> while hen != "*"
>sum = sum + hen
> return sum
> 
> dir exp_2:
>if sum >= total_needed:
>  print "Profit can be made."
>else:
>  print "Expect a loss."
> 
> total_needed = int(raw_input("What is the total eggs needed? "))
> hen = int(raw_input("How many eggs did each hen lay? Enter them in 1
> by 1 or enter * when done. "))
> exp_1
> exp_2
> 
> [/code]
> 
> If not, then how do I do so?

Please work through the tutorial, then try to write actual Python code and
come back if you have problems with your implementation of the program. 
Show us the real code and a description of either what error message you
get, with full traceback, or if it does not raise an exception but just
does not what you excpect it to do, tell us what you expected and what you
get instead.

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


Re: class object interface document

2008-03-02 Thread Gabriel Genellina
En Mon, 03 Mar 2008 04:37:38 -0200, Neil.Fang.CN <[EMAIL PROTECTED]>  
escribió:
> On Mar 2, 6:26 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>> En Sun, 02 Mar 2008 00:55:23 -0200, Neil.Fang.CN  
>> <[EMAIL PROTECTED]>  
>> escribió:
>>
>> > Where can I find the Python class object interface document, such as
>> > struct PyClassObject, PyClass_New()? Thanks!
>>
>> PyClass_* and PyInstance_* are for old-style classes and instances  
>> respectively, and will disappear in v3.0.
>> PyInstance is in the section 7.5.2 in the Python/C API Reference  
>> Manual; I don't find any documentation on PyClass itself.

> Thanks for your reply.
> What is the counterpart in v3.0?

New style classes, that exist since v2.2
http://www.python.org/doc/newstyle/

-- 
Gabriel Genellina

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


Re: [Python-Dev] [ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-02 Thread Martin v. Löwis
>> But it would be really nice if the configure fix for 2.5 was 
>> backported to 2.4.5 since Zope is still on 2.4 and Mac OS X skipped 
>> system builds for 2.4 going direct from 2.3 -> 2.5.
> 
> 
> Yes, it would be very nice if this worked out of the box on Mac OS X 
> 10.5.2.  It's definitely a surprise for those of us who built our 2.4.4 
> on Mac OS X 10.4.x.

I can put a notice in the release notes, but I definitely won't change
it to work out of the box. If 2.4.4 compiled out of the box on this box,
it would have been a regression and would have to be fixed. IIUC, 2.4.4
won't compile on 10.5, either, and Python 2.4.5 will have no code to
port it to new platforms.

Regards,
Martin

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


Re: [Python-Dev] [ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-02 Thread Martin v. Löwis
>> Assuming no major problems crop up, a final release of Python 2.4.4 will
>> follow in about a week's time.
> 
> I do suppose you mean 2.4.5.

Oops, yes.

> 2.4.5 won't build for me from the svn checkout on Mac OS X 10.5.2:
> 
> gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp 
> -mno-fused-madd -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. 
> -I./Include  -DPy_BUILD_CORE  -c ./Modules/posixmodule.c -o 
> Modules/posixmodule.o
> ./Modules/posixmodule.c: In function ‘posix_setpgrp’:
> ./Modules/posixmodule.c:3145: error: too few arguments to function 
> ‘setpgrp’
> make: *** [Modules/posixmodule.o] Error 1
> 
> I can only presume I'm doing something wrong at this point, since I 
> don't consider myself a Mac OS X developer.

No. 2.4.5 just won't compile on OSX 10.5.2. This bug has been fixed for
2.5 (IIUC), but the fix was not backported (nor should it be, as it
is not relevant for security). Use OS X 10.4 if you want to use Python
2.4.

Regards,
Martin

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


Re: class object interface document

2008-03-02 Thread Neil.Fang.CN

Thanks for your reply.
What is the counterpart in v3.0?

-- Neil

On Mar 2, 6:26 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Sun, 02 Mar 2008 00:55:23 -0200, Neil.Fang.CN <[EMAIL PROTECTED]>  
> escribió:
>
> > Where can I find the Python class object interface document, such as
> > struct PyClassObject, PyClass_New()? Thanks!
>
> PyClass_* and PyInstance_* are for old-style classes and instances  
> respectively, and will disappear in v3.0.
> PyInstance is in the section 7.5.2 in the Python/C API Reference Manual; I  
> don't find any documentation on PyClass itself.
>
> --
> Gabriel Genellina

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


Re: SV: Where's GUI for Python?

2008-03-02 Thread Tim Roberts
"K Viltersten" <[EMAIL PROTECTED]> wrote:
>
>As long as we're on the subject, i also wonder
>if there's a general concensus on which 
>technology is recommended in the different 
>types of projects that are developed. (E.g. 
>"use A for small/fast fixes, use B for stuff
>you'll need to maintain later on".)

Are you talking specifically about GUI toolkits?  I seriously doubt that
anyone routinely uses more than one GUI with Python (although I'm sure
there are exceptions).  Each of them has a pretty big learning curve to
climb, and once you have climbed it, all of the GUI kits will solve the
same problems.

(Caution: the following contains gross generalities.)

If you have ever done GUI programming in Windows using the Win32 API, then
wxPython will seem more natural than Tkinter or Qt (although I should point
out that all of them work equally well on Windows and Linux).

If you have ever done GUI programming in X, or if you have done script with
with Tcl/Tk, then it is likely that Tkinter will seem more natural than
wxPython.

Perhaps the best option is to take a look at some samples, and see what
looks more natural to you.  wxPython, for instance, has a wonderful set of
demos that demonstrate almost every feature of the toolkit.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SQLLITE

2008-03-02 Thread Daniel Fetchinson
> > > I am having a minor problem when I try and do this:
> > > c.execute("insert into [tblTranscripts] (MovieID,Transcript)
> > > Values(" + movieID + ",'" + formatText + "');") (don't even bother
> > > commenting of the sql style I know its bad form but this is a simple
> > > script). Whenever I try and do the insert I get table not found,
> > > however when I perform the sql through sqlite's command line program
> > > (the sql is outputted via a print statement) it works fine. Any ideas?
> >
> > No, and without more context nobody will have. Does working with the
> > table with other statments work, how do you connect the DB, are you sure
> > you really use the same DB-file and so forth.
> >
> Beginner stuff is usually forgetting 'use moviedata'.

This is not needed for sqlite. The database is defined by the file the
sqlite executable is working on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 2.6a1 and 3.0a3

2008-03-02 Thread Tim Roberts
Kay Schluehr <[EMAIL PROTECTED]> wrote:
>
>On 2 Mrz., 06:53, Ben Finney <[EMAIL PROTECTED]>
>wrote:
>
>> One of the stated goals of the migration is that the '2to3' program
>> will only migrate Python 2.6 code -> Python 3.0 code.
>
>Yes, I know. Why?
>
>"The master said so" isn't an entirely satisfying answer.

Nevertheless, it IS the answer for many questions in the Python world.
That's the advantage of being Benevolent Dictator For Life.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import, how to change sys.path on Windows, and module naming?

2008-03-02 Thread Tim Roberts
Jeremy Nicoll - news posts <[EMAIL PROTECTED]> wrote:
>
>Does every Windows user have: 2 C:\WINDOWS\system32\python25.zip
>in their sys.path?  What's the point of having a zip in the path?

Starting with Python 2.4, Python is able to import modules directly from a
zip, as if it were a directory.  It's a very handy feature for distributing
premade packages.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Telnet formatting?

2008-03-02 Thread Jean-Paul Calderone
On Sat, 1 Mar 2008 16:51:08 -0800 (PST), [EMAIL PROTECTED] wrote:
>Hi everyone:
>
>I posted here a couple days ago looking for some help creating a
>Telnet-based chat server. You guys pointed me to Twisted, which has
>solved most of my issues.
>
>However, what I want to do is analyze strings received for keywords
>such as 'listcmds' and have the server return something to the client.
>I know how to do that part, at least.
>
>The issue is, when I use clients like PuTTY, it returns a lot of what
>appears to be formatting (e.g. if I typed Hello, it would return "\xff
>\xfb\x1f\xff\
>xfb \xff\xfb\x18\xff\xfb'\xff\xfd\x01\xff\xfb\x03\xff\xfd\x03Hello".)
>
>How would I go about filtering this stuff out of the strings? The
>thing is too, if I use other Telnet programs like Microsoft Telnet,
>they don't have this formatting, so I want to be able to recognize if
>it does have this formatting and act based on if it does or if it
>doesn't.
>
>Any help is appreciated, I know I'm probably asking too many questions
>already :)

If you're using Twisted's telnet implementation, then all of the telnet
command sequences will be handled separately from the application data.

It might help if you share some of your code.

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


Re: Python-based regular expression parser that allows patterns to call functions?

2008-03-02 Thread Paul McGuire
pyparsing also includes a decorator function, traceParseAction, which
will list out calls to parse actions, the tokens passed in, and the
value returned or exception raised.  If you add "@traceParseAction"
before each of the parse actions in my example, you can see the token
processing being done in the parse actions.

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


Is it possible to return a variable and use it...?

2008-03-02 Thread Nathan Pinno
Hello all,

Is it possible to return a variable and then use it like the
following:
[code]
dir exp_1:
while hen != "*"
   sum = sum + hen
return sum

dir exp_2:
   if sum >= total_needed:
 print "Profit can be made."
   else:
 print "Expect a loss."

total_needed = int(raw_input("What is the total eggs needed? "))
hen = int(raw_input("How many eggs did each hen lay? Enter them in 1
by 1 or enter * when done. "))
exp_1
exp_2

[/code]

If not, then how do I do so?

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


Re: tcp

2008-03-02 Thread Roy Smith
In article 
<[EMAIL PROTECTED]>,
 Gabriel Genellina <[EMAIL PROTECTED]> wrote:

> On 2 mar, 17:21, [EMAIL PROTECTED] wrote:
> 
> > This worked:
> >
> > import socket
> > from time import time
> >
> > for i in range( 20 ):
> >     HOST = ''
> >     PORT = 80 #<
> >     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> >     s.bind((HOST, PORT))
> >     print( 'listen' )
> >     s.listen(1)
> >     conn, addr = s.accept()
> >     print( 'connected', addr )
> >     print( conn.recv( 4096 ) ) #<
> >     conn.send( bytes('test %f > html>'%time(),'ascii') )
> >     conn.close() #<
> >     s.close()
> >
> > ... and connect with a browser:  http://localhost/if it's internet
> > exploder.
> 
> Note that there is no need (nor is desirable) to close and rebind the
> listening socket for each connection.

I'd say, "nor is desirable", is an understatement.  On most systems, an 
attempt to re-bind to a given port number soon after it was unbound will 
fail (unless you utter magic ioctl incantations).  This will manifest 
itself in the s.bind() call raising an exception on the *second* pass 
through the loop.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to subclass a built-in int type and prevent comparisons

2008-03-02 Thread Gabriel Genellina
En Fri, 29 Feb 2008 19:00:06 -0200, Bronner, Gregory  
<[EMAIL PROTECTED]> escribi�:

> I'm trying to create a type-safe subclass of int (SpecialInt) such that
> instances of the class can only be compared with ints, longs, and other
> subclasses of SpecialInt -- I do not want them to be compared with
> floats, bools, or strings, which the native int implementation supports.
>
> Obviously, I could overload __lt_, __eq__, __le__, etc, and write a
> bunch of boilerplate code.
>
> Should this code throw an exception if the types are not comparable?
> What would I lose by doing that?
>
> def __gt__(self, other):
>   if(other is self):
>   return False
>   if(self.__isComparable(other)):
>   return int(self)>int(other)
>   else:
>   raise ValueError(str(self) +" and "+ str(other)
> +" are not comparable")

I think that the easiest way is to write __cmp__ similar to your code  
above, and then redefine __gt__, __ge__ etc based on that.
__gt__ = lambda self, other: self.__cmp__(other)>0

Note that you have to override a lot of methods too; if x is a SpecialInt  
instance, abs(x) or x+1 will return a plain integer instead.

> Is this code likely to be efficient?

Unless you implement the above in a C extension, certainly it will run  
much slower than the original int implementation. But measure how much  
this is going to affect you.

-- 
Gabriel Genellina

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

Re: tcp

2008-03-02 Thread Gabriel Genellina
On 2 mar, 17:21, [EMAIL PROTECTED] wrote:

> This worked:
>
> import socket
> from time import time
>
> for i in range( 20 ):
>     HOST = ''
>     PORT = 80 #<
>     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>     s.bind((HOST, PORT))
>     print( 'listen' )
>     s.listen(1)
>     conn, addr = s.accept()
>     print( 'connected', addr )
>     print( conn.recv( 4096 ) ) #<
>     conn.send( bytes('test %f html>'%time(),'ascii') )
>     conn.close() #<
>     s.close()
>
> ... and connect with a browser:  http://localhost/if it's internet
> exploder.

Note that there is no need (nor is desirable) to close and rebind the
listening socket for each connection. The loop should start with the
accept call, and end at the conn.close() call (s.close() is left out
of the loop).
And then you get a pretty standard server that handles one connection
at a time.

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


Re: Where's GUI for Python?

2008-03-02 Thread Roy H. Han
Hi Konrad,

I remember taking a long time in deciding which GUI framework to use last
year and I picked wxGlade/wxPython because it seemed mature, easy to use and
easy to understand.

In the beginning I wasted a lot of time coding the GUI manually but wxGlade
lets me use the mouse to arrange the components so that I can focus on
writing the event handling code.  I mostly don't touch the code that wxGlade
auto-generates and I work my code around it.
http://wxglade.sourceforge.net/demo/

Sorry I responded to your personal email by mistake.  I pressed Reply All in
gmail.

I don't know who wrote wxGlade or wxPython but both have been real
timesavers to me.

Roy

On Sun, Mar 2, 2008 at 3:50 AM, Konrad Viltersten <[EMAIL PROTECTED]>
wrote:

> > Konrad, I use wxPython with wxGlade.
> > I love wxGlade!
> > wxGlade http://wxglade.sourceforge.net/
> > You need to look at this documentation to
> > code event handling. wxWidgets:
> > http://www.wxwidgets.org/manuals/stable/wx_classesbycat.html
> >
> > You can also try coding the GUI manually,
> > but it is much easier to use wxGlade.
> > wxPython
> > http://wiki.wxpython.org/AnotherTutorial
>
> May i ask what's the advantage in using
> wxGlade instead of the buil-in Tkinter?
>
> Also - why did you replied to my private
> email instead of to news? Is the choice of
> GUI an infected matter among the Python
> community, by any chance?
>
> --
> Regards
> Konrad Viltersten
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Organizing Books in My Amazon Cart

2008-03-02 Thread W. Watson
Anyone know of a way of listing all the books in my Amazon Shopping Cart--To 
Buy Latter? I have a considerable number, and working my way through the 
list is time consuming. Possibly someone has written a program to do it 
(Python, Perl, ...)? I have no idea if that's even possible.

I figure this is one the largest NGs in my inventory, so maybe someone has 
thought about it, or can direct me to a more likely NG for the question.
-- 
  Wayne Watson (Nevada City, CA)

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


Re: along the lines, hash and obj. id.

2008-03-02 Thread castironpi
On Feb 27, 5:38 pm, [EMAIL PROTECTED] wrote:
> On Feb 27, 4:16 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> > For a), you use something like obj.a.somemethod(). "obj.a" still refers to
> > the same object, even if it changed internally; if obj.a and foo.bar both
> > were refering to the same object, they still do. [1]
> > Or wrap the value into another shared object.
> it can still set the element there: elem.val= 0, elem.val+= 1, &c., in

Following obj.a.val is foo.bar.val and obj.a is foo.bar, you can also
get away with a= A(); a.c.val= 2; assert A.c.val== 2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Character Problem

2008-03-02 Thread Harun BAYKAL
Hi,

I am studying on an addon developed for QGIS, a GIS software. But I
have a problem. The extension has been developed with QT and Python.
Actually Python is used for the interface design. For the user
interface Python reads some values from some database files. I am not
experienced Python user and the first developer of the addon had
written the python codes for his database. And his database
doesn't include any characters than the usual characaters. But my
database file contains many characters which are not used in English.
So I can not compile the extension because Python can not read the
database files.

So how can I change the python files for making it to read the
databases without modifying the database. Otherwise I had to clear all
the non usual characters from the database file which means most of
the names and strings will be wrong. So somehow I had to make the
python files to read the other unicode and non english characters?
Anybody have any idea about how I can I fix such a problem.

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


Re: [Python-Dev] [ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-02 Thread Fred Drake
On Mar 2, 2008, at 8:35 PM, Kevin Teague wrote:
> This issue was fixed for Python 2.5. As the issue notes, you can  
> work around it with:
>
> ./configure MACOSX_DEPLOYMENT_TARGET=10.5

Indeed, that works wonderfully for me for 2.4.5.

> But it would be really nice if the configure fix for 2.5 was  
> backported to 2.4.5 since Zope is still on 2.4 and Mac OS X skipped  
> system builds for 2.4 going direct from 2.3 -> 2.5.


Yes, it would be very nice if this worked out of the box on Mac OS X  
10.5.2.  It's definitely a surprise for those of us who built our  
2.4.4 on Mac OS X 10.4.x.


   -Fred

-- 
Fred Drake   




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


Re: Altering imported modules

2008-03-02 Thread Paul McGuire
On Mar 2, 3:48 pm, Tro <[EMAIL PROTECTED]> wrote:
> On Sunday 02 March 2008, Terry Reedy wrote:
>
>
>
>
>
> > "Tro" <[EMAIL PROTECTED]> wrote in message
> >news:[EMAIL PROTECTED]
>
> > | Hi, list.
> > |
> > | I've got a simple asyncore-based server. However, I've modified the
>
> > asyncore
>
> > | module to allow me to watch functions as well as sockets. The modified
> > | asyncore module is in a specific location in my project and is imported
>
> > as
>
> > | usual from my classes.
> > |
> > | Now I'd like to use the tlslite library, which includes an asyncore mixin
> > | class. However, tlslite imports "asyncore", which doesn't include my own
> > | modifications.
> > |
> > | I'd like to know if it's possible to make tlslite load *my* asyncore
>
> > module
>
> > | without changing any of the tlslite code.
>
> > If your module is also 'asyncore' and comes earlier in the search path, I
> > would expect the import to get yours.
>
> It's not. It has a package prefix like my.package.asyncore. I think I can
> either move my version of asyncore up a couple of levels or add the
> my.package directory to sys.path.
>
> My version of asyncore imports several functions from the built-in asyncore.
> Now that my version of it is imported as asyncore, how would it import the
> built-in version from python2.5/site-packages?
>
> Thanks,
> Tro- Hide quoted text -
>
> - Show quoted text -

What happens if you do "import my.package.asyncore as asyncore"?

If that doesn't work (trying the simplest hack first), I know that
there are various hooks in the import mechanism that should help.

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


Re: [Python-Dev] [ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-02 Thread Kevin Teague
"It has to do with the MACOSX_DEPLOYMENT_TARGET. If it's set to 10.4,  
the
legacy version of setpgrp is used (with args), it it's 10.5, setpgrp
expects no arguments. It seems configure won't detect the difference."

http://bugs.python.org/issue1358

This issue was fixed for Python 2.5. As the issue notes, you can work  
around it with:

./configure MACOSX_DEPLOYMENT_TARGET=10.5

But it would be really nice if the configure fix for 2.5 was  
backported to 2.4.5 since Zope is still on 2.4 and Mac OS X skipped  
system builds for 2.4 going direct from 2.3 -> 2.5.

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


Re: Book Recomendations

2008-03-02 Thread David Lees
Ira Solomon wrote:
> I am an experienced programmer (40 years).  I've done Algol (if you've
> heard of that you must be old too), PL/1, VB,VBA, a little C, and a
> few other odd languages (e.g. Taskmate).
> I'm interested in learning Python and have downloaded a slew of books.
> Too many.
> I'd like a recommendation as to which books are considered to be the
> cream of the crop.
> I know there are tutorials on the web, but, again, I don't know the
> quality.  I would appreciate recommendations on those as well.
> 
> Thanks
> 
> Ira
Different people have different learning styles.  Two books I like are 
Wesley Chun's Core Python Programming (2nd edition) and Mangnus 
Hetland's Beginning Python.  Have fun with Python.  I discovered it 
about 7 years ago, use it by choice for my intermittent programming 
requirements and find it a pleasure to use.  Also this group is very 
helpful.

(My programming experience also goes back to Algol, Basic and assembler 
circa 1965.  Which makes me middle aged, but not necessarily experienced 
:)  )

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


Re: [Python-Dev] [ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-02 Thread Brett Cannon
On Sun, Mar 2, 2008 at 4:52 PM, Fred Drake <[EMAIL PROTECTED]> wrote:
> On Mar 2, 2008, at 7:43 PM, Fred Drake wrote:
>  > 2.4.5 won't build for me from the svn checkout on Mac OS X 10.5.2:
>
>
>  Neither does 2.3.7 now that I've tried that:
>
>  gcc  -u __dummy -u _PyMac_Error -framework System -framework
>  CoreServices -framework Foundation -o python.exe \
> Modules/python.o \
> libpython2.3.a -ldl
>  Undefined symbols:
>"__dummy", referenced from:
>  ld: symbol(s) not found
>  collect2: ld returned 1 exit status
>  make: *** [python.exe] Error 1
>
>  Of course, I wasn't using an earlier 2.3.x version on this box.  I
>  would really like to be able to use 2.4.5, since I've been using 2.4.4
>  for work for a while now.

For me on OS X 10.5.2 (gcc 4.0.1) for 2.37 I am getting a ton of:

  sem_post: Bad file descriptor
  sem_init: Function not implemented
  sem_trywait: Bad file descriptor

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


Re: [Python-Dev] [ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-02 Thread Fred Drake
On Mar 2, 2008, at 7:43 PM, Fred Drake wrote:
> 2.4.5 won't build for me from the svn checkout on Mac OS X 10.5.2:


Neither does 2.3.7 now that I've tried that:

gcc  -u __dummy -u _PyMac_Error -framework System -framework  
CoreServices -framework Foundation -o python.exe \
Modules/python.o \
libpython2.3.a -ldl
Undefined symbols:
   "__dummy", referenced from:
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [python.exe] Error 1

Of course, I wasn't using an earlier 2.3.x version on this box.  I  
would really like to be able to use 2.4.5, since I've been using 2.4.4  
for work for a while now.


   -Fred

-- 
Fred Drake   




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


Re: [Python-Dev] [ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-02 Thread Fred Drake
On Mar 2, 2008, at 4:05 PM, Martin v. Löwis wrote:
> Assuming no major problems crop up, a final release of Python 2.4.4  
> will
> follow in about a week's time.

I do suppose you mean 2.4.5.

2.4.5 won't build for me from the svn checkout on Mac OS X 10.5.2:

gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused- 
madd -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include  - 
DPy_BUILD_CORE  -c ./Modules/posixmodule.c -o Modules/posixmodule.o
./Modules/posixmodule.c: In function ‘posix_setpgrp’:
./Modules/posixmodule.c:3145: error: too few arguments to function  
‘setpgrp’
make: *** [Modules/posixmodule.o] Error 1

I can only presume I'm doing something wrong at this point, since I  
don't consider myself a Mac OS X developer.


   -Fred

-- 
Fred Drake   




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


Re: Run Python app at startup

2008-03-02 Thread dave_mikesell
On Mar 2, 3:37 pm, "SMALLp" <[EMAIL PROTECTED]> wrote:
> Hy.
> I create simple application. Yust an windows and "compile" it with
> py2exe. I add registry  value
> reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v
> MyApp /t REG_SZ /d C:\myapp.exe /f'
>
> And it wont start. When i use console instead od window in py2exe i get
> console opend but it closes.
>
> Program:
> 
> import os
> import wx
>
> app = wx.App()
> frame = wx.Frame(None, -1, "MyFrame")
> frame.Show()
>
> app.MainLoop()
> 
>
> Then in commang prompt:
>
> python.exe setup.py py2exe
>
> 
> from distutils.core import setup
> import py2exe
>
> setup(console=['prog.py'])
> 

Don't you have to include the wxPython code somehow, perhaps on the
command line when building the exe?

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


Re: First post from a Python newbiw

2008-03-02 Thread Jeff Schwab
[EMAIL PROTECTED] wrote:
> is there a better way of creating d??
 a = [[0] * 3 for dummy in xrange(3)]
>> Each element of a refers to a distinct array.
>>
>>> Why not simply [[0]*3]*3 ?
>> All three elements of the result refer to the same array.
> 
> ... whereas you reassign all three elements of [0]* 3.
> 
 ((0,)*3,)*3
> ((0, 0, 0), (0, 0, 0), (0, 0, 0))
> 
> You're safe in this one-- changing [0][0] won't change [1][0], 'cuz
> you can't!

A technically correct solution. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-03-02 Thread Jeff Schwab
Paul Rubin wrote:
> Jeff Schwab <[EMAIL PROTECTED]> writes:
>> Better yet, how hard would it be to define an otherwise int-like type
>> that did not define a non-flooring division operator?  Are there any
>> real use cases for such a type?
> 
> User defined types in python are fairly heavyweight compared with the
> built-in types,

Yet they continue to form the basis of almost all non-trivial Python 
programs.  Anyway, it's a bit soon to be optimizing. :)


> and a type like that is just another thing for the
> user to have to remember.

How so?  A well-written function generally shouldn't depending on the 
exact types of its arguments, anyway.  If someone has written a function 
to find (e.g.) the median of a collection of numbers, their code should 
already be prepared to accept values of user-defined numeric types.  If 
I want to call such a function with my hand-rolled DivisionSafeInteger 
type, it should just work, unless specifically documented to work only 
with a particular subset of Python data types.


> The C library has a bunch of different types like off_t (offset in a

off_t is vendor-specific extension, not part of the standard C library. 
  In gcc, it's a typedef for __off_t, which is a macro for _G_off_t, 
which is in turn a macro for a compiler-specific type called _IO_off_t. 
  Elsewhere, it may just be a typedef of long int.


> file) and size_t, so if you pass an off_t to a function that expects a
> size_t as that arg, the compiler notices the error.

On what compiler?  I've never seen a C compiler that would mind any kind 
of calculation involving two native, unsigned types.

 $ cat main.c
 #include 
 int main() { off_t ot = 0; long li = 3L; ot = li; }
 $ make
 cc -ansi -pedantic -Wall -std=c99main.c   -o main
 $


> But they are
> really just integers and they compile with no runtime overhead.

They do indeed have run-time overhead, as opposed to (e.g.) meta-types 
whose operations are performed at compile-time.  If you mean they have 
less overhead than types whose operations perform run-time checks, then 
yes, of course that's true.  You specifically stated (then snipped) that 
you "would be happier if int/int always threw an error."  The beauty of 
a language with such extensive support for user-defined types that can 
be used like built-in type is that you are free to define types that 
meet your needs.  The weight of such hand-rolled solutions may lead to 
performance problems at first, but C-linkable extensions go a long way 
to help; hence numpy et al.


> So, I think Python won't easily support lots of different types of
> integers, and we've got what we've got.

My understanding is that Python will easily support lots of different 
types of just about anything.  That's the point.  In theory at least, it 
supports programming in a way that lets the translator (compiler + 
interpreter) keep track of the exact types being used, so that the 
programmer doesn't have to.  The fact that the tracking is done 
dynamically, rather than statically, is a fundamental design decision 
that was made early in the language's development.


> There's an interesting talk linked from LTU about future languages:
> 
>   http://lambda-the-ultimate.org/node/1277

Thanks, but that just seems to have links to the slides.  Is there a 
written article, or a video of Mr. Sweeney's talk?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First post from a Python newbiw

2008-03-02 Thread castironpi
> >>> is there a better way of creating d??
>
> >> a = [[0] * 3 for dummy in xrange(3)]
>
> Each element of a refers to a distinct array.
>
> > Why not simply [[0]*3]*3 ?
>
> All three elements of the result refer to the same array.

... whereas you reassign all three elements of [0]* 3.

>>> ((0,)*3,)*3
((0, 0, 0), (0, 0, 0), (0, 0, 0))

You're safe in this one-- changing [0][0] won't change [1][0], 'cuz
you can't!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function Overloading and Python

2008-03-02 Thread castironpi
On Feb 25, 11:04 am, [EMAIL PROTECTED] wrote:
> > B1.fun(A(x), A(y), A(z)) == B.fun(A(x), A(y), A(z))
> > but
> > B1.fun(A1(x), A(y), A(z) != B.fun(A1(x), A(y), A(z))
>
> > Is there a data-structure solution or third party module that would
> > mimic this behavior?
>
> class B:
>    xfun= Overloaded()
>    def fun( self, *a ):
>       return self.xfun.dispatch( self, *a )
>   [EMAIL PROTECTED]( A, A, A )
>    def q( self, x, y, z ):
>       return 'B AAA'
>   [EMAIL PROTECTED]( A1, A, A )
>    def q( self, x, y, z ):
>       return 'B A1AA'
> B.xfun.push( B )

You could also call xfun.methods( self ) in B.__init__.
Overloaded.methods binds the methods specified with xfun.make to the B
instance.  In this case, the effect is,

self.fun= types.MethodType( self.__class__.[x?]fun, self ) -- I forget
by now.

But time is money, and money doesn't grow on trees-- so catch me later
with your own.

(A decorator could also do it too-- and just in the base class!)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-03-02 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes:
> Better yet, how hard would it be to define an otherwise int-like type
> that did not define a non-flooring division operator?  Are there any
> real use cases for such a type?

User defined types in python are fairly heavyweight compared with the
built-in types, and a type like that is just another thing for the
user to have to remember.

The C library has a bunch of different types like off_t (offset in a
file) and size_t, so if you pass an off_t to a function that expects a
size_t as that arg, the compiler notices the error.  But they are
really just integers and they compile with no runtime overhead.

So, I think Python won't easily support lots of different types of
integers, and we've got what we've got.  

There's an interesting talk linked from LTU about future languages:

  http://lambda-the-ultimate.org/node/1277
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mod_python Unable to create file

2008-03-02 Thread Kaushik Barat
Hey thanks a lot Sean.Setting the permissions on the directory path solved
the problem.

On Sun, Mar 2, 2008 at 11:09 AM, Sean Allen <[EMAIL PROTECTED]> wrote:

>
> On Mar 2, 2008, at 3:24 AM, kaush wrote:
>
> > On Mar 1, 11:24 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> >> On Sat, 01 Mar 2008 22:47:02 -0800, kaush wrote:
> >>> I am using Apache and mod_python to service POST/GET requests on MAC
> >>> OS. My script tries to create a file
> >>
> >>> file = open(file_path, 'w')
> >>
> >>> This fails with the following error
> >>
> >>> EACCES
> >>> Permission denied
> >>
> >>> What is missing?
> >>
> >> To state the ovious: the rights to create a file at `file_path`.
> >> Remember
> >> that web servers usually have their own "user".
> >>
> >> Ciao,
> >> Marc 'BlackJack' Rintsch
> >
> > Thanks Marc.
> > In Apache what are the ways/directives to set the rights to a folder?
>
> none. you set permissions via the operating system.
>
> chmod would be the command from terminal you are looking for.
>
> or you can do get info on the folder in question via the finder and
> set perms there.
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: First post from a Python newbiw

2008-03-02 Thread Jeff Schwab
Christoph Zwerschke wrote:
> Marc 'BlackJack' Rintsch schrieb:
>> On Sun, 02 Mar 2008 14:15:09 +, Steve Turner wrote:
>>
>>> Apart from doing something like
>>> a=[0,0,0]
>>> b=[0,0,0]
>>> c=[0,0,0]
>>> d=[a,b,c]
>>>
>>> is there a better way of creating d??
>>
>> a = [[0] * 3 for dummy in xrange(3)]

Each element of a refers to a distinct array.

> Why not simply [[0]*3]*3 ?

All three elements of the result refer to the same array.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Book Recomendations

2008-03-02 Thread Micah Cowan
Tommy Nordgren <[EMAIL PROTECTED]> writes:

> On 2 mar 2008, at 01.56, Ira Solomon wrote:
>
>> I am an experienced programmer (40 years).  I've done Algol (if you've
>> heard of that you must be old too), PL/1, VB,VBA, a little C, and a
>> few other odd languages (e.g. Taskmate).
>> I'm interested in learning Python and have downloaded a slew of books.
>> Too many.
>> I'd like a recommendation as to which books are considered to be the
>> cream of the crop.
>> I know there are tutorials on the web, but, again, I don't know the
>> quality.  I would appreciate recommendations on those as well.
>>
>> Thanks
>>
>> Ira
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>   I would recommend "Programming Python", by Mark Lutz, from O'Reillys

Programming Python assumes you already have a working knowledge of
basic Python programming (that is, it assumes you've read Learning
Python).

-- 
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First post from a Python newbiw

2008-03-02 Thread Terry Reedy

"Christoph Zwerschke" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Marc 'BlackJack' Rintsch schrieb:
| > On Sun, 02 Mar 2008 14:15:09 +, Steve Turner wrote:
| >
| >> Apart from doing something like
| >> a=[0,0,0]
| >> b=[0,0,0]
| >> c=[0,0,0]
| >> d=[a,b,c]
| >>
| >> is there a better way of creating d??
| >
| > a = [[0] * 3 for dummy in xrange(3)]
|
| Why not simply [[0]*3]*3 ?

Because that is essentially the same as what the OP originally did,
which does not work as he wanted.



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


Re: tuples, index method, Python's design

2008-03-02 Thread Roy Smith
In article 
<[EMAIL PROTECTED]>,
 Paul Boddie <[EMAIL PROTECTED]> wrote:

> On 2 Mar, 19:06, Alan Isaac <[EMAIL PROTECTED]> wrote:
> > On April 12th, 2007 at 10:05 PM Alan Isaac wrote:
> >
> > > The avoidance of tuples, so carefully defended in other
> > > terms, is often rooted (I claim) in habits formed from
> > > need for list methods like ``index`` and ``count``.
> > > Indeed, I predict that Python tuples will eventually have
> > > these methods and that these same people will then defend
> > > *that* status quo.
> 
> You were more confident about this than I was. Still, nothing happens
> if no-one steps up to do something about it.
> 
> > http://python.org/download/releases/2.6/NEWS.txt>
> >
> > - Issue #2025 :  Add tuple.count() and tuple.index()
> >
> >   methods to comply with the collections.Sequence API.
> 
> Here's the tracker item that may have made it happen:
> 
> http://bugs.python.org/issue1696444
> 
> I think you need to thank Raymond Hettinger for championing the
> cause. ;-)
> 
> Paul

Callooh! Callay!  We are delivered from one of the most long-lived and 
pointless (if minor) warts in an otherwise clean and logical type 
hierarchy.  Thank you, Raymond!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Altering imported modules

2008-03-02 Thread Tro
On Sunday 02 March 2008, Terry Reedy wrote:
> "Tro" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> | Hi, list.
> |
> | I've got a simple asyncore-based server. However, I've modified the
>
> asyncore
>
> | module to allow me to watch functions as well as sockets. The modified
> | asyncore module is in a specific location in my project and is imported
>
> as
>
> | usual from my classes.
> |
> | Now I'd like to use the tlslite library, which includes an asyncore mixin
> | class. However, tlslite imports "asyncore", which doesn't include my own
> | modifications.
> |
> | I'd like to know if it's possible to make tlslite load *my* asyncore
>
> module
>
> | without changing any of the tlslite code.
>
> If your module is also 'asyncore' and comes earlier in the search path, I
> would expect the import to get yours.

It's not. It has a package prefix like my.package.asyncore. I think I can 
either move my version of asyncore up a couple of levels or add the 
my.package directory to sys.path.

My version of asyncore imports several functions from the built-in asyncore. 
Now that my version of it is imported as asyncore, how would it import the 
built-in version from python2.5/site-packages?

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


Re: First post from a Python newbiw

2008-03-02 Thread Marc 'BlackJack' Rintsch
On Sun, 02 Mar 2008 21:58:31 +0100, Christoph Zwerschke wrote:

> Marc 'BlackJack' Rintsch schrieb:
>> On Sun, 02 Mar 2008 14:15:09 +, Steve Turner wrote:
>> 
>>> Apart from doing something like
>>> a=[0,0,0]
>>> b=[0,0,0]
>>> c=[0,0,0]
>>> d=[a,b,c]
>>>
>>> is there a better way of creating d??
>> 
>> a = [[0] * 3 for dummy in xrange(3)]
> 
> Why not simply [[0]*3]*3 ?

Because:

In [77]: a = [[0] * 3] * 3

In [78]: a
Out[78]: [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

In [79]: a[0][0] = 42

In [80]: a
Out[80]: [[42, 0, 0], [42, 0, 0], [42, 0, 0]]

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


Re: tuples, index method, Python's design

2008-03-02 Thread Christoph Zwerschke
Paul Boddie schrieb:
> On 2 Mar, 19:06, Alan Isaac <[EMAIL PROTECTED]> wrote:
>> On April 12th, 2007 at 10:05 PM Alan Isaac wrote:
>>
>>> The avoidance of tuples, so carefully defended in other
>>> terms, is often rooted (I claim) in habits formed from
>>> need for list methods like ``index`` and ``count``.
>>> Indeed, I predict that Python tuples will eventually have
>>> these methods and that these same people will then defend
>>> *that* status quo.
> 
> You were more confident about this than I was. Still, nothing happens
> if no-one steps up to do something about it.

And nobody stepped up because it had been made very clear by Guido and 
others that they don't want tuples to grow methods.

I remember there had been ridiculously excessive threads about this, 
this probably being one of many others:
http://groups.google.de/group/comp.lang.python/browse_thread/thread/430a692bc634a04f/

I don't think this was very encouraging for people who wanted to do 
something about it.

Anyway, it's good to see this happened now. Thanks to Raymond.

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


Run Python app at startup

2008-03-02 Thread SMALLp
Hy.
I create simple application. Yust an windows and "compile" it with
py2exe. I add registry  value
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v
MyApp /t REG_SZ /d C:\myapp.exe /f'

And it wont start. When i use console instead od window in py2exe i get
console opend but it closes.

Program:

import os
import wx

app = wx.App()
frame = wx.Frame(None, -1, "MyFrame")
frame.Show()

app.MainLoop()


Then in commang prompt:

python.exe setup.py py2exe



from distutils.core import setup
import py2exe

setup(console=['prog.py'])


Help please!


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


Re: First post from a Python newbiw

2008-03-02 Thread Steve Turner
Christoph Zwerschke wrote: 

: Marc 'BlackJack' Rintsch schrieb:
:: On Sun, 02 Mar 2008 14:15:09 +, Steve Turner wrote:
:: 
::: Apart from doing something like
::: a=[0,0,0]
::: b=[0,0,0]
::: c=[0,0,0]
::: d=[a,b,c]
::: 
::: is there a better way of creating d??
:: 
:: a = [[0] * 3 for dummy in xrange(3)]
: 
: Why not simply [[0]*3]*3 ?

I've just tried that and it gives the same as my earlier b=[a,a,a]

-- 
Steve

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


Re: RELEASED Python 2.6a1 and 3.0a3

2008-03-02 Thread Ben Finney
Kay Schluehr <[EMAIL PROTECTED]> writes:

> On 2 Mrz., 06:53, Ben Finney <[EMAIL PROTECTED]>
> wrote:
> 
> > One of the stated goals of the migration is that the '2to3'
> > program will only migrate Python 2.6 code -> Python 3.0 code.
> 
> Yes, I know. Why?
> 
> "The master said so" isn't an entirely satisfying answer.

The people putting in the work to write '2to3' said so.

-- 
 \"Courteous and efficient self-service." —Café sign, southern |
  `\France |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Book Recomendations

2008-03-02 Thread Jeff Schwab
 > Ira Solomon wrote:
 >> I am an experienced programmer (40 years) . . .
 >> I'm interested in learning Python

 > js wrote:
 >> I wonder why nobody mension Python Cookbook yet . . .
 >> and Python Standard Library

Because cookbooks are not supposed to be language introductions.  They 
are collections of non-obvious techniques, for use by people already 
familiar with a core language and its standard libraries.  Python in 
particular offers a lot for traditional programmers to wrap their minds 
around before considering cookbooks; Programming Python, for example, 
purports to help programmers think Pythonically, and probably belongs 
chronologically between the introductory books and the cookbooks.

Many programmers coming from different languages tend (at first) to 
write code that makes experienced Pythonistas cringe.  Effective use of 
the language depends on an understanding of its extremely dynamic 
nature, which can be tough to grasp for those of us coming from compiled 
language backgrounds.  It seems to me, based purely on discussions seen 
in comp.lang.python, that even folks coming from relatively dynamic 
languages like Lisp often underestimate the level of run-time 
indirection provided by Python.  One of the neat things about the 
Nutshell book is that it shows how even the process of resolving object 
attributes is potentially complicated, and how the new 'type' metaclass 
helps to at least make the process more consistent than with old-style 
objects.

Experienced programmers first have to learn that an expression like 
"a.x" means something very different in Python from what it means 
elsewhere; then, they can begin leveraging these language features to do 
the sorts of things illustrated in the cookbooks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tcp

2008-03-02 Thread Gif
thanks everybody, i've got this to work. i'm not trying to write an
actual web server, i'm just using it for some procedures like URL
rewriting.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Altering imported modules

2008-03-02 Thread Terry Reedy

"Tro" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Hi, list.
|
| I've got a simple asyncore-based server. However, I've modified the 
asyncore
| module to allow me to watch functions as well as sockets. The modified
| asyncore module is in a specific location in my project and is imported 
as
| usual from my classes.
|
| Now I'd like to use the tlslite library, which includes an asyncore mixin
| class. However, tlslite imports "asyncore", which doesn't include my own
| modifications.
|
| I'd like to know if it's possible to make tlslite load *my* asyncore 
module
| without changing any of the tlslite code.

If your module is also 'asyncore' and comes earlier in the search path, I 
would expect the import to get yours. 



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


sympy: nifty, but... (was: How about adding rational fraction to Python?)

2008-03-02 Thread Mensanator
On Mar 1, 12:29 pm, "Anand Patil" <[EMAIL PROTECTED]>
wrote:
> Not sure if this is common knowledge yet but 
> Sympy,http://code.google.com/p/sympy, has a rational type.

I hadn't heard of this before, thanks for the link.

Very nifty, lots of goodies not found in gmpy (although
it seems to lack a modular inverse function and the linear
congruence solver that can be derived from it making it
of no value to me).

Alas, it's written in Python. Who writes a math library
in Python?

Nevertheless, I thought I would try out the Rational numbers.

Once I figured out how to use them, I converted my Polynomial
Finder by Newton's Forward Difference Method program to use
sympy instead of gmpy.

I have a test case where I create 1 66 degree polynomial where
the coefficients are large rationals. The polynomial was
calculated flawlessly


## sympy
##  Term0: [66, -66, 66, -66, 66, -66, 66, -66, 66, -66, 66,
-66, 66, -66, 66, -66, 66, -66, 66, -66, 66, -66, 66, -66, 66, -66,
66, -66, 66, -66, 66, -66, 66, -66, 66, -66, 66, -66, 66, -66, 66,
-66, 66, -66, 66, -66, 66, -66, 66, -66, 66, -66, 66, -66, 66, -66,
66, -66, 66, -66, 66, -66, 66, -66, 66, -66, 66, 0]
##
##Seq: [66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 66]
##
##The Polynomial:
##
##
##1
##
---
*  n**66
##
8247650592082470666723170306785496252186258551345437492922123134388955774976000
##
##
##-67
##
--
*  n**65
##
249928805820680929294641524448045340975341168222589014937034034375422902272000
##
##
##67
##
---
*  n**64
##
230703513065243934733515253336657237823391847590082167634185262500390371328

But because they are calculated using Python,
it took 175 seconds compared to 0.2 seconds
for gmpy to do the same polynomial.

So, I'll keep it around for it's neat features
that gmpy doesn't have, but it won't replace gmpy
for any serious work.


>
> In [2]: from sympy import *
>
> In [3]: Rational(21,4)
> Out[3]: 21/4
>
> In [4]: Rational(21,4)+Rational(3,4)
> Out[4]: 6

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


Re: tuples, index method, Python's design

2008-03-02 Thread Alan Isaac
Paul Boddie wrote:

> Here's the tracker item that may have made it happen:

> http://bugs.python.org/issue1696444 

> I think you need to thank Raymond Hettinger for championing the 

> cause. ;-)





Yes indeed!

Alan Isaac


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


[ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-02 Thread Martin v. Löwis
On behalf of the Python development team and the Python community, I'm
happy to announce the release candidates of Python 2.4.5 and 2.4.5.

Both releases include only security fixes. Python 2.5 is the latest
version of Python, we're making this release for people who are still
running Python 2.3 or 2.4.

See the release notes at the website (also available as Misc/NEWS in
the source distribution) for details of bugs fixed; most of them prevent
interpreter crashes (and now cause proper Python exceptions in cases
where the interprerter may have crashed before).

Assuming no major problems crop up, a final release of Python 2.4.4 will
follow in about a week's time.

For more information on Python 2.3.7 and 2.4.5, including download
links for various platforms, release notes, and known issues, please
see:

 http://www.python.org/2.3.7
 http://www.python.org/2.4.5

Highlights of the previous major Python releases are available
from the Python 2.4 page, at

 http://www.python.org/2.3/highlights.html
 http://www.python.org/2.4/highlights.html

Enjoy this release,
Martin

Martin v. Loewis
[EMAIL PROTECTED]
Python Release Manager
(on behalf of the entire python-dev team)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First post from a Python newbiw

2008-03-02 Thread Christoph Zwerschke
Marc 'BlackJack' Rintsch schrieb:
> On Sun, 02 Mar 2008 14:15:09 +, Steve Turner wrote:
> 
>> Apart from doing something like
>> a=[0,0,0]
>> b=[0,0,0]
>> c=[0,0,0]
>> d=[a,b,c]
>>
>> is there a better way of creating d??
> 
> a = [[0] * 3 for dummy in xrange(3)]

Why not simply [[0]*3]*3 ?

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


Re: Altering imported modules

2008-03-02 Thread Tro
On Saturday 01 March 2008, Tro wrote:
> Hi, list.
>
> I've got a simple asyncore-based server. However, I've modified the
> asyncore module to allow me to watch functions as well as sockets. The
> modified asyncore module is in a specific location in my project and is
> imported as usual from my classes.
>
> Now I'd like to use the tlslite library, which includes an asyncore mixin
> class. However, tlslite imports "asyncore", which doesn't include my own
> modifications.
>
> I'd like to know if it's possible to make tlslite load *my* asyncore module
> without changing any of the tlslite code.

I guess I could just copy over the relevant tlslite file that imports asyncore 
and change the import, but that seems clumsy.

Is there no better way?

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


Re: Network server- / client-side messaging

2008-03-02 Thread castironpi
'''
Last time, we left off at:
'''

class InterfaceClientSide( ClientSide ):
message= MessageDec()
incremental= message.incremental()
settings= AYT( .5, 3 )
user_act= message.out()
def __init__( self, image ):
self._image= image
ClientSide.__init__( self )
def on_scale( self, *args ):
change= self._whatchange(
self.on_scale, *args )
self.user_act( change )
def on_rotate( self, *args ):
change= self._whatchange(
self.on_rotate, *args )
self.user_act( change )
@incremental( 1 )
def layout_return( self, layoutchange ):
renderchange( layoutchange )
@incremental( 2 )
def layout_return( self, layoutchange ):
renderchange( layoutchange )
@message
def time_estimate( self, etc ):
report( etc )

class InterfaceServerSide( ServerSide ):
message= MessageDec()
incremental= message.incremental()
settings= AYT( .5, 3 )
time_estimate= message.out()
layout_return= incremental()
def __init__( self, image ):
self._image= image
ServerSide.__init__( self )
@message.intervene()
def user_act( self, change ):
etc= self.calculateeta( change )
self.time_estimate( etc )
preliminary= self.calculation()
preliminary_change= whatchange( preliminary )
self.layout_return( preliminary_change )
completed= self.other_calculation()
completed_change= whatchange( completed )
self.layout_return( completed_change )
self.layout_return.finish()

'''
Another use ClientSide and ServerSide should support is a peer-to-peer
chat-and-game server.  And that said, it's not clear that there's any
distinction between ServerSide and ClientSide anyway, depending on
exactly how the listen and connect methods abstract.  How much of the
implementation do they share?  Most.

You could mark 'time_estimate' as incremental( 3 ); they're separated
for illustration purposes.

One remaining question is how to intervene in user_act, if a second
change arrives before the previous complete.  You could combine the
earlier change parameter in the new call and throw an exception in the
thread handling the earlier one at its first loss of control--- and
maybe even at once with settrace!  That tends to be costly.  Not to
mention, change has already entered derived-class space.  ServerSide
should make sure it's easy enough to address the issue on one's own,
and @message.nonintervene() is available too.
'''
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2008-03-02 Thread Paul Boddie
On 2 Mar, 19:06, Alan Isaac <[EMAIL PROTECTED]> wrote:
> On April 12th, 2007 at 10:05 PM Alan Isaac wrote:
>
> > The avoidance of tuples, so carefully defended in other
> > terms, is often rooted (I claim) in habits formed from
> > need for list methods like ``index`` and ``count``.
> > Indeed, I predict that Python tuples will eventually have
> > these methods and that these same people will then defend
> > *that* status quo.

You were more confident about this than I was. Still, nothing happens
if no-one steps up to do something about it.

> http://python.org/download/releases/2.6/NEWS.txt>
>
> - Issue #2025 :  Add tuple.count() and tuple.index()
>
>   methods to comply with the collections.Sequence API.

Here's the tracker item that may have made it happen:

http://bugs.python.org/issue1696444

I think you need to thank Raymond Hettinger for championing the
cause. ;-)

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


Re: How about adding rational fraction to Python?

2008-03-02 Thread Jeff Schwab
Paul Rubin wrote:
> I can live with int/int=float but
> find it sloppy and would be happier if int/int always threw an error
> (convert explicitly if you want a particular type result).

Better yet, how hard would it be to define an otherwise int-like type 
that did not define a non-flooring division operator?  Are there any 
real use cases for such a type?  Maybe a division operator could be 
defined to perform a run-time check that, for an operation n/d==q, 
n==q*d; else, throw an exception.  Code written to support duck-typed 
integers should work with such a UDT "out of the box."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cx_Freeze : LookupError: unknown encoding: ascii

2008-03-02 Thread Rakesh Kumar
On Mar 1, 3:41 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > Can somebody point to some clues about options that need to be passed
> > to FreezePython API to get the right executable.
>
> You need to tell it to include the encodings.ascii module.
>
> Regards,
> Martin


Thanks Martin.

Adding something like

./freeze --include-modules=encodings.ascii,encodings.utf_8 

fixed the issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tcp

2008-03-02 Thread castironpi
On Mar 2, 11:38 am, Steve Holden <[EMAIL PROTECTED]> wrote:
> Nobody thinks you are a fool for wanting help with your problems, it's
> simply that you have to provide enough information about what' wring for
> us to get a handle on the issues.

This worked:

import socket
from time import time

for i in range( 20 ):
HOST = ''
PORT = 80 #<
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
print( 'listen' )
s.listen(1)
conn, addr = s.accept()
print( 'connected', addr )
print( conn.recv( 4096 ) ) #<
conn.send( bytes('test %f'%time(),'ascii') )
conn.close() #<
s.close()

... and connect with a browser:  http://localhost/ if it's internet
exploder.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner's assignment question

2008-03-02 Thread Schizoid Man
Gabriel Genellina wrote:
> En Sun, 02 Mar 2008 08:25:49 -0200, Schizoid Man <[EMAIL PROTECTED]> escribi�:
> 
>> Lorenzo Gatti wrote:
>>> On Mar 1, 3:39 pm, Schizoid Man <[EMAIL PROTECTED]> wrote:
 As in variable assignment, not homework assignment! :)

 I understand the first line but not the second of the following code:

 a, b = 0, 1
 a, b = b, a + b

 In the first line a is assigned 0 and b is assigned 1 simultaneously.

 However what is the sequence of operation in the second statement? I;m
 confused due to the inter-dependence of the variables.
>>>
>>> The expressions of the right of the assignment operator are evaluated
>>> before assigning any new values, to the destinations on the left side
>>> of the assignment operator.
>>> So substitutig the old values of a and b the second assignment means
>>>
>>> a, b = 0, 0 + 1
>>>
>>> Simplifying the Python Reference Manual ("6.3 Assignment Statements")
>>> a little :
>>>
>>> assignment_stmt ::= target_list "="+ expression_list
>>>
>>> An assignment statement evaluates the expression list (remember that
>>> this can be a single expression or a comma-separated list, the latter
>>> yielding a tuple) and assigns the single resulting object to each of
>>> the target lists, from left to right.
>>>
>>> [...]
>>>
>>> WARNING: Although the definition of assignment implies that overlaps
>>> between the left-hand side and the right-hand side are `safe' (for
>>> example "a, b = b, a" swaps two variables), overlaps within the
>>> collection of assigned-to variables are not safe! For instance, the
>>> following program prints "[0, 2]":
>>>
>>> x = [0, 1]
>>> i = 0
>>> i, x[i] = 1, 2
>>> print x
>>>
>>> Lorenzo Gatti
>>
>> Thank you for the explanation. I guess my question can be simplified as:
>>
>> First step: a, b = 0, 1
>> No problem here as a and b are assigned values.
>>
>> Second step: a, b = b, a + b
>>
>> Now my question is does b become a + b after a becomes 1 or while a
>> stays at 0?
>>
>> As the assignment occurs simultaneously I suppose the answer is while a
>> stays at 0.
> 
> Read the previous response carefully and you'll answer your question. 
> The right hand side is EVALUATED in full before values are assignated to 
> the left hand side. Evaluating b, a+b results in 1, 1. The, those values 
> are assigned to a, b.

Thank you very much. It's clear now.
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: Escaping a triple quoted string' newbie question

2008-03-02 Thread Jules Stevenson
> > float $pos[]=particleShape1.worldPosition;
> >
> > setAttr ("heartPP_1_"+particleShape1.particleId+".tx") $pos[0];
> >
> > setAttr ("heartPP_1_"+particleShape1.particleId+".ty") $pos[1];
> >
> > setAttr ("heartPP_1_"+particleShape1.particleId+".tz") $pos[2];
> > """
> > dynExpression (p, s=expRuntime, rad=1)  #generate the expression
> >
> > Then maya errors out, however if I pass maya an 'escaped' version:
> >
> > expRuntime="""
> > float $pos[]=particleShape1.worldPosition;\nsetAttr
> > (\"heartPP_1_\"+particleShape1.particleId+\".tx\") $pos[0];\nsetAttr
> > (\"heartPP_1_\"+particleShape1.particleId+\".ty\") $pos[1];\nsetAttr
> > (\"heartPP_1_\"+particleShape1.particleId+\".tz\") $pos[2]; """
> >
> > Then all is well. My question is, is there any way to convert the first
> > variable example to the second? It's a lot easier to type and on the
> eye.
> 
> Except for the doble-space on the first version, \n is the line separator
> on both, so I'll ignore them.
> """one
> two"""
> is the same thing as "one\ntwo" (even on Windows). The only remaining
> difference that I see is " -> \"
> 
> def mayaquote(text):
>return text.replace('"', '\\"')
> 

Thanks, this will work great. I was just wondering if there was an automatic
'string to escaped text' type function. Otherwise I'd have to build parsing
for all chars that could cause a wobbly, but these may be few, so not too
much of an issue.

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


Re: mod_python Unable to create file

2008-03-02 Thread Sean Allen

On Mar 2, 2008, at 3:24 AM, kaush wrote:

> On Mar 1, 11:24 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Sat, 01 Mar 2008 22:47:02 -0800, kaush wrote:
>>> I am using Apache and mod_python to service POST/GET requests on MAC
>>> OS. My script tries to create a file
>>
>>> file = open(file_path, 'w')
>>
>>> This fails with the following error
>>
>>> EACCES
>>> Permission denied
>>
>>> What is missing?
>>
>> To state the ovious: the rights to create a file at `file_path`.   
>> Remember
>> that web servers usually have their own "user".
>>
>> Ciao,
>> Marc 'BlackJack' Rintsch
>
> Thanks Marc.
> In Apache what are the ways/directives to set the rights to a folder?

none. you set permissions via the operating system.

chmod would be the command from terminal you are looking for.

or you can do get info on the folder in question via the finder and  
set perms there.

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


Re: Problem with the strip string method

2008-03-02 Thread Colin J. Williams
[EMAIL PROTECTED] wrote:
> On Mar 2, 11:45 am, Steve Holden <[EMAIL PROTECTED]> wrote:
>> I suspect what you need is the .replace() method.
> 
> The information's there-- the word 'contiguous' might clear it up a
> bit.
> 
>>> Return a copy of the string with the
>>> leading and trailing characters removed.
>>> The chars argument is a string
>>> specifying the set of characters to be
>>> removed. If omitted or None, the chars
>>> argument defaults to removing
>>> whitespace. The chars argument is not a
>>> prefix or suffix; rather, all
>>> combinations of its values are stripped:
> 
> Return the string's substring from the first character not a member of
> 'chars' to the last such.
> 
> Remove contiguous leading and trailing members of 'chars'.  If omitted
> or None, 'chars' defaults over to the set of whitespace set( "\n\r\t
> " ). (XXX TODO: ask Steve Reg Ex Guru this).

Thanks to all respondents, Steve Holden 
is right, I expected more than I should 
have.

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


Re: Question on importing and function defs

2008-03-02 Thread castironpi
On Mar 2, 11:44 am, Steve Holden <[EMAIL PROTECTED]> wrote:
> TC wrote:
> > On Mar 2, 11:37 am, Gary Herron <[EMAIL PROTECTED]> wrote:
> >> TC wrote:
> >>> I have a problem.  Here's a simplified version of what I'm doing:
> >>> I have functions a() and b() in a module called 'mod'.  b() calls a().
> >>> So now, I have this program:
> >>> from mod import *
> >>> def a():
> >>>     blahblah
> >>> b()
> >>> The problem being, b() is calling the a() that's in mod, not the new
> >>> a() that I want to replace it.  (Both a()'s have identical function
> >>> headers, in case that matters.)  How can I fix this?
> >>> Thanks for any help.
> >> Since b calls mod.a, you could replace mod.a with your new a.  Like
> >> this:  (Warning, this could be considered bad style because it will
> >> confuse anyone who examines the mod module in an attempt to understand
> >> you code.)
>
> >>   import mod
>
> >>   def replacement_a():
> >>     ...
>
> >>   mod.a = replacement_a
>
> >>   ...
>
> >> Or another option.  Define b to take, as a parameter, the "a" function
> >> to call.
>
> >> In mod:
>
> >>   def a():
> >>    ...
>
> >>   def b(fn=a):  # to set the default a to call
> >>     ...
>
> >> And you main program:
>
> >>   from mod import *
>
> >>   def my_a():
> >>     ...
>
> >>   b(my_a)
>
> >> Hope that helps
>
> >> Gary Herron
>
> > Thanks for the tips, but no luck.  This is for a homework assignment,
> > so there are a couple of requirements, namely that I can't touch
> > 'mod', and I have to do 'from mod import *' as opposed to 'import
> > mod'.
>
> > So the first method you suggested won't work as written, since the mod
> > namespace doesn't exist.  I tried a = replacement_a, but b() is still
> > calling mod's version of a() for some reason.  And because I can't
> > touch mod, I can't use your second suggestion.
>
> > In case I somehow oversimplified, here's the actual relevant code, in
> > 'mod' (actually called 'search').  The first fn is what I've been
> > calling a(), the second is b().
>
> > (lots of stuff...)
>
> > def compare_searchers(problems, header,
> > searchers=[breadth_first_tree_search,
> >                       breadth_first_graph_search,
> > depth_first_graph_search,
> >                       iterative_deepening_search,
> > depth_limited_search,
> >                       astar_search]):
> >     def do(searcher, problem):
> >         p = InstrumentedProblem(problem)
> >         searcher(p)
> >         return p
> >     table = [[name(s)] + [do(s, p) for p in problems] for s in
> > searchers]
> >     print_table(table, header)
>
> > def compare_graph_searchers():
> >     compare_searchers(problems=[GraphProblem('A', 'B', romania),
> >                                 GraphProblem('O', 'N', romania),
> >                                 GraphProblem('Q', 'WA', australia)],
> >             header=['Searcher', 'Romania(A,B)', 'Romania(O, N)',
> > 'Australia'])
>
> > That's the end of the 'search' file.  And here's my program, which
> > defines an identical compare_searchers() with an added print
> > statement.  That statement isn't showing up.
>
> > from search import *
>
> > def compare_searchers(problems, header,
> > searchers=[breadth_first_tree_search,
> >                       breadth_first_graph_search,
> > depth_first_graph_search,
> >                       iterative_deepening_search,
> > depth_limited_search,
> >                       astar_search, best_first_graph_search]):
> >     def do(searcher, problem):
> >         p = InstrumentedProblem(problem)
> >         searcher(p)
> >         return p
> >     table = [[name(s)] + [do(s, p) for p in problems] for s in
> > searchers]
> >     print 'test'
> >     print_table(table, header)
>
> > compare_graph_searchers()
>
> Since you've admitted it's for homework, here are a couple of hints.
>
> 1. The b() function is *always* going to try and resolve its references
> in the namespace it was defined in;
>
> 2. The technique you need is most likely known as "monkey patching".
> When you say "I can't touch mod", that may mean "the source of mod must
> remain unchanged", which is subtly different. Google is your friend ...
>
> Good luck with your assignment.
>
> regards
>   Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/- Hide quoted text -
>
> - Show quoted text -

You can use 'settrace' to intervene.  You might be able to delete the
'a'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beautiful Code in Python?

2008-03-02 Thread castironpi
On Mar 2, 12:01 pm, John DeRosa <[EMAIL PROTECTED]> wrote:
> On Mon, 3 Mar 2008 01:23:32 +0900, js <[EMAIL PROTECTED]> wrote:
> >Hi,
>
> >Have you ever seen Beautiful Python code?
> >Zope? Django? Python standard lib? or else?
>
> >Please tell me what code you think it's stunning.
>
> Just about any Python code I look at.

Decorators, with, and namedtuple.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the strip string method

2008-03-02 Thread castironpi
On Mar 2, 11:45 am, Steve Holden <[EMAIL PROTECTED]> wrote:
> I suspect what you need is the .replace() method.

The information's there-- the word 'contiguous' might clear it up a
bit.

> > Return a copy of the string with the
> > leading and trailing characters removed.
> > The chars argument is a string
> > specifying the set of characters to be
> > removed. If omitted or None, the chars
> > argument defaults to removing
> > whitespace. The chars argument is not a
> > prefix or suffix; rather, all
> > combinations of its values are stripped:

Return the string's substring from the first character not a member of
'chars' to the last such.

Remove contiguous leading and trailing members of 'chars'.  If omitted
or None, 'chars' defaults over to the set of whitespace set( "\n\r\t
" ). (XXX TODO: ask Steve Reg Ex Guru this).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2008-03-02 Thread Alan Isaac
On April 12th, 2007 at 10:05 PM Alan Isaac wrote:

> The avoidance of tuples, so carefully defended in other 

> terms, is often rooted (I claim) in habits formed from 

> need for list methods like ``index`` and ``count``. 

> Indeed, I predict that Python tuples will eventually have 

> these methods and that these same people will then defend 

> *that* status quo.





http://python.org/download/releases/2.6/NEWS.txt>



- Issue #2025 :  Add tuple.count() and tuple.index() 

  methods to comply with the collections.Sequence API.



Cheers,

Alan Isaac




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


Re: Beautiful Code in Python?

2008-03-02 Thread John DeRosa
On Mon, 3 Mar 2008 01:23:32 +0900, js <[EMAIL PROTECTED]> wrote:

>Hi,
>
>Have you ever seen Beautiful Python code?
>Zope? Django? Python standard lib? or else?
>
>Please tell me what code you think it's stunning.

Just about any Python code I look at.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the strip string method

2008-03-02 Thread Steve Holden
Colin J. Williams wrote:
> The Library Reference has
> strip( [chars])
> 
> Return a copy of the string with the 
> leading and trailing characters removed. 
> The chars argument is a string 
> specifying the set of characters to be 
> removed. If omitted or None, the chars 
> argument defaults to removing 
> whitespace. The chars argument is not a 
> prefix or suffix; rather, all 
> combinations of its values are stripped:
>  >>> '   spacious   '.strip()
>  'spacious'
>  >>> 'www.example.com'.strip('cmowz.')
>  'example'
> 
> Only the last two examples below behave 
> as expected.
> 
Adjust your expectations. The software is correct.

> Is it intended that the full range of 
> characters be handled?
> 
> Colin W.
> 
> [Dbg]>>> 'ab$%\n\rcd'.strip('%')
> 'ab$%\n\rcd'
> [Dbg]>>> 'ab$%cd'.strip('$')
> 'ab$%\n\rcd'
> [Dbg]>>> 'ab$%cd'.strip('$')
> 'ab$%cd'
> [Dbg]>>> '  ab$%cd  '.strip('$')
> '  ab$%cd  '
> [Dbg]>>> '  ab$%cd  '.strip('%')
> '  ab$%cd  '
> [Dbg]>>> '   spacious   '.strip()
> 'spacious'
> [Dbg]>>> 'www.example.com'.strip('cmowz.')
> 'example'

I suspect what you need is the .replace() method.

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

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


Re: Question on importing and function defs

2008-03-02 Thread Steve Holden
TC wrote:
> On Mar 2, 11:37 am, Gary Herron <[EMAIL PROTECTED]> wrote:
>> TC wrote:
>>> I have a problem.  Here's a simplified version of what I'm doing:
>>> I have functions a() and b() in a module called 'mod'.  b() calls a().
>>> So now, I have this program:
>>> from mod import *
>>> def a():
>>> blahblah
>>> b()
>>> The problem being, b() is calling the a() that's in mod, not the new
>>> a() that I want to replace it.  (Both a()'s have identical function
>>> headers, in case that matters.)  How can I fix this?
>>> Thanks for any help.
>> Since b calls mod.a, you could replace mod.a with your new a.  Like
>> this:  (Warning, this could be considered bad style because it will
>> confuse anyone who examines the mod module in an attempt to understand
>> you code.)
>>
>>   import mod
>>
>>   def replacement_a():
>> ...
>>
>>   mod.a = replacement_a
>>
>>   ...
>>
>> Or another option.  Define b to take, as a parameter, the "a" function
>> to call.
>>
>> In mod:
>>
>>   def a():
>>...
>>
>>   def b(fn=a):  # to set the default a to call
>> ...
>>
>> And you main program:
>>
>>   from mod import *
>>
>>   def my_a():
>> ...
>>
>>   b(my_a)
>>
>> Hope that helps
>>
>> Gary Herron
> 
> Thanks for the tips, but no luck.  This is for a homework assignment,
> so there are a couple of requirements, namely that I can't touch
> 'mod', and I have to do 'from mod import *' as opposed to 'import
> mod'.
> 
> So the first method you suggested won't work as written, since the mod
> namespace doesn't exist.  I tried a = replacement_a, but b() is still
> calling mod's version of a() for some reason.  And because I can't
> touch mod, I can't use your second suggestion.
> 
> In case I somehow oversimplified, here's the actual relevant code, in
> 'mod' (actually called 'search').  The first fn is what I've been
> calling a(), the second is b().
> 
> (lots of stuff...)
> 
> def compare_searchers(problems, header,
> searchers=[breadth_first_tree_search,
>   breadth_first_graph_search,
> depth_first_graph_search,
>   iterative_deepening_search,
> depth_limited_search,
>   astar_search]):
> def do(searcher, problem):
> p = InstrumentedProblem(problem)
> searcher(p)
> return p
> table = [[name(s)] + [do(s, p) for p in problems] for s in
> searchers]
> print_table(table, header)
> 
> def compare_graph_searchers():
> compare_searchers(problems=[GraphProblem('A', 'B', romania),
> GraphProblem('O', 'N', romania),
> GraphProblem('Q', 'WA', australia)],
> header=['Searcher', 'Romania(A,B)', 'Romania(O, N)',
> 'Australia'])
> 
> 
> That's the end of the 'search' file.  And here's my program, which
> defines an identical compare_searchers() with an added print
> statement.  That statement isn't showing up.
> 
> from search import *
> 
> def compare_searchers(problems, header,
> searchers=[breadth_first_tree_search,
>   breadth_first_graph_search,
> depth_first_graph_search,
>   iterative_deepening_search,
> depth_limited_search,
>   astar_search, best_first_graph_search]):
> def do(searcher, problem):
> p = InstrumentedProblem(problem)
> searcher(p)
> return p
> table = [[name(s)] + [do(s, p) for p in problems] for s in
> searchers]
> print 'test'
> print_table(table, header)
> 
> compare_graph_searchers()

Since you've admitted it's for homework, here are a couple of hints.

1. The b() function is *always* going to try and resolve its references 
in the namespace it was defined in;

2. The technique you need is most likely known as "monkey patching". 
When you say "I can't touch mod", that may mean "the source of mod must 
remain unchanged", which is subtly different. Google is your friend ...

Good luck with your assignment.

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

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


Re: tcp

2008-03-02 Thread Steve Holden
Gif wrote:
> i would like to apologize once more. i understand that you are saying
> "what a fool he is waiting for us to solve all his problems", cause
> i've said that for other posts, when they seemed "immature". It's just
> that i couldn't find a way out of 20 lines of code and this drove me
> mad.
> 
> i end this topic here.

If you want to use the socket module, take a look at

   http://holdenweb.com/py/networking/

which contains links to some fairly explicit notes about how to write 
TCP and UDP servers in Python.

Nobody thinks you are a fool for wanting help with your problems, it's 
simply that you have to provide enough information about what' wring for 
us to get a handle on the issues.

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

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


Re: Can one get "for x in y" to work for non builtin classes?

2008-03-02 Thread Preben Randhol
On Sun, 2 Mar 2008 06:15:54 -0800 (PST)
Giles Brown <[EMAIL PROTECTED]> wrote:

> http://docs.python.org/lib/typeiter.html

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


Re: Article of interest: Python pros/cons for the enterprise

2008-03-02 Thread Paul Rubin
Robert Brown <[EMAIL PROTECTED]> writes:
> Unfortunately, performance often comes at the cost of safety and
> correctness.  Optimized C programs can crash when pointers walk off the
> end of arrays or they can yield incorrect results when integers overflow
> the limits of the hardware.

Yes, even unoptimized C programs can do that.  C is just plain dangerous.

> [SBCL Common Lisp]
> Very rarely, say inside a loop, I temporarily change my default compiler
> settings.  Inside the lexical scope of these declarations, the compiled
> code does no run-time type checking and trusts me.  Here, broken Lisp
> code can crash the system (just as broken C code can), but the compiled
> code runs very fast.
> 
> I trade off safety for speed, but only where necessary.

It seems to me that this trade-off results from a problem with the
language's expressivity.  If you have a sound argument that the
subscripts in your loop are actually safe, you ought to be able to
express that argument to the compiler for static checking.  That
should result in safe code with no runtime checks needed.

That said, trying to provide that level of expressivity is at the
cutting edge of programming language research, and in real-world
languages, for now, we have to live with some runtime checks.
But in an example like (pseudocode):

   for i in 1..100:
   hack(x[i])

it should be enough to check outside the loop in constant time that
1..100 are valid subscripts for x, then generate the loop code with
no check on each separate access.  That is maybe not possible in C
because i might be aliased to something, but in a sane language it
should be possible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the strip string method

2008-03-02 Thread Martin Blume
"Colin J. Williams" schrieb 
> The Library Reference has
> strip( [chars])
> 
> Return a copy of the string with the 
> leading and trailing characters removed. 
  

It's "leading and trailing", not 
"leading, trailing or embedded".

>>> "xxxaaaxxx".strip("x")
'aaa'
>>> "xxxaaaxxxaaaxxx".strip("x")
'aaaxxxaaa'
>>>

HTH 
Martin



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


Re: Python-based regular expression parser that allows patterns to call functions?

2008-03-02 Thread Paul McGuire
On Mar 2, 8:41 am, Andrew Warkentin <[EMAIL PROTECTED]> wrote:
> I am writing a filtering HTTP proxy (the site 
> ishttp://xuproxy.sourceforge.net/). I want it to be compatible with
> Proxomitron (http://proxomitron.info/) filters. I need a regular
> expression parser that allows patterns to call functions (or more
> likely, class methods), to implement "matching commands" (look at the
> Proxmitron documentation to see what I mean). Does anyone know if such a
> library exists for Python, or do I have to write my own parser?

Andrew -

Pyparsing allows you to define parse actions that get called when
element within a grammar are matched.  These actions can update
external data structures, modify the matched text, or can be used to
provide additional semantic validation.  Here's an example:

from pyparsing import *

integer = Regex(r"\b\d+\b")
# could also be written as
#~ integer = WordStart() + Word(nums) + WordEnd()

# convert matched text to actual integer
def cvt_to_int (tokens):
return int(tokens[0])

# only accept integers < 100
def must_be_less_than_100(tokens):
if (tokens[0]) >= 100:
raise ParseException("only integers < 100 are allowed")

# add value to running tally of matches
def increment_tally(tokens):
global running_total
running_total += tokens[0]

integer.setParseAction( cvt_to_int)
integer.addParseAction( must_be_less_than_100 )
integer.addParseAction( increment_tally )

# could also be written as
#~ integer.setParseAction( cvt_to_int,
#~ must_be_less_than_100,
#~ increment_tally )

running_total = 0
print integer.searchString("absdlkj 1 5 12 121 78 22")
print running_total

Prints:

[[1], [5], [12], [78], [22]]
118

More info about pyparsing at http://pyparsing.wikispaces.com, plus
more examples, and links to other doc sources.

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


Re: Question on importing and function defs

2008-03-02 Thread TC
On Mar 2, 11:37 am, Gary Herron <[EMAIL PROTECTED]> wrote:
> TC wrote:
> > I have a problem.  Here's a simplified version of what I'm doing:
>
> > I have functions a() and b() in a module called 'mod'.  b() calls a().
>
> > So now, I have this program:
>
> > from mod import *
>
> > def a():
> > blahblah
>
> > b()
>
> > The problem being, b() is calling the a() that's in mod, not the new
> > a() that I want to replace it.  (Both a()'s have identical function
> > headers, in case that matters.)  How can I fix this?
>
> > Thanks for any help.
>
> Since b calls mod.a, you could replace mod.a with your new a.  Like
> this:  (Warning, this could be considered bad style because it will
> confuse anyone who examines the mod module in an attempt to understand
> you code.)
>
>   import mod
>
>   def replacement_a():
> ...
>
>   mod.a = replacement_a
>
>   ...
>
> Or another option.  Define b to take, as a parameter, the "a" function
> to call.
>
> In mod:
>
>   def a():
>...
>
>   def b(fn=a):  # to set the default a to call
> ...
>
> And you main program:
>
>   from mod import *
>
>   def my_a():
> ...
>
>   b(my_a)
>
> Hope that helps
>
> Gary Herron

Thanks for the tips, but no luck.  This is for a homework assignment,
so there are a couple of requirements, namely that I can't touch
'mod', and I have to do 'from mod import *' as opposed to 'import
mod'.

So the first method you suggested won't work as written, since the mod
namespace doesn't exist.  I tried a = replacement_a, but b() is still
calling mod's version of a() for some reason.  And because I can't
touch mod, I can't use your second suggestion.

In case I somehow oversimplified, here's the actual relevant code, in
'mod' (actually called 'search').  The first fn is what I've been
calling a(), the second is b().

(lots of stuff...)

def compare_searchers(problems, header,
searchers=[breadth_first_tree_search,
  breadth_first_graph_search,
depth_first_graph_search,
  iterative_deepening_search,
depth_limited_search,
  astar_search]):
def do(searcher, problem):
p = InstrumentedProblem(problem)
searcher(p)
return p
table = [[name(s)] + [do(s, p) for p in problems] for s in
searchers]
print_table(table, header)

def compare_graph_searchers():
compare_searchers(problems=[GraphProblem('A', 'B', romania),
GraphProblem('O', 'N', romania),
GraphProblem('Q', 'WA', australia)],
header=['Searcher', 'Romania(A,B)', 'Romania(O, N)',
'Australia'])


That's the end of the 'search' file.  And here's my program, which
defines an identical compare_searchers() with an added print
statement.  That statement isn't showing up.

from search import *

def compare_searchers(problems, header,
searchers=[breadth_first_tree_search,
  breadth_first_graph_search,
depth_first_graph_search,
  iterative_deepening_search,
depth_limited_search,
  astar_search, best_first_graph_search]):
def do(searcher, problem):
p = InstrumentedProblem(problem)
searcher(p)
return p
table = [[name(s)] + [do(s, p) for p in problems] for s in
searchers]
print 'test'
print_table(table, header)

compare_graph_searchers()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the strip string method

2008-03-02 Thread Jorge Godoy
Colin J. Williams wrote:

> Return a copy of the string with the
> leading and trailing characters removed.
  

> Only the last two examples below behave
> as expected.

They all looks OK to me.

> [Dbg]>>> 'ab$%\n\rcd'.strip('%')
> 'ab$%\n\rcd'

No "%" at the beginning or end of string.  Nothing changed.

> [Dbg]>>> 'ab$%cd'.strip('$')
> 'ab$%\n\rcd'

No "$" at the beginning or end of string.  Nothing changed.  I believe that
you didn't copy this from the standard input due to the presence of "\r\n"
on the answer...

> [Dbg]>>> 'ab$%cd'.strip('$')
> 'ab$%cd'

No "$" at the beginning or end of string.  Nothing changed.

> [Dbg]>>> '  ab$%cd  '.strip('$')
> '  ab$%cd  '

No "$" at the beginning or end of string.  Nothing changed.

> [Dbg]>>> '  ab$%cd  '.strip('%')
> '  ab$%cd  '

No "%" at the beginning or end of string.  Nothing changed.

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


SV: Keeping the console window

2008-03-02 Thread K Viltersten
> You may use python in interactive mode:
> 
> $ python -i yourScript.py
> 
> Or use a blocking readline:
> 
> $ cat yourScript.py
> import sys
> sys.stdin.readline()


Thanks guys!

--
Regards
Konrad Viltersten

sleep- a substitute for coffee for the poor
ambition - lack of sense to be lazy

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


Problem with the strip string method

2008-03-02 Thread Colin J. Williams
The Library Reference has
strip( [chars])

Return a copy of the string with the 
leading and trailing characters removed. 
The chars argument is a string 
specifying the set of characters to be 
removed. If omitted or None, the chars 
argument defaults to removing 
whitespace. The chars argument is not a 
prefix or suffix; rather, all 
combinations of its values are stripped:
 >>> '   spacious   '.strip()
 'spacious'
 >>> 'www.example.com'.strip('cmowz.')
 'example'

Only the last two examples below behave 
as expected.

Is it intended that the full range of 
characters be handled?

Colin W.

[Dbg]>>> 'ab$%\n\rcd'.strip('%')
'ab$%\n\rcd'
[Dbg]>>> 'ab$%cd'.strip('$')
'ab$%\n\rcd'
[Dbg]>>> 'ab$%cd'.strip('$')
'ab$%cd'
[Dbg]>>> '  ab$%cd  '.strip('$')
'  ab$%cd  '
[Dbg]>>> '  ab$%cd  '.strip('%')
'  ab$%cd  '
[Dbg]>>> '   spacious   '.strip()
'spacious'
[Dbg]>>> 'www.example.com'.strip('cmowz.')
'example'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-03-02 Thread Paul Rubin
Lie <[EMAIL PROTECTED]> writes:
> You hit the right note, but what I meant is the numeric type
> unification would make it _appear_ to consist of a single numeric type
> (yeah, I know it isn't actually, but what appears from outside isn't
> always what's inside).

That is clearly not intended; floats and decimals and integers are
really different from each other and Python has to treat them distinctly.

> > Try with a=7, b=25
> 
> They should still compare true, but they don't. The reason why they
> don't is because of float's finite precision, which is not exactly
> what we're talking here since it doesn't change the fact that
> multiplication and division are inverse of each other.

What?  Obviously they are not exact inverses for floats, as that test
shows.  They would be inverses for mathematical reals or rationals,
but Python does not have those.

> One way to handle this situation is to do an epsilon aware
> comparison (as should be done with any comparison involving floats),
> but I don't do it cause my intention is to clarify the real problem
> that multiplication is indeed inverse of division and I want to
> avoid obscuring that with the epsilon comparison.

I think you are a bit confused.  That epsilon aware comparison thing
acknowledges that floats only approximate the behavior of mathematical
reals.  When we do float arithmetic, we accept that "equal" often
really only means "approximately equal".  But when we do integer
arithmetic, we do not expect or accept equality as being approximate.
Integer equality means equal, not approximately equal.  That is why
int and float arithmetic cannot work the same way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beautiful Code in Python?

2008-03-02 Thread Michele Simionato
On Mar 2, 5:23 pm, js <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Have you ever seen Beautiful Python code?
> Zope? Django? Python standard lib? or else?
>
> Please tell me what code you think it's stunning.

The doctest module in the standard library.

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


Re: Question on importing and function defs

2008-03-02 Thread Gary Herron
TC wrote:
> I have a problem.  Here's a simplified version of what I'm doing:
>
> I have functions a() and b() in a module called 'mod'.  b() calls a().
>
> So now, I have this program:
>
> from mod import *
>
> def a():
> blahblah
>
> b()
>
>
> The problem being, b() is calling the a() that's in mod, not the new
> a() that I want to replace it.  (Both a()'s have identical function
> headers, in case that matters.)  How can I fix this?
>
> Thanks for any help.
>   

Since b calls mod.a, you could replace mod.a with your new a.  Like 
this:  (Warning, this could be considered bad style because it will 
confuse anyone who examines the mod module in an attempt to understand 
you code.)


  import mod

  def replacement_a():
...

  mod.a = replacement_a

  ...


Or another option.  Define b to take, as a parameter, the "a" function 
to call.

In mod:

  def a():
   ...

  def b(fn=a):  # to set the default a to call
...

And you main program:

  from mod import *

  def my_a():
...

  b(my_a)


Hope that helps

Gary Herron

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


SV: Where's GUI for Python?

2008-03-02 Thread K Viltersten
>>  You should also take a look at wxGlade:
>>
>>  http://wxglade.sourceforge.net/
>>
>>  which sits on top of wxPython:
>>
>>  http://wxpython.org/
>>
>>  which wraps wxWidgets:
>>
>>  http://www.wxwindows.org/
> 
> I have used wxGlade, and while it worked well 
> enough, it didn't seem to fit my brain. I 
> always found myself "thinking backwards" in order
> to guess how the tool needed me to do things.
> For me, though, everytime I see raw wxPython code 
> these days I cringe, and am thankful that I don't 
> have to deal with it anymore.

May i see a short sample of the two different
ways of coding, please? I'm very curious how
they differ (and of course, decide what's the
most pleasurable way for me).

As long as we're on the subject, i also wonder
if there's a general concensus on which 
technology is recommended in the different 
types of projects that are developed. (E.g. 
"use A for small/fast fixes, use B for stuff
you'll need to maintain later on".)

--
Regards
Konrad Viltersten

sleep- a substitute for coffee for the poor
ambition - lack of sense to be lazy

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


Re: Question on importing and function defs

2008-03-02 Thread Nick Miller
TC wrote:
> I have a problem.  Here's a simplified version of what I'm doing:
>
> I have functions a() and b() in a module called 'mod'.  b() calls a().
>
> So now, I have this program:
>
> from mod import *
>
> def a():
> blahblah
>
> b()
>
>
> The problem being, b() is calling the a() that's in mod, not the new
> a() that I want to replace it.  (Both a()'s have identical function
> headers, in case that matters.)  How can I fix this?
>
> Thanks for any help.
>   

The only problem I could see with this is a local function issue. 
Meaning that even when you write the new a() function in the main source 
file, b() doesn't know it exists because it's relying on it's own 
"local" a() in the module. I'm also new to using Python so I that's all 
I can think would be the problem.

Nick

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


Re: How about adding rational fraction to Python?

2008-03-02 Thread Lie
On Mar 2, 10:02 pm, Paul Rubin  wrote:
> Lie <[EMAIL PROTECTED]> writes:
> > Anyway, I don't think Python should
> > work that way, because Python have a plan for numerical integration
> > which would unify all numerical types into an apparent single type,
> > which requires removal of operator's limitations.
>
> Well I think the idea is to have a hierarchy of nested numeric types,
> not a single type.

You hit the right note, but what I meant is the numeric type
unification would make it _appear_ to consist of a single numeric type
(yeah, I know it isn't actually, but what appears from outside isn't
always what's inside).

> > from __future import division
> > a = 10
> > b = 5
> > c = a / b
> > if c * b == a: print 'multiplication is inverse of division'
>
> Try with a=7, b=25

They should still compare true, but they don't. The reason why they
don't is because of float's finite precision, which is not exactly
what we're talking here since it doesn't change the fact that
multiplication and division are inverse of each other. One way to
handle this situation is to do an epsilon aware comparison (as should
be done with any comparison involving floats), but I don't do it cause
my intention is to clarify the real problem that multiplication is
indeed inverse of division and I want to avoid obscuring that with the
epsilon comparison.
-- 
http://mail.python.org/mailman/listinfo/python-list


Beautiful Code in Python?

2008-03-02 Thread js
Hi,

Have you ever seen Beautiful Python code?
Zope? Django? Python standard lib? or else?

Please tell me what code you think it's stunning.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can one get "for x in y" to work for non builtin classes?

2008-03-02 Thread Preben Randhol
On Sun, 2 Mar 2008 08:09:24 -0800 (PST)
[EMAIL PROTECTED] wrote:

> On Mar 2, 8:15 am, Giles Brown <[EMAIL PROTECTED]> wrote:

> > http://docs.python.org/lib/typeiter.html
> 
> Be careful on your descision to return an ordered iterator or not--
> that is, whether it iterates over the dictionary or the list (if I
> understand you correctly).  If the order's unimportant then please
> disregard.

I was thinking to iterate over the list which contains the uniq_ids as
order is important :-)

Thanks!

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

Question on importing and function defs

2008-03-02 Thread TC
I have a problem.  Here's a simplified version of what I'm doing:

I have functions a() and b() in a module called 'mod'.  b() calls a().

So now, I have this program:

from mod import *

def a():
blahblah

b()


The problem being, b() is calling the a() that's in mod, not the new
a() that I want to replace it.  (Both a()'s have identical function
headers, in case that matters.)  How can I fix this?

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


Re: Can one get "for x in y" to work for non builtin classes?

2008-03-02 Thread castironpi
On Mar 2, 8:15 am, Giles Brown <[EMAIL PROTECTED]> wrote:
> On Mar 2, 2:08 pm, Preben Randhol 
> [EMAIL PROTECTED]> wrote:
> > On Sun, 2 Mar 2008 15:06:17 +0100
>
> > Preben Randhol <[EMAIL PROTECTED]> wrote:
> > >    class dbase(list):
>
> > Sorry the definition of the class is:
>
> >         class dbase(object):
>
> > it doesn't derive from the list class.
>
> > Preben
>
> http://docs.python.org/lib/typeiter.html

Be careful on your descision to return an ordered iterator or not--
that is, whether it iterates over the dictionary or the list (if I
understand you correctly).  If the order's unimportant then please
disregard.

You can also use:

>>> a= [2,3,4]
>>> b= iter( a )
>>> next( b )
2
>>> next( b )
3
>>> next( b )
4
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Book Recomendations

2008-03-02 Thread James Matthews
I liked Core Python Programming 2nd edition!

On Sun, Mar 2, 2008 at 4:27 PM, Ken Dere <[EMAIL PROTECTED]> wrote:

> Ira Solomon wrote:
>
> > I am an experienced programmer (40 years).  I've done Algol (if you've
> > heard of that you must be old too), PL/1, VB,VBA, a little C, and a
> > few other odd languages (e.g. Taskmate).
> > I'm interested in learning Python and have downloaded a slew of books.
> > Too many.
> > I'd like a recommendation as to which books are considered to be the
> > cream of the crop.
> > I know there are tutorials on the web, but, again, I don't know the
> > quality.  I would appreciate recommendations on those as well.
> >
> > Thanks
> >
> > Ira
>
> I started off with Fortran 6X so I have been in the business about as
> long.
> Do just about everything now in Python.
>
> I liked Learning Python
>
>
> Ken D.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://search.goldwatches.com/?Search=Movado+Watches
http://www.jewelerslounge.com
http://www.goldwatches.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Keeping the console window

2008-03-02 Thread castironpi
On Mar 2, 9:55 am, Sam <[EMAIL PROTECTED]> wrote:
> You may use python in interactive mode:
>
> $ python -i yourScript.py
>
> Or use a blocking readline:
>
> $ cat yourScript.py
> import sys
> sys.stdin.readline()
>
> ++
>
> Sam

FWIW, for what it's worth, you can invoke the interpreter from a batch
file/shell script too, and just use the native PAUSE instruction to
prompt for 'any key to continue'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-based regular expression parser that allows patterns to call functions?

2008-03-02 Thread castironpi
On Mar 2, 8:41 am, Andrew Warkentin <[EMAIL PROTECTED]> wrote:
> I am writing a filtering HTTP proxy (the site 
> ishttp://xuproxy.sourceforge.net/). I want it to be compatible with
> Proxomitron (http://proxomitron.info/) filters. I need a regular
> expression parser that allows patterns to call functions (or more
> likely, class methods), to implement "matching commands" (look at the
> Proxmitron documentation to see what I mean). Does anyone know if such a
> library exists for Python, or do I have to write my own parser?

To make a list of commands available:

class C:
   def behavior( self ): pass
   def behavior2( self ): pass
   cmds= [ behavior, behavior2 ]

Then search C.cmds for a match to the regular expression.
C.behavior.func_name contains the string 'behavior' for checking.  You
might need to "bind" the contents of C.cmds before you call them too.
More info available, just ask.

You can also do:

class C:
   @string_callable
   def behavior( self ): pass
   @string_callable
   def behavior2( self ): pass

and

class C:
   def behavior( self ): pass
   def behavior2( self ): pass
   cmds= [ 'behavior', 'behavior2' ]

(strings this time), and use getattr( C, 'behavior' ) or for c= C(),
getattr( c, 'behavior' ).

class C:
   def behavior( self ): pass
   def behavior2( self ): pass
   cmds= [ 'behavior', 'behavior2' ]
C.cmds= commandmap( C, C.cmds )

can generate a dictionary of strings to methods.  And there's always

getattr( c, strA ), for your choice of strA, which throws an exception
if strA is not an attribute (method or property) of c, and hasattr( c,
strA ) can test if it is.

You less often want to generate distinct functions based on parameters
only, but you can.

c= C()
def behavior3( self ): pass
c.behavior3= behavior3

so c.behavior3() is legal.

Where does that get you?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tcp

2008-03-02 Thread Diez B. Roggisch
Gif schrieb:
> sorry for acting like a fool but this is just to weirdly easy that i
> can't get to work. i've written a small web server in another language
> and this is more like copying code.
> i already have everything figured out, except this one but noone seems
> either willing or capable of helping me.
> again sorry but i was in a very bad mood.

Writing a webserver (you NEVER stated that that is your ultimate goal) 
is a two-liner in Python.

See the module SimpleHTTPServer.

Using the extremely lowlevel module socket is a totally different beast. 
It requires rather deep knowledge of unix sockets, and has a steep 
learning curve.

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


Re: Keeping the console window

2008-03-02 Thread Sam
You may use python in interactive mode:

$ python -i yourScript.py

Or use a blocking readline:

$ cat yourScript.py
import sys
sys.stdin.readline()

++

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


Network server- / client-side messaging

2008-03-02 Thread castironpi
'''
a website wants to show you different arrangements of framed pictures
on a wall.  you can click, drag, scale, and rotate pictures in place.
you can also drag new pictures in to it.

spacing is uniform and settable-- if you rotate one, the readout of
the total square area changes along with the new value.  you can also
select themes from the host that determine formulae for spacing, based
on established aesthetics constraints.

user clicks a picture and clicks rotate.  clientside doesn't want to
transmit the whole array back to the server for calculation, but
calculation takes a long time, due to the complexity of the spacing
formulae.  therefore, maintain paralell data on both sides: client for
displaying and interfacing, so as not to inform the server of every
mouse click, and server side to decrease transmission redundancy and
size.  do not broadcast every click, but do not broadcast entire
interface state.  constraint-based best-fit labor distribution is
between.

changes are sent to the server in the form of the change parameters
(perhaps a change object), the layout is updated roughly (still by
server-side procedures), and then precisely (along with the sq. ft.
readout) when the calculation completes.  the interface remains
continuously active.

Partial cast:
'''

class PictureClientSide:
def __init__( self, image ):
self._image= image
def on_scale( self, *params ):
change= self.whatchange( scale, *params )
self.tell_the_server( change )
def on_rotate( self, *params ):
change= self.whatchange( rotate, *params )
self.tell_the_server( change )
def server_says( self, layoutchange ):
renderchange( layoutchange )

class PictureServerSide:
def __init__( self, image ):
self._image= image
def client_says( self, change ):
preliminary= self.calculation()
preliminary_change= whatchange( preliminary )
tell_the_client( preliminary_change )
completed= self.other_calculation()
completed_change= whatchange( completed )
tell_the_client( completed_change )

'''
It's too tangled to proceed.  What if a second client 'change' and the
first server 'completed' cross paths?  Will you cancel the first
change explicitly or just drop it?  Are you shooting for five-nines
quality, or one?  What about signal loss and reordering?  Will you
retransmit an entire message upon suspected loss, or intervalled AYT
messages (are you there)?  What about an immediate time estimate?  How
general can the underlying framework be?  The rest is a brainstorm.
Please critique.
'''

class PictureClientSide( ClientSide ):
settings= Setting1(), Setting2()
@incremental
def server_says( self, layoutchange ):
renderchange( layoutchange )

class PictureServerSide( ServerSide ):
settings= Setting3(), Setting4()

'''
We may want to distinguish requests in both directions.  Depending on
which side takes care of the rotation, server_says may divide based on
increment.
'''

class PictureClientSide( ClientSide ):
@incremental( 1 )
def server_says( self, layoutchange ):
renderchange( layoutchange )
@incremental( 2 )
def server_says( self, layoutchange ):
renderchange( layoutchange )

'''
Furthermore, you may want the time estimate in its own method.
'''

class PictureClientSide( ClientSide ):
@incremental( layoutchange, 1 )
def server_says( self, layoutchange ):
renderchange( layoutchange )
@incremental( layoutchange, 2 )
def server_says( self, layoutchange ):
renderchange( layoutchange )
@message( timeout_message )
def timeout_message( self, etc ):
report( etc )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's BNF

2008-03-02 Thread MartinRinehart
Gabriel Genellina wrote:

> About the generated page: I think it would be more useful if each symbol
> links to its definition, instead of showing an alert(). This way it's
> easier to navigate the tree, specially with complex declarations.

That was my first shot. It didn't work. (Every line is its own table
because
you can't put named anchors inside a table, something I really
regret.)
If the production is already viewable, there's no jump when you click
the
link.. If the production is on the last page (many are)
you jump to the last page and then have to hunt down the production.
Remind me to figure out Ajax so you get what we really want: click on
it
and see its definition highlighted.

> You can place the current text into a "title" attribute and most browsers
> will show it as a tooltip.

Great! Consider it done. Konqueror, Firefox, Opera and even MSIE.

How would ,  and  make our lives easier?

I also tried putting the definitions into the status bar. If you ever
feel
tempted to do something similar, let the urge pass. (This now works
in Firefox 2 if you use the correct settings to allow javascript to
write
to the status bar. It doesn't work in Konqueror or Opera and I can't
even find the settings for MSIE.) Trying to get this to work DID get me
to considerably improve the readability of the HTML, so it wasn't a
total waste.

The tooltips are a big step forward. Thanks again.

Improved version at
http://www.MartinRinehart.com/articles/python-parse-bnf.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Book Recomendations

2008-03-02 Thread Ken Dere
Ira Solomon wrote:

> I am an experienced programmer (40 years).  I've done Algol (if you've
> heard of that you must be old too), PL/1, VB,VBA, a little C, and a
> few other odd languages (e.g. Taskmate).
> I'm interested in learning Python and have downloaded a slew of books.
> Too many.
> I'd like a recommendation as to which books are considered to be the
> cream of the crop.
> I know there are tutorials on the web, but, again, I don't know the
> quality.  I would appreciate recommendations on those as well.
> 
> Thanks
> 
> Ira

I started off with Fortran 6X so I have been in the business about as long. 
Do just about everything now in Python.

I liked Learning Python


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


Re: Python Telnet formatting?

2008-03-02 Thread Grant Edwards
On 2008-03-02, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I posted here a couple days ago looking for some help creating
> a Telnet-based chat server. You guys pointed me to Twisted,
> which has solved most of my issues.

And we told you that you needed to implement the telnet protocol.

> The issue is, when I use clients like PuTTY, it returns a lot
> of what appears to be formatting (e.g. if I typed Hello, it
> would return "\xff \xfb\x1f\xff\
> xfb\xff\xfb\x18\xff\xfb'\xff\xfd\x01\xff\xfb\x03\xff\xfd\x03Hello".)

That "stuff" that you call "formatting" are commands for the
telnet protocol.  Apparently you've ignored what I told you
about implementing the telnet protocol (or using something that
does).

> How would I go about filtering this stuff out of the strings?

Once again:  If you're trying to write a telnet server, you
need to implement the telnet protocol.

> The thing is too, if I use other Telnet programs like
> Microsoft Telnet, they don't have this formatting,

Different telnet clients act a little differently.  Some won't
try to negotiate with the tenlet server until the server starts
the negotiation.

> so I want to be able to recognize if it does have this
> formatting and act based on if it does or if it doesn't.

You have to handle the telnet protocol if you want to talk to
telnet clients.

-- 
Grant Edwards   grante Yow!  Yow! Those people
  at   look exactly like Donnie
   visi.comand Marie Osmond!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tcp

2008-03-02 Thread Grant Edwards
On 2008-03-02, Gif <[EMAIL PROTECTED]> wrote:

> sorry for acting like a fool but this is just to weirdly easy
> that i can't get to work. i've written a small web server in
> another language and this is more like copying code. i already
> have everything figured out, except this one but noone seems
> either willing or capable of helping me.

Because you don't seem either willing or capable of describing
your problem in enough detail to allow anybody to help you.

Post a small program that demonstrates the "problem".

Describe precisely how that program fails to do what you want
it to.

-- 
Grant Edwards   grante Yow!  I was giving HAIR
  at   CUTS to th' SAUCER PEOPLE
   visi.com... I'm CLEAN!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tcp

2008-03-02 Thread Gif
i would like to apologize once more. i understand that you are saying
"what a fool he is waiting for us to solve all his problems", cause
i've said that for other posts, when they seemed "immature". It's just
that i couldn't find a way out of 20 lines of code and this drove me
mad.

i end this topic here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-03-02 Thread Paul Rubin
Lie <[EMAIL PROTECTED]> writes:
> That's quite complex and restrictive, but probably it's because my
> mind is not tuned to Haskell yet.

That aspect is pretty straightforward, other parts like only being
able to do i/o in functions having a special type are much more confusing.

> Anyway, I don't think Python should
> work that way, because Python have a plan for numerical integration
> which would unify all numerical types into an apparent single type,
> which requires removal of operator's limitations.

Well I think the idea is to have a hierarchy of nested numeric types,
not a single type.

> from __future import division
> a = 10
> b = 5
> c = a / b
> if c * b == a: print 'multiplication is inverse of division'

Try with a=7, b=25

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


  1   2   >