| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Comments:
<0> uhm do python's file open() types make sense? w empties the file and opens it for writing, r for reading but r+ seems to open it for appending, right? so what if i want to read the file and then replace the existing contents? <1> tuxipuxi: 'r+' is 'reading, but also writing' <1> tuxipuxi: 'a' is 'appending' <2> tuxipuxi, those work the same as in C <3> OmgWtfIDiedLol: If the subject of that sentence is me, then no. If the subject is the tutorial, then you're wrong. <0> ah i see <0> and what if i want to read the file, clean it and write my stuff? <1> tuxipuxi: if you want to want to read the file, and then replace the contents, either use 'r+' and seek to the start after you're done reading, or (much better) read from the file and write to a temp file, and when you're done, close both files and rename the tempfile to the real file. <4> I have the thing in the exact same syntax as everything else, but it still tells me incorrect sntax <3> OmgWtfIDiedLol: http://python.org/doc/tut/ <4> grrr <0> Yhg1s: that's "much better"? sounds like an ugly hack to me. what about opening it for reading, read it, close it, open it for writing? <0> ****s too, but seems to **** less than a temp file <4> I've been reading that for the past 48 hourse <2> tuxipuxi, either do what Yhg1s suggests or use the .truncate file method <0> ah truncate sounds good
<2> tuxipuxi, it is better in that the replacement is then atomic (no race conditions if someone else happens to be reading the file while you're working on it) <1> tuxipuxi: 'much better' is putting it mildly. If you write to the temp file, you will never have a broken file. If you write to the file directly, and your app crashes, your OS crashes or you have a powerfailure, your file will be corrupt. <5> is there somewhere a module repository, like perl's CPAN? <1> Yango: cheeseshop.python.org <0> Yhg1s: ok right from a safety PoV it's much better.. but i think i will use benji's way as this is not *that* critical <0> thanks to you both <4> CardinalFang: just retyped the line exactly the way it was, no more invalid syntax error <4> nothing the python tutorial could have helped with <5> what will happen if I install a module (python setup.py install) over the existing one? It is for sure safe, probably safe, for sure not safe, module dependant? <1> Yango: module dependant. It won't break, but it may leave old modules around. <3> OmgWtfIDiedLol: Python is not magical. You didn't type it the same. <1> (if the package renamed or deleted files between the two versions) <6> My ISP won't install modules for me. I was thinking there's got to be a way to create my own "modules" directory and tell my scripts "look in $SomeNewPath too". <6> Possible? <1> KurtB: sure. see the '--home' argument to setup.py, and set the PYTHONPATH environment variable. <6> Yhg1s, thank you! <7> holitas <5> you can run EasyInstall on 'ClientCookie' with the <5> --delete-conflicting option. Can't find the way to do that, what does "run EasyInstall" means exactly? I downloaded ez_setup.py, installed setuptools, but can't seem to find the way to "run EasyInstall" <5> forget my question, please <8> Hello! anyone knows how to cast text encoded like this :\x00O\x00\xdc\x00 \x00I\x00d\x00e\x00e\x00l\x00a\x00b\x00o\x00r turned into text using python ? <9> http://pydoc.org/2.4.1/subprocess.html#Popen <9> why doesn't the bit at the bottom mention .stdout and friends? <9> http://pydoc.org/2.3.3/popen2.html <9> and it's not mentioned at *all* here! <10> how does python free objects that are circuarily referenced.. it just has reference counts..? <5> johnlev, maybe os.waitpid() is what you need? <9> Yango: well, I can do it all by hand sure, this seems rather silly <9> it appears I need popen2.Popen3 but there's zero indication in the docs regarding returns (except ***uming it's the same as .popen3() <3> ludde3: Google for "python gc". <4> isn't popen2 the same as popen3? <9> it's not clear to me why they haven't bothered to document .Popen3 <5> and why doesn't the wait() or returncode values of Popen objects aren't what you need? <11> "certiorari" < eh? <3> Yango: You SEGV'd my parser. <5> CardinalFang, pyn? <9> Yango: sure. now where is the child's stdout and stderr? <3> It's in my head. <9> because they don't exist in the docs. <5> CardinalFang, oh, sorry, my generator oopsed :) <12> these popen2.Popen4 things are just getting overhand.. they just should make a "popen" module with "popen" that does everything correctly <4> lol <12> not to be confused with os.popen ! <12> grr <12> or subcommand or what it is called <5> (child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize, mode) <9> Yango: no, I can't use that - no exit code. <9> I've discovered by googling about .tochild and .fromchild, but haven't yet managed to guess (!) the stderror <13> module subprocess <9> TenOfTen: python 2.4 only. <13> so copy paste the code to your 2.3 <9> sorry, that's absurd. it's actually easier to just use the fork primitives (now I know why this code used them before) <9> thanks anyway, guys <7> que fuerte... nos llevamos 25 aos de nuestra vida durmiendo... y 1,5 en la taza del water... y 2 practicando ***o <14> damn python with his indent-is-part-of-language <14> this makes it quite harder to like print the source, or send via email text / news / etc - occ***ions to make mistake and confusing <13> email/news is for samples, real code go in .tgz or a version control system <5> raf256, as if you send C code unindented via email/text/news. Any respectable editor has autoindent so the point is kinda moot
<5> plus TenOfTen's point <2> raf256, I've never had a problem with those things, <shrug> <14> Yango: print that on paper and get self confused <14> ofcourse identing is good <14> but you can make mistake, send code throught media like news group or something, get it word-wrapped, and.. unusable <13> so you compile from paper? <14> yes <2> news group postings shouldn't be so wide as to wrap <13> any sane paper has an url to the tgz <14> on exam for example, or on meeting perhaps <5> and it's certainly not impossible to print things indented, it's not even hard <2> and he has one of those indentation-stripping printers, TenOfTen, I hate those <14> I dont say it's a _big_ problem, but still <15> use spaces to indent, you can email that just fine <13> you can email spaces now? wow <13> how do you print your \t? <11> > < <11> TenOfTen, ^ <14> TenOfTen: say again? <15> raf256: using tabs to indent is what is causing your problems <16> if i want to grab a bunch of args (filenames) from say cmd line and process them should I use f(*args)? <15> raf256: from what I understand at some points tabs won't even be allowed for indenting <14> kosh: using tabs is a good idea, spaces are lame, IMHO that is, because <14> no, no flame. I said "because", not "because I siad so" ;) <5> raf256, because it gets you in trouble when sending email or printing code <14> 1. main argument: every person uses spaces width he prefers. 2, 3, 8, whatever <14> 2. by the way, \t makes smaller files a bit <13> not if you zip <5> raf256, every person displays \t as he wishes. <14> yes <13> i convert all tabs to 4 spaces automatically in emacs everytime i save <17> raf256, I've rarely seen code that uses something other than 4 spaces for indentation in Python code. <14> TenOfTen: then work in a team with person using 8 or 2 spaces, <18> how can i make my re work across a multi-line string? adding the M option doesn't do the trick <17> I mean, *very* rarely. <14> and then watch how SVN CVS or diff thinks entire file got changed <2> same here TFK <13> raf256: i have smarter co-workers than that <13> raf256: diff can ignore whitespace <2> (and it didn't survive long) <14> well, I like compact design <14> no need for new line after loop, allow smaller ident == more code on one screen.. <3> My monthly posting of this link: http://wiki.chad.org/IndentationUsingTabs <13> raf256: you should try perl <14> I know =) <5> maybe Brain**** <14> no.. I will rather stick to C++, and perhaps perl for scripting <14> Yango: brain **** is the exact opposite of compact <13> not if its zipped <13> :P <14> TenOfTen: =_ <14> :)) <14> not to mention <5> textwise it isn't you don't need spaces <14> when scan of it's print out is zipped <13> just the fact that mixing spaces and tabs will screw everything is enough, and do admit you have spaces in your files somewhere <3> I do not. <15> 4 spaces is the standard <19> does anyone here know of a python ircbot thing, like the java pircbot? <1> %source <20> My source is available at http://www.freshmeat.net/projects/pynfo <1> see? python IRC bot. <1> another popular bot is 'supybot' <19> ahh <19> thank you! <13> CardinalFang: one day you will share a project with someone else, then you will :) <5> CardinalFang, I get the metainformation point of using tabs, but how are spaces intepreted differently in different environments? They have also a unique meaning all editors understand. <3> Yango: I don't understand your question. <3> TenOfTen: Hopefully I can pick my projects or projectmates better than that. <13> hehe, youll never succeed :) <13> (no offense) <3> TenOfTen: When in doubt on a new project, I turn on "list" in vi, and it becomes obvious what the idiom is for that file. I obey existing idioms. When I start a project or file, I do it the way I think is right.
Return to
#python or Go to some related
logs:
1200x800 grub.conf console acpupsd gnome mysql 4.0 ORDER BY SUM #python #perl pspsdk ubuntu #gentoo #linux bacula netgear error firewall initialization failed bitdefender
|
|