[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Printing to a format string

Jesse Brown

5/20/2006 7:17:00 PM

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.

3 Answers

F. Senault

5/20/2006 8:26:00 PM

0

Le 20 mai 2006 à 21:17, jesse.r.brown@gmail.com 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)

Jesse Brown

5/21/2006 4:32:00 AM

0

Yes, thank you.
How foolish I feel now after having seen the solution...

Mike Painter

10/9/2008 3:13:00 AM

0

CB wrote:
> On Wed, 8 Oct 2008 18:55:43 -0700, "Mike Painter"
> <mddotpainter@sbcglobal.net> wrote:
>
>> CB wrote:
>>> On Tue, 7 Oct 2008 19:00:16 -0700, "Mike Painter"
>>> <mddotpainter@sbcglobal.net> wrote:
>>>
>>>> CB wrote:
>>>>> On Mon, 6 Oct 2008 19:55:34 -0700, "Mike Painter"
>>>>> <mddotpainter@sbcglobal.net> wrote:
>>>>>
>>>>>
>>>>>
>>>>> Please do some study on what Paul said about the law.
>>>>> Then get back to me.
>>>>
>>>> You continue to make arbitrary choices based on what you want.
>>>> Clearly your bible is contradictory at any level.
>>>> You claim Paul is the authority
>>>>
>>>> Some claim the words of Jesus are the authority
>>>>
>>>> Matthew 5:18-19
>>>> Till heaven and earth pass, one jot or tittle shall nowise pass
>>>> from the law, till all be fulfilled. Whosoever therefore shall
>>>> break one of these least commandments, and shall teach men so, he
>>>> shall be called the least in the kingdom of heaven.
>>>>
>>>> Luke 16:17
>>>> It is easier for heaven and earth to pass, than one tittle of the
>>>> law to fail.
>>>
>>> Jesus said that while still under the law.
>>> Nice try.
>>
>> Not accorsing to Luke.
>
> Yes, according to Luke.
>
>> But even if this was true either what he said was true or it was not.
>> If it was not true then he lied.
>
> No, you are just ignorant & uninformed.

So give a third option. It was partially true?
It is just part of a myth so the truth or fiction is just part of teh story?
Because?
Because you said so?

>>
>>
>>>>
>>>> And I'm sure that some will claim Luke as the authority
>>>> Luke 16:16
>>>> The law and the prophets were until John [the Baptist]: since that
>>>> time the kingdom of heaven is preached.
>>>
>>> And it was preached. The Kingdom of God was not established until
>>> the day of Pentecost.
>>>
>>> Like I said, get back to me when you get an education.
>>> Try 2nd grade.
>>
>>
>> It's "As I said" and Luke contradicts what you claim. Only one can
>> be right and all can be wrong.
>>
>> You are just another salad bar christian who claims to use the whole
>> bible but picks and chooses what you want.