我在Mac OS 10.6 Snow Leopard上,我正在尝试在我的PATH变量中添加一个目录,这样我就可以在终端提示符下输入:python alarm.py来编写一个小脚本.
我把路径放在我的.profile文件中,它似乎出现在我回显$ PATH时,但是python仍然无法找到我放在该目录中的脚本.
这是我的主目录中的.profile文件的内容:
~ toby$ vim .profile
export PATH=/Users/tobylieven/Documents/my_scripts:$PATH
Run Code Online (Sandbox Code Playgroud)
这是echo $ PATH的输出,其中一切似乎都很好:
~ toby$ echo $PATH
/Users/tobylieven/Documents/my_scripts:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试运行的脚本:
~ toby$ ls /Users/tobylieven/Documents/my_scripts
-rwxrwxrwx@ 1 tobylieven staff 276 17 Jan 21:17 alarm.py
Run Code Online (Sandbox Code Playgroud)
这是我试图用来运行脚本的命令和我得到的失败消息:
~ toby$ python alarm.py
python: can't open file 'alarm.py': [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)
如果有人知道我可能做错了什么,那就太好了.非常感谢.
我正在学习javascript中的类和继承。我认为以下是扩展现有对象的相当标准的方法,因为我从Object.create的MDN文档中获得了样式
我期待看到“确定”,然后看到“是!控制台中的“ Hello”,但出现此错误:
Uncaught TypeError: #<MyPromise> is not a promise
at new MyPromise (<anonymous>:5:17)
at <anonymous>:19:6
Run Code Online (Sandbox Code Playgroud)
看起来Promise构造函数正在抛出异常,因为它可以告诉我给我初始化的对象不是一个简单的Promise。
我希望Promise构造函数初始化我的对象,就像它是一个Promise对象一样,这样我就可以扩展该类。他们为什么不编写Promise构造函数来使用这种通用模式?难道我做错了什么?为您加油!
MyPromise = function(message, ok) {
var myPromise = this;
this.message = message;
this.ok = ok;
Promise.call(this, function(resolve, reject) {
if(this.ok) {
console.log('ok');
resolve(myPromise.message);
} else {
console.log('not ok');
reject(myPromise.message);
}
});
};
MyPromise.prototype = Object.create(Promise.prototype);
MyPromise.prototype.constructor = MyPromise;
(new MyPromise('Hello', true))
.then(function(response) {console.log('Yay! ' + response);})
.except(function(error) {console.log('Aww! ' + error);});
Run Code Online (Sandbox Code Playgroud)
我最初试图制作一个可以使用的BatchAjax类,例如:
(new BatchAjax([query1, query2]))
.then(function(response) {console.log('Fires when …
Run Code Online (Sandbox Code Playgroud) 当我尝试安装nvm并测试它是否安装在我的vagrant shell配置脚本中时,使用:
sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash
source ~/.bashrc
nvm
Run Code Online (Sandbox Code Playgroud)
我明白了:
==> default: => Downloading nvm as script to '/root/.nvm'
==> default: => Appending source string to /root/.bashrc
==> default: => You can now install Node.js by running `nvm install`
==> default: /tmp/vagrant-shell: line 7: nvm: command not found
Run Code Online (Sandbox Code Playgroud)
首先我不希望它以root用户身份安装,我想将其安装为/ home/vagrant中的vagrant用户以避免权限问题.
第二个为什么在我source .bashrc
按照nvm安装说明中的指定运行时找不到命令https://github.com/creationix/nvm?
我有一个解决方案,我现在正在添加.