I am trying to add variation to different aliases, without having to rewrite the entire command:
#bot.command(aliases=['test'])
async def example(ctx)
if alias=='test':
#do something first
else:
#run command
Possible Solutions:
The error is the naming of the statement. I Have tried using command.aliases and aliases
Any help would be appreciated.
This is available as ctx.invoked_with
The command name that triggered this invocation. Useful for finding out which alias called the command.
ctx.message.content.split(' ')[0].strip(ctx.prefix)
Is a pretty good way to get the invoked command, so you could do something like
#bot.command(aliases=['test'])
async def example(ctx):
command_ran = ctx.message.content.split(' ')[0].strip(ctx.prefix)
if command_ran == 'test':
#do something first
else:
#run command
Related
I am trying to place my snowflakes into git repository. Some of the part are environment specific, like
use schema analytics_dev ### I will have to change this while deploying to qa and stuff.
I was thinking if could replace these with variable like this
set env='dev'
use schema analytics+$env
But this an error "SQL compilation error: syntax error line 1 at position 20 unexpected '+'."
How do I achieve this functionality?
Here's a way, to append vars, and use as an identifier:
set env = 'dev';
set analytics_schema = 'analytics' || $env;
use schema identifier($analytics_schema);
A couple of options here:
set (min, max)=(40, 70);
select $min;
And this:
set var_artist_name ='Jackson Browne';
select getvariable('var_artist_name');
and more here:
https://docs.snowflake.com/en/sql-reference/session-variables.html
I have a folder with some files named like this:
MonteCarlo_LHE_50-150_Tune_v14-v1.txt
MonteCarlo_LHE_50-150_Tune_v14_ext1-v1.txt
I want to concatenate the contents of these files into a single file with the common base name like this:
MonteCarlo_LHE_50-150_Tune_v14.txt
I know this can be done with:
cat inputfiles > outputfiles
However, I know it's possible to do this with Rakefile. I want to use rake because I have large number of input files like the one named above and I want to automate it. Any help is appreciated.
I have a basic version but if anyone has a much refined version please post:
def get_sample_names(substring)
inputs = Dir.glob("inputs/test/*.txt").select {|x| x.include? substring}
inputs = inputs.map{|x| File.basename(x).sub(".txt", ".txt")}
inputs.push(substring+'.txt')
return inputs
end
samples = Hash[
"mc" => get_sample_names('MonteCarlo_LHE_50-150_Tune_v14'),
]
def concat_text_files(the_samples, numberofsamples)
i = 0
loop do
sh "cat inputs/test/#{the_samples[i]} inputs/test/#{the_samples[i+1]} > inputs/test/#{the_samples[i+2]}"
i += 3
if i == 3*numberofsamples
break
end
end
end
task :concatText => concat_text_files(samples['mc'], numberofsamples=1)
The drawback of this solution is we have to define all the expected sample names before we run the rake.
I want to execute certain step before executing my function. The step takes variable as an argument. I am not able to pass it in context.execute_steps.
eg.
call1 = "version"
call1_method = "get"
context.execute_steps('''When execute api{"method":call1_method, "call":call1}''')
however this does not work. I get error in argument parsing because variables are not in quotes. I don't see any such example in behave documentation. Any help would be really appreciated.
There's a bunch of stuff that could be going on. I found here that if you're using python 3 you need to make it unicode by including a u in front of '''. I also was a bit tripped up that you have to include when, then or given as part of execute step command (not just the name of the step), but your example seems to be doing that. I'm kind of confused by what the way you're passing variables but can tell you this how you use execute_steps and works in python 2 & 3 with behave 1.2.5.
#step('I set the Number to "{number:d}" exactly')
def step_impl(context, number):
context.number = 10
context.number = number
#step('I call another step')
def step_impl(context):
context.execute_steps(u'''when I set the Number to "5" exactly''')
print(context.number)
assert context.number == 10, 'This will fail'
Then calling:
Given I call another step
When some not mentioned step
Then some other not mentioned step
Would execute when I set the Number to "5" exactly as part of the when I call another step.
Hard to say for your exact example because I'm unfamiliar with the other step you're trying to execute but if you defined the previous step with something like:
#step('execute api "{method}" "{version}"')
def step_impl(context, method, version):
# do stuff with passed in method and version variables
you should the be able to use it like so in another step.
#step('I call another step')
def step_impl(context):
context.execute_steps(u'''When execute api "get" "version1"''')
If your problem is just passing information between steps. You could just use context to pass it between them.
#step('I do the first function')
def step_impl(context):
context.call1 = "version"
context.call1_method = "get"
#step('I call another step')
def step_impl(context):
print(%s and %s are available in this function % (context.call1, context.call1_method)
And then call the steps in a row
When I do the first function
And I call another step
...
I'm new in SPSS program but I've tried to search a solution to my problem. The idea is find a way to loop through some variable names (or I think so). I want to create the variables P216_XX, P217_XX, T211_XX and OCUPAC_XX, with other variables like some inputs (P216_13, P216_12, P216_11, P216_10, P217_13, P217_12, P217_11, P217_10, T211_13, T211_12, T211_11, T211_10, OCUPAC_13, OCUPAC_12, OCUPAC_11, OCUPAC_10 and IIIDDDEEE).
I'm following the next tedious instruction:
******TEDIOUS INSTRUCTION:
*****P216_XX.
IF (IIIDDDEEE=1) P216_XX=P216_13.
EXECUTE.
IF (IIIDDDEEE=2) P216_XX=P216_12.
EXECUTE.
IF (IIIDDDEEE=3) P216_XX=P216_11.
EXECUTE.
IF (IIIDDDEEE=4) P216_XX=P216_10.
EXECUTE.
*****P217_XX.
IF (IIIDDDEEE=1) P217_XX=P217_13.
EXECUTE.
IF (IIIDDDEEE=2) P217_XX=P217_12.
EXECUTE.
IF (IIIDDDEEE=3) P217_XX=P217_11.
EXECUTE.
IF (IIIDDDEEE=4) P217_XX=P217_10.
EXECUTE.
*****T211_XX.
IF (IIIDDDEEE=1) T211_XX=T211_13.
EXECUTE.
IF (IIIDDDEEE=2) T211_XX=T211_12.
EXECUTE.
IF (IIIDDDEEE=3) T211_XX=T211_11.
EXECUTE.
IF (IIIDDDEEE=4) T211_XX=T211_10.
EXECUTE.
*****OCUPAC_XX.
IF (IIIDDDEEE=1) OCUPAC_XX=OCUPAC_13.
EXECUTE.
IF (IIIDDDEEE=2) OCUPAC_XX=OCUPAC_12.
EXECUTE.
IF (IIIDDDEEE=3) OCUPAC_XX=OCUPAC_11.
EXECUTE.
IF (IIIDDDEEE=4) OCUPAC_XX=OCUPAC_10.
EXECUTE.
In stata, the form would reduce the previous syntax with something like that:
foreach x in P216 P217 T211 OCUPAC {
replace `x'_XX=`x'_13 if IIIDDDEEE==1
replace `x'_XX=`x'_12 if IIIDDDEEE==2
replace `x'_XX=`x'_11 if IIIDDDEEE==3
replace `x'_XX=`x'_10 if IIIDDDEEE==4
}
*
In SPSS, I proved with vector, but SPSS don't accept me root in the vector, only variables. I don't know how to continue and I haven't found something similar yet
Is possible found a solution with native SPSS language? (I forgot to comment that in my work, the "administrator" doesn't allow us to install other programs like Python). What would be a possible solution?
There are a quite a lot of ways you can simplify this code, look up:
DEFINE/ENDDEFINE, SPSS's macro language.
DO IF
DO REPEAT
You need to be familiar with each and know what your end goal is to assess which option is best for you.
I have a google-cloud-endpoints, in the docs, I did'nt find how to write a PATCH method.
My request:
curl -XPATCH localhost:8080/_ah/api/hellogreeting/1 -d '{"message": "Hi"}'
My method handler looks like this:
from models import Greeting
from messages import GreetingMessage
#endpoints.method(ID_RESOURCE, Greeting,`
path='hellogreeting/{id}', http_method='PATCH',
name='greetings.patch')
def greetings_patch(self, request):
request.message, request.username
greeting = Greeting.get_by_id(request.id)
greeting.message = request.message # It's ok, cuz message exists in request
greeting.username = request.username # request.username is None. Writing the IF conditions in each string(checking on empty), I think it not beatifully.
greeting.put()
return GreetingMessage(message=greeting.message, username=greeting.username)
So, now in Greeting.username field will be None. And it's wrong.
Writing the IF conditions in each string(checking on empty), I think it not beatifully.
So, what is the best way for model updating partially?
I do not think there is one in Cloud Endpoints, but you can code yours easily like the example below.
You will need to decide how you want your patch to behave, in particular when it comes to attributes that are objects : should you also apply the patch on the object attribute (in which case use recursion) or should you just replace the original object attribute with the new one like in my example.
def apply_patch(origin, patch):
for name in dir( patch ):
if not name.startswith( '__' ):
setattr(origin,name,getattr(patch,name))