shell

sed and rev shell command into Python script

sed and rev shell command into Python script Question: There is a shell command, I am trying to convert the logic into python. But I don’t know what to do, I need some help with that. shell command is this : cd ../../../tests/src/main/test ls find . -name ‘*.vrlp’ | while read FILENAME do TEST_CASE=`echo $FILENAME …

Total answers: 1

Shell find logic into Python script

Shell find logic into Python script Question: cd db/test/vs ls find . -name ‘*.vrlp’ | while read FILENAME do TEST_CASE=`echo $FILENAME | sed s/"./"//g | sed s/".vrlp"//g | rev | cut -f1 -d"/" | rev` CLASS=`echo $FILENAME | sed s/"./"//g | sed s/"/$TEST_CASE"//g | sed s/".vrlp"//g` done There are a lot of class files (FILENAME) …

Total answers: 1

sed shell command into Python script

sed shell command into Python script Question: There is a shell command, I am trying to convert the logic into python. But I don’t know what to do, I need some help with that. shell command is this : cd ../../../tests/src/main/java ls grep -R "@Test" -A 1 | grep void | while read LINE do …

Total answers: 1

Exception Handling with subprocess.run in Python

Exception Handling with subprocess.run in Python Question: I am trying to create a function that can run any shell command and return the stdout of that command, without worrying about any exceptions that could be thrown. When testing the code written below with incorrect commands like xyz testing, I get a FileNotFoundError rather that the …

Total answers: 1

Translate multi-command pipeline bash to python

Translate multi-command pipeline bash to python Question: This is what I have in my bash script: example=$(echo $var | cut -c 40- | sed "/[a-zA-Z0-9]$/!d"). I am trying to translate it to python. In Python, echo $var | cut -c 40- would give print(var[40]). And I know that [a-zA-Z0-9] means any character in the range …

Total answers: 1

Translating Bash to Python

Translating Bash function call to Python Question: I am trying to translate this from Bash to Python: password=$(func_name "${configFile}" "<password" "2") func_name and configFile have been defined earlier in the script. func_name is a function and configFile is a working directory leading to an XML file. But I don’t know what to do with func_name …

Total answers: 1

Trouble understanding Bash and translating to Python

Trouble understanding Bash and translating to Python Question: I am trying to translate this from Bash to Python: export file="${directory}/scrutation_$(date "+%Y%m%d_%H%M%S").log" I know that export sets an environment variable, and that (date "+%Y%m%d_%H%M%S") is strftime("%d/%m/%Y, %H:%M:%S") in Python. This is what I have tried: import os os.environ[file]= f"{directory}/scrutation[strftime("%d/%m/%Y, %H:%M:%S")].log" Is this correct? Asked By: answer007 …

Total answers: 1

Jupyter Notebook "!" command not using Virtual Environment

Jupyter Notebook "!" command not using Virtual Environment Question: As we all know we can use !<command> to ensure the cell runs a terminal command. However if we usepip install lxml it installs lxml in the root python kernel and not the kernel environment that we mention in Jupyter. With !command in jupyter notebook, any …

Total answers: 2

Run node.js in interactive mode in terminal like "python -i …"?

Run node.js in interactive mode in terminal like "python -i …"? Question: Dumb question alert: I know that it is possible to run node.js in interactive mode like "python -i foo.py" where it runs the code in foo.py but then leaves you at the prompt ">>>" to interact, but how do I do it in …

Total answers: 1

Is it possible to loop through a JSON file using shell to call to an API?

Is it possible to loop through a JSON file using shell to call to an API? Question: Wondering if it is possible to take a json file such as: [ { "firstName": "John", "lastName": "Doe", "dob": "1900-01-01", "zipCode": "12345", "subscriberId": "123456789", "policyNumber": "12345" }, { "firstName": "Jane", "lastName": "Doe", "dob": "1900-01-01", "zipCode": "54321", "subscriberId": "987654321", …

Total answers: 2