conditional-statements

Idiomatic way to test if no positional params are given?

懵懂的女人 提交于 2019-12-01 20:46:17
问题 What is the most idiomatic way in Bash to test if no positional parameters are given? There are so many ways to check this, I wonder if there is one preferred way. Some ways are: ((! $# )) # check if $# is 'not true' (($# == 0)) # $# is 0 [[ ! $@ ]] # $@ is unset or null 回答1: For me, the classical way is: [[ $# -eq 0 ]] 回答2: If you want it to be an error to have no positional parameters: : ${@?no positional parameters} will print "no positional parameters" to standard error (and exit a non

Update Query based on condition

不问归期 提交于 2019-12-01 20:26:28
问题 I would like to do the following. Update a field based on the value of another field like update table set if(fielda=1){fieldb=2 fieldc=3}else{fieldd=2 fielde=3} I know this is not valid mysql but its the best way for me to describe the problem. 回答1: update table set b = case when a = 1 then 2 else b end, c = case when a = 1 then 3 else c end, d = case when a = 1 then d else 2 end, e = case when a = 1 then e else 3 end edit according to your comment try this: update table set datefield_a =

Using multiple NOT IN statements with Python

不羁岁月 提交于 2019-12-01 19:34:26
I need to URLs with three specific specific substrings out of a loop. The following code worked, but I am sure there's a more elegant way to do it: for node in soup.findAll('loc'): url = node.text.encode("utf-8") if "/store/" not in url and "/cell-phones/" not in url and "/accessories/" not in url: objlist.loc.append(url) else: continue Thank you! url = node.text.encode("utf-8") sub_strings = ['/store','/cell-phones/','accessories'] if not any(x in url for x in sub_strings): objlist.loc.append(url) else: continue From the docs : any returns True if any element of the iterable is true. If the

What does “string literal in condition” mean?

穿精又带淫゛_ 提交于 2019-12-01 18:12:07
Whenever I try to run the program, an error pops up saying "string literal in condition (on line 10)". What am I doing wrong? puts "Welcome to the best calculator there is. Would you like to (a) calculate the area of a geometric shape or (b) calculate the equation of a parabola? Please enter an 'a' or a 'b' to get started." response = gets.chomp if response == "a" or "A" puts "ok." elsif response == "b" or "B" puts "awesome." else puts "I'm sorry. I did not get that. Please try again." end You have to specify the full condition on both sides of the or . if response == "a" or response == "A"

boost named_condition is not waking up waiting process

梦想的初衷 提交于 2019-12-01 14:43:54
I have 2 processes (producer and consumer) sharing an int deque in shared memory, I have the producer process put 2 numbers in the deque and then it gets in a wait state losing its mutex lock. I then have the consumer process removing the numbers and printing them. It then does a notify on the condition which the producer is waiting on. The consumer then goes on its own wait on a second condition. After this case the producer does not wake up. I am using the same mutex between the processes. Please find all code below. Include file shared_memory.h: #ifndef SharedMemory_h #define SharedMemory_h

How to config Many-to-many with condition, in Sqlalchemy

删除回忆录丶 提交于 2019-12-01 12:40:34
I'm use sqlalchemy 0.6.4. I have 2 classes: Question and Tag, they are many-to-many. class Question(Base): __tablename__ = "questions" id = Column(Integer, primary_key=True) deleted = Column(Boolean) ... tags = relationship('Tag', secondary=r_questions_tags) class Tag(Base): __tablename__ = "tags" id = Column(BigInteger, primary_key=True) questions = relationship('Question', secondary=r_questions_tags) So, tag.questions will get all the questions belong to a tag. But now, since the Question has a deleted column, I hope to do like this: class Tag(Base): ... # get non-deleted questions questions

boost named_condition is not waking up waiting process

陌路散爱 提交于 2019-12-01 12:34:36
问题 I have 2 processes (producer and consumer) sharing an int deque in shared memory, I have the producer process put 2 numbers in the deque and then it gets in a wait state losing its mutex lock. I then have the consumer process removing the numbers and printing them. It then does a notify on the condition which the producer is waiting on. The consumer then goes on its own wait on a second condition. After this case the producer does not wake up. I am using the same mutex between the processes.

How to config Many-to-many with condition, in Sqlalchemy

匆匆过客 提交于 2019-12-01 11:54:37
问题 I'm use sqlalchemy 0.6.4. I have 2 classes: Question and Tag, they are many-to-many. class Question(Base): __tablename__ = "questions" id = Column(Integer, primary_key=True) deleted = Column(Boolean) ... tags = relationship('Tag', secondary=r_questions_tags) class Tag(Base): __tablename__ = "tags" id = Column(BigInteger, primary_key=True) questions = relationship('Question', secondary=r_questions_tags) So, tag.questions will get all the questions belong to a tag. But now, since the Question

How can I assign a boolean condition result to a scalar variable in perl?

浪子不回头ぞ 提交于 2019-12-01 08:15:03
I am doing the following, but it is not working properly: my $enabled = $hash && $hash->{'key'} && $hash->{'key'}->{'enabled'} && $hash->{'key'}->{'active'}; Is this an acceptable way to assign a boolean value to a scalar variable? My code is misbehaving in strange ways, as it is, and I believe it is because of this assignment. I have validated that the individual values exist for all of these keys and are set to a value. P.S. Sorry for being a noob! I googled for ~10 minutes and couldn't find the answer anywhere. The Perl boolean operators like && , || , and , or don't return a boolean value,

Excel - programm cells to change colour based on another cell

本秂侑毒 提交于 2019-12-01 07:11:11
I am trying to create a formula for Excel whereby a cell would change colour based on the text in the previous cell. So for example if cell B2 contains the letter X and then B3 is Y, I would like B3 to turn green. Equally, if B2 contains X and B3 contains W I would like B3 to turn red. Any ideas much appreciated! Select cell B3 and click the Conditional Formatting button in the ribbon and choose "New Rule". Select "Use a formula to determine which cells to format" Enter the formula: =IF(B2="X",IF(B3="Y", TRUE, FALSE),FALSE) , and choose to fill green when this is true Create another rule and