我有以下场景:
Load Page A
Check if Element_A exists in Page A
Click Button_A
On Clicking Button_A, Page B is loaded
Check if Element_B exists in Page B and Click Button_B
and so on...
Run Code Online (Sandbox Code Playgroud)
我写了这样的代码:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class MyWebsiteTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_element_a_in_page_a(self):
driver = self.driver
driver.get(PAGE_A)
element = driver.get_element_by_id("element_a")
self.assertIsNotNone(element,"Oops.")
def load_page_b_if_previous_function_is_true(self):
#WHAT DO I DO HERE?
#I Need to run this function given test_element_a_in_page_a succeeds.
def tearDown(self):
self.driver.close() …Run Code Online (Sandbox Code Playgroud) 我有一本csv通过大熊猫阅读的书read_csv,
data = pandas.read_csv(file)
现在一小部分是这样的,
data['interest']:
one.a
two.a
three.a
four.b
Run Code Online (Sandbox Code Playgroud)
等等...
我想创建一个新的pandas系列,比方说,
data['i']它只包含第一部分data['interest'],即
one
two
three
four
Run Code Online (Sandbox Code Playgroud)
现在我可以遍历整个事情split,但是我可以用地图做吗?
像 - data['i'] = map(split_and_get_first_part, data['interest'])?
我有一个像这样的json:
{
"a": {
"x": {
"y": {
"a": {},
"z": {},
"b": {}
}
},
"c": {},
"b": {
"c": {
"d": {}
}
},
"d": {},
...
}
}
Run Code Online (Sandbox Code Playgroud)
有没有快速的方法将其转换为flare.json格式?
像这样:
{
"name":"a",
"children":[
{
"name":"x",
"children":
{
"name":"y",
"children":[{"name":"a", "size":0},{"name":"z","size":0},{"name":"b","size":0}]
...
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我的表是这样的:
| A | B | ...
---------
| 1 | a | ...
---------
| 2 | |
---------
| 3 | |
---------
| 4 | b |
---------
Run Code Online (Sandbox Code Playgroud)
我希望这是我的输出:
| A | B | ...
---------
| a | | ...
---------
| 2 | |
---------
| 3 | |
---------
| b | |
---------
Run Code Online (Sandbox Code Playgroud)
所以我循环列B,只要有值,B那么我应该替换相应的值A
到目前为止,我尝试过这样的:
Sub LoopRange()
Dim rCell As Range
Dim rRng As Range
Set rRng1 = …Run Code Online (Sandbox Code Playgroud) 所以我有一个像这样的laaaaaaaarge文件:
Item|Cost1|Cost2
Pizza|50|25
Sugar|100|100
Spices|100|200
Pizza|100|25
Sugar|200|100
Pizza|50|100
Run Code Online (Sandbox Code Playgroud)
我想为特定项添加所有Cost1s和Cost2s并生成合并输出.
我写了一个python代码来做到这一点,
item_dict = {}
for line in file:
fields = line.split('|')
item = fields[0]
cost1 = fields[1]
cost2 = fields[2]
if item_dict.has_key(item):
item_dict[item][0] += int(cost1)
item_dict[item][1] += int(cost2)
else:
item_dict[item] = [int(cost1),int(cost2)]
for key, val in item_dict.items():
print key,"|".join(val)
Run Code Online (Sandbox Code Playgroud)
无论如何,在awk或使用任何其他魔法中非常有效和快速地执行此操作?
或者我可以让我的python更优雅,更快?
预期产出
Pizza|200|150
Sugar|300|200
Spices|100|200
Run Code Online (Sandbox Code Playgroud) 我有这样的代码:
count = 0
for line in lines:
#do something with line
#do something more with line
#finish doing that thing with line
count = count + 1
if count % 10000 == 0:
print count
Run Code Online (Sandbox Code Playgroud)
这是在python中维护count变量的正确方法吗?我可以让它看起来更好吗?
我有这样的excel表:
A | B
-----
0 | 2
0 | 3
0 | 4
0 | 5
0 | 6
0 | 7
1 | 8
1 | 9
1 | 10
1 | 11
1 | 12
2 | 13
2 | 14
...
Run Code Online (Sandbox Code Playgroud)
如何获取A中每个值最后一次出现的B的值?
输出是 -
C | D
0 | 7
1 | 12
2 | 14
Run Code Online (Sandbox Code Playgroud)
有这么简单的方法吗?谢谢!
我有一个映射器。
for line in sys.stdin:
#if line is from file1
#process it based on some_arbitrary_logic
#emit k,v
#if line is from file2
#process it based on another_arbitrary_logic
#emit k, v
Run Code Online (Sandbox Code Playgroud)
我需要通过 hadoop 流 API-input file1和另一个-input file2.
我如何实现这一目标?我怎么知道STDINhadoop流给我的哪一行属于哪个文件?
更新
File1
Fruit, Vendor, Cost
Oranges, FreshOrangesCompany, 50
Apples, FreshAppleCompany, 100
File2
Vendor, Location, NumberOfOffices
FreshAppleCompany, NewZealand, 45
FreshOrangeCompany, FijiIslands, 100
Run Code Online (Sandbox Code Playgroud)
我需要做的是打印出他们卖橙子的办公室数量。
Oranges 100.
所以这两个文件都需要到INPUT映射器。
这是最蟒蛇的做法 -
ys = []
for x in xs:
z = compute_something(x)
#z is an object of some class
ys.append(z.a_property_of_z)
return ys
Run Code Online (Sandbox Code Playgroud)
或者我可以在一些聪明的列表理解中处理上述内容吗?或函数式编程?还是其他一些蟒蛇魔法?
python ×6
excel ×2
excel-2010 ×2
excel-vba ×2
vba ×2
awk ×1
bash ×1
cloudera ×1
coding-style ×1
d3.js ×1
hadoop ×1
javascript ×1
json ×1
linux ×1
mapreduce ×1
pandas ×1
pep ×1
python-2.7 ×1
regex ×1
selenium ×1
unit-testing ×1
unix ×1