Re: connect four (game)

2017-11-27 Thread namenobodywants
On Sunday, November 26, 2017 at 7:09:25 PM UTC-8, Michael Torrie wrote:
 
> So you are using this Infinity class as a sentinel value of some kind?
> Representing game state?  There may be an easier way than a full on
> custom type.  Sometimes just a sentinel object is sufficient.  Or an
> enumeration.

they're not sentinels; they're the maximum and minimum of the extended real 
numbers; the point is that, no matter how boards are evaluated (which is, of 
course, subject to change), a won game is always the most valuable and a lost 
game is always the least valuable; ordinary real numbers could be used for the 
purpose, but in that case i would have to figure out the maximum and minimum of 
the heuristic values the script assigns and then add/subtract one (for example) 
to get the value of a won/lost game

peace
stm

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


Re: connect four (game)

2017-11-27 Thread Chris Angelico
On Mon, Nov 27, 2017 at 9:01 PM,   wrote:
> On Sunday, November 26, 2017 at 7:09:25 PM UTC-8, Michael Torrie wrote:
>
>> So you are using this Infinity class as a sentinel value of some kind?
>> Representing game state?  There may be an easier way than a full on
>> custom type.  Sometimes just a sentinel object is sufficient.  Or an
>> enumeration.
>
> they're not sentinels; they're the maximum and minimum of the extended real 
> numbers; the point is that, no matter how boards are evaluated (which is, of 
> course, subject to change), a won game is always the most valuable and a lost 
> game is always the least valuable; ordinary real numbers could be used for 
> the purpose, but in that case i would have to figure out the maximum and 
> minimum of the heuristic values the script assigns and then add/subtract one 
> (for example) to get the value of a won/lost game
>

Or you could use the floating-point values for positive and negative
infinity, which already compare as you need with all integers and
floats. But that's up to you.

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


Re: Benefits of unicode identifiers (was: Allow additional separator in identifiers)

2017-11-27 Thread Antoon Pardon
Op 23-11-17 om 19:42 schreef Mikhail V:
> Chris A wrote:
>
>>> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote:
>>>
 Chris A wrote:

 Fortunately for the world, you're not the one who decided which
 characters were permitted in Python identifiers. The ability to use
 non-English words for function/variable names is of huge value; the
 ability to use a hyphen is of some value, but not nearly as much.
>>> Fortunately for the world we have Chris A. Who knows what is
>>> fortunate and of huge values.
>>> So is there any real world projects example of usage of non-latin scripts
>>> in identifiers? Or is it still only a plan for the new world?
>
>> Yes, I've used them personally. And I know other people who have.
>
> Oh, I though it would be more impressive showcase for 'huge value'.
> If we drop the benefit of the bare fact that you can do it, or you just
> don't know English, how would describe the practical benefit?
> If you don't know english, then programming at all will be just too hard.
> (or one must define a new whole language specially for some local script)

Well maybe the value is not huge, but I really appreciate the possibility.
Being able to write something like below, makes things a lot more clear
for me.

Po = Pc + R * Vec(cos(θo), sin(θo))
Pe = Pc + R * Vec(cos(θe), sin(θe))
𝚫θ = θe - θo
𝚫P = Pe - Po

-- 
Antoon Pardon.

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


Re: connect four (game)

2017-11-27 Thread bartc

On 27/11/2017 03:04, Michael Torrie wrote:

On 11/26/2017 08:39 AM, bartc wrote:

The problem was traced to two lines that were in the wrong order (in the
original program). I can't see how unit tests can have helped in any way
at all, and it would probably have taken much longer.


What makes you think that?  Surely other decoders were doing the right
thing and you could compare your output against theirs?  JPEGs may be
lossy but the path through the decoder should be deterministic.

Or even if every decoder is slightly unique, at least yours should
output self-consistent data.


The original used some floating point code, I changed that to use 
integer code (eg a combination of multiplying and shifting; it make a 
difference on compiled version, perhaps not so much in .py).


But also (IIRC) there was a difference in taking the remainder of 
negative integer division, where different compilers may round up or down.


So there can easily be differences when compared at the binary level, 
but which shouldn't be noticeable with the human eye.


(https://pastebin.com/P7V1Bvkk
https://pastebin.com/raw/P7V1Bvkk  raw version with no ads, or colour)

 In other words, once you know you fixed

the chroma problem, you can use that jpeg as a unit test to make sure
future big fixes and enhancements don't break something else.
Regression testing is very important. Many times I've fixed a bug, only
to introduce new ones that broke formerly correct behavior.

Anyway, unit testing is certainly a challenging concept, and I'm no more
good at it than you are.


Some people are obsessed with having unit tests. Others are the same 
about using debuggers, especially in compiled code.


I've never used either, but I do alright. Some of the stuff I do is 
unsuitable for those for technical reasons, but also some of the 
problems I've come across just don't fit into such patterns.


People should use what works best for them, unless they're in a team 
where the have to use certain tools and working methods.



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


Re: connect four (game)

2017-11-27 Thread namenobodywants
On Monday, November 27, 2017 at 2:10:56 AM UTC-8, Chris Angelico wrote:

> Or you could use the floating-point values for positive and negative
> infinity

perfecto! thank you!

peace
stm

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


I have framework on python with pyunit, facing below issue while executing test case

2017-11-27 Thread jaya . birdar
Please let me know anyone aware about the issue


Traceback (most recent call last):
File "testrunner.py", line 447, in 
testrunner_obj.main()
File "testrunner.py", line 433, in main
self.result()
File "testrunner.py", line 310, in result
result = runner.run(self.suite)
File "/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 720, in 
run
test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 100, in run
self._handleClassSetUp(test, result)
File "/usr/lib/python2.7/unittest/suite.py", line 153, in _handleClassSetUp
self._addClassOrModuleLevelException(result, e, errorName)
File "/usr/lib/python2.7/unittest/suite.py", line 198, in 
_addClassOrModuleLevelException
result.addError(error, sys.exc_info())
File “/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 633, in 
addError
output = self.complete_output()
File “/autoPyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 591, in 
complete_output
return self.outputBuffer.getvalue()
AttributeError: '_TestResult' object has no attribute 'outputBuffer'
-- 
https://mail.python.org/mailman/listinfo/python-list


While, If, Count Statements

2017-11-27 Thread Cai Gengyang

Input :

count = 0

if count < 5:
  print "Hello, I am an if statement and count is", count

while count < 10:
  print "Hello, I am a while and count is", count
  count += 1

Output :

Hello, I am an if statement and count is 0
Hello, I am a while and count is 0
Hello, I am a while and count is 1
Hello, I am a while and count is 2
Hello, I am a while and count is 3
Hello, I am a while and count is 4
Hello, I am a while and count is 5
Hello, I am a while and count is 6
Hello, I am a while and count is 7
Hello, I am a while and count is 8
Hello, I am a while and count is 9

The above input gives the output below. Why isn't the output instead :

Hello, I am an if statement and count is 0
Hello, I am a while and count is 0
Hello, I am an if statement and count is 1
Hello, I am a while and count is 1
Hello, I am an if statement and count is 2
Hello, I am a while and count is 2
Hello, I am an if statement and count is 3
Hello, I am a while and count is 3
Hello, I am an if statement and count is 4
Hello, I am a while and count is 4
Hello, I am a while and count is 5
Hello, I am a while and count is 6
Hello, I am a while and count is 7
Hello, I am a while and count is 8
Hello, I am a while and count is 9
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Benefits of unicode identifiers (was: Allow additional separator in identifiers)

2017-11-27 Thread Rustom Mody
On Monday, November 27, 2017 at 3:43:20 PM UTC+5:30, Antoon Pardon wrote:
> Op 23-11-17 om 19:42 schreef Mikhail V:
> > Chris A wrote:
> >
> >>> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote:
> >>>
>  Chris A wrote:
> 
>  Fortunately for the world, you're not the one who decided which
>  characters were permitted in Python identifiers. The ability to use
>  non-English words for function/variable names is of huge value; the
>  ability to use a hyphen is of some value, but not nearly as much.
> >>> Fortunately for the world we have Chris A. Who knows what is
> >>> fortunate and of huge values.
> >>> So is there any real world projects example of usage of non-latin scripts
> >>> in identifiers? Or is it still only a plan for the new world?
> >
> >> Yes, I've used them personally. And I know other people who have.
> >
> > Oh, I though it would be more impressive showcase for 'huge value'.
> > If we drop the benefit of the bare fact that you can do it, or you just
> > don't know English, how would describe the practical benefit?
> > If you don't know english, then programming at all will be just too hard.
> > (or one must define a new whole language specially for some local script)
> 
> Well maybe the value is not huge, but I really appreciate the possibility.
> Being able to write something like below, makes things a lot more clear
> for me.
> 
> Po = Pc + R * Vec(cos(θo), sin(θo))
> Pe = Pc + R * Vec(cos(θe), sin(θe))
> 𝚫θ = θe - θo
> 𝚫P = Pe - Po

Yeah… This is important
And Ive tried to elaborate such suggestions here
http://blog.languager.org/2014/04/unicoded-python.html
[includes some of your suggestions!]
I should emphasize that the details there range between straightforward and
facetious.  The general sense of going beyond ASCII is not facetious at all
In fact its ridiculous in the reverse direction: just as FORTRAN and COBOL
believed that programming IN ALL UPPERCASE was somehow kosher, likewise
a 2017 language believing that sticking to ASCII is sound is faintly ridiculous.

But that brings me to the opposite point:
I feel its important to distinguish ‘parochial/sectarian unicode’ from 
‘universal unicode’.
More on the distinction http://blog.languager.org/2015/03/whimsical-unicode.html
More on the universal aspect: 
http://blog.languager.org/2015/02/universal-unicode.html

Having said that I should be honest to mention that I saw your post first on
my phone where the θ showed but the 𝚫 showed as a rectangle something like ⌧

I suspect that Δ OTOH would have worked… dunno

So yes, there can be non-trivial logistic problems going beyond ASCII
As there are problems with errant mail-clients transmitting 
indentation-sensitive languages and so on!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I have framework on python with pyunit, facing below issue while executing test case

2017-11-27 Thread Ned Batchelder

On 11/27/17 8:13 AM, [email protected] wrote:

Please let me know anyone aware about the issue


Traceback (most recent call last):
File "testrunner.py", line 447, in 
testrunner_obj.main()
File "testrunner.py", line 433, in main
self.result()
File "testrunner.py", line 310, in result
result = runner.run(self.suite)
File "/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 720, in 
run
test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 100, in run
self._handleClassSetUp(test, result)
File "/usr/lib/python2.7/unittest/suite.py", line 153, in _handleClassSetUp
self._addClassOrModuleLevelException(result, e, errorName)
File "/usr/lib/python2.7/unittest/suite.py", line 198, in 
_addClassOrModuleLevelException
result.addError(error, sys.exc_info())
File “/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 633, in 
addError
output = self.complete_output()
File “/autoPyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 591, in 
complete_output
return self.outputBuffer.getvalue()
AttributeError: '_TestResult' object has no attribute 'outputBuffer'


It's hard to say without seeing all your code, but I notice PyUnit 0.3 
in your traceback.  If that's the PyUnit I think it is, PyUnit 1.4.1 was 
released 16(!) years ago, and has been in the standard library as 
unittest since version 2.1.  Are you running ancient versions of your 
test infrastructure?


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


Re: While, If, Count Statements

2017-11-27 Thread bartc

On 27/11/2017 12:54, Cai Gengyang wrote:


Input :

count = 0

if count < 5:
   print "Hello, I am an if statement and count is", count

while count < 10:
   print "Hello, I am a while and count is", count
   count += 1

Output :

Hello, I am an if statement and count is 0
Hello, I am a while and count is 0
Hello, I am a while and count is 1
Hello, I am a while and count is 2
Hello, I am a while and count is 3
Hello, I am a while and count is 4
Hello, I am a while and count is 5
Hello, I am a while and count is 6
Hello, I am a while and count is 7
Hello, I am a while and count is 8
Hello, I am a while and count is 9

The above input gives the output below. Why isn't the output instead :

Hello, I am an if statement and count is 0
Hello, I am a while and count is 0
Hello, I am an if statement and count is 1
Hello, I am a while and count is 1
Hello, I am an if statement and count is 2
Hello, I am a while and count is 2
Hello, I am an if statement and count is 3
Hello, I am a while and count is 3
Hello, I am an if statement and count is 4
Hello, I am a while and count is 4
Hello, I am a while and count is 5
Hello, I am a while and count is 6
Hello, I am a while and count is 7
Hello, I am a while and count is 8
Hello, I am a while and count is 9


Because the if-statement is only executed once, then it does the loop.

Try:

count = 0

while count < 10:
  if count < 5:
 print "Hello, I am an if statement and count is", count
  print "Hello, I am a while and count is", count
  count += 1

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


Re: connect four (game)

2017-11-27 Thread Rustom Mody
On Monday, November 27, 2017 at 12:12:24 PM UTC+5:30, Chris Angelico wrote:
> On Mon, Nov 27, 2017 at 3:04 PM, Rustom Mody  wrote:
> >> Aviators have pinned down the best solution to this, I think. A pilot
> >> is not expected to be perfect; he is expected to follow checklists. A
> >> preflight checklist. A departure checklist. A landing checklist.
> >> Everything that needs to be done right is mentioned on the list, and
> >> you just go through the list and make sure you've done everything.
> >
> > And thats where the analogy breaks down.
> > Presumably a 50 person short-flight and a 600-person transcontinental may 
> > have
> > at least something in common in their pilot-checklists
> > What common will you find in a multi-million line OS, a thousand line script
> > and a student prime-numbers first-program?
> 
> You locate a pure function. I can pretty much guarantee that the first
> two will have a number of them, and the third one may or may not, but
> almost certainly should. Pure functions are the easiest to unit-test.
> Then you build up from there.
> 
> > No I am not dissing on testing and TDD; just that universality¹ of 
> > computing devices
> > is something that our civilization is nowhere near understanding, leave 
> > alone
> > dealing with — two programs can be more far apart than a bullock cart and a 
> > jet.
> > And yet they are both programs
> 
> ... so?

I know how to drive a car… and various two-wheelers.
I not so sure of a bus/truck… I suppose I could get one from here to there
at a pinch… without killing someone… though not quite sure of that!
Doesn't translate into knowing how to 'drive' planes or bullock-carts


gcc is tested with dejagnu. Do you imagine that knowing python's unittest or
nose directly translates into dejagnu expertise?
And even if we stay with industry-strength programs — gcc, linux-kernel, 
CPython, KDE — do you imagine that testing one helps in testing the other?
I doubt it (though I am hardly an expert with testing frameworks)

Once again let me end by saying that testing and TDD are good ideas
And it would be nice if there was more of it in/for python
[See http://osherove.com/tdd-kata-1/ one of the first hits that google
gives (me) for TDD python, and you find the python example
actually shows Ruby!]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Benefits of unicode identifiers (was: Allow additional separator in identifiers)

2017-11-27 Thread Rustom Mody
On Monday, November 27, 2017 at 6:48:56 PM UTC+5:30, Rustom Mody wrote:
> Having said that I should be honest to mention that I saw your post first on
> my phone where the θ showed but the 𝚫 showed as a rectangle something like ⌧
> 
> I suspect that Δ OTOH would have worked… dunno

Yeah Δ shows whereas 𝚫 doesn't (on my phone)
And ⌧ does show but much squatter than the replacement char the phone shows
when it cant display a char
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: connect four (game)

2017-11-27 Thread Chris Angelico
On Mon, Nov 27, 2017 at 10:38 PM, bartc  wrote:
> On 27/11/2017 03:04, Michael Torrie wrote:
>>
>> On 11/26/2017 08:39 AM, bartc wrote:
>>>
>>> The problem was traced to two lines that were in the wrong order (in the
>>> original program). I can't see how unit tests can have helped in any way
>>> at all, and it would probably have taken much longer.
>>
>>
>> What makes you think that?  Surely other decoders were doing the right
>> thing and you could compare your output against theirs?  JPEGs may be
>> lossy but the path through the decoder should be deterministic.
>>
>> Or even if every decoder is slightly unique, at least yours should
>> output self-consistent data.
>
>
> The original used some floating point code, I changed that to use integer
> code (eg a combination of multiplying and shifting; it make a difference on
> compiled version, perhaps not so much in .py).

The JPEG spec says what a given file should decode to. So you can use
a reference implementation to confirm that your code is correctly
decoding. Even if you might legitimately encode the same image in
different ways, each of those encoded files should decode to one exact
image, regardless of which decoder is used.

Your decoder was straight-up buggy, and tests would have proven this.

> But also (IIRC) there was a difference in taking the remainder of negative
> integer division, where different compilers may round up or down.

In every compiler, interpreter, and CPU that I've ever used, the
remainder has been well-defined. In what situation was it ill-defined,
such that different compilers could do different things?

> Some people are obsessed with having unit tests. Others are the same about
> using debuggers, especially in compiled code.
>
> I've never used either, but I do alright. Some of the stuff I do is
> unsuitable for those for technical reasons, but also some of the problems
> I've come across just don't fit into such patterns.
>
> People should use what works best for them, unless they're in a team where
> the have to use certain tools and working methods.

Yep, and if "producing buggy code that fails to comply with the spec"
is what works best for you, then please don't tell us that we're
advocating the wrong thing. Testing might not fix everything, but it
does help, especially in those easy cases where you're working with a
pure function that has a single correct output for a given input.
Which, if I'm not misunderstanding the specs, is the case for pretty
much every compression scheme in current use - including JPEG.

For myself, I don't write as many tests as I should. But I'm not going
to go around telling people that tests are a waste of time.

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


Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)

2017-11-27 Thread Rustom Mody
On Friday, November 24, 2017 at 10:11:24 PM UTC+5:30, Skip Montanaro wrote:
> > Because if I already can't understand the words, it will be more useful
> > to me to be able to type them reliably at a keyboard, for replication,
> > search, discussion with others about the code, etc.
> 
> I am probably not alone in my Americo-centric world where I can't even
> easily type accented Latin-1 characters. I happen to be using Linux as
> I type this, but type at a Windows keyboard at work (ugh) and have
> long been a user of Macs (still have one or two at home). Might the
> problem be further multiplied by the number of different ways I have
> of entering text? Would Emacs running on Linux, but displaying on
> Windows be different than Chrome running directly on Linux? 

I strongly suspect that any recent emacs will have M-x insert-char
(earlier it was called ucs-insert) default bound C-x 8 RET (yeah thats clunky)
which will accept at the minibuffer input

At which point the hex for é which is e9 can be entered — yeah its unreasonable 
to expect to remember that!
Its more reasonable to remember that that is an e acute; 
And e itself is a latin lower case letter
All of which becomes entering (in the minibuffer)
LATIN SMALL LETTER E ACUTE
- upper case not required; emacs will upcase it for you
- And will also provide some tab/star expansion help
ie *letter e acuteTAB 
expands to
LATIN *L LETTER E ACUTE
Further TAB-prodding will give you these choices
LATIN CAPITAL LETTER E ACUTE (É)LATIN CAPITAL LETTER E WITH ACUTE (É)
LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND ACUTE (Ế)
LATIN CAPITAL LETTER E WITH MACRON AND ACUTE (Ḗ)
LATIN SMALL LETTER E ACUTE (é)  LATIN SMALL LETTER E WITH ACUTE (é)
LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE (ế)
LATIN SMALL LETTER E WITH MACRON AND ACUTE (ḗ)

You could go one step more sophisticated and use TeX-input method
(C-x RET C-\)
After which \'e will collapse as é
“Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!” you may ask
True… So as you rightly do, 
- pick it up from google
- put emacs into tex input mode
- paste from google into emacs
- place point on the new char and type C-u C-x =
  Among other things emacs will helpfully inform you (among other things)
  to input: type "\'{e}" or "\'e" with TeX input method
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody  wrote:
> You could go one step more sophisticated and use TeX-input method
> (C-x RET C-\)
> After which \'e will collapse as é
> “Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!” you may ask
> True… So as you rightly do,
> - pick it up from google
> - put emacs into tex input mode
> - paste from google into emacs
> - place point on the new char and type C-u C-x =
>   Among other things emacs will helpfully inform you (among other things)
>   to input: type "\'{e}" or "\'e" with TeX input method

Which is closely related to the Compose key input method that I use.
First, you assign a key on your keyboard to be Compose (at least on
all my systems, there isn't one by default); I use the key between
left Ctrl and left Alt. Then you have certain key sequences available
that involve holding Compose and pressing something, and then pressing
something else. In the same way that you might press Ctrl-X, Q to do
something, you could press Compose-T, M to produce ™. Sounds
complicated, but it's not. It's right enough. All your accented
letters can be created with Compose-accent, letter - eg
Compose-apostrophe, e => é, or Compose-backtick, a => à.

Not sure what systems that's supported on. I use Debian GNU/Linux with
Xfce; I believe the Compose key handling is all done by X11, so it
should be fairly widely available at least on Linux-derived systems.

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


Re: connect four (game)

2017-11-27 Thread Ian Kelly
On Nov 27, 2017 7:08 AM, "Chris Angelico"  wrote:


In every compiler, interpreter, and CPU that I've ever used, the
remainder has been well-defined. In what situation was it ill-defined,
such that different compilers could do different things?


In C89 the result of integer division and modulo with negative operands
were implementation-defined -- the result of division could be either
floored or truncated, and the modulo result also varied to match.

This was fixed in C99, with division results always being truncated
(whereas Python uses the floor).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)

2017-11-27 Thread Rustom Mody
On Monday, November 27, 2017 at 8:07:47 PM UTC+5:30, Chris Angelico wrote:
> On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody wrote:
> > You could go one step more sophisticated and use TeX-input method
> > (C-x RET C-\)
> > After which \'e will collapse as é
> > “Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!” you may ask
> > True… So as you rightly do,
> > - pick it up from google
> > - put emacs into tex input mode
> > - paste from google into emacs
> > - place point on the new char and type C-u C-x =
> >   Among other things emacs will helpfully inform you (among other things)
> >   to input: type "\'{e}" or "\'e" with TeX input method
> 
> Which is closely related to the Compose key input method that I use.
> First, you assign a key on your keyboard to be Compose (at least on
> all my systems, there isn't one by default); I use the key between
> left Ctrl and left Alt. 

Ha Ha So you wont speak the unspeakable?¿!¡

I also have my compose set (to Capslock)
And I entered those chars above with C?? and C!! where C is Capslock

I most frequently use that for ⇒ (C=>) → (C->) ¹ (C^1) ₁ (C_1) etc
One can find other goodies at /usr/share/X11/locale/en_US.UTF-8/Compose

I didn't start with mentioning that to Skip because his basic requirement
(as I got it) was that
- input method should be OS-neutral
- emacs can be assumed

And so the only OS-non-neutrality that I am aware of is that sometimes
Alt works as Meta (gui-emacsen) and sometimes not terminal/text emacsen 
(typically, though I believe some ppl successfully tweak this also)
And so M-x can mean Alt-x (chord) or ESC-x (sequence) and a few such anomalies
But beyond that emacsen should be same for all OSes (modulo versions)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: connect four (game)

2017-11-27 Thread bartc

On 27/11/2017 13:57, Chris Angelico wrote:

On Mon, Nov 27, 2017 at 10:38 PM, bartc  wrote:




Your decoder was straight-up buggy, and tests would have proven this.


I created my Python version after the abysmal results from other Python 
decoders I tried which didn't work at all, gave the wrong results, 
didn't support other subsampling ratios, or hung. Or if they did work, 
they took forever.


I suggest you compare my version with some of those.

The first time I looked at a jpeg decoder, it was a massive C library of 
about 30 different source files. Sometimes you need to take short-cuts. 
My version generates images which are indistinguishable from those 
derived via other decoders.



But also (IIRC) there was a difference in taking the remainder of negative
integer division, where different compilers may round up or down.


In every compiler, interpreter, and CPU that I've ever used, the
remainder has been well-defined. In what situation was it ill-defined,
such that different compilers could do different things?


In certain C implementations, rounding the results of integer division 
could go up or down. This is a post from comp.lang.c from 2008:


"Nate Eldredge"  wrote in message
news:[email protected]...

> Mr. Burns  writes:
>
>> Hi group,
>>
>> suppose I have a grid of cells of size (R,C) and coordinates
>> (0..R-1,0..C-1) and
>> I'm translating pixel coordinates to grid coordinates by dividing by 
cell

>> size.
>>
>> Now, all works well for values >= 0, but for values < 0 I'm getting
>> inconsistent results.
>>
>> On one platform, division of negative numbers rounds towards negative
>> infinity, i.e., (-1 / 10) gives -1.  (this is what I want)
>>
>> On another platform (solaris), rounding is towards zero, and (-1 / 
10) is

>> 0!
>>
>> All numbers are plain ints.
>
> The C99 standard specifies truncation towards zero (like your Solaris
> compiler).  However, the previous C90 standard left it up to the
> implementation to decide which way to round when one of the operands is
> negative, as long as it is consistent with the % operator.


Exactly what the problem was with my jpeg program where a number from my 
language and compiler ended up as 187, but on C compiled with gcc as 
186, I can't remember. I /think/ it was to do with such rounding.


This is not a big deal: one program ends up with a pixel value of 186 
(in a range of 0 to 255), and another with 187. The true value in the 
original photo may have required a value somewhere between 186 and 187, 
so both values could be considered wrong!



Which, if I'm not misunderstanding the specs, is the case for pretty
much every compression scheme in current use - including JPEG.


JPEG uses lossy compression. The resulting recovered data is an 
approximation of the original.



For myself, I don't write as many tests as I should. But I'm not going
to go around telling people that tests are a waste of time.


I'm fairly certain the OP's program didn't work perfectly first time. So 
some procedure had to be followed to try it and decide if it behaved 
according to the specification they had in mind.


I believe that process can also be called 'testing'. And in this case, 
involving a visual GUI, it really demands tests verified by a human 
rather than spending the next six months writing automatic test 
procedures that simulate mouse input and examine the pixels on the 
screen to see if they correspond to what should happen.


> Your decoder was straight-up buggy, and tests would have proven this.

How did YOU determine it was buggy; unit-tests? And did you just do what 
everyone else does?


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


Re: While, If, Count Statements

2017-11-27 Thread Ned Batchelder

On 11/27/17 7:54 AM, Cai Gengyang wrote:

Input :

count = 0

if count < 5:
   print "Hello, I am an if statement and count is", count

while count < 10:
   print "Hello, I am a while and count is", count
   count += 1

Output :

Hello, I am an if statement and count is 0
Hello, I am a while and count is 0
Hello, I am a while and count is 1
Hello, I am a while and count is 2
Hello, I am a while and count is 3
Hello, I am a while and count is 4
Hello, I am a while and count is 5
Hello, I am a while and count is 6
Hello, I am a while and count is 7
Hello, I am a while and count is 8
Hello, I am a while and count is 9

The above input gives the output below. Why isn't the output instead :

Hello, I am an if statement and count is 0
Hello, I am a while and count is 0
Hello, I am an if statement and count is 1
Hello, I am a while and count is 1
Hello, I am an if statement and count is 2
Hello, I am a while and count is 2
Hello, I am an if statement and count is 3
Hello, I am a while and count is 3
Hello, I am an if statement and count is 4
Hello, I am a while and count is 4
Hello, I am a while and count is 5
Hello, I am a while and count is 6
Hello, I am a while and count is 7
Hello, I am a while and count is 8
Hello, I am a while and count is 9


It's easy to imagine that this sets up a rule that remains in effect for 
the rest of the program:


    if count < 5:
    print "Hello, I am an if statement and count is", count

But that's not how Python (and most other programming languages) works.  
Python reads statements one after another, and executes them as it 
encounters them.  When it finds the if-statement, it evaluates the 
condition, and if it is true *at that moment*, it executes the contained 
statements.  Then it forgets all about that if-statement, and moves on 
to the next statement.


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


Re: Python-list Digest, Vol 170, Issue 34

2017-11-27 Thread ROGER GRAYDON CHRISTMAN
I'll answer your question with a couple questions:

Why do you expect to get the results you seem to expect?

What part of your code should repeat (and why)?

A key factor in recognizing the difference between 'if' and 'while'
is knowing what effect they have on the indented statements 
that follow them.

Roger Christman
Pennsylvania State University

On Mon, Nov 27, 2017 Cai Gengyang wrote:
>

>Message: 38
>Date: Mon, 27 Nov 2017 04:54:21 -0800 (PST)
>From: Cai Gengyang 
>Subject: While, If, Count Statements
>Message-ID: 
>Content-Type: text/plain; charset="UTF-8"
>
>
>Input :
>
>count = 0
>
>if count < 5:
>  print "Hello, I am an if statement and count is", count
>
>while count < 10:
>  print "Hello, I am a while and count is", count
>  count += 1
>
>Output :
>
>Hello, I am an if statement and count is 0
>Hello, I am a while and count is 0
>Hello, I am a while and count is 1
>Hello, I am a while and count is 2
>Hello, I am a while and count is 3
>Hello, I am a while and count is 4
>Hello, I am a while and count is 5
>Hello, I am a while and count is 6
>Hello, I am a while and count is 7
>Hello, I am a while and count is 8
>Hello, I am a while and count is 9
>
>The above input gives the output below. Why isn't the output instead :
>
>Hello, I am an if statement and count is 0
>Hello, I am a while and count is 0
>Hello, I am an if statement and count is 1
>Hello, I am a while and count is 1
>Hello, I am an if statement and count is 2
>Hello, I am a while and count is 2
>Hello, I am an if statement and count is 3
>Hello, I am a while and count is 3
>Hello, I am an if statement and count is 4
>Hello, I am a while and count is 4
>Hello, I am a while and count is 5
>Hello, I am a while and count is 6
>Hello, I am a while and count is 7
>Hello, I am a while and count is 8
>Hello, I am a while and count is 9
>
>

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


Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)

2017-11-27 Thread Skip Montanaro
> I strongly suspect that any recent emacs will have M-x insert-char
> (earlier it was called ucs-insert) default bound C-x 8 RET (yeah thats clunky)
> which will accept at the minibuffer input

I tried C-x 8 e acute TAB

and was prompted with "E-acute". I don't know why it would have
capitalized the "e". Still, I plowed ahead and hit RET

which yielded an "Invalid character" message in the minibuffer.

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


Re: connect four (game)

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 2:14 AM, bartc  wrote:
> JPEG uses lossy compression. The resulting recovered data is an
> approximation of the original.

Ah but it is a perfect representation of the JPEG stream. Any given
compressed stream must always decode to the same output. The lossiness
is on the ENcoding, not the DEcoding.

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


Re: nospam ** infinity?

2017-11-27 Thread breamoreboy
On Monday, November 27, 2017 at 1:19:38 AM UTC, Chris Angelico wrote:
> On Mon, Nov 27, 2017 at 12:14 PM, Skip Montanaro wrote:
> >> There seems to be a gateway loop of some sort going on.
> >> I'm seeing multiple versions of the same posts in
> >> comp.lang.python with different numbers of "nospam"s
> >> prepended to the email address.
> >
> > This is the second thread about this. I was thinking it might be
> > related to recent changes to the gate_news process on mail.python.org,
> > but this fingerprint looks nothing like what gate_news does.
> >
> > Looking at a somewhat long-ish thread:
> >
> > https://groups.google.com/d/topic/comp.lang.python/YoxLtkzlt_o/discussion
> >
> > I see a couple posts from Chris Angelico, only some of which have a
> > "nospam" preface. It would seem that someone was trying to mark
> > certain posters as "not spammy," (I'm sure Chris is flattered) and
> > somehow posts with that private marking leaked out of the user's
> > system starting in the past twelve hours or so.
> >
> > Newsreader configuration problem?
> 
> More likely, someone was trying to obscure the email addresses, but
> managed to tag my name instead. Definitely looks like some sort of
> automation failure. The only question is, whose? If it's not from
> gate_news, there's someone here on the list/ng that is (probably
> accidentally) reposting everything.
> 
> ChrisA

I suspect that it's a big own goal as even stuff from the RUE is getting 
through.

--
Kindest regards.

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


Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 1:55 AM, Rustom Mody  wrote:
> On Monday, November 27, 2017 at 8:07:47 PM UTC+5:30, Chris Angelico wrote:
>> On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody wrote:
>> > You could go one step more sophisticated and use TeX-input method
>> > (C-x RET C-\)
>> > After which \'e will collapse as é
>> > “Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!” you may ask
>> > True… So as you rightly do,
>> > - pick it up from google
>> > - put emacs into tex input mode
>> > - paste from google into emacs
>> > - place point on the new char and type C-u C-x =
>> >   Among other things emacs will helpfully inform you (among other things)
>> >   to input: type "\'{e}" or "\'e" with TeX input method
>>
>> Which is closely related to the Compose key input method that I use.
>> First, you assign a key on your keyboard to be Compose (at least on
>> all my systems, there isn't one by default); I use the key between
>> left Ctrl and left Alt.
>
> Ha Ha So you wont speak the unspeakable?¿!¡

Heh, you mean the term "Windows key"? It's not appropriate on
keyboards that don't have an actual Windows logo on it. There are
other names for it, but I figured the easiest way was to describe its
location :D

But yes, that key. If you have a Windows key, you can assign it to be
the Compose key. Or, of course, you could redefine left control, so
that Ctrl-X is with the right key and Compose-X is with the left one.
Or any other key you like.

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


Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 5:13 AM, Skip Montanaro
 wrote:
>> If you have a Windows key, you can assign it to be
>> the Compose key.
>
> Would this be true on a machine running Windows? My work environment
> has me developing on Linux, with a Windows desktop. It's not clear to
> me that any sort of xmodmap shennanigans would work. Won't Windows
> itself always gobble up that key?

Now that, I can't tell you about. As mentioned, the specific system I
was using was provided by X11, so it wouldn't work on anything else.
(Don't know about Wayland; I think it might have an equivalent.) For
other window managers, you'd have to find some alternative.

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


Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)

2017-11-27 Thread Skip Montanaro
> If you have a Windows key, you can assign it to be
> the Compose key.

Would this be true on a machine running Windows? My work environment
has me developing on Linux, with a Windows desktop. It's not clear to
me that any sort of xmodmap shennanigans would work. Won't Windows
itself always gobble up that key?

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


Re: connect four (game)

2017-11-27 Thread bartc

On 27/11/2017 17:41, Chris Angelico wrote:

On Tue, Nov 28, 2017 at 2:14 AM, bartc  wrote:

JPEG uses lossy compression. The resulting recovered data is an
approximation of the original.


Ah but it is a perfect representation of the JPEG stream. Any given
compressed stream must always decode to the same output. The lossiness
is on the ENcoding, not the DEcoding.


You make it sound as bad as currency calculations where different 
software must produce results that always match to the nearest cent.


We're talking about perhaps +1 or -1 difference in the least significant 
bit of one channel of one pixels. If the calculation is consistent, then 
you will not know anything is amiss.


By +1 or -1, I mean compared with the same jpeg converted by independent 
means.


I also passed the same jpeg through another C program (not mine) using 
its own algorithms. There some pixels varied by up to +/- 9 from the 
others (looking at the first 512 bytes of the conversion to ppm).


Here's my test image: 
https://github.com/bartg/langs/blob/master/card2.jpg (nothing naughty).


Tell me what the definitive values of the pixels in this part of the 
image should be (I believe this corresponds to roughly the leftmost 180 
pixels of the top line; there are two million pixels in all). And tell 
me WHY you think those are the definitive ones.


Bear in mind also that this is not intended to be the world's most 
perfect software. But it does do a good enough job. And the other two 
Python versions I have, at the minute don't work at all.



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


Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)

2017-11-27 Thread Paul Moore
On 27 November 2017 at 18:13, Skip Montanaro  wrote:
>> If you have a Windows key, you can assign it to be
>> the Compose key.
>
> Would this be true on a machine running Windows? My work environment
> has me developing on Linux, with a Windows desktop. It's not clear to
> me that any sort of xmodmap shennanigans would work. Won't Windows
> itself always gobble up that key?

Programs can access the Windows key. IIRC, there is a utility that
provides compose-key functionality on Windows. I can't recall the name
right now and it's on my other PC, not this one, but I'll try to
remember to post the name tomorrow...

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


Re: connect four (game)

2017-11-27 Thread Ned Batchelder

On 11/27/17 1:57 PM, bartc wrote:

On 27/11/2017 17:41, Chris Angelico wrote:

On Tue, Nov 28, 2017 at 2:14 AM, bartc  wrote:

JPEG uses lossy compression. The resulting recovered data is an
approximation of the original.


Ah but it is a perfect representation of the JPEG stream. Any given
compressed stream must always decode to the same output. The lossiness
is on the ENcoding, not the DEcoding.


You make it sound as bad as currency calculations where different 
software must produce results that always match to the nearest cent.


We're talking about perhaps +1 or -1 difference in the least 
significant bit of one channel of one pixels. If the calculation is 
consistent, then you will not know anything is amiss.


By +1 or -1, I mean compared with the same jpeg converted by 
independent means.


I also passed the same jpeg through another C program (not mine) using 
its own algorithms. There some pixels varied by up to +/- 9 from the 
others (looking at the first 512 bytes of the conversion to ppm).


Here's my test image: 
https://github.com/bartg/langs/blob/master/card2.jpg (nothing naughty).


Tell me what the definitive values of the pixels in this part of the 
image should be (I believe this corresponds to roughly the leftmost 
180 pixels of the top line; there are two million pixels in all). And 
tell me WHY you think those are the definitive ones.


Bear in mind also that this is not intended to be the world's most 
perfect software. But it does do a good enough job. And the other two 
Python versions I have, at the minute don't work at all.





Surely the details of JPEG decompression, and the possible presence of 
flaws in certain decoders, is beyond the scope of this thread?


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


Re: Pros and cons of Python sources?

2017-11-27 Thread Martin Schöön
Den 2017-11-26 skrev Cameron Simpson :
> On 26Nov2017 10:00, nospam.Martin Schöön  wrote:
>>
>>Hmm, I seem to remember not being able to install packages with pip unless I
>>did sudo pip.
>
> And this is exactly what I'm warning about. Many Linux users see some kind of 
> failure and just stick sudo on the front of the command. It is almost always 
> the wrong things to do, leading to effects in the OS install area instead of 
> being safely contained within one's home directory or work area.
>
> Instead of reaching straight for sudo, look at pip's manual or help. You will 
> find that:
>
>   pip install --user ...
>
> installs modules local to your home directory, avoiding troublesome installs 
> into the OS area.
>
Guilty as charged.

So, how do I restore order in my Python 2.7 installation? Uninstall
everything that looks, smells and tastes like Python 2.7 and then
re-install?

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


Re: Pros and cons of Python sources?

2017-11-27 Thread Paul Moore
On 27 November 2017 at 20:20, Martin Schöön  wrote:
> Den 2017-11-26 skrev Cameron Simpson :
>> On 26Nov2017 10:00, nospam.Martin Schöön  wrote:
>>>
>>>Hmm, I seem to remember not being able to install packages with pip unless I
>>>did sudo pip.
>>
>> And this is exactly what I'm warning about. Many Linux users see some kind of
>> failure and just stick sudo on the front of the command. It is almost always
>> the wrong things to do, leading to effects in the OS install area instead of
>> being safely contained within one's home directory or work area.
>>
>> Instead of reaching straight for sudo, look at pip's manual or help. You will
>> find that:
>>
>>   pip install --user ...
>>
>> installs modules local to your home directory, avoiding troublesome installs
>> into the OS area.
>>
> Guilty as charged.
>
> So, how do I restore order in my Python 2.7 installation? Uninstall
> everything that looks, smells and tastes like Python 2.7 and then
> re-install?

Or just accept that everything's probably fine, but be prepared to
deal with the fact that something like that is what you should do if
you find a problem you can't resolve yourself and need to ask for help
from upstream (e.g., your distro provider or the pip maintainers).
It's not so much that anyone's forcing you to do anything a particular
way - just setting the boundaries on what they are willing to support
if you need help.

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


Re: Pros and cons of Python sources?

2017-11-27 Thread Andrew Z
Martin,
 Im Late to the party, but my (newbish) .02

I learned hard way not to mix rpm and pip (im on fedora).

Yes, pip ...-user is what i use now exclusively.

I doubt you can _easily_ clean everything up..especially considering that a
few linux core utils depend on python nowadays.
 Maybe you can try to "brute-force" it , by using : dnf/rpm --whatprovides
..| sort -u
And comparing with pip list.. (just a general idea).

You may also try to stand up a vm and compare lists from there too... (
agly, but will get the work done)

I have same mess as you do, but with python3. In my situation, i know i
messed something, because matplot would not graph anything despite my best
efforts. One day (in next e-6 months) when i get very annoyed with this
problem, ill wipe clean the machine and reinstall from scratch.

On Nov 27, 2017 15:25, "Martin Schöön"  wrote:

Den 2017-11-26 skrev Cameron Simpson :
> On 26Nov2017 10:00, nospam.Martin Schöön  wrote:
>>
>>Hmm, I seem to remember not being able to install packages with pip
unless I
>>did sudo pip.
>
> And this is exactly what I'm warning about. Many Linux users see some
kind of
> failure and just stick sudo on the front of the command. It is almost
always
> the wrong things to do, leading to effects in the OS install area instead
of
> being safely contained within one's home directory or work area.
>
> Instead of reaching straight for sudo, look at pip's manual or help. You
will
> find that:
>
>   pip install --user ...
>
> installs modules local to your home directory, avoiding troublesome
installs
> into the OS area.
>
Guilty as charged.

So, how do I restore order in my Python 2.7 installation? Uninstall
everything that looks, smells and tastes like Python 2.7 and then
re-install?

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


Re: Compile Python 3 interpreter to force 2-byte unicode

2017-11-27 Thread wojtek mula
On Sunday, November 26, 2017 at 1:00:19 AM UTC+1, Terry Reedy wrote:
> You must be trying to compile 2.7.  There may be Linux distributions
> that compile this way.

You're right, I need 2.7. Any hint which distro has got these settings?

> If you want to seriously work with unicode, many recommend using modern
> Python.

I have to fix a bug in my C extension that appears only in UCS-2 python (i.e.
Windows). I can reboot to Windows and debug there, but it's pain in a neck for
various reasons.

w.

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


Re: connect four (game)

2017-11-27 Thread nospam.nospam.nospam.alister via Python-list
On Sat, 25 Nov 2017 12:26:52 -0800, namenobodywants wrote:

> On Friday, November 24, 2017 at 8:07:07 AM UTC-8, Chris Angelico wrote:
>
>> This is the kind of function that needs a docstring and some comments.
>> What exactly is this doing? What are the "lines" of the board? What's
>> the difference between "linear" and "lines"? What exactly is it
>> returning?
>
> producing documentation is an extremely difficult task for me, but i've
> come up with the following:
>
> """
> makelines(length,numrows,numcolumns) IS THE LIST OF ALL LISTS L, WITH
> LENGTH length, OF COORDINATES FROM A numrows x numcolumns MATRIX, SUCH
> THAT THE ENTRIES OF L ALL LIE IN A LINE:
>
> LET horizontal BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN
> A HORIZONTAL LINE LET vertical BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE
> ENTRIES LIE IN A VERTICAL LINE LET downward BE ALL THE
> APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A DOWNWARD-SLOPING
> DIAGONAL LINE LET upward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE
> ENTRIES LIE IN AN UPWARD-SLOPING DIAGONAL LINE THEN
> makelines(length,numrows,numcolumns) IS THE UNION OF ALL THE
> AFOREMENTIONED SETS """
>
> def makelines(length,numrows,numcolumns):
> horizontal = [[(i, j+k) for k in range(length)] for i in
> range(numrows) for j in range(numcolumns)]
> vertical = [[(i+k, j) for k in range(length)] for i in
> range(numrows) for j in range(numcolumns)] downward = [[(i+k, j+k)
> for k in range(length)] for i in range(numrows) for j in
> range(numcolumns)]
> upward = [[(i+k, j-k) for k in range(length)] for i in
> range(numrows) for j in range(numcolumns)] linear = horizontal +
> vertical + downward + upward return [line for line in linear if
> all(i in range(6) and j in range(7) for (i,j) in line)]
>
> def getlines(board):
> coordlines = makelines(4,6,7) ## GLOBAL return [[board[square] for
> square in line] for line in coordlines
>
>
> i tried to remove all the superfluous spaces from that, but lining up
> code vertically is very helpful to me, so i don't think i can really
> dispense with the practice
>
> peace stm

the documentation should come after the def statement that way is becomes a
"Doc String" & can be accessed using the help function you may also want to
check out the recommended way of structuring a doc string,
 it could help you with your difficulty in writing them (a problem shared by
many)



--
This door is baroquen, please wiggle Handel. (If I wiggle Handel, will it
wiggle Bach?)
-- Found on a door in the MSU music building

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


Re: Argh!! Can't wrap my head around this Python stuff!

2017-11-27 Thread Stefan Ram
Ram) (Stefan Ram)

Greg Tibbet  writes:
>I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit
>of Java and trying to learn this new-fangled Python language!

  Which actually is older than Java.

>def ellipse(self, xy, fill=None, outline=None):
>"""Draw an ellipse."""
>ink, fill = self._getink(outline, fill)
>if fill is not None:
>self.draw.draw_ellipse(xy, fill, 1)
><...snipped...>
>ellipse() uses the method  self.draw.draw_ellipse()   Okay, fine...
>but WHERE is draw_ellipse defined??  What magic is happening there?

  Depends on the nature of â»selfâ«.

  Usually, the answer would be that it's defined in a superclass.

  But with Python, one could also decrypt a string and then feed
  the result to â»execâ« to dynamically add methods to an object
  whose source code is well hidden.

  Looking into the matter, it turns out, however, ...

  â»_draw_ellipseâ« is defined in the language C in the file
  â»_imaging.câ« and then mapped to â»draw_ellipseâ« via PyMethodDef
  which is part of Python's C API.

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


Re: connect four (game)

2017-11-27 Thread nospam . nospam . nospam . bartc
On 25/11/2017 16:07, Michael Torrie wrote:
> On 11/25/2017 06:00 AM, bartc wrote:
>> And there's a quite lot left of the rest of the program to worry about too!
>>
>> If you add 'window()' at the end of the program, then it seems to run on
>> Python 3. I'd play around with it first before thinking up strategies
>> for testing it.
>
> Actually, no.  Unit testing ideally should be done for each and every
> class as they are being written (before they are written in fact), no
> matter how small and trivial the class.  That way as you compose larger
> and larger units of code, the chances of things being right is greater
> compared to doing it the other way around.

The way I write code isn't incrementally top down or bottom up. It's backwards
and forwards. Feedback from different parts means the thing develops as a
whole. Sometimes parts are split into distinct sections, sometimes different
parts are merged.

Sometimes you realise you're on the wrong track, and sections have to be redone
 or a different approach used, which can be done in the earlier stages.

If I had to bother with such systematic tests as you suggest, and finish and
sign off everything before proceeding further, then nothing would ever get
done. (Maybe it's viable if working from an exacting specification that someone
 else has already worked out.)

I've also found that many of the bugs that do appear, also do so in ways you
never anticipated. Or in circumstances you would never have thought of.

(I've always thought that programming is a bit like creating new laws. The same
 laws need to work for everyone and in any circumstances, but no one can
foresee everything, and laws need to be tweaked and added to. Perhaps unit
tests can apply there too...)

> You may argue that testing doesn't matter for his small game, written
> for his own education and amusement.  The fact is that software in
> general is of abysmal quality across the boards, and promoting a habit
> of unit testing is good, even for trivial, home-grown stuff.

I thought people were being hard on the OP.

As for testing, I remember in a company I worked in, a complicated circuit was
submitted to a company that would put it into a mass-produced chip. This
company did massive numbers of emulated tests shown on a huge printout that
showed that all combinations of inputs and outputs worked exactly as intended.

Except the actual chip didn't work. As for the printout, the designer took it
home and used it as an underlay for a new carpet. A rather expensive underlay.

--
bartc

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


Re: Stopping an iterator and continuing later (Posting On Python-List P

2017-11-27 Thread november nihal
On Saturday, 25 November 2017 20:59:02 UTC, Lawrence Dâ ÖOliveiro  wrote:
> On Sunday, November 26, 2017 at 6:43:05 AM UTC+13, [email protected]
wrote:
> > I worked out how to use iterators to generate values one at a time
> > then ran into a second problem which is time. Is it possible to
> > save an iterator so that i can continue from where I stopped?
>
> Yes. Just stop calling it. Then, when you start again, you will get the
values continuing from that point.

I should have added I switch off the machine when I stop. ( I dont have options
 to keep it in a sleep mode or in hibernation )

NN

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


Re: [META] Why are duplicate posts coming through?

2017-11-27 Thread nospam . Chris Angelico
On Mon, Nov 27, 2017 at 11:04 AM, Skip Montanaro
 wrote:
> Chris,
>
> Please forward one or two to me. Mark Sapiro and I have been banging on the
> SpamBayes instance which supports the Usenet gateway. I suppose it's
> possible some change caused the problem you're seeing.
>
> Skip

Sent a couple through.

ChrisA

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


Re: Compile Python 3 interpreter to force 2-byte unicode

2017-11-27 Thread nospam . nospam . nospam . Rustom Mody
Mody)

On Sunday, November 26, 2017 at 3:43:29 AM UTC+5:30, Chris Angelico wrote:
> On Sun, Nov 26, 2017 at 9:05 AM,  wojtek.mula wrote:
> > Hi, my goal is to obtain an interpreter that internally
> > uses UCS-2. Such a simple code should print 65535:
> >
> >   import sys
> >   print sys.maxunicode
> >
> > This is enabled in Windows, but I want the same in Linux.
> > What options have I pass to the configure script?
>
> Why do you want to? What useful value do you have in creating this
> buggy interpreter?

I see that you are familiar with this bug: https://bugs.python.org/issue13153

And I see it or something very close is still buggy in python 3.5 [No it does
not allow me to paste an SMP char but if I open a file containing one it
crashes and rather messily â ö no way to close the idle other than killing the
shell]

No thats not a diatribe against idle; just that its reasonable to want python
to support work-arounds for reasonably common bugs in the current
unicode-ecosystem

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


Re: nospam ** infinity?

2017-11-27 Thread nospam . Skip Montanaro
> There seems to be a gateway loop of some sort going on.
> I'm seeing multiple versions of the same posts in
> comp.lang.python with different numbers of "nospam"s
> prepended to the email address.

This is the second thread about this. I was thinking it might be related to
recent changes to the gate_news process on mail.python.org, but this
fingerprint looks nothing like what gate_news does.

Looking at a somewhat long-ish thread:

https://groups.google.com/d/topic/comp.lang.python/YoxLtkzlt_o/discussion

I see a couple posts from Chris Angelico, only some of which have a "nospam"
preface. It would seem that someone was trying to mark certain posters as "not
spammy," (I'm sure Chris is flattered) and somehow posts with that private
marking leaked out of the user's system starting in the past twelve hours or
so.

Newsreader configuration problem?

Skip

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


Re: nospam ** infinity?

2017-11-27 Thread nospam . Chris Angelico
On Mon, Nov 27, 2017 at 12:14 PM, Skip Montanaro
 wrote:
>> There seems to be a gateway loop of some sort going on.
>> I'm seeing multiple versions of the same posts in
>> comp.lang.python with different numbers of "nospam"s
>> prepended to the email address.
>
> This is the second thread about this. I was thinking it might be
> related to recent changes to the gate_news process on mail.python.org,
> but this fingerprint looks nothing like what gate_news does.
>
> Looking at a somewhat long-ish thread:
>
> https://groups.google.com/d/topic/comp.lang.python/YoxLtkzlt_o/discussion
>
> I see a couple posts from Chris Angelico, only some of which have a
> "nospam" preface. It would seem that someone was trying to mark
> certain posters as "not spammy," (I'm sure Chris is flattered) and
> somehow posts with that private marking leaked out of the user's
> system starting in the past twelve hours or so.
>
> Newsreader configuration problem?

More likely, someone was trying to obscure the email addresses, but managed to
tag my name instead. Definitely looks like some sort of automation failure. The
 only question is, whose? If it's not from gate_news, there's someone here on
the list/ng that is (probably accidentally) reposting everything.

ChrisA

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


Re: connect four (game)

2017-11-27 Thread nospam . nospam . nospam . bartc
On 25/11/2017 23:49, Terry Reedy wrote:
> On 11/25/2017 4:57 PM, [email protected] wrote:
>> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote:
>>
>>> I did, and it looks buggy to me.â  The top and left frame lines are
>>> missing.â  If I click a square, the bottom square in the column lights
>>> up.â  But then I have no idea whether those are your intentions or not.
>> i hadn't noticed about the frame lines, but it's the same for me; but
>> i'm hoping you meant to write that the TOP square in a column flashes
>> when you "drop a token" down that column;
>
> All squares start white.â  Only the bottom square turns red or black,
> after perhaps a .3 second delay during which there is some jitter in
> white squares above, which could be the effect of white flashing white.

There are a couple of lines that look like this:

 self.grid.squarebuttons[column].flash()

If you comment out those two lines, then the flashing disappears, and it still
works.

Of course, if I'd used unit tests, I'd have figured that out a lot sooner. I
would just have had the somewhat bigger problem of devising a unit test that
would detect this.


--
bartc

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


Re: connect four (game)

2017-11-27 Thread nospam . Michael Torrie
On 11/25/2017 12:58 PM, [email protected] wrote:
> the idea is that there should be exactly one object posinf (positive
infinity) that compares as strictly greater than any number ever considered,
and exactly one object neginf that compares as strictly less; as the code
stands now there is no reason not to use +/-70 in that capacity; the "infinity"
 class is there so that the game-playing parts of the code (which at present
are intentionally as primitive as possible) can be modified more smoothly
later; the single place where "infinity" is instantiated is in the function
"getvalue", which returns the value of a finished game:
>
> def getvalue(winner,accessibles):
> return Infinity(+1) if winner == ex else Infinity(-1) if winner == oh
else 0 if not accessibles else None
>
> if ex has won then the value of the game is posinf; if oh has won then it's
neginf; if the game is tied (no winner but no accessible columns remaining)
then the value of the game is zero; otherwise the game is not finished and its
finished value is None

So you are using this Infinity class as a sentinel value of some kind?
Representing game state?  There may be an easier way than a full on custom
type.  Sometimes just a sentinel object is sufficient.  Or an enumeration.

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


Re: Argh!! Can't wrap my head around this Python stuff!

2017-11-27 Thread nospam . nospam . nospam . Wanderer
On Sunday, November 26, 2017 at 4:10:12 AM UTC-5, Greg Tibbet wrote:
> I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit
> of Java and trying to learn this new-fangled Python language!
>
> I've got a small program that uses PIL to create an image, draw some
> primitives (rectanges, ellipses, etc...) and save it.  Works fine...
> no issues.
>
> I've found in the past, the best way to "really learn" the language
> was to "dig into the guts" and understand it,.. I thought I was making
> progress, but when looking into the PIL library to see what's going on
> behind the scenes, I find the following code in ImageDraw.py
>
> def ellipse(self, xy, fill=None, outline=None):
> """Draw an ellipse."""
> ink, fill = self._getink(outline, fill)
> if fill is not None:
> self.draw.draw_ellipse(xy, fill, 1)
> <...snipped...>
>
> ellipse() uses the method  self.draw.draw_ellipse()   Okay, fine...
> but WHERE is draw_ellipse defined??  What magic is happening there?
> I've searched the entire PIL directory tree, and the ONLY two places
> draw_ellipse is mentioned are right there in the ellipse() function...
> WHAT am I missing??
>
> Thanks!
> -Stumpy (aka Greg)

I'm googlesmart when it comes to Python. I used to know C. I practically knew
what the assembly language would look like when it compiled. There was no
internet and searching through books can be really laborious so you almost had
to really know it to use it. But with Python, I don't start from first
principles. I google what I want to do, download the appropriate packages and
read through the examples. It can be really frustrating when you get bugs,
because you don't know what's going on deep down in the code.

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


Re: connect four (game)

2017-11-27 Thread nospam . Michael Torrie
On 11/26/2017 07:11 AM, bartc wrote:
>> You may argue that testing doesn't matter for his small game, written
>> for his own education and amusement.  The fact is that software in
>> general is of abysmal quality across the boards, and promoting a habit
>> of unit testing is good, even for trivial, home-grown stuff.
>
> I thought people were being hard on the OP.

I wasn't being hard on the OP. My observation is about the state of
*all* software.  My software especially, your software, Microsoft's
software.  It all is of rather poor quality compared to the rigors of other
industries like civil engineering, manufacturing, etc.

> As for testing, I remember in a company I worked in, a complicated
> circuit was submitted to a company that would put it into a
> mass-produced chip. This company did massive numbers of emulated tests
> shown on a huge printout that showed that all combinations of inputs and
> outputs worked exactly as intended.
>
> Except the actual chip didn't work. As for the printout, the designer
> took it home and used it as an underlay for a new carpet. A rather
> expensive underlay.

That's unfortunately, but seems to reinforce the notion that adequate testing
is required.  Clearly for a microchip, theoretically testing the chip's
"software" (for lack of a better term) was not adequate.  An analogy to our
software situation is that someone tested the algorithm, but not the actual,
in-use implementation of the algorithm.

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


Re: Argh!! Can't wrap my head around this Python stuff!

2017-11-27 Thread nospam . nospam . nospam . bartc
On 26/11/2017 09:09, Greg Tibbet wrote:
>
> I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit
> of Java and trying to learn this new-fangled Python language!
>
> I've got a small program that uses PIL to create an image, draw some
> primitives (rectanges, ellipses, etc...) and save it.  Works fine...
> no issues.
>
> I've found in the past, the best way to "really learn" the language
> was to "dig into the guts" and understand it,.. I thought I was making
> progress, but when looking into the PIL library to see what's going on
> behind the scenes, I find the following code in ImageDraw.py
>
> def ellipse(self, xy, fill=None, outline=None):
>  """Draw an ellipse."""
>  ink, fill = self._getink(outline, fill)
>  if fill is not None:
>  self.draw.draw_ellipse(xy, fill, 1)
> <...snipped...>
>
> ellipse() uses the method  self.draw.draw_ellipse()   Okay, fine...
> but WHERE is draw_ellipse defined??  What magic is happening there?
> I've searched the entire PIL directory tree, and the ONLY two places
> draw_ellipse is mentioned are right there in the ellipse() function...
> WHAT am I missing??

Python isn't a very pure language in that much of the functionality that looks
like it should be written in Python (because you imported a module just like
you import any Python module), actually is written in something else, as has
been pointed out.

It's reasonable that some things need to be implemented using some foreign
functions. But the boundary between Python and non-Python is blurred.

Take this program:

  import sys

and try and find sys.py in your installation.

(This is an obstacle if, for example, you're thinking of implementing a Python
interpreter. In theory, once you have it working, it should run any .py
program. But the critical modules it needs don't have .py source code. And the
interface to those non-Python functions isn't defined with special byte-code
instructions.

(It will be done /via/ those instructions, but the magic needed is on the other
 side of them. Calling into sys.fn() uses the same CALL_FUNCTION byte-code as
calling into a regular Python function.)

As I said, it's not pure. More of a jungle as you've found out.)

--
bartc

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


[META] Why are duplicate posts coming through?

2017-11-27 Thread nospam . Chris Angelico
Not sure whether this is an issue for -owner or not; apologies if not.

I'm seeing a whole lot of reasonably-recent posts getting re-sent, with
"nospam" attached to the posters' names. And they're getting re-sent multiple
times. Sometimes the posts have encoding problems (small amounts of mojibake).

What's going on? Is there something going haywire with the news/mail gateway?
Is there a rogue client re-posting a bunch of news? Somebody testing something?

ChrisA

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


Re: connect four (game)

2017-11-27 Thread nospam . Michael Torrie
On 11/26/2017 08:39 AM, bartc wrote:
> The problem was traced to two lines that were in the wrong order (in the
> original program). I can't see how unit tests can have helped in any way
> at all, and it would probably have taken much longer.

What makes you think that?  Surely other decoders were doing the right thing
and you could compare your output against theirs?  JPEGs may be lossy but the
path through the decoder should be deterministic.

Or even if every decoder is slightly unique, at least yours should output
self-consistent data.  In other words, once you know you fixed the chroma
problem, you can use that jpeg as a unit test to make sure future big fixes and
 enhancements don't break something else. Regression testing is very important.
 Many times I've fixed a bug, only to introduce new ones that broke formerly
correct behavior.

Anyway, unit testing is certainly a challenging concept, and I'm no more good
at it than you are.

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


I have anaconda, but Pycharm can't find it

2017-11-27 Thread nospam . C W
Hello all,

I am a first time PyCharm user. I have Python 3 and Anaconda installed. They
work together on Sublime Text, but not on Pycharm.

Pycharm tells me it cannot find modules numpy, matplotlib, etc.

What should I do? I tried to set the interpreter environment, and a few other
options, none seem to work.

This is the typical solution, but it does not work
https://stackoverflow.com/questions/35623776/import-numpy-on-pycharm

Thanks,

-Mike

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


Re: connect four (game)

2017-11-27 Thread nospam . Chris Angelico
On Mon, Nov 27, 2017 at 1:55 PM, Michael Torrie  wrote:
> On 11/26/2017 07:11 AM, bartc wrote:
>>> You may argue that testing doesn't matter for his small game, written
>>> for his own education and amusement.  The fact is that software in
>>> general is of abysmal quality across the boards, and promoting a habit
>>> of unit testing is good, even for trivial, home-grown stuff.
>>
>> I thought people were being hard on the OP.
>
> I wasn't being hard on the OP. My observation is about the state of
> *all* software.  My software especially, your software, Microsoft's
> software.  It all is of rather poor quality compared to the rigors of
> other industries like civil engineering, manufacturing, etc.

Not all software is poor quality compared to all examples of those industries.
You'll find the equivalent of software bugs in a lot of hardware situations;
the difference with software is that we have 100% perfect reproduction in the
end-user products, so we call it a design flaw instead of a production
artifact. (How often do you buy a box of something and find that a couple of
them just break?) Even in large-scale civil engineering projects, there are
plenty of stupidities. The house I'm living in has a place where the tiled
floor doesn't quite align with the wall that it meets, and I can't figure out
why; somewhere, two things that ought to have been parallel just aren't.
Bridges have been known to crack, cars break down for no good reason, your
hamburger just doesn't taste right today.

Aviators have pinned down the best solution to this, I think. A pilot is not
expected to be perfect; he is expected to follow checklists. A preflight
checklist. A departure checklist. A landing checklist. Everything that needs to
 be done right is mentioned on the list, and you just go through the list and
make sure you've done everything. Interestingly enough, that approximately
corresponds to unit testing (or maybe integration testing) - you design a suite
 of tests, and every time you do something, you make sure all the tests pass.
Neither test suites nor checklists can prevent all problems - but they CAN
prevent the same problems from cropping up again and again. (Which is kinda
important when you're dealing with airliners carrying hundreds of people. They
crash very rarely because the crew follow their checklists religiously, and
when they do, there's an investigation that can result in new tests being
added.)

ChrisA

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


Re: [META] Why are duplicate posts coming through?

2017-11-27 Thread nospam . Rustom Mody
On Monday, November 27, 2017 at 5:35:09 AM UTC+5:30, Skip Montanaro wrote:
> Chris,
>
> Please forward one or two to me. Mark Sapiro and I have been banging on the
> SpamBayes instance which supports the Usenet gateway. I suppose it's
> possible some change caused the problem you're seeing.
>
> Skip
>
> On Nov 26, 2017 5:22 PM, "Chris Angelico" wrote:
>
> Not sure whether this is an issue for -owner or not; apologies if not.
>
> I'm seeing a whole lot of reasonably-recent posts getting re-sent,
> with "nospam" attached to the posters' names. And they're getting
> re-sent multiple times. Sometimes the posts have encoding problems
> (small amounts of mojibake).
>
> What's going on? Is there something going haywire with the news/mail
> gateway? Is there a rogue client re-posting a bunch of news? Somebody
> testing something?

And the spam continues unabated
Except that the subject lines are changed

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


I have framework on python with pyunit, facing below issue while

2017-11-27 Thread jaya birdar
Please let me know anyone aware about the issue


Traceback (most recent call last):
File "testrunner.py", line 447, in  testrunner_obj.main()
File "testrunner.py", line 433, in main self.result()
File "testrunner.py", line 310, in result result = runner.run(self.suite)
File "/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 720, in
run
test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return
self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 108, in run test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return
self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 108, in run test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return
self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 100, in run
self._handleClassSetUp(test, result) File
"/usr/lib/python2.7/unittest/suite.py", line 153, in _handleClassSetUp
self._addClassOrModuleLevelException(result, e, errorName) File
"/usr/lib/python2.7/unittest/suite.py", line 198, in
_addClassOrModuleLevelException
result.addError(error, sys.exc_info()) File â
£/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 633, in
addError
output = self.complete_output()
File â £/autoPyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 591, in
 complete_output
return self.outputBuffer.getvalue() AttributeError: '_TestResult' object has no
 attribute 'outputBuffer'

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


Re: connect four (game)

2017-11-27 Thread nospam . Rustom Mody
On Monday, November 27, 2017 at 9:08:42 AM UTC+5:30, Chris Angelico wrote:
> On Mon, Nov 27, 2017 at 1:55 PM, Michael Torrie  wrote:
> > On 11/26/2017 07:11 AM, bartc wrote:
> >>> You may argue that testing doesn't matter for his small game, written
> >>> for his own education and amusement.  The fact is that software in
> >>> general is of abysmal quality across the boards, and promoting a habit
> >>> of unit testing is good, even for trivial, home-grown stuff.
> >>
> >> I thought people were being hard on the OP.
> >
> > I wasn't being hard on the OP. My observation is about the state of
> > *all* software.  My software especially, your software, Microsoft's
> > software.  It all is of rather poor quality compared to the rigors of
> > other industries like civil engineering, manufacturing, etc.
>
> Not all software is poor quality compared to all examples of those
> industries. You'll find the equivalent of software bugs in a lot of
> hardware situations; the difference with software is that we have 100%
> perfect reproduction in the end-user products, so we call it a design
> flaw instead of a production artifact. (How often do you buy a box of
> something and find that a couple of them just break?) Even in
> large-scale civil engineering projects, there are plenty of
> stupidities. The house I'm living in has a place where the tiled floor
> doesn't quite align with the wall that it meets, and I can't figure
> out why; somewhere, two things that ought to have been parallel just
> aren't. Bridges have been known to crack, cars break down for no good
> reason, your hamburger just doesn't taste right today.
>
> Aviators have pinned down the best solution to this, I think. A pilot
> is not expected to be perfect; he is expected to follow checklists. A
> preflight checklist. A departure checklist. A landing checklist.
> Everything that needs to be done right is mentioned on the list, and
> you just go through the list and make sure you've done everything.

And thats where the analogy breaks down. Presumably a 50 person short-flight
and a 600-person transcontinental may have at least something in common in
their pilot-checklists What common will you find in a multi-million line OS, a
thousand line script and a student prime-numbers first-program?

No I am not dissing on testing and TDD; just that universalityâ1 of computing
devices
is something that our civilization is nowhere near understanding, leave alone
dealing with â ö two programs can be more far apart than a bullock cart and a
jet.
And yet they are both programs

â1 Ive seen CS PhDs ask a student why a student didnt incorporate some
error-checking
  into his compiler which amounted to solving the halting problem.
  More mundanely I see students have a hard time seeing their phones and their
  laptops as 'the same'

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


Re: connect four (game)

2017-11-27 Thread nospam . Gregory Ewing
Chris Angelico wrote:

> On Mon, Nov 27, 2017 at 1:11 AM, bartc  wrote:
 >
>>If I had to bother with such systematic tests as you suggest, and finish and
>>sign off everything before proceeding further, then nothing would ever get
>>done. (Maybe it's viable if working from an exacting specification that
>>someone else has already worked out.)
>
> I wonder whether you're somehow special in that
> testing fundamentally doesn't work for you, or that you actually don't
> need to write tests.

I think the point is that a strict test-first discipline goes against the grain
 of exploratory programming.

When you're not sure how to approach a problem, it's useful to be able to
quickly try things out. If you have to write a bunch of tests for every little
thing before you can write the code for it, you can end up writing a lot of
tests for code that never ends up getting used. That's a good way to kill all
your enthusiasm for a project.

Also, stopping to write tests all the time interrupts your flow of thought.
You're deep into details of the solution, you realise you need class X, then
you have to stop and write tests for X. That makes you think a lot about all
the details of X, and by the time you're finished you've lost track of the big
picture.

I don't think anyone disputes that having a reasonably complete set of tests is
 a good thing. The argument is about whether it's strictly necessary to write
the tests
*first* in all cases.

Maybe you find it's a useful discipline that helps ensure the tests get
written. That's fine, but it doesn't mean that
*everyone* should be forced to do it that way all the time,
even if they're just programming for a hobby. That's confusing the desired end
result with a particular means of achieving it.

--
Greg

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


Re: connect four (game)

2017-11-27 Thread nospam . Chris Angelico
On Mon, Nov 27, 2017 at 10:08 AM, Gregory Ewing
 wrote:
> Chris Angelico wrote:
>
>> On Mon, Nov 27, 2017 at 1:11 AM, bartc  wrote:
>
>>
>>>
>>> If I had to bother with such systematic tests as you suggest, and finish
>>> and
>>> sign off everything before proceeding further, then nothing would ever
>>> get
>>> done. (Maybe it's viable if working from an exacting specification that
>>> someone else has already worked out.)
>>
>>
>> I wonder whether you're somehow special in that
>> testing fundamentally doesn't work for you, or that you actually don't
>> need to write tests.
>
>
> I think the point is that a strict test-first discipline goes
> against the grain of exploratory programming.
>
> When you're not sure how to approach a problem, it's useful
> to be able to quickly try things out. If you have to write a
> bunch of tests for every little thing before you can write
> the code for it, you can end up writing a lot of tests for
> code that never ends up getting used. That's a good way to
> kill all your enthusiasm for a project.

I agree, and that's why I don't tend to go for TDD. But writing tests
afterwards is a good thing, something I think bartc seems to disagree with.

ChrisA

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


Re: connect four (game)

2017-11-27 Thread nospam . Chris Angelico
On Mon, Nov 27, 2017 at 9:01 PM,   wrote:
> On Sunday, November 26, 2017 at 7:09:25 PM UTC-8, Michael Torrie wrote:
>
>> So you are using this Infinity class as a sentinel value of some kind?
>> Representing game state?  There may be an easier way than a full on
>> custom type.  Sometimes just a sentinel object is sufficient.  Or an
>> enumeration.
>
> they're not sentinels; they're the maximum and minimum of the extended real
numbers; the point is that, no matter how boards are evaluated (which is, of
course, subject to change), a won game is always the most valuable and a lost
game is always the least valuable; ordinary real numbers could be used for the
purpose, but in that case i would have to figure out the maximum and minimum of
 the heuristic values the script assigns and then add/subtract one (for
example) to get the value of a won/lost game
>

Or you could use the floating-point values for positive and negative infinity,
which already compare as you need with all integers and floats. But that's up
to you.

ChrisA

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


Re: While, If, Count Statements

2017-11-27 Thread Stefan Ram
Cai Gengyang  writes:

  Statement 0:

>count = 0

  Statement 1:

>if count < 5:
>  print "Hello, I am an if statement and count is", count

  Statement 2:

>while count < 10:
>  print "Hello, I am a while and count is", count
>  count += 1

  There are three statements here.

  They are executed in the given sequence.

  First, statement 0 binds the name â»countâ« to an
  object which has the int-value â»0â«.

  Next, statement 1 prints â»am an ifâ«. Now statement 1
  was executed. It will never be revisited. It's history.

  Next, statement 2 will print "am a while" several times.
  It is separated from statement 2, like, totally.
  The statement 1 is in the remote past from where it
  never will return to be executed while the while
  loop is happily printing aways its "am a while" :-).
  Statement 1 is sad :-(, because it will never print no more.
  Never more.

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


Re: connect four (game)

2017-11-27 Thread namenobodywants
On Sunday, November 26, 2017 at 7:09:25 PM UTC-8, Michael Torrie wrote:

> So you are using this Infinity class as a sentinel value of some kind?
> Representing game state?  There may be an easier way than a full on
> custom type.  Sometimes just a sentinel object is sufficient.  Or an
> enumeration.

they're not sentinels; they're the maximum and minimum of the extended real
numbers; the point is that, no matter how boards are evaluated (which is, of
course, subject to change), a won game is always the most valuable and a lost
game is always the least valuable; ordinary real numbers could be used for the
purpose, but in that case i would have to figure out the maximum and minimum of
 the heuristic values the script assigns and then add/subtract one (for
example) to get the value of a won/lost game

peace
stm

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


Re: connect four (game)

2017-11-27 Thread nospam . bartc
On 27/11/2017 03:04, Michael Torrie wrote:
> On 11/26/2017 08:39 AM, bartc wrote:
>> The problem was traced to two lines that were in the wrong order (in the
>> original program). I can't see how unit tests can have helped in any way
>> at all, and it would probably have taken much longer.
>
> What makes you think that?  Surely other decoders were doing the right
> thing and you could compare your output against theirs?  JPEGs may be
> lossy but the path through the decoder should be deterministic.
>
> Or even if every decoder is slightly unique, at least yours should
> output self-consistent data.

The original used some floating point code, I changed that to use integer code
(eg a combination of multiplying and shifting; it make a difference on compiled
 version, perhaps not so much in .py).

But also (IIRC) there was a difference in taking the remainder of negative
integer division, where different compilers may round up or down.

So there can easily be differences when compared at the binary level, but which
 shouldn't be noticeable with the human eye.

(https://pastebin.com/P7V1Bvkk
https://pastebin.com/raw/P7V1Bvkk  raw version with no ads, or colour)

  In other words, once you know you fixed
> the chroma problem, you can use that jpeg as a unit test to make sure
> future big fixes and enhancements don't break something else.
> Regression testing is very important. Many times I've fixed a bug, only
> to introduce new ones that broke formerly correct behavior.
>
> Anyway, unit testing is certainly a challenging concept, and I'm no more
> good at it than you are.

Some people are obsessed with having unit tests. Others are the same about
using debuggers, especially in compiled code.

I've never used either, but I do alright. Some of the stuff I do is unsuitable
for those for technical reasons, but also some of the problems I've come across
 just don't fit into such patterns.

People should use what works best for them, unless they're in a team where the
have to use certain tools and working methods.


--
bartc

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


Re: While, If, Count Statements

2017-11-27 Thread nospam . bartc
On 27/11/2017 12:54, Cai Gengyang wrote:
>
> Input :
>
> count = 0
>
> if count < 5:
>print "Hello, I am an if statement and count is", count
>
> while count < 10:
>print "Hello, I am a while and count is", count
>count += 1
>
> Output :
>
> Hello, I am an if statement and count is 0
> Hello, I am a while and count is 0
> Hello, I am a while and count is 1
> Hello, I am a while and count is 2
> Hello, I am a while and count is 3
> Hello, I am a while and count is 4
> Hello, I am a while and count is 5
> Hello, I am a while and count is 6
> Hello, I am a while and count is 7
> Hello, I am a while and count is 8
> Hello, I am a while and count is 9
>
> The above input gives the output below. Why isn't the output instead :
>
> Hello, I am an if statement and count is 0
> Hello, I am a while and count is 0
> Hello, I am an if statement and count is 1
> Hello, I am a while and count is 1
> Hello, I am an if statement and count is 2
> Hello, I am a while and count is 2
> Hello, I am an if statement and count is 3
> Hello, I am a while and count is 3
> Hello, I am an if statement and count is 4
> Hello, I am a while and count is 4
> Hello, I am a while and count is 5
> Hello, I am a while and count is 6
> Hello, I am a while and count is 7
> Hello, I am a while and count is 8
> Hello, I am a while and count is 9

Because the if-statement is only executed once, then it does the loop.

Try:

count = 0

while count < 10:
   if count < 5:
  print "Hello, I am an if statement and count is", count
   print "Hello, I am a while and count is", count
   count += 1

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


Re: While, If, Count Statements

2017-11-27 Thread nospam . Ned Batchelder
On 11/27/17 7:54 AM, Cai Gengyang wrote:
> Input :
>
> count = 0
>
> if count < 5:
>print "Hello, I am an if statement and count is", count
>
> while count < 10:
>print "Hello, I am a while and count is", count
>count += 1
>
> Output :
>
> Hello, I am an if statement and count is 0
> Hello, I am a while and count is 0
> Hello, I am a while and count is 1
> Hello, I am a while and count is 2
> Hello, I am a while and count is 3
> Hello, I am a while and count is 4
> Hello, I am a while and count is 5
> Hello, I am a while and count is 6
> Hello, I am a while and count is 7
> Hello, I am a while and count is 8
> Hello, I am a while and count is 9
>
> The above input gives the output below. Why isn't the output instead :
>
> Hello, I am an if statement and count is 0
> Hello, I am a while and count is 0
> Hello, I am an if statement and count is 1
> Hello, I am a while and count is 1
> Hello, I am an if statement and count is 2
> Hello, I am a while and count is 2
> Hello, I am an if statement and count is 3
> Hello, I am a while and count is 3
> Hello, I am an if statement and count is 4
> Hello, I am a while and count is 4
> Hello, I am a while and count is 5
> Hello, I am a while and count is 6
> Hello, I am a while and count is 7
> Hello, I am a while and count is 8
> Hello, I am a while and count is 9

It's easy to imagine that this sets up a rule that remains in effect for the
rest of the program:

 â â â  if count < 5:
 â â â â â â â  print "Hello, I am an if statement and count is", count

But that's not how Python (and most other programming languages) works.â Python
 reads statements one after another, and executes them as it encounters them.â 
 When it finds the if-statement, it evaluates the condition, and if it is true
*at that moment*, it executes the contained statements.â  Then it forgets all
about that if-statement, and moves on to the next statement.

--Ned.

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


Re: connect four (game)

2017-11-27 Thread nospam . Rustom Mody
On Monday, November 27, 2017 at 12:12:24 PM UTC+5:30, Chris Angelico wrote:
> On Mon, Nov 27, 2017 at 3:04 PM, Rustom Mody  wrote:
> >> Aviators have pinned down the best solution to this, I think. A pilot
> >> is not expected to be perfect; he is expected to follow checklists. A
> >> preflight checklist. A departure checklist. A landing checklist.
> >> Everything that needs to be done right is mentioned on the list, and
> >> you just go through the list and make sure you've done everything.
> >
> > And thats where the analogy breaks down.
> > Presumably a 50 person short-flight and a 600-person transcontinental may
have
> > at least something in common in their pilot-checklists
> > What common will you find in a multi-million line OS, a thousand line
script
> > and a student prime-numbers first-program?
>
> You locate a pure function. I can pretty much guarantee that the first
> two will have a number of them, and the third one may or may not, but
> almost certainly should. Pure functions are the easiest to unit-test.
> Then you build up from there.
>
> > No I am not dissing on testing and TDD; just that universalityâ1 of
computing devices
> > is something that our civilization is nowhere near understanding, leave
alone
> > dealing with â ö two programs can be more far apart than a bullock cart and
a jet.
> > And yet they are both programs
>
> ... so?

I know how to drive a carâ | and various two-wheelers. I not so sure of a
bus/truckâ | I suppose I could get one from here to there at a pinchâ | without
 killing someoneâ | though not quite sure of that! Doesn't translate into
knowing how to 'drive' planes or bullock-carts


gcc is tested with dejagnu. Do you imagine that knowing python's unittest or
nose directly translates into dejagnu expertise? And even if we stay with
industry-strength programs â ö gcc, linux-kernel, CPython, KDE â ö do you
imagine that testing one helps in testing the other? I doubt it (though I am
hardly an expert with testing frameworks)

Once again let me end by saying that testing and TDD are good ideas And it
would be nice if there was more of it in/for python [See
http://osherove.com/tdd-kata-1/ one of the first hits that google gives (me)
for TDD python, and you find the python example actually shows Ruby!]

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


Re: Python-list Digest, Vol 170, Issue 34

2017-11-27 Thread ROGER GRAYDON CHRISTMAN
I'll answer your question with a couple questions:

Why do you expect to get the results you seem to expect?

What part of your code should repeat (and why)?

A key factor in recognizing the difference between 'if' and 'while' is knowing
what effect they have on the indented statements that follow them.

Roger Christman
Pennsylvania State University

On Mon, Nov 27, 2017 Cai Gengyang wrote:
>

>Message: 38
>Date: Mon, 27 Nov 2017 04:54:21 -0800 (PST)
>From: Cai Gengyang 
>Subject: While, If, Count Statements
>Message-ID: 
>Content-Type: text/plain; charset="UTF-8"
>
>
>Input :
>
>count = 0
>
>if count < 5:
>  print "Hello, I am an if statement and count is", count
>
>while count < 10:
>  print "Hello, I am a while and count is", count
>  count += 1
>
>Output :
>
>Hello, I am an if statement and count is 0
>Hello, I am a while and count is 0
>Hello, I am a while and count is 1
>Hello, I am a while and count is 2
>Hello, I am a while and count is 3
>Hello, I am a while and count is 4
>Hello, I am a while and count is 5
>Hello, I am a while and count is 6
>Hello, I am a while and count is 7
>Hello, I am a while and count is 8
>Hello, I am a while and count is 9
>
>The above input gives the output below. Why isn't the output instead :
>
>Hello, I am an if statement and count is 0
>Hello, I am a while and count is 0
>Hello, I am an if statement and count is 1
>Hello, I am a while and count is 1
>Hello, I am an if statement and count is 2
>Hello, I am a while and count is 2
>Hello, I am an if statement and count is 3
>Hello, I am a while and count is 3
>Hello, I am an if statement and count is 4
>Hello, I am a while and count is 4
>Hello, I am a while and count is 5
>Hello, I am a while and count is 6
>Hello, I am a while and count is 7
>Hello, I am a while and count is 8
>Hello, I am a while and count is 9
>
>

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


Re: Benefits of unicode identifiers (was: Allow additional separator

2017-11-27 Thread nospam . Antoon Pardon
Op 23-11-17 om 19:42 schreef Mikhail V:
> Chris A wrote:
>
>>> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote:
>>>
 Chris A wrote:

 Fortunately for the world, you're not the one who decided which
 characters were permitted in Python identifiers. The ability to use
 non-English words for function/variable names is of huge value; the
 ability to use a hyphen is of some value, but not nearly as much.
>>> Fortunately for the world we have Chris A. Who knows what is
>>> fortunate and of huge values.
>>> So is there any real world projects example of usage of non-latin scripts
>>> in identifiers? Or is it still only a plan for the new world?
>
>> Yes, I've used them personally. And I know other people who have.
>
> Oh, I though it would be more impressive showcase for 'huge value'.
> If we drop the benefit of the bare fact that you can do it, or you just
> don't know English, how would describe the practical benefit?
> If you don't know english, then programming at all will be just too hard.
> (or one must define a new whole language specially for some local script)

Well maybe the value is not huge, but I really appreciate the possibility.
Being able to write something like below, makes things a lot more clear for me.

Po = Pc + R * Vec(cos(î,o), sin(î,o)) Pe = Pc + R * Vec(cos(î,e), sin(î,e))
gØÜ«î, = î,e - î,o
gØÜ«P = Pe - Po

--
Antoon Pardon.

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


Re: connect four (game)

2017-11-27 Thread nospam . Gregory Ewing
bartc wrote:
> (Maybe it's viable if working from an exacting
> specification that someone else has already worked out.)

In my experience, for anything non-trivial that hasn't been done before, these
"exacting specifications" never exist. Even if someone handles wnat they
*think* are exact and complete specifications, they're not. :-)

--
Greg

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


Re: connect four (game)

2017-11-27 Thread nospam . bartc
On 27/11/2017 13:57, Chris Angelico wrote:
> On Mon, Nov 27, 2017 at 10:38 PM, bartc  wrote:


> Your decoder was straight-up buggy, and tests would have proven this.

I created my Python version after the abysmal results from other Python
decoders I tried which didn't work at all, gave the wrong results, didn't
support other subsampling ratios, or hung. Or if they did work, they took
forever.

I suggest you compare my version with some of those.

The first time I looked at a jpeg decoder, it was a massive C library of about
30 different source files. Sometimes you need to take short-cuts. My version
generates images which are indistinguishable from those derived via other
decoders.

>> But also (IIRC) there was a difference in taking the remainder of negative
>> integer division, where different compilers may round up or down.
>
> In every compiler, interpreter, and CPU that I've ever used, the
> remainder has been well-defined. In what situation was it ill-defined,
> such that different compilers could do different things?

In certain C implementations, rounding the results of integer division could go
 up or down. This is a post from comp.lang.c from 2008:

"Nate Eldredge"  wrote in message
news:[email protected]...

 > Mr. Burns  writes:
 >
 >> Hi group,
 >>
 >> suppose I have a grid of cells of size (R,C) and coordinates
 >> (0..R-1,0..C-1) and
 >> I'm translating pixel coordinates to grid coordinates by dividing by
cell
 >> size.
 >>
 >> Now, all works well for values >= 0, but for values < 0 I'm getting
 >> inconsistent results.
 >>
 >> On one platform, division of negative numbers rounds towards negative
 >> infinity, i.e., (-1 / 10) gives -1.  (this is what I want)
 >>
 >> On another platform (solaris), rounding is towards zero, and (-1 /
10) is
 >> 0!
 >>
 >> All numbers are plain ints.
 >
 > The C99 standard specifies truncation towards zero (like your Solaris
 > compiler).  However, the previous C90 standard left it up to the
 > implementation to decide which way to round when one of the operands is
 > negative, as long as it is consistent with the % operator.


Exactly what the problem was with my jpeg program where a number from my
language and compiler ended up as 187, but on C compiled with gcc as 186, I
can't remember. I /think/ it was to do with such rounding.

This is not a big deal: one program ends up with a pixel value of 186 (in a
range of 0 to 255), and another with 187. The true value in the original photo
may have required a value somewhere between 186 and 187, so both values could
be considered wrong!

> Which, if I'm not misunderstanding the specs, is the case for pretty
> much every compression scheme in current use - including JPEG.

JPEG uses lossy compression. The resulting recovered data is an
approximation of the original.

> For myself, I don't write as many tests as I should. But I'm not going
> to go around telling people that tests are a waste of time.

I'm fairly certain the OP's program didn't work perfectly first time. So some
procedure had to be followed to try it and decide if it behaved according to
the specification they had in mind.

I believe that process can also be called 'testing'. And in this case,
involving a visual GUI, it really demands tests verified by a human rather than
 spending the next six months writing automatic test procedures that simulate
mouse input and examine the pixels on the screen to see if they correspond to
what should happen.

 > Your decoder was straight-up buggy, and tests would have proven this.

How did YOU determine it was buggy; unit-tests? And did you just do what
everyone else does?

--
Bartc

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


Re: Increasing the diversity of people who write Python (was:

2017-11-27 Thread nospam . Chris Angelico
On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody  wrote:
> You could go one step more sophisticated and use TeX-input method
> (C-x RET C-\)
> After which \'e will collapse as ÄC
> â £Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!â Ø you may
ask
> Trueâ | So as you rightly do,
> - pick it up from google
> - put emacs into tex input mode
> - paste from google into emacs
> - place point on the new char and type C-u C-x =
>   Among other things emacs will helpfully inform you (among other things)
>   to input: type "\'{e}" or "\'e" with TeX input method

Which is closely related to the Compose key input method that I use. First, you
 assign a key on your keyboard to be Compose (at least on all my systems, there
 isn't one by default); I use the key between left Ctrl and left Alt. Then you
have certain key sequences available that involve holding Compose and pressing
something, and then pressing something else. In the same way that you might
press Ctrl-X, Q to do something, you could press Compose-T, M to produce âäø.
Sounds complicated, but it's not. It's right enough. All your accented letters
can be created with Compose-accent, letter - eg Compose-apostrophe, e => ÄC, or
 Compose-backtick, a => Ä .

Not sure what systems that's supported on. I use Debian GNU/Linux with Xfce; I
believe the Compose key handling is all done by X11, so it should be fairly
widely available at least on Linux-derived systems.

ChrisA

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


Re: Benefits of unicode identifiers (was: Allow additional separator

2017-11-27 Thread wxjmfauth
Le lundi 27 novembre 2017 14:52:19 UTC+1, Rustom Mody a ÄCcritâ :
> On Monday, November 27, 2017 at 6:48:56 PM UTC+5:30, Rustom Mody wrote:
> > Having said that I should be honest to mention that I saw your post first
on
> > my phone where the î, showed but the gØÜ« showed as a rectangle something
like âî$
> >
> > I suspect that îö OTOH would have workedâ | dunno
>
> Yeah îö shows whereas gØÜ« doesn't (on my phone)
> And âî$ does show but much squatter than the replacement char the phone shows
> when it cant display a char

It is a least unicode.

Much better than what this idotic and buggy Flexible String Representation is
presenting to the eyes of users.

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


Re: connect four (game)

2017-11-27 Thread nospam . Chris Angelico
On Mon, Nov 27, 2017 at 10:38 PM, bartc  wrote:
> On 27/11/2017 03:04, Michael Torrie wrote:
>>
>> On 11/26/2017 08:39 AM, bartc wrote:
>>>
>>> The problem was traced to two lines that were in the wrong order (in the
>>> original program). I can't see how unit tests can have helped in any way
>>> at all, and it would probably have taken much longer.
>>
>>
>> What makes you think that?  Surely other decoders were doing the right
>> thing and you could compare your output against theirs?  JPEGs may be
>> lossy but the path through the decoder should be deterministic.
>>
>> Or even if every decoder is slightly unique, at least yours should
>> output self-consistent data.
>
>
> The original used some floating point code, I changed that to use integer
> code (eg a combination of multiplying and shifting; it make a difference on
> compiled version, perhaps not so much in .py).

The JPEG spec says what a given file should decode to. So you can use a
reference implementation to confirm that your code is correctly decoding. Even
if you might legitimately encode the same image in different ways, each of
those encoded files should decode to one exact image, regardless of which
decoder is used.

Your decoder was straight-up buggy, and tests would have proven this.

> But also (IIRC) there was a difference in taking the remainder of negative
> integer division, where different compilers may round up or down.

In every compiler, interpreter, and CPU that I've ever used, the remainder has
been well-defined. In what situation was it ill-defined, such that different
compilers could do different things?

> Some people are obsessed with having unit tests. Others are the same about
> using debuggers, especially in compiled code.
>
> I've never used either, but I do alright. Some of the stuff I do is
> unsuitable for those for technical reasons, but also some of the problems
> I've come across just don't fit into such patterns.
>
> People should use what works best for them, unless they're in a team where
> the have to use certain tools and working methods.

Yep, and if "producing buggy code that fails to comply with the spec" is what
works best for you, then please don't tell us that we're advocating the wrong
thing. Testing might not fix everything, but it does help, especially in those
easy cases where you're working with a pure function that has a single correct
output for a given input. Which, if I'm not misunderstanding the specs, is the
case for pretty much every compression scheme in current use - including JPEG.

For myself, I don't write as many tests as I should. But I'm not going to go
around telling people that tests are a waste of time.

ChrisA

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


Re: Benefits of unicode identifiers (was: Allow additional separator

2017-11-27 Thread nospam . Rustom Mody
On Monday, November 27, 2017 at 3:43:20 PM UTC+5:30, Antoon Pardon wrote:
> Op 23-11-17 om 19:42 schreef Mikhail V:
> > Chris A wrote:
> >
> >>> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote:
> >>>
>  Chris A wrote:
> 
>  Fortunately for the world, you're not the one who decided which
>  characters were permitted in Python identifiers. The ability to use
>  non-English words for function/variable names is of huge value; the
>  ability to use a hyphen is of some value, but not nearly as much.
> >>> Fortunately for the world we have Chris A. Who knows what is
> >>> fortunate and of huge values.
> >>> So is there any real world projects example of usage of non-latin scripts
> >>> in identifiers? Or is it still only a plan for the new world?
> >
> >> Yes, I've used them personally. And I know other people who have.
> >
> > Oh, I though it would be more impressive showcase for 'huge value'.
> > If we drop the benefit of the bare fact that you can do it, or you just
> > don't know English, how would describe the practical benefit?
> > If you don't know english, then programming at all will be just too hard.
> > (or one must define a new whole language specially for some local script)
>
> Well maybe the value is not huge, but I really appreciate the possibility.
> Being able to write something like below, makes things a lot more clear
> for me.
>
> Po = Pc + R * Vec(cos(î,o), sin(î,o))
> Pe = Pc + R * Vec(cos(î,e), sin(î,e))
> gØÜ«î, = î,e - î,o
> gØÜ«P = Pe - Po

Yeahâ | This is important
And Ive tried to elaborate such suggestions here
http://blog.languager.org/2014/04/unicoded-python.html
[includes some of your suggestions!] I should emphasize that the details there
range between straightforward and facetious.  The general sense of going beyond
 ASCII is not facetious at all In fact its ridiculous in the reverse direction:
 just as FORTRAN and COBOL believed that programming IN ALL UPPERCASE was
somehow kosher, likewise a 2017 language believing that sticking to ASCII is
sound is faintly ridiculous.

But that brings me to the opposite point: I feel its important to distinguish â
 ÿparochial/sectarian unicodeâ Ö from
â ÿuniversal unicodeâ Ö.
More on the distinction http://blog.languager.org/2015/03/whimsical-unicode.htm
 l
More on the universal aspect: http://blog.languager.org/2015/02/universal-unico
 de.html

Having said that I should be honest to mention that I saw your post first on my
 phone where the î, showed but the gØÜ« showed as a rectangle something like
âî$

I suspect that îö OTOH would have workedâ | dunno

So yes, there can be non-trivial logistic problems going beyond ASCII As there
are problems with errant mail-clients transmitting indentation-sensitive
languages and so on!

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


Re: connect four (game)

2017-11-27 Thread namenobodywants
On Monday, November 27, 2017 at 2:10:56 AM UTC-8, Chris Angelico wrote:

> Or you could use the floating-point values for positive and negative
> infinity

perfecto! thank you!

peace
stm

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


nospam ** infinity?

2017-11-27 Thread nospam . Gregory Ewing
There seems to be a gateway loop of some sort going on. I'm seeing multiple
versions of the same posts in comp.lang.python with different numbers of
"nospam"s prepended to the email address.

--
Greg

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


Re: connect four (game)

2017-11-27 Thread nospam . Chris Angelico
On Tue, Nov 28, 2017 at 2:14 AM, bartc  wrote:
> JPEG uses lossy compression. The resulting recovered data is an
> approximation of the original.

Ah but it is a perfect representation of the JPEG stream. Any given compressed
stream must always decode to the same output. The lossiness is on the ENcoding,
 not the DEcoding.

ChrisA

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


Re: connect four (game)

2017-11-27 Thread nospam . Ian Kelly
On Nov 27, 2017 7:08 AM, "Chris Angelico"  wrote:


In every compiler, interpreter, and CPU that I've ever used, the remainder has
been well-defined. In what situation was it ill-defined, such that different
compilers could do different things?


In C89 the result of integer division and modulo with negative operands were
implementation-defined -- the result of division could be either floored or
truncated, and the modulo result also varied to match.

This was fixed in C99, with division results always being truncated (whereas
Python uses the floor).

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


Re: Increasing the diversity of people who write Python (was:

2017-11-27 Thread nospam . Chris Angelico
On Tue, Nov 28, 2017 at 1:55 AM, Rustom Mody  wrote:
> On Monday, November 27, 2017 at 8:07:47 PM UTC+5:30, Chris Angelico wrote:
>> On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody wrote:
>> > You could go one step more sophisticated and use TeX-input method
>> > (C-x RET C-\)
>> > After which \'e will collapse as ÄC
>> > â £Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!â Ø you may
ask
>> > Trueâ | So as you rightly do,
>> > - pick it up from google
>> > - put emacs into tex input mode
>> > - paste from google into emacs
>> > - place point on the new char and type C-u C-x =
>> >   Among other things emacs will helpfully inform you (among other things)
>> >   to input: type "\'{e}" or "\'e" with TeX input method
>>
>> Which is closely related to the Compose key input method that I use.
>> First, you assign a key on your keyboard to be Compose (at least on
>> all my systems, there isn't one by default); I use the key between
>> left Ctrl and left Alt.
>
> Ha Ha So you wont speak the unspeakable?â¿!â¡

Heh, you mean the term "Windows key"? It's not appropriate on keyboards that
don't have an actual Windows logo on it. There are other names for it, but I
figured the easiest way was to describe its location :D

But yes, that key. If you have a Windows key, you can assign it to be the
Compose key. Or, of course, you could redefine left control, so that Ctrl-X is
with the right key and Compose-X is with the left one. Or any other key you
like.

ChrisA

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


Re: Increasing the diversity of people who write Python (was:

2017-11-27 Thread nospam . Skip Montanaro
> If you have a Windows key, you can assign it to be
> the Compose key.

Would this be true on a machine running Windows? My work environment has me
developing on Linux, with a Windows desktop. It's not clear to me that any sort
 of xmodmap shennanigans would work. Won't Windows itself always gobble up that
 key?

Skip

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


Re: Increasing the diversity of people who write Python (was:

2017-11-27 Thread nospam . Skip Montanaro
> I strongly suspect that any recent emacs will have M-x insert-char
> (earlier it was called ucs-insert) default bound C-x 8 RET (yeah thats
clunky)
> which will accept at the minibuffer input

I tried C-x 8 e acute TAB

and was prompted with "E-acute". I don't know why it would have capitalized the
 "e". Still, I plowed ahead and hit RET

which yielded an "Invalid character" message in the minibuffer.

Skip

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


Merits of otherwise of test-first (Re: connect four (game))

2017-11-27 Thread nospam . Gregory Ewing
bartc wrote:
> Testing everything comprehensively just wouldn't be useful for me who
> works on whole applications, whole concepts, not just a handful of
> functions with well-defined inputs and outputs.

I had this experience with Pyrex (the precursor to Cython). The various parts
are so interdependent that it doesn't really make sense to test individual
classes or methods on their own. It would require a huge amount of scaffolding
and wouldn't really prove much.

Instead, what I did was write tests for units of *functionality*. (Can it
compile an assignment statement? An expression that adds two things? Subtracts
them? etc.) I wrote a very large number of them, plus a test framework to run
them and compare the output with known good output.

I can't claim that I always wrote the tests *first* (sometimes I did, sometimes
 I didn't). But I never had any trouble motivating myself to write the tests.
Partly this is because the way my test framework worked, there was very little
difference between a manual test and an automated one. I had to write a test
file to test it at all, and having done that, it was just as easy to save it
away together with its output so that it became part of the automated test
suite.

It was also partly because the benefits of having a comprehensive automatic
test suite were so blindingly obvious in that project. Its complexity meant
that it was particularly easy to break something accidentally when adding a new
 feature. If that happened, the tests would almost certainly pick it up
immediately. Without those tests, I would never have been able to develop it to
 the point I did.

>> So there was something else wrong with the chip. I'm not sure what
>> your point is.
>
> The extensive testing was like unit testing, but needed to be even more
> thorough because of the commitment involved. It failed to spot a problem.

Testing obviously isn't guaranteed to find all problems in a system with
complex behaviour, but that doesn't mean testing is useless. It would have been
 hugely more risky to go ahead and build the chip without testing the design at
 all!

BTW, hardware is a bit different from software. It's possible
for a design to be *logically* correct and pass all the simulations, but for
the hardware to fail for messy physics- related reasons. (Charles Moore tells a
 story like that about one of his Forth chips. A transistor driving a
particular signal was too small, and if you executed a particular instruction
too many times in too short a time interval, it would overheat and produce
incorrect results.)

--
Greg

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


Re: Increasing the diversity of people who write Python (was:

2017-11-27 Thread nospam . Chris Angelico
On Tue, Nov 28, 2017 at 5:13 AM, Skip Montanaro
 wrote:
>> If you have a Windows key, you can assign it to be
>> the Compose key.
>
> Would this be true on a machine running Windows? My work environment
> has me developing on Linux, with a Windows desktop. It's not clear to
> me that any sort of xmodmap shennanigans would work. Won't Windows
> itself always gobble up that key?

Now that, I can't tell you about. As mentioned, the specific system I was using
 was provided by X11, so it wouldn't work on anything else. (Don't know about
Wayland; I think it might have an equivalent.) For other window managers, you'd
 have to find some alternative.

ChrisA

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


Re: [META] Why are duplicate posts coming through?

2017-11-27 Thread nospam . Skip Montanaro
Chris,

Please forward one or two to me. Mark Sapiro and I have been banging on the
SpamBayes instance which supports the Usenet gateway. I suppose it's possible
some change caused the problem you're seeing.

Skip

On Nov 26, 2017 5:22 PM, "Chris Angelico"  wrote:

Not sure whether this is an issue for -owner or not; apologies if not.

I'm seeing a whole lot of reasonably-recent posts getting re-sent, with
"nospam" attached to the posters' names. And they're getting re-sent multiple
times. Sometimes the posts have encoding problems (small amounts of mojibake).

What's going on? Is there something going haywire with the news/mail gateway?
Is there a rogue client re-posting a bunch of news? Somebody testing something?

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

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


Re: I have framework on python with pyunit, facing below issue while

2017-11-27 Thread nospam . Ned Batchelder
On 11/27/17 8:13 AM, [email protected] wrote:
> Please let me know anyone aware about the issue
>
>
> Traceback (most recent call last):
> File "testrunner.py", line 447, in 
> testrunner_obj.main()
> File "testrunner.py", line 433, in main
> self.result()
> File "testrunner.py", line 310, in result
> result = runner.run(self.suite)
> File "/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 720,
in run
> test(result)
> File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
> return self.run(*args, **kwds)
> File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
> test(result)
> File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
> return self.run(*args, **kwds)
> File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
> test(result)
> File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
> return self.run(*args, **kwds)
> File "/usr/lib/python2.7/unittest/suite.py", line 100, in run
> self._handleClassSetUp(test, result)
> File "/usr/lib/python2.7/unittest/suite.py", line 153, in _handleClassSetUp
> self._addClassOrModuleLevelException(result, e, errorName)
> File "/usr/lib/python2.7/unittest/suite.py", line 198, in
_addClassOrModuleLevelException
> result.addError(error, sys.exc_info())
> File â £/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 633,
in addError
> output = self.complete_output()
> File â £/autoPyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 591,
in complete_output
> return self.outputBuffer.getvalue()
> AttributeError: '_TestResult' object has no attribute 'outputBuffer'

It's hard to say without seeing all your code, but I notice PyUnit 0.3 in your
traceback.â  If that's the PyUnit I think it is, PyUnit 1.4.1 was released
16(!) years ago, and has been in the standard library as unittest since version
 2.1.â  Are you running ancient versions of your test infrastructure?

--Ned.

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


Re: Increasing the diversity of people who write Python (was:

2017-11-27 Thread nospam . Paul Moore
On 27 November 2017 at 18:13, Skip Montanaro  wrote:
>> If you have a Windows key, you can assign it to be
>> the Compose key.
>
> Would this be true on a machine running Windows? My work environment
> has me developing on Linux, with a Windows desktop. It's not clear to
> me that any sort of xmodmap shennanigans would work. Won't Windows
> itself always gobble up that key?

Programs can access the Windows key. IIRC, there is a utility that provides
compose-key functionality on Windows. I can't recall the name right now and
it's on my other PC, not this one, but I'll try to remember to post the name
tomorrow...

Paul

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


Re: Pros and cons of Python sources?

2017-11-27 Thread nospam . Cameron Simpson
On 26Nov2017 10:00, nospam.Martin SchĶĶn  wrote:
>Den 2017-11-26 skrev Cameron Simpson :
>> On 25Nov2017 08:34, rusi  wrote:
>>>On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote:
 The problem with mixing repository-installed packages with pip-installed
 packages is that there's always a chance a Debian update will overwrite
 a pip package, possibly with an older version.  Or a pip-installed
 package might bring in a new version that's not compatible with some
 debian-installed package, breaking something.
>>>
>>>On (recent?) debian/ubuntu pip seems to use the 'user-scheme'
>>>which means pip runs without sudo and installs in ~/.local/lib
>>>So I dont believe literal overwriting would occur
>>
>> Though the point should be made that one should run pip as oneself, and try
>to
>> avoid doing it as the root user (including avoiding sudo). Many
>UNIX/Linux/etc
>> users believe "installs" should be done as root, and in this case that is
>> easily avoided, with all its potential for damage to the vendor supplied
>> environment.
>
>Hmm, I seem to remember not being able to install packages with pip unless I
>did sudo pip.

And this is exactly what I'm warning about. Many Linux users see some kind of
failure and just stick sudo on the front of the command. It is almost always
the wrong things to do, leading to effects in the OS install area instead of
being safely contained within one's home directory or work area.

Instead of reaching straight for sudo, look at pip's manual or help. You will
find that:

  pip install --user ...

installs modules local to your home directory, avoiding troublesome installs
into the OS area.

Cheers,
Cameron Simpson  (formerly [email protected])

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


Re: connect four (game)

2017-11-27 Thread nospam . Ned Batchelder
On 11/27/17 1:57 PM, bartc wrote:
> On 27/11/2017 17:41, Chris Angelico wrote:
>> On Tue, Nov 28, 2017 at 2:14 AM, bartc  wrote:
>>> JPEG uses lossy compression. The resulting recovered data is an
>>> approximation of the original.
>>
>> Ah but it is a perfect representation of the JPEG stream. Any given
>> compressed stream must always decode to the same output. The lossiness
>> is on the ENcoding, not the DEcoding.
>
> You make it sound as bad as currency calculations where different
> software must produce results that always match to the nearest cent.
>
> We're talking about perhaps +1 or -1 difference in the least
> significant bit of one channel of one pixels. If the calculation is
> consistent, then you will not know anything is amiss.
>
> By +1 or -1, I mean compared with the same jpeg converted by
> independent means.
>
> I also passed the same jpeg through another C program (not mine) using
> its own algorithms. There some pixels varied by up to +/- 9 from the
> others (looking at the first 512 bytes of the conversion to ppm).
>
> Here's my test image:
> https://github.com/bartg/langs/blob/master/card2.jpg (nothing naughty).
>
> Tell me what the definitive values of the pixels in this part of the
> image should be (I believe this corresponds to roughly the leftmost
> 180 pixels of the top line; there are two million pixels in all). And
> tell me WHY you think those are the definitive ones.
>
> Bear in mind also that this is not intended to be the world's most
> perfect software. But it does do a good enough job. And the other two
> Python versions I have, at the minute don't work at all.
>
>

Surely the details of JPEG decompression, and the possible presence of flaws in
 certain decoders, is beyond the scope of this thread?

--Ned.

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


Re: Benefits of unicode identifiers (was: Allow additional separator

2017-11-27 Thread nospam . Rustom Mody
On Monday, November 27, 2017 at 6:48:56 PM UTC+5:30, Rustom Mody wrote:
> Having said that I should be honest to mention that I saw your post first on
> my phone where the î, showed but the gØÜ« showed as a rectangle something
like âî$
>
> I suspect that îö OTOH would have workedâ | dunno

Yeah îö shows whereas gØÜ« doesn't (on my phone) And âî$ does show but much
squatter than the replacement char the phone shows when it cant display a char

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


Re: connect four (game)

2017-11-27 Thread nospam . bartc
On 27/11/2017 17:41, Chris Angelico wrote:
> On Tue, Nov 28, 2017 at 2:14 AM, bartc  wrote:
>> JPEG uses lossy compression. The resulting recovered data is an
>> approximation of the original.
>
> Ah but it is a perfect representation of the JPEG stream. Any given
> compressed stream must always decode to the same output. The lossiness
> is on the ENcoding, not the DEcoding.

You make it sound as bad as currency calculations where different software must
 produce results that always match to the nearest cent.

We're talking about perhaps +1 or -1 difference in the least significant bit of
 one channel of one pixels. If the calculation is consistent, then you will not
 know anything is amiss.

By +1 or -1, I mean compared with the same jpeg converted by independent means.

I also passed the same jpeg through another C program (not mine) using its own
algorithms. There some pixels varied by up to +/- 9 from the others (looking at
 the first 512 bytes of the conversion to ppm).

Here's my test image:
https://github.com/bartg/langs/blob/master/card2.jpg (nothing naughty).

Tell me what the definitive values of the pixels in this part of the image
should be (I believe this corresponds to roughly the leftmost 180 pixels of the
 top line; there are two million pixels in all). And tell me WHY you think
those are the definitive ones.

Bear in mind also that this is not intended to be the world's most perfect
software. But it does do a good enough job. And the other two Python versions I
 have, at the minute don't work at all.


--
bartc

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


Re: I have anaconda, but Pycharm can't find it

2017-11-27 Thread nospam . Miki Tebeka
You need to set the Python interpreter for the project to be the Anaconda one.
See https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html

On Monday, November 27, 2017 at 1:56:58 AM UTC+2, C W wrote:
> Hello all,
>
> I am a first time PyCharm user. I have Python 3 and Anaconda installed.
> They work together on Sublime Text, but not on Pycharm.
>
> Pycharm tells me it cannot find modules numpy, matplotlib, etc.
>
> What should I do? I tried to set the interpreter environment, and a few
> other options, none seem to work.
>
> This is the typical solution, but it does not work
> https://stackoverflow.com/questions/35623776/import-numpy-on-pycharm
>
> Thanks,
>
> -Mike

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


Re: Increasing the diversity of people who write Python (was:

2017-11-27 Thread nospam . Rustom Mody
On Friday, November 24, 2017 at 10:11:24 PM UTC+5:30, Skip Montanaro wrote:
> > Because if I already can't understand the words, it will be more useful
> > to me to be able to type them reliably at a keyboard, for replication,
> > search, discussion with others about the code, etc.
>
> I am probably not alone in my Americo-centric world where I can't even
> easily type accented Latin-1 characters. I happen to be using Linux as
> I type this, but type at a Windows keyboard at work (ugh) and have
> long been a user of Macs (still have one or two at home). Might the
> problem be further multiplied by the number of different ways I have
> of entering text? Would Emacs running on Linux, but displaying on
> Windows be different than Chrome running directly on Linux?

I strongly suspect that any recent emacs will have M-x insert-char (earlier it
was called ucs-insert) default bound C-x 8 RET (yeah thats clunky) which will
accept at the minibuffer input

At which point the hex for ÄC which is e9 can be entered â ö yeah its
unreasonable to expect to remember that! Its more reasonable to remember that
that is an e acute; And e itself is a latin lower case letter All of which
becomes entering (in the minibuffer) LATIN SMALL LETTER E ACUTE
- upper case not required; emacs will upcase it for you
- And will also provide some tab/star expansion help
ie *letter e acuteTAB
expands to
LATIN *L LETTER E ACUTE
Further TAB-prodding will give you these choices LATIN CAPITAL LETTER E ACUTE
(Äë)   LATIN CAPITAL LETTER E WITH ACUTE (Äë)
LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND ACUTE (áº1)
LATIN CAPITAL LETTER E WITH MACRON AND ACUTE (á,û)
LATIN SMALL LETTER E ACUTE (ÄC) LATIN SMALL LETTER E WITH ACUTE (ÄC)
LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE (ế)
LATIN SMALL LETTER E WITH MACRON AND ACUTE (á,ù)

You could go one step more sophisticated and use TeX-input method (C-x RET C-\)
After which \'e will collapse as ÄC
â £Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!â Ø you may ask
Trueâ | So as you rightly do,
- pick it up from google
- put emacs into tex input mode
- paste from google into emacs
- place point on the new char and type C-u C-x =
  Among other things emacs will helpfully inform you (among other things)
  to input: type "\'{e}" or "\'e" with TeX input method

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


Re: connect four (game)

2017-11-27 Thread nospam . Chris Angelico
On Mon, Nov 27, 2017 at 3:04 PM, Rustom Mody  wrote:
>> Aviators have pinned down the best solution to this, I think. A pilot
>> is not expected to be perfect; he is expected to follow checklists. A
>> preflight checklist. A departure checklist. A landing checklist.
>> Everything that needs to be done right is mentioned on the list, and
>> you just go through the list and make sure you've done everything.
>
> And thats where the analogy breaks down.
> Presumably a 50 person short-flight and a 600-person transcontinental may
have
> at least something in common in their pilot-checklists
> What common will you find in a multi-million line OS, a thousand line script
> and a student prime-numbers first-program?

You locate a pure function. I can pretty much guarantee that the first two will
 have a number of them, and the third one may or may not, but almost certainly
should. Pure functions are the easiest to unit-test. Then you build up from
there.

> No I am not dissing on testing and TDD; just that universalityâ1 of computing
devices
> is something that our civilization is nowhere near understanding, leave alone
> dealing with â ö two programs can be more far apart than a bullock cart and a
jet.
> And yet they are both programs

... so?

> â1 Ive seen CS PhDs ask a student why a student didnt incorporate some
error-checking
>   into his compiler which amounted to solving the halting problem.
>   More mundanely I see students have a hard time seeing their phones and
their
>   laptops as 'the same'

Again: so? Testing methodologies don't require that.

ChrisA

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


I guess I'd better plonk anything From: nospam.*

2017-11-27 Thread Grant Edwards
At least the phase delay through the feedback loop appears to be many
hours.  That should postpone disaster for a few days...

-- 
Grant Edwards   grant.b.edwardsYow! I'm sitting on my
  at   SPEED QUEEN ... To me,
  gmail.comit's ENJOYABLE ... I'm WARM
   ... I'm VIBRATORY ...

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


Re: How to shut down a TCPServer serve_forever() loop?

2017-11-27 Thread Ian Kelly
On Sat, Nov 25, 2017 at 7:10 AM, John Pote  wrote:
> Hi all,
>
> My problem in summary is that my use of the shutdown() method only shuts
> down a server after the next TCP request is received.
>
> I have a TCP server created in the run() method of a thread.
>
> class TCPlistener( Thread ):
> def run( self ):
>with socketserver.TCPServer(  ("localhost", ), ConnHandler )
> as server:
> self.server = server
> print( "TCP listener on: %s:%d" % ( self.host, self.port ) )
> self.server.serve_forever()
>
> print( "TCPlistener:run() ending" )
>
> ConnHandler is a simple echo class with only a handle() method
>
> The main bit of the program is
>
> if __name__ == "__main__":
> serverThrd = TCPlistener()
> serverThrd.start()#start TCP IP server listening
> print("server started")
>
> ch = getche()#wait for key press
> print()
> serverThrd.server.shutdown()
>
> print( "main ending" )
>
> Everying works as expected, numerous connections can be made and the
> received text is echoed back.
>
> The issue is that if I press a key on the keyboard the key is immediately
> shown on the screen but then the shutdown() call blocks until another TCP
> connection is made, text is echoed back and only then does
> serve_forever()return followed by shutdown()returning as can be seen from
> the console session,
>
>>>python36 TCPIPserver.py
> server started
> TCP listener on: localhost:
> q #pressed 'q' key
> 127.0.0.1 wrote: #Sent some text from PuTTY
> b'SOME TEXT'
> TCPlistener:run() ending
> main ending
>
> How can I get shutdown()to shut down the server immediately without waiting
> for the next TCP connection?

Make a connection to the server after calling shutdown to wake up the
server's event loop? I'm guessing it only checks the shutdown flag
after responding to an event, so there's probably not much else you could do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pros and cons of Python sources?

2017-11-27 Thread Cameron Simpson

On 27Nov2017 20:20, Martin Schöön  wrote:

Den 2017-11-26 skrev Cameron Simpson :

On 26Nov2017 10:00, nospam.Martin Schöön  wrote:

Hmm, I seem to remember not being able to install packages with pip unless I
did sudo pip.


And this is exactly what I'm warning about. Many Linux users see some kind of
failure and just stick sudo on the front of the command. It is almost always
the wrong things to do, leading to effects in the OS install area instead of
being safely contained within one's home directory or work area.

Instead of reaching straight for sudo, look at pip's manual or help. You will
find that:

  pip install --user ...

installs modules local to your home directory, avoiding troublesome installs
into the OS area.


Guilty as charged.

So, how do I restore order in my Python 2.7 installation? Uninstall
everything that looks, smells and tastes like Python 2.7 and then
re-install?


Depeneds on your OS/distro. Redhat's RPM used to have some kind of --verify 
option to compare package definitions aginst what was physically present.


But if the package is mainstream you're probably ok? You could just live with 
it and do no more damage.


Otherwise, look to see what python packages are installed which you think you 
may have pipped, and reinstall those. But also, pip tends not to install things 
that are already present, so you might be fine.


Cheers,
Cameron Simpson  (formerly [email protected])
--
https://mail.python.org/mailman/listinfo/python-list


Re: I have framework on python with pyunit, facing below issue while

2017-11-27 Thread Ben Finney
[email protected] (jaya birdar) writes:

> Please let me know anyone aware about the issue

Please let us know about the issue.

* What Python is this? Installed how? Running on what platform?

* What code base is this? What is a simple complete, executable example
  http://www.sscce.org/> that *we* can run to see the same behaviour?

* What expectation did you have for the code when you run it? What is
  the behaviour it should show, and how is that different from what you
  got?

* What other possibly unusual context does this code have, that we might
  need to know about to understand what's happening?

-- 
 \ “If you're not part of the solution, you're part of the |
  `\  precipitate.” —Steven Wright |
_o__)  |
Ben Finney

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


Please disable “digest” mode to participate (was: Python-list Digest, Vol 170, Issue 34)

2017-11-27 Thread Ben Finney
nospam."ROGER GRAYDON CHRISTMAN"  (ROGER GRAYDON CHRISTMAN)
writes:

> I'll answer your question with a couple questions:

Roger, your messages often are not replies to the original message, but
replies to a “digest” composed by the mailing list.

The digest messages are useful, but only for the recipient as a
read-only digest. Enabling “digest” mode is only for when you are
*certain* that you will never at any point need to respond to any
message from the forum. That's not true, so should be turned off.

Message digests are not useful if you want to participate in the forum:
your replies are to messages we've never seen, they do not thread
correctly, and you have a lot of additional clean-up to do in the quoted
material. This is all making it harder for you to participate in the
forum.

Instead: go to your settings in the mailing list subscription, and
disable “digest” mode. You will then be able to respond directly to
specific messages when they arrive, the same ones the rest of us see and
have in threaded discussions.

-- 
 \ “I went to a fancy French restaurant called ‘Déjà Vu’. The head |
  `\  waiter said, ‘Don't I know you?’” —Steven Wright |
_o__)  |
Ben Finney 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nospam ** infinity?

2017-11-27 Thread Skip Montanaro
>> Newsreader configuration problem?
>
> More likely, someone was trying to obscure the email addresses, but managed to
> tag my name instead. Definitely looks like some sort of automation failure. 
> The
>  only question is, whose? If it's not from gate_news, there's someone here on
> the list/ng that is (probably accidentally) reposting everything.

I'm 99.5% certain it's not gate_news. It's always been running. The
only thing Mark and I changed was to get SpamBayes running again as
part of gate_news. Its only effect on a message is to add relevant
headers (typically X-Spam-Evidence and X-Spam-Status). It never
modifies existing headers.

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


Re: nospam ** infinity?

2017-11-27 Thread Skip Montanaro
> I'm 99.5% certain it's not gate_news.

A funny thing. All messages I have looked at so far with the "nospam"
thing have a Message-ID from binkp.net. (They are also all Usenet
posts.) For example:

Newsgroups: comp.lang.python
Subject: Re: I have anaconda, but Pycharm can't find it
Date: Sun, 26 Nov 2017 22:40:00 +1200
Organization: Agency BBS, Dunedin - New Zealand | bbs.geek.nz
Message-ID: <[email protected]>
Mime-Version: 1.0

Any ideas how to investigate further?

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


Re: Increasing the diversity of people who write Python

2017-11-27 Thread Alexandre Brault
A quick Google search turned up WinCompose. It defaults to Right-Alt for
its compose key, but that's configurable


On 2017-11-27 02:05 PM, Paul Moore wrote:
> On 27 November 2017 at 18:13, Skip Montanaro  wrote:
>>> If you have a Windows key, you can assign it to be
>>> the Compose key.
>> Would this be true on a machine running Windows? My work environment
>> has me developing on Linux, with a Windows desktop. It's not clear to
>> me that any sort of xmodmap shennanigans would work. Won't Windows
>> itself always gobble up that key?
> Programs can access the Windows key. IIRC, there is a utility that
> provides compose-key functionality on Windows. I can't recall the name
> right now and it's on my other PC, not this one, but I'll try to
> remember to post the name tomorrow...
>
> Paul

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


While, If, Count Statements

2017-11-27 Thread nospam . Cai Gengyang

Input :

count = 0

if count < 5:
  print "Hello, I am an if statement and count is", count

while count < 10:
  print "Hello, I am a while and count is", count
  count += 1

Output :

Hello, I am an if statement and count is 0 Hello, I am a while and count is 0
Hello, I am a while and count is 1
Hello, I am a while and count is 2
Hello, I am a while and count is 3
Hello, I am a while and count is 4
Hello, I am a while and count is 5
Hello, I am a while and count is 6
Hello, I am a while and count is 7
Hello, I am a while and count is 8
Hello, I am a while and count is 9

The above input gives the output below. Why isn't the output instead :

Hello, I am an if statement and count is 0 Hello, I am a while and count is 0
Hello, I am an if statement and count is 1 Hello, I am a while and count is 1
Hello, I am an if statement and count is 2 Hello, I am a while and count is 2
Hello, I am an if statement and count is 3 Hello, I am a while and count is 3
Hello, I am an if statement and count is 4 Hello, I am a while and count is 4
Hello, I am a while and count is 5
Hello, I am a while and count is 6
Hello, I am a while and count is 7
Hello, I am a while and count is 8
Hello, I am a while and count is 9

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


Re: Benefits of unicode identifiers (was: Allow additional separator in identifiers)

2017-11-27 Thread Peter J. Holzer
On 2017-11-24 04:52:57 +0100, Mikhail V wrote:
> On Fri, Nov 24, 2017 at 4:13 AM, Chris Angelico  wrote:
> > On Fri, Nov 24, 2017 at 1:44 PM, Mikhail V  wrote:
> >> From my above example, you could probably see that I prefer somewhat
> >> middle-sized identifiers, one-two syllables. And naturally, they tend to
> >> reflect some process/meaining, it is not always achievable,
> >> but yes there is such a natural tendency, although by me personally
> >> not so strong, and quite often I use totally meaningless names,
> >> mainly to avoid visual similarity to already created names.
> >> So for very expanded names, it ends up with a lot of underscores :(
> >
> > Okay. So if it makes sense for you to use English words instead of
> > individual letters, since you are fluent in English, does it stand to
> > reason that it would make sense for other programmers to use Russian,
> > Norwegian, Hebrew, Korean, or Japanese words the same way?
> 
> I don't know. Probably, especially if those *programmers* don't know latin
> letters, then they would want to write code with their letters and their
> language. This target group, as I said, will have really hard time
> with programming,

I don't think that's the target group. As you say, if you don't know
latin letters you'll have a hard time with Python (or almost any
programming language). You can't read the keywords or the standard
library function names.

I think the target group is people who can read the latin alphabet and
probably also at least a bit of English, but who are working on in-house
projects.

As a very simple example, many years ago, when I was still at the
university, we decided that we needed a program to manage our students.
So we got some students to write one ;-). As a general rule, identifiers
and comments for all projects had to be in English, which generally made
a lot of sense since we collaborated with institutes in other countries.
But for that project that rule wasn't really appropriate, as we noticed
when one of the students asked us what "Matrikelnummer" is in English.
Nobody knew, so we consulted a dictionary and apparently it's
"enrollment number". Simple enough, but is that intelligible to all
English speakers or is it specific to British universities? And even
worse - whoever is going to maintain that code would be either a staff
member or a student of our institute - they would certainly know what a
"Matrikelnummer" is, but would they understand that enrollment_number is
supposed to contain that? So we decided that domain specific jargon
should not be translated. A bit of bilingual mishmash (first_name and
course_title, but matrikelnummer and kennummer) was better than using
words that knowbody understood.

Now that particular word doesn't contain any non-ASCII characters and
German has only 4 letters not in ASCII, and for all of them there are
official ASCII substitutes, so writing German words in ASCII isn't a
problem.

But for languages with non-latin alphabets (or just a higher density of
accented letters) that's different. If my native language was Russian
and I was writing some in-house application for a Russian company which
contained a lot of Russian company jargon which can't be easily
translated to English (and back), I'm quite sure that I would prefer to
write that jargon in cyrillic and not in some transliteration.

> and in Python in particular, because they will be not only forced to learn
> some english, but also will have all 'pleasures' of  multi-script editing.
> But wait, probably one can write python code in, say Arabic script *only*?
> How about such feature proposal?

There is source filter which lets you write Perl in traditional Chinese.
This even changes the syntax to be closer to Chinese syntax. There is
also one which lets you write Perl in Latin (obviously that uses the
Latin alphabet, but it changes the syntax even more). Don't know whether
something like this is possible in Python, but arguably the result
wouldn't be Python any more (just like Lingua::Romana::Perligata isn't
really Perl - it just happens to be implemented using the Perl
interpreter).


> Ok, so we return back to my original question: apart from
> ability to do so, how beneficial is it on a pragmatical basis?

When I use German identifiers (which I generally don't) I do use
umlauts. When I need to do some physical computations, I might use greek
letters (or maybe not - as a vim user I can type Δt easily enough, but
can the colleague using PyCharm on Windows? I have no idea). So for me
the benefit is rather small. But as I said, German is almost
ASCII-compatible.

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | [email protected] | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


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


Re: Stopping an iterator and continuing later

2017-11-27 Thread nospam . Gregory Ewing
november nihal wrote:
> I should have added I switch off the machine when I stop. ( I dont have
options
>  to keep it in a sleep mode or in hibernation )

The iterator returned by itertools.combinations is pickleable:

 >>> from pickle import dumps, loads
 >>> from itertools import combinations
 >>> c = combinations([1,2,3,4,5], 2)
 >>> next(c)
(1, 2)
 >>> next(c)
(1, 3)
 >>> next(c)
(1, 4)
 >>> s = dumps(c)
 >>> d = loads(s)
 >>> next(d)
(1, 5)

--
Greg

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


  1   2   >