ANN: Leo 4.4.7 final released

2008-02-24 Thread Edward K Ream
Leo 4.4.7 final is available at:
http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

This version features a new ipython plugin that provides a two-way bridge
between Leo and IPython.  See 
http://webpages.charter.net/edreamleo/IPythonBridge.html

Leo is a text editor, data organizer, project manager and much more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4.7:

- The ipython plugin creates a simple, powerful, effective bridge between 
IPython and Leo.
  See http://webpages.charter.net/edreamleo/IPythonBridge.html
- Improved handling of unicode encodings in @auto files.
- All import commands now support @path directives in ancestor nodes.
- Fixed several minor bugs.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Forum:http://groups.google.com/group/leo-editor
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://leo.tigris.org/source/browse/leo/
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html


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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


[ANN] Shed Skin (restricted) Python-to-C++ compiler 0.0.27

2008-02-24 Thread Mark Dufour
Hi all,

I have just released Shed Skin 0.0.27. Thanks in large part to the
GHOP students, this new release comes with some interesting new
goodies:

- support for 're', via libpcre (perl-compatible-regular-expressions)
- support for 'time' (except for time.strptime under Windows)
- basic support for 'staticmethod' and 'property'
- support for 'fnmatch', 'glob' (bootstrapped)
- improved support for 'os' (POSIX)
- OSX support again (including extension modules!)
- many fixes for multi-dir/multi-file projects
- several builtin optimizations (zip, list(str)..)
- type model for 'datetime' (no C++ implementation yet)
- split up compiler core, ss.py, into several files
- many minor bugfixes

As for the 4 new modules (re, time, fnmatch, glob), this means Shed
Skin now supports most of the following modules:

bisect
collections
copy
fnmatch
getopt
glob
math
os
os.path
random
re
string
sys
time

I could still really use some help with implementing/bootstrapping
implementations for 'datetime' and 'socket', and further improving
'os' (especially under Windows).

Note that since the previous release we have a nice tutorial online.
It explains in detail how to install and use Shed Skin, how to use it
to build (simple) extension modules and how to combine Shed Skin with
numpy and parallel processing solutions such as Parallel Python.


Thanks,
Mark Dufour.
-- 
One of my most productive days was throwing away 1000 lines of code
- Ken Thompson
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


vtd-xml 2.3 released

2008-02-24 Thread jimmy Zhang
VTD-XML 2.3 is now released. To download the latest version please visit
http://sourceforge.net/project/showfiles.php?group_id=110612package_id=120172.

Below is a list of new features and enhancements in this version.

  a.. VTDException is now introduced as the root class for all other
VTD-XML's exception classes (per suggestion of Max Rahder).
  b.. Transcoding capability is now added for inter-document cut and paste.
You can cut a chuck of bytes in a UTF-8 encoded document and paste it into a
UTF-16 encoded document and the output document is still well-formed.
  c.. ISO-8859-10, ISO-8859-11, ISO-8859-12, ISO-8859-13, ISO-8859-14 and
ISO-8859-15 support has now been added
  d.. Zero length Text node is now possible.
  e.. Ability to dump in-memory copy of text is added.
  f.. Various code cleanup, enhancement and bug fixes.

Below are some new articles related to VTD-XML

  a.. Index XML documents with VTD-XML
http://xml.sys-con.com/read/453082.htm
  b.. Manipulate XML content the Ximple Way
http://www.devx.com/xml/Article/36379
  c.. VTD-XML: A new vision of XML
http://www.developer.com/xml/article.php/3714051
  d.. VTD-XML: XML Processing for the future
http://www.codeproject.com/KB/cs/vtd-xml_examples.aspx

If you (or someone you know) like the concept of VTD-XML, think that it can
help solve enterprises' XML processing related issues (particularly those
related to SOA), and would like to directly influence and contribute to the
development of the future of Internet, please email me
[EMAIL PROTECTED]). We are looking for open source software developers
and project management people to take VTD-XML to the next level.




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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: [ANN] Shed Skin (restricted) Python-to-C++ compiler 0.0.27

2008-02-24 Thread Mark Dufour
Of course I forgot to add the URL:

http://shedskin.googlecode.com


Mark Dufour.
-- 
One of my most productive days was throwing away 1000 lines of code
- Ken Thompson
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Return value of an assignment statement?

2008-02-24 Thread Marc 'BlackJack' Rintsch
On Sat, 23 Feb 2008 22:44:30 +, Tim Roberts wrote:

 Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 
On Fri, 22 Feb 2008 11:00:17 -0800, Aahz wrote:

 It's just too convenient to be able to write
 
 L += ['foo']
 
 without rebinding L.

nitpickBut ``+=`` does rebind./nitpick
 
 Usually, but there's an exception for lists, which a specific
 implementation for += that calls append.  Or do I misunderstand you?

Terry Reedy showed the tuple proof, here's the read only property case::

 class A(object):
 def __init__(self):
 self._data = list()

 @property
 def data(self):
 return self._data

 a = A()
 a.data += [42]

Output::

 Traceback (most recent call last):
   File test.py, line 25, in module
 a.data += [42]
 AttributeError: can't set attribute

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


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

2008-02-24 Thread Steven D'Aprano
On Sat, 23 Feb 2008 19:45:45 -0800, Jeff Schwab wrote:

 Paul Rubin wrote:
 Jeff Schwab [EMAIL PROTECTED] writes:
 One great thing about C is that
 a programmer can realistically hope to know the entire language
 definition; maybe Guido would like the same to be true of Python.
 
 C is horrendously complicated, with zillions of obscure traps.  C++ is
 even worse;
 
 Who feeds you this stuff?
 
 
 there's actually a published book specifically about C++ pitfalls.
 
 Mercy, a whole book?

Well, that might not be zillions, but it is sure a lot of pitfalls.


 My current favorite book of language-specific pitfalls:
 
  http://www.javapuzzlers.com/

I'm not sure what you are trying to communicate here.


 Wait a few years.  A Python Puzzlers book will surely be on the shelves
 eventually.

You wish.

If so, then it will either be an incredibly short book, or the language 
Python in 2012 will be nothing like Python now.



 Here are some of the top results when Googling python
 pitfalls:
 
  http://zephyrfalcon.org/labs/python_pitfalls.html
  http://evanjones.ca/python-pitfall-scope.html

Yeah, let's have a look at those. From the first link:

1. Inconsistent indentation
2. Assignment, aka names and objects
3. The += operator
4. Class attributes vs instance attributes
5. Mutable default arguments
6. UnboundLocalError
7. Floating point rounding errors
8. String concatenation
9. Binary mode for files
10. Catching multiple exceptions

Ten pitfalls. You might be able to pad that out to a twenty page leaflet, 
including an index. Number ten is already gone from Python 3; numbers 7 
and 9 aren't Python specific at all; most of the others are only a 
pitfall if you come to Python thinking that Python is C or Java, or 
whatever other language you're used to.

The second link is just bizarre. It claims that Python does not have 
nested, block variable scopes like I am accustomed to in nearly every 
other programming language I use, like C, C#, C++, Objective C, Perl, and 
Java. (Notice the common denominator?) But that's nonsense -- Python 
does have nested block variable scopes. This pitfall, if it is one, is 
that Python doesn't create a new scope for if-blocks. Coming from a 
Pascal background instead of C, it never even occurred to me that if-
blocks could be a new scope, or that anyone would possibly want it to be.

Again, the real pitfall is not Python, but imagining that Python is C.


 
 Maybe C++ needs better pub.  The guy who wrote the first of those
 articles says elswhere on his web site:
 
  My Python pitfalls article seems to be a popular read. It's
  written from a somewhat negative viewpoint: things that can go
  wrong. (Of course, that's useful; you're never going to do these
  things wrong again. Right? ;-) To counter-balance this, I think
  there should an article with a more positive viewpoint as well. So
  I was wondering, if I could collect 10 anti-pitfalls; parts of
  the Python language that are especially clever, elegant and
  intuitive.
 
 
 Good luck with that.

[quote]
I've seen Python criticized as ugly precisely because it doesn't have a 
trick-based view of the world. In many ways, it's a dull language, 
borrowing solid old concepts from many other languages  styles: boring 
syntax, unsurprising semantics, few automatic coercions, etc etc. But 
that's one of the things I like about it. -- Tim Peters

But even given that, here's a good start, the first four things that came 
to mind:

1. Program structure follows indentation. No more wars over where to put 
the braces. The presentation *is* the structure.

2. Namespaces.

3. Generators and iterators. Especially generators.

4. Exceptions. try blocks are fast, don't be scared to use them.



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


Re: Official IRC channel for Python?

2008-02-24 Thread Torsten Bronger
Hallöchen!

Steve Holden writes:

 js wrote:

 Really? maybe I'm been blocked from it...  thanks.

 Currently 479 users.

I'd be nice if we could achieve some sort of network effect in
[EMAIL PROTECTED]  I don't want to start a Jabber v. IRC
debate here; I simply prefer it and maybe others do so, too.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
-- 
http://mail.python.org/mailman/listinfo/python-list


simpleparse - what is wrong with my grammar?

2008-02-24 Thread Laszlo Nagy
The program below gives me segmentation fault (core dumped).

Environment:
   Linux gandalf-desktop 2.6.20-16-generic #2 SMP Tue Feb 12 05:41:34 
UTC 2008 i686 GNU/Linux
   Python 2.5.1

What is wrong with my grammar? Can it be an internal error in simpleparse?

Thanks,

   Laszlo


from simpleparse.common import numbers, strings, comments
from simpleparse.parser import Parser

declaration = r'''
expr:= paren_expr/unop_expr/binop_expr/word
paren_expr  := (,expr,)
unop_expr   := unop,expr
binop_expr  := expr,binop,expr
unop:= (+/-)
binop   := (|//@)
word:= [a-zA-Z], [a-zA-Z0-9_]*
'''

parser = Parser( declaration)
success, resultTrees, nextCharacter = 
parser.parse(testword,production=expr,processor=None)
print success


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


Re: Tkinter: Missing the last piece of the puzzle

2008-02-24 Thread MartinRinehart


Simon Forman wrote:
 yes! check out http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/464635

 HTH,
 ~Simon

Thanks, Simon. Looks like that will do it.

Actually, it looks like that will overdo it. I'll be setting File/Save
to enabled after every keystroke. Ideally, I'd like to set my statuses
when the user clicks the File option or types Alt-F. This makes me
wonder if there's a mixin that could find this event. Hmmm.

Alternatively, could modify this code to NOT reset the modified flag,
so I only get called on the first modification. Hmmm.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2008-02-24 Thread Arnaud Delobelle
On Feb 24, 8:08 am, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Sat, 23 Feb 2008 19:45:45 -0800, Jeff Schwab wrote:
 The second link is just bizarre. It claims that Python does not have
 nested, block variable scopes like I am accustomed to in nearly every
 other programming language I use, like C, C#, C++, Objective C, Perl, and
 Java. (Notice the common denominator?) But that's nonsense -- Python
 does have nested block variable scopes. This pitfall, if it is one, is
 that Python doesn't create a new scope for if-blocks. Coming from a
 Pascal background instead of C, it never even occurred to me that if-
 blocks could be a new scope, or that anyone would possibly want it to be.

I haven't read the link, but it is true that python  3 is deficient
in that area: names in an enclosing scope can be accessed but not
rebound.  In the latter case the interpreter assumes them to be local
names.  Python 3000 fixes this with the new 'nonlocal' compilation
directive.  E.g.

(python 2.5)

 def counter(acc=0, step=1):
... def tick():
... acc += step
... return acc
... return tick
...
 c = counter()
 c()
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 3, in tick
UnboundLocalError: local variable 'acc' referenced before assignment


(python 3.0)

 def counter(acc=0, step=1):
... def tick():
... nonlocal acc
... acc += step
... return acc
... return tick
...
 c = counter()
 c()
1
 c()
2


--
Arnaud

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


Re: looking for open source simulink clone in python

2008-02-24 Thread Stef Mientki
[EMAIL PROTECTED] wrote:
 Does anyone know of something like this? I've searched to no avail.
 GNUradio companion is promising but tied to gnuradio.
   
not exactly, this is what I've found until now

   * Orange http://magix.fri.uni-lj.si/orange/screenshots.asp
   * Elefant https://elefant.developer.nicta.com.au/
   * Enthought with Traits UI, they are developping it for a customer,
 and planned to show us something in december 2007, but I guess
 it's somewhat delayed.
   * Vision http://www.scripps.edu/%7Esanner/python/viper/index.html
   * Pyphant
 
http://www.fmf.uni-freiburg.de/service/Servicegruppen/sg_wissinfo/Software/Pyphant
 




So I decided to start another one, some results can be seen here:
 
http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_animations_screenshots.html
 


cheers,
Stef

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


Re: PHP Developer highly interested in Python (web development) with some open questions...

2008-02-24 Thread MartinRinehart
re encryption

I ran a small software company in the '80s. We did the unthinkable:
shipped our software with a money-back guarantee. Anyone could buy the
software, copy it and then request a full refund.

Return rate: 0.5%. Of the returns we guessed that about half of them
were for perfectly legit reasons.

Treat your customers as if they're all honest and ethical. Most of
them will be. The rest will defeat your encryption efforts or just
skip your product.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: n00b with urllib2: How to make it handle cookie automatically?

