Re: Noob in Python. Problem with fairly simple test case

2015-07-21 Thread Chris Angelico
On Wed, Jul 22, 2015 at 3:38 AM, Jason P.  wrote:
> Despite the impression that surely I gave, I'm quite familiar with 
> programming and general bug hunting rules. The problem is that I'm 
> inexperienced with Python and the subtle details of multiple threads ;)
>

Heh, it doesn't hurt to remind people of basic debugging techniques
sometimes. Worst case, you come back and say "Yep, I tried that, and
here's the result". Best case, someone else (who doesn't know what you
know) will come along with a superficially similar problem, will see
the suggested technique, and even if the actual issue is quite
different, will be better able to diagnose it.

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-21 Thread Jason P.
El miércoles, 15 de julio de 2015, 14:12:08 (UTC+2), Chris Angelico  escribió:
> On Wed, Jul 15, 2015 at 9:44 PM, Jason P.  wrote:
> > I can't understand very well what's happening. It seems that the main 
> > thread gets blocked listening to the web server. My intent was to spawn 
> > another process for the server independent of the test. Obviously I'm doing 
> > something wrong. I've made several guesses commenting pieces of code 
> > (tearDown method for example) but I didn't manage to solve the problem(s).
> >
> 
> When you find yourself making guesses to try to figure out what's
> going on, here are two general tips:
> 
> 1) Cut out as many pieces as you can. Test one small thing at a time.
> 2) If In Doubt, Print It Out! Stick print() calls into the code at key
> places, displaying the values of parameters or the results of
> intermediate calculations - or just saying "Hi, I'm still here and I'm
> running!".
> 
> For #1, I would recommend first just trying to get the web service
> going. Can you connect (using an external program) on port 8000 and
> receive a text/plain HTTP response saying "Hello World!"? Never mind
> about the test for the moment.
> 
> And for #2, judicious placement of console output will help you figure
> out things you're not sure about. For instance, you're suspecting that
> the main thread is getting blocked handling the web server. Easy way
> to check:
> 
> def setUp(self):
> # Start the forecast server
> self.server = ForecastServer()
> self.server.start(webservice.app)
> 
> Just before you construct the server, print something out. After
> you've constructed it but before you call start(), print something
> out. And after starting it, print something out. Then run the program.
> If you see the first line and no other, then it's blocking during the
> construction. Other deductions I'm sure you can figure out.
> 
> One small point: Probe even things that you think are trivial. In the
> above example, I cannot see any reason why constructing
> ForecastServer() could possibly block, because its init does nothing
> but set a flag. But you can get surprised by things sometimes - maybe
> the problem is actually that you're not running the code you think you
> are, but there's some other ForecastServer kicking in, and it's
> synchronous rather than subprocess-based.
> 
> End-to-end testing is all very well, but when something goes wrong,
> the key is to break the program down into smaller parts. Otherwise,
> all you have is "it doesn't work", which is one of the most useless
> error reports ever. If someone comes to python-list saying "it doesn't
> work", we'll be asking him/her to give a lot more details; if your
> aunt asks you for help printing out a document because "it doesn't
> work", you'll probably have to go over and watch her attempt it; and
> it's the same with your test cases - you make them tell you more
> details.
> 
> Hope that helps! The techniques I'm offering are completely
> problem-independent, and even language-independent. IIDPIO debugging
> works in anything that gives you a console, which is pretty much
> everything - maybe it won't be print() but logging.debug(), but the
> same technique works.
> 
> ChrisA


Thanks for your comments Chris.

I've come back to the problem today after a few days on trip. Fortunately 
someone in other mailing list pointed me that the join method was hanging the 
main thread. Without this inconvenience I can focus on the exercise's main goal.

Despite the impression that surely I gave, I'm quite familiar with programming 
and general bug hunting rules. The problem is that I'm inexperienced with 
Python and the subtle details of multiple threads ;)

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


Off-topic: Europe [was Re: Noob in Python. Problem with fairly simple test case]

2015-07-19 Thread Steven D'Aprano
On Mon, 20 Jul 2015 03:25 am, Rick Johnson wrote:

> On Sunday, July 19, 2015 at 4:18:31 AM UTC-5, Laura Creighton wrote:
>> And, despite Norway not being part of the EU, Scandinavia
>> is still in Europe.
> 
> This is a bit off topic: But i don't consider Scandinavia to
> be a part of the EU. 

Laura didn't say that Scandinavia (Finland, Sweden, Norway, Denmark) is part
of the European Union (a political union), she explicitly stated that
Norway is not. But it is part of Europe, which is a geographical area that
runs from Ireland to the Ural mountains in Russia, from the Mediterranean
to the Arctic Circle.

> Not anymore than i would consider 
> America to be a part of the EU. Sure, we're all colloquially
> known as "the west", 

"The West" has nothing to do with this. But for the record, "the West"
includes Australia and New Zealand, which are in the south-east.

> The only ubiquitous
> binding agent between all the member countries is the
> existential need to conglomerate military power against foes
> in the east.

You're thinking of NATO. The EU is primarily a political union designed to
reduce the cost of business when dealing with other European countries. If
it has any military influence, it is that countries that allow free trade
and travel between themselves are less likely to war on each other than
those that don't. Germany is less likely to invade France again, so long as
German business and French business are all part of the same business. At
least the sort of war that involves actual shooting.

[Disclaimer: countries that have little or no contact at all are even less
likely to go to war against each other.]


> Beyond that, the union is superficial at best. 
> If the bailout fails, or another worldwide financial crisis
> hits, the outcome could be disastrous for the EU.

Actually, the best thing for the EU right now would probably be for Greece
to withdraw from the Euro and float their own currency, but otherwise
remain in the EU. Not only would that be the best outcome for Greece, but
it would give the German bureaucrats and the Troika a kick to the seat of
their pants for attempting to interfere in the democratic process. 


> When those pension checks stop coming in the mail, people get
> violent!

The pension cheques stopped coming about 18 months ago, and despite
austerity, despite putting millions of people out of work, despite sticking
a railway spike into the Greek economy (or perhaps because of these three
factors) Greece owes more money now than it did when the Germans declared
economic war on them on behalf of the banks.


-- 
Steven

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-19 Thread Laura Creighton
In a message of Sun, 19 Jul 2015 10:25:35 -0700, Rick Johnson writes:
>On Sunday, July 19, 2015 at 4:18:31 AM UTC-5, Laura Creighton wrote: 
>> And, despite Norway not being part of the EU, Scandinavia
>> is still in Europe.
>
>This is a bit off topic: But i don't consider Scandinavia to
>be a part of the EU. Not anymore than i would consider
>America to be a part of the EU.

Well, that makes one of you. The significant number of people
who want to pull Sweden out of the EU still have a lot of work
ahead of them before ignoring laws that come from Brussels is
in my future.  But in or out of the EU, Sweden will still be in Europe.

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-19 Thread MRAB

On 2015-07-19 18:25, Rick Johnson wrote:

On Sunday, July 19, 2015 at 4:18:31 AM UTC-5, Laura Creighton wrote:

And, despite Norway not being part of the EU, Scandinavia
is still in Europe.


This is a bit off topic: But i don't consider Scandinavia to
be a part of the EU. Not anymore than i would consider
America to be a part of the EU. Sure, we're all colloquially
known as "the west", but large ideological and social design
structures exist between the members. And besides, there is
a great possibility that the EU could implode on itself.


[snip]

Denmark and Sweden are _both_ members of the EU.

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-19 Thread Rick Johnson
On Sunday, July 19, 2015 at 4:18:31 AM UTC-5, Laura Creighton wrote: 
> And, despite Norway not being part of the EU, Scandinavia
> is still in Europe.

This is a bit off topic: But i don't consider Scandinavia to
be a part of the EU. Not anymore than i would consider
America to be a part of the EU. Sure, we're all colloquially
known as "the west", but large ideological and social design
structures exist between the members. And besides, there is
a great possibility that the EU could implode on itself. 

Take for instance the disaster of Greece, with many other
large players teetering on the edge. The only ubiquitous
binding agent between all the member countries is the
existential need to conglomerate military power against foes
in the east. Beyond that, the union is superficial at best.
If the bailout fails, or another worldwide financial crisis
hits, the outcome could be disastrous for the EU. 

When those pension checks stop coming in the mail, people get
violent!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Noob in Python. Problem with fairly simple test case

2015-07-19 Thread Laura Creighton
In a message of Sat, 18 Jul 2015 16:18:57 -0700, Rick Johnson writes:
>I'll have to admit you make a good point here. Although the
>argument is diminished by observing that Ruby is far more
>popular in Asia than Python. Python seems to be mainly a
>Scandinavian, European, and American toy. For the most part
>anyway. There are always exceptions to any rule. I mean,
>think about it: who besides Xah Lee has an Asian name here?
>And it's been years since we've heard from him! O:-D

This is because this is an english-speaking mailing list, not
because people who don't speak English aren't using Python.  Being
here isn't much of an indicator.  And, despite Norway not being
part of the EU, Scandinavia is still in Europe.

Laura

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-18 Thread Rick Johnson
On Friday, July 17, 2015 at 5:46:01 PM UTC-5, Terry Reedy wrote:
> But these relative numbers are, as near as I can tell,
> restricted to the english-speaking world, perhaps extended
> to the latin-1 based world. Anyone who wants unicode
> identifiers must use Python 3 (or a translated Python like
> ChinesePython).  Anyone seriously working with Unicode
> will find 3.3+ more pleasant, if not required (especially
> on Windows).

I'll have to admit you make a good point here. Although the
argument is diminished by observing that Ruby is far more
popular in Asia than Python. Python seems to be mainly a
Scandinavian, European, and American toy. For the most part
anyway. There are always exceptions to any rule. I mean,
think about it: who besides Xah Lee has an Asian name here?
And it's been years since we've heard from him! O:-D

> On Amazon, the first hit for 'Japanese Python' is Dive
> into Python 3 (Japanese edition).  As near as I can tell,
> there is no Japanese edition for the original Dive into
> Python (2).  As I remember, half the Python books I saw in
> Japan *3 years ago* were for Python 3.
> 
> Overall, I suspect that Python 3 penetration is greater in
> Asia.

I would agree with that assessment, simply because of the
Unicode factor. But i don't believe it's a "large
audience". And don't get me wrong, i'm not wishing for the
numbers to go one way or another. I just simply want to find
the truth.

> Rick, I only care about porting of public libraries.
> Leave your private code in Python 2.  Continue writing new
> code in Python 2 if you wish.  I only object to those who
> pressure others to not port to or writes in Python 3.

I don't want to pressure anyone in either direction. We, as
the greater python community, did not vote to break
backwards compatibility, it was dropped on us like an Acme
anvil. But what we _can_ choose, is the version that suits
our needs best. I have chosen to remain with 2.x. I
encourage others to decide for themselves. I don't think
pushing 3.x is any less evil than pushing 2.x -- unless the
programmer is a python neophyte. In that case, go with 3.x.

> If you want to help 2.7 become better, we need people test
> and backport patches to 2.7. Since 2.x bugs me as much as
> 3.x seems to bug you, I am considering not backporting
> until someone volunteers to help.

What do you need help with? Can you be more specific? Of
course, a few people on this list are under the impression
that i cannot write Python code unless Tkinter is imported
first. I guess they think Tkinter is some sort of "magic
module" that endows it's importer with mad skills (such as
those i posses). Or, it could be that they're unwilling to
give me any credit. Who knows? I never did participate in
office politics anyway. I'm always too busy getting things
done!

> Now my question for you or anyone else: If the vast
> majority of Python programmers are focused on 2.7, why are
> volunteers to help fix 2.7 bugs so scarce?  Does they all
> consider it perfect (or sufficient) as is? Should the core
> developers who do not personally use 2.7 stop backporting,
> because no one cares if they do?

My guess is that most have become disenfranchised. Perhaps
some have moved to other languages. Perhaps some are
surviving on old code annuities and don't need to work
anymore. The number of programmers in this world is very
small, and Python programmers represent a very small subset
of _that_ small subset. Which means, small numerical losses
can result in extreme damage to the "intellectual fortitude"
of a community like ours. The days when the Python community
could spare a few minds is over, -- as we have entered an era
of Pythonic depression. Perhaps one day we'll look back on
these tough times and tell fabulously exaggerated stories of 
how rugged individualism, and a pinch of community spirit, 
freed the world from the dark clutches of evil.

  HISTORY IS DEFINED BY THE WINNERS

Let me know where i can be of assistance. It's always a
great pleasure to make utter fools of my rivals. >:-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Noob in Python. Problem with fairly simple test case

2015-07-18 Thread Rick Johnson
On Friday, July 17, 2015 at 3:39:02 PM UTC-5, Laura Creighton wrote:
> I think kivy is doing a very nice job of python-on-the-mobile.
> Have you looked?  Please do not rant at me, just tell me what you
> think.

Hello Laura,

I'm not sure if you're replying to me (as there is no quoted
context) but since you mentioned "rant" i "suppose" that you 
could be referring be me? I mean, i don't know what gave you 
the impression that i would rant at anyone? But don't worry 
dear, i've always self-censored my rants when females are 
listening -- oops, gonna get some flac for that comment! O:-)

First off. I don't remember seeing you here before. So allow 
me to say that having a female presence in this group is quite
refreshing. I hope you continue to participate!

Also, I have a lot to say on this subject, and most of what
i say below is intended as a "general response", so please 
don't take any of my words as a personal attack. Thanks.


 Regarding Kivy


I was not aware of this project until you mentioned it.
However, i'm skeptical because: (1) it will suffer from 
latency issues, especially on the mobile platforms, and (2) 
but even if not, i feel projects like this are only 
encouraging the stagnation of our evolution towards 
multi-device compatibility.


 The road to enlightenment is paved with introspection


For the last few decades we have been consumed with the task
of bringing multi-platform-ism to every language or API or
software or whatever. And this was a noble pursuit indeed!

HOWEVER,

We are now moving into a new age. Not of cross-platform-ism
(where we want to write code *ONCE* and have it run on
Linux, Windows, and Mac) but were we want to write code
*ONCE* and have it run on a desktop, or a notebook, or a
phone, or a watch, or a refrigerator, or even a HUD in our 
spaceship!

I believe it's high time that we move away from religious
ideologies codified in "selfish syntaxes" and "selfish
interfaces". 

Because, we seek out these segregating policies just so we 
can say "hey, we're different", when in reality, we're
all the same underneath.

For example: printing to stdout is printing to stdout -> no
matter what syntax you choose to use. Likewise, iterating
over a collection of items, or creating an object that
implements the OOP paradigm, or writing a stream into a
storage medium -> the fundamentals of these concepts do not
change simply by plastering them with selfish identities.
Neither is the concept of a GUI window any different if that
window was created in Windows, Linux, or Mac.

I could provide example after example (ad nauseum) of how
we're creating these selfish syntaxes and selfish
interface, but i think you get the point.

This "need to fulfill" the underlying selfish desires that
we, as humans harbor, is preventing us (as programmers,
software engineers, hardware producers, and most importantly
-> end users) from reaching computing Nirvana. No programmer
should ever need to re-write the same code numerous times so
that it can run on multiple devices.  We, are injecting
needless superfluity into this system. And for no more
reason than our need to fulfill selfish desires!

Why are we *NOT* working together to create a single, linear,
and scaleable system of producing software, A system that
compiles all the best ideas, and throws the remainder into
the refuse bin of history.

The only system i've seen that has made *ANY* attempt  (as
feeble as it may be) is DHTML. But even with it's modern
look and feel, it lacks the necessary hooks into the diverse
platforms to get any "real work" done. However, utilizing
the Trojan horse of "browser ubiquity", and expanding on it,
may be much less work than rebuilding the entire system from
the ground up (something to ponder...)

Most of what we're doing, in the programming language design
field, is fighting over who's version of "superficial CSS"
is going to be the official version. Our partisan efforts
are merely adolescent accessorizing. But we lack the
introspective ability to notice the vanity and futility of 
our efforts.

If you want to know why i rant so much, it's because i'm
both saddened and angry that we waste our time on these
petty battles. When, in fact, we could achieve greatness by
working towards a common goal.


 Utopia's eventually fail Rick!


I'm aware of that! I'm aware that "conflict" is the
invisible force that breathes life into the cogs of
evolution. But your superficial understanding of my proposal
is not a failure of my proposal. ON THE CONTRARY!

For example. We can *ALL* remember how every cell phone
manufacture had their own selfish implementation of a
charging

Re: Noob in Python. Problem with fairly simple test case

2015-07-17 Thread Emile van Sebille

On 7/17/2015 3:45 PM, Terry Reedy wrote:


Now my question for you or anyone else: If the vast majority of Python
programmers are focused on 2.7,


I consider myself in this group.


why are volunteers to help fix 2.7 bugs so scarce?


perhaps the bugs that are show stoppers are providing the impetus to 
move forward to 3.x rather than fix?  This may be an argument to stop 
back-porting fixes.  (security bugs being the exception)



Does they all consider it perfect (or sufficient) as is?


I have a number of one-off projects in place and running without issues 
on python versions all the way back to probably 1.52 (it's turtles all 
the way down)  In all cases, the python version is perfect (or 
sufficient) as it sits.  I do continue to support the applications and 
find myself writing mostly in some common core level of 2.x.



Should the core developers who do not personally use 2.7 stop
backporting, because no one cares if they do?


That'd work for me.  I'm not looking to upgrade the python versions of 
functioning productive code.  Of course, neither are my customers 
looking to pay for me to f*ck^h^h^h^hupgrade up their non-buggy systems.


Emile





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


Re: Noob in Python. Problem with fairly simple test case

2015-07-17 Thread Terry Reedy

On 7/17/2015 12:15 AM, Rick Johnson wrote:

On Thursday, July 16, 2015 at 9:44:56 PM UTC-5, Steven D'Aprano wrote:

[...] My take from all this is that overall, Python 3
take-up is probably > around 10% of all Python users,


All that rambling just to agree with me? My educated guess
is a minimum of 75% still using Python2.x.


I would call that a strong majority.


But i'll take your 90% because it makes my argument stronger! O:-D


Unlike Chris, I would see that as a 'vast majority'.

But these relative numbers are, as near as I can tell, restricted to the 
english-speaking world, perhaps extended to the latin-1 based world. 
Anyone who wants unicode identifiers must use Python 3 (or a translated 
Python like ChinesePython).  Anyone seriously working with Unicode will 
find 3.3+ more pleasant, if not required (especially on Windows).


On Amazon, the first hit for 'Japanese Python' is Dive into Python 3 
(Japanese edition).  As near as I can tell, there is no Japanese edition 
for the original Dive into Python (2).  As I remember, half the Python 
books I saw in Japan *3 years ago* were for Python 3.


Overall, I suspect that Python 3 penetration is greater in Asia.

Rick, I only care about porting of public libraries.  Leave your private 
code in Python 2.  Continue writing new code in Python 2 if you wish.  I 
only object to those who pressure others to not port to or writes in 
Python 3.


If you want to help 2.7 become better, we need people test and backport 
patches to 2.7. Since 2.x bugs me as much as 3.x seems to bug you, I am 
considering not backporting until someone volunteers to help.


Now my question for you or anyone else: If the vast majority of Python 
programmers are focused on 2.7, why are volunteers to help fix 2.7 bugs 
so scarce?  Does they all consider it perfect (or sufficient) as is? 
Should the core developers who do not personally use 2.7 stop 
backporting, because no one cares if they do?


--
Terry Jan Reedy

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-17 Thread Mark Lawrence

On 17/07/2015 21:38, Laura Creighton wrote:

I think kivy is doing a very nice job of python-on-the-mobile.
Have you looked?  Please do not rant at me, just tell me what you
think.

Laura



At least rr occasionally comes out with something useful, usually WRT 
tkinter.  He's in the bottom division when compared to the RUE, who is 
still managing to get onto gg with his complete nonsense.  I'll admit I 
enjoy tripping over there just to report him.


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

Mark Lawrence

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-17 Thread Laura Creighton
I think kivy is doing a very nice job of python-on-the-mobile.
Have you looked?  Please do not rant at me, just tell me what you
think.

