Printing mixtures in integers and strings 
Author Message
 Printing mixtures in integers and strings

Hello,

            I'm trying to use something like this:-

def move(row): #Moves the dispenser to the row on the plate
    print "Moved to Row - " + row

    Where row is expected to be a number.  However when I import this into
teh interpreter I get an error message - stating that __add__ and __radd__
have not been defined:-

Traceback (innermost last):
  File "<console>", line 1, in ?
  File "c:\projects\scripting\TrialScripting\AcmeBRD.py", li
TypeError: __add__ nor __radd__ defined for these operands

    However when I enter text e.g. "BOB" into the function it works fine!
Therefore I assume that I need to explicity convert the into to a string,
does anybody know how to do that - I can;t find the command in teh docs!!!

    Thanks, in advance, for your help.

Cheers,

Neil Benn
Automation Informatics Scientist
Cambridge Antibody Technology



Mon, 15 Sep 2003 03:26:58 GMT  
 Printing mixtures in integers and strings
Use ',' instead of '+'
--or--
print "Moved to Row - %d" % row

--

Emile van Sebille

---------

Quote:
> Hello,

>             I'm trying to use something like this:-

> def move(row): #Moves the dispenser to the row on the plate
>     print "Moved to Row - " + row

>     Where row is expected to be a number.  However when I import this into
> teh interpreter I get an error message - stating that __add__ and __radd__
> have not been defined:-

> Traceback (innermost last):
>   File "<console>", line 1, in ?
>   File "c:\projects\scripting\TrialScripting\AcmeBRD.py", li
> TypeError: __add__ nor __radd__ defined for these operands

>     However when I enter text e.g. "BOB" into the function it works fine!
> Therefore I assume that I need to explicity convert the into to a string,
> does anybody know how to do that - I can;t find the command in teh docs!!!

>     Thanks, in advance, for your help.

> Cheers,

> Neil Benn
> Automation Informatics Scientist
> Cambridge Antibody Technology



Tue, 16 Sep 2003 04:06:24 GMT  
 Printing mixtures in integers and strings

Quote:

> Hello,

>             I'm trying to use something like this:-

> def move(row): #Moves the dispenser to the row on the plate
>     print "Moved to Row - " + row

Try defining your function as:

def move( row ) :
   print "Moved to Row -", row

Use the comma instead of the + sign.  This should solve your problem.

--

 -------------------
 | Douglas Gorley  |

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



Tue, 16 Sep 2003 04:05:34 GMT  
 Printing mixtures in integers and strings

Quote:
>             I'm trying to use something like this:-

> def move(row): #Moves the dispenser to the row on the plate
>     print "Moved to Row - " + row

Convert the int to a string:
print "Moved to Row - " + str (row)
or
print "Moved to Row - " + `row`

Daniel

--
Daniel Dittmar

SAP DB, SAP Labs Berlin
http://www.sapdb.org/



Tue, 16 Sep 2003 16:28:40 GMT  
 Printing mixtures in integers and strings
Hi Neil,

Quote:

> Hello,

>             I'm trying to use something like this:-

> def move(row): #Moves the dispenser to the row on the plate
>     print "Moved to Row - " + row

You are trying to add (operator "+") a number and a string

Quote:

>     Where row is expected to be a number.  However when I import this into
> teh interpreter I get an error message - stating that __add__ and __radd__
> have not been defined:-

> Traceback (innermost last):
>   File "<console>", line 1, in ?
>   File "c:\projects\scripting\TrialScripting\AcmeBRD.py", li
> TypeError: __add__ nor __radd__ defined for these operands

Which is the expected result since built-in strings and ints
do not add together
You can modify __add__ or __radd__ methods in these object
so they know how to add a number a string or the opposite.

It's easier to convert number to string : print "Moved to
Row - " + str(row),
or let's 'print' to do this conversion : print "Moved to Row
- ", row
(prints string "Moved to Row - " and then prints printable
form of var "row" which happens to be str(row))

Enrique



Tue, 16 Sep 2003 22:48:12 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. convert integer string to date string

2. Grab with mixture

3. printing and getting integers in assmbler

4. Printing integer value

5. Reading and Printing integers with zeros

6. Help required translating strings to integer arrays

7. Converting a number in a String character to an Integer

8. Integer to Binary String

9. String to Integer

10. Code Snippet: Integer to String Converter

11. Convert 2D-Integer-Array to String

12. How do I convert integer to string array?

 

 
Powered by phpBB® Forum Software