Re: Error handling with @parallel decorator

2016-01-17 Thread Steven D'Aprano
On Monday 18 January 2016 17:15, Ankur Agrawal wrote:

> I am trying to catch Abort exception. When I use fabric's run(...) method,
> the host it tries to connect is not available and so it aborts with
> connect time out exception. I am not able to catch it. Following is a two
> different ways of code snippet-
> First I try following  -
> 
> class FabricException(Exception):
> pass
> 
> with settings(abort_exception = FabricException):
> 
> try:
> output = run(command)
> except FabricException:
> print 'inside exception'
> LOG.debug("inside exception")
> 
> It didn't go in exception block. Instead it threw -
> NetworkError: Timed out trying to connect to pqaltsnas300.corp.intuit.net
> (tried 1 time)
> Aborting.
> SystemExit: 1

Are you sure that the exception is being raised where you think it is being 
raised? You think that it is being raised by run(command), but it is 
possible that the exception is occurring somewhere else?

Don't catch the exception at all, and read the *entire* traceback. It will 
show you what line is raising the error.

Then, surround that line with:

try:
the line that fails
except Exception as err:
print err
print type(err)
LOG.debug(err)
raise

This will tell you exactly what the exception type actually is. Perhaps you 
are trying to catch the wrong thing.

VERY IMPORTANT: catching all exceptions in this way should nearly always 
only be used for debugging purposes. Don't do that in production.

https://realpython.com/blog/python/the-most-diabolical-python-antipattern/




-- 
Steve

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


Error handling with @parallel decorator

2016-01-17 Thread Ankur Agrawal
I am trying to catch Abort exception. When I use fabric's run(...) method,
the host it tries to connect is not available and so it aborts with connect
time out exception. I am not able to catch it. Following is a two different
ways of code snippet-
First I try following  -

class FabricException(Exception):
pass

with settings(abort_exception = FabricException):

try:
output = run(command)
except FabricException:
print 'inside exception'
LOG.debug("inside exception")

It didn't go in exception block. Instead it threw -
NetworkError: Timed out trying to connect to pqaltsnas300.corp.intuit.net
(tried 1 time)
Aborting.
SystemExit: 1

Then I try to continue even if exception -
command  = 'ls -l'
with settings(warn_only = True):
  output = run(command)

Still it threw the same exception
NetworkError: Timed out trying to connect to pqaltsnas300.corp.intuit.net
(tried 1 time)
Aborting.
SystemExit: 1

Appreciate if somebody tell if I am missing anything ?

Thanks,
Ankur
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ERROR: IDLEs subprocesses did not make a connection...

2016-01-17 Thread Terry Reedy

On 1/14/2016 12:42 PM, Lee, Brandon wrote:

Hello!

I am running into the following error and need some guidance.


I summarized at
https://bugs.python.org/issue25514#msg258498
the reasons listed in the SO page you linked and another linked on that 
page.  Running through the list is your job.


> Please see the screenshots of the error,
> the files I currently have in the /python directory.

This is a text-only, no attachment mailing list.  Attachments become 
useless 'cid' links that open a blank page.


--
Terry Jan Reedy

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


Re: "x == None" vs "x is None"

2016-01-17 Thread Ben Finney
 writes:

> I prefer (x is None) and (x is not None).

There are good reasons to prefer this.

But this is not a good reason:

> This matches the SQL concept of NULL.

That's not really helpful, because it *doesn't* match.

> (X = NULL) is not valid since NULL is not a value and cannot be
> compared with anything.

SQL Null fails comparison with any value. Python ``None`` is a value and
can be compared like any other value.

SQL Null is neither truthy nor falsy; three-value logic is required when
Null can occur. Python ``None`` is falsy by definition, and two-value
(Boolean) logic continues to obtain.

SQL Null is not a value and has no data type. Python ``None`` is an
object and, like any other object, has a type defining the operations
that it can perform.

And so on. While some libraries do conflate SQL Null with Python
``None``, the two concepts really behave quite differently. It is
needlessly misleading to say they “match” in any sense.

I'm in the camp that says, while SQL is quite useful, its NULL is a wart
https://dba.stackexchange.com/questions/5222/why-shouldnt-we-allow-nulls/6049>.

