[Tutor] downloading modules for both python 2 and 3

2017-04-09 Thread Benjamin Fishbein
I’ve been writing an app using Kivy, and now I want to test it out on an 
iPhone. However, this can currently only be done in Python 2.
https://kivy.org/docs/guide/packaging-ios.html 

But when I import kivy in Python2, I get an ImportError.
ImportError: No module named kivy
So I need to install kivy for Python 2.
But when I do:
sudo pip install kivy
I get the following:
Requirement already satisfied: requests in 
./anaconda/lib/python3.5/site-packages (from Kivy-Garden>=0.1.4->kivy) 

Do you know how I can convince my computer to download a module for Python 2 
when I already have it for Python 3?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What would be good use cases for the enum module?

2017-04-09 Thread Alan Gauld via Tutor
On 09/04/17 04:00, boB Stepp wrote:

> understandable to me, but I am having difficulty imagining where I
> might want to use these features.
> 

Steven has given the basics, here are a few more real world examples:

Any kind of status value:
(open,closed,opening, closing,locked)  - control valve
(on, off) - light
(red,green,amber,red-amber) - uk traffic light

small collections:
days of week
months in year
(cleaning, reception, waiting, valet) - rota duties
(hourly,daily,weekly,monthly,annual) - schedules

Enums are very common in larger programs once you get
used to the concept. It's a bit like dictionaries: many
traditional programmers think of everything as arrays
and can't initially think of when they would use a dictionary
(arbitrary key rather than numeric index) But once you
get started you find dictionaries are at least as useful
as arrays..

And, surprise, surprise, there is a link. Very often
enums form the set of valid keys to a dictionary...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] downloading modules for both python 2 and 3

2017-04-09 Thread Peter Otten
Benjamin Fishbein wrote:

> I’ve been writing an app using Kivy, and now I want to test it out on an
> iPhone. However, this can currently only be done in Python 2.
> https://kivy.org/docs/guide/packaging-ios.html
>  But when I import kivy in
> Python2, I get an ImportError. ImportError: No module named kivy So I need
> to install kivy for Python 2. But when I do:
> sudo pip install kivy
> I get the following:
> Requirement already satisfied: requests in
> ./anaconda/lib/python3.5/site-packages (from Kivy-Garden>=0.1.4->kivy)
> 
> Do you know how I can convince my computer to download a module for Python
> 2 when I already have it for Python 3?

On my (Linux) system there are multiple versions of pip, called pip2, pip3, 
pip3.7; you might look for those.

Or you try to pick the desired interpreter with

$ sudo /path/to/desired/python -m pip install kivy

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What would be good use cases for the enum module?

2017-04-09 Thread Mats Wichmann
On 04/09/2017 01:54 AM, Alan Gauld via Tutor wrote:
> On 09/04/17 04:00, boB Stepp wrote:
> 
>> understandable to me, but I am having difficulty imagining where I
>> might want to use these features.
>>
> 
> Steven has given the basics, here are a few more real world examples:
> 
> Any kind of status value:
> (open,closed,opening, closing,locked)  - control valve
> (on, off) - light
> (red,green,amber,red-amber) - uk traffic light
> 
> small collections:
> days of week
> months in year
> (cleaning, reception, waiting, valet) - rota duties
> (hourly,daily,weekly,monthly,annual) - schedules

All of these can of course be done without enums.  So the extra benefit
of an enum is that the set is closed (immutable) and requires
uniqueness: picking some other value will be an error, adding a new
enumerator with an already used value is an error.

Not sure if the question really way "what good are enums" or "what good
is the new Python enum module"... in looking that over there seems to be
a lot of stuff, almost seems unlike the Python project to add something
with so many options, that really doesn't have *huge* utility.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2017-04-09 Thread shubham goyal
Hello, I am a c++ programmer and wants to learn python for internship
purposes. How can i learn the advanced python fast mostly data science
packages, I know basic python.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What would be good use cases for the enum module?

2017-04-09 Thread Alan Gauld via Tutor
On 09/04/17 13:58, Mats Wichmann wrote:

> All of these can of course be done without enums.  So the extra benefit
> of an enum is that the set is closed (immutable) and requires
> uniqueness: picking some other value will be an error, 

Indeed, good catch. The value of an enum over an integer is
that the values are limited to those prescribed by the enum,
any attempt to pass or create a different value will be an error.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] downloading modules for both python 2 and 3

2017-04-09 Thread Mats Wichmann
On 04/09/2017 02:20 AM, Peter Otten wrote:
> Benjamin Fishbein wrote:
> 
>> I’ve been writing an app using Kivy, and now I want to test it out on an
>> iPhone. However, this can currently only be done in Python 2.
>> https://kivy.org/docs/guide/packaging-ios.html
>>  But when I import kivy in
>> Python2, I get an ImportError. ImportError: No module named kivy So I need
>> to install kivy for Python 2. But when I do:
>> sudo pip install kivy
>> I get the following:
>> Requirement already satisfied: requests in
>> ./anaconda/lib/python3.5/site-packages (from Kivy-Garden>=0.1.4->kivy)
>>
>> Do you know how I can convince my computer to download a module for Python
>> 2 when I already have it for Python 3?
> 
> On my (Linux) system there are multiple versions of pip, called pip2, pip3, 
> pip3.7; you might look for those.
> 
> Or you try to pick the desired interpreter with
> 
> $ sudo /path/to/desired/python -m pip install kivy

I'd highly suggest building a virtualenv for work requiring a specific
project to be installed. When doing that, you can call out the Python
you want involved, something like this sequence I just ran:

$ virtualenv -p /usr/bin/python2 kivywork
Already using interpreter /usr/bin/python2
New python executable in /home/mats/kivywork/bin/python2
Also creating executable in /home/mats/kivywork/bin/python
Installing setuptools, pip, wheel...done.
$ cd kivywork/bin
$ source activate
(kivywork) $ pip install --upgrade pip
Requirement already up-to-date: pip in
/home/mats/kivywork/lib/python2.7/site-packages
(kivywork) $ pip install --upgrade setuptools
Requirement already up-to-date: setuptools in
/home/mats/kivywork/lib/python2.7/site-packages
Requirement already up-to-date: appdirs>=1.4.0 in
/home/mats/kivywork/lib/python2.7/site-packages (from setuptools)
Requirement already up-to-date: packaging>=16.8 in
/home/mats/kivywork/lib/python2.7/site-packages (from setuptools)
Requirement already up-to-date: six>=1.6.0 in
/home/mats/kivywork/lib/python2.7/site-packages (from setuptools)
Requirement already up-to-date: pyparsing in
/home/mats/kivywork/lib/python2.7/site-packages (from
packaging>=16.8->setuptools)
(kivywork) $ pip install kivy
Collecting kivy
  Downloading kivy-1.9.1.tar.gz (16.4MB)
100% || 16.4MB 91kB/s
Complete output from command python setup.py egg_info:
Using distutils

Cython is missing, its required for compiling kivy !


Traceback (most recent call last):
  File "", line 1, in 
  File "/tmp/pip-build-ZXsSua/kivy/setup.py", line 184, in 
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils


Command "python setup.py egg_info" failed with error code 1 in
/tmp/pip-build-ZXsSua/kivy/
$


Well, you get the idea.  I couldn't finish the install for the reason
listed.  With a virtualenv you get a controlled environment specifically
for what you want to do; the "activate" step gets it going, and changes
your prompt to show you you're in that environment. Should you need to
clean up now, it's a snap - just remove the virtualenv directory; you
have not messed with your "system" python.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What would be good use cases for the enum module?

2017-04-09 Thread boB Stepp
On Sat, Apr 8, 2017 at 11:13 PM, Steven D'Aprano  wrote:
> On Sat, Apr 08, 2017 at 10:00:21PM -0500, boB Stepp wrote:
>> After reading some discussion on the Python main list about the enum
>> module and some suggested changes, I thought I would read the docs on
>> it at
>> https://docs.python.org/3/library/enum.html?highlight=enum#module-enum
> [...]
>> And I am having an even harder time imagining what I would want to use
>> Enum for if I don't care about the values assigned to the names and
>> use auto to automatically assign values.  I am having a real crisis of
>> imagination here!  Anyone with some commonplace and practical
>> applications of the enum module?
>
> Have you read the PEP for the enum module? There's also an earlier,
> rejected PEP:
>
> https://www.python.org/dev/peps/pep-0354/
>
> https://www.python.org/dev/peps/pep-0435/

A general question about PEPs:  Is there generally a PEP preceding the
addition of any new feature to the core language or the standard
library?  I gather that even an accepted PEP (In this instance PEP
0435.) may not reflect the final form of the added feature(s) as I did
not see direct mention of "auto", though that feature was alluded to.

> ... but basically an enum
> is an abstract symbol with a pretty representation to make debugging
> easier.
>
> For example, suppose I have a function that justifies a paragraph of
> text:
>
> def justify(paragraph, where):
> ...
>
> where the `where` argument specifies whether to justify the text on the
> left, on the right, in the centre, or fully justified on both sides. One
> way to specify that is to use numeric constants:
>
> if where == 1:
> # justify on the left
> elif where == 2:
> # justify on the right
> elif where == 3:
> # justify in the centre
> elif where == 4:
> # fully justify at both ends
>
> but there's no connection between the numbers I choose and the type of
> justification. I could just have sensibly used -3, 87, 4 and 32.5 as 1,
> 2, 3 and 4.
>
> A bit better is to use strings:
>
> if where == 'LEFT':
> # justify on the left
> elif where == 'RIGHT':
> # etc
>
> which at least now is self-documenting, but it suggests that the `where`
> argument might take any string at all, which is not correct. There are
> only four fixed values it can take. And besides, having to use the
> quotation marks is tiresome.
>
> So let's invent four (or even five, for Americans) named constants:
>
> LEFT = 'LEFT'
> RIGHT = 'RIGHT'
> CENTRE = CENTER = 'CENTRE'
> FULL = 'FULLY JUSTIFIED'
>
>
> Now we're getting closer. The caller can say:
>
> text = justify(some_text, CENTRE)
>
> which is nice, and the justify() function can include:
>
> if where == LEFT:
> ...
>
> without quotation marks, which is also nice. That solves about 95% of
> the problem.

Up to this point was basically where I was at when I submitted my
questions.  Why have enumerations when this is already quite doable?
But what you write next turns on the light bulb for me:

> The last niggly 5% is a subtle thing. Because the constants are strings,
> we might be tempted to do string things to them, either deliberately or
> by mistake:
>
>
> justification_mode = CENTRE.lower() + LEFT[1:]  # Oops!
> # much later
> justify(some_text, justification_mode)
>
>
> which of course will fail, but it will fail *when the string is used*,
> not when you do the string-stuff to those constants. It would be nice if
> it failed straight away, at the "justification_mode" line.
>
> To fix that, we need something which looks like a string when you print
> it, for debugging, but actually isn't a string, so it doesn't accept all
> the usual string methods. That's effectively just an abstract symbol,
> and the way to get this in Python is with an enum.

Thanks, Steve, that clarifies things quite nicely.  Great example!

> Enums have a few other nice properties, which you may or may not care
> about, but the primary use is to act as set of related named symbols.
>

The iterability looks useful.  IntEnum looks interesting.  IntFlag and
Flag I am currently clueless about.  I would have to dig deeper as I
don't fully understand their uses yet.

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-04-09 Thread Mats Wichmann
On 04/09/2017 04:42 AM, shubham goyal wrote:
> Hello, I am a c++ programmer and wants to learn python for internship
> purposes. How can i learn the advanced python fast mostly data science
> packages, I know basic python.

Try an internet search?

Don't mean to be snide, but there are lots of resources, including a ton
of books, several courses, tutorials, websites, etc.  For example:

https://www.analyticsvidhya.com/blog/2016/10/18-new-must-read-books-for-data-scientists-on-r-and-python/

We can /possibly/ help you with specific questions here.


Quick hint: you will need to think a little differently in Python than
C++, static vs. dynamic typing, classes work differently, private things
are not really private, etc.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-04-09 Thread Alan Gauld via Tutor
On 09/04/17 11:42, shubham goyal wrote:
> Hello, I am a c++ programmer and wants to learn python for internship
> purposes. How can i learn the advanced python fast mostly data science
> packages, I know basic python.

There are tutorials on most things.
But it depends on what you mean by advanced python. The ScyPy and NumPy
type stuff is certainly for advanced users of Python but mostly the
Python itself is fairly standard. To me, advanced Python means messing
around with metaclasses, decorators, functools, itertools and the like.

But thee are so many niche areas where Python is used its almost
impossible to recommend any single direction. Once past the basics
its a case of specializing in a given domain.

The biggest jump for most C++ programmers is giving up on type safety.
C++ has strict typing embedded as a religious dogma that it can seem
very strange for a C++ programmer to rely on dynamic typing and trust
that the system will just work. It was one of the things that surprised
me - that by giving up strict typing my programs were no less reliable.
But that understanding does change the way you design and think about
code - and, in particular, how you design and use objects.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Tkinter entry box text changed event

2017-04-09 Thread Phil
Again, thank you for reading this.

I would like a function to be called when I enter text and then tab to the next 
entry box. I've been trying to follow the answers to similar questions in Stack 
Overflow but I've become hopelessly confused because of the different answers 
given to seemingly the same question.

I have created a row of entry boxes and a matching function like this:

for i in range(8):
self.numbers[i]= Entry(master, width=4, justify=CENTER, foreground="gray")
self.numbers[i].grid(row=16, column=i)
self.numbers[i].bind('StringVar()', self.my_function)

def my_function(event):
print("function called")

The function is not called and I know that the binding of the function to the 
entry boxes is not the correct method. What am I missing?

-- 
Regards,
Phil
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor