在 python 中导入模块时遇到一些问题。这是我的文件夹结构
my_app/
app.py
__init__.py (I want to import a function from this file)
folder1/
__init.py
method1.py
folder2/
__init__.py
method.py
Run Code Online (Sandbox Code Playgroud)
在我的根中,__init__.py我有这个功能
def want_to_be_run_elsewhere():
pass
Run Code Online (Sandbox Code Playgroud)
在我的 app.py 中,我想导入这个函数并在我启动我的应用程序时运行它,但我不确定如何去做。
from my_app import want_to_be_run_elsewhere
Run Code Online (Sandbox Code Playgroud)
这会抛出一个名为 my_app 的无模块
据我所知,我拥有所有必要的__init__.py文件,所以它可能与 sys.path 相关?
我在这里阅读了一些类似的主题,但我无法解决这个问题。
pytest的内置灯具的范围可以改变吗?
这不起作用:
@pytest.fixture(scope="class")
def myFixture(tmpdir):
pass
Run Code Online (Sandbox Code Playgroud)
...因为tmpdir功能范围:
ScopeMismatch: You tried to access the 'function' scoped fixture 'tmpdir' with a 'class' scoped request object, involved factories
Run Code Online (Sandbox Code Playgroud)
是否有可能覆盖pytest的内置灯具的范围,这样我就可以得到一个类范围的tmpdir灯具?
每次规格运行时,RSpec都会打印出来Run options: include {:focus=>true}.
我已经知道运行选项是什么,所以有没有办法抑制这个输出?
操作系统:Ubuntu 16.04.3 LTS(GNU/Linux 4.4.0-1066-aws x86_64)
Selenium版本:selenium == 3.6.0
浏览器:Mozilla Firefox 63.0
Geckodriver版本:geckodriver-v0.19.0-linux64
创建一个新的Firefox浏览器并执行一些步骤 - 解析网站.
与日志崩溃: -
self.driver = webdriver.Firefox()
File "/home/ubuntu/env/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 154, in __init__
keep_alive=True)
File "/home/ubuntu/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/home/ubuntu/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/ubuntu/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "/home/ubuntu/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: newSession
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这个问题并且有可能的解决方案?
更新:运行以下命令: geckodriver --log trace & curl -d '{}' 127.0.0.1:4444/session
记录: …
如果
$REMOTE已安装遥控器的本地仓库$BRANCH我尚未提取的远程仓库中的新分支我可以获取该分支并在单个命令中将其检入到同名的跟踪本地分支中吗?
我可以用两个命令实现所需的结果
git fetch $REMOTE $BRANCH
git checkout $BRANCH # or more explicitly git checkout -b $BRANCH $REMOTE/$BRANCH
Run Code Online (Sandbox Code Playgroud)
或者(灵感来自问题的答案我如何查看远程Git分支?)
git fetch $REMOTE $BRANCH:$BRANCH
git branch --set-upstream-to=$BRANCH $BRANCH
Run Code Online (Sandbox Code Playgroud) 是否有官方记录的git工作流程就像nvie的"Gitflow"工作流程但没有发布分支?
http://nvie.com/posts/a-successful-git-branching-model/
https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow
我想我没有看到发布分支的目的,为什么不只是标记一个来自master的发布?(也许这是一回事).
这是我想要了解的神经网络神经元的Python表示
class Network(object):
def __init__(self, sizes):
self.num_layers = len(sizes)
self.sizes = sizes
self.biases = [np.random.randn(y, 1) for y in sizes[1:]]
self.weights = [np.random.randn(y, x)
for x, y in zip(sizes[:-1], sizes[1:])]
Run Code Online (Sandbox Code Playgroud)
这是我目前的理解:
self.num_layers = len(sizes):返回大小的项目数self.sizes = sizes:将自我实例大小分配给函数参数大小self.biases = sizes:从标准正态分布生成一个元素数组(表示为np.random.randn(y, 1))以下行计算是什么?
self.weights = [np.random.randn(y, x)
for x, y in zip(sizes[:-1], sizes[1:])]
Run Code Online (Sandbox Code Playgroud)
我是Python的新手.这个代码可以在Python shell中使用,这样我可以通过单独调用每一行来获得更好的理解吗?
有没有办法可以覆盖System.out.print()的输出.这是我想做的事情?System.out.print("ABCDEFGHIJK L"); 将打印:ABCDEFGHIJKL
现在我想编写一个方法来覆盖特定位置的输出.覆盖(7,"XY Z"); 应输出我,ABCXYZGHIJKL
这些应该发生在控制台中.
请帮忙.谢谢
当一个unittest.mock.Mock对象被调用时,我可以检查具有该调用的确切签名的参数值:
from unittest.mock import Mock
m = Mock() # creation of mock
m('foo', bar='baz') # call to the mock
m.assert_called_once_with('foo', bar='baz') # check call arguments
Run Code Online (Sandbox Code Playgroud)
检查具有相同值的其他签名将失败.例如,如果我们检查'baz'作为位置参数而不是命名参数,则断言将失败:
m.assert_called_once_with('foo', 'baz')
# AssertionError: Expected call: mock('foo', 'baz')
# Actual call: mock('foo', bar='baz')
Run Code Online (Sandbox Code Playgroud)
它必须.如果功能被替换m为
def actual_fu(foo, bar):
# do something
Run Code Online (Sandbox Code Playgroud)
然后调用将是等效的,但如果是的话
def a_different_actual_fu(foo, *args, bar='some default'):
# do something
Run Code Online (Sandbox Code Playgroud)
那么这些电话就不一定了.Mock不知道实际函数的签名,因此它不能依赖于我们在第一种情况下的等价性.
有没有办法通过让Mock(或断言助手函数或类似函数)了解模拟替换的实际函数来检查与它们是通过位置传递还是作为关键字参数无关的调用参数值?
该Mock对象可以知道它所取代的对象(可以是一个函数或方法)与可选的spec参数或autospeccing,但那些用于不同的目的(限制什么叫以允许在模拟),并且不影响以后 - 事实核查.
是否有内置函数或标准库函数大致相当于
def recur_until(start, step_fu, stop_predicate=lambda _: False):
current = start
while not stop_predicate(current):
yield current
current = step_fu(current)
Run Code Online (Sandbox Code Playgroud)
要么
def recur_while(start, step_fu, predicate=lambda _: True):
current = start
while predicate(current):
yield current
current = step_fu(current)
Run Code Online (Sandbox Code Playgroud)
甚至只是
def recur(start, step_fu):
current = start
while True:
yield current
current = step_fu(current)
Run Code Online (Sandbox Code Playgroud)
在任何版本的Python?(当与之结合时,后者与其他两个一样好itertools.takewhile.)
像这样的生成器函数将允许迭代地计算某些递归定义的序列,即一阶递归关系.
虽然这些在需要时不太难实现,但我觉得像他们这样的东西应该是itertools或者可能的functools一部分,但如果是的话,我还没有在文档中发现它.
list(recur_until(2, lambda x: x**2 - 1, lambda x: x > 1e4))
# [2, 3, 8, 63, 3968]
Run Code Online (Sandbox Code Playgroud)
还应该使用非数字元素:
list(recur_until('', lambda x: …Run Code Online (Sandbox Code Playgroud) python ×6
git ×2
fixtures ×1
functools ×1
geckodriver ×1
git-branch ×1
git-checkout ×1
git-fetch ×1
git-flow ×1
github ×1
java ×1
mocking ×1
numpy ×1
pytest ×1
recurrence ×1
recursion ×1
rspec ×1
scope ×1
selenium ×1
ubuntu ×1
unit-testing ×1