我经常有一个处理一个文件的命令,我想在目录中的每个文件上运行它.有没有内置的方法来做到这一点?
例如,假设我有一个程序data输出关于文件的重要数字:
./data foo
137
./data bar
42
Run Code Online (Sandbox Code Playgroud)
我想以某种方式在目录中的每个文件上运行它,如下所示:
map data `ls *`
ls * | map data
Run Code Online (Sandbox Code Playgroud)
产生这样的输出:
foo: 137
bar: 42
Run Code Online (Sandbox Code Playgroud) 有没有什么方法可以对大型数组进行malloc,但是用2D语法引用它?我想要的东西:
int *memory = (int *)malloc(sizeof(int)*400*200);
int MAGICVAR = ...;
MAGICVAR[20][10] = 3; //sets the (200*20 + 10)th element
Run Code Online (Sandbox Code Playgroud)
#define INDX(a,b) (a*200+b);
Run Code Online (Sandbox Code Playgroud)
然后参考我的blob:
memory[INDX(a,b)];
Run Code Online (Sandbox Code Playgroud)
我更喜欢:
memory[a][b];
Run Code Online (Sandbox Code Playgroud)
int *MAGICVAR[][200] = memory;
Run Code Online (Sandbox Code Playgroud)
没有这样的语法吗?请注意我不仅使用固定宽度数组的原因是它太大而无法放在堆栈上.
void toldyou(char MAGICVAR[][286][5]) {
//use MAGICVAR
}
//from another function:
char *memory = (char *)malloc(sizeof(char)*1820*286*5);
fool(memory);
Run Code Online (Sandbox Code Playgroud)
我收到警告,passing arg 1 of toldyou from incompatible pointer type但代码有效,我已经确认访问了相同的位置.没有使用其他功能有没有办法做到这一点?
Haskell中是否存在指针质量的概念?==要求事物得到Eq,并且我有一些东西包含(值 - > IO值),而且 - >和IO都没有得到Eq.
编辑:我创建了这另一种语言翻译确实有指针相等,所以我想,同时仍然能够使用Haskell函数模型关闭模型此行为.
编辑:示例:我想要一个special能够执行此操作的函数:
> let x a = a * 2
> let y = x
> special x y
True
> let z a = a * 2
> special x z
False
Run Code Online (Sandbox Code Playgroud) 在Python中,该with语句用于确保始终调用清理代码,无论抛出异常还是返回函数调用.例如:
with open("temp.txt", "w") as f:
f.write("hi")
raise ValueError("spitespite")
Run Code Online (Sandbox Code Playgroud)
在这里,即使引发了异常,文件也会关闭.这里有一个更好的解释.
Ruby中有这个构造的等价物吗?或者你可以编写一个代码,因为Ruby有延续吗?
在Haskell中,由于懒惰,您可以构建无限列表:
Prelude> let g = 4 : g
Prelude> g !! 0
4
Prelude> take 10 g
[4,4,4,4,4,4,4,4,4,4]
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试构建这样的列表时到底发生了什么?
Prelude> let f = f !! 10 : f
Prelude> f !! 0
Interrupted.
Prelude> take 10 f
[Interrupted.
Prelude>
Run Code Online (Sandbox Code Playgroud)
该Interrupted.s的我按CTRL + C等待几秒钟后.它似乎陷入无限循环,但为什么会这样呢?
非Haskellers的解释:
该:操作是prepend:
Prelude> 4 : [1, 2, 3]
[4,1,2,3]
Run Code Online (Sandbox Code Playgroud)
这一行:
Prelude> let g = 4 : g
Run Code Online (Sandbox Code Playgroud)
说"让我们g通过预先4列入名单来构建清单g".当你要求第一个元素时,返回4,因为它已经存在.当你要求第二个元素时,它会查找4之后的元素.该元素将是列表的第一个元素g,我们刚刚计算(4),因此4返回.下一个元素是g我们再次计算的第二个元素,等等......
!!仅仅是索引到一个列表,所以这意味着在指数获得元素 …
如果我有一个模块,foo在Lib/site-packages,我可以import foo,它会工作.然而,当我从鸡蛋中安装东西时,我得到的东西就像blah-4.0.1-py2.7-win32.egg文件夹一样,里面有模块内容,但我仍然只需要做import foo,而不是更复杂.Python如何跟踪鸡蛋?它不仅仅是dirname匹配,就好像我将该文件夹放入Python安装而不通过dist-utils,它找不到模块.
更清楚:我刚刚安装了zope.文件夹名称为"zope.interface-3.3.0-py2.7-win32.egg".这有效:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import zope.interface
>>>
Run Code Online (Sandbox Code Playgroud)
我创建了一个"blah-4.0.1-py2.7-win32.egg"文件夹,其中包含一个空模块"haha"(和__init__.py).这不起作用:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import blah.haha
Traceback (most recent call last):
File "<stdin>", line 1, in …Run Code Online (Sandbox Code Playgroud) 我想utils/django.py在我的项目中创建一个模块.在顶部我有线:
from django.db import models
Run Code Online (Sandbox Code Playgroud)
但是,它会尝试从自身导入,这会导致错误.我知道我可以使用前置强制进行相对导入.:
from .django.db import models
Run Code Online (Sandbox Code Playgroud)
有没有办法强制进行非相对导入?
我有这个装饰:
def timed_out(timeout):
def decorate(f):
if not hasattr(signal, "SIGALRM"):
return f
def handler(signum, frame):
raise TimedOutExc()
@functools.wraps(f)
def new_f(*args, **kwargs):
old = signal.signal(signal.SIGALRM, handler)
signal.alarm(timeout)
try:
result = f(*args, **kwargs)
finally:
signal.signal(signal.SIGALRM, old)
signal.alarm(0)
return result
new_f.func_name = f.func_name
return new_f
return decorate
Run Code Online (Sandbox Code Playgroud)
但代码只能在linux上执行任何操作,因为在Windows上,没有SIGALRM.在Windows中使用此代码的最简单方法是什么?
我有这样的代码:
setTimeout(foo, 600);
Run Code Online (Sandbox Code Playgroud)
我一直认为foo没有任何争论,例如:
function foo() { /* bars */ }
Run Code Online (Sandbox Code Playgroud)
但是,执行以下操作:
function foo(a) { alert(a); /* bars */ }
Run Code Online (Sandbox Code Playgroud)
弹出一个显示-7的警报.这个数字代表什么?
我正在使用谷歌日历API,我收到两个错误.
GTMGatherInputStream.m:25:13:找到名为'initWithArray:'的多个方法
#import "GTMGatherInputStream.h"
@implementation GTMGatherInputStream
+ (NSInputStream *)streamWithArray:(NSArray *)dataArray {
return [[[self alloc] initWithArray:dataArray] autorelease]; //error on this line
}
Run Code Online (Sandbox Code Playgroud)GTMOAuth2Authentication.h:31:11:找不到'GTMSessionFetcher.h'文件
#if GTM_USE_SESSION_FETCHER
#import "GTMSessionFetcher.h" //GTMSessionFetcher.h file not found error
#else
#import "GTMHTTPFetcher.h"
#endif // GTM_USE_SESSION_FETCHER
Run Code Online (Sandbox Code Playgroud)我在网上到处研究过这个错误,但我什么都没发现.我正在使用GM Xcode 7.0运行GM El capitan.我已经尝试了多种不同的方法来解决它,但没有任何方法可行.我的代码不会编译.我该如何解决?
python ×4
haskell ×2
module ×2
pointers ×2
alarm ×1
api ×1
arrays ×1
bash ×1
c ×1
comparison ×1
control-flow ×1
easy-install ×1
egg ×1
equality ×1
google-api ×1
import ×1
importerror ×1
installation ×1
javascript ×1
malloc ×1
map ×1
objective-c ×1
path ×1
ruby ×1
shell ×1
signals ×1
swift ×1
windows ×1
xcode7 ×1