Re: spam on the list - how are things now?

2009-01-15 Thread Terry Reedy
James Mills wrote: On Fri, Jan 16, 2009 at 1:30 PM, wrote: We've been running SpamBayes on the news-to-mail gateway on mail.python.org for a couple weeks now. To me it seems like the level of spam leaking onto the list has dropped way down but I'd like some feedback from people who read the p

lazy evaluation is sometimes too lazy... help please.

2009-01-15 Thread Ken Pu
Hi, below is the code I thought should create two generates, it[0] = 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the same!!! from itertools import * itlist = [0,0] for i in range(2): itlist[i] = (x+(i*10) for x in count()) print "what's in the bags:" print list(islice(itli

Re: Injecting a global into a defined function??

2009-01-15 Thread Terry Reedy
Cong Ma wrote: Terry Reedy wrote: Not to me. You are using the module as a singleton class. The alternative is to write a class, make the functions methods, and instantiate the class. If that instance must be a singleton, more work is required. If multiple instances make sense, you can go the

Re: Beginner: Data type conversion question

2009-01-15 Thread Marc 'BlackJack' Rintsch
On Thu, 15 Jan 2009 21:09:43 -0800, flagg wrote: > def checkSerial(): > """ > Checks the current 'date' portion of the serial number and checks > the current 'counter'(the two digit number at the end of the serial > number), then returns a complete new serial """ > currentDate

Re: Python Style Guide Questions

2009-01-15 Thread Ben Finney
koranthala writes: > import x > b = x.a > or > from x import a > b = a > >I read in Learning Python that it is always better to use the > former - especially since namespace wont be dirtied. The namespace isn't really dirtied by ‘from foo import spam’, since it's clear within t

Re: English-like Python

2009-01-15 Thread Terry Reedy
The Music Guy wrote: Just out of curiousity, have there been any attempts to make a version of Python that looks like actual English text? I mean, so much of Python is already based on the English language that it seems like the next natural step would be to make a programming language which is a

Re: problem in implementing multiprocessing

2009-01-15 Thread Terry Reedy
gopal mishra wrote: Hello, I am trying to implement the multiprocessing in my application to take advantage of multiple cores. I have created two Separate process something like this. que = Queue Process(target = getData, args=(que , section, MdbFile,)).start() Process(target = getData, args=

Re: Library for extracting new content from email reply messages?

2009-01-15 Thread Terry Reedy
Bernard Rankin wrote: Hello, I'm looking to build a simple mostly email-based trouble ticket system. (I've yet to find a ready-made python solution that is both simple and well designed) Is there a Python email parsing library that can assist in extracting new content from messages that

Re: Beginner: Data type conversion question

2009-01-15 Thread Terry Reedy
flagg wrote: I am still fairly new to python and programming in general. My question is regarding data conversion, I am working on a script that will edit dns zone files, one of the functions i wrote handles updating the serial number. Our zone files use the date as the first part of the serial

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-15 Thread Terry Reedy
On Jan 15, 8:02 am, Paul Rubin wrote: Have you looked at Tim Sweeney's talk that I mentioned in another post? http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s... I did. He gives a really nice use case for Python's ability to dynamically

Re: English-like Python

2009-01-15 Thread Erik Max Francis
Tobias Andersson wrote: The Music Guy skrev: Just out of curiousity, have there been any attempts to make a version of Python that looks like actual English text? I mean, so much of Python is already based on the English language that it seems like the next natural step would be to make a progra

Re: optimizing large dictionaries

2009-01-15 Thread Scott David Daniels
Paul Rubin wrote: Per Freem writes: 2] is there an easy way to have nested defaultdicts? ie i want to say that my_dict = defaultdict(defaultdict(int)) -- to reflect the fact that my_dict is a dictionary, whose values are dictionary that map to ints. but that syntax is not valid. my_dict = def

Re: Python Style Guide Questions

2009-01-15 Thread koranthala
On Jan 16, 12:00 pm, Terry Reedy wrote: > koranthala wrote: > > Hi, > >    Which is more advisable? > > import x > > b = x.a > >              or > > from x import a > > b = a > > If I know I want just one thing from x, I tend to use latter. > I also like 'import xyzlib as x' > > >    I read in Lea

Re: Py3 - converting bytes to ascii

2009-01-15 Thread Anjanesh Lekshminarayanan
The problem seems be solved with urllib.request.urlretrieve() I think the binary information read() was giving had headers like content-size - but not HTTP headers. The first couple of bytes indicate how much content to read and after reading that content, the next set of bytes indicate the next

Client Socket Connection to Java server

2009-01-15 Thread TechieInsights
I am having problems with a socket connection to a Java server. In java I just open the socket, pass the length and then pass the bits across the socket. I created a socket object: import socket class MySocket: def __init__(self, host='localhost', port = 28192, buffsize = 1024):

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread mario ruggier
On Jan 16, 2:30 am, ajaksu wrote: > On Jan 15, 8:21 pm, mario ruggier wrote: > > > OK! Here's a small script to make it easier... > > Thanks! I think I found a quick way around the restrictions (correct > me if I borked it), but I think you can block this example by > resetting your globals/built

Re: Python Style Guide Questions

2009-01-15 Thread Terry Reedy
koranthala wrote: Hi, Which is more advisable? import x b = x.a or from x import a b = a If I know I want just one thing from x, I tend to use latter. I also like 'import xyzlib as x' I read in Learning Python that it is always better to use the former - especially since na

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-15 Thread Russ P.
On Jan 15, 12:21 pm, Bruno Desthuilliers wrote: > Once again, the important point is that there's a *clear* distinction > between interface and implementation, and that you *shouldn't* mess with > implementation. If you "*shouldn't* mess with the implementation", then what is wrong with enforcin

Re: English-like Python

2009-01-15 Thread Tobias Andersson
The Music Guy skrev: Just out of curiousity, have there been any attempts to make a version of Python that looks like actual English text? I mean, so much of Python is already based on the English language that it seems like the next natural step would be to make a programming language which is a

Re: Python Style Guide Questions

2009-01-15 Thread Steven D'Aprano
On Thu, 15 Jan 2009 22:13:06 -0800, koranthala wrote: > Hi, >Which is more advisable? > import x > b = x.a > or > from x import a > b = a > >I read in Learning Python that it is always better to use the > former Perhaps not "always", but often. > - especially since namespa

Python Style Guide Questions

2009-01-15 Thread koranthala
Hi, Which is more advisable? import x b = x.a or from x import a b = a I read in Learning Python that it is always better to use the former - especially since namespace wont be dirtied. But, doing that with PEP 8 together causes my code to look rather cluttered. Reason being tha

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread Martin v. Löwis
> s = urandom(10).encode('hex') > > AttributeError: 'bytes' object has no attribute 'encode' py> binascii.hexlify(os.urandom(10)) b'92b91d5734a9fe562f23' Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

multiprocessing vs. distributed processing

2009-01-15 Thread James Mills
I've noticed over the past few weeks lots of questions asked about multi-processing (including myself). For those of you new to multi-processing, perhaps this thread may help you. Some things I want to start off with to point out are: "multiprocessing will not always help you get things done fast

Re: English-like Python

2009-01-15 Thread Paul Rubin
The Music Guy writes: > ...might be translated as... > >>> Import the operating system module. http://coboloncogs.org -- http://mail.python.org/mailman/listinfo/python-list

Re: English-like Python

2009-01-15 Thread Chris Rebert
On Thu, Jan 15, 2009 at 5:02 PM, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be t

Re: English-like Python

2009-01-15 Thread James Mills
On Fri, Jan 16, 2009 at 11:02 AM, The Music Guy wrote: > Just out of curiousity, have there been any attempts to make a version > of Python that looks like actual English text? I mean, so much of Python > is already based on the English language that it seems like the next > natural step would be

English-like Python

2009-01-15 Thread The Music Guy
Just out of curiousity, have there been any attempts to make a version of Python that looks like actual English text? I mean, so much of Python is already based on the English language that it seems like the next natural step would be to make a programming language which is actually a spoken one.

problem in implementing multiprocessing

2009-01-15 Thread gopal mishra
Hello, I am trying to implement the multiprocessing in my application to take advantage of multiple cores. I have created two Separate process something like this. que = Queue Process(target = getData, args=(que , section, MdbFile,)).start() Process(target = getData, args=(que , section, MdbFil

Re: Beginner: Data type conversion question

2009-01-15 Thread flagg
On Jan 15, 9:16 pm, Chris Rebert wrote: > On Thu, Jan 15, 2009 at 9:09 PM, flagg wrote: > > I am still fairly new to python and programming in general.  My > > question is regarding data conversion, I am working on a script that > > will edit dns zone files, one of the functions i wrote handles >

Re: vb2py status?

2009-01-15 Thread alex23
On Jan 16, 3:17 pm, axtens wrote: > So is vb2py dead? If not, any idea when it'll support python 3? You're always better off asking at the project site than here, but given it hasn't been updated since Feb 2004 I think it's safe to say the project is dead. But it *is* open source, so feel free t

Re: Beginner: Data type conversion question

2009-01-15 Thread Chris Rebert
On Thu, Jan 15, 2009 at 9:09 PM, flagg wrote: > I am still fairly new to python and programming in general. My > question is regarding data conversion, I am working on a script that > will edit dns zone files, one of the functions i wrote handles > updating the serial number. > Our zone files use

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread Paul Rubin
"James Mills" writes: > >>> "".join([hex(c) for c in os.urandom(10)]) > '0x540x6c0xdf0xd90xe10x7c0x330x370x9a0x8' That doesn't look so good, because of all the 0x. -- http://mail.python.org/mailman/listinfo/python-list

Library for extracting new content from email reply messages?

2009-01-15 Thread Bernard Rankin
Hello, I'm looking to build a simple mostly email-based trouble ticket system. (I've yet to find a ready-made python solution that is both simple and well designed) Is there a Python email parsing library that can assist in extracting new content from messages that have been sent in reply

Beginner: Data type conversion question

2009-01-15 Thread flagg
I am still fairly new to python and programming in general. My question is regarding data conversion, I am working on a script that will edit dns zone files, one of the functions i wrote handles updating the serial number. Our zone files use the date as the first part of the serial and a two digit

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-15 Thread Paul Rubin
Michele Simionato writes: > Or perhaps it is you who changed? I can only speak for myself, but > when I first met Python (coming from Basic, Pascal, Fortran, > Mathematica, Maple) it was the best language I could imagine. I would say Algol 60 and Lisp were great languages the same way the Burroug

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread James Mills
On Fri, Jan 16, 2009 at 2:46 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > gert writes: >> s = urandom(10).encode('hex') >> AttributeError: 'bytes' object has no attribute 'encode' > > Oh, Python 3. It's done some different way, someone else will have to > specify. I'm still using 2

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-15 Thread Michele Simionato
On Jan 15, 8:02 am, Paul Rubin wrote: > I'd say there was a time Lisp worked the right way, and a time C > worked the right way, and maybe a time Python worked the right way, > and for a while, Algol 60 was perfection embodied.  But times have > changed more than thos

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread Paul Rubin
gert writes: > s = sha1(bytes(random(),'utf-8')).hexdigest() > i found this, looks let say strange. But it works :) Be careful, if you're relying on the uniqueness and unpredictability of this number for program security, that random() isn't designed for such purposes. Use os.urandom instead. --

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread Paul Rubin
gert writes: > s = urandom(10).encode('hex') > AttributeError: 'bytes' object has no attribute 'encode' Oh, Python 3. It's done some different way, someone else will have to specify. I'm still using 2.x. -- http://mail.python.org/mailman/listinfo/python-list

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-15 Thread Paul Rubin
"Rhodri James" writes: > It strikes me that what you actually want to write is the script that > scans your C data structure There is not a C data structure at the moment. It's all Python. -- http://mail.python.org/mailman/listinfo/python-list

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-15 Thread Paul Rubin
Terry Reedy writes: > > Right. And if the file is large enough that even parsing all the > > records to check the fields takes hours, well, that's where I'm at. > > So what is the problem? Let it run overnight. The idea of buying faster and faster computers is to not have to wait overnight.

Re: Lazy List Generator Problem

2009-01-15 Thread alex23
On Jan 16, 12:42 pm, Mark Hahnenberg wrote: > When I execute this code, the numbers 2,3,4,...,11 are printed (i.e. > nothing gets filtered out).  Could anyone explain why this is > happening?  I generally understand generators, and my hypothesis is > that reassigning to nats the result of filterin

Re: Injecting a global into a defined function??

2009-01-15 Thread James Mills
On Fri, Jan 16, 2009 at 1:59 PM, Cong Ma wrote: > I've thought of this too, but it turns out those functions are related to each > other very loosely. They do a lot of completely different things independently > and have just one common global variable to share. IMHO it would reduce the > readabil

Re: Injecting a global into a defined function??

2009-01-15 Thread James Mills
On Fri, Jan 16, 2009 at 4:28 AM, Cong Ma wrote: > I'd appreciate your hints on this problem. I'm writing a module in which > several > functions can alter the value of a global variable (I know this sounds evil, > please forgive me...). What I'm trying to do is to eliminate the "global foo" > lin

Re: Injecting a global into a defined function??

2009-01-15 Thread Cong Ma
Terry Reedy wrote: > Not to me. You are using the module as a singleton class. The > alternative is to write a class, make the functions methods, and > instantiate the class. If that instance must be a singleton, more work > is required. If multiple instances make sense, you can go the class > r

One Bug of Python 3.0

2009-01-15 Thread Wayne Huang
I met a bug of CGIXMLRPCRequestHandler in Python3.0. Because of the bug, I couldn't use RPC in Apache CGI. The version of my Python 3.0 is "Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] win32". The code of my client is follow. s = xmlrpc.client.ServerProxy('http://loc

Re: spam on the list - how are things now?

2009-01-15 Thread James Mills
On Fri, Jan 16, 2009 at 1:30 PM, wrote: > We've been running SpamBayes on the news-to-mail gateway on mail.python.org > for a couple weeks now. To me it seems like the level of spam leaking onto > the list has dropped way down but I'd like some feedback from people who > read the python-list@pyt

Re: process/thread instances and attributes

2009-01-15 Thread James Mills
After some work ... I've taken Laszlo's suggestion of using Value (shared memory) objects to share state between the -pseudo- Process (manager) object and it's underlying multiprocessing.Process instance (and subsequent process): Here is the code: #!/usr/b

spam on the list - how are things now?

2009-01-15 Thread skip
We've been running SpamBayes on the news-to-mail gateway on mail.python.org for a couple weeks now. To me it seems like the level of spam leaking onto the list has dropped way down but I'd like some feedback from people who read the [email protected] mailing list on the topic. Thanks, --

Re: optimizing large dictionaries

2009-01-15 Thread Paul McGuire
On Jan 15, 5:31 pm, Per Freem wrote: > ...the aKeys are very small (less than 100) where > as the bKeys are the ones that are in the millions.  so in that case, > doing a Try-Except on aKey should be very efficient, since often it > will not fail, ... Do you know the aKeys in advance? If so, the

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread Mark Wooding
mario ruggier writes: > 2009-01-15 22:26:18,704 ERROR [evoque] AttributeError: 'function' > object has no attribute 'func_globals': File "", line 1, in > Damn. So that doesn't work. :-( > But even if inspect did have the func_globals attribute, the "open" > builtin will not be found on __bu

Re: Suggested improvements for IDLE (non-official)

2009-01-15 Thread Tim H
r wrote: On Jan 14, 4:43 pm, Terry Reedy wrote: [snip] I think the 'main' IDLE maintainer is no longer active. I think someone who would do more than fix critical bugs might be welcome. Hello Terry, That's what i was beginning to think. I am not quite ready (as far as my skills are concerned

Lazy List Generator Problem

2009-01-15 Thread Mark Hahnenberg
I'm trying to make a lazy, (theoretically) infinite prime number sieve using generators. The code I have thus far is: #!/usr/bin/env python import itertools def sieve(): nats = naturals(2) while True: elem = nats.next() yield elem nats = itertools.ifilterfalse(lambda x:

Re: Python 3 isinstance

2009-01-15 Thread Rhamphoryncus
On Jan 14, 3:14 pm, "Lambert, David W (S&T)" wrote: > Please, why isn't a set permitted as the second argument to isinstance? The real problem is it would be misleading. isinstance(a, myset) suggests implementation like type(a) in myset, but it's really any (isinstance(a, t) for t in myset). If

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-15 Thread Rhodri James
On Thu, 15 Jan 2009 17:13:41 -, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: Roy Smith writes: C is not evil. It's a tool. Would you call a hammer evil because it's not very good at driving screws? I would call a hammer evil if it were built in a way that made it unnecessaril

Re: Convention vs. fascism

2009-01-15 Thread Aaron Brady
On Jan 15, 6:41 pm, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 10:24:19 +1100, Ben Finney wrote: > > Steven D'Aprano writes: > > >> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > > >> > Steven D'Aprano writes: > > >> >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > > >

Re: Ordering of urlencoded tuples incorrect

2009-01-15 Thread John Machin
On Jan 16, 11:59 am, [email protected] wrote: > I'm having problems with the ordering of the tuples produced by > urllib.urlencode.  Taking an example straight from the docs and so > doing the following: What are "the docs" you are reading that include such an example? The docs distributed

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-15 Thread Rhodri James
On Thu, 15 Jan 2009 17:07:00 -, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: Luis Zarrabeitia writes: No, copy and paste from the original data structures would eliminate those mismatches. The whole point is that would be possible if Python had data structure definitions ("type

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread ajaksu
On Jan 15, 8:21 pm, mario ruggier wrote: > OK! Here's a small script to make it easier... Thanks! I think I found a quick way around the restrictions (correct me if I borked it), but I think you can block this example by resetting your globals/builtins: exprs = [ '(x for x in range(1)).gi_fr

Re: Alphametric fun with Python

2009-01-15 Thread Terry Reedy
[email protected] wrote: Raymond Hettinger: for simple programs that take minutes to write and get the job done. Thank you for posting this. It illustrates well the point you intended. For fun here's a specific example: from csp import Problem, timing print "SEND+MORE=MONEY problem:

Re: Ordering of urlencoded tuples incorrect

2009-01-15 Thread MRAB
[email protected] wrote: I'm having problems with the ordering of the tuples produced by urllib.urlencode. Taking an example straight from the docs and so doing the following: import urllib ... params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})

Re: Convention vs. fascism

2009-01-15 Thread Ben Finney
Steven D'Aprano writes: > But by focusing on such a small aspect of my post (a quarter of my > text), It clearly was important to you, since you phrased it in highly emotive terms (and even, by your account, had to scale the emotion back a little). So, I don't think the proportion of number-of-c

Soap Client

2009-01-15 Thread DougJrs
Good Evening Everyone, I am working to create a Soap client in Python using wsdl2py. So far I have been pretty successful in creating most of the client, but I am having trouble figuring out how to change the content of the message that is being sent. After running wsdl2py I have created this cl

Re: except sqlite3.Error as e:

2009-01-15 Thread gert
On Jan 16, 1:47 am, gert wrote: > except sqlite3.Error as e: >     ERROR = "Error " + ... > > how does except work in python3 ? except sqlite3.Error as e: ERROR = "Error " + e.args[0] oops i thought it did not work somehow in 3.0 but it does :) -- http://mail.python.org/mailman/listinfo/pytho

Ordering of urlencoded tuples incorrect

2009-01-15 Thread benlucas99
I'm having problems with the ordering of the tuples produced by urllib.urlencode. Taking an example straight from the docs and so doing the following: import urllib ... params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) print params The documentation fo

except sqlite3.Error as e:

2009-01-15 Thread gert
except sqlite3.Error as e: ERROR = "Error " + ... how does except work in python3 ? -- http://mail.python.org/mailman/listinfo/python-list

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-15 Thread Ben Sizer
On Jan 14, 4:37 pm, Ivan Illarionov wrote: > On Jan 14, 1:49 pm, Ben Sizer wrote: > > > No, I don't want to do anything with sys.path apart from see it. I > > just wanted my original question answered, not a guess at my intent > > and a solution for something I'm not doing. ;) Thanks though! > >

Re: Convention vs. fascism

2009-01-15 Thread Steven D'Aprano
On Fri, 16 Jan 2009 10:24:19 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: >> >> > Steven D'Aprano writes: >> > >> >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: >> >> >> >> > Familiarize yourself with PEP8 for n

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread gert
On Jan 16, 1:20 am, Paul Rubin wrote: > gert writes: > > s = sha1(random()).hexdigest() > > > TypeError: object supporting the buffer API required, > > > How does sha1 work in python3.0 please ? > > sha1 hashes strings, not numbers.  Try using str(random()).  But if

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread gert
On Jan 16, 1:14 am, gert wrote: > from random import random > from hashlib import sha1 > s = sha1(random()).hexdigest() > > TypeError: object supporting the buffer API required, > > How does sha1 work in python3.0 please ? s = sha1(bytes(random(),'utf-8')).hexdigest() i found this, looks let say

Re: [python3.0] s = sha1(random()).hexdigest()

2009-01-15 Thread Paul Rubin
gert writes: > s = sha1(random()).hexdigest() > > TypeError: object supporting the buffer API required, > > How does sha1 work in python3.0 please ? sha1 hashes strings, not numbers. Try using str(random()). But if you want some random hex digits, try os.urandom(10).encode('hex') rather than

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-15 Thread Terry Reedy
Paul Rubin wrote: Terry Reedy writes: I do not see any connection, really, between what you describe above and your desire for static type-checking expressed elsewhere. When I was regularly doing analysis of empirical data files, I learned (sometimes the hard way, as you describe above) to **A

[python3.0] s = sha1(random()).hexdigest()

2009-01-15 Thread gert
from random import random from hashlib import sha1 s = sha1(random()).hexdigest() TypeError: object supporting the buffer API required, How does sha1 work in python3.0 please ? -- http://mail.python.org/mailman/listinfo/python-list

Re: optimizing large dictionaries

2009-01-15 Thread Christian Heimes
Per Freem schrieb: > 1] is Try-Except really slower? my dict actually has two layers, so > my_dict[aKey][bKeys]. the aKeys are very small (less than 100) where > as the bKeys are the ones that are in the millions. so in that case, > doing a Try-Except on aKey should be very efficient, since often

Re: optimizing large dictionaries

2009-01-15 Thread Steven D'Aprano
On Thu, 15 Jan 2009 14:49:29 -0800, bearophileHUGS wrote: > Matimus, your suggestions are all good. > > Try-except is slower than: > if x in adict: ... else: ... Not according to my tests. >>> def tryexcept(D, key): ... try: ... return D[key] ... except KeyError: ...

Re: Python Crashes

2009-01-15 Thread David Bolen
koranthala writes: > Could anyone guide me on this? I have been facing this issue for a > day, and cannot seem to solve it. We had a scheduling system that had a similar "once in a long while hard Windows-process crash" which after a bunch of work to try to track down the source, the most ro

Re: optimizing large dictionaries

2009-01-15 Thread Paul Rubin
Per Freem writes: > 2] is there an easy way to have nested defaultdicts? ie i want to say > that my_dict = defaultdict(defaultdict(int)) -- to reflect the fact > that my_dict is a dictionary, whose values are dictionary that map to > ints. but that syntax is not valid. my_dict = defaultdict(lambd

Re: optimizing large dictionaries

2009-01-15 Thread Per Freem
thanks to everyone for the excellent suggestions. a few follow up q's: 1] is Try-Except really slower? my dict actually has two layers, so my_dict[aKey][bKeys]. the aKeys are very small (less than 100) where as the bKeys are the ones that are in the millions. so in that case, doing a Try-Except o

Re: Convention vs. fascism

2009-01-15 Thread Ben Finney
Steven D'Aprano writes: > On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > > > Steven D'Aprano writes: > > > >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: > >> > >> > Familiarize yourself with PEP8 for naming and > >> > coding-conventions first. > >> > >> Enough of th

Re: Executing global code

2009-01-15 Thread MRAB
Steven D'Aprano wrote: > On Thu, 15 Jan 2009 17:50:54 +0100, Peter Otten wrote: > >> Jakub Debski wrote: >> >>> Is it possible to execute global code (module-level code) more than >>> once keeping the state of global variables? This means no reload() and >>> no moving the code to a function. >> Yo

Re: report on building of python 2.5.2 under msys under wine on linux.

2009-01-15 Thread Luke Kenneth Casson Leighton
> practical decision, due to /bin/sh.exe messing around and stopping > python.exe from running! (under cmd.exe it's fine. i have to do a > bit more investigation: http://bugs.python.org/issue4956 found it. -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread mario ruggier
On Jan 15, 11:35 pm, Terry Reedy wrote: > Peter Otten wrote: > > List comprehensions delete the helper variable after completion: > > I do not believe they did in 2.4.  Not sure of 2.5.  There is certainly >   a very different implementation in 3.0 and, I think, 2.6.  OP > neglected to mention Pyt

Re: Import functions in current namespace

2009-01-15 Thread Markus Schreyer
Wow.. :) I think this is one kind of a stupid question.. ;) Anyway.. thanks a lot.. :) -- http://mail.python.org/mailman/listinfo/python-list

How to verify whether a process got hanged or still alive.

2009-01-15 Thread neel
Hi There, I want to check the health of IE process using python. I am running an application on IE. I have to verify that the application is not crashing the IE. Is there any module which can help me in getting the process status? Thanks, Neel -- http://mail.python.org/mailman/listinfo/python-lis

How to verify whether a process got hanged or still alive.

2009-01-15 Thread neel
Hi There, I want to check the health of IE process using python. I am running an application on IE. I have to verify that the application is not crashing the IE. Is there any module which can help me in getting the process status? Thanks, Neel -- http://mail.python.org/mailman/listinfo/python-lis

logging multiple messages

2009-01-15 Thread Daniel
I was fighting with a problem all day that was producing multiple messages in my logging output. The problem was related to the fact that I was defining logging handlers multiple times. I found the following posting from a few years ago that related to my problem: http://groups.google.com/group/

Re: optimizing large dictionaries

2009-01-15 Thread Steven D'Aprano
On Thu, 15 Jan 2009 23:22:48 +0100, Christian Heimes wrote: >> is there anything that can be done to speed up this simply code? right >> now it is taking well over 15 minutes to process, on a 3 Ghz machine >> with lots of RAM (though this is all taking CPU power, not RAM at this >> point.) > > cl

Re: Python DateTime Manipulation

2009-01-15 Thread Jervis Whitley
On Fri, Jan 16, 2009 at 9:19 AM, Kingston wrote: > I have a user input a date and time as a string that looks like: > "200901010100" but I want to do a manipulation where I subtract 7 days > from it. > > The first thing I tried was to turn the string into a time with the > format "%Y%m%d%H%M" and

Re: newbie OOP question (what's the analogue to java interfaces in Python?)

2009-01-15 Thread Benjamin Kaplan
On Thu, Jan 15, 2009 at 4:28 PM, Larry Caruso wrote: > I'm an old time C programmer, but a newbie to OOP and Python. One OOP > book I'm reading, "Holub on Patterns," discusses Java Interfaces in some > detail (see http://en.wikipedia.org/wiki/Interface_(Java) for example) but > with limited time

Re: optimizing large dictionaries

2009-01-15 Thread bearophileHUGS
Matimus, your suggestions are all good. Try-except is slower than: if x in adict: ... else: ... A defaultdict is generally faster (there are some conditions when it's not faster, but they aren't much common. I think it's when the ratio of duplicates is really low), creating just a tuple instead of

Re: Possible bug in Tkinter - Python 2.6

2009-01-15 Thread Terry Reedy
Eric Brunel wrote: Hi all, I found a behaviour that might be a bug in Tkinter for Python 2.6. Here is the script: - from Tkinter import * from tkMessageBox import * from tkFileDialog import * root = Tk() def ask_file(): file_name = askopenfilename() print fil

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread Steven D'Aprano
On Thu, 15 Jan 2009 07:56:02 -0800, mario ruggier wrote: > On Jan 15, 4:06 pm, Steven D'Aprano cybersource.com.au> wrote: > > Hi Steve! > >> > class GetItemEvaluator(object): >> >     def __init__(self): >> >         self.globals = globals() # some dict (never changes) > > Ya, this is just a b

Re: Executing global code

2009-01-15 Thread Steven D'Aprano
On Thu, 15 Jan 2009 17:50:54 +0100, Peter Otten wrote: > Jakub Debski wrote: > >> Is it possible to execute global code (module-level code) more than >> once keeping the state of global variables? This means no reload() and >> no moving the code to a function. > > You have a module containing e.

Re: Convention vs. fascism (was: General direction)

2009-01-15 Thread Steven D'Aprano
On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote: >> >> > Familiarize yourself with PEP8 for naming and coding-conventions >> > first. >> >> Enough of the PEP8-fascism please. It is not compulsory to

Re: Import functions in current namespace

2009-01-15 Thread Chris Rebert
On Thu, Jan 15, 2009 at 2:35 PM, Markus Schreyer wrote: > Hi, > we embedded python into our application via Swig. Now we like to wrap the > raw API functionality into a nicer more handleable module, but instead of > repeating every function in this wrapper i thought about importing them into > the

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread Terry Reedy
mario ruggier wrote: On Jan 15, 4:06 pm, Steven D'Aprano wrote: Hi Steve! class GetItemEvaluator(object): def __init__(self): self.globals = globals() # some dict (never changes) Ya, this is just a boiled down sample, and for simplicity I set to to the real globals(), so of cour

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread Terry Reedy
Peter Otten wrote: List comprehensions delete the helper variable after completion: I do not believe they did in 2.4. Not sure of 2.5. There is certainly a very different implementation in 3.0 and, I think, 2.6. OP neglected to mention Python version he tested on. Code meant to run on 2

Import functions in current namespace

2009-01-15 Thread Markus Schreyer
Hi, we embedded python into our application via Swig. Now we like to wrap the raw API functionality into a nicer more handleable module, but instead of repeating every function in this wrapper i thought about importing them into the namespace of the wrapper module. I like to give you an example of

Re: Python DateTime Manipulation

2009-01-15 Thread Chris Rebert
On Thu, Jan 15, 2009 at 2:19 PM, Kingston wrote: > I have a user input a date and time as a string that looks like: > "200901010100" but I want to do a manipulation where I subtract 7 days > from it. > > The first thing I tried was to turn the string into a time with the > format "%Y%m%d%H%M" and

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread mario ruggier
On Jan 15, 10:35 pm, ajaksu wrote: > On Jan 15, 1:56 pm, mario ruggier wrote: > > > As > > I mentioned in another thread, the real application behind all this is > > one of the *few* secure templating systems around. Some info on its > > security is at:http://evoque.gizmojo.org/usage/restricted/

  1   2   3   >