Re: More like a shell command.

2008-08-06 Thread Richie Hindle
[Bill]
 Is there anyway I can extend python to accept a command
 which looks more like shell syntax than a function call.

 I want to be able to do this:

 if blah :
 MyCommand  Arg1  Arg2

As a general rule, if Python gives you a syntax error then you can't
achieve what you want without modifying Python's grammar (and turning
it into something that isn't Python any more).

-- 
Richie Hindle
[EMAIL PROTECTED]
Search your Visual Studio projects instantly with Entrian Source Search,
our powerful Source Code Search add-in: http://entrian.com/source-search
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bug in re.findall?

2008-07-04 Thread Richie Hindle
Hi Marcin,

 subnetlist=192.168.100.0 , 192.168.101.0
 ipre=re.compile(([0-9]{1,3}\.){3}[0-9]{1,3})
 
  ipre.findall(subnetlist)
 ['100.', '101.']

Correct - it returns the most recently captured text for your sole group.

 a=ipre.finditer(subnetlist)
  a.next().group()
 '192.168.100.0'

Also correct, because match.group() returns the whole of the matched text.
If you wanted just your captured piece, you need this:

  a.next().group(1)
 '100.'

Hope that helps!

-- 
Richie Hindle
[EMAIL PROTECTED]
http://entrian.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 disable proxy

2008-01-04 Thread Richie Hindle
Hi Dimitris,

 I've been looking for a way to explicitly disable the use of proxies with 
 urllib2, no matter what the environment dictates. Unfortunately I can't find 
 a way [...]

Would changing the environment work?  Like this:

 del os.environ['http_proxy']
 do_stuff_with_urllib2()

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OPLC purchase period extended

2007-11-28 Thread Richie Hindle

[Aahz]
 I'm sure that some people would be willing to serve as middleware...

I would *love* to have one of these for my kids, if anyone here would be
prepared to forward one to the UK for me.  I can pay you the postage by
PalPal, Amazon voucher, whatever suits.

The XO reminds me of the computers I grew up with in the early 80s - the
Sinclair ZX Spectrum and the BBC Micro.  They're miles apart technically,
but similar in the way they're designed for children.  The lack of that
kind of computer is something that's vaguely worried me for my kids - a
Windows PC, or even Linux or Mac, carries so much baggage that trying to
learn basic programming on it would have a much steeper learning curve
than a more basic, child-targeted machine.  Something that's designed for
children and has Python as its main programming language is a dream come
true!

It's also something that can safely be left lying around the house, and
become a part of everyday family life, in a way that a desktop machine or
a standard laptop can't.  When the story I'm reading to my 4-year-old
mentions Elvis and she asks who he is, rather than traipsing down two
flights of stairs to the study and cranking up the PC, being able to grab
the XO - which was partly hers - to answer her question would be just
fantastic.

And what better way to encourage friends and family to donate to the OLPC
cause than to demonstrate the real thing to them?  The G1G1 scheme is a
great idea, and it's a real shame they've had to limit its availability to
North America.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NUCULAR fielded text searchable indexing

2007-10-10 Thread Richie Hindle

[Paul]
 tell us how the software compares to stuff like Lucene or Xapian.

+1

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


Re: changes on disk not visible to script ?

2007-10-08 Thread Richie Hindle
[Bruce]
 f.close()
 cmd = echo %s | %s%(argument_file,the_program)

Either: you are a VB programmer and you've actually typed f.close rather
than f.close(),

Or: you meant type (or cat) rather than echo,

Or: I need a new crystal ball.  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: changes on disk not visible to script ?

2007-10-08 Thread Richie Hindle
[Bruce]
 VB programmer!? Thats really harsh..

No offence intended!  8-)

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


Re: Coming from Perl

2007-09-13 Thread Richie Hindle

[Amer]
 Can you or anyone see anything in the posted code that might be the 
 cause?

 #!/usr/bin/python
 import cgitb; cgitb.enable(display=0, logdir=.)
 import sys
 sys.stderr = sys.stdout
 print Content-Type: text/html
 print

My guess would be that you don't have cgitb in your server environment, or
that you have a bogus one.  Rearrange things like this:

