Re: Python simple web development
What about Werkzeug? I like its simplicity (well, basically everything I need are WSGI request/response objects :) + some templating library). Petr 2009/6/25 Private Private : > Hi, > > I am looking for a python library which will allow me to do a simple > web development. I need to use > some forms (but nice looking :-) ), creating images based on input > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). > > Can you suggest anything ? -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python Way for module configuration?
Hi, 2009/6/28 kj : ... > What I'm interested in is the general problem of providing > configuration parameters to a module. > Some database/ORM libraries are configured via simple strings in the form "dialect://user:passw...@host/dbname[?key=value..]", for example "mysql://me:topsec...@localhost/test?encoding=utf8". Is this what you want to know? Petr -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with mysql db
Hi, use %s instead of %d in SQL statements, because (AFAIK) conversions (including SQL escaping) from Python values to SQL values are done before the % operator is called - that value is not a number by that point. I hope you understood it, sorry for my English :-) You can also check MySQLdb module source, it's pretty clear. PM 2009/6/29 golu : > here i have posted my code...plz tell why am i getting the error "int > argument required" on the hash marked line(see below) although i am > giving an int value > #the code > import os > import string > import MySQLdb > import stopcheck > conn = MySQLdb.connect(host='localhost',user='root',db='urdb') > > def file_extractor(dir_name): >url_count = 0 > >for file in os.listdir(dir_name): > if(file[-4:] == '.txt'): >file_path = os.path.join(dir_name,file) >curse = conn.cursor() >url_count += 1 >curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)", > (url_count,file_path)) #error >word_extractor(url_count,file_path) > def word_extractor(url_count,file): >fhandle = open(file) >line = fhandle.readline() >k=stopcheck.checker() >k.create() > >while line: > words = line.split() > cursor = conn.cursor() > for word1 in words: > if word1 not in string.punctuation: >if (k.check(word1) is 0) and (word1[0:4] != 'http') : > word_count+=1 > try: >cursor.execute("INSERT INTO word_table(id,word) > VALUES(%d,%s)" , (word_count,word1)) >cursor.execute("INSERT INTO wordmatch > (word_id,url_id) values(%d,%d)",(word_count,url_count)) > except MySQLdb.Error, e: > print "Error %d: %s" % (e.args[0], e.args[1]) > line=fhandle.readline() > > if __name__ == '__main__': >#url_count=0 >#word_count=0 > >dir = os.path.join('D://','acm') >file_extractor(dir) > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters for a C program in Linux.
Hi, this can be done using module "subprocess"; there is also function popen() in module "os" and module popen2, but they are deprecated since Python 2.6. PM 2009/6/30 venutaurus...@gmail.com : > Hi all, > I have to write an automted script which will test my c > program. That program when run will ask for the commands. For example: > > local-host# ./cli > Enter 1 for add > Enter 2 for sub > Enter 3 for mul > 1---Our option > Enter two numbers > 44 33 Our option > Result is 77 > > As shown in the above example it lists all the options and waits for > user input and once given, it does some operations and waits for some > more. This has to be automated. > > Can someone give suggestions how to do this in Python (Linux Platform > in particular). > > Thank you, > Venu. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters for a C program in Linux.
2009/6/30 venutaurus...@gmail.com : ... > Can you give some more explanation about how exactly this can be > done.. Popen object enables you to run any program in a newly-created child process, write to its standard input and read from its standard and error outputs. There is an example how your test program could look like: import subprocess p = subprocess.Popen("./cli", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) result, errs = p.communicate("1\n44 33\n") assert not errs assert result.splitlines()[-1] == "Result is 77" Popen objects have also attributes stdin, stdout and stderr, you can use them if you do not want to use communicate(). Be aware that you if you call stdout.read(), it reads everything and blocks until EOF occurrs (usually until the popen-ed program quits). You can also use readline(), but this can also block until the subprocess writes any line. In cases where this could be a problem (i think this automated test programs are not that cases) polling, nonblocking I/O or threads can be used. I have pasted complete example (with a script simulating your "cli" program) here: http://paste.pocoo.org/show/125944/ PM -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb and ordering of column names in list returned by keys() w/ a DictCursor
2009/7/2 Tim Chase : >> Will this order at least be the same for that same query every time the >> script is executed? > > I wouldn't count on it. The order is only defined for the one iteration > (result of the keys() call). If the order matters, I'd suggest a > double-dispatch with a non-dict (regular/default) query result, something ... Dictionaries are usually designed to have the best performance when accessing certain key, so it is not expected that dictionary items will be in any particular order; this applies not only for Python. But (for Python dict) you can be sure that results of items(), keys(), values(), iteritems(), iterkeys(), and itervalues() will correspond if called with no intervening modifications to the dictionary. If such a functionality is needed, there is a collections.OrderedDict that was introduced in Python 3.1; there is also an implementation for Python 2.4 or later: http://code.activestate.com/recipes/576693/ (this links is from "What’s New In Python 3.1") PM -- http://mail.python.org/mailman/listinfo/python-list