在性能方面,什么会更好.使用PHP来回显所有的HTML输出,这样我就可以使用各种工作代码和变量,或者在整个文档中定期将HTML转义为php.
我知道可能存在一些可读性问题,但我并不担心.
谢谢大家!
例1
echo '<html>',
'<body>',
'The content of the ',$container,' element is displayed in your ', $other_container,
'</body>',
'</html>';
Run Code Online (Sandbox Code Playgroud)
要么
<html>
<body>
The content of the <?php echo $container; ?> element is displayed in your <?php echo $other_container; ?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 当我点击提交图像时,我在GET请求中获得了一些额外的参数:
main.php?selected=user_manager_main&mode=set_active&set_this_id=13&x=4&y=7
Run Code Online (Sandbox Code Playgroud)
请注意,x并y在最后.我当然没有定义x和y最后.这些值似乎是随机的.这是表单代码:
echo '<form action ="main.php" method="get">';
echo ' <input type="hidden" name="selected" value="user_manager_main" />';
echo ' <input type="hidden" name="mode" value="set_inactive" />';
echo ' <input type="hidden" name="set_this_id" value="'.$row['USER_ID'].'" />';
echo '<input type="image" src="images/delete.gif" alt="Submit" />';
echo '</form>';
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢!
大家好!我遇到了时区问题.
我的时间戳是2010-07-26 23:35:03
我真正想做的是从那时起减去15分钟.
我的方法是简单转换为unix时间,减去秒数并转换回来.简单吧?
我的问题是python使用我的本地时区调整返回的unix时间,目前东部夏令时,我认为是GMT -4.
所以当我这样做时:
# packet[20] holds the time stamp
unix_time_value = (mktime(packet[20].timetuple()))
Run Code Online (Sandbox Code Playgroud)
我得到1280201703,这是星期二,2010年7月27日03:35:03.我可以做这个:
unix_time_value = (mktime(packet[20].timetuple())) - (4 * 3600)
Run Code Online (Sandbox Code Playgroud)
但现在我必须检查东部标准时间-5 GMT并将(4*3600)调整为(5*3600).有没有办法告诉python不使用我的本地时区只是转换时间戳或者有一个简单的方法来获取数据包[20]并减去15分钟?
作为我之前的一个后续问题,我需要将参数传递给视图.在JS执行之前,不知道该参数.
在我的URLConf中:
url(r'^person/device/program/oneday/(?P<meter_id>\d+)/(?P<day_of_the_week>\w+)/$',
therm_control.Get_One_Day_Of_Current_Thermostat_Schedule.as_view(),
name="one-day-url"),
Run Code Online (Sandbox Code Playgroud)
我可以传递这个URL,它很棒!(谢谢你们).
http://127.0.0.1:8000/personview/person/device/program/oneday/149778/Monday/
Run Code Online (Sandbox Code Playgroud)
在我的模板中,我有这个:
var one_day_url = "{% url personview:one-day-url meter_id=meter_id day_of_the_week='Monday' %}";
Run Code Online (Sandbox Code Playgroud)
在我的javascript中:
$.ajax({
type: 'GET',
url: one_day_url ,
dataType: "json",
timeout: 30000,
beforeSend: beforeSendCallback,
success: successCallback,
error: errorCallback,
complete: completeCallback
});
Run Code Online (Sandbox Code Playgroud)
当这触发它工作正常,除了我不一定想要周一.
如果我将javascript更改为:
var one_day_url = "{% url personview:one-day-url meter_id=meter_id %}";
and then
$.ajax({
type: 'GET',
url: one_day_url + '/Monday/',
dataType: "json",
timeout: 30000,
beforeSend: beforeSendCallback,
success: successCallback,
error: errorCallback,
complete: completeCallback
});
Run Code Online (Sandbox Code Playgroud)
我在渲染错误时得到了Caught NoReverseMatch.我假设因为URLconf仍然想要重写以包含?P\w +).
我好像如果我改变了破坏abailty的URL conf来查找视图,如果我做我上面做的事情,它会给我NoREverseMatch错误.
任何指导将不胜感激.
我一直在寻找答案,只发现了我的问题.我通过这个过程对代码进行了评论,说明哪些内容有用,哪些内容不存在以及每行都有什么错误.提前致谢.
#
# list_of_numbers is a list with numbers
# like '3.543345354'
#
# I want to change to a number with two places
#
#
# for each item in the list
for idx, value in enumerate(list_of_numbers):
# make sure it is not none
if value != None:
#
# convert to a float - this works
temp_val = float(value)
# test and print the format - yep this works
print("%.2f" % temp_val)
# store in a new variable …Run Code Online (Sandbox Code Playgroud) 如果我执行以下操作:
IF @THING = TRUE BEGIN
DECLARE @BIGTHING AS BIGINT
END
Run Code Online (Sandbox Code Playgroud)
SQL Server会为此分配资源@BIGTHING吗?
或者更好的问题:SQL Server是否解析存储过程并在执行之前分配所有声明的变量?
我有一份每晚都有的工作.我在我的存储过程中进行自己的日志记录,以便在出现故障时告诉我发生了什么.
昨晚工作失败,我知道在哪里.当我手动运行作业时,它成功了.所以我去了工作经历,看看我能找到什么.
我选择了"显示步骤详细信息"并可以看到消息.到目前为止这么好,但这是我的问题.
显示消息/错误的框中填充了大量信息,但是其中显示"步骤失败"的最后一部分被其他没有错误信息的消息截断.那些其他消息是正常的.我使用BCP很多次并期待它们.
我的问题是:有没有办法在存储过程中清除它?我所要做的就是在失败的stpred程序部分之前清除它,以便我有一个清晰的框
要么
有没有办法看到更多的细节?我查询了sysjobhistory,但它基本上是相同的信息.截断/切断并没有多大用处.
要么
有没有办法关闭在作业期间记录的消息,以便只有错误存在.
谢谢 !!谢谢!
我的示例字典是这样的
data_dictionary = {1:'blue',2:'green',3:'red',4:'orange',5:'purple',6:'mauve'}
Run Code Online (Sandbox Code Playgroud)
data_dictionary可以有更多元素,具体取决于传入的数据.第一个值是我们称之为payload_index的值.我总是得到payload_index 1到4.
我需要从中汇编一个列表.满容易:
for payload_index in data_dictionary :
assembled_packet.append(data_dictionary[payload_index])
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要总是跳过第3个元素.我想我可以做一个if但这样效率很低:
for payload_index in data_dictionary :
if payload_index <> 3:
assembled_packet.append(data_dictionary[payload_index])
Run Code Online (Sandbox Code Playgroud)
我可以分两步完成前三个元素,但问题是我无法弄清楚如何获得其余的因为第三个元素之后的元素数量变化.我尝试使用一个不可能的高指数(下图)但显然失败了:
#get element 1 and two
for index in range(0,3):
assembled_packet.append(data_dictionary[index])
#get element 1 and two
for index in range(4,999):
assembled_packet.append(data_dictionary[index])
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢!
以下代码不起作用,但我正在使用的是我要完成的示例:
SELECT thing_id
FROM table_of_things
WHERE table_of_things.thing_color, table_of_things.thing_flavor IN
( SELECT good_color,good_flavor FROM good_things )
Run Code Online (Sandbox Code Playgroud)
编辑:从我的代码到某些人显然很明显.我试图使用子查询中的两个条件从table_of_things中获取things_id.
我正在听安全现在,我可以发誓史蒂夫吉布森提到你可以在超链接本身内定义一个页面的结构.我给你举个例子,显然是非功能性的:
<a href="<h1>THIS IS THE PAGE</h1>" target="_blank">This link makes a page</a>
Run Code Online (Sandbox Code Playgroud)
如果有人有这样做的例子我会很感激发布它.谢谢!
大家好.尝试使用Python中的列表提高效率,但我似乎无法弄清楚我是否可以做我想做的事情,或者即使值得搞清楚.
stream是一个列表.列表中的每个项目都类似于:
10,123400FFFE001DB9AA
我试图在逗号之后到达每个项目的第二部分,所以我通过列表分割每个项目并将其存储在temp中.我将temp [1]追加到名为incoming_data的另一个列表中.
我想将拆分和保存的行组合到temp并将incoming_data列表追加到一行,如:
incoming_data.append(item.split( ''))
我知道上面的语法是完全错误的,但我希望它能解决问题.这是我目前的代码.
其他批评也像往常一样欢迎.谢谢!
#init the final list
incoming_data = list()
#iterate over each item in the list
for item in stream:
#clear the temp variable for next time
temp = ''
#we sometimes get blank items in the stream list so check first
if item <> '':
#split each item in the stream list using the comma as delimiter
temp = item.split(',')
#append to the final data lis
incoming_data.append(temp[1])
Run Code Online (Sandbox Code Playgroud) 关于include/requre_once的快速问题.我有一些常见于几页的代码,我认为最好是在每个页面调用文件而不是代码重复.
我在while循环中调用include_once,我注意到我必须使用include('file.php'),否则它只会加载它(并显示它)一次.我想我(假设)假设它将在第一个循环上加载它并将代码保留在缓存中以避免在循环的每次迭代中访问磁盘.
我四处寻找"load_once_and_cache"类型的命令,但没有找到任何东西.
有没有人对此有任何建议,或者是将每页中的代码作为唯一选项.
再次感谢!
在我看来,函数可以引用其范围之外的变量,但不能设置它们.它是否正确?我明白了吗?
我还包括全局变量用法.我知道他们是糟糕的ju-ju并会避开它们; 我知道如何解决这个问题,但只是想明确一点.
我的示例程序:
import foo
# beginning of functions
# this one works because I look at the variable but dont modify it
def do_something_working:
if flag_to_do_something:
print "I did it"
# this one does not work because I modify the var
def do_something_not_working:
if flag_to_do_something:
print "I did it"
flag_to_do_something = 0
# this one works, but if I do this God kills a kitten
def do_something_using_globals_working_bad_ju_ju:
global flag_to_do_something
if flag_to_do_something:
print "I did it"
flag_to_do_something = 0 …Run Code Online (Sandbox Code Playgroud) python ×5
html ×3
sql-server ×3
php ×2
t-sql ×2
django ×1
forms ×1
html5 ×1
javascript ×1
performance ×1