Pythonic way of reading a textfile line by line without throwing an exception

2007-08-28 Thread Deivys Ramirez
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(

Re: "Try:" which only encompasses head of compound statement

2007-08-28 Thread Jameson . Quinn
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

Re: Pythonic way of reading a textfile line by line without throwing an exception

2007-08-28 Thread Larry Bates
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? >

RE: How to free memory ( ie garbage collect) at run time with Python2.5.1(windows)

2007-08-28 Thread Delaney, Timothy (Tim)
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

Re: Pythonic way of reading a textfile line by line without throwing an exception

2007-08-28 Thread Matimus
> 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

Re: Haskell like (c:cs) syntax

2007-08-28 Thread Matimus
> 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

Re: "Try:" which only encompasses head of compound statement

2007-08-28 Thread Ben Finney
[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

status of Programming by Contract (PEP 316)?

2007-08-28 Thread Russ
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

Re: Check for dict key existence, and modify it in one step.

2007-08-28 Thread Dustan
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

Unable to read large files from zip

2007-08-28 Thread Kevin Ar18
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

Re: Is it reasonably easy easy to something like this with python?

2007-08-28 Thread Bruno Desthuilliers
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

Re: tempfile.mkstemp and os.fdopen

2007-08-28 Thread billiejoex
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

Re: Getting subprocesses to be hidden on Windows

2007-08-28 Thread Roger Upole
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

Re: Gmane's been quiet ...

2007-08-28 Thread Grant Edwards
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

Re: Gmane's been quiet ...

2007-08-28 Thread Grant Edwards
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

Re: Pythonic way of reading a textfile line by line without throwing an exception

2007-08-28 Thread Asun Friere
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

Newbie question - sorting a slice

2007-08-28 Thread hwg
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

Re: Compiling Source with alternate Openssl lib

2007-08-28 Thread Kevin T. Ryan
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

Re: Newbie question - sorting a slice

2007-08-28 Thread half . italian
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

Re: Newbie question - sorting a slice

2007-08-28 Thread Paul McGuire
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

Creating a multi-tier client/server application

2007-08-28 Thread Jeff
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

test

2007-08-28 Thread ddyche
-- http://mail.python.org/mailman/listinfo/python-list

Re: tempfile.mkstemp and os.fdopen

2007-08-28 Thread Gabriel Genellina
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

Re: status of Programming by Contract (PEP 316)?

2007-08-28 Thread Steven Bethard
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

Re: Creating a multi-tier client/server application

2007-08-28 Thread Paul Rubin
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

Re: status of Programming by Contract (PEP 316)?

2007-08-28 Thread Russ
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

Re: status of Programming by Contract (PEP 316)?

2007-08-28 Thread Michele Simionato
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

Re: status of Programming by Contract (PEP 316)?

2007-08-28 Thread Russ
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

setup.py question

2007-08-28 Thread Eric S. Johansson
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

<    1   2