Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31763
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ramit.prasad@jpmorgan.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'memory.': 0.05; 'completeness': 0.07; 'python': 0.09; 'iterate': 0.09; 'received:155': 0.09; 'subject:not': 0.11; 'sat,': 0.15; "'r').read()": 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'instead:': 0.16; 'oct': 0.16; 'received:155.180': 0.16; 'received:155.180.234': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'securities,': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'string,': 0.17; 'unicode': 0.17; 'memory': 0.18; 'windows': 0.19; 'to:name:python- list@python.org': 0.20; 'file.': 0.20; 'trying': 0.21; 'task': 0.23; 'random': 0.24; 'received:169.254': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'done.': 0.27; 'possibility': 0.27; '2.3': 0.27; 'accuracy': 0.27; 'converting': 0.27; 'instead.': 0.27; 'chris': 0.28; '>>>>': 0.29; 'received:169': 0.29; 'header:Received:8': 0.30; 'file': 0.32; 'could': 0.32; 'doubt': 0.33; 'to:addr:python-list': 0.33; 'text': 0.34; 'done': 0.34; 'follows:': 0.35; 'something': 0.35; 'but': 0.36; 'closing': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'files': 0.38; 'shows': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'close': 0.63; 'information,': 0.63; 'url:email': 0.63; 'more': 0.63; 'legal': 0.65; '20,': 0.65; 'subject': 0.66; 'purchase': 0.67; 'physical': 0.69; 'sale': 0.76; 'have?': 0.84; 'received:169.254.8': 0.84; 'subject:available': 0.96 |
| X-DKIM | OpenDKIM Filter v2.1.3 sz1.jpmchase.com q9JJd8KB027329 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1350675548; bh=5xcLH6uqfBCd2HjwtAqWXcm8yMwgaeIJj0yH8+WweX4=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=OW6RzanR5JIHXiHYwTO4A+4xYPGY+CGBXX2lZmMRenBi3JOuMmu0nUFON0gjNBVHp GPomoDOscpCbB0p2ltMT1Ell/N0r/vElyZ3BAzX2QX3NbLSnjZ/HDapHA4LRgGS66u RrfgiGOcQgInT1rRcXf4PIQNA01O9C5wNGL5oULk= |
| From | "Prasad, Ramit" <ramit.prasad@jpmorgan.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Subject | RE: Python does not take up available physical memory |
| Thread-Topic | Python does not take up available physical memory |
| Thread-Index | Ac2uHGpaUb5JSqdJR1m8LKyDAm0X3wAM7IAAAAfSgYA= |
| Date | Fri, 19 Oct 2012 19:38:54 +0000 |
| References | <76D03718A3233B4C8CC236C169B535B5A23E063E45@AUSP01VMBX08.collaborationhost.net> <CAPTjJmr0Ja0+u-3JNaTXBA8Ua1FykM3Q18pxRRPPg8XNWN3DUw@mail.gmail.com> |
| In-Reply-To | <CAPTjJmr0Ja0+u-3JNaTXBA8Ua1FykM3Q18pxRRPPg8XNWN3DUw@mail.gmail.com> |
| Accept-Language | en-US |
| Content-Language | en-US |
| X-MS-Has-Attach | |
| X-MS-TNEF-Correlator | |
| x-originating-ip | [10.67.79.47] |
| Content-Transfer-Encoding | quoted-printable |
| MIME-Version | 1.0 |
| X-DLP-FWD | Yes |
| Content-Type | text/plain; charset="us-ascii" |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2529.1350675556.27098.python-list@python.org> (permalink) |
| Lines | 23 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1350675556 news.xs4all.nl 6852 [2001:888:2000:d::a6]:36249 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:31763 |
Show key headers only | View raw
Chris Angelico wrote:
> On Sat, Oct 20, 2012 at 4:08 AM, Pradipto Banerjee
> <pradipto.banerjee@adainvestments.com> wrote:
> > I am trying to read a file into memory. The size of the file is around 1 GB.
> > I have a 3GB memory PC and the Windows Task Manager shows 2.3 GB available
> > physical memory when I was trying to read the file. I tried to read the file
> > as follows:
> >
> >
> >
> >>>> fdata = open(filename, 'r').read()
>
> Is this Python 2 or Python 3? Just throwing a random possibility out
> there, could it be that reading it in and converting it to Unicode
> text requires more memory than you have?
>
> My recommendation: Unless you actually need to search the whole file
> as a single string, iterate over the file instead:
>
> for line in open(filename):
> # do something with line
If you (OP) are in Python 2.5+ I would do the following instead.
with open(filename) as f:
for line in f:
# do something with line
This will automatically close the file when it is done. I doubt
it will help with memory issues, but closing files after you
are done with them is a Good practice.
Ramit Prasad
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: Python does not take up available physical memory "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-19 19:38 +0000
csiph-web