| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Comments:
<0> and "r+" for read/write mode <1> not a very big one <2> hmm <2> outfile? <2> do I need to define outfile? <3> outfile = open(....) <2> right, so.. same as fh? <3> well, you want a separate file to write to, probably <2> nah, I'm good :) <2> I'd prefer to write to the one I'm reading from <3> well then you'll have to open the file in "r+" mode... though i don't personally recommend that, you could potentially corrupt/lose the file that way <2> oh, right <4> Nev|Newbie: probably reading, writing to a temp file and then moving/renaming would be a better idea. <2> hmm <5> j0! <2> yeah
<2> >>> fh = open('C:\Program Files\World of Warcraft\Interface\AddOns\GetDKP\dkp_list.LUA', "r+") <2> >>> for line in fh.readlines(): <2> if not line.startswith("ENDDKPLIST"): <2> fh.write(line) <2> gave me a blank file :) <3> yes, reading and writing a file simultaneously needs to be handled with great care, no matter what programming language/environment you are using <2> yeah <3> nearly always what you want is to make a temp file <4> Nev|Newbie: yeah, trampling over your own feet, as it were <5> Nev|Newbie, Hmmm. This is probably straightforward. Make it three steps: <2> :) <5> fh = open(); lines = fh.readlines(); fh.seek( to the beginning ); for line in lines: .... <5> I think the seek() is important. <2> what does seek do? <5> Sets the file pointer. <6> seek moves the file pointer <2> ah <2> tbh, I do not know what a file pointer is. Either that, or I just can't remember atm :) <5> I don't know were it would be after a .readlines() . <5> It's a cursor that represents where data is beign read and written to. <2> oh right <5> Is this program ending right away? You might need to fh.close() if you need the file-on-disk to be available for something else in the course of this program. (Thus, explaining the emptyness.) <2> well, I'm not fully sure if python is capable of this, but my plan is to have 3 stages, and this is stage 2.. <2> first, start a bat that downloads the latest file from a server (got the bat done) <2> then, edit the file <2> and last, execute an application <5> Gotcha. Yes. Close the file explicitly. <3> you can do all that - you can even do it all from within python <3> you will need to close the file to ensure it gets flushed out to disk <2> yeah, the trouble is, I don't know the language awesomely well yet ;) <2> yeah <2> what exactly am I supposed to put in fh.seek( to the beginning )? <2> (instead of to the beginning..) <5> Skip the seek business. I would make a temp-file anyway. infile, outfile = file(), file(); for line in infile: if ..: out.write; ... os.rename("out", "in") <2> :O <5> Nev|Newbie, In general, http://python.org/doc/lib/ has all the answers. Read up on "file", the builtin type. <2> hehe, yeah, I guess I should.. hmm <7> Nev|Newbie: I recommend www.diveintopython.org for learning the language + some of the standard libs <5> #python is never a substitute for docs. We wrote them. We get angry when people don't read them. <2> you don't seem that angry :) <2> and yeah, I added both of those links to my favs <5> Later, all./ <2> later, thanks alot for your help :) <2> later guys, thanks again. I might be back, but once I've solved this, I'll read up on python properly :) <8> have fun :D <2> :D <9> is there anyway to protect a variable of a cl*** to be modified? <8> i'm not sure, although a convention is that you prefix any "private" variable with an underscore <8> it's generally understood that such variables should not be fiddled with outside the cl*** <10> hi <9> Greatred, but I know there's a function (like __blah__) that does what I want <9> I just don't remember ;/ <8> oh... <10> does any1 know how to disable ctrl-c? i an using curses in python.? <8> i don't suppose you mean properties do you, lucasd? <9> Greatred, no <8> in that case, no idea <8> __setattr__?
<8> if that's right... <9> Greatred, oh yes... that's it.. thanks a lot ;D <8> i hope that works. i've never played with it, and it might be the wrong name <10> does any1 know how to disable ctrl-c? i an using curses in python.? <8> ah yes... __setattr__( self, name, value) <8> mammuth, no, but you might try catching the exception that it raises... or maybe change the signal handler for SIGINT <3> mammuth: wrap your code in a try: clause and catch KeybaordInterrupt <8> i'm unsure what the normal method is <10> aha, ok.. <11> Greatred, <8> kbrooks <11> KeyboardInterrupt is raised in te default sigint handler <10> NameError: name 'KeybaordInterrupt' is not defined <10> hmm <10> i sess <3> spell it right <10> yes <10> ;-) <8> i wonder if programming is difficult for people with dyslexia <8> when it comes down to symbol names etc <10> what ISNT possible with python???!!! <8> doing the dishes <10> true <8> getting girls <10> nearly. <3> actually, i have robots that run python :P they don't do the dishes, but maybe i can work on that ;) <8> sweet :) <10> he <3> getting girls works better with perl, unfortunately <10> i C <8> i think you mean "pearls" <3> nah: http://perlmonks.org/?node_id=384100 <10> hmm, i can still hit ctrl-z... <10> must be shell prefs <8> mammuth, you might need to catch an interrupt for that one <3> if you want to catch that, it's a different signal than ctrl-c (i think STOP) <3> search for how to set signal handlers in python (i don't know myself) <10> how to except on more than one exception? <8> aww, that perl program works too :D <8> mammuth, it won't be an exception handler this time <10> ok. ill try.. <8> that's a cute bit of code :D <3> thanks ;) <8> and she said "yes" apparently, i take it back :) <3> hehehe <3> we're getting married in august <8> yay, congrats :D <3> thanks :) <8> i won't try that on the girl that i like, since she's not a coding geek ;) <3> hehehe <3> that is one thing i don't think i could do in python :p <8> yes, the indentation rules would kill you <8> mammuth, look in the signal module, particularly at the signal function <3> and lack of punctuation / ability to do crazy things with goofy variable names <8> you want to ***ign a function (or callable object) for the STOP signal <8> yeah perl's a bit crazy like that :D <12> she's all "(setq tab-width 8)", and i'm like "no way, girly" <8> oh please, that's not LISP is it? <8> or Emacs lisp maybe <13> Hi again! :) <8> lost the newbie tag eh? <14> apparently, yes! <14> someone must have made a mistake <14> anyway, I'm aaalmost done, there's just one minor issue :) <14> even though I do infile.close <14> outfile.close <14> I do not have permission to rename/delete the files <14> because they are in use <14> what am I doing wrong? <3> you add parens, right? <3> outfile.close() <14> >.< <8> indeedy :) <8> which is interesting actually
Return to
#python or Go to some related
logs:
gentoo error 80 #web #web #oe vmw codec ubuntu #kde #gentoo yum install for dr16 ubuntu mp500 driver opensuse printer permission cups 631
|
|