[Tutor] printing items form list

2017-03-03 Thread Rafael Knuth
I want to print individual items from a list like this:

You have a book, towel, shirt, pants in your luggage.

This is my code:

suitcase = ["book", "towel", "shirt", "pants"]
print ("You have a %s in your luggage." % suitcase)

Instead of printing out the items on the list, my code appends the
list to the string. How do I need to modify my code?

== RESTART: C:/Users/Rafael/Documents/01 - BIZ/Python/Python Code/PPC_7.py ==
You have a ['book', 'towel', 'shirt', 'pants'] in your luggage.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing items form list

2017-03-03 Thread Peter Otten
Rafael Knuth wrote:

> I want to print individual items from a list like this:
> 
> You have a book, towel, shirt, pants in your luggage.
> 
> This is my code:
> 
> suitcase = ["book", "towel", "shirt", "pants"]
> print ("You have a %s in your luggage." % suitcase)
> 
> Instead of printing out the items on the list, my code appends the
> list to the string. How do I need to modify my code?

Have a look at the str.join() method:

>>> suitcase = ["book", "towel", "shirt", "pants"]
>>> print("You have a %s in your luggage." % ", ".join(suitcase))
You have a book, towel, shirt, pants in your luggage.

See 


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


[Tutor] Tables in Tkinter

2017-03-03 Thread Pooja Bhalode
Hi,

I am trying to use tkintertable in Python 2.7 to create a table in GUI
using Tkinter.
The table that I am trying to get is a table with scrollable rows. I just
want to display the data in the table in the Tkinter window. I do not wish
to make it interactive, since  just want to display the data.

it would have two columns: Experiments and sensitivity
And number of rows based on the number of experiments present. These number
of rows would have a scrollbar attached to it so that the user can scroll
to the last row if needed.
Can someone please suggest me how I can proceed?
I tried reading through the page: https://github.com/dmnfarrell/tkintertable
But I am not able to understand how to create or edit the row and column
names.
I would really appreciate it if you could let me know.
Thank you so much.

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


[Tutor] Radiobuttons (two options out of 4)

2017-03-03 Thread Pooja Bhalode
Hi,

I am trying to create a GUI with four options out of which the user is
supposed to select two. But once the user selected two out of those four
options, the others need to get greyed out at that instant.

I tried the following thing:

*Label(lom, text = "Choose two options from:").grid(row = 9, column = 1,
sticky = W)*
* check1butt = Checkbutton(lom, text = "A-optimality", variable =
check1).grid(row = 10, column = 1, sticky = W)*
* check2butt = Checkbutton(lom, text = "D-optimality", variable =
check2).grid(row = 11, column = 1, sticky = W)*
* check3butt = Checkbutton(lom, text = "E-optimality", variable =
check3).grid(row = 12, column = 1, sticky = W)*
* check4butt = Checkbutton(lom, text = "Parameter Co-Variance", variable =
check4).grid(row = 13, column = 1, sticky = W)*
* if check1.get() == 1:*
* if check2.get() == 1:*
* check3butt.config(state = 'disabled')*
* check4butt.config(state = 'disabled')*
But here, the other two options do not greyed out after selecting the first
and the second option. I am aware that this is still half way there, but
this snippet doesnot seem to work the way it should.

Can someone please suggest me what I can do? Or any other ways to do this?
I was thinking of using Radiobuttons, but then radiobuttons only allow one
option to be chosen. Is there a way?
Thank you

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


Re: [Tutor] printing items form list

2017-03-03 Thread Mats Wichmann
On 03/03/2017 05:12 AM, Rafael Knuth wrote:
> I want to print individual items from a list like this:
> 
> You have a book, towel, shirt, pants in your luggage.
> 
> This is my code:
> 
> suitcase = ["book", "towel", "shirt", "pants"]
> print ("You have a %s in your luggage." % suitcase)
> 
> Instead of printing out the items on the list, my code appends the
> list to the string. How do I need to modify my code?
> 
> == RESTART: C:/Users/Rafael/Documents/01 - BIZ/Python/Python Code/PPC_7.py ==
> You have a ['book', 'towel', 'shirt', 'pants'] in your luggage.


By way of explanation:

suitcase = ["book", "towel", "shirt", "pants"]
print(type(suitcase))
print ("You have a %s in your luggage." % suitcase)


===

You have a ['book', 'towel', 'shirt', 'pants'] in your luggage.

suitcase is a list.  You explicitly ask for it to be shown a string with
"%s", so the list class's string representation method is called to
produce what the class thinks is the best way to show what the list
contents looks like.  that conversion to a string someone else's idea
(Python default), but not what you wanted, though; joining with commas
is the right choice based on what you said you wanted.


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


Re: [Tutor] printing items form list

2017-03-03 Thread Antonio Zagheni via Tutor
Hello Rafael,
I believe you are a beginner...
That is another way to do 
this...-
suitcase = ["book, ", "towel, ", "shirt, ", "pants"]
st = ''

for i in suitcase:
    
    st = st + i
    
print ("You have a %s in your luggage.") %st

Best regards...
Antonio Zagheni.

  From: "tutor-requ...@python.org" 
 To: tutor@python.org 
 Sent: Friday, March 3, 2017 2:00 PM
 Subject: Tutor Digest, Vol 157, Issue 8
   
Send Tutor mailing list submissions to
    tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
    https://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
    tutor-requ...@python.org

You can reach the person managing the list at
    tutor-ow...@python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

  1. printing items form list (Rafael Knuth)
  2. Re: printing items form list (Peter Otten)


--

Message: 1
Date: Fri, 3 Mar 2017 13:12:23 +0100
From: Rafael Knuth 
To: "Tutor@python.org" 
Subject: [Tutor] printing items form list
Message-ID:
    
Content-Type: text/plain; charset=UTF-8

I want to print individual items from a list like this:

You have a book, towel, shirt, pants in your luggage.

This is my code:

suitcase = ["book", "towel", "shirt", "pants"]
print ("You have a %s in your luggage." % suitcase)

Instead of printing out the items on the list, my code appends the
list to the string. How do I need to modify my code?

== RESTART: C:/Users/Rafael/Documents/01 - BIZ/Python/Python Code/PPC_7.py ==
You have a ['book', 'towel', 'shirt', 'pants'] in your luggage.


--

Message: 2
Date: Fri, 03 Mar 2017 13:30:23 +0100
From: Peter Otten <__pete...@web.de>
To: tutor@python.org
Subject: Re: [Tutor] printing items form list
Message-ID: 
Content-Type: text/plain; charset="ISO-8859-1"

Rafael Knuth wrote:

> I want to print individual items from a list like this:
> 
> You have a book, towel, shirt, pants in your luggage.
> 
> This is my code:
> 
> suitcase = ["book", "towel", "shirt", "pants"]
> print ("You have a %s in your luggage." % suitcase)
> 
> Instead of printing out the items on the list, my code appends the
> list to the string. How do I need to modify my code?

Have a look at the str.join() method:

>>> suitcase = ["book", "towel", "shirt", "pants"]
>>> print("You have a %s in your luggage." % ", ".join(suitcase))
You have a book, towel, shirt, pants in your luggage.

See 




--

Subject: Digest Footer

___
Tutor maillist  -  Tutor@python.org
https://mail.python.org/mailman/listinfo/tutor


--

End of Tutor Digest, Vol 157, Issue 8
*


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


Re: [Tutor] printing items form list

2017-03-03 Thread Peter Otten
Antonio Zagheni via Tutor wrote:

> suitcase = ["book, ", "towel, ", "shirt, ", "pants"] 

Hm, looks like you opened Rafael's suitcase while he wasn't looking, and 
sneaked in some commas and spaces ;) 

That's cheating...

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


Re: [Tutor] printing items form list

2017-03-03 Thread David Rock

> On Mar 3, 2017, at 12:52, Peter Otten <__pete...@web.de> wrote:
> 
> Antonio Zagheni via Tutor wrote:
> 
>> suitcase = ["book, ", "towel, ", "shirt, ", "pants"]
> 
> Hm, looks like you opened Rafael's suitcase while he wasn't looking, and
> sneaked in some commas and spaces ;)
> 
> That's cheating...

yeah, just a little. :-)

You can use join for this:

suitcase = ["book", "towel", "shirt", "pants"]
output = ', '.join(suitcase)
print ("You have a %s in your luggage.") %output


—
David Rock
da...@graniteweb.com




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


Re: [Tutor] printing items form list

2017-03-03 Thread Alan Gauld via Tutor
On 03/03/17 18:52, Peter Otten wrote:
> Antonio Zagheni via Tutor wrote:
> 
>> suitcase = ["book, ", "towel, ", "shirt, ", "pants"] 
> 
> Hm, looks like you opened Rafael's suitcase while he wasn't looking, and 
> sneaked in some commas and spaces ;) 
> 
> That's cheating...

Its also very difficult to maintain since if you add
new items to the suitcase you need to make sure they
all have commas except the last one. And inconsistent data formatting in
a list is a nightmare.

For example, what happens if you decide to sort the list,
the last item is no longer last and the commas are all
messed up.

That's one reason why join() is a better solution, it
handles all of that for you. It's also faster, although
in a small application you'd never notice the difference.

-- 
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] Tables in Tkinter

2017-03-03 Thread Alan Gauld via Tutor
On 03/03/17 16:07, Pooja Bhalode wrote:

> The table that I am trying to get is a table with scrollable rows. I just
> want to display the data in the table in the Tkinter window. I do not wish
> to make it interactive, since  just want to display the data.

In that case you could just use a scrolled frame (from PMW, which you
installed as part of the tkintertable install). Simply add labels
using the grid manager into your frame. Set a different background
colour for the top row to make them headings and choose appropriate
borders and styles.

It should be fairly easy to build up a simple display grid that way.

-- 
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] printing items form list

2017-03-03 Thread dirkjso...@gmail.com

On 03/03/2017 12:19 PM, Alan Gauld via Tutor wrote:

On 03/03/17 18:52, Peter Otten wrote:

Antonio Zagheni via Tutor wrote:


suitcase = ["book, ", "towel, ", "shirt, ", "pants"]

Hm, looks like you opened Rafael's suitcase while he wasn't looking, and
sneaked in some commas and spaces ;)

That's cheating...

Its also very difficult to maintain since if you add
new items to the suitcase you need to make sure they
all have commas except the last one. And inconsistent data formatting in
a list is a nightmare.

For example, what happens if you decide to sort the list,
the last item is no longer last and the commas are all
messed up.

That's one reason why join() is a better solution, it
handles all of that for you. It's also faster, although
in a small application you'd never notice the difference.

The ','.join(suitcase) is obviously best of all, but if one doesn't know 
that method, the below suggestion can be fixed with:


suitcase = ['book', 'towel', 'shirt', 'pants']

for i in suitcase:
st = st + i + ', '

print('You have a s% in your luggage.' % st)


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


Re: [Tutor] Radiobuttons (two options out of 4)

2017-03-03 Thread Alan Gauld via Tutor
On 03/03/17 16:43, Pooja Bhalode wrote:

> I am trying to create a GUI with four options out of which the user is
> supposed to select two. But once the user selected two out of those four
> options, the others need to get greyed out at that instant.
> 
> I tried the following thing:
> 
> *Label(lom, text = "Choose two options from:").grid(row = 9, column = 1,
> sticky = W)*
> * check1butt = Checkbutton(lom, text = "A-optimality", variable =
> check1).grid(row = 10, column = 1, sticky = W)*
> * check2butt = Checkbutton(lom, text = "D-optimality", variable =
> check2).grid(row = 11, column = 1, sticky = W)*
> * check3butt = Checkbutton(lom, text = "E-optimality", variable =
> check3).grid(row = 12, column = 1, sticky = W)*
> * check4butt = Checkbutton(lom, text = "Parameter Co-Variance", variable =
> check4).grid(row = 13, column = 1, sticky = W)*
> * if check1.get() == 1:*
> * if check2.get() == 1:*
> * check3butt.config(state = 'disabled')*
> * check4butt.config(state = 'disabled')*

The problem is you are not thinking about this in an event driven way.
The two if statements are only ever executed once when you create the
GUI, they are never used again.

What you need to do is create an event handler that will check how
many buttons are checked and if it is 2 set the unchecked buttons to
disabled. Then bind that event handler to all four buttons.


-- 
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] printing items form list

2017-03-03 Thread David Rock

> On Mar 3, 2017, at 13:42, dirkjso...@gmail.com  wrote:
> 
> On 03/03/2017 12:19 PM, Alan Gauld via Tutor wrote:
>> 
>> That's one reason why join() is a better solution, it
>> handles all of that for you. It's also faster, although
>> in a small application you'd never notice the difference.
>> 
> The ','.join(suitcase) is obviously best of all, but if one doesn't know that 
> method, the below suggestion can be fixed with:
> 
> suitcase = ['book', 'towel', 'shirt', 'pants']
> 
> for i in suitcase:
>st = st + i + ', '
> 
> print('You have a s% in your luggage.' % st)

There are three issues with that statement.
1. not knowing a method is not an excuse.  It’s worth knowing join because it 
has a lot of flexibility (and it _is_ known because of this discussion)
2. Your code as written doesn’t work because st is not defined before you use it

>>> suitcase = ['book', 'towel', 'shirt', 'pants']
>>> for i in suitcase:
... st = st + i + ', '
...
Traceback (most recent call last):
  File "", line 2, in 
NameError: name 'st' is not defined

3. Your [fixed] code (added st = ‘') and join do NOT do the same thing (note 
the extra comma and space at the end of yours)
  join: You have a book, towel, shirt, pants in your luggage.
  yours: You have a book, towel, shirt, pants,  in your luggage.


String concatenation with a loop is notorious for adding extra stuff at the 
end.  To get it right, you have to take into account what to do at the end of 
the list, which adds code complexity.

—
David Rock
da...@graniteweb.com




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


[Tutor] pdf generation problem

2017-03-03 Thread Jason Snyder
I have the following program where I am trying to generate a pdf:

  1 import matplotlib
  2 matplotlib.use('AGG')
  3 import matplotlib.pyplot as plt
  4 import matplotlib.image as image
  5 import matplotlib.gridspec as gridspec
  6 from matplotlib.backends.backend_pdf import PdfPages
  7 import numpy as np
  8
  9 np.random.seed(0)
 10
 11 x, y = np.random.randn(2, 100)
 12
 13 with PdfPages('wx_plot.pdf') as pdf:
 14   fig, (ax1,ax2) = plt.subplots(nrows=2, figsize=(8,11))
 15   gs = gridspec.GridSpec(2, 1,
 16 height_ratios=[1.5,3]
 17 )
 18   ax1 = plt.subplot(gs[0])
 19   ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
 20   ax1.grid(True)
 21   ax1.axhline(0, color='black', lw=2)
 22
 23   ax2 = plt.subplot(gs[1])
 24   ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
 25   ax2.grid(True)
 26   ax2.axhline(0, color='black', lw=2)
 27   pdf.savefig('fig')
 28 pdf.close()

When I run it I get the following error:

Traceback (most recent call last):
  File "testinger.py", line 13, in 
with PdfPages('wx_plot.pdf') as pdf:
AttributeError: __exit__


What is going on here and how do I resolve this issue?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Radiobuttons (two options out of 4)

2017-03-03 Thread Pooja Bhalode
Hi Alan,

Thank you for letting me know.
I tried putting in the event handlers for the checkbuttons as shown below.


num = 0
def selfcheck(event):
 print "Self Check"
 num = num + 1
 if num == 2:
check1butt.config(state = 'disabled')
check2butt.config(state = 'disabled')
check3butt.config(state = 'disabled')
check4sbutt.config(state = 'disabled')

Label(lom, text = "Choose two options from:").grid(row = 9, column = 1,
sticky = W)
check1butt = Checkbutton(lom, text = "A-optimality", variable = check1)
check1butt.bind("", selfcheck)
check1butt.grid(row = 10, column = 1, sticky = W)
check2butt = Checkbutton(lom, text = "D-optimality", variable = check2)
check2butt.bind("", selfcheck)
check2butt.grid(row = 11, column = 1, sticky = W)

check3butt = Checkbutton(lom, text = "E-optimality", variable = check3)
check3butt.bind("", selfcheck)
check3butt.grid(row = 12, column = 1, sticky = W)

check4butt = Checkbutton(lom, text = "Parameter Co-Variance", variable =
check4)
check4butt.bind("", selfcheck)
check4butt.grid(row = 13, column = 1, sticky = W)
if check1.get() == 1:
if check2.get() == 1:
check3butt.config(state = 'disabled')
check4butt.config(state = 'disabled')

But here, I have the problem where I do not know how to design the function
selfcheck. Here, the function should disable the rest of the checkbuttons
which are not selected after two options are selected by the user. Can you
please let me know how to design the function?
Thank you

Pooja

On Fri, Mar 3, 2017 at 2:42 PM, Alan Gauld via Tutor 
wrote:

> On 03/03/17 16:43, Pooja Bhalode wrote:
>
> > I am trying to create a GUI with four options out of which the user is
> > supposed to select two. But once the user selected two out of those four
> > options, the others need to get greyed out at that instant.
> >
> > I tried the following thing:
> >
> > *Label(lom, text = "Choose two options from:").grid(row = 9, column = 1,
> > sticky = W)*
> > * check1butt = Checkbutton(lom, text = "A-optimality", variable =
> > check1).grid(row = 10, column = 1, sticky = W)*
> > * check2butt = Checkbutton(lom, text = "D-optimality", variable =
> > check2).grid(row = 11, column = 1, sticky = W)*
> > * check3butt = Checkbutton(lom, text = "E-optimality", variable =
> > check3).grid(row = 12, column = 1, sticky = W)*
> > * check4butt = Checkbutton(lom, text = "Parameter Co-Variance", variable
> =
> > check4).grid(row = 13, column = 1, sticky = W)*
> > * if check1.get() == 1:*
> > * if check2.get() == 1:*
> > * check3butt.config(state = 'disabled')*
> > * check4butt.config(state = 'disabled')*
>
> The problem is you are not thinking about this in an event driven way.
> The two if statements are only ever executed once when you create the
> GUI, they are never used again.
>
> What you need to do is create an event handler that will check how
> many buttons are checked and if it is 2 set the unchecked buttons to
> disabled. Then bind that event handler to all four buttons.
>
>
> --
> 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 maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tables in Tkinter

2017-03-03 Thread Pooja Bhalode
Hi Alan,

Can you please guide me to an example related to this problem? I do not
know how to use the scrollable frame, set backgrounds etc.
Sorry, I am new to tables in Tkinter. I could not find any examples as well

Please let me know.
Thank you

Pooja

On Fri, Mar 3, 2017 at 2:35 PM, Alan Gauld via Tutor 
wrote:

> On 03/03/17 16:07, Pooja Bhalode wrote:
>
> > The table that I am trying to get is a table with scrollable rows. I just
> > want to display the data in the table in the Tkinter window. I do not
> wish
> > to make it interactive, since  just want to display the data.
>
> In that case you could just use a scrolled frame (from PMW, which you
> installed as part of the tkintertable install). Simply add labels
> using the grid manager into your frame. Set a different background
> colour for the top row to make them headings and choose appropriate
> borders and styles.
>
> It should be fairly easy to build up a simple display grid that way.
>
> --
> 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 maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Problems with matplotlib

2017-03-03 Thread Jason Snyder
I installed the python module matplotlib on a computer and when I try to
run a program with the commands:

import matplotlib.pyplot as plt I get the following errors:

Traceback (most recent call last):
  File "new.py", line 1, in 
import matplotlib
  File "/usr/lib64/python2.7/site-packages/matplotlib/__init__.py", line
151, in 
from matplotlib.rcsetup import (defaultParams,
  File "/usr/lib64/python2.7/site-packages/matplotlib/rcsetup.py", line 20,
in 
from matplotlib.colors import is_color_like
  File "/usr/lib64/python2.7/site-packages/matplotlib/colors.py", line 54,
in 
import matplotlib.cbook as cbook
  File "/usr/lib64/python2.7/site-packages/matplotlib/cbook.py", line 32,
in 
import new
  File "/home/www/html/auroratest/new.py", line 8, in 
plt.scatter(x,y)
NameError: name 'plt' is not defined

when I try to use something like import matplotlib.image as image I get the
following errors:

Traceback (most recent call last):
  File "new.py", line 1, in 
import matplotlib.image as image
  File "/usr/lib64/python2.7/site-packages/matplotlib/__init__.py", line
151, in 
from matplotlib.rcsetup import (defaultParams,
  File "/usr/lib64/python2.7/site-packages/matplotlib/rcsetup.py", line 20,
in 
from matplotlib.colors import is_color_like
  File "/usr/lib64/python2.7/site-packages/matplotlib/colors.py", line 54,
in 
import matplotlib.cbook as cbook
  File "/usr/lib64/python2.7/site-packages/matplotlib/cbook.py", line 32,
in 
import new
  File "/home/www/html/auroratest/new.py", line 1, in 
import matplotlib.image as image
  File "/usr/lib64/python2.7/site-packages/matplotlib/image.py", line 13,
in 
from matplotlib import rcParams
ImportError: cannot import name rcParams

What is causing these errors and what specific things do I need to do to
resolve this.  I need this explained clearly in a step by step way.

Thanks,

Jason

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


Re: [Tutor] Radiobuttons (two options out of 4)

2017-03-03 Thread Alan Gauld via Tutor
On 03/03/17 20:59, Pooja Bhalode wrote:

> I tried putting in the event handlers for the checkbuttons as shown below.
> 
> num = 0
> def selfcheck(event):
>  print "Self Check"
>  num = num + 1
>  if num == 2:

You need num to be inside the function since it needs
to be reset to zero on every check.

And the increment should only be if the button
is checked. Something like(untested pseudo-code)

def selfcheck(evt):
   num = 0
   for butt in [butt1,butt2,butt3,butt4]:
   if butt.isChecked:
  num += 1

   if num == 2
  for butt in [butt1,butt2,butt3,butt4]:
 if not butt.isChecked:
butt.disable()
   else:   # if a button is unchecked, re-enable all
   for butt in [butt1,butt2,butt3,butt4]:
  butt.enable()

You then need to bind that to the mouse click event
for each button.


-- 
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] pdf generation problem

2017-03-03 Thread Alan Gauld via Tutor
On 04/03/17 00:28, Jason Snyder wrote:
> I have the following program where I am trying to generate a pdf:

>   6 from matplotlib.backends.backend_pdf import PdfPages
>   7 import numpy as np

>  13 with PdfPages('wx_plot.pdf') as pdf:

> When I run it I get the following error:
> 
> Traceback (most recent call last):
>   File "testinger.py", line 13, in 
> with PdfPages('wx_plot.pdf') as pdf:
> AttributeError: __exit__
> 
> What is going on here and how do I resolve this issue?

I don't know, but it's not really a python language problem
more of a matplotlib/SciPy problem so you should probably
try asking first on the SciPy support forum.

We don't mind offering general help on third party
libraries but that looks like a very specific module
issue.

-- 
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] Tables in Tkinter

2017-03-03 Thread Alan Gauld via Tutor
On 03/03/17 21:15, Pooja Bhalode wrote:
> Hi Alan,
> 
> Can you please guide me to an example related to this problem? I do not
> know how to use the scrollable frame, set backgrounds etc.
> Sorry, I am new to tables in Tkinter. I could not find any examples as well

WE are all new to tables in Tkinter because they don;t exist.
You either have to build your own or find a third party one.

Here is a very simple 3 row, 2 column table:

>>> top = tk.Tk()
>>> tab = tk.Frame(top)
>>> tk.Label(tab, text="Left", border=2, relief=tk.SUNKEN,
width=5).grid(column=0,row=0)
>>> tk.Label(tab, text="Right", border=2, relief=tk.SUNKEN,
width=5).grid(column=1,row=0)
>>> tk.Label(tab, text="1L", border=2, relief=tk.SUNKEN,
width=5).grid(column=0,row=1)
>>> tk.Label(tab, text="2L", border=2, relief=tk.SUNKEN,
width=5).grid(column=0,row=2)
>>> tk.Label(tab, text="1R", border=2, relief=tk.SUNKEN,
width=5).grid(column=1,row=1)
>>> tk.Label(tab, text="2R", border=2, relief=tk.SUNKEN,
width=5).grid(column=1,row=2)
>>> tab.pack()
>>> top.mainloop()

I don't have PMW installed but if you substitute

tab = pmw.ScrolledFrame(top)

for the Frame in my example it might just work!

Alternatively there is a ScrolledWindow in Tix,
although I've never used it. (Tix also has a Grid
and ScrolledGrid pair which I've tried to use
but failed to get it to work!)

-- 
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] Problems with matplotlib

2017-03-03 Thread Alan Gauld via Tutor
On 03/03/17 22:59, Jason Snyder wrote:
> I installed the python module matplotlib on a computer and when I try to
> run a program with the commands:
> 
> import matplotlib.pyplot as plt I get the following errors:

It could be an installation issue, but really this list
is for the core language and standard library. matplotlib
is, I think, part of SciPy and you would probably get
better support using the dedicated SciPy forum.

-- 
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] Problems with matplotlib

2017-03-03 Thread Peter Otten
Jason Snyder wrote:

> I installed the python module matplotlib on a computer and when I try to
> run a program with the commands:
> 
> import matplotlib.pyplot as plt I get the following errors:
> 
> Traceback (most recent call last):
>   File "new.py", line 1, in 
> import matplotlib
>   File "/usr/lib64/python2.7/site-packages/matplotlib/__init__.py", line
> 151, in 
> from matplotlib.rcsetup import (defaultParams,
>   File "/usr/lib64/python2.7/site-packages/matplotlib/rcsetup.py", line
>   20,
> in 
> from matplotlib.colors import is_color_like
>   File "/usr/lib64/python2.7/site-packages/matplotlib/colors.py", line 54,
> in 
> import matplotlib.cbook as cbook
>   File "/usr/lib64/python2.7/site-packages/matplotlib/cbook.py", line 32,
> in 
> import new
>   File "/home/www/html/auroratest/new.py", line 8, in 
> plt.scatter(x,y)
> NameError: name 'plt' is not defined
> 
> when I try to use something like import matplotlib.image as image I get
> the following errors:
> 
> Traceback (most recent call last):
>   File "new.py", line 1, in 
> import matplotlib.image as image
>   File "/usr/lib64/python2.7/site-packages/matplotlib/__init__.py", line
> 151, in 
> from matplotlib.rcsetup import (defaultParams,
>   File "/usr/lib64/python2.7/site-packages/matplotlib/rcsetup.py", line
>   20,
> in 
> from matplotlib.colors import is_color_like
>   File "/usr/lib64/python2.7/site-packages/matplotlib/colors.py", line 54,
> in 
> import matplotlib.cbook as cbook
>   File "/usr/lib64/python2.7/site-packages/matplotlib/cbook.py", line 32,
> in 
> import new

This looks like a name clash. There is a module called "new" in Python's 
standard library, and matplotlib is trying to install that. Instead your own

>   File "/home/www/html/auroratest/new.py", line 1, in 

is found. Once you rename your new.py to something else (and remove the 
corresponding new.pyc) things should start to work again.

> import matplotlib.image as image
>   File "/usr/lib64/python2.7/site-packages/matplotlib/image.py", line 13,
> in 
> from matplotlib import rcParams
> ImportError: cannot import name rcParams
> 
> What is causing these errors and what specific things do I need to do to
> resolve this.  I need this explained clearly in a step by step way.
> 
> Thanks,
> 
> Jason
> 


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


Re: [Tutor] pdf generation problem

2017-03-03 Thread Peter Otten
Jason Snyder wrote:

> I have the following program where I am trying to generate a pdf:
> 
>   1 import matplotlib
>   2 matplotlib.use('AGG')
>   3 import matplotlib.pyplot as plt
>   4 import matplotlib.image as image
>   5 import matplotlib.gridspec as gridspec
>   6 from matplotlib.backends.backend_pdf import PdfPages
>   7 import numpy as np
>   8
>   9 np.random.seed(0)
>  10
>  11 x, y = np.random.randn(2, 100)
>  12
>  13 with PdfPages('wx_plot.pdf') as pdf:
>  14   fig, (ax1,ax2) = plt.subplots(nrows=2, figsize=(8,11))
>  15   gs = gridspec.GridSpec(2, 1,
>  16 height_ratios=[1.5,3]
>  17 )
>  18   ax1 = plt.subplot(gs[0])
>  19   ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
>  20   ax1.grid(True)
>  21   ax1.axhline(0, color='black', lw=2)
>  22
>  23   ax2 = plt.subplot(gs[1])
>  24   ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
>  25   ax2.grid(True)
>  26   ax2.axhline(0, color='black', lw=2)
>  27   pdf.savefig('fig')
>  28 pdf.close()
> 
> When I run it I get the following error:
> 
> Traceback (most recent call last):
>   File "testinger.py", line 13, in 
> with PdfPages('wx_plot.pdf') as pdf:
> AttributeError: __exit__
> 
> 
> What is going on here and how do I resolve this issue?

You have an old version of matplotlib where the PdfPages class does not yet 
implement the context manager protocol. You can 

(1) upgrade the library. In that case line 28 is redundant; just do

with PdfPages(...) as pdf:
   # do stuff

(2) continue to use the version you have and close explicitly:

pdf = PdfPages(...)
# do stuff
pdf.close()


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