Re: Best way to create a copy of a list

2006-04-04 Thread Frank Millman

Fredrik Lundh wrote:
> Frank Millman wrote:
>
> > I have found two ways of doing it that seem to work.
> >
> > 1 - row = table[23][:]
> >
> > 2 - row = []
> >  row[:] = table[23]
> >
> > Are these effectively identical, or is there a subtle distinction which
> > I should be aware of.
> >
> > I did some timing tests, and 2 is quite a bit faster if 'row'
> > pre-exists and I just measure the second statement.
>
> quite a bit ?  maybe if you're using very short rows, and all rows
> have the same length, but hardly in the general case:
>
> python -mtimeit -s "data=[range(100)]*100; row = []" "row[:] = data[23]"
> 10 loops, best of 3: 5.35 usec per loop
>
> python -mtimeit -s "data=[range(100)]*100" "row = data[23][:]"
> 10 loops, best of 3: 4.81 usec per loop
>
> (for constant-length rows, the "row[:]=" form saves one memory
> allocation, since the target list can be reused as is.  for longer rows,
> other things seem to dominate)
>
> 

Interesting. My results are opposite.

python -mtimeit -s "data=[range(100)]*100; row = []" "row[:] =
data[23]"
10 loops, best of 3: 2.57 usec per loop

python -mtimeit -s "data=[range(100)]*100" "row = data[23][:]"
10 loops, best of 3: 2.89 usec per loop

For good measure, I tried Rune's suggestion -

python -mtimeit -s "data=[range(100)]*100" "row = list(data[23])"
10 loops, best of 3: 3.69 usec per loop

For practical purposes these differences are immaterial - I do not
anticipate huge quantities of data.

If they are all equivalent from a functional point of view, I lean
towards the second version. I agree with Rune that the third one is
nicer to read, but somehow the [:] syntax makes it a bit more obvious
what is going on.

Thanks

Frank

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


Re: wxpython in action book

2006-04-04 Thread momobear

Butternut squash wrote:
> any recommendations? any opinions?
>
> I want to learn to program in python and need a gui reference. I'll be
> updating various mysql tables. I have most of the code ready to roll by
> using a command line. I need put some lipstick on my project.
>
> pyQT seems viable but there is not really a good reference and tutorial
>
> so now I'm considering wxPython and saw this book and I'm wanting to know if
> if's even worth spending my $40 on.
>
> Thanks.
what about pygtk,  do u have any idea ab it?

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


Re: Find similar images using python

2006-04-04 Thread Christos Georgiou
On Fri, 31 Mar 2006 15:10:11 -0800, rumours say that Scott David Daniels
<[EMAIL PROTECTED]> might have written:

>Christos Georgiou wrote:
>>  I did make a module based on imgseek, and together with PIL,
>> I manage my archive of email attachments (it's incredible how many
>> different versions of the same picture people send you: gif, jpg
>> in different sizes etc) and it works fairly well.
>> 
>> E-mail me if you want the module, I don't think I have it currently online
>> anywhere.

>This sounds like a great recipe for the cookbook:
> http://aspn.activestate.com/ASPN/Cookbook/Python

Actually, it should go to the CheeseShop, since it is a python module that
is a bridge between PIL and the C module (I don't believe multi-file modules
are appropriate for the cookbook, but ICBW); however, my web space is out of
reach for some months now (in a web server at a previous company I worked
for), and I'm in the process of fixing that :)
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Registration Code

2006-04-04 Thread Ryan Ginstrom
> On Behalf Of Dave Mandelin:
> Second, I hear that in general it is very difficult to make a
> time-limited demo, because the code has to be all there, so all a
> cracker has to do is bypass the "if". It seems that even this method
> won't work for that. Do you know of any way to make time limiting
> secure?

If the application is to be Windows only (and I assume this from statement
about using py2exe), one fairly secure and easy method is to put some
critical functionality into a plain DLL or (compiled) COM module, and use a
commercial software-protection program like Armadillo on that. Armadillo is
much more secure than just about anybody could make on their own, and instead
of wasting time (and probably introducing bugs) implementing it yourself, you
can use that time improving your application. Armadillo handles all sorts of
protection schemes, from time limitations to machine locking and "crippling,"
and combinations thereof. (I have no commercial or other interest in
Armadillo.)

Another tack to take is to maintain content updates on a Website for
download. The Website would check the registration code. This foils most
cracking methods, and even shared codes can be blacklisted when found. Of
course, this only works for certain types of applications, but when it is
possible it has the benefits of not requiring significant changes to your
application, remaining transparent to the user, and most importantly, not
antagonizing legitimate users. And of course, it would enable cross-platform
(commercial) use of your application. A variation of this strategy is the
subscription model.

Regards,
Ryan

---
Ryan Ginstrom
http://ginstrom.com 

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


Framework/module for generating HTML documentation

2006-04-04 Thread Ryan Ginstrom
I have been maintaining a body of documentation in plain HTML files.

I would now like to automate the generation of the HTML files. Maintaining
the HTML files now is tedious and error prone, because every time I
move/remove/add a section, I have to renumber the following sections and
update my internal links.

I have looked at some of the HTML-generation frameworks, but the selection is
somewhat bewildering, and most also seem geared to generating dynamic or
static content for Websites. I guess what I am looking for is a Wiki-like
documentation generation engine, but generating a bunch of statically linked
files.

E.g., I want to go from something like this:
Introduction
Some text
Getting Started
Some text
Installation
Some text. See Getting Started for details.

To this:
[index.html]
Contents
1. Introduction
2. Getting Started

2.1. Installation


[1.html]
1. Introduction
Some text
Contents  Next

[2.html]
2. Getting Started
Some text
Prev  Contents  Next

[2_1.html]
2.1. Installation
Some text. See Getting Started for details.
Prev  Contents  Next

If someone can recommend a framework/module that will help me achieve this, I
would greatly appreciate it. I could do it from scratch, but if this has been
tackled before (as I suspect it has), I'd like to stand on those developers'
shoulders .

Regards,
Ryan

---
Ryan Ginstrom

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


Re: Loading a default browser under Windows

2006-04-04 Thread Philippe Martin
BartlebyScrivener wrote:

> Philippe,
> 
> import webbrowser
> 
> webbrowser.open("http://groups.google.com/group/comp.lang.python";)
> 
> rpd

Many thanks,

Philippe

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


Standalone Python functions in UML?

2006-04-04 Thread Roman Susi
Hi!

Out of curiosity, how do I draw functions outside classes with UML? How 
module could be drawn in this case?

More theoretical question is if I create classes on the fly, how UML can 
reflect that?

(I know that Python code itself is best at communication design ideas, 
but there are some people which prefer to talk UML.)

(Have not found anything relevant with google)

Thanks!

Regards,
Roman Suzi

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


Re: what's going on here?

2006-04-04 Thread Ant
You are along the right lines. Try printing out the content of each URL
- one of the pages will match your expression, but has additional
instructions... I think you are reaching the end of their false trail
when you get None returned from the url.

The set of pages themselves are the linked list - each contains a
reference to the next element in the sequence. You don't need one to
solve the problem, the problem *is* the linked list!

An example of a linked list in Python is the following if you are
interested:


class Element (object):
next = None
def __init__(self, content):
self.content = content

class LinkedList (object):
first = None
last = None

def add(self, item):
elmnt = Element(item)
if not self.first:
self.first = elmnt
if self.last:
self.last.next = elmnt
self.last = elmnt
def __iter__(self):
current = self.first
while current:
yield current.content
current = current.next

ll = LinkedList()

for i in range(10):
ll.add(i)

for x in ll:
print "Res: %s" % x

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


Re: Python and microsoft outlook-using com, can I interact with msoutlook?

2006-04-04 Thread Daniel Dittmar
[EMAIL PROTECTED] wrote:
> Hi All,
> I know that Microsoft Exchange has a com interface, CDO, but I can't seem to
> find one for Microsoft outlook.
> does anyone have code snippets for using msoutlook and python, or
> suggestions?

You can use CDO to manage your Inbox, send mail etc.

The following functions navigate to a certain folder and parse every 
message text for a certain regular expression:

def spamstat ():
 s = Dispatch ("Mapi.Session")
 s.Logon ("Default Outlook Profile")
 junk = findJunk (s)
 rex = re.compile ('The ([0-9]+) emails listed below')
 for msg in junk.Messages:
 text = msg.Text
 match = rex.search (text)
 if match:
 date = parseDate (msg.TimeSent)
 print (date, int (match.group (1)))

def findJunk (s):
 inbox = s.Inbox
 for folder in s.Inbox.Folders:
 if folder.Name == 'Junk':
 return folder


See the Spambayes Outlook plugin (http://spambayes.sourceforge.net/) for 
a complex example.

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


Does anyone know where is the Berkeley XML Database documentation for its Python API?

2006-04-04 Thread Sullivan WxPyQtKinter
I have been looking for python API documentation of BDBXML for quite a
few days but I could not find it. Anyone has any idea where it is? Or
if there is not such a thing at all, how could I get started?

In addition, in the previous posts I have seen some grumble about
python API's lack of XMLexception and some basic programming and
debugging elements for project engineering. Are they added or fixed in
the lastest version of BSBXML? 


Thank you for help.

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


scraping nested tables with BeautifulSoup

2006-04-04 Thread [EMAIL PROTECTED]
I'm trying to get the data on the "Central London Property Price Guide"
box at the left hand side of this page
http://www.findaproperty.com/regi0018.html

I have managed to get the data :) but when I start looking for tables I
only get tables of depth 1 how do I go about accessing inner tables?
same happens for links...

this is what I've go so far

import sys
from urllib import urlopen
from BeautifulSoup import BeautifulSoup

data = urlopen('http://www.findaproperty.com/regi0018.html').read()
soup = BeautifulSoup(data)

for tables in soup('table'):
table = tables('table')
if not table: continue
print table #this returns only 1 table

#this doesn't work at all

nested_table = table('table')
print nested_table

all suggestions welcome

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


Dice probability problem

2006-04-04 Thread Tomi Lindberg
Hi,

I'm trying to find a way to calculate a distribution of 
outcomes with any combination of dice. I have the basics 
done, but I'm a bit unsure how to continue. My main concern 
is how to make this accept any number of dice, without 
having to write a new list comprehension for each case?

Here's a piece of code that shows the way I'm doing things 
at the moment.

-- code begins --

# A die with n faces
D = lambda n: [x+1 for x in range(n)]

# A pool of 3 dice with 6 faces each
pool = [D(6)] * 3

# A List of all outcomes with the current 3d6 pool.
results = [x+y+z for x in pool[0] for y in pool[1]
for z in pool[2]]

# A dictionary to hold the distribution
distribution = {}

# If outcome is already a key, adds 1 to its value.
# Otherwise adds outcome to keys and sets its value
# to 1.
def count(x):
 if distribution.has_key(x): distribution[x] += 1
 else: distribution[x] = 1

# Maps the results with above count function.
map(count, results)

-- code ends --

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


Re: Does anyone know where is the Berkeley XML Database documentation for its Python API?

2006-04-04 Thread Amit Khemka
There are no official/un-official documentation for bdbxml python api AFAIK !!!

If you want some examples look in "dbxml/examples/python/", directory
in your dbxml installation.

Though for most part the python api closely follows the C++/Java api
(look: http://www.dbxml.com/docs/programmer.html ) for details.

You may also find http://blog.gmane.org/gmane.comp.db.dbxml.general useful.

cheers,
amit.


On 4 Apr 2006 01:34:25 -0700, Sullivan WxPyQtKinter
<[EMAIL PROTECTED]> wrote:
> I have been looking for python API documentation of BDBXML for quite a
> few days but I could not find it. Anyone has any idea where it is? Or
> if there is not such a thing at all, how could I get started?
>
> In addition, in the previous posts I have seen some grumble about
> python API's lack of XMLexception and some basic programming and
> debugging elements for project engineering. Are they added or fixed in
> the lastest version of BSBXML?
>
>
> Thank you for help.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--

Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: markup.py - 1.2 - an HTML/XML generator

2006-04-04 Thread Daniel Nogradi
> > $ pwd
> > /usr/lib/python2.4/site-packages
> > $ grep -re klass . | wc -l
> > 274
> > $ grep -re class_ . | wc -l
> > 897
>
> How many of those "class_" instances are really just substrings of
> "__class__" and "class_name" and such?  On my machine, I see a handful
> in the standard library, and _none_ in site-packages (which has only
> 1709 .py files, mind you).
>
> > For me that's enough. "class_" is used at least three times more than
> > "klass". Besides, as Scott pointed out, "class_" is prefered by the
> > guidelines too.
>
> Actually what he posted explicitly states that "cls" is preferred.
> Following that it says that one should considering appending _ if the
> name conflicts with a keyword (and one can assume it means "for all
> keywords other than class").
>
> >>`cls`, at least, is more commonly used within
> >>Python itself (e.g., classmethods).
> >
> > Yes. cls wouldn't be a good choice. But class_ is. Or maybe even
> > css_class. But klass isn't.
>
> As has been pointed out, klass has a fairly established tradition of
> use.  (I happen to agree with the PEP and use "cls" exclusively for such
> things, and do agree that "klass" is crude.)
>



It seems there are 3 competing versions:

(1) cls
(2) class_
(3) klass

(1) is encouraged by PEP-8 for class methods
(2) is encouraged by the same PEP for keyword arguments if there aren't synonyms
 available
(3) is used widely and doesn't seem ugly to anyone whose language uses
'k' for the
 first sound in the English pronounciation of the word 'class'.
And it happens in
 English too, although usually not at the beginning of the word,
like 'quick', 'break',
 etc.

And there is an additional point in PEP-8, namely one should avoid
spelling corruption, so 'print_' is preferred instead of 'prnt' but
the best is to invent a synonym. Now the question is whether 'klass'
counts as a spelling corruption or it is more like a synonym. I
thought it's not a corruption that's why I chose to use it (I must
also admit I haven't even thought about (1) or (2) at all or PEP-8 to
begin with). So I guess 'klass' is okay, but I'm open to other
suggestions, I have only problems with 'class_' as I usually dislike
non-alphabetical characters unless they are absolutely necessary.

Any further thoughts on this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standalone Python functions in UML?

2006-04-04 Thread Ravi Teja
>> Out of curiosity, how do I draw functions outside classes with UML? How
module could be drawn in this case?

As a utility class.

>> More theoretical question is if I create classes on the fly, how UML can
reflect that?

"On the fly" usually means "at runtime". I guess you mean if you
"change code" will my diagram stay in sync?. You will have to use round
trip tools. I don't know any tool supports round trip for Python code.
But if you just mean reverse engineering, lookup PyNSource, Boa
Constructor, PyReverse among others

>> (I know that Python code itself is best at communication design ideas,
but there are some people which prefer to talk UML.)

Actually no. Python is a good tool for "prototyping" which is not the
same as "communicating design ideas". Diagrams are better for the later
and do not need to be executable. At least from what I know, except
Eiffel, no language makes that claim. UML is really the only contender
currently for design notation.

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


Re: Standalone Python functions in UML?

2006-04-04 Thread Rob Cowie

Roman Susi wrote:
> Hi!
>
> Out of curiosity, how do I draw functions outside classes with UML? How
> module could be drawn in this case?

I would say that within a class diagram, you can't. In other UML
diagrams (such as sequence interaction), the function is simply used as
if it were a method belonging to an object. If you need to make it
clear where this function is located within the code, use a note on the
diagram.

Remember, UML is not able to accurately capture all implementation
details of a system; It's not meant to.

>
> More theoretical question is if I create classes on the fly, how UML can
> reflect that?

Again, don't try to depict fine-grained implementation details. If the
dynamically generated class is important to the class diagram, include
it but don't include all of it's internals (methods etc.). Use a note
to exaplin how/when/why it is generated.

>
> (I know that Python code itself is best at communication design ideas,
> but there are some people which prefer to talk UML.)
>
> (Have not found anything relevant with google)
> 
> Thanks!
> 
> Regards,
> Roman Suzi

Rob C

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


Re: Dice probability problem

2006-04-04 Thread Alexander Schmolck
Tomi Lindberg <[EMAIL PROTECTED]> writes:

> I'm trying to find a way to calculate a distribution of outcomes with any
> combination of dice. I have the basics done, but I'm a bit unsure how to
> continue. My main concern is how to make this accept any number of dice,
> without having to write a new list comprehension for each case?

You need to think about the right way to break the problem down into some
operation that can be repeated one fewer times than there are dice (if you
just have a single dice, nothing needs to be done) and then repeat it.

An obvious candidate is adding a single dice to the sums computed so far:

def addDice(sums, dice):
return [x+y for x in dice for y in sums]

If you have less than 1 dice the answer is 
# len(pool) == 1
pool[0]

After that, each time you add a dice you need to call addDice on the sum
computed for all the previous dice and the new dice:

# len(pool) == 2
addDice(resultFor1, pool[1])
addDice(pool[0], pool[1])

then

# len(pool) == 3
addDice(resultFor2, pool[2])
addDice(addDice(resultFor1, pool[1]), pool[2])
addDice(addDice(pool[0], pool[1]), pool[2])

finally you get

# len(pool) == n
addDice(addDice(addDice(..., pool[n-3]), pool[n-2]) pool[n-1])

OK, so how do we get the repetition?

Conveniently the pattern f(...f(f(x[0],x[1]),x[2])...,x[n-1]) or equivalently,
if we write the infix operator * for f: x[0]*x[1]*...*x[n-1], can just be 
written as
reduce(f, x) in python. So we get:

reduce(addDice, pool)
== reduce(lambda sums, dice: [x+y for x in dice for y in sums], pool)

You should presumably also try writing this out as a single function, without
using reduce (but recognizing the (left) reduction pattern is useful, even if
you don't use python's reduce).

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


Re: Dice probability problem

2006-04-04 Thread Alexander Schmolck
Alexander Schmolck <[EMAIL PROTECTED]> writes:

> addDice(resultFor1, pool[1])
> addDice(pool[0], pool[1])


sorry should have spelled out that successive lines are meant to be
equivalent, i.e.

 addDice(resultFor1, pool[1])
==   addDice(pool[0], pool[1])

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


Re: Dice probability problem

2006-04-04 Thread Antoon Pardon
Op 2006-04-04, Tomi Lindberg schreef <[EMAIL PROTECTED]>:
> Hi,
>
> I'm trying to find a way to calculate a distribution of 
> outcomes with any combination of dice. I have the basics 
> done, but I'm a bit unsure how to continue. My main concern 
> is how to make this accept any number of dice, without 
> having to write a new list comprehension for each case?

IMO you are looking at it from the wrong side.

It would be better to construct distributions for one
die and make a function that can 'add' two distributions
together. So for 3D6 you first add the distribution of
a D6 to the distribution of a D6 and to this result
you add the distribution of a D6 again.

If you need more to start, just ask.

> Here's a piece of code that shows the way I'm doing things 
> at the moment.
>
> -- code begins --
>
> # A die with n faces
> D = lambda n: [x+1 for x in range(n)]
>
> # A pool of 3 dice with 6 faces each
> pool = [D(6)] * 3
>
> # A List of all outcomes with the current 3d6 pool.
> results = [x+y+z for x in pool[0] for y in pool[1]
> for z in pool[2]]

This is very inefficient. I wouldn't want to calculate
the distribution of 10D10 this way.

Try to think how you would do this with only D2's.

(Triangle of Pascal) and generalize it.

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


Re: ANN: uuid-0.1 Released

2006-04-04 Thread jUrner

I would like to contact Ka-Ping Yee, but got no answer to my emails so
far.
Maybe s.o. knows how to contact Ka-Ping Yee.

BTW persistant storage for clock sequence is not implemented in my
module so far.
I will consider it for the next release. Any ideas how to implement ?

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


Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-04 Thread ChaosKCW
Hi

Thanks for all the posts. I am still digesting it all but here are my
initial comments.

>Don't. You can't. Those characters don't exist in the ASCII character set.
>SQLite 3.0 deals with UTF-8 encoded SQL statements, though.
>http://www.sqlite.org/version3.html

As mentioned by the next poster, there is, its supposed to be encode
with the 'ignore' option. Thus you lose data, but thats just dandy with
me. As for SQLite supporting unicode, it probably does, but something
on the python side (probabyl in apsw) converts it to ascii at some
point before its handed to SQLite.

>The .encode() method returns a new value; it does not change an object inplace.
>  sql = sql.encode('utf-8')

Ah yes, big bistake on my part :-/

>He is using apsw.  apsw correctly handles unicode.  In fact it won't
>accept a str with bytes >127 as they will be an unknown encoding and
>SQLite only uses Unicode internally.  It does have a blob type
>using buffer for situations where binary data needs to be stored.
>pysqlite's mishandling of Unicode is one of the things that drove
>me to writing apsw in the first place.

Ok if SQLite uses unicode internally why do you need to ignore
everything greater than 127, the ascii table (256 bit one) fits into
unicode just fine as far as I recall? Or did I miss the boat here ?

Thanks,

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


Re: Best way to create a copy of a list

2006-04-04 Thread Jorge Godoy
"Frank Millman" <[EMAIL PROTECTED]> writes:

> Interesting. My results are opposite.

I got the same here (cPython 2.4.1):

[EMAIL PROTECTED] ~ % python -mtimeit -s "data=[range(100)]*100; row = []" 
"row[:] = data[23]"
100 loops, best of 3: 1.15 usec per loop
[EMAIL PROTECTED] ~ % python -mtimeit -s "data=[range(100)]*100" "row = 
data[23][:]"
10 loops, best of 3: 1.42 usec per loop
[EMAIL PROTECTED] ~ % python -mtimeit -s "data=[range(100)]*100" "row = 
list(data[23])"
10 loops, best of 3: 1.93 usec per loop
[EMAIL PROTECTED] ~ % 

> If they are all equivalent from a functional point of view, I lean
> towards the second version. I agree with Rune that the third one is
> nicer to read, but somehow the [:] syntax makes it a bit more obvious
> what is going on.

I prefer the third option for readability.  It makes it clear that I'll get a
*new* list with the 23rd row of data.  Just think: how would you get the 1st
column of the 23rd row?

>>> a = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]
>>> a
[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]
>>> a[1]
[2, 3]
>>> a[1][1]
3
>>> a[1][:]
[2, 3]
>>> 

Someone might think that the "[:]" means "all columns" and the syntax to be
equivalent to "data[23]". 


-- 
Jorge Godoy  <[EMAIL PROTECTED]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-04 Thread John Machin
"Thus you lose data, but thats just dandy with
me.": Please reconsider this attitude, before you perpetrate a nonsense
or even a disaster.

Wrt your last para:
1. Roger didn't say "ignore" -- he said "won't accept" (a major
difference).
2. The ASCII code comprises 128 characters, *NOT* 256.
3. What Roger means is: given a Python 8-bit string and no other
information, you don't have a clue what the encoding is. Most codes of
interest these days have the ASCII code (or a mild perversion thereof)
in the first 128 positions, but it's anyones guess what the writer of
the string had in mind with the next 128.

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


Re: question about nasty regex

2006-04-04 Thread Peter Hansen
Lawrence D'Oliveiro wrote:
> In article <[EMAIL PROTECTED]>,
>  Paul Rubin  wrote:
>>"Some people, when confronted with a problem, think ``I know, I'll use
>>regular expressions.'' Now they have two problems."  --JWZ
> 
> Regexes are good if you need a solution quickly, and you're not 
> processing large amounts of data on a regular basis. (How large is 
> large? When you're chewing through appreciable amounts of CPU time doing 
> it.)

But "need a solution quickly" in this group is usually interpreted as 
saving programmer time, not CPU time.  I wouldn't have been able to come 
up with that monstrosity nearly as quickly as Tim did, and I wouldn't 
even be able to understand it without significant study, and I 
definitely would have trouble maintaining it a few months later when I 
found a test case which it didn't handle properly.  I also wouldn't even 
have confidence that it worked perfectly without throwing a dozen test 
cases at it...

On the other hand, I could code a hybrid or entirely non-regex solution 
in five or ten minutes (with tests!), and it would be quite readable.

> Once you get to that point, it would be more efficient to hand-code your 
> own state machine to do the parsing. Of course, doing it in an (even 
> partially) interpreted language like Python or Perl would defeat the 
> point...

The number of problems for which Python and Perl aren't fast enough is 
far smaller than most people think, as is the number of problems for 
which regular expressions are really a suitable solution. :-)

-Peter

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


warning users of problems with logging

2006-04-04 Thread Chris Curvey
The following code exists in logging/config.py

handlers[hand] = h
except: #if an error occurs when instantiating a handler, too bad
 pass#this could happen e.g. because of lack of privileges

The problem here is that if something did go wrong instantiating the
handler, you have no idea what the problem was (permissions, syntax
error, wrong parameters), and later on you get a message like:

Traceback (most recent call last):
  File "c:\python24\lib\logging\config.py", line 151, in fileConfig
log.addHandler(handlers[hand])
KeyError: 'default'

I propose that we change the code so that we have a fighting chance of
figuring out what's going on, like this:

handlers[hand] = h
except Exception, e: #if an error occurs when instantiating a
handler, too bad
 print e #this could happen e.g. because of
lack of privileges

But I'm not sure if a "print" statement is the best way to go about it.
 Any thoughts?

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


CD Burning

2006-04-04 Thread Albert Leibbrandt
Hi

Can anybody tell me which windows API or python module they are using 
for writing cd's / dvd's with python?

Thanks
Albert

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


Windows Services

2006-04-04 Thread rodmc
Hello,

I am trying to figure out how to write a windows service, I am totally
new to it. I have written a simple test case, however it doesn't appear
to do anything. Although it installs and appears to start, when I run a
query of its status (using another app) it says it is not running.  As
a note I am running it as the administrator in a Win2k machine to avoid
any problems with permissions - although I would rather not do this for
ever :-)

I install the software as follows:

python testservice.py install
python testservice.py start

I am sure I am missing something out as I am basically working from
code samples for other solutions which I have seen. In particular one
for getting CherryPy to run as a service.

When I have figured this all out I intend to add in some code I have
already written which runs a server application.

It may be all rather obvious but I am quite new Python (just a few
months) and totally new to Windows services.

Thanks in advance for any help.

Best,

Rod


import win32serviceutil
import win32service
import win32event
import os,sys

class helloworld:

def test(self):
x=1
filename=open("c:test.txt","w")
while x<10:
print >>filename,x
x=x+1

class MyService(win32serviceutil.ServiceFramework):
"""NT Service."""

_svc_name_ = "Test"
_svc_display_name_ = "Test"

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
# create an event that SvcDoRun can wait on and SvcStop
# can set.
self.stop_event = win32event.CreateEvent(None, 0, 0, None)

def SvcDoRun(self):
print "got here"
helloworld.test()
win32event.WaitForSingleObject(self.stop_event,
win32event.INFINITE)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.stop_event)

if __name__ == '__main__':
win32serviceutil.HandleCommandL

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


tuple syntax ',' (ending in comma?)

2006-04-04 Thread Michael Yanowitz
Hello:

   I am still relatively new to Python. I am confused by the syntax for
tuples.
I had:
  thread.start_new_thread(read_data_thread, (strDataFilename))
  and got back the following error:

  File "scene.py", line 256, in readData
thread.start_new_thread(read_data_thread, (strDataFilename))
TypeError: 2nd arg must be a tuple

   The way I fixed this error was I added an extra , (comma) to the tuple:
  thread.start_new_thread(read_data_thread, (strDataFilename,))

  I am just confused by the syntax. I am used to a comma meaning that there
should be another parameter after the comma and if no additional parameter
the comma would not be necessary.

Thanks in advance:



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


Re: tuple syntax ',' (ending in comma?)

2006-04-04 Thread Georg Brandl
Michael Yanowitz wrote:
> Hello:
> 
>I am still relatively new to Python. I am confused by the syntax for
> tuples.
> I had:
>   thread.start_new_thread(read_data_thread, (strDataFilename))
>   and got back the following error:
> 
>   File "scene.py", line 256, in readData
> thread.start_new_thread(read_data_thread, (strDataFilename))
> TypeError: 2nd arg must be a tuple
> 
>The way I fixed this error was I added an extra , (comma) to the tuple:
>   thread.start_new_thread(read_data_thread, (strDataFilename,))
> 
>   I am just confused by the syntax. I am used to a comma meaning that there
> should be another parameter after the comma and if no additional parameter
> the comma would not be necessary.

What would you expect

>>> 3 * (5 + 2)

to print? Certainly not "(7, 7, 7)", but it would if all expressions in
parentheses were tuples.

Thus, the comma is necessary to disambiguate and explicitly tell the parser
that you mean to construct a tuple.

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


Re: warning users of problems with logging

2006-04-04 Thread Peter Otten
Chris Curvey wrote:

> The following code exists in logging/config.py
> 
> handlers[hand] = h
> except: #if an error occurs when instantiating a handler, too bad
>  pass#this could happen e.g. because of lack of privileges
> 
> The problem here is that if something did go wrong instantiating the
> handler, you have no idea what the problem was (permissions, syntax
> error, wrong parameters), and later on you get a message like:
> 
> Traceback (most recent call last):
>   File "c:\python24\lib\logging\config.py", line 151, in fileConfig
> log.addHandler(handlers[hand])
> KeyError: 'default'
> 
> I propose that we change the code so that we have a fighting chance of
> figuring out what's going on, like this:
> 
> handlers[hand] = h
> except Exception, e: #if an error occurs when instantiating a
> handler, too bad
>  print e #this could happen e.g. because of
> lack of privileges
> 
> But I'm not sure if a "print" statement is the best way to go about it.

I think this is fixed in subversion, see
http://svn.python.org/view/python/trunk/Lib/logging/config.py?rev=42074&r1=38949&r2=42074

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


Re: Standalone Python functions in UML?

2006-04-04 Thread Philippe Martin
Roman Susi wrote:

> Hi!
> 
> Out of curiosity, how do I draw functions outside classes with UML? How
> module could be drawn in this case?
> 
I'm not up to par on the latest UML specs (or not too old) - but I don't
believe UML handles that: it is called a class diagram after all.

> More theoretical question is if I create classes on the fly, how UML can
> reflect that?

You mean objects I think: by using a 0..n in you agregation ?

> 
> (I know that Python code itself is best at communication design ideas,
> but there are some people which prefer to talk UML.)
> 
> (Have not found anything relevant with google)
> 
> Thanks!
> 
> Regards,
> Roman Suzi

Regards,

Philippe

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


Re: Problem with wrapping GNU Units

2006-04-04 Thread TheSeeker
Hi,

Perhaps in another revision, as utilizing Unum, while cool, would be
quite a change to my code.

Could it be that the readline library used by GNU Units can detect the
difference between a 'real' tty and a pipe? If so, how can I trick it?

Thanks,
Duane

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


Re: Windows Services

2006-04-04 Thread Larry Bates
rodmc wrote:
> Hello,
> 
> I am trying to figure out how to write a windows service, I am totally
> new to it. I have written a simple test case, however it doesn't appear
> to do anything. Although it installs and appears to start, when I run a
> query of its status (using another app) it says it is not running.  As
> a note I am running it as the administrator in a Win2k machine to avoid
> any problems with permissions - although I would rather not do this for
> ever :-)
> 
> I install the software as follows:
> 
> python testservice.py install
> python testservice.py start
> 
> I am sure I am missing something out as I am basically working from
> code samples for other solutions which I have seen. In particular one
> for getting CherryPy to run as a service.
> 
> When I have figured this all out I intend to add in some code I have
> already written which runs a server application.
> 
> It may be all rather obvious but I am quite new Python (just a few
> months) and totally new to Windows services.
> 
> Thanks in advance for any help.
> 
> Best,
> 
> Rod
> 
> 
> import win32serviceutil
> import win32service
> import win32event
> import os,sys
> 
> class helloworld:
> 
> def test(self):
> x=1
> filename=open("c:test.txt","w")
> while x<10:
> print >>filename,x
> x=x+1
> 
> class MyService(win32serviceutil.ServiceFramework):
> """NT Service."""
> 
> _svc_name_ = "Test"
> _svc_display_name_ = "Test"
> 
> def __init__(self, args):
> win32serviceutil.ServiceFramework.__init__(self, args)
> # create an event that SvcDoRun can wait on and SvcStop
> # can set.
> self.stop_event = win32event.CreateEvent(None, 0, 0, None)
> 
> def SvcDoRun(self):
> print "got here"
> helloworld.test()
> win32event.WaitForSingleObject(self.stop_event,
> win32event.INFINITE)
> 
> def SvcStop(self):
> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
> win32event.SetEvent(self.stop_event)
> 
> if __name__ == '__main__':
> win32serviceutil.HandleCommandL
> 
I found Mark Hammond and Andy Robinson's book Python Programming on
Win32 to be a great resource when I wrote my first service.  It has
several examples that helped a lot.

Remember services run inside of infinite loops.  Inside SvcDoRun
you must have some construct like:

while 1:
#-
# Wait for service stop signal, if I timeout, loop again
#-
rc=win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
#
# Check to see if self.hWaitStop happened
#
if rc == win32event.WAIT_OBJECT_0:
#
# Stop signal encountered
#
break

else:
#
# Put body of service here
#



You also should probably change win32event.INFINITE to some number (expressed
in milliseconds) or your service gets blocked and doesn't do anything.

The sequence goes like this:

Inside an infinite loop, sleep for some time
Wake up and check if you received a stop signal
If you have, exit the infinite loop (by returning from SvcDoRun)
If not, run whatever code you want to execute each time you loop

Hope this helps.
Larry Bates
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what's going on here?

2006-04-04 Thread John Salerno
Ant wrote:
> You are along the right lines. Try printing out the content of each URL
> - one of the pages will match your expression, but has additional
> instructions... I think you are reaching the end of their false trail
> when you get None returned from the url.

But the weird thing is that when I tried the same script earlier in the 
day, it went through about 200+ links before encountering a situation 
that my script didn't handle. But now when I get this latest error that 
I posted, it's only going through about 150 links before stopping.

> The set of pages themselves are the linked list - each contains a
> reference to the next element in the sequence. You don't need one to
> solve the problem, the problem *is* the linked list!

Interesting! That's good news, and I'm glad I didn't spend hours trying 
to use one to solve it! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: CherryPy-2.2.0-rc1 released

2006-04-04 Thread remi
Hello everyone,

After six months of hard work and 300 changesets since the last stable
release I'm happy to announce that CherryPy-2.2.0-final is out.

The biggest changes are:

- switch to a lowercase api (although the old camelCase API is still
supported for backward compatibility)

- support for multiple applications (new "cherrypy.tree" object)

- better error handling

- lots of bug fixes (especially in file-based sessions)

- better test suite.

Check out http://www.cherrypy.org/wiki/UpgradeTo2.2 for more details.

***
About CherryPy:

CherryPy is a simple (no dependencies), pythonic (doesn't
get in your way) web development framework.

Here is a sample Hello, World in CherryPy:

# import cherrypy
# class HelloWorld:
# @cherrypy.expose
# def index(self):
# yield ""
# yield "Hello world!"
# yield ""
# cherrypy.root = HelloWorld()
# cherrypy.server.start()

The project has been growing strongly lately:
cherrypy.org averaged 3000 visitors/day in March,
up from 2000 visitors/day in January and February;
and the cherrypy-users list just passed 700 users.


Details and downloads are available from:

http://www.cherrypy.org 


Remi.

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


Re: tuple syntax ',' (ending in comma?)

2006-04-04 Thread John Salerno
Michael Yanowitz wrote:

>   I am just confused by the syntax. I am used to a comma meaning that there
> should be another parameter after the comma and if no additional parameter
> the comma would not be necessary.

But isn't it incorrect to think in terms of 'parameters' when referring 
to tuples? Tuples just contain elements, not parameters, so it might 
help not to think of it as function call syntax.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: scraping nested tables with BeautifulSoup

2006-04-04 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> I'm trying to get the data on the "Central London Property Price Guide"
> box at the left hand side of this page
> http://www.findaproperty.com/regi0018.html
> 
> I have managed to get the data :) but when I start looking for tables I
> only get tables of depth 1 how do I go about accessing inner tables?
> same happens for links...
> 
> this is what I've go so far
> 
> import sys
> from urllib import urlopen
> from BeautifulSoup import BeautifulSoup
> 
> data = urlopen('http://www.findaproperty.com/regi0018.html').read()
> soup = BeautifulSoup(data)
> 
> for tables in soup('table'):
>   table = tables('table')
>   if not table: continue
>   print table #this returns only 1 table

There's something fishy here. soup('table') should yield all the tables
in the document, even nested ones. For example, this program:

data = '''

  
  
  
  Stuff
  
  
  

'''

from BeautifulSoup import BeautifulSoup as BS

soup = BS(data)
for table in soup('table'):
  print table.get('width')


prints:
100%
150

Another tidbit - if I open the page in Firefox and save it, then open 
that file into BeautifulSoup, it finds 25 tables and this code finds the 
table you want:

from BeautifulSoup import BeautifulSoup
data2 = open('regi0018-firefox.html')
soup = BeautifulSoup(data2)

print len(soup('table'))

priceGuide = soup('table', dict(bgcolor="#e0f0f8", border="0", 
cellpadding="2", cellspacing="2", width="150"))[1]
print priceGuide.tr


prints:
25
Central London Property Price Guide


Looking at the saved file, Firefox has clearly done some cleanup. So I 
think you have to look at why BS is not processing the original data the 
way you want. It seems to be choking on something.

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


Difference in Python and Ruby interactive shells

2006-04-04 Thread dmh2000
I am experimenting with the interactive interpreter environments of
Python and Ruby and I ran into what seems to be a fundamental
difference. However I may be doing something wrong in Python. Please
comment and correct me if I am wrong

In both languages, you can start up the interactive interpreter
('python' and 'irb'), load source files and do stuff, like create
objects and call their methods. When you want to change something, you
can edit those same source files outside the environment and reload
them from within the interactive environment. But, here is the
difference: with Python, when you reload the source file (module in
Python terms), it seems that your existing variables stay bound to the
implementations from the old version of the module. In Ruby, after a
reload, your existing variables point to the new implementation. At
least, that is what happens with classes and their methods.  This means
that in Python, if you have an application built up interactively, with
references to objects, data structures pointing to objects, etc., you
would have to reconstruct that application to get the new
implementation. With Ruby, when you load the new implementation, you
get it immediately.

here is a simple example:

---
Python interactive shell (python.exe)

C:\home\dh0072\rq>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.

# load a local file b.py for test

>>> import b

# instantiate an object and call a method

>>> x = b.B()
>>> x.p()
B

# edit b.py offline to change method 'p' to do something different then
reload

>>> reload(b)

>>> x.p()
B

# binding of variable 'x' IS NOT changed. points to old version

>>> y = b.B()
>>> y.p()
B

# new instance of 'b' points to new version

>>>
---
Ruby interactive shell (irb.exe)

C:\home\dh0072\rq>irb

# load a local file b.py for test

irb(main):001:0> load "b.rb"
=> true

# instantiate an object and call a method

irb(main):002:0> x = B.new
=> #
irb(main):003:0> x.p
B
=> nil

# edit b.py offline to change method 'p' to do something different then
reload

irb(main):004:0> load "b.rb"
=> true
irb(main):005:0> x.p

=> nil

# binding of variable 'x' IS changed. points to new version

irb(main):006:0> y = B.new
=> #
irb(main):007:0> y.p

=> nil

#  new instance of 'b' points to new version

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


Re: symbolic links, aliases, cls clear

2006-04-04 Thread Pankaj
its true for the processes, gone to the system mode and from there the
process is not considering the shell variable any more.

In case of deamons also it is the same case. For Phython programs, I am
not sure , may they are also nohops, so might be not accessing the
shell variables. But i think you have defined the alias to some other
place the error is reported by shell that cls not found.

This could be investigated if you do some tests with the system. Like
alias is shell script you can open it and read it , how it invokes the
command for creating aliases. etc etc.

Alias: When the shell is in picture it directly replaces the string
"cls" to "clear" and execute the clear.

Symbolic links: are reference to the inode of the actual files, so it
should work in your case.

just run
#which clear
(O/P , you will get the location of binary say /usr/bin/clear)

Now you can create the symbolic link named as cls at location
"/usr/bin". this symbolic link should be a soft link to /usr/bin/clear.
 you can also put the symbolic links to any of the location that is
displayed by $PATH variable.

for any command you execute in shell, it functions in following order:
(Not exactly the same, need to confirm, i might miss some of the steps)

1) check with the shell variable(whether any alias to this command
exists or not!)
2) search it in the locations $PATH and execute the command is it is
found.
so on...

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


Re: ANN: CherryPy-2.2.0 released

2006-04-04 Thread remi
Oops ... The title should have been "CherryPy-2.2.0 released", not
"CherryPy-2.2.0-rc1" ...


[EMAIL PROTECTED] wrote:
> Hello everyone,
>
> After six months of hard work and 300 changesets since the last stable
> release I'm happy to announce that CherryPy-2.2.0-final is out.
>
> The biggest changes are:
>
> - switch to a lowercase api (although the old camelCase API is still
> supported for backward compatibility)
>
> - support for multiple applications (new "cherrypy.tree" object)
>
> - better error handling
>
> - lots of bug fixes (especially in file-based sessions)
>
> - better test suite.
>
> Check out http://www.cherrypy.org/wiki/UpgradeTo2.2 for more details.
>
> ***
> About CherryPy:
>
> CherryPy is a simple (no dependencies), pythonic (doesn't
> get in your way) web development framework.
>
> Here is a sample Hello, World in CherryPy:
>
> # import cherrypy
> # class HelloWorld:
> # @cherrypy.expose
> # def index(self):
> # yield ""
> # yield "Hello world!"
> # yield ""
> # cherrypy.root = HelloWorld()
> # cherrypy.server.start()
>
> The project has been growing strongly lately:
> cherrypy.org averaged 3000 visitors/day in March,
> up from 2000 visitors/day in January and February;
> and the cherrypy-users list just passed 700 users.
>
>
> Details and downloads are available from:
> 
> http://www.cherrypy.org 
> 
> 
> Remi.

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


Re: Difference in Python and Ruby interactive shells

2006-04-04 Thread Claudio Grondi
dmh2000 wrote:
> I am experimenting with the interactive interpreter environments of
> Python and Ruby and I ran into what seems to be a fundamental
> difference. However I may be doing something wrong in Python. Please
> comment and correct me if I am wrong
> 
> In both languages, you can start up the interactive interpreter
> ('python' and 'irb'), load source files and do stuff, like create
> objects and call their methods. When you want to change something, you
> can edit those same source files outside the environment and reload
> them from within the interactive environment. But, here is the
> difference: with Python, when you reload the source file (module in
> Python terms), it seems that your existing variables stay bound to the
> implementations from the old version of the module. In Ruby, after a
> reload, your existing variables point to the new implementation. At
> least, that is what happens with classes and their methods.  This means
> that in Python, if you have an application built up interactively, with
> references to objects, data structures pointing to objects, etc., you
> would have to reconstruct that application to get the new
> implementation. With Ruby, when you load the new implementation, you
> get it immediately.
I am not fully sure it is what you are speaking about, but I mean, that 
you have overlooked, that in the IDLE menu item [Shell] you have the 
option to restart the shell what takes you back to the initial state.
It would be interesting to know for me here, if there is in Ruby the 
option to keep the old values when starting a new run?

Claudio
> 
> here is a simple example:
> 
> ---
> Python interactive shell (python.exe)
> 
> C:\home\dh0072\rq>python
> Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
> 
> # load a local file b.py for test
> 
> 
import b
> 
> 
> # instantiate an object and call a method
> 
> 
x = b.B()
x.p()
> 
> B
> 
> # edit b.py offline to change method 'p' to do something different then
> reload
> 
> 
reload(b)
> 
> 
x.p()
> 
> B
> 
> # binding of variable 'x' IS NOT changed. points to old version
> 
> 
y = b.B()
y.p()
> 
> B
> 
> # new instance of 'b' points to new version
> 
> 
> ---
> Ruby interactive shell (irb.exe)
> 
> C:\home\dh0072\rq>irb
> 
> # load a local file b.py for test
> 
> irb(main):001:0> load "b.rb"
> => true
> 
> # instantiate an object and call a method
> 
> irb(main):002:0> x = B.new
> => #
> irb(main):003:0> x.p
> B
> => nil
> 
> # edit b.py offline to change method 'p' to do something different then
> reload
> 
> irb(main):004:0> load "b.rb"
> => true
> irb(main):005:0> x.p
> 
> => nil
> 
> # binding of variable 'x' IS changed. points to new version
> 
> irb(main):006:0> y = B.new
> => #
> irb(main):007:0> y.p
> 
> => nil
> 
> #  new instance of 'b' points to new version
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to comment lot of lines in python

2006-04-04 Thread Rick Zantow
Kent Johnson <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> Rick Zantow wrote:
>> Kent Johnson <[EMAIL PROTECTED]> wrote in news:44310867$1_1
>> @newspeer2.tds.net:
>> 
>>> Sion Arrowsmith wrote:
 Out of curiousity, is there a modern editor which *doesn't* allow
 you to comment/uncomment a selected bunch of lines of code?

>>> TextPad is my editor of choice but it doesn't have this feature.
>>>
>> 
>> I use TextPad all the time, and while it is true that the feature is
>> not built in, it's misleading to say it doesn't have it. It is
>> implemented by means of a macro definition. I assign a key to a
>> 'comment' macro (basically replacing regex ^ with '# ' for the
>> selected text) to do this. And of course I have a reciprocal
>> 'uncomment' macro as well. 
> 
> Thank you! I don't suppose you have any tricks to make it work with 
> UTF-8 data outside the cp1252 character set, do you?
> 

Sadly, I don't. TP claims Unicode support, but I'm not sure what they 
mean; it does seem to be restricted to cp1252.

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


Re: warning users of problems with logging

2006-04-04 Thread Chris Curvey
So it is.  Great!

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


Re: Framework/module for generating HTML documentation

2006-04-04 Thread Thomas Guettler
Hi,

I have a little script which creates numbers by scanning the  tags.
But up to now it only works for single file. But it would be easy to
split e.g. on every  tag.

http://www.thomas-guettler.de/scripts/number-html-headings.py.txt

Am Tue, 04 Apr 2006 17:01:43 +0900 schrieb Ryan Ginstrom:
> E.g., I want to go from something like this:
> Introduction
> Some text
> Getting Started
> Some text
> Installation
> Some text. See Getting Started for details.
> 
> To this:
> [index.html]
> Contents
> 1. Introduction
> 2. Getting Started
> 
>   2.1. Installation
> 

-- 
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: [EMAIL PROTECTED]

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


Re: CD Burning

2006-04-04 Thread Sybren Stuvel
Albert Leibbrandt enlightened us with:
> Can anybody tell me which windows API or python module they are
> using for writing cd's / dvd's with python?

I'd install cygwin and use cdrecord. That seems the easiest way to go
about burning disks to me.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference in Python and Ruby interactive shells

2006-04-04 Thread Sybren Stuvel
dmh2000 enlightened us with:
> When you want to change something, you can edit those same source
> files outside the environment and reload them from within the
> interactive environment. But, here is the difference: with Python,
> when you reload the source file (module in Python terms), it seems
> that your existing variables stay bound to the implementations from
> the old version of the module.

IMO this is the only proper way of doing things. A variable points to
something in memory. When a module is reloaded, that thing in memory
is still there - because it is referenced, it does not get garbage
collected.

> Ruby interactive shell (irb.exe)
>
> C:\home\dh0072\rq>irb
>
> # load a local file b.py for test
>
> irb(main):001:0> load "b.rb"
>=> true
>
> # instantiate an object and call a method
>
> irb(main):002:0> x = B.new
>=> #
> irb(main):003:0> x.p
> B
>=> nil
>
> # edit b.py offline to change method 'p' to do something different then
> reload
>
> irb(main):004:0> load "b.rb"
>=> true
> irb(main):005:0> x.p
> 
>=> nil
>
> # binding of variable 'x' IS changed. points to new version

IMHO this is nasty. An assignment has already been performed.
Reloading some module should not (again, IMHO) change anything that
happened before it was reloaded.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference in Python and Ruby interactive shells

2006-04-04 Thread Steve Juranich
dmh2000 wrote:

> I am experimenting with the interactive interpreter environments of
> Python and Ruby and I ran into what seems to be a fundamental
> difference. However I may be doing something wrong in Python. Please
> comment and correct me if I am wrong
> 
> In both languages, you can start up the interactive interpreter
> ('python' and 'irb'), load source files and do stuff, like create
> objects and call their methods. When you want to change something, you
> can edit those same source files outside the environment and reload
> them from within the interactive environment. But, here is the
> difference: with Python, when you reload the source file (module in
> Python terms), it seems that your existing variables stay bound to the
> implementations from the old version of the module. In Ruby, after a
> reload, your existing variables point to the new implementation. At
> least, that is what happens with classes and their methods.  This means
> that in Python, if you have an application built up interactively, with
> references to objects, data structures pointing to objects, etc., you
> would have to reconstruct that application to get the new
> implementation. With Ruby, when you load the new implementation, you
> get it immediately.

This is correct.  I'm a bit fuzzy on the details, so some of this might be
wrong, but here's what's going on (I'm pretty sure):

When Python loads (or reloads) a module, it encounters a `class' block,
which causes it to create a new type in memory.  The instances created from
this type are bound to the type object.  This means that after a reload,
your "B" class is pointing to a different object in memory.  However, all
of your previous instances are still bound to the old definition (which is
still in memory, it's just not bound to the "B" name any more).  As a
simple test, do 'x.__class__ is y.__class__'.  This should return False.

Ruby, on the other hand, allows you to redefine classes on the fly.  So when
Ruby reads a 'class' block, it's either (1) redefining a previously defined
object's definition, or (2) creating a new class with the definition in the
block.

I *think* that the reason for this is that the Python virtual machine (aka,
the interpreter) is much more efficient than the Ruby VM.  So if you want
fast code, I'd stick with Python.  However, if you regularly build large
applications in memory from an interactive interpreter, then perhaps Ruby
is the way for you to go. :-)

Cheers.
-- 
Steve Juranich
Tucson, AZ
USA

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


ANN: CherryPy-2.2.0 released

2006-04-04 Thread remi
(sorry for the double-post, the title of the previous one was wrong)

Hello everyone,

After six months of hard work and 300 changesets since the last stable
release I'm happy to announce that CherryPy-2.2.0-final is out.

The biggest changes are:

- switch to a lowercase api (although the old camelCase API is still
supported for backward compatibility)

- support for multiple applications (new "cherrypy.tree" object)

- better error handling

- lots of bug fixes (especially in file-based sessions)

- better test suite.

Check out http://www.cherrypy.org/wiki/UpgradeTo2.2 for more details.

***
About CherryPy:

CherryPy is a simple (no dependencies), pythonic (doesn't
get in your way) web development framework.

Here is a sample Hello, World in CherryPy:

# import cherrypy
# class HelloWorld:
# @cherrypy.expose
# def index(self):
# yield ""
# yield "Hello world!"
# yield ""
# cherrypy.root = HelloWorld()
# cherrypy.server.start()

The project has been growing strongly lately:
cherrypy.org averaged 3000 visitors/day in March,
up from 2000 visitors/day in January and February;
and the cherrypy-users list just passed 700 users.


Details and downloads are available from:

http://www.cherrypy.org 


Remi.

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


Re: Difference in Python and Ruby interactive shells

2006-04-04 Thread Diez B. Roggisch
> In both languages, you can start up the interactive interpreter
> ('python' and 'irb'), load source files and do stuff, like create
> objects and call their methods. When you want to change something, you
> can edit those same source files outside the environment and reload
> them from within the interactive environment. But, here is the
> difference: with Python, when you reload the source file (module in
> Python terms), it seems that your existing variables stay bound to the
> implementations from the old version of the module. In Ruby, after a
> reload, your existing variables point to the new implementation. At
> least, that is what happens with classes and their methods.  This means
> that in Python, if you have an application built up interactively, with
> references to objects, data structures pointing to objects, etc., you
> would have to reconstruct that application to get the new
> implementation. With Ruby, when you load the new implementation, you
> get it immediately.

I don't know ruby enough to comment on _how_ they achieve that. But  I know
python enough to tell you that your observation is correct, and perfectly
consistent with what python ususally does. 

The problem here stems from the fact that in python, there are names and
values. The latter (also referred to as objects) can be bound to a name. 

Now loading a module creates class-objects, and binds them under a name -
the class-name. But this name is by no means special. You can e.g. do

class Foo:
  pass

Foo = 10

That will create a class that is bound to the name Foo - and the rebind that
very name to something completely different(tm).

Now creating an instance of that class creates an object, that has a
_reference_ to its class - not its name! 

Which means that there is no connection to the _name_ of that class! Well,
one can get to that, because the class knows the name it was bound to when
it was created - but that is only for documentary purposes.

When reloading a module, a new class object is created. And bound to the
name same name as before - but all instances created before keep a
reference to their old class. Which makes perfect sense: in python, it is
possible to create classes individually for each instance, if one wants to
- by metaclasses, or factoryfunctions like this:

def createClass():
   class Foo:
  pass
   return Foo

So - if that works, there is no way how one can know that this reloading of
a module is anything special.

Regards,

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


Re: what's going on here?

2006-04-04 Thread John Salerno
John Salerno wrote:
> Ant wrote:
>> You are along the right lines. Try printing out the content of each URL
>> - one of the pages will match your expression, but has additional
>> instructions... I think you are reaching the end of their false trail
>> when you get None returned from the url.
> 
> But the weird thing is that when I tried the same script earlier in the 
> day, it went through about 200+ links before encountering a situation 
> that my script didn't handle. But now when I get this latest error that 
> I posted, it's only going through about 150 links before stopping.
> 
>> The set of pages themselves are the linked list - each contains a
>> reference to the next element in the sequence. You don't need one to
>> solve the problem, the problem *is* the linked list!
> 
> Interesting! That's good news, and I'm glad I didn't spend hours trying 
> to use one to solve it! :)

Ok, I'm confused. I ran the script again today (this time at work again) 
and it worked! I made no changes, so I'm not sure what the issue was. 
But thank god I'm passed this problem, although I'm sure it only gets 
worse now!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to comment lot of lines in python

2006-04-04 Thread Kent Johnson
Rick Zantow wrote:
>> Thank you! I don't suppose you have any tricks to make it work with 
>> UTF-8 data outside the cp1252 character set, do you?
>>
> 
> Sadly, I don't. TP claims Unicode support, but I'm not sure what they 
> mean; it does seem to be restricted to cp1252.

TP will correctly read and write UTF-8 files if they use only the 
characters available in cp1252. So there is a little Unicode support but 
it breaks down pretty quickly with, e.g. Chinese or even Polish.

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


How to get pyMinGW?

2006-04-04 Thread Ames Andreas
Hi all,

the download link on http://jove.prohosting.com/iwave/ipython/pyMinGW.html 
seems to be broken.  Can anybody provide another link?

Is there a current version for python 2.4.3 available?


TIA,

aa

-- 
Andreas Ames | Programmer | Comergo GmbH |
Voice:  +49 69 7505 3213 | ames AT avaya . com
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with display placement

2006-04-04 Thread Samantha
I am new to Python and am attempting to write a routine that will display a 
five game selection for a power ball drawing. I think I have the random 
drawing set to work ok, but I want to have the dialog box move in the center 
of my screen. I can't seem to get the code correct to do this. Any help 
would be appreciated.
Thanks,
S
This is the routine I have.
###

import random
from Tkinter import *
root = Tk()


frame = Label(root, width=50, height=2, background = 'white', text = 
'PowerBall Numbers')
frame.pack()

def GetNumbers():

numbers = random.sample(xrange(53), 5)
numbers.sort()
numbers[0] = numbers[0] + 1

numbers[1] = numbers[1] + 1

numbers[2] = numbers[2] + 1

numbers[3] = numbers[3] + 1

numbers[4] = numbers[4] + 1
powerball = random.sample(xrange(42), 1)
powerball[0] = powerball[0] + 1

return numbers, powerball

y = 0
sp1 = sp2 = sp3 = sp4 = sp5 ='   '
w = 0
for x in range(5):
 y = y + 1
 MyNumbers= GetNumbers()
 x = MyNumbers

 num1= str(x[0][0])

 num2 = str(x[0][1])

 num3 = str(x[0][2])

 num4 = str(x[0][3])

 num5 = str(x[0][4])

 pbnum = str(MyNumbers[1][0])

 root.title =('Powerball Numbers')
 w = Label(root, width=50, height=2, background= 'white' ,  text='Game 
'+str(y)+': Numbers: '+num1.zfill(2)+'  '+num2.zfill(2)+'  '+num3.zfill(2)+' 
'+num4.zfill(2)+'  '+num5.zfill(2)+'  '+'PowerBall: '+pbnum.zfill(2))
 w.pack()

root.mainloop()

# 


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


ANN: CherryPy-2.2.0 released

2006-04-04 Thread remi
(sorry for the double-post, the title of the previous one was wrong)

Hello everyone,

After six months of hard work and 300 changesets since the last stable
release I'm happy to announce that CherryPy-2.2.0-final is out.

The biggest changes are:

- switch to a lowercase api (although the old camelCase API is still
supported for backward compatibility)

- support for multiple applications (new "cherrypy.tree" object)

- better error handling

- lots of bug fixes (especially in file-based sessions)

- better test suite.

Check out http://www.cherrypy.org/wiki/UpgradeTo2.2 for more details.

***
About CherryPy:

CherryPy is a simple (no dependencies), pythonic (doesn't
get in your way) web development framework.

Here is a sample Hello, World in CherryPy:

# import cherrypy
# class HelloWorld:
# @cherrypy.expose
# def index(self):
# yield ""
# yield "Hello world!"
# yield ""
# cherrypy.root = HelloWorld()
# cherrypy.server.start()

The project has been growing strongly lately:
cherrypy.org averaged 3000 visitors/day in March,
up from 2000 visitors/day in January and February;
and the cherrypy-users list just passed 700 users.


Details and downloads are available from:

http://www.cherrypy.org 


Remi.

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


Re: Help with display placement

2006-04-04 Thread [EMAIL PROTECTED]
This code come up, fairly centered in my screen.  What do you mean by
move?

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


how do you use pickle?

2006-04-04 Thread John Salerno
Here's what I have:

import pickle

data = open(r'C:\pickle_data.txt', 'w')
image = open(r'C:\peakhell.jpg')
pickle.Pickler(data)
data.dump(image)
data.close()
image.close()

First off, I'm not sure the second line is the way to do that. But my 
main problem is I don't know how to define the steps when pickling an 
object. How do you first create the object? Does it return a value? I tried:

pickler = pickle.Pickler(data)
pickle.Pickler(data)

Then I tried:

pickler.dump(image)
data.dump(image)

Basically, I'm just confused about all the syntax involved. Which 
objects do I operate on, and when? I can't find these answers in the 
documentation or in the interactive help, because I don't see any examples.

Furthermore, I get this error every time:

Traceback (most recent call last):
   File "C:\Documents and Settings\jsaler01.TUFTS\My 
Documents\Python24\myscripts\challenges\pickle.py", line 3, in -toplevel-
 import pickle
   File "C:\Documents and Settings\jsaler01.TUFTS\My 
Documents\Python24\myscripts\challenges\pickle.py", line 7, in -toplevel-
 pickle.Pickler(data)
AttributeError: 'module' object has no attribute 'Pickler'

So that makes me really confused, because I must have the syntax totally 
wrong if it can't even get past the initial creation of a pickler object.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference in Python and Ruby interactive shells

2006-04-04 Thread Michele Simionato
You want this recipe from Michael Hudson:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164

"automatically upgrade class instances on reload()"

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


Re: scraping nested tables with BeautifulSoup

2006-04-04 Thread [EMAIL PROTECTED]
Hey Kent,

thanks for your reply. how did you exactly save the file in firefox? if
I save the file locally I get the same error.

print len(soup('table')) gives me 4 instead 25

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


Re: how do you use pickle?

2006-04-04 Thread Fredrik Lundh
John Salerno wrote:

> Here's what I have:
>
> import pickle
>
> data = open(r'C:\pickle_data.txt', 'w')
> image = open(r'C:\peakhell.jpg')
> pickle.Pickler(data)
> data.dump(image)
> data.close()
> image.close()
>
> First off, I'm not sure the second line is the way to do that. But my
> main problem is I don't know how to define the steps when pickling an
> object. How do you first create the object? Does it return a value? I tried:
>
> pickler = pickle.Pickler(data)
> pickle.Pickler(data)
>
> Then I tried:
>
> pickler.dump(image)
> data.dump(image)
>
> Basically, I'm just confused about all the syntax involved. Which
> objects do I operate on

any object that supports pickling.

file handles does not belong to that group (what did you expect
pickle to do with a file handle ?)

or did "object" refer to the Pickler instance?  you don't really need to
bother with that; just use the dump *function* instead:

pickle.dump(object, file)

but if you insist on using your own Pickler instance, you have to save
the pickler instance in a variable, and call the dump method on that in-
stance:

myfile = open(somefilename, "wb")
mypickler = pickle.Pickler(myfile)
mypickler.dump(object)





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


Re: Best way to create a copy of a list

2006-04-04 Thread Alex Martelli
Frank Millman <[EMAIL PROTECTED]> wrote:
   ...
> If they are all equivalent from a functional point of view, I lean
> towards the second version. I agree with Rune that the third one is
> nicer to read, but somehow the [:] syntax makes it a bit more obvious
> what is going on.

I vastly prefer to call list(xxx) in order to obtain a new list with the
same items as xxx -- couldn't be more obvious than that.

You can't claim it's obvious that xxx[:] *copies* data -- because in
Numeric, for example, it doesn't, it returns an array that *shares* data
with xxx.  So, the [:] notation sometimes copies and sometimes does not,
list list(...) always copies -- if I want to ensure that a copy does
happen, then list(...) is the more obvious and readable choice.


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


Re: Difference in Python and Ruby interactive shells

2006-04-04 Thread malv
I think reload should be preceded by import.
Example:
Online code modification: upon modifying and saving mytest.py issue on
the interactive shell:
   >>>import mytest
   >>>reload(mytest)

The shell should respond with ""  (NOT:mytest.pyc)

Note that modules importing mytest should not use 'import * from
mytest' but 'import mytest';
This requires qualifying all objects as mytest.obj

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


Re: Help with display placement

2006-04-04 Thread Samantha
I want to be able to control where the dialog is displayed .  X,Y location 
from the upper left corner of the screen.
S
<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> This code come up, fairly centered in my screen.  What do you mean by
> move?
> 


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


Final Call for Papers: IAENG International Workshop on Software Engineering (in IMECS 2006)

2006-04-04 Thread imecs2006
Final CFP From:
IAENG: International Association of Engineers (http://www.iaeng.org)
Engineering Letters (http://www.engineeringletters.com)

The 2006 IAENG International Workshop on Software Engineering

(Part of The International MultiConference of Engineers and Computer
Scientists IMECS 2006)

IMECS 2006: 20-22 June, 2006, Hong Kong

http://www.iaeng.org/IMECS2006/IWSE2006.html


The IWSE'06 workshop is held as part of the International
MultiConference of Engineers and Computer Scientists 2006. The IMECS
2006 is organized by the International Association of Engineers
(IAENG), and serves as good platforms for the engineering community
members to meet with each other and to exchange ideas. Extended version
of the papers under this workshop can be included in the special issue
of our journal Engineering Letters. And, further extended version can
also be included in a book called "Current Trends in Software
Engineering " to be published by IAENG.

The IMECS 2006 multiconference has the focus on the frontier topics in
the theoretical and applied engineering and computer science subjects.
It consists of 14 workshops (see the details at IMECS website:
www.iaeng.org/IMECS2006). The multiconference serves as good platforms
for the engineering community members of different disciplines to meet
with each other and to exchange ideas. The current conference committee
of the IMECS 2006 includes over 140 workshop co-chairs and committee
members of mainly research center heads, department heads, professors,
research scientists from over 20 countries, while a few of the
committee members are also experienced software development directors
and engineers.

All submitted papers will be under peer review and accepted papers will
be published in the conference proceeding (ISBN: 988-98671-3-3). The
abstracts will be indexed and available at major academic databases.
The Technology Research Databases (TRD) of CSA (Cambridge Scientific
Abstracts), DBLP and Computer Science Bibliographies have promised to
index the print proceeding in advance of its publication. And after the
publication of the proceeding, print copies will also be sent to
databases like IEE INSPEC, Engineering Index (EI) and ISI Thomson
Scientific for indexing. The accepted papers will also be considered
for publication in the special issues of the journal Engineering
Letters. Some participants may also be invited to submit extended
version of their conference papers for considering as book chapters
(soon after the conference).


The topics of the workshop include, but not limited to, the following:

Software requirements engineering
Software architecture design
Software reusable components
Software testing and analysis
Software processes and workflows
Software safety, security and reliability
Software maintenance
Reverse engineering
Grid software
Software economics
Distribution systems
Programming languages
Embedded software systems
And their applications


=
Submission:

Prospective authors are invited to submit their draft paper in abstract
format (one page) or in full paper format to [EMAIL PROTECTED] by 12
March, 2006. The submitted file can be in MS Word format, PS format, or
PDF formats.

The first page of the draft paper should include:

· Title of the paper;
· Name, affiliation and e-mail address for each author;
· A maximum of 5 keywords of the paper;

Also, the name of the workshop session that the paper is being
submitted to should be stated in the email.


=
Important Dates:

Proposals for special conference sessions and tutorials deadline: 30
December, 2005
Draft Manuscript / Abstract Submission Deadline (extended): 6 April,
2006
Camera-Ready papers & Pre-registration Due (extended): 13 April, 2006
IMECS 2006: 20-22 June, 2006


More details about the IWSE 2006 can be found at:
http://www.iaeng.org/IMECS2006/IWSE2006.html


IWSE Workshop Co-chairs and Committee Members:

Chin-Chen Chang
IEEE Fellow, IEE Fellow
Chair Professor in Department of Information Engineering and Computer
Science, Feng Chia University, Taiwan

Zonghua Gu (co-chair)
Assistant Professor
Dept. of Computer Science,
Hong Kong University of Science and Technology, HK

Pao-Ann Hsiung
Associate Professor, Institute of Computer Science and Information
Engineering
National Chung Cheng University, Taiwan

Quah Tong Seng (co-chair)
Professor of Information Communication Institute of Singapore (ICIS)
Nanyang Technological University, Singapore

Chen-Hua She (co-chair)
Assistant Professor, Department of Mechanical and Automation
Engineering
Da-Yeh University, Taiwan




It will be highly appreciated if you can circulate these calls for
papers to your colleagues.

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

Re: Difference in Python and Ruby interactive shells

2006-04-04 Thread Alex Martelli
Michele Simionato <[EMAIL PROTECTED]> wrote:

> You want this recipe from Michael Hudson:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164
> 
>   "automatically upgrade class instances on reload()"

Note that the version in the printed Cookbook (2nd edition) was
substantially enhanced (mostly by me and Michael working together), I
don't know if Michael updated his ASPN recipe to reflect that but at any
rate you can download all the code from the printed Cookbook as a
zipfile from O'Reilly's site (sorry, I don't recall the URL).


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


Re: scraping nested tables with BeautifulSoup

2006-04-04 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> Hey Kent,
> 
> thanks for your reply. how did you exactly save the file in firefox? if
> I save the file locally I get the same error.

I think I right-clicked on the page and chose "Save page as..."

Here is a program that shows where BS is choking. It finds the last leaf 
node in the parse data by descending the last child of each node:

from urllib import urlopen
from BeautifulSoup import BeautifulSoup

data = urlopen('http://www.findaproperty.com/regi0018.html').read()
soup = BeautifulSoup(data)

tag = soup
while hasattr(tag, 'contents') and tag.contents:
 tag = tag.contents[-1]

print type(tag)
print tag


It prints:








So for some reason BS thinks that everything from  to the end 
is a single string.

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


Re: Difference in Python and Ruby interactive shells

2006-04-04 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Michele Simionato" <[EMAIL PROTECTED]> wrote:

> You want this recipe from Michael Hudson:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164
> 
>   "automatically upgrade class instances on reload()"


Impressive, but YIKES, there ought to be a simpler way to do this.  I 
think during the development phase editing and reloading would be very 
common and you'd want everything updated.  So why is it done the other 
way, the reference stays the same?  Is that useful?  Maybe time for a 
'switch' to set in Python to choose which behavior you want.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you use pickle?

2006-04-04 Thread John Salerno
Fredrik Lundh wrote:

> file handles does not belong to that group (what did you expect
> pickle to do with a file handle ?)
> 
> or did "object" refer to the Pickler instance?  you don't really need to
> bother with that; just use the dump *function* instead:
> 
> pickle.dump(object, file)
> 
> but if you insist on using your own Pickler instance, you have to save
> the pickler instance in a variable, and call the dump method on that in-
> stance:
> 
> myfile = open(somefilename, "wb")
> mypickler = pickle.Pickler(myfile)
> mypickler.dump(object)

I'm sorry, but I'm terribly confused. Nothing seems to be working for 
me. I *think* what I need to pickle is an image file, but so far I think 
all I'm doing is passing the file handle in as the 'object', which 
probably isn't correct. How would I get the actual image object to pass 
in? But I also tried pickling a string and that didn't work either.

I tried it both ways you suggest, but I can't get past the errors. I 
keep getting either

AttributeError: 'module' object has no attribute 'dump' (when I use the 
function)

or

AttributeError: 'module' object has no attribute 'dump' (when I create 
an instance)

Is there something special I need to do to use the pickle module? My 
program seems to recognize the import, but it keeps saying that nothing 
is an attribute of it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you use pickle?

2006-04-04 Thread John Salerno
John Salerno wrote:

> AttributeError: 'module' object has no attribute 'dump' (when I create 
> an instance)

That should be:

AttributeError: 'module' object has no attribute 'Pickler' (when I 
create an instance)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: scraping nested tables with BeautifulSoup

2006-04-04 Thread [EMAIL PROTECTED]
so it must be the malformed HTML comment that is confusing BS. I might
try different methods to see if I get the same problem... 

thanks

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


Dr. Dobb's Python-URL! - weekly Python news and links (Apr 4)

2006-04-04 Thread Peter Otten
QOTW: "Don't be too sure that it's compatible for the indefinite future. XML
is just as future-proof as any other format." - Sybren Stuvel

"Submitting a proposed change or fix [of the Python docs] is easier and
quicker than arguing about it on c.l.py and it seems to get pretty quickly
to the actual document maintainers." - Kent Johnson

Still struggling with recursion? comp.lang.python is newbie-friendly:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/2ca81c529b485f89/cf531016b54d0ca1?tvc=1

An interview with Michael Foord, author of MovablePython, is the
latest entry in the Python411 series intended to help you learn
Python and learn about Python:
http://www.awaretek.com/python/index.html

PyInstaller advances Gordon McMillan's earlier and widely-used 
work on Python installation:
http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi

"If PL/SQL is your only programming language, your Oracle work
may suffer." In her introductory article Catherine Devlin
demonstrates the power of Python from the perspective of a database
user:
http://www.oracle.com/technology/pub/articles/devlin-python-oracle.html
http://catherinedevlin.blogspot.com/2006/03/otn-article-addendum.html

Getting hold of subclasses is easy with new-style classes:
http://groups.google.com/group/comp.lang.python/msg/8fbe567f4ff121f9

Once you learn about the secret of iter()'s second parameter,
many use cases of a while-loop in C can be better expressed with
a for-loop in Python:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/b3ab8141c492bb21/df51ed3d13dd4975?tvc=1

The Python 2.4.3 bugfix release is available:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/93a2ad5d99db34ec


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

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

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

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

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

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

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

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

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

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

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

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

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

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

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

Among several Python-oriented RSS/RDF feeds available are
http://www.python

Re: scraping nested tables with BeautifulSoup

2006-04-04 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> Hey Kent,
> 
> thanks for your reply. how did you exactly save the file in firefox? if
> I save the file locally I get the same error.

The Firefox version, among other things, turns all the funky  and 
 tags into comments. Here is a way to do the same thing with BS:

import re
from urllib import urlopen
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup

# This tells BS to turn  into  which allows it
# to do a better job parsing this data
fixExclRe = re.compile(r']+)>')
BeautifulStoneSoup.PARSER_MASSAGE.append( (fixExclRe, r'') )

data = urlopen('http://www.findaproperty.com/regi0018.html').read()
soup = BeautifulSoup(data)

priceGuide = soup('table', dict(bgcolor="e0f0f8", border="0", 
cellpadding="2", cellspacing="2", width="150"))[1]
print priceGuide


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


Re: Dice probability problem

2006-04-04 Thread Tomi Lindberg
First, thanks to Antoon and Alexander for replying.

Antoon Pardon wrote:

> It would be better to construct distributions for one
> die and make a function that can 'add' two distributions
> together.

As both replies pointed to this direction, I tried to take 
that route. Here's the unpolished code I came up with. Does 
it look even remotely sane way to accomplish my goal?

-- code begins --

# A die with n faces
D = lambda n: [x+1 for x in range(n)]

# A new die with 6 faces
d6 = D(6)

# Adds another die to results.
def add_dice(sums, die):
 # If first die, all values appear once
 if not sums:
 for face in die:
 sums[face] = 1
 # Calculating the number of appearances for additional
 # dice
 else:
 new_sums = {}
 for k in sums.keys():
 for f in die:
 if new_sums.has_key(k+f):
 new_sums[k+f] += sums[k]
 else:
 new_sums[k+f] = sums[k]
 sums = new_sums
 return sums

sums = add_dice({}, d6)
sums = add_dice(sums, d6)
sums = add_dice(sums, d6)

-- code ends --

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


Re: how do you use pickle?

2006-04-04 Thread Fredrik Lundh
John Salerno wrote:

> > but if you insist on using your own Pickler instance, you have to save
> > the pickler instance in a variable, and call the dump method on that in-
> > stance:
> >
> > myfile = open(somefilename, "wb")
> > mypickler = pickle.Pickler(myfile)
> > mypickler.dump(object)
>
> I'm sorry, but I'm terribly confused. Nothing seems to be working for
> me. I *think* what I need to pickle is an image file, but so far I think
> all I'm doing is passing the file handle in as the 'object'

define "image file".  the data in the file, the file name, or some other
representation?

> I tried it both ways you suggest, but I can't get past the errors. I
> keep getting either
>
> AttributeError: 'module' object has no attribute 'dump' (when I use the
> function)

did you, by any chance, name your test script "pickle.py" ?





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


Re: how do you use pickle?

2006-04-04 Thread Pythor

John Salerno wrote:

> I'm sorry, but I'm terribly confused. Nothing seems to be working for
> me. I *think* what I need to pickle is an image file,

SNIP

Hint: Read the source for that page more carefully.

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


Re: how do you use pickle?

2006-04-04 Thread John Salerno
Fredrik Lundh wrote:
> John Salerno wrote:
> 
>>> but if you insist on using your own Pickler instance, you have to save
>>> the pickler instance in a variable, and call the dump method on that in-
>>> stance:
>>>
>>> myfile = open(somefilename, "wb")
>>> mypickler = pickle.Pickler(myfile)
>>> mypickler.dump(object)
>> I'm sorry, but I'm terribly confused. Nothing seems to be working for
>> me. I *think* what I need to pickle is an image file, but so far I think
>> all I'm doing is passing the file handle in as the 'object'
> 
> define "image file".  the data in the file, the file name, or some other
> representation?
> 
>> I tried it both ways you suggest, but I can't get past the errors. I
>> keep getting either
>>
>> AttributeError: 'module' object has no attribute 'dump' (when I use the
>> function)
> 
> did you, by any chance, name your test script "pickle.py" ?

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


Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-04 Thread Robert Kern
Roger Binns wrote:
> "Paul Boddie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> 
>>It looks like you may have Unicode objects that you're presenting to
>>sqlite. In any case, with earlier versions of pysqlite that I've used,
>>you need to connect with a special unicode_results parameter,
> 
> He is using apsw.  apsw correctly handles unicode.  In fact it won't
> accept a str with bytes >127 as they will be an unknown encoding and
> SQLite only uses Unicode internally.  It does have a blob type
> using buffer for situations where binary data needs to be stored.
> pysqlite's mishandling of Unicode is one of the things that drove
> me to writing apsw in the first place.

Ah, I misread the OP's traceback.

Okay, the OP is getting regular strings, which are probably encoded in
ISO-8859-1 if I had to guess, from the Oracle DB. He is trying to pass them in
to SQLiteCur.execute() which tries to make a unicode string from the input:

In [1]: unicode('\xdc')
---
exceptions.UnicodeDecodeErrorTraceback (most recent call
last)

/Users/kern/

UnicodeDecodeError: 'ascii' codec can't decode byte 0xdc in position 0: ordinal
not in range(128)

*Now*, my advice to the OP is to figure out the encoding of the strings that are
being returned from Oracle. As I said, ISO-8859-1 is probably a good guess.
Then, he would *decode* the string to a unicode string using the encoding. E.g.:

  row = row.decode('iso-8859-1')

Then everything should be peachy. I hope.

-- 
Robert Kern
[EMAIL PROTECTED]

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: how do you use pickle?

2006-04-04 Thread John Salerno
Fredrik Lundh wrote:

> define "image file".  the data in the file, the file name, or some other
> representation?

I was being dense again. I was just opening the file, but not reading 
it! After reading it, it's easy to pickle it.

> did you, by any chance, name your test script "pickle.py" ?

That did the trick! Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you use pickle?

2006-04-04 Thread John Salerno
Pythor wrote:
> John Salerno wrote:
> 
>> I'm sorry, but I'm terribly confused. Nothing seems to be working for
>> me. I *think* what I need to pickle is an image file,
> 
> SNIP
> 
> Hint: Read the source for that page more carefully.
> 

Hmmm...the source doesn't say much. Is there more to do with the source 
beyond using it to figure out what 'peak hell' means?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standalone Python functions in UML?

2006-04-04 Thread bruno at modulix
Ravi Teja wrote:
(snip)
>>>More theoretical question is if I create classes on the fly, how UML can
> 
> reflect that?
> 
> "On the fly" usually means "at runtime". I guess you mean if you
> "change code" will my diagram stay in sync?.

Nope, the OP really meant "on the fly", as in "at runtime". In python,
it is possible to create new classes at runtime. Remember,
everything-is-an-object implies that classes are objects too.

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


Re: Python and microsoft outlook-using com, can I interact with msoutlook?

2006-04-04 Thread J Correia

><[EMAIL PROTECTED]> wrote in message 
>news:[EMAIL PROTECTED]
>Hi All,
> know that Microsoft Exchange has a com interface, CDO, but I can't seem to
>find one for Microsoft outlook.
>does anyone have code snippets for using msoutlook and python, or
>suggestions?

Check out:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/173216
also:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/266625
and:
http://www.win32com.de/index.php?option=com_content&task=view&id=97&Itemid=192

Also I've emailed you a pdf I'd downloaded a while back,
unfortunately I can't remember the source to credit here.

That should get you started.

HTH,

JC



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


Re: Standalone Python functions in UML?

2006-04-04 Thread bruno at modulix
Philippe Martin wrote:
> Roman Susi wrote:
> 
(snip)

>>More theoretical question is if I create classes on the fly, how UML can
>>reflect that?
> 
> 
> You mean objects I think:

Yes : class objects !-)

Python's classes *are* objects. And you can create new classes at runtime.

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


Re: Dice probability problem

2006-04-04 Thread Gerard Flanagan

Tomi Lindberg wrote:
>
> # A die with n faces
> D = lambda n: [x+1 for x in range(n)]
> 

That can be written:

D = lambda n : range(1,n+1)

Gerard

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


Re: how do you use pickle?

2006-04-04 Thread Pythor

John Salerno wrote:
> Pythor wrote:
> > John Salerno wrote:
> >
> >> I'm sorry, but I'm terribly confused. Nothing seems to be working for
> >> me. I *think* what I need to pickle is an image file,
> >
> > SNIP
> >
> > Hint: Read the source for that page more carefully.
> >
>
> Hmmm...the source doesn't say much. Is there more to do with the source
> beyond using it to figure out what 'peak hell' means?

Yes... It mentions a whole different file, which you need to use pickle
on.

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


kinterbas and Python

2006-04-04 Thread Balin

Hi all,
I have some problem with packege kinterbas for Firebird db connection
this is my code:

import kinterbasdb

class ConnessioneDB:
def initialize(self):
kinterbasdb.init(concurrency_level=1)
con = kinterbasdb.connect(host='192.168.1.20',
database='/home/db/TEST.FDB', user='SYSDBA', password='masterkey) <--- E

def testtable(self):
cur = con.cursor()
cur.execute("SELECT * FROM TEST")
for row in cur:
print str(row[0])

if __name__ == '__main__':
xCon = ConnessioneDB()
xCon.initialize() <-- ERROR 
xCon.testtable()

use kinterbas.init(concurrency_level=?) to set the concurrency level
legally...why ? I'm try to set this value
kinterbas.init(concurrency_level=1)  but don't work...please help..this
is my first program. Thanks in advanced.Marco.Italy
-- 

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


Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-04 Thread Paul Boddie
Robert Kern wrote:
> Roger Binns wrote:
> > "Paul Boddie" <[EMAIL PROTECTED]> wrote
> >>It looks like you may have Unicode objects that you're presenting to
> >>sqlite. In any case, with earlier versions of pysqlite that I've used,
> >>you need to connect with a special unicode_results parameter,

Note that I've since mentioned client_encoding which seems to matter
for pysqlite 1.x.

> > He is using apsw.  apsw correctly handles unicode.  In fact it won't
> > accept a str with bytes >127 as they will be an unknown encoding and
> > SQLite only uses Unicode internally.  It does have a blob type
> > using buffer for situations where binary data needs to be stored.
> > pysqlite's mishandling of Unicode is one of the things that drove
> > me to writing apsw in the first place.

For pysqlite 2.x, it appears that Unicode objects can be handed
straight to the API methods, and I'd be interested to hear about your
problems with pysqlite, Unicode and what actually made you write apsw
instead.

> Ah, I misread the OP's traceback.
>
> Okay, the OP is getting regular strings, which are probably encoded in
> ISO-8859-1 if I had to guess, from the Oracle DB. He is trying to pass them in
> to SQLiteCur.execute() which tries to make a unicode string from the input:

[...]

There's an Oracle environment variable that appears to make a
difference: NLS_CHARSET, perhaps - it's been a while since I've had to
deal with Oracle, and I'm not looking for another adventure into
Oracle's hideous documentation to find out.

> *Now*, my advice to the OP is to figure out the encoding of the strings that 
> are
> being returned from Oracle. As I said, ISO-8859-1 is probably a good guess.
> Then, he would *decode* the string to a unicode string using the encoding. 
> E.g.:
>
>   row = row.decode('iso-8859-1')
>
> Then everything should be peachy. I hope.

Yes, just find out what Oracle wants first, then set it all up, noting
that without looking into the Oracle wrapper being used, I can't
suggest an easier way.

Paul

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


Re: Standalone Python functions in UML?

2006-04-04 Thread Roman Susi
Ravi Teja wrote:
>>>Out of curiosity, how do I draw functions outside classes with UML? How
> 
> module could be drawn in this case?
> 
> As a utility class.

So, function could be a utility class method. If there are no better ways.

>>>More theoretical question is if I create classes on the fly, how UML can
> 
> reflect that?
> 
> "On the fly" usually means "at runtime". I guess you mean if you
> "change code" will my diagram stay in sync?. You will have to use round
> trip tools. I don't know any tool supports round trip for Python code.
> But if you just mean reverse engineering, lookup PyNSource, Boa
> Constructor, PyReverse among others

No. I do not need it. I just want to know if UML is capable of doing it.

> 
>>>(I know that Python code itself is best at communication design ideas,
> 
> but there are some people which prefer to talk UML.)
> 
> Actually no. Python is a good tool for "prototyping" which is not the
> same as "communicating design ideas". Diagrams are better for the later
> and do not need to be executable. At least from what I know, except
> Eiffel, no language makes that claim. UML is really the only contender
> currently for design notation.

Well, maybe SOL (Semantic Object Language) could also be quite
beneficial in some cases. At least, it depends with whom to communicate
design ideas and what level of formality to maintain.

Also, my argument that Python is quite good at communicating design
ideas is supported by the fact that Python developers do not use UML (or
other modelling tools/languages) as often as say Java programmers, nor
feel the need to. And probably Python is too dynamic for UML. That is
another reason rountrip tools aren't there.

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


Re: how do you use pickle?

2006-04-04 Thread John Salerno
Pythor wrote:
> John Salerno wrote:
>> Pythor wrote:
>>> John Salerno wrote:
>>>
 I'm sorry, but I'm terribly confused. Nothing seems to be working for
 me. I *think* what I need to pickle is an image file,
>>> SNIP
>>>
>>> Hint: Read the source for that page more carefully.
>>>
>> Hmmm...the source doesn't say much. Is there more to do with the source
>> beyond using it to figure out what 'peak hell' means?
> 
> Yes... It mentions a whole different file, which you need to use pickle
> on.
> 

Yikes, I even took a second look at that after you said re-read the 
source and then I ignored it! Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with display placement

2006-04-04 Thread [EMAIL PROTECTED]
Ok so I'm not to bright sometimes

Well if you want this kinda control I suggest you go ahead and subclass
toplevel, but the simple answer before running

root.mainloop()


make a call to

root.geometry(geometryString)



geoometrystring is in the format WxH+X+Y  - you may hve to do some
screen calcs first to get the right numbers.  ie "50x100+50+50" create
a  50pix by 100 pix window offset 50 from the top and 50 from the left.

To my mind, better to subclass toplevel and set everything in there -
but's mostly stylistic preference for something this simple.

And while I'm making suggestions ;)  Try wxPython.  I used tKinter for
about 3 months before tossing it in frustration when I wanted to do
somtheing "slick" , but I have a lot of fondness for some quick and
dirty UI's I did in tKinter a ways back.

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


Re: scraping nested tables with BeautifulSoup

2006-04-04 Thread [EMAIL PROTECTED]
Thanks Kent that works perfectly.. How can I strip all the HTML and
create easily a dictionary of {location:price}  ??

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


Re: Standalone Python functions in UML?

2006-04-04 Thread Philippe Martin
But not in UML: a class diagram will represent classes while a sequence
diagram objects.

Philippe



bruno at modulix wrote:

> Philippe Martin wrote:
>> Roman Susi wrote:
>> 
> (snip)
> 
>>>More theoretical question is if I create classes on the fly, how UML can
>>>reflect that?
>> 
>> 
>> You mean objects I think:
> 
> Yes : class objects !-)
> 
> Python's classes *are* objects. And you can create new classes at runtime.
> 
> (snip)

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


Re: how do you use pickle?

2006-04-04 Thread Pythor

John Salerno wrote:
> Pythor wrote:
> > John Salerno wrote:
> >> Pythor wrote:
> >>> John Salerno wrote:
> >>>
>  I'm sorry, but I'm terribly confused. Nothing seems to be working for
>  me. I *think* what I need to pickle is an image file,
> >>> SNIP
> >>>
> >>> Hint: Read the source for that page more carefully.
> >>>
> >> Hmmm...the source doesn't say much. Is there more to do with the source
> >> beyond using it to figure out what 'peak hell' means?
> >
> > Yes... It mentions a whole different file, which you need to use pickle
> > on.
> >
>
> Yikes, I even took a second look at that after you said re-read the
> source and then I ignored it! Thanks!

Whis is why I said carefully ;)  I missed it several times myself when
I was working on the challenge.

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


Re: scraping nested tables with BeautifulSoup

2006-04-04 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> Thanks Kent that works perfectly.. How can I strip all the HTML and
> create easily a dictionary of {location:price}  ??

This should help:

prices = priceGuide.table

for tr in prices:
 print tr.a.string, tr.a.findNext('font').string

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


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Apr 4)

2006-04-04 Thread gene tani

Peter Otten wrote:
> The old Python "To-Do List" now lives principally in a
> SourceForge reincarnation.
> http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse
> http://python.sourceforge.net/peps/pep-0042.html
>

Thanks, very nice summary.

One thing, the peps moved:
http://www.python.org/dev/peps/pep-0042/

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


ANNOUNCE: wxPython 2.6.3.2

2006-04-04 Thread Robin Dunn

Announcing
--

The 2.6.3.2 release of wxPython is now available for download at
http://wxpython.org/download.php.  This is a mostly bug fix release
and takes care of several "unfortunate features" discovered in the
2.6.3.0 release made last week.  A summary of changes is listed below
and at http://wxpython.org/recentchanges.php.


What is wxPython?
-

wxPython is a GUI toolkit for the Python programming language. It
allows Python programmers to create programs with a robust, highly
functional graphical user interface, simply and easily. It is
implemented as a Python extension module that wraps the GUI components
of the popular wxWidgets cross platform library, which is written in
C++.

wxPython is a cross-platform toolkit. This means that the same program
will usually run on multiple platforms without modifications.
Currently supported platforms are 32-bit Microsoft Windows, most Linux
or other Unix-like systems using GTK2, and Mac OS X 10.2+, in most
cases the native widgets are used on each platform.


Changes in 2.6.3.2
--

Fixed reference leak in wx.gizmos.TreeListCtrl.GetSelections.

wxMSW: Fixed sizing issue with wx.Choice and wx.ComboBox.  This change
was implemented by reverting a prior fix for a different problem
(continuous painting/resizing when a combobox is used as a widget in a
wx.html.HtmlWindow) so a method to fix both problems is still being
investigated.

wxGTK: Fixed potential buffer overrun when pasting from the
clipboard.

Fixed problem in wx.lib.splitter when used on 64-bit platforms.  Used
the current length of the list for specifying an append instead of
sys.maxint.

wxMSW: Support added for XP themed owner drawn buttons and bitmap
buttons.  For example, if you change the foreground color of a button
it will now be drawn with the XP themed style rather than an ugly
generic button style.

XRCed: Fix for Copy/Paste objects with international characters.

Fixed the equality and inequality operators for some of the basic
data types (wx.Point, wx.Size, wx.Colour, etc.) to no longer raise a
TypeError if the compared object is not compatible, but to just return
a boolean as expected.  For example::

  wx.Colour(64,0,64) == 123  ==> False

wxMSW: Fixed (again) sizing/positioning issues of calling Realize on
a wx.ToolBar that is not manaaged directly by a frame and that is
already shown.

wxMSW: Fixed wx.Choice/wx.ComboBox so they send events when a new item
is selected only with the keyboard.



-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!

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


Re: how do you use pickle?

2006-04-04 Thread John Salerno
Pythor wrote:

> Whis is why I said carefully ;)  I missed it several times myself when
> I was working on the challenge.

Ok, frustration has set in again. I see the file name in the source 
code, but am I meant to actually access a file, or just use the name 
itself? I also had to look up what 'banner' meant in Unix, which wasn't 
a very fun thing to have to do for a Python puzzle.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: wxPython 2.6.3.2

2006-04-04 Thread John Salerno
Robin Dunn wrote:
> 
> Announcing
> --
> 
> The 2.6.3.2 release of wxPython is now available for download at
> http://wxpython.org/download.php.  This is a mostly bug fix release
> and takes care of several "unfortunate features" discovered in the
> 2.6.3.0 release made last week.  A summary of changes is listed below
> and at http://wxpython.org/recentchanges.php.

Does it just install over the previous version?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you use pickle?

2006-04-04 Thread John Salerno
John Salerno wrote:
> Pythor wrote:
> 
>> Whis is why I said carefully ;)  I missed it several times myself when
>> I was working on the challenge.
> 
> Ok, frustration has set in again. I see the file name in the source 
> code, but am I meant to actually access a file, or just use the name 
> itself? I also had to look up what 'banner' meant in Unix, which wasn't 
> a very fun thing to have to do for a Python puzzle.

Ah, I should have known we weren't done with URL manipulation yet. Now I 
just need to figure out what to do with this source code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] markup.py - 1.2 - an HTML/XML generator

2006-04-04 Thread Walter Dörwald
Peter Hansen wrote:
> Felipe Almeida Lessa wrote:
>> $ pwd
>> /usr/lib/python2.4/site-packages
>> $ grep -re klass . | wc -l
>> 274
>> $ grep -re class_ . | wc -l
>> 897
> 
> How many of those "class_" instances are really just substrings of 
> "__class__" and "class_name" and such?  On my machine, I see a handful 
> in the standard library, and _none_ in site-packages (which has only 
> 1709 .py files, mind you).
> 
>> For me that's enough. "class_" is used at least three times more than
>> "klass". Besides, as Scott pointed out, "class_" is prefered by the
>> guidelines too.
> 
> Actually what he posted explicitly states that "cls" is preferred. 
> Following that it says that one should considering appending _ if the 
> name conflicts with a keyword (and one can assume it means "for all 
> keywords other than class").

No, I think what it means is this: "Use cls as the name of the first
argument in a classmethod. For anything else (i.e. name that are not the
first argument in a classmethod) append an _, if it clashes with a
Python keyword.". So class_ is perfectly OK, if the Python argument maps
to the HTML attribute name.

Bye,
   Walter Dörwald
-- 
http://mail.python.org/mailman/listinfo/python-list


[wxPython-users] Re: ANNOUNCE: wxPython 2.6.3.2

2006-04-04 Thread Kevin Walzer
Robin Dunn wrote:
> 
> Announcing
> --
> 
> The 2.6.3.2 release of wxPython is now available for download at
> http://wxpython.org/download.php.  This is a mostly bug fix release
> and takes care of several "unfortunate features" discovered in the
> 2.6.3.0 release made last week.  A summary of changes is listed below
> and at http://wxpython.org/recentchanges.php.
> 
> 
> What is wxPython?
> -
> 
> wxPython is a GUI toolkit for the Python programming language. It
> allows Python programmers to create programs with a robust, highly
> functional graphical user interface, simply and easily. It is
> implemented as a Python extension module that wraps the GUI components
> of the popular wxWidgets cross platform library, which is written in
> C++.
> 
> wxPython is a cross-platform toolkit. This means that the same program
> will usually run on multiple platforms without modifications.
> Currently supported platforms are 32-bit Microsoft Windows, most Linux
> or other Unix-like systems using GTK2, and Mac OS X 10.2+, in most
> cases the native widgets are used on each platform.
> 
> 
> Changes in 2.6.3.2
> --
> 
> Fixed reference leak in wx.gizmos.TreeListCtrl.GetSelections.
> 
> wxMSW: Fixed sizing issue with wx.Choice and wx.ComboBox.  This change
> was implemented by reverting a prior fix for a different problem
> (continuous painting/resizing when a combobox is used as a widget in a
> wx.html.HtmlWindow) so a method to fix both problems is still being
> investigated.
> 
> wxGTK: Fixed potential buffer overrun when pasting from the
> clipboard.
> 
> Fixed problem in wx.lib.splitter when used on 64-bit platforms.  Used
> the current length of the list for specifying an append instead of
> sys.maxint.
> 
> wxMSW: Support added for XP themed owner drawn buttons and bitmap
> buttons.  For example, if you change the foreground color of a button
> it will now be drawn with the XP themed style rather than an ugly
> generic button style.
> 
> XRCed: Fix for Copy/Paste objects with international characters.
> 
> Fixed the equality and inequality operators for some of the basic
> data types (wx.Point, wx.Size, wx.Colour, etc.) to no longer raise a
> TypeError if the compared object is not compatible, but to just return
> a boolean as expected.  For example::
> 
>   wx.Colour(64,0,64) == 123  ==> False
> 
> wxMSW: Fixed (again) sizing/positioning issues of calling Realize on
> a wx.ToolBar that is not manaaged directly by a frame and that is
> already shown.
> 
> wxMSW: Fixed wx.Choice/wx.ComboBox so they send events when a new item
> is selected only with the keyboard.
> 
> 
> 
Is the new build of wxPython-Mac a universal binary?

-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: wxPython 2.6.3.2

2006-04-04 Thread Robin Dunn
Kevin Walzer wrote:

> Is the new build of wxPython-Mac a universal binary?
> 

No, not yet.  There is still some more work to do for that.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!

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


  1   2   >