说我有这个简单的python脚本:
file = open('C:\\some_text.txt')
print file.readlines()
print file.readlines()
Run Code Online (Sandbox Code Playgroud)
运行时,第一个打印件打印包含文件文本的列表,而第二个打印件打印空白列表.我想这并不完全出乎意料.但有没有办法"回卷"文件,以便我可以再次阅读?或者是重新打开它的最快方式?
我想用一个模型来保存django应用程序的系统设置,所以我想限制模型只能有一条记录,如何做限制?
我正在提供带命令的Javascript函数字符串(SVG路径命令):
eg. "move 10 10 line 50 50"
Run Code Online (Sandbox Code Playgroud)
move和line是命令
数字是x,y坐标
我想为这些命令添加特殊字符串,这将指示函数使用特定变量
eg. "move %mouseX%+1 %mouseY%+1"
Run Code Online (Sandbox Code Playgroud)
其中%mouseX%和%mouseY%将是鼠标x,y坐标
我该如何解析和替换这些?
我有一个上下文菜单插件,在右键单击元素时将显示上下文菜单.但这对ajax嵌入式元素不起作用.所以我必须使用ajax live,当它感觉到右键单击时触发上下文菜单功能.
是否有一个jquery检测右键点击的插件?
我想这样做:
public class BaseTable<T extends TableEntry>
{
protected int mRows;
protected int mCols;
protected ArrayList<T> mEntries;
public BaseTable(int rows, int cols)
{
mRows = rows;
mCols = cols;
mEntries = new ArrayList<T>();
for (int i = 0; i < rows; i++)
{
mEntries.add(new T(cols)); //this obv. doesn't work
}
}
}
Run Code Online (Sandbox Code Playgroud)
实例化泛型很难实现,但更难以实现的是,T这里没有默认构造函数,它int在构造函数中需要一个参数.
如何才能做到这一点?
我也在这里问了一个跟进问题.如果你能回答这个问题,我将不胜感激.
这个问题是相关的,但只有在假定类具有默认构造函数时才有意义.
我正在编写一个程序,需要在目录及其所有子目录中搜索具有特定扩展名的文件.这将在本地和网络驱动器上使用,因此性能有点问题.
这是我现在使用的递归方法:
private void GetFileList(string fileSearchPattern, string rootFolderPath, List<FileInfo> files)
{
DirectoryInfo di = new DirectoryInfo(rootFolderPath);
FileInfo[] fiArr = di.GetFiles(fileSearchPattern, SearchOption.TopDirectoryOnly);
files.AddRange(fiArr);
DirectoryInfo[] diArr = di.GetDirectories();
foreach (DirectoryInfo info in diArr)
{
GetFileList(fileSearchPattern, info.FullName, files);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以将SearchOption设置为AllDirectories而不使用递归方法,但将来我会插入一些代码来通知用户当前正在扫描的文件夹.
现在我正在创建一个FileInfo对象列表,我真正关心的是文件的路径.我将有一个现有的文件列表,我想将其与新的文件列表进行比较,以查看添加或删除了哪些文件.有没有更快的方法来生成这个文件路径列表?有什么办法可以优化这个文件搜索来查询共享网络驱动器上的文件吗?
更新1
我尝试创建一个非递归方法,通过首先查找所有子目录,然后迭代扫描每个目录中的文件来执行相同的操作.这是方法:
public static List<FileInfo> GetFileList(string fileSearchPattern, string rootFolderPath)
{
DirectoryInfo rootDir = new DirectoryInfo(rootFolderPath);
List<DirectoryInfo> dirList = new List<DirectoryInfo>(rootDir.GetDirectories("*", SearchOption.AllDirectories));
dirList.Add(rootDir);
List<FileInfo> fileList = new List<FileInfo>();
foreach (DirectoryInfo dir in dirList)
{
fileList.AddRange(dir.GetFiles(fileSearchPattern, SearchOption.TopDirectoryOnly));
}
return fileList;
}
Run Code Online (Sandbox Code Playgroud)
更新2
好吧,所以我在本地和远程文件夹上运行了一些测试,这两个文件夹都有很多文件(~1200).以下是我运行测试的方法.结果如下. …
代码1:
template<class T>
const PtrInterface<T>*
PtrInterface<T>::newRef() const {
PtrInterface<T>* me = (PtrInterface<T>*) this;
++me->references_;
//++this->references_;
return this;
}
Run Code Online (Sandbox Code Playgroud)
代码2:
template<class T>
const PtrInterface<T>*
PtrInterface<T>::newRef() const {
//PtrInterface<T>* me = (PtrInterface<T>*) this;
//++me->references_;
++this->references_;
return this;
}
Run Code Online (Sandbox Code Playgroud)
是否有任何情况下这两个代码块会做不同的事情?谢谢!
假设我有
public static List<T2> Map<T,T2>(List<T> inputs, Func<T, T2> f)
{
return inputs.ConvertAll((x) => f(x));
}
private int Square(int x) { return x*x; }
public void Run()
{
var inputs = new List<Int32>(new int[]{2,4,8,16,32,64,128,256,512,1024,2048});
// this does not compile
var outputs = Map(inputs, Square);
// this is fine
var outputs2 = Map<Int32,Int32>(inputs, Square);
// this is also fine (thanks, Jason)
var outputs2 = Map<Int32,Int32>(inputs, (x)=>x*x);
// also fine
var outputs2 = Map(inputs, (x)=>x*x);
}
Run Code Online (Sandbox Code Playgroud)
为什么不编译?
编辑:错误是:
错误CS0411:无法从用法推断出方法'Namespace.Map <T,T2>(System.Collections.Generic.List <T>,System.Func <T,T2>)'的类型参数.尝试显式指定类型参数. …
我在运行EXC_BAD_ACCESS时遇到了一个对象,这个对象几乎没有performSelector:withObject:afterDelay选择器方法调用另一个对象而我正在释放该对象......
//我班上的某些地方,我正在打电话
[self performSelector:@selector(callObject1Function) withObject:nil afterDelay:2.0];
Run Code Online (Sandbox Code Playgroud)
我只是不明白我想当你dealloc的对象,与对象相关的一切都应该删除或取消,即使performSelector有延迟!有人可以解释一下,谢谢......