我正在从学习Python艰难的方式学习Python包,其中一个练习它说:
将脚本放在可以运行的bin目录中
对我来说,这看起来有点模糊.我不确定哪种脚本会进入bin文件夹.Hitchhiker的包装指南说
将你编写过的任何使用你的软件包的脚本放入bin中,你认为这些脚本对你的用户有用.如果您没有,请删除bin目录.
但是我仍然想知道那里会有什么样的剧本.所以,我知道它可能听起来像一个愚蠢的问题,但是有人可以给我一个例子说明何时,以及为什么会在其包的bin文件夹中放入"脚本"?
所以我一直在努力学习"学习Python的艰难之路"的最后一个练习,它指出在我运行程序之前,你必须设置Pythonpath环境变量,如下所示:
export PYTHONPATH=$PYTHONPATH:.
Run Code Online (Sandbox Code Playgroud)
我已经完成了这个,并且在它没有工作之后(我假设这就是为什么当我尝试运行我的程序时,我得到一个ImportError),我做了一些关于pythonpath的研究.它基本上说Pythonpath是要找到要导入的模块的位置.所以我将Pythonpath设置为我试图导入的模块的实际位置,但仍无济于事.
这是我的目录:
我试图运行app.py,尝试导入main.py模块:
from gothonweb import maps
Run Code Online (Sandbox Code Playgroud)
但我仍然得到这个错误:
Traceback (most recent call last):
File "python_stuff/projects/GothonWeb/bin/app.py", line 2, in <module>
from gothonweb import maps
ImportError: No module named gothonweb
Run Code Online (Sandbox Code Playgroud)
有谁知道什么?哦,其他一些细节.在Mac Os X Lion上运行Python 2.7,如果有帮助的话.
假设我已经在Objective-C中创建了一个Fraction类(如"使用Objective-C编程"一书).其中一个方法是添加:,首先创建如下:
//Fraction.h & most of Fraction.m left out for brevity's sake.
-(Fraction *)add: (Fraction*) f {
Fraction *result = [[Fraction alloc] init];
//Notice the dot-notation for the f-Fraction
result.numerator = numerator * f.denominator + denominator * f.numerator;
result.denominator = denominator * f.denominator;
return result;
}
Run Code Online (Sandbox Code Playgroud)
然后在后面的一个练习中,它将返回类型和参数类型更改为id并使其工作.点符号,如上所示不再起作用,所以我改为:
-(id)add: (id)f {
Fraction *result = [[Fraction alloc] init];
result.numerator = numerator * [f denominator] + denominator * [f numerator];
// So forth and so on...
return result;
}
Run Code Online (Sandbox Code Playgroud)
现在我想为什么点符号需要改变是因为直到运行时,程序不知道传递给add参数(f)的对象是什么类型,因此编译器不知道f的任何访问方法.
我能接近理解这个吗?如果没有,有人可以澄清一下吗?