Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Error:can't assign to operator

Reply
Thread Tools

Re: Error:can't assign to operator

 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      08-02-2008
On Fri, 1 Aug 2008 03:19:25 -0600, "Prasad, Mrunalini"
<> declaimed the following in
gmane.comp.python.general:

> Hello:
>
> I am getting the above error while tryign to run the tower of hanoi
> program. The error is at line 42 highligted in red below. PLease advise
>

Note 1: color coding does not get past pure text email/news clients.

> #!/usr/bin/env python
>
> class Hanoi:
>
> def __init__(self, N):
> self.N = N
>
> try:
> raise ValueError(N)
> except ValueError, e:
> print "bad! value: %d" % e.value
>

Indentation is incorrect here... The unindented try: has ended the
definition of class Hanoi; as a result, all the indented stuff below is
seen as part of the except: branch...

> def display():
>
> print "A"
> for i in range(N):
> print "%d\n", A[i]
> i += 1

What do you expect that i += 1 to be performing? It's just going to
be replaced by the next value in the range() iteration.

Also, print statements already include a newline so this would be
trying to double space the output...

Moreover, you are printing a literal "%d", a new-line, and the value
of some global variable named A (which doesn't exist!) on the next line.
You'd be better off just using:

for itm in A:
print itm

<snip>

> def move(source, dest):
>
> i = 0;j = 0
> while ((source + i) == 0) and (i < N):


What is source -- better be some sort of numeric data type...

This looks more like a badly translated C program which was using
pointer arithmetic to index through an array given the starting address.

> dest + j - 1 = source + i


Especially here... I suspect the C looked something like

*(dest + j -1) = *(source + i)


I suggest reading the Python tutorial first before trying to port a
program from another language.

--
Wulfraed Dennis Lee Bieber KD6MOG

HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-)
HTTP://www.bestiaria.com/

 
Reply With Quote
 
 
 
 
Emile van Sebille
Guest
Posts: n/a
 
      08-03-2008
Dennis Lee Bieber wrote:

just an fyi....

> self.towers = [ list(reversed(range(self.numDisks))),


or range(self.numDisks-1,-1,-1)

Emile

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Error:can't assign to operator Emile van Sebille Python 1 08-01-2008 11:51 PM
Does std::string do a shallow copy in copy construtor and assign operator ? suman.nandan@gmail.com C++ 2 05-26-2007 07:47 AM
Vector Assign vs Vector operator= Chris Roth C++ 4 02-22-2007 12:57 PM
assign operator as variable ? s99999999s2003@yahoo.com Python 2 06-07-2006 06:33 AM
Suggesting for overloading the assign operator Rim Python 20 07-08-2003 06:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57