Re: How can an int be '+' with a tuple?

2018-06-02 Thread Jach Fong
Yes, (I think) I know the *any usage, but don't know their type will be changed after unpack? Gary Herron 於 2018/6/3 下午 12:05 寫道: In fact, the value of *any* is *not* an integer.  The *any notation causes Python to pack all the arguments into a tuple. This feature is usually used when there ar

Re: How can an int be '+' with a tuple?

2018-06-02 Thread Jach Fong
> (For good reasons, attachments are dropped when messages are distributed > on the forum.) For whom who can not get the attachment:-) ###a simplified version of "Programming Python 4ed, Example 10-20. import _thread as thread import queue threadQueue = queue.Queue(maxsize=0) def queueChecker(w

Re: Why exception from os.path.exists()?

2018-06-02 Thread Steven D'Aprano
On Sun, 03 Jun 2018 10:38:34 +1000, Chris Angelico wrote: > Let's just rewind this subthread a little bit. YOU said that the > behaviour of os.path.exists on Unix systems should be "return False for > invalid things" on the basis that the Windows invalid paths return > False. Remember? No, inval

Re: How can an int be '+' with a tuple?

2018-06-02 Thread Jach Fong
After a quick check I got: D:\Works\Python\PP4E-Examples-1.4\Examples\PP4E>py Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> t = ('myname',) >>> n = (3,) >>> n + t (3, 'myn

Re: How can an int be '+' with a tuple?

2018-06-02 Thread Steven D'Aprano
On Sun, 03 Jun 2018 04:59:34 +, Steven D'Aprano wrote: > On Sun, 03 Jun 2018 10:55:04 +0800, Jach Fong wrote: > >> The attached is a script which can run under Python 3.4/Windows Vista >> correctly. One thing make me puzzled is that the "any + context" at >> line 18. The "any" was passed as a

Re: How can an int be '+' with a tuple?

2018-06-02 Thread Steven D'Aprano
On Sun, 03 Jun 2018 10:55:04 +0800, Jach Fong wrote: > The attached is a script which can run under Python 3.4/Windows Vista > correctly. One thing make me puzzled is that the "any + context" at line > 18. The "any" was passed as an integer from line 43 and the "context" > was defined as a tuple a

Re: How can an int be '+' with a tuple?

2018-06-02 Thread Gary Herron
In fact, the value of *any* is *not* an integer.  The *any notation causes Python to pack all the arguments into a tuple. This feature is usually used when there are multiple (and an unknown number) of parameters, but it works perfectly well with a single parameter. Here's an example: >>> def

Re: How can an int be '+' with a tuple?

2018-06-02 Thread Ben Finney
Jach Fong writes: > The attached is a script Thanks for making an example script. Instead of attaching it, please post it along with your message so that everyone can read it. You can make scripts suitable for posting in your message, by keeping them short and simple http://sscce.org/>. (For go

Re: How can an int be '+' with a tuple?

2018-06-02 Thread Chris Angelico
On Sun, Jun 3, 2018 at 12:55 PM, Jach Fong wrote: > The attached is a script which can run under Python 3.4/Windows Vista > correctly. One thing make me puzzled is that the "any + context" at line > 18. The "any" was passed as an integer from line 43 and the "context" > was defined as a tuple at l

How can an int be '+' with a tuple?

2018-06-02 Thread Jach Fong
The attached is a script which can run under Python 3.4/Windows Vista correctly. One thing make me puzzled is that the "any + context" at line 18. The "any" was passed as an integer from line 43 and the "context" was defined as a tuple at line 35. This concatenation works! how? Best Regards, Jach

Re: Why exception from os.path.exists()?

2018-06-02 Thread Gregory Ewing
Steven D'Aprano wrote: Do you really mean to say that a computer that won't boot is POSIX compliant? No, I was pointing out the absurdity of saying that the Windows kernel layer is POSIX compliant, which is what the post I was replying to seemed to be saying. -- Greg -- https://mail.python.org

Re: Why exception from os.path.exists()?

2018-06-02 Thread Chris Angelico
On Sun, Jun 3, 2018 at 10:08 AM, Steven D'Aprano wrote: > Chris, you seem to be labouring under the misapprehension that the claim > is that a stock standard Windows installation complies > with the latest version of the POSIX standard. > > That's not the case. > > The claim (and fact) is that Wi

Re: Why exception from os.path.exists()?

2018-06-02 Thread Steven D'Aprano
On Sun, 03 Jun 2018 11:47:40 +1200, Gregory Ewing wrote: > Paul Moore wrote: >> Windows (the kernel) has the >> capability to implement fork(), but this isn't exposed via the Win32 >> API. To implement fork() you need to go to the raw kernel layer. Which >> is basically what the Windows Linux subs

Re: Indented multi-line strings

2018-06-02 Thread Dan Stromberg
On Sat, Jun 2, 2018 at 11:43 AM, Chris Angelico wrote: > >> 1) Messy code because people unindent inside their source code, > >> creating wonky indentation (which Python usually avoids) > >> > >> 2) Forcing readers to look up the third-party module you're using > >> before they can understand you

Re: Sorting NaNs

2018-06-02 Thread Richard Damon
On 6/2/18 7:35 PM, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 17:28:28 +0200, Peter J. Holzer wrote: > >> On 2018-06-02 10:40:48 +, Steven D'Aprano wrote: >>> On Sat, 02 Jun 2018 09:32:05 +0200, Peter J. Holzer wrote: Also nope. It looks like NaNs just mess up sorting in an unpredic

Re: Why exception from os.path.exists()?

2018-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2018 21:28:41 +1000, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 9:13 PM, Steven D'Aprano > wrote: >> On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: >> > Windows isn't POSIX compliant. Technically, Windows is POSIX compliant. You have to turn off a bunch

Re: Sorting NaNs

2018-06-02 Thread Richard Damon
On 6/2/18 7:50 PM, Ned Batchelder wrote: > Careful, "same input" is vague.  In Python2, object() instances are > compared based on their id, in other words, their memory location. It > would be easy to overlook the idea that the layout in memory is part > of whether two inputs are "the same". > > I

Re: Sorting NaNs

2018-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2018 21:51:16 +0100, Ben Bacarisse wrote: > Paul Rubin writes: > >> Steven D'Aprano writes: >>> it too will mess up sorting in unpredictable ways. So don't do that. >> >> Hmm. GHCi 7.4.2: >> >> Prelude> let x = 0.0 / 0.0 >> Prelude> x >> NaN >> Prelude> x==x >>

Re: Why exception from os.path.exists()?

2018-06-02 Thread Richard Damon
On 6/2/18 7:47 PM, Gregory Ewing wrote: > Paul Moore wrote: >> Windows (the kernel) has the >> capability to implement fork(), but this isn't exposed via the Win32 >> API. To implement fork() you need to go to the raw kernel layer. Which >> is basically what the Windows Linux subsystem (bash on Win

Re: Sorting NaNs

2018-06-02 Thread Ned Batchelder
On 6/2/18 6:16 PM, Richard Damon wrote: On 6/2/18 4:51 PM, Ben Bacarisse wrote: Paul Rubin writes: Steven D'Aprano writes: it too will mess up sorting in unpredictable ways. So don't do that. Hmm. GHCi 7.4.2: Prelude> let x = 0.0 / 0.0 Prelude> x NaN Prelude> x==x

Re: Why exception from os.path.exists()?

2018-06-02 Thread Gregory Ewing
Paul Moore wrote: Windows (the kernel) has the capability to implement fork(), but this isn't exposed via the Win32 API. To implement fork() you need to go to the raw kernel layer. Which is basically what the Windows Linux subsystem (bash on Windows 10) does What people usually mean by "POSIX c

Re: Sorting NaNs

2018-06-02 Thread Gregory Ewing
Peter J. Holzer wrote: If it was a deliberate decicion I would say it was intentional. It was a deliberate decision not to define an ordering for NaNs, but the particular behaviour of sorting them is accidental. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Sorting NaNs

2018-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2018 17:28:28 +0200, Peter J. Holzer wrote: > On 2018-06-02 10:40:48 +, Steven D'Aprano wrote: >> On Sat, 02 Jun 2018 09:32:05 +0200, Peter J. Holzer wrote: >> > Also nope. It looks like NaNs just mess up sorting in an >> > unpredictable way. Is this the intended behaviour or ju

Re: Sorting NaNs

2018-06-02 Thread Richard Damon
On 6/2/18 4:51 PM, Ben Bacarisse wrote: > Paul Rubin writes: > >> Steven D'Aprano writes: >>> it too will mess up sorting in unpredictable ways. So don't do that. >> Hmm. GHCi 7.4.2: >> >> Prelude> let x = 0.0 / 0.0 >> Prelude> x >> NaN >> Prelude> x==x >> False >> Prelud

Re: Sorting NaNs

2018-06-02 Thread Ben Bacarisse
Paul Rubin writes: > Steven D'Aprano writes: >> it too will mess up sorting in unpredictable ways. So don't do that. > > Hmm. GHCi 7.4.2: > > Prelude> let x = 0.0 / 0.0 > Prelude> x > NaN > Prelude> x==x > False > Prelude> :m Data.List > Prelude Data.List> sort [1,2,

Re: Indented multi-line strings

2018-06-02 Thread Chris Angelico
On Sun, Jun 3, 2018 at 2:52 AM, Dan Stromberg wrote: > > On Fri, Jun 1, 2018 at 2:57 PM, Chris Angelico wrote: >> >> If you dislike adding features to a language on the basis that it >> makes the language harder to learn, remember that you instead force >> one of three even worse options: >> >> 1

Re: Why exception from os.path.exists()?

2018-06-02 Thread Dan Stromberg
On Sat, Jun 2, 2018 at 4:28 AM, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 9:13 PM, Steven D'Aprano > wrote: > > On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: > Can someone confirm whether or not all the listed signals are actually > supported? We know that Ctrl-C maps to the int

How to move the scrollbar to inside the text widget

2018-06-02 Thread moideen50
I am a Newbie I have this code from tkinter import * root = Tk() root.geometry("1200x1000+30+30") # width x height + x_offset + y_offset: T = Text(root, height=10, width=100) T.place(x=20, y=30) for i in range(40): T.insert(END, "This is line %d\n" % i) # create a vertical scrollbar to the r

Re: Indented multi-line strings

2018-06-02 Thread Dan Stromberg
On Fri, Jun 1, 2018 at 2:57 PM, Chris Angelico wrote: > If you dislike adding features to a language on the basis that it > makes the language harder to learn, remember that you instead force > one of three even worse options: > > 1) Messy code because people unindent inside their source code, >

Re: Why exception from os.path.exists()?

2018-06-02 Thread Tim Chase
On 2018-06-02 00:14, Steven D'Aprano wrote: > Since /wibble doesn't exist, neither does /wibble/a\0b > > > py> os.path.exists("/wibble") > False > py> os.path.exists("/wibble/a\0b") > Traceback (most recent call last): > File "", line 1, in > File "/storage/torrents/torrents/python/Pytho

Re: Sorting NaNs

2018-06-02 Thread Peter J. Holzer
On 2018-06-02 10:40:48 +, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 09:32:05 +0200, Peter J. Holzer wrote: > > Also nope. It looks like NaNs just mess up sorting in an unpredictable > > way. Is this the intended behaviour or just an accident of > > implementation? (I think it's the latter: I

Re: Why exception from os.path.exists()?

2018-06-02 Thread Peter J. Holzer
On 2018-06-02 01:51:07 +, Grant Edwards wrote: > On 2018-06-01, Steven D'Aprano wrote: > > But since "\0" is the correct type (a string), and the fact that it > > happens to be illegal on POSIX is a platform-dependent detail of no more > > importance than the fact that "?" is illegal on Wind

Re: Fwd: QUERY

2018-06-02 Thread Ned Batchelder
On 6/2/18 9:08 AM, S Srihari wrote: To: python-list@python.org I AM UNABLE TO INSTALL PYTHON. KINDLY HELP ME. Put yourself in our shoes: how can we help you with so little information?  We don't know what operating system you are on, we don't know what you have tried, we don't know what has

Re: Fwd: QUERY

2018-06-02 Thread Grant Edwards
On 2018-06-02, S Srihari wrote: > I AM UNABLE TO INSTALL PYTHON. > KINDLY HELP ME. You're not doing it wrong. To fix this, do it right instead. -- https://mail.python.org/mailman/listinfo/python-list

Fwd: QUERY

2018-06-02 Thread S Srihari
To: python-list@python.org I AM UNABLE TO INSTALL PYTHON. KINDLY HELP ME. -- https://mail.python.org/mailman/listinfo/python-list

Re: Why exception from os.path.exists()?

2018-06-02 Thread Paul Moore
On 2 June 2018 at 12:28, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 9:13 PM, Steven D'Aprano > wrote: >> On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: >> > Windows isn't POSIX compliant. Technically, Windows is POSIX compliant. You have to turn off a bunch of fe

Re: Why exception from os.path.exists()?

2018-06-02 Thread Chris Angelico
On Sat, Jun 2, 2018 at 9:13 PM, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: > Windows isn't POSIX compliant. >>> >>> Technically, Windows is POSIX compliant. You have to turn off a bunch >>> of features, turn on another bunch of features, and what you ge

Re: syntax question

2018-06-02 Thread Chris Angelico
On Sat, Jun 2, 2018 at 9:08 PM, Sharan Basappa wrote: > Can anyone please tell me what the following line in a python program does: > > line = lambda x: x + 3 > > I have pasted the entire code below for reference: > > from scipy.optimize import fsolve > import numpy as np > line = lambda x: x + 3

Re: syntax question

2018-06-02 Thread Timo Furrer
>From the Python documentation at https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions > Small anonymous functions can be created with the lambda keyword. This function returns the sum of its two arguments: lambda a, b

Re: Sorting NaNs

2018-06-02 Thread Chris Angelico
On Sat, Jun 2, 2018 at 9:02 PM, Steven D'Aprano wrote: > The violation of reflexivity is weird though :-) > > x = float(NAN) > x == x # returns False > > Don't argue, just accept it :-) The way I learned it was: there are (of course) a finite number of bit patterns that can represent NaN

