Discussion on some Code Issues
python at mrabarnett.plus.com
Sun Jul 8 20:27:24 CEST 2012
On 08/07/2012 18:17, Chris Angelico wrote:
> On Mon, Jul 9, 2012 at 3:05 AM, <subhabangalore at gmail.com> wrote:
>> On Sunday, July 8, 2012 1:33:25 PM UTC+5:30, Chris Angelico wrote:
>>> On Sun, Jul 8, 2012 at 3:42 PM, <subhabangalore at gmail.com> wrote:
>>> > file_open=open("/python32/doc1.txt","r")
>>> Also, as has already been mentioned: keeping your data files in the
>>> Python binaries directory isn't usually a good idea. More common to
>>> keep them in the same directory as your script, which would mean that
>>> you don't need a path on it at all.
>> No file path! Amazing. I do not know I like to know one small example please.
> Python will look for a file called doc1.txt in the directory you run
> the script from (which is often going to be the same directory as your
> .py program).
>> Btw, some earlier post said, line.split() to convert line into bag of words can
>> be done with power(), but I did not find it, if any one can help. I do close
>> files do not worry. New style I'd try.
> I don't know what power() function you're talking about, and can't
> find it in the previous posts; the nearest I can find is a post from
> Ranting Rick which says a lot of guff that you can ignore. (Rick is a
> professional troll. Occasionally he says something useful and
> courteous; more often it's one or the other, or neither.)
I believe the relevant quote is """especially the Python gods have
given you *power* over string objects""". If that's the case, he's not
referring to a method or a function called "power".
He did give the good warning about the problem there could be if the
original string contains "$", the character being used as the separator.
> As to the closing of files: There are a few narrow issues that make it
> worth using the 'with' statement, such as exceptions; mostly, it's
> just a good habit to get into. If you ignore it, your file will
> *usually* be closed fairly soon after you stop referencing it, but
> there's no guarantee. (Someone else will doubtless correct me if I'm
> wrong, but I'm pretty sure Python guarantees to properly flush and
> close on exit, but not necessarily before.)
More information about the Python-list