-- 
 \“… it's best to confuse only one issue at a time.” —Brian W. |
  `\Kernighan and Dennis M. Ritchie, _The C programming language_, |
_o__) 1988 |
Ben Finney

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


Re: how do I put the python on my desktop or even access it

2016-01-17 Thread eryk sun
On Sun, Jan 17, 2016 at 6:05 PM, Michael Torrie  wrote:
> On 01/17/2016 02:46 PM, eryk sun wrote:
>> On Sun, Jan 17, 2016 at 9:03 AM, Michael Torrie  wrote:
>>>
>>> but if it's a text-mode program you must run it from cmd.exe like this:
>>>
>>> python \path\to\myprogram.py.
>>
>> You only need to run from another console program to keep the window
>> open after Python exits. You can even do that in other ways, but doing
>> that is more complicated than it is useful.
>
> Yes, but then we'll get the OP posting to ask why his python program
> doesn't run. When he double-clicks his Py file it pops up briefly then
> disappears! (Unless the code waits for user input of course).

I was attempting to clarify the language that one "must run it from
cmd.exe". This only needs to be done if you need to keep the window
open after a console program has exited. Also, it doesn't have to be
cmd.exe. You can use powershell.exe, bash.exe, another instance of
python.exe, etc -- any console program that lets you start a child
process and wait for it to exit.

>> BTW, each console window is hosted by an instance of conhost.exe.
>> There's nothing special about cmd.exe with respect to the console.
>
> Of course, but I doubt very many people know about conhost.exe.  And
> conhost.exe is rather useless in and of itself unless you have something
> to run on it.  Thus the usual way to get a console window that you can
> actually work with is to run cmd.exe.  I seriously doubt you would tell
> a newbie to somehow use conhost.exe to run his program.

I often come across even experienced Windows programmers on Stack
Overflow who somehow have drawn the conclusion that cmd.exe *is the
console*. I take whatever opportunity I can get to correct this
misunderstanding with a little FYI note.

For a newbie, I would of course suggest IDLE. I may also suggest
changing the shebang to "#!python3 -i" while debugging a script. They
can double-click on the script's icon to run it, and after it's done
executing or if there's an unhandled exception, they can inspect the
result in the REPL.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how do I put the python on my desktop or even access it

2016-01-17 Thread Michael Torrie
On 01/17/2016 02:46 PM, eryk sun wrote:
> On Sun, Jan 17, 2016 at 9:03 AM, Michael Torrie  wrote:
>>
>> but if it's a text-mode program you must run it from cmd.exe like this:
>>
>> python \path\to\myprogram.py.
> 
> You only need to run from another console program to keep the window
> open after Python exits. You can even do that in other ways, but doing
> that is more complicated than it is useful.

Yes, but then we'll get the OP posting to ask why his python program
doesn't run. When he double-clicks his Py file it pops up briefly then
disappears! (Unless the code waits for user input of course).

> BTW, each console window is hosted by an instance of conhost.exe.
> There's nothing special about cmd.exe with respect to the console.

Of course, but I doubt very many people know about conhost.exe.  And
conhost.exe is rather useless in and of itself unless you have something
to run on it.  Thus the usual way to get a console window that you can
actually work with is to run cmd.exe.  I seriously doubt you would tell
a newbie to somehow use conhost.exe to run his program.

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


Re: Modify Settings window pop-up

2016-01-17 Thread Michael Torrie
On 01/17/2016 03:54 PM, Dennis Lee Bieber wrote:
> On Sun, 17 Jan 2016 16:52:52 -0500, Terry Reedy 
> declaimed the following:
> 
>> On 1/17/2016 12:13 PM, Arvind Vallabhaneni wrote:
>>>
>>> [cid:888c5934-3c75-43d8-9e76-59a9dfbef814]
>>
>> What is this?  When I mouse over, Thunderbird just says 'about: blank' 
>> on the status line.  I will not click on something so unknown.
> 
>   Never having seen the format before either, I'm going to make a WAG and
> think that GUID is a "Clipboard ID", rather than the contents of the
> clipboard itself...

It's what happens when a multi-part email message goes through the
Usenet gateway I guess.  cid notation is used in html email to link to
an attached imaged in an email.

To the OP: email attachments generally don't work on this usenet
newsgroup and mailing list.

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


Re: Modify Settings window pop-up

2016-01-17 Thread Terry Reedy

On 1/17/2016 12:13 PM, Arvind Vallabhaneni wrote:


I installed the python interpreter and pycharm program onto my home desktop. 
However, while doing some simple programming exercises from class, the window 
below keeps popping up every time I type a few words or try to run the program.


This problem description is way too vague to answer.


[cid:888c5934-3c75-43d8-9e76-59a9dfbef814]


What is this?  When I mouse over, Thunderbird just says 'about: blank' 
on the status line.  I will not click on something so unknown.


--
Terry Jan Reedy

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


Re: how do I put the python on my desktop or even access it

2016-01-17 Thread eryk sun
On Sun, Jan 17, 2016 at 9:03 AM, Michael Torrie  wrote:
>
> but if it's a text-mode program you must run it from cmd.exe like this:
>
> python \path\to\myprogram.py.

You only need to run from another console program to keep the window
open after Python exits. You can even do that in other ways, but doing
that is more complicated than it is useful.

BTW, each console window is hosted by an instance of conhost.exe.
There's nothing special about cmd.exe with respect to the console.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "x == None" vs "x is None"

2016-01-17 Thread Chris Angelico
On Mon, Jan 18, 2016 at 8:33 AM, Random832  wrote:
>  writes:
>
>> I prefer (x is None) and (x is not None).
>>
>> This matches the SQL concept of NULL.
>>
>> (X = NULL) is not valid since NULL is not a value and cannot be compared
>> with anything.
>
> The suitably generic SQL operator is "is (not) distinct from", in some
> dialects of SQL [certainly if you're using NULL directly you can simply
> use is/is not, but the "distinct from" operators can be used to compare
> two expressions that may either or both be NULL.
>
> "X is not distinct from Y" == "X = Y or X is NULL and Y is NULL"

It's worth noting that Python's None is not really the same as SQL's
NULL... although that's partly because nothing is. NULL isn't quite
the same as IEEE NaN, nor C's null pointer, nor Python's None, all of
which are quite different from each other. All of them can be used to
represent some of the same concepts, but they behave very differently.
Trying to explain one in terms of another is likely to trip people up
somewhere.

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


Re: "x == None" vs "x is None"

2016-01-17 Thread Random832
 writes:

> I prefer (x is None) and (x is not None).
>
> This matches the SQL concept of NULL.
>
> (X = NULL) is not valid since NULL is not a value and cannot be compared
> with anything.

The suitably generic SQL operator is "is (not) distinct from", in some
dialects of SQL [certainly if you're using NULL directly you can simply
use is/is not, but the "distinct from" operators can be used to compare
two expressions that may either or both be NULL.

"X is not distinct from Y" == "X = Y or X is NULL and Y is NULL"

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


Re: "x == None" vs "x is None"

2016-01-17 Thread paul.hermeneutic
I prefer (x is None) and (x is not None).

This matches the SQL concept of NULL.

(X = NULL) is not valid since NULL is not a value and cannot be compared
with anything.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python plugin (semantic-aware) for the Qt Creator IDE

2016-01-17 Thread John Fabiani
What about debugging?
On Jan 16, 2016 6:02 AM, "Leandro T. C. Melo"  wrote:

> Hi again...
>
> Sorry, but I have a new url for the video (it's just slightly modified).
>
> https://youtu.be/71aqIwv3vJs
>
> Thanks,
> Leandro
>
>
> On Thursday, January 14, 2016 at 9:23:47 AM UTC-2, Leandro T. C. Melo
> wrote:
> > Hi everyone,
> >
> > I've recently published a Python (and other languages) plugin for the Qt
> Creator IDE. In fact, Qt Creator already has some official Python support,
> but it consists of only basic editing features. The plugin I'm working on
> gives you semantic highlighting, diagnostics, and completion.
> >
> > Here you go with an introduction video: https://youtu.be/XHrnvswtW6o
> >
> > The implementation is probably not mature enough to replace an
> industrial Python IDE or text editor yet, but hopefully I'll get there. If
> you'd like to try it out, please be patient with eventual bugs but feel
> free to report them to me.
> >
> > Notice the plugin is actually a thin layer bridging Qt Creator and the
> Uaiso engine[1], which is multi-language source code modeller. So if by any
> chance you'd like to write a plugin for any other IDE or text editor,
> you'll get the other languages out of the box (currently there's D and Go).
> >
> > Any kind of feed become is welcome.
> >
> > Thanks,
> > Leandro
> >
> > [1] https://github.com/ltcmelo/uaiso
>
> --
> https://mail.python.org/mailman/listinfo/python-announce-list
>
> Support the Python Software Foundation:
> http://www.python.org/psf/donations/
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Modify Settings window pop-up

2016-01-17 Thread Arvind Vallabhaneni

I installed the python interpreter and pycharm program onto my home desktop. 
However, while doing some simple programming exercises from class, the window 
below keeps popping up every time I type a few words or try to run the program.


[cid:888c5934-3c75-43d8-9e76-59a9dfbef814]


 I tried to click repair, and it didn't make a difference; I also tried to 
minimize it and continue working, but it still keeps popping up.

Is there a setting or something I installed incorrectly for it to do this? I am 
not able to work for more than 10 or 15 seconds at a time because this window 
comes up so frequently. Please let me know if there is a way to resolve this, I 
was not able to find a solution through Google or your website. Thank you in 
advance for your help.


Best regards,

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


Re: Hello.

2016-01-17 Thread jacob Kruger

Environment variables pointing to c:\python..?
(needs to point to actual installation directory)

Jacob Kruger
Blind Biker
Skype: BlindZA
"Roger Wilco wants to welcome you...to the space janitor's closet..."

On 2016-01-16 11:41 PM, Hmood Js wrote:

cmd won't recognize python at all I've checked several times , and I don't 
understand what's wrong

Sent from Mail for Windows 10



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


Re: Hello.

2016-01-17 Thread Bernardo Sulzbach
This is likely due to the fact that python.exe is not in PATH. Try
reinstalling Python with this option or adding it yourself.
-- 
https://mail.python.org/mailman/listinfo/python-list


why does windows command prompt not recognize "python"?

2016-01-17 Thread bob gailer


On Jan 17, 2016 9:13 AM, "Hmood Js" > wrote:

>
> cmd won't recognize python at all I've checked several times , and I 
don't understand what's wrong


Better to ask this at help or tutor @ Python.org. I am sending this to 
help, with a new subject,. Please reply to that address with that subject


Please make the subject meaningful. "Hello" is not.

Please state questions clearly, so we don't have to guess. For now I'll 
guess.

I
You have opened a "command prompt" and typed "python". You got 'python'' 
is not recognized as an internal or external command, operable program 
or batch file.


If that is true, continue. Otherwise tell us what you did and what you got.

What led you to expect something different? What did you expect?

When I do the above I get

Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 
bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>>

Please reply to above questions. The more you tell us the easier it is 
to help.


How did you install python? What version?
--
https://mail.python.org/mailman/listinfo/python-list


Re: how do I put the python on my desktop or even access it

2016-01-17 Thread Michael Torrie
On 01/16/2016 01:11 PM, zack fitzsimons wrote:
> 
> 
> 
> 
> 
> 
> 

I'm assuming based on your empty email that you must be running Windows.
 Python is a command-line program.  First run cmd.exe and then from
there you can run python.exe and interact with it in immediate mode.  To
create and run python programs, you can use a text editor to make the
program, and then, if it's a graphical program, you can double-click it,
but if it's a text-mode program you must run it from cmd.exe like this:

python \path\to\myprogram.py.

There is a graphical integrated development environment that comes with
Python called IDLE that you can run from the start menu. I suspect this
is where you'll want to go first.

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


Re: Hello.

2016-01-17 Thread Igor Korot
Hi,

On Sat, Jan 16, 2016 at 4:41 PM, Hmood Js  wrote:
> cmd won't recognize python at all I've checked several times , and I don't 
> understand what's wrong

What does this mean exactly?
Can you give an example?

Thank you.

>
> Sent from Mail for Windows 10
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: how do I put the python on my desktop or even access it

2016-01-17 Thread Igor Korot
-- Forwarded message --
From: Igor Korot 
Date: Sun, Jan 17, 2016 at 9:44 AM
Subject: Re: how do I put the python on my desktop or even access it
To: zack fitzsimons 


Hi,

On Sat, Jan 16, 2016 at 3:11 PM, zack fitzsimons
 wrote:

You can't put a snake onto you Desktop.
And the best way to access is to go to Africa.

;-)

Thank you.

>
>
>
>
>
>
>
> Sent from Windows Mail
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Hello.

2016-01-17 Thread Hmood Js
cmd won't recognize python at all I've checked several times , and I don't 
understand what's wrong

Sent from Mail for Windows 10

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


how do I put the python on my desktop or even access it

2016-01-17 Thread zack fitzsimons







Sent from Windows Mail
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keen eyes

2016-01-17 Thread Chris Angelico
On Sun, Jan 17, 2016 at 10:17 PM, BartC  wrote:
> On 17/01/2016 08:25, Chris Angelico wrote:
>>
>> On Sun, Jan 17, 2016 at 6:37 PM, Ian Kelly  wrote:
>>>
>>> Technically it defaults to non local. The var statement allocates a
>>> variable within the current scope. Otherwise it searches up the chain of
>>> parent scopes for a matching variable...
>>
>>
>> This far, it's exactly the same as C.
>>
>>> ... terminating at the global scope.
>>
>>
>> This is the bit that gets ridiculous. Undeclared variables in C are
>> compile-time errors. Undeclared variables in JS are implicit globals.
>> This is stupid.
>
>
> My own language is something in-between. If a name is not declared locally,
> it will look at more global scopes. If nothing is found, it will
> auto-declare a local.
>
> So the JS bug wouldn't occur. However, there is the problem that, given a
> perfectly working function with implicitly locals, at some point in the
> future someone could introduce a global that will clash with the name of a
> local, and screw things up.
>
> Because of that, the Python scheme is better on the whole. The only issue is
> that sometimes you think you're assigning to a global, but it's really a
> local if you forget the 'global' declaration within the function.

The Python scheme makes a lot of logical sense. The C scheme (declare
everything, otherwise it's an error) makes a lot of logical sense.
I've never seen a hybrid scheme that makes as much sense as either of
the above. In both Python's and C's ways of doing things, you can look
at a single function and know which names are local and which are
external. Have fun trying to share code snippets without knowing full
context...

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


Re: "x == None" vs "x is None"

2016-01-17 Thread Chris Angelico
On Sun, Jan 17, 2016 at 10:05 PM, Ulli Horlacher
 wrote:
> Chris Angelico  wrote:
>> On Sun, Jan 17, 2016 at 8:51 PM, Ulli Horlacher
>>  wrote:
>> > I have seen at several places "x == None" and "x is None" within
>> > if-statements.
>> > What is the difference?
>> > Which term should I prefer and why?
>>
>> tl;dr: Prefer "x is None" as a check.
>
> And for the negation?
> "if not x is None" or "if x is not None"
>
> I have seen the last one several times, but i do not understand it, because:
>
 x=0
 x is not None
> True
 not None
> True
 x is True
> False

There's no actual difference:

>>> dis.dis(lambda x: x is not None)
  1   0 LOAD_FAST0 (x)
  3 LOAD_CONST   0 (None)
  6 COMPARE_OP   9 (is not)
  9 RETURN_VALUE
>>> dis.dis(lambda x: not x is None)
  1   0 LOAD_FAST0 (x)
  3 LOAD_CONST   0 (None)
  6 COMPARE_OP   9 (is not)
  9 RETURN_VALUE

The compiler can tell that "not x is None" is exactly the same thing
as "x is not None". Personally, I'd rather spell it "is not None",
partly because it reads more like English that way, and partly because
one operator is better than two; but you're welcome to spell it "not x
is None" if that has other benefits (eg consistency).

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


Re: "x == None" vs "x is None"

2016-01-17 Thread Peter Otten
Ulli Horlacher wrote:

> Chris Angelico  wrote:
>> On Sun, Jan 17, 2016 at 8:51 PM, Ulli Horlacher
>>  wrote:
>> > I have seen at several places "x == None" and "x is None" within
>> > if-statements.
>> > What is the difference?
>> > Which term should I prefer and why?
>> 
>> tl;dr: Prefer "x is None" as a check.
> 
> And for the negation?
> "if not x is None" or "if x is not None"
> 
> I have seen the last one several times, but i do not understand it,
> because:
> 
 x=0
 x is not None
> True
 not None
> True
 x is True
> False

- "is" has higher precedence than "not"
- "is not" is an operator in its own right. 

So the evaluation is

not (x is None)
x (is not) None

https://docs.python.org/dev/library/stdtypes.html#comparisons
https://docs.python.org/dev/reference/expressions.html#operator-precedence

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


Re: Keen eyes

2016-01-17 Thread BartC

On 17/01/2016 08:25, Chris Angelico wrote:

On Sun, Jan 17, 2016 at 6:37 PM, Ian Kelly  wrote:

Technically it defaults to non local. The var statement allocates a
variable within the current scope. Otherwise it searches up the chain of
parent scopes for a matching variable...


This far, it's exactly the same as C.


... terminating at the global scope.


This is the bit that gets ridiculous. Undeclared variables in C are
compile-time errors. Undeclared variables in JS are implicit globals.
This is stupid.


My own language is something in-between. If a name is not declared 
locally, it will look at more global scopes. If nothing is found, it 
will auto-declare a local.


So the JS bug wouldn't occur. However, there is the problem that, given 
a perfectly working function with implicitly locals, at some point in 
the future someone could introduce a global that will clash with the 
name of a local, and screw things up.


Because of that, the Python scheme is better on the whole. The only 
issue is that sometimes you think you're assigning to a global, but it's 
really a local if you forget the 'global' declaration within the function.


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


Re: OT The fiction section

2016-01-17 Thread Ulli Horlacher
Marko Rauhamaa  wrote:
> Steven D'Aprano :
> 
> > https://pbs.twimg.com/media/CWgV0ruUsAAcUD7.jpg
> 
> Not bad.

$ python
Python 2.7.3 (default, Jun 22 2015, 19:33:41) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> bad=False
>>> not bad
True


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "x == None" vs "x is None"

2016-01-17 Thread Ulli Horlacher
Chris Angelico  wrote:
> On Sun, Jan 17, 2016 at 8:51 PM, Ulli Horlacher
>  wrote:
> > I have seen at several places "x == None" and "x is None" within
> > if-statements.
> > What is the difference?
> > Which term should I prefer and why?
> 
> tl;dr: Prefer "x is None" as a check.

And for the negation?
"if not x is None" or "if x is not None"

I have seen the last one several times, but i do not understand it, because:

>>> x=0
>>> x is not None
True
>>> not None
True
>>> x is True
False


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT The fiction section

2016-01-17 Thread Marko Rauhamaa
Steven D'Aprano :

> https://pbs.twimg.com/media/CWgV0ruUsAAcUD7.jpg

Not bad.


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


OT The fiction section

2016-01-17 Thread Steven D'Aprano
https://pbs.twimg.com/media/CWgV0ruUsAAcUD7.jpg

-- 
Steve

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


Re: Primality sieve challenge

2016-01-17 Thread jonas . thornvall
Den söndag 17 januari 2016 kl. 10:44:47 UTC+1 skrev jonas.t...@gmail.com:
> Maybe we could have a challenge finding the base with best reducion factor 
> upto base 100 00? One probably do not want to store more vectors than 
> that in memory, and i guess
> 
> Reducing composites in the integer field
> http://jt.node365.se/composite.html
> 
> 
> I've made my own kind of primality sieve that work by reducing lthe number 
> field into composite "legs" and prime "egs". The legs that contain just 
> composites in the numberfield will be thrown away sieved?
> 
> I asked the people at sci.math if there was a known upper limit for the 
> reduction using this type of counters in the integer field, they said no.
> 
> I wonder if there is a name for this type of sieve/counter within information 
> theory?
> 
> My idea is to find a base with very high percentage of composite legs, remove 
> all start numbers that produce only composites in their legs, and then store 
> the other egs that contain prime in an array.
> 
> That array will than serve the purpose modelling the new integer field, using 
> the searched base with highest composite reduction.
> 
> 
> The script seaching the bases take a few seconds, so there could be alot of 
> improvements. I have a feeling that using bignumb bases as sieves will be out 
> of range for us mere mortals, but who knows maybe for computer theorists.

At least i am impressed how well it reduce the composite integer field but of 
course you need a big array...

The math guys said just construct the base using the primes 2*3*5*7*11*13*17... 
and so on.

NEWBASE = 510510 --
BASE= 510510 Composite legs= 92.91551585669234% ===
One could say it is a bit clumsy but i think it is neat be able to peel of 
numbers that do not even need to be considered for primality test.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "x == None" vs "x is None"

2016-01-17 Thread Chris Angelico
On Sun, Jan 17, 2016 at 8:51 PM, Ulli Horlacher
 wrote:
> I have seen at several places "x == None" and "x is None" within
> if-statements.
> What is the difference?
> Which term should I prefer and why?

tl;dr: Prefer "x is None" as a check.

The two checks have slightly different meaning, and almost always you
want the identity check. "x is None" is asking the identity question
"does the name x refer to the exact same object as the singleton
None", but "x == None" is asking the value question "does the object
referred to by x want to consider itself equal to None". For instance:

class NoneLike(object):
def __eq__(self, other):
if other is None: return True
return isinstance(other, NoneLike)

>>> x = NoneLike()
>>> x == None
True
>>> x is None
False

The object referred to as x is not None itself, but it has decided to
call itself equal to None. This is incredibly unusual, and will
generally not be what you want.

As an additional bonus, the identity check is faster. The equality
check has to ask the object if it's equal or not, but the identity
check just says "same object? Y/N", which is generally going to be a
cheap check (in CPython, the objects' pointers can be compared).

But the main reason is semantic - you generally do not _want_ the
possibility of objects comparing equal to None. And if you actually
do, you'd better have some kind of comment there, or someone will come
along and change your code to the more normal "is None".

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


"x == None" vs "x is None"

2016-01-17 Thread Ulli Horlacher
I have seen at several places "x == None" and "x is None" within
if-statements.
What is the difference? 
Which term should I prefer and why?


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Primality sieve challenge

2016-01-17 Thread jonas . thornvall
Maybe we could have a challenge finding the base with best reducion factor upto 
base 100 00? One probably do not want to store more vectors than that in 
memory, and i guess

Reducing composites in the integer field
http://jt.node365.se/composite.html


I've made my own kind of primality sieve that work by reducing lthe number 
field into composite "legs" and prime "egs". The legs that contain just 
composites in the numberfield will be thrown away sieved?

I asked the people at sci.math if there was a known upper limit for the 
reduction using this type of counters in the integer field, they said no.

I wonder if there is a name for this type of sieve/counter within information 
theory?

My idea is to find a base with very high percentage of composite legs, remove 
all start numbers that produce only composites in their legs, and then store 
the other egs that contain prime in an array.

That array will than serve the purpose modelling the new integer field, using 
the searched base with highest composite reduction.


The script seaching the bases take a few seconds, so there could be alot of 
improvements. I have a feeling that using bignumb bases as sieves will be out 
of range for us mere mortals, but who knows maybe for computer theorists.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keen eyes

2016-01-17 Thread Chris Angelico
On Sun, Jan 17, 2016 at 6:37 PM, Ian Kelly  wrote:
> Technically it defaults to non local. The var statement allocates a
> variable within the current scope. Otherwise it searches up the chain of
> parent scopes for a matching variable...

This far, it's exactly the same as C.

> ... terminating at the global scope.

This is the bit that gets ridiculous. Undeclared variables in C are
compile-time errors. Undeclared variables in JS are implicit globals.
This is stupid.

Oh, plus the fact that you can have "var x;" anywhere but it always
applies to the whole function. But most of the time, that won't bite
you.

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