我的代码目前看起来像这样:
if option1:
...
elif option2:
...
elif option3:
....
Run Code Online (Sandbox Code Playgroud)
等等.虽然我并不满意,但我想知道在python中是否有更好的选择.我的脚本是一个基于控制台的脚本,我使用argparser来获取用户需要的内容.
我有一个简单的excel表,其中包含基本的excel公式,例如sums,以及从另一个单元格中检索值.现在,我想基本上在两个现有行之间插入一个空行(我已经看过如何在现有excel中使用HSSF(Apache POI)在两行之间插入一行,但我遇到了一些奇怪的问题错误).
所以我尝试通过这样做来移动行:
worksheet.shiftRows(15,16,2);
Run Code Online (Sandbox Code Playgroud)
而我得到的回报是:
Exception in thread "main" java.lang.RuntimeException: not implemented yet
at org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook.getExternalSheetIndex(XSSFEvaluationWorkbook.java:127)
at org.apache.poi.ss.formula.FormulaParser.createAreaRefParseNode(FormulaParser.java:615)
at org.apache.poi.ss.formula.FormulaParser.parseRangeable(FormulaParser.java:462)
at org.apache.poi.ss.formula.FormulaParser.parseRangeExpression(FormulaParser.java:268)
at org.apache.poi.ss.formula.FormulaParser.parseSimpleFactor(FormulaParser.java:1119)
at org.apache.poi.ss.formula.FormulaParser.percentFactor(FormulaParser.java:1079)
at org.apache.poi.ss.formula.FormulaParser.powerFactor(FormulaParser.java:1066)
at org.apache.poi.ss.formula.FormulaParser.Term(FormulaParser.java:1426)
at org.apache.poi.ss.formula.FormulaParser.additiveExpression(FormulaParser.java:1526)
at org.apache.poi.ss.formula.FormulaParser.concatExpression(FormulaParser.java:1510)
at org.apache.poi.ss.formula.FormulaParser.comparisonExpression(FormulaParser.java:1467)
at org.apache.poi.ss.formula.FormulaParser.unionExpression(FormulaParser.java:1447)
at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:1568)
at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:176)
at org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter.updateNamedRanges(XSSFRowShifter.java:116)
at org.apache.poi.xssf.usermodel.XSSFSheet.shiftRows(XSSFSheet.java:2363)
at org.apache.poi.xssf.usermodel.XSSFSheet.shiftRows(XSSFSheet.java:2306)
at com.shel.myProgram.workbook.copyAndInsert(workbook.java:120)
at com.shel.myProgram.workbook.test(workbook.java:111)
at com.shel.myProgram.driver.main(driver.java:24)
Run Code Online (Sandbox Code Playgroud)
编辑:
我正在使用这种依赖:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) 假设我的列号为26,当我创建一个公式时,我的公式应该是这样的,例如:SUM(AA1:AA3).但是如何将26翻译成AA?或者说27到AB?Apache POI有没有办法将Column索引用作整数并将其转换为字母表示形式?
现在我有这个
ByteArrayInputStream in = new ByteArrayInputStream("2".getBytes());
System.setIn(in);
//code that does something with user inputs
Run Code Online (Sandbox Code Playgroud)
但问题是,在//代码执行某些操作时,我有多个用户输入提示,是否可以形成用户输入列表并让它在时机到来时获取相应的输入?我尝试过像"2 \n2 \n10 \nHello \n".getBytes()这样的愚蠢的事情,但这不起作用.
编辑:
我通过Scanner对象获取用户输入:
Scanner inputScanner = new Scanner(System.in);
inputScanner.nextLine();
Run Code Online (Sandbox Code Playgroud) 做:之间是否有任何显着差异:
CellStyle newCellStyle = workbook.createCellStyle();
neweCellStyle.cloneStyleFrom(oldCell.getCellStyle());
newCell.setCellStyle(newCellStyle);
Run Code Online (Sandbox Code Playgroud)
与
CellStyle newCellStyle = oldCell.getCellStyle();
newCell.setCellStyle(newCellStyle);
Run Code Online (Sandbox Code Playgroud)
我之所以这样问是因为我不确定采用第一种方法是否有可能造成太多的CellStyles,我遇到了一些问题,如果我在一个特定的工作簿中创建了太多的CellStyles,那么工作簿的所有样式都会消失.那么采取第二种方法有什么问题吗?
我正在尝试在合并现有 Cookie 的同时使用 Requests 模块在 python 上发出 get 请求,这是我的代码的样子:
import requests
url="https://stackoverflow.com/"
headers = {"User-Agent", "Mozilla/5.0"}
cookie = {
"domain": ".stackoverflow.com",
"expirationDate": "1458316186",
"hostOnly": "false",
"httpOnly": "false",
"name": "__qca",
"path": "/",
"secure": "false",
"session": "false",
"storeId": "0",
"value": "P0-SOMEVALUE-SOMEVALUE",
"id": 1
}
print requests.get(url, cookies=cookie).text
Traceback (most recent call last):
File "test.py", line 19, in <module>
print requests.get(url, cookies=cookie).text
File "C:\Python27\lib\site-packages\requests\api.py", line 55, in get
return request('get', url, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File …Run Code Online (Sandbox Code Playgroud) 我的目标是缓存视图,直到发生视图缓存需要过期的事件为止,否则缓存 1 小时。这就是我在 urls.py 中的内容
url(r'^get_some_stuff/$', cache_page(60 * 60, key_prefix='get_some_stuff')(views.StuffView.as_view())),
Run Code Online (Sandbox Code Playgroud)
这很好用。现在我尝试获取缓存的视图以验证其中是否有内容,我尝试了以下操作:
from django.core.cache import cache
cache.get('get_some_stuff')
Run Code Online (Sandbox Code Playgroud)
但这返回 None。我希望做这样的事情:
from django.core.cache import cache
#relevant event happened
cache.delete('get_some_stuff')
Run Code Online (Sandbox Code Playgroud)
处理缓存的正确方法是什么?
我尝试过传递 uri 路径:
cache.get('/api/get_some_stuff/')
Run Code Online (Sandbox Code Playgroud)
我仍然没有得到回报。
>>> cache.has_key('/api/get_some_stuff/')
False
>>> cache.has_key('/api/get_some_stuff')
False
>>> cache.has_key('get_some_stuff')
False
Run Code Online (Sandbox Code Playgroud)
我已经查看了建议的答案,它根本没有解决根本问题。它看起来并不像传递 uri 路由路径作为密钥那么简单,因为密钥在 django 中有些抽象。
现在我运行的方式是我有一组用 pytest 编写的测试用例,如果它们失败了,我就会修复并返工。如果他们通过,我使用 pytest-cov 来获取覆盖率并手动决定覆盖率是否足够好。我想知道如果覆盖阈值低于 x 数量,pytest 是否有可能失败。
pytest --cov=myproject tests --cov-report=html
coverage report --fail-under=80
....
myproject/services/subnet.py 36 33 8%
myproject/severity.py 5 0 100%
--------------------------------------------------------------------------------------------------------------------
TOTAL 8843 8739 1%
....
Run Code Online (Sandbox Code Playgroud) 这是我当前的测试:
我的设置:
class CheckTestParentMocked:
@pytest.fixture(autouse=True)
def run_around_tests(self, mocker):
self.profile = 'myprofile'
self.region = 'eu-west-1'
mocked_boto = mocker.patch(self.boto_client_path) #mypackage.module.boto3
mocked_session = mocked_boto.Session()
self.mocked_client = mocked_session.client()
Run Code Online (Sandbox Code Playgroud)
我的实际估计:
def test_gets_non_authorizer_api(self):
def side_effect(*args, **kwargs):
if args or kwargs:
# these are resources
return [{
'items': [
{
'id': 'resource-id-foo',
'path': '/',
'resourceMethods': ['GET']
}
]
}]
else:
# these are apis
return [{'items': [
{
'id': 'foo',
'name': 'foo-name'
}
]
}]
self.paginator.paginate.side_effect = side_effect
self.mocked_client.get_method.return_value = {
'authorizationType': 'NONE'
}
assertion = { …Run Code Online (Sandbox Code Playgroud) 我正在使用此处的范围滑块:http://materializecss.com/forms.html
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.js"></script>
<form action="#">
<p class="range-field">
<input type="range" id="test5" min="0" max="100" />
</p>
</form>Run Code Online (Sandbox Code Playgroud)
我设法改变了当你点击滑块时弹出的"拇指"的颜色:
input[type=range]+.thumb{
background-color: #400090;
}
Run Code Online (Sandbox Code Playgroud)
通常我可以检查chrome上的元素并获取我必须更改的类以更改其颜色.由于某些原因,我无法弄清楚如何检查滑块中的"点"以找到我必须添加的类以更改其颜色.