Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
In os x you can use repeat command to repeat a command! If you want to send multiple get request using cURL:
repeat 10 curl https://www.google.com

In Linux we can do the same using for loop:
for i in {1..12}; do echo 'test'; done

#osx #linux #repeat #for
An interesting scenario in Python

If you have list of numbers like below:

numbers= ["+98121434", "+9821322", "+986241234"]


Now let's say you want to check a partial number like 121434, or 98121434 or +98121434 to see if it is inside of the list. What
would you do?

It's clear that you cannot do something like:

# YOU CANNOT DO THIS!
if number in numbers:
pass


So to check all the list element and also check the partial number we can do as below:

if any(partial_number in s for s in numbers):
pass


We have explained any before enough. Check previous posts for any and all.


#python #any #for
Array and loop in bash script

To define an array you can use a structure like below, be careful that we don't use comma in between:

dbs=( 'test1' 'test2' 'test3' )


Now to loop over the array elements use for:

for your_db in ${dbs[@]}
do
echo $your_db
done

This is it!

#bash #scripting #for #loop #array
How to prepend a string to all file names in a directory in a bash script?

for f in *.py; do mv "$f" "old-$f"; done

The above one-line will loop over all files in current directory with .py extension and prepend old- into the files.

So for example a file with name main.py will be renamed to old-main.py

#python #bash #script #prepend #move #rename #for