Laura

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-17 Thread Rick Johnson
On Friday, July 17, 2015 at 1:38:52 AM UTC-5, Steven D'Aprano wrote:
> 75% or 90% is not a "vast majority". Vast majority implies more than 99%.
> 
> But regardless of the precise meaning of "vast", if you want to dismiss one
> in four people (25%) or one in ten (10%) as inconsequential, then you've
> got some serious issues.

My estimate was *CONSERVATIVE* Steven. Read my words:
"EDUCATED GUESS". Unlike you, I'm not going to falsify the
numbers just to win an argument. I feel very strongly about
the 75%, even though i know the percentage is much higher.

> You can't "risk" the upgrade? What precisely are you afraid of?

Simple. I don't want to waste even a second of time
debugging old code that has been bug free for years. I would
rather spend that time writing new code. Productivity is
important to "some" of us Steven!

And don't drag out that old cliche about how running 2to3 is
the path to lands of "milk and honey". I call BS! With the
nonrestrictive typing of Python a bug can be hidden from even
the best testing methodology. Why would i risk exception hell
just to please you? I don't make my decisions based on your,
or the BDFL's, opinions of what is best for me. Heck, i
don't make my decisions based on what "might" be good for
the Python community. MY CODE! My RULES! GOT IT?

> That's nonsense. Spinning tires implies no forward motion.
> Python 3 usage is *certainly* moving forward: we've gone
> from the situation in 2008 of nobody using it, to the
> current situation where there's lots of activity around
> it:

How much of that is purely hype? Remember the explosion of
Python usage *BEFORE* Python3? However, there
has been a steady decline of Python usage since.

> students learning on Python 3, 

You act as if *EVERY* student that ever uses Python will
continue using Python forever, and *ONLY* Python! When in
fact, Python is mostly a stepping stone for CS-101 students
on their path to real languages like C, Java, DHTML, and the
APIs of the various mobile platforms. *THIS* is where code is
written to solve real life problems. *THIS* is where code
directly interacts with the *VAST MAJORITY* (yeah i said it!)
of humans on this planet to get stuff done! But where's Python? 

Oh, i know, it's stuck on my desktop. @_@

PYTHON IS A ONE TRICK PONY!

> My guess is, the rate of Python 3 adoption is going to hit
> the tipping point in 2 or 3 years, after which time it
> will be *very* rapid.

THE INTERNET WILL REMEMBER YOUR PREDICTION!

A lot can happen in 2-3 years that may render Python
obsolete (and your blabbing about 2020, really?).  My
prediction is that Python will never recover from this
backward compatibility issue. And sadly, Python2 had been
gaining stong momentum before Python3 arrived.

The code break was the first blow, and the evolving
technologies will be the final blow. Desktops computers are
becoming obsolete, and mobile platforms are the future. This
train has long since departed the station.

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-17 Thread Chris Angelico
On Fri, Jul 17, 2015 at 4:47 PM, Steven D'Aprano  wrote:
>> Jessie's default should be 2.7, at least. Wheezy shipped 2.7, too;
>> it's only Squeeze (now out of support) that didn't ship any 2.7.x
>> Python. Are you sure you can't at least upgrade to 2.7?
>
> I'm not sure, I'm not actively involved in that specific project. All I know
> is that the guys are always complaining about Jessie, and that they're
> using 2.6.

Huh. Then maybe it's the other way: Jessie no longer ships or supports
2.6, so if 2.7 breaks the code, then so will Jessie. But I'm looking
over the 2.7 What's New page, and it honestly doesn't jump out at me
screaming "Your code will break!". Strange.

Anyway, the specifics don't matter. What matters is that there *are*
people who are using the system-provided Python, and that (so far)
that's Py2 for the majority of Linux distros. But that's definitely
changing; Ubuntu and Debian are both aiming toward a state of "ship
Python 3 by default, but if you want 2.7, you'll have to download it",
which implies that all system scripts will be ported to 3.x. Once that
happens, I expect that all Debian-derived distros will follow pretty
quickly (it's easy to transition if someone else has already done the
vast majority of the work, by which I clearly mean about 87.4%), and
non-Debian distros can probably take advantage of the prior work too,
to some extent. That'll shift the balance on Linux from "mostly Py2"
to "mostly Py3", and that'll have knock-on effects on Windows and Mac
OS too, as third-party script developers will find it advisable [1] to
write their code to match the predominantly available version.

> My guess is, the rate of Python 3 adoption is going to hit the tipping point
> in 2 or 3 years, after which time it will be *very* rapid.

Yep, I'd agree with that estimate. Debian Stretch (9) may or may not
switch; I'd be very surprised if Debian Buster (10) didn't have Py3 by
default.

ChrisA

[1] The question is, what did the archbishop find?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Noob in Python. Problem with fairly simple test case

2015-07-17 Thread Jean-Michel Pichavant
- Original Message -
> From: "Steven D'Aprano" 
> 75% or 90% is not a "vast majority". Vast majority implies more than
> 99%.

You could not be more wrong.

More than 99% is a stupendous majority, while within 95 to 99% is a tremendous 
majority.
>From the official "Majority rating" 2015 edition, a vast majority would be 
>between 87 and 87.6%.

Of course this is only valid in the northern hemisphere (my apologies for 
stating the obvious).

JM



-- IMPORTANT NOTICE: 

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Steven D'Aprano
On Fri, 17 Jul 2015 01:01 pm, Chris Angelico wrote:

> On Fri, Jul 17, 2015 at 12:44 PM, Steven D'Aprano 
> wrote:
>> My take from all this is that overall, Python 3 take-up is probably
>> around 10% of all Python users...
> 
> Really? That low? Wow. 

Well, that's based on a guess that for every Python programmer you see
talking on the Internet, on Stackoverflow, Usenet, etc. there are probably
ten or so who are invisible to us. They work a nominally 9 to 5 government
or corporate job programming in Python, are forbidden to install packages
which aren't approved by IT, and don't even have access to Stackoverflow
let alone have time to chew the fat here. Those folks, I expect, are almost
all using Python 2.6 or 2.7, with a small minority on even older versions.

Some small percentage of them will still be using Python 2 in 20 years time,
just as there are a small minority of people still using Python 1.5 today.


> Jessie's default should be 2.7, at least. Wheezy shipped 2.7, too;
> it's only Squeeze (now out of support) that didn't ship any 2.7.x
> Python. Are you sure you can't at least upgrade to 2.7?

I'm not sure, I'm not actively involved in that specific project. All I know
is that the guys are always complaining about Jessie, and that they're
using 2.6.



-- 
Steven

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Steven D'Aprano
On Fri, 17 Jul 2015 02:15 pm, Rick Johnson wrote:

> On Thursday, July 16, 2015 at 9:44:56 PM UTC-5, Steven D'Aprano wrote:
>> [...] My take from all this is that overall, Python 3
>> take-up is probably > around 10% of all Python users,
> 
> All that rambling just to agree with me? My educated guess
> is a minimum of 75% still using Python2.x. But i'll take
> your 90% because it makes my argument stronger! O:-D

75% or 90% is not a "vast majority". Vast majority implies more than 99%.

But regardless of the precise meaning of "vast", if you want to dismiss one
in four people (25%) or one in ten (10%) as inconsequential, then you've
got some serious issues.


[...]
> Well i'm not "actively hostile" to py3 by any means, i just
> can't risk the upgrade at this time.

You can't "risk" the upgrade?

What precisely are you afraid of?


>> The take-up rate of Python 3 is about where we would
>> expect after less than seven years:
> 
> Well, that's one way of coping with it. I know a lot of
> folks worked hard to get Python3 up and running, but they
> need to realize that these sort of transitions take time.

Rick, you're being patronising.

Before even a single line of code was written for Python 3, Guido and the
core developers knew that there would be a long migration path from 2 to 3.
Hence the parallel versions, and the long transition plan:

* Python 2.6 and Python 3.0 came out more or less together, and 2.6 was
explicitly designed as a transitional version with a number of Python 3
features available via __future___ imports;

* Python 2.7 has an extended maintenance period; instead of the usual 2-3
years, 2.7 will be maintained for 10 years (until 2020);

* there will also be at least three more years of commercial third-party
maintenance available from companies like Red Hat.

The core developers don't need to be told that "these sort of transitions
take time". They predicted almost from the beginning that it would take 10
years for the transition. They didn't commit to a long period of parallel
versions because they *like* having twice as much work to do.


> Heck, there is always the possibility that Python3 never
> gets any real traction. Until it's usage reaches 50%, it's
> only spinning tires in the mud, digging a deeper hole.

That's nonsense. Spinning tires implies no forward motion. Python 3 usage is
*certainly* moving forward: we've gone from the situation in 2008 of nobody
using it, to the current situation where there's lots of activity around
it: students learning on Python 3, books about it, the avant-garde and
early adopters have already moved to Python 3, and the majority of
libraries also support Python 3.

The chances of that forward motion coming to a stop are very slim. The work
being done on async and concurrency for Python 3.5 is getting lots of
people excited, and Red Hat and Debian have committed to migrating to
Python 3. Where they go, Centos, Fedora, Mint and (probably) Ubuntu are
sure to follow, and quite quickly too.

My guess is, the rate of Python 3 adoption is going to hit the tipping point
in 2 or 3 years, after which time it will be *very* rapid.


> Not to mention the elephant in the room: We have been moving
> towards mobile and cloud ubiquity, and this trend is not
> going to stop. If Python wants to survive it had better
> start adapting, and adapting fast. If not, it shall become
> just another forgotten language relegated to obscurity
> within the dark corners of academia.

Yeah, right. Like academic computer scientists use Python.

Whatever way you look at it, Python is one of the top 10 programming
languages. It's at no risk of becoming forgotten any time soon.

http://import-that.dreamwidth.org/1388.html




-- 
Steven

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Chris Angelico
On Fri, Jul 17, 2015 at 2:15 PM, Rick Johnson
 wrote:
> On Thursday, July 16, 2015 at 9:44:56 PM UTC-5, Steven D'Aprano wrote:
>> [...] My take from all this is that overall, Python 3
>> take-up is probably > around 10% of all Python users,
>
> All that rambling just to agree with me? My educated guess
> is a minimum of 75% still using Python2.x. But i'll take
> your 90% because it makes my argument stronger! O:-D

You said "vast majority". That's not 75:25, which is just a 3:1 ratio.

> Well, that's one way of coping with it. I know a lot of
> folks worked hard to get Python3 up and running, but they
> need to realize that these sort of transitions take time.
> Heck, there is always the possibility that Python3 never
> gets any real traction. Until it's usage reaches 50%, it's
> only spinning tires in the mud, digging a deeper hole.

Given how easily the two coexist, I would say that demanding 50%
before giving Py3 any respect at all is a bit presumptuous. Py3 has
already gained very real traction; it just hasn't achieved a majority
of usage.

> Not to mention the elephant in the room: We have been moving
> towards mobile and cloud ubiquity, and this trend is not
> going to stop. If Python wants to survive it had better
> start adapting, and adapting fast. If not, it shall become
> just another forgotten language relegated to obscurity
> within the dark corners of academia.

Mobile is just how people access things. Usually there has to be a
server on the back end. "Cloud" also implies some sort of server. What
languages are people using on servers? Python is right up there among
them. The basic notion of client-server infrastructure has been around
for three parts of forever, and it isn't going anywhere.

Thank you for your FUD. Allow me to offer my preferred alternative.

https://www.youtube.com/watch?v=6e1hZGDaqIw

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Rick Johnson
On Thursday, July 16, 2015 at 9:44:56 PM UTC-5, Steven D'Aprano wrote:
> [...] My take from all this is that overall, Python 3
> take-up is probably > around 10% of all Python users,

All that rambling just to agree with me? My educated guess
is a minimum of 75% still using Python2.x. But i'll take
your 90% because it makes my argument stronger! O:-D

> but it's the most influential 10%: newbies learning Python
> 3 at school, the people chatting about Python on the
> Internet, writing blog posts and answering questions on
> Stackoverflow. Furthermore, there's probably another 30%
> who *want* to use Python 3 but cannot due to company
> policy. In my day job, I fall into that category: the
> company I work for use Python as their main language for
> our flagship application, and by policy we're stuck with
> using the default Python on Debian jessie, which is 2.6.
> The numbers of people actively hostile to Python 3 is
> probably less than 10%.

Well i'm not "actively hostile" to py3 by any means, i just
can't risk the upgrade at this time. Perhaps in another five
years or so i might change my mind. But then, in another
five years, something more interesting might come along and
sweep me off my feet. Who knows, I'm a sucker for romance.

> The take-up rate of Python 3 is about where we would
> expect after less than seven years:

Well, that's one way of coping with it. I know a lot of
folks worked hard to get Python3 up and running, but they
need to realize that these sort of transitions take time.
Heck, there is always the possibility that Python3 never
gets any real traction. Until it's usage reaches 50%, it's
only spinning tires in the mud, digging a deeper hole.

Not to mention the elephant in the room: We have been moving
towards mobile and cloud ubiquity, and this trend is not
going to stop. If Python wants to survive it had better
start adapting, and adapting fast. If not, it shall become
just another forgotten language relegated to obscurity
within the dark corners of academia.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Larry Hudson via Python-list

On 07/15/2015 08:11 PM, Chris Angelico wrote:

On Thu, Jul 16, 2015 at 1:01 PM, Larry Hudson via Python-list
 wrote:

On 07/15/2015 05:11 AM, Chris Angelico wrote:



[snip]



In addition to using print(), in some places I like using input() instead,
as in:
 input('x={}, y={} --> '.format(x, y))
