我跑的时候
import sys
print sys.path
Run Code Online (Sandbox Code Playgroud)
在我的Mac(Mac OS X 10.6.5,Python 2.6.1)上,我得到以下结果.
/Library/Python/2.6/site-packages/ply-3.3-py2.6.egg ... /Library/Python/2.6/site-packages/ipython-0.10.1-py2.6.egg /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload /Library/Python/2.6/site-packages /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode
它们分为5类.
我可以使用代码添加更多路径
sys.path.insert(0, MORE_PATH)
Run Code Online (Sandbox Code Playgroud)
根据Michael的回答,我调查了site.py,并得到了以下代码.
def addsitepackages(known_paths):
"""Add site-packages (and possibly site-python) to sys.path"""
sitedirs = []
seen = []
for prefix in PREFIXES:
if not prefix or prefix in seen:
continue
seen.append(prefix)
if sys.platform …Run Code Online (Sandbox Code Playgroud) 我需要通过运行which abc命令来设置环境.是否有Python等效的which命令功能?这是我的代码.
cmd = ["which","abc"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
res = p.stdout.readlines()
if len(res) == 0: return False
return True
Run Code Online (Sandbox Code Playgroud) 为什么这个Ruby对象to_s和inspect看起来做同样事情的方法?
该p方法调用inspect并放置/打印to_s用于表示对象的调用.
如果我跑
class Graph
def initialize
@nodeArray = Array.new
@wireArray = Array.new
end
def to_s # called with print / puts
"Graph : #{@nodeArray.size}"
end
def inspect # called with p
"G"
end
end
if __FILE__ == $0
gr = Graph.new
p gr
print gr
puts gr
end
Run Code Online (Sandbox Code Playgroud)
我明白了
G
Graph : 0
Graph : 0
Run Code Online (Sandbox Code Playgroud)
to_s和之间有什么区别inspect?puts,print以及p?如果我注释掉 …
这是类名称空间中的静态println函数吗?outSystem
namespace System {
class out {
static println ...
}
我怎么能解释这个名字?在JRE中定义了这个函数?在java.lang.System/ java.lang.Object?
我开始使用Visual Studio 2010中,我与C#程序完成后,我看到有.sln,并.suo在项目的根目录中的文件和.csproj子目录中的文件.这些文件是为了什么?
我需要识别要放入Git存储库的文件.连同我创建的源代码/文档,我猜这三个文件是我唯一需要处理的文件.但是,我不确定我是否正在跟踪正确的文件.
个人宏文件怎么样?我有Emacs键开关宏,.sln文件或.csproj文件有这个宏吗?
以下简单的LINQ代码
string[] words = { "hello", "wonderful", "linq", "beautiful", "world" };
// Get only short words
var shortWords =
from word in words
where word.Length <= 5
select word;
// Print each word out
shortWords.Dump();
Run Code Online (Sandbox Code Playgroud)
可以使用列表推导将其翻译成python,如下所示.
words = ["hello", "wonderful", "linq", "beautiful", "world"]
shortWords = [x for x in words if len(x) <=5]
print shortWords
Run Code Online (Sandbox Code Playgroud)
通常,最简单的调试方法是使用printf.我该怎么做来调试emacs-lisp?如何从elisp打印emacs编辑器?或者有没有办法调试elisp代码?
例如,如何检查以下代码是否在.emacs文件中运行?
(load "auctex.el" nil t t)
Run Code Online (Sandbox Code Playgroud) 我读了一些不鼓励使用DYLD_LIBRARY_PATH的文章,因为动态库的路径应该使用-install_name,@ aptath和@loader_path来修复.
在制作在Linux和Mac OS X上运行的程序方面,Mac OS X的DYLD_LIBRARY_PATH正好与Linux的LD_LIBRARY_PATH完全相同.而且,我们可以(几乎)共享同一个没有-install_name和@rpath的make文件.
我需要检查加载dll后运行GetTypes()的时间量.代码如下.
Assembly assem = Assembly.LoadFrom(file);
sw = Stopwatch.StartNew();
var types1 = assem.GetTypes();
sw.Stop();
double time1 = sw.Elapsed.TotalMilliseconds;
Run Code Online (Sandbox Code Playgroud)
我想卸载并重新加载dll以检查再次运行GetTypes()所花费的时间.
assem = null够好吗?