Re: Is there a way to display source code for Python function?

2014-10-02 Thread Viet Nguyen
On Thursday, October 2, 2014 10:47:28 PM UTC-7, Ian wrote:
> On Thu, Oct 2, 2014 at 11:34 PM, Viet Nguyen
> 
>  wrote:
> 
> > Hi,
> 
> >
> 
> > When I am debug mode, is there some command which will help display the 
> > source code for a Python function of interest?  Much like you'd use "info 
> > proc" to display contents of Tcl proc.
> 
> >
> 
> > Thanks,
> 
> > Viet
> 
> 
> 
> You can use inspect.getsource() to get the source code for a function,
> 
> class, or module. The source must be available at whatever location
> 
> the module was imported from, and of course it won't work for anything
> 
> implemented in C.

Hi,
I tried:

def func(a):
  a = 'abcd'

>>> inspect.getsource(func)
Traceback (most recent call last):
  File "", line 1, in 
  File "/sw/packages/python/current/lib/python2.7/inspect.py", line 701, in 
getsource
lines, lnum = getsourcelines(object)
  File "/sw/packages/python/current/lib/python2.7/inspect.py", line 690, in 
getsourcelines
lines, lnum = findsource(object)
  File "/sw/packages/python/current/lib/python2.7/inspect.py", line 538, in 
findsource
raise IOError('could not get source code')
IOError: could not get source code


What is wrong?

Thanks,
Viet

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


Re: Is there a way to display source code for Python function?

2014-10-02 Thread Viet Nguyen
On Thursday, October 2, 2014 10:34:15 PM UTC-7, Viet Nguyen wrote:
> Hi,
> 
> 
> 
> When I am debug mode, is there some command which will help display the 
> source code for a Python function of interest?  Much like you'd use "info 
> proc" to display contents of Tcl proc.
> 
> 
> 
> Thanks,
> 
> Viet

I tried this:
>>> def func(a):
...   a = 'abcd'


>>> inspect.getsource(func)
Traceback (most recent call last):
  File "", line 1, in 
  File "/sw/packages/python/current/lib/python2.7/inspect.py", line 701, in 
getsource
lines, lnum = getsourcelines(object)
  File "/sw/packages/python/current/lib/python2.7/inspect.py", line 690, in 
getsourcelines
lines, lnum = findsource(object)
  File "/sw/packages/python/current/lib/python2.7/inspect.py", line 538, in 
findsource
raise IOError('could not get source code')
IOError: could not get source code

>>> inspect.getsourcelines(func)
Traceback (most recent call last):
  File "", line 1, in 
  File "/sw/packages/python/current/lib/python2.7/inspect.py", line 690, in 
getsourcelines
lines, lnum = findsource(object)
  File "/sw/packages/python/current/lib/python2.7/inspect.py", line 538, in 
findsource
raise IOError('could not get source code')
IOError: could not get source code

What is wrong?

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


Re: Is there a way to display source code for Python function?

2014-10-02 Thread Ian Kelly
On Thu, Oct 2, 2014 at 11:34 PM, Viet Nguyen
 wrote:
> Hi,
>
> When I am debug mode, is there some command which will help display the 
> source code for a Python function of interest?  Much like you'd use "info 
> proc" to display contents of Tcl proc.
>
> Thanks,
> Viet

You can use inspect.getsource() to get the source code for a function,
class, or module. The source must be available at whatever location
the module was imported from, and of course it won't work for anything
implemented in C.
-- 
https://mail.python.org/mailman/listinfo/python-list


Is there a way to display source code for Python function?

2014-10-02 Thread Viet Nguyen
Hi,

When I am debug mode, is there some command which will help display the source 
code for a Python function of interest?  Much like you'd use "info proc" to 
display contents of Tcl proc.

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


Re: Clearing globals in CPython

2014-10-02 Thread Stefan Behnel
Chris Angelico schrieb am 02.10.2014 um 16:12:
> On Fri, Oct 3, 2014 at 12:07 AM, Grant Edwards wrote:
>> On 2014-10-01, Steven D'Aprano wrote:
>>
>>> Obviously the easiest way to recover is to exit the current session and
>>> restart it, but as a challenge, can we recover from this state?
>>
>> Python apparently _does_ need a "restart command".
> 
> Apparently not... you saw how easily Peter recovered :)

Right. All we need is a builtin function for that recovery code.

Stefan


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


Re: Error from pandas.io.data import DataReader

2014-10-02 Thread Miki Tebeka
Greetings,

> I am trying to run this snippet of code.
> 
> from pandas.io.data import DataReader
> ...
> 
> I keep getting this error.
> 
> Traceback (most recent call last):
> 
>   File "C:\Python27\download_dow.py", line 1, in 
> 
> from pandas.io.data import DataReader
> 
> ImportError: No module named pandas.io.data

* Do you have pandas installed? (Does "import pandas" work?)
* If it is installed, what version do you have? ( "print(pandas.__version__")

HTH,
--
Miki
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Chris Angelico
On Fri, Oct 3, 2014 at 9:16 AM, Steven D'Aprano
 wrote:
>> Anyway, pylint doesn't complain about a bare use of lambda, but it
>> does complain about a map applied to a lambda or a filter applied to a
>> lambda.  Pylint says they could be replaced by a list comprehension,
>> with the warning "deprecated-lambda".
>
> The warning name is misleading, lambda is not deprecated. But stylistically,
> many people prefer to use a generator expression in place of map or filter:
>
> # instead of this
> map(lambda x: 2*x+1, values)
>
> # use this
> (2*x+1 for x in values)
>
> # instead of this
> filter(lambda x: x > 23, values)
>
> # use this
> (x for x in values if x > 23)

Don't forget that your equivalencies are based on the Py3 map/filter,
which return non-list iterables. There's no really convenient
equivalent to the map() usage of "call this function with each of
these args, and discard the return values", as it looks very odd to do
a list comp for nothing:

[print(x) for x in list_of_strings]

Short of borrowing Pike's automap syntax:

print(list_of_strings[*])

there's really not much that's better than the original map() call. On
the other hand, there aren't actually all that many times when I've
needed to do this, and the simple for loop generally suffices:

for x in list_of_strings: print(x)

So it's not a huge deal.

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


Re: Function passed as an argument returns none

2014-10-02 Thread Chris Angelico
On Fri, Oct 3, 2014 at 11:49 AM, Rustom Mody  wrote:
> Ok so there is no conventional attribution line because it was
> cut-pasted from elsewhere in the thread but there is a clear
> and unequivocal prefix of "OP subject as well as post".

When I respond to this part...

> Why/how should there be any ambiguity that that is Shiva??

... and then to this, the normal assumption is that, since both are at
the same indentation level, they're both covered by the same heading
line. Compare:

def rustom():
yield "... there is no conventional ..."
yield "... elsewhere in the thread ..."
yield "... unequivocal ..."

# I respond to this...

yield "... any ambiguity ..."

# Is there any expectation that the above line of code isn't part of
the same function?

And there IS an unequivocal prefix of "OP subject as well as post". It
looks like this:

On Thu, Oct 2, 2014 at 8:37 AM, Shiva
 wrote:
> Any idea why 'None' is getting passed even though calling the donuts(4)
> alone returns the expected value?

And there's even an unambiguous way to indicate that you're responding
to the original poster, but not the original post. Watch!

On Thu, Oct 2, 2014 at 6:46 PM, Shiva
 wrote:
