Thursday, April 8, 2010

comp.lang.python - 25 new messages in 12 topics - digest

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

comp.lang.python@googlegroups.com

Today's topics:

* daemon.DaemonContext - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/89daec0325dde0d2?hl=en
* Pythonic list reordering - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f9493c7f802d0329?hl=en
* Performance of list vs. set equality operations - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/818d143c7e9550bc?hl=en
* pass object or use self.object? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6f51302327b58aac?hl=en
* Dynamically growing an array to implement a stack - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/a98cf3a9303bedbf?hl=en
* How to open and read an unknown extension file - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/570025039368c07b?hl=en
* order that destructors get called? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/6c875525954df888?hl=en
* The Regex Story - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/6511effbbbfc5584?hl=en
* lambda with floats - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/c803050597639e1e?hl=en
* Cleanup guarantees? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/80cea772fdae47be?hl=en
* SIP - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/f1667242f17f70c7?hl=en
* Is there any module/utility like 'rsync' in python - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/60d5a3842d0a4d58?hl=en

==============================================================================
TOPIC: daemon.DaemonContext
http://groups.google.com/group/comp.lang.python/t/89daec0325dde0d2?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Apr 8 2010 4:52 pm
From: Ben Finney


Rebelo <puntabluda@gmail.com> writes:

> i found a crude workaround:
> i wrote a function in which i start logging after deamon starts

That seems rather sub-optimal; you'll be unable to use the logger for
anything before the daemon context opens. This kind of problem is
exactly what 'DaemonContext.files_preserve' is intended to address.

Hopefully you can make use of the 'DaemonContext.files_preserve' option
as intended; please see my message earlier in this thread.

