Re: Exception Handling in Python 3

2010-10-25 Thread Martin v. Loewis
Am 24.10.2010 23:48, schrieb Steve Holden:
> On 10/24/2010 4:44 PM, John Nagle wrote:
>> Are exception semantics changing in a way which would affect that?
> 
> No, I don't believe so. I simply felt that the traceback gives too much
> information in the case where an exception is specifically being raised
> to replace the one currently being handled.

I think you have puzzled readers a lot (including me) with the statement:

"that Python 3 no longer allows an exception to be raised in an except
clause"

That certainly isn't the case.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Handling in Python 3

2010-10-25 Thread Steve Holden
On 10/25/2010 2:57 AM, Martin v. Loewis wrote:
> Am 24.10.2010 23:48, schrieb Steve Holden:
>> On 10/24/2010 4:44 PM, John Nagle wrote:
>>> Are exception semantics changing in a way which would affect 
>>> that?
>> 
>> No, I don't believe so. I simply felt that the traceback gives too 
>> much information in the case where an exception is specifically 
>> being raised to replace the one currently being handled.
> 
> I think you have puzzled readers a lot (including me) with the 
> statement:
> 
> "that Python 3 no longer allows an exception to be raised in an 
> except clause"
> 
> That certainly isn't the case.
> 
Of course it isn't. I believe the only readers puzzled  by my assertion
would be those who did not read the parenthesized comment immediately
following the sentence you quoted, which read:

> (or rather that it reports it as a separate exception that occurred
> during the handling of the first)

I understand that this behavior is deliberate. I just don't feel that it
is universally helpful.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: Question on multiple python environments in Apache

2010-10-25 Thread Mario Miri
Why wouldn't you use multiple apache instances?

On Fri, Oct 22, 2010 at 11:28 PM, Jeffrey Gaynor wrote:

> I have several different versions of a web app that run under Apache. The
> issue is that I need to have several different configurations available
> under several environments (such as Django, mod_python and plain vanilla
> mod_wsgi). Is there a simple way to get several of these to be completely
> independent? I thought about virtualenv, but it seems that I can only get
> one virtual environment for the entire server (so this just keeps it
> distinct from my main python install), rather than half a dozen. These will
> be on a dedicated test server so performance is not an issue.
>
> Does anyone know of a good FAQ that discusses this?
>
> Thanks in advance,
>
> Jeff
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


free Internship in the United States / uk /canada /austraila

2010-10-25 Thread neha shena
free Internship in the United States / uk /canada /austraila

Internships are practical experiences that bridge the gap between the
educational world and the real world allowing students to understand
what is really like to work in the industry of their choice.
International internships offer much more than the usual internship
you would conduct in your country. These types of internships will
open your eyes to new ways and new personal and professional
relationships, will provide you with new settings and a new culture
and expand your opportunities. Here is a small summary on how to get
internships in the United States. read more

http://childschooledu.blogspot.com/2010/10/get-internship-in-united-states.html
-- 
http://mail.python.org/mailman/listinfo/python-list


init inside def

2010-10-25 Thread targetsmart
Hi,
today I just came across a python code snippet where __init__ was
defined inside a function..
I am not able to understand the reason why

The code snippet was similar like

def func1(a,b):
  def __init__():
func2(a,b)
  def func2(a,b):
if a == b:
  return True
else:
  return False
  return False

So far I have seen __init__ only used inside class definitions not
inside any function, could somebody tell me how __init__ can be useful
inside a function definition..?

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


Why "flat is better than nested"?

2010-10-25 Thread kj


In "The Zen of Python", one of the "maxims" is "flat is better than
nested"?  Why?  Can anyone give me a concrete example that illustrates
this point?

TIA!

~kj

PS: My question should not be construed as a defense for "nested".
I have no particular preference for either flat or nested; it all
depends on the situation; I would have asked the same question if
the maxim had been "nested is better than flat".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Has Next in Python Iterators

2010-10-25 Thread Kelson Zawack
The example I have in mind is list like [2,2,2,2,2,2,1,3,3,3,3] where
you want to loop until you see not a 2 and then you want to loop until
you see not a 3.  In this situation you cannot use a for loop as
follows:

foo_list_iter = iter([2,2,2,2,2,2,1,3,3,3,3])
for foo_item in foo_list_iter:
if foo_item != 2:
break
because it will eat the 1 and not allow the second loop to find it.
takeWhile and dropWhile have the same problem.  It is possible to use
a while loop as follows:

foo_list_item = foo_list_iter.next()
while foo_list_item == 2:
foo_list_item = foo_list_iter.next()
while foo_list_item == 3:
foo_list_item = foo_list_iter.next()

but if you can't be sure the list is not empty/all 2s then all 3s you
need to surround this code in a try block.  Unless there is a good
reason for having to do this I think it is undesirable because it
means that the second clause of the loop invariant, namely that you
are not off the end of the list, is being controlled outside of the
loop.

As for the feasibly of implementing a has_next function I agree that
you cannot write one method that will provide the proper functionality
in all cases, and thus that you cannot create a has_next for
generators.  Iterators however are a different beast, they are
returned by the thing they are iterating over and thus any special
cases can be covered by writing a specific implementation for the
iterable in question.  This sort of functionality is possible to
implement, because java does it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: init inside def

2010-10-25 Thread bruno.desthuilli...@gmail.com
On 25 oct, 12:05, targetsmart  wrote:
> Hi,
> today I just came across a python code snippet where __init__ was
> defined inside a function..
> I am not able to understand the reason why
>
> The code snippet was similar like
>
> def func1(a,b):
>   def __init__():
>     func2(a,b)
>   def func2(a,b):
>     if a == b:
>       return True
>     else:
>       return False
>   return False
>
> So far I have seen __init__ only used inside class definitions not
> inside any function, could somebody tell me how __init__ can be useful
> inside a function definition..?

__init__ as an inner function name has no special meaning. And in the
above snippet it happens to to be totally useless since it's not
neither called nor returned nor used in any way. In fact, since func2
is not used neither (and totally braindead FWIW), the above snippet is
functionally equivalent to:

def func1(a, b):
return False

Perhaps the real snippet would make more sense ?


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


Re: Has Next in Python Iterators

2010-10-25 Thread Stefan Behnel

Kelson Zawack, 25.10.2010 12:33:

The example I have in mind is list like [2,2,2,2,2,2,1,3,3,3,3] where
you want to loop until you see not a 2 and then you want to loop until
you see not a 3.  In this situation you cannot use a for loop as
follows:

foo_list_iter = iter([2,2,2,2,2,2,1,3,3,3,3])
for foo_item in foo_list_iter:
 if foo_item != 2:
 break
because it will eat the 1 and not allow the second loop to find it.
takeWhile and dropWhile have the same problem.  It is possible to use
a while loop as follows:

foo_list_item = foo_list_iter.next()
while foo_list_item == 2:
 foo_list_item = foo_list_iter.next()
while foo_list_item == 3:
 foo_list_item = foo_list_iter.next()


Why not combine the two into this:

foo_list_iter = iter([2,2,2,2,2,2,1,3,3,3,3])
for item in foo_list_iter:
if item != 2:
   print item
   break
# not sure what to do with the "1" here, hope you do ...
for item in foo_list_iter:
if item != 3:
   print item

Also take a look at the itertools module, which provide little helpers like 
takewhile(), groupby() and some other nice filters.




As for the feasibly of implementing a has_next function I agree that
you cannot write one method that will provide the proper functionality
in all cases, and thus that you cannot create a has_next for
generators.  Iterators however are a different beast, they are
returned by the thing they are iterating over and thus any special
cases can be covered by writing a specific implementation for the
iterable in question.


Well, then just write the specific iterable wrappers that you need for your 
specific case. If you do it well, you can make your code a lot easier to 
read that way. And that's usually a very good proof that something like 
"has_next()" is not needed at all and just complicates things.




This sort of functionality is possible to
implement, because java does it.


Like that was an argument for anything. Java iterators also require you to 
implement "remove()". I can't remember ever doing anything else but 
throwing an exception in my implementation for that. Bad design isn't a 
good reason for a feature to be copied.


Stefan

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


Help Need in running a Python Program from terminal

2010-10-25 Thread Raji
Greetings !

I want to analyse and debug a python program  ( its a astrology application
)

Downloaded the code from here http://openastro.org/?Download
for Ubuntu

When i executed the main file python openastro.py from terminal i stopped
with the following error

Traceback (most recent call last):
  File "openastro.py", line 90, in 
TRANSLATION[LANGUAGES[i]] =
gettext.translation("openastro",TDomain,languages=['en'])
  File "/usr/lib/python2.6/gettext.py", line 484, in translation
raise IOError(ENOENT, 'No translation file found for domain', domain)
IOError: [Errno 2] No translation file found for domain: 'openastro'


Need help to solve this error

-- 
Regards

Raji

http://sraji.wordpress.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I chain methods?

2010-10-25 Thread Stefan Schwarzer
Hi Steve and others,

On 2010-10-25 06:08, Steve Holden wrote:
> On 10/24/2010 11:42 PM, Chris Rebert wrote:
>> On Sun, Oct 24, 2010 at 4:11 PM, James Mills
>>  wrote:
>>> I don't agree but anyway... I've just not seen it commonly used
>>> amongst python programmers.
>>
>> If Python wanted to encourage method-chaining-style, then list.sort(),
>> list.reverse(), and several other built-in type methods would (ala
>> Ruby) return self rather than None. Since they don't, and since
>> "uncommon idiom" is a near-oxymoron, I think we can safely conclude
>> that method chaining isn't idiomatic in Python. Not that it doesn't
>> have specialized uses though (See asterisk note).
>>
> Yes, the Twisted guys use method chaining a lot - it's definitely
> idiomatic in that framework.

It's also used in the pstats module:
http://docs.python.org/library/profile.html#instant-user-s-manual

But I agree with others that it doesn't seem to be a
typical Python idiom.

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


Re: nntplib and ssl

2010-10-25 Thread Andrew
On Fri, 22 Oct 2010 23:23:31 +0200, Antoine Pitrou wrote:

> On Fri, 22 Oct 2010 17:02:07 -0400
> Andrew  wrote:
>> 
>> Python's nntplib seems ideal for my purposes, but as far as I can see it
>> doesn't support nntps connections. If I understand nntp correctly (I may
>> not) that means, among other things, it sends passwords in cleartext. 
>> 
>> That won't do. I note that python has a separate ssl module but I must
>> admit I'm at a loss as to how to fit the two together. I'm working from the
>> Python 3.1.2 documentation, page noted here:
> 
> There's an issue open for this:
> http://bugs.python.org/issue1926

I found that but noted it was dated for a few years ago. Of course like an
idiot I didn't scroll down the page and see that it was still active as of
last month. 

> A patch is there, but it's totally outdated. If you're interested, you
> could provide a new patch against py3k SVN (that is, the next 3.2,
> although the deadline for new features is in a couple of weeks).

I'd say I'm interested...but despite not being too terrible a programmer,
I've never written and submitted a patch for anything in my life and have
no idea how to go about it. ;-) I suppose google could solve that problem.

> It's probably not very difficult to write such a patch. You mostly need
> to wrap the connection in an SSL socket, then give that socket to the
> NNTP connection class. Details will be found out by studying the
> nntplib code.

I might take a crack at it if I can figure out how. Thanks for the help.

--

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


Re: ftplib - Did the whole file get sent?

2010-10-25 Thread Brendan
On Oct 23, 1:03 pm, Sean DiZazzo  wrote:
> On Oct 22, 10:48 pm, Steven D'Aprano 
> cybersource.com.au> wrote:
> > On Fri, 22 Oct 2010 22:03:38 -0700, Sean DiZazzo wrote:
> > > How can I assure him (and the client) that the transfer completed
> > > successfully like my log shows?
>
> > "It has worked well for many years, there are no reported bugs in the ftp
> > code
> > [...]
>
> Thanks for your advice Steven.  I agree with you,and did take that
> approach to start with.  Then the request for the actual FTP "ack"
> caught me off guard.  I had to break out Wireshark and run a few tests
> just to make sure I knew exactly what I was talking about.
>
> I think I will try to explain that asking for the "ack" is not really
> a valid request.  Something like this:
>
> "Technically, these messages are used only on the lowest level of the
> FTP protocol itself.  Any client or library implementing FTP would be
> sending these messages under the covers...in this case I think its
> done in the socket library.  It is possible that there is a bug in the
> Python FTP library, just like it's possible there is a bug in any
> other FTP client.  Considering how long this library has been around
> (~15-20 years), and how often it is used, it is very unlikely that a
> bug causing a partial transfer but showing a success has managed to
> stick around for so long."
>
> Does that make sense?
>
> > > Is ftplib reliable enough to say that if an exception is not thrown,
> > > that the file was transferred in full?
>
> > Python 2.4 is pretty old. Have you checked the bug tracker to see if
> > there are any reported bugs in ftplib that might be relevant? Or the
> > What's New for 2.5, 2.6 and 2.7? The source code for ftplib seems fairly
> > straightforward to me -- if there was an error, I can't see that it could
> > have been suppressed.
>
> > But really, unless you can reproduce the error, I'd say the error lies
> > elsewhere.
>
> > --
> > Steven
>
> I'll check bugs and whats new before sending any response.  The more I
> think about this, I am beginning to think that he is just trying to
> find someone to blame for a problem, and has chosen me.
>
> Thanks again.
>
> ~Sean

Your boss is both moron and wanker.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embarrassing class question

2010-10-25 Thread Brendan
On Oct 22, 2:21 pm, Peter Pearson  wrote:
> On Fri, 22 Oct 2010 07:49:39 -0700 (PDT), Brendan wrote:
>
> [snip]
>
>
>
>
>
> > x.py
> > class X(object):
> >     pass
>
> > y.py
> > import x
> > class Y(x.X):
> >     pass
>
> > z.py
> > import x
> > import y
> > class ZX(x.X):
> >     pass
> > class ZY(y.Y):
> >     pass
>
> > w.py
> > import x
> > import y
> > import z
> > class WX(x.X):
> >     pass
> > class WY(y.Y):
> >     pass
> > class WZX(z.ZX):
> >     pass
> > class WZY(z.ZY):
> >     pass
>
>  import x, y, z, w
>  dir(x)
> > ['X', '__builtins__', '__doc__', '__file__', '__name__',
> > '__package__']
>  dir(y)
> > ['Y', '__builtins__', '__doc__', '__file__', '__name__',
> > '__package__', 'x']
>  dir(z)
> > ['ZX', 'ZY', '__builtins__', '__doc__', '__file__', '__name__',
> > '__package__', 'x', 'y']
>  dir(w)
> > ['WX', 'WY', 'WZX', 'WZY', '__builtins__', '__doc__', '__file__',
> > '__name__', '__package__', 'x', 'y', 'z']
>
> I apologize for being dense, but I don't understand what bothers
> you about this behavior.  Yes, module w imports x, and therefore
> w.x exists.  Is that bad?
>
> --
> To email me, substitute nowhere->spamcop, invalid->net.- Hide quoted text -
>
> - Show quoted text -

No worries. I am the one who is dense. What bothers me is that I have
not noticed this before when importing other Python modules. I use
Python sporadically, and frequently use the dir command to learn or
remind myself of class methods. Python examples/tutorials on classes
always show everything(classes and subclasses) in the same module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Descriptors and decorators

2010-10-25 Thread Joost Molenaar
WebOb contains this little nugget of code that allows you to define a
decorator that works on both methods and functions:

class Decorator(object):
def __init__(self, func):
self.func = func
def __get__(self, object, type=None):
if type is None:
return self
newfunc = self.func.__get__(object, type)
return self.__class__(newfunc)

I adapted it into a class, so that I can inherit this functionality
without thinking about it:

class trace(Decorator):
def __call__(self, *a, **kw):
print '-->', self.func.__name__, repr(a), repr(kw)
result = self.func(*a, **kw)
print '<--', self.func.__name__, '=', repr(result)
return result

I can then use it like this:

class C(object):
@trace
def m(self, x):
return 2 * x

And like this:

@trace
def f(x):
return 2 * x

It works:

>>> o = C()
>>> o.m(21)
--> m (21,) {}
<-- m = 42
>>> f(21)
--> f (21,) {}
<-- f = 42

I'm still not sure what Decorator.__get__ does, or at least I'm not
sure enough to be able to explain it well.

Logically, the method C.m is unbound at the time the class is defined
but o.m is bound when it is called. This means that what
Decorator.__init__ receives as its 'func' parameter is the unbound
method C.m, and when it runs it should operate on the bound method o.m
instead. I suspect that this is what happens inside Decorator.__get__:
create a new instance of the decorator, with a bound version of the
decorated method, and call that without needing a 'self' parameter.

Is this in fact the easiest way to explain it?

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


Re: ftplib - Did the whole file get sent?

2010-10-25 Thread sjm
On Oct 23, 2:03 am, Sean DiZazzo  wrote:

I follow every ftp put (STOR) with a dir command.  Then if the
recipient claims that they never got it (or did not get all of it), I
have evidence that they did and that their byte count is the same as
mine.

This does not entirely guarantee that the ftp was perfect but it goes
a long way.  It also provides useful information if there is a
problem.

HTH,
  SJM

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


Re: Descriptors and decorators

2010-10-25 Thread bruno.desthuilli...@gmail.com
On 25 oct, 14:15, Joost Molenaar  wrote:
> WebOb contains this little nugget of code that allows you to define a
> decorator that works on both methods and functions:
>
> class Decorator(object):
>     def __init__(self, func):
>         self.func = func
>     def __get__(self, object, type=None):
>         if type is None:
>             return self
>         newfunc = self.func.__get__(object, type)
>         return self.__class__(newfunc)
(snip)

> I'm still not sure what Decorator.__get__ does, or at least I'm not
> sure enough to be able to explain it well.

http://wiki.python.org/moin/FromFunctionToMethod


> Logically, the method C.m is unbound at the time the class is defined

"At the time the class is defined" - that is (usually) when the
"class" statement's body is executed -, 'm' is a plain function. Note
that by that time, class 'C' doesn't even exist, so there's no way you
could have a 'C.m' method ;)

So, your decorator is applied to a function, and wraps it into a
Decorator object. Or more exactly, the function is defined, then the
Decorator class is called so a new Decorator object is instanciated
with the function as argument, and finally this Decorator instance is
rebound to the name under which the function was formely known. All
this happenning _before_ class C even exists, so when the class object
is created, it has an attribute by the name of the decorated function
which is in fact a Decorator instance.

Now this instance is itself a descriptor, so when C.m or o.m are
looked up, the descriptor protocol is fired and Descriptor.__get__ is
called. If called without at least a 'type' argument, it just returns
itself, so it works as an ordinary function. Else it calls the
function's own descriptor implementation to get a bound or unbound
method, and returns a new instance of the decorator with the method as
argument.

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


Re: Why "flat is better than nested"?

2010-10-25 Thread Alex Willmer
On Oct 25, 11:07 am, kj  wrote:
> In "The Zen of Python", one of the "maxims" is "flat is better than
> nested"?  Why?  Can anyone give me a concrete example that illustrates
> this point?

I take this as a reference to the layout of the Python standard
library and other packages i.e. it's better to have a module hierarchy
of depth 1 or 2 and many top level items, than a depth of 5+ and only
a few top level items.

For instance

import re2
import sqlite3
import logging

import something_thirdparty

vs

import java.util.regex
import java.sql
import java.util.logging

import org.example.thirdparty.something

There are of course some Python packages that go deeper than 2
(xml.dom.minidom), but the majority are shallow. I think the
motivation is to make the packages more discoverable, and to avoid
classification arguments (does regex go under util or text). Alone the
statement would imply a single, global space ala C but that of course
is evil and so one must balance it with "Namespaces are one honking
great idea -- let's do more of those!"

I don't think it applies to data structures though. If a deeply nested
tree models your data well, then use it.

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


Re: Has Next in Python Iterators

2010-10-25 Thread Jussi Piitulainen
Kelson Zawack writes:

> The example I have in mind is list like [2,2,2,2,2,2,1,3,3,3,3]
> where you want to loop until you see not a 2 and then you want to
> loop until you see not a 3.  In this situation you cannot use a for
> loop as follows:
...
> because it will eat the 1 and not allow the second loop to find it.
> takeWhile and dropWhile have the same problem.  It is possible to
...

The following may or may not be of interest to you, or to someone
else. If not, please ignore. Probably I misuse some of the technical
terms.

Instead of trying to consume an initial part of an iterable, one can
make a new generator that consumes the underlying iterator in the
desired way. This works nicely if no other code consumes the same
underlying data. My implementation of "after" is below, after the
examples, and after that is an alternative implementation.

  Python 3.1.1 (r311:74480, Feb  8 2010, 14:06:51)
  [GCC 4.4.3] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> from echoed import *
  >>> list(after(after([3,1,4,1,5], is2), is3))
  [1, 4, 1, 5]
  >>> list(after(after([2,2,3,1,4,1,5], is2), is3))
  [1, 4, 1, 5]
  >>> list(after(after([2,2,1,4,1,5], is2), is3))
  [1, 4, 1, 5]
  >>> list(after(after([2,2], is2), is3))
  []
  >>> list(after(after([3,3], is2), is3))
  []
  >>> list(after(after([], is2), is3))
  []
  >>> list(after(after([1,4,1,5], is2), is3))
  [1, 4, 1, 5]

The implementation of "after" uses two simple auxiliaries, "echoed"
and "evens", which double every item and drop every other item,
respectively. In a sense, "after" returns the echoes of the desired
items: when the first item of interest is encountered in the echoed
stream, its echo remains there.

def echoed(items):
for item in items:
yield item
yield item

def evens(items):
for item in items:
yield item
next(items)

def after(items, is_kind):
echoed_items = echoed(items)
try:
while is_kind(next(echoed_items)):
next(echoed_items)
except StopIteration:
pass
return evens(echoed_items)

def is2(x):
return x == 2

def is3(x):
return x == 3

Alternatively, and perhaps better, one can push the first item of
interest back into a new generator. The auxiliary "later" below does
that; "past" is the alternative implementation of the desired
functionality, used like "after" above.

def later(first, rest):
yield first
for item in rest:
yield item

def past(items, is_kind):
items = iter(items)
try:
item = next(items)
while is_kind(item):
item = next(items)
except StopIteration:
return items
return later(item, items)

The names of my functions may not be the best. Many more disclaimers
apply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why "flat is better than nested"?

2010-10-25 Thread bruno.desthuilli...@gmail.com
On 25 oct, 15:34, Alex Willmer  wrote:
> On Oct 25, 11:07 am, kj  wrote:
>
> > In "The Zen of Python", one of the "maxims" is "flat is better than
> > nested"?  Why?  Can anyone give me a concrete example that illustrates
> > this point?
>
> I take this as a reference to the layout of the Python standard
> library and other packages i.e. it's better to have a module hierarchy
> of depth 1 or 2 and many top level items, than a depth of 5+ and only
> a few top level items.
>
(snip)

This also applies to inheritance hierarchies (which tend to be rather
flat in Python compared to most mainstreams OOPLs), as well as nested
classes etc.


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


Re: Why "flat is better than nested"?

2010-10-25 Thread Robin Becker

On 25/10/2010 11:07, kj wrote:



In "The Zen of Python", one of the "maxims" is "flat is better than
nested"?  Why?  Can anyone give me a concrete example that illustrates
this point?


...
I believe that the following illustrates the nesting issue (I think this is from 
somewhere in Chomsky)



The rat ate the corn.
The rat that the cat killed ate the corn.
The rat that the cat that the dog chased killed ate the corn.

I believe this is called central embedding.


There's also the old schoolboy saying "I know that that that that that boy said 
is wrong!".


The nested nature makes the semantics quite hard. The same will be true of 
nested tuple/list and similar programming structures.

--
Robin Becker

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


downcasting problem

2010-10-25 Thread Nikola Skoric
Hi everybody,

I need to downcast an object, and I've read repeatedly that if you
need to downcast, you did something wrong in the design phase. So,
instead of asking how do you downcast in python, let me explain my
situation.

I have a 2-pass parser. 1st pass ends up with a bunch of superclass
object, and 2nd pass is supposed to downcast those to one of
subclasses so I can work with them.

Details:

I have a file full of lines which I parse into Line objects. I also
have two subclasses of Line, namely Individual and Family. Constructor
of both subclasses needs all Line objects in the file to be
constructed, so I cannot construct subclass objects in the first pass.

The Python way of doing this (as I understand it) would be to wrap a
subclass around Line and have the Line object as an attribute of a
subclass. Now, this obviously breaks polymorphism and I now have to
reimplement all of Line's classes in subclasses. Although
reimplementation is simple (def method(self): return
self.line.method()), that way of doing things is just not elegant.

So, is there any more elegant solution to my problem?

Thanks in advance.

-- 
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help Need in running a Python Program from terminal

2010-10-25 Thread Philip Semanchuk

On Oct 25, 2010, at 7:16 AM, Raji wrote:

> Greetings !
> 
> I want to analyse and debug a python program  ( its a astrology application
> )
> 
> Downloaded the code from here http://openastro.org/?Download
> for Ubuntu
> 
> When i executed the main file python openastro.py from terminal i stopped
> with the following error
> 
> Traceback (most recent call last):
>  File "openastro.py", line 90, in 
>TRANSLATION[LANGUAGES[i]] =
> gettext.translation("openastro",TDomain,languages=['en'])
>  File "/usr/lib/python2.6/gettext.py", line 484, in translation
>raise IOError(ENOENT, 'No translation file found for domain', domain)
> IOError: [Errno 2] No translation file found for domain: 'openastro'

Hi Raji,
Did you have a look at the documentation for the call that's failing?

Here's the doc for gettext.translation():
http://docs.python.org/library/gettext.html#gettext.translation

I don't know anything about gettext or openastro, but the doc says, "If no .mo 
file is found, this function raises IOError..." which is the problem you're 
having. It seems like what you downloaded is expecting to find a .mo file but 
can't. You might want to check the package instructions on openastro.org to 
make sure there's not more you need to do to install it.

Good luck
Philip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Has Next in Python Iterators

2010-10-25 Thread Hrvoje Niksic
Kelson Zawack  writes:

> Iterators however are a different beast, they are returned by the
> thing they are iterating over and thus any special cases can be
> covered by writing a specific implementation for the iterable in
> question.  This sort of functionality is possible to implement,
> because java does it.

Note that you can wrap any iterator into a wrapper that implements
has_next along with the usual iteration protocol.  For example:

class IterHasNext(object):
def __init__(self, it):
self.it = iter(it)

def __iter__(self):
return self

def next(self):
if hasattr(self, 'cached_next'):
val = self.cached_next
del self.cached_next
return val
return self.it.next()

def has_next(self):
if hasattr(self, 'cached_next'):
return True
try:
self.cached_next = self.it.next()
return True
except StopIteration:
return False

>>> it = IterHasNext([1, 2, 3])
>>> it.next()
1
>>> it.has_next()
True
>>> it.next()
2
>>> it.next()
3
>>> it.has_next()
False
>>> it.next()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 11, in next
StopIteration
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why "flat is better than nested"?

2010-10-25 Thread Alex Willmer
On Oct 25, 2:56 pm, Robin Becker  wrote:
> On 25/10/2010 11:07, kj wrote:
>
> > In "The Zen of Python", one of the "maxims" is "flat is better than
> > nested"?  Why?  Can anyone give me a concrete example that illustrates
> > this point?
>
> ...
> I believe that the following illustrates the nesting issue (I think this is 
> from
> somewhere in Chomsky)
>
> The rat ate the corn.
> The rat that the cat killed ate the corn.
> The rat that the cat that the dog chased killed ate the corn.
>
> I believe this is called central embedding.
>
> There's also the old schoolboy saying "I know that that that that that boy 
> said
> is wrong!".
>
> The nested nature makes the semantics quite hard. The same will be true of
> nested tuple/list and similar programming structures.

I agree in the case of a suped-up hierachical record structure that
encourages code like

my_far =
the_record.something.something_else.foo[2].keep_going.bar.baz()

A tree of homogeneous nodes that one walks or recurses into (e.g. a b-
tree or r-tree) is a case where I would ignore this maxim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why "flat is better than nested"?

2010-10-25 Thread rantingrick
On Oct 25, 5:07 am, kj  wrote:
> In "The Zen of Python", one of the "maxims" is "flat is better than
> nested"?  Why?  Can anyone give me a concrete example that illustrates
> this point?

Simple. This commandment (endowed by the anointed one, GvR) is
directed directly at lisp and those filthy lispers. If you don't know
what lisp is then Google it. Then try to program with it for one hour.
Very soon after your head will explode from the nested bracket plague
and then you shall be enlightened!

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


Re: Question on multiple python environments in Apache

2010-10-25 Thread Jeffrey Gaynor
Because that is a mess to manage, involving hacking the Apache source and 
multiple recompiles (this will have to run under CentOS). Using Python should 
be easy and not entail multiple compiles of other people's software. My main 
question boils down to the best way to get mutltiples interpreters running at a 
time or, failing that, a way to get separate threads. 

Is there an *easy* way to do this with virtualenv or virtual hosts under Apache?

- Original Message -
From: "Mario Miri" 
To: "python-list" 
Sent: Monday, October 25, 2010 2:50:55 AM
Subject: Re: Question on multiple python environments in Apache


Why wouldn't you use multiple apache instances? 


On Fri, Oct 22, 2010 at 11:28 PM, Jeffrey Gaynor < jgay...@ncsa.uiuc.edu > 
wrote: 


I have several different versions of a web app that run under Apache. The issue 
is that I need to have several different configurations available under several 
environments (such as Django, mod_python and plain vanilla mod_wsgi). Is there 
a simple way to get several of these to be completely independent? I thought 
about virtualenv, but it seems that I can only get one virtual environment for 
the entire server (so this just keeps it distinct from my main python install), 
rather than half a dozen. These will be on a dedicated test server so 
performance is not an issue. 

Does anyone know of a good FAQ that discusses this? 

Thanks in advance, 

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


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


Re: downcasting problem

2010-10-25 Thread Tim Chase
While a dirty hack for which I'd tend to smack anybody who used 
it...you *can* assign to instance.__class__


>>> class A:
... def __init__(self, name):
... self.name = name
... def __str__(self): return self.name
...
>>> class B(A):
... def foo(self): print "I'm B: %r" % self.name
...
>>> class C(A):
... def foo(self): print "I'm C: %r" % self.name
...
>>> a = A("Alpha")
>>> print a
Alpha
>>> a.__class__

>>> a.__class__ = B
>>> a.foo()
I'm B: 'Alpha'
>>> a.__class__ = C
>>> a.foo()
I'm C: 'Alpha'


If it breaks you get to keep all the parts :)

-tkc



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


Re: nntplib and ssl

2010-10-25 Thread Steve Holden
On 10/25/2010 7:26 AM, Andrew wrote:
> On Fri, 22 Oct 2010 23:23:31 +0200, Antoine Pitrou wrote:
> 
>> On Fri, 22 Oct 2010 17:02:07 -0400
>> Andrew  wrote:
>>>
>>> Python's nntplib seems ideal for my purposes, but as far as I can see it
>>> doesn't support nntps connections. If I understand nntp correctly (I may
>>> not) that means, among other things, it sends passwords in cleartext. 
>>>
>>> That won't do. I note that python has a separate ssl module but I must
>>> admit I'm at a loss as to how to fit the two together. I'm working from the
>>> Python 3.1.2 documentation, page noted here:
>>
>> There's an issue open for this:
>> http://bugs.python.org/issue1926
> 
> I found that but noted it was dated for a few years ago. Of course like an
> idiot I didn't scroll down the page and see that it was still active as of
> last month. 
> 
>> A patch is there, but it's totally outdated. If you're interested, you
>> could provide a new patch against py3k SVN (that is, the next 3.2,
>> although the deadline for new features is in a couple of weeks).
> 
> I'd say I'm interested...but despite not being too terrible a programmer,
> I've never written and submitted a patch for anything in my life and have
> no idea how to go about it. ;-) I suppose google could solve that problem.
> 
>> It's probably not very difficult to write such a patch. You mostly need
>> to wrap the connection in an SSL socket, then give that socket to the
>> NNTP connection class. Details will be found out by studying the
>> nntplib code.
> 
> I might take a crack at it if I can figure out how. Thanks for the help.
> 
You might find helpful information at

  http://python.org/dev/

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: Descriptors and decorators

2010-10-25 Thread Joost Molenaar
On 25 October 2010 15:20, bruno.desthuilli...@gmail.com
 wrote:
> So, your decorator is applied to a function, and wraps it into a
> Decorator object. Or more exactly, the function is defined, then the
> Decorator class is called so a new Decorator object is instanciated
> with the function as argument, and finally this Decorator instance is
> rebound to the name under which the function was formely known. All
> this happenning _before_ class C even exists, so when the class object
> is created, it has an attribute by the name of the decorated function
> which is in fact a Decorator instance.
>
> Now this instance is itself a descriptor, so when C.m or o.m are
> looked up, the descriptor protocol is fired and Descriptor.__get__ is
> called. If called without at least a 'type' argument, it just returns
> itself, so it works as an ordinary function. Else it calls the
> function's own descriptor implementation to get a bound or unbound
> method, and returns a new instance of the decorator with the method as
> argument.

Thanks, Bruno.
Your python-wiki page and walk-through for the Decorator code make it
clear. I now finally understand that methods are in fact ordinary
functions at the time the class is created, and that the descriptor
protocol turns them into bound or unbound methods when they're
accessed as attributes:

>>> class K(object): pass
...
>>> def g(self): pass
...
>>> g

>>> K.m = g
>>> K.m

>>> K.__dict__['m']

>>> K().m
>

Cheers! Now I will try to wrap my brain around metaclasses and coroutines. ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why "flat is better than nested"?

2010-10-25 Thread Steve Holden
On 10/25/2010 10:47 AM, rantingrick wrote:
> On Oct 25, 5:07 am, kj  wrote:
>> In "The Zen of Python", one of the "maxims" is "flat is better than
>> nested"?  Why?  Can anyone give me a concrete example that illustrates
>> this point?
> 
> Simple. This commandment (endowed by the anointed one, GvR) is
> directed directly at lisp and those filthy lispers. If you don't know
> what lisp is then Google it. Then try to program with it for one hour.
> Very soon after your head will explode from the nested bracket plague
> and then you shall be enlightened!
> 
And everyone taking the Zen too seriously should remember that it was
written by Tim Peters one night during the commercial breaks between
rounds of wrestling on television. So while it can give useful guidance,
it's nether prescriptive nor a bible ...

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why "flat is better than nested"?

2010-10-25 Thread kj
In  
rantingrick  writes:

>On Oct 25, 5:07=A0am, kj  wrote:
>> In "The Zen of Python", one of the "maxims" is "flat is better than
>> nested"? =A0Why? =A0Can anyone give me a concrete example that illustrate=
>s
>> this point?

>Simple. This commandment (endowed by the anointed one, GvR) is
>directed directly at lisp and those filthy lispers. If you don't know
>what lisp is then Google it. Then try to program with it for one hour.
>Very soon after your head will explode from the nested bracket plague
>and then you shall be enlightened!

Some of the earliest programming I ever did was in Lisp.  Scheme
actually.  In good ol' 6.001, back in '82.  I loved it.  I have no
problem whatsoever with it.

Benightedly yours,

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


Re: Question on multiple python environments in Apache

2010-10-25 Thread Steve Holden
On 10/25/2010 10:50 AM, Jeffrey Gaynor wrote:
> Because that is a mess to manage, involving hacking the Apache source
> and multiple recompiles (this will have to run under CentOS). Using
> Python should be easy and not entail multiple compiles of other
> people's software. My main question boils down to the best way to get
> mutltiples interpreters running at a time or, failing that, a way to
> get separate threads.
> 
> Is there an *easy* way to do this with virtualenv or virtual hosts
> under Apache?
> 
I fail to see why you have to recompile Apache to be able to run
multiple instances. I wonder if anyone has told Web Faction, who
typically run a separate instance of Apache for each web site run by
each of the many users who share one of their virtual hosts.

As far as I can see each of my web sites uses a bog standard Apache
server process with output on a specific TCP port, which is then
consumed by a front-end server process that forwards to individual
Apache instances according to what it sees in the request's Host: header.

Is it possible you misunderstood the advice?

regards
 Steve

> - Original Message - From: "Mario Miri"
>  To: "python-list"  
> Sent: Monday, October 25, 2010 2:50:55 AM Subject: Re: Question on
> multiple python environments in Apache
> 
> 
> Why wouldn't you use multiple apache instances?
> 
> 
> On Fri, Oct 22, 2010 at 11:28 PM, Jeffrey Gaynor <
> jgay...@ncsa.uiuc.edu > wrote:
> 
> 
> I have several different versions of a web app that run under Apache.
> The issue is that I need to have several different configurations
> available under several environments (such as Django, mod_python and
> plain vanilla mod_wsgi). Is there a simple way to get several of
> these to be completely independent? I thought about virtualenv, but
> it seems that I can only get one virtual environment for the entire
> server (so this just keeps it distinct from my main python install),
> rather than half a dozen. These will be on a dedicated test server so
> performance is not an issue.
> 
> Does anyone know of a good FAQ that discusses this?
> 
> Thanks in advance,
> 
> Jeff


-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: downcasting problem

2010-10-25 Thread Nikola Skoric
Dana Mon, 25 Oct 2010 09:38:42 -0500, 
Tim Chase  kaze:
> While a dirty hack for which I'd tend to smack anybody who used 
> it...you *can* assign to instance.__class__

Wow! Python never stops to amaze me.

> If it breaks you get to keep all the parts :)

Yes, I can see great potential for shit hitting the fan here.

Thanks for the tip!

-- 
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
-- 
http://mail.python.org/mailman/listinfo/python-list


j2py - overloading __init__

2010-10-25 Thread Brendan
I am posting here in the hopes the author of java2python will see it.
Does j2py handle overloading of the __init__ constructor?  For me it
is calling __init__ and not calling the decorator overloaded __init__0.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: j2py - overloading __init__

2010-10-25 Thread Brendan
On Oct 25, 12:57 pm, Brendan  wrote:
> I am posting here in the hopes the author of java2python will see it.
> Does j2py handle overloading of the __init__ constructor?  For me it
> is calling __init__ and not calling the decorator overloaded __init__0.

Never mind. Moronic type mistake.
-- 
http://mail.python.org/mailman/listinfo/python-list


[OFF] sed equivalent of something easy in python

2010-10-25 Thread Daniel Fetchinson
This question is really about sed not python, hence it's totally off.
But since lots of unix heads are frequenting this list I thought I'd
try my luck nevertheless.

If I have a file with content

1
2
3
4
5
6
7
8
...

i.e. each line contains simply its line number, then it's quite easy
to convert it into

2
3
7
8
12
13
...

using python. The pattern is that the first line is deleted, then 2
lines are kept, 3 lines are deleted, 2 lines are kept, 3 lines are
deleted, etc, etc.

But I couldn't find a way to do this with sed and since the whole
operation is currently done with a bash script I'd hate to move to
python just to do this simple task.

What would be the sed equivalent?

Cheers,
Daniel



-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OFF] sed equivalent of something easy in python

2010-10-25 Thread Tim Chase

On 10/25/2010 11:25 AM, Daniel Fetchinson wrote:

using python. The pattern is that the first line is deleted,
then 2 lines are kept, 3 lines are deleted, 2 lines are kept,
3 lines are deleted, etc, etc.


If you have GNU sed, you can use

  sed -n '2~5{N;p}'

which makes use of the GNU "~" extension. If you need a more
portable version:

 sed -n '1d;N;p;N;N;N;d'

Both have the side-effect that the expect the printed lines to 
come in pairs, so if you have


 seq 17 | sed -n '...'

it won't print the 17, but if you take it to 18, it will print 17 
and 18.  To address that (so to speak), you can use


 sed -n '1d;p;n;p;N;N;N;d'


But I couldn't find a way to do this with sed and since the
whole operation is currently done with a bash script I'd hate
to move to python just to do this simple task.


I'm not sure this is a great reason to avoid Python, but whatever 
floats your boat :)


However, if you have further sed questions, the sed mailing list 
over at Yahoo! Groups is a friendly one and will keep the noise 
down here.


-tkc



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


Re: [OFF] sed equivalent of something easy in python

2010-10-25 Thread Daniel Fetchinson
>> using python. The pattern is that the first line is deleted,
>> then 2 lines are kept, 3 lines are deleted, 2 lines are kept,
>> 3 lines are deleted, etc, etc.
>
> If you have GNU sed, you can use
>
>sed -n '2~5{N;p}'
>
> which makes use of the GNU "~" extension. If you need a more
> portable version:
>
>   sed -n '1d;N;p;N;N;N;d'
>
> Both have the side-effect that the expect the printed lines to
> come in pairs, so if you have
>
>   seq 17 | sed -n '...'
>
> it won't print the 17, but if you take it to 18, it will print 17
> and 18.  To address that (so to speak), you can use
>
>   sed -n '1d;p;n;p;N;N;N;d'

Thanks a lot, Tim!

>> But I couldn't find a way to do this with sed and since the
>> whole operation is currently done with a bash script I'd hate
>> to move to python just to do this simple task.
>
> I'm not sure this is a great reason to avoid Python, but whatever
> floats your boat :)

Well, the reason I wanted to avoid python in this particular case is
that I have a large bash script that does its job perfectly and I
needed to insert this additional task into it. I had 3 choices: (1)
rewrite the whole thing in python (2) add this one task in python (3)
add this one task in sed. I chose (3) because (1) looked like a waste
of time and (2) made me take care of 2 files instead of 1 from now on.

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Has Next in Python Iterators

2010-10-25 Thread Paul Rudin
Kelson Zawack  writes:

> The example I have in mind is list like [2,2,2,2,2,2,1,3,3,3,3] where
> you want to loop until you see not a 2 and then you want to loop until
> you see not a 3.

"loop until you see not a 2" - you mean yield 2s as long as there are 2s
to be consumed?

"loop until you see not a 3" - you mean yield 3s as long as there are 3s
to be consumed?

So in this case you'd see just the initial 2s? (Since the 1 immediately
follows the 2s and is "not a 3")

def twos_then_threes(iterable):
i = iter(iterable)
n = i.next()
while n==2:
   yield n
   n=i.next()
while n==3:
   yield n
   n=i.next()

so... no need for any has_next()

or do I misunderstand what you want to do? Probably this can be done
with some itertools.groupby() cunningness...




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


Re: How do I chain methods?

2010-10-25 Thread Terry Reedy

On 10/24/2010 11:42 PM, Chris Rebert wrote:

On Sun, Oct 24, 2010 at 4:11 PM, James Mills
  wrote:

On Mon, Oct 25, 2010 at 9:02 AM, Chris Rebert  wrote:

Method chaining is usually* not idiomatic in Python.


I don't agree but anyway... I've just not seen it commonly used
amongst python programmers.


If Python wanted to encourage method-chaining-style, then list.sort(),
list.reverse(), and several other built-in type methods would (ala
Ruby) return self rather than None. Since they don't, and since
"uncommon idiom" is a near-oxymoron, I think we can safely conclude
that method chaining isn't idiomatic in Python.


It is intentionally not idiomatic for methods that mutate or otherwise 
operate strictly by side-effect, as in the OP example.


It *is* idiomatic for methods that return new objects.

>>> s = ' abc def '
>>> s.strip().title()
'Abc Def'

And, of course, it is used internally to implement expressions with 
operators that also produce new objects.


>>> 3*2+1 == 3 .__mul__(2) . __add__(1)
True

--
Terry Jan Reedy

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


Re: Has Next in Python Iterators

2010-10-25 Thread Ian
On Oct 25, 4:33 am, Kelson Zawack  wrote:
> The example I have in mind is list like [2,2,2,2,2,2,1,3,3,3,3] where
> you want to loop until you see not a 2 and then you want to loop until
> you see not a 3.  In this situation you cannot use a for loop as
> follows:
>
> foo_list_iter = iter([2,2,2,2,2,2,1,3,3,3,3])
> for foo_item in foo_list_iter:
>     if foo_item != 2:
>         break
> because it will eat the 1 and not allow the second loop to find it.
> takeWhile and dropWhile have the same problem.  It is possible to use
> a while loop as follows:
>
> foo_list_item = foo_list_iter.next()
> while foo_list_item == 2:
>     foo_list_item = foo_list_iter.next()
> while foo_list_item == 3:
>     foo_list_item = foo_list_iter.next()
>
> but if you can't be sure the list is not empty/all 2s then all 3s you
> need to surround this code in a try block.  Unless there is a good
> reason for having to do this I think it is undesirable because it
> means that the second clause of the loop invariant, namely that you
> are not off the end of the list, is being controlled outside of the
> loop.

from itertools import chain, imap, izip, tee
from operator import itemgetter

foo_list_iter, next_foo_list_iter = tee([2,2,2,2,2,2,1,3,3,3,3])
next_foo_list_iter = chain([None], next_foo_list_iter)
foo_list_iter = imap(itemgetter(0), izip(foo_list_iter,
next_foo_list_iter))

for foo_item in foo_list_iter:
if foo_item != 2:
foo_list_iter = next_foo_list_iter
break

But in practice I think the best solution is to create an explicit
iterator wrapper that implements hasnext() and use it as needed, as
others in this thread have suggested.

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: downcasting problem

2010-10-25 Thread John Nagle

On 10/25/2010 7:38 AM, Tim Chase wrote:

While a dirty hack for which I'd tend to smack anybody who used it...you
*can* assign to instance.__class__


   That's an implementation detail of CPython.  May not work in 
IronPython, Unladen Swallow, PyPy, or Shed Skin.


(An implementation with a JIT has to trap stores into some
internal variables and invalidate the generated code.
This adds considerable complexity to the virtual machine.
Java JVMs, for example, don't have to support that.)

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


Re: Unicode questions

2010-10-25 Thread Seebs
On 2010-10-25, Lawrence D'Oliveiro  wrote:
> In message , Petite 
> Abeille wrote:
>> Characters vs. Bytes

> And why do certain people insist on referring to bytes as ???octets

One common reason is that there have been machines on which "bytes" were
not 8 bits.  In particular, the usage of "byte" as "the smallest addressible
storage" has been rather firmly ensconced in the C spec, so people used to
that are likely aware that, on a machine where the smallest directly
addressible chunk of space is 16 bits, it's quite likely that char is 16
bits, and thus by definition a "byte" is 16 bits, and if you want an octet,
you have to extract it from a byte.

-s
-- 
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to optimize and monitor garbage collection?

2010-10-25 Thread Terry Reedy

On 10/24/2010 8:39 PM, kj wrote:


I'm designing a system that will be very memory hungry unless it
is "garbage-collected" very aggressively.

In the past I have had disappointing results with the gc module:
I noticed practically no difference in memory usage with and without
it.  It is possible, however, that I was not measuring memory
consumption adequately.

What's the most accurate way to monitor memory consumption in a
Python program, and thereby ensure that gc is working properly?

Also, are there programming techniques that will result in better
garbage collection?  For example, would it help to explicitly call
del on objects that should be gc'd?


Python the language is not much concerned with memory. For an 
interpreter running on a computer, there are four memory sizes to be 
considered: the virtual memory assigned to the process; the physical 
memory assigned to the process; the physical memory used by Python 
objects; and the the memory used by 'active' objects accessible from 
program code. As far as I know, the OS can only see and report on the 
first and/or second.


If the gap between the second and third (assigned and used physical 
memory) is large and includes 'blocks' that are totally unused, the 
interpreter *may* be able to return such blocks. But do not count on it. 
When this gap expands because the program deletes objects without 
returning blocks, people get fooled by OS reports of assigned memory not 
shrinking (even though used memory is).


CPython tries to minimize the gap between all objects and active object 
both with reference counting and cyclic garbage collection (gc). Yes, 
you can help this along by judicious use of del and gc.collect. The goal 
should be to minimize the maximum active memory size. Reusing large 
arrays (rather than deleting and creating a new one) can sometimes help 
by avoiding fragmentation of allocated memory.


Terry Jan Reedy

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


Re: Unicode questions

2010-10-25 Thread Terry Reedy

On 10/25/2010 2:33 AM, Steve Holden wrote:

On 10/25/2010 1:42 AM, Lawrence D'Oliveiro wrote:

In message, Petite
Abeille wrote:


Characters vs. Bytes


And why do certain people insist on referring to bytes as “octets”?


Because back in the old days bytes were of varying sizes on different
architectures - indeed the DECSystem-10 and -20 had instructions that
could be parameterized as to byte size. So octet was an unambiguous term
for the (now standard) 8-bit byte.


As I remember, there were machines (CDC? Burroughs?) with 6-bit 
char/bytes: 26 upper-case letters, 10 digits, 24 symbols and control chars.

--
Terry Jan Reedy


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


Re: Why "flat is better than nested"?

2010-10-25 Thread kj
In  Steve Holden 
 writes:

>On 10/25/2010 10:47 AM, rantingrick wrote:
>> On Oct 25, 5:07 am, kj  wrote:
>>> In "The Zen of Python", one of the "maxims" is "flat is better than
>>> nested"?  Why?  Can anyone give me a concrete example that illustrates
>>> this point?
>> 
>> Simple. This commandment (endowed by the anointed one, GvR) is
>> directed directly at lisp and those filthy lispers. If you don't know
>> what lisp is then Google it. Then try to program with it for one hour.
>> Very soon after your head will explode from the nested bracket plague
>> and then you shall be enlightened!
>> 
>And everyone taking the Zen too seriously should remember that it was
>written by Tim Peters one night during the commercial breaks between
>rounds of wrestling on television. So while it can give useful guidance,
>it's nether prescriptive nor a bible ...

Well, it's pretty *enshrined*, wouldn't you say?  After all, it is
part of the standard distribution, has an easy-to-remember invocation,
etc.  *Someone* must have taken it seriously enough to go through
all this bother.  If it is as trivial as you suggest (and for all
I know you're absolutely right), then let's knock it off its pedestal
once and for all, and remove it from the standard distribution.

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


Re: downcasting problem

2010-10-25 Thread Emmanuel Surleau
> Hi everybody,
> 
> I need to downcast an object, and I've read repeatedly that if you
> need to downcast, you did something wrong in the design phase. So,
> instead of asking how do you downcast in python, let me explain my
> situation.
> 
> I have a 2-pass parser. 1st pass ends up with a bunch of superclass
> object, and 2nd pass is supposed to downcast those to one of
> subclasses so I can work with them.
> 
> Details:
> 
> I have a file full of lines which I parse into Line objects. I also
> have two subclasses of Line, namely Individual and Family. Constructor
> of both subclasses needs all Line objects in the file to be
> constructed, so I cannot construct subclass objects in the first pass.
> 
> The Python way of doing this (as I understand it) would be to wrap a
> subclass around Line and have the Line object as an attribute of a
> subclass. Now, this obviously breaks polymorphism and I now have to
> reimplement all of Line's classes in subclasses. Although
> reimplementation is simple (def method(self): return
> self.line.method()), that way of doing things is just not elegant.

> So, is there any more elegant solution to my problem?

Why not have an abstract Line class with your Line methods, a SimpleLine (your 
current Line class, extends AbstractLine), and IndividualLine and FamilyLine 
(both extending AbstractLine)?

Cheers,

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


Re: ftplib - Did the whole file get sent?

2010-10-25 Thread John Nagle

On 10/22/2010 10:03 PM, Sean DiZazzo wrote:

Hi,

I have some scripts that send files via ftplib to a client's ftp
site.  The scripts have generally worked great for a few years.
Recently, the client complained that only part of an important  file
made it to their server.  My boss got this complaint and brought it to
my attention.

The first thing I did was track down the specific file transfer in my
logs.  My log showed a success, I told my boss that, but he wasn't
satisfied with my response.  He began asking if there is a record of
the file transfer ack and number of bytes sent for this transfer.  I'm
not keeping a record of that...only success or failure (and some
output)

How can I assure him (and the client) that the transfer completed
successfully like my log shows?  I'm using code similar to the
following:

try:
 ftp = ftplib.FTP(host)
 ftp.login(user, pass)
 ftp.storbinary("STOR " + destfile, open(f.path, 'rb'))
 # log this as success
except:
 # log this as an error

Is ftplib reliable enough to say that if an exception is not thrown,
that the file was transferred in full?


   No.

   This was for years an outstanding problem with FTP under Windows.
See "http://www.fourmilab.ch/documents/corrupted_downloads/";
And 
"http://us.generation-nt.com/answer/incomplete-ftp-upload-under-windows-xp-help-139017881.html";

And "http://winscp.net/forum/viewtopic.php?t=6458";.  Many FTP
implementations have botched this.  TCP has all the machinery to
guarantee that both ends know the transfer completed
properly, but it's often misused.

   Looking at the Python source, it doesn't look good.  The "ftplib"
module does sending by calling sock_sendall in "socketmodule.c".
That does an OS-level "send", and once everything has been sent,
returns.

   But an OS-level socket send returns when the data is queued for
sending, not when it is delivered.  Only when the socket is closed,
and the close status checked, do you know if the data was delivered.
There's a final TCP close handshake that occurs when close has
been called at both ends, and only when it completes successfully
do you know that the data has been delivered.

   At the socket level, this is performed by "shutdown" (which
closes the connection and returns the proper network status
information), or by "close" (which forces a shutdown but doesn't
return status).

   Look at sock_close in "socketmodule.c".  Note that it ignores the
return status on close, always returns None, and never raises an 
exception.  As the Linux manual page for "close" says:
"Not checking the return value of close() is a common but nevertheless 
serious programming error. It is quite possible that errors on a 
previous write(2) operation are first reported at the final close(). Not 
checking the return value when closing the file may lead to silent loss 
of data."


   "ftplib", in "storlines" and "storbinary", calls "close"
without calling "shutdown" first.  So if the other end disconnects
after all data has been queued but not received, the sender will
never know.  FAIL.

   So there's your bug.

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


Re: Why "flat is better than nested"?

2010-10-25 Thread Terry Reedy

On 10/25/2010 3:11 PM, kj wrote:


Well, it's pretty *enshrined*, wouldn't you say?


No.

>  After all, it is part of the standard distribution,

So is 'import antigravity'

> has an easy-to-remember invocation,

etc.  *Someone* must have taken it seriously enough to go through
all this bother.  If it is as trivial as you suggest (and for all
I know you're absolutely right), then let's knock it off its pedestal
once and for all, and remove it from the standard distribution.


If you are being serious, you are being too serious (as in humorless).
The 'Zen of Python' is somewhere between 'trivial' and 'enshrined on a 
pedestal'. The two undocumented easter egg imports (visible in 
pythonx.y/Lib) are for both fun and edification.


--
Terry Jan Reedy

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


Re: Unicode questions

2010-10-25 Thread Steve Holden
On 10/25/2010 2:36 PM, Terry Reedy wrote:
> On 10/25/2010 2:33 AM, Steve Holden wrote:
>> On 10/25/2010 1:42 AM, Lawrence D'Oliveiro wrote:
>>> In message, Petite
>>> Abeille wrote:
>>>
 Characters vs. Bytes
>>>
>>> And why do certain people insist on referring to bytes as “octets”?
>>
>> Because back in the old days bytes were of varying sizes on different
>> architectures - indeed the DECSystem-10 and -20 had instructions that
>> could be parameterized as to byte size. So octet was an unambiguous term
>> for the (now standard) 8-bit byte.
> 
> As I remember, there were machines (CDC? Burroughs?) with 6-bit
> char/bytes: 26 upper-case letters, 10 digits, 24 symbols and control chars.

Yes, and DEC used the same (?) code, calling it SIXBIT. Since their
systems had 36-bit words it packed in very nicely.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: Why "flat is better than nested"?

2010-10-25 Thread Steve Holden
On 10/25/2010 3:11 PM, kj wrote:
> In  Steve Holden 
>  writes:
> 
>> On 10/25/2010 10:47 AM, rantingrick wrote:
>>> On Oct 25, 5:07 am, kj  wrote:
 In "The Zen of Python", one of the "maxims" is "flat is better than
 nested"?  Why?  Can anyone give me a concrete example that illustrates
 this point?
>>>
>>> Simple. This commandment (endowed by the anointed one, GvR) is
>>> directed directly at lisp and those filthy lispers. If you don't know
>>> what lisp is then Google it. Then try to program with it for one hour.
>>> Very soon after your head will explode from the nested bracket plague
>>> and then you shall be enlightened!
>>>
>> And everyone taking the Zen too seriously should remember that it was
>> written by Tim Peters one night during the commercial breaks between
>> rounds of wrestling on television. So while it can give useful guidance,
>> it's nether prescriptive nor a bible ...
> 
> Well, it's pretty *enshrined*, wouldn't you say?  After all, it is
> part of the standard distribution, has an easy-to-remember invocation,
> etc.  *Someone* must have taken it seriously enough to go through
> all this bother.  If it is as trivial as you suggest (and for all
> I know you're absolutely right), then let's knock it off its pedestal
> once and for all, and remove it from the standard distribution.
> 
I don't know who decided to put the "this" module into Python as an
Easter egg. But don't think you can suppress it now. Trying to do so
would only bring out people's inherent religious fervor and cause an
outcry you would regret.

Besides which I am sure Tim Peters derives a lot of harmless fun from
seeing people take it so seriously.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: Why "flat is better than nested"?

2010-10-25 Thread Ethan Furman

kj wrote:

In  Steve Holden 
 writes:


On Oct 25, 5:07 am, kj  wrote:

In "The Zen of Python", one of the "maxims" is "flat is better than
nested"?  Why?  Can anyone give me a concrete example that illustrates
this point?


Two points on the practical side:  most folk only remember a few levels 
deep, so shallow is easier to work with*; and, while premature 
optimization is usually a waste of time, effort, money, hair, etc., each 
level costs another lookup.



And everyone taking the Zen too seriously should remember that it was
written by Tim Peters one night during the commercial breaks between
rounds of wrestling on television. So while it can give useful guidance,
it's nether prescriptive nor a bible ...


Well, it's pretty *enshrined*, wouldn't you say?  After all, it is
part of the standard distribution, has an easy-to-remember invocation,
etc.  *Someone* must have taken it seriously enough to go through
all this bother.  If it is as trivial as you suggest (and for all
I know you're absolutely right), then let's knock it off its pedestal
once and for all, and remove it from the standard distribution.


The Zen is good humor, and good advice.  An excellent reminder to strive 
for balance in all things...


~Ethan~

--
* citation needed, I know
--
http://mail.python.org/mailman/listinfo/python-list


Re: downcasting problem

2010-10-25 Thread Diez B. Roggisch
Nikola Skoric  writes:

> Hi everybody,
>
> I need to downcast an object, and I've read repeatedly that if you
> need to downcast, you did something wrong in the design phase. So,
> instead of asking how do you downcast in python, let me explain my
> situation.
>
> I have a 2-pass parser. 1st pass ends up with a bunch of superclass
> object, and 2nd pass is supposed to downcast those to one of
> subclasses so I can work with them.

This is usually called a 'reducer' in parsing, and it's purpose is to
rewrite the parsing result to something new.

It's usually implemented using a visitor-pattern.

In your case, it should be rather straightforward, by simply iterating
over the objects and creating new, more specialized types depending on
what you actually need.

So you don't need to delegate anything.

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


Re: Why "flat is better than nested"?

2010-10-25 Thread Ben Finney
Steve Holden  writes:

> And everyone taking the Zen too seriously should remember that it was
> written by Tim Peters one night during the commercial breaks between
> rounds of wrestling on television. So while it can give useful
> guidance, it's nether prescriptive nor a bible ...

Even to those who don't know or don't remember its history, the Zen has
an excellent reminder of just how seriously it should be taken:

Load the source code for the ‘this’ module into a text editor, and see
how many of the maxims it violates.

-- 
 \ “Dyslexia means never having to say that you're ysror.” |
  `\—anonymous |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Inconsistent results from int(floatNumber)

2010-10-25 Thread gershar
I had some problems with some Python projects that gave variable
results that I could not track down. Eventually and reluctantly I
converted them to Java. Later, when I had more time I tried to analyze
what the Python code was doing and found something strange. The
following snippet illustrates the problem.

>>> i = -50.0
>>> for x in xrange(5):
i += 0.1
z = i * 10.0
print
print z
print int(z)

-499.0
-499

-498.0
-498

-497.0
-496

-496.0
-495

-495.0
-494


The first two iterations look OK but after that the int(z) function
returns the wrong value. It looks like the value was rounded down.  If
a just do this:
>>> int(-497.0)
-497
I get the value I expect.
So what is the problem?

It looks like a rounding problem but on the surface there is nothing
to round. I am aware that there are rounding limitations with floating
point arithmetic but the value passed to int() is always correct. What
would cause it to be off by 1 full digit in only some cases? Perhaps
something behind the scenes in the bowels of the interpreter ?.

I could not get the thing to fail without being inside the for loop;
does that have something to do with it?

To fix the problem I could use round() or math.floor().  Like this.

>>> i = -50.0
>>> for x in xrange(5):
i += 0.1
z = i * 10.0
print
print z
print(round(z))

-499.0
-499.0

-498.0
-498.0

-497.0
-497.0

-496.0
-496.0

-495.0
-495.0

Why should I have to do this?

Is there a general rule of thumb to know when this could be a problem?

Should any float-to-int conversion be suspect?

The above code was run in Python 2.5.4 on WinXP and Python 2.6.2 on
Linux(Fedora12)
Can anyone verify if this would be the same on 3.x?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inconsistent results from int(floatNumber)

2010-10-25 Thread Ian
On Oct 25, 3:44 pm, gershar  wrote:
> It looks like a rounding problem but on the surface there is nothing
> to round. I am aware that there are rounding limitations with floating
> point arithmetic but the value passed to int() is always correct.

No, it isn't:

>>> for x in xrange(5):
...   i += 0.1
...   z = i * 10.0
...   print
...   print z
...   print repr(z)
...   print int(z)
...

-499.0
-499.0
-499

-498.0
-498.0
-498

-497.0
-496.94
-496

-496.0
-495.94
-495

-495.0
-494.94
-494

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inconsistent results from int(floatNumber)

2010-10-25 Thread Dave Angel

On 2:59 PM, gershar wrote:

I had some problems with some Python projects that gave variable
results that I could not track down. Eventually and reluctantly I
converted them to Java. Later, when I had more time I tried to analyze
what the Python code was doing and found something strange. The
following snippet illustrates the problem.




i = -50.0
for x in xrange(5):

i += 0.1
z = i * 10.0
print
print z
print int(z)

-499.0
-499

-498.0
-498

-497.0
-496

-496.0
-495

-495.0
-494


The first two iterations look OK but after that the int(z) function
returns the wrong value. It looks like the value was rounded down.  If
No, the value is truncated upward, towards zero.  Down would be towards 
negative infinity.  And rounding would work, that's not what int() does.

a just do this:

int(-497.0)

-497
I get the value I expect.
So what is the problem?

It looks like a rounding problem but on the surface there is nothing
to round. I am aware that there are rounding limitations with floating
point arithmetic but the value passed to int() is always correct.
Define "correct."  If you mean that it's exactly an integer, that's 
false.  It's off a little, because 0.1 isn't exact, and multiplying by 
10 doesn't fix it.

  What
would cause it to be off by 1 full digit in only some cases? Perhaps
something behind the scenes in the bowels of the interpreter ?.

I could not get the thing to fail without being inside the for loop;
does that have something to do with it?

To fix the problem I could use round() or math.floor().  Like this.


round() is entirely different than truncating or flooring.

i = -50.0
for x in xrange(5):

i += 0.1
z = i * 10.0
print
print z
print(round(z))

-499.0
-499.0

-498.0
-498.0

-497.0
-497.0

-496.0
-496.0

-495.0
-495.0

Why should I have to do this?

Is there a general rule of thumb to know when this could be a problem?

Should any float-to-int conversion be suspect?

The above code was run in Python 2.5.4 on WinXP and Python 2.6.2 on
Linux(Fedora12)
Can anyone verify if this would be the same on 3.x?

This doesn't have anything to do with Python, but everything to do with 
binary floating point.  The thing that's confusing you most is that you 
think that if a value prints as 497.0, that it's actually equal to 
497.0.  False.


When you have an approximate value like 0.1, and you do arithmetic with 
it, sometimes the values aren't exact.


In :Python 3, they avoid this particular symptom usually by printing the 
values differently.  But the problem still exists.



DaveA

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


Re: Inconsistent results from int(floatNumber)

2010-10-25 Thread Terry Reedy

On 10/25/2010 5:44 PM, gershar wrote:

I had some problems with some Python projects that gave variable
results that I could not track down. Eventually and reluctantly I
converted them to Java. Later, when I had more time I tried to analyze
what the Python code was doing and found something strange. The
following snippet illustrates the problem.


i = -50.0
for x in xrange(5):

i += 0.1


The binary float resulting from the conversion of .1 is slightly greater 
than .1, so this increases i by slightly more than .1



z = i * 10.0


so z is increased be lightly more that 1


print
print z
print int(z)


float.__int__ truncates toward 0.


-499.0
-499

-498.0
-498

-497.0
-496


And here the extra increase shows up.


-496.0
-495

-495.0
-494



It looks like a rounding problem but on the surface there is nothing
to round. I am aware that there are rounding limitations with floating
point arithmetic but the value passed to int() is always correct.


No it is not. To see this, print more digits (which themselves are 
approximations of the actual binary value). With 3.1.2 on x86 system:


i = -50.0
form = '{:24.18f}'.format
print(form(.1))
for x in range(15):
i += 0.1
z = i * 10.0
print()
print(form(z))
print(int(z))

>>>
0.16

 -499.00
-499

 -498.00
-498

 -496.943157
-496

 -495.943157
-495

 -494.943157
-494

To completely understand, you would have to look at the binary bit 
pattern and know the exact behavior of floating point arithmetic on a 
system and the exact decimal to binary to decimal conversion algorithm.


--
Terry Jan Reedy

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


Re: Inconsistent results from int(floatNumber)

2010-10-25 Thread Ian
On Oct 25, 4:25 pm, Terry Reedy  wrote:
> The binary float resulting from the conversion of .1 is slightly greater
> than .1, so this increases i by slightly more than .1
>
> >    z = i * 10.0
>
> so z is increased be lightly more that 1

It should also be pointed out that Java in fact does the same thing:

$ cat Test.java
class Test
{
public static void main(String[] argv)
{
double i = -50.0;
for (int x = 0; x < 5; x++)
{
i += 0.1;
double z = i * 10.0;
System.out.println("");
System.out.println(z);
System.out.println((int) z);
}
}
}
$ javac Test.java
$ java Test

-499.0
-499

-498.0
-498

-496.94
-496

-495.94
-495

-494.94
-494

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: downcasting problem

2010-10-25 Thread Tim Chase

On 10/25/2010 12:56 PM, John Nagle wrote:

On 10/25/2010 7:38 AM, Tim Chase wrote:

While a dirty hack for which I'd tend to smack anybody who used it...you
*can* assign to instance.__class__


 That's an implementation detail of CPython.  May not work in
IronPython, Unladen Swallow, PyPy, or Shed Skin.


Curious by your claim, could you confirm this someplace in the 
docs?  From my reading of [1]'s "If x is an instance of a 
new-style class, then type(x) is typically the same as 
x.__class__ (although this is not guaranteed - a new-style class 
instance is permitted to override the value returned for 
x.__class__)" is that this can be overridden (the definition of 
"overridden" however may mean different things to different 
people)  and [2] refers to "__class__ assignment works only if 
both classes have the same __slots__" (that seems pretty clear 
that __class__ assignment is permissible)


-tkc


[1]
http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes

[2]
http://docs.python.org/reference/datamodel.html#__slots__





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


PyCon 2011 Reminder: Call for Proposals, Posters and Tutorials - us.pycon.org

2010-10-25 Thread Jesse Noller
PyCon 2011 Reminder: Call for Proposals, Posters and Tutorials - us.pycon.org
===

Well, it's October 25th! The leaves have turned and the deadline for submitting
main-conference talk proposals expires in 7 days (November 1st, 2010)!

We are currently accepting main conference talk proposals:
http://us.pycon.org/2011/speaker/proposals/

Tutorial Proposals:
http://us.pycon.org/2011/speaker/proposals/tutorials/

Poster Proposals:
http://us.pycon.org/2011/speaker/posters/cfp/

PyCon 2011 will be held March 9th through the 17th, 2011 in Atlanta, Georgia.
(Home of some of the best southern food you can possibly find on Earth!) The
PyCon conference days will be March 11-13, preceded by two tutorial days
(March 9-10), and followed by four days of development sprints (March 14-17).

We are also proud to announce that we have booked our first Keynote
speaker - Hilary Mason, her bio:

"Hilary is the lead scientist at bit.ly, where she is finding sense in vast
data sets. She is a former computer science professor with a background in
machine learning and data mining, has published numerous academic papers, and
regularly releases code on her personal site, http://www.hilarymason.com/.
She has discovered two new species, loves to bake cookies, and asks way too
many questions."

We're really looking forward to having her this year as a keynote speaker!

Remember, we've also added an "Extreme" talk track this year - no introduction,
no fluff - only the pure technical meat!

For more information on "Extreme Talks" see:

http://us.pycon.org/2011/speaker/extreme/

We look forward to seeing you in Atlanta!

Please also note - registration for PyCon 2011 will also be capped at a
maximum of 1,500 delegates, including speakers. When registration opens (soon),
you're going to want to make sure you register early! Speakers with accepted
talks will have a guaranteed slot.

We have published all registration prices online at:
http://us.pycon.org/2011/tickets/

Important Dates
November 1st, 2010: Talk proposals due.
December 15th, 2010: Acceptance emails sent.
January 19th, 2011: Early bird registration closes.
March 9-10th, 2011: Tutorial days at PyCon.
March 11-13th, 2011: PyCon main conference.
March 14-17th, 2011: PyCon sprints days.
Contact Emails:

Van Lindberg (Conference Chair) - v...@python.org
Jesse Noller (Co-Chair) - jnol...@python.org
PyCon Organizers list: pycon-organiz...@python.org
-- 
http://mail.python.org/mailman/listinfo/python-list


python library for mail/news message headers & bodies?

2010-10-25 Thread Arthur Divot
Is there a python library equivalent to Perl's News::Article
(load a file containing a news or mail message into an
object, manipulate the headers and body, create a new empty
one, save one to a file)?

Thanks!

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


Re: python library for mail/news message headers & bodies?

2010-10-25 Thread Chris Rebert
On Mon, Oct 25, 2010 at 7:18 PM, Arthur Divot  wrote:
> Is there a python library equivalent to Perl's News::Article
> (load a file containing a news or mail message into an
> object, manipulate the headers and body, create a new empty
> one, save one to a file)?

The `email` package in the std lib?:
http://docs.python.org/library/email.html

The Global Module Index is your friend:
http://docs.python.org/modindex.html

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Bank Loan Online and Small Business Finance in the US

2010-10-25 Thread neha shena
Bank Loan Online and Small Business Finance in the US

A bank loan online generally refers to funding provided by a bank that
can be accessed through an online application. Online applications
usually only take a few minutes to complete and are analyzed by the
bank within a couple of days. Bank loans typically do not require as
many documents as a small business loan, but banks may require
applicants to provide personal financial statements and credit
histories along with the purpose of the loaned funds.
 more read

http://lifeplaan.blogspot.com/2010/09/bank-loan-online-and-small-business.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Schengen States Study VISA ( Scolarship Visa)

2010-10-25 Thread neha shena
Schengen States Study  VISA ( Scolarship Visa)

The European Union (EU) allows for the free movement of goods between
Italy and other member states: Austria, Belgium, Bulgaria, Cyprus,
Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece,
Hungary, Ireland, Latvia, Lithuania, Luxembourg, Malta, Netherlands,
Poland, Portugal, Romania, Slovakia, Slovenia, Sweden, and United
Kingdom. The European Union has numerous bilateral and multilateral
agreementsmore

http://childschooledu.blogspot.com/2010/10/get-internship-in-united-states.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unix-head needs to Windows-ize his Python script (II)

2010-10-25 Thread Lawrence D'Oliveiro
In message , MRAB wrote:

> On 25/10/2010 02:19, Lawrence D'Oliveiro wrote:
>
>> In message, Dave
>> Angel wrote:
>>
>>> No. GUI programs are marked as win-app, so w stands for "Windows". Non
>>> GUI programs run in the console.
>>
>> You mean “GUI console”. So non-GUI apps get a GUI element whether they
>> want it or not, while GUI ones don’t. That’s completely backwards.
> 
> No, it's not. The fact that the console is also a GUI window is an
> implementation detail ...

It is not an implementation detail. It is intrinsic to the way Windows 
works. No other OS does it backwards like this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unix-head needs to Windows-ize his Python script (II)

2010-10-25 Thread Lawrence D'Oliveiro
In message , Steve 
Holden wrote:

> and, in fact, the console is only a GUI window in a windowed system. It
> might be one of the console emulation windows that init starts under
> linux, or even a terminal connected to a computer by a serila line, for
> heavens sake.

But now you’re no longer talking about Windows. Windows is the only one that 
gets it backwards like this, forcing the creation of GUI elements for non-
GUI-based programs, and not for GUI-based ones.

More reasonably-designed systems, such as you describe above, make no such 
distinction between “GUI” and “non-GUI” programs. There is no difference 
based on the name of your executable, how it is built, or what libraries it 
links to; the only difference is in its run-time behaviour, whether it 
invokes any GUI functions or not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why "flat is better than nested"?

2010-10-25 Thread Jorgen Grahn
On Mon, 2010-10-25, bruno.desthuilli...@gmail.com wrote:
> On 25 oct, 15:34, Alex Willmer  wrote:
>> On Oct 25, 11:07 am, kj  wrote:
>>
>> > In "The Zen of Python", one of the "maxims" is "flat is better than
>> > nested"?  Why?  Can anyone give me a concrete example that illustrates
>> > this point?
>>
>> I take this as a reference to the layout of the Python standard
>> library and other packages i.e. it's better to have a module hierarchy
>> of depth 1 or 2 and many top level items, than a depth of 5+ and only
>> a few top level items.
>>
> (snip)
>
> This also applies to inheritance hierarchies (which tend to be rather
> flat in Python compared to most mainstreams OOPLs), as well as nested
> classes etc.

Which mainstream languages are you thinking of?  Java?  Because C++ is
as flat as Python.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unix-head needs to Windows-ize his Python script (II)

2010-10-25 Thread Steve Holden
On 10/26/2010 2:08 AM, Lawrence D'Oliveiro wrote:
> In message , MRAB wrote:
> 
>> On 25/10/2010 02:19, Lawrence D'Oliveiro wrote:
>>
>>> In message, Dave
>>> Angel wrote:
>>>
 No. GUI programs are marked as win-app, so w stands for "Windows". Non
 GUI programs run in the console.
>>>
>>> You mean “GUI console”. So non-GUI apps get a GUI element whether they
>>> want it or not, while GUI ones don’t. That’s completely backwards.
>>
>> No, it's not. The fact that the console is also a GUI window is an
>> implementation detail ...
> 
> It is not an implementation detail. It is intrinsic to the way Windows 
> works. No other OS does it backwards like this.

I really don't understand what you are trying to say here. Could you
please explain? I know you to be a capable and sensible person, but this
sounds like nonsense to me, so I must be misunderstanding.

regards
 Steve

-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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