Re: [Tutor] When are strings interned?

2009-07-02 Thread Jeremiah Dodds
On Wed, Jul 1, 2009 at 4:44 PM, Angus Rodgers  wrote:

> Hello, world!
>
> This is my first post to the Tutor list (although I've already
> posted to comp.lang.python a couple of times).
>
> I'm currently reading Chapter 4 of Wesley Chun's book, "Core
> Python Programming" (2nd ed.).
>
> I find this, in Python 2.5.4, on my Win98SE system (using IDLE):
>
> >>> n = "colourless"
> >>> o = "colourless"
> >>> n == o
> True
> >>> n is o
> True
> >>> p = "green ideas"
> >>> q = "green ideas"
> >>> p == q
> True
> >>> p is q
> False
>
> Why the difference?
> --
>
>

IIRC, in cPython (the "defaul" python available from python.org), there is
an optimization done for strings (and I think integers) below a certain
size. This is an implementation detail, and could be different in (for
instance) Jython.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When are strings interned?

2009-07-02 Thread Lie Ryan
Angus Rodgers wrote:
> Hello, world!
> 
> This is my first post to the Tutor list (although I've already
> posted to comp.lang.python a couple of times).
> 
> I'm currently reading Chapter 4 of Wesley Chun's book, "Core 
> Python Programming" (2nd ed.).
> 
> I find this, in Python 2.5.4, on my Win98SE system (using IDLE):
> 
 n = "colourless"
 o = "colourless"
 n == o
> True
 n is o
> True
 p = "green ideas"
 q = "green ideas"
 p == q
> True
 p is q
> False
> 
> Why the difference?

In this particular case, the reason is because "colourless" can be used
as an identifier. Now, before I continue, I need to warn, never to rely
on any sort of interning behavior; as they are strictly implementation
detail, implementation specific, and is NOT the behavior of Python (but
only the behavior of CPython).

Identifier are strings that can be used for names (variables). In python
most name lookups are actually a dict lookup (except for locals).
Strings that can be used as identifier are interned to speed up these
lookups. Identifiers cannot contain spaces, that's why green ideas are
not interned.

And... have I told you not to rely on this behavior? NEVER rely on this
implementation details. Once you get bitten by it, you'll regret it.

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


[Tutor] window graphics

2009-07-02 Thread David H. Burns
I am new to Python and I'm looking for help on graphics in Python3.0. 
All the graphics libraries I've seen are far to complex (and don't seem 
compatible with 3. What I really need to know is two things (1) how to 
set up a graphic window and (2)how to plot a pixel. Basically that's all 
a "graphics package" needs. Is this the right group?


Any help appreciated,

David

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


Re: [Tutor] When are strings interned?

2009-07-02 Thread Andrew Fithian
My guess is that Python sees the space and decides it isn't a short
string so it doesn't get interned. I got the expected results when I
used 'green_ideas' instead of 'green ideas'.
-Drew



On Wed, Jul 1, 2009 at 6:43 PM, Marc Tompkins wrote:
> On Wed, Jul 1, 2009 at 5:29 PM, Robert Berman  wrote:
>>
>> > >>> n = "colourless"
>> > >>> o = "colourless"
>> > >>> n == o
>> > True
>> > >>> n is o
>> > True
>> > >>> p = "green ideas"
>> > >>> q = "green ideas"
>> > >>> p == q
>> > True
>> > >>> p is q
>> > False
>> >
>> > Why the difference?
>>
>> The string p is equal to the string q. The object p is not the object q.
>>
>> Robert
>
> Yes, but did you read his first example?  That one has me scratching my
> head.
> --
> www.fsrtechnologies.com
>
> ___
> Tutor maillist  -  tu...@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help with python game program

2009-07-02 Thread Lie Ryan
Luke Paireepinart wrote:
> Please don't reply to messages like this.  If you are starting a new
> thread, send a new e-mail to tutor@python.org .
>  DO NOT start a thread by replying to another message.  If you do, it
> will bork on people's machines who use threaded e-mail readers.  also,
> please remove long, irrelevant quotations from your e-mails unless you
> reference it.  for example, the quoted text in your e-mail is at least
> 10x longer than the actual content.
> I believe mark already answered your question.
> Thanks,
> -Luke
> 
> On Tue, Jun 30, 2009 at 7:38 PM, jonathan wallis
> mailto:mindboggle...@gmail.com>> wrote:
> 
> My problem is simple, is their a way to make a variable equal
> multiple numbers? Such as X = 5 through 10, and then the program
> makes x  equal something random 5 through 10, or something similar.

And most importantly, don't top-post.

  Because it messes up reading order.
  Why is top-posting harmful?

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


Re: [Tutor] window graphics

2009-07-02 Thread Gregor Lingl

Hi David,

Python 3 (preferably 3.1)  has a very easy to use graphics module in the 
standard library:
the turtle module. It has a lot of capabilities, but alas, its working 
with geometrical

objects and   doesn't allow to adress single pixels  .

Get started by writing:

>>> from turtle import *
>>> forward(100)

You can find the docs in Python Docs'  global module index

You can find example scripts in the Demo directory of the source code 
distribution

or here:

http://svn.python.org/view/python/branches/py3k/Demo/turtle/

If you want to give it a try and need more information, please feel free 
to ask


Regards,
Gregor

David H. Burns schrieb:
I am new to Python and I'm looking for help on graphics in Python3.0. 
All the graphics libraries I've seen are far to complex (and don't 
seem compatible with 3. What I really need to know is two things (1) 
how to set up a graphic window and (2)how to plot a pixel. Basically 
that's all a "graphics package" needs. Is this the right group?


Any help appreciated,

David

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




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


Re: [Tutor] window graphics

2009-07-02 Thread A.T.Hofkamp

David H. Burns wrote:
I am new to Python and I'm looking for help on graphics in Python3.0. 
All the graphics libraries I've seen are far to complex (and don't seem 
compatible with 3. What I really need to know is two things (1) how to 
set up a graphic window and (2)how to plot a pixel. Basically that's all 
a "graphics package" needs. Is this the right group?


For Python help it is, for specific GUI-toolkit related questions, the group 
for the toolkit that you use may be better.


With respect to your question, it is too early to use Python 3.0. As you have 
found out already, most libraries don't support 3.0 yet. Also, most of the 
Python tutorials and documentation is written for Python 2.


I'd recommend that you start with Python 2.6 instead. Once you understand the 
language, making the transition to Python 3 will be relatively easy.
(and, starting with 2.6, the language is slowly changing towards 3, so by the 
time 2.8 or 2.9 is released, you'll be writing almost Python 3)



Indeed, many graphics packages are complex, since they aim to give full GUI 
toolkit coverage so you can make full-blown graphic applications. However, 
when you restrict yourself to just drawing on a canvas, the toolkits are 
fairly simple and similar (at least the ones I have seen, PyGTK and a little 
PyQT).
Most tutorials for the GUI toolkits start rendering lines at a canvas at some 
point, so take that as a starting point, and strip all the stuff you don't need.


Another approach may be to use pygame instead of a GUI toolkit.


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


Re: [Tutor] window graphics

2009-07-02 Thread Alan Gauld


"David H. Burns"  wrote

All the graphics libraries I've seen are far to complex (and don't seem 
compatible with 3. 


See the other posts re the wisdom of using Python 3 at this stage, 
however


What I really need to know is two things (1) how to 
set up a graphic window 



from tkinter import *
tk = Tk()
c = Canvas(tk, height=100,width=100)
c.pack()
c.create_line(0,15,30,75)

1

c.create_oval(50,70,80,90)

2

tk.mainloop()


2)how to plot a pixel. Basically that's all  a "graphics package" needs. 

There is no pixel method per say but you can plot a single pixel 
sized oval.


c.create_oval(4,4,4,4)

Which is hard to see but here is a fuller example:


tk = Tk()
c = Canvas(tk, height=100,width=100)
c.pack()
for x in range(25,50):

   c.create_oval(x,x,x,x)


tk.mainloop()


3) Is this the right group?
Yes.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/l2p/


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


[Tutor] IDLE 3.0 menu weirdness

2009-07-02 Thread Alan Gauld

I tried posting this on the IDLE list but got no replies so

I've been updating my online tutorial to Python v3.
I've come across a weird "feature" of IDLE 3:
The menus show as a pair of up/down arrows! 
Clicking the arrows does nothing obvious.


If you select a menu and then hit the letter of the 
menu item it works OK but you can't see it on screen 
so can't use the mouse. This is a real pain! 
Has anyone else found this? Or is it just me?

And does anyone know what to do to fix it ?

I'm using Windows XP Pro SP2 and Python 3.0


import sys
sys.version

'3.0 (r30:67503, Dec 11 2008, 09:05:16) [MSC v.1500 32 bit (Intel)]'




IDLE for 2.5.1 works fine on the same machine

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/l2p/

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


Re: [Tutor] window graphics

2009-07-02 Thread Kent Johnson
On Wed, Jul 1, 2009 at 3:49 PM, David H. Burns wrote:
> I am new to Python and I'm looking for help on graphics in Python3.0. All
> the graphics libraries I've seen are far to complex (and don't seem
> compatible with 3. What I really need to know is two things (1) how to set
> up a graphic window and (2)how to plot a pixel. Basically that's all a
> "graphics package" needs.

Why do you want to plot single pixels? Drawing single pixels directly
to a window is likely to be too slow for any substantive project.

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


Re: [Tutor] window graphics

2009-07-02 Thread Kent Johnson
Forwarding to the list with my reply...

On Thu, Jul 2, 2009 at 8:16 PM, David H. Burns wrote:
> I don't necessarily want to plot single pixels. I'm not at all sure what
> "directly" means in this context. "Plotting" to the screen involves sending
> data to a software algorithm which invokes the appropriate hardware to "turn
> on" the pixel. What I want is a simple and versatile way of displaying
> graphics. The ability to display a single pixel when desired seems necessary
> for that. I don't see that plotting single pixel would be slower than any
> other method, be cause at some point in any graphics package some algorithm
> has to do exactly that. It is true that modern graphics cards are
> complicated and have their own processors which allow many "built in"
> features using both hardware and software algorithms. So  it may be that
> what I think I want to do not the most efficient way to use them. But these
> cards musts be addressed by some software routine. I guess that is what I am
> looking for.

My point is, you should look for a higher-level of interface than
single pixels. What do you want to plot? Bitmap images? Graphs and
charts? Sprites?

Pygame and Pyglets and PIL will help to create and draw bitmaps and sprites.
PyOpenGL is perhaps the closest to the hardware.
matplotlib and a host of others are good for graphs and charts.
There are several good 3-D rendering programs for python
Tkinter Canvas lets you draw basic shapes
etc

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