Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Bruno Cauet
Remarks heard & form updated.
Nathaniel, I'm not sure about that: even if the code is 2- and 3-compatible
you'll pick one runtime. 2 others questions now mention writing polyglot
code.

By the way I published the survey on HN, /r/programming & /r/python:
https://news.ycombinator.com/item?id=8730156 http://redd.it/2ovlwm
http://redd.it/2ovls4
Feel free to publish it anywhere else, to get as many answers as possible.

Bruno

2014-12-10 18:24 GMT+01:00 Nathaniel Smith :

> On 10 Dec 2014 17:16, "Ian Cordasco"  wrote:
> >
> > On Wed, Dec 10, 2014 at 11:10 AM, Donald Stufft 
> wrote:
> > >
> > > On Dec 10, 2014, at 11:59 AM, Bruno Cauet 
> wrote:
> > >
> > > Hi all,
> > > Last year a survey was conducted on python 2 and 3 usage.
> > > Here is the 2014 edition, slightly updated (from 9 to 11 questions).
> > > It should not take you more than 1 minute to fill. I would be pleased
> if you
> > > took that time.
> > >
> > > Here's the url: http://goo.gl/forms/tDTcm8UzB3
> > > I'll publish the results around the end of the year.
> > >
> > > Last year results: https://wiki.python.org/moin/2.x-vs-3.x-survey
> > >
> > >
> > > Just going to say http://d.stufft.io/image/0z1841112o0C is a hard
> question
> > > to answer, since most code I write is both.
> > >
> >
> > The same holds for me.
>
> That question appears to have just grown a "compatible with both" option.
>
> It might make sense to add a similar option to the following question
> about what you use for personal projects.
>
> -n
>
> ___
> Python-Dev mailing list
> python-...@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/brunocauet%40gmail.com
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Bruno Cauet
Hi all,
Last year a survey was conducted on python 2 and 3 usage.
Here is the 2014 edition, slightly updated (from 9 to 11 questions).
It should not take you more than 1 minute to fill. I would be pleased if
you took that time.

Here's the url: http://goo.gl/forms/tDTcm8UzB3
I'll publish the results around the end of the year.

Last year results: https://wiki.python.org/moin/2.x-vs-3.x-survey

Thank you
Bruno
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to detect that a function argument is the default one

2014-12-11 Thread Jean-Michel Pichavant


- Original Message -
> From: "Chris Angelico" 
> > c1 = Circle((0,0), 10, None)
> > print c1.mass
> > 20
> > c1.radius = 20
> > print c1.mass
> > 40
> 
> I think that juust might count as scope creep :) 
> ChrisA

Here you go :p

c1 = Circle((0,0), 10, None)
print c1.mass
20
c1.grow(+10)
print c1.mass
40

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Bruno Cauet
I hesitated a while before deciding not to include it! Apart from python core 
development what would be the reasons to work mostly on this version ?
I'll fix the omission right ahead.



—
Tagada tsouin tsouin

On Wed, Dec 10, 2014 at 10:57 PM, Chris Angelico  wrote:

> On Thu, Dec 11, 2014 at 3:59 AM, Bruno Cauet  wrote:
>> Here's the url: http://goo.gl/forms/tDTcm8UzB3
>> I'll publish the results around the end of the year.
> On "Which versions do you use?", 3.5 is not included. My primary
> Python 3 build on here is a 3.5 built from trunk. :)
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: eGenix mxODBC Plone/Zope Database Adapter 2.2.0

2014-12-11 Thread eGenix Team: M.-A. Lemburg

ANNOUNCING

  mxODBC Plone/Zope Database Adapter

Version 2.2.0

  for the Plone CMS and Zope server platform

  Available for Plone 4.0-4.3 and Plone 5.0,
Zope 2.12 and 2.13, on
Windows, Linux, Mac OS X, FreeBSD and other platforms

This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-Zope-DA-2.2.0-GA.html


INTRODUCTION

The eGenix mxODBC Zope DA allows you to easily connect your Zope or
Plone CMS installation to just about any database backend on the
market today, giving you the reliability of the commercially supported
eGenix product mxODBC and the flexibility of the ODBC standard as
middle-tier architecture.

The mxODBC Zope Database Adapter is highly portable, just like Zope
itself and provides a high performance interface to all your ODBC data
sources, using a single well-supported interface on Windows, Linux,
Mac OS X, FreeBSD and other platforms.

This makes it ideal for deployment in ZEO Clusters and Zope hosting
environments where stability and high performance are a top priority,
establishing an excellent basis and scalable solution for your Plone
CMS.

Product page:

http://www.egenix.com/products/zope/mxODBCZopeDA/


NEWS

We are pleased to announce our new version 2.2.0 of the mxODBC
Zope/Plone Database Adapter product.

In this release, we have upgraded the adapter to mxODBC 3.3.1 and
added compatibility with the latest Plone releases and ODBC
drivers/managers.

Feature Enhancements


 * Compatible with Plone 4.0 - 4.3.

 * Compatible with the upcoming Plone 5.0.

Enhanced Support for Stored Procedures

 * Added documentation on how to call stored procedures from Plone /
   Zope.

 * Added support for input, output and input/output parameters to the
   .callproc() method for calling stored procedures.

 * Added documentation on how to use External Methods to access and
   use the mxODBC Zope DA connection objects.

Fast Cursor Types

 * Switched to forward-only cursor types for all database backends,
   since this provides a much better performance for MS SQL Server and
   IBM DB2 drivers.

Updated mxODBC API

 * Access all new features from the updated mxODBC 3.3 API via the
   DatabaseConnect.connection attribute or by importing the mxODBC API
   directly. Please see the mxODBC 3.3.0 and 3.3.1 release
   announcements for full details.

Easier Installation

 * ThreadLock egg distribution provided by eGenix to avoid having a
   compiler installed for the installation buildout run. Please see
   our ThreadLock distribution release announcement for details:

   
http://www.egenix.com/company/news/eGenix-ThreadLock-Distribution-2.13.0.1.html

For the full list of features, please see the mxODBC Zope DA feature
list:

http://www.egenix.com/products/zope/mxODBCZopeDA/#Features


Driver Compatibility Enhancements
-

 * ODBC driver compatibility updated. By upgrading to the latest
   mxODBC 3.3 release, we are bringing all compatibility enhancements
   added to mxODBC 3.3 to the mxODBC Zope DA. This includes updated
   support for Oracle, MS SQL Server, Sybase ASE, IBM DB2, PostgreSQL
   and MySQL. See the mxODBC 3.3.0 and 3.3.1 release announcements for
   full details:

   http://www.egenix.com/company/news/eGenix-mxODBC-3.3.0-GA.html
   http://www.egenix.com/company/news/eGenix-mxODBC-3.3.1-GA.html

 * ODBC manager compatibility updated. Built against unixODBC 2.3.2,
   iODBC 3.52.8, DataDirect 7.1.2 on Unix. Built against the MS
   Windows Manager ODBC on Windows. Built against iODBC 3.52.8 on Mac
   OS X.

The complete list of changes is available on the mxODBC Zope DA
changelog page.

http://www.egenix.com/products/zope/mxODBCZopeDA/changelog.html


UPGRADING

Users are encouraged to upgrade to this latest mxODBC Plone/Zope
Database Adapter release to benefit from the new features and updated
ODBC driver support. We have taken special care not to introduce
backwards incompatible changes, making the upgrade experience as
smooth as possible.

For major and minor upgrade purchases, we will give out 20% discount
coupons going from mxODBC Zope DA 1.x to 2.2 and 50% coupons for
upgrades from mxODBC 2.x to 2.2. After upgrade, use of the original
license from which you upgraded is no longer permitted. Patch level
upgrades (e.g. 2.2.0 to 2.2.1) are always free of charge.

Please contact the eGenix.com Sales Team with your existing license
serials for details for an upgrade discount coupon.

If you want to try the new release before purchase, you can request
30-day evaluation licenses by v

Re: Python script isn't producing text in data file

2014-12-11 Thread alister
On Thu, 11 Dec 2014 05:19:44 +, Grant Edwards wrote:

> On 2014-12-11, Docfxit  wrote:
> 
>> I am happy to paste it into a post.  The reason I didn't is because
>> it's very large.  The Python script is 1239 lines long.  The example
>> summary is 105 lines long.  The input log is 6810 lines long.
>>
>> Are you sure you want me to post all of that here?  Or would you like
>> me to post it on a pastebin?
> 
> You're going to need to create a _short_ example program that
> demonstrates the problem you're asking about.  It needs to be included
> in your post and fit in _one_ screen full.  A few people will look at
> longer examples, but your chances of the right person seeing it and
> figuring out your problem before their internal timer (or the one on the
> microwave) goes "ding!"  drop precipitously as it gets longer. Your
> chances approach 0 pretty fast if it requires following a URL to some
> site full of malware[1].
> 
> 
> [1] Yes, all sites are full of malware.

Also creating the shorter example will often reveal the subtle bug or 
design flaw that you are currently overlooking.
 
this is a good start towards diagnosing your own issue (& then of course 
people here will help if you are still having the problem)


-- 
You're too beautiful to ignore.  Too much woman.
-- Kirk to Yeoman Rand, "The Enemy Within", stardate 
unknown
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script isn't producing text in data file

2014-12-11 Thread alister
On Wed, 10 Dec 2014 20:23:56 -0800, Docfxit wrote:

> On Wednesday, December 10, 2014 7:55:17 PM UTC-8, Ben Finney wrote:
>> Docfxit  writes:
>> 
>> > I am happy to paste it into a post.  The reason I didn't is because
>> > it's very large.  The Python script is 1239 lines long.
>> 
>> That's too long to direct us toward, no matter where you put it.
>> 
>> Your task, then, is to construct a *much* smaller and simpler example
>> that still demonstrates the behaviour you want explained.
>> 
>> Once you have that, one of two things will be true:
>> 
>> * It will be small and clear enough that we can discuss it here
>>   usefully. Or
>> 
>> * You will have understood the problem well enough to solve it
>> yourself.
>> 
>> Please, construct a Short, Self-Contained, Complete Example
>> http://sscce.org/> of code that exhibits the behaviour.
>> 
>> --
>>  \  "When cryptography is outlawed, bayl bhgynjf jvyy unir
>>  |
>>   `\  cevinpl." --Anonymous
>>   |
>> _o__) 
>> |
>> Ben Finney
> 
> Thank you all for the encouragement to make it smaller.
> I don't know enough about Python to figure out how to isolate where the
> problem is happening.

That should then be your first port of call, check the Python 
documentation & step through the code manually.
> 
> Maybe it would be best If I could get some help in getting a debugger
> working so I can try to work through the script one line at a time. 

it is probably just as easy to add print statements into a copy of the 
code so you can where the code has got to & what your Values are.

> I have started to install a debugger but I can't get it working.
> I'm working in Win7 Pro.  I'm trying to get Winpdb working.
> I have an error when I run the debugger.  It says winpdb is missing.
> 
> winpdb.py is located in:   -same version
> C:\Python27\Lib\site-packages C:\winpdb-winpdb
> 
> winpdb   is located in:
> C:\winpdb-winpdb
> 
> Is winpdb supposed to be in c:\python27?
> 
> If it is, how is it supposed to get there?  (Some install?)
> 
> Thanks,
> 
> Docfxit





-- 
You canna change the laws of physics, Captain; I've got to have thirty 
minutes!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script isn't producing text in data file

2014-12-11 Thread Peter Otten
Docfxit wrote:

> I don't know enough about Python to figure out how to isolate where the
> problem is happening.

Can you get hold of the person who wrote the script? 


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


Re: How to detect that a function argument is the default one

2014-12-11 Thread Jean-Michel Pichavant
- Original Message -
> From: "ast" 

> >
> >> Note : what is the mass of a circle ?
> >
> 
> In fact it's a ball moving in a plan.
> I will change that name.

I would advise to remove the the mass parameter of your Sphere initialization. 
It could be inconsistent with the radius.
To compute the mass you would need the radius and the  volumetric mass density.

pseudo code:

class Sphere(object):
  def __init__(self, center, radius, density):

  @property
  def volume(self):
return 4/3.*pi*self.radius^3

  @property
  def mass(self):
return self.volume*self.density

You'll find no the net the density for most of the materials.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Problem with a dialog

2014-12-11 Thread ast

Hello

I provide two almost identical small test case programs.
The first one works as expected, 'True' is printed on the
console.
With the second one Python complains that 'test' is not 
known. I dont understand why.


Python 3.4, windows


#
## First
#

from tkinter import *
import tkinter.simpledialog

class MyDialog(tkinter.simpledialog.Dialog):

   def body(self, master):
   print(test)
   
   def apply(self):

   pass

root = Tk()
test = True
setup = MyDialog(root)

# 'True' is printed on the console. Works !



#
## Second
#

from tkinter import *
import tkinter.simpledialog

class MyDialog(tkinter.simpledialog.Dialog):

   def body(self, master):
   print(test)
   
   def apply(self):

   pass

def try_():

   test = True 
   setup = MyDialog(root)



root = Tk()
try_()

# NameError: name 'test' is not defined
--
https://mail.python.org/mailman/listinfo/python-list


Re: gdb python print truncated string

2014-12-11 Thread milanxa
-=Scorp=-

 Okay, i fixed this limit (truncated) as follows: find python2.7-gdb.py (in 
/usr/lib... path) and found/change value for MAX_OUTPUT_LEN const (default 
value is 1024), then restart gdb and you'll se new truncate limits.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with a dialog

2014-12-11 Thread Steven D'Aprano
ast wrote:

> Hello
> 
> I provide two almost identical small test case programs.
> The first one works as expected, 'True' is printed on the
> console.
> With the second one Python complains that 'test' is not
> known. I dont understand why.


> #
> ## Second
> #
>  
> from tkinter import *
> import tkinter.simpledialog
> 
> class MyDialog(tkinter.simpledialog.Dialog):
> 
> def body(self, master):
> print(test)

Here, "test" must be a global variable. Since the body() method doesn't
assign to the name "test" (e.g. a line like "test = 23") that makes it a
global.


> def apply(self):
> pass
> 
> def try_():
> test = True
> setup = MyDialog(root)

Here, the try_() function creates two local variables, "test" and "setup".
The important thing here is that "test" is local to the function, not
global.

That means that when MyDialog's body() method runs, it looks for a global
variable "test", but there isn't one. The local variable inside try_() is
invisible to it.

You can make "test" global by declaring it global:

def try_():
global test
test = True
setup = MyDialog(root)



If that solves your problem to your satisfaction, you can stop reading now.



Still here? Good :-)

To be a little more advanced for a moment... what you tried to do (possibly
inadvertently?) is possible in some computer languages, but not Python. In
most languages, the rule is that functions (and methods) can see the
following variables:

- variables inside the function itself (local variables)

- variables inside nested functions [see below], sometimes 
  called "nonlocal variables"

- global variables defined at the top level of the module or 
  program (outside of any function)


but not variables inside functions that *call* your function. This is
called "static scoping" or "lexical scoping".

What's a nested function? That's just when you put a function inside another
function:

def outer():
x = 23
def inner():
return 3*x
return inner() + 1


In this case, inner() is nested inside outer(), so it can see outer()'s
local variables, such as "x". Nothing else can see inner(), since it is
local to outer().

As I said, most programming languages work like this. But a small minority
use a different system, called "dynamic scoping". In dynamic scoping, it
doesn't matter *where* a function is defined, only where it is called. With
dynamic scoping, your code would have worked correctly.

If you are used to languages like Javascript, you may have done that
deliberately, thinking Python worked the same way. It doesn't.


-- 
Steven

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


Re: Problem with a dialog

2014-12-11 Thread ast


"Steven D'Aprano"  a écrit dans le message de 
news:54898820$0$12989$c3e8da3$54964...@news.astraweb.com...




As I said, most programming languages work like this. But a small minority
use a different system, called "dynamic scoping". In dynamic scoping, it
doesn't matter *where* a function is defined, only where it is called. With
dynamic scoping, your code would have worked correctly.



Thank you  very much.

This is my mistake
I knew that a function defined in a scope "knows" the variables defined
in that scope, at least for reading (for writing, it is more complicated).
I didnt realize that my function/class was called, not defined in that
scope. 


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


New member - 'odd' question

2014-12-11 Thread Jacob Kruger
Firstly, python is one of my two current focus areas, and while I still work 
with python 2.7, sort of for backward compatibility, my other focus area is web 
development, making use of PHP, javascript, jQuery, MySQL, etc.

And, I develop on windows7 64 bit machines, in conjunction with screen reader 
software - either jaws, or NVDA, if that means much...

Now, one of the current pieces of work am busy with involves sort of automating 
the process of converting some MS access databases to MySQL, and 
manipulating/rearranging the data during the conversion process.

I am implementing this using a python app, making use of wxPython to implement 
the GUI, and am using pyodbc to pull in the data structures, and read the data 
from .mdb files, and then am trying to use either pyodbc, or MySQLdb modules to 
then handle interaction with the MySQL side of things, and the MySQL database 
engine is part of the WAMP installation on my dev machine, FWIW.

Now, on my primary, desktop machine, it seems like if I implement pyodbc 
connections and cursors to handle the input data/structures from an .mdb file, 
and then write out the relevant SQL queries to text files, and then try to read 
them in, split them into separate statements, and execute them against the 
MySQL database, that part of it runs fine, but, the odd issue seems to be that 
if I did in fact first create/open a pyodbc connection object, along with it's 
relevant cursor object, and even if make sure close both of them, then on my 
one machine, after then initiating the direct MySQLdb connection object, I am 
still unable to actually close the whole app down - the main class is a sort of 
inheritor of wx.Frame, and before closing it down, I destroy both the Frame and 
all it's children, but, the main oddity is that while this works fine on my 
other laptop, on my desktop machine it always just ends up telling me 
python.exe is not responding, and would I like to force it to close?

And, it's definitely got something to do with the combination of having created 
and/or destroyed the pyodbc objects first, and then creating MySQLdb objects, 
since either half works fine by itself, but not together - on one machine 
anyway.

Just wondering what can be causing this to occur on one machine, but not the 
other, relatively similar, but maybe cleaner machine, and how to try track down 
something like this?

That's also why am posting this here - trying to figure out how to track down 
what's causing this odd behaviour.

TIA

Jacob Kruger
Blind Biker
Skype: BlindZA
...Roger Wilco wants to welcome you, to the space janitor's closet...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with a dialog

2014-12-11 Thread ast


"Steven D'Aprano"  a écrit dans le message de 
news:54898820$0$12989$c3e8da3$54964...@news.astraweb.com...



You can make "test" global by declaring it global:

def try_():
   global test
   test = True
   setup = MyDialog(root)



If that solves your problem to your satisfaction, you can stop reading now.



Since try() is a callback function called when a button is pushed,
with the effect to open a dialog, I tried to define MyDialog class
inside try(). The program is the following and it works. I no
longer need to define test as global.
Is it a good practice to define a class inside a function ?


from tkinter import *
import tkinter.simpledialog

def try_():

   class MyDialog(tkinter.simpledialog.Dialog):

   def body(self, master):
   print(test)

   def apply(self):
   pass


   test = True
   setup = MyDialog(root)


root = Tk()
try_() 


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


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Giampaolo Rodola'
On Wed, Dec 10, 2014 at 5:59 PM, Bruno Cauet  wrote:

> Hi all,
> Last year a survey was conducted on python 2 and 3 usage.
> Here is the 2014 edition, slightly updated (from 9 to 11 questions).
> It should not take you more than 1 minute to fill. I would be pleased if
> you took that time.
>
> Here's the url: http://goo.gl/forms/tDTcm8UzB3
> I'll publish the results around the end of the year.
>
> Last year results: https://wiki.python.org/moin/2.x-vs-3.x-survey
>
> Thank you
> Bruno
>
> ___
> Python-Dev mailing list
> python-...@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/g.rodola%40gmail.com
>

I still think the only *real* obstacle remains the lack of important
packages such as twisted, gevent and pika which haven't been ported yet.
With those ones ported switching to Python 3 *right now* is not only
possible and relatively easy, but also convenient.


-- 
Giampaolo - http://grodola.blogspot.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When do default parameters get their values set?

2014-12-11 Thread Chris Kaynor
On Wed, Dec 10, 2014 at 7:15 PM, Steven D'Aprano 
wrote:

> On Wed, 10 Dec 2014 18:18:44 -0800, Rustom Mody wrote:
>
>
> > And going the other way -- no defs only lambdas its this:
> >
> >
>  f = lambda : (lambda x= {}: x)
>  f()() is f()()
> > False
>  d = f()
>  d() is d()
> > True
> 
> 
> >
> > But I have a different question -- can this be demonstrated without the
> > 'is'?
>
>
> Can *what* be demonstrated? That the functions returned are different
> objects, or that the dicts are different objects? Both? Something else?
>
> Using "is" you are demonstrating that calling the function twice returns
> two distinct objects. That is the purpose of "is", to compare object
> identity. Without "is", you can compare object IDs directly:
>
> id(f()()) == id(f()())
>
> but that's ugly and less efficient. Using "is" is the more idiomatic and
> natural way to do this.
>

In CPython, that does not work, as the dictionary will be garbage collected
after each call to id:
>>> f = lambda : (lambda x= {}: x)
>>> f()() is f()()
False
>>> id(f()()) == id(f()())
True


>
> Other than that, you could do something to demonstrate the consequences
> of the two values being distinct objects:
>
> a = f()()  # Call twice to get a dict.
> b = f()()
> a['key'] = 23
> b['key']  # raises KeyError
>
>
> or
>
> a = f()  # Call once to get a function.
> b = f()
> a.attribute = 23
> b.attribute  # raises AttributeError
>
>
> Or you could inspect the byte-code of f and try to understand it.
>
>
Another way would be to to demonstrate the behavior, without using is,
would be to use a global counter variable:

a = 1
def f():
global a
def g(b=[a]):
return b
a += 1
return g

 >>> f()()
[1]
>>> f()()
[2]
>>> a = f()
>>> a()
[3]
>>> a()
[3]
>>> b = f()
>>> b()
[4]
>>> a()
[3]
-- 
https://mail.python.org/mailman/listinfo/python-list


is_ as method or property?

2014-12-11 Thread Mateusz Loskot
Hi,

I have been looking at various places to answer this dilemma:

If a class member function simply tests something and
returns a b::oolean call it

def is_():
 pass

like 'is_even'.

Should I define it as a classic method

def is_even(self):
pass

or as a property

@property
def is_even(self):
pass

The question above is based on similar question I found [1],
but that one is specifically about naming.
I'm trying to solve the aspect of implementation of such predicate.

I've looked into the Python 3.4 libs and most of such functions is
realised as a classic method, but in several cases they are
defined with @property decorator, for example:
email.message.MIMEPart.iis_attachment
ipaddress._BaseNetwork.is_multicast
ipaddress._BaseNetwork is_reserved
and a few more.

So, a classic method or a property, which one is the Pythonic 3 way for
such member predicates?

[1] *Naming Conventions* by Thorsten Kampe
https://mail.python.org/pipermail/python-list/2007-June/438156.html

Best regards,
-- 
Mateusz  Loskot, http://mateusz.loskot.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to detect that a function argument is the default one

2014-12-11 Thread Ian Kelly
On Thu, Dec 11, 2014 at 3:02 AM, Jean-Michel Pichavant <
jeanmic...@sequans.com> wrote:
> I would advise to remove the the mass parameter of your Sphere
initialization. It could be inconsistent with the radius.
> To compute the mass you would need the radius and the  volumetric mass
density.

You assume a three-dimensional universe. Clearly this is a two-dimensional
"ball" with a density equal to pi/2 mass units per area unit.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to detect that a function argument is the default one

2014-12-11 Thread Ian Kelly
On Thu, Dec 11, 2014 at 11:03 AM, Ian Kelly  wrote:
>
> On Thu, Dec 11, 2014 at 3:02 AM, Jean-Michel Pichavant <
jeanmic...@sequans.com> wrote:
> > I would advise to remove the the mass parameter of your Sphere
initialization. It could be inconsistent with the radius.
> > To compute the mass you would need the radius and the  volumetric mass
density.
>
> You assume a three-dimensional universe. Clearly this is a
two-dimensional "ball" with a density equal to pi/2 mass units per area
unit.

Er. 2/pi.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is_ as method or property?

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 4:34 AM, Mateusz Loskot  wrote:
> If a class member function simply tests something and
> returns a b::oolean call it
>
> def is_():
>  pass
>
> like 'is_even'.
>
> Should I define it as a classic method
>
> def is_even(self):
> pass
>
> or as a property
>
> @property
> def is_even(self):
> pass

A property should be used if what you're creating is "virtually an
attribute". If it would make sense to have an attribute is_even, then
a property is_even makes sense. If in doubt, go with a method.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is_ as method or property?

2014-12-11 Thread Ethan Furman
On 12/11/2014 09:34 AM, Mateusz Loskot wrote:
> 
> def is_():
>  pass
> 
> like 'is_even'.
> 
> Should I define it as a classic method
> 
> def is_even(self):
> pass
> 
> or as a property
> 
> @property
> def is_even(self):
> pass
> 
> So, a classic method or a property, which one is the Pythonic 3 way for
> such member predicates?

Generally, attributes (and properties look like attributes) are for items that 
the object already knows the answer to,
and methods are for things that need to be calculated, and may change 
throughout the life of the object.

--
~Ethan~



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Text Code(from 'Getting Started in Beautiful Soup' re: cd Soup , returns 'Syntax Error, invalid syntax'

2014-12-11 Thread Simon Evans
At the start of Chapter 3 of 'Getting Started in Beautiful Soup' it has said to 
create a html file, 'ecological 

pyramid.html' - which I have already done re:







plants
10


algae
10




deer
1000

deer
1000


rabbit
2000




fox
100


bear
100




lion
80


tiger
50





and ran it okay in 'Explorer', and text then says to save it to a folder named 
'Soup' which I have done. 
On the next page (30) it says to navigate to that folder with the following  
code to the python console :-
 
cd Soup

however console rejects that code with the following return: - 

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> cd Soup
  File "", line 1
cd Soup
  ^
SyntaxError: invalid syntax
>>>

Thank you for reading, hope you can help.
Yours
Simon Evans
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Text Code(from 'Getting Started in Beautiful Soup' re: cd Soup , returns 'Syntax Error, invalid syntax'

2014-12-11 Thread sohcahtoa82
On Thursday, December 11, 2014 11:21:52 AM UTC-8, Simon Evans wrote:
> At the start of Chapter 3 of 'Getting Started in Beautiful Soup' it has said 
> to create a html file, 'ecological 
> 
> pyramid.html' - which I have already done re:
> 
> 
> 
> 
> 
> 
> 
> plants
> 10
> 
> 
> algae
> 10
> 
> 
> 
> 
> deer
> 1000
>  
> deer
> 1000
> 
> 
> rabbit
> 2000
> 
> 
> 
> 
> fox
> 100
> 
> 
> bear
> 100
> 
> 
> 
> 
> lion
> 80
> 
> 
> tiger
> 50
> 
> 
> 
> 
> 
> and ran it okay in 'Explorer', and text then says to save it to a folder 
> named 'Soup' which I have done. 
> On the next page (30) it says to navigate to that folder with the following  
> code to the python console :-
>  
> cd Soup
> 
> however console rejects that code with the following return: - 
> 
> Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on 
> win
> 32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> cd Soup
>   File "", line 1
> cd Soup
>   ^
> SyntaxError: invalid syntax
> >>>
> 
> Thank you for reading, hope you can help.
> Yours
> Simon Evans

You're probably supposed to type that in your command-line console (Similar to 
a Linux terminal), not your Python console.  "cd" is a command-line console 
command.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Mark Roberts
I disagree. I know there's a huge focus on The Big Libraries (and wholesale
migration is all but impossible without them), but the long tail of
libraries is still incredibly important. It's like saying that migrating
the top 10 Perl libraries to Perl 6 would allow people to completely ignore
all of CPAN. It just doesn't make sense.

-Mark

On Thu, Dec 11, 2014 at 6:47 AM, Giampaolo Rodola' 
wrote:

>
>
> On Wed, Dec 10, 2014 at 5:59 PM, Bruno Cauet  wrote:
>
>> Hi all,
>> Last year a survey was conducted on python 2 and 3 usage.
>> Here is the 2014 edition, slightly updated (from 9 to 11 questions).
>> It should not take you more than 1 minute to fill. I would be pleased if
>> you took that time.
>>
>> Here's the url: http://goo.gl/forms/tDTcm8UzB3
>> I'll publish the results around the end of the year.
>>
>> Last year results: https://wiki.python.org/moin/2.x-vs-3.x-survey
>>
>> Thank you
>> Bruno
>>
>> ___
>> Python-Dev mailing list
>> python-...@python.org
>> https://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe:
>> https://mail.python.org/mailman/options/python-dev/g.rodola%40gmail.com
>>
>
> I still think the only *real* obstacle remains the lack of important
> packages such as twisted, gevent and pika which haven't been ported yet.
> With those ones ported switching to Python 3 *right now* is not only
> possible and relatively easy, but also convenient.
>
>
> --
> Giampaolo - http://grodola.blogspot.com
>
>
> ___
> Python-Dev mailing list
> python-...@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/wizzat%40gmail.com
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Text Code(from 'Getting Started in Beautiful Soup' re: cd Soup , returns 'Syntax Error, invalid syntax'

2014-12-11 Thread Dave Angel
Please give your environment when starting a new thread.  Python version 
and OS version.  In this case, I'm guessing Windows, because I have to 
guess something to give a meaningful answer.


On 12/11/2014 02:21 PM, Simon Evans wrote:

At the start of Chapter 3 of 'Getting Started in Beautiful Soup' it has said to 
create a html file, 'ecological

pyramid.html' - which I have already done re:





and ran it okay in 'Explorer', and text then says to save it to a folder named 
'Soup' which I have done.
On the next page (30) it says to navigate to that folder with the following  
code to the python console :-

cd Soup

however console rejects that code with the following return: -

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.

cd Soup

   File "", line 1
 cd Soup
   ^
SyntaxError: invalid syntax




cd is not a Python "command", it's a   cmd command.  In other words, you 
type that in your DOS box before starting Python.



--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list


Re: Text Code(from 'Getting Started in Beautiful Soup' re: cd Soup , returns 'Syntax Error, invalid syntax'

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 6:34 AM, Dave Angel  wrote:
> Please give your environment when starting a new thread.  Python version and
> OS version.  In this case, I'm guessing Windows, because I have to guess
> something to give a meaningful answer.
>
> On 12/11/2014 02:21 PM, Simon Evans wrote:
>> Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
>> on win
>> 32

You mean like how he quoted his Python startup line, thus telling you
Python version, word size, and the fact that it's win32?

Granted, it would be nice to have that up front, rather than buried
deep in the text, but the information _is_ there.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Text Code(from 'Getting Started in Beautiful Soup' re: cd Soup , returns 'Syntax Error, invalid syntax'

2014-12-11 Thread Dave Angel

On 12/11/2014 02:40 PM, Chris Angelico wrote:

On Fri, Dec 12, 2014 at 6:34 AM, Dave Angel  wrote:

Please give your environment when starting a new thread.  Python version and
OS version.  In this case, I'm guessing Windows, because I have to guess
something to give a meaningful answer.

On 12/11/2014 02:21 PM, Simon Evans wrote:

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
on win
32


You mean like how he quoted his Python startup line, thus telling you
Python version, word size, and the fact that it's win32?

Granted, it would be nice to have that up front, rather than buried
deep in the text, but the information _is_ there.



Right of course.  My eyeballs didn't happen to scan that far to the 
right.  I was looking for drive letters or backslashes, or other clues, 
but missed the three-letter one "win" or for that matter the "MSC" one, 
which wouldn't actually have been conclusive.



--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Dan Stromberg
On Thu, Dec 11, 2014 at 11:35 AM, Mark Roberts  wrote:
> I disagree. I know there's a huge focus on The Big Libraries (and wholesale
> migration is all but impossible without them), but the long tail of
> libraries is still incredibly important. It's like saying that migrating the
> top 10 Perl libraries to Perl 6 would allow people to completely ignore all
> of CPAN. It just doesn't make sense.

Things in the Python 2.x vs 3.x world aren't that bad.

See:
https://python3wos.appspot.com/ and
https://wiki.python.org/moin/PortingPythonToPy3k
http://stromberg.dnsalias.org/~strombrg/Intro-to-Python/ (writing code
to run on 2.x and 3.x)

I believe just about everything I've written over the last few years
either ran on 2.x and 3.x unmodified, or ran on 3.x alone.  If you go
the former route, you don't need to wait for your libraries to be
updated.

I usually run pylint twice for my projects (after each change, prior
to checkin), once with a 2.x interpreter, and once with a 3.x
interpreter (using
http://stromberg.dnsalias.org/svn/this-pylint/trunk/this-pylint) , but
I gather pylint has the option of running on a 2.x interpreter and
warning about anything that wouldn't work on 3.x.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Brett Cannon
On Thu Dec 11 2014 at 3:14:42 PM Dan Stromberg  wrote:

> On Thu, Dec 11, 2014 at 11:35 AM, Mark Roberts  wrote:
> > I disagree. I know there's a huge focus on The Big Libraries (and
> wholesale
> > migration is all but impossible without them), but the long tail of
> > libraries is still incredibly important. It's like saying that migrating
> the
> > top 10 Perl libraries to Perl 6 would allow people to completely ignore
> all
> > of CPAN. It just doesn't make sense.
>
> Things in the Python 2.x vs 3.x world aren't that bad.
>
> See:
> https://python3wos.appspot.com/ and
> https://wiki.python.org/moin/PortingPythonToPy3k
> http://stromberg.dnsalias.org/~strombrg/Intro-to-Python/ (writing code
> to run on 2.x and 3.x)
>
> I believe just about everything I've written over the last few years
> either ran on 2.x and 3.x unmodified, or ran on 3.x alone.  If you go
> the former route, you don't need to wait for your libraries to be
> updated.
>
> I usually run pylint twice for my projects (after each change, prior
> to checkin), once with a 2.x interpreter, and once with a 3.x
> interpreter (using
> http://stromberg.dnsalias.org/svn/this-pylint/trunk/this-pylint) , but
> I gather pylint has the option of running on a 2.x interpreter and
> warning about anything that wouldn't work on 3.x.
>

Pylint 1.4 has a --py3k flag to run only checks related to Python 3
compatibility under Python 2.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When do default parameters get their values set?

2014-12-11 Thread random832
On Wed, Dec 10, 2014, at 21:18, Rustom Mody wrote:
> But I have a different question -- can this be demonstrated without the
> 'is'?

Er, yeah. You can, for example, add an item to one of the dictionaries
and observe that it's not present in the other.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script isn't producing text in data file

2014-12-11 Thread Docfxit
On Thursday, December 11, 2014 1:32:02 AM UTC-8, Peter Otten wrote:
> Docfxit wrote:
> 
> > I don't know enough about Python to figure out how to isolate where the
> > problem is happening.
> 
> Can you get hold of the person who wrote the script?

No.  I tried.  They are not answering their email.

Thanks for the suggestion,

Docfxit
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Ben Finney
"Giampaolo Rodola'"  writes:

> I still think the only *real* obstacle remains the lack of important
> packages such as twisted, gevent and pika which haven't been ported
> yet.

What disqualifies other obstacles from being “*real* obstacles”? How do
you determine that?

> With those ones ported switching to Python 3 *right now* is not only
> possible and relatively easy, but also convenient.

If my program relies on an obscure library ‘foo’, and that library is
not ported to Python 3, switching to Python 3 is not feasible, and
certainly not convenient — regardless of the status of “important
packages such as twisted, gevent, and pika”.

So your assertion here is plainly false.

What is it you're actually wanting to say?

-- 
 \“Some people, when confronted with a problem, think ‘I know, |
  `\   I'll use regular expressions’. Now they have two problems.” |
