Re: List of WindowsError error codes and meanings

2011-05-21 Thread John J Lee
Andrew Berg  writes:

> This is probably somewhat off-topic, but where would I find a list of
> what each error code in WindowsError means? WindowsError is so broad
> that it could be difficult to decide what to do in an except clause.
> Fortunately, sys.exc_info()[1][0] holds the specific error code, so I
> could put in an if...elif...else clause inside the except clause if I
> needed to, but I don't know what all the different errors are.

Since Python 2.5, the errno attribute maps the Windows error to error
codes that match the attributes of module errno.

http://docs.python.org/library/exceptions.html#exceptions.WindowsError

So for some purposes you can use the same UNIXy error codes you can use
on most other platforms.  Example:

import errno

try:
operation()
except WindowsError, exc:
if exc.errno != errno.ENOENT:
raise
print "file/directory does not exist"

Obviously whether this is useful depends on the error cases you need to
handle.

Undocumented: when there's no useful mapping to errno, you get
errno.EINVAL.


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


Re: application level monitoring for python

2011-05-21 Thread John J Lee
Walter Chang  writes:

> Hi
>
> is there any open source library for python that can allow application
> level monitoring ? For example,application can send per request level/
> aggregated monitoring events and some remote server dump it and show
> in the monitoring graph in real time  ?  What's best way of doing
> that ?

Zenoss is a popular tool for that kind of thing.  Here's an example of
sending a Zenoss event over XML-RPC:

http://dancingpenguinsoflight.com/2009/05/send-events-to-zenoss-from-scripts/

Presumably you can send it evnts over other transports somehow (e.g. UDP).

Zenoss is itself implemented in Python.


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


Re: Parsing a graph image

2011-05-21 Thread John J Lee
Bastian Ballmann  writes:

> Hi,
>
> the project sounds like the exact tool that i need but regarding the
> user manual one has to mark the points on the graph manually. Therefore
> it's more work to get the data out than doing it without a tool. Or may
> I miss something here?
> Greets

Read the documentation more carefully: it has features that allow
extracting points from line charts automatically.

If you want something fully automated, you just want jam on it ;-)


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


Re: checking if a list is empty

2011-05-21 Thread John J Lee
Gregory Ewing  writes:

> Hans Georg Schaathun wrote:
>>  0 is a number as real and existent as any other,
>> one would think that the empty list is also as real and existent as
>> any other list.
>
> 0 does have some special properties, though, such as
> being the additive identity and not having a multiplicative
> inverse. Adding falseness as another special property isn't
> too much of a stretch and turns out to be useful.
>
> Likewise, it's useful to treat empty containers as having
> a similar special property, since they're often a base or
> terminating case in algorithms.
>
> It's especially useful in a dynamic language where any
> additional operations such as finding the length or
> comparing with zero has a run-time cost.
>
> Yes, you have to learn it, but it's a small thing to
> learn with a considerable payoff.

(apologies if somebody already bikeshedded this argument in this thread)

In the absence of an explicit interface declaration (have any standards
emerged for that in Python 3, BTW?), the use of len() does give you some
information about the interface, which sometimes makes it easier to
change the function.

I'm sure you fully understand this, but I'll spell it out.  Consider
this function:

def xyzzy(x):
if x:
print "yes"


Let's say I've read the function, and I've seen this call site:

xyzzy(["spam", "eggs"])


Now I want to change xyzzy:

def xyzzy(x):
if x:
print "probably"
if len(x) == 1:
print "definitely"


But there may be many call sites.  Perhaps xyzzy even implements part of
a poorly-documented external API.  So can x be None?  There's no way to
know short of checking all call sites, which may be impossible.  It may
not even be feasible to check the *only* call site, if you're
implementing somebody else's poorly documented closed-source API (a
situation I came across at work only yesterday, when that situation
resulted in a bug report).  If it's written this way, it's clear that it
can't be None:

def xyzzy(x):
if len(x) != 0:
print "yes"


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


Abandoning Python

2011-05-21 Thread John J Lee


I still like Python after using it for over a decade, but there are
things I don't like.

What are your favourite up-and-coming languages of the moment?

Here's my wishlist (not really in any order):

 * A widely used standard for (optional) interface declaration -- or
   something better.  I want it to be easier to know what interface an
   object has when reading code, and which objects provide that
   interface.
 * Lower memory usage and faster execution speed.  Yes, this has been a
   price worth paying.  But I do want jam on it, please: give me a
   language where I get most of Python's advantages but don't have to
   pay it.
 * Better support for writing correct programs in the form of better
   support for things like non-imperative programming, DBC, etc. (with
   the emphasis on "etc").
 * Perhaps better built-in support for common tasks in common application
   domains.  Concurrency, persistence, database queries come to mind.
 * Better refactoring tools, better code analysis tools (lint, search,
   etc.).
 * An even larger user base, contributing more and better free and
   commercial software.

I'm prepared to compromise on the last one.  Obviously, it should do all
that while preserving all the nice features of Python -- surely an easy
task.


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


Re: Abandoning Python

2011-05-22 Thread John J Lee
Daniel Kluev  writes:

> On Sun, May 22, 2011 at 2:49 AM, John J Lee  wrote:
>> Here's my wishlist (not really in any order):
>
> How come pony is not listed there? Language cannot be better than
> python without pony!

Pony, absolutely.  I took that as read.


>>  * An even larger user base, contributing more and better free and
>>   commercial software.
[...]
> As there is rather heavy inertia in software development community,
> expecting some language to acquire "even larger user base" is
> hopeless.

I did say I was prepared to compromise on that one.  After all, when I
started using Python it was a lot smaller that it is now.  If a language
is good enough to tempt me away from Python, probably the same is true
for other people too -- as it was with Python a decade or so ago.


> Also, most of these complaints could be solved by using correct python
> dialect for particular task - RPython, Cython and so on.

Different topic.


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


Re: Using distutils 2.4 for python 2.3

2005-09-24 Thread John J. Lee
Noam Raphael <[EMAIL PROTECTED]> writes:

> Fredrik Lundh wrote:
> > 
> > you can enable new metadata fields in older versions by assigning to
> > the DistributionMetadata structure:
> > 
> > try:
> > from distutils.dist import DistributionMetadata
> > DistributionMetadata.package_data = None
> > except:
> > pass
> > 
> > setup(
> > ...
> > package_data=...
> > )
> > 
> >  
> 
> I tried this, but it made python2.4 behave like python2.3, and not 
> install the package_data files.
> 
> Did I do something wrong?

I'm *guessing* should have been something like (untested):

from distutils.dist import DistributionMetadata
try:
DistributionMetadata.classifiers
except AttributeError:
DistributionMetadata.classifiers = None

setup(
...
classifiers=...
)


John

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


Re: Help on regular expression match

2005-09-24 Thread John J. Lee
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:
[...]
> or, if you're going to parse HTML pages from many different sources, a
> real parser:
> 
> from HTMLParser import HTMLParser
> 
> class MyHTMLParser(HTMLParser):
> 
> def handle_starttag(self, tag, attrs):
> if tag == "a":
> for key, value in attrs:
> if key == "href":
> print value
> 
> p = MyHTMLParser()
> p.feed(text)
> p.close()
> 
> see:
> 
> http://docs.python.org/lib/module-HTMLParser.html
> http://docs.python.org/lib/htmlparser-example.html
> http://www.rexx.com/~dkuhlman/quixote_htmlscraping.html

It's worth noting that module HTMLParser is less tolerant of the bad
HTML you find in the real world than is module sgmllib, which has a
similar interface.  There are also third party libraries like
BeautifulSoup and mxTidy that you may find useful for parsing "HTML as
deployed" (ie. bad HTML, often).

Also, htmllib is an extension to sgmllib, and will do your link
parsing with even less effort:

import htmllib, formatter, urllib2
pp = htmllib.HTMLParser(formatter.NullFormatter())
pp.feed(urllib2.urlopen("http://python.org/";).read())
print pp.anchorlist


Module HTMLParser does have better support for XHTML, though.


John

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


Re: Help on regular expression match

2005-09-24 Thread John J. Lee
"Johnny Lee" <[EMAIL PROTECTED]> writes:

> Fredrik Lundh wrote:
[...]
> To the HTMLParser, there is another problem (take my code for example):
> 
> import urllib
> import formatter
> parser = htmllib.HTMLParser(formatter.NullFormatter())
> parser.feed(urllib.urlopen(baseUrl).read())
> parser.close()
> for url in parser.anchorlist:
>   if url[0:7] == "http://":
>   print url
> 
> when the baseUrl="http://www.nba.com";, there will raise an
> HTMLParseError because of a line of code " 2001, 2002 !>". I found that this line of code is inside 

Re: desktop module (was Re: Open PDF)

2005-09-24 Thread John J. Lee
"Paul Boddie" <[EMAIL PROTECTED]> writes:
[...]
> I've just uploaded a patch/suggestion/module (#1301512) to SourceForge
> which seeks to provide the equivalent of os.startfile for KDE and GNOME
> (as well as Windows) as part of a generic desktop module:
> 
> http://sourceforge.net/tracker/index.php?func=detail&aid=1301512&group_id=5470&atid=305470
> 
> Rather than submit yet another PEP and argue about insignificant
> details whilst the webbrowser module sits comfortably in the standard
> library, failing to address general file-opening issues directly and
> doing the wrong thing under various modern desktop environments, I
> advocate people submitting suggestions, criticism and amendments to the
> uploaded attachment until we have something like os.startfile for all
> major desktop environments.

Nice.  I've started the ball rolling with what I think is a KDE bug
fix (though I'm certain you know more about KDE than I do...), and
some comments on the tracker.


John

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


Re: Poor man's OCR: need performance improvement tips

2005-09-24 Thread John J. Lee
"qvx" <[EMAIL PROTECTED]> writes:
[...]
> 4. Process each line: compare pixels of each letter of alphabet with
> corresponding pixels in line of input picture. This consists of loops
> comparing pixel by pixel. This is my performance bottleneck.
> 
> I'm using PIL for initial image processing. But then I use plain Python
> loops for pixel matrix comparision. One nice optimization was to call
> PIL.Image.getdata() at the begining and then use data[y*w+x] instead of
> PIL.Image.getpixel(xy). I would like to compare each character raster
> with corresponding image pixels in a "single operation" and avoid
> (Python) loops.
[...]

I don't know what exactly "compare" means here, so no Numeric code,
but GIYF when it comes to the PIL<-->Numeric conversion (I imagine
numarray is almost identical here, though I've not used it in anger):

http://effbot.org/zone/pil-numpy.htm


Since you mention C++, scipy.weave may also be of interest to you.


John

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


Re: Using '__mul__' within a class

2005-09-25 Thread John J. Lee
"Gerard Flanagan" <[EMAIL PROTECTED]> writes:
[...]
> class FibonacciMatrix:
[...]
> def Copy( self ):
[...]

__copy__ would be a more standard name.  Then:

import copy
fm = FibonacciMatrix()
fm2 = copy.copy(fm)


I suppose you could also add:

__deepcopy__ = __copy__


in the body of the class definition.


John

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


Re: How to decompile an exe file compiled by py2exe?

2005-09-25 Thread John J. Lee
Leo Jay <[EMAIL PROTECTED]> writes:
[...]
> I opened the `hjparser.exe' file in UltraEdit(a hex editor), and found
> some partial statements and comments but not complete.
> 
> so, my problem is i'm sure that the source code is in `hjparser.exe'
> but i don't know how to decompile the executable file `hjparser.exe'
> into `hjparser.py',
[...]

Unfortunately, things we're sure of are not always true.  But you
could try asking on the relevant mailing list for py2exe, making sure
to say some nice things about Thomas Heller at the same time ;-)

Personally, if the source were valuable to me, I would stop using my
hard drive immediately and pay a company to try to recover it, perhaps
making a direct copy of my HDD first using a low level copy command
like dd, so I had my other data to continue working with (though of
course, I'd hope I would have a restorable backup if it were
valuable).


John

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


Re: Overloading __init__ & Function overloading

2005-09-30 Thread John J. Lee
Paul Rubin <"http://phr.cx"@NOSPAM.invalid> writes:

> "Iyer, Prasad C" <[EMAIL PROTECTED]> writes:
> > But I want to do something like this
> > 
> > class BaseClass:
> > def __init__(self):
> > # Some code over here
> > def __init__(self, a, b):
> > # Some code over here
> > def __init__(self, a, b, c):
> > # some code here
> 
> You can only use one __init__ method.  You'd have it count the args:
> 
> class BaseClass:
>   def __init__(self, *args):
>  if len(args) == 2:
> a, b = args
> # some code
>  elif len(args) == 3:
> a, b, c = args
> # more code

Weee... more readably, you can use:

 1. Named arguments (aka "keywords arguments" -- though a keyword arg
isn't a keyword, of course...)

 2. Factory (class methods) (I'm using those parentheses around "class
methods" for precedence, not annotation -- unlike here ;-)

 3. Plain old factory methods

 4. Factory "functions" implemented as classes with a __call__ method

 5. Factory classes with named factory methods (perhaps even class
methods)

 6. Plain old factory functions


It's all terribly restrictive, as you can see 

(Yes, I know the OP used the same name to call all the constructors in
his examples -- but that's just an expectation carried over from other
languages)


John

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


Re: 'ascii' codec can't encode character u'\u2013'

2005-09-30 Thread John J. Lee
deelan <[EMAIL PROTECTED]> writes:
[...]
> query = "UPDATE blogs_news SET text = %s WHERE id=%s"
> cursor.execute(query, (text_extrated, id))
> 
> so mysqldb will take care to quote text_extrated automatically. this
> may not not your problem, but it's considered "good style" when dealing
> with dbs.
[...]

More than just good style: it prevents SQL injection attacks that
could otherwise allow people to do bad things to your databases.


John

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


Re: Where to find python c-sources

2005-09-30 Thread John J. Lee
"Tor Erik Sønvisen" <[EMAIL PROTECTED]> writes:

> "Erik Max Francis" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> > Tor Erik S�nvisen wrote:
> >
> >> I need to browse the socket-module source-code. I believe it's contained 
> >> in the file socketmodule.c, but I can't locate this file... Where should 
> >> I look?
> >
> > The source tarball, available on python.org.  Are people really too lazy 
> > to do elementary research on Google?
> >
> > -- 
> > Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
> > San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
> >   The people are to be taken in very small doses.
> >   -- Ralph Waldo Emerson
> 
> Thanks for the answers... And yes, I have searched google! 

How odd -- the most useful link (the viewcvs page for this source
file) is the very first link for me when I search for socketmodule.c

Does google vary in its results across the globe?


John

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

Re: A Moronicity of Guido van Rossum

2005-09-30 Thread John J. Lee
Steve Holden <[EMAIL PROTECTED]> writes:
> I'm responding off-list

No you're not!

Sorry if I missed some subtle joke here...


John

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


Re: Will python never intend to support private, protected and public?

2005-09-30 Thread John J. Lee
Steve Holden <[EMAIL PROTECTED]> writes:
> Rocco Moretti wrote:
[...]
> > Right, but like doors that automatically lock when they close, items 
> > which are there to protect you can be a nusaince, especially when you've 
> > left your keys on the dining room table.
> 
> That would make a good Onion (www.TheOnion.com) headline: "Users 
> Discover Computer Security Conflicts with Desire for Convenience"

:-) The Onion, yay.

Area Man Forgets Work Password, Will Employ Post-It Notes in Future


John

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


Re: PDF Viewer

2005-09-30 Thread John J. Lee
Pepe Pena <[EMAIL PROTECTED]> writes:

> I am new to programming and need some guidance on the development of
> the following application.  The proposed application will display
> two pdf documents simultaneously to be viewed and simple navigation
> will be facilitated (i.e. turning pages).
> 
> Furthermore, the pdf documents must be linked to one another.  If a
> particular page is viewed in one document, the second document will
> display a specific page.
> 
> Can anyone please provide any assistance or comments on how I should
> proceed to create the mentioned application using Python within the
> windows environment, thank you.

I believe Acrobat (NOT Acrobat Reader) supports a COM interface you
could use from Python (with ctypes, maybe even with pywin32 -- not
sure if it supports IDispatch).

Alternatively, if you feel rather adventurous, try compiling KPDF on
Windows with the free Qt3 port(s?) or Qt4, if that's arrived yet.  If
you're successful there, you still need to figure out writing KPart
plugins in Python, which certainly used to be tricky, but maybe that's
a solved problem by now...


Alternatively, if this was just an idea for a toy project rather than
work and you don't have Acrobat and/or lots of spare time, my advice
is to pick a different problem, and learn Ctrl-Shift-L and
Ctrl-Shift-K in Acrobat Reader instead, which have served me well in
my work at ReportLab (which does involve some work with PDF files, as
you might expect!-).  Even more embarrassingly high-tech , and
even more useful for comparing two PDFs IME: holding two superimposed
printouts up to the light from a window (yes, we have a tool that lets
us do this, but the print-it-out-and-hold-it-up method seems to have
won the popularity contest, maybe thanks to the excellent "slide the
pages around" UI for comparing parts of a page that may have moved
from one file to the other...).


John

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


Re: PEP 308 accepted - new conditional expressions

2005-10-01 Thread John J. Lee
"Michele Simionato" <[EMAIL PROTECTED]> writes:
[...]
> Guido could have decided two years ago, sparing us the PEP 308 ordalia.
> So, I am happy that at the end we will have a conditional operator, but
> I am not happy of how the process worked out. It was just an enormous
> waste of resources that could have been employed much better :-(

Seems that's what Guido thinks too:


http://mail.python.org/pipermail/python-dev/2005-September/056561.html

| If there's one thing I've learned from the PEP 308 vote, it is that
| votes for language don't work. I prefer some discussion on Python-dev
| after which I pick one.

I think he said at the time that it was an experiment.


John

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


Re: Where to find python c-sources

2005-10-03 Thread John J. Lee
[Tor Erik S�nvisen]
> socketmodule.c, but I can't locate this file... Where should I look?

[John, finding 'socketmodule.c' responds well to "I'm Feeling Lucky"]
> Does google vary in its results across the globe?

[Michael]
> The search terms might be obvious to you, but it simply means your google-fu
> is strong, and the strong should help the weak. (or not attack them at
> least...)

You believe that Tor is dumb enough not to think of searching for
"socketmodule.c" when, um, searching for socketmodule.c?


John

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

Re: Where to find python c-sources

2005-10-07 Thread John J. Lee
Terry Hancock <[EMAIL PROTECTED]> writes:

> On Friday 30 September 2005 04:37 pm, John J. Lee wrote:
> > "Tor Erik Sønvisen" <[EMAIL PROTECTED]> writes:
> > > Thanks for the answers... And yes, I have searched google! 
> > 
> > How odd -- the most useful link (the viewcvs page for this source
> > file) is the very first link for me when I search for socketmodule.c
> > 
> > Does google vary in its results across the globe?
> 
> Of course you meant to be snippy and sarcastic,

I really was wondering if such results varied, because it seemed hard
to believe somebody wouldn't do a similar search.  And the idea that
he might have been too lazy didn't enter my head 


> but you've actually
> exemplified the reason why so many people don't find such a thing
> with Google.  Like all search engines, you have to know the right
> keyword -- to a fair degree of precision -- in order to find what
> you're looking for.

Oh, come off it.  It seems hard to imagine that trying socketmodule.c
when looking for socketmodule.c requires some expert search-fu that
I'm supposed to posess.


> This is very unlike asking a question of a human being.  *People*
> respond much better to general subject headings such as "socket
> module" or "python sources" rather than looking for something
> ultra-specific like a particular file name.

He wasn't looking for general information.  He told us he was looking
for socketmodule.c, for Pete's sake!  And "python sources" *does*
takes you to the Python sources.


> Researchers take this
> training with them when they approach Google and treat it like
> a magic librarian -- they give it the same thing they would come
> to a human librarian with.

You conjure up in my mind a nice picture of an be-cardiganed gentleman
in an oak-panelled corner of the British Library, in his early
seventies complete with pipe, dust, and technophobia.  Seems an
unlikely image for somebody with an email address containing the
string "@stud.cs." and stating their interest in reading networking
code written in C 

Still, going back to researchers-with-pipes ("researcher" meaning
"collator of information" rather than "creator/discoverer of original
ideas"), I perhaps naively assume that such Google-phobic researchers
must nowadays do other work for a living.  Who'd want to employ a
researcher who can't efficiently use search engines and other
databases these days?  But as I say, I could well be naive here... I
recall my not-astonishment at trying to find a book in a local (but
not small) public library, and finding that the librarian was unable
to do so, despite their apparent enthusiasm at my request, and initial
proud promises that the databases they pay for would find it even if
none of the regional libraries had a copy (due in this case I suspect,
and hasten to add, to the databases simply lacking the relevant
records, rather than incompetence on the part of the librarian).  I
walked round the corner and found it on both Amazon and Google in
around a few seconds each time.  I had been led to believe books were
something of a library speciality...

In fact, rambling a little further, I can honestly say (in the
certainty and enjoyment of offending any librarians reading <0.75
wink>) that I've never knowingly extracted any useful information from
a librarian, who in legend are supposed to have such old-style
researcher-fu as you refer to.  This applies even to pre-Google days,
despite having spent a fair amount of time in libraries, and asking a
fair range of questions over a period of years: some very specific,
some quite general and wooly; some particular, some about general
search strategies and techniques.  Perhaps that
just reflects my interests or level of competence in one way or
another.

[...]
> Seriously, though, for anybody new to using search engines, it
> is a very useful rule of thumb -- search for a specific word
> likely to appear on the page you are looking for, and not
> elsewhere.
[...]

It's quite true that has to be learned.


John

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


Re: how do you pronounce wxpython

2005-10-08 Thread John J. Lee
"Alex" <[EMAIL PROTECTED]> writes:

> My native language is not English so I just wonder how you pronounce
> wxPython.
> 
> vi-ex python
> double-you-ex python
> wax-python
> 
> or something else

I'm sure you'll get five different answers.

Personally, I say the 'wx' bit as 'wooks' (like 'books' in Southern
England pronunciation, ie. short 'oo').

Qt --> 'cute'

Tk --> 'tick'

Gtk --> I can't write this one down...


John

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


Re: Well written open source Python apps

2005-10-13 Thread John J. Lee
"Ben" <[EMAIL PROTECTED]> writes:

> Could anyone suggest an open source project that has particularly well
> written Python?  I am especially looking for code that people would
> describe as "very Python-ic".  (Not trying to start any kind of war -
> just wanted some good examples of a well written Python app to read.)
[...]

At the time I looked at it I thought this was nice, though that was
some time ago (it was still 'sketch' then) so I wonder if I'd still
have the same opinion if I looked now (due to me changing my view of
"good code", not the skencil source code changing!):

http://www.nongnu.org/skencil/


John

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


Re: A problem while using urllib

2005-10-13 Thread John J. Lee
Steve Holden <[EMAIL PROTECTED]> writes:
[...]
>File "/usr/lib/python2.4/urllib2.py", line 996, in do_open
>  raise URLError(err)
> urllib2.URLError: 
> 
> Looking at that part of the course of urrllib2 we see:
> 
>  headers["Connection"] = "close"
>  try:
>  h.request(req.get_method(), req.get_selector(), req.data, 
> headers)
>  r = h.getresponse()
>  except socket.error, err: # XXX what error?
>  raise URLError(err)
> 
> So my conclusion is that there's something in the Cygwin socket module 
> that causes problems not seen under other platforms.
> 
> I couldn't find any obviously-related error in the Python bug tracker, 
> and I have copied this message to the Cygwin list in case someone there 
> knows what the problem is.
[...]

I don't *think* this is related, but just in case:

http://python.org/sf/1208304


John

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


Re: Yes, this is a python question, and a serious one at that (moving to Win XP)

2005-10-13 Thread John J. Lee
Kenneth McDonald <[EMAIL PROTECTED]> writes:
[...]
> absolutely preventing me from making the switch. Number one is the  
> lack of a decent command line and command-line environment, and I'm  
> wondering (hoping) if perhaps someone has written a "Python shell"-- 
> something that will look like a regular shell, let users type in  
> commands, maybe have some of the nice features of bash etc. like tab  
> completion, etc, and will then execute an underlying python script  
> when the command is entered. I'm not thinking of IDLE, but something  
> that is really aimed more at being a system terminal, not a Python- 
> specific terminal.
[...]

cmd.exe can be made bearable.  I just got a new machine, so I'll have
to do this myself in the next few days...

0. Make a shortcut to cmd.exe, stick it somewhere get-at-able,
   eg. quick launch toolbar

1. Somewhere under the menu reachable from the little icon in the
   top-left corner you can set the default directory when cmd is
   launched, plus there's some way to set up env vars (eg. PYTHONPATH)

2. Fiddle with buffers to make them sensible sizes (that menu again).

3. Adjust colours to taste (menu again).

4. There's a registry key for tab completion somewhere...

5. Make sure .py is associated with the Python you want


Also see IPython, which does do shell-ish things as well as python-ish
things.



John

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


Re: UI toolkits for Python

2005-10-13 Thread John J. Lee
Kenneth McDonald <[EMAIL PROTECTED]> writes:
[...]
> both doing fairly well in general. I'm already aware of the licensing  
> issues surrounding qt (fwiw, I think their license fee for commercial  
> use is eminently reasonable), so aside from that, I was wondering if  
[...]

Qt 4 is available as GPL even on Windows.


John

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


Re: urllib2 problem

2005-10-28 Thread John J. Lee
"Jeremy Martin" <[EMAIL PROTECTED]> writes:
[...]
> website. I originally just used urllib.urlopen and everything worked 
> fine on my Windows PC at work. I tried the same script at home on my 
> Fedora COre 3 box using python 2.4, and whenever I try to connect to 
> the site I get the (110, Connection Timed Out) Error.  
> 
> At first I thought my firewall was causing problems with the script but 
> I noticed an odd patten. If the web site asked to accept cookies (like 
> the site I need) the script times out), if I point it to a site that 
> doesnt it works fine. Ive tried several attempts at using urllib2 and 
> the HTTPCookieProccessor and I still have no luck.

If this is just a single server you're talking to, this doesn't
necessarily implicate HTTPCookieProccessor -- it may be that that
server does different stuff depending on whether you return cookies or
not (not much point in having the cookies if not ;-), so the timeout
might be caused by all kinds of unrelated problems.


> Can anyone give me 
> any advice or pointers on what may be the problem here? I apologize if 
> this is kind of a rookie question but Ive been searching for about a 
> week with no luck. 

I'm the author of cookielib and HTTPCookieProccessor.  It's very hard
to guess what's wrong without being able to reproduce the problem.  If
you can send me your script ([EMAIL PROTECTED]), I may be able to help.

One point, though.  This doesn't seem to be the problem you are
having, but it's a good thing for this info to be more easily
Google-able for others: Are you using threads?  cookielib is
thread-broken, I suspect (poorly-tested thread support code was left
in when I contributed the module, which was a mistake: I'm almost
certain it's incorrect, and intend to request the thread
synchronisation code be removed in 2.5).  I suspect that could cause
deadlock if you are using threads.  It's probably possible to work
around this, but I reccommend just not using threads (and not only
because of my buggy synchronisation code!).  But as I say, I don't
think this is your problem.


John

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


Re: Scanning a file

2005-10-30 Thread John J. Lee
[EMAIL PROTECTED] (Alex Martelli) writes:
[...]
> If you're trying to test your code to ensure it explicitly closes all
> files, you could (from within your tests) rebind built-ins 'file' and
> 'open' to be a class wrapping the real thing, and adding a flag to
> remember if the file is open; at __del__ time it would warn if the file
> had not been explicitly closed.  E.g. (untested code):
[...]

In general __del__ methods interfere with garbage collection, don't
they?  I guess in the case of file objects this is unlikely to be
problematic (because unlikely to be any reference cycles), but I
thought it might be worth warning people that in general this
debugging strategy might get rather confusing since the __del__ could
actually change the operation of the program by preventing garbage
collection of the objects whose lifetime you're trying to
investigate...


John

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


Re: Using Python to add thumbnails to Explorer

2005-10-30 Thread John J. Lee
"Roger Upole" <[EMAIL PROTECTED]> writes:
> "c d saunter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
[...]
> > Turns out I need to use a .dll shell extension as per
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
> > shellcc/platform/shell/programmersguide/shell_int/shell_int_extending/
> > extensionhandlers/shell_ext.asp
> >
> > Not so simple, and not (directly) a job for Python.
> 
> Sorry, I didn't realize you meant per-file.
> However, Pythoncom supports both the interfaces
> (IExtractIcon and IPersistFile) specified on the page
> you referenced, so you ought to be able to implement
> an icon handler with the Pywin32 extensions.

Or, if not, then you can do it with module ctypes.

http://starship.python.net/crew/theller/ctypes/


There's an O'Reilly book called something like "win32 shell
programming" that covers this stuff.


John

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


Re: Scanning a file

2005-10-31 Thread John J. Lee
Paul Watson <[EMAIL PROTECTED]> writes:
[...]
> How "ill" will things be when large bodies of code cannot run 
> successfully on a future version of Python or a non-CPython 
> implementation which does not close files.  Might as well put file 
> closing on exit into the specification.
[...]

There are many, many ways of making a large body of code "ill".

Closing off this particular one would make it harder to get benefit of
non-C implementations of Python, so it has been judged "not worth it".
I think I agree with that judgement.


John

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


Re: Python's website does a great disservice to the language

2005-11-01 Thread John J. Lee
Robert Boyd <[EMAIL PROTECTED]> writes:
[...]
> rounded corners. The Python site is clean and to-the-point. I guess I could
> admin that the various Python logos look dated, but that's about it. Oh, and
[...]

I love the logos!

python.org looks simple to me, not amateurish.  But that just goes to
show that I think differently from your PHB, and in my book the
details of the visual design should be aimed at attracting more people
to the language as well as being easy to use, so I'm happy there's a
redesign.


John

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


Re: urllib2 Opener and Proxy/Authentication issues

2005-11-08 Thread John J. Lee
"Ray Slakinski" <[EMAIL PROTECTED]> writes:
[...]
> ps: settings.GlobalProxySetting is defined as a string, for example:
> 
> non-authenticated proxy: "http://192.168.1.1:3128";
> authenticated proxy: "http://user:[EMAIL PROTECTED]:3128"
[...]

IIRC urllib2 is slightly broken wrt proxy auth and the @ syntax.  I
think I even explained here or on wwwsearch-general mailing list what
needed fixing -- IIRC again, it's very simple to fix but of course
needs testing, a unit test case adding, posting a patch on the SF
tracker.  Go for it!


John

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


Re: web interface

2005-11-08 Thread John J. Lee
Jorge Godoy <[EMAIL PROTECTED]> writes:

> "Ajar" <[EMAIL PROTECTED]> writes:
> 
> > I have a stand alone application which does some scientific
> > computations. I want to provide a web interface for this app. The app
> > is computationally intensive and may take long time for running. Can
> > someone suggest me a starting point for me? (like pointers to the
> > issues involved in this, or even better any of the existing tools for
> > doing this...)
> 
> For the long running task you might get some idea from cvsmonitor (Perl
> code).  It has a long running task that is updating some repositories and
> giving feedback from time to time to the user.
> 
> One thing is: detach all what is possible from user interface and give
> feedback from time to time to avoid browser timeout and the user thinking the
> app hanged.

If you're using CGI:

You usually have to start the long job by asking a separate server
process to do it -- eg. using XML RPC.  Otherwise, you'll get browser
timeouts (and maybe web server timeouts too).  Your little server
process can then do e.g. os.fork (unix) or subprocess.CreateProcess
(win32) (subprocess is only available in Python 2.4) to actually start
your long job.  Use a Refresh header (use a META HTML element, or set
up your web server appropriately) in your "waiting for job to finish"
web page (or reload the page from JS code) to poll the server to see
if the job has completed.


John

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


Re: Is mod_python 3.1 good for commercial blogging/CMS?

2005-11-08 Thread John J. Lee
"Ben Sizer" <[EMAIL PROTECTED]> writes:
[...]
> It as not easy to work with the CGI-style code in a WYSIWYG web editor
> as it is to edit a template, which is probably the main reason for
> their use. Also, coding everything with req.write() means that each
[...]

You seem to believe CGI is incompatible with templating.  Why?  The
two are entirely independent of each other.


John

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


Re: IE Temporary Internet Files & Python

2005-11-13 Thread John J. Lee
"James Hu" <[EMAIL PROTECTED]> writes:

> Maybe the reason is ..\Content.IE5\index.dat can't be deleted! 
[...]

IIRC, it can/could be from linux (with Win NT 4 installed on a VFAT
partition), so I guess it is/was a normal file to that extent.


John

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


Re: Confusion about __call__ and attribute lookup

2005-11-13 Thread John J. Lee
Kent Johnson <[EMAIL PROTECTED]> writes:

> Leif K-Brooks wrote:
> > New-style classes look up special methods on the class, not on the instance:
> 
> For my future reference, is this documented somewhere in the standard docs?

Maybe somewhere in here :-(

http://www.python.org/doc/newstyle.html


John

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


Re: Web-based client code execution

2005-11-20 Thread John J. Lee
Paul Watson <[EMAIL PROTECTED]> writes:

> What are the options?
> 
> The user to hits a web page, downloads code (Python I hope), execute it, 
> and be able to return the results.  It needs to be able to go through 
> standard HTTP so that it could be run from behind a corporate firewall 
> without any other ports being opened.
> 
> Am I stuck doing an ActiveX control?
[...]

If you just need to talk on port 80, just go ahead and do that (module
socket, module httplib, module urllib2, urllib.getproxies, etc), and
write a normal desktop application.


If it must run in a browser, here is some food for thought:


Compile Python to JavaScript -- very cool

http://www.aminus.org/blogs/index.php/phunt/2005/10/06/subway_s_new_ajax_framework

http://www.aminus.org/blogs/index.php/phunt/2005/10/09/psst_crackajax_is_in_svn


Plain old AJAX with Python on server side

https://sourceforge.net/projects/json-py/

http://www.google.co.uk/search?q=ajax+python&btnG=Search (um, ignore the 1st 
result)


Write Java applets in Python

http://www.jython.org/


Flash 'local storage'

http://www.macromedia.com/support/documentation/en/flashplayer/help/help02.html

Sort-of AJAX-for-Flash stuff

http://www.cs.unc.edu/~parente/tech/tr04.shtml
http://www.simonf.com/flap/

Flash itself (boo;-)

http://www.macromedia.com/


XUL and PyXPCOM (Firefox only)

http://www.xulplanet.com/

http://trac.nunatak.com.au/projects/nufox


Firefox future capabilities in this direction (probably most of this
is relevant)

http://www.mozilla.org/roadmap/gecko-1.9-roadmap.html

http://weblogs.mozillazine.org/roadmap/archives/2005_09.html


John

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


Re: Ajax for the Developers

2005-11-20 Thread John J. Lee
"Sabin.A.K, Bangalore" <[EMAIL PROTECTED]> writes:
[...]
> 1. Changing state with links (GET requests)
> 2.Asynchronously performing batch operations

I don't understand those two.


> 3.Breaking the back button
[...]

http://en.wikipedia.org/wiki/AJAX


Also of interest:

http://www.mozillazine.org/talkback.html?article=7162


John

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


mmm-mode, python-mode and doctest-mode?

2005-11-30 Thread John J Lee
Is it possible to get doctest-mode to work with mmm-mode and python-mode 
nicely so that docstrings containing doctests are editable in 
doctest-mode?

In my utter e-lisp ignorance, I tried this:

(require 'mmm-auto)
(setq mmm-global-mode 'maybe)
(mmm-add-classes
  '(
(doctest
 :submode doctest-mode
 :front "\"\"\""
 :back "\"\"\"")))
(mmm-add-mode-ext-class nil "\\.py$" 'doctest)

That has the following problems:

  - Fails to set the background colour of the doctest-mode regions to the 
default mmm-mode gray (as documented by mmm-mode - and observed for 
another mmm class I have).  Maybe an interaction with python-mode?

  - Confuses python-mode: the face of docstrings sometimes fluctuates from 
second to second between the string face and the face of ordinary text 
(I assume the former face is python-mode's string face and the latter face 
is the doctest-mode English-text face)!


Any tips appreciated!


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


Re: mmm-mode, python-mode and doctest-mode?

2005-12-01 Thread John J. Lee
bruno at modulix <[EMAIL PROTECTED]> writes:

> John J Lee wrote:
> > Is it possible to get doctest-mode to work with mmm-mode and python-mode
> > nicely so that docstrings containing doctests are editable in doctest-mode?
> 
> I don't know.
> 
> (snip)
> > 
> > Any tips appreciated!
> > 
> 
> Seems like comp.emacs could be a good place for this question

I've only posted to gnu.emacs.help previously (the message you reply
to was cross-posted there), since the name seemed to suggest
friendliness to people like me who use emacs a lot but are clueless
with elisp :-).  But thinking again I guess comp.emacs is just the
general emacs group, while gnu.emacs.help is the GNU-specific one?


John

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


Re: Eclipse best/good or bad IDE for Python?

2005-12-04 Thread John J. Lee
Aaron Bingham <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED] wrote:
[...ex-emacs user explains switch to Eclipse...]
> The killer PyDev feature for me is pylint integration.  Being informed 
> immediately when you mistype a variable name is a big timesaver.  Also 

I now find it difficult to mis-type variable names in Emacs, since I
have F4 bound to dabbrev-expand.  I also do standard things like using
query-replace when renaming.  Actually, something like dabbrev-expand
is perhaps the one thing I would find indispensible switching to any
other editor -- I wonder if Eclipse/PyDev has it?

(dabbrev-expand searches backwards in the current buffer to find
'words' that are completions of the word you're typing immediately
before the cursor position (then back and forth in all other buffers
if search in the current buffer failed...), until it finds a
completion; then you can repeat the command to cycle through all other
possible completions.)


> nice is the refactoring support (although this it is possible to 
> integrate BicycleRepairMan! with Emacs, I found it easier to use in 
> Eclipse).
[...]

Refactoring and the general 'semantic slant' certainly seems the
interesting bit about Eclipse (that and the fact that Emacs is a bit
old and hairy, and Eclipse is growing a big user base like Emacs).

Not entirely sure Lisp->Java is progress, though.


John

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


Re: Eclipse best/good or bad IDE for Python?

2005-12-04 Thread John J. Lee
Fabio Zadrozny <[EMAIL PROTECTED]> writes:
[...]
> I must also warn you that I'm its current maintainer, and it is *my* 
> favorite IDE :-)
[...]
> But in the end, as I said, it is a subjective matter, so, you'll have to 
> decide it for yourself.

Hey, Fabio, can this be true:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=15820

|--- Comment #4 From Chris McLaren  2003-01-08 10:43  [reply] ---
|
|this is not a key bindings issue anymore - key bindings can be fully 
|customized but vi emulation requires special support from the editor. closing 
|this pr - best step is to try and lobby vi emulation to the draft proposal.



They're kidding, right???  Can it be possible there's no free vi mode
for Eclipse??  If something so basic is missing from the core stuff,
gives me little hope emacs will be displaced as the Big Beast of
editors anytime soon...

The basis in Java makes me worry a tiny bit too.  First, Lisp plus the
'programmers scratch their own itch' model seems to have been very
successful in letting people Get the Job Done in Emacs.  More
important, I fear licensing issues will keep away Emacs hackers who
might otherwise switch and make the platform more usable for other
Emacs refugees.



John

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


Re: HTML parsing/scraping & python

2005-12-04 Thread John J. Lee
Sanjay Arora <[EMAIL PROTECTED]> writes:

> We are looking to select the language & toolset more suitable for a
> project that requires getting data from several web-sites in real-
> timehtml parsing/scraping. It would require full emulation of the
> browser, including handling cookies, automated logins & following
> multiple web-link paths. Multiple threading would be a plus but not
> requirement.
[...]

What's the application?


John

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


Re: Eclipse best/good or bad IDE for Python?

2005-12-05 Thread John J Lee
On Mon, 5 Dec 2005, Fabio Zadrozny wrote:
[...]
> Being java, does not worry me that much... there are already many vms aside 
> from suns (including gcj), and I think that if you do not want to program in 
> java, adding scripting layers for jython, jruby, etc should be fairly easy 
> (given that someone has the time to do it).
[...]

Sure, but it was the fact that the *core* is in Java I was thinking about. 
I wonder how 'closed' it is.  Probably I'm just creating FUD for myself. 
I heard Phillip Eby say good things about its design, which can't be a bad 
sign.


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


Re: Bitching about the documentation...

2005-12-05 Thread John J. Lee
"BartlebyScrivener" <[EMAIL PROTECTED]> writes:

> Thank you. I shall try that the next time I see something in the
> documentation for beginners. Generally the Python docs are quite good,
> in my opinion. I was merely taking issue with the poster who suggested
> that Python novices and nonprogrammers should complain less and
> contribute more. It's not immediately apparent how to contribute. And
> if you go looking via the main page you end up in a LaTex tutorial.

Just by-the-way: Actually the Python docs use a really restricted
range of LaTeX commands, so you really need know *nothing* about LaTeX
even if you *do* go to the trouble of supplying LaTeX markup.  Just
follow what you see in the files in eg. python/trunk/Doc/lib/lib*.tex
(if you scan through the list of markup available in the 'Documenting
Python' manual, even better), and be sure to warn of the fact that
you're a LaTeX newbie when uploading patches so committers know what
they're getting.

(My advice is don't try to *compile* the docs unless you're ready for
some pain, though -- last time I looked it was quite unpleasant to get
it working.)

Also, note that Python is now in SVN, no longer in CVS:

http://svn.python.org/view/python/trunk/Doc/lib/
http://svn.python.org/projects/python/trunk/Doc/lib/
http://www.python.org/dev/devfaq.html#subversion-svn

http://docs.python.org/doc/doc.html


John

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


Re: PyQT installation

2005-01-01 Thread John J. Lee
[EMAIL PROTECTED] (Alex Martelli) writes:
[...]
> Basically: if you want it on Windows for free, forget Qt

Correct.


> (I hear the
> cygwin people are trying to make a GPL Qt available for Win+cyg+XFree,
> but I suspect trolltech ain't happy about that -- anyway, I don't think
> it would be "native", X11 being still required).
[...]

Not correct.  It's driven by KDE, and it's more ambitious than that:

http://kde-cygwin.sourceforge.net/qt3-win32/roadmap.php


IIRC, people have already run some KDE apps under Windows (though
still needing X, so far).

I wonder how TrollTech will react as (and if) it progresses.


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


Re: PyQT installation

2005-01-01 Thread John J Lee
On Sat, 1 Jan 2005, Ken Godee wrote:
[...]
> I believe the book "C++ GUI programming Qt3" comes
> with a windows Qt gpl 3.x version. Just have to buy
> the book. No PyQt version to match thou.

"GPL only if you buy the book" makes no sense.  Either it's GPL or it 
isn't.  (It isn't, in fact.)

[...]
> > IIRC, people have already run some KDE apps under Windows (though
> > still needing X, so far).
> > 
> > I wonder how TrollTech will react as (and if) it progresses.
> > 
> 
> I don't think your giving TrollTech any credit here, yes they have
> a business model and need to make money, but not everybody is
> Microsoft. They are fully aware and supportive of the project
> and I remember reading not to long ago they struck an aggrement
> with the project that if anything ever happened to TrollTech they
> would release Qt to project under gpl, or something like that.

I'd forgotten about that agreement (again, driven by KDE).  Reassuring,
assuming the legalese corresponds to what one assumes is the spirit of it,
and that it will hold water if/when tested in the courts.

I am surprised if they support the effort to make a GPL native MS Windows
version of Qt.  They wouldn't have to be evil monopolists to be concerned
about this development, IMHO.


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


Re: using HTTP Digest auth with arbitrary HTTP methods?

2005-01-03 Thread John J. Lee
John Reese <[EMAIL PROTECTED]> writes:

> In comp.lang.python, [I] wrote:
[...]
> I instead copied it (to urllib3.py) and made the following changes:
>   a. in AbstractDigestAuthHandler.get_authorization, call
>  req.get_method() instead of req.has_data() and 'POST' or 'GET'
>  (python has a ternary operator, who knew)

(Re ternary operator: Everybody who read this list at certain times in
the past is painfully aware of that fact, and of precisely why it's
not quite true, and of all the syntax alternatives for real ternary
conditionals that will never be part of Python ;-)


>   b. in AbstractHTTPHandler.do_open, call req.get_method instead of the 
>  hard-coded if-logic which is the same as that in req.get_method
> 
> Both of these seem like bugs in urllib2.

Yup, bugs both.


> Then I overrode urllib2.Request and made it possibly to set the method,
> and then passed an instance of my custom Request class (the one that
> shouldn't have to exist, since Request should allow method to be set
> explicitly) to OpenerDirector.open().
> 
> I'd like to see these changes make it into the standard library -- after
> being vetted by whoever's in charge of urllib2.  Anybody know who I
> should talk to?

Nobody is really in charge: just go ahead and submit a patch.  Drop me
an email when you do, and I'll try to review it.  The only reason
urllib2 doesn't already do arbitrary HTTP methods is that nobody has
spent the time to think carefully if a .set_method() really is the
right way to do it, then followed through with the work needed to get
a patch applied.

As always, a precondition for change is that somebody thinks something
through carefully, writes tests, documentation, patch and submits all
three to the SF patch tracker with a brief explanation like the one
you give above.

BTW, Greg Stein started work on adding the stuff you need at the
httplib level (as module httpx).  He seems too busy to finish it, but
see modules httpx and davlib (one or both are in the Python CVS
sandbox).  He thinks httplib is a better place for DAV than urllib2,
and he should know.  But go ahead and fix urllib2 anyway... :-)


John

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


Re: HTTP GET request with basic authorization?

2005-01-03 Thread John J. Lee
Jonas Galvez <[EMAIL PROTECTED]> writes:

> Christopher J.  wrote:
> > I tried this, but it didn't work:
> > conn.request("GET", "/somepage.html", None,
> > {"AUTHORIZATION": "Basic username:password"})
[...]
> import re, base64, urllib2
>  
> userpass = ('user', 'pass')
> url = 'http://somewhere'
> 
> request = urllib2.Request(url)
> authstring = base64.encodestring('%s:%s' % userpass)
> authstring = authstring.replace('\n', '')
> request.add_header("Authorization", "Basic %s" % authstring)
>  
> content = urllib2.urlopen(request).read()

There are handlers in urllib2 to do this for you, you shouldn't need
to do it by hand.  I rarely do, so I won't risk an example...


John

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


Re: What can I do with Python ??

2005-01-03 Thread John J. Lee
Lee Harr <[EMAIL PROTECTED]> writes:
[...]
> I think it looks pretty good. The only problem I see is section 5
> where it says:
> 
> 5. Did we miss your concern?
> 
>  Please add a comment to this page.
> 
> 
> but the page is immutable.


Hopefully one of the site maintainers will read this and demonstrate
that it's actually readonly rather than immutable, then make it
appendable ;-)



John

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


Re: rotor replacement

2005-01-22 Thread John J. Lee
Paul Rubin <"http://phr.cx"@NOSPAM.invalid> writes:
[...]
> Building larger ones seems to
> have complexity exponential in the number of bits, which is not too
[...]

Why?


> It's not even known in theory whether quantum computing is
> possible on a significant scale.

Discuss. 

(I don't mean I'm requesting a discussion -- it just reads like a
physics / philosophy exam essay question, which traditionally end with
that word :)


John

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


Re: rotor replacement

2005-01-25 Thread John J. Lee
Paul Rubin <http://[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] (John J. Lee) writes:
> > > Building larger ones seems to
> > > have complexity exponential in the number of bits, which is not too
> > 
> > Why?
> 
> The way I understand it, that 7-qubit computer was based on embedding
> the qubits on atoms in a large molecule, then running the computation

Oh, you mean that particular kind, OK.  Doesn't apply to QC in
general.


> > > It's not even known in theory whether quantum computing is
> > > possible on a significant scale.
> > 
> > Discuss. 
> 
> The problem is maintaining enough coherence through the whole
> calculation that the results aren't turned into garbage.  In any
> physically realizeable experiment, a certain amount of decoherence
> will creep in at every step.  So you need to add additional qubits for
> error correction, but then those qubits complicate the calculation and
> add more decoherence, so you need even more error correcting qubits.

Yes, that's much more interesting, dunno what the current state of
play is.

[...]
> I'm not any kind of expert in this stuff but have had some
> conversations with people who are into it, and the above is what they
> told me, as of a few years ago.  I probably have it all somewhat garbled.

Me too :-)


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


Re: delay and force in Python

2005-01-25 Thread John J. Lee
Nick Coghlan <[EMAIL PROTECTED]> writes:
[...]
> (xrange can't handle Python longs, unfortunately, so we *are*
> constrained by sys.maxint. However, since my machine only has half a
> gig of RAM, the above is still a damn sight quicker than the
> equivalent list comprehension would be!)
[...]

Other way 'round: if you had even more RAM, the listcomp would be even
slower for this job!


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


Re: cookielib and urllib2: thread-safe?

2005-01-29 Thread John J. Lee
Alex Hunsley <[EMAIL PROTECTED]> writes:

> I'm writing a test script in python for pulling web pages from a web
> server using urllib2 and cookielib. Since the main thing I am testing
> is what happens when concurrent requests are made to the web server, I
> need to make several requests concurrently, which I'll do from
> different threads in my python script. So the important question is:
> are cookielib and urllib2 thread safe? Are there any precautions that
> apply to using these libs in a multi-threaded context?

urllib2: For HTTP, yes, AFAIK.  For other protocols, eg. FTP, perhaps
not.

cookielib: No.  It's currently thread-broken, simply because I've
never had reason to do threaded stuff with it.  There is thread
synchronization code in there, but I have little doubt that it's
broken, because it's untested (I should have removed the
synchronization code entirely, in fact, since nobody volunteered to
test & fix before release: unfortunately the first beta caught me by
surprise...).

I won't be making it threadsafe, so don't wait for me to do it.  I'm
happy to help others do so.  Nothing especially hard for somebody with
plenty of thread experience to do, AFAIK.

I had thought part of a patch had gone in which stated this
thread-unsafety very prominently in the cookielib module docs, but it
seems that never happened, or at least not in time for 2.4.0 -- eek!


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


RFC 2965 cookies, cookielib, and mailman.

2005-01-30 Thread John J Lee
Just noticed your c.l.py post quoted below.  Nobody but me knows or cares
about this obscure stuff ;-) so I'm not surprised you got no answer...

C. Titus Brown   Dec 27 2004, 12:41 pm wrote:
[...]
> The issue turned out to be that mailman sends out RFC 2965 [1] cookies,
> which are by default rejected by cookielib.  I don't remotely pretend to
> understand the issues involved; hence my post ;).
> 
> A few questions for those more clued in than me:
> 
> * what is the difference between RFC 2965 cookies and others?

See "Where can I find out more about the HTTP cookie protocol?" here:

http://wwwsearch.sourceforge.net/ClientCookie/

For both very short, slightly longer (first link in that section, to a
section of the ClientCookie docs on the cookie standards), and
insanely detailed (Kristol's paper) explanations.


> * why would mailman implement RFC 2965 cookies over the old format?
> (I'm guessing simply because it's the latest/best/format?)

Because Barry didn't realise that almost no browsers implement it (and
never will), I guess.


> * why would cookielib NOT accept RFC 2965 cookies by default?

See above: browsers don't implement it.  It's essentially dead as an
internet standard.  The only real standard is "what IE and Mozilla
do", plus some wisdom from RFCs 2109, 2965 and (more readably!) 2964.

[...]
> In any case, the way to make the cookielib example work for mailman is
> like so:
> 
>  policy = cookielib.DefaultCookiePolicy(rfc2965=True)
>  cj = cookielib.LWPCookieJar('cookies.lwp', policy=policy)

Hmm, cookielib should work if IE and Mozilla do, so that's a bug :(
You shouldn't need to turn on 2965 handling.

Do you have a script that demonstrates the problem, so I can fix it?

Thanks


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


Re: string issue

2005-02-04 Thread John J. Lee
Steve Holden <[EMAIL PROTECTED]> writes:
[...]
> You are modifying the list as you iterate over it. Instead, iterate
> over a copy by using:
> 
> for ip in ips[:]:
>...

Just to help popularise the alternative idiom, which IMO is
significantly less cryptic (sane constructors of mutable objects
almost always make a copy, and list is no exception: it's guaranteed
to do so):

for ip in list(ips):
   ...


Works back to at least Python 1.5.2.


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


Re: "Collapsing" a list into a list of changes

2005-02-04 Thread John J. Lee
Steven Bethard <[EMAIL PROTECTED]> writes:

> Mike C. Fletcher wrote:
[...]
> >  >>> def changes( dataset ):
> > ... last = None
> > ... for value in dataset:
> > ... if value != last:
> > ... yield value
> > ... last = value
> > ...>>> print list(changes(data ))
> > which is quite readable/elegant IMO.
> 
> But fails if the list starts with None:
> 
> py> lst = [None,0,0,1,1,1,2,2,3,3,3,2,2,2,4,4,4,5]
> py> def changes(dataset):
> ... last = None
> ... for value in dataset:
> ... if value != last:
> ... yield value
> ... last = value
> ...
> py> list(changes(lst))
> [0, 1, 2, 3, 2, 4, 5]
> 
> A minor modification that does appear to work:
> 
> py> def changes(dataset):
> ... last = object()
> ... for value in dataset:
> ... if value != last:
> ... yield value
> ... last = value
> ...
> py> list(changes(lst))
> [None, 0, 1, 2, 3, 2, 4, 5]

Unless the first object in the list has a weird __cmp__ (does
happen...).  OK, weird __cmp__s are nasty anyway, but still, why
compound it through cleverness when you can write a really plodding
function that *always* does what it says on the tin?

clever-is-evil-ly y'rs,


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


Insane import behaviour and regrtest.py: heeelp

2005-02-05 Thread John J. Lee
I'm tearing my hair out at what seems like weird import behaviour I'm
getting from Python's stdlib test script, regrtest.py (not for the
first time: seem to have forgotten the resolution from last time, and
the time before, and the time before that, when this damn test script
of Python's had me screaming at the screen... I don't seem to be
learning my lesson here :( )

*Please* somebody inform me *what* affects what file Python will pick
up, other than:

0. Python executable

1. sys.path

2. current working directory

3. Directory in which script lives
 
4. Directory from which script was invoked

5. The contents of one's hard drive

Even with all of these constant (and not all of them should directly
affect the outcome in any case, I know), I get different modules
picked up from imports in two scripts, and I'm damned if I can see
why.

Here's the first script, just a test script:

import os, sys
sys.path = ['/hda/usr/local/buf/python/python/dist/src/Lib', 
'/home/john/lib/python', '/usr/local/lib/python24.zip', 
'/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', 
'/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', 
'/usr/local/lib/python2.4/site-packages']
abstest = "test.test_urllib2"
print 'abstest', abstest
print 'sys.path', sys.path
print 'cwd', os.getcwd()
the_package = __import__(abstest, globals(), locals(), [])
print 'the_package.__path__', the_package.__path__

If I stick that script in my Python CVS Lib/test directory as blah.py,
then cd to Lib and:

$ python2.4 test/blah.py
abstest test.test_urllib2
sys.path ['/hda/usr/local/buf/python/python/dist/src/Lib', 
'/home/john/lib/python', '/usr/local/lib/python24.zip', 
'/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', 
'/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', 
'/usr/local/lib/python2.4/site-packages']
cwd /hda/usr/local/buf/python/python/dist/src/Lib
*
the_package.__path__ ['/hda/usr/local/buf/python/python/dist/src/Lib/test']


All as expected: I pick up Lib/test/test_urllib2.py -- that ***
business is coming from a print >> sys.stderr statement I inserted at
module level in that copy of the module (though the >> sys.stderr is
probably unnecessary, since IIRC regrtest does not rebind sys.stdout
when the -v option is given, as in my usage below).


But, when I run the second script, Lib/test/regrtest.py, with a
modified sys.path (see paragraph below) and the same print statements
as in my test script inserted:

$ python2.4 test/regrtest.py -f test/torun -v
test_urllib2
abstest test.test_urllib2
sys.path ['/hda/usr/local/buf/python/python/dist/src/Lib', 
'/home/john/lib/python', '/usr/local/lib/python24.zip', 
'/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', 
'/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', 
'/usr/local/lib/python2.4/site-packages']
cwd /hda/usr/local/buf/python/python/dist/src/Lib
the_package.__path__ ['/usr/local/lib/python2.4/test']

I get the test_urllib2.py from /usr/local/lib/python2.4 (note __path__
and lack of *s), though everything else (sys.path, cwd, etc.)
remains the same as my test script above!

The only change I made to regrtest other than the print statements was
to add Lib to sys.path, so I pick up modules from CVS instead of the
installed 2.4 versions (yeah, I know I should build and install a
python2.5 executable from CVS, but I don't see how that's relevant here).

Why???  Help!

stupid-stupid-stupid-gh--ly y'rs,


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


Re: How do I enter/receive webpage information?

2005-02-05 Thread John J. Lee
Jorgen Grahn <[EMAIL PROTECTED]> writes:
[...]
> I did it this way successfully once ... it's probably the wrong approach in 
> some ways, but It Works For Me.
> 
> - used httplib.HTTPConnection for the HTTP parts, building my own requests
>   with headers and all, calling h.send() and h.getresponse() etc.
> 
> - created my own cookie container class (because there was a session
>   involved, and logging in and such things, and all of it used cookies)
> 
> - subclassed sgmllib.SGMLParser once for each kind of page I expected to
>   receive. This class knew how to pull the information from a HTML document,
>   provided it looked as I expected it to.  Very tedious work. It can be easier
>   and safer to just use module re in some cases.
> 
> Wrapped in classes this ended up as (fictive):
> 
> client = Client('somehost:80)
> client.login('me', 'secret)
> a, b = theAsAndBs(client, 'tomorrow', 'Wiltshire')
> foo = theFoo(client, 'yesterday')
> 
> I had to look deeply into the HTTP RFCs to do this, and also snoop the
> traffic for a "real" session to see what went on between server and client.

I see little benefit and significant loss in using httplib instead of
urllib2, unless and until you get a particulary stubborn problem and
want to drop down a level to debug.  It's easy to see and modify
urllib2's headers if you need to get low level.

One starting point for web scraping with Python:

http://wwwsearch.sourceforge.net/bits/GeneralFAQ.html

There are some modules you may find useful there, too.

Google Groups for urlencode.  Or use my module ClientForm, if you
prefer.  Experiment a little with an HTML form in a local file and
(eg.) the 'ethereal' sniffer to see what happens when you click
submit.

The stdlib now has cookie support (in Python 2.4):

import cookielib, urllib2
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

r = opener.open("http://example.com/";)
print r.read()

Unfortunately, it's true that network sniffing and a reasonable
smattering of knowledge about HTTP &c., does often turn out to be
necessary to scrape stuff.  A few useful tips:

http://wwwsearch.sourceforge.net/ClientCookie/doc.html#debugging


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


Re: How do I enter/receive webpage information?

2005-02-05 Thread John J. Lee
Jorgen Grahn <[EMAIL PROTECTED]> writes:
[...]
> - subclassed sgmllib.SGMLParser once for each kind of page I expected to
>   receive. This class knew how to pull the information from a HTML document,
>   provided it looked as I expected it to.  Very tedious work. It can be easier
>   and safer to just use module re in some cases.
[...]

BeautifulSoup is often recommended (never tried it myself).

Remember HTMLtidy and its offshoots (eg. tidylib, mxTidy) are
available for cleaning horrid HTML while-u-scrape, too.

Alternatively, some people swear by automating Internet Explorer;
other people would rather be hit on the head with a ball-peen hammer
(not only the MS-haters)...


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


Re: Pickling and inheritance are making me hurt

2005-02-05 Thread John J. Lee
Kirk Strauser <[EMAIL PROTECTED]> writes:

> I have a module that defines a Search class and a SearchResult class.  I use
> these classes by writing other modules that subclass both of them as needed
> to interface with particular search engines.
> 
> My problem is that Search defines a method (called automatically by __del__)
  ^^^

Don't Do That.  __del__ methods are bad.  They mess up cyclic garbage
collection, IIRC.  ISTR other problems with them, too...


[...]
> Exception pickle.PicklingError:  0xb7f7ad6c> in  0xb7ec954c>> ignored
[...]

...yeah, there's one: thanks for reminding me ;-)

You may want to read up on __getstate__ and __setstate__, BTW.


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


Re: Insane import behaviour and regrtest.py: heeelp

2005-02-06 Thread John J. Lee
Nick Coghlan <[EMAIL PROTECTED]> writes:

> John J. Lee wrote:
> > The only change I made to regrtest other than the print statements was
> > to add Lib to sys.path, so I pick up modules from CVS instead of the
> > installed 2.4 versions (yeah, I know I should build and install a
> > python2.5 executable from CVS, but I don't see how that's relevant here).
> 
> I didn't read your whole message so I may be off track here, but
> regrtest.py has some arguably demented path handling behaviour, and
> it's driven mainly by the physical location of regrtest.py. In
> particular:
> 
> def findtestdir():
>  if __name__ == '__main__':
>  file = sys.argv[0]
>  else:
>  file = __file__
>  testdir = os.path.dirname(file) or os.curdir
>  return testdir
> 
> So intead of adding anything to sys.path, tweak the call to 'main' on
> the final line to set "testdir" appropriately.

Nope: that just affects finding the *names* of the tests.  It does not
determine the location from which they are actually imported.  I tried
it, and I get the same results as before (the test modules from my
installed copy of Python are picked up instead of the local copies in
my CVS checkout's Lib/test, apparently entirely contrary to sys.path).


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


Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-06 Thread John J. Lee
"Adomas" <[EMAIL PROTECTED]> writes:

> Well, a bit more secure would be
> 
> eval(expression, {'__builtins__': {}}, {})
> 
> or alike.

Don't believe this without (or even with ;-) very careful thought,
anyone.  Google for rexec.


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


Trainee Developer / Consultant Vacancy at ReportLab, London

2005-07-08 Thread John J. Lee
Vacancy at ReportLab, London

ReportLab develop enterprise reporting and document generation solutions
using cutting-edge Python technology, and have a growing business with an
excellent blue chip customer base.  You may also know us from our open
source PDF and graphics library...

We have a job opening for one trainee I.T. consultant working in our
solutions team.  Full time junior positions based in our Wimbledon
(London, England) office.

We are already interviewing, so a quick response is essential!

Full details are at http://www.reportlab.com/careers.html

Reply to [EMAIL PROTECTED]


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


Re: Fighting Spam with Python

2005-08-26 Thread John J. Lee
David MacQuigg  writes:
[...]
> I haven't used Spambayes, but my experience with Spamnix (an offshoot
> of Spam Assassin) is that statistical filters always have a few false
> rejects.  In my case, that's about two per week.
[...]

That is precisely the problem that Bayesian filtering was designed to
solve.

AFAIK, Spam Assassin is a non-Bayesian filter.  (Though I think I
heard they were thinking of grafting on Bayesian filtering to their
existing algorithms, I'm not sure if they did it, or even if that's
actually a sane thing to do.)

[David, in an earlier email]
> reject.  15% will get an immediate accept without filtering, because
> the sender is authenticated and has a good reputation.  Eventually,
> all reputable senders will join the 15%, and the 5% will shrink to
> where we can ignore it.

Two questions you seem to be implicitly assuming particular answers
to: Is widespread authentication a good thing?  Does it solve any
problem not solved by Bayesian filtering plus good mail client
support?  My first reaction is to answer "no" to both questions, so to
regard your effort as harmful.  Might be interesting to hear why you
think it's a good thing, though.


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


Re: Insane import behaviour and regrtest.py: heeelp

2005-02-06 Thread John J. Lee
Tim Peters <[EMAIL PROTECTED]> writes:

> [John J. Lee]
> > ...
> > I tried it, and I get the same results as before (the test modules from my
> > installed copy of Python are picked up instead of the local copies in
> > my CVS checkout's Lib/test, apparently entirely contrary to sys.path).
> 
> Try running Python with -vv (that's two letter "v", not one letter
> "w").  That will display a long-winded account of everything Python
> tries in order to satisfy an import.

Thanks.

I'm still puzzled, though.  Reading the -vv output, I see that when
importing test_cookielib (which is currently the only line in my
regrtest.py -f file), Python doesn't appear to look in Lib/test to
find module "test.test_cookielib" (the actual string passed by
regrtest.py to __import__): see the output below.

Why does Python not look in

/usr/local/src/python/python/dist/src/Lib/test

for test_cookielib.py{,c,o}??


Snippet to show print statements I added to my regrtest.py :

. try:
. save_stdout = sys.stdout
. try:
. if cfp:
. sys.stdout = cfp
. print test  # Output file starts with test name
. if test.startswith('test.'):
. abstest = test
. else:
. # Always import it from the test package
. abstest = 'test.' + test
.+print >> sys.stderr, ">>>>>>>sys.path", sys.path
. the_package = __import__(abstest, globals(), locals(), [])
.+print >> sys.stderr, ">>>>>>>the_package.__path__", 
the_package.__path__
. the_module = getattr(the_package, test)
. # Most tests run to completion simply as a side-effect of

Only other change to regrtest.py:

. if __name__ == '__main__':
. # Remove regrtest.py's own directory from the module search path.  This
. # prevents relative imports from working, and relative imports will screw
. # up the testing framework.  E.g. if both test.test_support and
. # test_support are imported, they will not contain the same globals, and
. # much of the testing framework relies on the globals in the
. # test.test_support module.
. mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
. i = pathlen = len(sys.path)
. while i >= 0:
. i -= 1
. if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
. del sys.path[i]
. if len(sys.path) == pathlen:
. print 'Could not find %r in sys.path to remove it' % mydir
.+lib = "/usr/local/src/python/python/dist/src/Lib"
.+sys.path.insert(0, lib)
.-main()
.+main(testdir=lib)


Here's what I've got in my CVS checkout:

Lib[0]$ pwd
/hda/usr/local/buf/python/python/dist/src/Lib
Lib[0]$ ls test/test_cookielib* | grep -v 'patch\|latest\|~'
test/test_cookielib.py
test/test_cookielib.pyc


And the output:

Lib[0]$ python2.4 -u -vv test/regrtest.py -f test/torun -v 2>&1 | less
[...long snip...]
# trying /usr/local/lib/python2.4/lib-tk/time.py
# trying /usr/local/lib/python2.4/lib-tk/time.pyc
# trying /usr/local/lib/python2.4/lib-dynload/time.so
dlopen("/usr/local/lib/python2.4/lib-dynload/time.so", 2);
import time # dynamically loaded from 
/usr/local/lib/python2.4/lib-dynload/time.so
test_cookielib
>>>>>>>sys.path ['/usr/local/src/python/python/dist/src/Lib', 
>>>>>>>'/home/john/lib/python', '/usr/local/lib/python24.zip', 
>>>>>>>'/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', 
>>>>>>>'/usr/local/lib/python2.4/lib-tk', 
>>>>>>>'/usr/local/lib/python2.4/lib-dynload', 
>>>>>>>'/usr/local/lib/python2.4/site-packages']
# trying /usr/local/lib/python2.4/test/test_cookielib.so
# trying /usr/local/lib/python2.4/test/test_cookielibmodule.so
# trying /usr/local/lib/python2.4/test/test_cookielib.py
import test.test_cookielib # from 
/usr/local/lib/python2.4/test/test_cookielib.py
# can't create /usr/local/lib/python2.4/test/test_cookielib.pyc
# trying /usr/local/lib/python2.4/test/re.so
# trying /usr/local/lib/python2.4/test/remodule.so
# trying /usr/local/lib/python2.4/test/re.py
# trying /usr/local/lib/python2.4/test/re.pyc
# trying /usr/local/lib/python2.4/test/time.so
# trying /usr/local/lib/python2.4/test/timemodule.so
# trying /usr/local/lib/python2.4/test/time.py
# trying /usr/local/lib/python2.4/test/time.pyc
# trying /usr/local/lib/python2.4/test/test.so
# trying /usr/local/lib/python2.4/test/testmodule.so
# trying /usr/local/lib/python2.4/test/test.py
# trying /usr/local/lib/python2

Re: newbie wants to compile python list of filenames in selected directories

2005-02-06 Thread John J. Lee
Greg Krohn <[EMAIL PROTECTED]> writes:
> anthonyberet wrote:
[...]
> > I want to write a script to compare filenames in chosen directories,
> > on windows machines. Ideally it would compose a list of strings of
> > all the filenames in the directories, and those directories would be
> > chosable by the user of the script.
[...]
> 
> os.listdir does almost exactly what you are asking for. For a little
> more flexibility, you can use os.path.walk, although it's not quite as
> newb friendly.
> 
> -greg

os.walk is perhaps newbie-friendlier than os.path.walk.

Or perhaps not: not having read the tutorial &c. for some time, I
don't know how good they are on generators...


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


Re: Insane import behaviour and regrtest.py: heeelp

2005-02-06 Thread John J. Lee
Tim Peters <[EMAIL PROTECTED]> writes:

> [John J. Lee]
> > I'm still puzzled, though.  Reading the -vv output, I see that when
[...]
> > Lib[0]$ pwd
> > /hda/usr/local/buf/python/python/dist/src/Lib
> 
> That doesn't look to be the same thing as the
> 
> /usr/local/src/python/python/dist/src/Lib
> 
> you're asking about, right?
[...]

Ah: somehow managed to look straight through that, so used am I to the
presence of these symlinks:

Lib[0]$ ls -l /usr/local/src
lrwxrwxrwx1 root root   19 Sep  4 13:45 /usr/local/src -> 
/hda/usr/local/src//
Lib[0]$ ls -l /hda/usr/local/src/python
lrwxr-xr-x1 john oldjohn25 Sep 11 13:21 
/hda/usr/local/src/python -> /hda/usr/local/buf/python/


The twisty mess of symlinks and owners is down to a couple of OS and
hard disk changes.

I don't immediately see why at 1am, but I guess that's the problem
(that, and trying to understand import details at 1am...).

Thanks!


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


Re: lambda and for that matter goto not forgetting sugar

2005-02-10 Thread John J. Lee
from goto.py ( http://entrian.com/goto/ ):
.# Label: "label .x"  XXX Computed labels.


:-)


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


Re: Commerical graphing packages?

2005-02-12 Thread John J. Lee
[EMAIL PROTECTED] writes:

> Check out GRACE. It's not specifically designed for Python, but I've
> been using with Python for a couple of years or more. I'm very happy
> with it, and it's free. It works both interactively and in batch mode.
> Do a google on GRACE.

If you're generating lots of graphs programatically, eg. on a web
server, grace is not what you want.  Yes, it has a command language,
but IIRC it depends on X11, and windows even pop up as it runs in
batch mode.  Bleh.

Gets the job done for interactive editing of publication-quality
scientific graphs, though.


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


Re: Testing web applications

2005-02-12 Thread John J. Lee
Josef Meile <[EMAIL PROTECTED]> writes:
> > I'm looking for frameworks to make testing web applications -
> > i.e. parsing and filling out forms - easier. I found Puffin, which
> > looks good but not very usable in the current state. I know that I
> > once read about other nice frameworks, but could not find one via
> > google. Any hints?
> Zope + Formulator is a nice combination to validating and designing
> forms and add some functionality. If you want a more complicated content
> management framework, then you can additionally install plain CMF or
> Plone, which is based on CMF. There is also something called Silva, but
> it doesn't have many products as the other two; however, it is also
> nice.
> 
> I have heard also about CherryPy, Quixote, Twisted Matrix and Webware,
> but I haven't tested them. Once I saw that somebody posted a link, which
> compares some of them, but I lost that thread :-(

Did you read the question?

:-)


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


Re: Commerical graphing packages?

2005-02-13 Thread John J. Lee
[EMAIL PROTECTED] writes:

> >If you're generating lots of graphs programatically, eg. on a web
> >server, grace is not what you want.  Yes, it has a command language,
> >but IIRC it depends on X11, and windows even pop up as it runs in
> >batch mode.  Bleh.
> 
> I don't understand what you're talking about. I've been using GRACE in
> batch mode for years and I've never had a window pop up. The only time
> a window "pops up" is when you start GRACE interactively.

Hmm, I guess I was actually using grace_np.py rather than batch
mode... it was a few years ago I last used it.


> The GRACE command language is not the greatest, but it gets the job
> done. It may have improved lately too (I run a fairly old version).
> 
> Another nice feature of GRACE is a fairly active user community and a
> mailing list for help. They helped get me unstuck several times a while
> back.

...and some nasty features are the rather nasty GUI (at least, I found
it awkward) and the fact that it's the only X11 application I've used
that ever managed to crash my whole X desktop.


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


Re: recommended way of generating HTML from Python

2005-02-21 Thread John J. Lee
Matt Goodall <[EMAIL PROTECTED]> writes:
[...]
> Agreed. Although I would go further and say that it's important to
> choose a templating system that allows the Python developer to annotate
> XHTML templates using **valid XML**, i.e. no "for x in y" loops, no "if
> foo" conditionals, no "i = 0" variable setting, no expression
> evaluations, etc.
[...]

Why does use of a templating system whose documemts are valid XML
imply no loops, conditionals, expression evaluation etc.?

Or are you just talking about particular (non-XML) syntaxes for these
constructs?


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


Re: creating .NET clients with python

2005-03-04 Thread John J. Lee
Guy Robinson <[EMAIL PROTECTED]> writes:

> Can anyone confirm if there is a python library that can allow me to
> create .NET clients in python.
> 
> My understanding is both IronPython and python for .NET can't create
> python .net clients?

IIUC, IronPython can, but it's not ready for production work yet (and
won't be for some while yet, I imagine).


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


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-04 Thread John J. Lee
Gary Nutbeam <[EMAIL PROTECTED]> writes:
> D H wrote:
[...]
> > Check out Castle on Rails for .NET/Mono.  It is still in early
> > development, but you can use it with C#, VB, or boo, and I'm sure
> > eventually with IronPython as well.
> 
> Thanks for the feedback. I should have been more specific though and
> mentioned this has done on Linux (client and server).

Mono runs on Linux.


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


Re: urllib2 meta-refresh

2005-03-04 Thread John J. Lee
JanC <[EMAIL PROTECTED]> writes:

> Artificial Life schreef:
> 
> > urllib2 does not seem to be able to handle META-REFRESH in an html
> > document. I just get back the html to the page that is supposed to
> > forward me to the intended page. Any way around this? 
> 
> Have a look at the HTTPRefreshProcessor in ClientCookie:
> 

Be sure to read all the notes under "Notes about ClientCookie, urllib2
and cookielib" on this page:

http://wwwsearch.sourceforge.net/ClientCookie/


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


Re: Python 2.4 removes None data type?

2005-03-05 Thread John J. Lee
Steve Holden <[EMAIL PROTECTED]> writes:
> Warren Postma wrote:
[...]
> > gloat. Are there any really evil glitches LEFT in Python? Now go
> > look at   Perl and come back and say
> > "Thank-deity-of-my-choice-I'm-using-Python".
> >
> Remaining warts that won't disappear:
> 
> print >> file, stuff

Not beautiful, yes, but evil?  Why?


> @decorator

Evil in the wrong hands...


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


Re: yum install python2.4

2005-03-06 Thread John J. Lee
[EMAIL PROTECTED] writes:

> My goal is to install python2.4 using yum (wouldn't you know it, it's a
> dependency for something else).
[...]

You're probably better off asking on a yum or Fedora list or
newsgroup.


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


Re: Modifying Call Tips and Intellisense Behavior

2005-03-06 Thread John J. Lee
[EMAIL PROTECTED] writes:

> I like the way call tips displays argument variables for functions when
> you type the "(" after the function name.  However, if one of the
> arguments to the function is something like "SomeMod.attribute", the
> intellisense will display all the exposed methods and attributes when
> "SomeMod." is typed.  This is fine but once I have selected the desired
> attribute and continue with entering the next argument, the original
> call tip for the function I'm working on is lost.  I think it would be
> nice if one could hit a key sequence or something to recall the last
> call tip.
> 
> Are there some other python editors that have this type of behavior?
> 
> If not, where should I start looking to tweak.

You haven't said what editor/IDE you're using now.


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


Re: a program to delete duplicate files

2005-03-14 Thread John J. Lee
Patrick Useldinger <[EMAIL PROTECTED]> writes:

> David Eppstein wrote:
> 
> > The hard part is verifying that the files that look like duplicates
> > really are duplicates.  To do so, for a group of m files that appear
> > to be the same, requires 2(m-1) reads through the whole files if you
> > use a comparison based method, or m reads if you use a strong
> > hashing method.  You can't hope to cut the reads off early when
> > using comparisons, because the files won't be different.
> 
> If you read them in parallel, it's _at most_ m (m is the worst case
> here), not 2(m-1). In my tests, it has always significantly less than
> m.

Hmm, Patrick's right, David, isn't he?

Except when m gets really BIG (say, M), in which case I suppose m is
no longer the worst case number of whole-file reads.

And I'm not sure what the trade off between disk seeks and disk reads
does to the problem, in practice (with caching and realistic memory
constraints).


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


Re: wxPython vs. pyQt

2005-03-20 Thread John J. Lee
Andrew E <[EMAIL PROTECTED]> writes:

> Hans-Peter Jansen wrote:
> > ..
> > While in PyQt world, I found these advantages:
> >  + conceptually vastly superior
> >  + powerful api/widgets/features
> >  + fast as hell due to the efficient binding of a quite efficient lib
> >  + cool tools, that are unicode/translation aware
> >  + very efficient programming environment/unbeatable productivity
> > While this sounds like the average sales talk, I will try to backup
> > these
> > claims a bit:
>  > ..
> 
> I've been a wx user since around 1999 and overall I like it. It annoys
> me a *lot* sometimes, but as Qt was always prohibitively expensive for
> commercial development, it was the only real option.
> 
> The key question from my point of view is: can I write commercial
> sell-if-I-want-to applications using Qt? If it is GPL, then I guess
> the answer is 'no'?

Yes, you can write commercial apps.  It's multi-licensed (commercial,
GPL, etc.): you get to pick the license(s) you want to use.  Read the
licenses.

PyQt's licensing follows Qt's very closely, so no real complications
there.  Note PyQt (including a Qt license for use only with PyQt) is
actually far cheaper than Qt alone (if you buy Blackadder).


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


Re: beeping portably

2005-03-20 Thread John J. Lee
"Jim" <[EMAIL PROTECTED]> writes:

> I'd like to emit beeps.  The twists are that (1) I hope to have control
> over the frequency of the beeps and their duration and (2) I'd like the
> solution to be portable across Linux, Windows, and OS X.
[...]

PyGame?  If it's too big for you, you could always borrow code from it.


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


Re: AttributeError: 'module' object has no attribute 'setdefaulttimeout'

2005-04-01 Thread John J. Lee
Steve Holden <[EMAIL PROTECTED]> writes:

> Peter Otten wrote:
> > adrian wrote:
> >
> >>urllib.socket.setdefaulttimeout(self.timeout)
> >>AttributeError: 'module' object has no attribute 'setdefaulttimeout'
> > socket.setdefaulttimeout() was added in Python 2.3. You need to
> > upgrade.
> > Peter
> >
> Alternatively you might still be ablet o get Tom O'Malley's
> tiemoutsocket module, which I used in several applications until 2.3
> integrated the functionality.

I seem to recall a bug related to sendall(), though, IIRC. I reported
it, but it didn't get fixed, again IIRC.


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


Re: Little Q: how to print a variable's name, not its value?

2005-04-01 Thread John J. Lee
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
[...]
> Restating:  I'm doing some debugging of some code.  I want to print out
> the value of two variables whose names are known.  Let's call them
> myTime and myPlace.
[...]

Why not simply get your editor to insert the variable name twice?  I
have that bound to C-c d in my .emacs.


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


Re: string goes away

2005-04-03 Thread John J. Lee
Duncan Booth <[EMAIL PROTECTED]> writes:
[...]
>str.join(sep, list_of_str)
[...]

Doesn't work with unicode, IIRC.



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


Re: string goes away

2005-04-04 Thread John J. Lee
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
[...]
> Of course that statement is also false. Performance prediction is very
> difficult, and you cannot imply much from this benchmark. In other
[...]

s/imply/infer/


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


Re: A ClientForm Question

2005-04-04 Thread John J. Lee
Francesco <[EMAIL PROTECTED]> writes:

> Il Fri, 01 Apr 2005 02:36:24 -0800, narke ha scritto:
> 
> > Does anyone here use ClientForm to handle a HTML form on client side?

Yes. :-)

[...]
> > forms = ParseResponse(urlopen(url))
> > 
> > form = forms[0]
> > urlopen(form.click("ZoomControl1:Imagebutton2"))
> > 
> > unfortunatly, however, when the code run, it just got a page which is
> > not the one i desired ( i actually wish to get the same page as i
> > 'click' the button).  I guess that is "onclick=" statement cause
> > something weird, but I do not understand it.  And, in the source
> > containing the form, i found nowhere the Page_ClientValidate() resides.

Learn JS ;-/  Could be lots of things, read these:

http://wwwsearch.sourceforge.net/ClientForm/index.html#faq

http://wwwsearch.sourceforge.net/ClientCookie/doc.html#debugging


> Similar problem for me.
> In the form, i have
>  onClick="document.UserForm.submit()">
> and i don't know how to click this.
> urlopen(form.click()) doesn't nothing.
> UserForm is the name of the form.

http://wwwsearch.sourceforge.net/ClientForm/index.html#faq


See second bullet point under "Why does .click()ing on a button not
work for me?".


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


Re: unittest vs py.test?

2005-04-04 Thread John J. Lee
"Raymond Hettinger" <[EMAIL PROTECTED]> writes:

> [Peter Hansen]
> > (I'm not dissing py.test, and intend to check it
> > out.
> 
> Not to be disrepectful, but objections raised by someone
> who hasn't worked with both tools equate to hot air.
[...]

Why?  Peter had a reasonable question which, AFAICT, doesn't depend on
any more detailed knowledge that what he had to work with.

What I don't understand about py.test (and trying it out seems
unlikely to answer this) is why it uses the assert statement.
unittest used to do that, too, but then it was pointed out that that
breaks when python -O is used, so unittest switched to self.assert_
&c.  Does py.test have some way around that?


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


Re: A ClientForm Question

2005-04-06 Thread John J. Lee
"narke" <[EMAIL PROTECTED]> writes:

> John J. Lee wrote,
> 
> > See second bullet point under "Why does .click()ing on a button not
> work for me?".
> 
> Thanks for you advice. However, after read through the FAQs, I have not
> managed to find a solution for my problem.  I belive my button is
> coupled with some Java script which mess thing up and there is no a
> easy solution.  Am I right?

Yes.


John

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


Re: Lambda: the Ultimate Design Flaw

2005-04-06 Thread John J. Lee
Simon Brunning <[EMAIL PROTECTED]> writes:

> On Apr 6, 2005 4:42 PM, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> > I've always wondered about this turn of phrase.  I seldom
> > eat a cake at one sitting.
> 
> Clearly you're just not trying. ;-)

:-)))


John

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


Re: Best editor?

2005-04-06 Thread John J. Lee
François Pinard <[EMAIL PROTECTED]> writes:
[...]
> Overall, Vim is also cleaner than Emacs, and this pleases me.
[...]

Is this still true when comparing XEmacs vs. vim? (rather than GNU
Emacs vs. vim)  I've always used GNU Emacs, but I have got the
impression that XEmacs is (was?) cleaner in some ways.


John

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


Re: Best editor?

2005-04-06 Thread John J. Lee
"ChinStrap" <[EMAIL PROTECTED]> writes:

> When not using the interactive prompt, what are you using? I keep
> hearing everyone say Emacs, but I can't understand it at all. I keep
> trying to learn and understand why so many seem to like it because I
> can't understand customization even without going through a hundred
> menus that might contain the thing I am looking for (or I could go
> learn another language just to customize!).
[...]
> Opinions on what the best is? Or reading I could get to maybe sway me
> to Emacs (which has the major advantage of being on everyone's system).

Two reasons I use emacs:

1. For any question "Can I do X with emacs", the answer is almost
   always "yes, use this code that's already written and working"

2. I already know it ;-)

BTW, I use vi keybindings, and I imagine all other editors can do the
same (though perhaps not as well as viper, the emacs package that does
this -- see 1. above), so that's no reason in itself to use vim.


John

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


Re: Best editor?

2005-04-06 Thread John J. Lee
Ville Vainio <[EMAIL PROTECTED]> writes:

> > "Miki" == Miki Tebeka <[EMAIL PROTECTED]> writes:
> 
> Miki> Emacs (or VIm in my case) takes time to learn. However when
> Miki> you start to understand it and know you way around it'll do
> Miki> things no other editor will do for you.
> 
> Other editors also do stuff Emacs won't do. Code completion is a
> killer feature and emacs sucks at it (yes, w/ Cedet too).
[...]

I thought that too, but then I bound dabbrev-expand to F4, and it
seems even better than 'proper' completion (for reducing keystrokes,
anyway).


John

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


Re: gui developing

2005-04-24 Thread John J. Lee
[EMAIL PROTECTED] (John J. Lee) writes:
> Shane Hathaway <[EMAIL PROTECTED]> writes:
[...]
> > However, I haven't heard whether PyQt for Qt 4 will also be available
> > under the GPL.
> 
> Yes, PyQt will be available under the same license as Qt.

Oops, s/license/licenses/


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


Re: Python licence again

2005-04-24 Thread John J. Lee
Will McGugan <[EMAIL PROTECTED]> writes:

> Peter Hansen wrote:
> > John J. Lee wrote:
> >
> >> I will never pronounce thorough 'thurrow', though.  One must draw a
> >> line.
> > How *do* you pronounce it?  "Thurrow" seems to match
> > how I say the word, along with everyone else I've
> > ever met (until now?).
> 
> I would pronounce it like 'thurra', since I'm Scottish.

Me too (England).


> It always
> makes me cringe when Americans pronounce 'Edinburgh' as 'edin-burrow'
> rather then 'edin-burra'.

Edin-br.  (There's a short vowel (a "schwa"?) on the end there that I
missed off because there's no unambigous ASCII symbol for it... But
it's the same vowel a child uses - at least in England! - to say "r"
when running through the alphabet, before they've learned the names
(ay bee cee dee) for the letters.)


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


Re: figuring out # of bytes

2005-04-24 Thread John J. Lee
Jaime Wyant <[EMAIL PROTECTED]> writes:

> On 22 Apr 2005 13:28:57 -0700, codecraig <[EMAIL PROTECTED]> wrote:
> > i want to the number of bytes in a string...
> > 
> > is, len(x) accurate?
> > 
> > so, x = "hi"
> > len(x) == 2 so that means two bytes?
> > 
> > thanks
> 
> No, that means that the string is two bytes in length.  The number of
> bytes is dependent on the encoding.  It seems like there was a thread
[...]

That's only an issue if type(x) != str.  (eg., type(x) == unicode)


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


Re: Data smoothing algorithms?

2005-04-29 Thread John J. Lee
"Anthra Norell" <[EMAIL PROTECTED]> writes:

> Hi,
> 
> The following are differences of solar declinations from one day to
> the next, (never mind the unit). Considering the inertia of a
> planet, any progress of (apparent) celestial motion over regular
> time intervals has to be highly regular too, meaning that a plot
> cannot be jagged. The data I googled out of Her Majesty's Nautical
> Almanac are merely nautical precision and that, I suppose, is where
> the jitter comes in. There's got to be algorithms out there to iron
> it out. If it were a straight line, I could do it. But this, over
> the whole year, is a wavy curve, somthing with a dominant sine
> component. Suggestions welcome.

The important thing is to have a (mathematical, hopefully) model of
how you expect the data to vary with time.  Start from there, and
then, for example, use regression to fit a curve to the data.

The "Numerical Recipes" (Press et al.) book is popular and IMHO is a
good place to learn about these things (comes in several language
flavours, including Fortran and C -- sadly no Python AFAIK), though
the implementations aren't a great choice for serious "production"
use, according to those in the know.

OTOH, there are quick and dirty methods that don't involve any model
worth speaking of -- and Press et al. covers those too :-)


John

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


Re: Which IDE is recommended?

2005-04-29 Thread John J. Lee
Dave Cook <[EMAIL PROTECTED]> writes:

> On 2005-04-27, monkey <[EMAIL PROTECTED]> wrote:
[...]
> Pydev has some compelling features, but I wish I didn't have to run eclipse
[...]

What are those compelling features of Pydev, for an emacs user?


John

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


Re: Can .py be complied?

2005-04-29 Thread John J. Lee
Steve Holden <[EMAIL PROTECTED]> writes:
[...]
> There's nothing wrong with open source projects catering to a market,
> and there's nothing wrong with running open source software on a
> proprietary operating system. To behave otherwise might reduce the
> growth opportunities for Python and its community.
> 
> no-zealotry-please-ly y'rs  - steve
[...]

I'm hesitant to label everybody who disagrees with you (and me) on
that a zealot.  Though I tend to take the same side you do, I'm not
entirely sure it's not just laziness on my part that I think that way.

Seems to me that holding opinions such as "it's a bad thing to support
open source software on closed source systems, and you should not do
it, for the common good" is far from crazy, even though I don't
currently happen to hold that view.


John

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


  1   2   3   4   5   >