#!/usr/bin/python
print Content-Type: text/html
print
import sys
sys.stderr = sys.stdout
import cgitb; cgitb.enable(display=0, logdir=.)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Richie Hindle

 [Amer]
 #!/usr/bin/python
 [...] On my home PC [...]
 [Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
 cannot find the file specified.

That's because on your home PC Python is somewhere like
C:\Python25\python.exe, not /usr/bin/python.

Are you sure /usr/bin/python is correct for your hosting environment?

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-31 Thread Richie Hindle

[Carsten]
 .. If we start labeling
 people, this thread will earn you a label that rhymes with roll.

[Hendrik]
 weird this - maybe a native English speaker can comment - 
 when I pronounce what fishermen do - it rhymes with roll,
 but when I am talking about the thing that lives under bridges
 and munches goats, the O sound is shorter, and more 
 towards the back of my mouth.

But - the word for someone who posts to the internet with the intention of
stirring up trouble derives from the word for what fishermen do, not from
the word for something that lives under a bridge.  It derives from trolling
for suckers or trolling for newbies.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strip() 2.4.4

2007-06-21 Thread Richie Hindle

[Nick]
 Why is there a apostrophe still at the end?

[Stephen]
 Is it possible that you actually have whitespace at the end
 of the line?

It's the newline - reading lines from a file doesn't remove the newlines:

from cStringIO import StringIO

DATA = \
'AF':'AFG':'004':'AFGHANISTAN':'Afghanistan'
'AL':'ALB':'008':'ALBANIA':'Albania'
'DZ':'DZA':'012':'ALGERIA':'Algeria'
'AS':'ASM':'016':'AMERICAN SAMOA':'American Samoa'


f1 = StringIO(DATA)

for line in f1:
print repr(line.rsplit(':')[4].strip(')) # repr shows the error

# This prints:
# 
# Afghanistan'\n
# Albania'\n
# Algeria'\n
# American Samoa'\n
# 
# Do this instead:

f1.seek(0)

for line in f1:
print line.strip().rsplit(':')[4].strip(')

# This prints:
#
# Afghanistan
# Albania
# Algeria
# American Samoa

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyMeld for html templates?

2007-01-22 Thread Richie Hindle
[Sean]
 The pymeld docs show examples only for the Python command line
 interpreter and show using the print statement to output stuff. But
 using mod_python.apache, I think you need to use req.write(something)
 format. And of course, this fails when you feed it output from Meld.

req.write(str(meld)) ?

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: PyMeld for html templates?

2007-01-19 Thread Richie Hindle
[Sean]
 I wonder if anyone has any thoughts on PyMeld as a template
 system for churning out general websites?

I'm doing that (but then I would be wouldn't I? 8-)
http://www.mandant.net is an example - the content of each page comes
from a file containing just the content, the layout and sidebar are
defined in a template HTML file, and the navigation is built by a
Python script.  All that is pulled together using PyMeld into a set of
HTML files and deployed to the web server (there's no need to it on the
fly for that site, but you certainly could).

 I want for a URI request to mysite.com/info
 to pull in a layout.html template which will in turn be populated by
 the info.html template. [...]  how about PyMeld, any ideas on how
 to do it or whether it will even work as I've described?

You'd do something like this:

from PyMeld import Meld

LAYOUT = htmlheadtitle id='title'The Title/title/head
bodydiv id='info'The page information goes here./div
p id='footerCopyright Me 2007./p/body/html

INFO = htmlheadtitle id='title'The real title/title/head
body id='info'pHere is the info, which would in the real world
be read from a file./p/body/html

page = Meld(LAYOUT)
info = Meld(INFO)
page.title = info.title._content
page.info = info.info._content
print page

Is that the sort of thing you had in mind?

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: why would anyone use python when java is there?

2006-11-30 Thread Richie Hindle

[Adam]
 For the life of me I can't understand why he would troll
 comp.lang.python when comp.lang.lisp is there.

+1 QOTW!

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why would anyone use python when java is there?

2006-11-30 Thread Richie Hindle

[Adam]
 For the life of me I can't understand why he would troll
 comp.lang.python when comp.lang.lisp is there.

[Richie]
 +1 QOTW!

[Paul]
 Overruled! ;-)
 
 Mostly because comp.lang.lisp seems to have become a much better place
 to get quotes of the week about Python than comp.lang.python itself.

Point taken... but had Adam said For the life of me I can't understand why
he would troll comp.lang.python when the rest of usenet is there I would
have still voted QOTW.  It was a pro-comp.lang.python vote, not an
anti-comp.lang.lisp vote.  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PythonTidy

2006-11-30 Thread Richie Hindle

[Roberto]
 # vim: set fileencoding=utf-8 :
 ...
 # -*- coding: utf-8 -*-
 ...
 About changing the encoding declaration from vim-style to emacs-style:
 I'll take it as an insult :)

[Laurent]
 This is not emacs-style, this is Python normalized source encoding
 directive for correct interpretation of u... strings by Python
 interpreter.

So is # vim: set fileencoding=utf-8.  Anything matching
coding[:=]\s*([-\w.]+) on the first or second line counts.

 See http://www.python.org/dev/peps/pep-0263/

Yes, you should.  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's going on here?

2006-11-22 Thread Richie Hindle

 What is subclassing adding to the class here?

A __dict__:

 o = object()
 dir(o)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
'__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__str__']
 class C(object): pass
...
 c = C()
 dir(c)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__']

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Re: can't open word document after string replacements

2006-10-24 Thread Richie Hindle

[Antoine]
 I have a word document containing pictures and text. This documents
 holds several 'ABCDEF' strings which serve as a placeholder for names.
 Now I want to replace these occurences with names in a list (members).

[Bruno]
 I don't know how it's named in english, but in french it's (well - it
 was last time I used MS Word, which is quite some times ago???) fusion
 de documents.

Mail Merge?

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Django website

2006-09-01 Thread Richie Hindle

[Antal]
 is there something wrong with django's website (djangoproject.com)
 or I have problems?
 It looks ugly, the css files can't be found, I even cannot download
 the source from there.

It's broken for me too, so it's not a problem at your end.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List match

2006-08-17 Thread Richie Hindle

[Stephen]
 [...] compare 2 lists and generate a new list that does not copy similar
 entries. An example below
 
 list= [apple, banana, grape]
 list2=[orange,banana, pear]
 
 now I want to compare these lits and generate a third list after
 comparison
 
 list3 would be [apple, banana,grape,orange, pear]

Use sets:

 from sets import Set as set  # For compatibility with Python 2.3
 one = [apple, banana, grape]
 two = [orange,banana, pear]
 print list(set(one) | set(two))
['grape', 'apple', 'orange', 'pear', 'banana']

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: undefined SW_MAXIMIZE for ShowWindow function

2006-07-14 Thread Richie Hindle

[Etayki]
 How do I get SW_MAXIMIZE to be defined?

It's in win32con.  Like this:

 from win32con import *
 SW_MAXIMIZE
3

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: undefined SW_MAXIMIZE for ShowWindow function

2006-07-14 Thread Richie Hindle

[Etayki]
 OK, so it it turns out, the window will maximize when SW_MAXIMIZE =3.
 But where can I find some documentation for that?

ShowWindow is a Win32 API call, so Googling within msdn.microsoft.com will
usually get you straight to the relevant documentation:

http://www.google.com/search?q=ShowWindow+site%3Amsdn.microsoft.com

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: undefined SW_MAXIMIZE for ShowWindow function

2006-07-14 Thread Richie Hindle

[Fredrik]
 oops.  thought you were using ctypes, not the pythonwin extensions.

Even when I'm using ctypes I use win32con for the constants, unless
there's some special reason why I need the code to be independent of
pywin32.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting current UNIX uid

2006-07-06 Thread Richie Hindle

[Johhny]
 I am trying to get the user that is running the scripts uid, I have had
 a look at the pwd module and it does not appear to offer that
 functionality. Is there any way within python to get that information ?

It's in the 'os' module:

 import os
 os.getuid()
553

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Having problems with strings in HTML

2006-06-27 Thread Richie Hindle

[Kiana]
 a href=http://bbc.botany.utoronto.ca/[...]?input=max=2[...];

[Lawrence]
 By the way, you _do_ realize that your  characters should be escaped 
 as amp;, don't you?

[Sion]
 No they shouldn't. They part of the url, which is (IIRC) a CDATA
 attribute of the A element, not PCDATA.

The W3C validator at http://validator.w3.org/ disagrees with you.  It
accepts this:

!DOCTYPE HTML PUBLIC -//W3C//DTD HTML
 4.01//ENhttp://www.w3.org/TR/html4/strict.dtd;
htmlheadtitleTest/title/head
body
pa href=http://somewhere.com?a=1amp;b=2;link/a/p
/body/html

but rejects this:

!DOCTYPE HTML PUBLIC -//W3C//DTD HTML
 4.01//ENhttp://www.w3.org/TR/html4/strict.dtd;
htmlheadtitleTest/title/head
body
pa href=http://somewhere.com?a=1b=2;link/a/p
/body/html

saying cannot generate system identifier for general entity b [...] The
most common cause of this error is unencoded ampersands in URLs.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception style (was: calling python functions using variables)

2006-05-19 Thread Richie Hindle

[Cameron]
 try:
 getattr(commands, VARIABLE)()
 except NameError:
 print  sys.stderr, Unknown command, VARIABLE
 
 this situation illustrates the discomfort I consistently
 feel:  how do I know that the NameError means VARIABLE didn't resolve,
 rather than that it did, but that evaluation of commands.VARIABLE()
 itself didn't throw a NameError?  My usual answer:  umm, unless I go
 to efforts to prevent it, I *don't* know that didn't happen.

The 'try' block should only include the code that you expect to fail with
the given exception.  Try this instead:

 try:
 command = getattr(commands, VARIABLE)
 except AttributeError:
 print  sys.stderr, Unknown command, VARIABLE
 else:
 command()

(Aside: I think AttributeError is correct here, not NameError.)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Making all string literals Unicode

2006-05-15 Thread Richie Hindle
Hi,

Am I imagining it, or is there a switch or an environment variable to
make Python treat all string literals as unicode?  I seem to recall
seeing it mentioned somewhere, but now I can't find it anywhere.

Thanks,

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Large Dictionaries

2006-05-15 Thread Richie Hindle

[Chris]
 Has anyone written a fast hash module which is more optimal for
 large datasets ?

PyJudy might be what you're looking for, though I've never used it:

  http://www.dalkescientific.com/Python/PyJudy.html

Judy's key benefits are scalability, high performance, and memory
efficiency. A Judy array is extensible and can scale up to a very large
number of elements, bounded only by machine memory. ... PyJudy arrays
are similar to Python dictionaries and sets.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making all string literals Unicode

2006-05-15 Thread Richie Hindle

[Richie]
 is there a switch or an environment variable to
 make Python treat all string literals as unicode?

[Thomas]
 python -U

Ah!  Thanks.

(I see it's deliberately omitted from the documentation because pieces
of the standard library don't work with it, which is quite reasonable
and explains why I couldn't find it.)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ascii to latin1

2006-05-09 Thread Richie Hindle

[Serge]
 def search_key(s):
 de_str = unicodedata.normalize(NFD, s)
 return ''.join(cp for cp in de_str if not
unicodedata.category(cp).startswith('M'))

Lovely bit of code - thanks for posting it!

You might want to use NFKD to normalize things like LATIN SMALL
LIGATURE FI and subscript/superscript characters as well as diacritics.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ascii to latin1

2006-05-09 Thread Richie Hindle

[Luis]
 When I used the NFD option, I came across many errors on these and
 possibly other codes: \xba, \xc9, \xcd.

What errors?  This works fine for me, printing Ecoute:

import unicodedata
def search_key(s):
de_str = unicodedata.normalize(NFD, s)
return ''.join([cp for cp in de_str if not
unicodedata.category(cp).startswith('M')])
print search_key(u\xc9coute)

Are you using unicode code point \xc9, or is that a byte in some
encoding?  Which encoding?

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


Re: ascii to latin1

2006-05-09 Thread Richie Hindle

[Serge]
 I have to admit that using
 normalize is a far from perfect way to  implement search. The most
 advanced algorithm is published by Unicode guys:
 http://www.unicode.org/reports/tr10/ If you read it you'll understand
 it's not so easy.

I only have to look at the length of the document to understand it's not
so easy.  8-)  I'll take your two-line normalization function any day.

 IMHO It is perfectly acceptable to declare you don't interpret those
 symbols.  After all they are called *compatibility* code points. I
 tried a quater symbol: Google and MSN don't interpret it. Yahoo
 doesn't support it at all. [...]
 if you have character digit two followed by superscript
 digit two; they look like 2 power 2, but NFKD will convert them into
 22 (twenty two), which is wrong. So if you want to use NFKD for search
 your will have to preprocess your data, for example inserting space
 between the twos.

I'm not sure it's obvious that it's wrong.  How might a user enter
2superscript digit 2 into a search box?  They might enter a genuine
superscript digit 2 in which case you're fine, or they might enter
2^2 in which case it depends how you deal with punctuation.  They
probably won't enter 2 2.

It's certainly not wrong in the case of ligatures like LATIN SMALL
LIGATURE FI - it's quite likely that the user will search for fish
rather than finding and (somehow) typing the ligature.

