I tried your suggestion but it does not work for me. I get a syntax
error at use of the first question mark when trying it in Idle.
When I try it from the desktop, it just flashes a black screen and
returns me to the desktop.
What is the question mark used for? I looked up the use of % and the
glossary says it returns the modulus. I don't understand why I would
want the modulus of anything.
I like the idea of text = text because it allows me to more easily
change my text. 
As long as I put text = "Your Score is : " + str( Game.score_value) the
program works fine.
Sorry I need further help
Gene

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Tuesday, June 07, 2005 2:58 PM
To: tutor@python.org
Subject: Tutor Digest, Vol 16, Issue 21

Send Tutor mailing list submissions to
        tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
        [EMAIL PROTECTED]

You can reach the person managing the list at
        [EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

   1. repr() (Bernard Lebel)
   2. Re: repr() (Max Noel)
   3. Re: Text problem (Kent Johnson)
   4. Re: repr() (Danny Yoo)
   5. Re: More image manipulation (Terry Carroll)
   6. Re: repr() (Terry Carroll)
   7. Re: repr() (Bernard Lebel)
   8. Re: Trying Ruby... (Christian Wyglendowski)
   9. Re: More image manipulation (Terry Carroll)
  10. Re: repr() (Danny Yoo)
  11. Re: interactif or not (Alan G)
  12. Fwd:  More image manipulation (D. Hartley)


----------------------------------------------------------------------

Message: 1
Date: Tue, 7 Jun 2005 15:42:39 -0400
From: Bernard Lebel <[EMAIL PROTECTED]>
Subject: [Tutor] repr()
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1

Hello,

Possibly I am missing something, but how do you use the repr() function?

I type this ultra-simple function:

def myFunc(): print 'hello'

Then run

repr( myFunc )

Wich returns

'<function myFunc at 0x009C6630>'


Okay then I run

s = repr( myFunc() )
print s

Wich returns

'None'


Thanks
Bernard


------------------------------

Message: 2
Date: Tue, 7 Jun 2005 20:50:51 +0100
From: Max Noel <[EMAIL PROTECTED]>
Subject: Re: [Tutor] repr()
To: Bernard Lebel <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed


On Jun 7, 2005, at 20:42, Bernard Lebel wrote:

> repr( myFunc )
>
> Wich returns
>
> '<function myFunc at 0x009C6630>'
>
>
> Okay then I run
>
> s = repr( myFunc() )
> print s
>
> Wich returns
>
> 'None'

     That's perfectly normal. Your last assignment calls the  
function, then assigns to s the representation of the function's  
return value. A function that doesn't have a return statement returns  
None, and repr(None) == 'None'. Which is what you get.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"



------------------------------

Message: 3
Date: Tue, 07 Jun 2005 15:51:28 -0400
From: Kent Johnson <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Text problem
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=windows-1252; format=flowed

EUGENE ASTLEY wrote:
> Python, pygames problem.
> 
> At the end of my game, I go back to the desk top after displaying the 
> score of the player, as follows:
> 
> Def game_over(self)
> 
> Games.Message(screen = self.screen,
> 
>             X = 400, y = 400
> 
>             Text + ?Your Score is  ? + str(Game.score_value),
> 
>             Size = 60, color = color.green,
> 
>             Lifetime = 1000, after_death = self.screen.quit()
> 
>  
> 
> This works well but I would like to have several lines of text. The 
> triple quote method does not work. How can I get several lines of text

> into the message?

It looks like you are using livewires and you have paraphrased your
code. It's helpful if you copy and paste the exact code you have tried
and any error message you get.

Looking at livewires.games.py I see

class Message(Text):

    def __init__ (self, screen, x, y, text, size, color,
                  a=0, dx=0, dy=0, da=0,
                  lifetime=0, after_death=None):

so I would try something like this:

def gameOver(self):
   text = ?""Your Score is  %s
Thank you for playing
Please come again""? % Game.score_value
    games.Message(x = 400, y = 400, text = text,
            size = 60, color = color.green,
            lifetime = 1000, after_death = self.screen.quit())

Kent



------------------------------

Message: 4
Date: Tue, 7 Jun 2005 13:25:15 -0700 (PDT)
From: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] repr()
To: Bernard Lebel <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: TEXT/PLAIN; charset=US-ASCII


> Okay then I run
>
> s = repr( myFunc() )
> print s
>
> Wich returns
>
> 'None'


Hi Bernard,

Ok, what do you expect to see instead of 'None'?  I ask this to make
sure
I understand the situation better.

Best of wishes?



------------------------------

Message: 5
Date: Tue, 7 Jun 2005 13:26:16 -0700 (PDT)
From: Terry Carroll <[EMAIL PROTECTED]>
Subject: Re: [Tutor] More image manipulation
To: "D. Hartley" <[EMAIL PROTECTED]>,   Python tutor
        <tutor@python.org>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Tue, 7 Jun 2005, D. Hartley wrote:

> def findlist():
>     newlist = []
>     for i in range(480):
>         line = fromlist[:640]
>         del fromlist[:640]
>         x = line.index(195)
>         y = x + 5
>         z = line[x:y]
>         del line[x:y]
>         for i in z:
>             newlist.append(i)
>         for i in line:
>             newlist.append(i)
>     return newlist

where does the variable named "fromlist" come from?  It's not passed
into 
the method as a parameter.

> B). If I run the steps in makenewpic one by one in the interpreter, it
> doesnt give me any "x not in list" error, it lets me do the result =
> newim.putdata(a) just fine.  But then when I type result.show() it
> tells me 'NoneType' object has no attribute 'show'.  At first I
> thought it was because when I was creating the blank newim, I was
> using mode "RGB" and adding a list of "P" pixel values to it. But I
> fixed it so that my newim is also mode "P" and it still tells me that
> type(result) = None.

You have:

>     result = newim.putdata(a)
>     return result

>From the PIL docs, putdata does not appear to return an image.  The
docs
for putdata say:

  putdata

  im.putdata(data)
  im.putdata(data, scale, offset)

Usually, when a PIL method returns an image, the docs say "=> image" 
after the method signature.  My guess is that putdata returns None,
which 
would be consistent with the error message "'NoneType' object has no 
attribute 'show'."

You'll probably want:

     newim.putdata(a)
     return newim

Instead.




------------------------------

Message: 6
Date: Tue, 7 Jun 2005 13:29:31 -0700 (PDT)
From: Terry Carroll <[EMAIL PROTECTED]>
Subject: Re: [Tutor] repr()
To: Bernard Lebel <[EMAIL PROTECTED]>, <tutor@python.org>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Tue, 7 Jun 2005, Bernard Lebel wrote:

> repr( myFunc )
> '<function myFunc at 0x009C6630>'
> 
> 
> 
> s = repr( myFunc() )
> print s
> 
> 'None'

In the first example, your repr invocation is:

  repr(myFunc)

i.e., you're asking for the repr of the function myFunc.

In the second example, your repr invocation is:

  repr(myFunc())

i.e., you're calling the function myFunc and asking for the repr of the 
*result*



------------------------------

Message: 7
Date: Tue, 7 Jun 2005 16:42:05 -0400
From: Bernard Lebel <[EMAIL PROTECTED]>
Subject: Re: [Tutor] repr()
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1

Ok thanks a lot.

The real question is, then, is there a way I can print the code of a
function as a string? Something like....

'def myFunction: print "hello"'


Thanks
Bernard



On 6/7/05, Max Noel <[EMAIL PROTECTED]> wrote:
> 
> On Jun 7, 2005, at 20:42, Bernard Lebel wrote:
> 
> > repr( myFunc )
> >
> > Wich returns
> >
> > '<function myFunc at 0x009C6630>'
> >
> >
> > Okay then I run
> >
> > s = repr( myFunc() )
> > print s
> >
> > Wich returns
> >
> > 'None'
> 
>      That's perfectly normal. Your last assignment calls the
> function, then assigns to s the representation of the function's
> return value. A function that doesn't have a return statement returns
> None, and repr(None) == 'None'. Which is what you get.
> 
> -- Max
> maxnoel_fr at yahoo dot fr -- ICQ #85274019
> "Look at you hacker... A pathetic creature of meat and bone, panting
> and sweating as you run through my corridors... How can you challenge
> a perfect, immortal machine?"
> 
>


------------------------------

Message: 8
Date: Tue, 7 Jun 2005 15:50:38 -0500
From: "Christian Wyglendowski" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Trying Ruby...
To: "Terry Carroll" <[EMAIL PROTECTED]>, <tutor@python.org>
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain;       charset="us-ascii"

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Terry Carroll
> Sent: Monday, June 06, 2005 8:20 PM
> To: tutor@python.org
> Subject: [Tutor] Trying Ruby...
> 
> This message is not as off-topic as it at first appears.
> 
> I'm a user of Activestate's ActivePython under Windows/XP.  I 
> want to give
> Ruby a spin, just for the heck of it.  I vaguely recall a post a few
> months ago, I don't know if it was in this forum, where someone had a
> problem in Python, and it turns out it was because a Ruby 
> install messed
> with some setting, perhaps in the Windows registry.

Terry,

If I remember correctly, it had to do with Tk getting messed up.  But
that's all I recall :-)

Christian
http://www.dowski.com 



------------------------------

Message: 9
Date: Tue, 7 Jun 2005 13:52:08 -0700 (PDT)
From: Terry Carroll <[EMAIL PROTECTED]>
Subject: Re: [Tutor] More image manipulation
To: Python tutor <tutor@python.org>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Tue, 7 Jun 2005, Terry Carroll wrote:

> On Tue, 7 Jun 2005, D. Hartley wrote:
> 
> > def findlist():
> >     newlist = []
> >     for i in range(480):
> >         line = fromlist[:640]
> >         del fromlist[:640]
> >         x = line.index(195)
> >         y = x + 5
> >         z = line[x:y]
> >         del line[x:y]
> >         for i in z:
> >             newlist.append(i)
> >         for i in line:
> >             newlist.append(i)
> >     return newlist
> 
> where does the variable named "fromlist" come from?  It's not passed
into 
> the method as a parameter.

I'm thinking more and more that this is the issue.  

Take a look at this, and see if it gives you the flavor.  Only the third

approach actually gives you what (I think) you want, rather than reusing

the same list over and over.

def testit1():
   print fromlist1[0]
   del fromlist1[0]
   return
fromlist1 = ['a', 'b', 'c', 'd']
print "testit1: Denise problem"
testit1()
testit1()
testit1()

def testit2(flist):
   print flist[0]
   del flist[0]
   return
fromlist2 = ['a', 'b', 'c', 'd']
print "testit2: Python Gotcha #6"
# http://www.ferg.org/projects/python_gotchas.html
testit2(fromlist2)
testit2(fromlist2)
testit2(fromlist2)

def testit3(flist):
   mylist = flist[:] 
   # copy the list rather than mutating it for next time
   print mylist[0]
   del mylist[0]
   return
fromlist3 = ['a', 'b', 'c', 'd']
print "testit3: the right way"
testit3(fromlist3)
testit3(fromlist3)
testit3(fromlist3)





------------------------------

Message: 10
Date: Tue, 7 Jun 2005 14:04:08 -0700 (PDT)
From: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] repr()
To: Bernard Lebel <[EMAIL PROTECTED]>
Cc: Tutor <tutor@python.org>
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: TEXT/PLAIN; charset=US-ASCII



On Tue, 7 Jun 2005, Bernard Lebel wrote:

> The real question is, then, is there a way I can print the code of a
> function as a string? Something like....
>
> 'def myFunction: print "hello"'

Hi Bernard,


Ah, ok.  You can use 'inspect':

    http://www.python.org/doc/lib/inspect-source.html

For example:

######
>>> import heapq
>>> import inspect
>>> print inspect.getsource(heapq.heappop)
def heappop(heap):
    """Pop the smallest item off the heap, maintaining the heap
invariant."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is
empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        _siftup(heap, 0)
    else:
        returnitem = lastelt
    return returnitem
######


It doesn't always work: it'll work only if the function is a pure-Python
function that's defined in a file that Python can find, since functions
themselves don't carry their own textual representation around.

Functions do contain the file name as well as their corresponding line
numbers:

######
>>> heapq.__file__
'/usr/lib/python2.3/heapq.pyc'
>>> heapq.heappop.func_code.co_firstlineno
136
######

which is sorta how inspect.getsource() works.


Best of wishes!



------------------------------

Message: 11
Date: Tue, 7 Jun 2005 22:15:57 +0100
From: "Alan G" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] interactif or not
To: "Cedric BRINER" <[EMAIL PROTECTED]>, <tutor@python.org>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain;       charset="iso-8859-1"

> > look to see if stdin is a tty. Unix is usually very careful about
who has a
> > "controlling tty" and who does not. In Python, file objects have
an isatty()
> > method that will return True or False.
> >
> > import sys
> > isinteractive = sys.stdin.isatty()
> > if isinteractive:
> > ...
> > else:
> > ...
> >
>
> tested and it works !

Aha! I knew about tty on Unix so I looked in the os module for it,
I never thought of it being a file method....

Alan G.



------------------------------

Message: 12
Date: Tue, 7 Jun 2005 14:57:33 -0700
From: "D. Hartley" <[EMAIL PROTECTED]>
Subject: [Tutor] Fwd:  More image manipulation
To: Python tutor <tutor@python.org>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1

Sorry, Terry, forgot to reply to the whole list. Here it is:

---------- Forwarded message ----------
From: D. Hartley <[EMAIL PROTECTED]>
Date: Jun 7, 2005 2:49 PM
Subject: Re: [Tutor] More image manipulation
To: Terry Carroll <[EMAIL PROTECTED]>


Terry,

OK. I tried them out and I do see the diffence. (btw, testit1 gave me
the following error:

Traceback (most recent call last):
 File "<pyshell#72>", line 1, in ?
   testit1()
 File "<pyshell#68>", line 3, in testit1
   del fromlist[0]
IndexError: list assignment index out of range

... was that something you intended? that didnt happen with my
original problem).

Anyway I def notice the diff between 2 and 3, but see here's the thing:

I think I *do* want it like #2, becaues I want it to keep returning
the same list (i.e., move on and use line 2 (b), and then line 3 (c),
and so on), rather than keep iterating over the same first line (a)
over and over again. I want to take the first line in the picture,
rearrange the pixels, and pop that line into the new list that I can
then (eventually) create a new image from. I *thought* my list was
populated (it's 307200 pixels long, after all), but it wont work when
i try to putdata it onto a new blank image.



> > where does the variable named "fromlist" come from?  It's not passed
into
> > the method as a parameter.

No, I had it defined right before the function. it pulls it in just
fine. And like I said, the function returns me with a list of 307200
values - which makes me think that it "got" all 307200 of the original
pixels, and performed the function correctly on each line. However,
when I did the following:

def test():
   y = findlist()
   for i in range(480):
       piece = y[:640]
       del y[:640]
       print "Line",i," - ",y[:5]

to look at the beginning five pixels of each of the new lines, for
line 479 (the last i), it gave me []. This doesnt make sense!

Hope I didnt miss something from your explanation...?

~Denise


------------------------------

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


End of Tutor Digest, Vol 16, Issue 21
*************************************

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

Reply via email to