使用rpy和psycopg2的Python循环

使用rpy和psycopg2的Python循环,python,r,for-loop,Python,R,For Loop,你好 我已经挣扎了一段时间,在谷歌上找不到答案。我在使用Python和rpy,而不是rpy2和psycopg2来实现PostgreSQL。尝试SQL循环时,我会执行以下操作: for i in xrange(1:11): script = "DELETE FROM table WHERE column = %d" % i cur.execute(script) for i in xrange(1:11): test = "15 * %d" % i r('test

你好

我已经挣扎了一段时间,在谷歌上找不到答案。我在使用Python和rpy,而不是rpy2和psycopg2来实现PostgreSQL。尝试SQL循环时,我会执行以下操作:

for i in xrange(1:11):
    script = "DELETE FROM table WHERE column = %d" % i
    cur.execute(script)
for i in xrange(1:11):
    test = "15 * %d" % i
    r('test')                # This does not work
    r.assign('test', test')
    r('print(test)')         # This does not work either
    x = r('test')
    print x                  # This prints 15 * 1, then 15 * 2, but not 15 and 30.
这很好,但是如何使用rpy做类似的事情呢?例如:

for i in xrange(1:11):
    script = "DELETE FROM table WHERE column = %d" % i
    cur.execute(script)
for i in xrange(1:11):
    test = "15 * %d" % i
    r('test')                # This does not work
    r.assign('test', test')
    r('print(test)')         # This does not work either
    x = r('test')
    print x                  # This prints 15 * 1, then 15 * 2, but not 15 and 30.

对不起,如果这太简单了,但我卡住了

我设法弄明白了

简单地说:

r('test <- 15 * %d' % i)
这以前从未像我这样起过作用:

r('test <- 15 * %d') % i
不知道为什么会有不同,但这似乎有效