Python Forum
[Help] Using "Class" with User Input in an online sign up form
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Help] Using "Class" with User Input in an online sign up form
#3
(Aug-23-2018, 03:04 PM)ichabod801 Wrote: I would not name the class method input, rather from_input or something similar. Since it's a method, it won't override the input built-in, but it just makes me cringe. I think it's a good habit never to name things after built-ins, so that you never do it when it could cause a problem.

I would also assign the inputs to some local variables, and then create the class with the local variables. Yeah, you can get user input as a parameter, but it strikes me as a bad idea for some reason. Also, you will want it set up my way if you ever do any validation on the user input.

Hi ichabod801, sorry for the late response. Please see my updated code below and let me know if I need to improve it? Thank you

class Studentform:

    def __init__(self, fname, lname, email, ccode, mobile, github, country, identity, want, codelevel, subs, like):
        self.fname      = fname
        self.lname      = lname
        self.email      = email
        self.ccode      = ccode
        self.mobile     = mobile
        self.github     = github
        self.country    = country
        self.identity   = identity
        self.want       = want
        self.codelevel  = codelevel
        self.subs       = subs
        self.like       = like

    @classmethod
    def raw_input(cls):
        return cls(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12)

var1 = input("First Name: \n")
var2 = input("Last Name: \n")
var3 = input("Email: \n")
var4 = int(input("Country code: \n"))
var5 = int(input("Phone number: \n"))
var6 = input("Github profile: \n")
var7 = input("Country: \n")
var8 = input("Identity (Woman/Non Binary/Man): \n")
var9 = input("I want to (Find my next job/Become a freelancer/Start my own tech startup): \n")
var10 = input("My coding level is (Beginner/Intermediate/Advanced): \n")
var11 = input("I want to subscribe to and join the following groups (Student/Working/Job seeking/Entrepreneur/Mom/Single Mom/Non-Binary/Trans/Retired/Career changer): \n")
var12 = input("I would also like to (Volunteer/Mentor/Hire): \n")

user = Studentform.raw_input()
Blockchain Visionary & Aspiring Encipher/Software Developer
me = {'Python Learner' : 'Beginner\'s Level'}
http://bit.ly/JoinMeOnYouTube
Reply


Messages In This Thread
RE: [Help] Using "Class" with User Input in an online sign up form - by vanicci - Aug-26-2018, 08:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to revert back to a previous line from user input Sharkenn64u 2 1,215 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  User input with while loops chizzy101010 2 6,904 Aug-25-2024, 06:00 PM
Last Post: chizzy101010
  Does @ at sign used for tother than decorators? ggpython000 1 1,187 Oct-12-2023, 09:08 AM
Last Post: buran
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 2,707 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  pyscript index error while calling input from html form pyscript_dude 2 2,100 May-21-2023, 08:17 AM
Last Post: snippsat
  restrict user input to numerical values MCL169 2 2,003 Apr-08-2023, 05:40 PM
Last Post: MCL169
  class Update input (Gpio pin raspberry pi) caslor 2 1,869 Jan-30-2023, 08:05 PM
Last Post: caslor
  user input values into list of lists tauros73 3 2,086 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 2,491 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 2,466 Dec-11-2022, 07:39 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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