Re: Questions: While And List Comprehension

2010-11-10 Thread alex23
Steve Holden wrote: > how about print [sys.stdin.readline() for i in range(5)] > > At least that won't consume the whole file. +1 on this approach. Clear and obvious and not reliant on any library modules other than sys. itertools, what WAS I thinking? :) -- http://mail.python.org/mailman/listi

Re: How to test if a module exists?

2010-11-10 Thread Tim Chase
On 11/10/10 03:50, Lawrence D'Oliveiro wrote: In message, Jon Dufresne wrote: Lawrence D'Oliveiro wrote: I see that you published my unobfuscated e-mail address on USENET for all to see. I obfuscated it for a reason, to keep the spammers away. I'm assuming this was a momentary lapse of judge

Re: Looping through files in a directory

2010-11-10 Thread Tim Chase
On 11/10/10 16:46, Matty Sarro wrote: Short story - I have a few thousand files in a directory I need to parse through. Is there a simple way to loop through files? I'd like to avoid writing a python script that can parse 1 file, and have to call it a few thousand times from a bash script. Any in

Re: Questions: While And List Comprehension

2010-11-10 Thread MRAB
On 11/11/2010 00:29, James Mills wrote: On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote: Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that still reads the entire sys.stdin (whatever it may be...) Here's a way of doing the same thing without consuming the entire

Re: Questions: While And List Comprehension

2010-11-10 Thread Chris Rebert
On Wed, Nov 10, 2010 at 5:38 PM, MRAB wrote: > On 11/11/2010 00:29, James Mills wrote: >> On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille  wrote: >>> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that >>> still reads the entire sys.stdin (whatever it may be...) >> >> Here'

Re: Is Eval *always* Evil?

2010-11-10 Thread Robert Kern
On 2010-11-10 17:14 , Christian Heimes wrote: Am 10.11.2010 18:56, schrieb Simon Mullis: Yes, eval is evil, may lead to security issues and it's unnecessary slow, too. # In the meantime - and as a proof of concept - I'm using a dict instead. xpathlib = { "houses": r'[ y.t

Re: Is Eval *always* Evil?

2010-11-10 Thread Robert Kern
On 2010-11-10 15:52 , Hrvoje Niksic wrote: Simon Mullis writes: If "eval" is not the way forward, are there any suggestions for another way to do this? ast.literal_eval might be the thing for you. No, that doesn't work since he needs to call methods. -- Robert Kern "I have come to believ

Re: Silly newbie question - Caret character (^)

2010-11-10 Thread Lawrence D'Oliveiro
In message , Seebs wrote: > On 2010-11-10, Terry Reedy wrote: > >> I was referring to Schildt using gets() all the time and thereby >> teaching new C generations to do he same. > > Ahh, yes. > > I am told that the current plan is to kill it in C1X. I would shed no > tears. Another function th

Re: Is Eval *always* Evil?

2010-11-10 Thread Lawrence D'Oliveiro
In message , Robert Kern wrote: > Well, the key reason he is using strings is so that he can easily slap on > a Django admin UI to allow certain users to add new expressions. lambdas > don't help with that. Provded you can trust the users who are allowed to add such expressions, it’s probably a

Re: Questions: While And List Comprehension

2010-11-10 Thread Steve Holden
On 11/10/2010 7:29 PM, James Mills wrote: > On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote: >> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that >> still reads the entire sys.stdin (whatever it may be...) > > Here's a way of doing the same thing without consuming

Re: DTD Parsing

2010-11-10 Thread Lawrence D'Oliveiro
In message , Christian Heimes wrote: > Don't repeat the mistakes of others and use XML as a configuration > language. XML isn't meant to be edited by humans. My principle is: anything automatically generated by machine is not fit for viewing or editing by humans. There’s nothing special about X

Re: DTD Parsing

2010-11-10 Thread Lawrence D'Oliveiro
In message , Christian Heimes wrote: > I'm sorry but every time I read XML and configuration in one sentence, I > see the horror of TomCat or Shibboleth XML configs popping up. Tomcat I know is written in Java; let me guess—Shibboleth is too? -- http://mail.python.org/mailman/listinfo/python-li

Re: DTD Parsing

2010-11-10 Thread Lawrence D'Oliveiro
In message , Ian Kelly wrote: > On 11/9/2010 11:14 PM, r0g wrote: >> >> config = {} >> for line in (open("config.txt", 'r')): >> if len(line) > 0 and line[0] <> "#": >> param, value = line.rstrip().split("=",1) >> config[param] = value > > That's five whole lines of code. Wh

Re: Questions: While And List Comprehension

2010-11-10 Thread Ian
On 11/10/2010 4:36 AM Felipe Vinturini said... > 2.* *I would like to know another way, a more pythonic way, to write the > following: > === > import sys > > def Z(iNumber): >      sum=0 >      while (iNumber>=5): >    

Re: Questions: While And List Comprehension

2010-11-10 Thread James Mills
On Thu, Nov 11, 2010 at 11:38 AM, MRAB wrote: > 'list' will exhaust the input, then the slicing will return at most 5 > lines. Hmm you're right :) -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list

Re: Questions: While And List Comprehension

2010-11-10 Thread James Mills
On Thu, Nov 11, 2010 at 1:02 PM, Steve Holden wrote: > This suggests that you are mistaken about not exhausting the source. Yeah I was mistaken. Oh well :) I was thinking of a generator-based solution and got lost in the implementation! -- -- James Mills -- -- "Problems are solved by method" --

Re: Questions: While And List Comprehension

2010-11-10 Thread James Mills
On Thu, Nov 11, 2010 at 11:01 AM, alex23 wrote: > +1 on this approach. Clear and obvious and not reliant on any library > modules other than sys. > > itertools, what WAS I thinking? :) maybe: import sys from itertools import islice print [v for v in islice((line for line in sys.stdin), 0, 5)]

Re: How to test if a module exists?

2010-11-10 Thread Jon Dufresne
On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro wrote: > In message , Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers

Re: subclassing str

2010-11-10 Thread not1xor1 (Alessandro)
Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto: How exactly does a.f(b, c) save time over f(a, b, c) unfortunately in real world you have: objId = objId.method(args) vs. objId = moduleName.method(objId, args) I know you can use "from moduleName import *", but IMHO that pro

Re: Class extension confusion :(

2010-11-10 Thread r0g
On 10/11/10 09:52, Peter Otten wrote: r0g wrote: I have a subclass of BaseHHTPRequestHandler which uses a dictonary "paths" and a function "api_call" which are defined in the main namespace of the module. I'd rather I was able to pass these object to the constructor and store them as data attri

Re: subclassing str

2010-11-10 Thread Chris Rebert
On Wed, Nov 10, 2010 at 8:14 PM, not1xor1 (Alessandro) <" "@libero.it> wrote: > Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto: > >> How exactly does >> >>    a.f(b, c) >> >> save time over >> >>     f(a, b, c) > > unfortunately in real world you have: > > objId = objId.method(args) > > vs. >

Re: How to test if a module exists?

2010-11-10 Thread Robert Kern
On 2010-11-10 22:18 , Jon Dufresne wrote: On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro wrote: In message, Jon Dufresne wrote: On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... I see that you published my unobfuscated e-mail address on USENET for all to see. I obfuscated it f

Re: DTD Parsing

2010-11-10 Thread Steve Holden
On 11/10/2010 10:07 PM, Lawrence D'Oliveiro wrote: > In message , Ian Kelly > wrote: > >> > On 11/9/2010 11:14 PM, r0g wrote: >>> >> >>> >> config = {} >>> >> for line in (open("config.txt", 'r')): >>> >> if len(line) > 0 and line[0] <> "#": >>> >> param, value = line.rstrip().split("

Re: How to test if a module exists?

2010-11-10 Thread r0g
On 10/11/10 12:45, Mark Wooding wrote: r0g writes: You use your main address on USENET rather than a junk one!? Obfuscated or not that's either brave or foolhardy! I use my real email address. I also have an aggressive spam filter. But I don't think that much of my comes from Usenet harvest

Re: Questions: While And List Comprehension

2010-11-10 Thread rantingrick
On Nov 10, 4:56 pm, Emile van Sebille wrote: > On 11/10/2010 4:36 AM Felipe Vinturini said... > > > Hi Folks, > > > I am quite new to python and I don't have a lot of experience with it yet. > > > I have two simple questions: > > > 1. Is there a way to limit the number of times a list comprehensio

Re: Questions: While And List Comprehension

2010-11-10 Thread James Mills
On Thu, Nov 11, 2010 at 3:05 PM, rantingrick wrote: > Hey all you guys could be mistaken. It looks like the OP is trying to > implement some sort of ghetto database. And he may NOT necessarily > want the FIRST five lines of the file. He said (and i quote) "the > values /between/ # and #". Where #

Re: Curses Programming

2010-11-10 Thread r0g
On 10/11/10 14:42, alexander wrote: Hi, all Here is the test. Plz help. / ***/ If you use the new image search of Google, you will

Re: udp sockets with python

2010-11-10 Thread Tim Roberts
Mag Gam wrote: > >I am measuring the round trip time using tcpdump. The C version is >giving me around 80 microseconds (average) and the python is giving me >close to 300 microseconds (average). If you need the performance of a compiled language, then it's probably not appropriate to use an inter

Re: DTD Parsing

2010-11-10 Thread r0g
On 10/11/10 20:38, Ian wrote: On Nov 10, 1:05 am, r0g wrote: That's five whole lines of code. Why go to all that trouble when you can just do this: import config Heh, mainly because I figure the config module will have a lot more options than I have use for right now and therefore the docs

Re: Questions: While And List Comprehension

2010-11-10 Thread r0g
On 10/11/10 22:56, Emile van Sebille wrote: On 11/10/2010 4:36 AM Felipe Vinturini said... Hi Folks, I am quite new to python and I don't have a lot of experience with it yet. I have two simple questions: 1. Is there a way to limit the number of times a list comprehension will execute? E.g. I

Re: DTD Parsing

2010-11-10 Thread r0g
On 10/11/10 23:18, Christian Heimes wrote: Am 10.11.2010 04:36, schrieb Asun Friere: Yes but configuration files are not necessarily meant to be edited by humans either! Yeah, you are right. I'm sorry but every time I read XML and configuration in one sentence, I see the horror of TomCat or Sh

Re: Looping through files in a directory

2010-11-10 Thread r0g
On 11/11/10 00:17, Steve Holden wrote: On 11/10/2010 5:46 PM, Matty Sarro wrote: Short story - I have a few thousand files in a directory I need to parse through. Is there a simple way to loop through files? I'd like to avoid writing a python script that can parse 1 file, and have to call it a f

Re: Looping through files in a directory

2010-11-10 Thread Chris Rebert
On Wed, Nov 10, 2010 at 10:11 PM, r0g wrote: > On 11/11/10 00:17, Steve Holden wrote: >> On 11/10/2010 5:46 PM, Matty Sarro wrote: >>> >>> Short story - I have a few thousand files in a directory I need to parse >>> through. Is there a simple way to loop through files? I'd like to avoid >>> writin

Re: Looping through files in a directory

2010-11-10 Thread r0g
On 11/11/10 06:23, Chris Rebert wrote: On Wed, Nov 10, 2010 at 10:11 PM, r0g wrote: On 11/11/10 00:17, Steve Holden wrote: On 11/10/2010 5:46 PM, Matty Sarro wrote: Short story - I have a few thousand files in a directory I need to parse through. Is there a simple way to loop through files?

Re: Is Eval *always* Evil?

2010-11-10 Thread Hrvoje Niksic
Robert Kern writes: > On 2010-11-10 15:52 , Hrvoje Niksic wrote: >> Simon Mullis writes: >> >>> If "eval" is not the way forward, are there any suggestions for >>> another way to do this? >> >> ast.literal_eval might be the thing for you. > > No, that doesn't work since he needs to call methods.

<    1   2