[Tutor] newbie Questions

2012-07-16 Thread Matthew Ngaha
Hi all. I'm new to Python and Programming in general. I've started out with
Python for beginners, and so far so good. My friend who i might add, is not
a programmer but has had experience in the world of programming (i dont
know how much but he claims a lot), has told me to forget about Python and
focus on PHP. He knows i studied a HTML and CSS course and told me for the
direction i'm going in, Python is not needed and won't give me all the
options or variety PHP can. Thats he's opinion, i'd rather make my own mind
up, but its lead me to these questions out of curiousity:

a) at this early stage i dont exactly know what web options are:(  but is
Python limited when it comes to matters relating to Web options/developing?
b) Are there better options, or can Python get the job done as good as any?
c) after completing and understanding a beginner's book, would i be at
intermediate level, or still below?
d) Would i need a more advanced tutorial, what do you advise after
finishing a beginners course?

e) And finally, are there other essential things i must learn after Python?
i heard Django is important?
f) is Django the equivelent to PHP's MySql?

You dont have to answer all questions. Just answering one would help me
greatly in my future decisions, as i want to commit fully to the right
programming language.

since this isnt a forum, how can i thank everyone for helping?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie Questions

2012-07-16 Thread Matthew Ngaha
Thanks guys, i didnt think i would get so many kind and helpful responses.
I am so grateful:x. I have read each and every reply and i am now very
confident in the direction i need to take. Everything is a lot clearer now.
Even though i'm new to programming, i am very intrigued by it and want to
dedicate a good portion of my time to it, and by reading the replies, i
know ive made the right choice in choosing Python over PHP:) To answer a
question on what was more important, a job that pays low, or to learn good
clean coding.. My answer is I want to devote my time in it for a love of
programming and to gain a deeper understanding on it. the money part is not
as important:)The book i am currently reading is "Python Programming for
the absolute beginner". I will save this mail in a special place on my hard
drive:) i really appreciate it guys:)


On Mon, Jul 16, 2012 at 4:16 PM, Alexandre Zani wrote:

> On Mon, Jul 16, 2012 at 5:09 AM, Matthew Ngaha 
> wrote:
> > Hi all. I'm new to Python and Programming in general. I've started out
> with
> > Python for beginners, and so far so good. My friend who i might add, is
> not
> > a programmer but has had experience in the world of programming (i dont
> know
> > how much but he claims a lot), has told me to forget about Python and
> focus
> > on PHP. He knows i studied a HTML and CSS course and told me for the
> > direction i'm going in, Python is not needed and won't give me all the
> > options or variety PHP can. Thats he's opinion, i'd rather make my own
> mind
> > up, but its lead me to these questions out of curiousity:
> >
> > a) at this early stage i dont exactly know what web options are:(  but is
> > Python limited when it comes to matters relating to Web
> options/developing?
>
> PHP will get you from 0 to website by the first page of your first
> tutorial. That's very attractive if you're interested in web
> programming. Most likely, if you use Python, you'll learn how to use
> the language more generally, before learning how to apply the language
> to a website. However, in my experience (I learned PHP a long time ago
> and Python a few years ago) Python gives you the most reward. I've
> used Python for website building, but also lots of other useful
> applications.
>
> > b) Are there better options, or can Python get the job done as good as
> any?
>
> It depends upon the job. If you plan on work as a programmer/software
> engineer, you will need to learn many languages. Yes, hammers can be
> used to put in screws and you could probably figure out how to use a
> screwdriver to put in a nail, but really, you're going to be
> successful if you have both a hammer and a screwdriver in your
> toolbox. Java, C, Python, C++, each have their own uses. However, (and
> this may be a biased assessment) PHP is more like a hammer with its
> head removed and a screwdriver duct-taped on it. Sure, you can use it,
> but it's not going to be a pleasant experience.
>
> The languages which I would say are closest to Python in terms of
> where they are put to use are Perl and Ruby. My advice is this: give
> them each a shot (the first couple pages of a tutorial shouldn't take
> more than a few hours) and see which makes you feel the most
> comfortable.
>
> > c) after completing and understanding a beginner's book, would i be at
> > intermediate level, or still below?
> > d) Would i need a more advanced tutorial, what do you advise after
> finishing
> > a beginners course?
>
> Code, code, code. Programming is a practice. You'll learn the most by
> doing and researching solutions for specific problems you are
> encountering. Then, read blog posts, watch PyCon videos, look at the
> mailing list etc... Just expose yourself to the language and community
> and learn through osmosis.
>
> >
> > e) And finally, are there other essential things i must learn after
> Python?
> > i heard Django is important?
>
> Django is just one way to do Python web development. It's hugely
> useful for some things and terribly useless for others. There are
> plenty of other ways to do web development.
>
> > f) is Django the equivelent to PHP's MySql?
>
> As plenty of people have said, Django is a way to make websites while
> MySQL is a database system. You can actually use MySQL with Django.
>
> >
> > You dont have to answer all questions. Just answering one would help me
> > greatly in my future decisions, as i want to commit fully to the right
> > programming language.
> >
> > since this isnt a forum, how can i thank everyone for helping?
> >
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-25 Thread Matthew Ngaha
>Hi Victoria. im a total beginner aswell but i noticed something. shouldnt this 
>line:

else: return s(0) == s(-1) and isPalindrome (s[1:-1])

be

 else: return s[0] == s[-1] and isPalindrome (s[1:-1])


it looks like you have the string s as a function which you are trying
to call. what you wanted was an index position right? which should be
s[] instead of s().

thanks for the help David. Sorry about the sent mail. Gmail is pretty
confusing for me:( ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] calculation issue.

2012-08-26 Thread Matthew Ngaha
Hi guys ive been reading a beginners book on python and the author
created a simple game with the liewires package. I understand the
explaination but there is just 1 part that i don't quite get. I'm not
great at maths but this isn't complex at all. i don't know if i should
post the whole code, cos' its only 1 line i don't get, so ill post
only relevant code and my comments inbetwen these lines "-" <- so
skim to those lines which are relevant. 1st here is the line of code i
don't get.

# sets buffer to approx 30% of pizza height, regardless of pizza speed
self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed) + 1

so the game is about a chef who drops pizzas from the top of a
building. Both chef and pizza are objects from a chef and pizza class.

- the pizza falls at a speed of 1. ---

class Pizza(games.Sprite):
---speed = 1
image = games.load_image("pizza.bmp")
def __init__(self, x, y = 90):
""" Initialize a Pizza object. """
super(Pizza, self).__init__(image = Pizza.image,
x = x, y = y,
--dy = Pizza.speed--
#dy is the verticle movement of the falling pizzas

--the pizza object is initilized in the chef class--
--self.tme_till_drop is the property i need help with-

class Chef(games.Sprite):
def __init__(self, y = 55, speed = 2, odds_change = 200):
""" Initialize the Chef object. """
super(Chef, self).__init__(image = Chef.image,
   x = games.screen.width / 2,
   y = y,
   dx = speed)

self.odds_change = odds_change
   self.time_til_drop = 0
self.check_drop() #this is the function that
determines timing of pizza drops

def check_drop(self):
""" Decrease countdown or drop pizza and reset countdown. """
if self.time_til_drop > 0:
self.time_til_drop -= 1
else:
new_pizza = Pizza(x = self.x) #positions the
pizza's x(horizontal positon) to match that of the chef's
games.screen.add(new_pizza)

# set buffer to approx 30% of pizza height, regardless of
pizza speed
self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed) + 1


i understand the code until the comment set buffer. No where in the
code does it say the pizza's height. Im guessing the height is the
actual pizza image's height in pixels. "pizza.bmp"

heres the code: self.time_til_drop = int(new_pizza.height * 1.3 /
Pizza.speed) + 1

so if, let's say the pizza height is 60(pixels). multiplying it by 1.3
gives me 78. dividing it by Pizza.speed seems pointless as Pizza.speed
is 1, and i will get 78 again. then adding one makes it 79. i don't
see how 79 is 30% of 60. 60 being the pizza's height. I know im
looking at it all wrong. Can anyone please help explain to me that
line of code and the authors calculation:(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calculation issue.

2012-08-26 Thread Matthew Ngaha
thanks guys.  Eryksun your explaination was brilliant and clear. i
understood what you explained but got a bit confused with this line:

The bottom of the next pizza is at y = 100 + 100 = 200

if this Pizza (pizza.b) was on hold at position y = 100 and the
previous pizza(pizza.a) had fallen an additional 132 pixels to 232
before pizza.b was released, shouldn't pizza.b still only be at
position y = 100? how did it gain the additional 100 pixels if it was
on hold while pizza.a reached 232. i understand how you've worked it
out, just need more clarification on how the Pizza.b fell an addition
100 pixels making its total distance 200.

Sorry Alan the code was rather big, i didnt want it to be  pain for
you guys trying to help. here is the full code. I do understand the
concept and what you've explained. i just want to fully understand the
method for when i dont have a book to hold my hand:) back to the code:

# Pizza Panic
# Player must catch falling pizzas before they hit the ground

from livewires import games, color
import random

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


class Pan(games.Sprite):
"""
A pan controlled by player to catch falling pizzas.
"""
image = games.load_image("pan.bmp")

def __init__(self):
""" Initialize Pan object and create Text object for score. """
super(Pan, self).__init__(image = Pan.image,
  x = games.mouse.x,
  bottom = games.screen.height)

self.score = games.Text(value = 0, size = 25, color = color.black,
top = 5, right = games.screen.width - 10)
games.screen.add(self.score)

def update(self):
""" Move to mouse x position. """
self.x = games.mouse.x

if self.left < 0:
self.left = 0

if self.right > games.screen.width:
self.right = games.screen.width

self.check_catch()

def check_catch(self):
""" Check if catch pizzas. """
for pizza in self.overlapping_sprites:
self.score.value += 10
self.score.right = games.screen.width - 10
pizza.handle_caught()


class Pizza(games.Sprite):
"""
A pizza which falls to the ground.
"""
image = games.load_image("pizza.bmp")
speed = 1

def __init__(self, x, y = 90):
""" Initialize a Pizza object. """
super(Pizza, self).__init__(image = Pizza.image,
x = x, y = y,
dy = Pizza.speed)

def update(self):
""" Check if bottom edge has reached screen bottom. """
if self.bottom > games.screen.height:
self.end_game()
self.destroy()

def handle_caught(self):
""" Destroy self if caught. """
self.destroy()

def end_game(self):
""" End the game. """
end_message = games.Message(value = "Game Over",
size = 90,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/2,
lifetime = 5 * games.screen.fps,
after_death = games.screen.quit)
games.screen.add(end_message)


class Chef(games.Sprite):
"""
A chef which moves left and right, dropping pizzas.
"""
image = games.load_image("chef.bmp")

def __init__(self, y = 55, speed = 2, odds_change = 200):
""" Initialize the Chef object. """
super(Chef, self).__init__(image = Chef.image,
   x = games.screen.width / 2,
   y = y,
   dx = speed)

self.odds_change = odds_change
self.time_til_drop = 0

def update(self):
""" Determine if direction needs to be reversed. """
if self.left < 0 or self.right > games.screen.width:
self.dx = -self.dx
elif random.randrange(self.odds_change) == 0:
   self.dx = -self.dx

self.check_drop()


def check_drop(self):
""" Decrease countdown or drop pizza and reset countdown. """
if self.time_til_drop > 0:
self.time_til_drop -= 1
else:
new_pizza = Pizza(x = self.x)
games.screen.add(new_pizza)

# set buffer to approx 30% of pizza height, regardless of
pizza speed
self.time_til_drop = int(new_pizza.height * 1.3 /
Pizza.speed) + 1


def main():
""" Play the game. """
wall_image = games.load_image("wall.jpg", transparent = False)
games.screen.background = wall_image

the_chef = Chef()
games.screen.add(the_chef)

the_pan = Pan()
games.screen.add(the_pan)

games.mouse.is_visible = False

games.screen.event_grab = True
games.screen.mainloop()

# start it up!
main()
_

[Tutor] help me decide

2012-09-04 Thread Matthew Ngaha
hey guys as i program more, i think of silly questions i would like
answers to. if anyone doesnt mind entertaining my question, please do
answer:) I have just about finished my beginner tutorial, just a few
exercises left. i feel confident using Python now but im still not
sure which direction i want to go in. I would at some point like to
learn how to use GUIs and a web Framework(Django). But i don't know
which of the 2 to start out with.

a) IF you happen to have used both, which one fills you with joy and
is more fun for you to program with, GUI programming, or web related /
Framework programming?

b) which was easier and less complex for you to learn? or should i say
had a lower learning curve? i ask this because the sooner i get an
understanding of one, i can maybe give the other one a go. But if it's
too hard i usually give 100% to it and never try learning anything
else until it computes.

my tutorial had a small section on tkinter. I have now looked for some
tutorials and noticed Python tutorials on both tkinter and Tk. As i
understand they are not the same thing but tkinter is like the
interface of Tk? my question is:

c) which tutorial would be better to study, Tkinter or Tk? and what
exactly is the difference? why do they have separate tutorials?

i looked at some pyQT articles, but its coding looks less organised
than Tkinter.

d) is this true? is Tkinter a lot more straight forward and Python friendly?

e) Does pyQT have grids (rows and columns) to place your widgets on
like Tkinter, or do you have to use x and y axis to position widgets
etc..?

Before i try to learn either, GUIs or a web Framework, i was looking
into maybe getting a deeper understanding of OOP. my tutorial only
covered it briefly.

f) would this be a good idea tackling OOP next before the other 2, or
is this a skill you master with more programming experience?

ok my last question is not so important:) im just curious as i grow
more fond of programming. well i keep reading Python is an all-purpose
general programming language(web frameworks, desktop apps,
science/maths etc..). I notice Java has similar features so should
also be considered an all-purpose general programming language. my
question is:

g) not a comparison in 1 specific area, but which language is better
or more suited to all around all-purpose quality.

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


Re: [Tutor] help me decide

2012-09-04 Thread Matthew Ngaha
sorry wrong i didnt send mail right.

hey i didnt explain it properly, i wasn't asking what language to use
 or learn. I am only going to be using Python. I meant whic area to
 study on 1st, GUI programing e.g Tkinter or Programming with a web
 framwork e.g Django.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help me decide

2012-09-04 Thread Matthew Ngaha
hey you didnt read my question:( i dont enjoy either because i have no
experience with them. so im asking questions about peoples personal
experiences with the 2 areas which can give me further information to
research on.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help me decide

2012-09-05 Thread Matthew Ngaha
Hi Alan thanks so much for your helpful answers.

> probably wxPython or GTk
> But if you want to get serious about GUIs I'd probably suggest wxPython
> instead - it ultimately is more powerful and complete and if you are only
> just starting will be easy to learn whereas  learning Tkinter and converting
> is more difficult (IMHO).

> PyQt is powerful too but there are several limitations in its licensing
> model that leave me slightly wary. Gtk is another option. Both of these were
> originally made popular in the Linux community but both are available cross
> platform now. (as are Tkinter and wxPython)

After your response ive decided GUI programming is defintely better
for me at this stage. I read Pyside is a replica of pyqt, same makers
qt but it covers all the licensing that PyQt doesnt, and if you learn
1 the other is almost exactly the same. Would this be a good enough
reason to give it and pyqt a try? how does it compare to wxPython?

also please could you tell me why you suggest wxPython over GTK? what
are the factors you looked at, is it better for beginners to start out
with a simpler toolkit and decide later on if its enough for them?

would you say out of the GUIs we have mentioned, apart from Tkinter,
that wxPython is the easiet to pick up yet a lot more complete than
Tkinter?

> I'm not a big fan of user interface programming in any shape. I started my
> career writing embedded software where the UI was a switch and some LEDs. So
> i am more interested in the internals of a program than in its outer
> appearance, but from necessity I've done a little bit of GUI work and even
> less web work.

this has interested me. is embedded programming a different field to
the type of programming in Python? it sounds like thats more lower
level prgroamming better suited to a language like C? is your work
today still related to this area? somewhere down the learn, after i
have mastered Python i'd definately like to learn about internals of a
program, even though the thought of that really scares me:)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help me decide

2012-09-06 Thread Matthew Ngaha
hey guys i just like to thank everyone for their input. Its really
helped me in deciding a lot of things. also @ Alan i think? as ive
started writing this mail it won;t let me look up previous senders but
thanks for your input. Also your field of work sounds very interesting
indeed. I can't dare to imagine the amount of hard work that got you
there.:) i only hope my dedication can take me half as far:)

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


Re: [Tutor] I need Help

2012-09-08 Thread Matthew Ngaha
this is the same book i bought a few months ago to get me started. the
instructions i remember where clear for windows. if there is a problem
with the download files on the site, the author has the files on his
own site also:

http://www.programgames.com/page4.html

save or run the file, once installed go to your start menu, choose All
Programs, choose Python 3.1, then choose IDLE(Python GUI)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I Need Help - further details now provided.

2012-09-09 Thread Matthew Ngaha
SORRY i wrote to you not the mailing list:(

im a beginner myself, and those instructions seem very complicated for
 me. But i did install Python and everything included with no problem.
 You need at least Python 3.1 for this book we have. its what the
 author recommended. version 2.7 as you have shown in the link is too
 old as it has different syntax. Try downloading Python from the link i
 included, you will have no trouble installing IDLE with this link.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] web frameworks

2012-09-09 Thread Matthew Ngaha
Hi all, i had a recent post about learning about guis and web
applications. i decided to try guis 1st, but i also decided that maybe
a very very very simple web framework would not be too much work for
me to study once in  while. I decided on Flask because i read it's the
simpliest framework out of all the others i've researched, only to
find out it's not supported on Python 3:(.. i wondered if someone with
experience can tell me, in their opinion a framework with a similar
learning curve to Flask that a beginner can easily understand and is
supported on Python 3. i thought cherrypy, but was told it's not
nearly as simple as Flask, and since my main focus is learning GUIs, a
simple web framework will be ideal only to understand how they work. i
understand Javascript  only a little, but html and css a bit better
etc..

also is mod_python similar to a framework? does it perform the same
tasks and also make good web applications? would this be a better
option?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web frameworks

2012-09-09 Thread Matthew Ngaha
sorry steven i keep replying to sender and not tutor:(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I Need Help - further details now provided.

2012-09-09 Thread Matthew Ngaha
> What instructions are you talking about?
>
> I'm sure that was very clear in your head when you wrote that, but think
> about how it looks to us. We could be reading your email hours, days,
> even months later. We see your comment about complicated instructions,
> but all context is lost and we have no idea what instructions you mean.
> You could be taking about anything.
>

sorry i havent gotten a hand of how the emails work. i thought the
original question from the sender and all corresponding emails would
still be visible for all to see, so i tried to shorten my mail. I was
trying to help someone having problems with IDLE. He showed a set of
instructions that didnt make sense to me as i didnt have to go through
that when installing IDLE.

Hi  Alan Gauld.

the book 'Python for the absolute beginner' is the best thing to ever
happen to me. The instructions that the original sender provided is
not from this book, i honestly do not know where the text is from, but
the book was very clear on how to install Python, providing a direct
link also. Im sure this beginner book will be of no use to you:) but
its an exciting read.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web frameworks

2012-09-09 Thread Matthew Ngaha
thanks for all the help guys. Cherrypy it is. i will take a look at
some cgi tutorials first, as Alan suggested, to get a good
understanding of how things work.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] simon says

2012-09-10 Thread Matthew Ngaha
hi guy my book has set me an assignment of a simon says game but i
don't really understand what it's asking me to do. here's the text:

write a version of the simon says game where a player has to repeat an
ever-growing, random sequence of colours and sounds using the
keyboard.

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


Re: [Tutor] simon says

2012-09-10 Thread Matthew Ngaha
> You should read up on the Simon Says rules and such. It's an
> established, old game. Once you get that, then work on replicating it
> through software.
>

thanks for your input. i understand Simon Says. I'm just struggling to
see the connection with the assignment. a sequence of colours and
sounds using the keyboard. I 'm trying to understand how this relates
to the game
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] simon says

2012-09-10 Thread Matthew Ngaha
>> hi guy my book has set me an assignment of a simon says game but i
>> don't really understand what it's asking me to do. here's the text:

It's the last chapter of Python Prgogramming for the absolute
beginner. they have covered all the basics. Even simple tkinter apps
and Pygame games. If i understand what the task was asking me to do,
im confident , even though i might struggle, that in the end i could
do it. But i simply don't understand what this task is asking for. It
doesn't sound similar to Simon Says
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] simon says

2012-09-10 Thread Matthew Ngaha
> This seems less about "simon says" the social game, and more about
> "simon", the 1980s electronic toy.
>
> That toy had four colored buttons that would light up in a sequence,
> playing a tone for each color.  The player would then have to press
> the buttons in the same sequence.  The game would then replay the
> sequence and add an additional step.  Player would have to enter the
> longer sequence in.  Continue until player loses (and game made an
> angry buzz).
>
> It was quite addictive.

this sounds like a lot of fun! time to think about how i will go about
this:) Thanks for making it clear.

Also @ Emile, thanks for the link.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] simon says

2012-09-11 Thread Matthew Ngaha
> Sounds as though what is wanted in a Pythonic version of an early electronic 
> game "Simon" that was marketed back in the late 70's.  It was roughly Frisbee 
> shaped although slightly larger.  The top was divided into four 
> quadrant-shaped paddles each of a different color.  The game consisted of 
> Simon generating longer and longer sequences of random color-sound flashes 
> (each element in the sequence consisted of a momentary sound accompanied by 
> the appropriate quadrant lighting up).  After Simon had generated a sequence, 
> the player had to duplicate it by pressing the paddles.  A successful 
> recreation of a sequence was rewarded by Simon generating a longer one, until 
> the player finally screwed up.  At that point Simon made an electronic rude 
> noise and the device was handed on to the next player if there were multiple 
> players.  The player who succeeded in matching the longest sequence was the 
> winner of that round.
>
> I'll bet ebay still has them for sale, and Google would get you a description 
> that would be better than mine.
>
> -Bill

Thanks Bill. I did some more searching and managed to find a few new
versions on youtube with altered gameplay i guess. Here's the closest
to what has been described here:

http://www.youtube.com/watch?v=agUABjGAJww

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


[Tutor] setting a timer

2012-09-12 Thread Matthew Ngaha
i have a way to set a timer for creating new objects copied from a
book but as i have started my next exercise in a very different way, i
want to avoid that math method/formula as it will cause me to
rearrange some classes totally...

i tried a simple method but its not working. any ideas? heres my code,
ill leave out the irrelevant code.

class Game(object):
interval = 0

def play(self):
Game.interval = 40
while Game.interval > 0:
self.count_down()

def count_down(self):
Game.interval -= 1

so the play() method gives interval a value of 40. the while loop
should reduce interval by 1 everytime it calls the count_down()
method. The problem is this is happening instantly. i've even put the
Game.interval value as high as 5 and it reaches 0 instantly.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] setting a timer

2012-09-12 Thread Matthew Ngaha
> Get a slower computer.
>
> I expect that if you find an old Commodore 64 from 1982, or perhaps
> an 1984 Apple Macintosh, it might be slow enough for your count down
> idea to work. But with modern computers, counting up to, or down from,
> 5 is more or less instantaneous in human terms.
>
> A better way to pause for a moment is this:
>
> import time
> time.sleep(0.1)  # pause for 0.1 second
> time.sleep(60)  # pause for 1 minutes

hah do u think i could find one of those on ebay???

i wasnt aware of the time module! thanks a lot for your help:)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] simon game issues

2012-09-13 Thread Matthew Ngaha
Hi guys. my Python tutorial set me a task to recreate a simon game
using livewires.
http://www.youtube.com/watch?v=agUABjGAJww
this is quite long, i understand if you can't help right away

summary:
i create 4 squared shaped objects(red, blue, green, yellow) as
instances for a class derived from the Sprite class
i create 4 animation objects to represent the 4 colour shaped objects.
the animations get brighter in colour so the user can understand which
colour he has to follow
the animations also light up when the user presses the keyboard key
they are assigned too.
they are instances for a class derived from the Animation class.
i have also included 4 sound files, assigned to 1 animation object to
be played each time that animation lights up

My problems:
everytime i want to play a sequence for the user to follow. i run into
this problem. i create 1 animation say red, so the user can see the
1st colour he has to follow. then i put a timed delay time.sleep(1)
before i display the next animation, say blue. i have tried many other
timing methods to achieve this, but once there is some sort of timer,
the whole screen pauses for the duration of the timed delay (but the
sound files play simultaneously during that freeze) then after that,
the sequence is displayed at the same time. not 1 after the other. so
even though i put the timer after the creation of the 1st animation,
the timer for some reason happens before it. is there a way i can get
around this?

I also start the game/program by displaying the 4 square objects
(Sprite Class) before adding their animation. after the creation of
the sprites i play the animation sequence. The problem is they play as
soon as the game starts before the Sprites are even displayed, and
also simultaneously (not in a sequnce) making it confusng. so after
creating the sprites, i added a timer so the animations happens after
the sprites are shown. But again because of this timer, which is meant
to occur after the creation of the sprites, when i start the game, i
get a blank screen for the duration of the timer((but the sound files,
again play simultaneously during that time). After that i still don't
get the sprites, i get their animatons instead, then finally the
sprites are displayed. i dont understand, the Sprites are meant to be
the 1st things on the screen, is there a solution?

Getting user input:
the last problem i have is when the user presses a key to select a
colour. i have the script check for the key press, then return the
colour to a function/method called def result(self, color): that
determines if he got the right colour. if he does i increase score by
1. to check results i create 2 lists. one with all 4 colours:

self.animation = [Pressed.dict_red, Pressed.dict_blue,
Pressed.dict_green, Pressed.dict_yellow]
then i create an empty list to append the sequence in the order i
randomly played them, so i can check if the user got each colour:
self.get_animation = [] < they append from the 1st list above and my
result function uses it to check colours

here's how it goes.
if keyboard for colour red is pressed:
create red animation:
send results back to result method: self.game.result(red)

my result method and its class:
self.stage = 3   ..#say if we were on stage 3. i would play 3
colours. stage 4 would be 4 colours

self.counter = -1 .#to correctly index list
def result(self, COLOUR):
self.counter += 1#count is now at 0
self.end_testing = self.stage..#this will count down from
the stages value. once it reaches 0, there is no more colours to check
for

if COLOUR in self.get_animation[self.counter]:
self.score.value += 1
self.end_testing -= 1

even though i am using a counter here to count down: self.end_testing
< i have used while and for loops also. My problem is none of these
work because a keypress from the user, even if tapped, registers as
multiple key presses, the self.score that i increment by 1 flies to
about 40 from 1 key press. as a result my counter i use to index the
list is way out of range. i tried to add a time.sleep(.03) as soon as
a key is pressed, so it would register once. it managed to limit it to
4 presses, so self.score would equal 4 after 1 press, 8 after 2.. in
that i started my counter at -4. then the code self.counter /= 4 would
give me 0. after the next 4 presses, my counter would be at 4, the
same code self.counter /= 4 would give me 1. after the next 4 presses,
my counter would be at 8, the same code self.counter /= 4 would give
me 2. this successfully fixed my indexing issue, but it needs A LOT of
if statements and it is getting to confusing. isnt there a way to make
1 key press mean 1? and not 40? other wise how can i keep track of the
score. any help? do i quit this exercise and blame it on the program
just not following my instructions?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python

Re: [Tutor] simon game issues

2012-09-14 Thread Matthew Ngaha
> It would appear you're running some form of event loop, such as
> wxpython, tkinter, pygame, or whatever.  If so, you have to do your
> delays using the mechanism that system defines, not using sleep().  As
> you've discovered, sleep() stops the whole thread, and that's not what
> you want.  What you want is to set an event to fire at some measured
> time in the future, so the actual waiting is done inside the event loop.
>

hey i looked at the livewires documentation and pulled up the timer
information. im struggling to figure out how to use its explanation. i
need to use it at 2 different parts of the program. 1st when the game
starts i need to create my sprite objects so they appear before my
animation objects:

red = Sprite(colour = Colours.red, x = 250, y = 255)
games.screen.add(red)

#timer event delay goes here so the animations don't start as soon as
the game is opened, before the coloured sprites as they've been doing.

self.create_animations()
-


i also need a timer event when i display my sequence of animation
objects so they dont show on screen simultaneously. so:

#1st animation
red_animation = Animation(images = c_red, x = 250, y = 255,
 repeat_interval = 4, n_repeats = 1)
games.screen.add(red_ani)
red_sound.play()

#Timer event to go here, so next animation in sequence goes after the
timed pause.

#2nd animation
blue_animation = Animation(images = c_blue, x = 373, y = 255,
   repeat_interval = 4, n_repeats = 1)
games.screen.add(blue_ani)
blue_sound.play()

do you think you can offer any help how to implement the timer code or
function? i will provide the link to the page, but here's the relevant
code:


Timer
The Timer class is a class you can add to something which is also a
subclass of Object, to make an object that performs actions at regular
intervals. A class which is intended to be used with another class is
called a mix-in. For instance, if you wanted to make a new class of
your own which was a Circle and also a Timer, you would define the
class by saying class MyClass (games.Circle, games.Timer):
 • init_timer (interval)

interval is how often the tick method is called, measured in timer
ticks. How long a tick is depends on the fps argument you give to the
Screen‘s mainloop method. Setting fps to 50 means a tick is 1/50 of a
second.

You must call this method emph{after} you have called the init_ method
for the Object subclass you are using.

• stop ()

Stop the timer running. It continues to exist, but doesn’t count any more.

• start ()

Starts the timer again. A full interval will elapse before it ticks.

• get_interval ()

Gets the current interval.

• set_interval (interval)

Sets the current interval.

• tick ()

This method must be supplied by you, by subclassing the Timer class.

http://www.geon.wz.cz/livewires/w-livewires.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Relative import help

2012-09-22 Thread Matthew Ngaha
i have an assignment from a book to practice implementing  relative
imports. it gave a very clear and easy to follow explanation, but my
results are proving the instructions are wrong. here's what i have
tried. my folder structure:

Project /

   __init__.py
   main.py
   Domestic /

  __init__.py
  players.py
  premier_leauge.py
  silverware.py
  Europe /

 __init__.py
 champions_league.py
 europa.py
 winners.py
 Internationals /

__init__.py
nations.py

its easy to use the normal import method to import something further
down the directory, but when trying to go up, nothing works. heres
something weird. winner.py in the Europe directory, i used this code
to try and import a class named Silverware in silverware.py 1
directory up:

from ..silverware import Silverware
heres my error mesages: ...  ValueError: Attempted relative import in
non-package

i can accept this and say i did something wrong, but i left the
import statement even with the error. now my main.py in the 1st
directory called Project. i imported winner.py. the file that got this
error message. And by importing this file, i have access to
silverware.py. i can access everything in this file through that old
import statement:

from ..silverware import Silverware
so why is it this statement wont allow me to import silverware.py to
winner.py directly, but still gives access to winner.py if winner.py
is imported from a directory on the same level or further up from
silverware.py? this is the exact code instructions my book gave me,
why isn't it working for files futher down?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Relative import help

2012-09-22 Thread Matthew Ngaha
> Not impossible, but I doubt that.
>
> Have you followed the instructions *exactly*? If not, you have
> probably missed something. What book is it?
>
> Otherwise, the book and you are probably using different versions of
> Python. What version of Python are you using, and what is the book
> using?

the book always indicates its using Python 3, but never actually
states which version of Python 3. The name of the book itself is
called Python 3 Object Oriented Programming. I'm i am using Python
3.1. i followed the instructions as the book instructed, creating the
same folder structure etc. It came out in 2010, im not really sure
which was the current Python version at that time.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Relative import help

2012-09-22 Thread Matthew Ngaha
> You probably have a path that reaches into Domestic or Europe sub-package.
> That can happen if e. g. Project/Domestic/Europe is your current working
> directory.
>
> Try to cd into the Project folder's parent directory and see if
>
> $ python -c 'import Project.Domestic.Europe.winners'
>
> works.

hey i am very new to programming:) what do you mean by Try to cd? how
and where should i do that to type the code you provided?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Relative import help