_o__)   —Jamie Zawinski, in alt.religion.emacs |
Ben Finney

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


Re: is_ as method or property?

2014-12-11 Thread Ben Finney
Chris Angelico  writes:

> A property should be used if what you're creating is "virtually an
> attribute".

Methods are attributes. Are you distinguishing here between “callable
attribute” versus “non-callable attribute”?

-- 
 \   “Repetition leads to boredom, boredom to horrifying mistakes, |
  `\   horrifying mistakes to God-I-wish-I-was-still-bored, and it |
_o__)  goes downhill from there.” —Will Larson, 2008-11-04 |
Ben Finney

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


Re: is_ as method or property?

2014-12-11 Thread Devin Jeanpierre
On Thu, Dec 11, 2014 at 1:33 PM, Ben Finney  wrote:
> Chris Angelico  writes:
>
>> A property should be used if what you're creating is "virtually an
>> attribute".
>
> Methods are attributes. Are you distinguishing here between “callable
> attribute” versus “non-callable attribute”?

Obviously, yes.

-- Devin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is_ as method or property?

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 8:33 AM, Ben Finney  wrote:
> Chris Angelico  writes:
>
>> A property should be used if what you're creating is "virtually an
>> attribute".
>
> Methods are attributes. Are you distinguishing here between “callable
> attribute” versus “non-callable attribute”?

I'm talking conceptually here. You can, for instance, have a stat
object which has attribute for the file size and owner, and then it
makes equal sense to have an "is_dir" attribute; but that one might be
a property, calculated from the file mode. It makes logical design
sense for it to be an attribute with the value right there, so it
makes design sense for it to be a property. On the other hand, a
string will not normally have, as an attribute, a lower-case version
of itself, so it makes better sense for that to be a callable method
rather than a property.

Yes, properties and methods are attributes. That's a technical detail
that has nothing to do with the design question of "should this be a
property or a method".

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Ian Kelly
On Wed, Dec 10, 2014 at 9:01 PM, Steven D'Aprano 
wrote:
>
> On Wed, 10 Dec 2014 09:46:55 -0700, Ian Kelly wrote:
>
> > I don't particularly have a problem with functions having attributes,
> > e.g. I think itertools.chain.from_iterable is just peachy. There is a
> > downside though, which is that making those functions attributes of
> > another function rather than of the module defeats the dir() function
> > for that module.
>
> I think you are missing the point of namespaces :-)
>
> When I call dir(os), I see os.path, but I don't see the names in os.path.
> That is working as designed.

I don't think I'm missing the point. os.path is a module. That makes it
well suited for a namespace, because that's what modules are designed and
expected to provide: the implementation of namespaces. A function, on the
other hand, is not well suited to be a namespace, because it's not expected
to provide one. When I see a new function, I don't think "I should check
what attributes it has." Instead, I wonder about what parameters it takes
and what it returns.

I expect to be able to open up my web browser and go to the library
documentation for the os.path module. I don't expect to find a separate
page for statistics.median, because the docs are organized around modules,
not functions.  Would the median function itself be documented in the
statistics page, in the statistics.median page, or redundantly in both?

I expect to be able to import modules, and by extension, namespaces.
 "import os.path" works.  "import statistics.median.low" would return an
error, as would "from statistics.median import low as median", if that were
the only function I wanted. In the latter case I would have to do something
like "from statics import median; median = median.low". That's not just
ugly; it also demonstrates how the programmer needs to remember and
incorporate the detail that this namespace does not work like other
namespaces.

> As the designer of the module I thought that median_low and median_high
> were important enough to include but not important enough to stick in the
> main module namespace.

To me this sounds backward. Namespaces are a great idea, but at the same
time they also create cognitive burden. One creates a namespace because the
contents are important enough to be referenced as a group, not because they
aren't as important as the other things they're grouped with. The reason
the collections ABCs were moved into collections.abc wasn't because they
weren't important enough to be in the top-level collections module.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Victor Stinner
2014-12-11 15:47 GMT+01:00 Giampaolo Rodola' :
> I still think the only *real* obstacle remains the lack of important
> packages such as twisted, gevent and pika which haven't been ported yet.

twisted core works on python 3, right now. Contribute to Twisted if
you want to port more code... Or start something new, asyncio (with
trollius, it works on Python 2 too).

The develpoment branch of gevent supports Python 3, especially if you
dont use monkey patching. Ask the developers to release a version, at
least with "experimental" Python 3 support.

I don't know pika. I read "Pika Python AMQP Client Library". You may
take a look at https://github.com/dzen/aioamqp if you would like to
play with asyncio.

> With those ones ported switching to Python 3 *right now* is not only
> possible and relatively easy, but also convenient.

 Victor
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Do you like the current design of python.org?

2014-12-11 Thread Ned Deily
Just a gentle reminder that any problems seen with or changes desired to 
the python.org website need to be documented on its issue tracker at 
https://github.com/python/pythondotorg/issues/.  Key players working on 
it likely are not aware of discussions here.

-- 
 Ned Deily,
 n...@acm.org

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


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Barry Warsaw
On Dec 11, 2014, at 11:35 AM, Mark Roberts wrote:

>I disagree. I know there's a huge focus on The Big Libraries (and wholesale
>migration is all but impossible without them), but the long tail of
>libraries is still incredibly important.

It is, but I think it's increasingly the case that packages which don't
support Python 3 will either be shamed into it, important enough to get high
quality contributed ports, or will be effectively abandoned and alternatives
found.  This is a big change from where we were several years ago.

All my new $work code is Python 3.  Some libraries are bilingual but
applications start and stay in Python 3-only.

Just recently the last two dependencies in Mailman 3 that blocked us from
beginning the port to Python 3 have been replaced[1].  We have active branches
that are slowly porting own code now[2].

While we can't quite declare victory yet, and there will always be legacy code
for which there just aren't the resources to port, I think it's perfectly
reasonable for Python 3 to be the default target version for any new code (and
a lot of existing code).

Cheers,
-Barry

[1] SQLAlchemy replaced Storm, and Falcon replaced restish in our trunk.

[2] https://code.launchpad.net/~barry/mailman/py3 and
https://code.launchpad.net/~raj-abhilash1/mailman/py3


pgpsEg8uVRAi1.pgp
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When do default parameters get their values set?

2014-12-11 Thread Steven D'Aprano
Chris Kaynor wrote:

> On Wed, Dec 10, 2014 at 7:15 PM, Steven D'Aprano 
> wrote:

>> Using "is" you are demonstrating that calling the function twice returns
>> two distinct objects. That is the purpose of "is", to compare object
>> identity. Without "is", you can compare object IDs directly:
>>
>> id(f()()) == id(f()())
>>
>> but that's ugly and less efficient. Using "is" is the more idiomatic and
>> natural way to do this.
>>
> 
> In CPython, that does not work, as the dictionary will be garbage
> collected after each call to id:
 f = lambda : (lambda x= {}: x)
 f()() is f()()
> False
 id(f()()) == id(f()())
> True


Nice catch! Thank you for the correction.



-- 
Steven

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


Re: How to detect that a function argument is the default one

2014-12-11 Thread Ben Finney
Tony the Tiger  writes:

> radius='10', mass='1'
>
> if radius == '10' ...
>
> if mass == '1' ...

This ignores the problem as stated: The OP wants to distinguish between
a value that was explicitly set by the caller, versus a value that was
set by default because the caller did not specify the parameter.

The general solution to this is to choose a value outside the domain, a
https://en.wikipedia.org/wiki/Sentinel_value> which is different
from any value the caller would choose for that parameter.

Often, the Python singleton ‘None’ is good for the purpose. I think in
this case, where the domain is numeric, a default of ‘None’ would do
fine.

class Foo:
def __init__(centre=(0, 0), radius=None, mass=None):
if radius is None:
# Caller didn't specify. Set a default value.
radius = 10
if mass is None:
# Caller didn't specify. Set a default value.
mass = 1
self.centre = centre
self.radius = radius
self.mass = mass

In some other cases, ‘None’ is a valid value for the caller to set, and
so cannot be used as a sentinel to distinguish the default. For those
cases, creating a specific object instance to serve as the sentinel is
simple and clear:

class Foo:

_SENTINEL = object()

def __init__(centre=(0, 0), radius=_SENTINEL, mass=_SENTINEL):
if radius is _SENTINEL:
# Caller didn't specify. Set a default value.
radius = 10
if mass is _SENTINEL:
# Caller didn't specify. Set a default value.
mass = 1
self.centre = centre
self.radius = radius
self.mass = mass

Creating a new object specifically for the sentinel means there is no
chance some other value will compare identical. Choosing a
leading-underscore name indicates to the reader that this is not part of
the public API.

-- 
 \“Odious ideas are not entitled to hide from criticism behind |
  `\   the human shield of their believers' feelings.” —Richard M. |
_o__) Stallman |
Ben Finney

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


Re: Problem with a dialog

2014-12-11 Thread Steven D'Aprano
ast wrote:


> Since try() is a callback function called when a button is pushed,
> with the effect to open a dialog, I tried to define MyDialog class
> inside try(). The program is the following and it works. I no
> longer need to define test as global.
> Is it a good practice to define a class inside a function ?

Your question is too general. It *can* be good practice, or it can be bad
practice.

Classes are "first class values" (pun not intended) in Python, which means
you can pass them to functions and you can generate them on the fly and
return them from functions too. There is a downside to that: classes are
fairly hefty objects compared to instances, so if every time you call a
function you create an instance of a brand new class instead of re-using
the same class, your memory consumption will be much higher.

In your case, it probably doesn't matter: you only create a single MyDialog
instance, so it shouldn't matter that the class is created dynamically
inside the function. But I'm going to suggest a more object oriented
solution that avoids the local/global scoping issue completely:

* Make test an attribute of MyDialog (what some other languages 
  call "an instance variable").


from tkinter import *
import tkinter.simpledialog

class MyDialog(tkinter.simpledialog.Dialog):
test = True
def body(self, master):
print(self.test)
def apply(self):
pass


def try_():
setup = MyDialog(root)
 
root = Tk()
try_()



