Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Lisi
On Tuesday 16 August 2011 00:48:08 Walter Prins wrote:
 On 16 August 2011 00:43, Connor Merritt kingconnor...@gmail.com wrote:
  So i installed python 2.7.1 on my linux and i bought a book that requires
  python 3 so installed python 3, and i used terminal and typed in python
  -V and it said 2.7.1 how do i get it to be 3 (i tried deleting it but i
  couldn't what should i do?)

 Try

 python3 -V

 The default is probably still Python2 but that does not mean you can't use
 Python explicitly.

If you prefer to have Python 3 only, you could also uninstall Python 2.7.1.  
You do not say what version of what distro you are using, nor what method you 
used to install Python 2, so I can't be more explicit.

Lisi

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


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Alan Gauld

On 16/08/11 07:52, Lisi wrote:

On Tuesday 16 August 2011 00:48:08 Walter Prins wrote:
 So i installed python 2.7.1 on my linux and i bought a book that 
requires

 python 3 so installed python 3, and i used terminal and typed in python
 -V and it said 2.7.1 how do i get it to be 3 (i tried deleting it but i
 couldn't what should i do?)

 Try

 python3 -V

 The default is probably still Python2 but that does not mean you 
can't use

 Python explicitly.

If you prefer to have Python 3 only, you could also uninstall Python 
2.7.1.
You do not say what version of what distro you are using, nor what 
method you

used to install Python 2, so I can't be more explicit.


You might need to ensure that you have at least 1 version of Python2 around
because a lot of Linux tools are still written in v2 and might break if you
uninstall all v2 versions...

I'd go with the python3 tip, that's what I use with 2 versions of Python...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] help in TKINTER

2011-08-16 Thread Alan Gauld

On 16/08/11 05:31, aditya wrote:

Hello tutors,

I wanted some help in using the Tkinter class for button creation, I am
not able to add on click events i.e. when I press the button certain
action should be performed for example if I press the button named 5,
then it should display 5 in the text field .


The default behaviour for a button is to do nothing.
If you want it to do something you will need to assign a
command action, usually a function or method name.

But without seeing your code (or at least short sample code)
we can't begin to guess what you might be doing wrong...

If you look at the GUI programming topic in my tutorial you
will see various short programs including some adding a button
and an associated action.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] directory within directory

2011-08-16 Thread Peter Otten
questions anon wrote:

 I would like to open up a bunch of files within a folder within a folder
 and then process them and output them in another location but with the
 same folder structure. I seem to having trouble with the folder within
 folder section.
 I have a separate folder for each year and then within a year I have a
 separate folder for each month but when I try to make a directory in a new
 location it does not place the month folders within the year folders,
 instead they are all places in the outputpath together
 any help will be greatly appreciated
 
 import os
 
 inputpath=r'E:/temp_samples2/'
 outputpath=r'E:/figureoutputs/'
 
 for (path, dirs, files) in os.walk(inputpath):
 for dir in dirs:
 print path, dir
 newfolders=outputpath+dir

Using string concatenation to produce file paths is errorprone.
Have a look at the path manipulation functions that the os.path module has 
to offer.

 if not os.path.exists(newfolders):
os.makedirs(newfolders)
print newfolders

dir is just the directory name. You get the source directory with

sourcepath = os.path.join(path, dir)

Now you have to remove the start of the path with

relativepath = os.path.relpath(sourcepath, inputpath)

Finally add the outputpath:

newdir = os.path.join(outputpath, relativepath)


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


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Lisi
On Tuesday 16 August 2011 09:05:44 Alan Gauld wrote:
 You might need to ensure that you have at least 1 version of Python2 around
 because a lot of Linux tools are still written in v2 and might break if you
 uninstall all v2 versions...

Thanks for that, Alan.  I knew that I had Python 2 by default and did not have 
to install it, but had not queried why.  I clearly should have.  I should 
also, of course, check whether something is a dependancy of something else 
before suggesting its removal. :-(  Luckily, if he used a package manager of 
any kind, it would have warned him that it is a dependancy of various 
packages.


If it was already on the system , I wonder why the OP needed to install it?

Lisi


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


[Tutor] Adding index numbers to tuple

2011-08-16 Thread Timo
Hello,
Maybe a bit confusing topic title, probably the example will do.

I have a tuple:
t = ('a', 'b', 'c', 'd')
And need the following output, list or tuple, doesn't matter:
(0, 'a', 1, 'b', 2, 'c', 3, 'd')

I tried with zip(), but get a list of tuples, which isn't the desired
output. Anyone with a solution or push in the right direction?

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


Re: [Tutor] Adding index numbers to tuple

2011-08-16 Thread Martin A. Brown

Hello,

 : Maybe a bit confusing topic title, probably the example will do.
 : 
 : I have a tuple:
 : t = ('a', 'b', 'c', 'd')
 : And need the following output, list or tuple, doesn't matter:
 : (0, 'a', 1, 'b', 2, 'c', 3, 'd')
 : 
 : I tried with zip(), but get a list of tuples, which isn't the desired
 : output. Anyone with a solution or push in the right direction?

Perhaps you did not know about enumerate?

  t = ('a', 'b', 'c', 'd')
  l = list()
  for x in enumerate(t):
  l.extend(x)

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Adding index numbers to tuple

2011-08-16 Thread Christian Witts

On 2011/08/16 03:10 PM, Timo wrote:

Hello,
Maybe a bit confusing topic title, probably the example will do.

I have a tuple:
t = ('a', 'b', 'c', 'd')
And need the following output, list or tuple, doesn't matter:
(0, 'a', 1, 'b', 2, 'c', 3, 'd')

I tried with zip(), but get a list of tuples, which isn't the desired 
output. Anyone with a solution or push in the right direction?


Cheers,
TImo


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


 t = ('a', 'b', 'c', 'd')
 new_t = zip(xrange(len(t)), t)
 new_t
[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]
 from itertools import chain
 list(chain.from_iterable(new_t))
[0, 'a', 1, 'b', 2, 'c', 3, 'd']

That would be for if you were using the zip way, but enumerate should be 
simpler as Martin pointed out.


--

Christian Witts
Python Developer

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


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Alan Gauld

On 16/08/11 10:14, Lisi wrote:

On Tuesday 16 August 2011 09:05:44 Alan Gauld wrote:
 You might need to ensure that you have at least 1 version of Python2 
around
 because a lot of Linux tools are still written in v2 and might break 
if you

 uninstall all v2 versions...

Thanks for that, Alan.  I knew that I had Python 2 by default and did 
not have

to install it, but had not queried why.
It can be hard to tell, sometimes distro designers just think something 
is useful.

For example many Linux users nowadays have no use for gcc but it is usually
packaged anyway.

If it was already on the system , I wonder why the OP needed to 
install it?


I suspect that the default was probably version 2.5 or 2.6 (My Ubuntu 
10.04 has 2.6)

So if OP installed 2.7 it would be additional.

My concern was that if they uninstalled 2.7 the default would revert to 
2.6 (or

whatever) and they might then be tempted to uninstall that too!

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] Adding index numbers to tuple

2011-08-16 Thread Hugo Arts
On Tue, Aug 16, 2011 at 3:42 PM, Christian Witts cwi...@compuscan.co.za wrote:
 On 2011/08/16 03:10 PM, Timo wrote:

 Hello,
 Maybe a bit confusing topic title, probably the example will do.

 I have a tuple:
 t = ('a', 'b', 'c', 'd')
 And need the following output, list or tuple, doesn't matter:
 (0, 'a', 1, 'b', 2, 'c', 3, 'd')

 I tried with zip(), but get a list of tuples, which isn't the desired
 output. Anyone with a solution or push in the right direction?

 Cheers,
 TImo

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

 t = ('a', 'b', 'c', 'd')
 new_t = zip(xrange(len(t)), t)
 new_t
 [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]
 from itertools import chain
 list(chain.from_iterable(new_t))
 [0, 'a', 1, 'b', 2, 'c', 3, 'd']

 That would be for if you were using the zip way, but enumerate should be
 simpler as Martin pointed out.


You can sort of mix the two together:

 from itertools import chain
 t = ('a', 'b', 'c', 'd')
 list(chain.from_iterable(enumerate(t)))
[0, 'a', 1, 'b', 2, 'c', 3, 'd']

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


[Tutor] Passing functions(with parameters) as paramiters to (looping)functions.

2011-08-16 Thread Jeff Peters

Hi;

I am trying to run a function inside a continuing loop, but do not seem 
to be able to pass any parameters (arguments ) when I do so.

I have placed working and non-working code , with output below.

## This works:

def loop(fn ):
for i in range(5):
fn(  )

def this_function(a= i am not a string):
print( a )

loop(this_function)

## with output:

 i am not a string
 i am not a string
 i am not a string
 i am not a string
 i am not a string


## But , this does not :

def loop(fn ):
for i in range(5):
fn(  )

def this_function(a= i am not a string):
print( a )

loop(this_function(I am a string) )  ## note the only change is here

## With this as output:


I am a string
Traceback (most recent call last):
  File /home/jeff/MyPythonStuff/call_sub.py, line 9, in module
loop(this_function(I am a string) )
  File /home/jeff/MyPythonStuff/call_sub.py, line 4, in loop
fn(  )
TypeError: 'NoneType' object is not callable


My OS is Debian  64 bit
I get the same output for both python2.7 and Python3.1
I think this should be do-able but I am in need of a clue.
Thanks.







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


Re: [Tutor] Passing functions(with parameters) as paramiters to (looping)functions.

2011-08-16 Thread Giovanni Tirloni
On Tue, Aug 16, 2011 at 1:44 PM, Jeff Peters je...@swva.net wrote:

 Hi;

 I am trying to run a function inside a continuing loop, but do not seem to
 be able to pass any parameters (arguments ) when I do so.
 I have placed working and non-working code , with output below.

 ## This works:

 def loop(fn ):
for i in range(5):
fn(  )

 def this_function(a= i am not a string):
print( a )

 loop(this_function)

 ## with output:
 
  i am not a string
  i am not a string
  i am not a string
  i am not a string
  i am not a string
 

 ## But , this does not :

 def loop(fn ):
for i in range(5):
fn(  )

 def this_function(a= i am not a string):
print( a )

 loop(this_function(I am a string) )  ## note the only change is here

 ## With this as output:

 
 I am a string
 Traceback (most recent call last):
  File /home/jeff/MyPythonStuff/**call_sub.py, line 9, in module
loop(this_function(I am a string) )
  File /home/jeff/MyPythonStuff/**call_sub.py, line 4, in loop
fn(  )
 TypeError: 'NoneType' object is not callable
 


Your loop() function expects the parameter 'fn' to be a function that it can
then call.

In your second example, it doesn't work because you already called the
function and is passing as parameter 'fn' whatever this_function() returned.


 type(this_function)
type 'function'

 type(this_function(I am a string))
I am a string
type 'NoneType'

If you really want this design, one way to fix it is to change loop() to
accept another argument that is going to be passed to the function.

def loop(fn, b):
  for i in range(5):
fn(b)

Perhaps if you explain what you are trying to accomplish, someone can
suggest a better way to design the code.

-- 
Giovanni Tirloni
sysdroid.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing functions(with parameters) as paramiters to (looping)functions.

2011-08-16 Thread Peter Otten
Jeff Peters wrote:

 Hi;
 
 I am trying to run a function inside a continuing loop, but do not seem
 to be able to pass any parameters (arguments ) when I do so.
 I have placed working and non-working code , with output below.
 
 ## This works:
 
 def loop(fn ):
  for i in range(5):
  fn(  )
 
 def this_function(a= i am not a string):
  print( a )
 
 loop(this_function)
 
 ## with output:
  
   i am not a string
   i am not a string
   i am not a string
   i am not a string
   i am not a string
  
 
 ## But , this does not :
 
 def loop(fn ):
  for i in range(5):
  fn(  )
 
 def this_function(a= i am not a string):
  print( a )
 
 loop(this_function(I am a string) )  ## note the only change is here

You are calling this_function() and then pass the result of the function 
call to your other function loop().

Instead you need another function that builds a function that calls 
this_function() with the desired argument:

 def loop(f):
... for i in range(5):
... f()
...
 def this_function(a):
... print(a)
...
 def make_function(f, arg):
... def g():
... f(arg)
... return g
...
 loop(make_function(this_function, foo))
foo
foo
foo
foo
foo
 loop(make_function(this_function, bar))
bar
bar
bar
bar
bar


Of course you could also change loop() to pass on arbitrary arguments:

 def loop(f, *args, **kw):
... for i in range(3):
... f(*args, **kw)
...
 loop(print, 1, 2)
1 2
1 2
1 2
 loop(print, 1, 2, sep=--)
1--2
1--2
1--2

Because building a function that just calls another function with some 
predefined arguments is a common need the standard library has 
functools.partial():

 from functools import partial
 print42 = partial(print, 42)
 print42()
42
 loop(print42)
42
42
42

Another variant is a lambda function with a default argument:

 loop(lambda a=whatever: print(a))
whatever
whatever
whatever




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


Re: [Tutor] Passing functions(with parameters) as paramiters to (looping)functions.

2011-08-16 Thread Prasad, Ramit
def loop(fn ):
 for i in range(5):
 fn(  )

def this_function(a= i am not a string):
 print( a )

loop(this_function(I am a string) )  ## note the only change is here

## With this as output:

 
I am a string
Traceback (most recent call last):
   File /home/jeff/MyPythonStuff/call_sub.py, line 9, in module
 loop(this_function(I am a string) )
   File /home/jeff/MyPythonStuff/call_sub.py, line 4, in loop
 fn(  )
TypeError: 'NoneType' object is not callable
 

NOTE: All code is untested.

You get a NoneType because this_function returns a None. What is happening is 
the this_function(xxx) gets called first and then that return value gets 
passed into loop as 'loop(None)'. I am not sure exactly what you are trying to 
do, but I would probably do something like passing in a list of arguments.

loop(this_function, iterable_of_arguments)

def loop(fn, args):
 for arg in args :
 fn( arg )

The way I would get an argument gets passed to this_function is really 
dependent on your goal. You may want to look at itertools / map libraries as 
well for more options.


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Jeremy G Clark
@ Connor -- you probably should heed the advice of Alan and leave your existing 
Python 2.x install alone.  For the exercises in your book, you should be able 
to include this line at the top of every script and it'll work just fine.  I 
can't remember, you may need to chmod +x in order for this to work.  Anyone?

#! /usr/bin/python3

Or, use python3 to open the script from the command line: connor@linuxbox# 
python3 script.py
This is how I test on my Ubuntu install.

-Original Message-
From: tutor-bounces+jeremy.clark=ucr@python.org 
[mailto:tutor-bounces+jeremy.clark=ucr@python.org] On Behalf Of Alan Gauld
Sent: Tuesday, August 16, 2011 9:07 AM
To: tutor@python.org
Subject: Re: [Tutor] which version do i have and how do i change it

On 16/08/11 10:14, Lisi wrote:
 On Tuesday 16 August 2011 09:05:44 Alan Gauld wrote:
  You might need to ensure that you have at least 1 version of Python2
 around
  because a lot of Linux tools are still written in v2 and might break
 if you
  uninstall all v2 versions...

 Thanks for that, Alan.  I knew that I had Python 2 by default and did 
 not have to install it, but had not queried why.
It can be hard to tell, sometimes distro designers just think something is 
useful.
For example many Linux users nowadays have no use for gcc but it is usually 
packaged anyway.

 If it was already on the system , I wonder why the OP needed to 
 install it?

I suspect that the default was probably version 2.5 or 2.6 (My Ubuntu
10.04 has 2.6)
So if OP installed 2.7 it would be additional.

My concern was that if they uninstalled 2.7 the default would revert to
2.6 (or
whatever) and they might then be tempted to uninstall that too!

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] Passing functions(with parameters) as paramiters to (looping)functions.

2011-08-16 Thread Jeff Peters

On 08/16/2011 01:46 PM, Peter Otten wrote:

Jeff Peters wrote:


Hi;

I am trying to run a function inside a continuing loop, but do not seem
to be able to pass any parameters (arguments ) when I do so.
I have placed working and non-working code , with output below.

## This works:

def loop(fn ):
  for i in range(5):
  fn(  )

def this_function(a= i am not a string):
  print( a )

loop(this_function)

## with output:
  
   i am not a string
   i am not a string
   i am not a string
   i am not a string
   i am not a string
  

## But , this does not :

def loop(fn ):
  for i in range(5):
  fn(  )

def this_function(a= i am not a string):
  print( a )

loop(this_function(I am a string) )  ## note the only change is here

You are calling this_function() and then pass the result of the function
call to your other function loop().

Instead you need another function that builds a function that calls
this_function() with the desired argument:


def loop(f):

... for i in range(5):
... f()
...

def this_function(a):

... print(a)
...

def make_function(f, arg):

... def g():
... f(arg)
... return g
...

loop(make_function(this_function, foo))

foo
foo
foo
foo
foo

loop(make_function(this_function, bar))

bar
bar
bar
bar
bar
Of course you could also change loop() to pass on arbitrary arguments:


def loop(f, *args, **kw):

... for i in range(3):
... f(*args, **kw)
...

loop(print, 1, 2)

1 2
1 2
1 2

loop(print, 1, 2, sep=--)

1--2
1--2
1--2

Because building a function that just calls another function with some
predefined arguments is a common need the standard library has
functools.partial():


from functools import partial
print42 = partial(print, 42)
print42()

42

loop(print42)

42
42
42

Another variant is a lambda function with a default argument:


loop(lambda a=whatever: print(a))

whatever
whatever
whatever




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



Thanks,  that  is what I needed.
not splitting the function name and argument list was
my problem.  and the  function creator  idea really appeals
thanks again - jeff


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


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Prasad, Ramit
 I can't remember, you may need to chmod +x in order for this to work.  Anyone?

You need to chmod if you want to call the script via shebang (./script.py). If 
you are calling it by doing 'python3 script.py' then you do not need it as 
python3 should already be executable.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



-Original Message-
From: tutor-bounces+ramit.prasad=jpmorgan@python.org 
[mailto:tutor-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of Jeremy 
G Clark
Sent: Tuesday, August 16, 2011 12:59 PM
To: tutor@python.org
Subject: Re: [Tutor] which version do i have and how do i change it

@ Connor -- you probably should heed the advice of Alan and leave your existing 
Python 2.x install alone.  For the exercises in your book, you should be able 
to include this line at the top of every script and it'll work just fine.  I 
can't remember, you may need to chmod +x in order for this to work.  Anyone?

#! /usr/bin/python3

Or, use python3 to open the script from the command line: connor@linuxbox# 
python3 script.py
This is how I test on my Ubuntu install.

-Original Message-
From: tutor-bounces+jeremy.clark=ucr@python.org 
[mailto:tutor-bounces+jeremy.clark=ucr@python.org] On Behalf Of Alan Gauld
Sent: Tuesday, August 16, 2011 9:07 AM
To: tutor@python.org
Subject: Re: [Tutor] which version do i have and how do i change it

On 16/08/11 10:14, Lisi wrote:
 On Tuesday 16 August 2011 09:05:44 Alan Gauld wrote:
  You might need to ensure that you have at least 1 version of Python2
 around
  because a lot of Linux tools are still written in v2 and might break
 if you
  uninstall all v2 versions...

 Thanks for that, Alan.  I knew that I had Python 2 by default and did 
 not have to install it, but had not queried why.
It can be hard to tell, sometimes distro designers just think something is 
useful.
For example many Linux users nowadays have no use for gcc but it is usually 
packaged anyway.

 If it was already on the system , I wonder why the OP needed to 
 install it?

I suspect that the default was probably version 2.5 or 2.6 (My Ubuntu
10.04 has 2.6)
So if OP installed 2.7 it would be additional.

My concern was that if they uninstalled 2.7 the default would revert to
2.6 (or
whatever) and they might then be tempted to uninstall that too!

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Jeremy G Clark
Yes, that's what I was trying to say.  Thanks for translating! :)

-Original Message-
From: Prasad, Ramit [mailto:ramit.pra...@jpmorgan.com] 
Sent: Tuesday, August 16, 2011 11:24 AM
To: Jeremy G Clark; tutor@python.org
Subject: RE: [Tutor] which version do i have and how do i change it

 I can't remember, you may need to chmod +x in order for this to work.  Anyone?

You need to chmod if you want to call the script via shebang (./script.py). If 
you are calling it by doing 'python3 script.py' then you do not need it as 
python3 should already be executable.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



-Original Message-
From: tutor-bounces+ramit.prasad=jpmorgan@python.org 
[mailto:tutor-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of Jeremy 
G Clark
Sent: Tuesday, August 16, 2011 12:59 PM
To: tutor@python.org
Subject: Re: [Tutor] which version do i have and how do i change it

@ Connor -- you probably should heed the advice of Alan and leave your existing 
Python 2.x install alone.  For the exercises in your book, you should be able 
to include this line at the top of every script and it'll work just fine.  I 
can't remember, you may need to chmod +x in order for this to work.  Anyone?

#! /usr/bin/python3

Or, use python3 to open the script from the command line: connor@linuxbox# 
python3 script.py This is how I test on my Ubuntu install.

-Original Message-
From: tutor-bounces+jeremy.clark=ucr@python.org 
[mailto:tutor-bounces+jeremy.clark=ucr@python.org] On Behalf Of Alan Gauld
Sent: Tuesday, August 16, 2011 9:07 AM
To: tutor@python.org
Subject: Re: [Tutor] which version do i have and how do i change it

On 16/08/11 10:14, Lisi wrote:
 On Tuesday 16 August 2011 09:05:44 Alan Gauld wrote:
  You might need to ensure that you have at least 1 version of Python2
 around
  because a lot of Linux tools are still written in v2 and might break
 if you
  uninstall all v2 versions...

 Thanks for that, Alan.  I knew that I had Python 2 by default and did 
 not have to install it, but had not queried why.
It can be hard to tell, sometimes distro designers just think something is 
useful.
For example many Linux users nowadays have no use for gcc but it is usually 
packaged anyway.

 If it was already on the system , I wonder why the OP needed to 
 install it?

I suspect that the default was probably version 2.5 or 2.6 (My Ubuntu
10.04 has 2.6)
So if OP installed 2.7 it would be additional.

My concern was that if they uninstalled 2.7 the default would revert to
2.6 (or
whatever) and they might then be tempted to uninstall that too!

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
This email is confidential and subject to important disclaimers and conditions 
including on offers for the purchase or sale of securities, accuracy and 
completeness of information, viruses, confidentiality, legal privilege, and 
legal entity disclaimers, available at 
http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Message: pygobject_register_sinkfunc is deprecated (GtkWindow)

2011-08-16 Thread Susana Iraiis Delgado Rodriguez
Hello List!

I just started to use PyGTK and Glade to create graphical interfaces, my
python interpreter version is 2.6.6; I also install the GTK2 Runtime
enviroment and Glade 3.6.6. I also installed in my computer
pycairo-1.8.10.win32-py2.6.exe, pygobject-2.26.0-1.win32-py2.6.exe and
pygtk-2.16.0+glade.win32-py2.6.exe so my graphic application will look and
work fine.

I tried to do an example in order to get familiar with this new tool, but
when I run the script I got the next message:
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
on
win32
Type help, copyright, credits or license for more information.
 import glade1
** Message: pygobject_register_sinkfunc is deprecated (GtkWindow)
** Message: pygobject_register_sinkfunc is deprecated (GtkInvisible)
** Message: pygobject_register_sinkfunc is deprecated (GtkObject)

My code is:
import pygtk
pygtk.require(2.0)
import gtk
import gtk.glade

class MainWin:
def __init__(self):
self.widgets = gtk.glade.XML(ejemplo_glade.glade)
signals = { on_entry1_activate : self.on_button1_clicked,
on_button1_clicked : self.on_button1_clicked,
gtk_main_quit : gtk.main_quit }
self.widgets.signal_autoconnect(signals)
self.label1 = self.widgets.get_widget(label1)
self.entry1 = self.widgets.get_widget(entry1)
def on_button1_clicked(self, widget):
texto = self.entry1.get_text()
self.label1.set_text(Hola %s % texto)


if __name__ == __main__:
MainWin()
gtk.main()

Does my python libraries are the correct ones for my interpreter?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Lisi
On Tuesday 16 August 2011 17:06:42 Alan Gauld wrote:
 It can be hard to tell, sometimes distro designers just think something
 is useful.

lisi@Tux:~$ aptitude why python
i   reportbug Depends python (= 2.5)
lisi@Tux:~$

!!

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


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Lisi
On Tuesday 16 August 2011 17:06:42 Alan Gauld wrote:
 My concern was that if they uninstalled 2.7 the default would revert to
 2.6 (or
 whatever) and they might then be tempted to uninstall that too!

Yes - mea culpa for not realising that.  Mind you, if I had investigated my 
own system I would hardly have come to the conclusion that Python was 
essential.

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


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Jerry Hill
On Tue, Aug 16, 2011 at 4:35 PM, Lisi lisi.re...@gmail.com wrote:
 lisi@Tux:~$ aptitude why python
 i   reportbug Depends python (= 2.5)
 lisi@Tux:~$

Keep in mind that that command only shows you a single dependency
chain.  Try again with aptitude -v why python to see all of the
dependencies.  On my ubuntu 11.04 machine, that command produces over
9000 lines of output, and over 800 distinct packages that depend on
python in one way or another.

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


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Lisi
On Tuesday 16 August 2011 21:53:46 Jerry Hill wrote:
 On Tue, Aug 16, 2011 at 4:35 PM, Lisi lisi.re...@gmail.com wrote:
  lisi@Tux:~$ aptitude why python
  i   reportbug Depends python (= 2.5)
  lisi@Tux:~$

 Keep in mind that that command only shows you a single dependency
 chain.  Try again with aptitude -v why python to see all of the
 dependencies.  On my ubuntu 11.04 machine, that command produces over
 9000 lines of output, and over 800 distinct packages that depend on
 python in one way or another.

Thanks for that.  Very illuminating and interesting.  I hadn't come across 
that command before.  (I tend to look things up in man aptitude rather than 
read it through.)

But in my case it only served to illustrate that nothing of any real 
importance in my system depends on Python.  In fact, not only were there no 
direct dependency chains leading to Python, since all of them had at least 
2 suggests in the chain, the few things that did depend on Python, at the 
end of the chain, after the suggests, were mostly not installed, so would not 
have missed Python.

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


Re: [Tutor] directory within directory

2011-08-16 Thread questions anon
Thank you, that does create the directories in the new place but when I
process the data it does not put the outputs in the correct directory they
all end up in the last directory created.
Below is the code of what I am trying to do.
Any feedback will be greatly appreciated.

from netCDF4 import Dataset
import numpy as N
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from netcdftime import utime
from datetime import datetime
import os

inputpath=r'E:/temp_samples2/'
outputpath=r'E:/figureoutputs/'

for (path, dirs, files) in os.walk(inputpath):
for dir in dirs:
print dir
sourcepath=os.path.join(path,dir)
relativepath=os.path.relpath(sourcepath,inputpath)
newdir=os.path.join(outputpath,relativepath)
if not os.path.exists(newdir):
os.makedirs(newdir)

for ncfile in files:
if ncfile[-3:]=='.nc':
ncfile=os.path.join(sourcepath,ncfile)
ncfile=Dataset(ncfile, 'r+', 'NETCDF4')
TSFC=ncfile.variables['T_SFC'][:,:,:]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][:]
fillvalue=ncfile.variables['T_SFC']._FillValue
TSFC=MA.masked_values(TSFC, fillvalue)
ncfile.close()

for TSFC, TIME in zip((TSFC[4::24]),(TIME[4::24])):
print TSFC, TIME
#convert time from numbers to date and prepare it to have no
symbols for saving to filename
cdftime=utime('seconds since 1970-01-01 00:00:00')
ncfiletime=cdftime.num2date(TIME)
print ncfiletime
timestr=str(ncfiletime)
d = datetime.strptime(timestr, '%Y-%m-%d %H:%M:%S')
date_string = d.strftime('%Y%m%d_%H%M')
print date_string
#Set up basemap using mercator projection
map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,

llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')

# compute map projection coordinates for lat/lon grid.
x,y=map(*N.meshgrid(LON,LAT))
map.drawcoastlines(linewidth=0.5)
map.drawstates()

plt.title('Surface temperature at %s UTC'%ncfiletime)
ticks=[-5,0,5,10,15,20,25,30,35,40,45,50]
CS = map.contourf(x,y,TSFC, ticks, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h], )
cbar=plt.colorbar(CS, cax=cax, drawedges=True)

#save map as *.png and plot netcdf file

plt.savefig((os.path.join(newdir,'TSFC'+date_string+'UTC.png')))




On Tue, Aug 16, 2011 at 6:21 PM, Peter Otten __pete...@web.de wrote:

 questions anon wrote:

  I would like to open up a bunch of files within a folder within a folder
  and then process them and output them in another location but with the
  same folder structure. I seem to having trouble with the folder within
  folder section.
  I have a separate folder for each year and then within a year I have a
  separate folder for each month but when I try to make a directory in a
 new
  location it does not place the month folders within the year folders,
  instead they are all places in the outputpath together
  any help will be greatly appreciated
 
  import os
 
  inputpath=r'E:/temp_samples2/'
  outputpath=r'E:/figureoutputs/'
 
  for (path, dirs, files) in os.walk(inputpath):
  for dir in dirs:
  print path, dir
  newfolders=outputpath+dir

 Using string concatenation to produce file paths is errorprone.
 Have a look at the path manipulation functions that the os.path module has
 to offer.

  if not os.path.exists(newfolders):
 os.makedirs(newfolders)
 print newfolders

 dir is just the directory name. You get the source directory with

 sourcepath = os.path.join(path, dir)

 Now you have to remove the start of the path with

 relativepath = os.path.relpath(sourcepath, inputpath)

 Finally add the outputpath:

 newdir = os.path.join(outputpath, relativepath)


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

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


Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Steven D'Aprano

Connor Merritt wrote:

So i installed python 2.7.1 on my linux and i bought a book that requires
python 3 so installed python 3, and i used terminal and typed in python -V
and it said 2.7.1 how do i get it to be 3 (i tried deleting it but i
couldn't what should i do?)


At the terminal, type python3 instead of python.



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


Re: [Tutor] numpy.mean across multiple netcdf files

2011-08-16 Thread questions anon
Thanks Andre I had a go at following your advice but it didn't seem to work
(it kept focusing on the last loop and not combining them all together) so I
have posted a note on scipy user group instead (code below).
Also thanks for the advice regarding averaging!


from netCDF4 import Dataset
import matplotlib.pyplot as plt
import numpy as N
from mpl_toolkits.basemap import Basemap
import os

MainFolder=rE:/temp_samples/
for (path, dirs, files) in os.walk(MainFolder):
for dir in dirs:
print dir
for ncfile in files:
if ncfile[-3:]=='.nc':
ncfile=os.path.join(path,ncfile)
ncfile=Dataset(ncfile, 'r+', 'NETCDF4')
TSFC=ncfile.variables['T_SFC'][4::24]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][:]
fillvalue=ncfile.variables['T_SFC']._FillValue
ncfile.close()

#calculate summary stats
big_array=[]
for i in TSFC:
big_array.append(i)
big_array=N.array(big_array)
Mean=N.mean(big_array, axis=0)

#plot output summary stats
map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,

llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
map.drawcoastlines()
map.drawstates()
x,y=map(*N.meshgrid(LON,LAT))
plt.title('Total Mean at 3pm')
ticks=[-5,0,5,10,15,20,25,30,35,40,45,50]
CS = map.contourf(x,y,Mean,ticks, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax, drawedges=True)
plt.show()


On Thu, Aug 11, 2011 at 4:48 PM, Andre' Walker-Loud walksl...@gmail.comwrote:

 Hello Anonymous Questioner,

 First - you will probably be told this isn't the correct email list for
 this question - this is a general python tutorial list, while your question
 is numpy specific, so if this doesn't help, you should probably look to
 another email list.

 There are a couple general comments to make regarding your question.
  Basically, you want to load all the data into one big numpy array.
  Currently, it seems your data array has 3 indices, from this line

  TSFC=ncfile.variables['T_SFC'][4::24,:,:]

 you can make a larger array with one more index, where the new index runs
 over files.  So instead of looping over the files as you do, you can use the
 loop to build the larger array.

 I am sure there is a more elegant way to do this, but here is something
 that is along the lines of what you want

  big_array = []
  for ncfile in files:
big_array.append(ncfile.variables['T_SFC'][4::24,:,:])

 if all of your data you are taking from each file is the same size for all
 the files, then you can declare the whole thing an array

  big_array = N.array(big_array)

 and then you can take averages very easily by specifying which index, or
 indices you want to average over.  If life is not so kind, and your files
 are of different sizes, then you have to be more careful.  But to give a
 precise answer to your problem would require knowledge of what your data
 files actually look like.


 Also, a bit of caution with averaging (in case you are unfamiliar).  Say
 you have 5 data sets, and each one has a different amount of data in it.  If
 you first take the average of each set, you can not simply take the average
 of those sets to produce the global average.  You have to weight each set by
 the amount of data you averaged.  Say the length of the sets are
 [N0,N1,N2,N3,N4] with average values [a0,a1,a2,a3,a4], then to produce the
 global average, you need to take

 avg = (1 / (N0+N1+N2+N3+N4) ) * (N0*a0 + N1*a1 + N2*a2 + N3*a3 + N4*a4)

 a few lines of algebra can demonstrate this produces the average you would
 get by combining all the data in all the sets and taking one big average.


 Regards,

 Andre



 On Aug 10, 2011, at 6:57 PM, questions anon wrote:

  I have many ncfiles each containing one month of hourly temperature data.
  I have worked out how to loop through a number of ncfiles and calculate
 the mean for each file at a particular time and even plot this and output as
 a *.png.
  What I am unsure of is how to calculate the mean at a particular time for
 all files.
  Do I somehow output the mean for each folder and then calculate the mean
 of all the means? Or is there some way to loop through and calculate it
 directly?
  Below is the code I have working that calculates the mean for each file.
 Any help will be greatly appreciated!!
 
  from netCDF4 import Dataset
  import numpy as N
 
  MainFolder=rD:/temp_samples/
  print MainFolder
  for (path, dirs, files) in os.walk(MainFolder):
  for dir in dirs:
  print dir
  path=path+'/'
 
  for ncfile in files:
  if ncfile[-3:]=='.nc':
  print dealing with ncfiles:, ncfile
  

Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Alan Gauld

On 16/08/11 21:53, Jerry Hill wrote:

...  Try again with aptitude -v why python to see all of the
dependencies.  On my ubuntu 11.04 machine, that command produces over
9000 lines of output, 


And on my 10.04 LTS PC it gives too many lines to scroll back
to the top (actually 1645 , I just checked :-)

And interestingly dependencies include gimp, gedit and scribus,
all things I use regularly.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] Tkinter: no module named messagebox

2011-08-16 Thread brandon w

On 08/14/2011 02:29 AM, Peter Otten wrote:

brandon w wrote:

   

On 08/13/2011 04:49 PM, Peter Otten wrote:
 
   

How do I find the modules in Tkinter?

 

The simplest approach is probably to explore your file system:

Step 1: where's Tkinter?

$ python -c 'import Tkinter, os; print os.path.dirname(Tkinter.__file__)'
/usr/lib/python2.6/lib-tk
   
   

I have tried # 1. with another command but all I get is an error messages.

$ python -c 'import time, os; print os.path.dirname(time.__doc__)' #
This one gave no output.
 

You typed time.__doc__ instead of time.__file__. With the latter you'd get
an AttributeError because the time module is implemented in C.

   

$ python -c 'import time, strftime, os; print
os.path.dirname(strftime.__doc__)'
Traceback (most recent call last):
File string, line 1, inmodule
ImportError: No module named strftime
 

Well you cannot import a module that doesn't exist...

   

$ python -c 'import os; from time import strftime; print
os.path.dirname(strftime.__file__)'
Traceback (most recent call last):
File string, line 1, inmodule
AttributeError: 'builtin_function_or_method' object has no attribute
'__file__'

$ python -c 'import time, os; print os.path.dirname(time.__file__)'
Traceback (most recent call last):
File string, line 1, inmodule
File /usr/lib/python2.6/posixpath.py, line 119, in dirname
  i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'

$  python -c 'import time, os; print os.path.dirname(time.__package__)'
more errors

I am obviously doing something wrong.
 

The method to find the location of a module that I gave works only for
modules and only for modules implemented in Python. You can find both
functions and modules implemented in Python with inspect.getsourcefile():

   

from inspect import getsourcefile
import os
getsourcefile(os) # a module
 

'/usr/lib/python2.6/os.py'
   

getsourcefile(os.path) # another module with an interesting filename
 

'/usr/lib/python2.6/posixpath.py'
   

getsourcefile(os.walk) # a function implemented in Python
 

'/usr/lib/python2.6/os.py'
   

getsourcefile(os.mkdir) # a function implemented in C
 

Traceback (most recent call last):
   File stdin, line 1, inmodule
   File /usr/lib/python2.6/inspect.py, line 441, in getsourcefile
 filename = getfile(object)
   File /usr/lib/python2.6/inspect.py, line 418, in getfile
 raise TypeError('arg is not a module, class, method, '
TypeError: arg is not a module, class, method, function, traceback, frame,
or code object



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

Thank a lot for your help. I will study what you have shown me.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter: no module named messagebox (brandon w)

2011-08-16 Thread brandon w

On 08/14/2011 03:10 AM, Robert Sjoblom wrote:

I have tried to follow the tutorial I found here:

Python 2.7 Tutorial
http://www.youtube.com/watch?v=uh6AdDX7K7U

This is what I have done so far:

#!/usr/bin/python

from Tkinter import *
import Tkinter.MessageBox
 

I figured I might as well, given how I recently had to learn about
this, give you a heads up on imports. The format from module import *
 is not a very good idea: it makes your code harder to read (as the
reader has to inspect each and every barename to check whether it's
actually assigned locally OR comes from the deuced *). To quote the
Zen of Python; namespaces are a honking great idea -- let's do more
of those!.

You can import modules with several different syntaxes:
import importable
import importable1, importable2, ..., importableN
import importable as preferred_name

Here importable is usually a module such as collections, but could be
a package or module in a package, in which case each part is separated
with a dot, for example os.path. The first two syntaxes are the
simplest  and also the safest because they avoid the possibility of
having name conflicts, since they force us to always use fully
qualified names.

The third syntax allows us to give a name of our choice to the package
or module we are importing. Theoretically, this could lead to name
clashes, but in practice the import importable as syntax is used to
avoid them.

There are some other import syntaxes:
from importable import object as preferred_name
from importable import object1, object2, ..., objectN
from importable import (object1, object2, ..., objectN)
from importable import *

In the last syntax, the * means import everything that is not
private, which in practical terms means either that every object in
the module is imported except for those whose names begin with a
leading underscore, or, if the module has a global __all__ variable
that holds a list of names, that all the objects in the __all__
variable are imported.

The from importable import * syntax imports all the objects from the
module (or all the modules from the package) -- this could be hundreds
of names. In the case of from os.path import *, almost 40 names are
imported, including dirname, exists, and split, any of which
might be names we would prefer to use for our own variables or
functions.

For example, if we write
from os.path import dirname
we can conveniently call dirname() without qualification. But if
further on in our code we write
dirname = .
the object reference dirname will now be bound to the string .
instead of to the dirname() function, so if we try calling dirname()
we will get a TypeError exception because dirname now refers to a
string, and we can't call strings.

However, given that Tkinter is such a huge package to begin with, I'd
say that you should continue to use from Tkinter import *, but be
aware of what you're doing when you type that, and that there is a
certain risk of conflicts.

best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
   
That is some really good information. Thank you for taking time to 
explain it all to me.

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


Re: [Tutor] Tkinter: no module named messagebox (brandon w)

2011-08-16 Thread brandon w

On 08/14/2011 11:14 AM, Alan Gauld wrote:

On 14/08/11 14:07, Wayne Werner wrote:

Of course I personally I usually do

import Tkinter as tk

Which means I only have to type 3 extra characters, but it removes any
ambiguity - tk.Something had to come from Tkinter


Thats exactly what I tend to do nowadays.

I used to use the import * method for tkinter but eventually
I got bit by a name clash and it took too long to realize the
problem so I now use the import as tk shortcut except for
very short scripts - usually just for tests or experiments..


Thanks. I just downloaded the pdf from your website.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Printing in the same place

2011-08-16 Thread brandon w
I am trying to print in the same place to make a clock in a tkinter 
window. I will loop the following code to update the time.


This seems to work but it is not printing in the same place:

#!/usr/bin/python
#Python 2.6.6

import time

for t in range(5):
digits = time.strftime('%H:%M:%S')
print \r, digits
time.sleep(0.1)




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