Re: [Tutor] Pygame

2009-07-23 Thread Albert Sweigart
Hi, I'm Al, the author of Invent Your Own Computer Games with Python.
The book does indeed cover Pygame. The last four chapters covers the
Pygame library, and the final one has the source code for a complete
game.

I still recommend learning Python first though, it will make it much
easier to understand the code. The book can do this for you and is
freely available at http://pythonbook.coffeeghost.net

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


Re: [Tutor] R?p. : Sorting Data in Databases

2009-11-23 Thread Albert Sweigart
Ken,

You should probably use the sorting functionality that your DBMS
provides. However, if you have a list of strings that end with a new
line and start with an apostrophe, you can use list comprehensions to
remove them:

newlist = [x[1:-1] for x in newlist]

You can look at the following links to find out more about list
comprehensions here:

http://www.secnetix.de/olli/Python/list_comprehensions.hawk
http://www.network-theory.co.uk/docs/pytut/ListComprehensions.html

-Al
You should check out my free beginner's Python book here:
http://inventwithpython.com


> Actually, I was fooling around with that today by adding to the list
> from the file and then sort.  I was using the following simplify method:
>
> newlist = []
>
> newlist = [
>    456, 54, 8, 158, 878
>    ]
> (above data read from file)
>
> newlist.sort()
>
> print newlist
> [8, 54, 158,  456, 878]
>
> (still working adding to new file]
>
> The actual sorted list has, as I recall, an apostrophe at the beginning
> and an \n at the end of every number I had.  I will be working on that.
>
> Thanks for your suggestion.
>
> Ken
> -- next part --
> An HTML attachment was scrubbed...
> URL: 
> 
>
> --
>
> ___
> Tutor maillist  -  tu...@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 69, Issue 105
> **
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difficulty with csv files - line breaks

2009-11-24 Thread Albert Sweigart
Tim,

I've checked your code and it seems to work as far as using newlines
for the line terminator. The default line terminator is \r\n, which
might not show up correctly in some text editors.

Otherwise, try checking to see if you've specified a blank line for
the line terminator. You can set it explicitly when you create your
csv.writer:

writer = csv.writer(text_file, quoting=csv.QUOTE_NONNUMERIC,
lineterminator='\r\n')


-Al
You should check out my free beginner's Python book here:
http://inventwithpython.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When max() doesn't work as expected

2009-12-03 Thread Albert Sweigart
max() for strings returns the largest string in an alphabetical sense.
So max(['z', 'aa']) would return 'z'.

You need to specify an ordering function, in your case, len():

max( ['z', ''], key=len)

...which will return '' because it is ordering by key.


-Al Sweigart


You should check out my free book for Python beginners, "Invent Your
Own Computer Games with Python"
http://inventwithpython.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What books do you recommend?

2009-12-09 Thread Albert Sweigart
I'd recommend Doug Hellman's Python Module of the Week blog (PyMOTW)
at http://www.doughellmann.com/projects/PyMOTW/

He goes into each of the standard library modules and gives examples
of them in use.

Dive Into Python 3 by Mark Pilgrim is also good for getting up to
speed on Python 3. http://diveintopython3.org/

And I recommend my book, "Invent Your Own Computer Games with Python"
which is freely available at http://inventwithpython.com
It doesn't go into the standard library modules, but it does have
several complete programs that are easy to read and understand. The
book is aimed at complete beginners and young adults (but is not
"kidsy").

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


Re: [Tutor] Append mode dilemma

2009-12-09 Thread Albert Sweigart
Your problem is on this line:

fobj.write('\n'.join(all))

This puts a newline in between each line in "all", but not at the end.
The fix is simple:

fobj.write('\n'.join(all) + '\n')

This will make sure that the last line has a newline at the end of it,
so that when you later append data, it will appear on a fresh line.

-Al Sweigart
You should check out my free beginner's Python book, "Invent Your Own
Computer Games with Python"
http://inventwithpython.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learn Python

2009-12-12 Thread Albert Sweigart
I'd recommend my book, "Invent Your Own Computer Games with Python",
which is available for free at:

http://inventwithpython.com

Each chapter focuses on the complete source code for a small game, and
teaches programming concepts from the code.

-Al

> Hi
> I'm trying to learn python but I have difficulties with classes.
> If someone has a code that shows the basic concepts and relationships in
> the classes, please send it to me.
> I will be happy if code possess very much comments
> --
> Grigor Kolev 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor