我正在Laravel中创建一个返回JSON的Web服务.
我创建了一个Account这样的模型:
class Account extends Eloquent {
// The database table used by the model.
// (If not defined then lowercase and plural of class name is consider as a table name)
protected $table = "account";
// define which column can be mass assign
protected $fillable = array("user_id", "account_group_id", "generated_by", "image", "name",
"address", "zip", "area_id", "mobile", "email", "phone", "fax",
"website", "pan", "cst", "tin", "ecc", "iesc", "transport",
"other", "outstanding", "cform", "status", "mitp");
// To prevent column from mass assignment. …Run Code Online (Sandbox Code Playgroud) 我可以很容易地在记事本++中找到'\n',但我的问题是我必须在没有特定字符(在这种情况下为"#")时找到'\n'.那么我用'\n'来使用正则表达式吗?可能吗?
示例:
Stuff to ignore
#Like that
Stuff
To change
Run Code Online (Sandbox Code Playgroud) 背景:我正在制作一个Ren'py游戏.值为Character().是的,我知道在这种背景之外这是一个愚蠢的想法.
我需要从类的范围之外的类中的输入字符串创建一个变量:
class Test:
def __init__(self):
self.dict = {} # used elsewhere to give the inputs for the function below.
def create_global_var(self, variable, value):
# the equivalent of exec("global {0}; {0} = {1}".format(str(variable), str(value)))
# other functions in the class that require this.
Test().create_global_var("abc", "123") # hence abc = 123
Run Code Online (Sandbox Code Playgroud)
我试过vars()[],globals()[variable] = value等等,他们根本不工作(他们甚至没有定义任何东西)编辑:这是我的问题.
我知道以下内容同样可以正常工作,但我希望变量在正确的范围内:
setattr(self.__class__, variable, value) # d.abc = 123, now. but incorrect scope.
Run Code Online (Sandbox Code Playgroud)
如何在类中使用字符串作为变量名在全局范围内创建变量,而不在python中使用属性或exec?
是的,我会进行健全检查.
怎么做.例如,我们有一个数组:
array(
0 => 'Regular 1 000',
1 => 'Regular 500',
2 => 'Regular 2 000',
3 => 'Big',
4 => 'Regular 1 000 000',
5 => 'Regular 50 000'
)
Run Code Online (Sandbox Code Playgroud)
我需要按顺序放置它们:
array(
3 => 'Big',
1 => 'Regular 500',
0 => 'Regular 1 000',
2 => 'Regular 2 000',
5 => 'Regular 50 000',
4 => 'Regular 1 000 000'
)
Run Code Online (Sandbox Code Playgroud)
我需要维护索引关联.看来我需要使用uasort.任何人都可以向我建议一个用于callable ( $cmp_function )价值的功能 吗?