2008-02-24 Thread est
On Feb 23, 5:57 am, 7stud [EMAIL PROTECTED] wrote:
 On Feb 21, 11:50 pm, est [EMAIL PROTECTED] wrote:

  Hi all,

  I need urllib2 do perform series of HTTP requests with cookie from
  PREVIOUS request(like our browsers usually do ).

 Cookies from a previous request made in the currently running
 program?  Or cookies from requests that were made when you previously
 ran the program?







  from cookielib import CookieJar
  class SmartRequest():
  cj=CookieJar()
  def __init__(self, strUrl, strContent=None):
  self.Request=   urllib2.Request(strUrl, strContent)
  self.cj.add_cookie_header(self.Request)
  self.Response   =   urllib2.urlopen(Request)
  self.cj.extract_cookies(self.Response, self.Request)
  def url
  def read(self, intCount):
  return self.Response.read(intCount)
  def headers(self, strHeaderName):
  return self.Response.headers[strHeaderName]

  The code does not work because each time SmartRequest is initiated,
  object 'cj' is cleared. How to avoid that?
  The only stupid solution I figured out is use a global CookieJar
  object. Is there anyway that could handle all this INSIDE the class?

 Examine this code and its output:

 class SmartRequest(object):
 def __init__(self, id):
 if not getattr(SmartRequest, 'cj', None):
 SmartRequest.cj = I'm a cookie jar. Created by request:

the getattr method is exactly what I am looking for, thanks!


On Feb 23, 2:05 pm, 7stud [EMAIL PROTECTED] wrote:
 On Feb 21, 11:50 pm, est [EMAIL PROTECTED] wrote:



  class SmartRequest():

 You should always define a class like this:

 class SmartRequest(object):

 unless you know of a specific reason not to.

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


iter(lambda:f.read(8192),'')

2008-02-24 Thread gert
what is the difference between iter(lambda:f.read(8192), ') and
iter(f.read(8192),'') ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Ruby with Netbeans question!

2008-02-24 Thread Steve
Hi all
Hope I`m ok posting a Netbeans query here?. I`m trying to learn Ruby
using the Netbeans IDE. It seems a pretty slick application but I`m
wondering if its possible to run a prog without creating a `new
project` each time?. I just want to be able to type in a few lines of
code and run it but it keeps running the `main project` which might be
an earlier prog I have written??. I`m sure the solution is staring me
in the face but would be grateful for any tips folk could provide.
Cheers
Steve
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: advanced usage of python threads

2008-02-24 Thread hyperboreean
Chris, I have already made my choice, I am asking just for a little help 
with some documentation.
I know about twisted.enterprise.adbapi, but the company is working with 
sqlalchemy at the time.
So please, I know you have good intentions but you're kind of not 
helping me :)
Well, probably instead of asking you people I should just start 
searching the net, thing that I am already doing. But if any of you has 
some info, please share.

Thanks.

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


Re: Ruby with Netbeans question!

2008-02-24 Thread Quentin Gallet-Gilles
Hi Steve,

Considering this is a Python list, I doubt you'll get much help for
something related to Netbeans and Ruby.
You're better off asking questions on the proper list :
http://www.netbeans.org/community/lists/

Quentin

On Sun, Feb 24, 2008 at 12:26 PM, Steve [EMAIL PROTECTED] wrote:

 Hi all
 Hope I`m ok posting a Netbeans query here?. I`m trying to learn Ruby
 using the Netbeans IDE. It seems a pretty slick application but I`m
 wondering if its possible to run a prog without creating a `new
 project` each time?. I just want to be able to type in a few lines of
 code and run it but it keeps running the `main project` which might be
 an earlier prog I have written??. I`m sure the solution is staring me
 in the face but would be grateful for any tips folk could provide.
 Cheers
 Steve
 --
 http://mail.python.org/mailman/listinfo/python-list

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

Re: Ruby with Netbeans question!

2008-02-24 Thread Steve
On Feb 24, 11:26 am, Steve [EMAIL PROTECTED] wrote:
 Hi all
 Hope I`m ok posting a Netbeans query here?. I`m trying to learn Ruby
 using the Netbeans IDE. It seems a pretty slick application but I`m
 wondering if its possible to run a prog without creating a `new
 project` each time?. I just want to be able to type in a few lines of
 code and run it but it keeps running the `main project` which might be
 an earlier prog I have written??. I`m sure the solution is staring me
 in the face but would be grateful for any tips folk could provide.
 Cheers
 Steve

Sorry folks wrong group!!.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: n00b with urllib2: How to make it handle cookie automatically?

2008-02-24 Thread est
On Feb 23, 2:42 am, Rob Wolfe [EMAIL PROTECTED] wrote:
 est [EMAIL PROTECTED] writes:
  Hi all,

  I need urllib2 do perform series of HTTP requests with cookie from
  PREVIOUS request(like our browsers usually do ). Many people suggest I
  use some library(e.g. pycURL) instead but I guess it's good practise
  for a python beginner to DIY something rather than use existing tools.

  So my problem is how to expand the urllib2 class

  from cookielib import CookieJar
  class SmartRequest():
      cj=CookieJar()
      def __init__(self, strUrl, strContent=None):
          self.Request    =   urllib2.Request(strUrl, strContent)
          self.cj.add_cookie_header(self.Request)
          self.Response   =   urllib2.urlopen(Request)
          self.cj.extract_cookies(self.Response, self.Request)
      def url
      def read(self, intCount):
          return self.Response.read(intCount)
      def headers(self, strHeaderName):
          return self.Response.headers[strHeaderName]

  The code does not work because each time SmartRequest is initiated,
  object 'cj' is cleared. How to avoid that?
  The only stupid solution I figured out is use a global CookieJar
  object. Is there anyway that could handle all this INSIDE the class?

  I am totally new to OOP  python programming, so could anyone give me
  some suggestions? Thanks in advance

 Google for urllib2.HTTPCookieProcessor.

 HTH,
 Rob- Hide quoted text -

 - Show quoted text -

Wow, thank you Rob Wolfe! Your reply is shortest yet most helpful! I
solved this problem by the following code.

class HTTPRefererProcessor(urllib2.BaseHandler):
Add Referer header to requests.

This only makes sense if you use each RefererProcessor for a
single
chain of requests only (so, for example, if you use a single
HTTPRefererProcessor to fetch a series of URLs extracted from a
single
page, this will break).

There's a proper implementation of this in module mechanize.


def __init__(self):
self.referer = None

def http_request(self, request):
if ((self.referer is not None) and
not request.has_header(Referer)):
request.add_unredirected_header(Referer, self.referer)
return request

def http_response(self, request, response):
self.referer = response.geturl()
return response

https_request = http_request
https_response = http_response

def main():
cj = CookieJar()
opener = urllib2.build_opener(
urllib2.HTTPCookieProcessor(cj),
HTTPRefererProcessor(),
)
urllib2.install_opener(opener)

urllib2.urlopen(url1)
urllib2.urlopen(url2)

if __main__ == __name__:
main()

And it's working great!

Once again, thanks everyone!
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2008-02-24 Thread Matthew Woodcraft
Jeff Schwab  [EMAIL PROTECTED] wrote:
 Matthew Woodcraft wrote:
 I see. Then, unless you don't care about data loss passing silently,
 this 'most traditional' way to open a file is unsuitable for files
 opened for writing.

 No, why would you think so?  If you want something special to happen 
 when the close() fails (as you indeed would if you were writing 
 important data), you have to say somehow that you want your special code 
 called.  What syntax would you like to see?  Here's what the C++ would 
 look like, supposing you have a type LoggingCloser that calls close and 
 logs any failure:

Sure, but this LoggingCloser isn't what you described as the 'most
traditional, easiest way to open a file in C++'.

The more general point is that, where you want to take action on
cleanup and you need to handle errors from this action, it usually
isn't enough to have one class per type of resource which knows what
clean up action is required (because the required response to the error
usually varies).

Additionally, in languages where exceptions are the usual way to report
errors but exceptions from destructors are not managed pleasantly, the
error recovery code can't use the language's normal mechanisms for
dealing with the error response.

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


Re: iter(lambda:f.read(8192),'')

2008-02-24 Thread Dustan
On Feb 24, 5:11 am, gert [EMAIL PROTECTED] wrote:
 what is the difference between iter(lambda:f.read(8192), ') and
 iter(f.read(8192),'') ?

One does not work, and one is syntactically incorrect:

 iter(f.read(8192),'')

Traceback (most recent call last):
  File pyshell#0, line 1, in module
iter(f.read(8192),'')
TypeError: iter(v, w): v must be callable
 iter(lambda:f.read(8192), ')

SyntaxError: EOL while scanning single-quoted string

To clarify:

f.read(8192) returns the next 8192 bytes of the file in a string, or
whatever is leftover, or an empty string when the file is exhausted.
lambda: f.read(8192) is a function that will return the next 8192
bytes of the file every time it is called.

So iter(f.read(8192),'') is evaluated as iter(some_string, ''). When
iter receives two arguments, it expects the first to be a function,
not a string.

iter(lambda:f.read(8192), '') (what you probably meant) is what it
looks like: iter(some_func, '').
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: graphing/plotting with python and interface builder

2008-02-24 Thread Diez B. Roggisch
Jacob Davis schrieb:
 I found SM2DGraphView, but I guess that I am too much of a newbie with 
 interface builder and pyobjc to figure out how to get SM2DGraphView to 
 work.  Are there any good tutorials (or better yet, examples) of how to 
 get SM2DGraphView to work?
 
 I don't know pyobjc well at all.

There isn't much to it. Unfortunately, there aren't many good tutorials, 
but at least a few examples in the pyobjc repository.

below is my code for implementing the SM2DGraphDataSource category. It 
is of course interspersed with my application-logic, but should give you 
a start.

Additionally, you need to load the SM2DGraphView-framework. The code to 
do so is also below.

Diez

#
#  BCGraphViewController.py
#  BruceControl
#
#  Created by Diez Roggisch on 22.02.08.
#  Copyright (c) 2008 __MyCompanyName__. All rights reserved.
#

from Foundation import *
from AppKit import *
import sys
from PyObjCTools import NibClassBuilder
import objc
MODES = displaySpeed, displayPosition

kSM2DGraph_Axis_Y = 0
kSM2DGraph_Axis_X = 1

kSM2DGraph_Axis_Y_Right = 2
kSM2DGraph_Axis_Y_Left = kSM2DGraph_Axis_Y

class BCGraphViewController(NibClassBuilder.AutoBaseClass):

 _displayPosition = False
 _displaySpeed = False


 def displayPosition(self):
 return self._displayPosition

 def setDisplayPosition_(self, v):
 self._displayPosition=  v
 self.reloadData()


 def displaySpeed(self):
 return self._displaySpeed

 def setDisplaySpeed_(self, v):
 self._displaySpeed=  v
 self.reloadData()


 def awakeFromNib(self):
 self._displayed_mis =  []
 self._ts_min = 0.0
 self._ts_max = 0.0
 self.graphView.setDataSource_(self)

 def setMotorInfos_(self, motor_infos):
 self._motor_infos = motor_infos
 # apparently, it's enough to just
 # subscribe once
 motor_infos[0].subscribeDisplayChanged(self)

 def setConnector_(self, connector):
 self._connector = connector
 connector.subscribeStateListener(self)

 def stateArrived_(self, n):
 state = n.object()
 ts  = float(state.timestamp) / 10.0 # nano to seconds
 if self._ts_min == 0:
 self._ts_min = ts
 self._ts_max = ts

 def reloadData(self):
 if self.numberOfLinesInTwoDGraphView_(None):
 self.graphView.reloadData()
 self.graphView.reloadAttributes()

 def displayChanged_(self, n):
 motor_info = n.object()
 motor_id = motor_info.motor_id
 if motor_info.display() and motor_info not in self._displayed_mis:
 self._displayed_mis.append(motor_info)
 else:
 try:
 self._displayed_mis.remove(motor_info)
 except ValueError:
 pass
 self.reloadData()

 @property
 def active_modes(self):
 return [mode for mode in MODES if getattr(self, mode)()]

 @property
 def activated_views(self):
 return len(self.active_modes)

 @objc.signature('I@:@')
 def numberOfLinesInTwoDGraphView_(self, view):
 res =  len(self._displayed_mis) * self.activated_views
 return res

 @objc.signature('@@:@I')
 def twoDGraphView_dataForLineIndex_(self, view, lineIndex):
 av = self.activated_views
 # first, compute the mi to be used
 offset = lineIndex // av
 mi = self._motor_infos[offset]
 mode = self.active_modes[lineIndex % av]
 return mi[mode]

 @objc.signature('d@:@Ii')
 def twoDGraphView_maximumValueForLineIndex_forAxis_(self, view, 
lineIndex, axis):
 if not self.numberOfLinesInTwoDGraphView_(view):
 return .0
 av = self.activated_views
 mode = self.active_modes[lineIndex % av]
 if axis == kSM2DGraph_Axis_Y:
 maxs = [mi.max[mode] for mi in self._displayed_mis]
 return max(maxs)
 elif axis == kSM2DGraph_Axis_X:
 return float(self._ts_max)
 return .0

 @objc.signature('d@:@Ii')
 def twoDGraphView_minimumValueForLineIndex_forAxis_(self, view, 
lineIndex, axis):
 if not self.numberOfLinesInTwoDGraphView_(view):
 return .0
 av = self.activated_views
 mode = self.active_modes[lineIndex % av]
 if axis == kSM2DGraph_Axis_Y:
 mins = [mi.min[mode] for mi in self._displayed_mis]
 return min(mins)
 elif axis == kSM2DGraph_Axis_X:
 return float(self._ts_min)
 return .0

 @objc.signature('@@:@I')
 def twoDGraphView_attributesForLineIndex_(self, view, lineIndex):
 try:
 if not self.numberOfLinesInTwoDGraphView_(None):
 return None
 av = self.activated_views
 # first, compute the mi to be used
 offset = lineIndex // av
 mi = self._motor_infos[offset]
 res = 

Re: PHP Developer highly interested in Python (web development) with some open questions...

2008-02-24 Thread Christian Heimes
Tamer Higazi wrote:
 - What is the Zope Applikation Server? Is it also a Webserver like the
 Apache or Tomcat Webserver?

Zope is much more than a webserver. It's a web application server
including a fast object database (ACID, support clustering and MVCC), a
powerful plugin architecture, builtin security and many, many more.

Read http://en.wikipedia.org/wiki/Zope

 - Is there a way of Round Tripp engineering based on UML XMI Files to
 generate python files (with it's dependencies) 

Plone and Archetypes (based on Zope) have a tool named ArchGenXML. It
takes UML XMI files and generates content types, workflows and products
for the Plone CMS.

 - Let us assume, I want to write a Web application in Python (what I did
 now in PHP5) and want to distribute my work under commercial usage.
 
 Can I encrypt my work and generate Licence Files for Customers who would
 purchase my End-Sollution like with:

Source code encryption can't stop people from reading or stealing your
code. Microsoft tries it, Apple tries it and even the RIAA tries it.
None of them had success in the past. :]

A proper service contract is more important.

Christian

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


Pydev/Eclipse: How to add filters for the navigator ?

2008-02-24 Thread Nebur
Running the latest version of pydev (1.3.13).
I failed to figure out how to add a filter that excludes stuff like
*.pyc from the file navigator. The Filters... dialogue allows to
Select All and Deselect All, but from an empty list :-(
What's the trick ? Thanks ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ILeo (IPython-Leo bridge); a marriage made in heaven?

2008-02-24 Thread shakeeb . alireza
  Are you part of Leo? This smells like a marketing scheme to me.

Actually this is an example of a beautiful collaboration between
Edward (the progenitor of leo) and Ville (the ipython side).

Fantastic and elegant stuff, which you have to try to appreciate.

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


Re: PHP Developer highly interested in Python (web development) with some open questions...

2008-02-24 Thread Tamer Higazi

Am Sonntag, den 24.02.2008, 13:44 +0100 schrieb Christian Heimes:
 
 Plone and Archetypes (based on Zope) have a tool named ArchGenXML. It
 takes UML XMI files and generates content types, workflows and products
 for the Plone CMS.

I don't want workflows, I want the classes and methods generated. Or do
I understand this answer wrong

 Source code encryption can't stop people from reading or stealing your
 code. Microsoft tries it, Apple tries it and even the RIAA tries it.
 None of them had success in the past. :]
 
 A proper service contract is more important.

Not true! you can disassemble the app and then have fun reading, not
that easy. I simply want that nobody reads the sourcecode or better
said the content of the python files I would have generated. 

But I think I have found one sollution. I have red that the bytecode
compiler from Python is very advanced (more then the PHP bcompiler) to
give me good brotection. 

Still I will have to look a lot for Python libraries which give me the
same hardcore feeling like ezComponent (ez.no). 

I think Python is great! And I will soon dive there in! 

:) 

What is the difference between Ruby and Python? Can anyone say that to
me? 

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


Re: advanced usage of python threads

2008-02-24 Thread Steve Holden
hyperboreean wrote:
 Chris, I have already made my choice, I am asking just for a little help 
 with some documentation.
 I know about twisted.enterprise.adbapi, but the company is working with 
 sqlalchemy at the time.
 So please, I know you have good intentions but you're kind of not 
 helping me :)
 Well, probably instead of asking you people I should just start 
 searching the net, thing that I am already doing. But if any of you has 
 some info, please share.
 
 Thanks.
 
Well, if you plan to use threading with Twisted you would probably be a 
lot better off asking questions on the Twisted mailing list.

   [EMAIL PROTECTED]

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: Official IRC channel for Python?

2008-02-24 Thread Steve Holden
Torsten Bronger wrote:
 Hallöchen!
 
 Steve Holden writes:
 
 js wrote:

 Really? maybe I'm been blocked from it...  thanks.
 Currently 479 users.
 
 I'd be nice if we could achieve some sort of network effect in
 [EMAIL PROTECTED]  I don't want to start a Jabber v. IRC
 debate here; I simply prefer it and maybe others do so, too.
 
The best way to achieve this may be to challenge the Twisted guys who 
habitually hang out on Python to do it in under ten lines :-)

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: iter(lambda:f.read(8192),'')

2008-02-24 Thread gert
aha ok got it :)

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


To PEAK or not to PEAK

2008-02-24 Thread Tzury Bar Yochay
I am about to start a large-scale enterprise project next month (I
insist on using Python instead Java and .NET and I am sure `they` will
thank me eventually).

I was wondering around making my components-and-libraries-shopping-
list and came across PEAK.
My paranoia is that PEAK would make me write my application in PEAK
instead of Python
(I felt that in the past with Django).

Therefore, I would like to hear the voices of you which have any
experience with PEAK.
Whether you are using it or used it in the past or tried to use it and
abandoned it.

How happy were you while using it?
How simple it is to use?

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


[ANN] Shed Skin (restricted) Python-to-C++ compiler 0.0.27

2008-02-24 Thread Mark Dufour
Hi all,

I have just released Shed Skin 0.0.27. Thanks in large part to the
GHOP students, this new release comes with some interesting new
goodies:

- support for 're', via libpcre (perl-compatible-regular-expressions)
- support for 'time' (except for time.strptime under Windows)
- basic support for 'staticmethod' and 'property'
- support for 'fnmatch', 'glob' (bootstrapped)
- improved support for 'os' (POSIX)
- OSX support again (including extension modules!)
- many fixes for multi-dir/multi-file projects
- several builtin optimizations (zip, list(str)..)
- type model for 'datetime' (no C++ implementation yet)
- split up compiler core, ss.py, into several files
- many minor bugfixes

As for the 4 new modules (re, time, fnmatch, glob), this means Shed
Skin now supports most of the following modules:

bisect
collections
copy
fnmatch
getopt
glob
math
os
os.path
random
re
string
sys
time

I could still really use some help with implementing/bootstrapping
implementations for 'datetime' and 'socket', and further improving
'os' (especially under Windows).

Note that since the previous release we have a nice tutorial online.
It explains in detail how to install and use Shed Skin, how to use it
to build (simple) extension modules and how to combine Shed Skin with
numpy and parallel processing solutions such as Parallel Python.


Thanks,
Mark Dufour.
-- 
One of my most productive days was throwing away 1000 lines of code
- Ken Thompson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] Shed Skin (restricted) Python-to-C++ compiler 0.0.27

2008-02-24 Thread Mark Dufour
Of course I forgot to add the URL:

http://shedskin.googlecode.com


Mark Dufour.
-- 
One of my most productive days was throwing away 1000 lines of code
- Ken Thompson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PHP Developer highly interested in Python (web development) with some open questions...

2008-02-24 Thread Paul Boddie
On 24 Feb, 14:33, Tamer Higazi [EMAIL PROTECTED] wrote:

 Not true! you can disassemble the app and then have fun reading, not
 that easy. I simply want that nobody reads the sourcecode or better
 said the content of the python files I would have generated.

Some quick answers:

http://wiki.python.org/moin/HowDoYouProtectSource

[...]

 Still I will have to look a lot for Python libraries which give me the
 same hardcore feeling like ezComponent (ez.no).

http://wiki.python.org/moin/WebProgramming

 I think Python is great! And I will soon dive there in!

 :)

Great!

 What is the difference between Ruby and Python? Can anyone say that to
 me?

http://wiki.python.org/moin/PythonVsRuby

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


Re: mapping problem

2008-02-24 Thread Mr Shore
yes
you guessed perfectly
I'm not a native English speaker
sorry for my poor english..
On Feb 16, 6:35 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Sat, 16 Feb 2008 01:35:32 -0800,MrShorewrote:
  I've now crawled the meta infor,but with multi name all means the same
  thing,
  such as MS,microsoft,microsoft corporation all means the same thing, how
  can I mapping words like this to the same thing?

 The same way you would map anything: use a dict.

 You know, sometimes I'm astounded by the ability of the human brain to
 find semantic meaning in what is grammatically and syntactically
 gibberish. Most of the words are English, but putting them all together
 makes no sense. And yet, by interpolating between key words, I can guess
 that the poster wants something like this:

 mapping = {MS: Microsoft, Microsoft: Microsoft,
 Microsoft Corporation: Microsoft}

 If I have guessed poorly, could you please try again, more carefully? If
 you're not a native English speaker, please say so and we'll make
 allowances, and if you are a native English speaker with no cognitive
 disabilities, you should be ashamed of wasting our time with such poor
 communication.

 --
 Steven
 who is unapologetic for being grumpy about the oxygen-thieves using the
 Internet these days, and if that makes me a curmudgeon, so be it.

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


Re: Seeing locals() from imported function

2008-02-24 Thread Luis M. González
This is one of these times when I feel so dumb and ashamed that I
wished I never dared to ask...
Well, that did the trick. Thanks!

luis

On Feb 24, 3:41 am, 7stud [EMAIL PROTECTED] wrote:
 Yes, define your functions so that they get all the input they need
 from the arguments that are passed in.

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


Re: mapping problem

2008-02-24 Thread Mr Shore
On Feb 16, 6:35 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Sat, 16 Feb 2008 01:35:32 -0800,MrShorewrote:
  I've now crawled the meta infor,but with multi name all means the same
  thing,
  such as MS,microsoft,microsoft corporation all means the same thing, how
  can I mapping words like this to the same thing?

 The same way you would map anything: use a dict.

 You know, sometimes I'm astounded by the ability of the human brain to
 find semantic meaning in what is grammatically and syntactically
 gibberish. Most of the words are English, but putting them all together
 makes no sense. And yet, by interpolating between key words, I can guess
 that the poster wants something like this:

 mapping = {MS: Microsoft, Microsoft: Microsoft,
 Microsoft Corporation: Microsoft}

 If I have guessed poorly, could you please try again, more carefully? If
 you're not a native English speaker, please say so and we'll make
 allowances, and if you are a native English speaker with no cognitive
 disabilities, you should be ashamed of wasting our time with such poor
 communication.

 --
 Steven
 who is unapologetic for being grumpy about the oxygen-thieves using the
 Internet these days, and if that makes me a curmudgeon, so be it.


in fact what I expected is a solution which can automatically do the
job
maybe something related with artificial intelligence
but seems feasible to do it manually
thx for all
and pre say sorry if my english once again caused your uncomfortable
in understanding.
-- 
http://mail.python.org/mailman/listinfo/python-list


_struct in Python 2.5.2

2008-02-24 Thread Olaf Schwarz
Hi,

I am trying to run this application
http://svn.navi.cx/misc/trunk/python/bemused/
on uNSLUng Linux 6.10 using the optware python packages.

As I obtained segmentation faults using Python 2.4, I have upgraded to
2.5.2. Now the execution terminates a lot earlier with this error
message:

  File /usr/local/bemused_mpd/bemused-mpd.py, line 33, in module
import bemused
  File /usr/local/bemused_mpd/bemused.py, line 27, in module
import bluetooth, syslog
  File /opt/lib/python2.5/site-packages/bluetooth.py, line 2, in
module
import struct
  File /opt/lib/python2.5/struct.py, line 30, in module
from _struct import Struct, error
ImportError: No module named _struct

I found out that there has been a file named _struct.so in 2.5.1 but
it has disappeared in 2.5.2. With no package available for downgrading
to 2.5.1 and no idea how to resolve this I am stuck at this point.

Any help appreciated.

Thank you
Olaf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asynchronous alarm

2008-02-24 Thread Alan Isaac
Paul Rubin wrote:
 a = Event()
 Thread(target=f, args=(a,)).start()
 raw_input('hit return when done: ')
 a.set()

Simple and elegant.
Thank you.
Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Seeing locals() from imported function

2008-02-24 Thread Steve Holden
Luis M. González wrote:
 This is one of these times when I feel so dumb and ashamed that I
 wished I never dared to ask...
 Well, that did the trick. Thanks!
 
 luis
 
 On Feb 24, 3:41 am, 7stud [EMAIL PROTECTED] wrote:
 Yes, define your functions so that they get all the input they need
 from the arguments that are passed in.
 
No need. You are allowed to learn.

If you come back with the same question ina week's time, *then* you can 
expect trouble ;-)

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: Article of interest: Python pros/cons for the enterprise

2008-02-24 Thread Lou Pecora
Just some anecdotal confirmation:

In article [EMAIL PROTECTED],
 Ryan Ginstrom [EMAIL PROTECTED] wrote:

 I personally used C++ for about 90% of my code for 10 years. During that
 time, I was chugging the C++ Kool-Aid so hard I almost peed myself. I still
 think that C++ is a beautiful language, but I have also come to think that
 starting a program with C++ is a premature optimization. 

Yes, I came to the same conclusion and now start all projects in Python, 
then add C/C++ extensions for optimization.  

 I think that very few Python programmers today started with Python. Most of
 them came to Python for a reason. 

Exactly right in my case.  In fact this observation is directly related 
to the one your the previous paragraph.  Python is a good language in 
which to start a progrom.

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


Re: some questions about ejabberd,spark and psi

2008-02-24 Thread Mr Shore
the url missed
http://allforces.com/2005/05/06/ichat-to-msn-through-jabber/
On 2月25日, 上午12时01分, Mr Shore [EMAIL PROTECTED] wrote:
 hi,every buddy
 I've now installed a jabber server,right it's ejabberd mentioned above
 and 2 jabber client,right again it's spark and psi
 and I can connect to jabber server by spark
 but failed by psi,saying 'certificate failed the authenticity
 test;Reason:certificate is self signed'
 and i follow this page to try to transport to MSN but once again
 failed
 the jabber server provided is obsolete so could anyone provide a valid
 jabber server?
 the third next is about the transport to MSN from ejabberd
 i'm running windowx XP os,with python vertion 2.5
 I downloaded the pyMSNT for windows but only to find it supports only
 vertion 2.2
 so is there any other way to transport to MSN besides pyMSNT?
 any advice will be appreciated:)

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

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

2008-02-24 Thread Lou Pecora
In article 
[EMAIL PROTECTED],
 Nicola Musatti [EMAIL PROTECTED] wrote:

 On Feb 22, 12:07 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
  Nicola Musatti [EMAIL PROTECTED] writes:
   In C++ memory is just another resource which you can handle just like
   any other one, possibly using RAII.
 
  Ok, I'll bite.  Here's a straightforward Python expression:
 
 a = [f(x) + g(y) for x,y in izip(m1, m2) if h(x,y).frob() == 7]
 
  Consider how many intermediate objects are being allocated in figuring
  out that listcomp.  Do you REALLY want to manage all the deallocation
  with something like RAII?
 
 
 What makes you think that a translation of a similar expression would
 involve explicit dynamic allocation at all? Barring bugs, here's an
 equivalent example:
 
 #include iostream
 #include map
 #include vector

[cut a lot of C++ code]

I realize the original point was about dynamic allocation and GC, but 
for me the raw juxtaposition of the *one* line of clear Python code with 
the equivalent mass of C++ code is shocking.  Thanks for that.

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


Re: simpleparse - what is wrong with my grammar?

2008-02-24 Thread Gary Herron
Laszlo Nagy wrote:
 The program below gives me segmentation fault (core dumped).

 Environment:
Linux gandalf-desktop 2.6.20-16-generic #2 SMP Tue Feb 12 05:41:34 
 UTC 2008 i686 GNU/Linux
Python 2.5.1

 What is wrong with my grammar? Can it be an internal error in simpleparse?
   
There's no way to tell from here.  It's almost certainly a problem with 
simpleparse.  Can you contact the developers of simpleparse? 

There is more you can do on your own:  Use a debugger or prints to 
decide which python line is causing this.  (Almost certainly the 
parse.parse, but *make sure* of that ...)  Then start reducing your 
grammar bit-by-bit until you get a working grammar and so narrow in on 
the portion that's causing this problem. 

This way, you may answer your own question, or provide enough 
information to motivate any knowledgeable volunteers to actually 
volunteer their time.

Good luck.

Gary Herron

 Thanks,

Laszlo


 from simpleparse.common import numbers, strings, comments
 from simpleparse.parser import Parser

 declaration = r'''
 expr:= paren_expr/unop_expr/binop_expr/word
 paren_expr  := (,expr,)
 unop_expr   := unop,expr
 binop_expr  := expr,binop,expr
 unop:= (+/-)
 binop   := (|//@)
 word:= [a-zA-Z], [a-zA-Z0-9_]*
 '''

 parser = Parser( declaration)
 success, resultTrees, nextCharacter = 
 parser.parse(testword,production=expr,processor=None)
 print success


   

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


some questions about ejabberd,spark and psi

2008-02-24 Thread Mr Shore
hi,every buddy
I've now installed a jabber server,right it's ejabberd mentioned above
and 2 jabber client,right again it's spark and psi
and I can connect to jabber server by spark
but failed by psi,saying 'certificate failed the authenticity
test;Reason:certificate is self signed'
and i follow this page to try to transport to MSN but once again
failed
the jabber server provided is obsolete so could anyone provide a valid
jabber server?
the third next is about the transport to MSN from ejabberd
i'm running windowx XP os,with python vertion 2.5
I downloaded the pyMSNT for windows but only to find it supports only
vertion 2.2
so is there any other way to transport to MSN besides pyMSNT?
any advice will be appreciated:)
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2008-02-24 Thread Jeff Schwab
Matthew Woodcraft wrote:
 Jeff Schwab  [EMAIL PROTECTED] wrote:
 Matthew Woodcraft wrote:
 I see. Then, unless you don't care about data loss passing silently,
 this 'most traditional' way to open a file is unsuitable for files
 opened for writing.
 
 No, why would you think so?  If you want something special to happen 
 when the close() fails (as you indeed would if you were writing 
 important data), you have to say somehow that you want your special code 
 called.  What syntax would you like to see?  Here's what the C++ would 
 look like, supposing you have a type LoggingCloser that calls close and 
 logs any failure:
 
 Sure, but this LoggingCloser isn't what you described as the 'most
 traditional, easiest way to open a file in C++'.

It's not there to open the file, it's there to check the error code on 
close.  That's what you said you wanted.


 The more general point is that, where you want to take action on
 cleanup and you need to handle errors from this action, it usually
 isn't enough to have one class per type of resource which knows what
 clean up action is required (because the required response to the error
 usually varies).

If there is variation, you can either pass some data to the responsible 
object's constructor, or you can give it policies for what to do in 
different situations.

http://en.wikipedia.org/wiki/Policy-based_design


 Additionally, in languages where exceptions are the usual way to report
 errors but exceptions from destructors are not managed pleasantly, the
 error recovery code can't use the language's normal mechanisms for
 dealing with the error response.

Huh?  Why not?
-- 
http://mail.python.org/mailman/listinfo/python-list


Developing Techniques (and naming conventions)

2008-02-24 Thread Adekoba
I have some questions... Say we have a package food

food/
  __init__.py
  ham.py
  cheese.py

Is it possible to have a file named food.py in the package and have
non-referential imports work? i.e., for ham.py to have a line import
food.food. From my experience, python will not work with this.


Alright, new scenario. Say we had:

food.py
food/
  __init__.py
  ham.py
  cheese.py

where food.py is a script that uses the package food. Is it possible
for this to work in any way? Every time I try to run food.py, python
tries to import everything from the script instead of from the
package. How can I fix this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a open souce IDE writen by C( C++) or partly writen by C( C++)?

2008-02-24 Thread Lie
On Feb 24, 11:23 am, zaley [EMAIL PROTECTED] wrote:
 On Feb 24, 6:48 am, Ricardo Aráoz [EMAIL PROTECTED] wrote:



  Lie wrote:
   On Feb 23, 4:02 pm, zaley [EMAIL PROTECTED] wrote:
   On Feb 22, 11:06 pm, Jesper polluks(#at#)post.tele.dk wrote:

   Give PyScripter fromhttp://www.mmm-experts.com/atry
   It is for Windows, though it is written in Delphi and not in C/C++
   /Jesper
   zaley [EMAIL PROTECTED] skrev i en meddelelsenews:[EMAIL PROTECTED]
   Of course, python scripts debugger
   On 2ÔÂ22ÈÕ, ÏÂÎç3ʱ22·Ö, zaley [EMAIL PROTECTED] wrote:
   My project need a simple scripts debugger . I hope I can find
   something instructive
   Stefan Behnel дµÀ£º
   zaley wrote:
   Is there a open souce IDE writen by C( C++) or partly writen by C( C+
   +)?
   Tons of them. What do you want to do with it?
   Stefan- Hide quoted text -
   - Show quoted text -
   But PyScripter is not a open source project

   Am I correct to say that the reason why you wanted an open source C++
   IDE is because you wanted the freedom to modify your own programming
   environment?
  From the About window in PyScripter :

  
  A freeware, open source Python scripter integrated
  development environment created with the ambition to bring to
  the Python community the quality and functionality available in
  commercial IDEs available for other languages.
  

  So I think we could say PyScripter IS an open source project.- Hide quoted 
  text -

  - Show quoted text -

 Really, what I want to do is that scripts can be executed step by
 step .
 I know By Py_Runstring  clauses  in main function can executed by
 step .
 But I can't know how to step into a function and how to step in a
 function.
 So I hope I can find something helpful in open source IDE for python.

IDLE (and all IDE's I know) can run programs step-by-step. In IDLE,
you've got to open the debug dialog (Debug - Debugger). After opening
the debug dialog, you run your programs like normal and your program
execution would be halted on the first command until you navigate
yourself through the debug dialog. The debug dialog has a few buttons:
Go, Step, Over, Out, Quit. Go means your program would run until it
met a breakpoint[1], Step means your program would execute the next
instruction, Over means your program would execute until the next
instruction in the same level (you'll see what I meant after you
played around it for a while), Out means your program would execute
until it goes out of the current level, and Quit is like giving a
KeyboardInterrupt (it stops program execution)

[1] Set a breakpoint by right-clicking on a code line then select set
breakpoint.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-02-24 Thread Steve Holden
Lie wrote:
 On Feb 18, 1:25 pm, Carl Banks [EMAIL PROTECTED] wrote:
 On Feb 17, 1:45 pm, Lie [EMAIL PROTECTED] wrote:

 Any iteration with repeated divisions and additions can thus run the
 denominators up.  This sort of calculation is pretty common (examples:
 compound interest, numerical integration).
 Wrong. Addition and subtraction would only grow the denominator up to
 a certain limit
 I said repeated additions and divisions.
 
 Repeated Addition and subtraction can't make fractions grow
 infinitely, only multiplication and division could.
 
On what basis is this claim made?

(n1/d1) + (n2/d2) = ((n1*d2) + (n2*d1)) / (d1*d2)

If d1 and d2 are mutually prime (have no common factors) then it is 
impossible to reduce the resulting fraction further in the general case 
(where n1 = n2 = 1, for example).

 Anyways, addition and subtraction can increase the denominator a lot
 if for some reason you are inputing numbers with many different
 denominators.
 
 Up to a certain limit. After you reached the limit, the fraction would
 always be simplifyable.
 
Where does this magical limit appear from?

 If the input numerator and denominator have a defined limit, repeated
 addition and subtraction to another fraction will also have a defined
 limit.

Well I suppose is you limit the input denominators to n then you have a 
guarantee that the output denominators won't exceed n!, but that seems 
like a pretty poor guarantee to me.

Am I wrong here? You seem to be putting out unsupportable assertions. 
Please justify them or stop making them.

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: How about adding rational fraction to Python?

2008-02-24 Thread Lie
On Feb 18, 1:25 pm, Carl Banks [EMAIL PROTECTED] wrote:
 On Feb 17, 1:45 pm, Lie [EMAIL PROTECTED] wrote:

   Any iteration with repeated divisions and additions can thus run the
   denominators up.  This sort of calculation is pretty common (examples:
   compound interest, numerical integration).

  Wrong. Addition and subtraction would only grow the denominator up to
  a certain limit

 I said repeated additions and divisions.

Repeated Addition and subtraction can't make fractions grow
infinitely, only multiplication and division could.

 Anyways, addition and subtraction can increase the denominator a lot
 if for some reason you are inputing numbers with many different
 denominators.

Up to a certain limit. After you reached the limit, the fraction would
always be simplifyable.

If the input numerator and denominator have a defined limit, repeated
addition and subtraction to another fraction will also have a defined
limit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-02-24 Thread Lie
On Feb 25, 12:46 am, Steve Holden [EMAIL PROTECTED] wrote:
 Lie wrote:
  On Feb 18, 1:25 pm, Carl Banks [EMAIL PROTECTED] wrote:
  On Feb 17, 1:45 pm, Lie [EMAIL PROTECTED] wrote:

  Any iteration with repeated divisions and additions can thus run the
  denominators up.  This sort of calculation is pretty common (examples:
  compound interest, numerical integration).
  Wrong. Addition and subtraction would only grow the denominator up to
  a certain limit
  I said repeated additions and divisions.

  Repeated Addition and subtraction can't make fractions grow
  infinitely, only multiplication and division could.

 On what basis is this claim made?

 (n1/d1) + (n2/d2) = ((n1*d2) + (n2*d1)) / (d1*d2)

 If d1 and d2 are mutually prime (have no common factors) then it is
 impossible to reduce the resulting fraction further in the general case
 (where n1 = n2 = 1, for example).

  Anyways, addition and subtraction can increase the denominator a lot
  if for some reason you are inputing numbers with many different
  denominators.

  Up to a certain limit. After you reached the limit, the fraction would
  always be simplifyable.

 Where does this magical limit appear from?

  If the input numerator and denominator have a defined limit, repeated
  addition and subtraction to another fraction will also have a defined
  limit.

 Well I suppose is you limit the input denominators to n then you have a
 guarantee that the output denominators won't exceed n!, but that seems
 like a pretty poor guarantee to me.

 Am I wrong here? You seem to be putting out unsupportable assertions.
 Please justify them or stop making them.


Well, I do a test on my own fraction class. I found out that if we set
a limit to the numerators and denominators, the resulting output
fraction would have limit too. I can't grow my fraction any more than
this limit no matter how many iteration I do on them. I do the test is
by something like this (I don't have the source code with me right
now, it's quite long if it includes the fraction class, but I think
you could use any fraction class that automatically simplify itself,
might post the real code some time later):

while True:
a = randomly do (a + b) or (a - b)
b = random fraction between [0-100]/[0-100]
print a

And this limit is much lower than n!. I think it's sum(primes(n)), but
I've got no proof for this one yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Christian Heimes
Adekoba wrote:
 food.py
 food/
   __init__.py
   ham.py
   cheese.py
 
 where food.py is a script that uses the package food. Is it possible
 for this to work in any way? Every time I try to run food.py, python
 tries to import everything from the script instead of from the
 package. How can I fix this?

Move the code from food.py to food/__init__.py. You can't have a package
and a module with the same name.

Christian

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


Re: How about adding rational fraction to Python?

2008-02-24 Thread Mark Dickinson
On Feb 24, 1:09 pm, Lie [EMAIL PROTECTED] wrote:
 And this limit is much lower than n!. I think it's sum(primes(n)), but
 I've got no proof for this one yet.

It's the least common multiple of the integers 1 through n, or
equivalently the product over all primes p = n of the highest power
of p not exceeding n.  So for n = 100, it's:

64 * 81 * 25 * 49 * 11 * 13 * 17 * ... rest of primes up to 100.

For general n, this number is of roughly the same order of magnitude
as e**n.

See

http://www.research.att.com/~njas/sequences/A003418

for more.

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


most loved template engine on python is?

2008-02-24 Thread Tamer Higazi
Hi people!
After deciding choosing python as my future killer application language
for writing web applications, I need from you guys still some support,
if you apologize.

Question:
Which is the most loved template engine for python?


I see, that I can do more aspect oriented programming with python as
with ruby (as comparing those languages). God thanks, I do not have to
create an object for every small thing in python and still generate
classes and access methods statically.


Tamer

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


Re: Python for web...

2008-02-24 Thread Tamer Higazi
http://www.djangobook.com/

if you love to read that book online. Otherwise, if you don't have DSL,
just mirror the site for offline usage with wget

Tamer

[EMAIL PROTECTED] wrote:
 Hi everyone,
 
 I have to develop a web based enterprise application for my final year
 project. Since i am interested in open source, i searched the net.
 Almost 90% of them were PHP and MySQL. Cant we use python for that ? I
 tried several sites, but there is not enough tutorial for beginners
 [mod_python, PSP etc]. I couldnt find any detailed book, not even a
 single book :( All the python books are covering only CGI part)
 
 Any suggestions? Any recommended book?
 
 Execuse my English.
 
 Thushanthan.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-02-24 Thread Lie
On Feb 25, 1:21 am, Mark Dickinson [EMAIL PROTECTED] wrote:
 On Feb 24, 1:09 pm, Lie [EMAIL PROTECTED] wrote:

  And this limit is much lower than n!. I think it's sum(primes(n)), but
  I've got no proof for this one yet.

 It's the least common multiple of the integers 1 through n, or
 equivalently the product over all primes p = n of the highest power
 of p not exceeding n.  So for n = 100, it's:

 64 * 81 * 25 * 49 * 11 * 13 * 17 * ... rest of primes up to 100.

 For general n, this number is of roughly the same order of magnitude
 as e**n.

Ah, yes, I meant product(primes(n)), please forgive my honest mistake
which is partially caused by me not supposed to still be awake at this
time of the day. And thanks for Mark for noticing the mistake, and
here is the code I used:

import fraction
import random

frac = fraction.frac
ops = (frac.__add__, frac.__sub__)

a = frac(random.randrange(1, 10), random.randrange(1, 10))
b = frac(random.randrange(1, 10), random.randrange(1, 10))

while True:
o = ops[random.randrange(0, 2)]
a = o(a, b)
b = frac(random.randrange(1, 10), random.randrange(1, 10))
print a

I decided to keep the num/den limit low (10) because higher values
might obscure the fact that it do have limits. And through further
observations, I think it is sufficient if the limit is imposed in the
denominator only (numerator can have any values it wanted to,
denominator growth is determined only by the limit of denominator
growth).

I think I'll also post the code for the fraction class I used, if you
have other fraction class that can automatically simplify, you could
use that instead as this class suffers from a naive GCD
implementation:

 fraction.py 
from __future__ import division


def GCD(a, b):
if b == 0: return a
return GCD(b, a % b)


class frac:

''' Fraction Class



A fraction class.



Attributes:

num  - the numerator of a fraction

den  - the denominator of a fraction



Methods:

add(a, b)   - add fraction a to fraction b and return a
new fraction

sub(a, b)   - subtract fraction b from fraction a and
return a new fraction

mul(a, b)   - multiply fraction a with fraction b and
return a new fraction

div(a, b)   - divides fraction b from fraction a and
return a new fraction

invert(a)   - invert the fraction (switch the numerator
and denominator)

neg(a)  - negates the fraction (negates numerator)

powr(a, b)  - raise fraction a to the power of b

simplify(a, b)  - simplify fraction to its canonical
representation



__init__(a, b)  - creates a new fraction

__str__(a, b)   - returns a string representation. Mixed
fraction if possible

__repr__(a, b)  - returns a string representation. Always
return vulgar fraction



Operators:

Conversion to fractions will be done automatically whenever
possible, in-place

operation is fully supported. Both regular and reflected
operation is supported.

a + b  - Calls frac.add(a, b)

a - b  - Calls frac.sub(a, b)

a * b  - Calls frac.mul(a, b)

a / b  - Calls frac.div(a, b)

a // b - Floors the resulting fraction from frac.div(a, b)

-a - Negates a fraction

+a - Returns a copy of the fraction

~a - Return the reciprocal of a



Comparisons:

Implemented through __cmp__(a, b), no rich comparison.

a == b  - a equals b

a != b  - a not equal b

a  b   - a greater than b

a  b   - a less than b

a = b  - a greater than or equal to b

a = b  - a less than or equal to b



Casting:

__complex__ - Converts the fraction to floats and return the
result as complex number

__int__ - Returns the whole part of the fraction in
Integer

__long__- Returns the whole part of the fraction in Long

__float__   - Returns the value of the fractino in Float



Exceptions:

ZeroDenominatorError

- A fraction cannot have zero as its denominator



Bugs:

- At the meantime, the fraction class doesn't mix well if used

  together with floating type numbers. Inline operators and

  initializers implicitly assumed that numbers are either
integers or

  fraction. So if there are operations involving floating
point or

  you initialized a fraction with a floating point number, the
result

  would be something like a floating point fraction.

'''



def __init__(self, a = 0, b = 1):

dev = GCD(a, b)

if b  0:

self.num = a // dev

elif b  0:

self.num = -a // dev

else:

raise frac.ZeroDenominatorError



self.den = abs(b) // dev



def simplify(self):

dev = GCD(self.num, self.den)

self.num //= dev

 

Re: simpleparse - what is wrong with my grammar?

2008-02-24 Thread Mike C. Fletcher
Laszlo Nagy wrote:
 The program below gives me segmentation fault (core dumped).

 Environment:
Linux gandalf-desktop 2.6.20-16-generic #2 SMP Tue Feb 12 05:41:34 
 UTC 2008 i686 GNU/Linux
Python 2.5.1

 What is wrong with my grammar? Can it be an internal error in simpleparse?
   
You've created an infinitely recursing grammar.  SimpleParse is a 
straightforward recursive descent parser without look-ahead (unless 
explicitly coded) or ambiguity resolution.  You are asking it to parse 
expr to see if expr,binop,expr is matched.  It will continue 
recursing down into expr until it runs out of ram or otherwise 
encounters a system-level fault.

You need to disambiguate your grammar to have it work with SimpleParse.  
How you do that will depend on what you really meant by expr,binop,expr:

abc

could be parsed as either:

((ab)c)

or:

(a(bc))

the following creates a parser that produces the first option (which is, 
I *think* what you wanted):

expr:= (simple_expr,no_binop)/binop_expr

binop_expr := simple_expr,binop_tail
 simple_expr := (paren_expr/unop_expr/word)
 no_binop := ?-binop/end
end  := EOF

paren_expr  := (,expr,)
unop_expr   := unop,expr
 binop_tail  := binop,expr
unop:= (+/-)
binop   := (|//@)
word:= [a-zA-Z], [a-zA-Z0-9_]*

the ?- lookahead is reasonably inefficient, but lookahead is always 
going around discarding partial results anyway, so it's no worse than 
most other formulations.

HTH,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: ANN: Phatch = PHoto bATCH processor and renamer based on PIL

2008-02-24 Thread Daniel Fetchinson
 I'm pleased to announce the release of Phatch which is a
 powerful batch processor and renamer. Phatch exposes a big part of the
 Python Imaging Library through an user friendly GUI. (It is using
 python-pyexiv2 to offer more extensive EXIF and IPTC support.) Phatch
 is not targeted at manipulating individual pictures (such as with
 Gimp), but repeating the same actions on hundreds or thousands of
 images.

 If you know PIL and have some nice recipes laying around, it is very
 easy to write plugins as Phatch generates the corresponding GUI
 automagically just like in Django. Any existings PIL scripts can be
 added very easily. Let me know if you want to contribute or have any
 questions.

 Homepage: http://photobatch.stani.be (free download link below)
 Tutorials: http://photobatch.wikidot.com/tutorials
 Translations: https://translations.launchpad.net/phatch/trunk/+pots/phatch
 License: GPLv3
 Screenshot:
 http://photobatch.wikidot.com/local--files/start/Screenshot-Phatch3d.jpg
 (the perspective and reflection is produced by Phatch itself)

 Phatch has many features, like:
 - EXIF information inspector with thumbnail
 - limit jpeg file size when saving
 - tons of actions organized by tags (including perspective, round
 corners, shadow, reflection, ...)
 - console version (Phatch can now run without a gui on servers)
 - batch rename and copy files based on exif metadata
 - data stamping (http://photobatch.wikidot.com)
 - online documentation wiki (http://photobatch.wikidot.com)

 Linux only features:
 - desktop or panel droplets on which images or folders can be dropped
 (will be ported to Windows  Mac)
 - Nautilus and desktop integration (with its own mime type and
 nautilus extension)
 - manpage with examples

 With python-pyexiv2 the following featues are added:
 - embedding the original EXIF and IPTC tags in the image

 All actions mostly have a separate pil function in their source code,
 so they could be read as a recipe book for PIL:
 * Auto Contrast - Maximize image contrast
 * Background - Put colour under transparent image
 * Border - Crop or add border to all sides
 * Brightness - Adjust brightness from black to white
 * Canvas - Crop the image or enlarge canvas without resizing the image
 * Colorize - Colorize grayscale image
 * Common - Copies the most common pixel value
 * Contrast - Adjust from grey to black  white
 * Convert Mode - Convert the color mode of an image (grayscale, RGB,
 RGBA or CMYK)
 * Copy - Copy image file
 * Effect - Blur, Sharpen, Emboss, Smooth, ...
 * Equalize - Equalize the image histogram
 * Fit - Downsize and crop image with fixed ratio
 * Grayscale - Fade all colours to gray
 * Invert - Invert the colors of the image (negative)
 * Maximum - Copies the maximum pixel value
 * Mask - Apply a transparency mask
 * Median - Copies the median pixel value
 * Minimum - Copies the minimum pixel value
 * Offset - Offset by distance and wrap around
 * Posterize - Reduce the number of bits of colour channel
 * Perspective - Shear 2d or 3d
 * Rank - Copies the rank'th pixel value
 * Reflect - Drops a reflection
 * Rename - Rename image file
 * Rotate - Rotate with random angle
 * Round - Round or crossed corners with variable radius and corners
 * Saturation - Adjust saturation from grayscale to high
 * Save - Save an image with variable compression in different types
 * Scale - Scale an image with different resample filters.
 * Shadow - Drop a blurred shadow under a photo with variable position,
 blur and color
 * Solarize - Invert all pixel values above threshold
 * Text - Write text at a given position
 * Transpose - Flip or rotate an image by 90 degrees
 * Watermark - Apply a watermark image with variable placement (offset,
 scaling, tiling) and opacity

 I develop Phatch on Ubuntu/Linux, but I have tested and polished it
 regularly on Windows and Mac Os X. (Only the droplet functionality
 needs to be ported.) Phatch is submitted to Debian unstable and
 Ubuntu Hardy. Packagers for other platforms are welcome.

 Requirements:
 - PIL 1.1.5 or higher
 - wxPython 2.6 or higher
 - pyexiv2 (optional)
 - python nautilus bindings (optional)


Now that we are at image manipulation does anyone know of a good,
possibly python based, image manipulation tool that can do the same as
the windows tool andrea mosaic?

http://www.andreaplanet.com/andreamosaic/samples/

Stani, if this is a good place for feature requests I would like to add it :)

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


Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Adekoba
On Feb 24, 1:06 pm, Christian Heimes [EMAIL PROTECTED] wrote:
 Adekoba wrote:
  food.py
  food/
__init__.py
ham.py
cheese.py

  where food.py is a script that uses the package food. Is it possible
  for this to work in any way? Every time I try to run food.py, python
  tries to import everything from the script instead of from the
  package. How can I fix this?

 Move the code from food.py to food/__init__.py. You can't have a package
 and a module with the same name.

 Christian

So it is not possible?

I don't think moving food.py's code to __init__.py would work out to
well, because then how would I run the script?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: _struct in Python 2.5.2

2008-02-24 Thread Martin v. Löwis
 I found out that there has been a file named _struct.so in 2.5.1 but
 it has disappeared in 2.5.2. With no package available for downgrading
 to 2.5.1 and no idea how to resolve this I am stuck at this point.
 
 Any help appreciated.

Where did you get your copy of Python 2.5.2 from, and how did you
install it? _struct should be there; if it isn't, something went
wrong during the installation.

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


Re: most loved template engine on python is?

2008-02-24 Thread Daniel Fetchinson
 After deciding choosing python as my future killer application language
 for writing web applications, I need from you guys still some support,
 if you apologize.

 Question:
 Which is the most loved template engine for python?

AFAIK, there is no single blessed template system. If you're up to web
development then your choice of framework will limit the choices for
template engines. For example if you choose Django I guess you'll have
to stick with its built-in template system (I might be wrong on this)
while if you choose turbogears you can choose between, genshi, kid,
myghty and some others.

If you don't have your own preferences the best bet is choosing the
default template system that comes with your choice of web framework.
With turbogears 1 it means kid, with turbogears 2 it means genshi.

For more info please see http://wiki.python.org/moin/Templating


 I see, that I can do more aspect oriented programming with python as
 with ruby (as comparing those languages). God thanks, I do not have to
 create an object for every small thing in python and still generate
 classes and access methods statically.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: most loved template engine on python is?

2008-02-24 Thread Tim Chase
 AFAIK, there is no single blessed template system. If you're up to web
 development then your choice of framework will limit the choices for
 template engines. For example if you choose Django I guess you'll have
 to stick with its built-in template system (I might be wrong on this)

Django's templating system comes built-in when you install
Django, but it's just a module like any other Python module.
Django views all just return strings (or iterables), so you can
easily include your favorite templating engine if the default
doesn't do it for you.  Including

 genshi, kid, myghty and some others.

I've even (in a fit of laziness during a mockup) used python's
dictionary string formatting for a fast templating solution.

 For more info please see http://wiki.python.org/moin/Templating

They're are many to choose from, so pick one that works for you,
and it should plug fairly easily into your framework of choice.

-tkc



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


urllib slow on Leopard

2008-02-24 Thread mark
I've recently switched from Ubuntu to OS X Leopard. I have some python 
scripts which download info from the web. The scripts were working fine 
before on Ubuntu, but urllib seems to work really slowly on Leopard.

I tried an example from the docs:

  import urllib2
  f = urllib2.urlopen('http://www.python.org/')
  print f.read(100)
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
http://www.w3.org/TR/xhtml1/DTD/xhtm
 

The line f = ... takes about a minute to return - but otherwise returns 
the predicted result. My web connection seems fine, so has anyone got 
any ideas as to what the problem might be?
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2008-02-24 Thread Larry Bugbee
On Feb 21, 10:22 am, Nicola Musatti [EMAIL PROTECTED] wrote:
 On Feb 21, 6:31 pm, Paul Boddie [EMAIL PROTECTED] wrote:
 
  The main reason why C++ has declined in usage is because almost
  everything of practical value is optional.

No, disagree.

 The main reason why C++ has declined in usage is because it never got
 the kind of corporate marketing enjoyed by Java and C#.

I'm inclined to disagree for two reasons.  C++ is a very complex
language.  Java (and the later C#) less so.  Couple that with reduced
debugging time due to garbage collection and fewer pointer problems, a
lot of us decided a factor of 2x in personal productivity was worth
it.  Runtime was initially an impediment, and still is for desktop
applications, but the trade was worth it.

Corporate marketing, and corporate attention in general, saw to it
that Java was well equipped with libraries and frameworks addressing
enterprise application needs.  ...but the *big* reason Java won over C+
+ is because your application became stable sooner.  ...with arguably
fewer problems later.

And the migration to Python is due in large part because of an
additional factor of 3-4x in personal productivity (over Java).
Improvements in runtime performance wouldn't hurt, but for many
applications that's not an issue.  (If optional data typing were
offered, Python's penetration in the enterprise space would be even
higher, and I suspect there would be performance gains as well.)

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


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

2008-02-24 Thread Jeff Schwab
Larry Bugbee wrote:

 And the migration to Python is due in large part because of an
 additional factor of 3-4x in personal productivity (over Java).
 Improvements in runtime performance wouldn't hurt, but for many
 applications that's not an issue.  (If optional data typing were

You mean static data typing, right?  Are there any known holes in the 
dynamic type system that still need to be plugged?  (I haven't heard of 
any.)

 offered, Python's penetration in the enterprise space would be even
 higher, and I suspect there would be performance gains as well.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-02-24 Thread Mensanator
On Feb 24, 1:09�pm, Lie [EMAIL PROTECTED] wrote:
 On Feb 25, 1:21 am, Mark Dickinson [EMAIL PROTECTED] wrote:

  On Feb 24, 1:09 pm, Lie [EMAIL PROTECTED] wrote:

   And this limit is much lower than n!. I think it's sum(primes(n)), but
   I've got no proof for this one yet.

  It's the least common multiple of the integers 1 through n, or
  equivalently the product over all primes p = n of the highest power
  of p not exceeding n. �So for n = 100, it's:

  64 * 81 * 25 * 49 * 11 * 13 * 17 * ... rest of primes up to 100.

  For general n, this number is of roughly the same order of magnitude
  as e**n.

 Ah, yes, I meant product(primes(n)), please forgive my honest mistake
 which is partially caused by me not supposed to still be awake at this
 time of the day. And thanks for Mark for noticing the mistake, and
 here is the code I used:

 import fraction
 import random

 frac = fraction.frac
 ops = (frac.__add__, frac.__sub__)

 a = frac(random.randrange(1, 10), random.randrange(1, 10))
 b = frac(random.randrange(1, 10), random.randrange(1, 10))

 while True:
 � � o = ops[random.randrange(0, 2)]
 � � a = o(a, b)
 � � b = frac(random.randrange(1, 10), random.randrange(1, 10))
 � � print a

 I decided to keep the num/den limit low (10) because higher values
 might obscure the fact that it do have limits. And through further
 observations, I think it is sufficient if the limit is imposed in the
 denominator only (numerator can have any values it wanted to,
 denominator growth is determined only by the limit of denominator
 growth).

 I think I'll also post the code for the fraction class I used, if you
 have other fraction class that can automatically simplify, you could
 use that instead as this class suffers from a naive GCD
 implementation:

Out of curiosity, of what use is denominator limits?

The problems where I've had to use rationals have
never afforded me such luxury, so I don't see what
your point is.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Jeroen Ruigrok van der Werven
-On [20080224 20:01], Adekoba ([EMAIL PROTECTED]) wrote:
I don't think moving food.py's code to __init__.py would work out to
well, because then how would I run the script?

import food

Which in turn has something like this in food/__init__.py:

from food.cheese import gouda
from food.ham import parma

__all__ = ['gouda', 'parma']

and in turn in your script you can now use food.gouda and food.parma.

Unless I totally misunderstood what you are trying to achieve.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
We have met the enemy and they are ours...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: most loved template engine on python is?

2008-02-24 Thread [EMAIL PROTECTED]
On 24 fév, 20:01, Tamer Higazi [EMAIL PROTECTED] wrote:
 Hi people!
(snip)
 Question:
 Which is the most loved template engine for python?

I don't have a single cue on this, but the one that most impresses me
so far is Mako.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Adekoba
On Feb 24, 3:21 pm, Jeroen Ruigrok van der Werven [EMAIL PROTECTED]
nomine.org wrote:
 -On [20080224 20:01], Adekoba ([EMAIL PROTECTED]) wrote:

 I don't think moving food.py's code to __init__.py would work out to
 well, because then how would I run the script?

 import food

 Which in turn has something like this in food/__init__.py:

 from food.cheese import gouda
 from food.ham import parma

 __all__ = ['gouda', 'parma']

 and in turn in your script you can now use food.gouda and food.parma.

 Unless I totally misunderstood what you are trying to achieve.

 --
 Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
 イェルーン ラウフロック ヴァン デル ウェルヴェンhttp://www.in-nomine.org/|http://www.rangaku.org/
 We have met the enemy and they are ours...

I was just curious if I could get a script name to be the same name as
the package directory, but apparently it is not possible. Instead I
think I am going to do something like:

setup.py
food/
  __init__.py
  ham.py
  cheese.py
scripts/
  food

and just set my PYTHONPATH to the parent directory. I have never done
a full scale project before in python, but I think this is probably on
track with what most people would do.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: To PEAK or not to PEAK

2008-02-24 Thread [EMAIL PROTECTED]
On 24 fév, 15:37, Tzury Bar Yochay [EMAIL PROTECTED] wrote:
 I am about to start a large-scale enterprise project next month (I
 insist on using Python instead Java and .NET and I am sure `they` will
 thank me eventually).

 I was wondering around making my components-and-libraries-shopping-
 list and came across PEAK.
 My paranoia is that PEAK would make me write my application in PEAK
 instead of Python

You should perhaps worry more about the support - IIRC, PEAK (as a
whole I mean)  is mostly abandon-ware...

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


Re: PHP Developer highly interested in Python (web development) with some open questions...

2008-02-24 Thread [EMAIL PROTECTED]
On 24 fév, 13:44, Christian Heimes [EMAIL PROTECTED] wrote:
 Tamer Higazi wrote:
  - What is the Zope Applikation Server? Is it also a Webserver like the
  Apache or Tomcat Webserver?

 Zope is much more than a webserver. It's a web application server
 including a fast object database (ACID, support clustering and MVCC), a
 powerful plugin architecture, builtin security and many, many more.

It's also some kind of a Rube Goldberg thingie...
http://en.wikipedia.org/wiki/Rube_Goldberg_machine

If you're into web applications, better to have a look at Pylons or
Django IMHO.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib slow on Leopard

2008-02-24 Thread James Matthews
Try running the script when python is running as root. I has issues like
this also!

On Sun, Feb 24, 2008 at 8:57 PM, mark [EMAIL PROTECTED] wrote:

 I've recently switched from Ubuntu to OS X Leopard. I have some python
 scripts which download info from the web. The scripts were working fine
 before on Ubuntu, but urllib seems to work really slowly on Leopard.

 I tried an example from the docs:

   import urllib2
   f = urllib2.urlopen('http://www.python.org/'http://www.python.org/%27
 )
   print f.read(100)
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
 http://www.w3.org/TR/xhtml1/DTD/xhtm
  

 The line f = ... takes about a minute to return - but otherwise returns
 the predicted result. My web connection seems fine, so has anyone got
 any ideas as to what the problem might be?
 --
 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: urllib slow on Leopard

2008-02-24 Thread André
On Feb 24, 3:57 pm, mark [EMAIL PROTECTED] wrote:
 I've recently switched from Ubuntu to OS X Leopard. I have some python
 scripts which download info from the web. The scripts were working fine
 before on Ubuntu, but urllib seems to work really slowly on Leopard.

 I tried an example from the docs:

   import urllib2
   f = urllib2.urlopen('http://www.python.org/')
   print f.read(100)
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
 http://www.w3.org/TR/xhtml1/DTD/xhtm
  

 The line f = ... takes about a minute to return - but otherwise returns
 the predicted result. My web connection seems fine, so has anyone got
 any ideas as to what the problem might be?

Nope, but it's not Leopard related.  Just checked here and it loaded
in about 1 sec.

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


Re: urllib slow on Leopard

2008-02-24 Thread Stefan Behnel
mark wrote:
 I've recently switched from Ubuntu to OS X Leopard. I have some python
 scripts which download info from the web. The scripts were working fine
 before on Ubuntu, but urllib seems to work really slowly on Leopard.
 
 I tried an example from the docs:
 
 import urllib2
 f = urllib2.urlopen('http://www.python.org/')
 print f.read(100)
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
 http://www.w3.org/TR/xhtml1/DTD/xhtm

 
 The line f = ... takes about a minute to return - but otherwise returns
 the predicted result. My web connection seems fine, so has anyone got
 any ideas as to what the problem might be?

It likely tries to load the DTD in the background, which requires network 
access.

http://www.w3.org/blog/systeam/2008/02/08/w3c_s_excessive_dtd_traffic

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


Re: How about adding rational fraction to Python?

2008-02-24 Thread casevh

 Out of curiosity, of what use is denominator limits?

 The problems where I've had to use rationals have
 never afforded me such luxury, so I don't see what
 your point is

In Donald Knuth's The Art of Computer Programming, he described
floating slash arithmetic where the total number of bits by the
numerator and denominator was bounded. IIRC, a use case was matrix
inversion.

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


Re: Python for web...

2008-02-24 Thread Ivan Van Laningham
Hi All--
Django is slick.  I just yesterday picked up the book and started
poking away.  Downloaded, Installed and running in about ten minutes
(I have several servers I can play with).  Today I have several
working pages.

Use mod_python if you can.

Django-mind-Beginner's-mind-ly y'rs,
Ivan

On Sun, Feb 24, 2008 at 12:03 PM, Tamer Higazi [EMAIL PROTECTED] wrote:
 http://www.djangobook.com/

  if you love to read that book online. Otherwise, if you don't have DSL,
  just mirror the site for offline usage with wget

  Tamer

  [EMAIL PROTECTED] wrote:
   Hi everyone,
  
   I have to develop a web based enterprise application for my final year
   project. Since i am interested in open source, i searched the net.
   Almost 90% of them were PHP and MySQL. Cant we use python for that ? I
   tried several sites, but there is not enough tutorial for beginners
   [mod_python, PSP etc]. I couldnt find any detailed book, not even a
   single book :( All the python books are covering only CGI part)
  
   Any suggestions? Any recommended book?
  
   Execuse my English.
  
   Thushanthan.
  --
  http://mail.python.org/mailman/listinfo/python-list




-- 
Ivan Van Laningham
God N Locomotive Works
http://www.pauahtun.org/
http://www.python.org/workshops/1998-11/proceedings/papers/laningham/laningham.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a open souce IDE writen by C( C++) or partly writen by C( C++)?

2008-02-24 Thread Ricardo Aráoz
zaley wrote:
 On Feb 24, 6:48 am, Ricardo Aráoz [EMAIL PROTECTED] wrote:
 Lie wrote:
 On Feb 23, 4:02 pm, zaley [EMAIL PROTECTED] wrote:
 On Feb 22, 11:06 pm, Jesper polluks(#at#)post.tele.dk wrote:
 Give PyScripter fromhttp://www.mmm-experts.com/atry
 It is for Windows, though it is written in Delphi and not in C/C++
 /Jesper
 zaley [EMAIL PROTECTED] skrev i en meddelelsenews:[EMAIL PROTECTED]
 Of course, python scripts debugger
 On 2ÔÂ22ÈÕ, ÏÂÎç3ʱ22·Ö, zaley [EMAIL PROTECTED] wrote:
 My project need a simple scripts debugger . I hope I can find
 something instructive
 Stefan Behnel дµÀ£º
 zaley wrote:
 Is there a open souce IDE writen by C( C++) or partly writen by C( C+
 +)?
 Tons of them. What do you want to do with it?
 Stefan- Hide quoted text -
 - Show quoted text -
 But PyScripter is not a open source project
 Am I correct to say that the reason why you wanted an open source C++
 IDE is because you wanted the freedom to modify your own programming
 environment?
 From the About window in PyScripter :

 
 A freeware, open source Python scripter integrated
 development environment created with the ambition to bring to
 the Python community the quality and functionality available in
 commercial IDEs available for other languages.
 

 So I think we could say PyScripter IS an open source project.- Hide quoted 
 text -

 - Show quoted text -
 
 Really, what I want to do is that scripts can be executed step by
 step .
 I know By Py_Runstring  clauses  in main function can executed by
 step .
 But I can't know how to step into a function and how to step in a
 function.
 So I hope I can find something helpful in open source IDE for python.

Exactly so. PyScripter does it easy, besides you can have in different
tabs all the modules of your application. You just hit the run button
and your program runs, you hit the debug button and you start going step
by step. It's free, easy to install, just give it a try and if you don't
like it just trash it.

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


Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Steve Holden
Adekoba wrote:
 On Feb 24, 1:06 pm, Christian Heimes [EMAIL PROTECTED] wrote:
 Adekoba wrote:
 food.py
 food/
   __init__.py
   ham.py
   cheese.py
 where food.py is a script that uses the package food. Is it possible
 for this to work in any way? Every time I try to run food.py, python
 tries to import everything from the script instead of from the
 package. How can I fix this?
 Move the code from food.py to food/__init__.py. You can't have a package
 and a module with the same name.

 Christian
 
 So it is not possible?
 
 I don't think moving food.py's code to __init__.py would work out to
 well, because then how would I run the script?

You run food/__init__.py with the following statement:

import food

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: Article of interest: Python pros/cons for the enterprise

2008-02-24 Thread Larry Bugbee
PS:  And tools like ShedSkin and Pyrex benefit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-02-24 Thread Steven D'Aprano
On Sun, 24 Feb 2008 10:09:37 -0800, Lie wrote:

 On Feb 25, 12:46 am, Steve Holden [EMAIL PROTECTED] wrote:
 Lie wrote:
  On Feb 18, 1:25 pm, Carl Banks [EMAIL PROTECTED] wrote:
  On Feb 17, 1:45 pm, Lie [EMAIL PROTECTED] wrote:

  Any iteration with repeated divisions and additions can thus run
  the denominators up.  This sort of calculation is pretty common
  (examples: compound interest, numerical integration).
  Wrong. Addition and subtraction would only grow the denominator up
  to a certain limit
  I said repeated additions and divisions.

  Repeated Addition and subtraction can't make fractions grow
  infinitely, only multiplication and division could.

 On what basis is this claim made?

 (n1/d1) + (n2/d2) = ((n1*d2) + (n2*d1)) / (d1*d2)

 If d1 and d2 are mutually prime (have no common factors) then it is
 impossible to reduce the resulting fraction further in the general case
 (where n1 = n2 = 1, for example).

  Anyways, addition and subtraction can increase the denominator a lot
  if for some reason you are inputing numbers with many different
  denominators.

  Up to a certain limit. After you reached the limit, the fraction
  would always be simplifyable.

 Where does this magical limit appear from?

  If the input numerator and denominator have a defined limit, repeated
  addition and subtraction to another fraction will also have a defined
  limit.

 Well I suppose is you limit the input denominators to n then you have a
 guarantee that the output denominators won't exceed n!, but that seems
 like a pretty poor guarantee to me.

 Am I wrong here? You seem to be putting out unsupportable assertions.
 Please justify them or stop making them.


 Well, I do a test on my own fraction class. I found out that if we set a
 limit to the numerators and denominators, the resulting output fraction
 would have limit too. I can't grow my fraction any more than this limit
 no matter how many iteration I do on them. I do the test is by something
 like this (I don't have the source code with me right now, it's quite
 long if it includes the fraction class, but I think you could use any
 fraction class that automatically simplify itself, might post the real
 code some time later):
 
 while True:
 a = randomly do (a + b) or (a - b)
 b = random fraction between [0-100]/[0-100] print a
 
 And this limit is much lower than n!. I think it's sum(primes(n)), but
 I've got no proof for this one yet.


*jaw drops*


Please stop trying to help convince people that rational classes are 
safe to use. That's the sort of help that we don't need.


For the record, it is a perfectly good strategy to *artificially* limit 
the denominator of fractions to some maximum value. (That's more or less 
the equivalent of setting your floating point values to a maximum number 
of decimal places.) But without that artificial limit, repeated addition 
of fractions risks having the denominator increase without limit.


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

Re: How about adding rational fraction to Python?

2008-02-24 Thread Steven D'Aprano
On Sun, 24 Feb 2008 12:19:53 -0800, Mensanator wrote:

 Out of curiosity, of what use is denominator limits?
 
 The problems where I've had to use rationals have never afforded me such
 luxury, so I don't see what your point is.

It ensures that your fraction's denominator doesn't grow indefinitely, at 
the cost of some precision. In principle, fraction denominators can grow 
exponentially. In practice, probably less quickly, but still quickly 
enough that people on this list have reported that adding two fractions 
lead to millions of digits in each denominator and massive paging as 
their computer struggled to perform the addition.

The beauty of fractions is that they give you infinite precision. The 
danger of fractions is that it takes a lot of memory to store infinitely 
precise numbers :)

Frankly, I think that for most real-world data, it's unlikely to be a 
problem, but Guido's experiences with ABC were the opposite. But then we 
don't know how naive the ABC fraction libraries were. For all I know they 
did this:

1/2 + 1/2 = 4/4
4/4 - 1/2 = 4/8
4/8 + 1/2 = 16/16
etc.



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


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

2008-02-24 Thread Larry Bugbee
 You mean static data typing, right?  Are there any known holes in the
 dynamic type system that still need to be plugged?  (I haven't heard of
 any.)

My apologies.  You are right, I meant optional, static typing.  Thanks
for the catch Jeff.

Python's dynamic typing is just fine.  But if I know the type, I want
the ability to nail it.  ...local variables, arguments, return values,
etc  And if I don't know or care, I'd leave it to dynamic typing.

The need for a lot of doc goes away, those new to the language that
think it's a big deal can be explicit, and as I suggested earlier, I
think the byte code interpreter could be made a lot smarter and
faster.  ...and corporate acceptance would follow.

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


Re: How about adding rational fraction to Python?

2008-02-24 Thread Steven D'Aprano
On Sun, 24 Feb 2008 11:09:32 -0800, Lie wrote:

 I decided to keep the num/den limit low (10) because higher values might
 obscure the fact that it do have limits.

You do realise that by putting limits on the denominator, you guarantee 
that the sum of the fractions also has a limit on the denominator? In 
other words, your test is useless.

With denominators limited to 1 through 9 inclusive, the sum will have a 
denominator of 2*3*5*7 = 210. But that limit is a product (literally and 
figuratively) of your artificial limit on the denominator. Add a fraction 
with denominator 11, and the sum now has a denominator of 2310; add 
another fraction n/13 and the sum goes to m/30030; and so on. 


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


Re: PHP Developer highly interested in Python (web development) with some open questions...

2008-02-24 Thread Diez B. Roggisch
 
 It's also some kind of a Rube Goldberg thingie...
 http://en.wikipedia.org/wiki/Rube_Goldberg_machine
 
 If you're into web applications, better to have a look at Pylons or
 Django IMHO.

You are entitled to your opinion, but calling Zope a 
Rube-Goldberg-machine is strong. To put it mildly. How about sharing 
some of the reasons for this?

Just for the record: I'm a Turbogears user and even commiter - so I'm 
certainly not from the zope zealotry department.

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


Re: n00b with urllib2: How to make it handle cookie automatically?

2008-02-24 Thread 7stud
On Feb 24, 4:41 am, est [EMAIL PROTECTED] wrote:
 On Feb 23, 2:42 am, Rob Wolfe [EMAIL PROTECTED] wrote:



  est [EMAIL PROTECTED] writes:
   Hi all,

   I need urllib2 do perform series of HTTP requests with cookie from
   PREVIOUS request(like our browsers usually do ). Many people suggest I
   use some library(e.g. pycURL) instead but I guess it's good practise
   for a python beginner to DIY something rather than use existing tools.

   So my problem is how to expand the urllib2 class

   from cookielib import CookieJar
   class SmartRequest():
       cj=CookieJar()
       def __init__(self, strUrl, strContent=None):
           self.Request    =   urllib2.Request(strUrl, strContent)
           self.cj.add_cookie_header(self.Request)
           self.Response   =   urllib2.urlopen(Request)
           self.cj.extract_cookies(self.Response, self.Request)
       def url
       def read(self, intCount):
           return self.Response.read(intCount)
       def headers(self, strHeaderName):
           return self.Response.headers[strHeaderName]

   The code does not work because each time SmartRequest is initiated,
   object 'cj' is cleared. How to avoid that?
   The only stupid solution I figured out is use a global CookieJar
   object. Is there anyway that could handle all this INSIDE the class?

   I am totally new to OOP  python programming, so could anyone give me
   some suggestions? Thanks in advance

  Google for urllib2.HTTPCookieProcessor.

  HTH,
  Rob- Hide quoted text -

  - Show quoted text -

 Wow, thank you Rob Wolfe! Your reply is shortest yet most helpful! I
 solved this problem by the following code.

 class HTTPRefererProcessor(urllib2.BaseHandler):
     Add Referer header to requests.

     This only makes sense if you use each RefererProcessor for a
 single
     chain of requests only (so, for example, if you use a single
     HTTPRefererProcessor to fetch a series of URLs extracted from a
 single
     page, this will break).

     There's a proper implementation of this in module mechanize.

     
     def __init__(self):
         self.referer = None

     def http_request(self, request):
         if ((self.referer is not None) and
             not request.has_header(Referer)):
             request.add_unredirected_header(Referer, self.referer)
         return request

     def http_response(self, request, response):
         self.referer = response.geturl()
         return response

     https_request = http_request
     https_response = http_response

 def main():
     cj = CookieJar()
     opener = urllib2.build_opener(
         urllib2.HTTPCookieProcessor(cj),
         HTTPRefererProcessor(),
     )
     urllib2.install_opener(opener)

     urllib2.urlopen(url1)
     urllib2.urlopen(url2)

 if __main__ == __name__:
     main()

 And it's working great!

 Once again, thanks everyone!

How does the class HTTPReferrerProcessor do anything useful for you?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-02-24 Thread Mensanator
On Feb 24, 4:50�pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Sun, 24 Feb 2008 11:09:32 -0800, Lie wrote:
  I decided to keep the num/den limit low (10) because higher values might
  obscure the fact that it do have limits.

 You do realise that by putting limits on the denominator, you guarantee
 that the sum of the fractions also has a limit on the denominator? In
 other words, your test is useless.

 With denominators limited to 1 through 9 inclusive, the sum will have a
 denominator of 2*3*5*7 = 210.

Th limit will be 2*2*2*3*3*5*7. As MD said, equivalently
the product over all primes p = n of the highest power
of p not exceeding n.


 But that limit is a product (literally and
 figuratively) of your artificial limit on the denominator. Add a fraction
 with denominator 11, and the sum now has a denominator of 2310; add
 another fraction n/13 and the sum goes to m/30030; and so on.

 --
 Steven

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

Re: packing things back to regular expression

2008-02-24 Thread Amit Gupta

 CL(?Pname1[a-z]+)XY(?:AB)[aeiou]+(?Pname2CD(?Pname3..)\?EF)

 Good luck.

 --
 Steven

This is what I did in the end (in principle). Thanks.

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


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

2008-02-24 Thread Aahz
In article [EMAIL PROTECTED],
Jeff Schwab  [EMAIL PROTECTED] wrote:

What I would like is not so much a new Python implementation, as a 
vehicle to help demonstrate a few things to other Python users. 
Recently, I've had a few replies in tones that imply I'm on the brink of 
entering several kill-files, mostly because I express disagreement with 
a few closely held beliefs of some other c.l.p posters.  For example, 
the following are widely held opinions with which I disagree:

(1) Python is a gotcha-free language.

HAHAHAHAHAHAHA -- please, do provide some evidence for this assertion.

(2) C++ is basically the same language as C, but more complicated.

Hardly.  Again, you need to provide evidence for this assertion.  What I
would say is that C++ has *all* the gotchas of C plus many of its own.

(3) Garbage collection is at least as desirable a language feature as 
deterministic destruction.

Enh.  There probably are some people who claim that, but I can't think
of any off-hand.  However, I suspect that part of the problem is that
you don't really understand Python: Python primarily relies on reference
counting, which combined with other features in Python makes cycle
creation rather easy, and there's no real option other than garbage
collection for cleaining up cycles.

(4) Static typing is inferior to dynamic typing.

There's some truth to what you say, but you are entirely misrepresenting
what people actually say: static typing is inferior to unit tests, and
dynamic typing requires less boilerplate than static typing and is
therefore easier to write.

In other ways, though, the Python community is just blindingly ignorant, 
arrogant, and argumentative.  

Absolutely.  But your blind ignorance and arrogant argumentation isn't
helping any.

I expect my use of Python to increase in the coming years, so I want   
the best possible relationship with other regular users, especially on 
Usenet.

Then maybe you should start by learning Python and what people actually
say about it.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

All problems in computer science can be solved by another level of 
indirection.  --Butler Lampson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-02-24 Thread Mensanator
On Feb 24, 4:42�pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Sun, 24 Feb 2008 12:19:53 -0800, Mensanator wrote:
  Out of curiosity, of what use is denominator limits?

  The problems where I've had to use rationals have never afforded me such
  luxury, so I don't see what your point is.

 It ensures that your fraction's denominator doesn't grow indefinitely, at
 the cost of some precision. In principle, fraction denominators can grow
 exponentially. In practice, probably less quickly, but still quickly
 enough that people on this list have reported that adding two fractions
 lead to millions of digits in each denominator and massive paging as
 their computer struggled to perform the addition.

Ok, but I've never seen that happen with the rationals
of the gmpy module. I'm getting the feeling that this
fear of rationals is overrated.

But maybe it's because I know what I'm doing.

Naw, that can't be it.


 The beauty of fractions is that they give you infinite precision. The
 danger of fractions is that it takes a lot of memory to store infinitely
 precise numbers :)

 Frankly, I think that for most real-world data, it's unlikely to be a
 problem,

My guess is that you're right.

 but Guido's experiences with ABC were the opposite. But then we
 don't know how naive the ABC fraction libraries were. For all I know they
 did this:

 1/2 + 1/2 = 4/4
 4/4 - 1/2 = 4/8
 4/8 + 1/2 = 16/16
 etc.

Perhaps Guido should have an occasional peek
at the monster he's created. The gmpy library
always reduces to lowest denominator, so the
above couldn't happen.


 --
 Steven

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

Re: Is there a open souce IDE writen by C( C++) or partly writen by C( C++)?

2008-02-24 Thread zaley
On 2月25日, 上午6时34分, Ricardo Aráoz [EMAIL PROTECTED] wrote:
 zaley wrote:
  On Feb 24, 6:48 am, Ricardo Aráoz [EMAIL PROTECTED] wrote:
  Lie wrote:
  On Feb 23, 4:02 pm, zaley [EMAIL PROTECTED] wrote:
  On Feb 22, 11:06 pm, Jesper polluks(#at#)post.tele.dk wrote:
  Give PyScripter fromhttp://www.mmm-experts.com/atry
  It is for Windows, though it is written in Delphi and not in C/C++
  /Jesper
  zaley [EMAIL PROTECTED] skrev i en meddelelsenews:[EMAIL PROTECTED]
  Of course, python scripts debugger
  On 2ÔÂ22ÈÕ, ÏÂÎç3ʱ22·Ö, zaley [EMAIL PROTECTED] wrote:
  My project need a simple scripts debugger . I hope I can find
  something instructive
  Stefan Behnel дµÀ£º
  zaley wrote:
  Is there a open souce IDE writen by C( C++) or partly writen by C( C+
  +)?
  Tons of them. What do you want to do with it?
  Stefan- Hide quoted text -
  - Show quoted text -
  But PyScripter is not a open source project
  Am I correct to say that the reason why you wanted an open source C++
  IDE is because you wanted the freedom to modify your own programming
  environment?
  From the About window in PyScripter :

  
  A freeware, open source Python scripter integrated
  development environment created with the ambition to bring to
  the Python community the quality and functionality available in
  commercial IDEs available for other languages.
  

  So I think we could say PyScripter IS an open source project.- Hide quoted 
  text -

  - Show quoted text -

  Really, what I want to do is that scripts can be executed step by
  step .
  I know By Py_Runstring  clauses  in main function can executed by
  step .
  But I can't know how to step into a function and how to step in a
  function.
  So I hope I can find something helpful in open source IDE for python.

 Exactly so. PyScripter does it easy, besides you can have in different
 tabs all the modules of your application. You just hit the run button
 and your program runs, you hit the debug button and you start going step
 by step. It's free, easy to install, just give it a try and if you don't
 like it just trash it.

I just want to know how to do it!!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-02-24 Thread Mel
Mensanator wrote:
 On Feb 24, 1:09�pm, Lie [EMAIL PROTECTED] wrote:
 I decided to keep the num/den limit low (10) because higher values
 might obscure the fact that it do have limits. [ ... ]
 
 Out of curiosity, of what use is denominator limits?
 
 The problems where I've had to use rationals have
 never afforded me such luxury, so I don't see what
 your point is.

In calculations dealing only with selected units of measure: dollars 
and cents, pounds, ounces and tons, teaspoons, gallons, beer bottles 
28 to a case, then the denominators would settle out pretty quickly.

In general mathematics, not.

I think that might be the point.

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

Re: Is there a open souce IDE writen by C( C++) or partly writen by C( C++)?

2008-02-24 Thread zaley
On 2月25日, 上午6时34分, Ricardo Aráoz [EMAIL PROTECTED] wrote:
 zaley wrote:
  On Feb 24, 6:48 am, Ricardo Aráoz [EMAIL PROTECTED] wrote:
  Lie wrote:
  On Feb 23, 4:02 pm, zaley [EMAIL PROTECTED] wrote:
  On Feb 22, 11:06 pm, Jesper polluks(#at#)post.tele.dk wrote:
  Give PyScripter fromhttp://www.mmm-experts.com/atry
  It is for Windows, though it is written in Delphi and not in C/C++
  /Jesper
  zaley [EMAIL PROTECTED] skrev i en meddelelsenews:[EMAIL PROTECTED]
  Of course, python scripts debugger
  On 2ÔÂ22ÈÕ, ÏÂÎç3ʱ22·Ö, zaley [EMAIL PROTECTED] wrote:
  My project need a simple scripts debugger . I hope I can find
  something instructive
  Stefan Behnel дµÀ£º
  zaley wrote:
  Is there a open souce IDE writen by C( C++) or partly writen by C( C+
  +)?
  Tons of them. What do you want to do with it?
  Stefan- Hide quoted text -
  - Show quoted text -
  But PyScripter is not a open source project
  Am I correct to say that the reason why you wanted an open source C++
  IDE is because you wanted the freedom to modify your own programming
  environment?
  From the About window in PyScripter :

  
  A freeware, open source Python scripter integrated
  development environment created with the ambition to bring to
  the Python community the quality and functionality available in
  commercial IDEs available for other languages.
  

  So I think we could say PyScripter IS an open source project.- Hide quoted 
  text -

  - Show quoted text -

  Really, what I want to do is that scripts can be executed step by
  step .
  I know By Py_Runstring  clauses  in main function can executed by
  step .
  But I can't know how to step into a function and how to step in a
  function.
  So I hope I can find something helpful in open source IDE for python.

 Exactly so. PyScripter does it easy, besides you can have in different
 tabs all the modules of your application. You just hit the run button
 and your program runs, you hit the debug button and you start going step
 by step. It's free, easy to install, just give it a try and if you don't
 like it just trash it.

I just want to know how to realize it in my program !!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: most loved template engine on python is?

2008-02-24 Thread subeen
On Feb 25, 1:01 am, Tamer Higazi [EMAIL PROTECTED] wrote:

 Question:
 Which is the most loved template engine for python?



I am learning MAKO and I think it's good. But can't tell that it's the
best as I didn't try others. :)

regards,
Subeen.
http://love-python.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


How to make rainbow RGB values?

2008-02-24 Thread Simon Forman
Hey all,
I want to map an int to a color on a rainbow spectrum, i.e. for an int
n in the range 0..N, low values (near 0) should map to the red end,
and high values (near N) to the blue/violet end.

The return values should be R, G, B tuples (well, #xx color
codes, but that's not the hard part.)

The trouble I'm having is in coming up with a good way to generate
color values that approximates the ROY G BIV rainbow spectrum.  This
is just a simple, non-scientific, non-photographic application,
nothing fancy.

I've tried a simple scheme of overlapping sines, but this resulted in
too much red and blue, and no indigo/violet.

Any suggestions?  I'm searching on the web now but not coming up with
much, so I thought I'd ask here.


TIA,
~Simon

Here's the sinecode I tried:


def g(n):
'''
map sine [-1.0 .. 1.0] = color byte [0 .. 255]
'''
return 255 * (n + 1) / 2.0


def f(start, stop, N):

interval = (stop - start) / N

for n in range(N):
coefficient = start + interval * n
yield g(sin(coefficient * pi))

n = 150
RED = f(0.5, 1.5, n)
GREEN = f(1.5, 3.5, n)
BLUE = f(1.5, 2.5, n)

RGBs = [('#%02x%02x%02x' % rgb) for rgb in zip(RED, GREEN, BLUE)]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to make rainbow RGB values?

2008-02-24 Thread Andrew McNamara
I want to map an int to a color on a rainbow spectrum, i.e. for an int
n in the range 0..N, low values (near 0) should map to the red end,
and high values (near N) to the blue/violet end.
[...]
I've tried a simple scheme of overlapping sines, but this resulted in
too much red and blue, and no indigo/violet.

Consider using an HSV-RGB conversion function. Saturation (S) and value
(V) should remain constant, while Hue (H) varies to get your rainbow
effect.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/
-- 
http://mail.python.org/mailman/listinfo/python-list


Create multiple directories

2008-02-24 Thread Paul Lemelle
I am somewhat new to Python and I am trying to create a program that
automatically creates directories from a range of numbers. I
researched the os.mkdir  os.makedirs methods, but they do not seem to
(I don't know) how to include an argumnet to step through my list. 

I woudl like to do the follwoing:
1) Ask the user how many folders to create
2) take raw_input and then translate it into a while loop that steps
through the os.mkdir process. 

Any would help would be appreicated. 

Paul

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


Re: Create multiple directories

2008-02-24 Thread Jeff Schwab
Paul Lemelle wrote:
 I am somewhat new to Python and I am trying to create a program that
 automatically creates directories from a range of numbers. I
 researched the os.mkdir  os.makedirs methods, but they do not seem to
 (I don't know) how to include an argumnet to step through my list. 
 
 I woudl like to do the follwoing:
 1) Ask the user how many folders to create
 2) take raw_input and then translate it into a while loop that steps
 through the os.mkdir process. 

Maybe something like this?

import os

def mkdirs(n):
 for i in range(n):
 os.mkdir(%d % i)

if __name__ == '__main__':
 mkdirs(int(raw_input(How many folders should I create? )))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a open souce IDE writen by C( C++) or partly writen by C( C++)?

2008-02-24 Thread Ricardo Aráoz
zaley wrote:

 So I hope I can find something helpful in open source IDE for python.
 Exactly so. PyScripter does it easy, besides you can have in different
 tabs all the modules of your application. You just hit the run button
 and your program runs, you hit the debug button and you start going step
 by step. It's free, easy to install, just give it a try and if you don't
 like it just trash it.
 
 I just want to know how to do it!!

Ok, I hope I'm not misunderstanding you.
You go to http://www.mmm-experts.com/Downloads.aspx
and you download PyScripter (windows installer). Then you run the
downloaded file (that would be PyScripter-setup.exe) and that will
install PyScripter in your machine. You run PyScripter, click the open
 button or menu File/Open... and choose the program you want to debug.
It  will be opened in an edit window in your PyScripter main window.
Then you click on Step into subroutine button or just press F7 and
you'll be in the first line of your program. From then on you keep
clicking Step into subroutine (F7) or Step over next function call
(F8) or Step out of the current subroutine or Run to cursor as you
see fit. You can add breakpoints just by clicking to the left of the
line numbers or the appropriate button. You can watch what's going on in
your program in the lower partition of your main window where you have a
Call Stack tab and also Variables, Watches, Breakpoints,
Output and Messages tabs.
From then on you are on your own.

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


object identity and hashing

2008-02-24 Thread castironpi
Can someone explain this?

 a= {}
 a[(3,)]= 0
 (3,) in a
True
 (3,) is (3,)
False
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object identity and hashing

2008-02-24 Thread Jeff Schwab
[EMAIL PROTECTED] wrote:
 Can someone explain this?
 
 a= {}

Create an empty dict and bind it to the name a.

 a[(3,)]= 0

Set the key/value pair (3,):0 to the dict.

 (3,) in a

Is (3,) one of the keys in the dict?

 True

Yes, it is.

 (3,) is (3,)

Create two separate tuples (that happen to be equivalent).  Are they the 
same object?

 False

No, they are not.

Every time you write (3,), you are potentially creating a new object. 
These objects have equal values (and hash codes), so they are 
interchangeable for purposes of keying a dict.

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


Re: Is there a open souce IDE writen by C( C++) or partly writen by C( C++)?

2008-02-24 Thread zaley
On 2月25日, 上午10时35分, Ricardo Aráoz [EMAIL PROTECTED] wrote:
 zaley wrote:
  So I hope I can find something helpful in open source IDE for python.
  Exactly so. PyScripter does it easy, besides you can have in different
  tabs all the modules of your application. You just hit the run button
  and your program runs, you hit the debug button and you start going step
  by step. It's free, easy to install, just give it a try and if you don't
  like it just trash it.

  I just want to know how to do it!!

 Ok, I hope I'm not misunderstanding you.
 You go tohttp://www.mmm-experts.com/Downloads.aspx
 and you download PyScripter (windows installer). Then you run the
 downloaded file (that would be PyScripter-setup.exe) and that will
 install PyScripter in your machine. You run PyScripter, click the open
  button or menu File/Open... and choose the program you want to debug.
 It  will be opened in an edit window in your PyScripter main window.
 Then you click on Step into subroutine button or just press F7 and
 you'll be in the first line of your program. From then on you keep
 clicking Step into subroutine (F7) or Step over next function call
 (F8) or Step out of the current subroutine or Run to cursor as you
 see fit. You can add breakpoints just by clicking to the left of the
 line numbers or the appropriate button. You can watch what's going on in
 your program in the lower partition of your main window where you have a
 Call Stack tab and also Variables, Watches, Breakpoints,
 Output and Messages tabs.

 From then on you are on your own.

 HTH


Hehe. You misunderstand me really.  I know what you say
I just want to know how to realize it using C language or other
language.
I need such source code to study
-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   3   >