Monday, September 28, 2015
python: multicast echo server
python: multicast echo server
code:
#!/usr/bin/python
##
# Author: Ali Okan Yuksel
# E-mail: okan.yuksel[at]vizyonarge.com
##
import socket
import struct
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', 1111))
mreq = struct.pack("=4sl", socket.inet_aton("226.2.14.8"), socket.INADDR_ANY)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
while True:
line=sock.recv(10240)
print line
print "--"
Wednesday, September 16, 2015
python traceback module usage
In Python 2.x:
import traceback
try:
raise TypeError("Oups!")
except Exception, err:
try:
raise TypeError("Again !?!")
except:
pass
traceback.print_exc()
Python 3.x :
import traceback
try:
raise TypeError("Oups!")
except Exception as err:
try:
raise TypeError("Again !?!")
except:
pass
traceback.print_tb(err.__traceback__)
Thursday, September 3, 2015
how to import csv file to sqlite3 database with custom a separator char on bash shell
how to import csv file to sqlite3 database with custom separator on bash shell:
echo -e '.separator ";"\n.import x datatmp' | sqlite3 /usr/local/app/graphs/data/data.db
echo -e '.separator ";"\n.import x datatmp' | sqlite3 /usr/local/app/graphs/data/data.db
Subscribe to:
Posts (Atom)