> * return 'Number of donuts: ',countreturns a tuple like:
> ('Number of donuts: ',9)

I can correctly attribute every piece that I respond to. It's really
not hard. In this particular case, I opened two additional replies,
and copied and pasted the bits I want into this reply. Some people
short-cut it, when they're responding to separate posts, and just do
something like this:

[Rustom Mode]
> Are you for real Steven??

Complete with a demonstration of what happens all too often when
things are done manually: a spelling error in the attribution line.
It's still unambiguous as to who wrote what, though a little less
helpful as regards chronology.

Attribution lines are part of being honest about who said what. I
wouldn't say that your post was evidence of malicious intent, but it
was sloppiness that led to an easily misunderstood post. On rereading,
I can see that you did try to indicate (by your text) that it was
meant to be followed by the OP's words, but you didn't put that into
the structure, and you certainly didn't distinguish between the
original post and the one made a little bit later. Please, if you
don't want to be called out for misattribution, just be a bit more
careful. It doesn't take a huge amount of effort.

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


Re: Function passed as an argument returns none

2014-10-02 Thread Rustom Mody
On Friday, October 3, 2014 5:41:12 AM UTC+5:30, Steven D'Aprano wrote:

> [Rustom]
> > Right and the OP subject as well as post are essentially that conflation:
> [allegedly Steven]
> >> Any idea why 'None' is getting passed even though calling the donuts(4)
> >> alone returns the expected value?

> I didn't write that. I don't know who you are quoting, but it isn't me.


Are you for real Steven??

Ok so there is no conventional attribution line because it was
cut-pasted from elsewhere in the thread but there is a clear
and unequivocal prefix of "OP subject as well as post".

Why/how should there be any ambiguity that that is Shiva??

Since you are merrily throwing around mis-attribution charges please explain 
the logic by which "Steven" == "OP"

Or are not aware OP means 'original post(er)'?

Likewise all the below '[allegedly Steven]s'...

> [Rustom]
> > And further if you consider that the explanations have aided, here's the
> > most recent 'conclusion':
> [allegedly Steven]
> >> * return 'Number of donuts: ',countreturns a tuple like:
> >> ('Number of donuts: ',9)

> And again, despite you attributing this to me, I did not write that.

> [allegedly Steven]
> >> * To just print the string without returning it as tuple , use string
> >> formatting.
> [Rustom]
> > You find this understanding satisfactory??

> And that's the third time in one post that you have attributed something
> written by somebody else to me.

> Rustom, I don't consider this blatant misattribution of other people's words
> to me is acceptable behaviour.

And what kind of conversation is it if I ask you

> > You find this understanding satisfactory??

as a question ABOUT you?

How you are able to confuse a question addressed TO you into a question
ABOUT you is beyond me.

Did you run out of your morning coffee or somethin?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-02 Thread Steven D'Aprano
Rustom Mody wrote:

> On Thursday, October 2, 2014 1:30:03 PM UTC+5:30, Steven D'Aprano wrote:
>> Chris Angelico wrote:
> 

Restoring the attribution line you removed:
On Thu, Oct 2, 2014 at 12:29 PM, Rustom Mody 
wrote:
>> >> So by now you know there are 2 kinds of return:
>> >> So the morals in short:
>> >> 1. Stick to the return that works -- python's return statement --
>> >> and avoid the return that seems to work -- the print statement

[Chris]
>> > Please. There are not two types of return; there are two completely
>> > different things here. Don't pretend that print is a bad form of
>> > return. It isn't.

[Steven] 
>> I strongly agree with Chris here. The OP's problem was due to confusion
>> between print and return, and the solution is to learn the difference
>> between printing output to the screen and returning values from a
>> function, and under what circumstances Python will automatically print
>> said returned values as a convenience. Conflating the two as "2 kinds of
>> return" is an invitation to even more confusion: "which was the 'good'
>> return again?".

[Rustom]
> Right and the OP subject as well as post are essentially that conflation:
> 
[allegedly Steven]
>> Any idea why 'None' is getting passed even though calling the donuts(4)
>> alone returns the expected value?

I didn't write that. I don't know who you are quoting, but it isn't me.

[Rustom]
> And further if you consider that the explanations have aided, here's the
> most recent 'conclusion':
> 
[allegedly Steven]
>> * return 'Number of donuts: ',countreturns a tuple like:
>> ('Number of donuts: ',9)

And again, despite you attributing this to me, I did not write that.

[allegedly Steven]
>> * To just print the string without returning it as tuple , use string
>> formatting.
> 
[Rustom]
> You find this understanding satisfactory??

And that's the third time in one post that you have attributed something
written by somebody else to me.

Rustom, I don't consider this blatant misattribution of other people's words
to me is acceptable behaviour. I don't believe that somebody with your
demonstrated competence at following email and usenet quoting conventions
is unaware that you are attributing other people's comments to me. I would
be inclined to chalk it up to an innocent mistake if not for the deliberate
removal of the attribution line showing *your* advice to the OP to consider
print one of "2 kinds of return".

The original poster was confused about the difference between return and
print. You replied by reinforcing that confusion, explicitly stating that
print is a kind of return (it isn't). I don't hold that against you --
making an ill-thought-out comment in good faith is not a sin.

But in your response to my criticism of that reply, you removed the
attribution to yourself, then agreed with me ("Right") and implied that
*your* comment about there being two kinds of return was the OP's
confusion. To me, that looks like a deliberate, but feeble and pathetic,
attempt to deflect criticism of your advice to the OP onto the OP. If true,
that's a low and sordid thing to do.

Your response to Shiva, the Original Poster:
https://mail.python.org/pipermail/python-list/2014-October/678978.html

Chris' response to you, with attribution line intact:
https://mail.python.org/pipermail/python-list/2014-October/678979.html

My response to Chris, with attribution line intact:
https://mail.python.org/pipermail/python-list/2014-October/678988.html

Your response to me, with attribution line deleted, and misattributing other
people's comments to me:
https://mail.python.org/pipermail/python-list/2014-October/679001.html



-- 
Steven

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


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Steven D'Aprano
Dan Stromberg wrote:

> On Thu, Oct 2, 2014 at 12:15 PM, Ian Kelly  wrote:
>> On Thu, Oct 2, 2014 at 10:33 AM,   wrote:
>>> Ah, so at least there is a reason for it, I'm far from being a
>>> mathematician though so it's not particularly obvious (for me anyway).
>>
>> You're not alone; a lot of people find the terminology not intuitive.
>> Even GvR has publicly lamented the choice of keyword.
> 
> Was lambda almost removed from CPython 3.x?

I'm not sure about "almost", but there was serious discussion about removing
it.


> Anyway, pylint doesn't complain about a bare use of lambda, but it
> does complain about a map applied to a lambda or a filter applied to a
> lambda.  Pylint says they could be replaced by a list comprehension,
> with the warning "deprecated-lambda".

The warning name is misleading, lambda is not deprecated. But stylistically,
many people prefer to use a generator expression in place of map or filter:

# instead of this
map(lambda x: 2*x+1, values)

# use this
(2*x+1 for x in values)

# instead of this
filter(lambda x: x > 23, values)

# use this
(x for x in values if x > 23)



-- 
Steven

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


Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-10-02 Thread Ned Deily
In article ,
 "Peter Tomcsanyi"  wrote:
> "Ned Deily"  wrote in message 
> news:nad-40cb03.10344701102...@news.gmane.org...
> > The python.org 3.4.x series of installers will likely never change from
> > linking with Tk 8.5 by default.  That would break a number of important
> > third-party Python packages that supply binary distributions built for
> > the python.org OS X pythons, like matplotlib.
> I respect your decision.
> But it surprises me because the Windows version of Python 3.4.1 already 
> comes with Tcl/Tk 8.6. Does it mean that there are no such problems with 
> matplotlib etc. in Windows?

The main issue is that, unlike MS and Windows, Apple has long shipped 
versions of Tcl and Tk with OS X.  As I understand it, Apple even helped 
sponsor the writing of the newer Cocoa-based Tk that would also work on 
64-bit systems after they decided to not extend the older Carbon APIs to 
64-bit, making the original OS X native Carbon-based Tk problematic on 
newer Macs and releases of OS X.  When the Cocoa Tk was first shipped 
with OS X 10.6, Tk 8.6 hadn't been released yet so they went with a 
backport to 8.5 and, for whatever reasons, Apple has been very slow to 
upgrade their 8.5.x Tk since then and have not shipped a 8.6 version 
yet.  That leaves us in a bit of a quandary for the python.org 
installers.  Ideally, we'd just like to continue to depend on an 
Apple-supplied version but even the most recent releases of OS X ship 
with serious bugs.  Fortunately, it's been possible and long been our 
practice to ship the python.org installers Pythons built in such a way 
that, at run time, they will automatically use a compatible third-party 
Tcl and Tk, if present, otherwise fall back to the system version.  By 
far, the leading third-party distributor of Tcl/Tk is ActiveState and 
they are actively involved in the development and maintenance of Tcl and 
Tk.  But, their releases are not open-source and have a license that, 
while generous, do not permit totally unrestricted usage.  Thus it is 
problematic to depend totally on their releases. So, to really support 
Tk 8.6, the only viable option at the moment would be for us to ship our 
own versions of Tk, like the Windows installer does.  But it wouldn't be 
acceptable, IMO, to force other projects and users to migrate to 8.6 in 
the middle of a release cycle, e.g. 3.4.x or 2.7.x.  Providing it as an 
option, though, would be OK.

> I think that one of the point when advertising Python is that it works 
> accross the platforms, so keeping one platform (mac) "behind" for months 
> seems to me going against the multiplatform promise of Python...

I don't think we mean to imply that all of the third-party libraries 
that Python is able to use are the same across all platforms.  It 
depends on the platform and the practices there.  The fact is that Tk 
8.5 is still the de facto standard for OS X 10.6+ and Tk 8.4 is the de 
facto standard for OS X 10.5 and earlier systems, because that's what 
Apple has shipped.  And that's why matplotlib et al and we still ship 
binary installers for OS X with 8.5 support.  Third-party open source 
packages distributors, like MacPorts or Anaconda, can more easily move 
to newer versions of things, like Tk 8.6, because they provide complete 
solutions for many applications and libraries: they have ports for 
matplotlib, numpy, pythonx.x, Tk, and all other dependencies.  The 
python.org installers have a much more limited scope.

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

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


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Chris Angelico
On Fri, Oct 3, 2014 at 6:06 AM, Dan Stromberg  wrote:
> Anyway, pylint doesn't complain about a bare use of lambda, but it
> does complain about a map applied to a lambda or a filter applied to a
> lambda.  Pylint says they could be replaced by a list comprehension,
> with the warning "deprecated-lambda".

That's not because lambda is a poor choice, but because map() in Py2
code can often be replaced with a list comp. (And map() in Py3 code
can often be replaced by a genexp.)

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


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Dan Stromberg
On Thu, Oct 2, 2014 at 12:15 PM, Ian Kelly  wrote:
> On Thu, Oct 2, 2014 at 10:33 AM,   wrote:
>> Ah, so at least there is a reason for it, I'm far from being a
>> mathematician though so it's not particularly obvious (for me anyway).
>
> You're not alone; a lot of people find the terminology not intuitive.
> Even GvR has publicly lamented the choice of keyword.

Was lambda almost removed from CPython 3.x?

Anyway, pylint doesn't complain about a bare use of lambda, but it
does complain about a map applied to a lambda or a filter applied to a
lambda.  Pylint says they could be replaced by a list comprehension,
with the warning "deprecated-lambda".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Programming for Everybody (Python)

2014-10-02 Thread Juan Christian
I recommend to everyone. Already took one of his courses on Coursera and
he's amazing as a teacher.

On Thu, Oct 2, 2014 at 4:24 PM, Seymore4Head 
wrote:

> Starts in 3 days
> Coursera.org
>
> About the Course
> This course is specifically designed to be a first programming course
> using the popular Python programming language.  The pace of the course
> is designed to lead to mastery of each of the topics in the class.  We
> will use simple data analysis as the programming exercises through the
> course.Understanding how to process data is valuable for everyone
> regardless of your career.  This course might kindle an interest in
> more advanced programming courses or courses in web design and
> development or just provide skills when you are faced with a bunch of
> data that you need to analyze. You can do the programming assignments
> for the class using a web browser or using your personal computer. All
> required software for the course is free.
> Course Syllabus
> Week One: Introduction - Why we program?
> Week Two: Variables and Expressions
> Week Three: Conditional code
> Week Four: Functions
> Week Five: Loops and Iteration
> Week Six: Strings
> Week Seven: Files
> Week Eight: Lists
> Week Nine: Dictionaries
> Week Ten: Tuples
> Optional Topic: Regular Expressions
>
> and.a free book.
> http://www.pythonlearn.com/book.php
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Grant Edwards
On 2014-10-02, c...@isbd.net  wrote:
> Grant Edwards  wrote:
>> On 2014-10-02, c...@isbd.net  wrote:
>>
>> > It throws me because 'lambda' simply has no meaning whatsoever for me,
>> > i.e. it's just a greek letter.
>> >
>> > So from my point of view it's like seeing 'epsilon' stuck in the
>> > middle of some code. 
>> >
>> > It's not as if I'm new to programming either, I've been writing
>> > software professionally since the early 1970s, now retired.
>> 
>> The use of "lamba" as a keyword to define an anonymous function is
>> borrowed from Lisp which got it from Lambda calculus.
>> 
>> http://en.wikipedia.org/wiki/Lambda_calculus
>
> Ah, so at least there is a reason for it, I'm far from being a
> mathematician though so it's not particularly obvious (for me
> anyway).

We EE types did get complex number notation using "j" which the
mathematicians find not particularly obvious.

-- 
Grant Edwards   grant.b.edwardsYow! It's a hole all the
  at   way to downtown Burbank!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Programming for Everybody (Python)

2014-10-02 Thread Seymore4Head
Starts in 3 days
Coursera.org

About the Course
This course is specifically designed to be a first programming course
using the popular Python programming language.  The pace of the course
is designed to lead to mastery of each of the topics in the class.  We
will use simple data analysis as the programming exercises through the
course.Understanding how to process data is valuable for everyone
regardless of your career.  This course might kindle an interest in
more advanced programming courses or courses in web design and
development or just provide skills when you are faced with a bunch of
data that you need to analyze. You can do the programming assignments
for the class using a web browser or using your personal computer. All
required software for the course is free. 
Course Syllabus
Week One: Introduction - Why we program?  
Week Two: Variables and Expressions
Week Three: Conditional code
Week Four: Functions
Week Five: Loops and Iteration
Week Six: Strings
Week Seven: Files
Week Eight: Lists
Week Nine: Dictionaries
Week Ten: Tuples
Optional Topic: Regular Expressions

and.a free book.
http://www.pythonlearn.com/book.php
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Ian Kelly
On Thu, Oct 2, 2014 at 10:33 AM,   wrote:
> Ah, so at least there is a reason for it, I'm far from being a
> mathematician though so it's not particularly obvious (for me anyway).

You're not alone; a lot of people find the terminology not intuitive.
Even GvR has publicly lamented the choice of keyword.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?

2014-10-02 Thread Dave Angel

On 09/30/2014 10:55 AM, c...@isbd.net wrote:

Dave Angel  wrote:

>>   

  name. And presumably you never remove an old name from the
  config.


The only things really likely to change (and may change regularly) are
the conversion factors, drifting voltage references etc. will
inevitably require these to be recalibrated every so often.  Other
than that it's just typos or me deciding to change the name of
something.



Right there you have an important design decision.  You then presumably 
have to have a way that each particular data point can record what 
configuration it's associated with. If you just change the calibration 
data externally, then all the old records are invalidated.





More troublesome is adding a new kind of data. You have to decide
  whether it's worth generalizing the code to anticipate the
  change,  or just admit that the code will grow at that point and
  that old code won't deal with the new data.


There's a separate module for each input type (just ADC and 1-wire at
the moment), I don't anticipate any more though I suppose there might
be digital inputs one day.  So a configuration [file] for each type
seems to make sense, generalising it would be more trouble than it's
worth I think.






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


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Rustom Mody
On Thursday, October 2, 2014 4:47:50 PM UTC+5:30, Marko Rauhamaa wrote:

> > It's not as if I'm new to programming either, I've been writing
> > software professionally since the early 1970s, now retired. I have no
> > formal computer training, there wasn't much in the way of university
> > courses on computing in the 1960s, I have a degree in Electrical
> > Engineering. Maybe that's why 'lambda' means nothing to me! :-)

> Lambda is special because it was thought of in the 1920's, well before
> there were any general-purpose computers.

> http://www.users.waitrose.com/~hindley/SomePapers_PDFs/2006CarH

If you find that heavy going, here's an intro lecture on λ-calculus
-- part of lectures on discrete math I've been preparing

https://www.youtube.com/watch?v=FZoq-GlOdSs&feature=youtu.be

Comments/criticisms welcome though do remember I am as new to
film-making today as I was to programming 30 years ago :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reticulated Python

2014-10-02 Thread Ethan Furman

On 10/02/2014 10:01 AM, Mark Lawrence wrote:


My apologies if this has been discussed before but I thought it may be of 
interest
wphomes.soic.indiana.edu/jsiek/files/2014/08/retic-python-v3.pdf


Looks interesting, thanks for the link!

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


Re: Recommended hosting

2014-10-02 Thread Chris Angelico
On Fri, Oct 3, 2014 at 3:33 AM, David Hutto  wrote:
> You can go over to Zenfinite. I just so happen to know the owner; so if you
> see a nice plan you like, and it's a little pricey, I can see if the price
> can be dropped.

Or maybe you not so much *know* the owner as *are* the owner... given
that it's your name all over the domain's whois info :)

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


Re: Recommended hosting

2014-10-02 Thread David Hutto
You can go over to Zenfinite. I just so happen to know the owner; so if you
see a nice plan you like, and it's a little pricey, I can see if the price
can be dropped.

On Thu, Oct 2, 2014 at 12:33 PM, Tim  wrote:

> On Thursday, October 2, 2014 9:30:38 AM UTC-4, writeson wrote:
> > Hi all,
> > I'd like to build a web site for myself, essentially a "vanity" web site
> 
> > web applications written with Python and Flask, running as uwsgi
> applications. These would support dynamic HTML where needed, but mostly it
> would provide REST API's.
> > static content delivered by Nginx
>
> Hi, I second webfaction--you can indeed run flask and nginx. They have
> good documentation and helpful support.
>
> I've used them over the years for Django sites, bottle applications, and
> plain static blog sites and never had a complaint.
>
> good luck!
> --Tim Arnold
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Best Regards,
David Hutto
*CEO:*
*Hutto Industrial Technologies Inc.http://www.zenfinite.com
*
http://www.payizm.com -Coming Soon!
http://www.mylayawayplan.com  -Coming Soon!
-- 
https://mail.python.org/mailman/listinfo/python-list


Reticulated Python

2014-10-02 Thread Mark Lawrence
My apologies if this has been discussed before but I thought it may be 
of interest wphomes.soic.indiana.edu/jsiek/files/2014/08/retic-python-v3.pdf


--
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: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread cl
Grant Edwards  wrote:
> On 2014-10-02, c...@isbd.net  wrote:
> > Travis Griggs  wrote:
> >> 
> >> 
> >> Sent from my iPhone
> >> 
> >> > On Oct 1, 2014, at 04:12, Peter Otten <__pete...@web.de> wrote:
> >> > 
> >> > `lambda` is just a fancy way to define a function inline
> >> 
> >> Not sure "fancy" is the correct adjective; more like syntactic tartness 
> >> (a less sweet version of syntactic sugar). 
> >> 
> > It throws me because 'lambda' simply has no meaning whatsoever for me,
> > i.e. it's just a greek letter.
> >
> > So from my point of view it's like seeing 'epsilon' stuck in the
> > middle of some code. 
> >
> > It's not as if I'm new to programming either, I've been writing
> > software professionally since the early 1970s, now retired.
> 
> The use of "lamba" as a keyword to define an anonymous function is
> borrowed from Lisp which got it from Lambda calculus.
> 
> http://en.wikipedia.org/wiki/Lambda_calculus
> 
Ah, so at least there is a reason for it, I'm far from being a
mathematician though so it's not particularly obvious (for me anyway).

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Recommended hosting

2014-10-02 Thread Tim
On Thursday, October 2, 2014 9:30:38 AM UTC-4, writeson wrote:
> Hi all, 
> I'd like to build a web site for myself, essentially a "vanity" web site 

> web applications written with Python and Flask, running as uwsgi 
> applications. These would support dynamic HTML where needed, but mostly it 
> would provide REST API's.
> static content delivered by Nginx

Hi, I second webfaction--you can indeed run flask and nginx. They have good 
documentation and helpful support. 

I've used them over the years for Django sites, bottle applications, and plain 
static blog sites and never had a complaint.

good luck!
--Tim Arnold
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Assignment Operators?

2014-10-02 Thread Ian Kelly
On Thu, Oct 2, 2014 at 7:24 AM, Didymus  wrote:
>The '|=' operator, I read should be like a = a | b, but this appears to 
> add the two numbers as long as it's more than the previous:

Note that:

a = a or b

and:

a = a | b

are different operations. It sounds like you're probably looking for
the former, not the latter.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python unittesting method call issue

2014-10-02 Thread Milson Munakami
On Saturday, September 27, 2014 5:26:00 PM UTC-6, Milson Munakami wrote:
> I am trying to set the precondition for the test first prior to test other 
> test cases. But as you can see in my code the precondition print command is 
> not fired! Can you explain the cause and solution how to fire the code with 
> in that method i.e. SetPreConditionFirewall() with setup variable 
> self. in this fucntion. Here is my code:
> 
> 
> 
> import json
> 
> import urllib
> 
> #import time
> 
> #from util import *
> 
> import httplib
> 
> 
> 
> #import sys
> 
> #from scapy.all import *
> 
> 
> 
> import unittest
> 
> 
> 
> import os, sys, socket, struct, select, time 
> 
> from threading import Thread
> 
> 
> 
> import logging
> 
> import traceback
> 
> 
> 
> class testFirewallS1( unittest.TestCase ):
> 
> def setUp(self):
> 
> self.controllerIp="127.0.0.1"
> 
> def tearDown(self):
> 
> if self.failed:
> 
> return
> 
> duration = time.time() - self.startTime_
> 
> self.cleanup(True)
> 
> if self.reportStatus_:
> 
> self.log.info("=== Test %s completed normally (%d sec)", 
> self.name_, duration)
> 
> 
> 
> def cleanup(self, success):
> 
> sys.excepthook = sys.__excepthook__
> 
> try:
> 
> return
> 
> except NameError:
> 
> self.log.error("Exception hit during cleanup, bypassing:\n%s\n\n" 
> % traceback.format_exc())
> 
> pass
> 
> else:
> 
> 
> 
> fail("Expected a NameError")
> 
> 
> 
> def SetPreConditionFirewall(self):
> 
> command = "http://%s:8080/wm/firewall/module/enable/json"; % 
> self.controllerIp
> 
> urllib.urlopen(command).read()
> 
> print self.controllerIp
> 
> print "Test Pre-condition setting here"
> 
> 
> 
> #Precondition Test
> 
> def testPreConditionFirewall(self):
> 
> print "Test pass"   
> 
> 
> 
> def suite():
> 
> 
> 
> suite = unittest.TestSuite()
> 
> 
> 
> suite.addTest(unittest.makeSuite(testFirewallS1))
> 
> 
> 
> return suite
> 
> 
> 
> 
> 
> if __name__ == '__main__':
> 
> 
> 
> suiteFew = unittest.TestSuite()
> 
> 
> 
> testFirewallS1("SetPreConditionFirewall")
> 
> 
> 
> suiteFew.addTest(testFirewallS1("testPreConditionFirewall"))
> 
> 
> 
> 
> 
> #Testing the Test Cases Begins Here
> 
> unittest.TextTestRunner(verbosity=2).run(suiteFew)
> 
> 
> 
> How can I do access that method on __main__ and how can that method can 
> access the setup variable.
> 
> 
> 
> Thanks

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


Re: How to set the global variable so that it can be accessed and released inside other methods

2014-10-02 Thread Chris Angelico
On Fri, Oct 3, 2014 at 1:29 AM, Milson Munakami  wrote:
> #I am trying to set net variable to global
> global net
>
> def CreateNet(self):
> "Create an empty network and add nodes to it."
> net = Mininet( controller=RemoteController )

You're almost there! All you have to do is move that global
declaration into CreateNet itself. That's the only place where it's
assigned to.

I'm not sure why you have a class that sets up a global, though. It
would be much more normal to use "self.net" everywhere instead.

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


How to set the global variable so that it can be accessed and released inside other methods

2014-10-02 Thread Milson Munakami
Hi,

I am newbie to Python,

I am trying to use unittest and python. My python script is like this:

#! /usr/bin/env python
__author__ = 'Milson Munakami'
__revision__ = '0.0.2'

import json
import urllib
import httplib
from scapy.all import *

import unittest

import os, sys, socket, struct, select, time 
from threading import Thread

import logging
import traceback

from mininet.net import Mininet
from mininet.node import OVSSwitch, OVSKernelSwitch, Controller, 
RemoteController
from mininet.log import setLogLevel, info
from mininet.cli import CLI

class testFirewallS1( unittest.TestCase ):

#I am trying to set net variable to global
global net
##

def setUp(self):
self.controllerIp="127.0.0.1"
self.switch = "00:00:00:00:00:00:00:01"
self.destinationIp = "10.0.0.1"
self.startTime_ = time.time()
self.failed = False
self.reportStatus_ = True
self.name_ = "Firewall"
self.log = logging.getLogger("unittest")
self.CreateNet()
self.SetPrecondition()  

def CreateNet(self):
"Create an empty network and add nodes to it."
net = Mininet( controller=RemoteController )

info( '*** Adding controller\n' )
net.addController( 'c0' , controller=RemoteController,ip= 
"127.0.0.1", port=6633)

info( '*** Adding hosts\n' )
h1 = net.addHost( 'h1', ip='10.0.0.1' )
h2 = net.addHost( 'h2', ip='10.0.0.2' )
h3 = net.addHost( 'h3', ip='10.0.0.3' )

info( '*** Adding switch\n' )
s1 = net.addSwitch( 's1' )

info( '*** Creating links\n' )
net.addLink( h1, s1 )
net.addLink( h2, s1 )
net.addLink( h3, s1 )

info( '*** Starting network\n')
net.start()

def tearDown(self):
if self.failed:
return
duration = time.time() - self.startTime_
self.cleanup(True)
if self.reportStatus_:
self.log.info("=== Test %s completed normally (%d 
sec)", self.name_, duration)

def cleanup(self, success):
sys.excepthook = sys.__excepthook__
self.SetFinalcondition()
try:
return
except NameError:
self.log.error("Exception hit during cleanup, 
bypassing:\n%s\n\n" % traceback.format_exc())
pass
else:

fail("Expected a NameError")

def StatusFirewall(self):
command = "http://%s:8080/wm/firewall/module/status/json"; % 
self.controllerIp
x = urllib.urlopen(command).read()
parsedResult = json.loads(x)
return parsedResult['result']

def CountFirewallRules(self):
command = "http://%s:8080/wm/firewall/rules/json"; % 
self.controllerIp
x = urllib.urlopen(command).read()
return x

def CountFlowRules(self):
command = "http://%s:8080/wm/core/switch/%s/flow/json"; % 
(self.controllerIp, self.switch)
x = urllib.urlopen(command).read()
parsedResult = json.loads(x)
content = parsedResult['00:00:00:00:00:00:00:01']
if content is None:
return "[]"
else:   
return str(content)

def SetPrecondition(self):
command = "http://%s:8080/wm/firewall/module/enable/json"; % 
self.controllerIp
urllib.urlopen(command).read()

# cleanup all Firewall rules
command = "http://%s:8080/wm/firewall/rules/json"; % 
self.controllerIp
x = urllib.urlopen(command).read()
parsedResult = json.loads(x)
for i in range(len(parsedResult)):
params = "{\"ruleid\":\"%s\"}" % 
parsedResult[i]['ruleid']
command = "/wm/firewall/rules/json"
url = "%s:8080" % self.controllerIp
connection =  httplib.HTTPConnection(url)
connection.request("DELETE", command, params)
connection.getresponse().read()

# sleep for REST command to get processed to avoid racing
time.sleep(5)

def SetFinalcondition(self):
command = "http://%s:8080/wm/firewall/module/disable/json"; % 
self.controllerIp
urllib.urlopen(command).read()

# cleanup all Firewall rules
   

Re: Recommended hosting

2014-10-02 Thread Tim Golden
On 02/10/2014 14:30, writeson wrote:
> Hi all,
> 
> I'd like to build a web site for myself, essentially a "vanity" web
> site to show off whatever web development skills I have, and perhaps
> do some blogging. I'm a Python developer, so I'd like to develop the
> site with the following stack:
> 
> web applications written with Python and Flask, running as uwsgi
> applications. These would support dynamic HTML where needed, but
> mostly it would provide REST API's.
> 
> static content delivered by Nginx
> 
> Can anyone give me some recommendations for a good hosting company
> that would allow me work with the above tool set? I'm US based if
> that makes a difference.

WebFaction is definitely a good bet; I've used them for years and, aside
from their developer-friendly features, their support is always prompt,
responsive and helpful.

I'm also starting to look at Python Anywhere but I don't know enough
about their service to recommend them or not. (Altho' they've been
active supporters of the Python world especially in the UK for quite a
few years and they're basically smart and good guys).

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


Re: Assignment Operators?

2014-10-02 Thread Grant Edwards
On 2014-10-02, Chris Angelico  wrote:
> On Thu, Oct 2, 2014 at 11:24 PM, Didymus  wrote:
> errors = False
> errors |= 3
> errors
>> 3
> errors |= 4
> errors
>> 7

[...]

> When you use False there, it's equivalent to zero.

Why is that, you ask?  [Or should, anyway]

The fact that booleans when found in an arithmetic context are
auto-magically coerced into integers with values 0,1 is a rather
unpythonic wart which has it's historical roots in the time when
Python didn't have a boolean type.  People used integers instead and a
lot of code bound the names True and False to the integers 1 and 0.

When the boolean type was introduced it was decided that backwards
compatibility with that practice was important.  This resulted in two
pragmatic but somewhat "impure" decisions:

 1) In Python 2, True and False are not keywords, they're just global
keywords that come pre-bound to the boolean singleton values of
'true' and 'false'.  You can re-bind them to other objects:

  Python 2.7.7 (default, Aug 20 2014, 11:41:28)

  >>> False = 3.14159
  >>> if False: print "False"
  ... 
  False
  >>>
  >>> import math
  >>> math.cos(False)
  -0.99964793

 2) When used in an arithmetic context, boolean values would be
converted into integer values 0,1.

When Python 3 came out, 1) was dropped and True/False were "promoted"
to keywords.  But, 2) is still the case.

-- 
Grant Edwards   grant.b.edwardsYow! I guess you guys got
  at   BIG MUSCLES from doing too
  gmail.commuch STUDYING!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clearing globals in CPython

2014-10-02 Thread Chris Angelico
On Fri, Oct 3, 2014 at 12:07 AM, Grant Edwards  wrote:
> On 2014-10-01, Steven D'Aprano  wrote:
>
>> Obviously the easiest way to recover is to exit the current session and
>> restart it, but as a challenge, can we recover from this state?
>
> Python apparently _does_ need a "restart command".

Apparently not... you saw how easily Peter recovered :)

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


Re: Clearing globals in CPython

2014-10-02 Thread Grant Edwards
On 2014-10-01, Steven D'Aprano  wrote:

> Obviously the easiest way to recover is to exit the current session and
> restart it, but as a challenge, can we recover from this state?

Python apparently _does_ need a "restart command".

-- 
Grant Edwards   grant.b.edwardsYow! The PILLSBURY DOUGHBOY
  at   is CRYING for an END to
  gmail.comBURT REYNOLDS movies!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Grant Edwards
On 2014-10-02, c...@isbd.net  wrote:
> Travis Griggs  wrote:
>> 
>> 
>> Sent from my iPhone
>> 
>> > On Oct 1, 2014, at 04:12, Peter Otten <__pete...@web.de> wrote:
>> > 
>> > `lambda` is just a fancy way to define a function inline
>> 
>> Not sure "fancy" is the correct adjective; more like syntactic tartness 
>> (a less sweet version of syntactic sugar). 
>> 
> It throws me because 'lambda' simply has no meaning whatsoever for me,
> i.e. it's just a greek letter.
>
> So from my point of view it's like seeing 'epsilon' stuck in the
> middle of some code. 
>
> It's not as if I'm new to programming either, I've been writing
> software professionally since the early 1970s, now retired.

The use of "lamba" as a keyword to define an anonymous function is
borrowed from Lisp which got it from Lambda calculus.

http://en.wikipedia.org/wiki/Lambda_calculus

-- 
Grant Edwards   grant.b.edwardsYow! Is this going to
  at   involve RAW human ecstasy?
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Thoughts on python classes to represent an ebook reader

2014-10-02 Thread math math
Thanks a lot. It is quite helpful to follow the thought process here.
Another person gave the example of 'Calibre', but I've found it
overwhelming and I couldn't find any UML diagram there (maybe not searched
hard enough).

Regards,
Felix
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clearing globals in CPython

2014-10-02 Thread Marco Buttu

On 01/10/2014 18:00, Steven D'Aprano wrote:


Out of curiosity, I ran:

globals().clear()

in the interactive interpreter. It broke much more than I expected!
Built-ins were no longer available, and import stopped working.


Interesting... :D


Obviously the easiest way to recover is to exit the current session and
restart it, but as a challenge, can we recover from this state?


>>> [].__class__.__module__ # It is a string...
'__builtin__'

So, I do not have any idea about how to get a module without importing 
something. Thanks for sharing :)


--
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbu...@oa-cagliari.inaf.it

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


Recommended hosting

2014-10-02 Thread writeson
Hi all,

I'd like to build a web site for myself, essentially a "vanity" web site to 
show off whatever web development skills I have, and perhaps do some blogging. 
I'm a Python developer, so I'd like to develop the site with the following 
stack:

web applications written with Python and Flask, running as uwsgi applications. 
These would support dynamic HTML where needed, but mostly it would provide REST 
API's.

static content delivered by Nginx

Can anyone give me some recommendations for a good hosting company that would 
allow me work with the above tool set? I'm US based if that makes a difference.

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


Re: Assignment Operators?

2014-10-02 Thread Chris Angelico
On Thu, Oct 2, 2014 at 11:24 PM, Didymus  wrote:
 errors = False
 errors |= 3
 errors
> 3
 errors |= 4
 errors
> 7
>
>The '|=' operator, I read should be like a = a | b, but this appears to 
> add the two numbers as long as it's more than the previous:
>
 errors |= 5
 errors
> 7

It is indeed (mostly) equivalent to "a = a | b". Do you understand
what bitwise 'or' does?

When you use False there, it's equivalent to zero. Everything after
that is straight-forward bitwise or.

http://en.wikipedia.org/wiki/Bitwise_operation#OR

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


Assignment Operators?

2014-10-02 Thread Didymus
Hi All,

   I was wondering if someone could explain an assignment operator that I'm 
seeing in some code. As an example:

>>> errors = False
>>> errors |= 3
>>> errors 
3
>>> errors |= 4
>>> errors
7

   The '|=' operator, I read should be like a = a | b, but this appears to add 
the two numbers as long as it's more than the previous:

>>> errors |= 5
>>> errors
7

   Is there anywhere I can read up more on this and the other assignment 
operators and what/how they work. I got this off 

http://rgruet.free.fr/PQR27/PQR2.7.html


I'm using:
% python
Python 2.7.5 (default, Sep 25 2014, 13:57:38) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux2


  Thanks for any help in advance.
   
 Tom
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyqt problem

2014-10-02 Thread Sachin Tiwari
On Thursday, October 2, 2014 3:19:22 PM UTC+5:30, Sachin Tiwari wrote:
> Hi 
> 
> I am learning pyqt, can any one help me to make instances of pushbutton 
> wherever cursor will be clicked on canvas,like a circuit simulator where  we 
> add components on canvas just by left or right click.
> 
> 
> 
> Thanks & Regards,
> 
> Sachin

Hi

swch = QPushButton('', self)
swch.setToolTip('Switch ')
swch.setCheckable(True)
swch.setIcon(QIcon('sw.png'))
swch.setIconSize(QSize(40,40))
swch.move(05, 25)
swch.clicked.connect(self.switch)

The above code will make a push button on canvas, now what I want when I will 
click on this button it get ready to drop anywhere on canvas by left click,I 
mean if I click 10 times on canvas 10 push button will be there.
 

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


Re: Function passed as an argument returns none

2014-10-02 Thread Rustom Mody
On Thursday, October 2, 2014 1:30:03 PM UTC+5:30, Steven D'Aprano wrote:
> Chris Angelico wrote:

> > wrote:
> >> So by now you know there are 2 kinds of return:
> >> So the morals in short:
> >> 1. Stick to the return that works -- python's return statement --
> >> and avoid the return that seems to work -- the print statement
> > Please. There are not two types of return; there are two completely
> > different things here. Don't pretend that print is a bad form of
> > return. It isn't.

> I strongly agree with Chris here. The OP's problem was due to confusion
> between print and return, and the solution is to learn the difference
> between printing output to the screen and returning values from a function,
> and under what circumstances Python will automatically print said returned
> values as a convenience. Conflating the two as "2 kinds of return" is an
> invitation to even more confusion: "which was the 'good' return again?".

Right and the OP subject as well as post are essentially that conflation:

> Any idea why 'None' is getting passed even though calling the donuts(4)
> alone returns the expected value?

And further if you consider that the explanations have aided, here's the most
recent 'conclusion':

> * return 'Number of donuts: ',countreturns a tuple like:
> ('Number of donuts: ',9)

> * To just print the string without returning it as tuple , use string
> formatting. 

You find this understanding satisfactory??
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-02 Thread Rustom Mody
On Thursday, October 2, 2014 3:18:22 PM UTC+5:30, wrote:
> Steven D'Aprano  wrote:
> > between printing output to the screen and returning values from a function,
> > and under what circumstances Python will automatically print said returned
> > values as a convenience. Conflating the two as "2 kinds of return" is an

> To me automatically printing something is a mis-feature!

Hehe! Nice one!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-10-02 Thread Peter Tomcsanyi

Thanks again for quick and informative reply.

"Ned Deily"  wrote in message 
news:nad-40cb03.10344701102...@news.gmane.org...

The python.org 3.4.x series of installers will likely never change from
linking with Tk 8.5 by default.  That would break a number of important
third-party Python packages that supply binary distributions built for
the python.org OS X pythons, like matplotlib.


I respect your decision.
But it surprises me because the Windows version of Python 3.4.1 already 
comes with Tcl/Tk 8.6. Does it mean that there are no such problems with 
matplotlib etc. in Windows?
I think that one of the point when advertising Python is that it works 
accross the platforms, so keeping one platform (mac) "behind" for months 
seems to me going against the multiplatform promise of Python...



File an update request for the tcl and tk ports on the MacPorts tracker.
The project is usually very responsive to such requests.
https://trac.macports.org


Thanks for the suggestion, I was considering asking them, but I did not know 
what is the best place/best way to do it.



Note that ActiveState hasn't yet released their versions of 8.6.2.


I know, I am waching their Web page, too.


As Kevin Walzer points out, you *can* also build your own.

I know. But *can* is quite subjective.
Being a Windows-only user and programmer for a (too) long time, the idea 
that the end-user should compile something from sources is very 
unconfortable to me. So many things can go wrong it the process when working 
with toolchains that I am not familiar with.



Sorry for the delay!


You do not need to appologize, I understand that it is extra work and that 
you did not promise it for sure.


Best regards

Peter


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


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Marko Rauhamaa
c...@isbd.net:

> It's not as if I'm new to programming either, I've been writing
> software professionally since the early 1970s, now retired. I have no
> formal computer training, there wasn't much in the way of university
> courses on computing in the 1960s, I have a degree in Electrical
> Engineering. Maybe that's why 'lambda' means nothing to me! :-)

Lambda is special because it was thought of in the 1920's, well before
there were any general-purpose computers.

http://www.users.waitrose.com/~hindley/SomePapers_PDFs/2006CarH
in,HistlamRp.pdf>

See Chapter 4.


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


Re: pyqt problem

2014-10-02 Thread Mark Lawrence

On 02/10/2014 10:49, sachin.tiwar...@gmail.com wrote:

Hi
I am learning pyqt, can any one help me to make instances of pushbutton 
wherever cursor will be clicked on canvas,like a circuit simulator where  we 
add components on canvas just by left or right click.

Thanks & Regards,
Sachin



Please show us what you're tried so far and where it's going wrong, 
we're not here simply to write code for you.


--
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


pyqt problem

2014-10-02 Thread sachin . tiwari50
Hi 
I am learning pyqt, can any one help me to make instances of pushbutton 
wherever cursor will be clicked on canvas,like a circuit simulator where  we 
add components on canvas just by left or right click.

Thanks & Regards,
Sachin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread cl
Travis Griggs  wrote:
> 
> 
> Sent from my iPhone
> 
> > On Oct 1, 2014, at 04:12, Peter Otten <__pete...@web.de> wrote:
> > 
> > `lambda` is just a fancy way to define a function inline
> 
> Not sure "fancy" is the correct adjective; more like syntactic tartness 
> (a less sweet version of syntactic sugar). 
> 
It throws me because 'lambda' simply has no meaning whatsoever for me,
i.e. it's just a greek letter.

So from my point of view it's like seeing 'epsilon' stuck in the
middle of some code. 

It's not as if I'm new to programming either, I've been writing
software professionally since the early 1970s, now retired.  I have no
formal computer training, there wasn't much in the way of university
courses on computing in the 1960s, I have a degree in Electrical
Engineering.  Maybe that's why 'lambda' means nothing to me!  :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-02 Thread cl
Steven D'Aprano  wrote:
> between printing output to the screen and returning values from a function,
> and under what circumstances Python will automatically print said returned
> values as a convenience. Conflating the two as "2 kinds of return" is an

To me automically printing something is a mis-feature!

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-02 Thread Chris Angelico
On Thu, Oct 2, 2014 at 6:46 PM, Shiva
 wrote:
> Hi All,
>
> Thank you everyone. This is fantastic - I post a query and go to sleep and
> by the time I get up there is already a nice little thread of discussion
> going on.

Yeah, that's what python-list is like! Busy list, lots of opinionated
people here...

> By the way, I sorted it with all your suggestions.
>
> def donuts(count):
>   if count <= 9: #This had to be 9 instead of 5 as per the question req.
> return 'Number of donuts: {0}'.format(count)
>   else:
> return 'Number of donuts: many'

Looks good!

> So to summarise what I learnt:
>
> * Just 'return' returns None - it is not related to what you print inside
> the function.If you want something specific out of a function return
> something specific.

Correct. As Steven and I said, printing is unrelated to returned
values. Running off the end of a function, or using "return" on its
own, is the same as "return None".

> * return 'Number of donuts: ',countreturns a tuple like:
> ('Number of donuts: ',9)

Right. The comma creates a tuple; the parentheses are printed on
display, to make it easier to read, but it's the comma that does it.
The comma has different meaning in some places, such as a function
call (like print), but otherwise it'll create a tuple.

> * To just print the string without returning it as tuple , use string
> formatting.

Yep! You're three for three. There are other ways to do things (you
could use str() and concatenation, or percent formatting, or any
number of ways), but they all do the same thing: they construct a
single string, which you can then return. Incidentally, when you use
.format() as you do there, the number 0 can be omitted - it's obvious
to the parser, so you can shortcut it:

>>> "Hello, {}!".format("world")
'Hello, world!'

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


Re: Function passed as an argument returns none

2014-10-02 Thread Shiva
Hi All,

Thank you everyone. This is fantastic - I post a query and go to sleep and
by the time I get up there is already a nice little thread of discussion
going on.

By the way, I sorted it with all your suggestions.

def donuts(count):
  if count <= 9: #This had to be 9 instead of 5 as per the question req.
return 'Number of donuts: {0}'.format(count)
  else:
return 'Number of donuts: many'

So to summarise what I learnt:

* Just 'return' returns None - it is not related to what you print inside
the function.If you want something specific out of a function return
something specific.

* return 'Number of donuts: ',countreturns a tuple like:
('Number of donuts: ',9)

* To just print the string without returning it as tuple , use string
formatting.

Thanks again,
Shiva

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


Re: Obscuring Python source from end users

2014-10-02 Thread Chris Angelico
On Thu, Oct 2, 2014 at 5:50 PM, Johannes Bauer  wrote:
> On 29.09.2014 16:53, Sturla Molden wrote:
>> Chris Angelico  wrote:
>>
 I have a project that involves distributing Python code to users in an
 organisation. Users do not interact directly with the Python code; they
 only know this project as an Excel add-in.

 Now, internal audit takes exception in some cases if users are able to
 see the source code.
>>>
>>> The solution is to fix your internal audit.
>>
>> +1
>
> You two have obviously never worked at a large corporation or you would
> both realize how tremendously naive and unhelpful this "solution" is.

Unhelpful? Perhaps, perhaps not. I would, however, distinguish between
the two parts of my original response as follows:

1) The *solution* is to fix the audit process.

2) But here's one of several *work-arounds*.

It may well be impossible to truly solve the problem, and I'm aware of
that. But sometimes you need to point out that a pyc-only distribution
is still distributing something very VERY close to the source code,
and therefore it's nigh useless to talk of not distributing Python
source.

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


Re: Clearing globals in CPython

2014-10-02 Thread Mark Lawrence

On 02/10/2014 09:11, Steven D'Aprano wrote:

Peter Otten wrote:


Steven D'Aprano wrote:



Obviously the easiest way to recover is to exit the current session and
restart it, but as a challenge, can we recover from this state?


$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

globals().clear()
import that

Traceback (most recent call last):
   File "", line 1, in 
ImportError: __import__ not found

object = 1 .__class__.__bases__[0]
Quitter = [c for c in object.__subclasses__() if c.__name__ ==

"Quitter"][0]

__builtins__ = Quitter.__call__.__globals__["__builtins__"]
import this

The Zen of Python, by Tim Peters


Nicely done!



Other than the Zen of Python what has Tim Peters ever done for us? 
Apart from...


--
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: Clearing globals in CPython

2014-10-02 Thread Steven D'Aprano
Peter Otten wrote:

> Steven D'Aprano wrote:

>> Obviously the easiest way to recover is to exit the current session and
>> restart it, but as a challenge, can we recover from this state?
> 
> $ python3
> Python 3.4.0 (default, Apr 11 2014, 13:05:11)
> [GCC 4.8.2] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 globals().clear()
 import that
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: __import__ not found
 object = 1 .__class__.__bases__[0]
 Quitter = [c for c in object.__subclasses__() if c.__name__ ==
> "Quitter"][0]
 __builtins__ = Quitter.__call__.__globals__["__builtins__"]
 import this
> The Zen of Python, by Tim Peters

Nicely done! 



-- 
Steven

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


Re: Function passed as an argument returns none

2014-10-02 Thread Steven D'Aprano
Chris Angelico wrote:

> On Thu, Oct 2, 2014 at 12:29 PM, Rustom Mody 
> wrote:
>> So by now you know there are 2 kinds of return:
>>
>> So the morals in short:
>>
>> 1. Stick to the return that works -- python's return statement --
>> and avoid the return that seems to work -- the print statement
> 
> Please. There are not two types of return; there are two completely
> different things here. Don't pretend that print is a bad form of
> return. It isn't.

I strongly agree with Chris here. The OP's problem was due to confusion
between print and return, and the solution is to learn the difference
between printing output to the screen and returning values from a function,
and under what circumstances Python will automatically print said returned
values as a convenience. Conflating the two as "2 kinds of return" is an
invitation to even more confusion: "which was the 'good' return again?".

While it is true that both return and print are related in the sense that
they are both ways of having a function produce output, that's about the
end of the similarity. One might as well say that assignment is a third
kind of return, because one can assign output to a global variable.

(Since print does not actually exit the current sub-routine, it definitively
is not a kind of return.)


-- 
Steven

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


Re: Obscuring Python source from end users

2014-10-02 Thread Johannes Bauer
On 29.09.2014 16:53, Sturla Molden wrote:
> Chris Angelico  wrote:
> 
>>> I have a project that involves distributing Python code to users in an
>>> organisation. Users do not interact directly with the Python code; they
>>> only know this project as an Excel add-in.
>>>
>>> Now, internal audit takes exception in some cases if users are able to
>>> see the source code.
>>
>> The solution is to fix your internal audit.
> 
> +1

You two have obviously never worked at a large corporation or you would
both realize how tremendously naive and unhelpful this "solution" is.

Cheers,
Johannes

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Obscuring Python source from end users

2014-10-02 Thread Steven D'Aprano
Marko Rauhamaa wrote:

> Dan Stromberg :
> 
>> On Mon, Sep 29, 2014 at 4:47 AM, Steven D'Aprano
>>> Yes. Distribute the pyc files only.
>>
>> Yes, this is the way it's usually done.
> 
> Has the .pyc file format stabilized? A decade ago, my employer shipped
> an application as .pyc files but had to ship the matching CPython binary
> with it.

There is no promise that Python byte code or the format of .pyc files will
be stable across minor releases. However, PEP 6 states that bugfix releases
should have stable .pyc files. 

http://legacy.python.org/dev/peps/pep-0006/

So, you ought to expect that .pyc files will change when any of the
following differs:

- the hardware (e.g. 32- versus 64-bit, or ARM versus x86 processor);

- the Python implementation (e.g. Stackless versus CPython);

- the minor or major version number (e.g. 2.6 to 2.7, or 2.x to 3.x);

but you can expect the .pyc files to remain compatible for:

- the operating system (e.g. Windows, Mac, Linux);

- bug-release versions (e.g. 2.7.1 to 2.7.2).

Of course, you can distribute the Python executable, but it may be easier to
just distribute a separate .pyc file for each minor release you wish to
support.

Here are some comments from one of the senior core developers:

http://www.curiousefficiency.org/posts/2011/04/benefits-and-limitations-of-pyc-only.html



-- 
Steven

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


Re: Obscuring Python source from end users

2014-10-02 Thread Terry Reedy

On 10/2/2014 1:17 AM, Marko Rauhamaa wrote:

Dan Stromberg :


On Mon, Sep 29, 2014 at 4:47 AM, Steven D'Aprano

Yes. Distribute the pyc files only.


Yes, this is the way it's usually done.


Has the .pyc file format stabilized?


No. The cache files are binary specific and are so labelled. x.py is 
compiled, for instance, to x.cpython-34.pyc



A decade ago, my employer shippe
an application as .pyc files but had to ship the matching CPython binary
with it.



--
Terry Jan Reedy

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