[Tutor] no longer need this tutor

2014-11-26 Thread moemedi baboile
 I want thank you guys for helping me out with python programming.I achieved 
the best out of this and now am on the next stage of programming, I now don't 
need this tutor any more...thank you once again. ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] bubble sort function

2014-11-26 Thread Sunil Tech
Hi Danny,

Curious to the use the need of using while True in the given example of
ask_for_a_digit().


On Mon, Nov 17, 2014 at 9:57 AM, Danny Yoo  wrote:

> > def ask_for_a_digit():
> > while True:
> > digit = raw_input("Give me a digit between 0 and 9.")
> > if digit not in "0123456789":
> > print "You didn't give me a digit.  Try again."
> > else:
> > return int(digit)
>
>
> Ooops.  I made a mistake.  ask_for_a_digit() is not technically quite
> right, because I forgot that when we're doing the expression:
>
> digit not in "0123456789"
>
> that this is technically checking that the left side isn't a substring
> of the right side.  That's not what I wanted: I intended to check for
> element inclusion instead.  So there are certain inputs where the
> buggy ask_for_a_digit() won't return an integer with a single digit.
>
> Here's one possible correction:
>
> ###
> def ask_for_a_digit():
> while True:
> digit = raw_input("Give me a digit between 0 and 9.")
> if len(digit) != 1 or digit not in "0123456789":
> print "You didn't give me a digit.  Try again."
> else:
> return int(digit)
> ###
>
>
> My apologies for not catching the bug sooner.
> ___
> 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] no longer need this tutor

2014-11-26 Thread Sunil Tech
Hi,

If you don't need.
You can anytime simply go to the link which is mentioned (as a footer in
the email) and unsubscribe.
rather posting this message to the tutor.

On Wed, Nov 26, 2014 at 2:59 PM, moemedi baboile <
moemedibabo...@yahoo.com.dmarc.invalid> wrote:

> I want thank you guys for helping me out with python programming.I
> achieved the best out of this and now am on the next stage of programming,
> I now don't need this tutor any more...thank you once again.
>
> ___
> 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] bubble sort function

2014-11-26 Thread Alan Gauld

On 26/11/14 09:57, Sunil Tech wrote:

Hi Danny,

Curious to the use the need of using while True in the given example of
ask_for_a_digit().


On Mon, Nov 17, 2014 at 9:57 AM, Danny Yoo mailto:d...@hashcollision.org>> wrote:

> def ask_for_a_digit():
> while True:
> digit = raw_input("Give me a digit between 0 and 9.")
> if digit not in "0123456789":
> print "You didn't give me a digit.  Try again."
> else:
> return int(digit)


The while loop makes it keep on asking until a valid input is
received. Without the while loop it would only ask once and
either return None or a digit.

HTH
--
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] no longer need this tutor

2014-11-26 Thread Giles Coochey

On 26/11/2014 09:59, Sunil Tech wrote:

Hi,

If you don't need.
You can anytime simply go to the link which is mentioned (as a footer 
in the email) and unsubscribe.

rather posting this message to the tutor.


I think he was just politely saying goodbye

--
Regards,

Giles Coochey, CCNP, CCNA, CCNAS
NetSecSpec Ltd
+44 (0) 8444 780677
+44 (0) 7584 634135
http://www.coochey.net
http://www.netsecspec.co.uk
gi...@coochey.net



smime.p7s
Description: S/MIME Cryptographic Signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] bubble sort function

2014-11-26 Thread Sunil Tech
Thank you Alan. But a question here, how would it understand that the given
input is valid?



The while loop makes it keep on asking until a valid input is
received. Without the while loop it would only ask once and
either return None or a digit.



On Wed, Nov 26, 2014 at 3:46 PM, Alan Gauld 
wrote:

> On 26/11/14 09:57, Sunil Tech wrote:
>
>> Hi Danny,
>>
>> Curious to the use the need of using while True in the given example of
>> ask_for_a_digit().
>>
>>
>> On Mon, Nov 17, 2014 at 9:57 AM, Danny Yoo > > wrote:
>>
>> > def ask_for_a_digit():
>> > while True:
>> > digit = raw_input("Give me a digit between 0 and 9.")
>> > if digit not in "0123456789":
>> > print "You didn't give me a digit.  Try again."
>> > else:
>> > return int(digit)
>>
>
> The while loop makes it keep on asking until a valid input is
> received. Without the while loop it would only ask once and
> either return None or a digit.
>
> HTH
> --
> 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] bubble sort function

2014-11-26 Thread Dave Angel
Please don't top-post.  Put your response under the quote you're 
responding to.  And trim the parts that are no longer relevant.  I've 
rearranged this message to try to pretend that you did that.


> On Wed, Nov 26, 2014 at 3:46 PM, Alan Gauld 
> wrote:
>
>> On 26/11/14 09:57, Sunil Tech wrote:
>>
>>> Hi Danny,
>>>
>>> Curious to the use the need of using while True in the given example of
>>> ask_for_a_digit().
>>>
>>>
>>> On Mon, Nov 17, 2014 at 9:57 AM, Danny Yoo >> > wrote:
>>>
>>>  > def ask_for_a_digit():
>>>  > while True:
>>>  > digit = raw_input("Give me a digit between 0 and 9.")
>>>  > if digit not in "0123456789":
>>>  > print "You didn't give me a digit.  Try again."
>>>  > else:
>>>  > return int(digit)
>>>
>>
>> The while loop makes it keep on asking until a valid input is
>> received. Without the while loop it would only ask once and
>> either return None or a digit.
>>


On 11/26/2014 06:16 AM, Sunil Tech wrote:

Thank you Alan. But a question here, how would it understand that the given
input is valid?



Inside the while loop there is a else clause containing a return 
statement.  That's how the code escapes the while loop:  whenever the 
user enters something deemed correct.


More traditionally, a break will exit a loop.  Or the while can contain 
a more complex condition.  Example of that, untested:


def ask_for_a_digit()
digit = "xxx"
while len(digit) != 1   or  digit not in "0123456789":
digit = raw_input("Give me a digit between 0 and 9.")

Unfortunately, this form doesn't include the "chiding" of the user. 
That's more painful, but it can be done.


def ask_for_a_digit()
digit = ()
while len(digit) != 1   or  digit not in "0123456789":
if digit = (): print "You didn't give me a digit.  Try again"
digit = raw_input("Give me a digit between 0 and 9.")




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


Re: [Tutor] bubble sort function

2014-11-26 Thread Sunil Tech
​Thank you Dave​

On Wed, Nov 26, 2014 at 5:23 PM, Dave Angel  wrote:

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


[Tutor] Memory management in Python

2014-11-26 Thread Mohamed Ben Mosbah
Hi I'm new to Python and I would like to know how he deals with memory
space.
I thought I had understood but I made a test and the results were
uncoherenent with my understanding, here is the thing:

>>> a=[1,2]
>>> l=[a,a]
>>> id(a); id(l[0]); id(l[1]);
61659528
61659528
61659528
>>> #All Have the same ID
>>> l[0]=[0,0]
>>> l
[[0, 0], [1, 2]]
>>> #Why didn't l[1] change as well?
>>> id(a); id(l[0]); id(l[1]);
61659528
61390280
61659528
>>> #How come id(l[0]) changed?
>>> a = [4,4]
>>> l
[[0, 0], [1, 2]]
>>> #Why didn't l[1] change? l[1] and a were occupying the same memory
adress!


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


Re: [Tutor] bubble sort function

2014-11-26 Thread Sunil Tech
Thank you Alan for explanation

That's what the bit inside the loop does.
> It checks whether the input string is a digit (specifically a decimal
> digit).
> If it is a digit it returns the result as an integer
> otherwise it spits out an error and goes round the loop again.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] bubble sort function

2014-11-26 Thread Alan Gauld


On 26/11/14 11:16, Sunil Tech wrote:

Thank you Alan. But a question here, how would it understand that the 
given input is valid?


That's what the bit inside the loop does.
It checks whether the input string is a digit (specifically a decimal 
digit).

If it is a digit it returns the result as an integer
otherwise it spits out an error and goes round the loop again.

PS Please don't top post. This thread is already getting hard to follow 
after

only 2 exchanges!

On Mon, Nov 17, 2014 at 9:57 AM, Danny Yoo 


>> wrote:

> def ask_for_a_digit():
> while True:
> digit = raw_input("Give me a digit between 0 and
9.")
> if digit not in "0123456789":
> print "You didn't give me a digit. Try again."
> else:
> return int(digit)


The while loop makes it keep on asking until a valid input is
received. Without the while loop it would only ask once and
either return None or a digit.

HTH


--
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] Memory management in Python

2014-11-26 Thread Raúl Cumplido
Hi,

This web is quite useful to visualize what is happening:
http://www.pythontutor.com/visualize.html#mode=edit

Step by Step:
>>> a=[1,2]
You create a list a which contains two objects, in this case two integers
(1, 2)
>>> l=[a,a]
You create a list which contains two objects, which happen to be the list
above created. This is just a reference to the object (1,2) same as list a
is referring to.
>>> l[0]=[0,0]
You modify the first element of the list to another list, now the reference
has been modified and it points to the new list [0, 0]
This is why the id of l[0] changes because you are referencing to another
object which has another id.
l[1] is still referencing to the list [1,2] same as a this is why the id
for a and l[1] doesn't change.

Take a look on the memory visualize tool which I think is helpful to
understand what is going on in this cases.

Kind Regards,
Raul

On Wed, Nov 26, 2014 at 12:57 PM, Mohamed Ben Mosbah <
benmosbahmoha...@gmail.com> wrote:

> Hi I'm new to Python and I would like to know how he deals with memory
> space.
> I thought I had understood but I made a test and the results were
> uncoherenent with my understanding, here is the thing:
>
> >>> a=[1,2]
> >>> l=[a,a]
> >>> id(a); id(l[0]); id(l[1]);
> 61659528
> 61659528
> 61659528
> >>> #All Have the same ID
> >>> l[0]=[0,0]
> >>> l
> [[0, 0], [1, 2]]
> >>> #Why didn't l[1] change as well?
> >>> id(a); id(l[0]); id(l[1]);
> 61659528
> 61390280
> 61659528
> >>> #How come id(l[0]) changed?
> >>> a = [4,4]
> >>> l
> [[0, 0], [1, 2]]
> >>> #Why didn't l[1] change? l[1] and a were occupying the same memory
> adress!
>
>
> Thank you for answering :)
>
> ___
> 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] Is there an easy way to center the root window (Tkinter) within the display?

2014-11-26 Thread boB Stepp
Python 2.4.4
Solaris 10

I can accomplish this by getting the screen height and width and
calculating pixel coordinates. But so far I have not found something
equivalent to anchor = 'CENTER' that can be applied to the root
window. Does such an easy attribute, method, or whatever exist in
Tkinter?

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


[Tutor] How to change the color of the title bar of the root window in Tkinter?

2014-11-26 Thread boB Stepp
Python 2.4.4
Solaris 10

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


Re: [Tutor] Memory management in Python

2014-11-26 Thread Alan Gauld

On 26/11/14 12:57, Mohamed Ben Mosbah wrote:

Hi I'm new to Python and I would like to know how he deals with memory
space.


Don't even think about it, you will only mislead yourself.
Seriously you shouldn't try to link Python objects to physical
memory locations. And you should certainly never build any
dependencies on locations into your code.

You are operating in a kind of virtual machine with its own ideas of 
where things are located and any relation to physical memory is purely 
coincidental.


Just think about objects and names.
Names refer to objects.
Some objects can be changed (mutable) and others can't (immutable).
Objects have an ID; which may or may not be related to their memory 
location.



I thought I had understood but I made a test and the results were
uncoherent with my understanding, here is the thing:

 >>> a=[1,2]
 >>> l=[a,a]
 >>> id(a); id(l[0]); id(l[1]);
61659528
61659528
61659528


So those references are all to the same object which is a list and
is therefore mutable. l refers to a different list which is also mutable.


 >>> #All Have the same ID
 >>> l[0]=[0,0]


You have now changed the first element of l so it no longer
refers to the same object as a but to a new list [0,0]


 >>> l
[[0, 0], [1, 2]]
 >>> #Why didn't l[1] change as well?


Because you didn't change what l[1] referred to, you only
changed l[0].


 >>> id(a); id(l[0]); id(l[1]);
61659528
61390280
61659528
 >>> #How come id(l[0]) changed?


Because you assigned it to the new list object.


 >>> a = [4,4]


and now you have created yet another list object and
referenced it from 'a'


 >>> l
[[0, 0], [1, 2]]
 >>> #Why didn't l[1] change? l[1] and a were occupying the same memory
adress!


No they weren't, the names 'a' and l[1] were both referring to the
same object but you changed 'a' to refer to a different object.
So they are now different. Python names have nothing to do with
memory locations, they are just references to 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


Re: [Tutor] Is there an easy way to center the root window (Tkinter) within the display?

2014-11-26 Thread Alan Gauld

On 26/11/14 16:46, boB Stepp wrote:


I can accomplish this by getting the screen height and width and
calculating pixel coordinates. But so far I have not found something
equivalent to anchor = 'CENTER' that can be applied to the root
window. Does such an easy attribute, method, or whatever exist in
Tkinter?


I'm not aware of one.
But forcing a window to be centre of the display is usually
a bad idea - and very annoyying to the user, especially if they have 
explicitly set their preferences for where new windows should appear.


More useful is to put it centre of the applications top level window
since thats where the users attention should be fixed! Most important of 
all is to ensure it goes on top (assuming its something important that 
you are splatting in front of them and not just some dull

report message like "File saved...").

But generally I leave such matters to the users preferences and
the OS. They know much more than I do about how the user wants
to work and what else is going on with the machine at the time.

--
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] How to change the color of the title bar of the root window in Tkinter?

2014-11-26 Thread Alan Gauld

On 26/11/14 16:48, boB Stepp wrote:

Python 2.4.4
Solaris 10


I can't find anything on this and I suspect that's because
title bar colour is generally part of the user's preferred
colour scheme. Even in Windoze the title bar colour is part
of the users preferences. Colour-blind users don't like
apps that mess with what they can read.

--
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] How to change the color of the title bar of the root window in Tkinter?

2014-11-26 Thread boB Stepp
On Wed, Nov 26, 2014 at 11:25 AM, Alan Gauld  wrote:
> On 26/11/14 16:48, boB Stepp wrote:
>>
>> Python 2.4.4
>> Solaris 10
>
>
> I can't find anything on this and I suspect that's because
> title bar colour is generally part of the user's preferred
> colour scheme. Even in Windoze the title bar colour is part
> of the users preferences. Colour-blind users don't like
> apps that mess with what they can read.

The application I am attempting to write will show up in the
foreground of our planning software. This planning software has its
own color scheme, which all of us are quite used to. As you might
guess, the Tkinter-produced windows do not match this scheme, not
anything close, and I am trying to discover ways to tweak my windows
to agree better with the planning software's display aesthetics.


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


Re: [Tutor] Is there an easy way to center the root window (Tkinter) within the display?

2014-11-26 Thread boB Stepp
On Wed, Nov 26, 2014 at 11:23 AM, Alan Gauld  wrote:
> On 26/11/14 16:46, boB Stepp wrote:
>
>> I can accomplish this by getting the screen height and width and
>> calculating pixel coordinates. But so far I have not found something
>> equivalent to anchor = 'CENTER' that can be applied to the root
>> window. Does such an easy attribute, method, or whatever exist in
>> Tkinter?
>
>
> I'm not aware of one.
> But forcing a window to be centre of the display is usually
> a bad idea - and very annoyying to the user, especially if they have
> explicitly set their preferences for where new windows should appear.

Thanks for bringing this to my attention. I do not believe it applies
to my current situation, but I could see that I need to keep it in
mind for most other things I might do.

In the current scenario, users of our planning system will initiate a
planning system script (proprietary language) that will call my python
program. The user cannot proceed further until my program completes,
which requires user interaction. So I do want it to be front and
center.

I will just have to do this the hard way then, which actually isn't
too hard ~(:>))


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


Re: [Tutor] Is there an easy way to center the root window (Tkinter) within the display?

2014-11-26 Thread Alan Gauld

On 26/11/14 17:44, boB Stepp wrote:


But forcing a window to be centre of the display is usually
a bad idea - and very annoyying to the user, especially if they have



In the current scenario, users of our planning system will initiate a
planning system script (proprietary language) that will call my python
program. The user cannot proceed further until my program completes,


So they can't read email, write reports, browse web sites?
And what if the OS or sysadmin is also trying to catch their eye - maybe 
because the server is going down and they have 30 secs to save their work?


Being a 'good guy' in a multi tasking/multi user world is tough :-)

--
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] How to change the color of the title bar of the root window in Tkinter?

2014-11-26 Thread Alan Gauld

On 26/11/14 17:39, boB Stepp wrote:


of the users preferences. Colour-blind users don't like
apps that mess with what they can read.


The application I am attempting to write will show up in the
foreground of our planning software. This planning software has its
own color scheme, which all of us are quite used to.


Seriously? It colours its own title bars? That's really poor.
Unless you test all employees for colour blindness first and
don't employ those blind to your colour scheme?
And that's probably illegal now in most western countries!

There are a lot of Windows apps that do arbitrary stuff like that
but if you are on Solaris I'd expect most apps to be controlled
by resources that the user can override if need be, Hard coded
colour schemes are just evil for no good reason.


guess, the Tkinter-produced windows do not match this scheme, not
anything close, and I am trying to discover ways to tweak my windows
to agree better with the planning software's display aesthetics.


The core window backgrounds etc can be coloured easily enough.
Its the stuff controlled by the Window Manager that's tougher.

What do you do for window managers that don't have a title bar
for example? (There are several...)

There's a good reason Tkinter doesn't make this easy
 - its to save you from yourself. :-)

However, if you want to know how to force it I suspect there will
be a way somehow, but you'll be more likely get the answer on the
Tkinter mailing list rather than here. Or maybe even by going
to the Tcl/Tk forums?

hth
--
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] Is there an easy way to center the root window (Tkinter) within the display?

2014-11-26 Thread boB Stepp
On Wed, Nov 26, 2014 at 11:50 AM, Alan Gauld  wrote:
> On 26/11/14 17:44, boB Stepp wrote:
>
[...]
> So they can't read email, write reports, browse web sites?
> And what if the OS or sysadmin is also trying to catch their eye - maybe
> because the server is going down and they have 30 secs to save their work?

Actually, they cannot do any of these things except save their work!
There is no sysadmin. Our IS department is totally Windows focused and
does not know how to help us with Solaris 10-based stuff. If we have
problems we either figure it out ourselves or call the owners of the
planning software for remote help. As I am the only person in our
group with any programming knowledge (weak though it is), this means I
usually wind up trying to solve issues as they arise. These client
machines are dedicated to a single purpose: radiation therapy
treatment planning. They either cannot or should not be doing anything
else

> Being a 'good guy' in a multi tasking/multi user world is tough :-)

If a user initiates one of my programs/scripts then the user is
focused on that task to exclusion of anything else, since that
comprises the next step in his planning process workflow.

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


Re: [Tutor] How to change the color of the title bar of the root window in Tkinter?

2014-11-26 Thread boB Stepp
On Wed, Nov 26, 2014 at 11:58 AM, Alan Gauld  wrote:
> On 26/11/14 17:39, boB Stepp wrote:
>
[...]
>> The application I am attempting to write will show up in the
>> foreground of our planning software. This planning software has its
>> own color scheme, which all of us are quite used to.
>
>
> Seriously? It colours its own title bars? That's really poor.
> Unless you test all employees for colour blindness first and
> don't employ those blind to your colour scheme?
> And that's probably illegal now in most western countries!

Color-blind users would not be able to be hired to do this work.
Having normal color vision is a job requirement. Of course, the title
bar colors are truly immaterial, but the colors of the isodose lines
that tell the user what dose different areas of the treatment area are
getting are critical. Contoured structures, both targets of the
radiation and organs that must be spared are all color coded. However,
my lack of skill and ignorance (as usual) is the problem...

Thankfully, Alan, you got me to thinking. And exploring. On our
systems it is difficult to know what is coming from the OS,
Solaris-10, and what is coming from the planning software. I had never
used Solaris prior to getting my current position and the last time I
had dabbled in Unix there were no windows-based interfaces, at least
not in the academic environment I was in then.

So I went into the common desktop environment without the planning
system running and verified that the planning system is in fact using
that color scheme for its windows. Which got me to wondering why the
trivial test window I created was not matching. It turns out that the
window was not getting focus unless the mouse was over the test
window, which resulted in in being totally gray except for the radio
button selected. My bad!

I have been playing with Tkinter on a Windows PC and then copying the
code over to the nearby Solaris box to see how it looks. I did not
have any need (yet) to actually click on anything, I was just looking
for the overall appearance of the window and its subelements.

But as usual you were very helpful and got my thinking (such as it is)
going in the proper direction!

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


Re: [Tutor] Is there an easy way to center the root window (Tkinter) within the display?

2014-11-26 Thread Alan Gauld

On 26/11/14 18:25, boB Stepp wrote:


So they can't read email, write reports, browse web sites?


Actually, they cannot do any of these things except save their work!


In that case you get away with it.
I'm still not sure messing with "user preferences" is a good thing
but you can at least be reasonably confident on the outcome.


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] Question about why a list variable is apparently global.

2014-11-26 Thread boB Stepp
Python 2.4.4
Solaris 10

#!/usr/bin/env python

from Tkinter import *

def printLabel():
print "Button number ", var.get(), " was pressed."
print "You selected this option:", l[var.get() - 1][0]

root = Tk()
root.title("ROI List Creator")
root.geometry(newGeometry='225x230+900+300')
root.tk_setPalette(background='gray')

buttonNumber = []
l = [("Brain_Partial", 1), ("Brain_Whole", 2),
("Head & Neck", 3), ("Chest", 4), ("Breast_Whole", 5),
("Breast_Partial", 6), ("Abdomen", 7), ("Pelvis", 8),
("Prostate", 9)]
var = IntVar()
for text, value in l:
buttonNumber.append(Radiobutton(root, text = text, value = value,
command=printLabel, variable = var).pack(anchor=W))
var.set(5)
print "The button's value is: ", var.get()
root.update()
print "The geometry info is: ", root.winfo_geometry()
print "The screen width is: ", root.winfo_screenwidth()
print "The screen height is: ", root.winfo_screenheight()
root.mainloop()

First, I continue to "Easter Egg Hunt" in the sweet land of Python,
and now Tkinter. So what I actually know is quite a hodgepodge at this
time.

The function above, printLabel(), will eventually read a file of names
anatomical structures based upon the user's radiobutton selection and
populate those names into a ROI List in our planning software. But for
now I am mostly focused on designing the small radiobutton window and
getting it to do what I expect. I am totally new to Tkinter, but it
seems much more manageable than what our planning software provides
for scripting GUIs.

First question: How can the printLabel() function see the list
variable, l, defined outside of this function? I thought that
functions only had access to variables local to the function and
whatever else is passed to it during the function call.

Second: Will the statements near the end that return the display
screen's width and height be a reliable way of determining the user's
actual monitor settings? My intent is to use this information to
appropriately scale and position windows; not only in this particular
simple window, but in others to come which will potentially be large
and complex. I have tested this on two different sized monitors where
I work and so far it has given the correct results.

Third: I am always open to stylistic comments and how to be more pythonic!

Fourth: And perhaps this should go into a new thread, I am not sure I
understand the full intent and use of Tkinter's Variable class. Any
clarification on this would be welcome as well.

Thanks in advance!

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


Re: [Tutor] Question about why a list variable is apparently global.

2014-11-26 Thread Alan Gauld

On 26/11/14 23:23, boB Stepp wrote:


def printLabel():
 print "Button number ", var.get(), " was pressed."
 print "You selected this option:", l[var.get() - 1][0]


...

buttonNumber = []
l = [("Brain_Partial", 1), ("Brain_Whole", 2),
 ("Head & Neck", 3), ("Chest", 4), ("Breast_Whole", 5),
 ("Breast_Partial", 6), ("Abdomen", 7), ("Pelvis", 8),
 ("Prostate", 9)]
var = IntVar()
for text, value in l:
 buttonNumber.append(Radiobutton(root, text = text, value = value,
 command=printLabel, variable = var).pack(anchor=W))



First question: How can the printLabel() function see the list
variable, l, defined outside of this function? I thought that
functions only had access to variables local to the function and
whatever else is passed to it during the function call.


...and read access to global variables; of which l is one.
You can also get write access by declaring the variable as global inside 
the function. That will work here because you made l global.


Better is to use a parameter of printLabel() and then pass 'l'
in when you call it when the button is pressed. That way the data can be 
anywhere or you can even use more than one data source for the same 
function. How do you do that? Declare another function:


def printLabel(data):
# use data here

def callPrintLabel():
return printLabel(l)

Then pass the new function name into your command.

buttonNumber.append(Radiobutton(root, text = text,
value = value, command=callPrintLabel,
variable = var).pack(anchor=W))


But since callPrintLabel()'s a one liner we can bypass the
definition and use a lambda with a default parameter instead:

buttonNumber.append(Radiobutton(root, text = text,
value = value, command=lambda d=l: printLabel(d),
variable = var).pack(anchor=W))

Now when the button is clicked it will call the lambda which uses
l as the default value for its parameter d. And it then calls
printLabel(d).


Second: Will the statements near the end that return the display
screen's width and height be a reliable way of determining the user's
actual monitor settings? My intent is to use this information to
appropriately scale and position windows; not only in this particular
simple window, but in others to come which will potentially be large
and complex. I have tested this on two different sized monitors where
I work and so far it has given the correct results.


It should do.


Third: I am always open to stylistic comments and how to be more pythonic!


Any sizeable GUI tends to be easier using OOP techniques. Most Tkinter 
GUI tutorials show how to write OOP based Tkinter code. Otherwise you 
wind up with an awful lot of global variables to remember and control.



Fourth: And perhaps this should go into a new thread, I am not sure I
understand the full intent and use of Tkinter's Variable class. Any
clarification on this would be welcome as well.


It's just a convenience feature provided by Tk and carried through to 
Tkinter. I rarely use it myself, finding it nearly as easy to do the 
management myself. But it does save a few lines...


--
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] Question about why a list variable is apparently global.

2014-11-26 Thread Steven D'Aprano
On Wed, Nov 26, 2014 at 05:23:40PM -0600, boB Stepp wrote:
> Python 2.4.4
> Solaris 10
> 
> #!/usr/bin/env python
> 
> from Tkinter import *
> 
> def printLabel():
> print "Button number ", var.get(), " was pressed."
> print "You selected this option:", l[var.get() - 1][0]
> 
> root = Tk()
> root.title("ROI List Creator")
> root.geometry(newGeometry='225x230+900+300')
> root.tk_setPalette(background='gray')
> 
> buttonNumber = []
> l = [("Brain_Partial", 1), ("Brain_Whole", 2),
> ("Head & Neck", 3), ("Chest", 4), ("Breast_Whole", 5),
> ("Breast_Partial", 6), ("Abdomen", 7), ("Pelvis", 8),
> ("Prostate", 9)]
> var = IntVar()
> for text, value in l:
> buttonNumber.append(Radiobutton(root, text = text, value = value,
> command=printLabel, variable = var).pack(anchor=W))
> var.set(5)
> print "The button's value is: ", var.get()
> root.update()
> print "The geometry info is: ", root.winfo_geometry()
> print "The screen width is: ", root.winfo_screenwidth()
> print "The screen height is: ", root.winfo_screenheight()
> root.mainloop()
> 
> First, I continue to "Easter Egg Hunt" in the sweet land of Python,
> and now Tkinter. So what I actually know is quite a hodgepodge at this
> time.
> 
> The function above, printLabel(), will eventually read a file of names
> anatomical structures based upon the user's radiobutton selection and
> populate those names into a ROI List in our planning software. But for
> now I am mostly focused on designing the small radiobutton window and
> getting it to do what I expect. I am totally new to Tkinter, but it
> seems much more manageable than what our planning software provides
> for scripting GUIs.
> 
> First question: How can the printLabel() function see the list
> variable, l, defined outside of this function? I thought that
> functions only had access to variables local to the function and
> whatever else is passed to it during the function call.

No, they also have access to globals and built-ins. You define the list 
l at the top level of your module. That makes it a global, so the 
printLavel() function can see it.

Note that this principle is critical to Python, otherwise functions 
couldn't call each other, or even built-ins! If you have two functions:

def f(): return g()

def g(): return "Hello!"

"g" is a global "variable" and f() can see it, otherwise it couldn't 
call it. 

I put variable in scare-quotes because it's actually more of a 
pseudo-constant, a constant by convention, since it is very unusual to 
change things you define as a function. To be more precise, the *name* 
"g" which refers to the function exists in the module's global scope. As 
a short-cut, we call such names "global variables", even if they never 
vary.

You only need to declare a global variable inside a function if you are 
re-assigning a value to it. Hence:

a = 1
b = 2
def test():
global b
b = b + a

Since you are only fetching the value of global name "a", not assigning 
to it, you don't need to declare it as global.


> Second: Will the statements near the end that return the display
> screen's width and height be a reliable way of determining the user's
> actual monitor settings? 

That's really an issue for tk/tcl, not Python. I would expect they are 
reliable, but tk/tcl have been around for a very, very long time so it 
would be surprising if there were bugs in something as common as getting 
the screen dimensions.



[...]
> Third: I am always open to stylistic comments and how to be more pythonic!

Fix your variable names!

You have a variable called "buttonNumber" which holds a LIST, not a 
number. Confusing!

You have another variable called "1", or is that "I", no sorry it's "l". 
Notice that depending on the font you use, 1 I and l can look almost 
exactly the same. That's a bad thing. Also, the name "l" doesn't mean 
anything, it doesn't tell you the purpose of the variable.

Then there is another variable called "var". That's nice, we already 
know it's a variable, but what role does it play in your program? Try to 
find a more descriptive name. 

> Fourth: And perhaps this should go into a new thread, I am not sure I
> understand the full intent and use of Tkinter's Variable class. Any
> clarification on this would be welcome as well.

Sorry, no clue.


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


Re: [Tutor] Memory management in Python

2014-11-26 Thread Steven D'Aprano

On Wed, Nov 26, 2014 at 01:57:52PM +0100, Mohamed Ben Mosbah wrote:
> Hi I'm new to Python and I would like to know how he deals with memory
> space.

That will depend on *which* Python you are using.

Jython uses the Java Virtual Machine, including the Java garbage 
collector. IronPython uses .Net. The "standard" Python, CPython is 
written in C and mostly uses the C malloc to manage memory.

But NONE of these things matter when you are writing pure Python code. 
Your Python code will behave mostly the same regardless of whether you 
use CPython, Jython or IronPython.


> I thought I had understood but I made a test and the results were
> uncoherenent with my understanding, here is the thing:
> 
> >>> a=[1,2]
> >>> l=[a,a]
> >>> id(a); id(l[0]); id(l[1]);
> 61659528
> 61659528
> 61659528
> >>> #All Have the same ID

Correct. You have two lists. The first list is [1, 2], and that object 
is bound to the name "a", also bound to item 0 of list "l", and bound to 
item 1 of list "l". 

Since a, l[0] and l[1] are three references to the same object, not 
three different objects, id() returns the same value each time.

Forget any idea you have that id() tells you where objects are in 
memory. The Java and .Net memory managers can move objects around in 
memory, so the IDs used there are simple counters:

steve@orac:~$ jython
Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19)
[OpenJDK Server VM (Sun Microsystems Inc.)] on java1.6.0_27
Type "help", "copyright", "credits" or "license" for more information.
>>> mylist = []
>>> id(mylist)
1



> >>> l[0]=[0,0]
> >>> l
> [[0, 0], [1, 2]]
> >>> #Why didn't l[1] change as well?

Here you create a new object, the list [0, 0], and bind it to the 
reference l[0]. You are not *modifying* the original list "a", but 
*replacing* it.

Think of references like names or job positions. A single 
person can have many different names:

John, father, son, husband, brother, boss, captain

can all refer to the same person.

Assignment in Python just changes the name:

boss = Fred

now means that John is no longer the boss, but he is still father, son,
husband, brother, captain.

So you start with a name for an object:

a = [1, 2]

Now you give it two more names:

l = [a, a]  # three names: a, l[0], l[1]

Then you re-assign or re-bind one of those names to a different object:

l[0] = [0, 0]


But you haven't mutated the object, you have only reassigned the name.

Instead, if you do this:

l[1][1] = 999
print(a)

that takes the list called "l[1]" and binds 999 to the first item. Since 
that list is also called "a", then it doesn't matter whether you print a 
or l[1], you will see the same object:

[1, 999]


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


[Tutor] Installing twisted

2014-11-26 Thread Gary
Hi all,
I have been trying to install the zope interface as part of the twisted 
installation with no luck.

Any suggestions ?


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


Re: [Tutor] Installing twisted

2014-11-26 Thread Alan Gauld

On 27/11/14 00:45, Gary wrote:

Hi all,
I have been trying to install the zope interface as part of the twisted 
installation with no luck.

Any suggestions ?


Nope. Sorry.

But since this list is aimed at the core language and standard
library, and neither Zope nor Twisted are part of that, you might
get more response on either a Zope or Twisted forum or failing
that on the main Python mailing list/newsgroup.

--
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] Installing twisted

2014-11-26 Thread bruce
Hey...

When you get this resolved.. if you don't mind.. post the soln back here!!

thanks

ps. I know, not strictly a py language issue.. but might really help
someone struggling to solve the same issue!



On Wed, Nov 26, 2014 at 7:45 PM, Gary
 wrote:
> Hi all,
> I have been trying to install the zope interface as part of the twisted 
> installation with no luck.
>
> Any suggestions ?
>
>
> Sent from my iPad
> ___
> 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] Question about why a list variable is apparently global.

2014-11-26 Thread boB Stepp
On Wed, Nov 26, 2014 at 6:20 PM, Steven D'Aprano  wrote:
> On Wed, Nov 26, 2014 at 05:23:40PM -0600, boB Stepp wrote:
[...]
>> First question: How can the printLabel() function see the list
>> variable, l, defined outside of this function? I thought that
>> functions only had access to variables local to the function and
>> whatever else is passed to it during the function call.
>
> No, they also have access to globals and built-ins. You define the list
> l at the top level of your module. That makes it a global, so the
> printLavel() function can see it.
>
> Note that this principle is critical to Python, otherwise functions
> couldn't call each other, or even built-ins! If you have two functions:
>
> def f(): return g()
>
> def g(): return "Hello!"
>
> "g" is a global "variable" and f() can see it, otherwise it couldn't
> call it.

So any variables lower in the program are accessible to those above it?

> I put variable in scare-quotes because it's actually more of a
> pseudo-constant, a constant by convention, since it is very unusual to
> change things you define as a function. To be more precise, the *name*
> "g" which refers to the function exists in the module's global scope. As
> a short-cut, we call such names "global variables", even if they never
> vary.
>
> You only need to declare a global variable inside a function if you are
> re-assigning a value to it. Hence:
>
> a = 1
> b = 2
> def test():
> global b
> b = b + a

So even though test() has access to a and b, it won't change b when
called unless b is declared global inside the function?

> [...]
>> Third: I am always open to stylistic comments and how to be more pythonic!
>
> Fix your variable names!

I knew I would be dinged on this, but I wanted to get my main question
(about global/local) out there before I left work. The code I posted
has been changed numerous times as I dickered around with Tkinter all
day today. Despite having Grayson's book on Tkinter, it has been hard
going for me. I PROMISE crummy variable names will not make it into
the final code. Once I get the logic working and the appearance like I
want it and more importantly understand what is going on, I am going
to rewrite everything from scratch.

> You have a variable called "buttonNumber" which holds a LIST, not a
> number. Confusing!

In an earlier version buttonNumber was a number.

> You have another variable called "1", or is that "I", no sorry it's "l".
> Notice that depending on the font you use, 1 I and l can look almost
> exactly the same. That's a bad thing. Also, the name "l" doesn't mean
> anything, it doesn't tell you the purpose of the variable.

Originally l (ell) was a physical list written out. I am not used to
the way python iterates, so I was playing around with this feature in
different ways until I was sure I saw what it was doing, especially
with the 2-tuples as list elements. Now that I see how this seems to
work, I am planning on having a configuration file of some sort that
will populate this list. Where I work we have multiple centers and
people will have different versions of this list. So I intend to
separate this out and each center can have their own custom
radiobutton list to choose from.

> Then there is another variable called "var". That's nice, we already
> know it's a variable, but what role does it play in your program? Try to
> find a more descriptive name.

I have been switching back and forth between different python books.
The name var came from Grayson's generic examples. I also got caught
out by "str" as a variable name on an earlier question. That
particular book is especially bad in variable names. But again,
instead of renaming other people's code snippets, I tend to use them
as is while I am experimenting with what their snippets are trying to
do.I suppose I should be more diligent even during my "play" time in
case I wind up copying and pasting portions of the play code into code
I intend to keep. I imagine I might not remember to change all of the
awful names into good ones.

Anyway thanks for your insights!

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


[Tutor] A small project

2014-11-26 Thread Santosh Kumar
Hi All,

I am planning to start a small project , so i need some suggestions on how
to go about it.

1) It basically takes some inputs like (name,age,course,joining
date,remarks) so on.
2) I want a light front end for it.
3) i should be able to query for a particular person on a particular date
or a joining date.
4) The app should be easily deployable both in the linux and windows
machines. ( something like a .exe in windows)

So this is my requirement as stated in the above four points. Now i need
suggestions on how to go ahead with these.

for 2) should i go for tkinter or do we have something even lighter.
for 3) to achieve this should i just go for a database, if yes i need
something which can be easily moved across.
for 4) if i have to create a executable , how to make sure all the above
requirements can be packaged into a application or a software.

Thanks in advance.
-- 
D. Santosh Kumar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor