Re: [Tutor] Looking for suggestions - update

2005-11-15 Thread Kent Johnson
->Terry<- wrote:
> Thanks for the reply Kent and others. I've made some
> changes and the game is quite playable now. I've put
> the new version online at the same links if anyone
> wants to take a look.

A few more ideas:

- I think you missed my earlier suggestion about simplifying get_button().

- You have the same code in two places to initialize the board. Code 
duplication is a strong "code smell" and it's generally a good idea to 
eliminate it. In this case it would be easy to make a function to initialize 
the board and call it in two places. The function can return the new board 
which you can then assign to the state variable.

- I think the program would benefit from having a Button class. Buttons have 
several different states and behaviours which could all be bundled into a 
class. The state of a button includes its location and whether it has a peg in 
it. The behaviours of a Button are draw, add or remove a peg, and hit testing. 

If you make this change I would expect that peg_coords and state would both be 
replaced by a list of Buttons. get_button() would look like this:

def get_button(click):
  for button in buttons:
if click in button:
   return button

redraw_screen() would become

def redraw_screen():
screen.blit(board, (0, 0))  # Draw board
for button in buttons:
button.draw(screen)
pygame.display.update()
return

Kent

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


Re: [Tutor] question about serial coms

2005-11-15 Thread Python
The device at the far end of the serial connection is echoing what you
write back to you.  This is a convenience for someone typing at a
terminal, but a nuisance when you are programming.

The easier way out is to turn echoing off at the far device.  Failing
that, you will want to provide a copy of your output to the read routine
so that it can filter your output out of the data stream coming back to
you.

Unfortunately there is no reliable error detection on a serial line, so
line errors can complicate the task of matching the echoes to your
output.

On Mon, 2005-11-14 at 17:04 -0800, Bennett, Joe wrote:
> I have been working with pyserial. One question I have
> is this. I have a loop that writes to the serial port
> and then waits about 500ms and then reads from the
> serial port. The first thing read from the serial port
> is ALWAYS the data written to the serial port... I
> must be missing something obvious, but I thuoght the
> two buffers were separate...
(snipped)
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp

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


Re: [Tutor] Favourite modules - Wiki Was Re: TurboGears - and some issues

2005-11-15 Thread Ron Phillips
>>> Ismael Garrido <[EMAIL PROTECTED]> 11/14/2005 11:55 PM >>>
Kent Johnson wrote:

>Maybe we should start a thread of favorite addons. For me, Jason
Orendorff's path module is definitely #1 on the list, probably followed
by Fredrik Lundh's ElementTree.
> http://www.jorendorff.com/articles/python/path/ 
> http://effbot.org/zone/element-index.htm 
> 
>
A wonderful idea! I have created a wiki page in Python.org with a list

of such 'favourite' modules.
Please take a look:
http://wiki.python.org/moin/UsefulModules 

I put some of the modules I could remember being praised here. I hope I

didn't miss any (well, save for web frameworks, I haven't been paying 
much attention)

I hope I haven't made a mess, it was my first edit into python's wiki.
I 
wasn't sure where to stick it, so I added it under DevelopmentTools.

I hope the page helps somebody!
(Today I'm "hopey" :)

Bye,
Ismael
+++
 
That is a good idea, and a nice page. Another would be to implement
some "social tagging" as on del.icio.us. It's kind of a popularity
contest, but that's really what's wanted here, I think. OTOH, the wiki
is probably the first place anyone would look, and I saw most of the
modules I already use, and I learned about a couple that look very
promising. 
 
One that I use a lot is Amara
(http://uche.ogbuji.net/tech/4suite/amara/manual) for making xml more
pythonic. Not to take anything away from ElementTree, it's a fine
package; but I find Amara easier to use. Some others that seem
'missing': PIL and NumPy. I didn't try to put it on the wiki page
because I wanted the tutors to have a chance to comment first. 

Anyway, thanks for the page. I have it bookmarked!

Ron

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


Re: [Tutor] Do I have to initialize TKInter before I can use it?

2005-11-15 Thread Alberto Troiano
Hey Nathan
I think this is what you are looking for

Code Below
from Tkinter import *
import tkMessageBox

tkMessageBox._show("Windows Title","This is the
description",icon=tkMessageBox.INFO,type=tkMessageBox.OK)
###End of Code

Regards

Alberto

-Mensaje original-
De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] En nombre de
Nathan Pinno
Enviado el: Martes, 15 de Noviembre de 2005 00:43
Para: 'Alan Gauld'; 'Tutor Mailing List'
Asunto: Re: [Tutor] Do I have to initialize TKInter before I can use it?

Alan and all,

I imported it, but its not there. I tried using the Message one found in it,
but I got an error message:
>>> import Tkinter
>>> tk = Tkinter.Tk()
>>> Tkinter.Message("Help","Help!")

Traceback (most recent call last):
  File "", line 1, in -toplevel-
Tkinter.Message("Help","Help!")
  File "D:\Python24\lib\lib-tk\Tkinter.py", line 2640, in __init__
Widget.__init__(self, master, 'message', cnf, kw)
  File "D:\Python24\lib\lib-tk\Tkinter.py", line 1862, in __init__
BaseWidget._setup(self, master, cnf)
  File "D:\Python24\lib\lib-tk\Tkinter.py", line 1840, in _setup
self.tk = master.tk
AttributeError: 'str' object has no attribute 'tk' 

What does this mean, and how can I get it working?
Nathan

-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED] 
Sent: November 14, 2005 9:35 PM
To: Nathan Pinno; Tutor Mailing List
Subject: Re: [Tutor] Do I have to initialize TKInter before I can use it?

Nathan,

> I am having problems. The latest error message I got was:
>tkMessageBox.showinfo("Hockey",
> NameError: name 'tkMessageBox' is not defined

A NameError means Python doesn't recognise the name.
Usually that's because either you didn't declare the variable or you forgot
to import the module or you spelled it wrong.

In this case I'd guess you forgot the import?

Python error messages are really quite helpful if you just stop and think
about what they are saying for a few minutes.

Alan G
Author of the learn to program web tutor
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] tkFileDialog.Directory

2005-11-15 Thread K . Weinert
Hello!

Michael Lange <[EMAIL PROTECTED]> wrote:
> I guess the tkFileDialog.Directory class isn't intended to be used
directly.
> Try tkFileDialog.askdirectory() instead.
> If there are problems with the grab state, try passing "parent=self.top"
to askdirectory().

That did it! Thanks a lot!

I would like to ask another question. I don't understand the exception
mechanism
of Python when running a Tkinter app. If an exception happens (it does
happen quite often
at the moment..), a traceback is written to the console while the Tk window
remains open
and the application is still running. This is not what I expected -- I
expected the application
would end. Why is that?

Is there a way to create an error handler for uncaught exceptions in Tkinter
apps?
In other words, can I change the behaviour from writing a traceback to the
console to
something else? Can I, for example, show a message box instead?

Here is a small example:

--- snip ---  
import Tix

def raise_exception():
  print 1/0
  
if __name__ == '__main__':
root = Tix.Tk()
root.title("Exception demo")

Tix.Button(root, text = "Don't press", command = raise_exception).pack()

try:
  root.mainloop()
except:
  print "An error has occured."
--- snip ---

The except part gets never executed.

Kind regards,
Karsten.

-- 
Telefonieren Sie schon oder sparen Sie noch?
NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [Fwd: Re: question about serial coms]

2005-11-15 Thread Python
(Forwarding to the list.)
-- 
Lloyd Kvam
Venix Corp
--- Begin Message ---
Ya know, you're right!... Wow, I feel good about
myself now..:) What I'll do is have the fist command
be ECHO OFF and see what happens...


Sorry about the waisted bandwidth, but thank you for
bringing me back to reality... It's the simple stuff
that will get ya! :)



-Joe

--- Python <[EMAIL PROTECTED]> wrote:

> The device at the far end of the serial connection
> is echoing what you
> write back to you.  This is a convenience for
> someone typing at a
> terminal, but a nuisance when you are programming.
> 
> The easier way out is to turn echoing off at the far
> device.  Failing
> that, you will want to provide a copy of your output
> to the read routine
> so that it can filter your output out of the data
> stream coming back to
> you.
> 
> Unfortunately there is no reliable error detection
> on a serial line, so
> line errors can complicate the task of matching the
> echoes to your
> output.
> 
> On Mon, 2005-11-14 at 17:04 -0800, Bennett, Joe
> wrote:
> > I have been working with pyserial. One question I
> have
> > is this. I have a loop that writes to the serial
> port
> > and then waits about 500ms and then reads from the
> > serial port. The first thing read from the serial
> port
> > is ALWAYS the data written to the serial port... I
> > must be missing something obvious, but I thuoght
> the
> > two buffers were separate...
> (snipped)
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> -- 
> Lloyd Kvam
> Venix Corp
> 
> 
--- End Message ---
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Favourite modules - Wiki Was Re: TurboGears - and some issues

2005-11-15 Thread Ismael Garrido
Ron Phillips wrote:

>That is a good idea, and a nice page. Another would be to implement
>some "social tagging" as on del.icio.us. It's kind of a popularity
>contest, but that's really what's wanted here, I think.
>
I believe the guys at PyPI were trying to do something similar. They're 
trying to measure the "pythoness" of modules. I'm hoping this list to 
become more about helping find the favourite modules. Like, if you got 
to process XML, what's the first module that comes to your mind? 
(ElementTree or Amara, but surely not the SAX/DOM parsers that Python 
has in the Std library)

> OTOH, the wiki
>is probably the first place anyone would look, and I saw most of the
>modules I already use, and I learned about a couple that look very
>promising. 
> 
>One that I use a lot is Amara
>(http://uche.ogbuji.net/tech/4suite/amara/manual) for making xml more
>pythonic. 
>
I added it to the list. Looks very promising.

>Not to take anything away from ElementTree, it's a fine
>package; but I find Amara easier to use. Some others that seem
>'missing': PIL and NumPy.
>
Added PIL. Not sure about NumPy... How's the deal between SciPy and 
NumPy? Isn't one part of the other?

>Anyway, thanks for the page. I have it bookmarked!
>  
>
Glad you liked it :)

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


Re: [Tutor] Looking for suggestions - update

2005-11-15 Thread ->Terry<-
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1




Today (Nov 15, 2005) at 6:08am, Kent Johnson spoke these wise words:

- ->->Terry<- wrote:
- ->> Thanks for the reply Kent and others. I've made some
- ->> changes and the game is quite playable now. I've put
- ->> the new version online at the same links if anyone
- ->> wants to take a look.
- ->
- ->A few more ideas:
- ->
- ->- I think you missed my earlier suggestion about simplifying get_button().

I tried your suggestion for changing get_button() and
changed it to:

def get_button(click):  # What peg was clicked?
for i, peg in peg_coords:
if click in peg:
return i + 1
return 0

but got this error.

Traceback (most recent call last):
  File "test.py", line 120, in ?
sel1 = check_valid_start()  # Verify valid start
  File "test.py", line 40, in check_valid_start
but = get_button([x, y])# Determine which peg position 1-15
  File "test.py", line 60, in get_button
for i, peg in peg_coords:
ValueError: too many values to unpack

So I changed it back for now with plans to take a
closer look again later.

- ->- You have the same code in two places to initialize the board. Code 
duplication is a strong "code smell" and it's generally a good idea to 
eliminate it. In this case it would be easy to make a function to initialize 
the board and call it in two places. The function can return the new board 
which you can then assign to the state variable.

Agreed.

- ->- I think the program would benefit from having a Button class. Buttons 
have several different states and behaviours which could all be bundled into a 
class. The state of a button includes its location and whether it has a peg in 
it. The behaviours of a Button are draw, add or remove a peg, and hit testing. 
- ->
- ->If you make this change I would expect that peg_coords and state would both 
be replaced by a list of Buttons. get_button() would look like this:
- ->
- ->def get_button(click):
- ->  for button in buttons:
- ->if click in button:
- ->   return button
- ->
- ->redraw_screen() would become
- ->
- ->def redraw_screen():
- ->screen.blit(board, (0, 0))  # Draw board
- ->for button in buttons:
- ->button.draw(screen)
- ->pygame.display.update()
- ->return
- ->
- ->Kent

Great! Thanks again for your suggestions and the link.
Time to do more reading. There is so much to learn,
but I'm gaining more confidence as I go.

Have a good day!
- -- 
Terry


"Be who you are and say what you feel, because those
 who mind don't matter and those who matter don't mind."
 -- Dr. Seuss
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFDeht5QvSnsfFzkV0RArnoAJ9UufSi0F0kO+Nup5siQmeMK3FYKQCfbivF
0hGFSAiEeiZOZ40bV35k7dY=
=NDW8
-END PGP SIGNATURE-

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


Re: [Tutor] tkFileDialog.Directory

2005-11-15 Thread Michael Lange
On Tue, 15 Nov 2005 17:03:24 +0100 (MET)
[EMAIL PROTECTED] wrote:

> 
> I would like to ask another question. I don't understand the exception
> mechanism
> of Python when running a Tkinter app. If an exception happens (it does
> happen quite often
> at the moment..), a traceback is written to the console while the Tk window
> remains open
> and the application is still running. This is not what I expected -- I
> expected the application
> would end. Why is that?
> 
> Is there a way to create an error handler for uncaught exceptions in Tkinter
> apps?
> In other words, can I change the behaviour from writing a traceback to the
> console to
> something else? Can I, for example, show a message box instead?
> 

If you only want to see the traceback in your gui, I recommend using Pmw.
Pmw pops up a Text window that shows the complete traceback, it doesn't catch 
the exception though.

> Here is a small example:
> 
> --- snip ---  
> import Tix
> 
> def raise_exception():
>   print 1/0
>   
> if __name__ == '__main__':
> root = Tix.Tk()
> root.title("Exception demo")
> 
> Tix.Button(root, text = "Don't press", command = raise_exception).pack()
> 
> try:
>   root.mainloop()
> except:
>   print "An error has occured."
> --- snip ---
> 
> The except part gets never executed.
> 

That's because the error isn't in the mainloop() method.
Probably you meant something like

def raise_exception():
try:
print 1 / 0
except ZeroDivisionError:
print "An error has occured."
# or with a message box:
# tkMessageBox.showerror(message='ZeroDivisionError')

?

Thank god python is nice enough to raise the error where it actually happens;
imagine your example would work, you would never know *where* the error happened
nor could you create adequate handlers for different exceptions in different 
situations.


I hope this helps

Michael

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


[Tutor] Overloading comparisons

2005-11-15 Thread Hugo González Monteverde
Hi all,

I defined an object wich describes a video clip, like this

class VideoSegment:
 def __init__(self, filename):
 # Attributes that have to be present
 self.filename = filename


The thing is, I will define an array of these objects for a cache, and 
would like to keep that array having less than 1000 elements. 
Periodically I will check it, and remove the oldest element.

suppose I have the modification time as an argument.

self.time = os.stat(self.filename).st_mtime

I can define the following for sorting the array:

 def __cmp__(self, other):
 """polymorph for comparisons"""
 if self.time < other.time:
 return -1
 elif self.time > other.time:
 return 1
 else:
 return 0

But then I want to test for existance doing

if 'lala.avi' in myarray:

and that has to be done by name. Is there any way this could work? My 
current __cmp__ of course treats objects with the same timestamp as 
identical objects.

Any comments are greatly appreciates, maybe my OOP is just sloppy...

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


[Tutor] Help me

2005-11-15 Thread sivapriya pasupathi


Hi There,

I am planning to start my career in computer programming.But i don't have specific resource(websire/book) to improve my basic computer programming skills.If you know any helpful resources,please let me know.
 
Thanks in advance.
Priya.
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

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


Re: [Tutor] saving project

2005-11-15 Thread alan . gauld
>>If you do
>>
>>File... Save
>>
>>Then select the location for your file and just give it a name, a
>'.py' 
>>extension will be added to the file.

But don't do this from the interactive shell! 
You need to create a new file (File->New) first 
and type your code in there.

HTH,

Alan G

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


[Tutor] Favourite Modules - wiki

2005-11-15 Thread Matt Williams
I think the Wiki's a great idea.


del.icio.us already has a Python tagged page: http://del.icio.us/tag/python

Other pages I use are:

http://mechanicalcat.net/pyblagg.html

http://www.planetpython.org/

I've added a couple of things to the Wiki - SQLObject and RSPython

Matt

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


Re: [Tutor] Overloading comparisons

2005-11-15 Thread Hugo González Monteverde
I know it is rude to reply to myself. But I found the answer and wanted 
to share it.

I did the following test:

 >>> class Lala:
... def __eq__(self, other):
... if self.name == other.name:
... return True
...
... def __cmp__(self, other):
... if self.time < other.time:
... return -1
... elif self.time > other.time:
... return 1
... else:
... return 0
...
 >>> ins0 = Lala()
 >>> ins0.time = 11
 >>> ins0.name = 'myname'
 >>>
 >>>
 >>> ins1 = Lala()
 >>> ins1.time = 10
 >>> ins1.name = 'myname'
 >>>
 >>> ins1 == ins0
True
 >>>
 >>> ins0>> ins1>>
 >>> #See? They test correctly for greater and lesser than (time)
... #but they test equal as to time.
...
 >>> #I even tried sort, it works fine.



The thing is to use the rich comparison functions.

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


Re: [Tutor] Overloading comparisons

2005-11-15 Thread Danny Yoo


> I defined an object wich describes a video clip, like this
>
> class VideoSegment:
>  def __init__(self, filename):
>  # Attributes that have to be present
>  self.filename = filename

[some text cut]

> I can define the following for sorting the array:

[some code cut]

> But then I want to test for existance doing
>
> if 'lala.avi' in myarray:

[some text cut]


Hi Hugo,

Rather than directly use a list to hold those VideoSegments, you may want
to make a separate VideoContainer.  A quick and dirty approach would look
something like this:

#
class VideoContainer:
def __init__(self):
self.segments = []

def addSegment(self, segment):
self.segments.append(segment)
self.segments.sort()

def deleteOldest(self): ...

def __contains__(self, segmentName): ...
#

The idea is to squirrel away the sorted list in this VideoContainer, and
not expose that implementation detail directly to people.  Why do we use a
list?  Why not a hash?  Why does the list have to be sorted?

Those are implementation details that we want to hide, just in case we
have to change our mind on how to effectively hold those Segments.  As far
as the world's concerned, a VideoContainer is something that we can put
VideoSegments in, and where we can drop old segments off.

(And if your operations are limited to this, you might even use something
like the 'heapq' module if you're concerned about efficiency.  See:
http://www.python.org/doc/lib/module-heapq.html for details.)


It should be the container's responsibility to keep the segments sorted
any time we add a new segment in.  The container can also know how to
check for segments by name (with the __contains__() function.)

Trying to have VideoSegment.__cmp__() to somehow juggle both the sorting
role and the existence checking role might not be a good idea.  You're
doing two distinct things, and I think they should be two different
methods.  And from a design perspective, I think that existence-checking
method should go in a class like VideoContainer.


Best of wishes!

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


Re: [Tutor] Overloading comparisons

2005-11-15 Thread Hugo González Monteverde
Hi Danny,

That's nice. I do think I'm going this way

I don't want the container to grow too big in memory, not bigger than 1k 
elements(it is a cache), but when deleting an element I need it to be 
the oldest files (again, because it is a cache)

Thanks for the advice, I'm going this way. My OOP skills *are* sloppy...

Hugo

Danny Yoo wrote:
> 
>>I defined an object wich describes a video clip, like this
>>
>>class VideoSegment:
>> def __init__(self, filename):
>> # Attributes that have to be present
>> self.filename = filename
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me

2005-11-15 Thread Danny Yoo


On Tue, 15 Nov 2005, sivapriya pasupathi wrote:

> I am planning to start my career in computer programming.But i don't
> have specific resource(websire/book) to improve my basic computer
> programming skills.If you know any helpful resources,please let me know.

Hi Priya,

Welcome aboard!

If you're looking for Python-specific resources, have you had a chance to
look through the Python.org web site?  There should be a lot of useful
links from the Beginners Guide and the Non Programmers tutorial list:

http://wiki.python.org/moin/BeginnersGuide

http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

As far as books on paper, there's a good list here:

http://wiki.python.org/moin/IntroductoryBooks

I've used Learning Python, and from what I remember, it was a fine
tutorial.

Unfortunately, I came to Python with previous programming experience, so I
might not be the best person to point out what books are friendly to
people starting from scratch.  *grin*

Does anyone else have recommendations?

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


Re: [Tutor] Looking for suggestions - update

2005-11-15 Thread Kent Johnson
->Terry<- wrote:
> Today (Nov 15, 2005) at 6:08am, Kent Johnson spoke these wise words:
> - ->- I think you missed my earlier suggestion about simplifying get_button().
> 
> I tried your suggestion for changing get_button() and
> changed it to:
> 
> def get_button(click):  # What peg was clicked?
> for i, peg in peg_coords:
> if click in peg:
> return i + 1
> return 0

Ah, my mistake, should be
for i, peg in enumerate(peg_coords):

enumerate() is a very handy built-in, given a sequence it returns a sequence of 
pairs of (index, value) for each value in the list. Use it when you need the 
index of an item while iterating a sequence.

Kent

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


Re: [Tutor] Help me

2005-11-15 Thread Christian Wyglendowski
 > -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Danny Yoo
> 
> On Tue, 15 Nov 2005, sivapriya pasupathi wrote:
> 
> > I am planning to start my career in computer programming.But i don't
> > have specific resource(websire/book) to improve my basic computer
> > programming skills.If you know any helpful resources,please 
> let me know.
> 
> Hi Priya,
> 
> Welcome aboard!
> 

[SNIP Danny's suggestions]

> 
> Unfortunately, I came to Python with previous programming 
> experience, so I
> might not be the best person to point out what books are friendly to
> people starting from scratch.  *grin*
> 
> Does anyone else have recommendations?

Python was my first programming language (I don't count PHP).  I started
learning about 4 years ago.  

I found the standard tutorial by Guido quite helpful.  I had to read it
a few times though, as it moves quite fast for a tutorial (for a raw
beginner, at least).

I also went through "How to Think Like a Computer Scientist".  It is a
great book that is freely available online.  

Finally, the interactive interpreter is sitting there just waiting for
you to start typing stuff in.  The help() and dir() functions are
particularly helpful when playing around in the interpreter.

Python Tutorial - http://docs.python.org/tut/tut.html
How to Think Like a Computer Scientist -
http://www.ibiblio.org/obp/thinkCSpy/

-also-

The Python Cookbook - http://www.oreilly.com/catalog/pythoncook2/


Good luck and welcome to Python!

Christian

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


[Tutor] question about ord

2005-11-15 Thread nephish
Hey there,
i am using a script to change a byte into an integer
like this:
a = the byte
value = ord(a)

but i cant find the operation that can change it back to a byte.
i am sure its easy, but i am missing how to do it.

thanks for any tips

sk

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


Re: [Tutor] question about ord

2005-11-15 Thread Kent Johnson
nephish wrote:
> Hey there,
>   i am using a script to change a byte into an integer
> like this:
>   a = the byte
>   value = ord(a)
> 
> but i cant find the operation that can change it back to a byte.

chr()

See http://docs.python.org/lib/built-in-funcs.html

Kent

-- 
http://www.kentsjohnson.com

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


Re: [Tutor] question about ord

2005-11-15 Thread Liam Clarke-Hutchinson
Hmm, 

Never thought of doing it that way.

try - 

import struct

a = theByte
value = ord(a)
theByteReloaded = struct.pack("i",value)

You nmay want to check the docs for the struct module at python.org on that
pattern.


Liam Clarke-Hutchinson


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of nephish
Sent: Wednesday, 16 November 2005 9:46 a.m.
To: tutor
Subject: [Tutor] question about ord


Hey there,
i am using a script to change a byte into an integer
like this:
a = the byte
value = ord(a)

but i cant find the operation that can change it back to a byte. i am sure
its easy, but i am missing how to do it.

thanks for any tips

sk

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

A new monthly electronic newsletter covering all aspects of MED's work is now 
available.  Subscribers can choose to receive news from any or all of seven 
categories, free of charge: Growth and Innovation, Strategic Directions, Energy 
and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
http://news.business.govt.nz for more details.




http://www.govt.nz - connecting you to New Zealand central & local government 
services

Any opinions expressed in this message are not necessarily those of the 
Ministry of Economic Development. This message and any files transmitted with 
it are confidential and solely for the use of the intended recipient. If you 
are not the intended recipient or the person responsible for delivery to the 
intended recipient, be advised that you have received this message in error and 
that any use is strictly prohibited. Please contact the sender and delete the 
message and any attachment from your computer.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about ord

2005-11-15 Thread Python
chr(value)
>>> chr(ord('a')) == 'a'
True

On Tue, 2005-11-15 at 14:46 -0600, nephish wrote:
> Hey there,
>   i am using a script to change a byte into an integer
> like this:
>   a = the byte
>   value = ord(a)
> 
> but i cant find the operation that can change it back to a byte.
> i am sure its easy, but i am missing how to do it.
> 
> thanks for any tips
> 
> sk
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:  603-653-8139
fax:320-210-3409
-- 
Lloyd Kvam
Venix Corp

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


Re: [Tutor] question about ord

2005-11-15 Thread nephish
Thanks for all your help and the link,
looking at the docs right now.
slaute`
shawn


On Wed, 2005-11-16 at 10:05 +1300, Liam Clarke-Hutchinson wrote:
> Hmm, 
> 
> Never thought of doing it that way.
> 
> try - 
> 
> import struct
> 
> a = theByte
> value = ord(a)
> theByteReloaded = struct.pack("i",value)
> 
> You nmay want to check the docs for the struct module at python.org on that
> pattern.
> 
> 
> Liam Clarke-Hutchinson
> 
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
> Of nephish
> Sent: Wednesday, 16 November 2005 9:46 a.m.
> To: tutor
> Subject: [Tutor] question about ord
> 
> 
> Hey there,
>   i am using a script to change a byte into an integer
> like this:
>   a = the byte
>   value = ord(a)
> 
> but i cant find the operation that can change it back to a byte. i am sure
> its easy, but i am missing how to do it.
> 
> thanks for any tips
> 
> sk
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> A new monthly electronic newsletter covering all aspects of MED's work is now 
> available.  Subscribers can choose to receive news from any or all of seven 
> categories, free of charge: Growth and Innovation, Strategic Directions, 
> Energy and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
> http://news.business.govt.nz for more details.
> 
> 
> 
> 
> http://www.govt.nz - connecting you to New Zealand central & local government 
> services
> 
> Any opinions expressed in this message are not necessarily those of the 
> Ministry of Economic Development. This message and any files transmitted with 
> it are confidential and solely for the use of the intended recipient. If you 
> are not the intended recipient or the person responsible for delivery to the 
> intended recipient, be advised that you have received this message in error 
> and that any use is strictly prohibited. Please contact the sender and delete 
> the message and any attachment from your computer.

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


[Tutor] Creating Tkinter Menubars

2005-11-15 Thread Double Six
Hi,

I am testing the following Tkinter code (attached at the end of
this message) by Fredrik Lundh on a Mac OS X 10.4.2 with Python
version 2.3. I do get a root window, but it is totally blank
without the desirable menubars such as File and Edit. What am I
missing?

Any help will be highly appreciated.

Thanks,
Joe

=

from Tkinter import *

class AppUI(Frame):

def __init__(self, master=None):
Frame.__init__(self, master, relief=SUNKEN, bd=2)

self.menubar = Menu(self)

menu = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="File", menu=menu)
menu.add_command(label="New")

menu = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Edit", menu=menu)
menu.add_command(label="Cut")
menu.add_command(label="Copy")
menu.add_command(label="Paste")

try:
self.master.config(menu=self.menubar)
except AttributeError:
# master is a toplevel window (Python 1.4/Tkinter
1.63)
self.master.tk.call(master, "config", "-menu",
self.menubar)

self.canvas = Canvas(self, bg="white", width=400,
height=400,
 bd=0, highlightthickness=0)
self.canvas.pack()


root = Tk()

app = AppUI(root)
app.pack()

root.mainloop()




Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me

2005-11-15 Thread Adam
On 15/11/05, sivapriya pasupathi <[EMAIL PROTECTED]> wrote:


Hi There,

I am planning to start my career in computer programming.But i
don't have specific resource(websire/book) to improve my basic computer
programming skills.If you know any helpful resources,please let me know.
 
Thanks in advance.
Priya.
I'd suggest Alan Gauld's tutorial as well, python was pretty much my
first language (I don't count VB) and his tutorial really helped. http://www.freenetpages.co.uk/hp/alan.gauld/

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


[Tutor] RTSP

2005-11-15 Thread Ismael Garrido
Hi

Does anyone know if there's any module able to download rtsp?
Failing that, any command line app that could do the job? (Already tried 
with mplayer, it didn't work)

I'm trying to download a series of streams automatically, I have already 
been able to open the page, parse all the links, and get to the rtsp:// 
address. But couldn't find any way to download them.

Any suggestions greatly appreciated.

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


Re: [Tutor] Do I have to initialize TKInter before I can use it?

2005-11-15 Thread Nathan Pinno
Albertito and all,

It worked! Thanks again! 

Thanks for all the help!
Nathan Pinno,
Owner/operator of The Web Surfer's Store.
http://www.the-web-surfers-store.com/
MSN Messenger: [EMAIL PROTECTED]
Yahoo! Messenger: spam_swatter31
AIM: f3mighty
ICQ: 199020705  

-Original Message-
From: Alberto Troiano [mailto:[EMAIL PROTECTED] 
Sent: November 15, 2005 8:51 AM
To: 'Nathan Pinno'; 'Alan Gauld'; 'Tutor Mailing List'
Subject: RE: [Tutor] Do I have to initialize TKInter before I can use it?

Hey Nathan
I think this is what you are looking for

Code Below
from Tkinter import *
import tkMessageBox

tkMessageBox._show("Windows Title","This is the
description",icon=tkMessageBox.INFO,type=tkMessageBox.OK)
###End of Code

Regards

Alberto

-Mensaje original-
De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] En nombre de
Nathan Pinno Enviado el: Martes, 15 de Noviembre de 2005 00:43
Para: 'Alan Gauld'; 'Tutor Mailing List'
Asunto: Re: [Tutor] Do I have to initialize TKInter before I can use it?

Alan and all,

I imported it, but its not there. I tried using the Message one found in it,
but I got an error message:
>>> import Tkinter
>>> tk = Tkinter.Tk()
>>> Tkinter.Message("Help","Help!")

Traceback (most recent call last):
  File "", line 1, in -toplevel-
Tkinter.Message("Help","Help!")
  File "D:\Python24\lib\lib-tk\Tkinter.py", line 2640, in __init__
Widget.__init__(self, master, 'message', cnf, kw)
  File "D:\Python24\lib\lib-tk\Tkinter.py", line 1862, in __init__
BaseWidget._setup(self, master, cnf)
  File "D:\Python24\lib\lib-tk\Tkinter.py", line 1840, in _setup
self.tk = master.tk
AttributeError: 'str' object has no attribute 'tk' 

What does this mean, and how can I get it working?
Nathan

-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED]
Sent: November 14, 2005 9:35 PM
To: Nathan Pinno; Tutor Mailing List
Subject: Re: [Tutor] Do I have to initialize TKInter before I can use it?

Nathan,

> I am having problems. The latest error message I got was:
>tkMessageBox.showinfo("Hockey",
> NameError: name 'tkMessageBox' is not defined

A NameError means Python doesn't recognise the name.
Usually that's because either you didn't declare the variable or you forgot
to import the module or you spelled it wrong.

In this case I'd guess you forgot the import?

Python error messages are really quite helpful if you just stop and think
about what they are saying for a few minutes.

Alan G
Author of the learn to program web tutor
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] RTSP

2005-11-15 Thread Kent Johnson
Ismael Garrido wrote:
> Hi
> 
> Does anyone know if there's any module able to download rtsp?
> Failing that, any command line app that could do the job? (Already tried 
> with mplayer, it didn't work)
> 
> I'm trying to download a series of streams automatically, I have already 
> been able to open the page, parse all the links, and get to the rtsp:// 
> address. But couldn't find any way to download them.

Maybe something in the Python RTSP Proxy can help:
http://www.onegoodidea.com/

Kent

-- 
http://www.kentsjohnson.com

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


Re: [Tutor] Favourite modules - Wiki Was Re: TurboGears - and some issues

2005-11-15 Thread Christopher Arndt
Ron Phillips schrieb:
> A wonderful idea! I have created a wiki page in Python.org with a list
> 
> of such 'favourite' modules.
> Please take a look:
> http://wiki.python.org/moin/UsefulModules 

Good idea! The GUI section might be problematic, though. I don't see that any
of the main GUI alternatives (GTK,Qt,wxWindows,Tk,PythonCard,...) can claim a
definite prefernce among the Python crowd and they are all more or less
Pythonic (except maybe Tk). Probably better just to link to some other
comprehensive list there.

Maybe a section on Template engines (Cheetah)?

And somewhere docutils belongs on that list, but i don't know where. Maybe
source code documentation? But then you'd probably have to list epydoc, gendoc,
etc. as well.

Fact is, that there are a lot of domains, where a clear favourite or "standard"
module has not emerged yet. E.g. audio, configuration file handling, HTML form
generation/validation, postgres database access, and so on...

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


Re: [Tutor] new topic draft

2005-11-15 Thread Christopher Arndt
Alan Gauld schrieb:
> I've just added an incomplete draft copy of my latest tutorial topic
> on using the Operating System from Python. The material that's 
> there discusses the role of the OS and looks at file handling
> usng os/os.path/shutil etc.
> 
> http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm

"Most computer users know that their computer has an operating system [...]"

I doubt that. Maybe you should say "Experienced computer users..." ;-)


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


Re: [Tutor] Favourite modules - Wiki Was Re: TurboGears - and some issues

2005-11-15 Thread Kent Johnson
Christopher Arndt wrote:
> Good idea! The GUI section might be problematic, though. I don't see that any
> of the main GUI alternatives (GTK,Qt,wxWindows,Tk,PythonCard,...) can claim a
> definite prefernce among the Python crowd and they are all more or less
> Pythonic (except maybe Tk). Probably better just to link to some other
> comprehensive list there.
> 
> Maybe a section on Template engines (Cheetah)?
> 
> And somewhere docutils belongs on that list, but i don't know where. Maybe
> source code documentation? But then you'd probably have to list epydoc, 
> gendoc,
> etc. as well.

I think this page will be more useful as a list of favorites or things that 
beginners might want to take a look at than as an encyclopedic list - there are 
other places to list all the template engines, all the GUI toolkits, etc.

Kent
-- 
http://www.kentsjohnson.com

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