conditional-statements

Assignment Condition in Python While Loop

时光总嘲笑我的痴心妄想 提交于 2019-11-26 16:06:13
问题 In C, one can do while( (i=a) != b ) { } but in Python, it appears, one cannot. while (i = sys.stdin.read(1)) != "\n": generates while (i = sys.stdin.read(1)) != "\n": ^ SyntaxError: invalid syntax (the ^ should be on the = ) Is there a workaround? 回答1: Use break: while True: i = sys.stdin.read(1) if i == "\n": break # etc... 回答2: You can accomplish this using the built-in function iter() using the two-argument call method: import functools for i in iter(fuctools.partial(sys.stdin.read, 1), '

Wix Installer : Setting component condition property when doing a MSIEXEC admin install at command line

微笑、不失礼 提交于 2019-11-26 15:33:48
We have three types/flavours of our product, but only one MSI written in WiX. When we build the installer we pass in the flavour via a defined constant: Call MSBUILD.bat ..\MSIs\CoreProduct\OurProduct.sln /p:DefineConstants="FLAVOUR=%_Flavour%" and the constant is setup in Visual Studio, under Build -> Define preprocessor variables as FLAVOUR=50. The build process, passes in values 50, 200 or LITE as the flavour. In the WiX code we have loads of conditions on our components that tell it which file to install based on the flavour; eg <Component Id="cmp7F45920B1AA100729BAE37FC846B3FC5" Guid="*">

How do I use NSConditionLock? Or NSCondition

放肆的年华 提交于 2019-11-26 15:19:48
问题 I am try to make one function wait for another, and I would like to use NSCondionLock in order to accomplish this. I am not asking for help, but really hoping someone could show me a decent tutorial or example to explain NSConditionLock, or possibly suggest a better method. 回答1: EDIT: as @Bonshington commented, this answer refers to NSCondition (as opposed to NSConditionLock ): - (void) method1 { [myCondition lock]; while (!someCheckIsTrue) [myCondition wait]; // Do something. [myCondition

Replace all elements of Python NumPy Array that are greater than some value

可紊 提交于 2019-11-26 14:08:11
I have a 2D NumPy array and would like to replace all values in it greater than or equal to a threshold T with 255.0. To my knowledge, the most fundamental way would be: shape = arr.shape result = np.zeros(shape) for x in range(0, shape[0]): for y in range(0, shape[1]): if arr[x, y] >= T: result[x, y] = 255 What is the most concise and pythonic way to do this? Is there a faster (possibly less concise and/or less pythonic) way to do this? This will be part of a window/level adjustment subroutine for MRI scans of the human head. The 2D numpy array is the image pixel data. mdml I think both the

Triggering jquery with css media queries

夙愿已清 提交于 2019-11-26 12:28:10
问题 I am using css media queries on my project to create a site that will work with any sized screen. I am looking to trigger difference jquery functions just like I would with css. For example, If the browser size is between 1000px and 1300px, I would like to call the following function: $(\'#mycarousel\').jcarousel({ vertical: true, scroll: 1, auto: 2, wrap: \'circular\' }); BUT when the browser size is below 1000px, the js would stop its processing. So on and so forth. I\'m not sure if this is

Replacing values from a column using a condition in R

杀马特。学长 韩版系。学妹 提交于 2019-11-26 12:10:52
问题 I have a very basic R question but I am having a hard time trying to get the right answer. I have a data frame that looks like this: ind<-rep(1:4,each=24) hour<-rep(seq(0,23,by=1),4) depth<-runif(length(ind),1,50) df<-data.frame(cbind(species,ind,hour,depth)) df$depth<-as.numeric(df$depth) What I would like it to select AND replace all the rows where depth < 10 (for example) with zero, but I want to keep all the information associated to those rows and the original dimensions of the data

Can I use conditional statements with EJS templates (in JMVC)?

大憨熊 提交于 2019-11-26 11:57:18
问题 and if yes, what is the syntax? My goal is to prepend an \'s\' to the word \'comment\' when there is more than one. in an jQuery.ejs template in a JMVC app. The following breaks. I can\'t find any docs for conditionals... <%=commentsNumber%> comment<% if (commentsNumber > 1) { %> s <% } %> 回答1: For others that stumble on this, you can also use ejs params/props in conditional statements: recipes.js File: app.get("/recipes", function(req, res) { res.render("recipes.ejs", { recipes: recipes });

Javascript recursion from Eloquent Javascript

ぐ巨炮叔叔 提交于 2019-11-26 11:37:44
问题 So this is from the Eloquent Javascript . I am trying to figure out how this code is actually stepped through. So we are trying to find a way to reach the target number by adding either 5 or multiplying by 3, and we start from the number 1. So, essentially, we are trying to find a sequence of such additions and multiplications that produce the target number? For example, the number 13 could be reached by first multiplying by 3 and then adding 5 twice, whereas the number 15 cannot be reached

Detecting Vowels vs Consonants In Python [duplicate]

我的未来我决定 提交于 2019-11-26 11:29:34
问题 This question already has answers here : How to test multiple variables against a value? (24 answers) Why does `a == b or c or d` always evaluate to True? (2 answers) Closed 6 years ago . What silly mistake am I making here that is preventing me from determining that the first letter of user input is a consonant? No matter what I enter, it allows evaluates that the first letter is a vowel. original = raw_input(\'Enter a word:\') word = original.lower() first = word[0] if len(original) > 0 and

Replace negative values by zero

半城伤御伤魂 提交于 2019-11-26 11:08:40
问题 We want to set all values in an array zero that are negative. I tried out a a lot of stuff but did not yet achieve a working solution. I thought about a for loop with condition, however this seems not to work. #pred_precipitation is our array pred_precipitation <-rnorm(25,2,4) for (i in nrow(pred_precipitation)) { if (pred_precipitation[i]<0) {pred_precipitation[i] = 0} else{pred_precipitation[i] = pred_precipitation[i]} } 回答1: Thanks for the reproducible example. This is pretty basic R stuff