Sunday, January 10, 2010

comp.lang.python - 10 new messages in 6 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Prepend to logging message - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/dda048a92c122117?hl=en
* Microsoft Office Word and Python (Win XP) - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/5aba5d0795b3ea0b?hl=en
* PIL how to display multiple images side by side - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/1518ceac623a90c1?hl=en
* subprocess.Popen does not close pipe in an error case - 2 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/11833908809de6ba?hl=en
* Ask how to use HTMLParser - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/582da459a7cccdc5?hl=en
* lightweight encryption of text file - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b31a5b5f58084f12?hl=en

==============================================================================
TOPIC: Prepend to logging message
http://groups.google.com/group/comp.lang.python/t/dda048a92c122117?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Jan 9 2010 5:01 pm
From: Joan Miller


How to prepend anything to a logging message? Is possible to do it
from the dictionary object (ExtraLog) or is there is that override
process() [1]?

------------------
class ExtraLog(object):

def __getitem__(self, name):
if name == 'foo':
result = 'testing'
return result

def __iter__(self):
keys = ['foo',]
keys.extend(self.__dict__.keys())
return iter(keys)

logger = logging.LoggerAdapter(logging.getLogger('foo'), ExtraLog())
------------------


[1] http://docs.python.org/library/logging.html#logging.LoggerAdapter


== 2 of 2 ==
Date: Sat, Jan 9 2010 7:27 pm
From: Ishwor Gurung


Joan,

2010/1/10 Joan Miller <peloko45@gmail.com>:
> How to prepend anything to a logging message? Is possible to do it
> from the dictionary object (ExtraLog) or is there is that override
> process() [1]?
>
> ------------------
> class ExtraLog(object):
>
>    def __getitem__(self, name):
>        if name == 'foo':
>            result = 'testing'
>        return result
>
>    def __iter__(self):
>        keys = ['foo',]
>        keys.extend(self.__dict__.keys())
>        return iter(keys)
>
> logger = logging.LoggerAdapter(logging.getLogger('foo'), ExtraLog())
> ------------------

Yep. Just subclass LoggerAdapter and override process(..)
Read this: http://docs.python.org/library/logging.html#adding-contextual-information-to-your-logging-output
--
Regards
Ishwor Gurung
Key id:0xa98db35e
Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5

==============================================================================
TOPIC: Microsoft Office Word and Python (Win XP)
http://groups.google.com/group/comp.lang.python/t/5aba5d0795b3ea0b?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Jan 9 2010 5:09 pm
From: David Monaghan


On Sat, 9 Jan 2010 11:18:12 -0800 (PST), "3lvss0809@gmail.com"
<3lvss0809@gmail.com> wrote:

>Dennis Lee Bieber: Im not familiar with python, also Im not
>programmer.

What you want to do isn't complicated, but it isn't simple either, unless
you're familiar with VBA/VBS. I approach these problems by first getting the
VBA code by recording a macro within Word. I then convert it to VB Script,
which is a learning process in itself. Converting that script to Python com
is another learning process and then putting the whole thing together with
file finding and saving is another job.

When you've done that, you won't feel able to say you're not a programmer -
and you should feel familiar with Python, too.

DaveM


== 2 of 2 ==
Date: Sat, Jan 9 2010 8:46 pm
From: Dennis Lee Bieber


On Sat, 9 Jan 2010 11:18:12 -0800 (PST), "3lvss0809@gmail.com"
<3lvss0809@gmail.com> declaimed the following in
gmane.comp.python.general:


> Dennis Lee Bieber: Im not familiar with python, also Im not
> programmer. Thats why Im not able to do so when people tell me "do
> this then use XYZ function which will give you ZYX from what you can
> do that and you will get result". Im still willing to learn but there
> are thousands of python tutorials and the one for exsactly this topic
> probably doesn't exsist. The .doc extension is required, so I cannot
> use .txt because I need the HD files in .doc.

And what I suggested as a prototype using plain text files was to
get you to where the Python side of things is working... Then you study
the COM aspect and plug it into the Python (replacing the simple text
I/O operations with COM operations).

This way you don't have to fight with learning both Python and COM
as one unit.
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/


==============================================================================
TOPIC: PIL how to display multiple images side by side
http://groups.google.com/group/comp.lang.python/t/1518ceac623a90c1?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Jan 9 2010 9:24 pm
From: Lie Ryan


On 1/9/2010 8:43 AM, suresh.amritapuri wrote:
> Hi,
>
> In PIL, how to display multiple images in say m rows and n colums when
> I have m*n images.
>
> suresh

Tkinter has PhotoImage widget and PIL has support for this widget:
http://www.pythonware.com/library/pil/handbook/imagetk.htm


== 2 of 2 ==
Date: Sat, Jan 9 2010 9:51 pm
From: "Alf P. Steinbach"


* Lie Ryan:
> On 1/9/2010 8:43 AM, suresh.amritapuri wrote:
>> Hi,
>>
>> In PIL, how to display multiple images in say m rows and n colums when
>> I have m*n images.
>>
>> suresh
>
> Tkinter has PhotoImage widget and PIL has support for this widget:
> http://www.pythonware.com/library/pil/handbook/imagetk.htm

Maybe I've misunderstood something (in that case glad to learn!), but I believe
PhotoImage is not a widget, and that a PhotoImage has to be presented in e.g. a
Label widget or some other widget that's able to display images.


Cheers,

- Alf

==============================================================================
TOPIC: subprocess.Popen does not close pipe in an error case
http://groups.google.com/group/comp.lang.python/t/11833908809de6ba?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Jan 9 2010 11:51 pm
From: Nobody


On Wed, 06 Jan 2010 11:39:37 -0800, Steven K. Wong wrote:

> Suppose now all the prog1.poll() calls/loop are replaced by a single
> prog1.wait(). Without the explicit prog1.stdout.close(), prog1.wait()
> will not return, so the calling process still hangs. Because calling
> prog1.wait() means that the calling process will naturally never read
> prog1.stdout, I would argue that prog1.wait() should close the pipe
> before actually waiting for prog1 to exit. Makes sense?

prog1.stdout might be being read by a different thread.

== 2 of 2 ==
Date: Sat, Jan 9 2010 11:54 pm
From: Nobody


On Wed, 06 Jan 2010 19:05:40 -0800, Steven K. Wong wrote:

> Well, the example code at
> http://www.python.org/ ... /subprocess.html#replacing-shell-pipeline
> has the same issue:

> Perhaps the doc can be improved to remind folks to close p1.stdout if
> the calling process doesn't need it, unless wait() is changed to close
> it and p1.wait() is called.
>
> Am I making any sense here?

The docs should include the p1.stdout.close().

It isn't needed in the typical case, where p2 runs until EOF on stdin, but
(as you have noticed) it matters if p2 terminates prematurely.


==============================================================================
TOPIC: Ask how to use HTMLParser
http://groups.google.com/group/comp.lang.python/t/582da459a7cccdc5?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 10 2010 12:16 am
From: Nobody


On Fri, 08 Jan 2010 11:44:48 +0800, Water Lin wrote:

> I am a new guy to use Python, but I want to parse a html page now. I
> tried to use HTMLParse. Here is my sample code:
> ----------------------
> from HTMLParser import HTMLParser

Note that HTMLParser only tokenises HTML; it doesn't actually *parse* it.
You just get a stream of tag, text, entity, text, tag, ..., not a parse
tree.

In particular, if an element has its start and/or end tags omitted, you
won't get any notification about the start and/or end of the element;
you have to figure that out yourself from the fact that you're getting a
tag which wouldn't be allowed outside or inside the element.

E.g. if the document has omitted </p> tags, if you get a <p> tag when
you are (or *thought* that you were) already within a paragraph, you can
infer the omitted </p> tag.

If you want an actual parser, look at BeautifulSoup. This also does
a good job of handling invalid HTML (which seems to be far more
common than genuine HTML).


==============================================================================
TOPIC: lightweight encryption of text file
http://groups.google.com/group/comp.lang.python/t/b31a5b5f58084f12?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 10 2010 12:33 am
From: Nobody


On Fri, 08 Jan 2010 20:14:51 +0100, Daniel Fetchinson wrote:

> I have a plain text file which I would like to protect in a very
> simple minded, yet for my purposes sufficient, way. I'd like to
> encrypt/convert it into a binary file in such a way that possession of
> a password allows anyone to convert it back into the original text
> file while not possessing the password one would only see the
> following with the standard linux utility 'file':

> What would be the simplest way to achieve this using preferably stock
> python without 3rd party modules? If a not too complex 3rd party
> module made it really simple that would be acceptable too.

RC4 (aka ArcFour) is quite trivial to implement, and better than inventing
your own cipher or using a Vignere:

import itertools

class arcfour:
def __init__(self, key):
self.s = range(256)
self.schedule(map(ord, key))
self.pad = self.prng()

def swap(self, i, j):
self.s[i], self.s[j] = self.s[j], self.s[i]

def schedule(self, key):
j = 0
for i, c in zip(xrange(256), itertools.cycle(key)):
j = (j + self.s[i] + c) % 256
self.swap(i, j)

def prng(self):
i = j = 0
while True:
i = (i + 1) % 256
j = (j + self.s[i]) % 256
self.swap(i, j)
yield self.s[(self.s[i] + self.s[j]) % 256]

def crypt(self, string):
chars = (chr(c ^ r) for c, r in zip(map(ord, string), self.pad))
return ''.join(chars)

I suggest that you don't use the password itself as the key, unless you're
sure that a low-entropy string won't be used. Instead, create an SHA hash
(see the sha and hashlib modules) of the password and use that.

==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate