Re: [Tutor] use the data None

2012-06-03 Thread Corey Richardson
On Sun, 3 Jun 2012 23:43:30 +0200
Tehn Yit Chin   wrote:

> Hi all,
> 
> I am trying to understand when it is appropriate to use None as in the
> following example
> 
> if abc != None:
>   print "abc is not None"
> 

The proper idiom, for a variety of reasons, is:

if abc is not None:
# do stuff

> 1) Can I use it to determine if the variable abc exists?
>

No. It will raise a NameError, which you would have to catch. To do
what you want, something along the lines of:

try:
abc
# it exists
except NameError:
# it doesn't

However, this is pretty dirty. Why are you using variables that
potentially don't exist?

> 2) Can I use it to determine if the variable abc does not contain
> anything?
> 

For a generic foo,

if foo not in abc:
# it's not there, Jim

Does this answer your questions?

(I've been away from Python for a bit, one of the other tutors might
correct me with better practice things, I'm rusty!)

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


Re: [Tutor] Connecting to MySQLdb

2012-06-01 Thread Corey Richardson
On Fri, 1 Jun 2012 19:01:00 -0400
Nicholas Picciano   wrote:

> Hello,
> 
> I have downloaded MySQLdb 1.2.3 from:
> 
> http://pypi.python.org/pypi/MySQL-python
> 
> Also, I'm using Python 2.7, but I can't even get past here:
> 
> >>> import MySQLdb
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named MySQLdb
> 
> Thanks

Did you install it? 

Assuming UNIX(-like):

I highly, *highly* recommend you use a virtualenv [1] and, if you want
a fancy UI, virtualenvwrapper [2]. From there you can install all the
packages you want with pip, without having to worry about mucking up
the system, versions of things, etc.

Assuming Windows:

Good luck!

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


Re: [Tutor] iPython check if user running script is root user (Linux)

2012-05-31 Thread Corey Richardson
On Thu, 31 May 2012 18:21:22 -0400
Dave   wrote:

> Hi. What is the right way to have an iPython script check to see if
> the user is currently root?
> 
> Here's how I do it in bash scripts:
> 
> 
> ## CHECK USERNAME PRIVILEGE
> 
> 
> if [ $(id -u) != "0" ];then
>echo "This script must be run as root."
>exit 1
> fi

import os
if os.environ['USER'] != 'root':
print('This script must be run as root.')
exit(1)


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


Re: [Tutor] Break Help

2012-05-29 Thread Corey Richardson
On Tue, 29 May 2012 17:50:37 -0700 (PDT)
PhantomsCore  
wrote:

> 
> if gameIsDone:
> if playAgain():
> missedLetters = ''
> correctLetters = ''
> gameIsDone = False
> secretWord = getRandomWord(words)
> else:
>   break
> 
> That is my coding. When I try to run it I get "Break outside loop"
> 

Because (surprise!) you are using break outside of a loop. Break is
only valid to break out of a for or while loop, and no where else. What
do you want to do with that program? Quit if playAgain() returns false?
Just leave out the else entirely, and if gameIsDone is False, it will
continue outside of that block.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] About the Mailing List

2011-07-28 Thread Corey Richardson
Excerpts from Steven D'Aprano's message of Fri Jul 29 01:32:36 -0400 2011:
> Jordan wrote:
> > How do I see what in the mailing list has already been responded too,
> > before it sends me the digest? For instance I wanted to respond to one
> > of the questions, but seeing that the time was almost two hours ago. I
> > am sure someone has already responded. Where could I check to see if
> > this is true? I assume the mailing list are posted some wheres on-line.
> > But I can only find the sign up page. Thanks in advance for the link.
> 
> Digest mode is a pain in the backside for people wanting to reply, and 
> an even bigger pain for those who read the replies to digests. Please 
> consider doing yourself, and everyone else, a favour by switching to 
> individual emails.
> 

I'll add on to that and say find the threading feature of your user
agent -- or switch to one that has said feature. I know recent thunderbird's
do it, if that's the sort of thing you're into. Thread view makes
things bucketloads easier.
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln


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


Re: [Tutor] Question related to Tkinker

2011-07-24 Thread Corey Richardson
Excerpts from Emeka's message of Sun Jul 24 02:56:02 -0400 2011:
> Hello All,
> 
> I am putting up a simple game .. the game is about manipulation. If the gets
> through level one ... I have to change the word with another...
> 
> Am I going to destroy level window and build level 2 or is there a way to
> just adjust the word (I used labels)
> 

When working with tkinter, http://effbot.org/tkinterbook/ will likely be your
best friend. Specifically, you're going to want 

your_label1.config(text="New word!")
your_label2.config(text="Another!")
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln


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


Re: [Tutor] Python editor for Ipad

2011-07-21 Thread Corey Richardson
Excerpts from bob gailer's message of Thu Jul 21 17:21:01 -0400 2011:
> On 7/21/2011 12:30 PM, Corey Richardson wrote:
> > If you have a browser, Cloud9 IDE might be able to do it.
> I just tried Cloud9 and gave up in frustration.
> 
> Unintuitive interfacre. No help. Finally edited a program. Tried to run 
> it. No results. Sigh.
> 
> Also appears to be a free TRIAL only.
> 

It says "Free for open source" on the homepage. I agree that the interface
is not intuitive. You cannot run any programs, to my knowledge, but I don't
hold that against them (I don't want my browser to become an operating 
environment/system, any more than I want my emacs to be one). It's certainly
not enough to replace my own setup but maybe someone likes this sort of
thing. It's also in Beta, I'd be willing to be that more stuff will happen
to it.
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln


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


Re: [Tutor] Python editor for Ipad

2011-07-21 Thread Corey Richardson
Excerpts from ian douglas's message of Thu Jul 21 16:44:17 -0400 2011:
> Yes, Cloud9 supports running/debugging/testing. They've also got github 
> support for pulling in your projects. It's a pretty clever tool.
> 

Could you share your secret? I didn't dig enough to figure it out. I saw the
"Run" button and its configuration, but it looks like it wants a JS file and
args? Or...maybe not?
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln


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


Re: [Tutor] Python editor for Ipad

2011-07-21 Thread Corey Richardson
Excerpts from Tahir Hafiz's message of Thu Jul 21 16:24:22 -0400 2011:
> Cloud9 seems interesting as a browser based IDE. Do you know if there is a
> way to run Python code as well create/edit it?
> 

Not as far as I know.
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln


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


Re: [Tutor] Python editor for Ipad

2011-07-21 Thread Corey Richardson
Excerpts from James Reynolds's message of Thu Jul 21 10:40:53 -0400 2011:
> I might have to discuss some routines I've written in Python (and possibly
> C). It would be easier to whip out the Ipad and show them some of the things
> I've done, rather than a bulky laptop.
> 
> I could of course PDF everything with highlighting off of eclipse, but
> ideally Ideally I would prefer a way for the user to interact with the text,
> rather than an image.
> 
> So basically, an IDE or text editor with syntax highlighting for python.
> 
> If you have any thoughts, I would greatly appreciate it!

If you have a browser, Cloud9 IDE might be able to do it. Or you could use
pygments to render the text to HTML and ... do you even have filesystem
access on an ipad? (This is assuming you don't want your code out public
for the whole world to see). So your best bet would probably be Cloud9 or 
a similar product. 
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln


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


Re: [Tutor] problem reading script

2011-07-01 Thread Corey Richardson
Excerpts from Alan Gauld's message of Fri Jul 01 13:03:40 -0400 2011:
> 
> "Lisi"  wrote
> 
> > Suggestions for "a programmers font" gratefully received.  
> 
> I generally use Courier.
> 
> Its ugly and old fashioned but it clearly shows 
> the differences between i,l, | and 1 and '' and " 
> and between ' and ` etc.
> 

I use and love inconsolata[0], it's a great font for programming,
and looks great as well (both on screen and off).

[0] - http://www.levien.com/type/myfonts/inconsolata.html
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need script help with concept

2011-06-17 Thread Corey Richardson

"Noah Hall"  wrote


Of course, if you mean *completely in-place replace* the question,
then you
will need something like ncurses (if on Linux)  -
http://docs.python.org/library/curses.html


There also exists urwid, which is multiplatform, and is also less 
painful to use. I hear

there is a port for Python 3 somewhere too. http://excess.org/urwid/
(Apologies if email is HTML, using a web client)

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


Re: [Tutor] Building games

2011-06-11 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 06/11/2011 12:32 PM, Wolf Halton wrote:
> I think pygame would let you do a simple graphical game.
> 

pygame can do plenty of complex graphics too.

FWIW, you might have a better time using something like PySFML(2) or
pyglet (I like pyglet much more than pygame, seems more pythonic) which
wrap OpenGL instead of SDL, allowing for more stuff. Not to mention if
you ever need a GUI there are a ton for OpenGL (even Qt, if you wanted).
Of course, it's up to the OP.

On 06/11/2011 07:34 AM, Tommy Bell wrote:
> Now, regarding the title, building games, i need to be able to place 
> buildings, like squares that is placed with the mouse and can be 
> clicked and these kind of things.
> 

In pygame/pyglet you'd want to be capturing mouse-click events and then
acting on the location of the click, seeing if it's in the area of the
square, etc.. Game programming is rather event-driven, similar to GUI
programming.

> Can anyone recommend places to go or books to read? the books i've 
> found so far are mostly about 2d-games like asteroids or something 
> similar. Not quite what I was hoping, and pygame.org has alot of good
> sources, but outside of simply taking apart an existing game and
> looking at how they did it, are there any ressources to help me 
> learn?

The docs for pygame and pyglet are great, use them. Of course, reading
the source of existing games is a great way to see how things are done,
and is always a good learning experience.

Cheers,
- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)

iQEcBAEBAgAGBQJN85uFAAoJEAFAbo/KNFvpaNoIAI0OeY7lnqdTR4AsdOdwZK0k
HrZ5xuEaXVyO6UArYvVynoB6cZF+hNGiYmIiv2IO/aYLCjU0WWAvSLfLGD4zgWFR
NnHdZvJ7SwfR4In4cYo2A6tkhNwHJpk2zSTgXqT07zDFvgCmyGGpTSjkHR6nWPdH
jowbVm4i34K3ToPbIH1bl36+NG3OW5CynNRiOgz8bibjAtS+UrwvUFTojN3dsQ4O
9YfJ9OIXP0HMUQ71Gv4nBQFWKu6Q0qhXgTpF6JFtu9wbYiJWKj5oWNHyEdYm70Za
zKeepAe9uNR2KZslQ6oB+AO2V2F2WoOoEARP6pBWmKg9lPNYCEt95HEYfe4a4MY=
=ZH7D
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Lists

2011-06-10 Thread Corey Richardson
On 06/10/2011 03:12 PM, Piotr Kamiński wrote:
> Could you please refrain from presenting your *religious* convictions
> in this list: the notions you believe in as well as the ones that you
> believe are false?
> 
> This is a *technical* list, as I understand it, solely dedicated to
> the technical side of teaching the *Python* programming language and 
> *programming* in general. I would like to keep it this way and I
> believe there are many persons or at least a number of people
> constituting a minority (or, likely, a silent majority) sharing my
> views in this respect.
> 
> What is more, I am profoundly convinced that there are many other
> mailing lists and/or sites on the Internet, specifically dedicated to
> debating various religious, worldview and philosophical issues.
> 

You should have stopped here. Or, even better, just not written at all.
It's the internet, does someone else's world religious really matter so
much that you write a lengthy response to the whole list (which should
be focused on python, as you mentioned)?

> ---
> 
> [...]
> 
> That is my outlook on religious and ideological matters. I have
> wanted it to be known, so I have mentioned it *once* (Steven provoked
> my response). I do not intend to remind you repeatedly how I despise
> the genocidal totalitarian Left (e.g. that starved to death *5 - 6
> million people* in Ukraine in 1932 - 1933 (
> http://en.wikipedia.org/wiki/Holodomor )) or pseudo liberal leftist
> denominations. If I ever feel a need for that, I can easily find a
> dedicated Internet forum and express my views in this thematic scope.
> I am quite sure nobody needs my repeated ideological propaganda *in
> this mailing list*; let me know if I am wrong...
> 

A wise man once said,

> Could you please refrain from presenting your *religious* convictions
> in this list: the notions you believe in as well as the ones that you
> believe are false?

Could be applied to government too.
-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax for Simplest Way to Execute One Python Program Over 1000's of Datasets

2011-06-09 Thread Corey Richardson
On 06/09/2011 03:49 PM, B G wrote:
> I'm trying to analyze thousands of different cancer datasets and run the
> same python program on them.  I use Windows XP, Python 2.7 and the IDLE
> interpreter.  I already have the input files in a directory and I want to
> learn the syntax for the quickest way to execute the program over all these
> datasets.
> 
> As an example,for the sample python program below, I don't want to have to
> go into the python program each time and change filename and countfile.  A
> computer could do this much quicker than I ever could.  Thanks in advance!
> 

I think os.listdir() would be better for you than os.walk(), as Walter
suggested, but if you have a directory tree, walk is better. Your file
code could be simplified a lot by using context managers, which for a
file looks like this:

with open(filename, mode) as f:
f.write("Stuff!")

f will automatically be closed and everything.

Now for some code review!

> 
> import string
> 
> filename = 'draft1.txt'
> countfile = 'draft1_output.txt'
> 
> def add_word(counts, word):
> if counts.has_key(word):
> counts[word] += 1
> else:
> counts[word] = 1
> 

See the notes on this later.

> def get_word(item):
> word = ''
> item = item.strip(string.digits)
> item = item.lstrip(string.punctuation)
> item = item.rstrip(string.punctuation)
> word = item.lower()
> return word

This whole function could be simplified to:

return item.strip(string.digits + string.punctuation).lower()

Note that foo.strip(bar) == foo.lstrip(bar).rstrip(bar)

> 
> 
> def count_words(text):
> text = ' '.join(text.split('--')) #replace '--' with a space

How about

text = text.replace('--', ' ')

> items = text.split() #leaves in leading and trailing punctuation,
>  #'--' not recognised by split() as a word separator

Or, items = text.split('--')

You can specify the split string! You should read the docs on string
methods:
http://docs.python.org/library/stdtypes.html#string-methods

> counts = {}
> for item in items:
> word = get_word(item)
> if not word == '':

That should be 'if word:', which just checks if it evaluates to True.
Since the only string that evaluate to False is '', it makes the code
shorter and more readable.

> add_word(counts, word)
> return counts

A better way would be using a DefaultDict, like so:

from collections import defaultdict
[...]

def count_words(text):
counts = defaultdict(int) # Every key starts off at 0!
items = text.split('--')
for item in items:
word = get_word(item)
if word:
counts[word] += 1
return counts


Besides that things have a default value, a defaultdict is the same as
any other dict. We pass 'int' as a parameter because defaultdict uses
the parameter as a function for the default value. It works out because
int() == 0.

> 
> infile = open(filename, 'r')
> text = infile.read()
> infile.close()

This could be:

text = open(filename).read()

When you're opening a file as 'r', the mode is optional!

> 
> counts = count_words(text)
> 
> outfile = open(countfile, 'w')
> outfile.write("%-18s%s\n" %("Word", "Count"))
> outfile.write("===\n")

It may just be me, but I think

outfile.write(('=' * 23) + '\n')

looks better.

> 
> counts_list = counts.items()
> counts_list.sort()
> for word in counts_list:
> outfile.write("%-18s%d\n" %(word[0], word[1]))
> 
> outfile.close

Parenthesis are important! outfile.close is a method object,
outfile.close() is a method call. Context managers make this easy,
because you don't have to manually close things.

Hope it helped,
-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects C++ vs Python

2011-06-09 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 06/09/2011 07:03 AM, Ashwini Oruganti wrote:
> On Thu, Jun 9, 2011 at 3:32 PM, Walter Prins  wrote:
> 
>> Object Oriented code in e.g. a procedural language like C, which obviously
>> doesn't support the notion of objects explicitly in the language, although
>> then it's up to you to come up with conventions and infrastructure to
>> support the concept of object orientation in your program.
> 
> 
> 
> Didn't know that!  It's interesting that  GObject is itself written in C,
> which is a procedural laguage..
> 

(The Python interpreter you're probably using is written in C too)
Well, anything object-oriented will get executed on a processor, which
is procedural, and stored in RAM, which is essentially just a giant
array of numbers. It should come with no surprise that OO can be and is
written in a procedural language.


An object is just data+behaviour, take this snippet of C:

struct address_book_entry {
  char *name;
  char *address;
  char *extra;
};

void
printPerson(struct address_book_entry d) {
  /* d is a pointer so we could modify it */
  printf("%s, age %d\n", d.name, d.age);
  printf("Address: %s", d.address);
}


Encapsulate that, and you have yourself an object. OO isn't hard to do,
even (single!) inheritance isn't too great of a challenge. It's getting
things dynamic instead of static that's the biggest challenge.

- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)

iQEcBAEBAgAGBQJN8SAiAAoJEAFAbo/KNFvpi/oIAJfSwifBQzilopoZTS3gEggT
4ekhhW1ao8XOcmgEBSrCLL5rWwQeYDGF1USkdeSQSpUfqEb6g7ua3HuhvOimRGKs
KQx7t5jhI3AvWKE/mXslXD4nCq+vRf0q4AvGngnnAByEeQfbeZPg3huLeo6/SzXn
QLHAbKKhcHWAXwmbhx4EbTkTEgyQocVNkjYj8z9bMxRcW0IMcj+ePDsPs0IQUALO
D2T4xwjb7QwDC1OgQoGbMwTEGWup2ULxAOpMpFVwgyz2BgY7rm1PkQ2NTJuYSGIE
TYhQ4HtyevMfORjPyfvq/JJG+QYBXseucAev4PizQkCgxuA++6JF7/VHJDXJPVw=
=LXLl
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python "glue"

2011-06-05 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 06/05/2011 06:25 AM, Benjamin Gregg wrote:
> Hi I recently bought a book (python programing for the absolute beginner)
> and it said python was a "glue" language (could work with other languages)
> I've been trying to make apps for android and webOS and I was wondering
> if I could use python for doing this through "glueing" to program games 
> on android and webOS can anyone help?


If you're on the android your options are limited. Indeed Python can
work with other languages, but not all of them and not easily. The
standard Python implementation, CPython, can really only glue together C
or C++ stuff. Jython can do Java, and IronPython can work with anything
that is using the .NET CLI.

On the 'droid your best bet would probably be
http://code.google.com/p/android-scripting/, but it's still very *very*
limited.

For webOS it looks like the only way you'll get Python is if you whip
together a C(++) program that statically links to it.

- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)

iQEcBAEBAgAGBQJN67V8AAoJEAFAbo/KNFvpv/MH/088lDJQqNlOHk/vKrzTjafQ
Mn0ybNrk3sKozkL5GE/UdX+ESTxmAnYUnDBM2VFNEV/FjBxyDTLfLAGEzBNs2u4t
LHvClprfW00xexm6wcOLMQHmR+peaPC5MGRIZgesP63istqkSNryxFAAlzRG9WW8
mJS8+r9BkQiSSDSdXDv2Jlk3/pNIwvMpp9Pwob9+O7IW4emSfqi1MtsTlkG9TnEv
HI3YQuDCSVQWyWZpUup7wSqlyUMr3LY5TiOXal4SFNLIh8Tw30p9uSB7s10VBntv
SURLH0pqTM7qWb7VKLCTRNwM5cda2pooXo/CPs/CdrG4mbWvyOiqpisihYrZQ5g=
=plrm
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Non programmer wanting to become programmer

2011-05-26 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 05/26/2011 03:36 PM, amt wrote:
> First of all, hello!  I want to start learning programming. I'm looking into
> becoming more than a hobbyist programmer. I searched a lot on Google on what
> programming language should I learn first and I see a lot of good words
> about Python so I decided to go for it but have some questions:
> 
> 1)What book should I start with?  ( I have checked Python for non
> programmers but there are a lot of titles there, what should I pick first?I
> was thinking about Invent your own computer games with Python.)
> 

I used Alan Gauld's tutor when I was first learning to program, it's at:
http://www.alan-g.me.uk/tutor/index.htm

Many of the other books listed on that wiki are great too, I've heard
good things about Python the Hard Way and How to think like a Computer
Scientist.

> 
> 2)Version 2 or version 3? What should I go for as a beginner and why? ( I
> ask because some books in the Python for non programmers section are for
> python 2, Invent your own computer games with Python is version 3.)
> 

For now, I'd say 2. It has more libraries available, and you won't be
missing much. Once you know python using the other version should take
you about 30ish minutes to figure out.
See http://wiki.python.org/moin/Python2orPython3
> 
> 3)Algorithms, memory management, data structures, when is the right time to
> learn them?
> 

Python does memory management for you, so you don't need to worry about
that. As for data structures, there's not much complex that you need to
know about that in python either, unless you are doing more advanced
things (like graphs!) Algorithms are good to learn too, but don't worry
about them right away.

For things like this I would recommend getting very familiar with
Python, and then picking up a bit of C.

- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)

iQEcBAEBAgAGBQJN3rF9AAoJEAFAbo/KNFvp0nYH/jUAx53mZD/jmKw5YbGbKXFq
lkSW/nWSftAle7oKtuBDOMjpK32/K/bYWXfPkJrrZicqt57mbT6xyeIFQmbplwrf
jpjEpNtbI/jSjrm9Na4mjuzRUIkJRUk4PgTT1Mk376eQKWfZo5OejWRiSF+BgMfH
6SSOkB/h+cWLDnAJ/mH46iLrxfrcM4ArPydEK/zxcm/JMSIgixG3RvbyF3l4y3Nr
ZV8yzKXeHedQpRns3a3/zUX4YsZ8izrMD2NQz0zDfXKpBhtjiSKXVi1/OUnYs+zY
TtwBbVCwFbFcHNenXNeXfK7cCqlw8HP3Xj87QmoXAj8X/OfRBV7AtZNtXqIQJe4=
=8uJL
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Program

2011-05-18 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 05/18/2011 09:05 AM, Johnson Tran wrote:
> Thanks for the reply.
> 
> So to append a word is it suppose to look kind of like:
> 
> word=raw_input("Name #1: ")
> word.append(words)
> 
> I keep getting error message:
> 
> Traceback (most recent call last):
>   File "/Users/JT/Desktop/pythonfinal", line 23, in 
> CollectNames()
>   File "/Users/JT/Desktop/pythonfinal", line 7, in CollectNames
> word.append(words)
> AttributeError: 'str' object has no attribute 'append'

Yes, because append belongs to list, and not str!
http://docs.python.org/tutorial/datastructures.html#more-on-lists

words = [
word = raw_input("Name #1: ")
words.append(word)

Keep in mind the rest of the email I sent, that part was one of the
least important (albeit fundamental).
- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)

iQEcBAEBAgAGBQJN08YBAAoJEAFAbo/KNFvpuSwH/jTqUncnANaRmlkJ3Mgd9C6k
QeGEduLfnxT5d0m6DIil7k9q8UKBgrrOE8MKbfanp0f/QIWFn7g4M8WAoNASUF26
Bb0sHuzCjAoEL3Gbf2nOejhBlAPCos4ReveDAysiSwJ4pe8hOQOzxQ73apNq8v1W
U8x0/X0JL5J6Cw/g4mEWd/Be2rYiQdL0xchpRB+9m6ATCTfo99g5VDR4kuB8T0Mi
wbfq/jEQZbKCWInwCHuD7n7438zUJad4MvNPPlBnrQDb76MzN4sU4ZXnKjRvYdsN
Z/fJKy40MWUtD/6Lw8fHhIVdtWFo0k6xM3bUjcPIYfRdHXHvX8NwEwyw3704YAY=
=SYly
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Program

2011-05-18 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 05/18/2011 08:26 AM, Johnson Tran wrote:
> Hi Again All,
> 
> I had a couple questions about my program:
> 
> def CollectNames():
> 
> answer_set=set([])
> sorted_list = sorted(answer_set)
> word=raw_input("Name #1: ")
> 
> word=raw_input("Name #2: ")
> 
> word=raw_input("Name #3: ")
> 
> word=raw_input("Name #4: ")
> 
> word=raw_input("Name #5: ") 
> 
> print "Your answer's sorted: ", ','.join(sorted_list)
> 
> CollectNames()
> 
> 
> 1.) how do i add each answer given to the list so it is printed at the end?

Well, you can't have ALL the answers printed at the end, but one way is
to use a list and .append(word) each time.

> 2.) also im trying to modify the program so if the user puts in the same 
> name, it will give an make them try again until they have 5 completely 
> different names.

Now, you might see a pattern in your prompt. Each time you ask for
input, you increment the name number. Perhaps this is the prime place
for a loop? If you add in a loop, it will also be fairly easy to add in
another loop to make sure they enter a name not in the list. So, your
pseudo-code might look something like this:

for i in range(6):
make prompt string;
get name;
while name in names_gotten:
get name;
add name to names_gotten;
print names_gotten;

(P.S., PEP 8 says functions should be lowercase_with_underscore,
not CamelCase)
- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJN074TAAoJEAFAbo/KNFvpdHwIAK1Ji+4Z3Fac0wtH2EgBDwp2
K8t10KpbtRYfWOCjiYfBAzZFWLrQ9I+lrmdth7Asf0ANg72U4gPHkp82ZbO8mhyz
02eDBPXboAmLcntxsxcmMkNlG1xPVeXjcriGwX/VcN2AguGKvrKkKbkkT+Ar+bWZ
ZpjH0ycNsAUTNeQLQEHJQJtPMktJ13XvlrjHN0YVoLpk812rAn+nuTZq+p0J5fzc
hCgyxUiRcHYllXZv/1AegOWbfon3BMur9fpV2UMo8JcsRTHto3Lb5c3jHqApNjfc
M48rpigGXjOzowj0WbsMmSHrskBglcSAy+xo/Ti0vnBXDMU3secWFWkaxDtdidk=
=oCrn
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Filtering out unique list elements

2011-05-03 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 05/03/2011 06:20 PM, Spyros Charonis wrote:
> [cat, dog, cat, cat, cat, dog, dog, tree, tree, tree, bird, bird, woods,
> woods]
> 
> I am wondering how to truncate this list so that I only print out the unique
> elements, i.e. the same list but with one occurrence per element:
> 
> [cat, dog, tree, bird, woods]
> 
> Any help much appreciated!

The set type enforces uniqueness:
http://docs.python.org/library/stdtypes.html#set

You would use list(set(l)) to get the list from l where everything is
unique.
- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNwITbAAoJEAFAbo/KNFvp9FYH/RMM0lqzBCoC5L3W4xIk6jNF
gU1vs3phP/EaD/l2kil/FjRrO6nNuV91415GeSfVFKo3FXZsq0LnEaOz1b4sZCdk
vmdFdONBugMixuuS8Iid3zB1hNmporc5kU2ze423MvxaDmPR0MGYYsZQ3LzFZDKK
eVFTQcdvP4Tw3o21jXBcoaVHbW+GFgmxzFzsp90CgU7Dgt9o0i4YEn2IYOMETNdC
6o/EgWL7oPiWnq0os6pzo9PbhbJ9VU38ICCW/KQkk1xqrXUtXU+RHZqktWSp8kEv
AQ7FqlYamOc0wZin/SSasGo7TOzVX3MFkW/rr/d8ZormCXs2tabDUcBw1XBKzok=
=UcP6
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ValueError

2011-05-03 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 05/03/2011 06:30 AM, Johnson Tran wrote:
> Hi All, 
> 
> i am trying to create a program module with two functions (conversion inches 
> to centimeters then centimeter to inches, I have my program working although 
> I am trying to adda Value Error function to my program but cannot seem to it 
> to work:
> 
> 
> def Conversion():
> print "This program converts the first value from inches to centimeters 
> and second value centimeters to inches."
> print "(1 inch = 2.54 centimeters)"
> inches = input("Enter length in inches: ")
> centimeters = 2.54 * inches
> print "That is", centimeters, "centimeters."
> 
> centimeters = input("Enter length in centimeters: ")
> inch = centimeters / 2.54
> print "That is", inch, "inches."
> 
> except ValueError:
> print "Invalid digit, please try again."
> 
> Conversion()
> 
> 
> 
> Any advice would be great, thanks!
> 
> JT

Well, you need a 'try' block before that except. Example:

try:
foo = int("blargh")
except ValueError:
pass

It looks like you're forgetting an important operation on the inches
variable, as well as centimeters later on.

Take a look at
http://docs.python.org/library/stdtypes.html#typesnumeric

For future questions, it's best to include what your program /is/ doing
that you think it shouldn't be, as well as any errors (tracebacks, copy
the whole thing!) you get.

- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNv+BHAAoJEAFAbo/KNFvpCdwH/0DRxVjevNxZy2HtYuxykzlA
x2ni1VnDMyS2YCsHvqIaglfK2hBeL+nstGL8kmEhGu4t5Z85nqGt9Ea2spPhPDxE
UJJ1O2nYFtLUZ1BC03vkC8aHI0aiijZjg7v7adKW4sD2laGTaeryLLR1qbGh3ZBP
rKTWK/NuyyMDRYjnP0gXsiYYNPc6E6WsbBTYWxGcMPwLnlvgmmXJBOLC6qj07eXu
X/fd5FwKSRJPMYIGT47zsnFdZdrN1SOOM537XH8CX+xQPTg/J8NeaiqoaWjTKLMn
PpXizt1AbuV1/0/Zqp6VKgTA/sxYtMfc4mFWjfovHlxJ/ahA19DaQjeWneIjldk=
=LkuV
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Compound if statement question.

2011-05-01 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 05/01/2011 02:28 PM, Greg Christian wrote:
> Is there a way to write an if statement that will pick up duplicates (two 
> ‘1’s):
> 
> L = ['1', '4', '1']
> if (L[0]) != (L[1]) != (L[2]):
> print "THEY ARE NOT EQUAL"
> else:
> print "THEY ARE EQUAL"
> 
> When I run this code, it prints “THEY ARE NOT EQUAL” when it should print the 
> else “THEY ARE EQUAL”.
> 

Well, think about what that if-statement is doing. It's making sure that
the first three elements of L aren't equal to each other. Due to
python's short-circuit evaluation, it breaks the if after the first one,
because '1' != '4'. The parentheses there are useless.

You might look at [1] to see if there is anything that will count how
many times something appears in a list...

[1] -- http://docs.python.org/tutorial/datastructures.html#more-on-lists

- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNvav2AAoJEAFAbo/KNFvpx/IH/iT54cNeVSSJsRQit13Hf91H
y6zy9Cx3pE9Pxf+crK+9tT53C67TxQIdLRcD83fuXF1iEZJYwVlgQv5Py7U7KIy2
X0SU9ScL4xy/b3k8QB+kj7w7wt4Aa0yPhAx6mZI0KXErj6hVjeIljQf6E3irY7K1
Uot5TY5vY6YieKX+Sc/C2Kv3nmPCM2x1TcuwzX+zIGFBNEuGDb1jNdTR8LkVG+nb
WqBPEtO5sEy9/5NULtExSgS80xUT/fLCRc6gpf5yQBIi/xm+lOBTx1hUCgYfrsLp
gCKOIrXtPaI1bYdxf2tApDUWXVAe5U7tB9z4s9Uz9bV3x8od2w5gsCmxLLJgLHs=
=Sz54
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] GUI IDLE for UBUNTU 10

2011-04-06 Thread Corey Richardson
On 04/06/2011 05:34 AM, Ratna Banjara wrote:
> Before this i used to run in windows with python IDLE which makes easy to
> write python codes and run using Run command or pressing F5.
> 
> Now i want to ask if there is python GUI IDLE equivalent in Ubuntu. Please
> help.

At the terminal, sudo apt-get install idle.

When you need software, search in Synaptic (Package Manager) or google
first, it's usually very accessible!
-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] String formatting question.

2011-03-29 Thread Corey Richardson
On 03/29/2011 03:41 PM, Prasad, Ramit wrote:
> Is there a difference (or preference) between using the following?
> "%s %d" % (var,num)
> VERSUS
> "{0} {1}".format(var,num)
> 
> 
> Ramit

If you're using Python 3, use the second one. If you're using Python 2,
you have no option but to use the first, as far as I know. Maybe Python
2.7 has that formatting, I'm not sure.

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


Re: [Tutor] Replying

2011-03-28 Thread Corey Richardson
On 03/28/2011 06:17 PM, Steven D'Aprano wrote:
> Corey Richardson wrote:
> 
>> Thunderbird has a "reply list" button that I use.
> 
> It does? What version are you using?

3.1.8

I don't know how it knows what a mailing list is and isn't, but it does.

After inspecting the headers of emails from a few different lists, it
appears: List-Id, Lust-Unsubscribe, List-Archive, List-Post, List-Help,
and List-Subscribe may be helping thunderbird along.
Also common among them is a "Precedence: list" header.

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


Re: [Tutor] Replying

2011-03-28 Thread Corey Richardson
On 03/28/2011 01:04 PM, markri...@gsoftcon.com wrote:
> When replying to the mailing list, does everyone just hit the reply button in 
> your email program. Because that sends the email directly to your email. Also 
> everyone is cc'ng the mailing list; is that the exceptable way to reply so 
> everyone in the list gets the replies?
> 

Thunderbird has a "reply list" button that I use.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what is it mean--- File "", line 1

2011-03-20 Thread Corey Richardson

Hi,

 I just write a simplest file test.py with only one line--print 
"hello", when I run it in command line:

python test.py


the follow message comes out:

File "" , line 1
 python test

SyntaxError: invalid syntax

but, the file can run in shell, also in the command line, I put


print "hello"


output is fine, "Hello"

thanks
Sharon

-
---

You're trying to run the file from the Python interpreter.
It does work in the shell, because that's what the shell does!
So, exit out of the Python interpreter before trying to run that command
(>>>exit, or Ctrl-D).

--
Corey Richardson
(Forgive the horrible formatting and HTML, on the road using a web 
client)



 
___

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


Re: [Tutor] Difference

2011-03-20 Thread Corey Richardson


-Original Message-
From: ANKUR AGGARWAL 
To: tutor 
Sent: Sun, Mar 20, 2011 1:49 pm
Subject: [Tutor] Difference


Hey
want to know whats the difference between the pygame.display.update() 
and pygame.display.flip()

An explanation with the example would be grea.
Thanks In Advance
Ankur Aggarwal

--
http://www.pygame.org/docs/ref/display.html#pygame.display.flip

Read that and the section below. In the future, pygame questions will 
be better

off answered by their mailing list or similar communication structure.

(Forgive for the poor formatting etc, on the road using a web client)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Efficiency of while versus (x)range

2011-03-16 Thread Corey Richardson
On 03/16/2011 08:32 PM, Shane O'Connor wrote:
> Hi,
> 
> First-time poster here. I've a question about loop efficiency - I was
> wondering whether this code:
> 
> i = 0
> while i < 1000:
> do something
> i+=1
> 
> is more efficient than:
> 
> for i in range(1000):
> do something
> 
> or:
> 
> for i in xrange(1000):
> do something
> 
> In my mind, the while loop should not allocate as much memory as range or
> have the overhead of the iterator of xrange (although aesthetically, I
> prefer the x/range style). Is this the case or does the compiler do
> something clever here?
> 

Only way to know is to check!
http://docs.python.org/library/timeit.html

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


Re: [Tutor] how to compress a folder in python

2011-03-16 Thread Corey Richardson

On 03/16/2011 09:15 AM, bhavanasi sarath wrote:
i want to learn how to compress a folder which is having some text 
filesbut compress that from another directory..




http://docs.python.org/library/zipfile.html
(Sorry for the HTML email, getting things set up on new workstation)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] multiple if and or statement

2011-03-14 Thread Corey Richardson
On 03/14/2011 03:41 PM, Mike Franon wrote:
> HI,
> 
> I had a question, when running this small snippet of test code:
> 
> 
> 
> a = ['test1', 'flag', 'monday']
> 
> for i in a:
> if i == 'test1' or 'test2':

if i == 'test1' or i == 'test2'

>print 'true'
> I know I am missing something, but in reality it should only print
> true once correct?

You are missing something. Before, you're simply testing the existence
of 'test2'. And since 'test2' is an immediate value (so to speak), it
always exists.

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


[Tutor] Homework Problem Flaming (was: Help!)

2011-03-03 Thread Corey Richardson
On 03/03/2011 04:58 PM, James Reynolds wrote:
> You are almost assuredly going to get flamed for not having a descriptive
> title and for asking what is obviously homework questions
> 

Maybe for not having a descriptive title, but there's nothing wrong with
coming to the list with homework!

The requirements are that you've put some work into it, you show your
code, you say what is should be doing that it isn't, and that you
explain what you've tried doing previously. At least, those are what I
look for. Even better that he said right up front that it was homework.

With homework problems, instead of saying "Hey, replace lines 42-48 with
foo", saying "Look into the bar module, it bazifies the proper value for
you". Teaching people to learn better for themselves instead of
hand-feeding them the answers. This list does a really good job with it,
IMO.


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


Re: [Tutor] Timer with exe command

2011-02-28 Thread Corey Richardson
On 02/28/2011 03:30 PM, Corey Richardson wrote:
> On 02/27/2011 10:02 PM, Kaden McLaws wrote:
>> I would like to set up the following using python: A timer that is activated 
>> when a user logs on to our computer, then shuts the computer down when the 
>> timer runs out (no matter what, ending all programs). First, a raw input is 
>> used, so that if you know the password, you may shut off the timer (set for 
>> 90 mins). Otherwise, it is activated. This is a timer to be used so 
>> (anonymous) can only spend 90 mins playing Modern Warfare, and not hours 
>> upon end like he does. I was also wondering about parsing. It would be 
>> effective if the last time the timer activated was recorded in a txt file, 
>> logged, so that the program can check and ensure that the last time the 
>> timer ended was at least 12 hours ago, so the computer just isnt turned 
>> right back on for another 90 mins repeatedly.Is there also a way to run the 
>> python hidden in the background so he cannot just figure out how to close 
>> it?If you aren't sure off all the details, email me back. Thanks for helping 
>> me save (anonymous) from 
w
> asting too much time on MW2! :)
> 
> [...]
> 
> Should be everything you need.
> 

Oh, and

http://docs.python.org/library/subprocess.html

I partially disagree with Wayne, it is certainly doable, and isn't too
too hard, but it will certainly take some doing without any Python
knowledge, so do take the time to learn.

I suggest http://www.alan-g.me.uk/l2p/
-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timer with exe command

2011-02-28 Thread Corey Richardson
On 02/27/2011 10:02 PM, Kaden McLaws wrote:
> I would like to set up the following using python: A timer that is activated 
> when a user logs on to our computer, then shuts the computer down when the 
> timer runs out (no matter what, ending all programs). First, a raw input is 
> used, so that if you know the password, you may shut off the timer (set for 
> 90 mins). Otherwise, it is activated. This is a timer to be used so 
> (anonymous) can only spend 90 mins playing Modern Warfare, and not hours upon 
> end like he does. I was also wondering about parsing. It would be effective 
> if the last time the timer activated was recorded in a txt file, logged, so 
> that the program can check and ensure that the last time the timer ended was 
> at least 12 hours ago, so the computer just isnt turned right back on for 
> another 90 mins repeatedly.Is there also a way to run the python hidden in 
> the background so he cannot just figure out how to close it?If you aren't 
> sure off all the details, email me back. Thanks for helping me save 
> (anonymous) from w
asting too much time on MW2! :)

http://docs.python.org/library/time.html#time.sleep
http://www.microsoft.com/windowsxp/using/helpandsupport/learnmore/ballew_commandline.mspx
(See "Shut Down the System")
http://docs.python.org/whatsnew/2.2.html?highlight=pyw (scroll down)
http://www.tutorial5.com/content/view/157/47/
http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files

Should be everything you need.

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


Re: [Tutor] Generator expressions...

2011-02-27 Thread Corey Richardson
On 02/27/2011 04:34 PM, Modulok wrote:
> 
> import hashlib
> 
> fd = open('/dev/urandom', 'rb')
> gen = (hashlib.sha256(i).hexdigest() for i in fd.read(4096))
> 

I think the problem is that you're only reading 4096 bits (bytes? No
idea), and iterating through that. I could be wrong.

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


Re: [Tutor] python module to search a website

2011-02-26 Thread Corey Richardson
On 02/26/2011 10:11 PM, vineeth wrote:
> Hello all,
> 
> I am looking forward for a python module to search a website and extract 
> the url.

What website, what is it searching for, and what URL is it looking for?

> 
> For example I found a module for Amazon with the name "amazonproduct", 
> the api does the job of extracting the data based on the query it even 
> parses the url data. I am looking some more similar query search python 
> module for other websites like Amazon.

The only module I found for amazon-product was a python interface to
Amazon's advertising API. What data does it extract, what query, and
which URL does it parse? From what I found that module uses the API to
search the website, a service provided by Amazon and not something
Python is doing itself.

You may want to look into urlparse and urllib2, for parsing URLs and
opening websites respectively.

http://docs.python.org/library/urlparse.html
http://docs.python.org/library/urllib2.html

If that isn't what you're looking for, you'll need to be a bit more
descriptive.

If you are going to be parsing the HTML and then searching for specific
elements you might look into BeautifulSoup.

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Corey Richardson
On 02/26/2011 04:32 PM, Justin Bonnell wrote:
> --My current working directory is not what I have been trying to cd to, so 
> I'm assuming that I am using the cd command wrong. 
> 
> I have tried:
> 
> $ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido
> $ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido/hello.py
> $ cd /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
> 

Alas, you still do it wrong. You don't just replace the space with a
backslash, you put a slash _before_ the space. Or like Steven (I think
it was) suggested, put it in quotes.



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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Corey Richardson
On 02/26/2011 04:10 PM, Justin Bonnell wrote:

> --This is the location of the file:
> 
>   /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
> 
> but it still says it cannot find the directory when I try to run it or cd to 
> it. Is there any way that I can tell which directory the shell is currently 
> working from?

At the terminal, the command "pwd" , print working directory, should do
the trick.

If you cannot cd to the directory, that's generally a pretty big hint
that the directory doesn't exist ;-)

But yet you can see it in your file browser? That's most curious.

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Corey Richardson
On 02/26/2011 06:05 AM, Walter Prins wrote:
> I'd be tempted to say you should not be worrying about such performance
> issues at this stage.  

Indeed, but I can't have every piece of variable information being saved
to disk and then read back again every time a player leaves or enters a
room, that'd just be silly!

Playing MUD's for a bit it gets annoying on a medium-size server when
you have to wait more than 3 seconds just to get how much health you
have after attacking some baddie. I won't be trying to pull every
microsecond of efficiency out of this, but I would like it to be
sensible and now waste time dawdling.

(And the full quote is "We should forget about *small* efficiencies, say
about 97% of the time: premature optimization is the root of all evil."
(emphasis added))

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Corey Richardson
On 02/26/2011 06:02 AM, Walter Prins wrote:
> On 26 February 2011 05:33, Corey Richardson  wrote:
> 
>> Aha, that explains why I didn't get any results. Each file got its own
>> interpreter instance.
>>
> 
> Not wanting to nit pick, but no: It's not that each *file* does has its own
> interpreter instance, it's that every python instance that you start does
> not automatically persist anything that gets created while it lives. In
> other words, you can import many modules (files) into any given interpreter
> instance, but whether or not the stuff gets persisted anywhere is a seperate
> matter.
> 
> Walter
> 

I ran them like this:
python use1.py
python use2.py
python plib.py

Each file got its own instance of the interpreter.

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


Re: [Tutor] Cross-Module Interaction

2011-02-25 Thread Corey Richardson
On 02/26/2011 12:11 AM, Steven D'Aprano wrote:
> [steve@sylar ~]$ python
> Python 2.5 (r25:51908, Nov  6 2007, 16:54:01)
> [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import lib
>  >>> import a
>  >>> lib.g
> []
>  >>> a.do_stuff()
>  >>> lib.g
> [42]
> 
> 
> Of course, when your application exists (or in this case, the 
> interactive session), the changes to lib.g will be lost because they 
> only exist in memory. If you want data to persist across application 
> runs, you need to arrange for the application to save the data to disk, 
> and then read it again when it starts up.

Aha, that explains why I didn't get any results. Each file got its own
interpreter instance.

> 
> Python has many tools for working with persistent data: Windows-style 
> ini files (module config parser), XML, JSON, Mac-style plists, YAML 
> (third-party module only), and pickles, to name only a few.

In any case everything would be called in one interpreter, which I
didn't know worked because I didn't test it like you showed it, but to
be safe I definitely need to persist that data every once in a while.

I'm slightly concerned about performance when it comes to
reading/writing to disk a lot when doing things like that, since if this
thing ever needs to scale I want it to be able to do that.

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


[Tutor] Cross-Module Interaction

2011-02-25 Thread Corey Richardson
Greetings, Tutors

(Sorry for the poor subject name, couldn't think of anything better)

I'm writing a MUD server as part of a school project. Yes this is
homework, but I'm not taking a traditional programming class (going
through the OCW for CS50 at Harvard and getting credit).

I'm in the design phase and am testing out a few things. One thing I
will definitely need is a global players_online collection which will
act much like the name implies.

My first thought was to have a module specifically for holding things
like that, global objects that all the interacting modules need access
to. I did a simple test with a lib module, and then a few modules that
simply added things to a list called g in that lib module, but the
changes did not persist (tested with another module that printed the
contents of lib.g)

I'm probably thinking about this from the wrong direction. Is there
something about this approach that I'm missing, or is there a different
way I should be using?

(If you're curious about the telephone data-transfer I was working on, I
ran into too much trouble with the various sound libraries that exist to
wrap over Alsa or JACK, so I put it off for the future after I'm more
comfortable with C/C++)
-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] scripts search

2011-02-25 Thread Corey Richardson
On 02/25/2011 03:20 PM, Victor Binns wrote:
> 
> Hello I am fairly new to python.
>  
> I have a small business and I wanted to use python in my business.  I have a 
> need for an 
> Employee Time and Attendance software.
>  
> Is there any python scripts out there that can do the trick?
>  

I don't know of any and a google didn't return favorable results. You'll
have to write it yourself. Luckily, Python is one of the more simple
languages and you should have a fairly easy time writing it.

Check out http://www.alan-g.me.uk/tutor/index.htm if you haven't
programmed before, and if you have, try this:
http://docs.python.org/tutorial/

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


Re: [Tutor] Running Existing Python

2011-02-25 Thread Corey Richardson
On 02/25/2011 06:42 PM, Justin Bonnell wrote:
> I downloaded Python 2.7.1. I think this is a pretty basic question.
> When I try to run the existing python files on the computer (hello.py), I 
> receive a syntax error. 
> 
> Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) 
> [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
> Type "copyright", "credits" or "license()" for more information.
>>>> python hello.py
> SyntaxError: invalid syntax
> 
> I am running Mac OS X version 10.6.6.
> Shouldn't I be able to run hello.py from the IDLE interpreter?

You need to run "python hello.py" in a terminal window, not from the
Python interpreter. If you are using IDLE, you can File > Open hello.py
and hit F5 to run it... I don't know if that advice applies to Mac,
might be different key strokes.

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


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Corey Richardson
On 02/25/2011 04:49 AM, Steven D'Aprano wrote:
> Alan Gauld wrote:
> 
>> Anything you can do locally you can do on the remote
>> machine with a combination of ssh, rsh, rlogin, telnet etc.
> 
> I'd like to remove a CD from the CD drive, and replace it with a 
> different disk.
> 
> 
> Being difficult just for the sake of it-ly y'rs,

And at that point, the all-encompassing "etc." steps in ;-)


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


Re: [Tutor] comparing strings

2011-02-25 Thread Corey Richardson
On 02/25/2011 02:53 AM, Edward Martinez wrote:
>  Thanks for the reply. i now understand that python uses either 
> ASCll or Unicode to compare and to do other things

1. Those are i's, not l's.
2. The first 128 characters of Unicode are the same as the only 128
characters of unicode.

Check out http://qcpages.qc.cuny.edu/~nixon/links/asciiUnicode.html

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


Re: [Tutor] Dictionnaries in object

2011-02-24 Thread Corey Richardson
On 02/24/2011 01:58 PM, Christopher Brookes wrote:
> Hi,
> 
> I want to create some powers in my fight program.
> I want to know if dictionnaries is the best solution to do it.
> 
> For now its look like this :
> 
> 
> //French name and description, don't care about it ;)
> 
> power1= {}
> power1['Name'] = 'Flammes infernales'
> power1['Description'] = 'Embrase lenemi et le feu bruler'
> 
> power2= {}
> power2['Name'] = 'Froid devorant'
> power2['Description'] = 'Gele lenemi sur place'
> 
> powerAll= [power1,power2]
> 
> but if i want to create like 20 powers, it will be long no ? is there any
> solution shorter (and better ?)
> 
> Thank you for reading,

powerAll = {"Flammes infernales": "Embrase lenemi et le feu bruler",
"Froid devorant": "Gele lenemi sur place"}

Have it implicit that the key is the name and the value is the
description. That's how I would do it, at least.

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


Re: [Tutor] comparing strings

2011-02-23 Thread Corey Richardson
On 02/23/2011 10:22 PM, Edward Martinez wrote:
> Hi,
> 
> I'm new to the list and programming.
> i have a question, why when i evaluate strings ie 'a' > '3' it reports 
> true,  how does python come up with  that?

Welcome! As far as I know, it compares the value of the ord()'s.

>>>ord('a')
97
>>>ord('3')
51

This is their number in the ASCII system. You can also do this:

>>>chr(97)
'a'
>>>chr(51)
'3'

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


Re: [Tutor] how to connect to Django's irc

2011-02-20 Thread Corey Richardson
On 02/20/2011 01:03 PM, shaheryar ali wrote:
> hi guys,
> 
> does anyone know how to connect to the Django's irc,
> As django is based on python there asking from you guys,
> 
> 
> thanks
> 

Point your favorite client at irc.freenode.net or use
http://webchat.freenode.net/. #django

You'll have better luck with django-specific questions on the django
mailing list.

-- 
Corey Richardson

I've never known any trouble which an hour's
reading didn't assuage.
-Charles De Secondat
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Having Troubles with For Loops

2011-02-19 Thread Corey Richardson
On 02/19/2011 01:06 PM, jyatesster wrote:
> I am refreshing my memory of Python programming after taking a class this
> past fall. I am using the book, *Python Programming for the absolute
> beginner*. I am at chapter 4, challenge 4 which instructs me to create a
> program that picks a random word and the player has to guess the word. The
> computer tells the player how mnay letters are in the word. Then the player
> gets five chances to ask if a letter is in the word. The computer can only
> respond with "yes" or "no." Then, the player must guess the word.
> 
> Here is what I have so far. I think I am doing something wrong with the for
> loops as the program is not reading whether the letter is in the constant
> and giving the appropriate response.
>  [snip]

You're going about it wrong. You should look into the len() function.
For example:

print("This word has %d letters" % (len(word)) )
for i in range(5):
letter = input("Guess a letter: ")
if letter.lower() in word.lower():
print("Yes")
else:
print("No")

Your for loops in the end don't do what you think they do.

for letter in XYLOPHONES: # Loops through XYLOPHONES
if letter.lower() not in XYLOPHONES: # Always will return false,
print("No")# because you are looping through the word itself
# etc.

You are also mixing Python 3's print() with Python 2's raw_input(), so
it's hard to tell which you are using. I'm assuming Python 2 because you
didn't report the raw_input() failing. If that's the case, you don't
need the ()'s around the text you are printing.

I also suggest you look into lists and list indexing. You should go
through the Python Tutorial [0] if you haven't before.

[0] - http://docs.python.org/tutorial/
-- 
Corey Richardson

I've never known any trouble which an hour's
reading didn't assuage.
-Charles De Secondat
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Backpropagation Learning in Python

2011-02-13 Thread Corey Richardson
On 02/13/2011 03:54 AM, Jaidev Deshpande wrote:
> Dear All
> 
> Please suggest a link to tutorials for backpropagation and other neural
> network training algorithms through Python.
> 
> Any other commentary is welcome, as I am new to both Python and Neural
> Networks.
> 
>


http://lmgtfy.com/?q=neural+networking+in+python
http://lmgtfy.com/?q=backpropagation+in+python


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


Re: [Tutor] Python + Sound

2011-02-11 Thread Corey Richardson
On 02/12/2011 02:27 AM, Steven D'Aprano wrote:
> Corey Richardson wrote:
>> Hello Tutors,
>>
>> I'm working on a small script that compresses a file, sends it through
>> the telephone, and then receives and decompresses the file on the other
>> end. The compression is the easy part. The transmission is the hard
>> part. If anyone has worked with sound before, what do you recommend?
> 
> [snip of excellent help and advice]
> 
> http://en.wikipedia.org/wiki/TCP/IP_model
> http://www.howstuffworks.com/modem.htm
> http://en.wikipedia.org/wiki/Modem
> 
> and this may entertain, and help:
> http://www.joelonsoftware.com/articles/LeakyAbstractions.html
> 

Always been a fan of Joel's articles.

> 
> Of course this can be done -- otherwise we wouldn't have the Internet!
> But my guess is that doing this in pure Python will be so slow it will
> be almost faster for you to copy the file onto a USB stick and
> hand-deliver it to the other end. But if you insist...

Well, I'm still on my way to learning other languages, Java (which I
hate) and soon I begin my voyage onwards into C. I figure once I get
something working in a tool I know how to use well, I'll be able to get
it done in a tool that I /don't/ know as well.

> 
> * Your compressed file is a bunch of bytes. You need to come up with
>   a scheme for encoding that to sound. This needs to be reversible
>   and designed to work on low-fidelity systems (phone networks).
>   The obvious way is to have one tone represent a one-bit, and another
>   *very different* tone represent a two-bit. See also "frequency
>   modulation" and "amplitude modulation".
> 
> * Because of noise on the line, you need a scheme for error correction.
>   Google for "Error correcting codes" for more information.
> 
> * The sender and receiver need a way to notify each other that they
>   are ready to start transmitting data. This is called a handshake.
>   Otherwise, you risk losing data from the ends of the transmission.
> 
> You described this as "a small script" -- it might be so far, but by the
> time you finish it will be huge.
> 
>> I don't really want to use the wave module because it looks like too
>> much work.
> 
> Pardon me while I chortle :)

Merely one aspect of a larger whole that I expected to be much more
complex - I didn't want to spend all my time working on sound encoding.
I think I have much more realistic view on it now.

Thank you _so much_ for the help. I truly appreciate it, you've given me
much more perspective, and I'll need to consider carefully my next
steps. Probably quite a bit of time at the drawing board!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python + Sound

2011-02-11 Thread Corey Richardson
On 02/12/2011 01:26 AM, David Hutto wrote:
> On Sat, Feb 12, 2011 at 1:24 AM, David Hutto  wrote:
>>> The point is to specifically transmit the data as sound, and then turn
>>> the sound back into the gzipped file. If I were doing this for anything
>>> other than my own entertainment and education, I'd do it some way that
>>> made sense :-)
>>>
>>
>> Do you mean just a wav file, and then send it to someone?
> 
> You want to have a sound file, gzip it, and then gunzip it on the other end?

I have any file, gzip it, turn it to a sound file, and then gunzip it on
the other end. Using tones to specify bit patterns, I'll work that out
after I get to the point where I can output sound.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python + Sound

2011-02-11 Thread Corey Richardson
On 02/12/2011 01:10 AM, David Hutto wrote:
> for some reason, if you're on linux, I wanna say use python's
> subprocess, and man pppd. also look into proc and a thread in the
> archives I did a while back.

The point is to specifically transmit the data as sound, and then turn
the sound back into the gzipped file. If I were doing this for anything
other than my own entertainment and education, I'd do it some way that
made sense :-)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python + Sound

2011-02-11 Thread Corey Richardson
Hello Tutors,

I'm working on a small script that compresses a file, sends it through
the telephone, and then receives and decompresses the file on the other
end. The compression is the easy part. The transmission is the hard
part. If anyone has worked with sound before, what do you recommend?
I've tried out audiere (didn't really work out) and alsaaudio (not quite
sure that it was working like I wanted to, probably an ID-10t error).
I'm doing this for a number of reasons including boredom and something
new that I've never seen before (too young to remember archaic things
like 'dial-up').

I don't really want to use the wave module because it looks like too
much work. I like the alsaaudio interface of p.write(data), but I didn't
really know what data was supposed to be (probably should read up on PCM
devices?)

So, what should I use? I can use different things different ways too, I
don't need one module for sending and one for recording.

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


Re: [Tutor] python packaging systems

2011-02-10 Thread Corey Richardson
On 02/09/2011 11:17 PM, Bill Allen wrote:
> I have found there are a few systems available to package Python programs as
> standalone programs for distribution.   Do the folks here have any
> recommendation or comment on any of these?
> 
> Thanks,
> --Bill
> 

I found cx_Freeze to be the most useful, because it supported Python 3.
The mailing list is also very helpful.

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


[Tutor] P2PU Python Challenges

2011-02-05 Thread Corey Richardson
In my journeys across the face of the Internet, I found this:
http://p2pu.org/general/python-challenges

Not sure what it's really going to be, but any new programmers/people
looking for something to do might be interested. I'm not quite sure how
a class can be organised around a web riddle, but it's there so someone
must have figured it out.

Just thought I'd share.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] print "Hello, World!"

2011-02-02 Thread Corey Richardson
On 2/2/2011 9:00 PM, Doug Marvel wrote:
> [snip]
>
> I am hoping for a link to a somewhat comprehensive online resource
> that explains from the beginning in English, plain English, as this is
> the only language I speak. Something to get my foot in the door would
> be awesome.
>
>
> Cheers,
> Doug Marvel

When I started out I used Alan Gauld's wonderful tutor:
http://www.alan-g.me.uk/tutor/index.htm

It references Python 2.3, but the same things apply for 2.6 as well.
What I like about that site is that it doesn't skip anything, and goes
into more advanced topics at the end.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Composing lists from both items and other lists

2011-02-01 Thread Corey Richardson
On 02/01/2011 06:23 PM, Andre Engels wrote:
> On Tue, Feb 1, 2011 at 9:40 PM, John Simon  wrote:
>> I'm looking for a way to flatten lists inside a list literal, kind of like
>> this:
>>
> start = '('
> end = ')'
> items = ['abc', '+', 'def']
> [start, *items, end]
>> ['(', 'abc', '+', 'def', ')']
>> Of course, the star doesn't work there. Is there any easy,
>> syntactically-lightweight way to get that output?
> 
> Is:
> 
> [start] + items + [end]
> 
> lightweight enough?
> 

That's what I was looking for. The simplest things sometimes go right
over my head... Ignore my other post, but list comprehensions are a
useful thing to know.

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


Re: [Tutor] Composing lists from both items and other lists

2011-02-01 Thread Corey Richardson
On 02/01/2011 03:40 PM, John Simon wrote:
> I'm looking for a way to flatten lists inside a list literal, kind of like
> this:
> 
 start = '('
 end = ')'
 items = ['abc', '+', 'def']
 [start, *items, end]
> ['(', 'abc', '+', 'def', ')']
> 
> Of course, the star doesn't work there. Is there any easy,
> syntactically-lightweight way to get that output?
> 
> Thanks,
> John
> 

Look into list comprehensions:

http://docs.python.org/tutorial/datastructures.html#list-comprehensions

You could use:
[start, [item for item in items], end]

But then you will have a nested list, which probably doesn't lend itself
to what you want. I myself don't know how to get rid of that, maybe some
of the gurus on this list know how.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The trap of the year

2011-01-25 Thread Corey Richardson
On 01/25/2011 06:49 PM, Steven D'Aprano wrote:
> Corey Richardson wrote:
> 
>> To be pedantic, a method _is_ a function, just under the umbrella of a
>> class, with it's parent object being passed to it.
> 
> To be even more pedantic, a method object is a wrapper (technically, a
> descriptor) around a function object. It's also slightly different
> between Python 2 and Python 3. Python 2 has bound and unbound method
> wrappers, depending on whether you call class.method or instance.method,
> but Python 3 gets rid of unbound methods and just returns the function
> object when you call class.method.
> 
> And of course, there are also "class methods" and "static methods", as
> well as custom-built method types.
> 
> Descriptors are fundamental to Python, but they're for advanced users.
> You can treat methods as just functions, except that they automatically
> get the first argument (usually called "self") automatically supplied.
> 
> 

Learning something every day, thank you Steven.

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


Re: [Tutor] class question

2011-01-25 Thread Corey Richardson
On 01/25/2011 08:50 PM, Steven D'Aprano wrote:
> Corey Richardson wrote:
>> On 01/25/2011 06:26 PM, Elwin Estle wrote:
>>> Is it better to have one large sort of "do it all" class, or break
>>> the larger class up into smaller classes?
> 
>> If you're just learning, go ahead and make a 'do it all' class. Don't do
>> it later in your growth as a programmer though.
> 
> Learn bad habits first, then spend years trying to break them!
> 
> *wink*


Hey, gotta learn the concepts first, right? ;-)
I remember my first "substantial" program, hangman! Quite a mess.
Excerpt:

def getlist3(self):
list3 = []
for i in range(5):
list3.append(self.gameWord[i])
self.list3 = list3

I don't even remember what list3 is. I have a whole function for a list
comprehension!

self.list3 = [char for (idx, char) in enumerate(gameWord) if
  gameWord.index(char, idx) < 5]

(list3 happened to be the hint characters given, remembered while doing)

Just proof that it doesn't have to take years, it could take months.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class question

2011-01-25 Thread Corey Richardson
On 01/25/2011 06:26 PM, Elwin Estle wrote:
> Is it better to have one large sort of "do it all" class, or break the larger 
> class up into smaller classes?  Seems to me like the one large class would be 
> clearer in some ways.  I have something I am trying to do that have somewhere 
> in the neighborhood of 20 attributes that all relate together, however there 
> are sort of "clumps" of attributes that have a sub-relationship to each other 
> and I wondered if they should be their own class, but I am not sure, assuming 
> that is a good idea, how these smaller classes might work together.  I have 
> only the foggiest notion of inheritance and I'd kind of like to stay away 
> from that aspect of things until I get a better grasp of individual classes.
> 

If you're just learning, go ahead and make a 'do it all' class. Don't do
it later in your growth as a programmer though.

Inheritance works like this:

class Parent:
def __init__(self):
print "Parent initialised"

class Child(Parent):
pass

The parenthesis set the superclass or parent class. If you now do:

c = Child()

You should see "Parent initialised" printed to the terminal. It makes
all the 'parents' methods available to it. You can think of it as
copying all the code from the parent class into the child class. You can
overwrite the methods too:

class Animal:
def speak(self):
print self.noise

class Pig(Animal):
def __init__(self):
self.noise = "Oink!"

pig = Pig()
pig.speak()

Hope it helped,
~Corey
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] extracting text from word files (.doc, .docx) and pdf

2011-01-25 Thread Corey Richardson
On 01/25/2011 04:52 PM, Juan Jose Del Toro wrote:
> Dear List;
> 
> I am looking for a way to extract parts of a text from word (.doc,.docx)
> files as well as pdf; the idea is to walk through the whole directory tree
> and populate a csv file with an excerpt from each file.
> For PDF I found PyPdf ave found nothing to read
> doc, docx
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

A docx file is a compressed XML file (or groups of files). I don't know
if there is a python module for it, but you could probably whip up your
own. I know 7z on Windows will extract a .docx (probably anything can if
you point to it, not sure). From there you'll need to explore the
structure and how Microsoft decided to use XML. ElementTree would
probably be useful here. Not sure about a doc file, a simple dd of a doc
file shows some garbage (probably useful for formatting ;-) as well as
the text. I found
http://code.activestate.com/recipes/279003-converting-word-documents-to-text/
.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] placing widgets

2011-01-25 Thread Corey Richardson
On 01/25/2011 04:31 PM, W S wrote:
> hi, i have written some Tk/Python code to do a few simple tasks, and am 
> having 
> trouble with my combobox placement on the frame.  is there a way to more 
> explicitly place it other than:  This method does not give a lot of control
> xx=apply(OptionMenu,(self,TCase)+tuple(TestCase))
> xx.grid(row=1, sticky=E+W)

You can use place (http://effbot.org/tkinterbook/place.htm). Never had
the occasion to use it, but you may find it useful.
~Corey
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The trap of the year

2011-01-25 Thread Corey Richardson
On 01/25/2011 04:28 PM, Karim wrote:
> 
> Hello Bob,
> 
> I know this fact for function but in this case this is not a function
> but a constructor method of a class.

To be pedantic, a method _is_ a function, just under the umbrella of a
class, with it's parent object being passed to it.
~Corey

> The impact is not the same because all instance share the same argument
> parameter.This a kind
> of singleton argument :-) . I believed that the constructor will create
> each time a new argument init.
> 
> 
> Regards
> Karim
> 


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


Re: [Tutor] Exercise suggestions

2011-01-22 Thread Corey Richardson

On 01/22/2011 03:09 PM, David Hutto wrote:

When I felt I was ready to start doing some work, I got involved in an open
source project. It's definitely an experience! Try going through
http://freshmeat.net/


Isn't that for those that aren't given real apprenticeship?:)



Programming is my hobby, not my profession. Also given the fact that 
I've yet to graduate high school, OS was the way to go for me.


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


Re: [Tutor] Exercise suggestions

2011-01-22 Thread Corey Richardson

On 01/22/2011 11:56 AM, michael scott wrote:

I am new to programming, I intend to get an entry level job programming
next year (or a little bit longer). I am switching fields and not going
to college, but kinda "self teaching" myself through various methods. I
currently understand concepts in programming in python up to classes
(like I understand how to make objects, I understand inheritance,
etc...), and I have experimented with building guis in Tkinter, but I'm
finding that I understand concepts, but have no real way to implement them.

So now my problem emerges... can anyone give me suggestions of exercises
I should do to help improve my knowledge of what I can "actually" do
with the concepts I have.

My main goal is to get to the point where I can assist in fixing bugs in
open source programs (I'll be learning C++ in a couple months as well),
but when I look at bugs / source code of larger programs, I am just so
blown away at how little I understand. So I need to find a way to bridge
the gap between my current level and the level needed to contribute to
open source programs. A lofty goal I understand, but it is my goal. And
I am very dedicated to reaching it.

Anyways, given my situation, do you good people have any suggestions for
me. I don't need a person walking me through it, a simple, "build a
program that asks a user to give you a name and create permutations of
it" is great. Of course that example is elementary, but that is the gist
of the responses I'm looking for. I just have no idea of what kind of
programs to build, my ignorance is holding me back in my opinion.

Any response is welcomed, but I do ask if you are critical of me, please
offer a method for me to improve the deficiency / deficiencies I have.
Thank you so much for reading my inquiry :)


When I felt I was ready to start doing some work, I got involved in an 
open source project. It's definitely an experience! Try going through 
http://freshmeat.net/ and remake a few things. Can't really recommend 
anything else, fresh out of ideas too ;-)


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


Re: [Tutor] Is it possible to tell, from which class an method was inherited from

2011-01-19 Thread Corey Richardson
On 01/19/2011 03:55 AM, Jojo Mwebaze wrote:
> Is it possible to tell, from which class an method was inherited from.
> take an example below
> 
> |class A:
> 
>def foo():
>  pass
> class B(A):
> 
>def boo(A):
>  pass
> 
> class C(B):
>def coo()
> 
>  pass
> class D(C):
> 
>def doo()
>   pass  
> 
 dir (D)
> 
> ['__doc__', '__module__', 'boo', 'coo', 'doo', 'foo']
> 
> |
> 
> Is there any method to tell me form which classes boo, coo, foo where
> inherited from?
> 
>   
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Try using the information here:
http://stackoverflow.com/questions/1938755/getting-the-superclasses-of-a-python-class

>From there, you can use the following (probably sub-prime):

def findRootParent(obj, method, prev=None):
for parent in obj.__bases__:
if hasattr(parent, method):
findRootParent(parent, method, parent)
print "I'm in %s, it has it" % obj.__name__
else:
print "%s first had %s" % (obj.__name__, method)

Here's a little test and some output:

class A(object):
def test1():
pass
def test2():
pass

class B(A):
def test3():
pass

class C(B):
def test4():
pass
findRootParent(C, "test1")

Output:
A first had test1
I'm in B, it has it
I'm in C, it has it

That's just me hacking together a solution. I don't know if its the best
or if one of the gurus on the list have a better one. It doesn't really
work if you have multiple inheritance:

class A(object):
def test1(): pass

class B(object):
def test2(): pass

class C(A, B): pass
findRootParent(C, "test1")
findRootParent(C, "test2")

Output:
A first had test1
I'm in C, it has it
C first had test1
C first had test2
B first had test2
I'm in C, it has it

Hope it helps,
~Corey
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about manipulate images!

2011-01-17 Thread Corey Richardson
On 01/17/2011 10:34 AM, zhengqing gan wrote:
> Hi,
>Thanks for the reply.
>But I found that there are some website which can convert images
> into iphone icon style images, there should be an kind of algorithm to
> manipulate.
>Thanks!
> 
> 

>From playing with
http://wizardtoolkit.com/shooter/iPhone-Icon-Generator, it appears all
that needs to be done is add a semi- or completely-transparent ovalish
blob on the top, and possibly a metallic looking frame. While I'm sure
you could take the (probably) tens to hundreds of hours finding a
mathematical formula to define that, you can probably just whip up some
semi-transparent blobs in GIMP/Photoshop/what-have-you and a metallic
frame. Then you can use PIL to combine them. Try:
http://python-forum.com/pythonforum/viewtopic.php?f=3&t=3462&start=0
http://stackoverflow.com/questions/3374878/with-the-python-imaging-library-pil-how-does-one-compose-an-image-with-an-alph

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


Re: [Tutor] Anyone interested in making a Python Help hotline?

2011-01-15 Thread Corey Richardson
On 01/15/2011 06:30 PM, Corey Richardson wrote:
> On 01/15/2011 05:45 PM, walter weston wrote:
>> I thought creating a Python help hotline would help programmers
>> exponential! I think they should make a help hotline for every
>> programming language. and since I havent discovered something similar It
>> would probably be lucretive!
>>
> 
> irc.freenode.net/python
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Forgive the double post, having issues with my MUA.

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


Re: [Tutor] Anyone interested in making a Python Help hotline?

2011-01-15 Thread Corey Richardson
On 01/15/2011 05:45 PM, walter weston wrote:
> I thought creating a Python help hotline would help programmers
> exponential! I think they should make a help hotline for every
> programming language. and since I havent discovered something similar It
> would probably be lucretive!
> 

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


Re: [Tutor] Anyone interested in making a Python Help hotline?

2011-01-15 Thread Corey Richardson
On 01/15/2011 05:45 PM, walter weston wrote:
> I thought creating a Python help hotline would help programmers
> exponential! I think they should make a help hotline for every
> programming language. and since I havent discovered something similar It
> would probably be lucretive!
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Python on Ubuntu 10.10?

2011-01-14 Thread Corey Richardson
On 01/14/2011 08:17 PM, Joel Knoll wrote:
> Hello,
> 
> I am new to programming and to Python.  I've been using Python with IDLE
> on Windows Vista for a few weeks now. 
> (And I'm loving it!)  However, I'm thinking about switching to Ubuntu
> 10.10.  If I download Ubuntu, will I still be able to use the
> IDLE environment?  I am really quite fond of it (mostly because it's
> what I know!).  To use Python in Ubuntu,
> will I have to do any additional downloading, or do Python and IDLE come
> built in and ready to use? 
> 
> Thanks for your time,
> 
> JC Knoll
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Python (2.6.6) comes default with Ubuntu IIRC. You'll need to:
sudo apt-get install idle
to download and install Idle, but it does all the lifting for you.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] color of "print" function

2011-01-14 Thread Corey Richardson
On 01/14/2011 07:48 PM, Bill DeBroglie wrote:
> Hello all,
> 
> I don't have a problem per se, but have noticed something that I'd  
> like to figure out...
> 
> Sometimes the "print" function appears orange for me, sometimes it  
> appears purple. Why does this happen and what's the difference anyway?  
> This seems to be the only function that varies like this, but I'm just  
> starting really so perhaps I'll come across more.
> 
> The coloring seems to be fairly arbitrary. At least, I haven't noticed  
> a pattern yet.
> 
> Using Mac OS X 10.5.8 and Python 2.7.1
> 
> Thank you for the help,
> bdb
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Is that specifically with Idle, or some other IDE? AFAIK the interpreter
has no coloring, unless you're using something like bpython or ipython.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to print random number multiply

2011-01-14 Thread Corey Richardson
On 01/14/2011 07:46 PM, walter weston wrote:
> I have mostly studied python and now I'm ready to start writing code. I
> want to print random numbers a certain ammount of times I am using the
> code  
> 
>  import random
> print (random.random())
> 
> I tried bind the print statement to a variable and when I call x for
> example I want it to print new numbers when I store the print statement
> in a variable x everytime I call x it's the same number and does change
> I wanted it to change when I call it could someone show me the code to
> do that thanks!
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
When you do:
x = print(random.random())
that evaluates random.random() once, and not every time you type in x.
What you want it is for loop:

for number in range(50):
print(random.random())

Coming from other languages you might think:
cntr = 0
while cntr < 50:
print(random.random())
cntr += 1

which is correct, but not pythonic.

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


Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??

2011-01-13 Thread Corey Richardson
On 01/13/2011 10:29 PM, Bill Allen wrote:
> That is correct about the difference between Python 2 and Python 3
> syntax.   However, I am surprised that with 2.7.1 these do not work.   I
> have found that on my Ubuntu system with Python 2.6.5 these Python 3
> syntax items do seem to work properly.  I am assuming they were back
> ported or something.  I would have expected the same for 2.7.1.
> 
> --Bill

I'm using Python 2.6.6 and I have a feeling you are not using python
2.6.5 with Python3 syntax working. I could be very wrong, but just a
hunch ;)

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


Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??

2011-01-13 Thread Corey Richardson
On 01/13/2011 08:50 PM, Elwin Estle wrote:
> I am going through the book mentioned in the subject line, and I have found a 
> couple of things that don't seem to work the way the author shows in the 
> book.  So, either I am doing something wrong, or what he is saying isn't 
> quite right.
> 
> I am using Python 2.7.1 on Mac OS X Leopard.
> 
> The first thing is what he has for getting keyboard input (this is non-GUI 
> stuff).
> 
> Several times he does something like this:
> 
> x = input('type something: ")
> 
> But when I do the above and type something in, I get an error message saying 
> that whatever I have typed in response to the above input() command, is an 
> undefined name, unless I put it in quotes when I type it.  I did a bit of 
> poking around on the net and found out that input() actually appears to treat 
> whatever is typed as an actual python command, i.e. as if it was being 
> "eval"ed.   If this is the case...why does he describe the usage this way in 
> his book?
> 
> On the other hand, raw_input() works just as exected, is it a typo?  Seems 
> like kind of a bad error to have in a Python book for beginners.
> 
> And I just found another one that doesn't appear to work as he describes.
> 
> print("some text here", end = ' ')
> 
> He says this is supposed to control the end character on a print statement, 
> allowing one to choose what the last character printed will be, other than a 
> newline.  But when I try it, I get a syntax error on the "=" after "end".
> 
> So is this not a valid command format?  Or is he using perhaps an earlier 
> version of python?  The copyright date on the book is 2010, and it is the 3rd 
> Edition of the book.
> 
> 
> 

He's not using an older version - you are! That book was written for
Python 3.x, you are using Python 2.x. As you have found, replace input
with raw_input, and for that print statement you can use:

print "Some text",

The comma suppresses the newline from being printed.

HTH,
~Corey

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


Re: [Tutor] Sorting a List

2011-01-12 Thread Corey Richardson
On 01/12/2011 09:42 PM, Luke Paireepinart wrote:
> Remember the sorted() method takes a key function, have this key
> function take in each filename and compare the numbers and you're all set!
> 
> -
> Sent from a mobile device. Apologies for brevity and top-posting.
> -
> 
> [snip]

Thanks everyone - I didn't get anything out of glob, but playing with
key and using a function that parsed the frame number out worked. Thanks
again,
~Corey

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


[Tutor] Sorting a List

2011-01-12 Thread Corey Richardson
Hello Tutors,

I am generating XML definitions for animations to be used in a
FIFE-based game. I need to sort the frames of the animations, and I am
currently using:
sorted([image for image in os.listdir(path) if image.endswith('.png')])

The final output in the XML is:














Having frame 10 and 11 between frame 1 and 2 is not desired behavior;
how can I sort all of these with walk_10.png and company (this isn't the
only animation like this) being after walk_9.png? A google search
doesn't return anything I could use. I tried just using
[image for image in os.listdir(path) if image.endswith('.png')],
but that doesn't appear to have any order.

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


Re: [Tutor] __init__() - is it required?

2011-01-10 Thread Corey Richardson
On 01/09/2011 04:27 PM, Steven D'Aprano wrote:
> Corey Richardson wrote:
>> Do all classes need an __init__() method? I have classes that look much
>> like this one starts out:
>>
>> class GenerateXML(object):
>> """Defines methods to be inherited for StaticXML and AnimationXML"""
>> def __init__(self):
>> pass
>>
>> I would rather not do that. Code without it runs fine, but will there be
>> any negative consequences down the road? Does object define an __init__
>> method for me?
> 
> You don't need to define an __init__ if you don't need one. A 
> placeholder __init__ that does nothing, as above, is a waste of space.
> 
> object includes an __init__ method that not only does nothing, but 
> ignores any arguments you pass to it:
> 
>  >>> object.__init__
> 
>  >>> object.__init__(1, 2, 3)
>  >>>
> 
> In Python 2.x, you can have "old-style" classes that don't inherit from 
> object. They too don't need an __init__:
> 
>  >>> class Old:  # *don't* inherit from object
> ... pass
> ...
>  >>> o = Old()
>  >>>
> 
> 

Thank you very much Alan and Steven!

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


[Tutor] __init__() - is it required?

2011-01-09 Thread Corey Richardson
Do all classes need an __init__() method? I have classes that look much
like this one starts out:

class GenerateXML(object):
"""Defines methods to be inherited for StaticXML and AnimationXML"""
def __init__(self):
pass

I would rather not do that. Code without it runs fine, but will there be
any negative consequences down the road? Does object define an __init__
method for me?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Open a text file, read and print pattern matching

2011-01-08 Thread Corey Richardson
On 01/09/2011 01:25 AM, tee chwee liong wrote:
> hi,
> 
> i have a sampledata as below. Pls refer to output, if found -1, how to
> list out all the Lane number? And if there is no -1, print PASS. My code
> is as below section.
>  
> thanks
> tcl76
>  
> sampledata
> Platform: PC
> Tempt : 25
> TAP0 :0
> TAP1 :1
> 
> +
> Port Chnl Lane EyVt
> +
> 0   1  175
> 0   1  2-1
> 0   1  310
> 0   1  4-1
> 0   1  512
> +
> Time: 20s
> 
>  
> output###
> case1: Found -1
> Lane 2 FAIL
> Lane 4 FAIL
>  
> case2: No -1
> All Lanes PASS
> ##
You couldn't possibly have gotten that output from the code you
provided, so why did you list it under output?
>  
> Code
> fname = "sampledata.txt"
> pattern = "-1"
> for search in open(fname):
> if pattern in search:
> print "FAIL"
> else:
> print "PASS"
> 
>  
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

I'm not quite sure how your data file is supposed to be laid out. I
suggest you have it setup so that every line that isn't actually data is
commented out somehow, and you only search the actual data. So, your new
data file could look like:

---paste--
#Platform: PC
#Tempt : 25
#TAP0 :0
#TAP1 :1

#+
#Port Chnl Lane EyVt
#+
0   1  175
0   1  2-1
0   1  310
0   1  4-1
0   1  512
#+
#Time: 20s
-end-paste

Your script could look something like:

data = [for line in open(filename) if not line.startswith("#")
for line in data:
line = line.split()
if line[3] == pattern:
print "Lane " + line[2] + " PASS"
else:
print "Lane " + line[2] + " FAIL"

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


Re: [Tutor] Parse MPL files

2011-01-07 Thread Corey Richardson
On 01/07/2011 06:29 PM, PyProg PyProg wrote:
> 2011/1/7 Corey Richardson :
> 
> Hi,
> 
> Thanks for your response.
> 
>> A google search yields no results for one. If you know the structure of
>> the MPL file, you can write your own parser. Look through the file with
>> a hex editor like Bless first, if you need to. Most likely the
>> information you want is right at the start of the file.
> 
> Parts of the data is inaccessible (very large parts in fact).The
> structure is like that:
> 
> Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> o = open("/home/toto/ae/1.MPL", "r")
>>>> oo = o.readlines()
>>>> for listage, ligne in enumerate(oo):
> ... print "Ligne n°", listage, ":", ligne
> ...
> Ligne n° 0 : MPLS0100:�
> 
> Ligne n° 1 : �...@�`5m2ts�x1�p>�1und
> �und`2M2TSp��>  �1und   �und`3M2TSqu��>
>  �1und �und`4M2T��>�1und
> �und:�X��p��quJ▒▒6PLEXDR▒�� �
> 
> Ligne n° 2 : 2011. 1. 1
> 
> GH DD� :  �T%d
> 
> Ligne n° 4 : 2011. 1. 1T%dGH X&�
> 
> Ligne n° 5 : 2011. 1. 1T%dGH▒�
> 
> Ligne n° 6 : 2011. 1. 1T%dGH
> �▒▒
> 
> (~�B���~���"�'��
> �u���A���>���O��$mCy�C�Ng�>�3�...@f�^�,dW&#�Y�}n�A�$▒�`��N0
> �d1A2
> 
> Ligne n° 7 :
> 
> Ligne n° 8 : WGS-841GPSFRANCE
> 
> ,dW&e n° 9 : FINISTÈRELOCMARIA-PLOUZANÉ---��N0
> �d1A2
> 
> Ligne n° 10 :
> 
> Ligne n° 11 : WGS-841GPSFRANCE
> 
> 5"A2e n° 12 : FINISTÈRELOCMARIA-PLOUZANÉ---��N0qdW*�d
> 
> Ligne n° 13 :
> 
> Ligne n° 14 : WGS-84GPSFRANCE
> 
> Ligne n° 15 : FINISTÈRE
> 5"A2   PLOUGONVELINCENTRE AQUATIQUE TRÉZIROISE��N0qdW*�d
> 
> Ligne n° 16 :
> 
> Ligne n° 17 : WGS-84GPSFRANCE
> 
> Ligne n° 18 : FINISTÈRE
>PLOUGONVELINCENTRE AQUATIQUE TRÉZIROISE� �
> 
> ��DMC-TZ10�DMC-TZ10�DMC-TZ10�DMC-TZ10
> 
> 
> How to set up a hex editor ?
> 
>> ~Corey Richardson
> 
> a+
> 

Open the file not with 'r' but with 'rb'. That opens the file as binary,
not text. To use Bless, run sudo apt-get install bless on Ubuntu and
variants, for Windows try HxD, http://mh-nexus.de/en/hxd/.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parse MPL files

2011-01-07 Thread Corey Richardson

On 01/07/2011 05:16 PM, PyProg PyProg wrote:
> Hi all,
> 
> I'm looking for a way to parse MPL files (.MPL or .mpl extension).
> These files are contained in the tree of some cameras that support the
> AVCHD ... and some cameras filming with a stream mpeg-ts.
> 
> I know a person who seeks to recover the data contained in these
> files. MPL (or .mpl). The data in this kind of file are the date and
> location (by GPS info), I would help him recover the data.
> 
> Is there a Python module who make that ?, or how to proceed ?
> 
> Thank you in advance.
> 
> a+
> 
A google search yields no results for one. If you know the structure of
the MPL file, you can write your own parser. Look through the file with
a hex editor like Bless first, if you need to. Most likely the
information you want is right at the start of the file.

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


Re: [Tutor] wx accelerator table: one keystroke seems skipped

2011-01-05 Thread Corey Richardson
On 01/05/2011 04:41 PM, Alex Hall wrote:
> Hello all,
> First, this is about a wx accelerator table, so if it is too off-topic
> for this list, let me know.
> 
> [snip]

I would go ask the wxPython mailing list or similar, just my 2 cents.
~Corey Richardson

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


Re: [Tutor] print stack traces not caused by errors

2011-01-04 Thread Corey Richardson
On 01/04/2011 06:59 PM, Alan Gauld wrote:
> 
> "Alex Hall"  wrote
> 
>> expected at all. I tried the pdb module, but I am running a wx 
>> program
>> so it is not helping. I tried:
>> python -m pdb c:\prog\solitaire\game.py
> 
> The key to using any debugger in a GUI environment is to set break
> points on the event handlers of interest. Then when the event fires
> the debugger will stop your code at the start of the event handler
> and you can examine the stack, variables etc and step through
> the code.
> 
> Single line stepping is tiresome so usually you are better off
> setting another break point within the function (just before or within
> a loop maybe? Or after reading a line from a file...). A watch point
> is even better but sadly I don't think pdb supports those. But
> the debugger in Eclipse and winPDB(?) do I think.
> 
> And of course print statements work too within the console
> window.
> 
> HTH,
> 
> Alan G. 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

I've done almost all my debugging via print statements at crucial
points. It's a good way to go, IMO.

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


Re: [Tutor] syntax error that i cant spot!

2011-01-02 Thread Corey Richardson
On 01/02/2011 09:40 AM, Brett Ritter wrote:
> On Sat, Jan 1, 2011 at 9:10 PM, Alan Gauld  wrote:
>> Why avoidCamelCase? I actually prefer it to using_non_camel_case
> 
> The readability is an often argued topic - I myself find the space of
> names_in_underscores to be more readable (words are distinct), but I
> try to follow the common conventions of the languages I'm using, and
> Python appears to use camelCase more than not.
> 

I tend to disagree with that. In the stdlib, as well as the builtins,
many, many methods are alllowercase, for example str.isdigit() or
socket.gethostname().
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread Corey Richardson

On 01/01/2011 02:28 PM, Ken Green wrote:

I am caught off guard but what is the purpose of the plus sign? I don't
recall seeing it used like that.

Ken

On 01/01/2011 12:11 PM, Abhijeet Rastogi wrote:

You missed a "+" after myName on line 30.

On Sat, Jan 1, 2011 at 10:32 PM, pete mailto:psmo...@live.com>> wrote:

Hi,
Please help just starting out and have come up with the following
code to create a simple guessing game.

on line 30 print good job etc i get a syntax error! sure it's
simple but i've looked for ages and cant spot it!

Regards
Pete

_



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


The + operator in this case concatenates, or joins, two strings.
"Hello, " + "World" == "Hello, World"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 82, Issue 54

2010-12-12 Thread Corey Richardson

On 12/12/2010 11:43 PM, marupalli charan wrote:

dont send me mails again. i want to unsubscript
At the bottom of every single message from the list there are the 
following lines:


To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

~Corey Richardson

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


Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Corey Richardson



On 12/10/2010 3:34 PM, Wayne Werner wrote:

If you just want a single line you can use chr(13) which is a carriage
return. If you want a more complex program you'll need a curses type
library
hth, wayne

On 12/10/10, Modulok  wrote:

List,

Forgive me if I don't describe this well, I'm new to it:

Assume I'm working in a command shell on a terminal. Something like
tcsh on xterm, for example. I have a program which does *something*.
Let's say it counts down from 10. How do I print a value, and then
erase that value, replacing it with another value? Say I had something
like '10' that appears, then wait a second, then the 10 is replaced by
'9'... '8'.. and so forth. The point is, I don't want to print to a
new line, nor do I want the new number to appear next to the previous
number... I just want to change it in place. (If that makes any
sense?) Think of console based progress counters in programs like
fetch or wget, or lame.

How do you do this in Python?
-Modulok-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



Try that in the interactive interpreter, it doesn't work.
>>> print "a" + chr(13)
a
(Python 2.6.6)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Corey Richardson



On 12/10/2010 3:14 PM, Modulok wrote:

List,

Forgive me if I don't describe this well, I'm new to it:

Assume I'm working in a command shell on a terminal. Something like
tcsh on xterm, for example. I have a program which does *something*.
Let's say it counts down from 10. How do I print a value, and then
erase that value, replacing it with another value? Say I had something
like '10' that appears, then wait a second, then the 10 is replaced by
'9'... '8'.. and so forth. The point is, I don't want to print to a
new line, nor do I want the new number to appear next to the previous
number... I just want to change it in place. (If that makes any
sense?) Think of console based progress counters in programs like
fetch or wget, or lame.

How do you do this in Python?
-Modulok-
___
Tutor maillist  - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



I've never used it before, but I think the curses module does this.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PHP

2010-12-04 Thread Corey Richardson


On 12/4/2010 2:27 PM, Kirk Bailey wrote:

For reasons of my work, of recent I have started aquiring php.
Straightaway, i was impressed by one powerful property; the ability to
imbed php into a html webpage, and switch into and out of php as needed,
and let normal ssi and html and css work the rest of the time, outside
of php. all I have to do is start the php block with
 # end the php block
and continue in html. What a BLOODY shame we can't do that in python,
which is otherwise awesome and superior in every way i can thus far
evaluate.


Actually, you CAN do that with Python. Python Server Pages (PSP) and 
mod_python enable you to do this on an Apache server.

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


Re: [Tutor] floats

2010-12-03 Thread Corey Richardson



On 12/3/2010 1:52 PM, Christopher Spears wrote:

I have a float variable that is very long.


float_a = 1.16667

However, I want to pass the value of float_a to float_b, but I want the float 
to be accurate to two decimal points.


float_a = 1.16667
print "%.2f" % float_a

1.17

I tried the following:


float_b = "%.2f" % float_a
float_b

'1.17'

type(float_b)



This doesn't work because it yields a string.

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


float_b = float(float_b)
That takes the string and makes it a float.
~Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Temperature Scales

2010-11-28 Thread Corey Richardson



On 11/28/2010 8:33 PM, Andre Jeyarajan wrote:


Write two functions that will convert temperatures back and forth from 
the Celsius and Fahrenheit temperature scales (using raw_input)



def C_F(x):

y = (x-32)*(5.0/9)

print y


def F_C(x):

y = (x*9.0/5)+32

print y


I have created the two functions but I don’t know what to do from here.


Can you help?


Thanks



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
I get the curious feeling this is homework.  You would need to do one of 
two things:
Pass the output of raw_input as an argument or rewrite your functions so 
that instead of taking the temperature as a parameter, it asks in the 
body of the function for a temperature. In either case, you will run 
into a little TypeError, easily fixed however.

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


Re: [Tutor] List Changing Order

2010-11-26 Thread Corey Richardson

Steven D'Aprano wrote:

Corey Richardson wrote:

Tutors,

I recall that the keys of dictionaries have arbitrary order, and may 
change over time. Is this true of lists? I can't find the answer from 
a simple Google search. Thank you!


Only if you re-arrange it yourself.

list.sort(), list.reverse() and random.shuffle(list) explicitly change 
the list's order. You can also manually move items around, e.g.:


list[3], list[5] = list[5], list[3]  # swap items 3 and 5

but otherwise lists keep their order.



Many thanks, everyone who replied.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] List Changing Order

2010-11-25 Thread Corey Richardson

Tutors,

I recall that the keys of dictionaries have arbitrary order, and may 
change over time. Is this true of lists? I can't find the answer from a 
simple Google search. Thank you!

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


Re: [Tutor] lists, arrays and saving data

2010-11-21 Thread Corey Richardson



On 11/21/2010 8:12 AM, Chris Begert wrote:

Hi Gurus

I just wrote my first little python program; so yes I'm very new to all this.

The goal in the end is to have a program that shows how the sun moves  from the 
point of view of a given location (i.e. solar paths added to some sort of 
stereographic diagram).

My very first program calculates the height (altitude) and direction of the sun 
(Azimuth) at a specific location during a specific time.

So here's my question (I'm sure its obvious for most of you):

How do I store a years worth of data of angles in an array / list / whatever is 
most useful when using Python?




Well now. You can store altitude and AZ in a tuple, and append that 
tuple to a list called, for example, data. data.append((altitude, AZ)), 
where data = list(). You will probably want to wrap all that calculation 
into a function that takes 6 arguments: longitude, latitude, month, day, 
hour, and minutes, instead of taking that input by hand. That way you 
can put everything into a nice for loop (in theory).

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


Re: [Tutor] Server

2010-11-05 Thread Corey Richardson



On 11/5/2010 3:18 PM, Chris King wrote:

 On 11/4/2010 9:46 PM, Corey Richardson wrote:



On 11/4/2010 8:43 PM, Chris King wrote:

 Dear Tutors,
May server and client programs aren't working. They basically 
simplify socket and SocketServer. Run them directly to test them. 
They do work locally. They don't work from one computer to the next 
on the same network. Please Help.


Sincerely,
Me, Myself, and I

P.S. How to you stop a server loop and open up the port?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

When ever I have worked on network, it's always been a firewall 
issue. If you are using Windows, turn off the built-in firewall. 
That's what fixed my problems.

Hope it helped,
~Corey

make sure you click reply to all, so you don't just send it to me
also, it is on the same network, so the server shouldn't be a problem


It has nothing to do with a server, it's the firewall built into Windows.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


  1   2   >