Python编程_,无法理解此代码的作用

时间:2018-07-16 08:25:54

标签: python python-3.x

因此,我正在按示例阅读一本名为Tkinter的书。我对使用python编程相当陌生。因此,当我在本书中键入示例代码时,我注意到我身上有一个陌生的代码。

AndroidDriver<MobileElement> driver=null;
AppiumDriverLocalService service=null;

service = AppiumDriverLocalService.buildDefaultService();

DesiredCapabilities capabilities = new DesiredCapabilities();  
capabilities.setCapability("platormName", "Android");  
capabilities.setCapability("deviceName", "yourAppUdid");  
capabilities.setCapability("appPackage","YourAppPackage");  
capabilities.setCapability("appActivity","yourAppActivity"); 


(or IOS)
DesiredCapabilities capabilities = new DesiredCapabilities();
// Set ios deviceName desired capability. Set your device name.
capabilities.setCapability("deviceName", "My iPhone");
// Set BROWSER_NAME desired capability. It’s iOSin our case here.
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
// Set iOS VERSION desired capability. Set your mobile device’s OS version.
capabilities.setCapability(CapabilityType.VERSION, "11.2.6");
// Set iOS platformName desired capability. It’s Android in our case here.
capabilities.setCapability("noReset", false);
capabilities.setCapability("platformName", "iOS");
//capabilities.setCapability("platformVersion", "7.1.1");
// Set your application’s appPackage if you are using any other app.
capabilities.setCapability("xcodeSigningId", "iPhone Developer");
capabilities.setCapability("appActivity", "com.<redacted>.<redacted>.<redacted>");
// It will launch app in iOS device.
capabilities.setCapability("udid", "<redacted>");
capabilities.setCapability("xcodeOrgId", "<redacted>");
capabilities.setCapability("automationName", "XCUITest");
capabilities.setCapability("bundleId", "com.<redacted>.<redacted>");
System.out.println("capabilities Set.");

service.start();

driver = new AndroidDriver<MobileElement>(service, capabilities);

我了解代码的工作原理和运行方式,但是由于某些特定原因,每当我删除代码“ _”的这一部分时,我都会尝试输入此错误显示的文本。

colour_schemes = [{"bg": "lightgrey", "fg": "black"}, {"bg": "grey", "fg": "white"}]

_, task_style_choice = divmod(len(self.tasks), 2)

my_scheme_choice = colour_schemes[task_style_choice]

我正在使用python 3.6.3版本,我似乎找不到与我有关的任何问题,有人可以向我解释什么“ _”,这对我的代码有影响。

谢谢!

1 个答案:

答案 0 :(得分:6)

下划线是有效的变量名称,通常用于表示该值将不被使用。通过divmod变量将仅使用task_style_choice返回的货币对中的第二个值。

_, task_style_choice = divmod(len(self.tasks), 2)