Re: Python 3000 idea -- + on iterables -> itertools.chain

2006-11-13 Thread Georg Brandl
George Sakkis wrote:
> Fredrik Lundh wrote:
> 
>> John Reese wrote:
>>
>> > It seems like it would be clear and mostly backwards compatible if the
>> > + operator on any iterables created a new iterable that iterated
>> > throught first its left operand and then its right, in the style of
>> > itertools.chain.
>>
>> you do know that "iterable" is an informal interface, right?  to what
>> class would you add this operation?
>>
>> 
> 
> The base object class would be one candidate, similarly to the way
> __nonzero__ is defined to use __len__, or __contains__ to use __iter__.

What has a better chance of success in my eyes is an extension to yield
all items from an iterable without using an explicit for loop: instead of

for item in iterable:
 yield item

you could write

yield from iterable

or

yield *iterable

etc.

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


Re: MemoryError

2006-11-13 Thread Steve Holden
Bugra Cakir wrote:
> Hi,
> 
> Within a Python program how can we avoid getting "MemoryError" problem ?
> 
Well that depends why you are getting it in the first place.

If you can post the traceback your program prints out then you might get 
some specific advice for the current case. The usual advice might be 
"don't use too much memory", but that alone probably won't be helpful.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Jython compile errors ...

2006-11-13 Thread donkeyboy
All,

I've tried the jythonc compiler to try and create an applet to see how
it works, but I get a number of Java compile errors that are way above
my knowledge. Does anyone know what any of the following means? I'm
using JDK 1.5.0_09, under Win XP SP2.

Runnnig the file " jython FILENAME" works, so I don't know what's
happening. Any thoughts?

C:\EclipseWorkbench\Jython>jythonc -d --jar leaders.jar jy_leaders.py
processing jy_leaders

Required packages:
  javax.swing
  java.lang
  java.awt
  java.applet
  java.util

Creating adapters:
  java.awt.event.ActionListener used in jy_leaders

Creating .java files:
  jy_leaders module
MyDrawPanel extends javax.swing.JPanel
Main extends java.applet.Applet

Compiling .java to .class...
Compiling with args: ['c:\\Program
Files\\Java\\jdk1.5.0_09\\bin\\javac', '-clas
spath',
'C:\\jython\\jython.jar;;.\\jpywork;;C:\\jython\\Tools\\jythonc;C:\\Ecli
pseWorkbench\\Jython\\.;C:\\jython\\Lib;C:\\jython',
'.\\jpywork\\jy_leaders.jav
a']1  .\jpywork\jy_leaders.java:3:  expected
public class jy_leaders extends java.lang.Object {
 ^
.\jpywork\jy_leaders.java:8: '{' expected
public static class _PyInner extends PyFunctionTable implements
PyRunnable {

  ^
.\jpywork\jy_leaders.java:419: ')' expected
Py.initProxy(this, "jy_leaders", "MyDrawPanel", args, 2
jython_leaders_sandbox.jpy$packages, jy_leaders.jpy$proxyProperties
, "", new String[] {"jy_leaders"});

^
.\jpywork\jy_leaders.java:548: ')' expected
Py.initProxy(this, "jy_leaders", "Main", args, 2jython_
leaders_sandbox.jpy$packages, jy_leaders.jpy$proxyProperties, "", n
ew String[] {"jy_leaders"});

 ^
.\jpywork\jy_leaders.java:565: ')' expected
Py.runMain(jy_leaders._PyInner.class, newargs, 2jython_lead
ers_sandbox.jpy$packages, jy_leaders.jpy$mainProperties, "", new St
ring[] {"jy_leaders"});
^
.\jpywork\jy_leaders.java:565: ';' expected
Py.runMain(jy_leaders._PyInner.class, newargs, 2jython_lead
ers_sandbox.jpy$packages, jy_leaders.jpy$mainProperties, "", new St
ring[] {"jy_leaders"});
^
.\jpywork\jy_leaders.java:565:  expected
Py.runMain(jy_leaders._PyInner.class, newargs, 2jython_lead
ers_sandbox.jpy$packages, jy_leaders.jpy$mainProperties, "", new St
ring[] {"jy_leaders"});
 ^
.\jpywork\jy_leaders.java:565: '{' expected
Py.runMain(jy_leaders._PyInner.class, newargs, 2jython_lead
ers_sandbox.jpy$packages, jy_leaders.jpy$mainProperties, "", new St
ring[] {"jy_leaders"});


   ^
.\jpywork\jy_leaders.java:569: '}' expected
^
9 errors

ERROR DURING JAVA COMPILATION... EXITING

Any help would be of great assistance -- thanks in advance.

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


Re: adding python scripting to my application

2006-11-13 Thread Julian

"martdi" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Jerry wrote:
>> I am not a Python guru by any means, but I believe that when an
>> application says that you can "script" their application with Python,
>> it means that you can actually write Python code to interact with the
>> application.  Embedding may be the same thing.  Extending (as I read
>> it) involves writing portions of your program in Python and have do the
>> logic portions.
>>
>> If you would like to allow users to write small scripts that interact
>> with your program and control it (a la VBScript or AppleScript), then I
>> believe embedding Python in your program is what you want.
>>
>> If you would like Python to run various parts of your program in order
>> to make some portions easier to write/manage/whatever, then you want to
>> "extend" your program using Python.
>>
>> The key difference being that you aren't providing a way for someone
>> else to interact with your program using Python if you are extending.
>>
>> Again, I am not a guru and a read through the docs on python.org would
>> probably be the best place to get sound technical advice on these
>> subjects.
>>
>> --
>> Jerry
>
>
> I'm not sure either, but I though Extending was making the C/C++ Code
> available from Python, while Embedding was making Python Code Available
> in your app.
>

Like I mentioned in my first post, one of the purposes of linking to python 
would be to run multiple cases in a for loop.
that would mean passing information from the python script to my c++ 
application. mean python would have to be the top-level program.
so, I think I should be looking at extending my program. I am going to look 
at using swig for this..

thanks,
Julian. 


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


Re: explicit self revisited

2006-11-13 Thread Michele Simionato
Peter Maas wrote:
> The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version):
>
> 1. Instance variables can be easily distinguished from local variables.
>
> 2. A method from a particular class can be called as
>baseclass.methodname(self, ).
>
> 3. No need for declarations to disambiguate assignments to local/instance
>variables.
>
> All these reasons are valid and retained by the following suggestion: let
> self be represented by the dot 

This suggestion has been discussed in the past (I remember having the
same idea
myself when I first learned Python). But at the end I believe the
explicit 'self' is
a better solution, because there are cases where it is useful to have
it (see Steven
d'Aprano's post) and also I like the fact that  I can spell it 'cls' in
classmethods and in
metaclasses. After a while one gets used to it and if you think a bit
it makes quite a
lot sense. Also, having the self explicit, makes Python object system
better (i.e.
it goes more in the direction of CLOS and less in the direction of
Java).

  Michele Simionato

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


httplib.InvalidURL: nonnumeric port: For characters in the proxy password in URL

2006-11-13 Thread Phoe6
Hi,
 The following piece of code works properly when my proxy password
contains characters[a-zA-Z0-9] etc. But when my proxy password
contained something like '|\/|' , the httplib incorrectly indentified
it as separator. How do I resolve this issue.


# Proxy Address
PROXY_IP = "1.1.9.8:80"

# Trying with linear way

proxy_user = 'user_name'
proxy_password='|\/|something'

# Setup the Proxy with urllib2

proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' +
PROXY_IP
proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)
urllib2.install_opener(opener)



I get the Error:

Traceback (most recent call last):
  File "C:\Python24\forge\ngwallp\ngwall.py", line 35, in ?
data = urllib2.urlopen(site)
  File "C:\Python24\lib\urllib2.py", line 130, in urlopen
return _opener.open(url, data)
  File "C:\Python24\lib\urllib2.py", line 358, in open
response = self._open(req, data)
  File "C:\Python24\lib\urllib2.py", line 376, in _open
'_open', req)
  File "C:\Python24\lib\urllib2.py", line 337, in _call_chain
result = func(*args)
  File "C:\Python24\lib\urllib2.py", line 1021, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "C:\Python24\lib\urllib2.py", line 980, in do_open
h = http_class(host) # will parse host:port
  File "C:\Python24\lib\httplib.py", line 586, in __init__
self._set_hostport(host, port)
  File "C:\Python24\lib\httplib.py", line 598, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: '|\'


Thanks,
Senthil

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


Re: Python 3000 idea -- + on iterables -> itertools.chain

2006-11-13 Thread George Sakkis
Fredrik Lundh wrote:

> George Sakkis wrote:
>
> > The base object class would be one candidate, similarly to the way
> > __nonzero__ is defined to use __len__, or __contains__ to use __iter__.
> >
> > Alternatively, iter() could be a wrapper type (or perhaps mixin)
> > instead of a function, something like:
>
> so you're proposing to either make *all* objects respond to "+", or
> introduce limited *iterator* algebra.

If by 'respond to "+"' is implied that you can get a "TypeError:
iterable argument required", as you get now for attempting "x in y" for
non-iterable y, why not ? Although I like the iterator algebra idea
better.

> not sure how that matches the OP's wish for "mostly backwards
> compatible" support for *iterable* algebra, really...

Given the subject of the thread, backwards compatibility is not the
main prerequisite. Besides, it's an *extension* idea; allow operations
that were not allowed before, not the other way around or modifying
existing semantics. Of course, programs that attempt forbidden
expressions on purpose so that they can catch and handle the exception
would break when suddenly no exception is raised, but I doubt there are
many of those...

George

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


Re: httplib.InvalidURL: nonnumeric port: For characters in the proxy password in URL

2006-11-13 Thread Fredrik Lundh
Phoe6 wrote:
> Hi,
>  The following piece of code works properly when my proxy password
> contains characters[a-zA-Z0-9] etc. But when my proxy password
> contained something like '|\/|' , the httplib incorrectly indentified
> it as separator.

if you want to prevent the URI parser from treating something as part of 
the URI, you need to quote it:

pwd = urllib.quote(pwd, "")



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


Re: httplib continuation packets

2006-11-13 Thread Steve Holden
Haakon Riiser wrote:
> [Fredrik Lundh]
> 
>> Haakon Riiser wrote:
>>
>>> Yes, and it doesn't help.
>> then the server is mostly likely broken beyond repair.
> 
> It's not in my power to upgrade the server, unfortunately.
> Guess I'll have to use Perl.
> 
>> to see if this really is the problem, you could try moving the call to 
>> self._send_output() from the end of the endheaders() method to the end 
>> of the _send_request() method (around line 870 in httplib.py, at least 
>> in 2.5).
> 
> Tried this, but the tcpdump still looks the same (two packets: one
> with the headers, one with the body), and now it fails with
> 
> urllib2.HTTPError: HTTP Error 501: Not Implemented
> 
> Nevertheless, I'm fairly sure that the packet fragmentation is
> the culprit.  It works perfectly with Perl, even when I make
> no effort at all to spoof the browser (no user-agent, referer,
> cookies, etc.).
> 
It really does seem quite bizarre that a server should respond 
differently to the same TCP request when it is split differently into IP 
datagrams.

There really is nothing wrong (from a standards point of view) with 
sending FIN with your last data segment. FIN means "I guarantee to send 
no more data, and will continue to acknowledge your segments until I see 
your FIN".

Are you planning to report this bug to Ipswitch? It certainly sounds 
like someone should.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: explicit self revisited

2006-11-13 Thread Steve Holden
Doug wrote:
[...]
> The explicit self is there simply because OOP was tacked onto python as
> an afterthought.

No, it was added in such a way that Python would be useful as a 
procedural as well as an OO language.

I don't know what's got into me.

can't-normally-say-boo-to-a-goose-ly y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Data structure for ordered sequence

2006-11-13 Thread [EMAIL PROTECTED]
Dear all,
 I am looking for a data structure to hold rectangles in a 2d space.
Please point me to any module which does these operations:
 Insert a rectangle into a particular co-ordinate.
 Get the rectangle/s right/left/above/below side to a particular
rectangle.
 Get all the rectangles within a box
 Delete a particular rectangle.

--
thanks.
Suresh

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


Re: reduce to be removed?

2006-11-13 Thread Steve Holden
Dustan wrote:
> Alright, I can see I'm a bit outvoted here. I tried your suggestions
> and it worked fine.
> 
> I'll also try to consider in the future that part of the problem might
> be lack of information conveyed on my part.
> 
Well, since such honest and public self-examination is so rarely seen 
(especially in the face of the effbot's occasional vehement bluntness) 
allow me to congratulate you on your open-mindedness.

Sometimes it seems like "egoless programming" went out with the 1980's. 
I'm sure I'll enjoy reading your future posts.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Jython compile errors ...

2006-11-13 Thread [EMAIL PROTECTED]
If you are looking for an example of jython there is one in embeded in
csound blue.  available from the csounds.com website I believe.  I have
used it under the new java framework.  I am not far enough along to
know if you are missing brackets {} exc and () and one ; but you can
try getting the python part to work under python 2.3


https://sourceforge.net/project/showfiles.php?group_id=156455

donkeyboy wrote:
> All,
>
> I've tried the jythonc compiler to try and create an applet to see how
> it works, but I get a number of Java compile errors that are way above
> my knowledge. Does anyone know what any of the following means? I'm
> using JDK 1.5.0_09, under Win XP SP2.
>
> Runnnig the file " jython FILENAME" works, so I don't know what's
> happening. Any thoughts?
>
> C:\EclipseWorkbench\Jython>jythonc -d --jar leaders.jar jy_leaders.py
> processing jy_leaders
>
> Required packages:
>   javax.swing
>   java.lang
>   java.awt
>   java.applet
>   java.util
>
> Creating adapters:
>   java.awt.event.ActionListener used in jy_leaders
>
> Creating .java files:
>   jy_leaders module
> MyDrawPanel extends javax.swing.JPanel
> Main extends java.applet.Applet
>
> Compiling .java to .class...
> Compiling with args: ['c:\\Program
> Files\\Java\\jdk1.5.0_09\\bin\\javac', '-clas
> spath',
> 'C:\\jython\\jython.jar;;.\\jpywork;;C:\\jython\\Tools\\jythonc;C:\\Ecli
> pseWorkbench\\Jython\\.;C:\\jython\\Lib;C:\\jython',
> '.\\jpywork\\jy_leaders.jav
> a']1  .\jpywork\jy_leaders.java:3:  expected
> public class jy_leaders extends java.lang.Object {
>  ^
> .\jpywork\jy_leaders.java:8: '{' expected
> public static class _PyInner extends PyFunctionTable implements
> PyRunnable {
>
>   ^
> .\jpywork\jy_leaders.java:419: ')' expected
> Py.initProxy(this, "jy_leaders", "MyDrawPanel", args, 2
> jython_leaders_sandbox.jpy$packages, jy_leaders.jpy$proxyProperties
> , "", new String[] {"jy_leaders"});
>
> ^
> .\jpywork\jy_leaders.java:548: ')' expected
> Py.initProxy(this, "jy_leaders", "Main", args, 2jython_
> leaders_sandbox.jpy$packages, jy_leaders.jpy$proxyProperties, "", n
> ew String[] {"jy_leaders"});
>
>  ^
> .\jpywork\jy_leaders.java:565: ')' expected
> Py.runMain(jy_leaders._PyInner.class, newargs, 2jython_lead
> ers_sandbox.jpy$packages, jy_leaders.jpy$mainProperties, "", new St
> ring[] {"jy_leaders"});
> ^
> .\jpywork\jy_leaders.java:565: ';' expected
> Py.runMain(jy_leaders._PyInner.class, newargs, 2jython_lead
> ers_sandbox.jpy$packages, jy_leaders.jpy$mainProperties, "", new St
> ring[] {"jy_leaders"});
> ^
> .\jpywork\jy_leaders.java:565:  expected
> Py.runMain(jy_leaders._PyInner.class, newargs, 2jython_lead
> ers_sandbox.jpy$packages, jy_leaders.jpy$mainProperties, "", new St
> ring[] {"jy_leaders"});
>  ^
> .\jpywork\jy_leaders.java:565: '{' expected
> Py.runMain(jy_leaders._PyInner.class, newargs, 2jython_lead
> ers_sandbox.jpy$packages, jy_leaders.jpy$mainProperties, "", new St
> ring[] {"jy_leaders"});
>
>
>^
> .\jpywork\jy_leaders.java:569: '}' expected
> ^
> 9 errors
>
> ERROR DURING JAVA COMPILATION... EXITING
> 
> Any help would be of great assistance -- thanks in advance.

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


Re: reduce to be removed?

2006-11-13 Thread Steve Holden
Dustan wrote:
> Fredrik Lundh wrote:
>> Dustan wrote:
[...]
>> Repeat after me:
>>
>> "Not everything has to be a one-liner."
> 
> Not everything has to be a one-liner. But readability helps.
> 
Indeed. And there is absolutely no conflict between those two statements.

Guido resisted introducing tertiary expressions for as long as he did 
precisely because he realised that some people would use them to produce 
unreadable one-liners instead of readable multi-line expressions of the 
same idea.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Decimal() instead of float?

2006-11-13 Thread Steve Holden
Michael B. Trausch wrote:
> Is there a way to use Decimal() by default in Python instead of float?  

No. You'll just have to be explicit.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: reduce to be removed?

2006-11-13 Thread Steve Holden
Paddy wrote:
> Dustan wrote:
> 
>> Anyway, I figured out a way to get the builtin
>> function 'sum' to work as I need:
>> sum([[1,2,3],[4,5,6],[7,8,9]],  [])
>>
> 
> Hah!
> No-one expects sum to be used on anything but numbers.
> 
> Except lists as above.
> 
> No-one expects sum to be used on anything but numbers, and maybe lists
> too.
> 
> ;-)
[voice mumbles:] "What about tuples"

Right, tuples too. But apart from tuples and lists, nobody expects sum 
to be used on anything but numbers.

In actual fact when Alex Martelli introduced sum() he intended it to be 
polymorphic over all the container types including strings. The check to 
exclude the string case was added when it was determined that it was 
terribly inefficient to concatenate strings that way. the same may well 
apply to other sequences.

I suppose it's only a matter of time before someone wants to define 
dict.__add__ ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Data structure for ordered sequence

2006-11-13 Thread [EMAIL PROTECTED]
There are probily better ways to do this.  The pil library has a
rectangle drawing feature, I would check through the docs of wxwindows
and tkinter unless this is homework because the pil people will not let
you distribute pils.  I am going to be looking for the same think let
me know if you get a better answer.

http://my.opera.com/yjfuk/blog/index.dml/tag/captcha


https://sourceforge.net/project/showfiles.php?group_id=156455
http://www.dexrow.com




[EMAIL PROTECTED] wrote:
> Dear all,
>  I am looking for a data structure to hold rectangles in a 2d space.
> Please point me to any module which does these operations:
>  Insert a rectangle into a particular co-ordinate.
>  Get the rectangle/s right/left/above/below side to a particular
> rectangle.
>  Get all the rectangles within a box
>  Delete a particular rectangle.
> 
> --
> thanks.
> Suresh

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


Re: Jython compile errors ...

2006-11-13 Thread John Machin

[EMAIL PROTECTED] wrote:
> If you are looking for an example of jython there is one in embeded in
> csound blue.  available from the csounds.com website I believe.  I have
> used it under the new java framework.  I am not far enough along to
> know if you are missing brackets {} exc and () and one ; but you can
> try getting the python part to work under python 2.3
>
>
> https://sourceforge.net/project/showfiles.php?group_id=156455
>
> donkeyboy wrote:
> > All,
> >
> > I've tried the jythonc compiler to try and create an applet to see how
> > it works, but I get a number of Java compile errors that are way above
> > my knowledge. Does anyone know what any of the following means? I'm
> > using JDK 1.5.0_09, under Win XP SP2.
> >
> > Runnnig the file " jython FILENAME" works, so I don't know what's
> > happening. Any thoughts?
[snip]

I was about to nominate somebody else for the monthly Most Astonishing
Result of Misreading a Post award, but the above just blew it away :-)

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


Re: Find interface associated with default route?

2006-11-13 Thread Steve Holden
Neal Becker wrote:
[...]
> 
> A quick strace reveals that 'route' just reads /proc/net/route, so:
> 
C:\Steve>type /proc/net/route
The syntax of the command is incorrect.

C:\Steve>type \proc\net\route
The system cannot find the path specified.

Python, but not platform dependent :-)

It would be nice to provide a shim module to provide stuff like this in 
a way that any platofrm could use. But when you look at the trouble it 
took to find a reasonable way for Ka Ping's guid function to locate an 
Ethernet address you'll agree that it would be a lot of work.

So probably reading /proc/net/route is a good bet for a limited range of 
platforms. OpenBSD is another place you won't find /proc/net/route.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Data structure for ordered sequence

2006-11-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 > unless this is homework because the pil people will not let
> you distribute pils.

I'm not sure I can parse this sentence fragment.  What do you mean?



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


Re: reduce to be removed?

2006-11-13 Thread Fredrik Lundh
Steve Holden wrote:

> In actual fact when Alex Martelli introduced sum() he intended it to be 
> polymorphic over all the container types including strings. The check to 
> exclude the string case was added when it was determined that it was 
> terribly inefficient to concatenate strings that way. the same may well 
> apply to other sequences.

an important difference is that if you repeatedly copy a string object, 
you'll actually copy *all* data in the string over and over again.  when 
you copy a list, you only copy references to the objects in the list. 
the size of the data *in* the list doesn't matter.

> I suppose it's only a matter of time before someone wants to define 
> dict.__add__ ...

that's been proposed quite a few times, and always gets stuck when it's 
time to define the exact semantics for dealing with collisions.  there 
are simply too many ways to do it, and all of them are can be trivially 
and efficiently implemented in terms of copy/update or for-in (or, in 
quite a few cases, by using sets instead of dicts).



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


Re: Data structure for ordered sequence

2006-11-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

>  I am looking for a data structure to hold rectangles in a 2d space.
> Please point me to any module which does these operations:
>  Insert a rectangle into a particular co-ordinate.
>  Get the rectangle/s right/left/above/below side to a particular
> rectangle.
>  Get all the rectangles within a box
>  Delete a particular rectangle.

how many rectangles do you plan to store in this structure?



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


Re: logging

2006-11-13 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> Hi all !
> How to remove a logger ?
> There si no logging.removeLogger(name) method.
> I've a lot of objects that create loging.
> When objects are destroyed, associated logger are not. This create
> memory leak...

Instead of removing unused loggers, reuse them. Calling getLogger with an
already known name will not create a new one, but instead return the
already existing one. 

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


str.title question after '

2006-11-13 Thread Antoon Pardon
I have a text in ascii. I use the ' for an apostroph. The problem is
this gives problems with the title method.  I don't want letters
after a ' to be uppercased. Here are some examples:

   argument   result  expected

  't smidje   'T Smidje   't Smidje
  na'ama  Na'Ama  Na'ama
  al pi tnu'atAl Pi Tnu'AtAl Pi Tnu'at


Is there an easy way to get what I want?

Should the current behaviour condidered a bug?
My would be inclined to answer yes, but that may be
because this behaviour would be wrong in Dutch. I'm
not so sure about english.

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


Re: how is python not the same as java?

2006-11-13 Thread Bruno Desthuilliers
Jorge Vargas wrote:
> On 9 Nov 2006 18:09:37 -0800, John Machin <[EMAIL PROTECTED]> wrote:
>>
>> Jorge Vargas wrote:
>> > On 9 Nov 2006 16:44:40 -0800, gavino <[EMAIL PROTECTED]> wrote:
>> > > both are interpreted oo langauges..
>> > >
>> > that is not correct java is compiled and the VM interprets the code
>>
>> ... and what do you think is in those pesky little .pyc files you may
>> have noticed lying around on your hard disk?
>>
> can you open a commandline

Open it with what ? A knife ?

> and start writting java code? no

And ? Some implementations of at least Haskell, OCaml, and Common Lisp
are compiled, and still offer a REPL.

> the division between java (runtime) and javac is very explicit,

And ?

> the
> compiler catches a lot of things, in python this is threaded in a
> totally different way.
> 
> the pyc files are just a "catching" system for the common python
> developer

The pyc files are binary files containing Python byte-code.

>, as for the java developer the .class files are executable
> code. In python noone runs the pyc files, the interpreter takes care
> of this for you.

And ? The fact that the Python runtime is smart enough (lol) to silently
 call the compiler when needed doesn't make Python (well, CPython...)
more or less "interpreted" or "compiled".


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


Re: Python 3000 idea -- + on iterables -> itertools.chain

2006-11-13 Thread Carl Banks
Georg Brandl wrote:
> What has a better chance of success in my eyes is an extension to yield
> all items from an iterable without using an explicit for loop: instead of
>
> for item in iterable:
>  yield item
>
> you could write
>
> yield from iterable
>
> or
>
> yield *iterable

Since this is nothing but an alternate way to spell a very specific
(and not-too-common) for loop, I expect this has zero chance of
success.


Carl Banks

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


Re: substring search without using built in utils

2006-11-13 Thread Bruno Desthuilliers
John Machin wrote:
> Bruno Desthuilliers wrote:
>> Gabriel Genellina wrote:
>>> At Wednesday 8/11/2006 22:29, zeal elite wrote:
>>>
 I am looking for substring search python program without using the
 built in funtions like find, or 'in'.
>>> The only reasonable usage for such a constraint would be a school
>>> assignment so: don't cheat and do your homework!
>>>
>> OTHO, looking for existing solutions to a same or similar problem and
>> studying them is usually considerer good practice in real-life
>> programming jobs !-)
>>
> 
> Looking at an existing solution for substring search that was coded in
> Python, instead of using the built-in functionality would IMHO be
> considered extremely bad practice in a real-life programming job.
> 

