我正在學習python,並且正在嘗試將值從輸入傳遞給模塊的參數,但我不知道如何啓動。Python模塊,將值傳遞給參數
有人可以給我一些建議嗎?
這是模塊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
這是代碼即時通訊使用調用並將值傳遞到ARGS上述模塊
#!/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()
即時猜測我在需要從用戶那裏獲取輸入並將其放置在類的變量中。我試過,但即時通訊猜測我做了一切錯誤?
大寫的成員/模塊/變量/函數名是unpythonic。代碼中唯一的大寫字母應該是'Employee'和'Att' – Eric
而'Employee.Age == str(Employee.Age)'將始終爲假 - 一個整數永遠不會等於它的字符串表示。 – Eric