bar

python assign values to list elements in loop

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is this a valid python behavior? I would think that the end result should be [0,0,0] and the id() function should return identical values each iteration. How to make it pythonic, and not use enumerate or range(len(bar))? bar = [1,2,3] print bar for foo in bar: print id (foo) foo=0 print id(foo) print bar output: [1, 2, 3] 5169664 5169676 5169652 5169676 5169640 5169676 [1, 2, 3] 回答1: First of all, you cannot reassign a loop variable―well, you can, but that won’t change the list you are iterating over. So setting foo = 0 will not change the

Why is a C++ bool var true by default?

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: bool "bar" is by default true, but it should be false, it can not be initiliazied in the constructor. is there a way to init it as false without making it static? Simplified version of the code: foo.h class Foo{ public: void Foo(); private: bool bar; } foo.c Foo::Foo() { if(bar) { doSomethink(); } } 回答1: In fact, by default it's not initialized at all. The value you see is simply some trash values in the memory that have been used for allocation. If you want to set a default value, you'll have to ask for it in the constructor : class Foo{

Hide NSWindow title bar

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to hide the titlebar in an NSWindow? I don't want to have to completely write a new custom window. I can't use NSBorderlessWindowMask because I have a bottom bar on my window, and using NSBorderlessWindowMask makes that disappear. I also tried using setContentBorderThickness:forEdge: with NSMaxYEdge and setting it to 0, that didn't work either. Any help is appreciated 回答1: [yourWindow setStyleMask:NSBorderlessWindowMask]; 回答2: Starting from OS X 10.11, you can hide title bar. window1.titlebarAppearsTransparent = true window1

Why can I not use $this as a lexical variable in PHP 5.5.4?

匿名 (未验证) 提交于 2019-12-03 01:11:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: $ php --version PHP 5.5.4 (cli) (built: Sep 19 2013 17:10:06) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies The following code (similar to example at https://bugs.php.net/bug.php?id=49543 ): class Foo { public function bar() { return function() use ($this) { echo "in closure\n"; }; } } fails with: PHP Fatal error: Cannot use $this as lexical variable Yet according to the PHP docs and a comment on that bug report from Rasmus Lerdorf, using $this in anonymous functions was added as of PHP 5

Pandas groupby and qcut

匿名 (未验证) 提交于 2019-12-03 01:11:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to structure Pandas groupby and qcut commands to return one column that has nested tiles? Specifically, suppose I have 2 groups of data and I want qcut applied to each group and then return the output to one column. This would be similar to MS SQL Server's ntile() command that allows Partition by(). A B C 0 foo 0.1 1 1 foo 0.5 2 2 foo 1.0 3 3 bar 0.1 1 4 bar 0.5 2 5 bar 1.0 3 In the dataframe above I would like to apply the qcut function to B while partitioning on A to return C. 回答1: import pandas as pd df = pd.DataFrame({'A':

Pandas groupby and qcut

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to structure Pandas groupby and qcut commands to return one column that has nested tiles? Specifically, suppose I have 2 groups of data and I want qcut applied to each group and then return the output to one column. This would be similar to MS SQL Server's ntile() command that allows Partition by(). A B C 0 foo 0.1 1 1 foo 0.5 2 2 foo 1.0 3 3 bar 0.1 1 4 bar 0.5 2 5 bar 1.0 3 In the dataframe above I would like to apply the qcut function to B while partitioning on A to return C. 回答1: import pandas as pd df = pd.DataFrame({'A':

Cannot use string offset as an array in php

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to simulate this error with a sample php code but haven't been successful. Any help would be great. "Cannot use string offset as an array" 回答1: For PHP4 ...this reproduced the error: $foo = 'bar'; $foo[0] = 'bar'; For PHP5 ...this reproduced the error: $foo = 'bar'; if (is_array($foo['bar'])) echo 'bar-array'; if (is_array($foo['bar']['foo'])) echo 'bar-foo-array'; if (is_array($foo['bar']['foo']['bar'])) echo 'bar-foo-bar-array'; (From bugs.php.net actually) Edit, so why doesn't the error appear in the first if condition even

Gnuplot Histogram Cluster (Bar Chart) with One Line per Category

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Histogram Cluster / Bar Chart I'm trying to generate the following histogram cluster out of this data file with gnuplot , where each category is represented in a separate line per year in the data file: # datafile year category num_of_events 2011 "Category 1" 213 2011 "Category 2" 240 2011 "Category 3" 220 2012 "Category 1" 222 2012 "Category 2" 238 ... But I don't know how to do it with one line per category. I would be glad if anybody has got an idea how to do this with gnuplot. Stacked Histogram Cluster / Stacked Bar Chart Even better

Instagram search bar with selenium

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working on a program that can type something in the instagram search bar. Here is the code of the website: <input class="XTCLo x3qfX " placeholder="Rechercher" value="" type="text"> I have already seen some posts about that but they did not work with me. Here is my code: input_search = wait(browser, 10).until( EC.visibility_of_element_located( (By.XPATH, "//input[@placeholder='Rechercher']") )) action=ActionChains(browser) action.move_to_element(input_search) action.send_keys(search) action.click() action.perform() how can I correct

change action bar direction to right-to-left

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm creating an android app for a right-to-left specific language. And I'm using ActionBarSherlock (a compatible android action bar library). The thing I exactly want is how to change the direction of action bar to RTL even the user not sets the default Locale an RTL language. If anyone has an idea even for standard android Action Bar it's valuable and may help please share it. Thanks 回答1: From Android API Level 17+ it supports RTL natively. To force your entire layout to be RTL including the ActionBar do the following. Edit your