小编Wal*_*mly的帖子

用Python解析方程式

我如何(轻松地)获取一个字符串,例如"sin(x)*x^2"用户可能在运行时输入的字符串,并生成一个可以评估任何值的Python函数x

python parsing equation

38
推荐指数
4
解决办法
5万
查看次数

返回表的字段名称的SQL命令是什么?

假设我有一个名为myTable的表.返回此表的所有字段名称的SQL命令是什么?如果答案是特定于数据库的,那么我现在需要SQL Server,但是也有兴趣看到其他数据库系统的解决方案.

mysql sql database sql-server

37
推荐指数
2
解决办法
11万
查看次数

如何在离线时安装conda环境?

我想在没有网络连接的机器上创建一个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基于此目录中的包创建环境?

python anaconda conda

34
推荐指数
3
解决办法
3万
查看次数

如何在IPython笔记本中阻止注释代码?

我已经在IPython笔记本中定义了一个函数,并希望能够阻止对它的一部分进行注释.直观地说,我希望能够突出显示一段代码,右键单击并选择注释掉选择,但这尚未实现.

有没有办法做到这一点?

ipython ipython-notebook

32
推荐指数
1
解决办法
3万
查看次数

如何在PowerShell中仅列出用户创建的变量?

是否可以在PowerShell中轻松列出用户创建的变量?该get-variableCmdlet的给了我所有的系统变量,以及这是不是有时想我.

例如,如果我打开一个新会话并执行

$a=1
$b=2
Run Code Online (Sandbox Code Playgroud)

我想的一些变种get-variable,只有收益ab因为他们已经在会议上明确创建的仅有的两个变量.

powershell scripting

7
推荐指数
2
解决办法
5001
查看次数

使用 rcpp 将 R 函数传递给 C 例程

我有一个来自下游库的 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 函数。

建议将不胜感激。

r rcpp

5
推荐指数
1
解决办法
68
查看次数

How to get the processor name in Python?

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?

python windows

4
推荐指数
2
解决办法
3320
查看次数

Pythonic搜索列表中的子字符串的方法

我有一个字符串列表 - 类似于

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 string substring list

3
推荐指数
4
解决办法
791
查看次数

在列表中运行一组Python脚本

我正在开发一个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']等内容.

我可以使用什么语法来实际运行此列表中引用的脚本?

python

2
推荐指数
1
解决办法
275
查看次数

为什么'Measure-Object -InputObject $ foo'与'$ foo |不同 PowerShell中的Measure-Object'?

我在目录中有六个.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)

这不是我所期待的.这里发生了什么?

windows powershell scripting

2
推荐指数
1
解决办法
450
查看次数