Printing to a format string

J

jesse.r.brown

I have run across something that I can quite figure out at the moment.
Here is the section of code I am dealing with:

# construct a string that can be
# output in the structure definition
# [depth] is the current tab depth
# [tab] is the tab width
def struct_str(depth,tab)
indent = " " * tab * depth
str = indent + "\"#@name\", \"#@fmt\", #@args,\n"
str += indent + "%15s %10s - #@err_msg \n" % [@name, @fmt]

I get an error when trying to assign @fmt to the %10s.
I _think_ the problem is that I have, in the @fmt variable, a c-style
printf format string. The error I get is:

../commands.rb:39:in `%': too few arguments (ArgumentError)

Am I doing something incorrectly? Or is there an easy way around this?

Note:
The @fmt come from a user-provided file, so careless translations will
lead to undefined effects. I want to try and fix this localy if
possible.

Thanks in advance for any help.
 
F

F. Senault

Le 20 mai 2006 à 21:17, (e-mail address removed) a écrit :
str += indent + "%15s %10s - #@err_msg \n" % [@name, @fmt]

I get an error when trying to assign @fmt to the %10s.
I _think_ the problem is that I have, in the @fmt variable, a c-style
printf format string. The error I get is:

Are you sure it isn't your @err_msg that contains "%" ? I'd write :

str += indent + "%15s %10s - %s \n" % [@name, @fmt, @err_msg]

Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top