Re: Running External Commands + Seeing when they are Finished
It works! Gasp! Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Writing to a certain line?
I was wondering if there was a way to take a txt file and, while keeping most of it, replace only one line. See, I'd have a file like: Tommy 555 Bob 62 Joe 529 And I'd want to set it to be: Tommy 555 Bob 66 Joe 529 Is there any easy way to do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing to a certain line?
bruno at modulix wrote: > Tommy B wrote: > > I was wondering if there was a way to take a txt file and, while > > keeping most of it, replace only one line. > > > This is a FAQ (while I don't know if it's in the FAQ !-), and is in no > way a Python problem. FWIW, this is also CS101... > > > You can't do this in place with a text file (would be possible with a > fixed-length binary format). > > The canonical way to do so - whatever the language, is to write the > modified version in a new file, then replace the old one. > > import os > old = open("/path/to/file.txt", "r") > new = open("/path/to/new.txt", "w") > for line in old: > if line.strip() == "Bob 62" > line = line.replace("62", "66") > new.write(line) > old.close() > new.close() > os.rename("/path/to/new.txt", "/path/to/file.txt") > > If you have to do this kind of operation frequently and don't care about > files being human-readable, you may be better using some lightweight > database system (berkeley, sqlite,...) or any other existing lib that'll > take care of gory details. > > Else - if you want/need to stick to human readable flat text files - at > least write a solid librairy handling this, so you can keep client code > free of technical cruft. > > HTH > -- > bruno desthuilliers > python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for > p in '[EMAIL PROTECTED]'.split('@')])" Umm... I tried using this method and it froze. Infiinite loop, I'm guessing. -- http://mail.python.org/mailman/listinfo/python-list
pysqlite error: Database locked?
I'm currently working on a casino script for an IRC bot. I was going to make a flat file database, but I decided to make it sqlite after some suggestions. I'm using pysqlite. http://pastebin.com/764315 < Source. The lines that have @@ (pastebin doesn't like me) in front of them are important. ERROR 2006-06-06T22:20:34 Uncaught exception in ['diceroll']. Traceback (most recent call last): File "G:\Python24\Lib\site-packages\supybot\callbacks.py", line 1170, in _call Command self.callCommand(command, irc, msg, *args, **kwargs) File "G:\Python24\Lib\site-packages\supybot\utils\python.py", line 62, in g f(self, *args, **kwargs) File "G:\Python24\Lib\site-packages\supybot\callbacks.py", line 1156, in callCommand method(irc, msg, *args, **kwargs) File "G:\Python24\Lib\site-packages\supybot\commands.py", line 906, in newf f(self, irc, msg, args, *state.args, **state.kwargs) File "G:\Python24\Scripts\plugins\Casino\plugin.py", line 160, in diceroll money_file_update(msg.nick, wager) File "G:\Python24\Scripts\plugins\Casino\plugin.py", line 43, in money_file_update cur2.execute('UPDATE players SET cash = ' + str(newcash) + ' WHERE name = \' ' + user + '\'') OperationalError: database is locked ERROR 2006-06-06T22:20:34 Exception id: 0x486de ' + user + '\'') OperationalError: database is locked ERROR 2006-06-06T22:20:34 Exception id: 0x486de That's the error. -- http://mail.python.org/mailman/listinfo/python-list
Running External Commands + Seeing when they are Finished
I'm currently working on a script that I will run when I leave my computer on at night. It runs external commands like Ad-Aware, Spybot, AVG, Avast, and the like. The problem is, I want to know how to make it so that one command starts only after the last one finishes. When I run them, they end up running all at once! Can someone please tell me if this is possible? Judging from what I've seen in Python's versitility, I bet it can... -- http://mail.python.org/mailman/listinfo/python-list
Re: Running External Commands + Seeing when they are Finished
The problem is with that (which is what I'm doing already) is that one app is in a window and one app is on the command line. Thus, you end up with both apps running at the same time. Are there any modules that have functions for checking when windows are opened or closed? -- http://mail.python.org/mailman/listinfo/python-list