1
저는 Python을 배우면서 현재 입력 한 값을 입력 모듈에서 args로 전달하려고합니다.하지만 시작하는 방법을 모릅니다.argthon에 값을 전달하는 Python 모듈
누군가가 조언을 해줄 수 있습니까?
이
이 전화 및 상기 모듈#!/usr/bin/python
import Employee
def Collection1():
while True:
Employee.Age = int(raw_input("How old are you? "))
if Employee.Age == str(Employee.Age):
print "You entered " + Employee.Age + " Please enter a number"
elif Employee.Age > 10:
break
elif Employee.Age > 100:
print "Please enter a sensible age"
else:
print "Please enter an age greater than 10"
return str(Employee.Age)
def Collection2():
Employee.Name = raw_input("What is your name? ")
return Employee.Name
def Collection3():
while True:
Employee.Sex = str(raw_input("Are you a man or a woman? "))
if Employee.Sex == "man":
Employee.Sex = "man"
return Employee.Sex
break
elif Employee.Sex == "woman":
Employee.Sex = "woman"
return Employee.Sex
break
else:
print "Please enter man or woman "
Attributes = Employee.Employee()
Collection1()
Collection2()
Collection3()
Attributes.displayEmployee()
임 추측 I의 인수로 값을 전달하여 상기 코드 IM이다
#!/usr/bin/python
class Employee:
'Practice class'
empCount = 0
def __init__(self, salary):
self.salary = salary
Employee.empCount += 1
def displayCount(self):
print "Total Employees %d" % Employee.empCount
def displayEmployee(self):
print "Salary: ", self.salary
class Att(Employee):
'Defines attributes for Employees'
def __init__(self, Age, Name, Sex):
self.Age = Age
self.Name = Name
self.Sex = Sex
def display(self):
print "Name: ", self.Name + "\nAge: ", self.Age, "\nSex: ", self.Sex
전화 모듈을 임 사용자로부터 입력을 받아 클래스의 변수에 넣어야합니다. 나는 그것을 시도했다. 그러나 im는 모든 것을 나쁘게하고있는 것을 당연하다고 생각 하느냐? 모듈의 변수를 설정하는 대신 로컬 변수를 사용하여, 당신은 외부 Collection1() 함수를 를 설정해야 어떤 설정에 아무 소용이 없다
대문자로 표시된 멤버/모듈/변수/함수 이름은 unpythonic입니다. 코드에서 대문자로 된 유일한 단어는'Employee'와'Att' 여야합니다. – Eric
그리고'Employee.Age == str (Employee.Age)'는 항상 거짓입니다 - 정수는 문자열 표현과 결코 같지 않습니다. – Eric