Indeed.

FWIW, and if it wasn't clear enough, my post was meant to be somewhat
ironic...


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


Using signal.alarm to terminate a thread

2006-11-13 Thread Adrian Casey
I have a multi-threaded python application which uses pexpect to connect to
multiple systems concurrently.  Each thread within my application is a
connection to a remote system.  The problem is when one of the child
threads runs a command which generates an unlimited amount of output.  The
classic example of this is the "yes" command.  If you
execute "pexpect.run('yes')", your cpu will sit at 100% forever.

Here is a simple multi-threaded program using pexpect which demonstrates the
problem.  The command 'yes' is run in a thread.  The parent says that when
the alarm goes off, run the handler function.  The thread sets the alarm to
trigger after 5 seconds.

#!/usr/bin/env python
import signal, os, pexpect, threading

def handler(signum, frame):
# This should get called after 5 seconds when the alarm fires.
os.system('killall yes')
print "The yes command has been killed!"

def runyes():
# Run the 'yes' command in a thread.  Set an alarm
# to fire in 5 seconds.
signal.alarm(5)
print "Running yes command..."
# If you run 'sleep 10' instead, this works.
pexpect.run('yes')
# Re-set the alarm.  (This is never reached.  The 'yes'
# command runs forever and is not interrupted by the alarm)
signal.alarm(0)

signal.signal(signal.SIGALRM, handler)
t = threading.Thread(target=runyes)
t.start()
t.join()
# END of code

Note that if the 'yes' command is substituted for 'sleep 10', the code works
perfectly.

Why can't the 'yes' command be interrupted using the SIGALRM method when the
sleep command can?  I realize that noone would really run 'yes' but what if
a user account has a buggy .bashrc and loops forever?  Just one thread
locking up like this holds up all the others.

Any ideas or suggestions on how to handle such situations in a
multi-threaded way would be appreciated.

Cheers.
Adrian Casey.
Alice Springs Linux User Goup.
http://www.aslug.org.au
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data structure for ordered sequence

2006-11-13 Thread [EMAIL PROTECTED]

Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> >  I am looking for a data structure to hold rectangles in a 2d space.
> > Please point me to any module which does these operations:
> >  Insert a rectangle into a particular co-ordinate.
> >  Get the rectangle/s right/left/above/below side to a particular
> > rectangle.
> >  Get all the rectangles within a box
> >  Delete a particular rectangle.
>
> how many rectangles do you plan to store in this structure?
> 
> 

Around 150 max

Thanks for the response.
--
Suresh

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


Re: str.title question after '

2006-11-13 Thread John Machin
Antoon Pardon wrote:
> I have a text in ascii. I use the ' for an apostroph. The problem is
> this gives problems with the title method.  I don't want letters
> after a ' to be uppercased. Here are some examples:
>
>argument   result  expected
>
>   't smidje   'T Smidje   't Smidje
>   na'ama  Na'Ama  Na'ama
>   al pi tnu'atAl Pi Tnu'AtAl Pi Tnu'at
>
>
> Is there an easy way to get what I want?

Depends on your definition of "easy". Writing your own function that
will regard the apostrophe as a letter would be "easy" in my book.

>
> Should the current behaviour condidered a bug?

Its limitations could use some documentation.

> My would be inclined to answer yes, but that may be
> because this behaviour would be wrong in Dutch. I'm
> not so sure about english.
>

It's not very appropriate for English, either:

| >>> "didn't".title()
| "Didn'T"

It's OK for the English way of writing Irish surnames e.g. O'Brien, but
not IMHO very good behaviour for anything else.

The docs say: "Return a titlecased version of the string: words start
with uppercase characters, all remaining cased characters are
lowercase." Evidently the definition of "word" is the culprit.

Doing titlecasing properly depends heavily on the language/locale and
what data you are working on. For example, in the UK and anywhere that
Scots have migrated in reasonable numbers, you would probably want to
do McDonald and MacDonald. Avoiding nonsenses like MacE and MacHin :-)
takes some effort and a look-up table, and may not be cost-effective.

A related problem: some people mistakenly try too hard to correct
perceived data entry errors and also produce nonsenses -- a colleague
of Dutch extraction occasionally received mail addressed to Mr O'Belt
:-)

Cheers,
John

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


Re: str.title question after '

2006-11-13 Thread Leo Kislov

Antoon Pardon wrote:
> I have a text in ascii. I use the ' for an apostroph. The problem is
> this gives problems with the title method.  I don't want letters
> after a ' to be uppercased. Here are some examples:
>
>argument   result  expected
>
>   't smidje   'T Smidje   't Smidje
>   na'ama  Na'Ama  Na'ama
>   al pi tnu'atAl Pi Tnu'AtAl Pi Tnu'at
>
>
> Is there an easy way to get what I want?

def title_words(s):
words = re.split('(\s+)', s)
return ''.join(word[0:1].upper()+word[1:] for word in words)

>
> Should the current behaviour condidered a bug?

I believe it follows definition of \w from re module.

> My would be inclined to answer yes, but that may be
> because this behaviour would be wrong in Dutch. I'm
> not so sure about english.

The problem is more complicated. First of all, why title() should be
limited to human languages? What about programming languages? Is
"bar.bar.spam" three tokens or one in a foo programming language? There
are some problems with human languages too: how are you going to
process "out-of-the-box" and "italian-american"?

  -- Leo

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


Re: reduce to be removed?

2006-11-13 Thread Steve Holden
Fredrik Lundh wrote:
> Steve Holden wrote:
[...]
>> I suppose it's only a matter of time before someone wants to define 
>> dict.__add__ ...
> 
> that's been proposed quite a few times, and always gets stuck when it's 
> time to define the exact semantics for dealing with collisions.  there 
> are simply too many ways to do it, and all of them are can be trivially 
> and efficiently implemented in terms of copy/update or for-in (or, in 
> quite a few cases, by using sets instead of dicts).
> 
But, as we both know, the fact that something can be trivially 
implemented in Python doesn't stop people asking for it to be added as 
native.

oh-no-indeed-ly y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Python 3000 idea -- + on iterables -> itertools.chain

2006-11-13 Thread Carl Banks
George Sakkis wrote:
> Fredrik Lundh wrote:
>
> > George Sakkis wrote:
> >
> > > The base object class would be one candidate, similarly to the way
> > > __nonzero__ is defined to use __len__, or __contains__ to use __iter__.
> > >
> > > Alternatively, iter() could be a wrapper type (or perhaps mixin)
> > > instead of a function, something like:
> >
> > so you're proposing to either make *all* objects respond to "+", or
> > introduce limited *iterator* algebra.
>
> If by 'respond to "+"' is implied that you can get a "TypeError:
> iterable argument required", as you get now for attempting "x in y" for
> non-iterable y, why not ?

Bad idea on many, many levels.  Don't go there.


> Although I like the iterator algebra idea
> better.
>
> > not sure how that matches the OP's wish for "mostly backwards
> > compatible" support for *iterable* algebra, really...
>
> Given the subject of the thread, backwards compatibility is not the
> main prerequisite. Besides, it's an *extension* idea; allow operations
> that were not allowed before, not the other way around or modifying
> existing semantics.

You missed the important word (in spite of Fredrick's emphasis):
iterable.  Your iter class solution only works for *iterators* (and not
even all iterators); the OP wanted it to work for any *iterable*.

"Iterator" and "iterable" are protocols.  The only way to implement
what the OP wanted is to change iterable protocol, which means changing
the documentation to say that iterable objects must implement __add__
and that it must chain the iterables, and updating all iterable types
to do this.  Besides the large amount of work that this will need,
there are other problems.

1. It increases the burden on third party iterable developers.
Protocols should be kept as simple as possible for this reason.
2. Many iterable types already implement __add__ (list, tuple, string),
so this new requirement would complicate these guys a lot.

> Of course, programs that attempt forbidden
> expressions on purpose so that they can catch and handle the exception
> would break when suddenly no exception is raised, but I doubt there are
> many of those...

3. While not breaking backwards compatibility in the strictest sense,
the adverse effect on incorrect code shouldn't be brushed aside.  It
would be a bad thing if this incorrect code:

a = ["hello"]
b = "world"
a+b

suddenly started failing silently instead of raising an exception.


Carl Banks

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


Re: httplib.InvalidURL: nonnumeric port: For characters in the proxy password in URL

2006-11-13 Thread Phoe6
Fredrik Lundh wrote:
> Phoe6 wrote:
> > Hi,
> >  The following piece of code works properly when my proxy password
> > contains characters[a-zA-Z0-9] etc. But when my proxy password
> > contained something like '|\/|' , the httplib incorrectly indentified
> > it as separator.
>
> if you want to prevent the URI parser from treating something as part of
> the URI, you need to quote it:
>
> pwd = urllib.quote(pwd, "")

Tried this and did not work out. It ended up confusing urllib and
urllib2 objects.
I dont want to import urllib, with the urllib2 itself wanted to work
around this piece of code.


proxy_user = r'senthil_or'
proxy_password='|\/|pr0c'
#proxy_password = r'|\/|pr0c'

# Setup the Proxy with urllib2

proxy_url = r'http://' + proxy_user + ':' + proxy_password + '@' +
PROXY_IP

proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)
urllib2.install_opener(opener)


Thanks,
Senthil

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


Re: httplib.InvalidURL: nonnumeric port: For characters in the proxypassword in URL

2006-11-13 Thread Fredrik Lundh
"Phoe6" wrote:

>> if you want to prevent the URI parser from treating something as part of
>> the URI, you need to quote it:
>>
>> pwd = urllib.quote(pwd, "")
>
> Tried this and did not work out. It ended up confusing urllib and
> urllib2 objects.

oh, please.  urllib.quote is a *function*; there's no way that calling that 
function
from code written for urllib2 will affect anything.

but you can access urllib.quote from the urllib2 namespace too.  it's actually 
the
very same function:

>>> urllib.quote

>>> urllib2.quote


(urllib2 imports lots of stuff from urllib)

> I dont want to import urllib, with the urllib2 itself wanted to work
> around this piece of code.

not wanting to solve a problem is a pretty lousy problem-solving strategy, 
really.

 



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


Re: Using signal.alarm to terminate a thread

2006-11-13 Thread Nick Craig-Wood
Adrian Casey <[EMAIL PROTECTED]> wrote:
>  I have a multi-threaded python application which uses pexpect to connect to
>  multiple systems concurrently.  Each thread within my application is a
>  connection to a remote system.  The problem is when one of the child
>  threads runs a command which generates an unlimited amount of output.  The
>  classic example of this is the "yes" command.  If you
>  execute "pexpect.run('yes')", your cpu will sit at 100% forever.
> 
>  Here is a simple multi-threaded program using pexpect which demonstrates the
>  problem.  The command 'yes' is run in a thread.  The parent says that when
>  the alarm goes off, run the handler function.  The thread sets the alarm to
>  trigger after 5 seconds.

1) Don't ever mix threads and signals - you are heading for trouble!

2) pexpect has a timeout parameter exactly for this case

import os, pexpect, threading

def runyes():
print "Running yes command..."
pexpect.run('yes', timeout=5)

t = threading.Thread(target=runyes)
t.start()
t.join()

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


An Invitation to Get Involved in Python Advocacy

2006-11-13 Thread Jeff Rush
I'd like to extend an invitation to those who would like to get involved in 
advocating the use of Python.  In August, the PSF hired me, for a 6-mo 
contract, to coordinate the Python advocacy effort.  Since then I've been 
working to make the next PyCon one of the best conferences yet, and putting in 
place the infrastructure of a newcomer portal (http://advocacy.python.org) 
focused on drawing in those people who don't know much about Python but have 
developed an interest for various reasons.  The portal also has an entry point 
(http://advocacy.python.org/getinvolved) to organize the materials and 
activities of those already in the Python community who want to get involved. 
I've also established a new mailing list <[EMAIL PROTECTED]> on which to 
discuss advocacy, replacing the <[EMAIL PROTECTED]> list, and a 
blog.(http://python-advocacy.blogspot.com) for keeping the Python community 
up-to-date about advocacy goings on.  The blog is aggregated into the official 
Planet Python (but I can't seem to reach the coordinator of the *unofficial* 
Planet Python).

A bit about the newcomer portal to place it in context; the portal is designed 
to help someone who has just become aware of Python decide if the language is 
right for them.  It seeks to quickly direct visitors to the information they 
want, and bring to their attention how diverse and vibrant the support for 
Python is.  The audience is not only programmers but also journalists, project 
managers, scientists/engineers, recruiters and educators.  Different audiences 
come at Python with different needs and often need different explanations. 
And some  are indeed programmers, but using other languages, who wonder how 
Python compares to what they are using now.

For the newcomer portal we have a need for content writers to focus on 
specific problem domains, for the various subcommunities to provide technology 
roadmaps and representative samples of source code that would entice someone 
to check them out.  As one example, the SciPy/NumPy group could write about 
what makes their software attractive to the scientific community and provide 
one-page sources that illustrates certain common operations, to show off the 
clarify and expressiveness of Python.  I've found plenty of material on the 
SciPy website that I'm weaving into the newcomer portal.

The portal is not designed to replace what we have at www.python.org but to 
complement it, and to serve as an organizing point for the extensive content 
already on www.python.org and elsewhere.  The portal also specifically 
supports dynamic content, relational database storage of information and easy 
plug-in of new components to add new features.  Such features will eventually 
include, among other things, a searchable roster of user groups, a registry of 
speakers and trainers and a catalog of books about Python, each with RSS feeds 
where appropriate.

And for the curious, the portal is written using the Zope 3 component system, 
building on the underlying Twisted subsystem for internal background 
scheduling and hooked to a PostgreSQL database.  The site makes use of Zope 3 
viewlets to provide pluggable display elements, reStructured text documents 
for a clean separation between content and infrastructure, and Nabu for 
synchronization of document collections into the indexing engine and 
persisting of the reST DOMs to enable content manipulation at presentation 
time according to what is to be viewed (biblio data, abstracts, content).  The 
portal is located on the python.org servers and all software and content are 
checked into svn.python.org.

In closing, I am greatly honored by the trust of the foundation members in me 
and hope to serve the community well.  As coordinator, I invite others to get 
involved and will strive to provide an assistive environment within which 
everyone can be productive.  The primary discussion area is the new mailing 
list which can be joined at:

   http://mail.python.org/mailman/listinfo/advocacy

and a list of what is needed is at:

   http://advocacy.python.org/getinvolved

I am also maintaining a list of accomplishments and near-term To-Do's for 
myself at:

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

Jeff Rush
Python Advocacy Coordinator
-- 
http://mail.python.org/mailman/listinfo/python-list


Set header from IMAP

2006-11-13 Thread Laszlo Nagy

  Dear List,

I'm trying to figure out, how to change the header of an e-mail that is 
accessed by an IMAP object.
There is some code below (not a complete program). The key function is 
the filter_mail function. It should move/delete/change/export messages, 
based on their header. For exporting messages, I use this: "typ,dat = 
self.conn.uid('FETCH',self.uid,'(RFC822)') ". The only thing I don't 
know how to do, is to insert/modify/delete custom headers in e-mails. I 
was looking for this on Google and the Python cookbook, but I did not 
find anyting useful. Please help.

   Laszlo


import local
import imaplib

class IMAPError(Exception):
pass

def check_imap_error((typ,data)):
if (typ != 'OK'):
raise IMAPError((typ,data))
   
def getnewimapconnection():
conn = imaplib.IMAP4_SSL(local.IMAP_HOST)
check_imap_error(conn.LOGIN(local.IMAP_LOGIN,local.IMAP_PWD))
return conn


conn = getnewimapconnection()
cnt = 0
try:
for inputfolder in (local.SOURCE_FOLDER,local.SOURCE_FOLDER2):
typ,data = conn.select(inputfolder)
check_imap_error((typ,data))
cnt = int(data[0])

if cnt > 0:
self.logger.info("Processing %s messages in %s",cnt,inputfolder)
# Get UID and RFC822 headers for all messages
typ, items = conn.fetch('1:%s'%cnt, '(UID RFC822.HEADER)')
check_imap_error((typ, items))
for item in items:
if isinstance(item,tuple):
uid = item[0].split()[2]
headers = item[1]
parser = email.Parser.Parser()
parsed = parser.parsestr(headers,True)
filter_mail(conn,uid,parsed)
conn.expunge()
else:
self.logger.info("No new messages in %s",inputfolder)
finally:
conn.logout()



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


Re: logging

2006-11-13 Thread [EMAIL PROTECTED]

Diez B. Roggisch wote:
> [EMAIL PROTECTED] wrote:
>
> > Hi all !
> > How to remove a logger ?
> > There si no logging.removeLogger(name) method.
> > I've a lot of objects that create loging.
> > When objects are destroyed, associated logger are not. This create
> > memory leak...
>
> Instead of removing unused loggers, reuse them. Calling getLogger with an
> already known name will not create a new one, but instead return the
> already existing one.
>
> Diez

Hi

That's a good idea but object name change (necessity).
The only issue seems to have a pool of loggers and select one into it.
I have to encapsulate logging library...
Thanks a lot.

Any ideas ?

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


Re: httplib.InvalidURL: nonnumeric port: For characters in the proxypassword in URL

2006-11-13 Thread Phoe6
Fredrik Lundh wrote:

Hi Fredrik,
   I apologize if I offended you or have shown any
impatience. I shall try again:

> oh, please.  urllib.quote is a *function*; there's no way that calling that 
> function
> from code written for urllib2 will affect anything.
>
> but you can access urllib.quote from the urllib2 namespace too.  it's 
> actually the
> very same function:
>
> >>> urllib.quote
> 
> >>> urllib2.quote
> 
>
> (urllib2 imports lots of stuff from urllib)

I dont know, it does not for me.

>>> urladd = "http://example.net:[EMAIL PROTECTED]:|\/|pr0c"
>>> print urladd
http://example.net:[EMAIL PROTECTED]:|\/|pr0c
>>>import urllib2
>>> url = urllib2.quote(urladd)
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'module' object has no attribute 'quote'
>>> import urllib
>>> url = urllib.quote(urladd)
>>> print url
http%3A//example.net%3A80%40username%3A%7C%5C/%7Cpr0c
>>>

> > I dont want to import urllib, with the urllib2 itself wanted to work
> > around this piece of code.
>
> not wanting to solve a problem is a pretty lousy problem-solving strategy, 
> really.

Sorry. :-) I shall take your advice and try to get to bottom of this
issue.
- To the piece of code, I import urllib
- use urllib.quote() to covert the proxy url to a quoted one.
and try again, I get an error:


Traceback (most recent call last):
  File "C:\Python24\forge\ngwallp\ngwall.py", line 38, in ?
data = urllib2.urlopen(site)
  File "C:\Python24\lib\urllib2.py", line 130, in urlopen
http://lava.nationalgeographic.com/cgi-bin/pod/wallpaper.cgi?day=13&month=11&year=06
return _opener.open(url, data)
  File "C:\Python24\lib\urllib2.py", line 358, in open
response = self._open(req, data)
  File "C:\Python24\lib\urllib2.py", line 376, in _open
'_open', req)
  File "C:\Python24\lib\urllib2.py", line 337, in _call_chain
result = func(*args)
  File "C:\Python24\lib\urllib2.py", line 573, in 
lambda r, proxy=url, type=type, meth=self.proxy_open: \
  File "C:\Python24\lib\urllib2.py", line 580, in proxy_open
if '@' in host:
TypeError: iterable argument required


This is where, I gave up and wrote the previous email as not to mess up
urllib with urllib2.
The piece of code, was working properly till I changed my proxy
password to something containng '|\/|'.
- Before shooting a mail to the grooups, i kindda encoded password to
valid url characters ( %7C%5C/%7C) and tried. But this did not work.
So, I dont think this is urllib.quote() issue. I am looking for a way
as how to use the ProxyHandler with authentication in different way
than I have used below.

proxy_url_add = r'http://' + proxy_user + ':' + proxy_password + '@' +
PROXY_IP
proxy_url = urllib.quote(proxy_url_add)

proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)
urllib2.install_opener(opener)

Thanks for your response.
Regards,
Senthil

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


Re: httplib.InvalidURL: nonnumeric port: For characters in theproxypassword in URL

2006-11-13 Thread Fredrik Lundh
"Phoe6" wrote:

> - use urllib.quote() to covert the proxy url to a quoted one.

you should use quote to convert the *password* to quoted form, not use it on
the entire URL.

 



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


Re: httplib.InvalidURL: nonnumeric port: For characters in theproxypassword in URL

2006-11-13 Thread Phoe6
Fredrik Lundh wrote:
> "Phoe6" wrote:
>
> > - use urllib.quote() to covert the proxy url to a quoted one.
>
> you should use quote to convert the *password* to quoted form, not use it on
> the entire URL.
>
Am sorry Fred. The same problem:

  File "C:\Python24\lib\httplib.py", line 598, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: '|\'

I dont think its an issue to be resolved with quote().

Thanks,
Senthil

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


Re: logging

2006-11-13 Thread Jorge Vargas
On 12 Nov 2006 23:50:40 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hi all !
> How to remove a logger ?
> There si no logging.removeLogger(name) method.
> I've a lot of objects that create loging.

why you need a logger per object? IMO 1 per package is more then enough.
> When objects are destroyed, associated logger are not. This create
> memory leak...
>
> Thanks for any idea.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Python development time is faster.

2006-11-13 Thread Chris Brat
I've seen a few posts, columns and articles which state that one of the
advantages of Python is that code can be developed x times faster than
languages such as <>.

Does anyone have any comments on that statement from personal
experience?
How is this comparison measured?


Thanks
Chris

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


Re: how is python not the same as java?

2006-11-13 Thread Jorge Vargas
ok then they are the same lets all go back to write java
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: httplib continuation packets

2006-11-13 Thread Haakon Riiser
[Steve Holden]

> It really does seem quite bizarre that a server should respond 
> differently to the same TCP request when it is split differently into IP 
> datagrams.
>
> There really is nothing wrong (from a standards point of view) with 
> sending FIN with your last data segment. FIN means "I guarantee to send 
> no more data, and will continue to acknowledge your segments until I see 
> your FIN".

It is the server that sends the FIN.  What happens is this (each
line corresponds to one packet):

  client: POST request headers
  client: POST request body
  server: FIN + ACK

On receiving the FIN + ACK packet, Python gets immediate
end-of-file on the POST request.  Unless the order of the
parameters in the POST request matters (I haven't yet tested this),
I have no other explanation than the fragmentation.  If Ipswitch
bothers to reply to my bug report, I'll look into it.  Otherwise,
I'm not wasting any more time on this -- it's not that big a deal
for me personally, since I have already scripted the stuff I needed
with Perl.

> Are you planning to report this bug to Ipswitch? It certainly sounds 
> like someone should.

I quickly browsed through ipswitch.com, but couldn't find any good
place to submit bugs.  I ended up using the product feedback web
form.  Wrote a one-line summary, and referred to this thread on
Google Groups.

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


Re: Python development time is faster.

2006-11-13 Thread Fredrik Lundh
Chris Brat wrote:

> I've seen a few posts, columns and articles which state that one of the
> advantages of Python is that code can be developed x times faster than
> languages such as <>.
>
> Does anyone have any comments on that statement from personal
> experience?

have you tried writing something in Python, or are you just asking around to
see if it's worth the effort to download it and play with it a little?

 



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


Re: httplib.InvalidURL: nonnumeric port: For characters intheproxypassword in URL

2006-11-13 Thread Fredrik Lundh
"Phoe6" wrote:

> Am sorry Fred. The same problem:
>
>  File "C:\Python24\lib\httplib.py", line 598, in _set_hostport
>raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
> httplib.InvalidURL: nonnumeric port: '|\'
>
> I dont think its an issue to be resolved with quote().

can you post the code you're using to build the URI ?

 



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


Re: explicit self revisited

2006-11-13 Thread Hendrik van Rooyen
"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote:


> Especially since there is a comefrom 


*breaks into song* : "Oh Susannah, now don't you cry for me..."

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


Re: Py3K idea: why not drop the colon?

2006-11-13 Thread Simon Brunning
On 11/11/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Hendrik van Rooyen wrote:
>
> >> blue is red or green or yellow
> >
> > *grin* - this can be construed as a weakness in Python -
>
> it's boolean logic, and it's incompatible with human use of the same
> terms in all contexts, not just Python.

Indeed.

The other day, I way showing my eight year old, Freja, what a program
looks like:

your_name = raw_input("What's your name? ")
if your_name.lower() == "freja":
print "You're very stinky,", your_name
else:
print "You smell lovely, ", your_name

After running it a couple of times, she dove in and changed the 2nd line to:

if your_name.lower() == "daddy or ella":

(Ella is my other daughter's name.) That's pretty close to correct,
I'd say - but you don't get anything for being close in a programming
language.

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging

2006-11-13 Thread Diez B. Roggisch
> 
> That's a good idea but object name change (necessity).

So what? You can log the name, but you don't need a logger with that name
for that!

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


Re: Python development time is faster.

2006-11-13 Thread Paddy

Chris Brat wrote:

> I've seen a few posts, columns and articles which state that one of the
> advantages of Python is that code can be developed x times faster than
> languages such as <>.
>
> Does anyone have any comments on that statement from personal
> experience?
> How is this comparison measured?
>
>
> Thanks
> Chris
Here's a start:
  http://www.tcl.tk/doc/scripting.html

Go Googling. There's a paper out their that compares error rates and
time to program, lines of code, for several languages and is often
cited in defence of scripting languages. (Scripting languages have
however moved on and now like to be called dynamic languages).

- Pad.

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


Re: reduce to be removed?

2006-11-13 Thread Kay Schluehr
On 12 Nov., 00:14, Fredrik Lundh <[EMAIL PROTECTED]> wrote:

> if you care about writing robust code, why not just use a for-loop,
> and the list extend method?
>
> 

Because generic solutions using HOFs increase abstraction and reduce()
the amount of code one has to write even when they are outcasted by
Guido?

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


Re: Python development time is faster.

2006-11-13 Thread Chris Brat
I work full time with Java, but downloaded python about a year ago and
started playing.

I've used it quite a few times in my working environment.

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


Character Encodings and display of strings

2006-11-13 Thread JKPeck
I am trying to understand why, with nonwestern strings, I sometimes get
a hex display and sometimes get the string printed as characters.

With my Python locale set to Japanese and with or without a # coding of
cp932 (this is Windows) at the top of the file, I read a list of
Japanese strings into a list, say, catlis.

With this code
for item in catlis:
print item
print catlis
print " ".join(catlis)

the first print (print item) displays Japanese text as characters..
The second print (print catlis) displays a list with the double byte
characters in hex notation.
The third print (print " ".join(catlis)) prints a combined string of
Japanese characters properly.

According to the print documentation,
"If an object is not a string, it is first converted to a string using
the rules for string conversions"

but the result is different with a list of strings.

The hex display looks like this:
['id', '\x90\xab\x95\xca', '\x90\xb6\x94N\x8c\x8e\x93\xfa',
'\x8fA\x8aw\x94N\x90\x94', '\x90E\x8e\xed', '\x8b\x8b\x97^',
'\x8f\x89\x94C\x8b\x8b', '\x8d\xdd\x90\xd0\x8c\x8e\x90\x94',
'\x90E\x96\xb1\x8co\x97\xf0', '\x90l\x8e\xed']

and correctly shows the hex values of the Japanese characters.

Why are these different?

TIA,
Jon Peck

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


Re: Character Encodings and display of strings

2006-11-13 Thread Fredrik Lundh
"JKPeck" wrote:

>I am trying to understand why, with nonwestern strings, I sometimes get
> a hex display and sometimes get the string printed as characters.
>
> With my Python locale set to Japanese and with or without a # coding of
> cp932 (this is Windows) at the top of the file, I read a list of
> Japanese strings into a list, say, catlis.
>
> With this code
> for item in catlis:
>   print item
> print catlis
> print " ".join(catlis)
>
> the first print (print item) displays Japanese text as characters..
> The second print (print catlis) displays a list with the double byte
> characters in hex notation.
> The third print (print " ".join(catlis)) prints a combined string of
> Japanese characters properly.
>
> According to the print documentation,
> "If an object is not a string, it is first converted to a string using
> the rules for string conversions"
>
> but the result is different with a list of strings.

a list is not a string, so it's converted to one using the standard list 
representation
rules -- which is to do repr() on all the items, and add brackets and commas as
necessary.

for some more tips on printing, see:

http://effbot.org/zone/python-list.htm#printing

 



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


Re: article on Python 2.5 features

2006-11-13 Thread Michele Simionato
Beliavsky wrote:
> A Parade of New Features Debuts in Python 2.5
> by Gigi Sayfan
> "Python 2.5 still has the smell of fresh paint but it's the perfect
> time to drill down on the most important new features in this
> comprehensive release. Read on for detailed explanations and examples
> of exception handling, resource management, conditional expressions,
> and more."
>
> The full article is at
> http://www.devx.com/webdev/Article/33005/0/page/1 .

The article is nice overall, but I did not like the part about enhanced
generators. For instance, the sentence "The new interactive send()
empowers
generators to implement co-routines", could be debated. Also, it gives
you the false impression that you could not interact with Python 2.2
generators ("interact" in the sense of the article). IMO the important
bit about Python 2.5 generators is that you can send exceptions to
a generator, all the other features can be emulated even using revious
versions of Python.
For instance, here is an emulation of his tokenizer using Python 2.2
generators and a helper 'read_eval_yield_loop' class:

# morally turns a Python 2.2+ generator into a Python 2.5 generator
class read_eval_yield_loop(object):
def __init__(self, gen, *args, **kw):
self._arg = None
self._it = gen(iter(lambda : self._arg, StopIteration), *args,
**kw)
def __iter__(self):
return self._it
def send(self, arg):
self._arg = arg
return self._it.next()
def next(self):
return self.send(None)

# copied from the article with very minor changes
def tokenizer3(read, text, sep):
try:
while True:
token = ''
while text[0] == sep:
text = text[1:]

index = 0
while text[index] != sep:
token += text[index]
index += 1
yield token
new_sep = read.next()
if new_sep != None:
sep = new_sep
text = text[index:]
except IndexError:
if token != '':
yield token

if __name__=='__main__':
print '--- Smart Python 2.2+ tokenizer ---'
g = read_eval_yield_loop(tokenizer3, text, ' ')
for t in g:
print t
if t == 'comma':
g.send(',')

  Michele Simionato

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


Find how to embed the BitTorrent in my program

2006-11-13 Thread 张沈鹏
Is there any module can easy embed the BitTorrent(both tracker and 
client) in myself's program .
Or where can find the documents for reuse official BitTorrent .

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


Re: Character Encodings and display of strings

2006-11-13 Thread JKPeck
Thanks for the quick answer.  I thought repr was involved here, but
when I use repr explicitly I get a notation where the backslashes are
escaped.  I also though that with the encoding explictily declared in
the source, that repr would take that into account and use the
character form, but obviously it doesn't.


Fredrik Lundh wrote:
> "JKPeck" wrote:
>
> >I am trying to understand why, with nonwestern strings, I sometimes get
> > a hex display and sometimes get the string printed as characters.
> >
> > With my Python locale set to Japanese and with or without a # coding of
> > cp932 (this is Windows) at the top of the file, I read a list of
> > Japanese strings into a list, say, catlis.
> >
> > With this code
> > for item in catlis:
> >   print item
> > print catlis
> > print " ".join(catlis)
> >
> > the first print (print item) displays Japanese text as characters..
> > The second print (print catlis) displays a list with the double byte
> > characters in hex notation.
> > The third print (print " ".join(catlis)) prints a combined string of
> > Japanese characters properly.
> >
> > According to the print documentation,
> > "If an object is not a string, it is first converted to a string using
> > the rules for string conversions"
> >
> > but the result is different with a list of strings.
>
> a list is not a string, so it's converted to one using the standard list 
> representation
> rules -- which is to do repr() on all the items, and add brackets and commas 
> as
> necessary.
>
> for some more tips on printing, see:
> 
> http://effbot.org/zone/python-list.htm#printing
> 
> 

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


Re: Python 3000 idea -- + on iterables -> itertools.chain

2006-11-13 Thread George Sakkis
Carl Banks wrote:

> George Sakkis wrote:
> > Fredrik Lundh wrote:
> >
> > > George Sakkis wrote:
> > >
> > > > The base object class would be one candidate, similarly to the way
> > > > __nonzero__ is defined to use __len__, or __contains__ to use __iter__.
> > > >
> > > > Alternatively, iter() could be a wrapper type (or perhaps mixin)
> > > > instead of a function, something like:
> > >
> > > so you're proposing to either make *all* objects respond to "+", or
> > > introduce limited *iterator* algebra.
> >
> > If by 'respond to "+"' is implied that you can get a "TypeError:
> > iterable argument required", as you get now for attempting "x in y" for
> > non-iterable y, why not ?
>
> Bad idea on many, many levels.  Don't go there.

Do you also find the way "in" works today a bad idea ?

> > Although I like the iterator algebra idea
> > better.
> >
> > > not sure how that matches the OP's wish for "mostly backwards
> > > compatible" support for *iterable* algebra, really...
> >
> > Given the subject of the thread, backwards compatibility is not the
> > main prerequisite. Besides, it's an *extension* idea; allow operations
> > that were not allowed before, not the other way around or modifying
> > existing semantics.
>
> You missed the important word (in spite of Fredrick's emphasis):
> iterable.  Your iter class solution only works for *iterators* (and not
> even all iterators); the OP wanted it to work for any *iterable*.

I didn't miss the important word, I know the distinction between
iterables and iterators; that's why I said I like the iterator algebra
idea better (compared to extending the object class so that effectively
creates an iterable algebra).

> "Iterator" and "iterable" are protocols.  The only way to implement
> what the OP wanted is to change iterable protocol, which means changing
> the documentation to say that iterable objects must implement __add__
> and that it must chain the iterables, and updating all iterable types
> to do this.  Besides the large amount of work that this will need,
> there are other problems.
>
> 1. It increases the burden on third party iterable developers.
> Protocols should be kept as simple as possible for this reason.
> 2. Many iterable types already implement __add__ (list, tuple, string),
> so this new requirement would complicate these guys a lot.

If __add__ was ever to be part of the *iterable* protocol, it would be
silly to implement it for every new iterable type; the implementation
would always be the same (i.e. chain(self,other)), so it should be put
in  a base class all iterables extend from. That would be either a
mixin class, or object. This is parallel to how __contains__ is part of
the sequence protocol, but if you (the 3rd party sequence developer)
don't define one, a default __contains__ that relies on __getitem__ is
created for you.

> > Of course, programs that attempt forbidden
> > expressions on purpose so that they can catch and handle the exception
> > would break when suddenly no exception is raised, but I doubt there are
> > many of those...
>
> 3. While not breaking backwards compatibility in the strictest sense,
> the adverse effect on incorrect code shouldn't be brushed aside.  It
> would be a bad thing if this incorrect code:
>
> a = ["hello"]
> b = "world"
> a+b
>
> suddenly started failing silently instead of raising an exception.

That's a good example for why I prefer an iterator rather than an
iterable algebra; the latter is too implicit as "a + b" doesn't call
only __add__,  but __iter__ as well. On the other hand, with a concrete
iterator type "iter(a) + iter(b)" is not any more error-prone than
'int(3) + int("2")' or 'str(3) + str("2")'.

What's the objection to an *iterator* base type and the algebra it
introduces explicitly ?

George

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


Re: Fredrik Lundh [was "Re: explicit self revisited"]

2006-11-13 Thread fynali
> You idiot.  Putting the word "official" in front of something doesn't
> mean it can't be FUD.  Especially when it is written by people such as
> yourself.  Have you not paid attention to anything happening in
> politics around the world during your lifetime?

Ridiculous boo-llshit!

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


CORBA: Fnorb Problems

2006-11-13 Thread rodmc
Hi,

I have installed Fnorb and everything seems to have gone ok. However I
keep getting the error message below. This is despite the fact that the
MS CL c++ preprocessor seems to be in PATH. I can type "cl" and
although I get nothing back in the DOS window, there is also no error
message.

Traceback (most recent call last):
  File "C:\Python24\Lib\site-packages\Fnorb\script\cpp.py", line 53, in
-toplevel-
raise "No C/C++ pre-processor found in your PATH!"
No C/C++ pre-processor found in your PATH!

On seeing what information is returned the variables which are
searching for the presence of CL in PATH come back with nothing.

System: Windows XP, Python 2.4, Most recent version of Fnorb 1.3.

Any pointers are welcome. Thanks in advance.


Best,

rod

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


Re: Python development time is faster.

2006-11-13 Thread Harry George
"Chris Brat" <[EMAIL PROTECTED]> writes:

> I've seen a few posts, columns and articles which state that one of the
> advantages of Python is that code can be developed x times faster than
> languages such as <>.
> 
> Does anyone have any comments on that statement from personal
> experience?
> How is this comparison measured?
> 
> 
> Thanks
> Chris
> 

Personal experience takes two forms.

1. Broad experience with languages, such that doing a single project
   in a new language gives a sense of the relative power and
   ease-of-use.  Everyone I know who is a strong Python supporter took
   that route.  There was an Ahh-Ha experience part way into the first
   project.  This includes folks who could charitably be called
   curmudgeons, and people who are truely fluent in, say, C++ or Lisp.

   For these people the main success factor is that "it just works".
   You spend time on new functionality, or experimenting with
   alternative algorithms, not on debugging.  Of course, we work in a
   regression-test-driven world, so we don't pile up a lot of untested
   code and then hope for the best.  Python facilitates that
   test-early-test-often approach with its modularity and fast
   edit-run cycle.

2. Write the same thing in 2 or more languages.  Due to machine
   migrations and project redirections I have done that with
   perl-and-python, java-and-python, modula3-and-python,
   lisp-and-python.  In all cases, python was the second language, so
   there is some learning curve to be adjusted for (i.e., I understood
   the semantics better).  However, since I've done some
   perl-and-perl, and lisp-and-lisp, I can maybe make that adjustment.

   The result was that python was relatively faster-to-develop.  I
   can't give a specific speedup factor, but I sure can say Python is
   now my default language.  The success factors were:

   a) Once you get the hang of the language (a weekend?), you can
   write without reference to the manuals.  Or if you do reference, it
   is a quick lookup.  No struggling to figure out how to code
   something.  Or to decypher what a line of code actually does.

   b) The project doesn't bog down as you add features.  The language
   can accomodate new paradigms, patterns, or major functionality.  If
   you do need to refactor, that is easy too.  

   c) Peer code reviews are easy -- both you and the reviewers can
   understand the code's intent at a glance.


-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python development time is faster.

2006-11-13 Thread Steven Bethard
Chris Brat wrote:
> I've seen a few posts, columns and articles which state that one of the
> advantages of Python is that code can be developed x times faster than
> languages such as <>.
> 
> Does anyone have any comments on that statement from personal
> experience?

I had to work at a laboratory a few years ago which used Java 
exclusively.  I was coming from several years as a graduate student 
using Python almost exclusively for my own work.  (But I used to teach 
introductory Java classes at my previous university, so I had plenty of 
Java experience.)

My own work and the work that I did for the lab were quite similar, 
mainly focused on training machine learning models on natural language 
processing tasks. I estimated that the Java code took me about 5x as 
long. Part of this is the verbosity of Java, e.g. where you have to 
write an anonymous inner class instead of using a function or a class 
object directly. But probably a larger part of this was using the Java 
libraries, which tend to be way over-engineered, and more complicated to 
use than they need to be.

A simple example from document indexing.  Using Java Lucene to index 
some documents, you'd write code something like::

 Analyzer analyzer = new StandardAnalyzer()
 IndexWriter writer = new IndexWriter(store_dir, analyzer, true)
 for (Value value: values) {
 Document document = Document()
 Field title = new Field("title", value.title,
 Field.Store.YES,
 Field.Index.TOKENIZED)
 Field text = new Field("text", value.text,
Field.Store.YES,
Field.Index.TOKENIZED)
 document.add(title)
 document.add(text)
 }

Why is this code so verbose?  Because the Lucene Java APIs don't like 
useful defaults. So for example, even though StandardAnalyzer is 
supposedly *Standard*, there's no IndexWriter constructor that includes 
it automatically. Similarly, if you create a Field with a string name 
and value (as above), you must specify both a Field.Store and a 
Field.Index - there's no way to let them default to something reasonable.

Compare this to Python code. Unfortunately, PyLucene wraps the Lucene 
APIs pretty directly, but I've wrapped PyLucene with my own wrapper that 
adds useful defaults (and takes advantages of things like Python's 
**kwargs).  Here's what the same code looks like with my Python wrapper 
to Lucene::

 writer = IndexWriter(store_dir)
 for value in values:
 document = Document(title=value.title, text=value.text)
 writer.addDocument(document)
 writer.close()

Gee, and I wonder why it took me so much longer to write things in Java. ;-)


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


Re: httplib.InvalidURL: nonnumeric port: For characters intheproxypassword in URL

2006-11-13 Thread Phoe6
Fredrik Lundh wrote:
>
> can you post the code you're using to build the URI ?
>
Okay. This piece of code fetches a page from a particular site. As I am
behind a firewall, I have to communicate through a proxy.

# Set the Proxy Address
PROXY_IP = "10.1.9.4:80"

# Trying with linear way

proxy_user = 'user_name'
proxy_password_orig='|\/|pc'
proxy_password = urllib.quote(proxy_password_orig)

#proxy_password = r'|\/|pr0c'

# Setup the Proxy with urllib2

proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' +
PROXY_IP

proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)
urllib2.install_opener(opener)

# Read the ngsite
tdate = str(datetime.date.today())
sepdate = re.compile('\d\d(\d\d)-(\d+)-(\d+)')

year = sepdate.match(tdate).group(1)
month = sepdate.match(tdate).group(2)
day = sepdate.match(tdate).group(3)

site =
r"http://lava.nationalgeographic.com/cgi-bin/pod/wallpaper.cgi?day="; +
day + "&month=" + month + "&year=" + year
print site
data = urllib2.urlopen(site)

-- 
Senthil

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


Re: how is python not the same as java?

2006-11-13 Thread Bruno Desthuilliers
Jorge Vargas wrote:
> ok then they are the same lets all go back to write java

No, thanks... I'll keep my snake !-)

And actually, I'm afraid I somewhat misunderstood your previous post - I
took it as meaning "Python has a REPL and you don't have to explicitelly
call the compiler so Python is interpreted". If that was not what you
meant, please consider this a typical case of "monday morning, not
enough coffein yet".

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


Re: httplib.InvalidURL: nonnumeric port: For charactersintheproxypassword in URL

2006-11-13 Thread Fredrik Lundh
"Phoe6" wrote:

> proxy_password = urllib.quote(proxy_password_orig)

make that:

proxy_password = urllib.quote(proxy_password_orig, "")

 



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


Re: Python development time is faster.

2006-11-13 Thread George Sakkis
Steven Bethard wrote:

> A simple example from document indexing.  Using Java Lucene to index
> some documents, you'd write code something like::
>
>  Analyzer analyzer = new StandardAnalyzer()
>  IndexWriter writer = new IndexWriter(store_dir, analyzer, true)
>  for (Value value: values) {
>  Document document = Document()
>  Field title = new Field("title", value.title,
>  Field.Store.YES,
>  Field.Index.TOKENIZED)
>  Field text = new Field("text", value.text,
> Field.Store.YES,
> Field.Index.TOKENIZED)
>  document.add(title)
>  document.add(text)
>  }
>
> Why is this code so verbose?  Because the Lucene Java APIs don't like
> useful defaults. So for example, even though StandardAnalyzer is
> supposedly *Standard*, there's no IndexWriter constructor that includes
> it automatically. Similarly, if you create a Field with a string name
> and value (as above), you must specify both a Field.Store and a
> Field.Index - there's no way to let them default to something reasonable.
>
> Compare this to Python code. Unfortunately, PyLucene wraps the Lucene
> APIs pretty directly, but I've wrapped PyLucene with my own wrapper that
> adds useful defaults (and takes advantages of things like Python's
> **kwargs).  Here's what the same code looks like with my Python wrapper
> to Lucene::
>
>  writer = IndexWriter(store_dir)
>  for value in values:
>  document = Document(title=value.title, text=value.text)out two
>  writer.addDocument(document)
>  writer.close()
>
> Gee, and I wonder why it took me so much longer to write things in Java. ;-)

Oh, the memories... I went down the same road about two years ago,
though I didn't know about PyLucene at the time and wrapped in jython
the parts of Lucene I used... never bothered to deal with java's
verbosity after that. It's a pity that jython resembles abandon-ware
these days, when jRuby showed up pretty recently and is gaining in
penetration with the java crowd. It will be a non-trivial loss for
python if it is left behind in the JVM world (at least if the latter is
not swallowed by the .NET dark forces, which doesn't seem to happen any
time soon ;-).

George

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


Re: CORBA: Fnorb Problems

2006-11-13 Thread Diez B. Roggisch
rodmc wrote:

> Hi,
> 
> I have installed Fnorb and everything seems to have gone ok. However I
> keep getting the error message below. This is despite the fact that the
> MS CL c++ preprocessor seems to be in PATH. I can type "cl" and
> although I get nothing back in the DOS window, there is also no error
> message.
> 
> Traceback (most recent call last):
>   File "C:\Python24\Lib\site-packages\Fnorb\script\cpp.py", line 53, in
> -toplevel-
> raise "No C/C++ pre-processor found in your PATH!"
> No C/C++ pre-processor found in your PATH!
> 
> On seeing what information is returned the variables which are
> searching for the presence of CL in PATH come back with nothing.
> 
> System: Windows XP, Python 2.4, Most recent version of Fnorb 1.3.
> 
> Any pointers are welcome. Thanks in advance.

I used omniorb, and have been very satisfied with it. You might consider
switching.

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


Re: httplib.InvalidURL: nonnumeric port: For characters in the proxypassword in URL

2006-11-13 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
 urllib.quote
>
 urllib2.quote
>

>>> urllib.quote

>>> urllib2.quote
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'module' object has no attribute 'quote'
>>> sys.version
'2.4.1 (#2, May  5 2005, 11:32:06) \n[GCC 3.3.5 (Debian 1:3.3.5-12)]'

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python development time is faster.

2006-11-13 Thread Diez B. Roggisch
> Oh, the memories... I went down the same road about two years ago,
> though I didn't know about PyLucene at the time and wrapped in jython
> the parts of Lucene I used... never bothered to deal with java's
> verbosity after that. It's a pity that jython resembles abandon-ware
> these days, when jRuby showed up pretty recently and is gaining in
> penetration with the java crowd. It will be a non-trivial loss for
> python if it is left behind in the JVM world (at least if the latter is
> not swallowed by the .NET dark forces, which doesn't seem to happen any
> time soon ;-).

I wouldn't consider jython abandonware. It is under active development, and
I'm using a 2.2 alpha successful for quite a while now - which usually
serves my needs.

The problem is/was that new-style classes were a major hurdle to take, and
this now seems to be conquered. So lets hope (or contribute code:P)
that jython will see a 2.4 version ASAP.

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


Dr. Dobb's Python-URL! - weekly Python news and links (Nov 13)

2006-11-13 Thread Cameron Laird
QOTW:  "It is humbling to see how simple yet powerfull python`s view on
things is" - Éric Daigneault 
http://groups.google.com/group/comp.lang.python/msg/bbd842715bb5b6eb

"[I]f a machine is expected to be infallible, it cannot also be
intelligent." - Alan Turing, 20 February 1947, lecture to London
Mathematical Socity on ACE http://en.wikipedia.org/wiki/ACE_(computer) >


Stefan Schukat illustrates an instructive use of COM in a multi-threaded
context which manages a MATLAB instance:

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

Someone should capture the scattered but valuable observations of this
report on Windows-hosted extending into a more enduring document:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/36c13e238e6e3bb4

Paul Boddie provides references on concurrency in Python:
http://groups.google.com/group/comp.lang.python/msg/4a507814e704b782

Microsoft publicizes IronPython's ASP.Net capabilities:

http://www.infoworld.com/archives/emailPrint.jsp?R=printThis&A=/article/06/11/07/HNvsiron_1.html

http://www.eweek.com/article2/0,1895,2053498,00.asp?kc=EWWHNEMNL110906EOAD
The latest release of eric3 supports QScintilla autocompletion,
and more:
http://www.die-offenbachs.de/detlev/eric.html

Is a "parameter-holding class" reasonable?  Probably so, at
least on occasion:

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


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

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

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

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

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

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

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

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

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

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

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

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

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

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

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

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

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi
http://python.de/backend.php
For more, see
http://www.syndic8.

Re: Character Encodings and display of strings

2006-11-13 Thread Diez B. Roggisch
JKPeck wrote:

> Thanks for the quick answer.  I thought repr was involved here, but
> when I use repr explicitly I get a notation where the backslashes are
> escaped.  I also though that with the encoding explictily declared in
> the source, that repr would take that into account and use the
> character form, but obviously it doesn't.

The encoding in the source has nothing to do with that. How should an
encoding (and possibly a gazillion different ones in gazillion other
sourcefiles of yours) influence the list repr code?

The encoding in the source-file is solely used to correctly parse unicode
literals, as these need a specific encoding to be generated from the
byte-string they are in the sourcecode.

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


tab compleation input

2006-11-13 Thread Eli Criffield

Here is what i want to do. I have a question in my program, and i want
to do tab completion for the valid answers.

Say i have :
--snip--
validanswers = [ 'yes', 'no', 'maybe', 'tuesday', 'never' ]

#and i ask

sys.stdout.write("Answer the Question: ")
answer = sys.stdin.readline().rstrip()
if answer not in valid answers:
  print "Wrong!"
--snip--

But what i want is when i enter the answer i can hit tab and it'll
complete one of the validanswers
I know i can do tab complete with readline and 'raw_input('> ')' but
that's only to execute python commands right?

Eli

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


Re: CORBA: Fnorb Problems

2006-11-13 Thread rodmc
>
> I used omniorb, and have been very satisfied with it. You might consider
> switching.
>
> Diez

Thanks, I have just downloaded that plus omniORBpy as well. I have the
binary version of omniORB but need to build omniORBpy, from what I can
see the build process is aimed at GCC and not VC++. Anyway I will try
to figure it out.

Best,

rod

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


Re: Python 3000 idea -- + on iterables -> itertools.chain

2006-11-13 Thread Georg Brandl
Carl Banks wrote:
> Georg Brandl wrote:
>> What has a better chance of success in my eyes is an extension to yield
>> all items from an iterable without using an explicit for loop: instead of
>>
>> for item in iterable:
>>  yield item
>>
>> you could write
>>
>> yield from iterable
>>
>> or
>>
>> yield *iterable
> 
> Since this is nothing but an alternate way to spell a very specific
> (and not-too-common) for loop, I expect this has zero chance of
> success.

well, it could also be optimized internally, i.e. with a new opcode.

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


Re: handling many default values

2006-11-13 Thread Michele Simionato
Alan Isaac wrote:
> Also, as an aside, no one objected to using
> self.__dict__.update(kwargs)
> in the __init__ function of the parameter holding class.

It is a common trick, also shown in the Python cookbook, IIRC. If you
are anal about
double underscores, you can also use

vars(self).update(kwargs)

  Michele Simionato

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


Re: CORBA: Fnorb Problems

2006-11-13 Thread Eric Brunel
On Mon, 13 Nov 2006 16:16:37 +0100, rodmc <[EMAIL PROTECTED]>  
wrote:

> Hi,
>
> I have installed Fnorb and everything seems to have gone ok. However I
> keep getting the error message below. This is despite the fact that the
> MS CL c++ preprocessor seems to be in PATH. I can type "cl" and
> although I get nothing back in the DOS window, there is also no error
> message.
>
> Traceback (most recent call last):
>   File "C:\Python24\Lib\site-packages\Fnorb\script\cpp.py", line 53, in
> -toplevel-
> raise "No C/C++ pre-processor found in your PATH!"
> No C/C++ pre-processor found in your PATH!

You don't say *when* this error occurs, i.e. what is the command that  
returns the exception. Assuming it's when you try to compile an IDL file  
with fnidl, just try:
fnidl --internal-cpp ...

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Elliptic Curve Simple Example

2006-11-13 Thread flit
Hello,

I am trying the Python Cryptography Toolkit, but I didnt succeed, maybe
I am not used to technical programming docs.

WHat I succeed, using the the AES example to encrypt and decrypt.
How Can I change it to use elliptic curves cryptography?
Anyone has a working example, in python to use elliptic to encrypt and
decrypt?

Any help is good
Thanks in advance

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


Re: explicit self revisited

2006-11-13 Thread Simon Brunning
On 11/13/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> > I suppose that in his view, language advocacy is a zero-sum game, so
> > positive comments about Python can be considered as FUD against his own
> > project.  He's even invented his own del.icio.us tag for this purpose:
> >
> >  http://del.icio.us/tag/pythonfud
>
> now at:
>
>  http://del.icio.us/tag/python-fud
>
> 

Hey, Fredrik, you have your own tag!
 I wish *I* had my own
tag. ;-)

I notice that, as you predicted, Python's lack of a goto is in there too.

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python component model

2006-11-13 Thread Magnus Lycka
sturlamolden wrote:
> There is a whole generation of computer users out there scared stiff of
> using the keyboard. Soon, computers will not have a keyboard at all.
> The trend is perhaps more pronounced among managers not writing code
> themselves, but "taking decisions" about which tools to use.

Is it just me, or does someone else feel that this is like
using magnetic letters on a refrigerator door instead of
a pen and paper. My two year old son thinks those magnetic
letters are fun, but then he can't write at all. My seven
year old has certainly switched to pen and paper (or computer)
for 99% of his writing. Sure, they have their use--it might be
more effective to write TENNIS with colorful letters across
the fridge door in some situation, but most of the time, pen
and paper is much more useful. You never run out of letters,
and it's easy to draw lines or arrows, complement the text
with a little picture etc. The cost for learning the skill
to write readable letters is well compensated for...

We recently released a toolkit for interfacing our systems
with legacy systems, and very soon, people started using it
in way we had never expected. I suppose that could be possible
with a "visual" tool too, but it seems to me that those tools
are typically fairly limited, just as computer based role-playing
games are much more limited than the ones played around a table
with a good flesh-and-blood game master who can respond to any
idea you come up with at the spur of the moment.

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


Re: explicit self revisited

2006-11-13 Thread Christophe
Simon Brunning a écrit :
> On 11/13/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>>
>> > I suppose that in his view, language advocacy is a zero-sum game, so
>> > positive comments about Python can be considered as FUD against his own
>> > project.  He's even invented his own del.icio.us tag for this purpose:
>> >
>> >  http://del.icio.us/tag/pythonfud
>>
>> now at:
>>
>>  http://del.icio.us/tag/python-fud
>>
>> 
> 
> Hey, Fredrik, you have your own tag!
>  I wish *I* had my own
> tag. ;-)
> 
> I notice that, as you predicted, Python's lack of a goto is in there too.

Hey, this is fun :D I also found that one : 
http://del.icio.us/dholton/python-fud-by-fredrik-lundh

But is seems they all point to the same article than yours so you get 
the points for it ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Singleton Class Exception

2006-11-13 Thread dischdennis
Hello List,

I would like to make a singleton class in python 2.4.3, I found this
pattern in the web:

class Singleton:
__single = None
def __init__( self ):
if Singleton.__single:
raise Singleton.__single
Singleton.__single = self


the line "raise Singleton.__single" invokes in my class the following
error:

exceptions must be classes, instances, or strings (deprecated), not
PurchaseRequisitionController



Greetings, Dennis

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


Re: Python development time is faster.

2006-11-13 Thread Egon Frerich
Chris Brat schrieb:
> I've seen a few posts, columns and articles which state that one of the
> advantages of Python is that code can be developed x times faster than
> languages such as <>.
>
> Does anyone have any comments on that statement from personal
> experience?
> How is this comparison measured?
>
>
> Thanks
> Chris
>
>   
Have a lookl at
http://wwwipd.ira.uka.de/EIR/otherwork/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Is python for me?

2006-11-13 Thread lennart
Hi,

I'm planning to learn a language for 'client' software. Until now, i
'speak' only some web based languages, like php. As a kid i programmed
in Basic (CP/M, good old days :'-) ) Now i want to start to learn a
(for me) new computer language.

I like Python. Its free, easy to learn and some favorite programs of my
are written in Python / can understand Python (like OpenOffice) etc.

But I'm not a full-time programmer. I know, that I've only time &
possibility to learn one (= 1) language good. So i ask myself is python
the language I'm looking for?

In the future, i want to write the following applications:
[*] A database driven program, which can handle my clients, tasks and
places (= 3 tables, has to work relative with each other). I think,
this isn't a problem for Python
[*] As a photographer i like to build a picture management system (also
db) with raw support. Raw is the raw-data from the sensor of the
camera. My questions:
- can python encode raw?
- can python head for a utility like dcraw?
- or head for a utility like IrfanView (delphi?) or something like
that? 

Tnx for your help!

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


Re: Python development time is faster.

2006-11-13 Thread flit
One thing I really like, is making "prototypes" on python.
Just to test some algorithm or procedure.
It is very fast and easy to debug.
So after, I make it in c++ (but not too much often, I leave it in
python today.)

Chris Brat wrote:
> I've seen a few posts, columns and articles which state that one of the
> advantages of Python is that code can be developed x times faster than
> languages such as <>.
>
> Does anyone have any comments on that statement from personal
> experience?
> How is this comparison measured?
> 
> 
> Thanks
> Chris

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


Re: Py3K idea: why not drop the colon?

2006-11-13 Thread Michael Hobbs
Steven D'Aprano wrote:
> On Fri, 10 Nov 2006 15:18:55 -0600, Michael Hobbs wrote:
>
>   
>> Ron Adam wrote:
>> 
>>> It is also an outline form that frequently used in written languages.  
>>> Something 
>>> python tries to do, is to be readable as if it were written in plain 
>>> language 
>>> where it is practical to do so.  So the colon/outline form makes a certain 
>>> sense 
>>> in that case as well.
>>>   
>>>   
>> That is perhaps the most convincing argument that I've heard so far. 
>> Indeed, I often find myself writing out colons when writing pseudo-code 
>> out on paper. The reason, however, is usually because my indents don't 
>> quite line up as perfectly on paper as they do in an editor. The colons 
>> provide a form of backup separation for when my columns start to get 
>> sloppy. (Natural language is actually filled with such redundancies in 
>> order to compensate for sloppy handwriting.)
>> 
>
> Er, natural language pre-dates handwriting by many tens or hundreds of
> thousands of years. The redundancy of natural language has many reasons,
> but compensating for sloppy handwriting is not one of them.  
I was using the term "natural language" in a wider sense, as in spoken 
languages, unspoken languages (sign languages), and writing systems. As 
far redundancies in writing systems go, it has been estimated that there 
is ~50% redundancy in the characters alone. That is, you can usually 
determine what a character is even when half of its strokes are removed. 
That's not even considering other redundancies such as using a phonetic 
alphabet vs. ideographs, or writing the vowels between consonants, which 
only started with the Greek alphabet.

>> This backup function 
>> obviously isn't needed when a computer is taking care of the layout.
>> 
>
> That word you use, "obviously", I don't think it means what you think it
> means. There's nothing obvious about your conclusion to me.
>
> while (this really long expression
> (which extends over multiple lines
> and contains many statements)
> some of which (like this one) contain
> nested bracketed terms such as (this
> expression here) but like all good 
> things) it eventually ends
> and we can get to the business
> of executing the while-block
>
> Compare that to the version with a colon:
>
> while (this really long expression
> (which extends over multiple lines
> and contains many statements)
> some of which (like this one) contain
> nested bracketed terms such as (this
> expression here) but like all good 
> things) it eventually ends:
> and we can get to the business
> of executing the while-block
>
>
> Arguably, the parser might not find the first version any more difficult
> than the second, but I know which one I'd rather read.  
I'd rather read neither. Both of them are obviously illegible. As the 
saying goes, you can write FORTRAN code in any language. That is, no 
language, no matter what its parsing rules, can prevent you from writing 
illegible code if you're determined to do so. To me, the second example 
is no more legible simply because it contains a colon somewhere. Proper 
style would dictate that you make some form of obvious break when 
writing a multi-line conditional, no matter which language you're using. 
Some possibilities:

while (this really long expression
(which extends over multiple lines
and contains many statements)
some of which (like this one) contain
nested bracketed terms such as (this
expression here) but like all good 
things) it eventually ends:

and we can get to the business
of executing the while-block


or

while (this really long expression
(which extends over multiple lines
and contains many statements)
some of which (like this one) contain
nested bracketed terms such as (this
expression here) but like all good 
things) it eventually ends:
and we can get to the business
of executing the while-block


or

while (this really long expression
(which extends over multiple lines
and contains many statements)
some of which (like this one) contain
nested bracketed terms such as (this
expression here) but like all good 
things) it eventually ends:
 BODY 
and we can get to the business
of executing the while-block


>> My final argument against the colons is to simply try programming in 
>> Ruby for a while and then come back to Python. I think you'll find that 
>> programming without the colons just simply feels more "natural".
>> 
>
> And maybe you're even correct. But one major reason of using the colon is
> to make it easier for _inexperienced_ programmers. Your suggestion that
> programming in Ruby for a while should be a prerequisite for making Python
> easy to read is an interesting one, but not one that many people will
> agree with. *wink*  
Is Python a cult, where it's considered dangerous to experience th

Research Master 0.1 (GPL/Python)

2006-11-13 Thread ccosse
ResearchMaster has been designed to simplify management of research
literature. It is a GUI interface to a system of folders and records.
Each record contains notes, meta info and BibTex info about an
associated file.  Instances of the single copy of a record can occur
throughout the folder system, as specified through a membership list.
A single button creates a recursive bibliography of all records
containing BibTex information which are children of the currently
selected parent node. One click launching of files by an associated
application is also supported. A tutorial document is included.

http://www.asymptopia.org

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


jython's future (was: Python development time is faster.)

2006-11-13 Thread Stefan Behnel
Diez B. Roggisch wrote
> I wouldn't consider jython abandonware. It is under active development, and
> I'm using a 2.2 alpha successful for quite a while now - which usually
> serves my needs.
> 
> The problem is/was that new-style classes were a major hurdle to take, and
> this now seems to be conquered. So lets hope (or contribute code:P)
> that jython will see a 2.4 version ASAP.

The jython project currently deploys a pretty cathedral-ish development style,
pretty much hidden from broader audiences. FWIW, it seems to be stuck in
trying to get out a 2.2 compliant release first, then to provide a 2.3
compliant version (at least, there's a branch for it). Guess it's a question
of human resources, but personally, I wouldn't care too much about
compatibility and just let people go and implement whatever feature they want
to be in on the way towards something as close to 2.5 (or maybe 2.4, why not)
as possible. Honestly, how many important Python modules do still run on 2.2?
Most switched to at least 2.3 quite a while ago.

After all, it's the compatible *software* that makes the difference, not the
platform. It's easier to say: "hey, this feature is lacking to make my program
run" than: "let's see, what else is there in that outdated specification to
implement?". And it's a lot more encouraging, too.

Just my little rant on this one ...

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


Re: Singleton Class Exception

2006-11-13 Thread Jason
dischdennis wrote:
> Hello List,
>
> I would like to make a singleton class in python 2.4.3, I found this
> pattern in the web:
>
> class Singleton:
> __single = None
> def __init__( self ):
> if Singleton.__single:
> raise Singleton.__single
> Singleton.__single = self
>
>
> the line "raise Singleton.__single" invokes in my class the following
> error:
>
> exceptions must be classes, instances, or strings (deprecated), not
> PurchaseRequisitionController
>
>
>
> Greetings, Dennis

The problem is that you yoinked a bad example of a singleton.  The
error is correct, only exceptions derived from the Exception class and
strings are supported.  (Strings are supported for historical usage,
and a deprecated.)

Why exactly do you need a singleton?  Do you want only one instance of
a class?  Often, you really want something that shares state: all are
one.  This pattern is known as a borg.  Please see
"http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531"; to see
how the Borg Pattern works.

If you absolutely gotta have a singleton, there are other ways of
implementing it.  I can think of only one reason: You want the
singleton's destructor to be called only if there are no remaining
instances in existance.  (For the Borg pattern, the deconstructor can
be called once per instance created.)

The problem with this reason is that Python doesn't guarantee when the
destructors will be called for instances (and some instances will never
have their destructors called).  Although C-Python implements usually
destroys an instance when its ref-count drops to 0, IronPython and
Jython may do things very differently.  (I have no experience with
either of those, so I cannot tell you how they differ.)

Still, if you're dead set on a Singleton class, I'll post one in a
little bit.

--Jason

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


Re: jython's future (was: Python development time is faster.)

2006-11-13 Thread Carsten Haese
On Mon, 2006-11-13 at 18:34 +0100, Stefan Behnel wrote:
> Honestly, how many important Python modules do still run on 2.2?

InformixDB still compiles on 2.2 except when I accidentally temporarily
break backwards compatibility.

Of course it's a matter of opinion whether it qualifies as an important
module. ;-)

-Carsten


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


Re: Character Encodings and display of strings

2006-11-13 Thread JKPeck
It seemed to me that this sentence

For many types, this function makes an attempt to return a string that
would yield an object with the same value when passed to eval().

might mean that the encoding setting of the source file might influence
how repr represented the contents of the string.  Nothing to do with
Unicode.  If a source file could have a declared encoding of, say,
cp932 via the # coding comment, I thought there was a chance that eval
would respond to that, too.


Diez B. Roggisch wrote:
> JKPeck wrote:
>
> > Thanks for the quick answer.  I thought repr was involved here, but
> > when I use repr explicitly I get a notation where the backslashes are
> > escaped.  I also though that with the encoding explictily declared in
> > the source, that repr would take that into account and use the
> > character form, but obviously it doesn't.
>
> The encoding in the source has nothing to do with that. How should an
> encoding (and possibly a gazillion different ones in gazillion other
> sourcefiles of yours) influence the list repr code?
>
> The encoding in the source-file is solely used to correctly parse unicode
> literals, as these need a specific encoding to be generated from the
> byte-string they are in the sourcecode.
> 
> Diez

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


Re: jython's future

2006-11-13 Thread Steve Holden
Carsten Haese wrote:
> On Mon, 2006-11-13 at 18:34 +0100, Stefan Behnel wrote:
>> Honestly, how many important Python modules do still run on 2.2?
> 
> InformixDB still compiles on 2.2 except when I accidentally temporarily
> break backwards compatibility.
> 
> Of course it's a matter of opinion whether it qualifies as an important
> module. ;-)
> 
I think you will find that most of Fredrik Lundh's stuff will work on 
1.5.2. He sets a fine example to us all.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Singleton Class Exception

2006-11-13 Thread Dan Lenski
dischdennis wrote:
> the line "raise Singleton.__single" invokes in my class the following
> error:
>
> exceptions must be classes, instances, or strings (deprecated), not
> PurchaseRequisitionController

Denis,
Jason's explanation is correct!  You are trying to use the Singleton
instance as the exception, which is not only confusing but illegal.
The argument of raise should be an instance of a class derived from
Exception.  You should define some kind of informative Exception class,
e.g.:

class SingletonException(Exception):
pass

class Singleton:
__single = None
def __init__( self ):
if Singleton.__single:
raise SingletonException()
Singleton.__single = self

foo = Singleton()# works
bar = Singleton()# raises SingletonException

Dan

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


httplib.ResponseNotReady question

2006-11-13 Thread Max
Hi, Group.

I'm not a Python programmer so this question may be really basic or
stupid. :)  I have some code that sends a simple request to an
end-point and reads the response.  That works just fine.  When I put
the code in a for loop though I get httplib.ResponseNotReady error
message.  It seems to me that I cannot call the requestor.getreply()
multiple times on the same requestor object.  Anyway, here's the part
of my code that is causing the problem (I hope the format is
preserved...).

def sendRequest( msg, loops ):
requestor = httplib.HTTP(SERVER_ADDR, SERVER_PORT)
requestor.putrequest("POST", "/path/to/endpoint")
requestor.putheader("Host", SERVER_ADDR)
requestor.putheader("Content-Type", "text/xml")
requestor.putheader("Content-Length", str(len( msg ) ) )
requestor.endheaders()
for i in range(loops):
requestor.send( msg )
print "[" + str(i) + "] Message Sent  : " +
time.strftime('%H:%M:%S', time.localtime())
(status_code, message, reply_headers) = requestor.getreply()
print "[" + str(i) + "] Response Received : " +
str(status_code)
print "[" + str(i) + "] Status: " +
time.strftime('%H:%M:%S', time.localtime())
print "-[ break ]-"

If I run this with loops=1 then everything works fine.  If I use a
number greater than 1 then I get the error.  Is there a method call
that I need to restore the requestor object to a condition where it's
eligible to receive another response?

Thanks, Max

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


Re: Is python for me?

2006-11-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
lennart <[EMAIL PROTECTED]> wrote:
>Hi,
>
>I'm planning to learn a language for 'client' software. Until now, i
>'speak' only some web based languages, like php. As a kid i programmed
>in Basic (CP/M, good old days :'-) ) Now i want to start to learn a
>(for me) new computer language.
>
>I like Python. Its free, easy to learn and some favorite programs of my
>are written in Python / can understand Python (like OpenOffice) etc.
>
>But I'm not a full-time programmer. I know, that I've only time &
>possibility to learn one (= 1) language good. So i ask myself is python
>the language I'm looking for?
>
>In the future, i want to write the following applications:
>[*] A database driven program, which can handle my clients, tasks and
>places (= 3 tables, has to work relative with each other). I think,
>this isn't a problem for Python
>[*] As a photographer i like to build a picture management system (also
>db) with raw support. Raw is the raw-data from the sensor of the
>camera. My questions:
>- can python encode raw?
>- can python head for a utility like dcraw?
>- or head for a utility like IrfanView (delphi?) or something like
>that? 
.
.
.
Yes.

Yes, Python is generally capable in all the roles you describe.
Perhaps most exciting, though, is that you can try out the
language yourself, TODAY, over the next few hours, and, in no
more time than that, get a realistic if limited idea how it's
likely to work for you.  With the right introduction http://docs.python.org/tut/ > you can be coding usefully in
Python very quickly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py3K idea: why not drop the colon?

2006-11-13 Thread John Salerno
Fredrik Lundh wrote:
> John Salerno wrote:
> 
>>> Anyway, the FAQ answer seems to be a weak argument to me.
>>
>> I agree. I was expecting something more technical to justify the 
>> colon, not just that it looks better.
> 
> yeah, the whole idea of treating programming languages as an interface 
> between people and computers is really lame.  no wonder nobody's using 
> Python for anything.
> 
> 
> 

personally, i don't mind the colon and see no need to lose it, but if we 
are talking in the realm of aesthetics, it actually seems like it would 
be cleaner if it weren't there...sure, at first everyone who is used to 
it might feel like something is missing, or the line is "hanging" open, 
but overall the less characters, the better, right? isn't that why the 
braces are gone?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: explicit self revisited

2006-11-13 Thread Peter Maas
Michele Simionato wrote:
> Peter Maas wrote:
>> All these reasons are valid and retained by the following suggestion: let
>> self be represented by the dot 
> 
> This suggestion has been discussed in the past (I remember having the
> same idea myself when I first learned Python). But at the end I believe
> the explicit 'self' is a better solution, because there are cases where
> it is useful to have it

Thanks, Michele. My intention wasn't to abandon explicit self but to replace
it by a shorter and unique entity. I searched a little for similar suggestions
in the past but didn't find them so I decided to post. I admit that my
suggestion was half-baked.

But at least I learned something: a heated debate isn't bound to become an
endless thread if the OP abstains from answering idiot replies ;)

--
Regards/Gruesse,

Peter Maas, Aachen
E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python for me?

2006-11-13 Thread [EMAIL PROTECTED]
As stated above python is capable of all those things, however on
larger applications like that it can tend to slow down a bit. And the
executables do need a little bit of work, because it's bassicly a dll
and a library of all your .pyc files. However python is still a great
language and I would recomend it. And most of these things will
probably be fixed in Python 3000!
Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> lennart <[EMAIL PROTECTED]> wrote:
> >Hi,
> >
> >I'm planning to learn a language for 'client' software. Until now, i
> >'speak' only some web based languages, like php. As a kid i programmed
> >in Basic (CP/M, good old days :'-) ) Now i want to start to learn a
> >(for me) new computer language.
> >
> >I like Python. Its free, easy to learn and some favorite programs of my
> >are written in Python / can understand Python (like OpenOffice) etc.
> >
> >But I'm not a full-time programmer. I know, that I've only time &
> >possibility to learn one (= 1) language good. So i ask myself is python
> >the language I'm looking for?
> >
> >In the future, i want to write the following applications:
> >[*] A database driven program, which can handle my clients, tasks and
> >places (= 3 tables, has to work relative with each other). I think,
> >this isn't a problem for Python
> >[*] As a photographer i like to build a picture management system (also
> >db) with raw support. Raw is the raw-data from the sensor of the
> >camera. My questions:
> >- can python encode raw?
> >- can python head for a utility like dcraw?
> >- or head for a utility like IrfanView (delphi?) or something like
> >that?
>   .
>   .
>   .
> Yes.
>
> Yes, Python is generally capable in all the roles you describe.
> Perhaps most exciting, though, is that you can try out the
> language yourself, TODAY, over the next few hours, and, in no
> more time than that, get a realistic if limited idea how it's
> likely to work for you.  With the right introduction  http://docs.python.org/tut/ > you can be coding usefully in
> Python very quickly.

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


Re: Py3K idea: why not drop the colon?

2006-11-13 Thread Michael Hobbs
Antoon Pardon wrote:
> On 2006-11-11, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>   
>> On Fri, 10 Nov 2006 13:16:32 -0600, Michael Hobbs wrote:
>>
>> 
>>> Yeah, okay, I didn't read through the details of the PEP. I picked a bad 
>>> example to illustrate a point that is still true. The FAQ also tries to 
>>> argue that it's a Good Thing that join() is a string method, not a list 
>>> method. It also tries to argue that there's a good reason that lists are 
>>> different than tuples. I don't think it would surprising that many 
>>> Python developers don't really buy those arguments either.
>>>   
>> Well, as far as I'm concerned, you've just blown your credibility
>> completely out the water now. 
>>
>> Yes, I'm aware that there are many Python programmers who don't get join()
>> or lists/tuples, but I'm constantly surprised by that fact. At the risk of
>> starting another argument, to my mind that's like discovering that there
>> are professional butchers who don't think that using a sharp knife is a
>> good idea.
>> 
>
> Well I would think that if you would find out that many professional
> butchers would think so, you might consider the idea has some merrit.
>   

As they say, insanity is nothing more than having a minority opinion. As 
more people take the opposite side, who's left being the crazy one? ;-)

- Mike

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


  1   2   >