return multiple values by using class to take inputs from users

return multiple values by using class to take inputs from users



I would like to make a class for taking inputs from the user and then return all these inputs for later process. An example, after taking inputs from the users (filenames) then the program stores the names in list. The program later will load the list and perform the process based on each filename for one process.



More explanations:



My code:


class ReturnAllInput():
def __init__(self,Morefilenames, Yourfilename, YourJsonName, Outputname, NameWithin):
self.Morefilenames = Morefilenames
self.Yourfilename = Yourfilename
self.YourJsonName = YourJsonName
self.Outputname = Outputname
self.NameWithin = NameWithin

def allInput():

Morefilenames =
while True:
a = input("Please enter your Morefilenames " )
if a == "Complete":
break
else:
Morefilenames .append(a)
# user typed complete
print("You entered Morefilenames ".format(len(Morefilenames )))
for n in Morefilenames :
print('.txt'.format(n))

Yourfilename= input("Yourfilename")
YourJsonName= input("YourJsonName")
Outputname= input("Outputname")
NameWithin= input("NameWithin")

return ReturnAllInput(Morefilenames , Yourfilename, YourJsonName, Outputname, NameWithin)


for l in allinput(): #this is the section I do not know how to change it so that I could loop my return values of Morefilenames)
if __name__ == "__main__":



If my codes arent good enough, please do let me know so that I could improve more. I am still a beginner and would like to learn more. Thank you in advance.





this probably belongs on the software engineering channel
– aydow
Sep 3 at 6:27





Maybe post here if just want to improve the code? codereview.stackexchange.com
– lagom
Sep 3 at 6:29






This code doesn't work, and would not be suitable for either of those sites.
– AChampion
Sep 3 at 6:31





I see. Alright. I will close this since its not deliverable. thank you and sorry
– JJson
Sep 3 at 6:36




1 Answer
1



if __name__ == '__main__': is just used when this python file is being used as a script to control the execution, see What does if __name__ == "__main__": do? and would normally be the outer control logic, e.g.:


if __name__ == '__main__':


if __name__ == '__main__':
for l in allinput():



allinput() returns the class, which isn't directly iterable. If you want to iterate over Morefilenames then reference that attribute, e.g.:


allinput()


Morefilenames


if __name__ == '__main__':
for l in allinput().Morefilenames:
print(l)



But you lose reference to you constructed class so it is probably better to separate these calls:


if __name__ == '__main__':
user_inputs = allinput()
for l in user_inputs.Morefilenames:
print(l)





Thank you so much for pointing out the mistakes I have. I will proceed to close this since it's not feasible. Sorry for posting the wrong one.
– JJson
Sep 3 at 6:36



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế