我如何(轻松地)获取一个字符串,例如"sin(x)*x^2"用户可能在运行时输入的字符串,并生成一个可以评估任何值的Python函数x?
假设我有一个名为myTable的表.返回此表的所有字段名称的SQL命令是什么?如果答案是特定于数据库的,那么我现在需要SQL Server,但是也有兴趣看到其他数据库系统的解决方案.
我想在没有网络连接的机器上创建一个conda环境.到目前为止我所做的是:
在连接到互联网的计算机上:
conda create -n python3 python=3.4 anaconda
Run Code Online (Sandbox Code Playgroud)
Conda将所有相关软件包归档到\Anaconda\pkgs.我把它们放在一个单独的文件夹中,并将其移动到没有网络连接的机器上.该文件夹具有路径PATHTO\Anaconda_py3\win-64
我试过了
conda create -n python=3.4 anaconda --offline --channel PATHTO\Anaconda_py3
Run Code Online (Sandbox Code Playgroud)
这给出了错误消息
Fetching package metadata:
Error: No packages found in current win-64 channels matching: anaconda
You can search for this package on Binstar with
binstar search -t conda anaconda
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?如何告诉conda基于此目录中的包创建环境?
我已经在IPython笔记本中定义了一个函数,并希望能够阻止对它的一部分进行注释.直观地说,我希望能够突出显示一段代码,右键单击并选择注释掉选择,但这尚未实现.
有没有办法做到这一点?
是否可以在PowerShell中轻松列出用户创建的变量?该get-variableCmdlet的给了我所有的系统变量,以及这是不是有时想我.
例如,如果我打开一个新会话并执行
$a=1
$b=2
Run Code Online (Sandbox Code Playgroud)
我想的一些变种get-variable,只有收益a和b因为他们已经在会议上明确创建的仅有的两个变量.
我有一个来自下游库的 C 函数,我像这样在 C 中调用
result = cfunction(input_function)
Run Code Online (Sandbox Code Playgroud)
input_function 是一个回调,需要具有以下结构
double input_function(const double &x)
{
return(x*x);
}
Run Code Online (Sandbox Code Playgroud)
哪里x*x是用户定义的计算,通常要复杂得多。我想cfunction使用 Rcpp进行包装,以便 R 用户可以在任意 R 函数上调用它。
NumericVector rfunction(Function F){
NumericVector result(1);
// MAGIC THAT I DON'T KNOW HOW TO DO
// SOMEHOW TURN F INTO COMPATIBLE input_funcion
result[0] = cfunction(input_function);
return(result);
}
Run Code Online (Sandbox Code Playgroud)
然后,R 用户可能会这样做rfunction(function(x) {x*x})并获得正确的结果。
我知道在内部调用 R 函数cfunction会降低速度,但我认为我可以在稍后弄清楚如何传递编译函数。我只想让这部分工作。
我能找到的最接近我需要的东西是这个https://sites.google.com/site/andrassali/computing/user-supplied-functions-in-rcppgsl它包装了一个使用回调的函数,该函数具有一个 oh-非常有用的第二个参数,我可以在其中填充 R 函数。
建议将不胜感激。
Using the platform module in Python on my Windows laptop, I get the following output
import platform
platform.processor()
Run Code Online (Sandbox Code Playgroud)
'Intel64 Family 6 Model 58 Stepping 9, GenuineIntel'
If I look at the Windows System Information, however, I am told that my processor is an Intel Core i5-3317U CPU at 1.70Ghz. How can I get Python to return processor information in this format?
我有一个字符串列表 - 类似于
mytext = ['This is some text','this is yet more text','This is text that contains the substring foobar123','yet more text']
Run Code Online (Sandbox Code Playgroud)
我想找到第一次出现以foobar开头的东西.如果我正在贪图,那么我会搜索foobar*.我目前的解决方案是这样的
for i in mytext:
index = i.find("foobar")
if(index!=-1):
print i
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,但我想知道是否有一个'更好'(即更pythonic)的方式这样做?
干杯,迈克
我正在开发一个Python项目,其中包含许多简单的示例脚本,以帮助新用户习惯系统.除了每个示例的源代码,我还包括我在测试计算机上获得的输出,以便用户知道一切顺利时会发生什么.
它发生在我身上,我可以用它作为单元测试的粗略形式.自动运行所有示例脚本,并针对预期输出执行大量差异.
我的所有示例脚本都以扩展名.py结尾,因此我可以轻松地使用类似的东西来获取文件名
pythonfiles=[filename for filename in os.listdir(source_directory) if filename[-3:]=='.py']
Run Code Online (Sandbox Code Playgroud)
因此,pythonfiles包含类似['example1.py','cool_example.py']等内容.
我可以使用什么语法来实际运行此列表中引用的脚本?
我在目录中有六个.txt文件.所以,我创建了一个变量:
$foo = gci -Name *.txt
Run Code Online (Sandbox Code Playgroud)
$foo现在是一个包含六个字符串的数组.就我而言,我有
PS > $foo
Extensions.txt
find.txt
found_nots.txt
output.txt
proteins.txt
text_files.txt
PS > $foo.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
PS > $foo.Count
6
Run Code Online (Sandbox Code Playgroud)
我想测量那个对象,所以我把它传递给Measure-Object:
PS > $foo | Measure-Object
Count : 6
Average :
Sum :
Maximum :
Minimum :
Property :
Run Code Online (Sandbox Code Playgroud)
这就是我所期待的.但是,我也可能这样通过$foo:
PS> Measure-Object -InputObject $foo
Count : 1
Average :
Sum :
Maximum :
Minimum :
Property :
Run Code Online (Sandbox Code Playgroud)
这不是我所期待的.这里发生了什么?