Run a python file with arguments in Colab - google-colaboratory

I am trying to run a python (test.py) file in Colab. The file needs inputting some parameters, e.g., "--epoch", "--class_file". What I did is:
!python test.py "--epoch" 100 "--class_file" class_file
#class_file is a path string
After argument parsing, the class_file is not interpreted as the intended path string, but instead a string like class file = "class_file". How did that happen?

Put the argument variable in a curly brackets {}: !python test.py "--epoch" 100 "--class_file" {class_file}.
Refer to a post Notebooks: Passing string variables as arguments to python script via command line(!), using quotes And $, eg -arg1 '$varible1'

Related

How to use KSH variable in string and Robotframework not to interpret it for a case variable

I tried to use Robot to do the following operation in KSH to remove the ".auto" postfix in a directory:
Write for file in .auto; do mv $file ${file%.}; done
The ${file%.} is for KSH variable however Robot always considered it as Robot variable and gave the error message: "Resolving variable '${file%.}' failed: Variable '${file}' not found."
Is there any way to tell Robot that the ${file%.*} is not for a Robot variable?
If a string has something the framework may interpret as inline variable usage - escape it, with the \ char.
In your case, put it in front of the ${:
Write for file in .auto; do mv $file \${file%.}; done

Can we pass a command line argument to property file reader in jmeter

I have a config.property file that contains all the property values to be used in jmeter, so i am using property file reader plugin to read the property file, here the problem is i don't want to hard code the path to config.properties file in property file reader so i want it to pass as command line argument but it is not working
command i am executing is
.\jmeter -JPROPERTY_FILE=<file_location> -n -t <path_to_jmx> -l <path_to_jtl> -j <path_to_log>
In the File Path of Property File Reader, replace:
${PROPERTY_FILE}
By using __P function:
${__P(PROPERTY_FILE)}
Your mistake is that you’re using Variable syntax for a property.
See:
http://jmeter.apache.org/usermanual/functions.html#__P
http://jmeter.apache.org/usermanual/functions.html#functions
You should be using __P() function like ${__P(PROPERTY_FILE)} or even __property() function like ${__property(PROPERTY_FILE,PROPERTY_FILE)}. The latter one automatically stores the retrieved value into a JMeter Variable so you won't have to additionally declare it under User Defined Variables of the Test Plan
Instead of using custom plugins I would suggest going for built-in JMeter functionality, there is -q command-line argument which allows loading and arbitrary .properties file so you will not have to install the plugin, care about order of Configuration Elements, etc.

Julia passing arguments, reading the command line

I am trying to prompt the user of my .jl file to enter user entered multiple destinations.
Basically I need the user to give an input & an output. I know in java you would use a scanner, or accept arguments when it is compiled in the command line. I am fine with either option. From what I have found looking through the Julia Documentation I think I could accomplish the first way of assigning a variable to the readline function.
(String)in = (String)Readline(STDIN)
From my understanding the variable 'in' should now contain a String of the user's input. I am encountering an error, in that when I compile my .jl code, because my command prompt does not stop to read user input, and just finishes reading the .jl code.
The first item to note in the code in your question is:
(String)in = (String)Readline(STDIN)
Julia 1.0.0 now uses stdin instead of STDIN.
Next, the (String) typecasting is not something you need or want to do in Julia.
Thus your code could read (though we get an error):
julia> in = readline(stdin)
This is a test.
ERROR: cannot assign variable Base.in from module Main
So variable in is in conflict with a Julia Base.in variable. Just use a another variable name.
julia> response = readline(stdin)
This is a test.
"This is a test"
This code is now working, but it has no prompt. Your answer provides an example input function with a prompt which you defined like this:
julia> function input(prompt::AbstractString="")
print(prompt)
return chomp(readline())
end
input (generic function with 2 methods)
The chomp function removes a single trailing \n newline character from the input string. Docs here.
Example use of the function here:
julia> input_file = input("Please enter input file name: ")
Please enter input file name: Data.txt
"Data.txt"
julia> output_file = input("Please enter output file name: ")
Please enter output file name: Output.txt
"Output.txt"
Command Line Args Method
As the docs point out, to just print out the arguments given to a script, you can do something like this:
println("Arguments passed to ", PROGRAM_FILE, ":")
for arg in ARGS
println(arg)
end
Here is an example of above code running on the Windows command line:
c:\OS_Prompt>julia PrintArgs.jl Data.txt Output1.txt Output2.txt Output3.txt
Arguments passed to PrintArgs.jl:
Data.txt
Output1.txt
Output2.txt
Output3.txt
You can also print out the script file name as shown, PrintArgs.jl.
After searching & testing I found one solution and decided to reply to it here. I had to declare my own function to be able to get the program to accept user input.
function input(prompt::AbstractString="")
print(prompt)
return chomp(readline())
end
I am not sure what the chomp function does, but I know it works for what I was asking. I am still curious if you can do something in Julia similar to java and C String args[], in which you pass extra information while you are telling your command to run. Something like the following.
Julia testFile.jl goHere.txt lookHere.txt

How to pass shell variable to pig param file

How we can pass shell variable to pig param file. As an example I have a shell variable defined as DB_NAME. i would like to define my pig parameter file as
p_db_nm=$DB_NAME
I tried like above which does not work and i did try like echo $DB_NAME does not work either.
I'm aware that i can pass this by using -param in command line but i have many variables which i would like to put it in param file but the values will be defined in shell script. I searched many topics in google and didn't have any luck!!!
My question is similar what was posted in http://grokbase.com/t/pig/user/09bdjeeftk/is-it-possible-to-use-an-env-variable-in-parameters-file but i see no workable solution is posted.
Can anyone help?
you can pass parameter file using –param_file option.
if Parameter File named "pig.cfg" defined like below,
p_db_nm=$DB_NAME
in the shell, pig command will be like this,
pig -param_file pig.cfg
and finally in your pig, you can use does variables named by KEY in the cfg file. (in this case, $p_db_nm)

Is it possible to pass the value of a parameter to an UDF constructor?

I've written a UDF which takes a constructor parameter.
I've successfully initialized and used it in grunt as
grunt> register mylib.jar
grunt> define Function com.company.pig.udf.MyFunction('param-value');
But I can't initialize it using a Pig parameter as in
grunt> define Decrypt com.company.pig.udf.MyFunction($secret);
or
grunt> define Decrypt com.company.pig.udf.MyFunction('$secret');
I tried to initialize $secret using both -param and -param_file options.
Are Pig parameters supported as UDF constructor arguments at all?
The function I'm loading is used to decrypt some data and the param-value contains special characters as "%$!" but no quotes. So I'm unsure whether I'm running into an value expansion issue or a parameter there is just not being expanded.
I'm setting the parameter value without quotes in a param file:
secret = My$ecr%t!
It is definitely possible to pass parameter values to UDFs. The problem seems to be the $ sign.
This should the correct syntax:
define Decrypt com.company.pig.udf.MyFunction('$secret');
In your parameter file put:
secret=My\$ecr%t!
The -dryrun option can be helpful for this it will create a file called <nameofpigfile>.pig.subsituted and not run the actual script.
pig -x local -dryrun -f mypigfile.pig -param_file myparameterfile
Also, you probably need pig >= 0.11
https://issues.apache.org/jira/browse/PIG-2931