Then the program stops at that point so you can study it.
To continue just press , or Ctrl-C to abort.


That's a neat trick, as long as you actually do have a console. IIDPIO
is extremely general (works across languages, across frameworks (eg a
web server), etc), but these kinds of extensions are pretty handy when
they make sense.

ChrisA

Actually, that was an (unstated) point -- it's handy where it _can_ be used and makes sense, but 
it is certainly not a universal technique.


Also I didn't specifically point out the '-->' that I use at the end of the string as an input 
prompt.  Obviously, optional as well.


 -=- Larry -=-

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Chris Angelico
On Fri, Jul 17, 2015 at 12:44 PM, Steven D'Aprano  wrote:
> My take from all this is that overall, Python 3 take-up is probably around
> 10% of all Python users...

Really? That low? Wow. I guess 90% could count as Rick's declared
"vast majority", although that term does imply more like 99%.

> Furthermore, there's probably another 30% who *want* to use Python 3 but
> cannot due to company policy. In my day job, I fall into that category: the
> company I work for use Python as their main language for our flagship
> application, and by policy we're stuck with using the default Python on
> Debian jessie, which is 2.6.

Jessie's default should be 2.7, at least. Wheezy shipped 2.7, too;
it's only Squeeze (now out of support) that didn't ship any 2.7.x
Python. Are you sure you can't at least upgrade to 2.7?

But yes, that's still not 3.x.

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Steven D'Aprano
It amuses me that this discussion started because the OP stated explicitly
that he uses Python 3, and Rick gave an answer for Python 2. Rather than
accept his mistake, Rick's defence is that practically nobody uses Python
3. (Presumably he means "apart from the guy who actually asked the
question".)

More comments below:


On Fri, 17 Jul 2015 10:30 am, Ranting Rick wrote:

> On Thursday, July 16, 2015 at 6:24:21 PM UTC-5, Chris Angelico wrote:
> 
> Any attempt to translate downloads into *REAL* usage
> statistics is doomed to be unreliable. Chris, you're smarter
> than this!
> 
> (1) for instance: Python2.x coders have been around long
> enough that they don't need to download as much from PyPi
> anymore. Whereas, Python3.x coders are more recent, therfor
> they will be downloading the majority of packages these
> days.

Translation: "It's only old dinosaurs that use Python 2! Newcomers to the
language are moving straight to Python 3!".


> (2) Also. Old and stable code bases do not change as much as
> new unstable code bases tend to do. Therfor, less Python2.x
> downloads

Translation: "Python 2 code is abandoned and no longer being actively
maintained. If you want code that's actually being worked on, Python 3 is
the place to go."


> (3) The numbers are falsified even more by 3.0 packages that
> are downloaded, but never actually used. Maybe the package
> was not what the downloaded expected it to be. I have
> downloaded many packages from PyPi and never used the
> majority of them.

Translation: "I don't use many libraries outside of what's in the standard
library."


I don't necessarily agree with *any* of these things, except for the initial
comment that it's difficult to tell exactly how many people are using any
specific version of Python. That at least is true. But:

- I think it is ridiculous to suggest that just because somebody has been
using Python for many years, they no longer need to download packages from
PyPI.

- While it's true that old stable code doesn't change, most heavily used
code is under active development for security updates, bug fixes, and new
features. This is *particularly* true now that Python 3 is in the picture.
The great majority of non-abandoned packages on PyPI have been, or are in
the process of being, updated to support Python 3.

- It's a dishonest argument to suggest that people download Python 3
packages but never use them, without acknowledging that the same applies to
Python 2 packages. By default, pip installs Python 2 packages, so if
anything the rate of "downloaded but not used" errors will be slightly
higher for Python 2 than Python 3. (It's easy for somebody to accidentally
download an unwanted Python 2 version of a package, but hard to download an
unwanted Python 3 version.)


>> Even if you don't correct for that, these figures show *at
>> most* 30-50% more Py2 usage than Py3, which hardly
>> justifies Rick's statement that the "vast majority" of
>> Python is 2.x.
>> 
> 
> I think I've dispelled the validity of your assertion and
> the weakness inherent in your mental heuristic. As my
> logical reasoning demonstrates, your percentages of 30%-50%
> are, at best, on the *LOW* end of the real percentages of
> Python2.x usage.

I believe Rick has misunderstood Chris' comment. Chris is not saying that
30-50% of Python users are using Python 2. He's saying that there are
30-50% *more* Python 2 users than Python 3, that is, for each Python 3 user
there are 1.3 to 1.5 Python 2 users, i.e. about 40% Python 3 versus 60%
Python 2.

I think that undercounts two sorts of users:

- those who are behind corporate or government firewalls;

- and those using only packages available via their Linux distro's package
management (yum, apt-get, etc)

neither of whom will be represented well by PyPI downloads, and both of
those will be mostly using Python 2. In other words, I think Chris is
overcounting Python 3 users.

My sense is that:

- A lot of newcomers to Python are starting with Python 3; quite a few
schools and colleges which teach Python now start with Python 3. From the
evidence I've seen on the tutor mailing list, I'd estimate that newcomers
are probably 40% Python 3.

- Established Python users of the sort who spend a lot of time talking about
Python on the Internet (e.g. here, on Reddit, Stackoverflow, blogging) tend
to be relatively early adopters of Python 3. Reddit, for example, is
extremely (and sometimes obnoxiously so) pro-Python 3. My estimate is that
there's probably about 60% Python 3 usage.

- Government and corporate users tend to be the opposite of early adaptors,
more like late or never adaptors. The majority of them won't upgrade to 3
until the last possible minute. Some will never upgrade -- there are still
people using Python 2.3 and even 1.5 who have no intention of upgrading to
2.7, let alone 3.x. My guess -- and this really is a plucked-from-thin-air
guess -- is that probably 5% or less are using Python 3. I think that this
group of users are th

Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Rick Johnson
On Thursday, July 16, 2015 at 6:24:21 PM UTC-5, Chris Angelico wrote:

Any attempt to translate downloads into *REAL* usage
statistics is doomed to be unreliable. Chris, you're smarter
than this!

(1) for instance: Python2.x coders have been around long
enough that they don't need to download as much from PyPi
anymore. Whereas, Python3.x coders are more recent, therfor
they will be downloading the majority of packages these
days.

(2) Also. Old and stable code bases do not change as much as
new unstable code bases tend to do. Therfor, less Python2.x
downloads

(3) The numbers are falsified even more by 3.0 packages that
are downloaded, but never actually used. Maybe the package
was not what the downloaded expected it to be. I have
downloaded many packages from PyPi and never used the
majority of them.

> 
> Even if you don't correct for that, these figures show *at
> most* 30-50% more Py2 usage than Py3, which hardly
> justifies Rick's statement that the "vast majority" of
> Python is 2.x.
> 

I think I've dispelled the validity of your assertion and
the weakness inherent in your mental heuristic. As my
logical reasoning demonstrates, your percentages of 30%-50%
are, at best, on the *LOW* end of the real percentages of
Python2.x usage.

And i'm not talking about downloads. I'm talking about
*REAL* code out in the wild. I talking about real
applications out in the wild, or living on hard drives doing
*REAL* work. That's the *REAL* litmus test of Python!

Not some false download statistics that can easily be
tainted by a large number of 2.x coders downloading and
"playing" with 3.0 source and packages, but never releasing
or even creating anything substantial. 

Where is the substantial amount of Python3000 applications,
code, and libraries? Sure you can point to PyPi, as it does
contain 3.0 compatible code, but that code is sitting around
doing nothing?

But more importantly than *WHERE* -> *WHAT* are they doing?

Are they making peoples lives better? Are they solving
problems? Or are they just toys written to satisfy some
childish need to play, before getting bored and moving on to
real life projects?

The fact is, the *REAL* code that is doing *REAL* work that
is solving *REAL* problems, is doing it in Python2.x That's
a fact Chris. And your smoke and mirror parlor tricks are
not going to change that one bit.


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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Chris Angelico
On Fri, Jul 17, 2015 at 7:27 AM, Emile van Sebille  wrote:
> On Thursday, July 16, 2015 at 3:11:56 PM UTC-5, Chris Angelico wrote:
>
>> Where's the latest survey results? I think the numbers don't agree
>> with you any more.
>
>
> Not that there's a source for that info, but a quick survey of yahoo results
> certainly continues to show more v2 activity.
>
> --anytime--
> python v3 -- 143
> python v2 -- 189
>
> --Past month--
> python v3 -- 386000
> python v2 -- 554000

Yes, and this is skewed somewhat by the Linux distros that ship Python
2 as the system Python, which leads to automatic use of Py2 in various
places. Even if you don't correct for that, these figures show *at
most* 30-50% more Py2 usage than Py3, which hardly justifies Rick's
statement that the "vast majority" of Python is 2.x. Different metrics
differ in the exact figures, but none show a 99:1 ratio or even 90:10
for any recent stats. The most skewed I can find puts Py2 at about
90%, of which a significant slab is 2.6, and 3.4 didn't exist yet:

https://alexgaynor.net/2014/jan/03/pypi-download-statistics/

(There are some 3.4 downloads in the stats, but they come from beta
users; when that blog post was written, 3.4 final was still several
months away.)

And the post makes several caveats about repeated downloads from eg
continuous integration systems, which naturally will tend to be skewed
heavily toward the old stable version. No, the "vast majority" of
Python is no longer on a single version.

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Emile van Sebille

On Thursday, July 16, 2015 at 3:11:56 PM UTC-5, Chris Angelico wrote:


Where's the latest survey results? I think the numbers don't agree
with you any more.


Not that there's a source for that info, but a quick survey of yahoo 
results certainly continues to show more v2 activity.


--anytime--
python v3 -- 143
python v2 -- 189

--Past month--
python v3 -- 386000
python v2 -- 554000

Emile


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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Rick Johnson
On Thursday, July 16, 2015 at 3:11:56 PM UTC-5, Chris Angelico wrote:
> Where's the latest survey results? I think the numbers don't agree
> with you any more.

What? You think the handful of regulars on this list in any
way shape or form somehow represents the multitude of *REAL*
python programmers who work day in and day out in the
trenches? ON THE FRONT LINES! 

Heck you're more naive than the BDFL: who gets a woody
simply from gawking at that atrociously inaccurate TIOBI
index! 

 Oooh. Oooh. Python is moving up the list!

Yeah, it's not just Python that's moving up. Besides, 
everybody knows his bots are out there manipulating the 
numbers!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Chris Angelico
On Fri, Jul 17, 2015 at 6:03 AM, Rick Johnson
 wrote:
> but a vast majority of the Python community is currently
> using, and will for many years continue using, Python<3.0.

Where's the latest survey results? I think the numbers don't agree
with you any more.

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-16 Thread Rick Johnson
On Wednesday, July 15, 2015 at 10:45:12 PM UTC-5, Chris Angelico wrote:
> A GUI is another form of console. 

And a blindingly obvious association is another form of
patronizing! What's next, are you going to tell us that a
Volvo is a street-legal Scandinavian version of an armored
personal carrier? Or perhaps you'll *WOW* us with your
knowledge that a penis is merely another form of editable
sausage? OBVIOUSLY YOUR "SAUSAGE" WAS CANNED IN VIENNA!

> Not all programs are run in a situation where this makes
> sense.

Really? I thought every situation was exactly the same. How
foolish am i? Oh please enlighten us with more of your wisdom!

> Also, please don't post Py2-only code when the OP clearly
> stated that 3.4.3 was being used...

Chris i hate to burst you're little naive "vajayjay bubble",
but a vast majority of the Python community is currently
using, and will for many years continue using, Python<3.0.
Just because they don't participate here => in your private
self-aggrandizing blog <= does not mean they don't exist!

See, unlike you, we didn't start writing Python code a few
years ago. No, we skipped the "pike detour" through the
intellectual ghetto, and we've been writing Python code for
many years. And we have millions of lines of code in our
repos!

And we're not about to risk "exception hell" just so we can
get a few "meager" new features and a "kewel" new print
function. Besides, most of the new features have long ago been
patched by creative programmers or are available via the: 

  from __future__ import KEWEL_NEW_FEATURE

I have a statement about what you can do with your print
function, but executing that statement might result in this
fine group throwing an IntegrityError. Therefor, i'll leave 
the "interpretation" of my statement as an academic exercise 
for all the Usenet eyeball-parsers.

sys.exit(0)


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


Re: Noob in Python. Problem with fairly simple test case

2015-07-15 Thread Chris Angelico
On Thu, Jul 16, 2015 at 1:33 PM, Rick Johnson
 wrote:
> On Wednesday, July 15, 2015 at 10:11:43 PM UTC-5, Chris Angelico wrote:
>> That's a neat trick, as long as you actually do have a console.
>
> Well if you don't have a console, another option is to use the
> dialogs of the "batteries included GUI" named Tkinter.
>
> from tkMessageBox import showinfo # Syntax == Python < 3.0

A GUI is another form of console. Not all programs are run in a
situation where this makes sense. Also, please don't post Py2-only
code when the OP clearly stated that 3.4.3 was being used...

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-15 Thread Rick Johnson
On Wednesday, July 15, 2015 at 10:11:43 PM UTC-5, Chris Angelico wrote:
> That's a neat trick, as long as you actually do have a console.

Well if you don't have a console, another option is to use the 
dialogs of the "batteries included GUI" named Tkinter. 

from tkMessageBox import showinfo # Syntax == Python < 3.0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Noob in Python. Problem with fairly simple test case

2015-07-15 Thread Chris Angelico
On Thu, Jul 16, 2015 at 1:01 PM, Larry Hudson via Python-list
 wrote:
> On 07/15/2015 05:11 AM, Chris Angelico wrote:
>>
>> On Wed, Jul 15, 2015 at 9:44 PM, Jason P.  wrote:
>>>
>>> I can't understand very well what's happening. It seems that the main
>>> thread gets blocked listening to the web server. My intent was to spawn
>>> another process for the server independent of the test. Obviously I'm doing
>>> something wrong. I've made several guesses commenting pieces of code
>>> (tearDown method for example) but I didn't manage to solve the problem(s).
>>>
>>
>> When you find yourself making guesses to try to figure out what's
>> going on, here are two general tips:
>>
>> 1) Cut out as many pieces as you can. Test one small thing at a time.
>> 2) If In Doubt, Print It Out! Stick print() calls into the code at key
>> places, displaying the values of parameters or the results of
>> intermediate calculations - or just saying "Hi, I'm still here and I'm
>> running!".
>>
> In addition to using print(), in some places I like using input() instead,
> as in:
> input('x={}, y={} --> '.format(x, y))
> Then the program stops at that point so you can study it.
> To continue just press , or Ctrl-C to abort.

That's a neat trick, as long as you actually do have a console. IIDPIO
is extremely general (works across languages, across frameworks (eg a
web server), etc), but these kinds of extensions are pretty handy when
they make sense.

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-15 Thread Larry Hudson via Python-list

On 07/15/2015 05:11 AM, Chris Angelico wrote:

On Wed, Jul 15, 2015 at 9:44 PM, Jason P.  wrote:

I can't understand very well what's happening. It seems that the main thread 
gets blocked listening to the web server. My intent was to spawn another 
process for the server independent of the test. Obviously I'm doing something 
wrong. I've made several guesses commenting pieces of code (tearDown method for 
example) but I didn't manage to solve the problem(s).



When you find yourself making guesses to try to figure out what's
going on, here are two general tips:

1) Cut out as many pieces as you can. Test one small thing at a time.
2) If In Doubt, Print It Out! Stick print() calls into the code at key
places, displaying the values of parameters or the results of
intermediate calculations - or just saying "Hi, I'm still here and I'm
running!".


In addition to using print(), in some places I like using input() instead, as 
in:
input('x={}, y={} --> '.format(x, y))
Then the program stops at that point so you can study it.
To continue just press , or Ctrl-C to abort.

 -=- Larry -=-

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


Re: Noob in Python. Problem with fairly simple test case

2015-07-15 Thread Chris Angelico
On Wed, Jul 15, 2015 at 9:44 PM, Jason P.  wrote:
> I can't understand very well what's happening. It seems that the main thread 
> gets blocked listening to the web server. My intent was to spawn another 
> process for the server independent of the test. Obviously I'm doing something 
> wrong. I've made several guesses commenting pieces of code (tearDown method 
> for example) but I didn't manage to solve the problem(s).
>

When you find yourself making guesses to try to figure out what's
going on, here are two general tips:

1) Cut out as many pieces as you can. Test one small thing at a time.
2) If In Doubt, Print It Out! Stick print() calls into the code at key
places, displaying the values of parameters or the results of
intermediate calculations - or just saying "Hi, I'm still here and I'm
running!".

For #1, I would recommend first just trying to get the web service
going. Can you connect (using an external program) on port 8000 and
receive a text/plain HTTP response saying "Hello World!"? Never mind
about the test for the moment.

And for #2, judicious placement of console output will help you figure
out things you're not sure about. For instance, you're suspecting that
the main thread is getting blocked handling the web server. Easy way
to check:

def setUp(self):
# Start the forecast server
self.server = ForecastServer()
self.server.start(webservice.app)

Just before you construct the server, print something out. After
you've constructed it but before you call start(), print something
out. And after starting it, print something out. Then run the program.
If you see the first line and no other, then it's blocking during the
construction. Other deductions I'm sure you can figure out.

One small point: Probe even things that you think are trivial. In the
above example, I cannot see any reason why constructing
ForecastServer() could possibly block, because its init does nothing
but set a flag. But you can get surprised by things sometimes - maybe
the problem is actually that you're not running the code you think you
are, but there's some other ForecastServer kicking in, and it's
synchronous rather than subprocess-based.

End-to-end testing is all very well, but when something goes wrong,
the key is to break the program down into smaller parts. Otherwise,
all you have is "it doesn't work", which is one of the most useless
error reports ever. If someone comes to python-list saying "it doesn't
work", we'll be asking him/her to give a lot more details; if your
aunt asks you for help printing out a document because "it doesn't
work", you'll probably have to go over and watch her attempt it; and
it's the same with your test cases - you make them tell you more
details.

Hope that helps! The techniques I'm offering are completely
problem-independent, and even language-independent. IIDPIO debugging
works in anything that gives you a console, which is pretty much
everything - maybe it won't be print() but logging.debug(), but the
same technique works.

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


Noob in Python. Problem with fairly simple test case

2015-07-15 Thread Jason P.

Hi all!

I'm working in a little Python exercise with testing since the beginning. So 
far I'm with my first end to end test (not even finished yet) trying to:

1) Launch a development web server linked to a demo app that just returns 
'Hello World!'

2) Make a GET request successfully

I can't understand very well what's happening. It seems that the main thread 
gets blocked listening to the web server. My intent was to spawn another 
process for the server independent of the test. Obviously I'm doing something 
wrong. I've made several guesses commenting pieces of code (tearDown method for 
example) but I didn't manage to solve the problem(s).

I'm running the test through PyCharm. Python version = 3.4.3



Here it's the code:


test_forecast_end_to_end.py
===

import unittest
from tests.end_to_end.forecastserver import ForecastServer
import src.forecast.webservice as webservice
import requests


class TestForecastEndToEnd(unittest.TestCase):

def setUp(self):
# Start the forecast server
self.server = ForecastServer()
self.server.start(webservice.app)

def tearDown(self):
# Stop the forecast server
self.server.stop()

def test_webservice_receives_a_request(self):
response = requests.get('http://localhost:8000')
print(response.text)


if __name__ == '__main__':
unittest.main()



forecastserver.py
=

from wsgiref.simple_server import make_server
import multiprocessing


class ForecastServer:

def __init__(self):
self._httpd_process = None

def start(self, webservice):
if not self._httpd_process:
httpd = make_server('localhost', 8000, webservice)
self._httpd_process = multiprocessing.Process(
target=httpd.serve_forever)
self._httpd_process.start()

def stop(self):
if self._httpd_process:
self._httpd_process.join()
self._httpd_process.terminate()

del self._httpd_process



webservice.py
=

def app(environ, start_response):
status = '200 OK'
headers = [('Content-type', 'text/plain')]
start_response(status, headers)

return ['Hello World!']
-- 
https://mail.python.org/mailman/listinfo/python-list