Re: Why exception from os.path.exists()?

2018-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: >>> Windows isn't POSIX compliant. >> >> Technically, Windows is POSIX compliant. You have to turn off a bunch >> of features, turn on another bunch of features, and what you get is the >> bare minimum POSIX compliance possible, but it's en

Re: Why exception from os.path.exists()?

2018-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2018 01:51:07 +, Grant Edwards wrote: > What about the case where somebody calls > > os.path.exists("/tmp/foo\x00bar") > > If /tmp/foo exists should it return True? That depends on whether /tmp/foo is a directory containing a file \0bar or not. Since that is not a legal file

syntax question

2018-06-02 Thread Sharan Basappa
Can anyone please tell me what the following line in a python program does: line = lambda x: x + 3 I have pasted the entire code below for reference: from scipy.optimize import fsolve import numpy as np line = lambda x: x + 3 solution = fsolve(line, -2) print solution -- https://mail.python.org

Re: Sorting NaNs

2018-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2018 10:31:37 +0100, Paul Moore wrote: > 1. The behaviour of comparisons involving NaN values is weird (not > undefined, as far as I know NaN behaviour is very well defined, but > violates a number of normally fundamental properties of comparisons) Not so much weird. They're just

Re: Sorting NaNs

2018-06-02 Thread Chris Angelico
On Sat, Jun 2, 2018 at 8:40 PM, Steven D'Aprano wrote: > Python's sort algorithm assumes that objects have consistent, sensible > comparisons. If you write an object like this: > > > class Rubbish: > def __eq__(self, other): > return random.random() > 0.5 > def __l

Re: Why exception from os.path.exists()?

2018-06-02 Thread Chris Angelico
On Sat, Jun 2, 2018 at 8:27 PM, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 10:32:55 +1000, Chris Angelico wrote: > >> On Sat, Jun 2, 2018 at 10:14 AM, Steven D'Aprano >> wrote: But assuming you're right, POSIX is still a set of minimum requirements - not maximums, to my knowledge

Re: Sorting NaNs

2018-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2018 09:32:05 +0200, Peter J. Holzer wrote: > Also nope. It looks like NaNs just mess up sorting in an unpredictable > way. Is this the intended behaviour or just an accident of > implementation? (I think it's the latter: I can see how a sort algorithm > which doesn't treat NaN spec

Re: Why exception from os.path.exists()?

2018-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2018 10:32:55 +1000, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 10:14 AM, Steven D'Aprano > wrote: >>> But >>> assuming you're right, POSIX is still a set of minimum requirements - >>> not maximums, to my knowledge. >> >> It isn't even a set of minimum requirements. "<" is lega

Re: Sorting NaNs

2018-06-02 Thread Chris Angelico
On Sat, Jun 2, 2018 at 7:31 PM, Paul Moore wrote: > On 2 June 2018 at 08:32, Peter J. Holzer wrote: >> Browsing through older messages I came upon a thread discussing the >> treatment of NaNs by median(). Since you have to (partially) sort the >> values to compute the median, I played around with

Re: Sorting NaNs

2018-06-02 Thread Paul Moore
On 2 June 2018 at 08:32, Peter J. Holzer wrote: > Browsing through older messages I came upon a thread discussing the > treatment of NaNs by median(). Since you have to (partially) sort the > values to compute the median, I played around with sorted(): > > Python 3.5.3 (default, Jan 19 2017, 14:11

Re: version

2018-06-02 Thread Paul Moore
On 2 June 2018 at 02:34, Mike McClain wrote: > It looks like what I was wanting is something like 'C's #if, a > compiler conditional. > > Does python have anything like that to tell the interpreter to ignore > a line that is not a comment or a quoted string? No, it doesn't. Honestly, if you are

Re: Indented multi-line strings

2018-06-02 Thread Paul Moore
On 1 June 2018 at 22:57, Chris Angelico wrote: > How will a method be worse than a standalone function? Please explain > this. Because the standalone function already exists (in the textwrap module). There's nothing wrong with adding string methods, but where they don't add anything that can't b

Sorting NaNs

2018-06-02 Thread Peter J. Holzer
Browsing through older messages I came upon a thread discussing the treatment of NaNs by median(). Since you have to (partially) sort the values to compute the median, I played around with sorted(): Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyrigh

Re: Attachments? Re: Indented multi-line strings (was: "Data blocks" syntax specification draft)

2018-06-02 Thread Peter J. Holzer
On 2018-06-02 07:59:07 +1000, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 7:03 AM, Peter J. Holzer wrote: > > On 2018-05-31 14:42:39 -0700, Paul wrote: > >> I have heard that attachments to messages are not allowed on this list, > >> which makes sense. However I notice that messages from Peter