Technically, what I have done here is make "test" a class attribute, that
is, it will be shared by all MyDialog instances. But since there is only
one instance, that doesn't matter.

Another approach is to forgo the line "test = True" inside the class, and
set a per-instance attribute when the instance is created. Add this method
to the class:

def __init__(self):
self.test = True


Generally speaking, the __init__ method approach is more common.





-- 
Steven

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


Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Steven D'Aprano
Ian Kelly wrote:

> A function, on the
> other hand, is not well suited to be a namespace, because it's not
> expected to provide one.


And that is exactly the point I am making about the inherent
conservativeness of Python developers.

Functions ARE namespaces, like instances of user-defined classes they have a
__dict__ and can carry per-instance state. (If you think that only modules
are namespaces, you are badly mistaken. Instances are namespaces too.) This
is *not* an accident of implementation, it is a deliberate design choice.
Contrast functions with builtin functions:

py> def f(): pass
...
py> vars(f)
{}
py> vars(len)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: vars() argument must have __dict__ attribute


Although functions are written in pure Python, their type is implemented in
C and could easily have been designed to be __dict__-less just like the
builtin_function_or_method type. But they weren't. It is a language feature
that functions are namespaces.

So why don't we use functions as namespaces?

We don't use functions as namespaces because nobody thinks of them as
namespaces, and we don't think of them as namespaces because nobody uses
them as namespaces -- and when somebody tries to break out of that vicious
circle, the conservativeness kicks in and the very idea is rejected.

I think that there is a legitimate debate to be had as to whether this
conservativeness and resistance to change is a good thing or a bad thing,
but I don't think that there should be any debate about the reality of the
Python community being strongly conservative, compared to the "anything
goes" attitude of (say) Ruby, Perl and Lisp programmers. We don't like code
that does anything we haven't seen a hundred times before.



-- 
Steven

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


Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Ian Kelly
On Thu, Dec 11, 2014 at 4:28 PM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:
>
> Ian Kelly wrote:
>
> > A function, on the
> > other hand, is not well suited to be a namespace, because it's not
> > expected to provide one.
>
>
> And that is exactly the point I am making about the inherent
> conservativeness of Python developers.
>
> Functions ARE namespaces, like instances of user-defined classes they
have a
> __dict__ and can carry per-instance state. (If you think that only modules
> are namespaces, you are badly mistaken. Instances are namespaces too.)

I never said that functions can't be used as namespaces. I said that
functions are *bad* namespaces, and I gave reasons why I think this is true.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 10:28 AM, Steven D'Aprano
 wrote:
> I think that there is a legitimate debate to be had as to whether this
> conservativeness and resistance to change is a good thing or a bad thing,
> but I don't think that there should be any debate about the reality of the
> Python community being strongly conservative, compared to the "anything
> goes" attitude of (say) Ruby, Perl and Lisp programmers. We don't like code
> that does anything we haven't seen a hundred times before.

I agree that Python is a lot more conservative than many languages,
and personally, I think it's good. When it comes to monkeypatching,
less is *definitely* better - less places where you have to figure out
what import changed the meanings of your built-ins, and so on. (Case
in point: A logger replacement tampered with the
log.info()/log.error() family of functions, adding a keyword
parameter. Took me a fair amount of digging to find out exactly where
that happened, and it made REPL importing of the module's functions
rather awkward.) The same is true of obscure namespaces, specifically
because they're obscure; if I do a JSON decode of something, I'm not
going to check to see if numbers came through as a subclass of float
with a ".warnings" attribute to tell me about loss of numeric
precision, even though that would be perfectly possible. Since almost
nobody does this, nobody will expect it to be done, ergo nobody will
go looking for it, and the feature may as well not even have been
implemented if it's never seen. Popularity *is* sometimes a legitimate
argument.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Do you like the current design of python.org?

2014-12-11 Thread Cameron Simpson

On 11Dec2014 00:19, Ian Kelly  wrote:

On Tue, Dec 9, 2014 at 10:16 PM, Cameron Simpson  wrote:

 - the AA menu buttons are all dysfunctional, being purely javascript; it

would be better if the menu was styled "display=none" by default, and made
visible by javascript

With Javascript enabled, the AA menu buttons don't seem to be displayed at
all, so I don't understand what the purpose of those is.


The point is more that with javascript disabled, the buttons are displayed and 
nonfunctional.



There are also the disappointingly common placeholder characters in

various place, for example to the left of each item in the "Socialize"
menu. These look like this:


 
http://plus.google.com/+Python";>Google+

I don't know what you mean. Are you saying that you see unrendered HTML to
the left of the items? All I see are icons.


Along with javascript, the NoScript extension blocks various untrusted objects.  
Those icons come from a loadable font, which was blocked. If I allow the font 
to load I get icons. You can imagine the abuse a font load can be used for, 
such as "I can't unsee that!" icon characters or better still, character 
transliteration for malicious purpose (we rely on the visual appearance of 
glyphs to be what we expect).


Cheers,
Cameron Simpson 

If people were meant to run around naked, they'd have been born that way.
   - Rico the Masher, bphei...@ucsvax.ucs.umass.edu
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Script to convert firewall rules

2014-12-11 Thread Jason Friedman
> I am network engineer and not expert in programming. I would like to make
> one python script to convert juniper netscreen firewall configuration into
> juniper SRX firewall configuration.
>

Looks pretty tricky, do you have a specification for each format containing
all the possible keywords/values?

If you could describe the logic in English then writing the equivalent in
Python would be straightforward for many people on this list.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Roy Smith
In article ,
 Ian Kelly  wrote:

> I never said that functions can't be used as namespaces. I said that
> functions are *bad* namespaces, and I gave reasons why I think this is true.

An excellent example of functions acting as namespaces is nosetest's 
@attr() decorator.  We use this, for example, to tag certain test cases 
as being reliant on facebook being up(*):

@attr('facebook', 'services')
def test_some_facebook_thing():
# whatever

this lets us turn all those tests on or off with a single switch.  The 
way @attr() is implemented, it sets attributes on the decorated 
function.  It's the most logical and obvious place to store a piece of 
information about a test case -- right on the test case itself.

Similarly, we've got tests that we annotate as being dependent on itunes 
being reachable, depending on certain data existing in the database(**), 
being too slow to want to run all the time(**), etc.

(*) and please don't tell me that tests shouldn't depend on external 
services.

(**) see first footnote
-- 
https://mail.python.org/mailman/listinfo/python-list


beautifulsoup VS lxml

2014-12-11 Thread iMath

which is more easy and elegant for pulling data  out of HTML?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: beautifulsoup VS lxml

2014-12-11 Thread Michael Torrie
On 12/11/2014 07:02 PM, iMath wrote:
> 
> which is more easy and elegant for pulling data  out of HTML?

Beautiful Soup is specialized for HTML parsing, and it can deal with
badly formed HTML, but if I recall correctly BeautifulSoup can use the
lxml engine under the hood, so maybe it's the way to go for you, is it
gives you the most flexibility.  It certainly has a good API that's easy
to use for data scraping.  Try it and see if it's acceptable.

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


Extension of while syntax

2014-12-11 Thread Nelson Crosby
I was thinking a bit about the following pattern:

value = get_some_value()
while value in undesired_values:
value = get_some_value()

I've always hated code that looks like this. Partly due to the repetition, but 
partly also due to the fact that without being able to immediately recognise 
this pattern, it isn't very readable.

Python already has one-line syntaxes (e.g. list comprehensions), I was 
wondering what people thought about a similar thing with while. It might look 
something like:

value = get_some_value() while value in undesired_values()

Perhaps not this exact syntax though, as the parser might try to do `value = 
(get_some_value() while...)` instead of `(value = get_some_value) while...`.

Other languages have features which allow something to look slightly less like 
this pattern, e.g. Java:

SomeType value;
while ((/* The assignment */ value = getSomeValue()) /* Compare */ == 
undesired_value) {}

Granted, this isn't exactly tidy, but it's a little more DRY and, IMO, 
preferable.

What are other's thoughts on this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extension of while syntax

2014-12-11 Thread Ben Finney
Nelson Crosby  writes:

> I was thinking a bit about the following pattern:
>
> value = get_some_value()
> while value in undesired_values:
> value = get_some_value()

I think that's an anti-pattern (because of the repetition, as you say).

An improvement::

value = some_default_value_such_as_None
while value in undesired_values:
value = get_some_value()

More common and generally useful::

while True:
value = get_some_value()
if value not in undesired_values:
break

> What are other's thoughts on this?

I think there are already clean ways to deal with this in common use.

https://wiki.python.org/moin/WhileLoop>
https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops>

-- 
 \   “… one of the main causes of the fall of the Roman Empire was |
  `\that, lacking zero, they had no way to indicate successful |
_o__)  termination of their C programs.” —Robert Firth |
Ben Finney

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


Re: Extension of while syntax

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 1:21 PM, Nelson Crosby  wrote:
> I was thinking a bit about the following pattern:
>
> value = get_some_value()
> while value in undesired_values:
> value = get_some_value()
>
> I've always hated code that looks like this. Partly due to the repetition, 
> but partly also due to the fact that without being able to immediately 
> recognise this pattern, it isn't very readable.
>
> Python already has one-line syntaxes (e.g. list comprehensions), I was 
> wondering what people thought about a similar thing with while. It might look 
> something like:

You could deduplicate it by shifting the condition:

while True:
value = get_some_value()
if value not in undesired_values: break

But I'm not sure how common this idiom actually is. Usually I'd modify
it, maybe with an iteration limit, or possibly some kind of prompt to
the human. Do you really have this perfectly pure form?

You could rework it to use filter(). I'm not sure that this is in any
way better code, but it is different...

>>> def get_some_value():
return int(input("Enter a value: "))
>>> undesired_values = {1, 2, 3}
>>> next(filter(lambda x: x not in undesired_values, iter(get_some_value, 
>>> object(
Enter a value: 3
Enter a value: 1
Enter a value: 2
Enter a value: 1
Enter a value: 3
Enter a value: 1
Enter a value: 2
Enter a value: 7
7
>>>

Look, ma! No duplication!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-11 Thread Terry Reedy

On 12/10/2014 5:04 PM, Bruno Cauet wrote:

I hesitated a while before deciding not to include it! Apart from python
core development what would be the reasons to work mostly on this version ?


where 'This version' == 3.5.  A possible reason: one is developing an 
app expected to be released fall 2015 after the 3.5 release and the app 
depends on something new in 3.5.  I must admit though that I cannot 
think of any such thing now for 3.5.  For 3.3 there was the new unicode, 
which was first committed about a year before release.  For 3.4, there 
was asyncio, but it was not committed until beta1, and was hardly usable 
then.


So it was a defensible position.  Anyone who would check 3.5 could just 
as well check 3.4 and have most of the same impact on the summary.


--
Terry Jan Reedy

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


RE: Extension of while syntax

2014-12-11 Thread Clayton Kirkwood
I would prefer:
while value = initial_value in undesired_values:
value = get_some_value()

Seems I've seen something like this before, C, Perl?

Clayton


>-Original Message-
>From: Python-list [mailto:python-list-
>bounces+crk=godblessthe...@python.org] On Behalf Of Ben Finney
>Sent: Thursday, December 11, 2014 6:38 PM
>To: python-list@python.org
>Subject: Re: Extension of while syntax
>
>Nelson Crosby  writes:
>
>> I was thinking a bit about the following pattern:
>>
>> value = get_some_value()
>> while value in undesired_values:
>> value = get_some_value()
>
>I think that's an anti-pattern (because of the repetition, as you say).
>
>An improvement::
>
>value = some_default_value_such_as_None
>while value in undesired_values:
>value = get_some_value()
>
>More common and generally useful::
>
>while True:
>value = get_some_value()
>if value not in undesired_values:
>break
>
>> What are other's thoughts on this?
>
>I think there are already clean ways to deal with this in common use.
>
>https://wiki.python.org/moin/WhileLoop>
>https://docs.python.org/3/tutorial/controlflow.html#break-and-
>continue-statements-and-else-clauses-on-loops>
>
>--
> \   “… one of the main causes of the fall of the Roman Empire was |
>  `\that, lacking zero, they had no way to indicate successful |
>_o__)  termination of their C programs.” —Robert Firth |
>Ben Finney
>
>--
>https://mail.python.org/mailman/listinfo/python-list


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


Re: Extension of while syntax

2014-12-11 Thread Terry Reedy

On 12/11/2014 9:21 PM, Nelson Crosby wrote:

I was thinking a bit about the following pattern:

value = get_some_value()
while value in undesired_values:
 value = get_some_value()


This is do_while or do_until.  In Python, write it as do_until in this form.

while True:
value = get_some_value()
if value not in undesired_values:
break


I've always hated code that looks like this. Partly due to the repetition,
but partly also due to the fact that without being able to immediately

> recognise this pattern, it isn't very readable.

The repetitiion is easily eliminated.


value = get_some_value() while value in undesired_values()


Forget this, or anything like it, as a 'serious' proposal.

--
Terry Jan Reedy

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


Re: Extension of while syntax

2014-12-11 Thread Ben Finney
(Please don't top-post; instead, interleave responses inline with the
quoted material and trim the excess. See
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style>.)

"Clayton Kirkwood"  writes:

> I would prefer:
> while value = initial_value in undesired_values:
> value = get_some_value()

The easy confusion between ‘=’ and ‘==’ in a condition is sufficient
that Python doesn't allow the ‘=’ operation in an expression.

I think that the subtle errors avoided by that is worth the loss of
expressions like the above.

-- 
 \  “Pity the meek, for they shall inherit the earth.” —Donald |
  `\  Robert Perry Marquis |
_o__)  |
Ben Finney

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


Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor

2014-12-11 Thread iMath
在 2014年12月11日星期四UTC+8下午1时25分41秒,Michael Torrie写道:
> On 12/10/2014 09:52 PM, iMath wrote:
> > I think the user interface shouldn't be freezed when using
> > concurrent.futures.ThreadPoolExecutor here,as it executes
> > asynchronously , but it doesn't meet my expectations,anyone can
> > explain why ? any other solutions here to not let user interface
> > freezed?
> > 
> > code is here 
> > http://stackoverflow.com/questions/27393533/user-interface-freezed-when-using-concurrent-futures-threadpoolexecutor
> 
> In most any GUI framework, regardless of your use of threads, your
> callbacks must return control to the main loop immediately (whether an
> on-click or an on-timer event), or the GUI *will* freeze.
> 
> You are spawning threads to download the urls, then sitting there
> waiting for them to finish in the callback.  Of course the GUI will
> freeze; your callback is blocking it.  What you should be doing is
> spawning the threads to do the download, then have the threads (using a
> proper QThread mechanism or some other semaphore mechanism) raise a
> signal to indicate they are done, which you will then catch in the main
> loop as a normal callback.  And really when it comes to I/O and GUIs,
> asynchronous calls are always better than threads.  Not sure what Qt has
> in the way of asynchronous i/o calls, and I'm not familiar enough with
> the various async i/o frameworks in Python to speak to that, though I
> did use Python-Twisted once... very powerful once you get your head
> wrapped around it.
> 
> Look through the list archives because in the last 3 or 4 weeks I and
> another Python user talked proper thread use with PyQt or PySide, with
> code examples.

"when it comes to I/O and GUIs, asynchronous calls are always better than 
threads."

I cannot grasp your meaning here, IMO, asynchronous calls are done by using 
threads.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor

2014-12-11 Thread Michael Torrie
On 12/11/2014 08:20 PM, iMath wrote:
> 在 2014年12月11日星期四UTC+8下午1时25分41秒,Michael Torrie写道:
>> On 12/10/2014 09:52 PM, iMath wrote:
> "when it comes to I/O and GUIs, asynchronous calls are always better than 
> threads."
> 
> I cannot grasp your meaning here, IMO, asynchronous calls are done by using 
> threads.

Not in your code.  All your I/O calls are synchronous; they block until
they are finished.  But if you mean that calling synchronous calls while
in a thread has a similar effect to an asynchronous call, you are
correct.  But the way you're waiting for the threads to finish, you're
blocking your gui.

An asynchronous API lets you start long-running I/O calls and define a
function that is automatically called upon completion.  In other words
it's event-driven.  Qt may provide everything you need already in an
asynchronous form.  Check the docs. And use google.  Here's a link I
found from a google search that illustrates how to fetch a url in Qt
using an asynchronous method.  You could fire off as many of these as
you want, then just wait for signals.

http://qt-project.org/wiki/Download_Data_from_URL


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


list comprehension return a list and sum over in loop

2014-12-11 Thread KK Sasa
Hi there,

The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 
is a function returning a list, say [x1,x2,x3,x4] for one example. So "results" 
is a list consisting of 1000 lists, each of length four. Here, what I want to 
get is the sum of 1000 lists, and then the result is a list of length four. Is 
there any efficient way to do this? Because I found it is slow in my case. I 
tried sum(d2(t[k]) for k in xrange(1000)), but it returned error: TypeError: 
unsupported operand type(s) for +: 'int' and 'list'. Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extension of while syntax

2014-12-11 Thread Marko Rauhamaa
Chris Angelico :

> You could deduplicate it by shifting the condition:
>
> while True:
> value = get_some_value()
> if value not in undesired_values: break
>
> But I'm not sure how common this idiom actually is.

Extremely common, and not only in Python.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: list comprehension return a list and sum over in loop

2014-12-11 Thread Mark Lawrence

On 12/12/2014 06:22, KK Sasa wrote:

Hi there,

The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a 
function returning a list, say [x1,x2,x3,x4] for one example. So "results" is a 
list consisting of 1000 lists, each of length four. Here, what I want to get is the sum 
of 1000 lists, and then the result is a list of length four. Is there any efficient way 
to do this? Because I found it is slow in my case. I tried sum(d2(t[k]) for k in 
xrange(1000)), but it returned error: TypeError: unsupported operand type(s) for +: 'int' 
and 'list'. Thanks.



I think you need something like this 
http://stackoverflow.com/questions/19339/a-transpose-unzip-function-in-python-inverse-of-zip


I'll let you add the finishing touches if I'm correct :)

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor

2014-12-11 Thread Marko Rauhamaa
Michael Torrie :

> An asynchronous API lets you start long-running I/O calls and define a
> function that is automatically called upon completion. In other words
> it's event-driven. Qt may provide everything you need already in an
> asynchronous form.

GUI developers have been doing event-driven programming for decades.
That's an excellent preparation for network programming as well.
Unfortunately, the minds of a generation of programmers were
contaminated by the thread craze of the 1990's (Java and Windows NT).


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Ian Kelly
On Thu, Dec 11, 2014 at 6:55 PM, Roy Smith  wrote:
>
> In article ,
>  Ian Kelly  wrote:
>
> > I never said that functions can't be used as namespaces. I said that
> > functions are *bad* namespaces, and I gave reasons why I think this is
true.
>
> An excellent example of functions acting as namespaces is nosetest's
> @attr() decorator.  We use this, for example, to tag certain test cases
> as being reliant on facebook being up(*):
>
> @attr('facebook', 'services')
> def test_some_facebook_thing():
> # whatever
>
> this lets us turn all those tests on or off with a single switch.  The
> way @attr() is implemented, it sets attributes on the decorated
> function.  It's the most logical and obvious place to store a piece of
> information about a test case -- right on the test case itself.

I agree this is a great use of function attributes, but this is an example
of tags or annotations, not namespaces. The purpose of namespaces is to
distinguish between different entities of the same name, e.g. 'pow' and
'math.pow' are two distinct functions that both happen to be named pow. We
can tell them apart because they're in separate namespaces.

In the nosetest example, the 'facebook' attribute always means the same
thing no matter which functions you apply it to. Conceptually speaking,
each instance of the attribute is the same annotation. The expression
test_some_facebook_thing.facebook doesn't perform the role of a namespace
because it's used to signify the presence of that annotation, not to
identify something.

A similar example from the standard library is the functools.lru_cache
decorator, which adds a cache_info function to the wrapped function.
However, the cache_info function always performs the same task in relation
to the particular function it decorates, so in this regard it acts more
like an object method than like a name in a namespace.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extension of while syntax

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 6:10 PM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> You could deduplicate it by shifting the condition:
>>
>> while True:
>> value = get_some_value()
>> if value not in undesired_values: break
>>
>> But I'm not sure how common this idiom actually is.
>
> Extremely common, and not only in Python.

Something like it is certainly common, but to justify dedicated
syntax, the pure form has to be so amazingly common as to merit it. As
soon as you modify the pure form in any way, you need the statement
form, for full flexibility.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 6:18 PM, Marko Rauhamaa  wrote:
> GUI developers have been doing event-driven programming for decades.
> That's an excellent preparation for network programming as well.
> Unfortunately, the minds of a generation of programmers were
> contaminated by the thread craze of the 1990's (Java and Windows NT).

Threads predate Java and NT, and with a much MUCH better
implementation, on OS/2. I don't consider my mind to have been
*contaminated* by the OS/2 threading model, which worked superbly.
Like all models, it has its limitations, but it's one worth getting
your head around IMO. Knowing when to use threads, when to use
processes, and when to keep everything in a single thread with some
kind of dispatch loop (and *which* dispatch loop) is a valuable skill.

But yes, the Windows threading model does have a number of annoying
flaws. And I don't remember how Java did things, except that I
struggled to find basic fundamental primitives like semaphores, and
had to use synchronized functions/objects instead.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Fatal Python error: PyCOND_WAIT(gil_cond) failed

2014-12-11 Thread keepplearningpython
Hi,
I am running ipython3 on Unix and constantly see this crash -
It happens when i try to issue commands on the ipython interactive shell.

I have tried to set the PYTHONDIR to /var/tmp/ in case there was an issue 
accessing the default location of the history file. However, this makes no 
difference.

I can run a command a few times successfully after which I hit this error.

This is my python version info 


Python 3.3.2 (default, Nov 14 2014, 12:28:17)
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help  -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.


Any suggestions on what might be going on?




Fatal Python error: PyCOND_WAIT(gil_cond) failed

Thread 0x088e8900:
  File "/opt/jde/lib/python3.3/site-packages/IPython/core/history.py", line 664 
in _writeout_input_cache
  File "/opt/jde/lib/python3.3/site-packages/IPython/core/history.py", line 680 
in writeout_cache
  File "/opt/jde/lib/python3.3/site-packages/IPython/core/history.py", line 65 
in needs_sqlite
  File "", line 2 in writeout_cache
  File "/opt/jde/lib/python3.3/site-packages/IPython/core/history.py", line 733 
in run
  File "/opt/jde/lib/python3.3/site-packages/IPython/core/history.py", line 65 
in needs_sqlite
  File "", line 2 in run
  File "/opt/jde/lib/python3.3/threading.py", line 637 in _bootstrap_inner
  File "/opt/jde/lib/python3.3/threading.py", line 614 in _bootstrap

Current thread 0x0804b000:
  File "/opt/jde/lib/python3.3/logging/__init__.py", line 940 in emit
  File "/opt/jde/lib/python3.3/logging/__init__.py", line 833 in handle
  File "/opt/jde/lib/python3.3/logging/__init__.py", line 1439 in callHandlers
  File "/opt/jde/lib/python3.3/logging/__init__.py", line 1377 in handle
  File "/opt/jde/lib/python3.3/logging/__init__.py", line 1367 in _log
  File "/opt/jde/lib/python3.3/logging/__init__.py", line 1232 in info
  File "/var/root/diags/src/lib/python/jde/jde/Model.py", line 644 in show
  File "", line 1 in 
  File "/opt/jde/lib/python3.3/site-packages/IPython/core/interactiveshell.py", 
line 2828 in run_code
  File "/opt/jde/lib/python3.3/site-packages/IPython/core/interactiveshell.py", 
line 2778 in run_ast_nodes
  File "/opt/jde/lib/python3.3/site-packages/IPython/core/interactiveshell.py", 
line 2668 in run_cell
  File 
"/opt/jde/lib/python3.3/site-packages/IPython/terminal/interactiveshell.py", 
line 555 in interact
  File 
"/opt/jde/lib/python3.3/site-packages/IPython/terminal/interactiveshell.py", 
line 436 in mainloop
  File "/opt/jde/lib/python3.3/site-packages/IPython/terminal/ipapp.py", line 
362 in start
  File "/opt/jde/lib/python3.3/site-packages/IPython/config/application.py", 
line 545 in launch_instance
  File "/opt/jde/lib/python3.3/site-packages/IPython/__init__.py", line 118 in 
start_ipython
  File "/opt/jde/bin/ipython3", line 6 in 
Abort (core dumped)

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


Re: Python Script to convert firewall rules

2014-12-11 Thread Kashif Rana
Hi Jason

Thanks for the reply. Yes I can make the all possible keywords/values for both 
formate. But after that what gonna be the logic to convert one format to other 
format. Like to convert one line below are the keywords:

set interface ethernet2/5 ip 10.17.10.1/24 (format 1)
set interfaces ge-0/0/0 unit 0 family inet address 10.17.10.1/24 (format 2)

(set, interface, ip) = (set, interfaces, family inet address)

But some values are variable and should ask the user to convert manually like 
ethernet2/5 equal to ge-0/0/0 or ge-0/0/1 or ge-0/0/2

And some values keep as it is like 10.17.10.1/24 

Also then format 2 can be converted int o format 3 (as below) for more 
readability of format 2. This is just optional. 

interfaces {  
ge-2/0/5 { 
unit 0 { 
family inet { 
address 10.17.10.1/24; 
} 
} 
} 
}

On Friday, December 12, 2014 5:45:20 AM UTC+4, Jason Friedman wrote:
> I am network engineer and not expert in programming. I would like to make one 
> python script to convert juniper netscreen firewall configuration into 
> juniper SRX firewall configuration.
> 
> 
> 
> Looks pretty tricky, do you have a specification for each format containing 
> all the possible keywords/values?
> 
> 
> If you could describe the logic in English then writing the equivalent in 
> Python would be straightforward for many people on this list.
-- 
https://mail.python.org/mailman/listinfo/python-list