Some superscripts are similar - I imagine there's a code point for the
superscript st in 1st (though I can't find it offhand) and you'd
definitely want to convert that to st.

NFKD normalization doesn't convert VULGAR FRACTION ONE QUARTER into
1/4 - I wonder whether there's some way to do that?

 After all they are called *compatibility* code points.

Yes, compatible with what the user types.  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython and twisted problem

2006-04-26 Thread Richie Hindle

[Chris]
 [we] already tried posting our problem
 on comp.lang.python but we didn't receive a successful reply so I thought I
 would try the mailing list.

[A bit OT but worth pointing out] The mailing list and the newsgroup gateway
to each other - everything sent to one also goes to the other (in theory at
least 8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list.clear() missing?!?

2006-04-13 Thread Richie Hindle

[Mystilleef]
 Lists should have a clear method. But what's shocking is that
 it doesn't seem obvious to others. list.clear() is a whole lot more
 readable, intuitive, flowable and desirable than [the alternatives]

+1 to all of that.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLParser fragility

2006-04-07 Thread Richie Hindle

[Richie]
 But Tidy fails on huge numbers of real-world HTML pages.  [...]
 Is there a Python HTML tidier which will do as good a job as a browser?

[Walter]
 You can also use the HTML parser from libxml2

[Paul]
 libxml2 will attempt to parse HTML if asked to [...] See how it fixes
 up the mismatching tags.

Great!  Many thanks.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLParser fragility

2006-04-05 Thread Richie Hindle

[Daniel]
 You could try HTMLTidy (http://www.egenix.com/files/python/mxTidy.html) 
 as a first step to get well formed HTML.

But Tidy fails on huge numbers of real-world HTML pages.  Simple things like
misspelled tags make it fail:

 from mx.Tidy import tidy
 results = tidy(htmlbodypreeHello world!/pre/body/html)
 print results[3]
line 1 column 7 - Warning: inserting missing 'title' element
line 1 column 13 - Error: pree is not recognized!
line 1 column 13 - Warning: discarding unexpected pree
line 1 column 31 - Warning: discarding unexpected /pre
This document has errors that must be fixed before
using HTML Tidy to generate a tidied up version.

Is there a Python HTML tidier which will do as good a job as a browser?

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


Re: Find similar images using python

2006-03-29 Thread Richie Hindle

[Thomas]
 How can I use python to find images that looks quite similar?

Have you looked at http://www.imgseek.net/ ?  It's an Open Source Python photo
collection manager that does exactly what you're asking for.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial again

2006-03-07 Thread Richie Hindle

[luca]
 Here is my code; why after the readline the port close?
 
 ser = serial.Serial(0)
 [...]
 ser.readline()
 
 Why after this the port close.

[Grant]
 Because the ser object is never used after that point, so it
 get's garbage collected and deleted.

[Steve]
 The ser name is still bound to the serial object, surely?

A piece of that code has been chopped off by someone's newsreader - it's the
body of a method, and ser.readline() is the last line of that method.

-- 
Richie Hindle
[EMAIL PROTECTED]

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python V2.4.2 source code

2006-02-06 Thread Richie Hindle

[John]
 That particular file doesn't include the implementation files for the core
 modules.

*Which* particular file?  Give us a URL.  The source tarball at
http://www.python.org/2.4.2/ (full URL
http://www.python.org/ftp/python/2.4.2/Python-2.4.2.tgz) contains the full
source.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: templates

2006-01-31 Thread Richie Hindle

[Christoph]
 The reason why [PyMeld] is slower than native templates seems clear: You 
 convert the whole page to objects in memory, and then serialize 
 everything back to HTML.

[Peter]
 Unless I'm misremembering, PyMeld is special amongst the total 
 decoupling of code and presentation crowd in that it does *not* convert 
 the whole page to objects in memory, but instead performs its operations 
 using regular-expression substitution, and serializing back to HTML is a 
 trivial operation since it's already serialized.

Peter is right for PyMeld, Christoph is right for PyMeldLite (which is a
variant of PyMeld used by Spambayes, and only works with valid XHTML).

The performance of PyMeld therefore depends on how much work you make it do -
if you insert a couple of values into a page, it's very fast.  If you do lots
and lots of operations on the whole of a large page, it can be very slow
because it's doing complex regular expression operations on a large string.
(It works this way because two of its design goals were to only touch the
parts of the page you ask it to touch, and to work with arbitrary, possibly
invalid, HTML.)

Incidentally, I'm changing PyMeld's license from Sleepycat to BSD, making it
free for use in closed source projects.  (I'll get around to updating the
website RSN 8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: templates

2006-01-31 Thread Richie Hindle

[thakadu]
 The method of generation the table rows was exactly the same as
 the example in the PyMeld documentation

Did you try using toFormatString() to speed it up?  See
http://www.entrian.com/PyMeld/doco.html

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file_name_fixer.py

2006-01-25 Thread Richie Hindle

[Fredrik]
 so re.sub(([_.])\\1+, \\1, newname) replaces runs consisting
 of either a . or an _ followed by one or more copies of itself, with
 a single instance of itself.

...and this:

 def isprime(n):
 return n  1 and not re.match(r'(xx+)\1+$', 'x'*n)

finds prime numbers.

I'll get me coat.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: recursively removing files and directories

2006-01-16 Thread Richie Hindle

[rbt]
 What is the most efficient way to recursively remove files and directories?

shutil.rmtree: http://docs.python.org/lib/module-shutil.html#l2h-2356

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: URL 'special character' replacements

2006-01-09 Thread Richie Hindle

[Claude]
 I have a huge list of URLs. These URLs all have ASCII codes for special
 characters, like %20 for a space or %21 for an exclamation mark.

You need urllib.unquote:

 import urllib
 help(urllib.unquote)
Help on function unquote in module urllib:

unquote(s)
unquote('abc%20def') - 'abc def'.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-22 Thread Richie Hindle

[Paul]
 The web app gets run by Karrigell like a CGI script
 is run by Apache, like a Linux app is run by the Linux kernel.

Paul, you keep making comparisons between Python web frameworks and the
Linux kernel.  Are you aware that there is a special note attached to the
Linux GPL[1] explaining that user-space code is not considered a derived
work of the Linux kernel?  Without that note, user-space code *could* be
considered a derived work of the kernel (obviously, or Linus Torvalds would
not have included the note).  Unless a GPL web framework carries a similar
notice, the comparison doesn't hold up.

[1] http://www.linux-m32r.org/lxr/http/source/COPYING

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Richie Hindle

[Pierre]
 I am Karrigell's author. I have chosen the GPL licence almost at random
 (I saw that the Python licence was GPL-compatible), so I don't mind
 switching to another Open Source licence if the GPL is liable to cause
 problems. Which one would you advice : BSD ? Python licence ? another ?

Well done on being open-minded!

You will hear valid arguments for GPL, LGPL, BSD and other licenses (though
the Python license is unsuitable for anything other than Python - see
http://wiki.python.org/moin/PythonSoftwareFoundationLicenseFaq)

A good solution would be multiple-licensing.  You state that the code is
(for example) triple-licensed under the GPL, LGPL and BSD licenses.  The
user of your code decides which license to obey.  It's no more work for you,
and you can please almost everyone (the only people you won't please are
those who believe that there is One True License, and frankly you should
ignore them - it's your code).

The only downside of allowing people to choose the BSD license rather than
the GPL is that potentially someone can choose the BSD license, improve
Karrigell, ship their product based on the improved code, and not give those
improvements back to the community.  But the Python license allows for this
too, and Python hasn't suffered for it.  IMO choosing a BSD license will get
you more users than GPL, and the benefits of that will outweigh the
potential downside.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.splitext() and case sensitivity

2005-12-21 Thread Richie Hindle

[rbt]
 Is there a way to make os.path.splitext() case agnostic?
 
 def remove_file_type(target_dir, file_type):
  for root, dirs, files in os.walk(target_dir):
  for f in files:
  if os.path.splitext(os.path.join(root, f))[1] in file_type:
  pass
 
 remove_file_type(sysroot, ['.tmp', '.TMP'])

  def remove_file_type(target_dir, file_type):
  [...]
   if os.path.splitext(f)[1].lower() == file_type.lower():
   pass

remove_file_type(sysroot, '.tmp')

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE; Try python beta

2005-12-20 Thread Richie Hindle

[Claudio]
 The page doesn't work for me in MSIE (I am on a Windows system)

[Mike]
 Yeah, I know. I poked at it briefly, but couldn't figure out what was
 goiing on. MSIE on the Mac doesn't work at all (no AJAT), and I don't
 have regular access to a Windows box to try it on.

I think it's your JavaScript '\r' processing that's broken.  Certainly the
error (unexpected EOF while parsing) is consistent with having a \r on the
end of the expression.  Won't this:

if (input.length == 1)

always fail in the case where the user has typed a newline?  I'd ditch that
code and do it at the server end:

expr = expr[4:].strip()

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonic equivalent of upvar?

2005-12-20 Thread Richie Hindle

[David]
 I'm trying to write something with the same brevity 
 as perl's one-liner
 
 eval \$$1=\$2 while @ARGV  $ARGV[0]=~ /^(\w+)=(.*)/  shift;

import sys, re
for arg in sys.argv[1:]:
if re.match(r'\w+=.*', arg):
exec arg
else:
break

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Disable 'windows key'

2005-12-20 Thread Richie Hindle

[Paul]
 I wonder if there might be a way of disabling [the windows key] within
 my program.

IHateThisKey will do this globally:

  http://www.bytegems.com/ihatethiskey.shtml

The free edition blocks the Windows key, and the paid one ($10) lets you
control all kinds of keys in quite flexible ways.  You can still use the
Windows key as a modifier (as in Windows+E for Explorer).

No affiliation other than as a happy customer.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE; Try python beta

2005-12-20 Thread Richie Hindle

[Richie]
 I think it's your JavaScript '\r' processing that's broken.  Certainly the
 error (unexpected EOF while parsing) is consistent with having a \r on the
 end of the expression.

[Mike]
 Python doesn't care about the trailing newline.

That's a carriage return, not a newline:

 eval(1+2\r)
Traceback (most recent call last):
  File stdin, line 1, in ?
  File string, line 1
1+2
  ^
SyntaxError: unexpected EOF while parsing

 My assumption is that if splitting on '\n' leaves us with one
 thing, we may have gotten a string that used \r for newlines

Ah, OK.  Your comment talks about DOS - that won't happen on DOS (or
Windows) which uses \r\n.  I don't know about the Mac.  But the \r\n pair
isn't handled by your code - strip() on the server side will make it work if
that's the problem:

 eval(1+2\r.strip())
3

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Disable 'windows key'

2005-12-20 Thread Richie Hindle

 But can it change Fn key mapping?

I don't think so, no.  There's no obvious user interface for that, anyway.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why and how there is only one way to do something?

2005-12-15 Thread Richie Hindle

[Steve]
 Since Python is Turing-complete

Is there some equivalent of Godwin's Law that we can invoke at this
point?  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32com 'catastrophic failure'

2005-12-06 Thread Richie Hindle

[gerd]
 com_error: (-2147418113, 'catastrophic failure', None, None)

The last time I saw this error it was because I'd created a control instance
but hadn't initialised it before trying to use it.  I had to do something
like this (apologies for the C++):

IPersistStreamInit* IPSI = NULL;
pUnknown-QueryInterface(IID_IPersistStreamInit, (void**) IPSI);
IPSI-InitNew();
IPSI-Release();

(pUnknown is the IUnknown of my newly-created control; error checking
omitted).

There are probably a million reasons why you might be getting that error,
but if this doesn't help then at least you'll have narrowed it down to
999,999.  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compare list

2005-11-15 Thread Richie Hindle

[Shi]
 Yes, i am using python 2.3,
 I have used from sets import *
 but still report the same error:
   Traceback (most recent call last):
 File interactive input, line 1, in ?
   NameError: name 'set' is not defined

It's 'Set', not 'set'.  Try this:

 import sets
 dir(sets)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compare list

2005-11-15 Thread Richie Hindle
Ben,

 But the logic output is wrong.
 from sets import Set as set
 lisA=[1,2,5,9]
 lisB=[9,5,0,2]
 lisC=[9,5,0,1]
 def two(sequence1, sequence2):
 set1, set2 = set(sequence1), set(sequence2)
 return len(set1.intersection(set2)) == 2
 print two(lisA,lisB)
 False(should be true!)

Slow down.  The intersection of A and B is [2, 5, 9].

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: generate HTML

2005-11-14 Thread Richie Hindle

[ss2003]
 I am stuck at above after doing a lot of f.write for every line of HTML
 . Any betterways to do this in python?

See the Templating Engines section of
http://wiki.python.org/moin/WebProgramming - I hope you have a few hours to
spare!  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Goto XY

2005-11-09 Thread Richie Hindle

[ale.of.ginger]
 WConio.gotoxy(10,10)
 error: GetConOut Failed

Are you running at a Windows Command Prompt, or in an IDE?  As I understand
it, WConio will only work in a Windows Command Prompt.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing a dll from Python

2005-10-20 Thread Richie Hindle

[Daniel]
 I tried the ctypes module.

ctypes is the right way to do it.  You need to post your code and whatever
errors you received.  Here's an example of using ctypes to call a DLL:

 from ctypes import *
 windll.user32.MessageBoxA(None, Hello world, ctypes, 0);

You use windll for stdcall functions (eg. the Windows API) and cdll for
cdecl functions.  I don't know which one VB defaults to.  If you get it
wrong, ctypes will give you an error talking about using the wrong calling
convention.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UI toolkits for Python

2005-10-18 Thread Richie Hindle

[Ken]
 Web interfaces are missing a lot more than this. Here are just a few  
 things that cannot be done with web-based interfaces (correct me  
 where I'm wrong):
 
 1) A real word processor.

http://www.writely.com/
http://www.goffice.com/

 2) Keybindings in a web application

http://rememberthemilk.com/
Google Keys (but what happened to it?  It's disappeared!)

 3) Drag and drop

http://www.walterzorn.com/dragdrop/dragdrop_e.htm

http://qooxdoo.oss.schlund.de/demo/release/public/test/user/Index.html
(pick Drag and Drop N from the dropdown on the right hand side of the top
bar)

 4) Resizable windows (i.e. not the browser window) within the  
 application.

http://qooxdoo.oss.schlund.de/demo/release/public/test/user/Index.html
(pick Window N from the dropdown on the right hand side of the top bar)

http://www.bindows.net/ (click Click for a quick DEMO)

 5) Anything other than absolutely trivial graphical programs.

Not sure what you mean by this... Google maps?

 web interfaces are still basically forms that can contain  
 buttons, checkboxes, text fields, and a few other basic controls. I  
 wish it were otherwise.

It *is* otherwise.  You should follow the Ajaxian weblog here:
http://www.ajaxian.com/

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jargons of Info Tech industry

2005-10-14 Thread Richie Hindle

  Not so: you disable Java, Javascript and plugins.  You leave the ability 
  to format, colour and hint documents.  This is not /that/ difficult.
 
 Don't forget disabling Unicode.  

http://news.netcraft.com/archives/2005/02/15/firefox_to_disable_idn_support_as_phishing_defense.html

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When someone from Britain speaks, Americans hear a British accent...

2005-10-07 Thread Richie Hindle

[Steve]
 and yes, I split that infinitive just to 
 annoy any pedants who may be reading

[Steven]
 *Real* pedants will know that English is not Latin, does not follow the
 grammatical rules of Latin, and that just because split infinitives are
 impossible -- not forbidden, impossible -- in Latin is no reason to forbid
 them in English.

Your previous post to this thread was chock-full of split nominatives: The
Hollywood voice, the specific regional accent, the English-speaking
world, the original French.  And you call yourself a grammarian.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When someone from Britain speaks, Americans hear a British accent...

2005-10-07 Thread Richie Hindle

[Richie]
 Your previous post to this thread was chock-full of split nominatives: The
 Hollywood voice, the specific regional accent, the English-speaking
 world, the original French.  And you call yourself a grammarian.

[Steve]
 I am presuming this post was meant to be a joke?

It was.

 No smileys, though, so you force us to make up our own minds.

Yes.  8-)

 Or is the green tomato also unacceptable?

It ought to be considered unacceptable by people who think that to
correctly apply is unacceptable, which is the point that Stephen was
making:

 *Real* pedants will know that English is not Latin, does not follow the
 grammatical rules of Latin, and that just because split infinitives are
 impossible -- not forbidden, impossible -- in Latin is no reason to forbid
 them in English.

Split nominatives like the green tomato are also impossible in Latin, but
no-one seems to object to their use in English.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Excel library with unicode support

2005-10-05 Thread Richie Hindle

[Mike]
 Is there a python library, that is able to create Excel files with
 unicode characters.

pyExcelerator claims to do this, but I've never used it.

  http://sourceforge.net/projects/pyexcelerator/

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Not defined

2005-10-03 Thread Richie Hindle

[Rob]
  from cgkit import *
  Sphere()
 Traceback (most recent call last):
   File interactive input, line 1, in ?
 NameError: name 'Sphere' is not defined

Do you have a file of your own called cgkit.py?  You're probably importing
that rather than the real thing.  Try this:

 import cgkit
 print cgkit.__file__
 dir(cgkit)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reply-To header

2005-10-03 Thread Richie Hindle

[Andrew]
 Is it just me, or does python-list@python.org not send with a Reply- 
 To header?

It's not just you.  I don't get one either.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Info] PEP 308 accepted - new conditional expressions

2005-09-30 Thread Richie Hindle

[Fredrik]
  X if C else Y
 
 hopefully, only one of Y or X is actually evaluated ?

Yes.  From Guido's announcement at
http://mail.python.org/pipermail/python-dev/2005-September/056846.html:

 The syntax will be
 
 A if C else B
 
 This first evaluates C; if it is true, A is evaluated to give the
 result, otherwise, B is evaluated to give the result.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rather unpythonic way of doing things

2005-09-29 Thread Richie Hindle

[Peter]
 http://www.pick.ucam.org/~ptc24/yvfc.html

Beautiful!  Greenspun's Tenth Rule[1] performed before your very eyes!  (Not
quite, because you started with Python so you were already half way there.
And yours probably isn't buggy.  8-)

[1] http://en.wikipedia.org/wiki/Greenspun's_Tenth_Rule

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A quick c.l.p netiquette question

2005-09-29 Thread Richie Hindle

[Peter]
 Does it really have to be 158 lines to demonstrate these few issues?

I think you missed the other Peter's second post, where he points to his
program: http://www.pick.ucam.org/~ptc24/yvfc.html

I didn't read every one of his 158 lines, but his code is pure poetry, or
possibly triple-distilled evil, depending on your point of view.  158 lines
very well spent either way!

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rather unpythonic way of doing things

2005-09-29 Thread Richie Hindle

[Peter]
 http://www.pick.ucam.org/~ptc24/yvfc.html

[Jeff]
 Yuma Valley Agricultural Center?
 Yaak Valley Forest Council?

I went through the same process.  My guess is Yes, Very F'ing Clever.
Peter?

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C#3.0 and lambdas

2005-09-23 Thread Richie Hindle

[amk]
 Similar things happen on the catalog SIG: people suggest, or even implement,
 an automatic package management system, But bring up the question of whether
 it should be called PyPI or Cheeseshop or the Catalog, and *everyone* can make
 a suggestion.

This is known as the bike shed effect:

   http://linuxmafia.com/~rick/lexicon.html#bikeshed

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCEMENT: The ring of the friendly serpent in business suite: Python, Zope, Plone

2005-09-12 Thread Richie Hindle

[Miklos]
 The ring of the friendly serpent in business suite: Python, Zope, Plone
 http://www.jegenye.com/

Did you mean business suit?

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code run from IDLE but not via double-clicking on its *.py

2005-09-02 Thread Richie Hindle

[Richie]
 Now what does the python Command Prompt say?

[n00m]
 It says... NOTHING! It just DISAPPEARS!

That's the strangest thing I've heard all week.  8-)

OK, one more thing to try - redirect the output of Python to some files
and see whether anything useful appears in the files:

C:\ d:
D:\ cd \python23
D:\ python d:\python23\socket6.py  out.txt 2 err.txt

Does anything appear in d:\python23\out.txt or d:\python23\err.txt?

[Dennis]
 I'd be tempted to blame the VBS script then... 

n00m, can you post the vbs?

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code run from IDLE but not via double-clicking on its *.py

2005-09-01 Thread Richie Hindle

[n00m]
 D:\python23\python d:\python23\socket6.py [Enter]
 
 It's OK so far. Python code is launched and starts listening
 to port 1434 (see the code below; it's the same code as in my
 neibouring topic).
 Now I launch a vbs script (which will connect to port 1434).
 I.e. I just double-click my.vbs file.
 And... voila! In a moment  silently console window closes
 without any error messages (or I just don't see them).
 But VBS reports a network error. Tested on win2k and win98.

That sounds impossible, so I must be misunderstanding something.  What
happens when you do this (forgive me if this seems patronising, but I'm
missing something about the way you're working)

1. Start a new Command Prompt via Start / Programs / Accessories / Command
Prompt (or the equivalent on your machine)

2. Type the following: d:\python23\python d:\python23\socket6.py [Enter]

3. Double-click your .vbs file in Windows Explorer.

Now what does the python Command Prompt say?  By your description above,
it sounds like it disappears, but that ought to be impossible.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SpamBayes wins PCW Editors Choice Award for anti-spam software.

2005-09-01 Thread Richie Hindle

[Alan]
 SpamBayes has won the Personal Computer World (pcw.co.uk) Editors Choice 
 award for anti-spam software

Yay!  Do we get one of those cheesy medals to put on our website?  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code run from IDLE but not via double-clicking on its *.py

2005-08-31 Thread Richie Hindle

[n00m]
 WHY ON THE EARTH 'module' object has no attribute 'AF_INET' ???

Because you have a socket.py in d:\python23\00 which is being picked up
instead of Python's own socket module.  You shouldn't give your modules
the same name as Python's own modules.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code run from IDLE but not via double-clicking on its *.py

2005-08-31 Thread Richie Hindle

[n00m]
 Funnily but I still can't get the code working... WITHOUT IDLE.
 I think it's because of import thread line. Seems something
 wrong with opening this module. In IDLE it works OK.

It's difficult to diagnose your problem with so little information. Please
post:

 o The command you're typing into the command prompt
 o The error message you're getting
 o The full traceback
 o The code you're trying to run, or if it's too big then the piece that
   the last line of the traceback refers to

Thanks,

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does any1 use pcapy module on win32 platforms?

2005-08-26 Thread Richie Hindle

[billiejoex]
 Hi. I'm trying to use pcapy module on Windows XP prof sp2 [...]
 On Windows machines the findalldevs() function (an output on the bottom)
 gives an unicode object that can't be processed by open_live function
 that tipically accept strings.
 
  pcapy.findalldevs()
 [u'\u445c\u7665\u6369\u5c65\u504e\u5f46\u6547\u656e\u6972\u4e63\u6964\u5773\u6e6
 [...]

For what it's worth, I can run that on my XP Professional SP2 machine and
it works perfectly:

 pcapy.findalldevs()
[u'\\Device\\NPF_{15310604-FCFC-4016-9D36-14DAA948A600}',
 u'\\Device\\NPF_{62280C1D-DC5C-42AF-BA0F-6BDB48418CA5}']

I'm using WinPcap 3.0.  My packet.dll is stamped as version 3.0.0.18.
Maybe you're running a different version?

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Network performance

2005-08-24 Thread Richie Hindle

[Roland]
 The client sends a number of lines (each ending with \n) and ends one  
 set of lines with a empty line.
 [...]
 I was surprised to find that the performance was [poor].

Are you sending all the lines in a single packet:

 sock.send('\n'.join(lines))

or sending them one at a time:

 for line in lines:
   sock.send(line + '\n')

?  If the latter, you are probably experiencing Nagle delays.  Google
will furnish you with any number of explanations of what that means, but
in summary, one end of a TCP/IP connection should never send two
consecutive small packets without receiving a packet from the other end.
('Small' typically means less than about 1400 bytes.)  Each time you do
that, you'll suffer an artificial delay introduced by TCP/IP itself.

-- 
Richie Hindle 
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The ONLY thing that prevents me from using Python

2005-08-24 Thread Richie Hindle

[Chris]
 Not to be a shill, but I'd be interested in testimonials on 
 http://linode.org/
 I wonder if virtualization is the next killer app.
 Certainly blows the WTF my ISP? question away...

I can't speak for linode.org, but I have a Xen VPS from rimuhosting.com
and it's early days but so far I've been very impressed.  It's $19/mo
(normally $20 but they kindly gave me a 5% Open Source Developer discount)
which is not that much more than a decent shared hosting account.  You
need to be comfortable with administering your own Linux box, but these
days that's not difficult.  (NB. entrian.com is not running on it yet.)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Database of non standard library modules...

2005-08-19 Thread Richie Hindle

[Steve]
 While cheeseshop might resonate with the Monty Python fans I have to
 say I think the name sucks in terms of explaining what to expect. If I
 ask someone where I can find a piece of code and the direct me to the
 cheese shop, I might look for another language.

+1

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .pth files

2005-08-09 Thread Richie Hindle

[Sylvain]
 I've some questions regarding pth files (which btw are undocumented in the
 python reference, is this intentional ?)

http://google.com/search?q=site:docs.python.org%20pth

The first hit explains how .pth files work (although it's the sort of
documentation that makes Xah Lee explode with fury).

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py: a very dangerous language

2005-08-01 Thread Richie Hindle

[Harald]
 Always go to bed exactly when you want to write the first lambda.

[Peter]
 Eureka. The Twentieth Pythonic Thesis has finally surfaced.

+1 QOTW.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Lots of pdf files

2005-07-22 Thread Richie Hindle

[Duncan]
 a mere $29.90, except it is GPL'd so I'm not sure what the money is for

Tech support [...] free forever for registered users.

But I've often wondered whether you could charge for mass-market GPL software
simply because your ordinary punter doesn't know what the GPL is, and doesn't
mind paying a small amount of money for decent software.  Whether it's
ethical, given that presumably the thing is GPL because it inherits GPL code
from other developers, I don't know.  Certainly the GPL itself has no
objection to charging for binaries provided you ship the source as well.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Better console for Windows?

2005-07-04 Thread Richie Hindle

[Richie]
 does anyone know of a way to scroll a Command Prompt window using the 
 keyboard?

[Bengt]
 Alt-spacebar, e, l, (uparrow/downarrow)*, Esc
  (lower case L)--^   ^--does the scrolling. Esc ends the 
 scrolling mode.

[Christos]
 Damn! it says Scroll in there in the system menu, doesn't it?  Talk
 about blindness...

aolMe too!/aol

Many thanks, Bengt.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: When someone from Britain speaks, Americans hear a British accent...

2005-07-04 Thread Richie Hindle

[Chan]
 T can be silent in England too ..
 
 frui'
 cricke'

[Stephen]
 Both of those words (fruit and cricket) have the letter T sounded.
 
 Stephen (Nationality: English).

Not necessarily - in my native accent they'd be replaced with glottal stops.

Richie (Nationality: West Yorkshire 8-)

(Having a daughter has improved my speech - I'm much more careful about
enunciating my words properly so that she doesn't pick up my bad habits.)

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: MS Compiler to build Python 2.3 extension

2005-06-30 Thread Richie Hindle

[woodsplitter]
 MS Visual C++ 6 is indeed the compiler that the python.org
 distributions are built with

Just to add back some context for people not following the thread: this is
Python 2.3 we're talking about.  2.4 is built with Visual Studio.NET.

 but MinGW works fine too.  In fact, the
 code generated by MinGW-GCC 3.4.4 outpaces that generated by MSVC++ 6.0
 by a considerable margin in some of my performance-critical extensions,
 and the size of the binaries is often smaller.

Interesting!

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Better console for Windows?

2005-06-29 Thread Richie Hindle

[Christos, on widening the Windows Command Prompt]
 Hm... right-click the cmd.exe window's title bar (or click on the
 top-left icon, or press Alt-Space), go to Properties, Layout tab, Window
 Size, Width.

Just to take this thread *completely* off-topic: does anyone know of a way
to scroll a Command Prompt window using the keyboard?

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: MS Compiler to build Python 2.3 extension

2005-06-29 Thread Richie Hindle

[Gary]
 I recenly built a C API Python extension for Python 2.3
 on OS X, and now I need to build it for Windows.  Will
 [MS Visual Studio Pro 6.0] do the trick?

Yes.  That's exactly the compiler that Python 2.3 itself, and most 2.3
extensions, were built with.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: FlashMX and Py2exe doesn't fly...

2005-06-28 Thread Richie Hindle

[Jim]
 They did it with Gush: (I think)
http://2entwine.com/
 
 It's a py program that embeds Flash very nice.

Very nice indeed!  Does anyone know any details about the technology they
used for this?  It appears to be closed source, and I couldn't see anything
on their site about the architecture (other than a list of credits that
includes ctypes, win32all, Macromedia and SciTE|Flash).

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Is there something similar to ?: operator (C/C++) in Python?

2005-06-24 Thread Richie Hindle

[Dave Brueck] 
 Please keep the discussion civil; please help keep c.l.py a nice place to 
 visit.

+1

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Posting a reply to a post in an existing thread

2005-06-09 Thread Richie Hindle

[Chad]
 What I need to know is, what do I put in either the TO field, the CC
 field, or the SUBJECT field for the list to see my message as a reply to
 an existing post in a thread and not a new thread.

You should use your email client's Reply feature to reply to one of the
existing messages in the thread.  This will put the right things in the
Subject:, To: etc. fields, and also include a hidden header field called
References: which refers to the post you're replying to.  Then when
someone receives your message, their email client will see the References:
header and know that your reply was part of the same thread as the message
to which you replied.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Launch file in Notepad

2005-05-12 Thread Richie Hindle

[George]
 b1=c:\test.txt

With this code, your problem is the embedded tab as you say.  Use either
rc:\test.txt or c:\\test.txt.  However, if this is true:

 By the way, b1 comes from a command line parameter, so the user enters 
 c:\test.txt as command line parameter.

then there will be no embedded tab.  How are you prompting the user?  When
I run this:

import os
b1=raw_input(Enter a filename: )
os.system('notepad.exe ' + b1)

and enter c:\test.txt, it works as expected.

[Brian]
 There are several ways, but the preferred solution is to switch the 
 slash direction: c:/test.txt. Python's smart enough to notice its 
 running on Windows and do the right thing with the slash.

In fairness to Windows, I don't believe Python does anything special here.
Windows itself happily accepts either forward slash or backslash at the OS
level - it's only the shells (explorer.exe or to a lesser extent cmd.exe)
that don't accept forward slashes.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Problems with csv module

2005-05-11 Thread Richie Hindle

[Florian]
 I've one problem using the csv module.
 The code: 
 
 self.reader = csv.reader(f, delimiter = ,)
 
 works perfectly. But when I use a variable for delimiter:
 
 self.reader = csv.reader(f, delimiter = Adelimiter)
 
 I get the traceback:
 
 
 File /home/florian/visualizer/ConfigReader.py, line 13, in __init__
 self.reader = csv.reader(f, delimiter = Adelimiter)
 TypeError: bad argument type for built-in operation

Is this your problem?:

 Adelimiter = u','
 reader = csv.reader(f, delimiter=Adelimiter)
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: bad argument type for built-in operation
 print type(Adelimiter)
type 'unicode'

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Problems with csv module

2005-05-11 Thread Richie Hindle

[Florian]
 You mean that csv.reader can't work with unicode as the delimiter parameter?

Exactly.  http://www.python.org/doc/2.3.5/lib/module-csv.html says:

Note: This version of the csv module doesn't support Unicode input. Also,
there are currently some issues regarding ASCII NUL characters. Accordingly,
all input should generally be printable ASCII to be safe. These restrictions
will be removed in the future. 

That note is still there in the current development docs, so it looks like
it hasn't yet been fixed.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Problems with csv module

2005-05-11 Thread Richie Hindle

[Florian]
 How can I convert Unicode to ASCII?

You're writing code using Unicode and you don't know how to convert it
ASCII?  You need to do some reading.  Here are a few links - Google can
provide many more:

  http://docs.python.org/tut/node5.html#SECTION00513
  http://diveintopython.org/xml_processing/unicode.html
  http://www.jorendorff.com/articles/unicode/python.html

The short answer to your question is this:

 U = u'My string'
 A = U.encode('ascii')
 print U, type(U), A, type(A)
My string type 'unicode' My string type 'str'

but you should really do some reading.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Strip white spaces from source

2005-05-10 Thread Richie Hindle

[qwweeeit]
 If someone is interested (I think nobody...) I can give my solution.

I'd be interested to see it, certainly.

It's always a good idea to post your solution, if only for future reference.
It's frustrating to do a Google Groups search for a problem and find that
someone else has solved it but without saying *how*.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Strip white spaces from source

2005-05-09 Thread Richie Hindle

[qwweeeit]
 I need to limit as much as possible the lenght of a source line,
 stripping white spaces (except indentation).
 For example:
 .   .   max_move and AC_RowStack.acceptsCards ( self, from_stack, cards
 )
 must be reduced to:
 .   .   max_move and AC_RowStack.acceptsCards(self,from_stack,cards)

Here's a script that does some of what you want (stripping whitespace within
the three types of brackets).  It was written to make code more compliant with
the Python style guide.

--- unspace.py ---

Strips spaces from inside brackets in Python source code, turning
( this ) into (this) and [ 1, ( 2, 3 ) ] into [1, (2, 3)].  This makes
the code more compliant with the Python style guide.  Usage:

  unspace.py filename

Output goes to stdout.

This file is deliberately written with lots of spaces within brackets,
so you can use it as test input.


import sys, re, token, tokenize

OPEN = [ '(', '[', '{' ]
CLOSE = [ ')', ']', '}' ]

class UnSpace:
Holds the state of the process; onToken is a tokenize.tokenize
callback.

def __init__( self ):
self.line = None # The text of the current line.
self.number = -1 # The line number of the current line.
self.deleted = 0 # How many spaces have been deleted from 'line'.

self.last_srow = 0
self.last_scol = 0
self.last_erow = 0
self.last_ecol = 0
self.last_line = ''

def onToken( self, type, tok, ( srow, scol ), ( erow, ecol ), line ):
tokenize.tokenize callback.
# Print trailing backslashes plus the indent for new lines.
if self.last_erow != srow:
match = re.search( r'(\s+\\\n)$', self.last_line )
if match:
sys.stdout.write( match.group( 1 ) )
sys.stdout.write( line[ :scol ] )

# Print intertoken whitespace except the stuff to strip.
if self.last_srow == srow and \
   not ( self.last_type == token.OP and self.last_tok in OPEN ) and \
   not ( type == token.OP and tok in CLOSE ):
sys.stdout.write( line[ self.last_ecol:scol ] )

# Print the token itself.
sys.stdout.write( tok )

# Remember the properties of this token.
self.last_srow, self.last_scol = ( srow, scol )
self.last_erow, self.last_ecol = ( erow, ecol )
self.last_type, self.last_tok = type, tok
self.last_line = line

def flush( self ):
if self.line is not None:
sys.stdout.write( self.line )


if __name__ == '__main__':
if len( sys.argv ) != 2:
print __doc__
else:
file = open( sys.argv[ 1 ], 'rt' )
unSpace = UnSpace()
tokenize.tokenize( file.readline, unSpace.onToken )
unSpace.flush()

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Python documentation moronicities (continued)

2005-04-26 Thread Richie Hindle

[Xah]
 I have produced my doc.
 ( http://xahlee.org/perl-python/python_re-write/lib/module-re.html )
 
 isn't there a hundred dollars due to me?

I don't have the time to write a full review of your version, but for the
record I've compared it with the original and I don't think it's a
significant improvement (apart from the title - String Pattern Matching
is a better title than Regular expression operations).  (And no, I'm not
sure I could do any better, but that's not the question.)

[Xah]
 it is published and announced here on April 18th.

[Steve]
 I'll have to take your word for that.

Xah is right - I have a copy here of his message of 18th April, saying i
have rewrote the Python's re module documentation..

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Compute pi to base 12 using Python?

2005-04-14 Thread Richie Hindle

[Dan]
 Now you've got me curious.  Why would an artist want the first 3003
 digits of pi to the base 12?

[Dick]
 He says,
 Do you know how I can get base12 pi?
 Because the chromatic scale is base12.
 c c# d d# e f f# g g# a a# b

He should read Douglas Adams' fictional essay Music and Fractal
Landscapes, from Dirk Gently's Holistic Detective Agency:

 I believe that there must be a form of
  music inherent in nature, in natural objects, in the patterns
  of natural processes.  A  music that would be as deeply
  satisfying as any naturally occurring beauty [...]

You can see the text here:


http://66.102.9.104/search?q=cache:3Ni6gRXCcJgJ:tash.dns2go.com/FTP/P800/Books%2520txt/Douglas%2520Adams%2520-%2520Dirk%2520Gently%27s%2520Holistic%2520Detective%2520Agency.txt+%22douglas+adams%22+%22Music+and+Fractal+Landscapes%22hl=en

or via this tinyurl:

  http://tinyurl.com/6ugnk

(Search within that page for the phrase Music and Fractal Landscapes.
Or Google for it, which is how I found the link.)

-- 
Richie Hindle
[EMAIL PROTECTED]

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


  1   2   >