私信  •  关注

greg

greg 最近创建的主题
greg 最近回复了
4 年前
回复了 greg 创建的主题 » 理解python中的列表

试着看看下面的代码。它应该有助于你了解幕后发生的事情:

arr = [1,2,3,9,10,12]
index = 0

for i in arr:
  print('First print: ', i, index, arr[index])
  arr.remove(i)
  print('Second print: ', i, index, arr[index])
  index += 1

  # ('First print: ', 1, 0, 1)
  # ('Second print: ', 1, 0, 2)
  # ('First print: ', 3, 1, 3)
  # ('Second print: ', 3, 1, 9)
  # ('First print: ', 10, 2, 10)
  # ('Second print: ', 10, 2, 12)

arr = [1,2,3,9,10,12]
index = 0

for i in list(arr):
  print('First print: ', i, index, arr[index])
  arr.remove(i)
  print('Second print: ', i, index, arr[index])
  index += 1

  # ('First print: ', 1, 0, 1)
  # ('Second print: ', 1, 0, 2)
  # ('First print: ', 2, 1, 3)
  # ('Second print: ', 2, 1, 9)
  # ('First print: ', 3, 2, 10)
  # ('Second print: ', 3, 2, 12)
  # Traceback (most recent call last):
  #  File "<stdin>", line 2, in <module>
  # IndexError: list index out of range

我发现了问题。数据库脚本最初是由某个工具创建的(我认为它可能是pgdump),然后添加了手动更改。这个工具在脚本的开头添加了一些不需要的语句。其中一项声明如下:

SELECT pg_catalog.set_config('search_path', '', false);

我想这个设置会覆盖“ALTER DATABASE设置搜索路径”。一旦我删除了该语句,脚本就可以正常工作,并创建表。

15 年前
回复了 greg 创建的主题 » Django与其他python web框架的对比?

你退房了吗?在最近评估了许多PythonWeb框架之后,我决定采用这个框架。如果你还没有的话,还可以看看谷歌应用引擎。