[Tutor] Assertion Error

2010-03-18 Thread sitharak

I tried this statement to store in RDF form

store=TripleStore()

But i'm getting this error

Traceback (most recent call last):
  File "", line 1, in 
store=TripleStore()
  File "C:\Users\Administrator\Desktop\TripleStore.py", line 13, in __init__
super(TripleStore, self).__init__(backend=backend)
  File "build\bdist.win32\egg\rdflib\Graph.py", line 1008, in __init__
super(BackwardCompatGraph, self).__init__(store=backend)
  File "build\bdist.win32\egg\rdflib\Graph.py", line 815, in __init__
assert self.store.context_aware, ("ConjunctiveGraph must be backed by"
AssertionError: ConjunctiveGraph must be backed by a context aware store.

plz help
-- 
View this message in context: 
http://old.nabble.com/Assertion-Error-tp27941982p27941982.html
Sent from the Python - tutor mailing list archive at Nabble.com.

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


Re: [Tutor] Problems with iterations and breaking loops

2010-03-18 Thread Alan Gauld


"Karjer Jdfjdf"  wrote

In reality I have to do this for a much larger dataset 
(eg 1 range * 10 = a lot), so the for v1, v2 in 
list_of_tuples doesn't work because it is too large for it.


What does the size have to do with it?
v1,v2 in list_of_tuples will only unpack one tuple at a 
time regardless of how big the list is.



I've tried to put it in a def, but:


Take the outer loop out of the function.
The point of functions is to break the problem down into 
manageable chunks.


You should probably have 3 functions here:
1) to do the calculation on a single element
2) to apply function(1) to each item in the tuple list
3) a function to apply function(") from min to max

That makes your code look like

def function3(min,max)
for n in range(min,max):
 function2(val, t_lst)

def function2((val, tuples)
 for tuple in tuples:
  function3(val,tuple)

def function(val,pair)
 # whatever calc you need

That way you can test each function in turn and 
stop the nested loops from dominating the logic.


def perform_calculations2(n, nmax, value, list_of_tuples, ):
#this works too good. It returns 10 times the correct 30 values

Because you have repeated the outer loop inside the function. 
Get rid of it.


something = []
for i2 in xrange(n, int(nmax+1)):

And please stop calling int() when the values are already ints.


for t in list_of_tuples:
v1 = t[0]
v2 = t[1]
something.append(str(i2) + "\tdoes something for\t" + str(v2))
return something

The above is all you need in your function.

HTH,

--
Alan Gauld
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] Self-intro and two short newbie questions

2010-03-18 Thread Kevin Kirton
Hi all,

I've committed myself to learning Python and have started reading
"Learning Python" (Mark Lutz) and looking through various online
resources.
My career so far has involved a little high school teaching and about
10 years of translating Japanese to English, but no programming or
coding.

I've also joined this list today and this is my first post.

My aim is to be able to create Python programs, specifically
"activities" that work on the OLPC's XO laptops and SoaS (Sugar on a
Stick).

My questions are: how long would you estimate it to take and how
complicated would it be to create the following as Python programs? (I
know it varies depending on the person, but for example, how long
would it take _you_?)

(i) a simple guitar tuning program involving an image of a guitar and
the playing of each of the standard strings of a guitar (E, A, D, G,
B, E) upon key input by the user
(something similar to this:
http://www.gieson.com/Library/projects/utilities/tuner/ (page is 782kb
to open))
and
(ii) a very basic turtle art program with an intentionally limited set
of commands and on-screen display words (say, a total of 30 to 50
specific strings), wherein the entire set of strings is offered to the
user (perhaps at first use of the program) in a format that enables
easy and full localization of the program so long as each of the
strings is translated appropriately and inputted to the program. I
know of turtle.py and xturtle.py, but I'm thinking of starting
something from scratch. It's the easy localization I'm interested in.

Hope these questions are appropriate. I'm grateful to be able to ask them here.

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


Re: [Tutor] parsing a "chunked" text file

2010-03-18 Thread Stefan Behnel

Karim Liateni, 04.03.2010 01:23:

Steven D'Aprano wrote:

def skip_blanks(lines):
"""Remove leading and trailing whitespace, ignore blank lines."""
for line in lines:
line = line.strip()
if line:
yield line


Is there a big difference to write your first functions as below because
I am not familiar with yield keyword?

def skip_blanks(lines):
"""Remove leading and trailing whitespace, ignore blank lines."""
return [line.strip() in lines if line.strip()]


Yes, a *big* difference in the true sense of the word. Your code (assuming 
you meant to write "... for line in ..." ) evaluates the entire list 
comprehension before returning from the call. Steven's code returns a 
generator that only handles one line (or a couple of empty lines) at a 
time. So, assuming that this runs against a large file, Steven's code uses 
only a constant amount of memory, compared to the whole file in your case, 
and is likely also a lot faster than your code as it involves less looping.


Stefan

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


Re: [Tutor] parsing a "chunked" text file

2010-03-18 Thread Hugo Arts
On Thu, Mar 18, 2010 at 12:54 PM, Stefan Behnel  wrote:
> Karim Liateni, 04.03.2010 01:23:
>
> Yes, a *big* difference in the true sense of the word. Your code (assuming
> you meant to write "... for line in ..." ) evaluates the entire list
> comprehension before returning from the call. Steven's code returns a
> generator that only handles one line (or a couple of empty lines) at a time.
> So, assuming that this runs against a large file, Steven's code uses only a
> constant amount of memory, compared to the whole file in your case, and is
> likely also a lot faster than your code as it involves less looping.
>

Though, if you changed the brackets into parentheses, you'd get a
generator expression, which *is* equivalent to Steven's version,
except that it calls strip() twice, which is a bit wasteful.

If the unnecessary extra call bothers you, you could do one of two things:
1) Learn how the yield keyword works. You should do this. It's an
awesome feature, and you'll come across it many more times.
2) go functional and import itertools. ifilter with a generator
expression, like so (pure functional programmers can also use imap
instead of the generator expr., which might be faster. profile to be
sure)

def skip_blanks(lines):
return ifilter(None, (l.strip() for l in lines))

Very short, has all the memory and speed benefits of the generator.
Personally I really like terse functional programming like this,
though I believe the general consensus in the python community is that
imperative alternatives are usually clearer to read.

If you want to know more about the yield keyword:
A terse description (assumes that you know how iterators work) is
here: http://docs.python.org/tutorial/classes.html#generators
A more detailed description of iterators and generators can be found
here: http://www.ibm.com/developerworks/library/l-pycon.html

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


Re: [Tutor] Self-intro and two short newbie questions

2010-03-18 Thread Wayne Werner
On Thu, Mar 18, 2010 at 6:42 AM, Kevin Kirton  wrote:

> Hi all,
>
> I've committed myself to learning Python and have started reading
> "Learning Python" (Mark Lutz) and looking through various online
> resources.
> My career so far has involved a little high school teaching and about
> 10 years of translating Japanese to English, but no programming or
> coding.
>

Welcome to python! I've never read that book, but I hear it's pretty good.


>
> I've also joined this list today and this is my first post.
>
> My aim is to be able to create Python programs, specifically
> "activities" that work on the OLPC's XO laptops and SoaS (Sugar on a
> Stick).
>

I don't know anything about the SoaS, but I do know a teeny bit about OLPC's
XO laptops. Python is a great tool for several reasons - among them the
availability of source code allows experimentation by XO users, which is in
line with the XO philosophy.


>
> My questions are: how long would you estimate it to take and how
> complicated would it be to create the following as Python programs? (I
> know it varies depending on the person, but for example, how long
> would it take _you_?)
>
> (i) a simple guitar tuning program involving an image of a guitar and
> the playing of each of the standard strings of a guitar (E, A, D, G,
> B, E) upon key input by the user
> (something similar to this:
> http://www.gieson.com/Library/projects/utilities/tuner/ (page is 782kb
> to open))
> and
>

I could probably make something similar to that in less than a few hours,
and most of it would be learning how to output the sound. If I had that
knowledge I could make a VERY basic one in ~30 minutes, and make one that's
rather nice within an hour or two.


> (ii) a very basic turtle art program with an intentionally limited set
> of commands and on-screen display words (say, a total of 30 to 50
> specific strings), wherein the entire set of strings is offered to the
> user (perhaps at first use of the program) in a format that enables
> easy and full localization of the program so long as each of the
> strings is translated appropriately and inputted to the program. I
> know of turtle.py and xturtle.py, but I'm thinking of starting
> something from scratch. It's the easy localization I'm interested in.
>

That would probably take a little longer if only the more complicated
design. That sounds like a project that I would probably work on over the
course of a few days - some research, some design, some coding.

Both of these projects are very possible for the beginner/novice with a
little education (I'd start on the guitar tuner first as its level of
complexity is much lower).

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


Re: [Tutor] Assertion Error

2010-03-18 Thread Emile van Sebille

On 3/17/2010 11:02 PM sitharak said...


I tried this statement to store in RDF form


This is too specialized for this list.  I couldn't find a dedicated news 
group for this project, but there is an IRC support channel -- see 
http://en.wikipedia.org/wiki/RDFLib#Support


HTH,

Emile




store=TripleStore()

But i'm getting this error

Traceback (most recent call last):
   File "", line 1, in
 store=TripleStore()
   File "C:\Users\Administrator\Desktop\TripleStore.py", line 13, in __init__
 super(TripleStore, self).__init__(backend=backend)
   File "build\bdist.win32\egg\rdflib\Graph.py", line 1008, in __init__
 super(BackwardCompatGraph, self).__init__(store=backend)
   File "build\bdist.win32\egg\rdflib\Graph.py", line 815, in __init__
 assert self.store.context_aware, ("ConjunctiveGraph must be backed by"
AssertionError: ConjunctiveGraph must be backed by a context aware store.

plz help



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


Re: [Tutor] Self-intro and two short newbie questions

2010-03-18 Thread spir
On Thu, 18 Mar 2010 22:42:05 +1100
Kevin Kirton  wrote:

> My questions are: how long would you estimate it to take and how
> complicated would it be to create the following as Python programs? (I
> know it varies depending on the person, but for example, how long
> would it take _you_?)

My opinion:
The time required to make a working app (with exactly the same features, in the 
same language) by 2 trained programmers can easily range from 1 to 10. The time 
required to make a given app by a given programmer can easily range from 1 to 
10 depending on the level of sophistication. "Devil hides in the details." ;-)

Denis


vit e estrany

spir.wikidot.com

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


Re: [Tutor] Self-intro and two short newbie questions

2010-03-18 Thread Alan Gauld
"Kevin Kirton"  wrote 


know it varies depending on the person, but for example, how long
would it take _you_?)

(i) a simple guitar tuning program involving an image of a guitar and
the playing of each of the standard strings of a guitar (E, A, D, G,
B, E) upon key input by the user


For a professional standard finish, working full time  I'd be looking 
at a day or two.



(ii) a very basic turtle art program with an intentionally limited set
of commands and on-screen display words (say, a total of 30 to 50
specific strings), wherein the entire set of strings is offered to the
user (perhaps at first use of the program) in a format that enables
easy and full localization of the program so long as each of the
strings is translated appropriately and inputted to the program. I
know of turtle.py and xturtle.py, but I'm thinking of starting
something from scratch. It's the easy localization I'm interested in.


This might be three days.
You could do both projects to a good standard in a week.

However if you need to include things like user manuals, 
help system, online support(auto updates) etc plus 
installation programs (Dunno if thats relevant to OLPC etc)

You could easily double the time and effort.

HTH,

Alan G.

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


[Tutor] movement controls

2010-03-18 Thread snet-1
A little stuck and could do with any sudjestions.

Aim:-
When the character goes past the middle of the screen, the background & level 
move downwards so the character can get to higher places, think sonic the 
hedgehog.

This is the bit I'm having problems with, I can get the character to get to the 
center, the background moves up & down but the character won't go back down 
when the level returns to normal height.

if bkGroundRect['rect'].top < 0 and charRect['rect'].top < 
winCenterRect.top:

bkGroundRect['rect'].top += spY
platRect['rect'].top += spY
jumpRect.top += spY
charRect['dir'] = STOP


if levelRect['rect'].bottom > winHeight and charRect['rect'].centery == 
winCenterx:
bkGroundRect['rect'].bottom -= spY
platRect['rect'].bottom -= spY
#jumpRect.bottom -= spY
charRect['dir'] = STOP

  #--this won't execute ? --#   
if levelRect['rect'].bottom <= winHeight:
if charRect['rect'].centery >= winCenterx and charRect['rect'].centerx 
< jumpRect.centerx:
charRect['dir'] = DOWN

I've included the whole code as a note pad so the above makes more sense, don't 
worry about all the comments, that's just for my convenience.

Thanks guys

Mark

'knight meets wall, wall won't let knight pass, knight says 'neh'

import pygame, sys, time
from pygame.locals import *

pygame.init()
#--Display--#
winWidth = 400
winHeight = 400
winCenterx = int(winWidth / 2)
winCentery = int(winHeight / 2)
window = pygame.display.set_mode((winWidth, winHeight), 0, 32)
#--Display--#

#--Images--#
BackgroundImage = pygame.image.load('Background.jpg')
FloorImage = pygame.image.load('Floor.jpg')
BallImage = pygame.image.load('Ball.jpg')
#--Images--#

#--Movement Variables--#
forward = False
backward = False
jump = False
UP = 8
DOWN = 2
STOP = 5

spX = 3
spY = 5
#--Movement Variables--#

#--Level Rects--#
bkGroundScImage = pygame.transform.scale(BackgroundImage, (1000, 1000))
bkGroundRect = {'rect':pygame.Rect(0, -650, 1000, 1000), 'dir':UP}

levelScImage = pygame.transform.scale(FloorImage, (1000, 50))
levelRect = {'rect':pygame.Rect(0, winHeight - 50, 1000, 50), 'dir':DOWN}

platScImage = pygame.transform.scale(FloorImage, (100, 25))
platRect = {'rect':pygame.Rect(75, 270, 100, 25), 'dir':DOWN}

platScImage1 = pygame.transform.scale(FloorImage, (100, 25))
platRect1 = {'rect':pygame.Rect(225, 250, 100, 25), 'dir':UP}

platScImage2 = pygame.transform.scale(FloorImage, (100, 25))
platRect2 = {'rect':pygame.Rect(375, 200, 100, 25), 'dir':UP}

platScImage3 = pygame.transform.scale(FloorImage, (100, 25))
platRect3 = {'rect':pygame.Rect(575, 150, 100, 25), 'dir':UP}

platScImage4 = pygame.transform.scale(FloorImage, (100, 25))
platRect4 = {'rect':pygame.Rect(675, 150, 100, 25), 'dir':UP}

platScImage5 = pygame.transform.scale(FloorImage, (100, 25))
platRect5 = {'rect':pygame.Rect(575, 0, 100, 25), 'dir':UP}

platScImage6 = pygame.transform.scale(FloorImage, (100, 25))
platRect6 = {'rect':pygame.Rect(375, 0, 100, 25), 'dir':UP}
#--Level Rects--#
#--Caracter Rects--#
charScImage = pygame.transform.scale(BallImage, (50, 50))
charRect = {'rect':pygame.Rect(20, 300, 50, 50), 'dir':DOWN}

jumpScImage = pygame.transform.scale(FloorImage, (50, 140))
jumpRect = pygame.Rect(20, 210, 50, 140)

winCenterRectScImage = pygame.transform.scale(FloorImage, (60, 60))
winCenterRect = pygame.Rect(winCenterx  - 30, winCentery - 30, 60, 60)
#--Caracter Rects--#
#--Collision Variables--#

solidX = int(charRect['rect'].width - spX - spX - 2)
solidY = int(charRect['rect'].height - spY - spY- 1)
#--Collision Variables--#
while True:
#--Level & scenery--#
window.blit(bkGroundScImage, bkGroundRect['rect'])
window.blit(levelScImage, levelRect['rect'])
window.blit(platScImage, platRect['rect'])
window.blit(platScImage1, platRect1['rect'])
window.blit(platScImage2, platRect2['rect'])
window.blit(platScImage3, platRect3['rect'])
window.blit(platScImage4, platRect4['rect'])
window.blit(platScImage5, platRect5['rect'])
window.blit(platScImage6, platRect6['rect'])
levelRect['rect'].top = bkGroundRect['rect'].bottom

#--Level & scenery--#

#--Character--#
window.blit(winCenterRectScImage, winCenterRect)
winCenterRect.center = (winCenterx, winCentery)

window.blit(jumpScImage, jumpRect)
jumpRect.centerx = charRect['rect'].centerx

window.blit(charScImage, charRect['rect'])
#--Character--#

#--Input controls--#
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()

if event.type == KEYDOWN:
if event.key == K_RIGHT:
forward = True
backward = False
if event.key == K_LEFT:
backward = True
forward = False
if event.key == K_UP:
jump = True

if event.type == KEYUP:
if event.key == K

Re: [Tutor] movement controls

2010-03-18 Thread Luke Paireepinart
You should probably decouple the view from the model - have the character
move around in a 2d plane in the model and then just draw the level in a
certain area around the 2d coordinates of the character.

On Thu, Mar 18, 2010 at 6:51 PM,  wrote:

>  A little stuck and could do with any sudjestions.
>
> Aim:-
> When the character goes past the middle of the screen, the background &
> level move downwards so the character can get to higher places, think sonic
> the hedgehog.
>
> This is the bit I'm having problems with, I can get the character to get to
> the center, the background moves up & down but the character won't go back
> down when the level returns to normal height.
>
> if bkGroundRect['rect'].top < 0 and charRect['rect'].top <
> winCenterRect.top:
>
> bkGroundRect['rect'].top += spY
> platRect['rect'].top += spY
> jumpRect.top += spY
> charRect['dir'] = STOP
>
>
> if levelRect['rect'].bottom > winHeight and charRect['rect'].centery ==
> winCenterx:
> bkGroundRect['rect'].bottom -= spY
> platRect['rect'].bottom -= spY
> #jumpRect.bottom -= spY
> charRect['dir'] = STOP
>
>   #--this won't execute ? --#
> if levelRect['rect'].bottom <= winHeight:
> if charRect['rect'].centery >= winCenterx and
> charRect['rect'].centerx < jumpRect.centerx:
> charRect['dir'] = DOWN
>
> I've included the whole code as a note pad so the above makes more sense,
> don't worry about all the comments, that's just for my convenience.
>
> Thanks guys
>
> Mark
>
> 'knight meets wall, wall won't let knight pass, knight says 'neh'
>
>
> ___
> 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] Self-intro and two short newbie questions

2010-03-18 Thread Kevin Kirton
Thanks very much for the responses.
I feel encouraged now to try to create the guitar tuner program by
myself first, and then the simple turtle art program after that.
It's kind of both exhilarating and daunting that I don't know exactly
where to start at the moment, but that's the fun of learning I guess.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor