Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24882 > unrolled thread
| Started by | subhabangalore@gmail.com |
|---|---|
| First post | 2012-07-04 16:21 -0700 |
| Last post | 2012-07-07 22:42 -0700 |
| Articles | 7 on this page of 27 — 8 participants |
Back to article view | Back to comp.lang.python
Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-04 16:21 -0700
Re: Discussion on some Code Issues Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-05 00:02 +0000
Re: Discussion on some Code Issues Rick Johnson <rantingrickjohnson@gmail.com> - 2012-07-04 17:08 -0700
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-04 20:25 -0700
Re: Discussion on some Code Issues Peter Otten <__peter__@web.de> - 2012-07-05 09:30 +0200
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-05 07:33 -0700
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-05 07:33 -0700
Re: Discussion on some Code Issues Peter Otten <__peter__@web.de> - 2012-07-06 09:35 +0200
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-07 12:54 -0700
Re: Discussion on some Code Issues Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-07 16:51 -0400
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-07 22:42 -0700
Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-08 18:03 +1000
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-08 10:05 -0700
Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-09 03:17 +1000
Re: Discussion on some Code Issues Roy Smith <roy@panix.com> - 2012-07-08 14:17 -0400
Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-09 07:54 +1000
Re: Discussion on some Code Issues Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-09 00:57 +0000
Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-09 18:41 +1000
Re: Discussion on some Code Issues Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-09 12:24 +0000
Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-10 00:47 +1000
Re: Discussion on some Code Issues Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-09 12:49 -0400
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-16 07:17 -0700
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-16 07:17 -0700
Re: Discussion on some Code Issues MRAB <python@mrabarnett.plus.com> - 2012-07-08 19:27 +0100
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-08 10:05 -0700
Re: Discussion on some Code Issues Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-08 15:07 -0400
Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-07 22:42 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-07-09 12:49 -0400 |
| Message-ID | <mailman.1951.1341852568.4697.python-list@python.org> |
| In reply to | #25057 |
On 09 Jul 2012 00:57:31 GMT, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> declaimed the following in
gmane.comp.python.general:
> On Mon, 09 Jul 2012 07:54:47 +1000, Chris Angelico wrote:
>
> > It's like
> > the difference between reminder text on a Magic: The Gathering card and
> > the actual entries in the Comprehensive Rules. Perfect example is the
> > "Madness" ability - the reminder text explains the ability, but uses
> > language that actually is quite incorrect. It's a better explanation,
> > though.
>
> Hang on, you say that an explanation which is "quite incorrect" is
> *better* than one which is correct?
>
Take into account that one of the detailed rules is that the text on
a card overrides the text in the rulebook.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | subhabangalore@gmail.com |
|---|---|
| Date | 2012-07-16 07:17 -0700 |
| Message-ID | <f319f778-5100-4eec-952f-06a8e43d04b6@googlegroups.com> |
| In reply to | #25047 |
On Sunday, July 8, 2012 10:47:00 PM UTC+5:30, Chris Angelico wrote: > On Mon, Jul 9, 2012 at 3:05 AM, <subhabangalore@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@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. > > open("doc1.txt","r") > > 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.) > > 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.) > > ChrisA Dear Group, The problem is more or less solved. Thank you for giving varied ways of thinking on the problem. Everytime I visit the group I learn so many things. Thank you all for taking your kind time to try to absolve the issue. Regards, Subhabrata Banerjee.
[toc] | [prev] | [next] | [standalone]
| From | subhabangalore@gmail.com |
|---|---|
| Date | 2012-07-16 07:17 -0700 |
| Message-ID | <mailman.2175.1342448249.4697.python-list@python.org> |
| In reply to | #25047 |
On Sunday, July 8, 2012 10:47:00 PM UTC+5:30, Chris Angelico wrote: > On Mon, Jul 9, 2012 at 3:05 AM, <subhabangalore@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@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. > > open("doc1.txt","r") > > 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.) > > 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.) > > ChrisA Dear Group, The problem is more or less solved. Thank you for giving varied ways of thinking on the problem. Everytime I visit the group I learn so many things. Thank you all for taking your kind time to try to absolve the issue. Regards, Subhabrata Banerjee.
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2012-07-08 19:27 +0100 |
| Message-ID | <mailman.1923.1341772228.4697.python-list@python.org> |
| In reply to | #25045 |
On 08/07/2012 18:17, Chris Angelico wrote:
> On Mon, Jul 9, 2012 at 3:05 AM, <subhabangalore@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@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.
>
> open("doc1.txt","r")
>
> 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.)
>
[toc] | [prev] | [next] | [standalone]
| From | subhabangalore@gmail.com |
|---|---|
| Date | 2012-07-08 10:05 -0700 |
| Message-ID | <mailman.1921.1341767161.4697.python-list@python.org> |
| In reply to | #25038 |
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@gmail.com> wrote:
> > Thanks for pointing out the mistakes. Your points are right. So I am trying to revise it,
> >
> > file_open=open("/python32/doc1.txt","r")
> > for line in file_open:
> > line_word=line.split()
> > print (line_word)
>
> Yep. I'd be inclined to rename file_open to something that says what
> the file _is_, and you may want to look into the 'with' statement to
> guarantee timely closure of the file, but that's a way to do it.
>
> 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.
>
> ChrisA
Dear Chirs,
No file path! Amazing. I do not know I like to know one small example please.
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.
Regards,
Subha
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-07-08 15:07 -0400 |
| Message-ID | <mailman.1924.1341774432.4697.python-list@python.org> |
| In reply to | #25035 |
On Sat, 7 Jul 2012 22:42:13 -0700 (PDT), subhabangalore@gmail.com
declaimed the following in gmane.comp.python.general:
>
> Thanks for pointing out the mistakes. Your points are right. So I am trying to revise it,
>
> file_open=open("/python32/doc1.txt","r")
> for line in file_open:
> line_word=line.split()
> print (line_word)
>
> To store them the best way is to assign a blank list and append but is there any alternate
> method for huge data it becomes tough as the list becomes huge if any way variables may be assigned.
>
Well, first to copy from an earlier post (just so I can trim the
unneeded)...
> > > I like to store in some variable,so that I may print line of my choice and manipulate them at my choice.
> > > Is there any way out to this problem?
It is still not clear exactly what the task itself is supposed to
be.
After all, you are splitting the line into a LIST of words, and then
here state the goal is to "print line of" choice... The line and not the
list? There is no hint of what "manipulate them" involves.
If the files are of any size, I would not even attempt to store them
internally... I'd be more likely to run a preprocess phase which opens
the file in binary mode, (maybe reads it in chunks), and builds a list
of /offsets/ to the start of each line. To process any specific line
later would use seek() operations to the start of the line, followed by
a read operation of just the length to the next line.
Doing an mmap() of the file may event speed up the later processing,
as you wouldn't be using I/O seeks, but just asking for slices from the
mmap'd file. The OS would be responsible for making sure the file
contents were in memory.
This won't work if the manipulation requires making a line longer or
shorter. In that case, preprocessing would be writing the lines to a
simple BSD-DB style "database", in which the "line number" is the key;
an manipulation would work on records fetched by line number, and
written back.
If you also store a "process date" in the BSD-DB database, you could
match it to the last modified time of the source file and skip
reprocessing if the source has not changed.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | subhabangalore@gmail.com |
|---|---|
| Date | 2012-07-07 22:42 -0700 |
| Message-ID | <mailman.1908.1341726136.4697.python-list@python.org> |
| In reply to | #25032 |
On Sunday, July 8, 2012 2:21:14 AM UTC+5:30, Dennis Lee Bieber wrote:
> On Sat, 7 Jul 2012 12:54:16 -0700 (PDT), subhabangalore@gmail.com
> declaimed the following in gmane.comp.python.general:
>
> > But I am bit intrigued with another question,
> >
> > suppose I say:
> > file_open=open("/python32/doc1.txt","r")
> > file=a1.read().lower()
> > for line in file:
> > line_word=line.split()
> >
> > This works fine. But if I print it would be printed continuously.
>
> "This works fine" -- Really?
>
> 1) Why are you storing data files in the install directory of your
> Python interpreter?
>
> 2) "a1" is undefined -- you should get an exception on that line which
> makes the following irrelevant; replacing "a1" with "file_open" leads
> to...
>
> 3) "file" is a) a predefined function in Python, which you have just
> shadowed and b) a poor name for a string containing the contents of a
> file
>
> 4) "for line in file", since "file" is a string, will iterate over EACH
> CHARACTER, meaning (since there is nothing to split) that "line_word" is
> also just a single character.
>
> for line in file.split("\n"):
>
> will split the STRING into logical lines (assuming a new-line character
> splits the lines) and permit the subsequent split to pull out wordS
> ("line_word" is misleading, as to will contain a LIST of words from the
> line).
>
> > I like to store in some variable,so that I may print line of my choice and manipulate them at my choice.
> > Is there any way out to this problem?
> >
> >
> > Regards,
> > Subhabrata Banerjee
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Thanks for pointing out the mistakes. Your points are right. So I am trying to revise it,
file_open=open("/python32/doc1.txt","r")
for line in file_open:
line_word=line.split()
print (line_word)
To store them the best way is to assign a blank list and append but is there any alternate
method for huge data it becomes tough as the list becomes huge if any way variables may be assigned.
Regards,
Subhabrata Banerjee.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web