| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Comments:
<0> is there a way of iterating list from middle of it without slicing? <1> Can I convert this to a unix timestamp? <1> I used to use date_default_timezone_set('US/Eastern') in PHP, together with strtotime(). Is tehre any similar to that in python? <0> as c/c++ pointer would do without creating a new list? <2> eugenekim15, you can iterate over the indices, xrange(middle_i, list_len), for example <3> kibab, true <4> eugenekim15: you can use itertools.islice <3> I'll do that <0> TFK: ChrisLong, thanks, i'll look into those 2 <2> the islice solution sounds better <0> ok thanks <0> what's the difference between range(n) and xrange(n)? <5> eugenekim15: memory usage <6> i have a python script, which imports a module, which imports another module, which then imports the first module again. python dosen't seem to like that, is it expected behaviour? <0> koollman: effect is just the same? <5> eugenekim15: usually, yes ... there is some strange case where it is not, but ...
<2> koollman, what case is that? <7> eugenekim15: not quite... the second is usally an iterable eg. (for x in xrange())... <2> Both are iterable o_O <5> TFK: in a code waiting for a list, or using indexes <8> eugenekim15, one returns a list, the other returns a generator <7> TFK: right... right I meant is usually only used as an iterable/generator. <2> koollman, oh. Then it's not strange :-) <3> cursor.execute("INSERT INTO %s VALUES('',%s,%s,%s,%s);", (table,informations[0],informations[1],informations[2],informations[3])) < wow, that sends an error :) <3> that technique you taught me may be good, but it's harder to use :p <9> not quite a generator, as I understand it: xrange(2,100,2)[10] #=> 22 -- it's a magic 'xrange' object <8> roryy, you're right. I just noticed that <8> Jojosan, you don't have quotes around your values <3> heh, yep, maybe that <3> however, MySQL returns an error with the value <3> s <3> will try it <10> How can I make sure that a new thread isn't started before the old one has finished? I just need to run 1 thread at a time to execute a scheduler while the main program is running. <11> how sure are you that you want threads? <11> more often than not, you dont. they are dangerous and uncontrollable. <12> polpak: He shouldn't. <10> ironfroggy: I need one thread because the main program would just hang while waiting for the schedule to be finished. <12> Jojosan: the problem is that the placeholders can only be used for data, not table names <12> Jojosan: so you need something like cursor.execute("insert into %s values ('', %%s, %%s, %%s, %%s)" % tableName, informations) <11> zenit: what are these other threads doing? <7> Jojosan: there should be a paramstyle attribute that tells you how you need to escape your values see http://www.python.org/dev/peps/pep-0249/ <0> umm, islice example on library is quite hard to understand, can someone help me with basic usage? something like m = somewhereInMid for i in lst[m:]: p*** ? <10> ironfroggy: actually nothing, I just needed the scheduler to run on it's own so the program would accept input from a user. Then when user creates a new schedule, I want the old thread to exit. <10> ironfroggy: right now I'm just deleting the queue in the thread, and it's stopped but still exists. <8> Erwin, ah. yeah, I see now. <11> 'for i in lst[m:]' would iterate the elements in lst starting at index m and continuing to the end. <11> zenit: so if its doing nothing, why is it even there? is it just waiting to trigger something (is that what you mean by a scheduler?) <7> Jojosan: for my version of MySQLdb... paramstyle == 'format', which is 'ANSI C printf format codes' <0> ironfroggy: yes , but i don't want to create new list everytime doing lst[m:] <4> eugenekim15: for i in islice(lst, m, None): should do it <0> cool <0> thanks <10> ironfroggy: hmm.. not sure if you understand me. The thread is running a loop, and executing a program on the right time. <10> ironfroggy: without a thread, the main program would be just busy waiting for the loop to finish. <11> zenit: why dont you do that in the main thread instead, in your event loop? <3> kibab, okies. I ***ume I have a recent one <10> ironfroggy: this is not a event, just a while-loop <11> while True: newInput = getNewUserInput(); checkTimeAndExecute(); <7> Jojosan: import MySQLdb; print MySQLdb.paramstyle <10> hmm.. <11> zenit: an even loop usually is in a while loop. <3> heh : <3> here is the found error : <3> _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''collection' VALUES('','','XiaoXiao',' ','Chinese')' at line 1" <3> But I can't see any syntax error <3> or maybe the 'collection' surrounded by quotes but that should not be a problem <7> Jojosan: put the rest of your query on pastebin or something? <3> kibab, I can write it, it's simple <13> '','' looks suspicious to me <3> well <3> that's two duets of simple quotes <8> Jojosan, as Erwin said you need to change the call to not put tablename in the set of placeholders <3> polpak, I see <3> did not get that <3> (still naab) <13> Jojosan ok, I see
<3> oh <3> %%s <11> naab? <3> yep <3> like noob <11> so noob you dont even know how to spell noob yet. wow. <10> ironfroggy: heh, maybe that's the simplest solution. I guess this could probably work even with several events. <11> zenit: you should definately avoid threads. they lead to trouble. <10> ironfroggy: I noticed. But I guess that a thread that's finished and stopped, should be removed after some time? <13> threads are fine in many cases. No trouble at all. <11> zenit: you cant be sure of that. nor can you be sure that you've successfully killed a thread, if you need to. <10> ironfroggy: so I might risk a thousand of threads? <11> who knows. but thats the point, you just cant be certain. <10> ok <14> Jojosan: There are much easier ways to do what you're trying to do <10> ironfroggy: thanks for your answers, they sched some light on a couple of things. <14> Jojosan: What is the scope of your need to interact with the database? Are you using it for complex queries, or just to store and retrieve data? <3> emlprime, store and retrieve datas <3> is the main activity of that python programm <3> (it's a music collection scanner) <3> emlprime, what is the easier way ? <14> Jojosan: You might try SQLObject <14> Jojosan: mysqldb is for when you want to be able to run raw queries <14> Jojosan: SQLObject is much more pythonic for persisting object data <14> Jojosan: and it's a little more database agnostic, so you can choose to use sqlite, postgresql, mysql, etc <14> Jojosan: without changing your code <14> Jojosan: http://sqlobject.org/index.html <3> okay <3> I'll look at that <14> Jojosan: this is, of course, ***uming you have permissions to install sqlobject <14> Jojosan: if not I can also help you get your SQL sorted out <3> (root) <14> Jojosan: word <15> emlprime: nibble <3> let's read the documentation <14> benji: I'm unfamiliar with nibble...is this some hamster-like greeting? <15> pretty close <3> but, anyway, that's not the only problem <3> argh <3> I hate these little problems <0> hmm, using islice is slower, how could it be? <3> Python is cool but there are hard things <14> Jojosan: ok, if you're going to do raw SQL <14> Jojosan: the best method I've found is to use python's string templating and dictionaries <3> mmm, I still need to learn a lot :) <14> Jojosan: _query_template = 'INSERT INTO %(tablename)s SET field1="%(field1)s, field2="%(field2)s"' <0> how could using islice rather be slower than using slicing? something like for i in islice(lst,start,end): rather than for i in lst[start:end] <3> heh <14> and then you can run the insert with db.execute( _query_template % _value_dictionary ) <3> seems that somehow I got it working <3> an ugly way but it works <3> (correctly <3> ) <3> hope it will work for curly characters too <14> Jojosan: well why not do it a non-ugly way? <3> emlprime, that's not _that ugly <7> emlprime: but you would have to be very careful that nothing in your "parameters" needs to be escaped.... <14> not really <13> yes really <15> emlprime, if you get any of the substitution values from the user, using string subst is a *very* bad idea <3> it's cursor.execute("INSERT INTO " + table + " VALUES(%s,%s,%s,%s)",(v1,v2,v3,v4)) <14> kibab: I always have a clean method that I p*** values through first <13> and that nothing in your parameters should *not* be quoted, like NULL <14> Zalamander: Sure, there are about 6 cases that I usually catch <0> i guess creating iterator is slower than copying list when list is simple? <14> Zalamander: I p*** the values through my cleaning method and it knows about functions, Non -> null, quote escaping <13> emlprime well, the alternative that Jojosan demonstrated does all the handling itself. <4> eugenekim15: i don't know, but maybe your list is not big enough. islice has some overhead <13> emlprime automatically converting the None object to "NULL", etc. <16> i love python <4> eugenekim15: yes, ure right <16> i've done an incredible amount of work in like 12 man-hours <16> i've completed about half of a middleware web suite
Return to
#python or Go to some related
logs:
#sdl #mysql php5-cli libreadline4 is not installable vsinit curl building for wirelesswan TDK_KNIGHT #perl Gentoo make.conf sempron 2800+ #gentoo gentoo packages-cd download
|
|