473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

concatenating strings

EHC
hello!

since i am a py noob, please bear with me ; )

how is it possible to concat a string and an integer in a
print-command? i've tried

print "This robot is named %s. The current speed setting is %d, and %s
has a lifetime of %d" % (self.name , self.speed , self.name)

as well as

print "This robot is named %s. The current speed setting is %d, and %s
has a lifetime of %d" & self.name % self.speed % self.name

though nothing works out...

background is a class named Robot with members speed, name, etc...

tia,
Erich

Dec 15 '06 #1
3 1068
EHC a écrit :
hello!

since i am a py noob, please bear with me ; )

how is it possible to concat a string and an integer in a
print-command? i've tried

print "This robot is named %s. The current speed setting is %d, and %s
has a lifetime of %d" % (self.name , self.speed , self.name)
Four % formating with only three arguments to format. It cannot work...

print "This robot is named %s. The current speed setting is %d, and %s
has a lifetime of %d" % (self.name , self.speed , self.name, self.lifetime)

....
background is a class named Robot with members speed, name, etc...
May try this too:
print "This robot is named %(name)s. The current speed setting is
%(speed)d, and %(name)s has a lifetime of %(lifetime)d" % self.__dict__

[note: liftefime may be a dynamically calculated value, and should be
providen via an accessor attribute]
Dec 15 '06 #2
thank you, i just plainly overlooked it ; )

now it works

Dec 15 '06 #3
Hi Erich

If you're going to be doing a lot of string substitution, you should
look at the Templating support in the library:

http://aspn.activestate.com/ASPN/Coo.../Recipe/304005

and (a little bit fancier):

http://aspn.activestate.com/ASPN/Coo.../Recipe/335308

Regards
Caleb
On Dec 15, 12:18 pm, "Erich Pul" <erich....@blackbox.netwrote:
thank you, i just plainly overlooked it ; )

now it works
Dec 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dont bother | last post by:
Hey, I have these attributes: index which is a numerical value value vector which is a numerical float value and I want to concatenate like this:
4
by: Juan | last post by:
Does any one know if there are reported bugs when concatenating strings? When debugging each variable has the correct value but when I try to concatenate them some values are missing (I can´t see...
1
by: ebobnar | last post by:
I need to call the function LoadImage which take a LPCTSTR argument to specify the path to the image to load. However, I need to create this path dynamically from user input by concatenating...
4
by: FB's .NET Dev PC | last post by:
Interesting note, the code below as is will attempt to cast what is clearly indicated as a string into a double. This is becuase the use of + as a concatenation operator. The error message...
6
by: Hennie7863 | last post by:
Hi, I have table which has the following values : ID SEQ Text 1 1 A 2 1 B 3 2 C 4 2 D 5 2 E
4
by: lindiwemaduna | last post by:
I want to concatenate values of two text boxes into one string but these should be separated by a space in the database table. i have tried all the following but twas not successful: Dim fullName...
21
by: c | last post by:
Hi everybody. I'm working on converting a program wriiten on perl to C, and facing a problem with concatenate strings. Now here is a small program that descripe the problem, if you help me to...
10
by: Neil | last post by:
Using the MS Rich Textbox Control 6.0 in Access 2000, I need to concatenate several RTB controls into a single RTF file. Sometimes two strings will be side-by-side; other times they need to be...
3
by: Big Brother | last post by:
I've been thinking about the seemingly simple task of writing a va_arg-type function to concatenate arbitarily many strings. My first thoughts violated the following principles: 1) never...
4
by: clinisbut | last post by:
I'm not sure if this is the right group, but I didn't found any other more appropiate to post my problem. I'm trying to concatenate chars using the Glib library and I'm getting strange...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.