2012-09-22 Thread Matthew Ngaha
> try
> import ../my_module
> instead of
> import ..my_module
> and see what happens.
> Your problem may be just that you haven't included the separator.
>
> .. means one directory higher but you must separate it from the file name.
>
> Two directories higher would be
> ../../my_module


sadly this was invalid syntax:(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Relative import help

2012-09-22 Thread Matthew Ngaha
> cd is a shell command;  you do it before starting Python.  You didn't
> mention what OS you're running, but cd should be about the same for
> Linux, Windows, or Mac.

im on windows. i always start Python via IDLE. ive never started it
for editing though the shell, run > cmd etc? ill type that into the
cmd but im not sure ill know how to work with Python after as ive
never used it through shell:(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Relative import help

2012-09-22 Thread Matthew Ngaha
> You probably have a path that reaches into Domestic or Europe sub-package.
> That can happen if e. g. Project/Domestic/Europe is your current working
> directory.
>
> Try to cd into the Project folder's parent directory and see if
>
> $ python -c 'import Project.Domestic.Europe.winners'
>
> works.

ive got into the parent directory and typed this code both in cmd, and
 my python file. niether seems to work. on idle i get invalid syntax
 error. im on windows
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Relative import help

2012-09-22 Thread Matthew Ngaha
> You had forward slashes in your description of the folder layout, so I
> assumed you were on a linux box or a mac. I think I have now learned the
> lesson and will make fewer assumptions in the future.
>
> First, in idle's "shell" window type
>
 import sys
 print(sys.executable)
>
> (dont' type the ">>>", that will appear automatically) This should print
> something like
>
> C:\python32\python3.exe
>
> Now use Windows Explorer to navigate to the parent folder of "Project" and
> follow the instructions on
>
> http://www.windows7hacker.com/index.php/2009/08/how-to-open-dos-prompt-
> command-here-in-windows-7-and-more/
>
> (hold the shift key and right-click, then choose [Open Command Window Here])
>
> You should now see an ugly little black box. Type in
>
> C:\python32\python3 -c 'import Project.Domestic.Europe.winners'
>
> but remember to replace C:\python32\python3 with the actual contents of
> sys.executable.
>
> Whew ;)

:p.. whew!! well i followed your instructions and everything went well
with inputting the sys.executable into my Project's cmd shell. Sadly
my winners.py still can't directly access silverware.py in the
directory further up. Not to worry though, i spent all of yesterday
and most of today trying to get it to work, im mentally tired with
this import stuff, i just want to work through the rest of the book
now:) Thats whats important. maybe i'll revisit relative importing
when i actually need to use it. I'm still a far way away from those
types of projects as im still reading beginner tutorials, and the
normal absolute imports seem to be doing just fine. Thanks for all
your help and efforts:)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Tkinter-discuss] displaying an image

2012-10-04 Thread Matthew Ngaha
> You need to install PIL to use the tutorial you are doing.
>
> http://www.pythonware.com/products/pil/

the site says
"
The current free version is PIL 1.1.7. This release supports Python
1.5.2 and newer, including 2.5 and 2.6. A version for 3.X will be
released later.
"

i have python 3. all the downloads below it only show python 2
versions. am i stuck?:(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Tkinter-discuss] whats Style()

2012-10-07 Thread Matthew Ngaha
sorry i sent the email directly by mistake. Just like to say thanks once
again for all the help
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Tkinter-discuss] whats Style()

2012-10-07 Thread Matthew Ngaha
>
> sorry i sent the email directly by mistake. Just like to say thanks once
> again for all the help
>
this email was a mistake, meant for anything mailing section.. please
ignore it
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] need an explanation

2012-10-11 Thread Matthew Ngaha
i need help on 2 topics.

1) can someone please tell me what sys is doing, and why its using weird
indexing?

if __name__ == "__main__":
A_Class(*sys.argv[1:4]).A_Class_Method()

is sys able to call methods? if so why does it need indexing if it uses * .


--
2) also i need help with zipfiles. these 2 functions are related in the
same class.

def __init__(self):
self.zipping_directory = "unzipped-{}".format(filename)

def _full_filename(self, filename):
return os.path.join(self.zipping_directory, filename)

def zip_files(self):
file = zipfile.ZipFile(self.filename, 'w')
for filename in os.listdir(self.zipping_directory):
file.write(self._full_filename(filename), filename)

the main thing i need help with is the last line. the zip file is writing
to a file but why does it use the same argument twice? the for loop above
that line returns the file from the zipping directory, which is the 2nd
argument on file.write? But the 1st argument is using that same file
because that is the file returned from the def _full_filename(self,
filename): method. so please can someone tell me why it uses the same file
argument twice in its write method?

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


Re: [Tutor] need an explanation

2012-10-11 Thread Matthew Ngaha
>
>
> Obviously a Monty Python fan as I see 3 methods :)
>
lol i dont know what i was looking at.. yes its 3 methods sorry:(


>
>> def __init__(self):
>>  self.zipping_directory = "unzipped-{}".format(filename)
>>
>
> Where did filename appear from above?
>
>
>
sorry i didnt write everything. the init method also had...
self.filename = filename  ... i will paste the whole code


>
> I suggest that you show us some real code that will run with some print
> statements in appropriate places to show us what is happening.  That way
> you may well be able to answer your own questions and learn at the same
> time.
>
>>
>
> sadly when i run the file i get an error so i dont know what to doto fix
it and be able to run

@ DAVE.. you said
sys is a module (presumably you have an import
somewhere above this line). In the module, there's a list argv.

the import statements are:

import sys
import os
import shutil
import zipfile

so im guessing [sys, os, shutil, zipfile]  these are the arguments being
passed? my mind tells me no, as these are more likely the arguments in the
A_Class init method?

here is he full code... i changed the names in the mail to make it clearer.
so the names in the code will be different. A_Class is actually ZipReplace
etc..

i cant test it because on start the program returns this error and i dont
know how to fix it:

ZipReplace(*sys.argv[1:4]).zip_find_replace()
TypeError: __init__() takes exactly 4 positional arguments (1 given)


full code:

import sys
import os
import shutil
import zipfile

class ZipReplace:
def __init__(self, filename, search_string, replace_string):
self.filename = filename
self.search_string = search_string
self.replace_string = replace_string
self.temp_directory = "unzipped-{}".format(
filename)

   def _full_filename(self, filename):
return os.path.join(self.temp_directory, filename)

def zip_find_replace(self):
self.unzip_files()
self.find_replace()
self.zip_files()

   def unzip_files(self):
os.mkdir(self.temp_directory)
zip = zipfile.ZipFile(self.filename)
try:
zip.extractall(self.temp_directory)
finally:
zip.close()

def find_replace(self):
for filename in os.listdir(self.temp_directory):
with open(self._full_filename(filename)) as file:
contents = file.read()
contents = contents.replace(
self.search_string, self.replace_string)
with open(self._full_filename(filename), "w") as file:
file.write(contents)

   def zip_files(self):
file = zipfile.ZipFile(self.filename, 'w')
for filename in os.listdir(self.temp_directory):
file.write(self._full_filename(filename), filename)
shutil.rmtree(self.temp_directory)

if __name__ == "__main__":
ZipReplace(*sys.argv[1:4]).zip_find_replace()

is a bit too advanced for me but i now see what it does.. although i wish
it didnt return an error when run.

so the arguments being passed are...

[os, shutil, zipfile] or [filename, search_string, return_string] ?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need an explanation

2012-10-12 Thread Matthew Ngaha
Thanks for everyone that replied. I really gained a lot from all the
input. Also thanks to Dave and Prasad for explaining why i had errors
trying to run the program. I fully understand the code now and im able to
run it without errors.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] hasattr()

2012-10-13 Thread Matthew Ngaha
im trying to understand this hasattr function. i am supposed to pass in an
object and an attribute name into its parametres... so im trying to get it
to return True. Here's a quick test

class Test:
def __init__(self):
   self.att = "testing"



>>> e = Test()
>>> hasattr(e, e.att)
False
>>> hasattr(e, "testing")
False

what can i do to make this True? my e object has an attribute att but it
returns False. Any code showing it return True?

the task i have been set is very difficult but i don't want to ask for help
just yet, i think understanding how hasattr works might make everything
else clear.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hasattr()

2012-10-14 Thread Matthew Ngaha
Thank you xDog and Steven. The whole assignment makes a lot of sense now
after your explanations of what hasattr is doing. Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Which is better Practice and why

2012-10-22 Thread Matthew Ngaha
In many of the tutorial examples ive come across, the main code's program
is never at the top level, but always in a function of some sort. i
understand why but, there is always a different way used to access the main
code, i want to know which is the best.


main()
 main's code

#top level
main()

they call the main program by simply calling the main function. I've also
seen a more complcated:

if __name__ == '__main__':
main()

the 2nd one usually includes a lot more code then i showed. can you please
tell me why different methods are used to access the main code? is it just
preference or is one way actually better coding practice?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which is better Practice and why

2012-10-22 Thread Matthew Ngaha
oh ok i understand it.. Thanks for the help guys
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with homework

2012-10-28 Thread Matthew Ngaha
>
> In your original getNames do something like this.
>> Initialise a counter to zero.
>> Every time you get a valid name increment the count.
>> If the count is three you're finished.
>>
> hey i was looking at the question as im learning also. With the counter,
would you use a while loop instead of a for loop, with the condition being
something like, while count < 3:  ? without len() the for loop option seems
difficult
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] need help

2012-11-01 Thread Matthew Ngaha
working through my tutorial ive been told to set up a simple webserver. i
can't even get started because the 1st line of code its asked me to do
fails with a syntax error. here's the code:

python3 -m http.server

any ideas what is going wrong? it asked me to make some simple .html files,
then in the same directory run that line of code. I havent any experience
with web servers, so i might not understand advanced instructions:(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2012-11-01 Thread Matthew Ngaha
>
>
>
> Always, *always* include the *full* error message, otherwise we have to
> guess. Not fun.  Some other questions: What operating system are you using?
>  What version of Python does your tutorial assume?  Do you in fact have
> Python 3 installed on your system?
>
>
>
maybe im running it from the wrong place.

on IDLE i get: SyntaxError: invalid syntax (, line 1)

and on cmd it says 'python3' is not recognized as an internal or external
command, operable program or batch file.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2012-11-01 Thread Matthew Ngaha
>
>
>
> Works for me with 3.3:
>
>
> aclark@Alexs-MacBook-Pro:~/ > python3.3 -m http.server
> Serving HTTP on 0.0.0.0 port 8000 ...
>
>
>
hey how do you start it or where do you run it from. did you type that
in the command line?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2012-11-01 Thread Matthew Ngaha
>
> If you got an error, quote it in full in your message (using copy/paste,
> not by retyping or paraphrasing.  As it stands, we don't know if the
> error was in bash, in csh, in cmd, or in Python, and if it was in
> python, we don''t know what version.
>
> > python3 -m http.server
>
> Where did you type that?  Was it in a shell, or the interpreter, or in
> IDLE, or someplace else complicated?
>


> You've already got one response showing it working with Python 3.3 on
> OSX.  it also works here, running Python 3.2 on Linux.  But you don't
> say what version, nor what OS.  I'd also ask what directory you're
> running it in.
>
> davea@think:~/temppython$ python3 -m http.server
> Serving HTTP on 0.0.0.0 port 8000 ...
>
i type it in both IDLE and CMD. in the directory where i made those .html
files, i held shift and right clicked to get the command line open. im on
windows vista. the i type that line in there. i use Python 3.1

also i made a .py file in that folder. opened it for editing, then pressed
F5 to run it., then type the code into IDLE's interactive interpreter.
which is where i got the invalid syntax error:

 SyntaxError: invalid syntax (, line 1)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2012-11-01 Thread Matthew Ngaha
>
> Don't run it from inside IDLE.  You were right to run it from cmd.
>
> Pasting the error message you showed elsewhere:
>
> 'python3' is not recognized as an internal or external
> command, operable program or batch file.
>
> That simply says that the PATH does not point to your PYTHON3.bat or
> PYTHON3.exe program.  When I was stuck on Windows, I used the ActivePython
> version, as it had many enhancements for Windows users over standard
> CPython.  One of those enhancements was a simpler install that set up
> associations and paths automatically.  Consequently, I don't have any idea
> how your Windows install tried to set up your PATH.  Look in a directory
> like  C:\Python3.1 to see if it's there at all.  And if it is, add it to
> your PATH.  That's a Windows thing, which you can do from the control
> panel.  But for testing, you can just manually add it to the path of your
> current cmd shell.
>
> In case you didn't know, PATH is an environment variable used by the cmd
> shell (and other programs) to search for .exe, .bat, and .cmd programs.
>

im really not any good with cmd or know how to set things to my python
path.  what do you mean when you say
Look in a directory like C:\Python3.1 to see if it's there at all? you mean
to see if the code works, or something else? i have my python installed not
in my C:drive but...

 D:\Data\Program Files Data\Py

in a folder named Py. i opened the cmd there and typed python3 and python
3.1 but got the same errors. i also ran the same code to start the server
but still got the same error.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2012-11-01 Thread Matthew Ngaha
>
> The interpreter executable in Windows is always called "python"
> (console) or "pythonw" (no console). The 3.1 installer doesn't put the
> executable's directory on the system PATH. The option to add this was
> added to the 3.3 installer. Otherwise you'll have to add the directory
> manually. In IDLE check the result of the following:
>
> >>> import sys
> >>> sys.executable
> '/usr/bin/python3'
>
> For you it will probably display "C:\Python31\pythonw.exe". That being
> the case; you have to append "C:\Python31" to your PATH. You can do
> this temporarily using the cmd shell's "set" command (e.g. set
> PATH=%PATH%;C:\Python31), or permanently in the system registry by
> following instructions easily found online.
>

here were the results:

>>> import sys
>>> sys.executable
'D:\\Data\\Program Files Data\\Py\\pythonw.exe'
>>> '/usr/bin/python3'
'/usr/bin/python3'
>>>

i dont see Python31 .. is this Py that is supposed to be Python31?.. and do
i type this exactly like you did in cmd?

set PATH=%PATH%;C:\Python31  ?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2012-11-01 Thread Matthew Ngaha
>
> No, in your case it's
>
> set PATH=%PATH%;D:\Data\Program Files Data\Py
>
> That's just a temporary modification for the current cmd process. It's
> easiest to show how to change it permanently with screen captures;
> search for "vista set path".
>

i followed the instructions at
http://banagale.com/changing-your-system-path-in-windows-vista.htm

i added "D:\Data\Program Files Data\Py" to my variable value but i still
get the same error that Py is not recognized:(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2012-11-01 Thread Matthew Ngaha
>
> "Py" is a directory.
>
> Once you've added the Python executable's directory to the path, you
> can start the http.server module as a script by running the following:
>
> python -m http.server
>
> Don't use "pythonw" in this case. The latter is associated with the
> .pyw file extension, used for scripts that run without a console. For
> example, IDLE is a GUI app that uses Tk widgets, so it doesn't need a
> console. That's why it runs with "pythonw.exe".
>

wow i am so grateful.. i had given up hope just trying different things.
its finally working. thank you:)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help

2012-11-19 Thread Matthew Ngaha
It's asking a lot if you want people to read your whole code to try
 and spot the errors. Try to run it from the console and paste what the
 errors are here.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help

2012-11-20 Thread Matthew Ngaha
> Traceback (most recent call last):
>   File "Match finder GUI.py", line 87, in ?
> app = Application(root)
>   File "\Match finder GUI.py", line 23, in __init__
> self.create_widgets()
>   File "Match finder GUI.py", line 61, in create_widgets
> self.submit_bttn = Button(self, text = "Submit", command = self.reveal)
> AttributeError: Application instance has no attribute 'reveal'
>
>

i only know really basic tkinter, but i think the error is looking for
a method called reveal(). other than your __init__()  and
create_widgets() methods, i only see an update() method. I think your
update method should be named reveal?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Proper useage of "open"

2012-12-12 Thread Matthew Ngaha
> I typed in to my script:
> a = open (dupli, r)
> and got an error stating that "dupli" is not deffined.

it needs the quotes around it. so try:

a = open ("dupli", "r")
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exercise

2012-12-14 Thread Matthew Ngaha
> return {e for (e, g) in self.sort_email.items()
> if g & groups_list}
>

guys i think ive got it. The & in that comprehension was really
confusing me, but i found out it means intersection, so i took the
sets manually and saw the results i got using intersection and it
became more clear from there. A Big Thanks if you took the time to
help solve my issues.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Programming for Absolute Beginners, 3rd Edition

2013-01-02 Thread Matthew Ngaha
> With the code not being on the page, I went to the directed website and got
> the downloads, yet I couldn't find the source code
> anywhere to be found. Am I missing something plainly obvious?

what exactly did you download? all the source code for every chapter
is included in the download
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] unclear topic

2013-01-14 Thread Matthew Ngaha
hey guys, this is not really a Python question. When ever im doing a
tutorial, it could be pygame or some gui application, i usually find
everything straight forward until the demonstration involves drawing.
Then maths is applied and i can't follow along as easily. In the end
by commenting out certain lines of code, i understand what each line
is doing but the fact is im still faced with being very weak at
drawing and working out the logic behind it. I also can't imagine if
im designing a program and need to do drawings of my own how i would
work out the calculations and be able to think for myself. The help im
asking for is what do i need to study to be able to design my own
programs that involve drawing? do i need to go off and learn maths? if
so which type? some sort of geometry? or do i start studying some sort
of physics? or does the answer lie within some framework/library
python tutorial?

on amazon ive seen:

maths books
physics book
2d engine physics books(box2d etc)
game physics books -  http://www.amazon.co.uk/Game-Physics-/dp/147103397X/


my other problem is i don't want to over do it. do i need to buy a
game physics book, if all i want to do is understand how to implement
my own calculations for complex objects etc? then again maybe that's
not so bad. If you know your way around this stuff? what did you learn
that gave you these skills?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Traffic Light

2013-01-19 Thread Matthew Ngaha
On Sat, Jan 19, 2013 at 10:56 PM, anthonym  wrote:
> Thanks again for the info Alan.  I am still passing the button process
> until I can get my rectangle and ovals on the canvass.  The program runs
> and produces a window with the radio buttons on top.  I would like them on
> the bottom but changes to the row field have no effect.
>
> Anybody have any ideas on why I don't see my shape on the canvass?

i doubt i can help, but it might help if you could paste the section
of the code in relation to what you're explaining and tell us what
it's doing? some people don't use tkinter so its a bit hard to
understand what you're saying.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Traffic Light

2013-01-19 Thread Matthew Ngaha
On Sun, Jan 20, 2013 at 12:05 AM, Matthew Ngaha  wrote:
> On Sat, Jan 19, 2013 at 11:29 PM, anthonym  wrote:
>> Sure thing.  Here is the code.  And after that is the box I get with the
>> radio buttons but no shapes.
>
 i might be way off as im struggling to understand how tkinter works,
 but i noticed a few things which hopefully might help. starting with
you wanting the buttons on the bottom of the window and not at the top
where they are showing.

>> from tkinter import *  # Import tkinter
>>
>> class Trafficlight:
>> def __init__(self):
>> window = Tk()
>> self.canvas = Canvas(window, width = 480, height = 480, bg =
>> "white")
>> self.canvas.pack()
>>
>> # Add three radio buttons to frame1
>> frame1 = Frame(window)
>> frame1.pack()
>>
>> rbRed = Radiobutton(frame1, text = "Red", bg = "red",
>> variable = self.v2,
>> value = 1,
>> command = self.processRadiobutton)
>> rbYellow = Radiobutton(frame1, text = "Yellow", bg = "yellow",
>> variable = self.v2, value = 2,
>> command = self.processRadiobutton)
>> rbGreen = Radiobutton(frame1, text = "Green", bg = "green",
>> variable = self.v2, value = 3,
>> command = self.processRadiobutton)
>>
>> rbRed.grid(row = 400, column = 1)
>> rbYellow.grid(row = 400, column = 2)
>> rbGreen.grid(row = 400, column = 3)
>>
>
 row = 400 seems a bit odd? do you really have 399 occupied rows? you
 define the canvas with absolute positioning: Canvas(window, width =
 480, height = 480). where you trying to place the buttons with
 absolute positioning also? it seems they are appearing inside the
 frame in which you have put them in so why are you trying to move them
 again? im guessing you would have to reposition the Frame itself. also
 you are not using instance variables(self) for either the frame or the
 buttons, maybe they lose the reference to them once moved outside the
 frame.

 as for your shapes not appearing:
>
>>def displayRect(self):
>>self.canvas.create_rectangle(10, 10, 100, 100, tages = "rect")
>>
>>   # Display a Oval for the top light
>>def displayOval(self):
>> self.canvas.create_oval(10, 10, 10, 10)
>> # Display an Oval for the middle light
>>def displayOval(self):
>> self.canvas.create_oval(20, 20, 20, 20)
>> # Display an Oval for the bottom light
>>def displayOval(self):
>> self.canvas.create_oval(30, 30, 30, 30)
>
 If that is the complete code you showed.. Your buttons are not doing
 anything. they are calling a method that does nothing:
 def processRadiobutton(self):
 pass

 also i dont see anywhere in your code where you are calling any of
 those methods that create the shapes. you have to fix your method that
 your buttons are calling, and have it call the correct method for your
 specific shape.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how can i use python 2 alongside 3?

2013-01-24 Thread Matthew Ngaha
hi guys i am a python 3.1.1. user but really need to use python 2 to
be able to use certain libraries and frameworks. i have installed
python 2.7 but they cant run together as all .py and .pyw files are
opened with python 3. i can open simple python 2 files by right
clicking and finding pythons 2's python.exe, but these only works for
simple files with no imports because the import i think seems to look
in the python 3 directory and can't find the packages.

i have checked stackoverflow for answers but i get lost in all the
terms and keywords they use to solve this. is there a simple
straightfoward way to fix this that is easy for someone like me to
understand or follow?

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


Re: [Tutor] how can i use python 2 alongside 3?

2013-01-24 Thread Matthew Ngaha
>
> Python 3.3 for Windows comes with a "launcher", which will approximate (for
> Python only) what Unix and Linux users have had for years for any scripting
> language.  You can get it separately, as Mark Lawrence has said, but maybe
> it's time to bring your 3.x current.
>
there was a lot of reading in the previous links, i got a bit lost as
i didnt recognize a lot of the words they were using. If i install
Pyhon 3.3 do i need to uninstall my current python 3.1 and reinstall
all the downloaded modules/packages i installed?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how can i use python 2 alongside 3?

2013-01-24 Thread Matthew Ngaha
>
> You don't have to uninstall 3.1 but you would have to install all the
> downloaded modules or packages that you have in your 3.1 site packages
> folder to the 3.3 site packages folder.  Maybe it's easier to simply grab
> the standalone pylauncher as I suggested earlier.  Only you know what is the
> path of least resistance.
>
yes the 2nd option (standalone pylauncher) sounds more convienient for
me. i just have to try and comprehend all the instructions given..
hopefully ill get there in the end
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how can i use python 2 alongside 3?

2013-01-24 Thread Matthew Ngaha
> yes the 2nd option (standalone pylauncher) sounds more convienient for
> me. i just have to try and comprehend all the instructions given..
> hopefully ill get there in the end

i managed to install the laucher. on the site when i click the correct
launcher 32bit, i chose "run" and it automatically installed rather
than asking me or allowing me to install it in cmd like their
directions showed. my python 3 files still open but python 2 files
still return errors like: print "string" is invalid syntax which tells
me its still using python 3 to open these files. when i right click
.py files a new option has been added to "open with" which is open
with Python Launcher for Windows. Even when i do this my python 2
files won't open
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how can i use python 2 alongside 3?

2013-01-24 Thread Matthew Ngaha
>
> Have you added shebang lines to those scripts yet?
>
yes i added them. i think the problem is at the start where it asks me to:

You should ensure the launcher is on your PATH - depending on how it was
installed it may already be there, but check just in case it is not.

>From a command-prompt, execute the following command:
py
You should find that the latest version of Python 2.x you have installed is
started ..

py is not recognized and and it said "depending on how it was
installed". the problem is it didnt allow me to select a path when
installing. it just automatically did everything. i have searched my
PC for python launcher but it cant find it, so i dont know where its
location is. i see it in "control panel" to uninstall a program but
right clicking it doesnt give me an option to see its containing
folder
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how can i use python 2 alongside 3?

2013-01-24 Thread Matthew Ngaha
> I'm not using it, since I'm not using Windows.  So these are guesses based
> on years stuck\b\b\b\b\b spent in the Windows environment.
>
> Clearly, the name of the program is py.exe, so that's what you should try
> searching for.  From the cmd prompt, try   dir /s  py.exe
>
> Or, you could just try searching under c:\windows  since that's where it's
> likely to be.
>
> To see your PATH, type  PATH   at the cmd prompt.
>
> To make temporary changes to your PATH (if py.exe is in an obscure place),
> just type
>   set PATH=c:\mydir;%PATH%
>
> To make permanent changes to PATH, you have to change the environment
> variables in the Control Panel.  I've done it many times, but don't recall
> just where it is.  Such permanent changes will affect any new runs of CMD,
> as well as affect any other program subsequently started.
>
thanks Dave. the file was py.exe as you said and the temporary path is
able to open both version 2 and 3's  python.exe. There seems to be a
problem. python 2 seems to be the only version opening my files unless
i do a few things. So with the shebang set:

the python launcher, launches my python 3 files with the correct
version if i double click the file or run it from a console. But it
uses the wrong version if i run it from IDLE or if i right click the
file and open with the Python Launcher. i guess i can live with that,
but is there anyway around this?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how can i use python 2 alongside 3?

2013-01-24 Thread Matthew Ngaha
> Did you find the "control-panel-way" to modify the PATH (assuming py.exe
> wasn't already in there) ?  Without it, I'd be surprised if right-click
> would work correctly.
>
> And as for IDLE, there are two different IDLEs, one in each directory. So
> run the one that corresponds to the python you'll be using.  How to do that?
> I dunno, since I don't use IDLE, but I'd find or make batch files called
> something like IDLE2.bat and IDLE3.bat that know how to find and run the
> appropriate IDLE.
>
i didnt use the control panel way but the right click is now working,
it was an error that in the script i had a txt.file open() and the
right click way said "no such file" but the other ways found the txt
file which is weird but right clicking works for other files without a
txt file. i can live with that. i think it wise for me to try to
permanently add the path with control panel.

Thanks for all the help, its such a relief to now be able to run python 2 files
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how can i use python 2 alongside 3?

2013-01-24 Thread Matthew Ngaha
On Thu, Jan 24, 2013 at 9:35 PM, eryksun  wrote:
> On Thu, Jan 24, 2013 at 1:56 PM, Matthew Ngaha  wrote:
>>
>> py is not recognized and and it said "depending on how it was
>> installed". the problem is it didnt allow me to select a path when
>> installing.
>
> The simpler installer is launchwin.msi, which installs to the Windows
> directory. This directory should already be on the PATH.
>
> In a cmd shell, check that 'assoc .py' is "Python.File" and that
> 'ftype Python.File' points to py.exe in your Windows directory, e.g.
> "C:\Windows\py.exe "%1" %*'. If it's wrong, re-install. Or fix it
> manually using assoc and ftype in an elevated cmd shell, which updates
> the local machine registry keys in HKLM\Software\Classes.
>
> Also, Windows Explorer has an "Open With" dialog that configures
> per-user settings for multiple associations, including a default (i.e.
> the "Always use..." checkbox). These keys are stored in
> HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py.
> Make sure that UserChoice is set to the Progid "Python.File". You
> should be able to change this using the 'Open With->Choose Default
> Program...' dialog.
>
> You can customize pylauncher by editing its ini file in your profile.
> For example, run 'notepad %localappdata%\py.ini' to create/edit it.
> See the docs for the settings, such as changing the default
> interpreter and adding custom shebangs.

sorry i didnt see this message. I havent read it yet although it looks
complicated. Thanks ill report back if i need help
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how can i use python 2 alongside 3?

2013-01-24 Thread Matthew Ngaha
> In a cmd shell, check that 'assoc .py' is "Python.File" and that
> 'ftype Python.File' points to py.exe in your Windows directory, e.g.
> "C:\Windows\py.exe "%1" %*'. If it's wrong, re-install. Or fix it
> manually using assoc and ftype in an elevated cmd shell, which updates
> the local machine registry keys in HKLM\Software\Classes.

i think this is ok, i got these results.
D:\Data\Py\mywork>assoc .py
.py=Python.File

D:\Data\Py\mywork>ftype Python.File
Python.File="D:\Data\Py2.7\python.exe" "%1" %*

> Also, Windows Explorer has an "Open With" dialog that configures
> per-user settings for multiple associations, including a default (i.e.
> the "Always use..." checkbox). These keys are stored in
> HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py.
> Make sure that UserChoice is set to the Progid "Python.File". You
> should be able to change this using the 'Open With->Choose Default
> Program...' dialog.
>

i dont quit understand when you say UserChoice is set to the Progid
"Python.File"? what is Progid? i cant seem to locate that path
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] following on

2013-02-18 Thread Matthew Ngaha
>> understanding of how everything works.
>
> Use it., Experiment with it. Break it.
> Thats the best way. Read the source code its all available in
> Python or C.
>

Hey can you please tell me which source code youre referring too? The
initial files that come with Python? also the C code, where can i
locate this? is C something worth learning? why is Python code
available in C?

>
>> like how can i make my own custom container and not have it
>> subclass list(), and still act like a list()?
>
> That's a more sensible option especially if you make it a type of container
> that Python doesn't already have. Maybe a bag or a stack
> or even a circular list. But there is no shame in inheriting from
> list if that makes sense. That would be good software engineering - don't
> reinvent the wheel!
> When building  reusable code start from the perspective of the user. Write

yes i will try not to reinvent the wheel, a lot of tutorials ive read
seem to always point this out. Just out of curiousity what is a bag,
stack or circular list? what is needed to create something like this?
i sort of heard about a stack its a C/C++ thing i think?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] following on

2013-02-18 Thread Matthew Ngaha
Hey, a Big thanks to everyone that has offered their input. I really
appreciate it. Also thanks for all the additional links, i will
definately start to read up on data structures , source code and
everything else that was suggested
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] break

2013-03-14 Thread Matthew Ngaha
i cant seem to break out of this loop. let me explain the variables you see:

Enemy.ships = [] #an Enemy class variable that contains enemy ships
self.missiles = [] an instance variable that appends how many Visible
missiles my ship has fired
Enemy.rects = [] an Enemy class variable that represents a rectangle
for every ship in Enemy.ships
Explosion() = a class where explosions occur
QPoint() = is a pyqt function that takes a point x, y position as arguments

im trying to destroy the ships if they hit a missile, even though i
use pyqt this is mainly python code

if Enemy.ships:
for missile in self.missiles:
for rect in Enemy.rects:
if QPoint(missile.x + 5, missile.y) in rect:
explosion = Explosion(rect.x(), rect.y())
self.explosions.append(explosion)
break

once the missile has hit 1 Enemy.rect i want to break and go to the
next missile so the missile is destroyed and doesnt hit another Enemy,
but for some reason the break i have isnt working and the same missile
sometimes is hitting 2 different rects on the same iteration. i have
done the same loop using a simple print statements on strings greater
than a certain length and it breaks correctly. anyone have any ideas
why the break isnt breaking out of the nested/inner loop but instead
continuing to loop through the Enemies?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] break

2013-03-14 Thread Matthew Ngaha
>>  if Enemy.ships:
>>  for missile in self.missiles:
>
>flag = False
>>
>>  for rect in Enemy.rects:
>
>assert(!flag)
>
>>  if QPoint(missile.x + 5, missile.y) in rect:
>>  explosion = Explosion(rect.x(), rect.y())
>>  self.explosions.append(explosion)
>
>flag = True
>>
>>  break

im about to try the suggestions. i on python 3 and this line is giving
me a syntax error assert(!flag).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] break

2013-03-14 Thread Matthew Ngaha
> One good approach is to have a separate function or method with
> both loops:
>
> def attack(self, Enemy):
>
> for missile in self.missiles:
> for rect in Enemy.rects:
> if QPoint(missile.x + 5, missile.y) in rect:
> explosion = Explosion(rect.x(), rect.y())
> self.explosions.append(explosion)
> return

i altered this because once it returns the outer loop also stops and i
need it incase i have more than 1 missile to loop through. i made it
so i did the outer loop in the program and sent the inner loop to this
function, but for some reason the code seems to break my program.. no
errors are returned but it just freezes on inputs and missile
collision.

> You could also set a flag and check it at the end of outer loop
> and have a second break statement when the flag is set.
>

im trying to figure out this technique with flags but i havent got it
yet.. what does a flag stand for?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] break

2013-03-14 Thread Matthew Ngaha
thanks guys ive finally got it working. even though i didnt use the
flag due to invalid syntax i realized since i was getting no errors i
wasnt actually doing anything wrong. My mistake was i removed the
ememy ship but for some reason forgot to remove the missile so it was
still active on the next update/mainloop. im still interested in
finding out how to write this in python 3 assert(!flag).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] urllib.urlretrieve ?

2013-04-07 Thread Matthew Ngaha
Im following a tutorial on what i believe is using Python 2 and i'm a
bit confused. I use Python 3 on windows vista. I believe
urlretrieve() is a python 2 function that isnt in 3, but why is the
tutorial using urllib instead of urllib2? Also when i run the program
on Python 3, it says:

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

so Python 3 doesnt recognize this function, i want to ask if there is
an equivalent function to 'urlretrieve' in Python 3? the program uses
this function to download a file as so:

urllib.urlretrieve(self._url, self._filename, reporthook)

the 3rd argument is a function that is called to track progress of the
current download status. i dont really need help with the program, i
understand its code, but i need to know if this function has one
similar in Python 3? or do you have any examples of how i could add
its functionality to Python 3.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib.urlretrieve ?

2013-04-07 Thread Matthew Ngaha
the whole program depends on the urlretrieve 3rd argument, the
function to be called.. is there no options to include a callback?

def _download(self):

def reporthook(pos, block, total):
if self.size != total:
self._size = total
self.on_size.emit()
self.progress = float(pos*block)/float(total)

urllib.urlretrieve(self._url, self._filename, reporthook)
##3rd arg calls inner function
self.running = False
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib.urlretrieve ?

2013-04-07 Thread Matthew Ngaha
> Look in the module docs for urlib.request.
>

Hi. Ive never used the urllib before unless it was typing in something
from an unrelated tutorial. I've also never done anything related to
web programming. I'm looking at the urllib.request page and i really
don't understand what i'm looking at. I'm confused as to what i should
be looking for.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib.urlretrieve ?

2013-04-07 Thread Matthew Ngaha
>
> You might want to look at requests module:
> http://docs.python-requests.org/en/latest/
> Many people think it is easier to use than the native python support.
>

are all of these modules related to web programming like clients and
(HTTP)servers? I've come across urllib a lot of times but only
followed along, maybe its best i just learn about HTTP and its
concepts etc so i can understand the request module better then come
back to my problem.. Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib.urlretrieve ?

2013-04-07 Thread Matthew Ngaha
yeah, sadly urlretrieve doesnt exist on my version of python. i just
need a function to put in the same line that replaces this one with
the same arguments in order to see the results of my tutorial.

urllib.urlretrieve(self._url, self._filename, reporthook)

On Sun, Apr 7, 2013 at 7:10 PM, Alan Gauld  wrote:
> On 07/04/13 17:20, Matthew Ngaha wrote:
>>>
>>> Look in the module docs for urlib.request.
>>>
>>
>> Hi. Ive never used the urllib before
>
>
> In Python 3 urllib combines (the best) features of
> urllib and urllib2 from Python 2.
>
>
>> web programming. I'm looking at the urllib.request page and i really
>> don't understand what i'm looking at. I'm confused as to what i should
>> be looking for.
>
>
> You were asking about urllib.urlretrieve.
> It's documented on that page.
>
> Now, beyond that, what else are you confused about?
> The more specific the question the more specific the answer.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib.urlretrieve ?

2013-04-07 Thread Matthew Ngaha
>org/2/library/urllib.html#urllib.urlretrieve
> or
> http://docs.python.org/3/library/urllib.request.html#urllib.request.urlretrieve
sorry about the top posting gmail has changed the way their messages
are done, it gave me a blank field i didnt realize i was writing above
the message.

i must have missed it but your 2nd link was exactly what i needed. ive
got the program to run without the module error. However i'm out of
luck as i now get this error:

urllib.error.HTTPError: HTTP Error 404: Not Found

i guess the tutorial is very old that the site doesnt exist anymore:(
Thanks for the help
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib.urlretrieve ?

2013-04-07 Thread Matthew Ngaha
> Unless you're looking for something specific from the URL that the
> tutorial uses, then you could use any address
>
> Bodsda

thanks i did that and to my suprise an extra file showed up in my
folder, of the page i just visited:) thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help regarding game code

2013-05-12 Thread Matthew Ngaha
>> bWater.clicked.connect( water_clicked ) AttributeError: 'int

use a paste site like http://bpaste.net/+python to show us the code.

i am no expert @ programming myself but that error is telling you you
used an int and tried to access an int method called connect somewhere
in your code. ints do not have this method. However some PyQt objects
(mostly button widgets) do have this method, which is actually a
signal called clicked for when you mouse click on the widget(button).
So basically ints (integers) do not have signals, try and connect the
name(variable name) of what you are clicking to that method, instead
of the int object (bWater)

bWater.clicked.connect( water_clicked )  should become:

button_name.clicked.connect( water_clicked )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] env var packages

2013-05-14 Thread Matthew Ngaha
i have to install django and ive come across some weird instructions.
it says to set Django's  django-admin.py file to my environment
variable. I was instructed to get django via easy installer that was
located in my Python/Scripts folder. it installed django to a
different place in site-packages, where django-admin.py resides.But
now its telling me to add this file to my env variable and it should
also be located in Python/Scripts .. but as i've said, its clearly not
there, it is somewhere in a site-packages/django sub folder. so is
this an error? or do i go ahead and add Python/Scripts to the env
variable, even those the file points somewhere else?

My 2nd problem is it says after adding it i will get a python
interpreter and Django's djando-admin.py commad up and running. What
does this mean? both files open? it was specific about adding the path
to the env variable, but if i already have python added, why do i need
to add django? shouldnt it already be added? i will quote:

"You should make sure "djando-admin.py" is in your PATH environment
variable so that it can be executed from the command-line (unless you
like calling interpreters by using full pathnames)"

does this mean in a terminal, that i can be in
"Python/myproject/script_one/" and be able to open a .py file in
"Python/myproject/script_two/" by simpling typing its file name
without having to cd into its directory or typing its full path?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] env var packages

2013-05-15 Thread Matthew Ngaha
Thank you Vasya and Eryksun. Sorry i didn't mention my OS i am on
windows. Thanks for the links and detailed explanations which after
following, i now have django up and running! thanks again
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Programming for the Absolute Beginner

2013-05-15 Thread Matthew Ngaha
i completed this book and i did every exercise. are you asking for
help with the challenges, or have you completed them and want code to
compare yours too? im relunctant to share challenge code, incase you
havent done them. They are really good exercises to try doing.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interested in learning Python

2013-05-15 Thread Matthew Ngaha
i recommend getting a copy of Python Programming for the absolute
beginner. It offers end of chapter exercises to make sure you
understand everything you are reading. It was a great read for me and
made my learning experience really fun. I garantee by the end you
would have gained a lot of confidence and will be able to pick up and
learn many new things
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] model methods in Django

2013-05-18 Thread Matthew Ngaha
 im following the official docs and after learning Python im sure of
how methods work, but the model example on the beginners guide has me
really confused.

The model definition is omitted but can anyone explain how this methed
(was_published_recently) is given these attributes:

class Poll(models.Model):
# ...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'

are the names of the attributes already attached to these
functions/methods, or are they being created on the fly with whatever
name you want? As i am unable to comprehend what is going on, i dont
really have a clue as to what each definition is doing and how it
affects the model, even after reading this section of the docs over
and over again im still lost.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] model methods in Django

2013-05-19 Thread Matthew Ngaha
Thanks guys i had no idea about these  method attributes and also
these underlying oop  __objects__

@ eryksun
i understand your explanation, im still having trouble figuring out
how django is being used in the tutorial.

class Poll(models.Model):
# ...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'
list_filter = ['pub_date']
search_fields = ['question']
date_hierarchy = 'pub_date'


if you look at the diagram under that function, why is the value of
"was_published_recently.short_description" the title of that field?
replacing the old title? is a "short_desccription" attribute set
somewhere in django being inactive, but once you make use of this
attribute(or keyword), whatever the value is automatically becomes the
field title? is it the same for boolean being the value of the field
with the checked or unchecked symbol?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] model methods in Django

2013-05-19 Thread Matthew Ngaha
> The default description is the name with underscores removed, unless
> you set a custom description in the function's "short_description"
> attribute. I'm not experienced with Django, so I can't ramble off lots
> of examples, but hopefully you get the gist.

Thanks that does clear it up. Also thats a huge script you linked, can
i ask which framework you're coming from, and why you have decided to
try out django? When i asked around, people's opinions of it weren't
good and i was recommended to try flask but as i only use Python 3, i
won't be able to use Flask.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] model methods in Django

2013-05-19 Thread Matthew Ngaha
> class Poll(models.Model):
>
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
>
>
> def was_published_recently(self):
> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>
> #
>
>
> was_published_recently.admin_order_field = 'pub_date'
> was_published_recently.boolean = True
> was_published_recently.short_description = 'Published recently?'
>
>
> Source:
> https://docs.djangoproject.com/en/dev/intro/tutorial01/
> https://docs.djangoproject.com/en/dev/intro/tutorial02/
>
>
> I find the Django (and this fragment) very elegant UP TO the comment.
>
is the dislike after the comment more to do with the python code
rather than django itself?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] model methods in Django

2013-05-19 Thread Matthew Ngaha
 > options.py is the biggest module in the admin package. The link I
> posted is to the get_actions method of ModelAdmin. In the tutorial,
> PollAdmin extends this class.
>
oh ok thanks, yes i will definately look through it

> I'm not coming from any framework. My knowledge of web development is
> scattered from bits learned here and there, out of curiosity rather
> than necessity. With Python 3 you're a bit limited, but you still have
> options. Obviously there's Django -- arguably the most popular,
> batteries-included framework. Pyramid is a leaner alternative. Bottle
> and CherryPy (also a WSGI server) are micro frameworks. There's also
> Tornado if you want an asynchronous framework based on callbacks and
> coroutines.

As there are a lot more guides for Django i think i will stick with it
rather than Pyramid. Maybe after ive learnt it well i can pick up
Cherrypy as i like the sounds of a small framework with a server. But
Django will be my main focus. Thanks for detailing the options for
Python 3
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] model methods in Django

2013-05-19 Thread Matthew Ngaha
On Sun, May 19, 2013 at 3:34 PM, Steven D'Aprano  wrote:
> Matthew, who are you quoting? Your email program should automatically insert
> an attribution line, such as the one just below. Without that attribution
> line, it is hard to follow the conversation, as we can't tell who you are
> quoting.
>
> On 20/05/13 00:23, Matthew Ngaha wrote:

ok thanks i didnt think about that. I was quoting eryksun. I'll
includethat line from now on
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] challenge-chapter 2

2013-05-22 Thread Matthew Ngaha
On Wed, May 22, 2013 at 6:02 AM, Andrew Triplett  wrote:
> I am on chapter two for Python Programming working on the challenges and the
> question is:
>
> 1. Create a list of legal and illegal variable names. Describe why each is
> either legal or illegal. Next, create a list of "good" and "bad" legal
> variable names. Describe why each is either a good or bad choice for a
> variable name.
>

The title is a bit ambigious. Just incase anyone likes the sound of
the challenge, the book is:
Python Programming For The Absolute Beginner
i also used it and would recommend it to anyone trying to learn Python
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difference between types

2013-05-23 Thread Matthew Ngaha
wait for someone more knowledgeable to answer, but from what i know,
Yes it does have a profound meaning.  Strings consist of character
sets. Something that was here way before Python

Like i said my experience is limited so i too would like to hear some reponses
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: QT Python: How to re-use the return value of fileDialog.openFileName() ?

2013-05-27 Thread Matthew Ngaha
Sorry for the forward, i forgot to reply to tutor

On Mon, May 27, 2013 at 3:53 AM, Sunitha Misra  wrote:

> self.fileDialog = QtGui.QFileDialog()
>
> QtCore.QObject.connect(self.toolButton,
> QtCore.SIGNAL(_fromUtf8("clicked()")), self.fileDialog.getOpenFileName)
>

i think the way youre doing it won't allow you to get the filename as
you are calling it through a signal.

Things you can do:

1) dont use self.fileDialog.getOpenFileName as a slot like you are
doing. Create a function and call it when the toolbar's button is
clicked, then in that function assign the filename to the return value
of self.fileDialog.getOpenFileName.

2) if the only thing your self.fileDialog is doing is responding to
the toolbar's button, don't create it at all. do what i said in #1 and
assign a filename variable to the full method of the dialog. What im
saying is there might be no need to create the self.fileDialog
instance variable at all.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: QT Python: How to re-use the return value of fileDialog.openFileName() ?

2013-05-27 Thread Matthew Ngaha
On Mon, May 27, 2013 at 2:14 PM, SM  wrote:

>But then I also had to use self.fileDialog from within the function. Not
> sure how I could avoid using fileDialog.
>
> Thanks.

No problem. to do it without the instance variable, you access its
method directly. so replace:

path = self.fileDialog.getOpenFileName()

with

path = QFileDialog.getOpenFileName(self)

which is basically the same thing except you're going to the method
directly instead of creating a class instance. The self argument may
or may not be needed, its been a while since ive used Qt.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] global variables

2013-08-22 Thread Matthew Ngaha
I'm always told to avoid using them. I read discussions on the python
irc channel about them but honestly i feel there are some times where
i can't avoid using them. Like where i want to keep track of a state
variable in many different functions that may or may not alter its
value and also not wanting any of the functions to return it to the
caller.

My question is how many global variables did your last decent sized
program have? Also please share any insight you have about them. I do
try to avoid them, but is this always possible?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] global variables

2013-08-22 Thread Matthew Ngaha
On Thu, Aug 22, 2013 at 1:40 PM, Chris Down  wrote:

> It sounds like you want to use a class.
> Why would you not just use a class if you want to store state?

I don't feel my program needs a class. Also i have been told to stop
using classes by some very experienced Python programmers on irc even
though i don't see why. It's confusing being told different things.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] global variables

2013-08-22 Thread Matthew Ngaha
On Thu, Aug 22, 2013 at 2:52 PM, Chris Down  wrote:
>I would doubt that anyone has told you "don't ever use classes", because
> that's nonsense; you've probably misread a dissuasion from that path in a
> single instance as applying more broadly than was intended.

I am being totally honest here. I was very confused at the time and i
said i didn't agree because it's what i had put so much effort into
learning. They went on to say at some well known Python talks speakers
have stated why using OOP (especially inheritance, but not excluding
any others) is very bad design and the same thing can always be
achieved without it. To be clear they said every use case OOP is the
worst option. I asked what about GUIs which their design is strongly
based around OOP? and they sad GUIs are badly designed to begin with
so it proves the point about OOP.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] global variables

2013-08-22 Thread Matthew Ngaha
On Thu, Aug 22, 2013 at 3:04 PM, Alan Gauld  wrote:
> On 22/08/13 13:36, Matthew Ngaha wrote:

> Global variables  in themselves are not the problem.
> It's how they tend to get used that causes problems.

> Globals that are only changed via a set of
> dedicated functions are not topo much of a
> problem - although they should probably be
> bundled as a class (or module)
>
> Usually that should be in a class. A class represents
> a set of operations using common data. Therefore shared
> state would naturally fit in a class along with the
> operations which depend on/modify that state.
>
Oh this makes a lot of sense. Sorry about disagreeing with Chris i now
see that perhaps a class is definately the best choice for keeping a
state variable.

> Thats more problematic and usually a sign of a bad design.
> Even if using global variables you should modify them
> explicitly via return values of functions rather than
> as hidden side-effects inside other functions.
>
> mystate = changestate(mystate, some, other, args)

Yeah i have to agree about the bad design now i think about it. I
didn't see the issues before reading this

> It is possible but only by playing silly games with
> semantics such as:
>
> class MyProgram
>global1 = 0
>global2 = True
>

> [Or alternatively you can hide them inside a database.]
>
> Now technically there are no globals but in fact we are
> just moving them inside the meaningless class and have
> all the same potential issues with global side effects
> etc.

About the class variables, i have used them a lot without realising
they had all the same side effects as global variables. Something i
now have to try a different approach with.

> In my experience there are usually a few globals required
> for any meaningful program. It's not avoiding globals
> completely that's important, it's being careful to use
> them sensibly and with good adherence to the principles
> of coupling and cohesion in the design.

Thanks  alot! This is definately a lot of food for choice and will
help in my future decisions. I'm happy i asked this question as i can
honestly say i had been developing some bad habbits. The responses
have definately been helpful about program design and not just global
variables.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


  1   2   >