[Tutor] inp. outp. - part 2 & variable - dictionary difference ...

David tayi177 at hotmail.com
Thu Nov 27 05:44:18 EST 2003


Hello ...


About my yesterday question:

I just noticed two "interesting" issues (probably releated only to my configuration):

1.) First I found out, after trying few times, closing Python, and opening it again, that sometimes it open file (for reading/writting), and sometimes just don't, arbitrary, meaning that its not like I couldn't open the file always I try, therefore the most logical conclusion would be - I miss-spelled the code, but no: I 100 % tryed with identical input, I double, triple-checked the "code" ... 
I use the method below, from Alan's tutorial (don't know, probably the only one method for read/write files) ... 
I also checked files (on Alan's suggestion), if the are accidentally set as "read-only", I even unchecked "archive" (but that wouldn't explain why I could open them yesteday) ... with no benefit - as I said sometimes just can, and sometimes just can't (I second case I get "no such file or directory: 'somename.txt'" error message) !!


>>> inp = open("lll.txt","r")           # made both files just before opening Python ...
>>> outp = open("ggg","w")
...       for line in inp.readlines():    # for intendation here, I am not sure if its right, cause I couldn't check it ...
...            outp.write(line)             # before sending this mail, because of all mentioned above ...
>>> inp.close()
>>> outp.close()


So, I was surely surprised yesterday, when (after "restarting" Python) trying to open the very same file, it was normally opened with the same method, with same text (input):

>>> inp = open("lll.txt","r")
>>> outp = open("ggg","w")

... but today after closing Python, shuting down PC (sleeping 8 hours) and trying to do the same thing again - there was the same (familiar) - "no such file or directory: 'somename.txt'" error message !!


I have also tryed what Danny suggested, some other method to open file, and typed:

>>> inp = open("D:/Program Files/Python/Lib/idlelib/Saves/ggg.txt") ... and the file was opened normally !!


... but in the very next line (of course after typing inp.close() ), with inp = open("somefile.txt","r") method:

>>> inp = open("lll.txt","r")  ... the was "no such file or directory" error message again !!



2.) Second about reading/writing from/into file, I noticed (yesterday, when I had luck and I could open file), that Python doesn't want to write from one file to another, which is non-empty (though maybe also just in my case) and also in file, which was already modified (something written in), changed from outside Python, during current session (of course, I used inp(close) before modified it) and even if this file was modified, and I later deleted that "new added" text (again maybe just in my case).



2.) Then I would really like to know, if I open some file, already process some line, and then miss-spell something, and some error message appears - do I need to close both (inp and out) files, and start from the beginning, or could I continue from the line before that error message ??



3.) And as the last question, Alan.G's answer on my question about "difference between different types of brackets", was:

"{} indicate a dictionary. ... One item in the pair is the lookup key, the other the return value." 

I am just curious - where is some "elemental" difference between dictionary (in practical use) and simple variable, cause "One item in the pair is the lookup key, the other the return value." - more or less resemble on variable deffiniton ...

Example: 

instance = "Actual usage of class" (here we have variable and its actual value, stored in some location in RAM)

... so here one item is also some sort of "lookup key", and the other "the return value" ...


Sorry, I really have more "theoretical" questions now on the beginning of learning how to programm, but it (answers here on Tutor list) really help me to imagine how everything works.


P.S., I save all the answers I get, and you couldn't imagine (or you probably do, but I just said so, cause it sounds nice), how helpfull is having you answers saved somewhere, and when something is not so clear, just open those files, and see what was doing wrong ...



Thank you all, Tadey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20031127/b1e8be68/attachment.html


More information about the Tutor mailing list