2012. 1. 13.

python formating datetime


from datetime import datetime
dt = datetime.now()
print dt.strftime("%Y.%m.%d %H.%M.%S")

#  output #
2012.01.13 00.03.01

2012. 1. 8.

python decode string.

json.loads(data)  #when you meet some charset errors

json.loads(data.decode("utf-8"))

2011. 12. 14.

insert file list into sqlite-db table by python


~                                                                                                        import os,sqlite3

con = sqlite3.connect("sqlite_test.db")
cur = con.cursor()

flist = os.listdir("/Users/path/")
for ff in flist:
        f = (ff,)
        cur.execute('insert into tbl_local (vcpath) values(?)' , f )  # watch out, question-mark.  there is no quotation mark
con.commit()
con.close()

2011. 11. 2.

VS error PRJ0050 and RegSetKeyValue

I met the visual studio error :prj0050 suddenly.  ( regist DLL error )
I didn't change any compile option or link.
I checked source codes.  I found  the reason.     I used the function  'RegSetKeyValue'.


Read MSDN-explains  more detail.(attention to remark section)
  http://msdn.microsoft.com/en-us/library/windows/desktop/ms724921(v=vs.85).aspx

2011. 11. 1.

InternetSetOption TIMEOUT option

I found  InternetSetoption with 'CONNECT_TIMEOUT' flag.
In my case.  when I used timeout option , I got a error code which is 'only query option'
Googling shows answer. It is that using thread.
But  I resolve problem by using 'CONTROL_RECEIVE_TIMEOUT' option .  because my case is that server response is too slow not connect -error-problem.

If you want to set option 'connect-timeout'  you must use thread-trick.

MSDN : http://support.microsoft.com/kb/224318

In my case :
 
DWORD dTimeout = 3000; // milisec.   
BOOL res = InternetSetOption(m_hInternet, INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT, (void*) &dTimeout, sizeof(dTimeout));
// Check res value. If your function call is success or not.