Programming, Teknologi

Using argparse to pass arguments into python script

Artikel ini juga tersedia dalam terjemahan Bahasa indonesia dengan judul Memakai argparse untuk memberikan argumen pada skrip python.

While doing some QA tasks, I got a case which I need to add and delete domain names from hundreds of categorized text files time after time.

Since it was repetitive and cost me time to perform it, I decided to create python script for automating that case.

Inspired by simplicity of linux command: ls which has several arguments with distinct functionalities, I also want my python script to be able to run multiple functions.

To accommodate that, I need to separate the input arguments.

After doing internet research, I found argparse solving this issue. With argparse library, user can pass arguments into python script.

Let’s write this argparse script.

Continue reading

Programming, Teknologi

Memakai argparse untuk memberikan argumen pada skrip python

You can read Using argparse to pass arguments into python script if you prefer this article in english translation.

Beberapa waktu yang lalu aku berhadapan dengan kasus menambah dan menghapus nama domain dari ratusan kategori file teks.

Berpikir kasus ini bakalan datang berulang-ulang, aku ambil keputusan bikin skrip python untuk menghemat waktu.

Sempat terinspirasi dari perintah linux: ls yang punya beberapa argumen dengan fungsi unik. Harapanku bahasa python juga punya library untuk bisa menerima lebih dari 1 masukan argumen.

Setelah riset di internet, aku temuin argparse bisa selesaikan masalah argumen masukan ini. Untuk praktiknya, setiap fungsi bisa memiliki argumen masukan terpisah.

Berikut adalah contoh implementasinya.

Continue reading

Programming, Teknologi

Resolving chrome error / throwing exception on python selenium


while running a selenium script, always throwing exception like :

File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\", line 67, in __init__
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\", line 87, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\", line 141, in start_session
'desiredCapabilities': desired_capabilities,

even if I already used the correct chromedriver location:

browser = webdriver.Chrome("C:/Python27/chromedriver.exe")

the error still showed up.

Continue reading

Programming, Teknologi

Fixing PYCURL ERROR 6 – “Couldn’t resolve host ‘'” on yum update


Found this problem on Centos 6.4 x86_64 :
Could not retrieve mirrorlist error was 14: PYCURL ERROR 6 - "Couldn't resolve host ''" Error: Cannot find a valid baseurl for repo: base


And I tried to fix it by these steps:
1. edit network interface. For my case, I used eth0
vim /etc/sysconfig/network-scripts/ifcfg-eth0

2. update NM_CONTROLLED to no

Continue reading