我正在为我常用的函数构建一个自定义包,它有几个函数不适合任何特定模块并被多个模块使用。我已经把他们的__init__.py,和它的作品,但我已经看到了推荐一个非常小的很多教程__init__.py。有没有更好的地方可以放它们?
我希望能够像这样称呼他们:
import mypackage
#functions in modules
mypackage.module.function()
#common functions
mypackage.function()
Run Code Online (Sandbox Code Playgroud)
我把这些功能放在哪里?
我有以下代码:
for i in list1:
if i == 5:
#skip the NEXT iteration (not the end of this one)
else:
#do something
Run Code Online (Sandbox Code Playgroud)
如何跳过抛出跳过的迭代后的迭代.例如,如果list1=[1, 2, 3, 4, 5, 6, 7],循环将跳过6并直接转到7因为5触发跳过我已经看到了这个问题和其他几个,但它们都处理跳过当前迭代,而我想跳过下一次迭代.这些问题的答案表明continue,据我所知,这将停止当前迭代的剩余部分并继续下一个问题,这不是我想要的.如何在循环中跳过单个迭代?
编辑:使用next()已被建议,但这对我不起作用.当我运行以下代码时:
a = [1, 2, 3, 4, 5, 6, 7, 8]
ai = iter(a)
for i in a:
print i
if i == 5:
_ = next(ai)
Run Code Online (Sandbox Code Playgroud)
我明白了
1
2
3
4
5
6 #this should not be …Run Code Online (Sandbox Code Playgroud)