![]() |
How to assign this output to a string variable? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to assign this output to a string variable? (/thread-17585.html) |
How to assign this output to a string variable? - Pedroski55 - Apr-17-2019 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 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?? RE: How to assign this output to a string variable? - Yoriz - Apr-17-2019 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 ?
RE: How to assign this output to a string variable? - Pedroski55 - Apr-18-2019 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! RE: How to assign this output to a string variable? - Yoriz - Apr-18-2019 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.
|