Python Forum
How to assign this output to a string variable?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to assign this output to a string variable?
#1
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??
Reply
#2
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 ?
Reply
#3
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!
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Replacing String Variable with a new String Name kevv11 2 729 Jul-29-2023, 12:03 PM
Last Post: snippsat
  Need help on how to include single quotes on data of variable string hani_hms 5 1,883 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python r string for variable mg24 3 2,634 Oct-28-2022, 04:19 AM
Last Post: deanhystad
  USE string data as a variable NAME rokorps 1 920 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  Removing Space between variable and string in Python coder_sw99 6 6,123 Aug-23-2022, 01:15 PM
Last Post: louries
  How to combine two output in one variable? ilknurg 2 1,143 Aug-01-2022, 09:31 AM
Last Post: Gribouillis
  Remove a space between a string and variable in print sie 5 1,706 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Split string using variable found in a list japo85 2 1,235 Jul-11-2022, 08:52 AM
Last Post: japo85
  Can you print a string variable to printer hammer 2 1,890 Apr-30-2022, 11:48 PM
Last Post: hammer
Question How to convert string to variable? chatguy 5 2,228 Apr-12-2022, 08:31 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020