[Tutor] error in using TurtleWorld modules, ThinkPython.org Book

2011-07-17 Thread Surya P.K. Kasturi
I am using Think Python book,  to learn python.
There is a module TurtleWorld that they described to draw lines <
http://www.greenteapress.com/thinkpython/swampy/install.html>

Though I could run the below code in the python shell, I couldn't do it
through a script file.


This is the script :

from TurtleWorld import *

world = TurtleWorld
bob = Turtle()
print bob

fd(bob, 100)
lt(bob)
fd(bob, 100)
lt(bob)
fd(bob, 100)
lt(bob)
fd(bob, 100)

wait_for_user()

*This is the following error I got at terminal :*


Traceback (most recent call last):
  File "turtle.py", line 7, in 
fd(bob, 100)
  File "/usr/local/lib/python2.6/dist-packages/TurtleWorld.py", line 187, in
fd
self.world.canvas.line([p1, p2], fill=self.pen_color)
AttributeError: 'NoneType' object has no attribute 'canvas'

*Could you help me to fix this error, please!*
*
*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to add directory to python search list

2011-07-17 Thread Peter Otten
Surya P.K. Kasturi wrote:

> OS : Ubuntu Linux
> Python Version : 2.6.4
> 
> I have some third party modules to be installed in my computer.
> So, I want to add the module directory to python search list.

The way I find most convenient is to create a text file with the .pth suffix
in a directory that is already seen by Python. I use the file

~/.local/lib/python2.6/site-packages/lib.pth

That file contains paths to the directories you want Python to see, one path 
per line.




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


Re: [Tutor] error in using TurtleWorld modules, ThinkPython.org Book

2011-07-17 Thread Peter Otten
Surya P.K. Kasturi wrote:

> I am using Think Python book,  to learn python.
> There is a module TurtleWorld that they described to draw lines <
> http://www.greenteapress.com/thinkpython/swampy/install.html>
> 
> Though I could run the below code in the python shell, I couldn't do it
> through a script file.
> 
> 
> This is the script :
> 
> from TurtleWorld import *
> 
> world = TurtleWorld

You forgot the parens in

world = TurtleWorld()

and therefore your turtle Bob

> bob = Turtle()
> fd(bob, 100)

has no world to live and move in.


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


Re: [Tutor] how to add directory to python search list

2011-07-17 Thread Steven D'Aprano

Surya P.K. Kasturi wrote:


can you tell me in detail how to do this.
I am new to linux.


"this" being:


On Sat, Jul 16, 2011 at 11:48 AM, Alan Gauld wrote:

You need to add the folder to your PYTHONPATH environment variable.
You usually do this your .login or .profile file.

Python will add the contents of PYTHONPATH to sys.path on startup.


(Surya, on this list we prefer if people don't top-post.)

What Alan means is for you to edit your login file so that it creates an 
environment variable. How you do that depends on which shell you are 
using. If you don't know which shell, try this:


(1) Open a fresh terminal window.
(2) Type "echo $SHELL" (without the quotation marks) and press Enter.

This will print something like this:


[steve@sylar ~]$ echo $SHELL
/bin/bash


So I am running "bash" as my shell. So I have the following line in my 
bash login file, .bashrc:



export PYTHONPATH=/home/steve/python/


That creates an environment variable, PYTHONPATH, which Python will 
automatically add to sys.path.


(Other shells will do this differently.)


Another alternative: I also have set a startup file:


export PYTHONSTARTUP=/home/steve/python/startup.py


I can put any Python code I like in startup.py and it will be run just 
before the interactive interpreter.


Or you can follow Peter's advice and use a .pth file.



--
Steven

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


Re: [Tutor] Hello World in Python without space

2011-07-17 Thread Lisi
On Saturday 16 July 2011 03:15:12 Richard D. Moores wrote:
> But that makes me wonder if there isn't a simpler way to do it with
> Python -- to delete the contents of a file without deleting the file?

Up to now, knowing no better ;-), I have opened the file in, or copied and 
pasted the contents of a file into, a word processor and turned on the 
non-printing characters.  It is then easy to see extraneous spaces, empty 
lines etc.  I then go back to the editor and do the revealed editing.

Rough, ready and cobbled - but easy, and it works. ;-)

If you use Windows and have no idea what I am talking about, I apologise.  It 
is so long since I used Windows that I have forgotten much of what it can and 
cannot do; and I don't know whether it can do this.

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


Re: [Tutor] error in using TurtleWorld modules, ThinkPython.org Book

2011-07-17 Thread Surya P.K. Kasturi
Thanks, .. that was a silly mistake.


On Sun, Jul 17, 2011 at 2:56 PM, Peter Otten <__pete...@web.de> wrote:

> Surya P.K. Kasturi wrote:
>
> > I am using Think Python book,  to learn python.
> > There is a module TurtleWorld that they described to draw lines <
> > http://www.greenteapress.com/thinkpython/swampy/install.html>
> >
> > Though I could run the below code in the python shell, I couldn't do it
> > through a script file.
> >
> >
> > This is the script :
> >
> > from TurtleWorld import *
> >
> > world = TurtleWorld
>
> You forgot the parens in
>
> world = TurtleWorld()
>
> and therefore your turtle Bob
>
> > bob = Turtle()
> > fd(bob, 100)
>
> has no world to live and move in.
>
>
> ___
> 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] how to add directory to python search list

2011-07-17 Thread Surya P.K. Kasturi
Thanks a lot. your posts are really helpful.

On Sun, Jul 17, 2011 at 4:41 PM, Steven D'Aprano wrote:

> Surya P.K. Kasturi wrote:
>
>  can you tell me in detail how to do this.
>> I am new to linux.
>>
>
> "this" being:
>
>  On Sat, Jul 16, 2011 at 11:48 AM, Alan Gauld *
>> *wrote:
>>
>>> You need to add the folder to your PYTHONPATH environment variable.
>>>
>>> You usually do this your .login or .profile file.
>>>
>>> Python will add the contents of PYTHONPATH to sys.path on startup.
>>>
>>
> (Surya, on this list we prefer if people don't top-post.)
>
> What Alan means is for you to edit your login file so that it creates an
> environment variable. How you do that depends on which shell you are using.
> If you don't know which shell, try this:
>
> (1) Open a fresh terminal window.
> (2) Type "echo $SHELL" (without the quotation marks) and press Enter.
>
> This will print something like this:
>
>
> [steve@sylar ~]$ echo $SHELL
> /bin/bash
>
>
> So I am running "bash" as my shell. So I have the following line in my bash
> login file, .bashrc:
>
>
> export PYTHONPATH=/home/steve/python/
>
>
> That creates an environment variable, PYTHONPATH, which Python will
> automatically add to sys.path.
>
> (Other shells will do this differently.)
>
>
> Another alternative: I also have set a startup file:
>
>
> export PYTHONSTARTUP=/home/steve/**python/startup.py
>
>
> I can put any Python code I like in startup.py and it will be run just
> before the interactive interpreter.
>
> Or you can follow Peter's advice and use a .pth file.
>
>
>
> --
> Steven
>
>
> __**_
> 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] what is 'doubleword alignment'?

2011-07-17 Thread Lisi
On Saturday 16 July 2011 21:53:55 Albert-Jan Roskam wrote:
> I know that the buffer is comprised of variables of 8-bytes, or multiples
> thereof, each. Numeric variables are 8 bytes, char vars are at least 8
> bytes. For example, a 10-byte value is 'ceiled' to 18 bytes. This is done
> with padding (spaces, I think). But the aligment part...?
then wrote:
> Got it already, I think. The word boundary of one chunk of information (in
> my case 8 bytes) is aligned in the computer's memory such that the
> boundary's address is a power of two.

Sorry to be slow.  Blame virtually no sleep last night ;-(  But even were the 
power of two bit correct (and I see subsequently that it is not), how is 18 a 
power of two?

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


Re: [Tutor] what is 'doubleword alignment'?

2011-07-17 Thread Walter Prins
On 17 July 2011 15:26, Lisi  wrote:

> Sorry to be slow.  Blame virtually no sleep last night ;-(  But even were
> the
> power of two bit correct (and I see subsequently that it is not), how is 18
> a
> power of two?
>
>
The 18 bytes is a bit of an irrelevance.  The point is that if the start of
the buffer falls on a dword (double word) alligned memory location then in
theory the access should be faster.  The term is a little bit ambiguous
because strictly speaking different processors have different word sizes.
Even so, usually when people speak of double-word alignment, it's often the
case that the term word in such a context has its original meaning, e.g. 16
bits.  A dword is then 32bits or 4 bytes.   A doubleword aligned memory
address is, using these assumptions, therefore an address that is divisible
by 4.  Obviously if the word size is 32bits, then a double word would be
64bits and a doubleword aligned address would need to be divisible by 8.  As
an aside, this type of optimization is often taken care of by compilers
under the hood, and in any case it's generally not something that you'll
really be considering as a Python programmer.  (If however you were working
on one of the Python runtimes or implementations, then you might well be
sometimes considering this type of thing, depending on exactly how
performance critical what you are working might be and what the runtime was
being implemented in.)

Regards

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


Re: [Tutor] Filling orders FIFO

2011-07-17 Thread Steven D'Aprano

Izz ad-Din Ruhulessin wrote:

Why are you doing it at the low level? Have you consideren using a framework
like Django for example?


Who is this question addressed to? Me?

If so, my answer is that Django is an awfully large dependency if all 
you need is a queue.


But if you think that Django has a good solution to the problem, by all 
means show us how you would use it.



P.S. we prefer that you don't top-post on this mailing list. It makes it 
easier to understand replies if they follow what they are replying to, 
rather than come before.


Steven.




2011/7/16 Steven D'Aprano 


Charles John wrote:


Hi I am new to python and was wondering what the best way to create an
order(bid and offer) queue, then match a bid and offer so that if
bid==offer, creates a filled order FIFO in python cgi using mysql? Does
anybody have any ideas? It would be greatly appreciated.


The simplest way to use a queue is with a list:

queue = []

You push items onto the queue with queue.append(item) and pop them off with
queue.pop(0).

However, popping items may be slow if the queue grows very large (tens of
thousands of items). It might be better to use a deque (double ended queue)
instead of a list:

from collections import deque
queue = deque()

To push items onto the right hand side of the queue, then pop them off the
left hand side:

queue.append(item)
queue.popleft()


As for the rest of your question, I don't understand what you mean by an
order(bid and offer) queue. Perhaps you could give an example of what you
mean.


--
Steven
__**_
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] how to add directory to python search list

2011-07-17 Thread ALAN GAULD
It depends on what shell you are using.

Most beginners use the Bash shell and for that you need to open your 
.bash_profile (or .bashrc, I can't recall the preferred one for env vars...)
and add a line like:

export PYTHONPATH=$PYTHONPATH:/path/to/my/python/modules

Next time you login Python should find your modules OK.

HTH

 Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/






From: Surya P.K. Kasturi 
To: Alan Gauld 
Cc: Tutor@python.org
Sent: Sunday, 17 July, 2011 7:45:08
Subject: Re: how to add directory to python search list

Mr. Gauld 

can you tell me in detail how to do this.
I am new to linux.


On Sat, Jul 16, 2011 at 11:48 AM, Alan Gauld  wrote:

Surya P.K. Kasturi wrote:
>
>OS : Ubuntu Linux
>>Python Version : 2.6.4
>>
>>I have some third party modules to be installed in my computer.
>>So, I want to add the module directory to python search list.
>>
>>I used :
>>
>>*>>> import sys*
>>*>>> sys.path.append('directory address')*
>>*
>>*
>>this could do my work but as soon as I close the terminal and reopen it, I
>>

You need to add the folder to your PYTHONPATH environment variable.
>You usually do this your .login or .profile file.
>
>Python will add the contents of PYTHONPATH to sys.path on startup.
>
>HTH,
>
>
>Alan G
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what is 'doubleword alignment'?

2011-07-17 Thread Kushal Kumaran
On Sun, Jul 17, 2011 at 9:15 PM, Walter Prins  wrote:
>
>
> On 17 July 2011 15:26, Lisi  wrote:
>>
>> Sorry to be slow.  Blame virtually no sleep last night ;-(  But even were
>> the
>> power of two bit correct (and I see subsequently that it is not), how is
>> 18 a
>> power of two?
>>
>
> The 18 bytes is a bit of an irrelevance.  The point is that if the start of
> the buffer falls on a dword (double word) alligned memory location then in
> theory the access should be faster.  The term is a little bit ambiguous
> because strictly speaking different processors have different word sizes.
> Even so, usually when people speak of double-word alignment, it's often the
> case that the term word in such a context has its original meaning, e.g. 16
> bits.  A dword is then 32bits or 4 bytes.   A doubleword aligned memory
> address is, using these assumptions, therefore an address that is divisible
> by 4.  Obviously if the word size is 32bits, then a double word would be
> 64bits and a doubleword aligned address would need to be divisible by 8.  As
> an aside, this type of optimization is often taken care of by compilers
> under the hood, and in any case it's generally not something that you'll
> really be considering as a Python programmer.  (If however you were working
> on one of the Python runtimes or implementations, then you might well be
> sometimes considering this type of thing, depending on exactly how
> performance critical what you are working might be and what the runtime was
> being implemented in.)
>

It's not just about performance.  Some hardware simply cannot access
data that is not correctly aligned.  C programs that indiscriminately
cast among pointers to types of different sizes are a pain to port off
lenient architectures like x86.  If you're writing C code that deals
with pointers, you *always* need to keep alignment in mind.

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