我偶尔会注意到Python脚本中的以下内容:
if __name__ == "__main__":
# do stuff like call main()
Run Code Online (Sandbox Code Playgroud)
这有什么意义?
我需要将页面提交到两个页面,具体取决于触发提交的按钮.两个页面都需要能够获取正在发送的$ _POST数据.这是我到目前为止所做的,但它不起作用.
<form name="user" action="" method="POST">
<textarea name="tname" id="tname"></textarea>
<input type='button' value='Submit'
onclick="document.user.action='edit.php'; document.user.submit(); this.form.target='_self'; return true;">
<input type='button' value='Preview'
onclick="document.user.action='preview.php'; document.user.submit(); this.form.target='_blank'; return true;">
</form>
Run Code Online (Sandbox Code Playgroud)
两个页面都在同一个窗口中打开(预览按钮应该在新窗口中打开).
我有一个函数,其目的是列出我的wordpress主题的images目录中的文件夹.当用户在站点的根目录中安装了wordpress时,它非常有用.但是,如果用户在根目录下的文件夹中安装了wordpress,则会失败...
$ mydir = get_dirs($ _ SERVER ['DOCUMENT_ROOT'].'/ wp-content/themes/mytheme/images');
只要将wordpress直接安装到站点的根目录(例如site.com/index.php),此功能就可以正常工作
但是,如果用户已将其博客安装在虚拟目录中,则此路径方法将失败.示例:site.com/somedirectory/index.php
有人可以用更好的方法来确定$ mydir的路径吗?
如果我可以用http地址提供我的函数,那将是非常简单的,但我的函数需要将images目录的路径作为服务器目录.有人知道使用http方法在给定目录下查找文件夹的方法吗?例如,我可以使用...获取对主题图像目录的引用
$ mydir = get_bloginfo('url').'/ wp-content/themes/mytheme/images';
但是,下面的函数不会占用URL,它必须是我要解析的所选目录的物理文件路径.所以我需要用一个带有URL的函数替换它,或者我需要找到一些方法将$ mydir函数转换为物理路径,或者其他一些方法.
这是我用于解析目录并将每个文件夹分配给数组的函数.
function get_dirs($path = '.')
{
$dirs = array();
try
{
foreach (new DirectoryIterator($path) as $file)
{
if ($file->isDir() && !$file->isDot())
{
$dirs[] = $file->getFilename();
}
}
}
catch(Exception $e)
{
//log exception or process silently
//just for test
echo "There is a problem inside the get_dirs function";
}
return $dirs;
}
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个检测图像边框的程序,例如我有一个正方形,程序检测到X/Y-Coords
例:
我将全对最短路径算法(Floyd-Warshall)应用于此有向图: alt text http://www.freeimagehosting.net/uploads/99b00085bf.jpg
该图由其邻接矩阵表示.简单的代码如下所示:
public class ShortestPath {
public static void main(String[] args) {
int x = Integer.MAX_VALUE;
int [][] adj= {
{0, 6, x, 6, 7},
{x, 0, 5, x, x},
{x, x, 0, 9, 3},
{x, x, 9, 0, 7},
{x, 4, x, x, 0}};
int [][] D = adj;
for (int k=0; k<5; k++){
for (int i=0; i<5; i++){
for (int j=0; j<5; j++){
if(D[i][k] != x && D[k][j] != x && D[i][k]+D[k][j] < …Run Code Online (Sandbox Code Playgroud) 给出以下对象:
public class Customer {
public String Name { get; set; }
public String Address { get; set; }
}
public class Invoice {
public String ID { get; set; }
public DateTime Date { get; set; }
public Customer BillTo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想用反射Invoice来获得一个Name属性Customer.这就是我所追求的,假设这段代码可行:
Invoice inv = GetDesiredInvoice(); // magic method to get an invoice
PropertyInfo info = inv.GetType().GetProperty("BillTo.Address");
Object val = info.GetValue(inv, null);
Run Code Online (Sandbox Code Playgroud)
当然,由于"BillTo.Address"不是Invoice该类的有效属性,因此失败.
所以,我尝试编写一个方法将字符串拆分成句点,并遍历对象寻找我感兴趣的最终值.它可以正常工作,但我对它并不完全满意:
public Object GetPropValue(String …Run Code Online (Sandbox Code Playgroud) 什么时候开始"index.php",我做require_once("/all_fns.php").
"all_fns.php"本身需要具有相对于all_fns.php(本身)的路径的文件.
我的问题是,我应该写all_fns相对于all_fns.php或index.php的路径吗?
这对我来说非常困惑,并希望直截了当.
我想在我的C/C++程序中使用"_test_and_set lock"汇编语言实现和原子交换汇编指令.
class LockImpl
{
public:
static void lockResource(DWORD resourceLock )
{
__asm
{
InUseLoop: mov eax, 0;0=In Use
xchg eax, resourceLock
cmp eax, 0
je InUseLoop
}
}
static void unLockResource(DWORD resourceLock )
{
__asm
{
mov resourceLock , 1
}
}
};
Run Code Online (Sandbox Code Playgroud)
这有效,但这里有一个错误.
问题是我想传递DWORD*resourceLock而不是DWORD resourceLock.
所以问题是如何将指针从C/C++传递到程序集并将其取回.?
提前致谢.
问候,-Jay.
PS这样做是为了避免用户空间和内核空间之间的上下文切换.
通过执行以下命令,我可以获得有关方法的信息
Type t=typeof(someType);
MemberInfo[] mInfo = t.GetMethods();
Run Code Online (Sandbox Code Playgroud)
如何获取有关在类型中声明的委托的信息?