Който го мързи да ги пише на ръка, си пише скрипт.
Example: python phpgetset.py par1 par2 par3
import sys print sys.argv def gSet(itm): print "function set"+itm[0].capitalize() + itm[1:]+"($"+itm+")" print "{" print "\t$this->"+itm+" = $"+itm+";" print "}" def gGet(itm): print "function get"+itm[0].capitalize() + itm[1:]+"()" print "{" print "\treturn $this->"+itm+";" print "}" for item in sys.argv[1:]: gSet(item) gGet(item)
След коментар от Ивайло, че това горното не е питон, пускам и неговата версия:
import sys def GetSet(itm, get_set = True): return "\n".join([ "function %set%s(%s)" % ("g" if get_set else "s", itm.capitalize(), "" if get_set else "$newval"), "{", ("\treturn $this->%s;" if get_set else "\t$this->%s = $newval;") % itm.lower(), "}", "",]) + (GetSet(itm, False) if get_set else "") #sys.argv.append("Property") print sys.argv for item in sys.argv[1:]: print GetSet(item)
Това не е Python. 🙂
import sys
def GetSet(get_set, itm):
return “\n”.join([
“function %set%s(%s)” % (“g” if get_set else “s”, itm.capitalize(), “” if get_set else “$newval”),
“{“,
(“\treturn $this->%s;” if get_set else “\t$this->%s = $newval;”) % itm.lower(),
“}”,])
print sys.argv
for item in sys.argv[1:]:
print GetSet(True, item)
print GetSet(False, item)
Всъщност това вече е Python. 🙂
[code]import sys
def GetSet(itm, get_set = True):
return “\n”.join([
“function %set%s(%s)” % (“g” if get_set else “s”, itm.capitalize(), “” if get_set else “$newval”),
“{“,
(“\treturn $this->%s;” if get_set else “\t$this->%s = $newval;”) % itm.lower(),
“}”, “”,]) + (GetSet(itm, False) if get_set else “”)
#sys.argv.append(“Property”)
print sys.argv
for item in sys.argv[1:]:
print GetSet(item)
[/code]