Hi everyone,
I'm a Python newbie but have experience programming PHP and C so i'm
not really new to programming but new to Python.
What's the "pythonic" way of reading a text file, line by line,
without throwing an exception when there's nothing to be read?
I've been trying to map my while(!eof(
Those are some good responses, but I think they focused a little too
much on the specifics of my example - especially the 'print'
statement. In real life, I want to set some return values to sensible
defaults if the file doesn't exist, but I want the errors from inside
the block to trickle up as no
Deivys Ramirez wrote:
> Hi everyone,
>
> I'm a Python newbie but have experience programming PHP and C so i'm
> not really new to programming but new to Python.
>
> What's the "pythonic" way of reading a text file, line by line,
> without throwing an exception when there's nothing to be read?
>
Alex Martelli wrote:
> rfv-370 <[EMAIL PROTECTED]> wrote:
>
>> have made the following small test:
>>
>> Before starting my test my UsedPhysicalMemory(PF): 555Mb
>>
> tf=range(0,1000)PF: 710Mb ( so 155Mb for my List)
> tf=[0,1,2,3,4,5] PF: 672Mb (Why? Why the remaini
> fp=open(filename, 'r')
> for line in fp:
> # do something with line
>
> fp.close()
Or, if you are using Python 2.5+, you can use the file context via the
`with' statement.
[code]
from __future__ import with_statement # this line won't be needed in
Python 2.6+
with open(filename, 'r') as fp
> Is there a pattern matching construct in Python like (head : tail), meaning
> 'head' matches the first element of a list and 'tail' matches the rest? I
> could not find this in the Python documentation.
Not really, but you could do something like this:
[code]
def foo(head, *tail):
#do stuff
[EMAIL PROTECTED] writes:
> In real life, I want to set some return values to sensible defaults
> if the file doesn't exist, but I want the errors from inside the
> block to trickle up as normal.
Sure. Just be careful only to catch the exceptions that you do want to
handle at that level of the co
I just stumbled onto PEP 316: Programming by Contract for Python
(http://www.python.org/dev/peps/pep-0316/). This would be a great
addition to Python, but I see that it was submitted way back in 2003,
and its status is "deferred." I did a quick search on
comp.lang.python,
but I don't seem to see mu
On Aug 28, 1:13 pm, rodrigo <[EMAIL PROTECTED]> wrote:
> evan,
>
> yes, it does help. Works like it should:
>
> class CountingDictionary(dict):
> def increment(self, key, delta=1):
> self[key] = self.get(key, 0) + delta
>
> d = CountingDictionary()
> d.increment('cat')
> d.increment('do
I posted this on the forum, but nobody seems to know the solution:
http://python-forum.org/py/viewtopic.php?t=5230
I have a zip file that is several GB in size, and one of the files inside of it
is several GB in size. When it comes time to read the 5+GB file from inside
the zip file, it fails
Gerardo Herzig a écrit :
> walterbyrd wrote:
>
>> This is made with a php5 framework called qcodo.
>>
>> http://examples.qcodo.com/examples/dynamic/inline_editing.php
>>
>> With qcodo it's easy to make grids that are sortable and inline
>> editable. Qcodo grids work from the database - not an xml
Thanks all.
Another question: I have to open file for writing ('wb') but I noticed
that both tempfile.mkstemp() and os.fdopen() accept a "mode" argument.
It's not clear *when* do I have to specify such mode. When using
tempfile.mkstemp?
>>> fileno, name = tempfile.mkstemp(text=False)
>>> fd = os.f
geoffbache wrote:
> On 28 Aug, 18:18, Larry Bates <[EMAIL PROTECTED]> wrote:
>> geoffbache wrote:
>> > Hi,
>>
>> > As part of my efforts to write a test tool that copes with GUIs
>> > nicely, I'm trying to establish how I can start a GUI process on
>> > Windows that will not bring up the window. S
On 2007-08-28, Steve Holden <[EMAIL PROTECTED]> wrote:
> ... so I was wondering if it's just me who hasn't seen any postings today?
AFAICT, it's been dead for a day or so. I posted something to
the py2exe list via the gmane NNTP server early this after noon
and it never showed up. I don't think
On 2007-08-28, Lawrence Oluyede <[EMAIL PROTECTED]> wrote:
> Steve Holden <[EMAIL PROTECTED]> wrote:
>> ... so I was wondering if it's just me who hasn't seen any postings today?
>
> I think so, through my usenet server I saw the usual lot of postings
Posting that were made to mailing lists via gm
On Aug 29, 9:49 am, "Deivys Ramirez" <[EMAIL PROTECTED]> wrote:
> What's the "pythonic" way of reading a text file, line by line,
> without throwing an exception when there's nothing to be read?
>
> I've been trying to map my while(!eof(fp)) mindset to the file object
> Python gives me when I call
I've searched the group and didn't see the answer to this...
Why doesn't this work?:
>>> letters = ['d', 'a', 'e', 'c', 'b']
>>> letters[1:3].sort()
>>>
This returns None.
Why? letters[1:3] is ['a', 'e', 'c']Sorting that should return
['a', 'c', 'e']
hwg
--
http://mail.python.org/mai
On Aug 28, 2:09 pm, "Kevin T. Ryan" <[EMAIL PROTECTED]> wrote:
> Hi All -
>
> I'm trying to compile Python on a Centos machine (RHEL) 3.8 for a
> hosting account that I just set up and I'm having 2 issues:
>
> 1. I ran into an issue with the "hashlib" module [I think] because it
> bumps it up agai
On Aug 28, 7:43 pm, hwg <[EMAIL PROTECTED]> wrote:
> I've searched the group and didn't see the answer to this...
>
> Why doesn't this work?:
>
> >>> letters = ['d', 'a', 'e', 'c', 'b']
> >>> letters[1:3].sort()
>
> This returns None.
>
> Why? letters[1:3] is ['a', 'e', 'c']Sorting that shou
On Aug 28, 9:43 pm, hwg <[EMAIL PROTECTED]> wrote:
> I've searched the group and didn't see the answer to this...
>
> Why doesn't this work?:
>
> >>> letters = ['d', 'a', 'e', 'c', 'b']
> >>> letters[1:3].sort()
>
> This returns None.
>
> Why? letters[1:3] is ['a', 'e', 'c']Sorting that shou
Hello everyone. I've searched through the archives here, and it seems
that questions similar to this one have come up in the past, but I was
hoping that I could pick your Pythonic brains a bit.
Here's a broad overview of what I need to do: cross-platform, client-
side GUI apps that interact with
--
http://mail.python.org/mailman/listinfo/python-list
On 28 ago, 22:21, billiejoex <[EMAIL PROTECTED]> wrote:
> Another question: I have to open file for writing ('wb') but I noticed
> that both tempfile.mkstemp() and os.fdopen() accept a "mode" argument.
> It's not clear *when* do I have to specify such mode. When using
> tempfile.mkstemp?
>
> Moreo
Russ wrote:
> I just stumbled onto PEP 316: Programming by Contract for Python
> (http://www.python.org/dev/peps/pep-0316/). This would be a great
> addition to Python, but I see that it was submitted way back in 2003,
> and its status is "deferred." I did a quick search on
> comp.lang.python,
> bu
Jeff <[EMAIL PROTECTED]> writes:
> Here's a broad overview of what I need to do: cross-platform, client-
> side GUI apps that interact with a server backed by a database. I'd
> also like the possibility of having a web interface for small portions
> of the app. ... any advice on anything I've m
On Aug 28, 9:35 pm, Steven Bethard <[EMAIL PROTECTED]> wrote:
> Russ wrote:
> > I just stumbled onto PEP 316: Programming by Contract for Python
> > (http://www.python.org/dev/peps/pep-0316/). This would be a great
> > addition to Python, but I see that it was submitted way back in 2003,
> > and it
On Aug 29, 7:21 am, Russ <[EMAIL PROTECTED]> wrote:
>
> Thanks for that information. That's too bad, because it seems like a
> strong positive capability to add to Python. I wonder why the cold
> reception. Were there problems with the idea itself or just the
> implementation? Or is it just a low p
On Aug 28, 10:58 pm, Michele Simionato <[EMAIL PROTECTED]>
wrote:
> Why do you think that would ad a strong positive capability?
> To me at least it seems a big fat lot of over-engineering, not
> needed in 99% of programs. In the remaining 1%, it would still not
> be needed since Python provides o
I have an environment where I have a bunch of data files or use would like
Python application. I want to use the data_files specification of set up to
distribute those files. But I also need to change ownership and permissions.
I
know there's some way to do this because I've done it once bef
101 - 129 of 129 matches
Mail list logo