--
\ "Of all classes the rich are the most noticed and the least |
`\ studied." —John Kenneth Galbraith, _The Age of Uncertainty_, |
_o__) 1977 |
Ben Finney


== 2 of 2 ==
Date: Thurs, Apr 8 2010 11:39 pm
From: Rebelo


Ben Finney wrote:
> Vinay Sajip <vinay_sajip@yahoo.co.uk> writes:
>
>> On Apr 8, 1:58 pm, Rebelo <puntabl...@gmail.com> wrote:
>>> Vinay Sajip wrote:
>>>> My guess is - files_preserve needs to be passed a file handle and
>>>> not alogginghandler.
>
> This is correct. As the 'DaemonContext.__init__' docstring says::
>
> | `files_preserve`
> | :Default: ``None``
> |
> | List of files that should *not* be closed when starting the
> | daemon. If ``None``, all open file descriptors will be closed.
> |
> | Elements of the list are file descriptors (as returned by a file
> | object's `fileno()` method) or Python `file` objects. Each
> | specifies a file that is not to be closed during daemon start.
>
>>> do you know where can i find good documnetation for python-daemon?
>
> The docstrings and PEP 3143 are currently the best documentation for
> 'python-daemon'; both describe the 'files_preserve' option as above.
>
>> http://groups.google.com/group/comp.lang.python/msg/851ce78e53812ade
>
> As expressed in the referenced message, I would welcome someone writing
> better documentation and contributing patches.
>
>> It may lead you to more information. The thread shows that Sean
>> DiZazzo got logging working with the package.
>
> It's important to note (as you did, thanks Vinay) that none of the
> 'logging.handlers' are file descriptors. Nor are they file objects.
>
> If we can get a Python 'file' object, we can use its 'fileno()' method
> to get the file descriptor.
>
> So how do we get the file object for a logging handler? The 'logging'
> module documentation doesn't mention any way to get at the stream object
> for the handlers.
>
> But looking at the source code for 'StreamHandler' on my system,
> '/usr/lib/python2.5/logging/__init__.py', shows a 'stream' attribute
> that is bound to the stream object. It's not marked private (i.e. it's
> not named with a leading underscore), so one presumes it is part of the
> public API.
>
>> I think you just have to pass the file object used by the handler
>> (fh.stream) in the files_preserve array.
>
> Not quite. As the docs specify, you need to pass the *file descriptors*
> for the files you want preserved. For regular Python file objects, the
> 'file.fileno()' method returns the file descriptor:
>
> lh = logging.handlers.TimedRotatingFileHandler(
> LOG_FILENAME,
> # …
> )
> log_stream_descriptor = lh.stream.fileno()
>
> daemon_context.files_preserve = [log_stream_descriptor]
>


thank you both for a detailed explanation.

==============================================================================
TOPIC: Pythonic list reordering
http://groups.google.com/group/comp.lang.python/t/f9493c7f802d0329?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 4:58 pm
From: Chris Rebert


On Thu, Apr 8, 2010 at 4:01 PM, Joaquin Abian <gatoygata2@gmail.com> wrote:
> On Apr 9, 12:52 am, Ben Racine <i3enha...@gmail.com> wrote:
>> I have a list...
>>
>> ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat']
>>
>> I want to sort it based upon the numerical value only.
>>
>> Does someone have an elegant solution to this?
>
> not sure about elegance, but my two cents:
>
>>> mylist = ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat']
>>> mylist = [(int(item.split('_')[1]), item) for item in mylist]
>>> mylist.sort()
>>> mylist = [item for idx, item in mylist]
>>> mylist
>
> ['dir_0_error.dat', 'dir_30_error.dat', 'dir_120_error.dat',
> 'dir_330_error.dat']

At least conceptually, that's how list.sort() with a key= argument
works internally (i.e. via Schwartzian transform).

Cheers,
Chris
--
http://blog.rebertia.com

==============================================================================
TOPIC: Performance of list vs. set equality operations
http://groups.google.com/group/comp.lang.python/t/818d143c7e9550bc?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 5:02 pm
From: Patrick Maupin


On Apr 8, 6:35 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:

> The CPython source contains lots of shortcuts like that. Perhaps the  
> checks should be stricter in some cases, but I imagine it's not so easy to  
> fix: lots of code was written in the pre-2.2 era, assuming that internal  
> types were not subclassable.

I don't know if it's a good "fix" anyway. If you subclass an internal
type, you can certainly supply your own rich comparison methods, which
would (IMO) put the CPU computation burden where it belongs if you
decide to do something goofy like subclass a list and then override
__len__.

Regards,
Pat

==============================================================================
TOPIC: pass object or use self.object?
http://groups.google.com/group/comp.lang.python/t/6f51302327b58aac?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 6:05 pm
From: Lie Ryan


On 04/08/10 18:20, Bruno Desthuilliers wrote:
> Lie Ryan a écrit :
>> On 04/07/10 18:34, Bruno Desthuilliers wrote:
>>> Lie Ryan a écrit :
>>> (snip)
>>>
>>>> Since in function in python is a first-class object, you can instead do
>>>> something like:
>>>>
>>>> def process(document):
>>>> # note: document should encapsulate its own logic
>>>> document.do_one_thing()
>>> Obvious case of encapsulation abuse here. Should a file object
>>> encapsulate all the csv parsing logic ? (and the html parsing, xml
>>> parsing, image manipulation etc...) ? Should a "model" object
>>> encapsulate the presentation logic ? I could go on for hours here...
>>
>> Yes, but no; you're taking it out of context. Is {csv|html|xml|image}
>> parsing logic a document's logic? Is presentation a document's logic? If
>> they're not, then they do not belong in document.
>
> Is len() a list logic ? If yes, it should belong to list !-)

Yes, that's why list.__len__() belongs to list while len() is a
convenience function that doesn't carry any concrete implementation.

> There are two points here : the first is that we (that is, at least, you
> and me) just don't know enough about the OP's project to tell whether
> something should belong to the document or not. period.

I think I see your point here. I retract my suggestion that it is
suitable for OP's purpose since I just realized OP is in a better
position to make the decision.

> The second point
> is that objects don't live in a splendid isolation, and it's perfectly
> ok to have code outside an object's method working on the object.
> wrt/ these two points, your "document should encapsulate its own logic"
> note seems a bit dogmatic (and not necessarily right) to me - hence my
> answer.

I agree with you about there are certain logics that should not be
inside the object (that's why I qualify the statement with `should`).
Glue logic, by definition, cannot be inside an object. I don't think we
are actually in disagreement here. But I think the dogma, followed with
caution, is generally good.

==============================================================================
TOPIC: Dynamically growing an array to implement a stack
http://groups.google.com/group/comp.lang.python/t/a98cf3a9303bedbf?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 5:15 pm
From: Patrick Maupin


On Apr 8, 3:54 pm, "M. Hamed" <mhels...@hotmail.com> wrote:
> Thanks Patrick, that is what I was exactly looking for.

You're welcome!

But I have to say, you should consider what Paul and Lie are saying.
In general, when I use a stack, I just use append() and pop(), as they
mention, and let the list automagically keep track of the pointer. (I
don't usually even bother subclassing list, but I will often write
something like push = mylist.append; pop = mylist.pop)

But since I don't know about your specific problem, and you obviously
didn't know you could assign to a slice of a list in this manner, I
focused on what you were asking for.

Paul and Lie are trying to focus more on what you really need than
what you asked for, and since you mentioned the magic word "stack",
they immediately assumed that you meant a standard LIFO, where you
only do operations on a single element at a time on one end of the
list. That's a fair assumption, and if that's the case, you should
consider whether you even need to keep an index around, or you can do
as they suggested and just let the current length of the list serve as
your index.

Regards,
Pat

==============================================================================
TOPIC: How to open and read an unknown extension file
http://groups.google.com/group/comp.lang.python/t/570025039368c07b?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 5:35 pm
From: Tim Chase


On 04/08/2010 12:22 PM, varnikat t wrote:
> it gives me this error
>
> TypeError: coercing to Unicode: need string or buffer, list found
>> Thanks for the help.it detects now using glob.glob("*.*.txt")
>> Can u suggest how to open and read file this way?
>>
>> *if glob.glob("*.*.txt"):
>> file=open(glob.glob("*.*.txt"))
>>
>> self.text_view.get_buffer().set_text(file.read())
>> else:
>> file=open(glob.glob("*.*.html"))
>>
>> self.text_view.get_buffer().set_text(file.read())

glob() returns a list of matching files, not a string. So you
need to iterate over those files:

filenames = glob.glob('*.*.txt')
if filenames:
for filename in filenames:
do_something_text(filename)
else:
for filename in glob('*.*.html'):
do_something_html(filename)

-tkc


==============================================================================
TOPIC: order that destructors get called?
http://groups.google.com/group/comp.lang.python/t/6c875525954df888?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Apr 8 2010 6:03 pm
From: Brendan Miller


Thanks Steven and Gabriel. Those are very informative responses.

In my case my resource isn't bound to a lexical scope, but the:

def __del__(self,
delete_my_resource=delete_my_resource):

pattern works quite well. I've made sure to prevent my class from
being part of a circular reference, so that the __del__ shouldn't be
an issue.

Brendan


== 2 of 2 ==
Date: Thurs, Apr 8 2010 6:30 pm
From: "Alf P. Steinbach"


* Brendan Miller:
> Thanks Steven and Gabriel. Those are very informative responses.
>
> In my case my resource isn't bound to a lexical scope, but the:
>
> def __del__(self,
> delete_my_resource=delete_my_resource):
>
> pattern works quite well. I've made sure to prevent my class from
> being part of a circular reference, so that the __del__ shouldn't be
> an issue.

It may work but is unfortunately not guaranteed to work.

Use a 'with' statement where you need guaranteed cleanup.


Cheers & hth.,

- Alf

==============================================================================
TOPIC: The Regex Story
http://groups.google.com/group/comp.lang.python/t/6511effbbbfc5584?hl=en
==============================================================================

== 1 of 5 ==
Date: Thurs, Apr 8 2010 6:29 pm
From: Dotan Cohen


> I would have agreed with you if someone were to make the statement
> until a few weeks ago; somehow in the last week or so, the mood about
> regex seems to has shifted to "regex is not suitable for anything"
> type of mood. As soon as someone (OP or not) proposed a regex
> solution, someone else would retort with don't use regex use
> string-builtins or pyparsing. It appears that the group has developed
> some sense of regexphobia; some people pushes using string builtins
> for moderately complex requirement and suggested pyparsing for not-so
> complex need and that keeps shrinking regex sweet spot. But that's
> just my inherently subjective observation.
>

Isn't that a core feature of a high-level language such as Python?
Providing the tools to perform common or difficult tasks easily
thought built in functions?

I am hard pressed to think of a situation in which a regex is
preferable to a built-in function.

--
Dotan Cohen

http://bido.com
http://what-is-what.com

Please CC me if you want to be sure that I read your message. I do not
read all list mail.


== 2 of 5 ==
Date: Thurs, Apr 8 2010 7:27 pm
From: MRAB


Dotan Cohen wrote:
>> I would have agreed with you if someone were to make the statement
>> until a few weeks ago; somehow in the last week or so, the mood about
>> regex seems to has shifted to "regex is not suitable for anything"
>> type of mood. As soon as someone (OP or not) proposed a regex
>> solution, someone else would retort with don't use regex use
>> string-builtins or pyparsing. It appears that the group has developed
>> some sense of regexphobia; some people pushes using string builtins
>> for moderately complex requirement and suggested pyparsing for not-so
>> complex need and that keeps shrinking regex sweet spot. But that's
>> just my inherently subjective observation.
>>
>
> Isn't that a core feature of a high-level language such as Python?
> Providing the tools to perform common or difficult tasks easily
> thought built in functions?
>
> I am hard pressed to think of a situation in which a regex is
> preferable to a built-in function.
>
Regexes do have their uses. It's a case of knowing when they are the
best approach and when they aren't.


== 3 of 5 ==
Date: Thurs, Apr 8 2010 7:32 pm
From: Dotan Cohen


> Regexes do have their uses. It's a case of knowing when they are the
> best approach and when they aren't.
>

Agreed. The problems begin when the "when they aren't" is not recognised.

--
Dotan Cohen

http://bido.com
http://what-is-what.com


== 4 of 5 ==
Date: Thurs, Apr 8 2010 9:48 pm
From: Lie Ryan


On 04/09/10 12:32, Dotan Cohen wrote:
>> Regexes do have their uses. It's a case of knowing when they are the
>> best approach and when they aren't.
>
> Agreed. The problems begin when the "when they aren't" is not recognised.

But problems also arises when people are suggesting overly complex
series of built-in functions for what is better handled by regex.

Using built-in functions (to me at least) is not a natural way to match
strings, and makes things less understandable for anything but very
simple manipulations. Regex is like Query-by-Example (QBE), in database,
you give an example and you get a result; you give the general pattern
and you get a match. Regex is declarative similar to full-blown parser,
instead of procedural like built-in functions. Regex's unsuitability for
complex parsing stems from terseness and inability to handle arbitrary
nests.

People need to recognize when built-in function isn't suitable and when
bringing forth pyparsing for parsing one or two is just an overkill.

Unreasonable phobia to regex is just as much harmful as overuse of it.


== 5 of 5 ==
Date: Thurs, Apr 8 2010 9:16 pm
From: Patrick Maupin


On Apr 8, 9:32 pm, Dotan Cohen <dotanco...@gmail.com> wrote:
> > Regexes do have their uses. It's a case of knowing when they are the
> > best approach and when they aren't.
>
> Agreed. The problems begin when the "when they aren't" is not recognised.

Arguing against this is like arguing against motherhood and apple
pie. The same argument can validly be made for any Python construct,
any C construct, etc. This argument is so broad and vague that it's
completely meaningless. Platitudes don't help people learn how to
code. Even constant measuring of speed doesn't really help people
start learning how to code -- it just shows them that there are a lot
of OCD people in this profession.

The great thing about Python is that a lot of people, with differing
ambitions, capabilities, amounts of time to invest, and backgrounds
can pick it up and just start using it.

If somebody asks "how do I use re for this" then IMO the *best*
possible response is to tell them how to use re for this (unless
"this" is *difficult* or *impossible* to do with re, in which case you
shouldn't answer the question unless you've had your coffee and you're
in a good mood). You might also gently explain that there other
techniques that might, in some cases be easier to code or read. But
performance? It's all fine and dandy for the experienced coders to
discuss the finer points of different techniques (which, BTW, are
usually all predicated on using the current CPython implementation,
and might in some cases be completely wrong with one of the new JITs
under development), but you have to trust people to know their own
needs! If somebody says "this is too slow -- how do I speed it up?"
then that's really the time to strut your stuff and show that you know
how to milk the language for all it's worth. Until then, just tell
them what they want to know, perhaps with a small disclaimer that it's
probably not the most efficient or elegant or whatever way to solve
their problem. The process of learning a computer language is one of
breaking through a series of brick walls, and in many cases people
will learn things faster if you help give them the tools to get past
their mental roadblocks.

The thing that Lie and I were reacting to was the visceral "don't do
that" that seems to crop up whenever somebody asks how to do something
with re. There are a lot of good use cases for re. Arguably,
something like mxtexttools or some other low-level text processor
would be better for a few of the cases, but they're not part of the
standard library and re is.

One of the great things about Python is that a lot of useful programs
can be written just using Python and the standard library. No C, no
third-party binary libraries, etc. It's not just batteries included
-- it's everything included!

I've written C extensions, both bare, and wrapped with Pyrex, and I've
used third-party extension modules, and while that's OK, it's much
better to have some Python source code in a repository that you can
pull down to any kind of system and just RUN. And look at. And learn
from.

Many useful programs need to do text processing. Often, the built-in
string functions are sufficient. But sometimes they are not.
Discouraging somebody from learning re is doing them a disservice,
because, for the things it is really good at, it is the *only* thing
in the standard library that IS really good.

Yes, you can construct regular expressions and example texts that will
exhibit horrible worst-case performance. But there are a lot of ways
to shoot yourself in the foot performance-wise in Python (as in any
language), and most of them don't require you to use *any* library
functions, much less the dreaded re module.

Often, when I see people give advice that is (I don't want to say
"knee-jerk" because the advice usually has a good foundation) so let's
say "terse" and "unexplained" or maybe even that it is an
"admonishment", it makes me feel that perhaps the person giving the
advice doesn't really trust Python.

I don't remember where I first read it, or heard it, but one of the
core strengths of Python is how easy it is to throw away code and
replace it with something better. So, trust Python to help people get
something going, and then (if they need or want to!) to make it
better.

Just my 2 cents worth.

Pat

==============================================================================
TOPIC: lambda with floats
http://groups.google.com/group/comp.lang.python/t/c803050597639e1e?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Apr 8 2010 6:32 pm
From: monkeys paw


On 4/8/2010 7:19 PM, Patrick Maupin wrote:
> On Apr 8, 6:06 pm, monkeys paw<mon...@joemoney.net> wrote:
>> On 4/7/2010 1:08 PM, Peter Pearson wrote:
>>
>>
>>
>>> On Tue, 06 Apr 2010 23:16:18 -0400, monkeys paw<mon...@joemoney.net> wrote:
>>>> I have the following acre meter which works for integers,
>>>> how do i convert this to float? I tried
>>
>>>> return float ((208.0 * 208.0) * n)
>>
>>>>>>> def s(n):
>>>> ... return lambda x: (208 * 208) * n
>>>> ...
>>>>>>> f = s(1)
>>>>>>> f(1)
>>>> 43264
>>>>>>> 208 * 208
>>>> 43264
>>>>>>> f(.25)
>>>> 43264
>>
>>> The expression "lambda x: (208 * 208) * n" is independent of x.
>>> Is that what you intended?
>>
>> Seems i should have done this:
>> g = lambda x: 208.0 * 208.0 * x
>> g(1)
>> 43264.0
>
> Yes, but then what is the 'n' for. When you do that, you are not
> using it, and it is still confusing.
>
> Regards,
> Pat

I was going from example and looking for something useful from
the lambda feature. I come from C -> Perl -> Python (recent). I
don't find lambda very useful yet.


== 2 of 3 ==
Date: Thurs, Apr 8 2010 8:02 pm
From: monkeys paw


On 4/7/2010 12:15 AM, Patrick Maupin wrote:
> On Apr 6, 11:10 pm, Patrick Maupin<pmau...@gmail.com> wrote:
>> On Apr 6, 11:04 pm, Patrick Maupin<pmau...@gmail.com> wrote:
>>
>>
>>
>>> On Apr 6, 10:16 pm, monkeys paw<mon...@joemoney.net> wrote:
>>
>>>> I have the following acre meter which works for integers,
>>>> how do i convert this to float? I tried
>>
>>>> return float ((208.0 * 208.0) * n)
>>
>>>> >>> def s(n):
>>>> ... return lambda x: (208 * 208) * n
>>>> ...
>>>> >>> f = s(1)
>>>> >>> f(1)
>>>> 43264
>>>> >>> 208 * 208
>>>> 43264
>>>> >>> f(.25)
>>>> 43264
>>
>>> Not sure why you are returning a lambda (which is just a function that
>>> does not have a name) from an outer function.
>>
>>> A function that does this multiplication would simply be:
>>
>>> def s(n):
>>> return 208.0 * 208.0 * n
>>
>>> Regards,
>>> Pat
>>
>> I realized I didn't show the use. A bit different than what you were
>> doing:
>>
>>>>> def s(n):
>>
>> ... return 208.0 * 208.0 * n
>> ...>>> s(1)
>> 43264.0
>>>>> s(0.5)
>> 21632.0
>>>>> s(3)
>>
>> 129792.0
>>
>> I'm not sure exactly what you mean by "acre meter" though; this
>> returns the number of square feet in 'n' acres.
>>
>> Regards,
>> Pat
>
> I should stop making a habit of responding to myself, BUT. This isn't
> quite an acre in square feet. I just saw the 43xxx and assumed it
> was, and then realized it couldn't be, because it wasn't divisible by
> 10. (I used to measure land with my grandfather with a 66 foot long
> chain, and learned at an early age that an acre was 1 chain by 10
> chains, or 66 * 66 * 10 = 43560 sqft.)
> That's an exact number, and 208 is a poor approximation of its square
> root.
>
> Regards,
> Pat

You are absolutely right Pat, so here is the correct equate which also
utilizes my original question of using floats in a lambda, perfectly...

g = lambda x: 208.71 * 208.71 * x
g(1)
43559.864100000006

but truly the easiest to remember is based on your chain:

g = lambda x: 660 * 66 * x
g(1)
43560

Now back to python...


== 3 of 3 ==
Date: Thurs, Apr 8 2010 9:31 pm
From: Steven D'Aprano


On Thu, 08 Apr 2010 21:32:10 -0400, monkeys paw wrote:

> I was going from example and looking for something useful from the
> lambda feature. I come from C -> Perl -> Python (recent). I don't find
> lambda very useful yet.

Perhaps you feel that lambda is a special kind of object. It isn't. It's
just a short-cut for creating an anonymous function object.

f = lambda x: x+1

is almost exactly the same as:

def function(x):
return x+1

f = function
del function


The only advantages of lambda are:

(1) you can write a simple function as a one-liner; and
(2) it's an expression, so you can embed it in another expression:

list_of_functions = [math.sin, lambda x: 2*x-1, lambda x, y=1: x**y]
for func in list_of_functions:
plot(func)


The disadvantage of lambda is that you can only include a single
expression as the body of the function.

You will generally find lambdas used as callback functions, and almost
nowhere else.


--
Steven

==============================================================================
TOPIC: Cleanup guarantees?
http://groups.google.com/group/comp.lang.python/t/80cea772fdae47be?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Apr 8 2010 9:13 pm
From: "Alf P. Steinbach"


Consider ...


<code language="Py3">
import urllib.request # urlopen
import codecs # getreader
import sys # stderr

def text_stream_from( url, encoding ):
text_reader = codecs.getreader( encoding )
connection = urllib.request.urlopen( url )
return text_reader( connection )

def list_text( url, encoding ):
lines = text_stream_from( url, encoding )
for line in lines:
print( line, end = "" )
lines.close() # Undocumented?

url = "http://www.rfc-editor.org/rfc/rfc1149.txt"
list_text( url, "ascii" )
</code>


First, I'm unable to find documentation that there /is/ a close method in the
text_reader object, and I'm unable to find documentation that there is a close
method in the file like connection object; is there such documentation?

Second, I'm unable to find documentation of when they're called and what they
do. It seems that (A) when the connection object's stream is exhausted by
reading, its close() method is called automatically, and (B) that when the
text_reader object's close method is called it calls the close method of the
wrapped stream (i.e. on the connection object). But where is this documented?


Cheers,

- Alf


== 2 of 2 ==
Date: Thurs, Apr 8 2010 10:59 pm
From: "Martin P. Hellwig"


On 04/09/10 05:13, Alf P. Steinbach wrote:
<cut socket open/close>
>
> Second, I'm unable to find documentation of when they're called and what
> they do. It seems that (A) when the connection object's stream is
> exhausted by reading, its close() method is called automatically, and
> (B) that when the text_reader object's close method is called it calls
> the close method of the wrapped stream (i.e. on the connection object).
> But where is this documented?
>
If nothing else, my guess would be the source somewhere between the
urllib and socket module.

--
mph

==============================================================================
TOPIC: SIP
http://groups.google.com/group/comp.lang.python/t/f1667242f17f70c7?hl=en
==============================================================================

== 1 of 4 ==
Date: Thurs, Apr 8 2010 10:01 pm
From: omnia neo


Hi All,

I was looking at the SIP tool to create a C extensions for python to
call.
Here is what I tried:
1. I created a simple c file and .h file <attached testfunc.c and
testfunc.h>
2. Then I created a corresponding testfunc.sip file
###################
%CModule siptest 0

%UnitCode
#include"testfunc.h"
%End

void pyfunc();
%MethodCode
func1();
%End
####################

3. I ran SIP <command: sip -e -j 1 -c . testfunc.sip> on this which
generated the following files:
sipsiptestpart0.c and sipAPIsiptest.h
4. I then added these generated files along with testfunc.c and
testfunc.h in my MS Visual studios solution to create a testsip.dll
file
5. Now to call my module from this dll I invoke a script which tries
to import my modules. My pythn call is as follows:

#code#
import siptest

I get following error :
import error : no module named siptest

Please help me find what I am not doing or what mistake am i commiting.


== 2 of 4 ==
Date: Thurs, Apr 8 2010 10:30 pm
From: Stefan Behnel


omnia neo, 09.04.2010 07:01:
> import siptest
>
> I get following error :
> import error : no module named siptest

Is the directory where your siptest.dll lies in your PYTHONPATH (sys.path)?

Otherwise, Python can't find it.

Stefan

== 3 of 4 ==
Date: Thurs, Apr 8 2010 10:42 pm
From: omnia neo


On Apr 9, 10:30 am, Stefan Behnel <stefan...@behnel.de> wrote:
> omnia neo, 09.04.2010 07:01:
>
> > import siptest
>
> > I get following error :
> > import error : no module named siptest
>
> Is the directory where your siptest.dll lies in your PYTHONPATH (sys.path)?
>
> Otherwise, Python can't find it.
>
> Stefan

thanks for reply Stefan..
well I added PYTHONPATH = <my dll path> in my environment variables
(windows XP).


== 4 of 4 ==
Date: Thurs, Apr 8 2010 10:51 pm
From: omnia neo


On Apr 9, 10:42 am, omnia neo <neo.omn...@gmail.com> wrote:
> On Apr 9, 10:30 am, Stefan Behnel <stefan...@behnel.de> wrote:
>
> > omnia neo, 09.04.2010 07:01:
>
> > > import siptest
>
> > > I get following error :
> > > import error : no module named siptest
>
> > Is the directory where your siptest.dll lies in your PYTHONPATH (sys.path)?
>
> > Otherwise, Python can't find it.
>
> > Stefan
>
> thanks for reply Stefan..
> well I added PYTHONPATH = <my dll path> in my environment variables
> (windows XP).

well I just tried this too.
I added the path using sys.path on the fly in my python script as
follows:

###############
import sys
sys.path.append("<dll path>")
print sys.path
import siptest
###############

again same error:
ImportError: No module named siptest.

==============================================================================
TOPIC: Is there any module/utility like 'rsync' in python
http://groups.google.com/group/comp.lang.python/t/60d5a3842d0a4d58?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Apr 8 2010 11:22 pm
From: hiral


Hi,

Is there any module/utility like 'rsync' in python.

Thank you in advance.
-Hiral


== 2 of 2 ==
Date: Thurs, Apr 8 2010 11:32 pm
From: garabik-news-2005-05@kassiopeia.juls.savba.sk


hiral <hiralsmaillist@gmail.com> wrote:
> Hi,
>
> Is there any module/utility like 'rsync' in python.
>

http://freshmeat.net/projects/pysync/
http://vdesmedt.com/~vds2212/rsync.html

--
-----------------------------------------------------------
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk |
-----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!


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

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