lewashby 56 Junior Poster

Looking at the current world I'd of to go with one of these.

Chines - China is growing with a booming economy
Japanese - Japan has the second largest economy in the world

Polish - The U.S. THINKS that it has a vested interest in Poland and will probably continue to use Poland as our Easter European foot.

Dutch - This is kind of a second though, but considering Holland is the birthplace of both the Python programming language as well as Linux, it might be something to consider.

Arabic - I U.S. will continue to have an interest in people who can speak Arabic for many ears, and for obvious reasons.

Spanish or Portuguese - Which ever Brazil Speaks, Brazil's economy is up and coming.

lewashby 56 Junior Poster

Please look at the program below as well as my understanding of how it flows and correct me if I'M wrong. Thanks

The first line in main - crit = Critter("Poochie"), creates an object with the string "Poochie" and autmoatically calls __init__, printing "A new critter has been born!"

__init__ creates a private attribute name?

The second line in main crit.talk() and prints Hi, I'm, self.name ("Poochie"), which it is able to get because get_name method?

print cirt.name prints "Poochie", again using the get_method?

# Property Critter
# Demonstrates get and set methods and properties

class Critter(object):
    """A virtual pet"""
    def __init__(self, name):
        print "A new critter has been born!"
        
        self.__name = name
        
        
    def get_name(self): #---------------------------------------reads a value to a private name?
        return self.__name
    
    
    def set_name(self, new_name): #-----------------------------set's a value to a private name?
        if new_name == "":
            print "A critter's name can't be the empty string."
        else:
            self.__name = new_name
            print "Name change successful."
            
    name = property(get_name, set_name) #----------------------allows access through dot notaion
    
    
    def talk(self):
        print "\nHi, I'm", self.name
        
        
# main

crit = Critter("Poochie")
crit.talk()

print "\nMy critter's name is:",
print crit.name

print "\nAttempting to change my critter's name."
crit.name = ""

print "\nAttempting to change my critter's name again."
crit.name = "Randolph"

crit.talk()

raw_input("\n\nPress the enter key to exit.")
lewashby 56 Junior Poster

In the following program, I have three different comments each after a line of code. Please read those comments to answer my questions.

# Property Critter
# Demonstrates get and set methods and properties

class Critter(object):
    """A virtual pet"""
    def __init__(self, name):
        print "A new critter has been born!"
        
        self.__name = name
        
        
    def get_name(self): #---------------------------------------reads a value to a private name?
        return self.__name
    
    
    def set_name(self, new_name): #-----------------------------set's a value to a private name?
        if new_name == "":
            print "A critter's name can't be the empty string."
        else:
            self.__name = new_name
            print "Name change successful."
            
    name = property(get_name, set_name) #----------------------allows access through dot notaion
    
    
    def talk(self):
        print "\nHi, I'm", self.name
        
        
# main

crit = Critter("Poochie")
crit.talk()

print "\nMy critter's name is:",
print crit.name

print "\nAttempting to change my critter's name."
crit.name = ""

print "\nAttempting to change my critter's name again."
crit.name = "Randolph"

crit.talk()

raw_input("\n\nPress the enter key to exit.")
lewashby 56 Junior Poster

Well for your first queston I found this that might make things a bit more clear for you. http://code.activestate.com/recipes/52304/
As for your secound question. And I hope I'm not way off in left feild about this. But I believe they are trying to domonstrate that some attributes and methods are accessible from outside the class "public", and that the others are only accessible from inside the class itself "private". I didn't test that, I'm kinda making a large assumption by just glancing at the code.

Yes that is correct, but it doesn't answer the question I had about self being use in this case.

lewashby 56 Junior Poster

I have to prgrams and thus, two question to ask. In the following program how does the line status = staticmethod(status) do anything? My python programming book somehow connects it to the line Critter.total += 1 but I don't see how? Please explain.

# Classy Critter
# Demonstrates class attributes and static methods

class Critter(object):
    """A virtual pet"""
    total = 0
    
    
    def status():
        print "\nThe total number of critters is", Critter.total
        
    status = staticmethod(status)
        
    def __init__(self, name):
        print "A critter has been born!"
            
        self.name = name
            
        Critter.total += 1
            
            
# main

print "Accessing the class attribute Critter.total:",
print Critter.total

print "\nCreating critters."

crit1 = Critter("critter 1")
crit2 = Critter("critter 2")
crit3 = Critter("critter 3")

Critter.status()

print "\nAccessing the class attribute through an object:",
print crit1.total

raw_input("\n\nPress the enter key to exit.")

The second program I want to know, does the self line self.__mood in the talk method refer to self in the talk method itself? Or the __init__ method where __mood was created. The same question goes for self.__private_method(). Does the self refer to the self in public_method where it was called, or again, the __init__ method/constructor?

# Private Critter
# Demonstrates private variables and methods

class Critter(object):
    """A virtual pet"""
    def __init__(self, name, mood):
        print "A new critter has been born!"
        
        self.name = name        # public attribute
        self.__mood = mood      # private attribute
        
        
    def talk(self):
        print "\nI'm", self.name
        print "Right now I feel", self.__mood, "\n"
        
    
    def __private_method(self):
        print "This is a private method."
        
    def public_method(self):
        print "This …
lewashby 56 Junior Poster

In the following program I don't understand the staticmethod or what is has to do with Critter.total. From what I can see, total is a class attribute and Critter.total is accessed from the __init__ constructor method. Thanks for any and all replies.

# Classy Critter
# Demonstrates class attributes and static methods

class Critter(object):
    """A virtual pet"""
    total = 0
    
    
    def status():
        print "\nThe total number of critters is", Critter.total
        
    status = staticmethod(status)
        
    def __init__(self, name):
        print "A critter has been born!"
            
        self.name = name
            
        Critter.total += 1
            
            
# main

print "Accessing the class attribute Critter.total:",
print Critter.total

print "\nCreating critters."

crit1 = Critter("critter 1")
crit2 = Critter("critter 2")
crit3 = Critter("critter 3")

Critter.status()

print "\nAccessing the class attribute through an object:",
print crit1.total

raw_input("\n\nPress the enter key to exit.")
lewashby 56 Junior Poster
lewashby 56 Junior Poster

The indentation is bad. The code should read

# Classy Critter
# Demonstrates class attributes and static methods

class Critter(object):
    """A virtual pet"""
    total = 0
    
    
    def status():
        print "\nThe total number of critters is", Critter.total
        
    status = staticmethod(status)
        
    def __init__(self, name):
        print "A critter has been born!"
            
        self.name = name
            
        Critter.total += 1
            
            
# main

print "Accessing the class attribute Critter.total:",
print Critter.total

print "\nCreating critters."

crit1 = Critter("critter 1")
crit2 = Critter("critter 2")
crit3 = Critter("critter 3")

Critter.status()

print "\nAccessing the class attribute through an object:",
print crit1.total

raw_input("\n\nPress the enter key to exit.")

About the error message: with your bad indentation, there was no __init__ method in class Critter. So the call crit1 = Critter("critter 1") passed the string argument "critter 1" to the object class, and finally to object.__new__ which creates a new object. Since python 3.0, this method does not accept any parameters but the calling class. Note that if you are using python >= 3, you must modify the print statements.

Thanks, that fixed that particular problem. But now I'M getting this error on line 33, by the way I'M using python 2.6

TypeError: unbound method status() must be called with Critter instance as first argument (got nothing instead)

lewashby 56 Junior Poster

In the following program, I'M getting the following error message when I try to run it.

TypeError: object.__new__() takes no parameters

# Classy Critter
# Demonstrates class attributes and static methods

class Critter(object):
    """A virtual pet"""
    total = 0
    
    
    def status():
        print "\nThe total number of critters is", Critter.total
        
        status = staticmethod(status)
        
        def __init__(self, name):
            print "A critter has been born!"
            
            self.name = name
            
            Critter.total += 1
            
            
# main

print "Accessing the class attribute Critter.total:",
print Critter.total

print "\nCreating critters."

crit1 = Critter("critter 1")
crit2 = Critter("critter 2")
crit3 = Critter("critter 3")

Critter.status()

print "\nAccessing the class attribute through an object:",
print crit1.total

raw_input("\n\nPress the enter key to exit.")

Could someone please tell me what's going on? Thanks for any and all replies. This code is from the book Pythong programming for the absolute beginner".

lewashby 56 Junior Poster

I've been trying to learn how to program for several years now. I've struggled with everything from C++, C#, to Python, but never got passed simple DOS text based screen programs that were very short. I'M now 24 and I work in a factory. I would love to find a carer filed with computers, but I'll take anything with heat and air.
I've heard that database programming is an easier thing to learn that general programming and that there is money to be made.
So my question is, is SQL/MySQL the right place for me to be and get started? And how long much learning will it take to get a job? Thanks for any and all answers.

lewashby 56 Junior Poster

Does anyone know how to get Wing IDE to work with iron python? But I would also like to keep quick access with WING IDE to my standard python as well. Thanks.

lewashby 56 Junior Poster

In the following program, at what point does my program call the _str__ method/constructor? I don't see it specifically being called at any point. I know it happens with this line print

"Printing crit1:"
print crit1

but I still don't see how or when this happens. Thanks for any and all help.

# Attribute Critter
# Demonstrates creating and accessing object attributes

class Critter(object):
    """A virtuaal pet"""
    def __init__(self, name):
        print "A new critter has been born!"
        
        self.name = name
        
    def __str__(self):
        rep = "Critter object\n"
        rep += "name: " + self.name + "\n"
        return rep
    
    def talk(self):
        print "Hi. I'm", self.name, "\n"
        
# main

crit1 = Critter("Poochie")
crit1.talk()

crit2 = Critter("Randolph") 
crit2.talk()

print "Printing crit1:"
print crit1

print "Directly accessing crit1.name:"
print crit1.name

raw_input("\n\nPress the enter key to exit.")
lewashby 56 Junior Poster

How do I get my python code to compile one line at a time so I can see exactly how the code works. If anyone knows how to do this with Wing IDE that would also be helpful. Thanks.

lewashby 56 Junior Poster

These three things are holding me back.

1. The new style class object parameter -

class MyClass(object)

Note that I'M also also not familir with the old style

2. The

_init_(

- constructor, or any constructs for that matter.

3. The

(self)

parameter. How is it different from the normal parameters or arguments?

lewashby 56 Junior Poster

I'M reading the book "Python Programing second edition for the absolute beginner". While explaining the object paramater whithin a class, this how it reads.

Base your class on object , a fundamental, built-in type.

Can someone please tell me what that means?
Thanks.

lewashby 56 Junior Poster

Does anyone know where I can find a goo pdf python reference for the following?

pre built constructors,

functions/methods for the follwoing

tuples, lists, dicts...etc

I hate reading a book with nothing but quick explanation, I want to see them for myself. And I already know how to find them using dir().
Thanks for any and all help.

lewashby 56 Junior Poster

Has anyone red "Microsoft XNA Game Studio 2.0"? I'M having a really hard time with it. From the get go, the book doesn't explain what to do with the code. It instructs me to alter a Draw() function, near the bottom of the code and then later wants me to make an new one at the top. It doesn't say, take out the old one, add the new one to the old, it just says look how this one is different from the other one. Obviously I cant compile the program like this. Has anyone else figured out how to read this book?

lewashby 56 Junior Poster

First of all, I'M reading the book "Microsoft XNA Game Studio 2.0". I understand the error I'M getting but I don't know what to do about it. The error says I can't use backgroundColor before it has been declared. I'M following along with the book so I don't see why I would be having these problems to begin with.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace MoodLight
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// UnloadContent will be called once per game …
lewashby 56 Junior Poster

I am currently reading two books, one on PHP and one on Python. Not that I'M good at ether. I'M about half way through the book on PHP or less and almost done with the one on Python. Though I haven't actually read anything web related in this particular Python book, I am aware that it can do web programming. My question is, which is better. Could I should I go ahead and drop the book on PHP considering that Python can do web programming as well as regular computer programming? Or does PHP have enough of an advantage to keep it up as well? Thanks.

lewashby 56 Junior Poster

I recently posted a very small program the uses pygame and the livewires package but was unable to get the program to run. I think the Title for that posting was Graphics Window or something close to that anyway. Since I can't resolve that problem, does anyone have any suggestions as to another way I could use pygame along with the livewires packege to accomplish that task? Thanks.

lewashby 56 Junior Poster

I am reading the book "Python Programming 2nd Ed. for the absolute beginner" and I am having some trouble with a very simple program. I was instructed to download and install pygame and the livewires package as I have done. This program is meant to display a grahical window, that's it. But I'M getting the following error with the following code.

AttributeError: 'module' object has no attribute 'init' on line 6

# New Graphics Window
# Demonstrates creating a graphics window

from livewires import games

games.init(screen_width = 640, screen_height = 480, fps = 50)

games.Screen.mainloop()
lewashby 56 Junior Poster

LiveWires is a pretty well dated Python course that uses a module called games as a wrapper for PyGame. It is supposed to make the use of PyGame easier for the beginner.

Looking over the module games.py, there is no init() method, unless there is a much newer version out.

I wonder why my book "Python Programming 2nd Ed. for the absolute beginner" gave me that program. This is frustrating.

lewashby 56 Junior Poster

I have installed pygame and livewires but am getting the following error with the following short program that I got from my python book.

AttributeError: 'module' object has no attribute 'init'

# New Graphics Window
# Demonstrates creating a graphics window

from livewires import games

games.init(screen_width = 640, screen_height = 480, fps = 50)

games.Screen.mainloop()
lewashby 56 Junior Poster

How do you know when to use a function by wraping the content between parentheses "function(x) or through dot notation x.function()
? thanks.

lewashby 56 Junior Poster

I got the book Torque for teens but I can't follow along with the book because it instructs me to copy the folder \example into itself and rename it to \experiment. The books says it's located in whatever directory I installed torque into and then \Torque\SDK\example
But I can't find it anywhere. Can someone help me please? Thanks.

lewashby 56 Junior Poster

I the following program, can someone please explain these two lines. "def __init__(self, master):, & Frame.__init__(self, master)"

One other thing. Shouldn't the method "update_count" use a return to return the new count? thanks.

# Click Counter
# Demonstrates binding an event with an event handler

from Tkinter import *

class Application(Frame):
    """GUI application which counts button clicks. """
    def __init__(self, master):
        """ Initialize the frame. """
        Frame.__init__(self, master)
        self.grid()
        self.bttn_clicks = 0    # the number of button clicks
        self.create_widget()
        
    def create_widget(self):
        """ Create button which displays number of clicks. """
        self.bttn = Button(self)
        self.bttn["text"] = "Total Clicks: 0"
        self.bttn["command"] = self.update_count
        self.bttn.grid()
        
    def update_count(self):
        """Increase click count and display new total. """
        self.bttn_clicks += 1
        self.bttn["text"] = "Total Clicks: " + str(self.bttn_clicks)
        
# main
root = Tk()
root.title("Click Counter")
root.geometry("200x50")

app = Application(root)

root.mainloop()
lewashby 56 Junior Poster

I more than half way through the book "Python programming for the absolute beginner" 2nd Ed. and things are really starting to get hairy. The book has me to write some code just before or after explaining each part. But I have to really concentrate on the paragraph I'M reading and jump back a few pages to see how and what part my code is doing in another part of the program. And I still sometimes get very frustrated and confused. Classes, Objects, Attributes, Constructors, privet & public, (self), (object)??? I think they need to brake programming books into at least two parts. The first without any OOP but that goes all the way through what it take to write programs, and a second one that teaches OOP and builds from the last book.
Does anyone have any good suggestions how how to learn this material? I feel like I need to see all the code beside the output/end result with lines going everywhere to I can follow every line of code.
I'M just tired of getting this frustrated. I gave up on C++ a long time ago. I think I gave up when I got to pointers but I know I was long lost before that. Thanks.

lewashby 56 Junior Poster

I more than half way through the book "Python programming for the absolute beginner" 2nd Ed. and things are really starting to get hairy. The book has me to write some code just before or after explaining each part. But I have to really concentrate on the paragraph I'M reading and jump back a few pages to see how and what part my code is doing in another part of the program. And I still sometimes get very frustrated and confused. Classes, Objects, Attributes, Constructors, privet & public??? I think they need to brake programming books into at least two parts. The first without any OOP but that goes all the way through what it take to write programs, and a second one that teaches OOP and builds from the last book.
Does anyone have any good suggestions how how to learn this material? I feel like I need to see all the code beside the output/end result with lines going everywhere to I can follow every line of code.
I'M just tired of getting this frustrated. I gave up on C++ a long time ago. I think I gave up when I got to pointers but I know I was long lost before that. Thanks.

lewashby 56 Junior Poster

In the program below, how does the value "Poochie" know where to go in the line

crit = Critter("Poochie")

And how do the get_name and set_name functions know when to do their thing, they don't seem to get called or anything? Thanks.

# Property Critter
# Demonstrates get and set methods and properties

class Critter(object):
    """A virtual pet"""
    def __init__(self, name):
        print "A new critter has been born!"
        self.__name = name
        
    def get_name(self):
        return self.__name
    
    def set_name(self, new_name):
        if new_name == "":
            print "A critter's name can't be the emty string."
        else:
            self.__name = new_name
            
    name = property(get_name, set_name)
    
    def talk(self):
        print "\nHi, I'm", self.name
        
# main
crit = Critter("Poochie")
crit.talk()

print "\nMy critter's name is:",
print crit.name
print "\nAttempting to change my critter's name."
crit.name = "Randolph"

crit.talk()

raw_input("\n\nPress the enter key to exit.")
lewashby 56 Junior Poster

In the following code, in the method

talk(self)

,

self.name

. What self is self.name referring to? I though variables created in functions and methods are only good within that method or function. But here it looks like it's talking to

__init__

&

__str__

. Can someone please explain? It's starting to get complicated and frustrating now. Thanks.

# Attribute Critter
# Demonstrates creating and accessing object attributes

class Critter(object):
    """A virtual pet"""
    def __init__(self, name):
        print "A new critter has been born!"
        self.name = name
        
    def __str__(self):
        rep = "Critter object\n"
        rep += "name: " + self.name + "\n"
        return rep
    
    def talk(self):
        print "Hi. I'M", self.name, "\n"
        
# main
crit1 = Critter("Poochie")
crit1.talk()

crit2 = Critter("Randolph")
crit2.talk()

print "Printing crit1:"
print crit1

print "Directly accessing crit1.name:"
print crit1.name

raw_input("\n\nPress the enter key to exit.")
lewashby 56 Junior Poster

Oh okay, thanks.

lewashby 56 Junior Poster

I'M reading a book on Python and my very first object/constructor program isn't show the output that the book is showing. I lacks the two lines "A new critter has been born!"

# Constructor Critter
# Demonstrates constructors

class Critter(object):
    """A virtual pet"""
    def _init_(self):
        print "A new critter has been born!"
        
    def talk(self):
        print "\nHi. I'm an instance of class Critter."
        
# main
crit1 = Critter()
crit2 = Critter()

crit1.talk()
crit2.talk()

raw_input("\n\nPress the enter key to exit.")

So what are objects all about anyway? It looks to me like a long complicated way of walling a function or method.

lewashby 56 Junior Poster

In the code below, the only part I'M having trouble with is word[position]. I know this is something really simple but I've always had trouble understanding these kinds of statements. I know that it print a random letter (position) from (word). What I don't know is why or how it does that. That's the part that never seems to get explained to me. How can you just put [], or sometimes (), around part of a statement and everything just work right? Thanks.

# Random Access
# Demonstrates string indexing

import random

word = "index"
print "The word is: ", word, "\n"

high = len(word)
low = -len(word)

for i in range(10):
    position = random.randrange(low, high)
    print "word[", position, "]\t", word[position]

raw_input("\n\nPress the enter key to exit.")
lewashby 56 Junior Poster

In the code below, the only part I'M having trouble with is word[position]. I know this is something really simple but I've always had trouble understanding these kinds of statements. I know that it prints a random letter (position) from (word). What I don't know is why or how it does that. That's the part that never seems to get explained to me. How can you just put [] around part of a statement and everything just work right? Thanks. Please don't give me an answer like "because that's what's it mad to do. Explain it to me.

# Random Access
# Demonstrates string indexing

import random

word = "index"
print "The word is: ", word, "\n"

high = len(word)
low = -len(word)

for i in range(10):
    position = random.randrange(low, high)
    print "word[", position, "]\t", word[position]

raw_input("\n\nPress the enter key to exit.")
lewashby 56 Junior Poster

In the program be below, I'M having trouble with these few lines, remember, I'M new.

What's going on here? I'M just a little confused because there is (word) wraped in len().

position = random.randrange(len(word))

And what's going on with these two lines? Thanks.

jumble += word[position]
    word = word[:position] + word[(position + 1):]
# Word Jumble
#
# The computer picks a random word and then "jumbles" it
# The player has to guess the original word

import random

# create a sequence of words to choose from
WORDS = ("python", "jumble", "easy", "difficult", "answer", "xylophone")

# pick one word randomly from the sequence
word = random.choice(WORDS)

# create a variable to use later to see if the guess is correct
correct = word

# create a jumbled version of the word
jumble = ""

while word:
    position = random.randrange(len(word))
    
    jumble += word[position]
    word = word[:position] + word[(position + 1):]
    
# start the game
print \
"""

            Welcome to Word Jumble!
            
        Unscramble the letters to make a word.
    (Press the enter key at the promt to quit.)
"""
print "The jumble is:", jumble

guess = raw_input("\nYour guess: ")
guess = guess.lower()

while(guess != correct) and (guess != ""):
    print "Sorry, that's not it."
    guess = raw_input("Your guess: ")
    guess = guess.lower()
    
if guess == correct:
    print "That's it! You guessed it!\n"
    
print "Thanks for playing."

raw_input("\n\nPress the enter key to exit.")