Re: [Tutor] [tutor] Zoom in and zoom out capability

2008-01-10 Thread Alan Gauld

"Varsha Purohit" <[EMAIL PROTECTED]> wrote

> Yeah i read about them. i tried using the resize function but i 
> was
> having difficulty with clarity of the image.

I remeber. That was because you were trying to zoom into
a small JPG image. You can't put more detail into an image
than is there to start with. Zooming into a small JPG will
always give you resolution problems.

Alan G. 


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


Re: [Tutor] run in "deamon" mode?

2008-01-10 Thread Alan Gauld

"Allen Fowler" <[EMAIL PROTECTED]> wrote

> How can a make a python script run in "deamon mode"? (on a linux 
> box)

ISTR that there is a recipe for this on the ActiveState cookbook site?

> That is, I want to run the program via "python myfile.py"
> and have it drop me back to the command line.

Simply running in background achioeves this - add ampersand (&)
after the command.

> The program should continue running until I kill it via it's PID,
> the machine shuts down, or the program itself decides to
> shutdown.   It should _not_  die when I simply log-out, etc.

OK, That needs more work - although I think running it from
sudo would do the trick if thats an option. Otherwise its
the cookbook recipe I think.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] run in "deamon" mode?

2008-01-10 Thread Aditya Lal
On Jan 10, 2008 11:11 AM, Allen Fowler <[EMAIL PROTECTED]> wrote:

> Hello,
>
> How can a make a python script run in "deamon mode"? (on a linux box)
>
> That is, I want to run the program via "python myfile.py" and have it drop
> me back to the command line.  The program should continue running until I
> kill it via it's PID, the machine shuts down, or the program itself decides
> to shutdown.   It should _not_  die when I simply log-out, etc.
>
> Is there a standard library module to help with this?
>
> -- Thank you
>
>
>
>
The simplest way to achieve this is as follows :
$ nohup python myfile.py &
Otherwise you need to become daemon from inside the program. fork(),
setsid(), etc. - the normal C language method for becoming a daemon..

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


Re: [Tutor] run in "deamon" mode?

2008-01-10 Thread Remco Gerlich
Hi,

A few days ago, someone posted a "daemon.py" to Reddit, that's supposed to
do everything needed. Haven't used it myself, but here it is:
http://hathawaymix.org/Software/Sketches/daemon.py

Remco

On Jan 10, 2008 6:41 AM, Allen Fowler <[EMAIL PROTECTED]> wrote:

> Hello,
>
> How can a make a python script run in "deamon mode"? (on a linux box)
>
> That is, I want to run the program via "python myfile.py" and have it drop
> me back to the command line.  The program should continue running until I
> kill it via it's PID, the machine shuts down, or the program itself decides
> to shutdown.   It should _not_  die when I simply log-out, etc.
>
> Is there a standard library module to help with this?
>
> -- Thank you
>
>
>
>
>
>
>  
> 
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search.
> http://tools.search.yahoo.com/newsearch/category.php?category=shopping
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] run in "deamon" mode?

2008-01-10 Thread Hiếu Hoàng
On Jan 10, 2008 12:41 PM, Allen Fowler <[EMAIL PROTECTED]> wrote:
>
> How can a make a python script run in "deamon mode"? (on a linux box)
>


The comments on this post sum up a lot of daemonizing modules. I
haven't tried any of them out if they run after you logged out, and
Aditya's "nohup" way looks quickest.

Hiếu
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to run a timer in window using TKINTER

2008-01-10 Thread brindly sujith
i want to run a timer in a window

plz guide me how to do this

after some 5 seconds i want to close the  same window automatically

send me the Tkinter code for this
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getting filen basename without extension

2008-01-10 Thread Timmie
Hello,
I would like to get the name of a file without it's extension/suffix.

What is the easiest and fastes way to get the basename
of a file wihout extension?

What I found is this:
import os
myfile_name_with_path = 'path/to/my/testfile.txt'
basename = os.path.basename(myfile_with_path)
filename = os.path.splitext(basename)
myfile_name_without_suffix = filename[0]

Can this be done with less code?

Thanks and kind regards,
Timmie

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


Re: [Tutor] how to run a timer in window using TKINTER

2008-01-10 Thread Alan Gauld

"brindly sujith" <[EMAIL PROTECTED]> wrote

>i want to run a timer in a window
> 
> plz guide me how to do this

There is a timer facility in Tkinter for this.

In your window constructor add a call to self.after()
Add a callback function/lambda that closes the window.

> send me the Tkinter code for this
##
from Tkinter import *

tk = Tk()
L =Label(tk, text="Wait for it!")
L.pack()
L.after(5000, tk.quit  )  # quit after 5000ms

tk.mainloop()
###
Is the shortest I could think of...

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

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


Re: [Tutor] getting filen basename without extension

2008-01-10 Thread Rolando Pereira
Timmie wrote:
> Hello,
> I would like to get the name of a file without it's extension/suffix.
> 
> What is the easiest and fastes way to get the basename
> of a file wihout extension?
> 
> What I found is this:
> import os
> myfile_name_with_path = 'path/to/my/testfile.txt'
> basename = os.path.basename(myfile_with_path)
> filename = os.path.splitext(basename)
> myfile_name_without_suffix = filename[0]
> 
> Can this be done with less code?
> 
> Thanks and kind regards,
> Timmie
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

I did something like this:

import os
path = 'path/to/file.ext'
filename = path.split(".")[0].split("/")[-1]
print filename
>>> file

The only problem I see is if the file has some "." character besides the
one before the extention.

-- 
   _
ASCII ribbon campaign ( )
 - against HTML email  X
 & vCards / \
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] getting filen basename without extension

2008-01-10 Thread Alan Gauld

"Timmie" <[EMAIL PROTECTED]> wrote 

> What is the easiest and fastes way to get the basename
> of a file wihout extension?
> 
> What I found is this:
> import os
> myfile_name_with_path = 'path/to/my/testfile.txt'
> basename = os.path.basename(myfile_with_path)
> filename = os.path.splitext(basename)
> myfile_name_without_suffix = filename[0]

The last two can be easily combined as:

> myfile_name_without_suffix = os.path.splitext(basename)[0]

without much loss of clarity.
You could combine the basename call as well of course, 
but that is getting too messy for my liking.

But otherwise you are using the "correct" mechanism if 
you want a reliable result.

Alan G.

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


Re: [Tutor] getting filen basename without extension

2008-01-10 Thread Timmie
> > What I found is this:
> > import os
> > myfile_name_with_path = 'path/to/my/testfile.txt'
> > basename = os.path.basename(myfile_with_path)
> > filename = os.path.splitext(basename)
> > myfile_name_without_suffix = filename[0]
> 
> The last two can be easily combined as:
> 
> > myfile_name_without_suffix = os.path.splitext(basename)[0]
> 
> But otherwise you are using the "correct" mechanism if 
> you want a reliable result.
Thanks for this confirmation.

I am happy to have made some tiny progress in my python learings...

Kind regards,
Timmie

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


Re: [Tutor] run in "deamon" mode?

2008-01-10 Thread Reed O'Brien
On Jan 10, 2008, at 12:41 AM, Allen Fowler wrote:

> Hello,
>
> How can a make a python script run in "deamon mode"? (on a linux box)
>
> That is, I want to run the program via "python myfile.py" and have  
> it drop me back to the command line.  The program should continue  
> running until I kill it via it's PID, the machine shuts down, or  
> the program itself decides to shutdown.   It should _not_  die when  
> I simply log-out, etc.
>
> Is there a standard library module to help with this?

Something I have thrown into scripts to daemonize them. NOTE: this is  
probably not the `best` way.  but it works...

import os
import sys

def daemonize():
"""Become a daemon, seperate from the terminal and redirect IO"""
if os.fork(): os._exit(0)
os.setuid(1) # set user to  daemon
os.setsid()
sys.stdin  = sys.__stdin__  = open('/dev/null','r')
sys.stdout = sys.__stdout__ = open('/dev/null','w')
sys.stdout = sys.__stderr__ = sys.stdout


Then when you start your program in say main()

call daemonize()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Opening a window to fit an image

2008-01-10 Thread James Newton
Hi Python Pros,

I want to create a window to fit an image that I read in on the fly.
I'm using pygame to load images and to create the window.  I find I have
to use pygame.display.set_mode() twice: once to allow me to use
pygame.image.loadfile(), and once to reset the window size after I have
been able to determine the size of the loaded image.

Does this have any undesired side-effects?  Is there a better way of
doing this?

Here's the relevant extract of my script.


import os
import pygame


def main():
pygame.init()

# You must use display.set_mode() before you can use image.load
# If you don't, you get an "error: No video mode has been set"
screen = pygame.display.set_mode((1, 1))

# Now we can load an image file and find out its size
vFile  = 'image.bmp' # in same folder as script
background = pygame.image.load(vFile).convert()
vRect  = background.get_rect()

# Reset the display mode to fit the image
screen = pygame.display.set_mode((vRect[2], vRect[3]))

# Show the image in the window
screen.blit(background, (0, 0))
pygame.display.update()

# 

main()


Thanks in advance for your help,

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


[Tutor] import sys; sys.exit()

2008-01-10 Thread Andrew Volmensky


I am going through the tutorial "Simple Sequences" here: http:// 
www.freenetpages.co.uk/hp/alan.gauld/

...and get an error. I have tried saving as exit.py from the editor  
and trying to run it and also entering the commands directly into the  
shell. My understanding is that this is supposed to exit the program,  
but that does not appear to be happening.

This is with MacPython 2.4 - Thanks!

IDLE 1.1.4
 >>>  RESTART  

 >>>

Traceback (most recent call last):
   File "/Users/andrew/python/exit.py", line 2, in -toplevel-
 sys.exit( )
SystemExit


 >>> import sys
 >>> sys.exit()

Traceback (most recent call last):
   File "", line 1, in -toplevel-
 sys.exit()
SystemExit
 >>>

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


Re: [Tutor] import sys; sys.exit()

2008-01-10 Thread Alan Gauld
"Andrew Volmensky" <[EMAIL PROTECTED]> wrote

> I am going through the tutorial "Simple Sequences" here: http://
> www.freenetpages.co.uk/hp/alan.gauld/

Good choice ;-)

> ...and get an error. I have tried saving as exit.py from the editor
> and trying to run it

How are you running it?
You need to run it from the Terminal application.
If you are using an IDE environment like IDLE the tool will
catch the attempt to exit and display a warning - which
is what you appear to be seeing.

> and also entering the commands directly into the
> shell.

Again if the shell is the one you get by typing python
at the Terminal prompt it should work and exit python.
But if you are using an IDE prompt such as IDLE then
IDLE will catch the attempt to exit.

> This is with MacPython 2.4 - Thanks!
>
> IDLE 1.1.4
> >>>  RESTART
> 
> >>>
>
> Traceback (most recent call last):
>   File "/Users/andrew/python/exit.py", line 2, in -toplevel-
> sys.exit( )
> SystemExit
>
>
> >>> import sys
> >>> sys.exit()
>
> Traceback (most recent call last):
>   File "", line 1, in -toplevel-
> sys.exit()
> SystemExit
> >>>

This looks like the expected behaviour inside IDLE.

I'll add a note to that effect to the web page, thanks for
pointing it out.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


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


[Tutor] replacing CreateProcess command for Vista compatibility?

2008-01-10 Thread Kirk Vander Meulen
Hi, I'm running the program Pymol (written in python) on Windows Vista, and
in trying to run one of its plugins, I em encountering the following error:

Error: 3
WindowsError Exception in Tk callback
  Function:  at 0x027C6DF0> (type: )
  Args: ()
Traceback (innermost last):
  File "C:\Program
Files\DeLanoScientific\PyMOL/modules\Pmw\Pmw_1_2\lib\PmwBase.py", line 1747,
in __call__
return apply(self.func, args)
  File "C:\Program
Files\DeLanoScientific\PyMOL/modules\Pmw\Pmw_1_2\lib\PmwDialog.py", line
153, in 
command=lambda self=self, name=name: self._doCommand(name))
  File "C:\Program
Files\DeLanoScientific\PyMOL/modules\Pmw\Pmw_1_2\lib\PmwDialog.py", line
132, in _doCommand
return command(name)
  File "C:\Program
Files\DeLanoScientific\PyMOL/modules\pmg_tk\startup\apbs_tools.py", line
1136, in execute
good = self.generatePdb2pqrPqrFile()
  File "C:\Program
Files\DeLanoScientific\PyMOL/modules\pmg_tk\startup\apbs_tools.py", line
1683, in generatePdb2pqrPqrFile
(retval,progout) = run(self.pdb2pqr.getvalue(),args)
  File "C:\Program
Files\DeLanoScientific\PyMOL/modules\pmg_tk\startup\apbs_tools.py", line
362, in run
retcode = subprocess.call(args,stdout=output_file.fileno(),stderr=
subprocess.STDOUT)
  File "C:\Program Files\DeLanoScientific\PyMOL\py24\lib\subprocess.py",
line 413, in call
return Popen(*args, **kwargs).wait()
  File "C:\Program Files\DeLanoScientific\PyMOL\py24\lib\subprocess.py",
line 543, in __init__
errread, errwrite)
  File "C:\Program Files\DeLanoScientific\PyMOL\py24\lib\subprocess.py",
line 706, in _execute_child
startupinfo)
WindowsError: [Errno 193] %1 is not a valid Win32 application


Probably not all of that is relevant, but I thought I'd at least lay it out
there in case there's something obvious there.  In doing crazy amounts of
googling, I *think* the problem is that the python file uses a command
called "createprocess()", and, while this may work ok in XP, it does not in
Vista (something to do with how the security setup has changed).  The
software is not guaranteed fully Vista-proof, so it seems like a possible
explantion.

So I'm hoping, although not very optimistically, that I can tweak this
command and regain compatibility with Vista.  One site I found suggests
using either "ShellExecute()" or "ShellExecuteEx()" in lieu of
"createprocess()".  Would this be a simple fix- how much would I have to
change?  Here is the relevant call:

hp, ht, pid, tid = CreateProcess(executable, args,
 # no special security
 None, None,
 # must inherit handles to pass std
 # handles
 1,
 creationflags,
 env,
 cwd,
 startupinfo)

Thanks for any help,

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


Re: [Tutor] import sys; sys.exit()

2008-01-10 Thread Kent Johnson
Andrew Volmensky wrote:

> ...and get an error. I have tried saving as exit.py from the editor  
> and trying to run it and also entering the commands directly into the  
> shell. My understanding is that this is supposed to exit the program,  
> but that does not appear to be happening.

sys.exit() doesn't do what you might think - it doesn't force an exit 
from the current process. All it does is raise a SystemExit exception. 
How this is handled depends on the context - SystemExit can be caught by 
an enclosing except handler just like any other exception.

If you are running a program directly, SystemExit will probably 
propagate to the interpreter and cause the program to exit, just as any 
other uncaught exception would.

Running in IDLE or another shell, the exception is caught and logged but 
it doesn't abort the process.

Kent

> This is with MacPython 2.4 - Thanks!
> 
> IDLE 1.1.4
>  >>>  RESTART  
> 
>  >>>
> 
> Traceback (most recent call last):
>File "/Users/andrew/python/exit.py", line 2, in -toplevel-
>  sys.exit( )
> SystemExit
> 
> 
>  >>> import sys
>  >>> sys.exit()
> 
> Traceback (most recent call last):
>File "", line 1, in -toplevel-
>  sys.exit()
> SystemExit
>  >>>
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

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


Re: [Tutor] replacing CreateProcess command for Vista compatibility?

2008-01-10 Thread Tiger12506
> WindowsError: [Errno 193] %1 is not a valid Win32 application

This line says that %1 is not a valid application. Windows uses %1 to mean 
the first argument on the command line to the program. Without seeing any 
code, it would be difficult to tell where this is being introduced, but the 
explanation is that someone somewhere (it may be you, it may be the 
libraries) is putting in %1 instead of the actual filename that %1 refers 
to. 

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


Re: [Tutor] import sys; sys.exit()

2008-01-10 Thread Andrew Volmensky
Thanks Alan,

When typing the commands [statements?] in the terminal I get this:

Last login: Sat Jan  5 22:20:44 on ttyp2
Welcome to Darwin!
warewerks-01:~ andrew$ python
Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> sys.exit()
warewerks-01:~ andrew$

Does that behavior look correct? Apparently I have exit out of the  
Python interpreter; yes?


Kent - also thank you! I hope "exceptions" are covered in a following  
tutorial!

> ...and get an error. I have tried saving as exit.py from the  
> editor  and trying to run it and also entering the commands  
> directly into the  shell. My understanding is that this is supposed  
> to exit the program,  but that does not appear to be happening.
>

sys.exit() doesn't do what you might think - it doesn't force an exit  
from the current process. All it does is raise a SystemExit  
exception. How this is handled depends on the context - SystemExit  
can be caught by an enclosing except handler just like any other  
exception.

If you are running a program directly, SystemExit will probably  
propagate to the interpreter and cause the program to exit, just as  
any other uncaught exception would.

Running in IDLE or another shell, the exception is caught and logged  
but it doesn't abort the process.

Kent


On Jan 10, 2008, at 9:33 AM, Alan Gauld wrote:

> "Andrew Volmensky" <[EMAIL PROTECTED]> wrote
>
>> I am going through the tutorial "Simple Sequences" here: http://
>> www.freenetpages.co.uk/hp/alan.gauld/
>
> Good choice ;-)
>
>> ...and get an error. I have tried saving as exit.py from the editor
>> and trying to run it
>
> How are you running it?
> You need to run it from the Terminal application.
> If you are using an IDE environment like IDLE the tool will
> catch the attempt to exit and display a warning - which
> is what you appear to be seeing.
>
>> and also entering the commands directly into the
>> shell.
>
> Again if the shell is the one you get by typing python
> at the Terminal prompt it should work and exit python.
> But if you are using an IDE prompt such as IDLE then
> IDLE will catch the attempt to exit.
>
>> This is with MacPython 2.4 - Thanks!
>>
>> IDLE 1.1.4
>  RESTART
>> 
>
>>
>> Traceback (most recent call last):
>>   File "/Users/andrew/python/exit.py", line 2, in -toplevel-
>> sys.exit( )
>> SystemExit
>>
>>
> import sys
> sys.exit()
>>
>> Traceback (most recent call last):
>>   File "", line 1, in -toplevel-
>> sys.exit()
>> SystemExit
>
>
> This looks like the expected behaviour inside IDLE.
>
> I'll add a note to that effect to the web page, thanks for
> pointing it out.
>
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] import sys; sys.exit()

2008-01-10 Thread Eric Brunson
Kent Johnson wrote:
> Andrew Volmensky wrote:
>
>   
>> ...and get an error. I have tried saving as exit.py from the editor  
>> and trying to run it and also entering the commands directly into the  
>> shell. My understanding is that this is supposed to exit the program,  
>> but that does not appear to be happening.
>> 
>
> sys.exit() doesn't do what you might think - it doesn't force an exit 
> from the current process. All it does is raise a SystemExit exception. 
> How this is handled depends on the context - SystemExit can be caught by 
> an enclosing except handler just like any other exception.
>
> If you are running a program directly, SystemExit will probably 
> propagate to the interpreter and cause the program to exit, just as any 
> other uncaught exception would.
>
> Running in IDLE or another shell, the exception is caught and logged but 
> it doesn't abort the process.
>   


FWIW, and in no way contradictory to what Kent said above, I find it 
more pythonic to simply raise SystemExit.  It doesn't require an import 
and when used in a program, if you raise SystemExit() with no 
parameters, the program will exit with no error.  Raising SystemExit( 
'some error message' ) will print the error message and exit with a 
non-zero status.


> Kent
>
>   
>> This is with MacPython 2.4 - Thanks!
>>
>> IDLE 1.1.4
>>  >>>  RESTART  
>> 
>>  >>>
>>
>> Traceback (most recent call last):
>>File "/Users/andrew/python/exit.py", line 2, in -toplevel-
>>  sys.exit( )
>> SystemExit
>>
>>
>>  >>> import sys
>>  >>> sys.exit()
>>
>> Traceback (most recent call last):
>>File "", line 1, in -toplevel-
>>  sys.exit()
>> SystemExit
>>  >>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

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


Re: [Tutor] import sys; sys.exit()

2008-01-10 Thread Steve Willoughby
On Thu, Jan 10, 2008 at 01:17:20PM -0800, Andrew Volmensky wrote:
> When typing the commands [statements?] in the terminal I get this:
> 
> Last login: Sat Jan  5 22:20:44 on ttyp2
> Welcome to Darwin!
> warewerks-01:~ andrew$ python
> Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import sys
>  >>> sys.exit()
> warewerks-01:~ andrew$
> 
> Does that behavior look correct? Apparently I have exit out of the  
> Python interpreter; yes?

Yes.

In a running program, a SystemExit exception will, unless some part 
of your program is specfically watching to intercept it, terminate
your program.  In your example above, you are exiting the interpreter.

If you were in IDLE instead of a terminal window, the GUI would 
catch it and ask you if you wanted to exit IDLE or just go back
to an interactive Python interpreter prompt.

> Kent - also thank you! I hope "exceptions" are covered in a following  
> tutorial!

Exceptions are something you should have at least basic familiarity
with (as a general concept, not necessarily a lot of detail) fairly 
soon upon starting to learn Python.  At least this much:

An exception is an error event raised by some part of your program
which ran into trouble trying to carry out an operation.  Normally,
the exception is printed out with some amount of relevant information
like "Division by zero error!" or "Permission denied opening foo.txt"
and your program will exit.

An uncaught exception raised in a function will immediately terminate
that function, and if the calling function wasn't set up to catch that
exception, then it's terminated too, and so on up the levels of the
call stack until something deals with that issue or you run out of 
levels to exit and you fall out of your program completely.

If you want to have Python try to run a block of code but let you
handle any exceptions which occur, you can do this:

  try:
(insert your code here...)
  except:
(the code here is run if anything in
the "try" block failed...)

If you want to handle a specific exception only, you can do
something like in this example:

  try:
spam = int(message_qty)
  except ValueError:
spam = 0
print "Warning:", message_qty, "is not a valid-looking number"
print "proceeding with a value of 0 instead."

If the int() function raises a ValueError, the code here will 
deal gracefully with that, and carry on.  Any other exception
will still be handled normally.

There's a lot more detail, but that's the basic gist of it.

-- 
Steve Willoughby|  Using billion-dollar satellites
[EMAIL PROTECTED]   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import sys; sys.exit()

2008-01-10 Thread Alan Gauld

"Andrew Volmensky" <[EMAIL PROTECTED]> wrote

> warewerks-01:~ andrew$ python
> Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more 
> information.
> >>> import sys
> >>> sys.exit()
> warewerks-01:~ andrew$
>
> Does that behavior look correct? Apparently I have exit out of the
> Python interpreter; yes?

Yes thats absolutely correct.

> Kent - also thank you! I hope "exceptions" are covered in a 
> following
> tutorial!

Indeed they are under Error handling.

Alan G.


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


[Tutor] shutils.copytree

2008-01-10 Thread Tony Cappellini
I'm using shutils for the first time, and I've un into a problem.
The docs for copytree are pretty sparse and don't mention any problem situations

Under WinXP, I'm trying to copy a directory tree to a USB device using
copytree, but copytree doesn't like a drive letter as a destination.

copytree('C:\\testdir', 'g:\\')

OsError: Permission denied was displayed

However, when I changed the call to copytree('C:\\testdir', 'g:\\junk')

copytree worked.

Why is the root directory '\\' not a valid destination?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shutils.copytree

2008-01-10 Thread Kent Johnson
Tony Cappellini wrote:
> I'm using shutils for the first time, and I've un into a problem.
> The docs for copytree are pretty sparse and don't mention any problem 
> situations
> 
> Under WinXP, I'm trying to copy a directory tree to a USB device using
> copytree, but copytree doesn't like a drive letter as a destination.
> 
> copytree('C:\\testdir', 'g:\\')

The source for copytree says, "The destination directory must not 
already exist." I suppose that is why you have a problem but I don't 
know the specific cause. Did you get a traceback?

The source also says, "Consider this example code rather than the 
ultimate tool" so maybe you should just copy it and make a version that 
does what you want. See shutil.py in your Python lib directory.

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


Re: [Tutor] run in "deamon" mode?

2008-01-10 Thread Allen Fowler
Thank you for all the great tips... I'll try a few and see what works.

I must say that I'm a bit surprised that the Python Std library does not have a 
module for this.  Are all python scripts expected to be small user-mode 
utilities?
 




  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

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


Re: [Tutor] run in "deamon" mode?

2008-01-10 Thread Eric Brunson
Allen Fowler wrote:
> Thank you for all the great tips... I'll try a few and see what works.
>
> I must say that I'm a bit surprised that the Python Std library does not have 
> a module for this.  Are all python scripts expected to be small user-mode 
> utilities?
>   
I really agree with you on that.  I have a daemonize.py I based on an 
ActiveState recipe that I've been using for several years.  I think it 
would be a great addition to the standard library.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor