Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Printing to a format string

Reply
Thread Tools

Printing to a format string

 
 
jesse.r.brown@gmail.com
Guest
Posts: n/a
 
      05-20-2006
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.

 
Reply With Quote
 
 
 
 
F. Senault
Guest
Posts: n/a
 
      05-20-2006
Le 20 mai 2006 à 21:17, http://www.velocityreviews.com/forums/(E-Mail 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
--
Feel my blood enraged It's just the fear of losing you
Don't you know my name Well, you been so long
(David Bowie, Cat People - Putting Out Fire)
 
Reply With Quote
 
 
 
 
jesse.r.brown@gmail.com
Guest
Posts: n/a
 
      05-21-2006
Yes, thank you.
How foolish I feel now after having seen the solution...

 
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: raw format string in string format method? Chris Angelico Python 3 03-01-2013 12:00 AM
Re: raw format string in string format method? Rick Johnson Python 0 02-28-2013 11:06 PM
Re: raw format string in string format method? Peter Otten Python 0 02-28-2013 03:41 PM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:28 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-18-2007 10:11 AM



Advertisments