Raw Input Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hokiegal99

    Raw Input Question

    How can I pass the content of one varible into raw_input? See below for
    what I'm trying to do:

    XXX = raw_input("1. Enter the string that you'd like to find: ")
    y = raw_input("2. Enter the string that you'd like to replace XXX with: ")

    I'm trying to pass x into y. I tried the "Enter the string that you'd
    like to replace", XXX, "with:" approach, but Pyhton told me that I could
    only pass 1 argument, no more.

    Thanks!!!

  • Erik Max Francis

    #2
    Re: Raw Input Question

    hokiegal99 wrote:
    [color=blue]
    > How can I pass the content of one varible into raw_input? See below
    > for
    > what I'm trying to do:
    >
    > XXX = raw_input("1. Enter the string that you'd like to find: ")
    > y = raw_input("2. Enter the string that you'd like to replace XXX
    > with: ")
    >
    > I'm trying to pass x into y. I tried the "Enter the string that you'd
    > like to replace", XXX, "with:" approach, but Pyhton told me that I
    > could
    > only pass 1 argument, no more.[/color]

    raw_input takes a string, and a string like any other. You can build
    the string yourself:

    "Enter the string to replace " + XXX + " with:"

    or

    "Enter the string to replace %s with:" % XXX

    --
    Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \ There never was a good war or a bad peace.
    \__/ Benjamin Franklin

    Comment

    • hokiegal99

      #3
      Re: Raw Input Question

      This one makes more sense to me so I used it, it works great:

      "Enter the string to replace %s with:" % XXX

      Thank you for your help!!!


      Erik Max Francis wrote:[color=blue]
      > hokiegal99 wrote:
      >
      >[color=green]
      >>How can I pass the content of one varible into raw_input? See below
      >>for
      >>what I'm trying to do:
      >>
      >>XXX = raw_input("1. Enter the string that you'd like to find: ")
      >>y = raw_input("2. Enter the string that you'd like to replace XXX
      >>with: ")
      >>
      >>I'm trying to pass x into y. I tried the "Enter the string that you'd
      >>like to replace", XXX, "with:" approach, but Pyhton told me that I
      >>could
      >>only pass 1 argument, no more.[/color]
      >
      >
      > raw_input takes a string, and a string like any other. You can build
      > the string yourself:
      >
      > "Enter the string to replace " + XXX + " with:"
      >
      > or
      >
      > "Enter the string to replace %s with:" % XXX
      >[/color]


      Comment

      • mackstann

        #4
        Re: Raw Input Question

        On Tue, Aug 26, 2003 at 10:33:36PM -0400, hokiegal99 wrote:[color=blue]
        > How can I pass the content of one varible into raw_input? See below for
        > what I'm trying to do:
        >
        > XXX = raw_input("1. Enter the string that you'd like to find: ")
        > y = raw_input("2. Enter the string that you'd like to replace XXX with: ")
        >
        > I'm trying to pass x into y. I tried the "Enter the string that you'd
        > like to replace", XXX, "with:" approach, but Pyhton told me that I could
        > only pass 1 argument, no more.[/color]

        Ah, you are confusing print's behavior for general string concatenation.
        I believe what you want to do is:

        y = raw_input("2. Enter the string that you'd like to replace "+XXX+" with:")

        or

        y = raw_input("2. Enter the string that you'd like to replace %s with:" % XXX)

        --
        m a c k s t a n n mack @ incise.org http://incise.org
        As the poet said, "Only God can make a tree" -- probably because it's
        so hard to figure out how to get the bark on.
        -- Woody Allen

        Comment

        Working...