Python Forum

Full Version: How to assign this output to a string variable?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to automate making my little homework webpages. I've made lots of little Python programs. For example:

makeRadioButtonsInlineV1.py

it makes sets of Radio buttons in html. It also returns a string of html. Below is the part that makes the html, it calls makeSetRBs():

def makeHTML():
    for j in range(0, int(numSets)):
          html = []
          value = str(j + 1)
          line1 = '<p> <b> ' + value + ': </b> <BR>\n'
          html.append(line1)
          gapNum = int(startNum) + j
          namenumber = radioName + str(gapNum)
          setRBs = makeSetRBs(value, namenumber)
          for k in range(0, len(setRBs)):
              html.append(setRBs[k])
          html.append('</p>\n')
          html.append('\n')
          htmlString = '\n'.join(html)
          file = open(pathToRBs + filename, 'a')
          file.write(htmlString)
          
    file.close()
    print('All done, now copy and paste into the webpage!')
    return htmlString;
I call the python with:

Quote:>>> import makeRBsInlineV1 as fl
How many radio buttons in each set of radio buttons?
4
How many sets of radio buttons do you want?
5
What should be the starting number for the RB names? Just a number ike 24?
1
What week number is this? Enter Week1 or similar.
Week100
All done, now copy and paste into the webpage!
All done should have a string now.
>>>

Trouble is, it starts immediately after 'import makeRBsInlineV1 as fl'. I have no chance to do:

myString = fl

How do I catch the output of fl as a string??
All i see is an uncalled function, how does this relate to the problem, what is fl and where are you assigning it to myString ?
Sorry, I always get in a panic and think I can't do it! I must have an inferiority complex!

This was the first time I tried to import my own files. I am a morning person. This morning at 5am I made it work for all my modules, integrated them in my file makeWebpage.py

Works great! I had to rearrange the original file so that the paths and variables were available to the functions like makeHTML

The trick seems to be, call a function, not a whole file. Then I can do:

myString = makeHTML()

Sorry to bother you!
It's ok, i see now that instead of calling myString = fl it should have been myString = fl.makeHTML() to access the function in the imported file.