Re: Python object overhead?

2007-03-24 Thread Felipe Almeida Lessa
On 3/23/07, Bjoern Schliessmann [EMAIL PROTECTED] wrote: (Note that almost everything in Python is an object!) Could you tell me what in Python isn't an object? Are you counting old-style classes and instances as not objects? -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: functions, classes, bound, unbound?

2007-03-24 Thread Felipe Almeida Lessa
On 24 Mar 2007 20:24:36 -0700, 7stud [EMAIL PROTECTED] wrote: Here is some example code that produces an error: [snip] Why do people absolutely *love* to do weird and ugly things with Python? Contests apart, I don't see lots of people trying this kind of things on other (common) languages. Say

Re: Can I reverse eng a .pyc back to .py?

2007-02-20 Thread Felipe Almeida Lessa
On 2/19/07, Steven W. Orr [EMAIL PROTECTED] wrote: The short story is that someone left, but before he left he checked in a .pyc and then both the directory was destroyed and the backups all got shredded (don't ask*). Is there anything that can be extracted? I looked on the web and the subject

Re: help on packet format for tcp/ip programming

2007-02-07 Thread Felipe Almeida Lessa
On 7 Feb 2007 19:14:13 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] struct module pack and unpack will only work for fixed size buffer : pack('1024sIL', buffer, count. offset) but the buffer size can vary from one packet to the next :-( Then send the size of the buffer before the buffer, so the

Re: maximum number of threads

2007-01-10 Thread Felipe Almeida Lessa
On 1/10/07, Gabriel Genellina [EMAIL PROTECTED] wrote: At Wednesday 10/1/2007 04:38, Paul Sijben wrote: Does anyone know what it going on here and how I can ensure that I have all the threads I need? Simply you can't, as you can't have 1 open files at once. Computer resources are not

Re: maximum number of threads

2007-01-10 Thread Felipe Almeida Lessa
On 1/10/07, Laurent Pointal [EMAIL PROTECTED] wrote: This is a system configurable limit (up to a maximum). See ulimit man pages. test ulimit -a to see what are the current limits, and try with ulimit -u 2000 to modify the maximum number of user process (AFAIK each thread

Re: Determine an object is a subclass of another

2007-01-09 Thread Felipe Almeida Lessa
On 9 Jan 2007 07:01:31 -0800, abcd [EMAIL PROTECTED] wrote: anyways, is there a way to check without having an instance of the class? In [1]: class A: ...: pass ...: In [2]: class B(A): ...: pass ...: In [3]: issubclass(B, A) Out[3]: True In [4]: isinstance(B(), B)

Re: Suitability for long-running text processing?

2007-01-08 Thread Felipe Almeida Lessa
On 1/8/07, tsuraan [EMAIL PROTECTED] wrote: [snip] The loop is deep enough that I always interrupt it once python's size is around 250 MB. Once the gc.collect() call is finished, python's size has not changed a bit. [snip] This has been tried under python 2.4.3 in gentoo linux and python 2.3

Re: Suitability for long-running text processing?

2007-01-08 Thread Felipe Almeida Lessa
On 1/8/07, tsuraan [EMAIL PROTECTED] wrote: I just tried on my system (Python is using 2.9 MiB) a = ['a' * (1 20) for i in xrange(300)] (Python is using 304.1 MiB) del a (Python is using 2.9 MiB -- as before) And I didn't even need to tell the garbage collector to do its

Re: Why less emphasis on private data?

2007-01-07 Thread Felipe Almeida Lessa
On 07 Jan 2007 02:01:44 -0800, Paul Rubin http://phr.cx@nospam.invalid wrote: Dennis Lee Bieber [EMAIL PROTECTED] writes: __ (two leading underscores) results in name-mangling. This /may/ be used to specify private data, but is really more useful when one is designing with multiple

Re: how to find the longst element list of lists

2007-01-07 Thread Felipe Almeida Lessa
On 1/7/07, Michael M. [EMAIL PROTECTED] wrote: How to find the longst element list of lists? s1 = [q, e, d] s2 = [a, b] s3 = [a, b, c, d] s = [s1, s2, s3] s.sort(key=len, reverse=True) print s[0] is s3 print s[1] is s1 print s[2] is s2 sx1, sx2, sx3 = s print 'sx1:', sx1 print 'sx2:', sx2

Re: Packaging up a Python/Twisted Matrix application...

2007-01-04 Thread Felipe Almeida Lessa
On 1/4/07, Chaz Ginger [EMAIL PROTECTED] wrote: I have a rather large Python/Twisted Matrix application that will be run on Windows, Linux and perhaps Macs. I was wondering if there are any tools that can be used to create an installer that will bring in Python, Twisted Matrix, my application

Re: A python library to convert RTF into PDF ?

2007-01-03 Thread Felipe Almeida Lessa
On 3 Jan 2007 10:52:02 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have tried to convert them to tex using OpenOffice, but the result is ugly as hell. Why not use OO.org to convert DOC to PDF? It does so natively, IIRC. -- Felipe. --

Re: static object

2007-01-03 Thread Felipe Almeida Lessa
On 1/3/07, meelab [EMAIL PROTECTED] wrote: I am looking for a way to create a static object or a static class - terms might be inappropriate - having for instance: An example will speak better than me: class Card(object): __cards = {} def __init__(self, number, suit):

Re: Are all classes new-style classes in 2.4+?

2006-12-31 Thread Felipe Almeida Lessa
On 31 Dec 2006 03:57:04 -0800, Isaac Rodriguez [EMAIL PROTECTED] wrote: I am using Python 2.4, and I was wondering if by default, all classes are assumed to be derived from object. This won't tell you advantages or disadvantages, but will show you that the default still is the old-style:

Re: A question about unicode() function

2006-12-31 Thread Felipe Almeida Lessa
On 31 Dec 2006 05:20:10 -0800, JTree [EMAIL PROTECTED] wrote: def funUrlFetch(url): lambda url:urllib.urlopen(url).read() This function only creates a lambda function (that is not used or assigned anywhere), nothing more, nothing less. Thus, it returns None (sort of void) no matter what is

Re: BeautifulSoup vs. loose chars

2006-12-26 Thread Felipe Almeida Lessa
On 26 Dec 2006 04:22:38 -0800, placid [EMAIL PROTECTED] wrote: So do you want to remove or replace them with amp; ? If you want to replace it try the following; I think he wants to replace them, but just the invalid ones. I.e., This this amp; that would become This amp; this amp; that

Re: Async callback in python

2006-12-04 Thread Felipe Almeida Lessa
On 4 Dec 2006 20:18:22 -0800, Linan [EMAIL PROTECTED] wrote: 3, If not, where to get the real one(s)? After reading Calvin's mail, you may want to see http://twistedmatrix.com/ . It's an assynchronous library built around the concept of deferreds (think of callbacks). You may like it =). Cya,

Re: global name 'self' is not defined

2006-12-02 Thread Felipe Almeida Lessa
On 2 Dec 2006 10:42:28 -0800, Evan [EMAIL PROTECTED] wrote: Why is it that the first call works fine, but the second tells me 'global name 'self' is not defined'? What I want is to have the dictionary 'estoc' available in my calling script. Well, you have not posted the code that is causing

Re: What are python closures realy like?

2006-12-01 Thread Felipe Almeida Lessa
On 12/1/06, Karl Kofnarson [EMAIL PROTECTED] wrote: [snip] def fun_basket(f): common_var = [0] def f1(): print common_var[0] common_var[0]=1 def f2(): print common_var[0] common_var[0]=2 if f == 1: return f1 if f == 2:

Re: Event driven server that wastes CPU when threaded doesn't

2006-10-29 Thread Felipe Almeida Lessa
29 Oct 2006 14:18:02 -0800, Paul Rubin http://phr.cx@nospam.invalid: Nick Vatamaniuc [EMAIL PROTECTED] writes: The simplest solution is to change your system and put the DB on the same machine thus greatly reducing the time it takes for each DB query to complete (avoid the TCP stack

Re: How to print a file in binary mode

2006-10-22 Thread Felipe Almeida Lessa
22 Oct 2006 06:33:50 -0700, Lucas [EMAIL PROTECTED]: I known how to do it.read() return a string. so1) bytes = read(1) #read the file by bit.2) chrString= ord(bytes) #convert the string to ASCII.3) print numberToBinary(chrString) #convert the ASCII to Binary using my function.4)

Re: PATCH: Speed up direct string concatenation by 20+%!

2006-09-29 Thread Felipe Almeida Lessa
28 Sep 2006 19:07:23 -0700, Larry Hastings [EMAIL PROTECTED]: THE BENCHMARKS Benchmark 1: def add(a, b, c, ... t): return a + b + c + ... + t for i in range(1000): add(aaa, bbb, ccc, ..., ttt) [snip] What about a + b? Or a + b + c? Does it have a large overhead on small

Re: QOTW (was Re: does anybody earn a living programming in python?)

2006-09-26 Thread Felipe Almeida Lessa
2006/9/26, Sybren Stuvel [EMAIL PROTECTED]: Aahz enlightened us with: Fredrik Lundh [EMAIL PROTECTED] wrote: well, if you're only watching mtv, it's easy to think that there's obviously not much demand for country singers, blues musicians, British hard rock bands, or melodic death metal

Re: does anybody earn a living programming in python?

2006-09-25 Thread Felipe Almeida Lessa
2006/9/25, Robert Kern [EMAIL PROTECTED]: walterbyrd wrote: If so, I doubt there are many. I wonder why that is? Well I do. So do the other dozen or so developers at my company. We're looking to hire a few more, in fact. And there are also those ReportLab guys: www.reportlab.com --

Re: What is the best way to get a web page?

2006-09-24 Thread Felipe Almeida Lessa
24 Sep 2006 10:09:16 -0700, Rainy [EMAIL PROTECTED]: Functionally they are the same, but third line included in Firefox. Opera View Source command produces the same result as Python. [snip] It's better to compare with the result of a downloader-only (instead of a parser), like wget on Unix.

Re: Decorator cllass hides docstring from doctest?

2006-09-21 Thread Felipe Almeida Lessa
2006/9/21, Berthold Höllmann [EMAIL PROTECTED]: Saving the following code to a file and running the code through python does not give the expected error. disableling the @decor line leads to the expected error message. Is this a bug or an overseen feature? Try the new_decor class described

Re: How to stop an [Rpyc] server thread?

2006-09-11 Thread Felipe Almeida Lessa
7 Sep 2006 23:38:08 -0700, Tal Einat [EMAIL PROTECTED]: I'm not an expert in socket programming, but I can't see the correlation between the listener socket being in timeout mode and a different behavior the other sockets.. Anyhow the main goal is being able to shut down the thread of the

Re: No ValueError for large exponents?

2006-09-10 Thread Felipe Almeida Lessa
2006/9/6, Robin Becker [EMAIL PROTECTED]: enigmadude wrote: As many have heard, IronPython 1.0 was released. When I was looking through the listed differences between CPython and IronPython, the document mentioned that using large exponents such as 10 ** 735293857239475 will cause CPython

Re: ANN: Pocoo (bulletin board software) 0.1 beta released

2006-09-10 Thread Felipe Almeida Lessa
10 Sep 2006 16:17:08 -0700, Paul Rubin http://phr.cx@nospam.invalid: So, I think it's not worth thinking about writing yet another BBS unless it can handle a Slashdot-sized load on a commodity PC. Python is slow. Psyco helps, but you should use C instead. And yes, I am kidding =) -- Felipe.

Re: Best Middle Tier Architechure?

2006-09-08 Thread Felipe Almeida Lessa
2006/9/7, Butternut Squash [EMAIL PROTECTED]: right now we are using c# and .net remoting in a way that just is not efficient. I want to rewrite a lot of what we do in python. I have seen XML-RPC and soap. Are there other options? It surely depends on what's going to be on the other sides.

Re: best split tokens?

2006-09-08 Thread Felipe Almeida Lessa
8 Sep 2006 13:41:48 -0700, Jay [EMAIL PROTECTED]: Let's say, for instance, that one was programming a spell checker or some other function where the contents of a string from a text-editor's text box needed to be split so that the resulting array has each word as an element. Is there a

Re: Best Middle Tier Architechure?

2006-09-08 Thread Felipe Almeida Lessa
2006/9/8, Butternut Squash [EMAIL PROTECTED]: I have to support multiple applications using different schema and databases. Would like to present as much as a unified interface as possible. I'd recomend CORBA as it supports multiple platforms and languages. SOAP and XML-RPC can be used as

Re: convert loop to list comprehension

2006-09-08 Thread Felipe Almeida Lessa
8 Sep 2006 17:37:02 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED]: 1. Using an _ is an interesting way to use a throw-away variable. Never would I think of that ... but, then, I don't do Perl either :) It's a kind of convention. For example, Pylint complains for all variables you set and don't use

Re: convert loop to list comprehension

2006-09-08 Thread Felipe Almeida Lessa
08 Sep 2006 17:33:20 -0700, Paul Rubin http://phr.cx@nospam.invalid: [EMAIL PROTECTED] writes: print sum( ([i]*n for i,n in enumerate(seq)), []) Wow, I had no idea you could do that. After all the discussion about summing strings, I'm astonished. Why? You already had the answer: summing

Re: python vs java

2006-09-07 Thread Felipe Almeida Lessa
2006/9/7, Bruno Desthuilliers [EMAIL PROTECTED]: I don't think one could pretend writing a cross-platform application without testing it on all targeted platforms. E.g: while creating a free software, you may not have an Apple computer but you may want to be *possible* to run your program

Re: [ANN] IronPython 1.0 released today!

2006-09-07 Thread Felipe Almeida Lessa
2006/9/5, Jim Hugunin [EMAIL PROTECTED]: I'm extremely happy to announce that we have released IronPython 1.0 today! http://www.codeplex.com/IronPython Does IronPython runs Twisted? -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: IronPython 1.0 released today!

2006-09-07 Thread Felipe Almeida Lessa
7 Sep 2006 16:34:56 -0700, Luis M. González [EMAIL PROTECTED]: People are already porting some of these libraries. Those that are written in pure python don't need to be ported, but those that rely on c extensions can be rewritten in c# or any other .NET language. Or in C that is P/Invoked

Re: threading support in python

2006-09-05 Thread Felipe Almeida Lessa
4 Sep 2006 19:19:24 -0700, Sandra-24 [EMAIL PROTECTED]: If there was a mod_dotnet I wouldn't be using CPython anymore. I guess you won't be using then: http://www.mono-project.com/Mod_mono -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: Higher-level OpenGL modules

2006-09-05 Thread Felipe Almeida Lessa
5 Sep 2006 03:44:47 -0700, Leon [EMAIL PROTECTED]: Greetings, Does anybody know of or is working on any python modules that allow for a direct but higher-level interface to OpenGL? For example, quick functions to draw lines, curves, and basic shapes; define hsb color mode; fill and stroke

Re: Client-side TCP socket receiving Address already in use upon connect

2006-09-03 Thread Felipe Almeida Lessa
2006/9/3, Alex Martelli [EMAIL PROTECTED]: Reflecting on the OP's use case, since all connections are forever being made to the same 16 servers, why not tweak thinks a bit to hold those connections open for longer periods of time, using a connection for many send/receive transactions instead

Re: What do you want in a new web framework?

2006-08-30 Thread Felipe Almeida Lessa
2006/8/30, Ben Finney [EMAIL PROTECTED]: re struct unicodedata decimal random logging Queue urlparse email operator cStringIO math cmath sets (merged to the language) itertools os + stat time tempfile glob Not that I use them all the time, but they

Re: GC and security

2006-08-30 Thread Felipe Almeida Lessa
2006/8/30, Les Schaffer [EMAIL PROTECTED]: is there a best practice way to do this? I'm not a cryptographer, but you should really try the function collect() inside the gc module. -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: range of int() type.

2006-08-23 Thread Felipe Almeida Lessa
23 Aug 2006 17:28:48 -0700, KraftDiner [EMAIL PROTECTED]: This is obvious... but how do I crop off the high order bits if necessary? a[0]0x ? min(a[0], 0x) ? -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: List comparison help please

2006-08-20 Thread Felipe Almeida Lessa
20 Aug 2006 14:47:14 -0700, Bucco [EMAIL PROTECTED]: I am trying to compare a list of items to the list of files generated by os.listdir. I am having trouble getting this to work and think I may be going down the wrong path. Please let me know if hter is a better way to do this. THis is

Re: Convert string to mathematical function

2006-08-01 Thread Felipe Almeida Lessa
Em Ter, 2006-08-01 às 18:45 -0700, jeremito escreveu: I am extending python with C++ and need some help. I would like to convert a string to a mathematical function and then make this a C++ function. I may be wrong, but I don't think you can create new C++ functions on-the-fly. At least I

Re: math.pow(x,y)

2006-06-11 Thread Felipe Almeida Lessa
Em Dom, 2006-06-11 às 11:19 -0700, fl1p-fl0p escreveu: import math math.pow(34564323, 456356) will give math range error. how can i force python to process huge integers without math range error? Any modules i can use possibly? 34564323**456356 ? -- Felipe. --

Re: how to get the length of a number

2006-06-11 Thread Felipe Almeida Lessa
Em Dom, 2006-06-11 às 20:10 +, Stan Cook escreveu: Can anyone tell me how to get the length of a number. I know len(string) will get the length of a string, but it doesn't like len(int). I seem to remember something like %s string. I tried to set a variable = to %s int, but that

Re: how to get the length of a number

2006-06-11 Thread Felipe Almeida Lessa
Em Dom, 2006-06-11 às 13:17 -0700, Saketh escreveu: Stan Cook wrote: Can anyone tell me how to get the length of a number. I know len(string) will get the length of a string, but it doesn't like len(int). I seem to remember something like %s string. I tried to set a variable = to %s

Re: how to get the length of a number

2006-06-11 Thread Felipe Almeida Lessa
Em Dom, 2006-06-11 às 22:33 +0200, Sybren Stuvel escreveu: Felipe Almeida Lessa enlightened us with: To see how many decimal digits it has: import math math.ceil(math.log(i, 10)) That doesn't work properly. import math math.ceil(math.log(1, 10)) 4.0 math.ceil

Re: Writing PNG with pure Python

2006-06-09 Thread Felipe Almeida Lessa
Em Sex, 2006-06-09 às 12:30 -0400, Alan Isaac escreveu: It's your code, so you get to license it. But if you wish to solicit patches, a more Pythonic license is IMHO more likely to prove fruitful. Pythonic license? That's new to me. I can figure out what a Python-like license is, but I'm

Re: Killing a thread

2006-06-09 Thread Felipe Almeida Lessa
Em Sex, 2006-06-09 às 13:54 -0700, Manish Marathe escreveu: On 6/9/06, Fredrik Lundh [EMAIL PROTECTED] wrote: Manish Marathe wrote: I am creating threads using my self defined class which inherits the threading.Thread class. I want to know how can I

Re: 10GB XML Blows out Memory, Suggestions?

2006-06-06 Thread Felipe Almeida Lessa
Em Ter, 2006-06-06 às 13:56 +, Paul McGuire escreveu: (just can't open it up like a text file) Who'll open a 10 GiB file anyway? -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: Open Source Charting Tool

2006-06-02 Thread Felipe Almeida Lessa
Em Sex, 2006-06-02 às 15:42 -0500, Larry Bates escreveu: ReportLab Graphics can do 2D and pie charts, but I don't think it does 3D charts yet. www.reporlab.org It does, but I'm not sure if the PNG backend is as good as the PDF one. -- Felipe. --

Re: Open Source Charting Tool

2006-06-02 Thread Felipe Almeida Lessa
Em Sex, 2006-06-02 às 16:56 -0400, A.M escreveu: I can't browse to www.reporlab.org, but I found http://www.reportlab.com/ which has a commercial charting product. Is that what you referring to? ReportLab (the commercial bussiness thing on .com) is where the main developers of ReportLab (a

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Felipe Almeida Lessa
Em Dom, 2006-05-21 às 17:11 +0200, Heiko Wundram escreveu: for node in tree if node.haschildren(): do something with node as syntactic sugar for: for node in tree: if not node.haschildren(): continue do something with node

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Felipe Almeida Lessa
Em Dom, 2006-05-21 às 11:52 -0700, gangesmaster escreveu: Today you can archive the same effect (but not necessarily with the same performance) with: for node in (x for x in tree if x.haschildren()): do something with node true, but it has different semantic meanings I know,

Re: calling upper() on a string, not working?

2006-05-16 Thread Felipe Almeida Lessa
Em Ter, 2006-05-16 às 20:25 +, John Salerno escreveu: it doesn't seem to work. The full code is below if it helps to understand. Why doesn't it work? What does it do, what did you expect it to do? ''.join(set('hi')) 'ih' ''.join(set('HI')) 'IH' ''.join(set('hiHI')) 'ihIH'

Re: New tail recursion decorator

2006-05-10 Thread Felipe Almeida Lessa
Em Ter, 2006-05-09 às 23:30 -0700, Kay Schluehr escreveu: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691 Is it thread safe? -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: NaN handling

2006-05-06 Thread Felipe Almeida Lessa
Em Sex, 2006-05-05 às 16:37 -0400, Ivan Vinogradov escreveu: This works to catch NaN on OSX and Linux: # assuming x is a number if x+1==x or x!=x: #x is NaN This works everywhere: nan = float('nan') . . . if x == nan: # x is not a number -- Felipe. --

Re: problems when unpacking tuple ...

2006-04-22 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-22 às 09:21 -0700, harold escreveu: for line in sys.stdin : try : for a,b,c,d in line.split() : pass except ValueError , err : print line.split() raise err Try this: for a, b, c, d in sys.stdin: print a, b, c, d --

Re: problems when unpacking tuple ...

2006-04-22 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-22 às 14:25 -0300, Felipe Almeida Lessa escreveu: Em Sáb, 2006-04-22 às 09:21 -0700, harold escreveu: for line in sys.stdin : try : for a,b,c,d in line.split() : pass except ValueError , err : print line.split() raise

Re: Problem calling math.cos()

2006-04-22 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-22 às 15:14 -0400, Sambo escreveu: when I import it (electronics) in python.exe in windows2000 and try to use it, it croaks. ??? $ python2.4 Python 2.4.3 (#2, Mar 30 2006, 21:52:26) [GCC 4.0.3 (Debian 4.0.3-1)] on linux2 Type help, copyright, credits or license for more

Re: Performance of Python 2.3 and 2.4

2006-04-22 Thread Felipe Almeida Lessa
Em Dom, 2006-04-23 às 00:20 +0200, Michal Kwiatkowski escreveu: Hi! I was just wondering... Probably there is another factor involved: $ python2.3 Python 2.3.5 (#2, Mar 6 2006, 10:12:24) [GCC 4.0.3 20060304 (prerelease) (Debian 4.0.2-10)] on linux2 Type help, copyright, credits or license

Re: PyLint results?

2006-04-21 Thread Felipe Almeida Lessa
Em Sex, 2006-04-21 às 13:49 -0400, Michael Yanowitz escreveu: I ran the new pylint and my code and I had a few questions on why those are warnings or what I can do to fix them: You can ignore the warnings you don't like with the --disable-msg option. Also, you can add a header to the file to

Re: String To Dict Problem

2006-04-21 Thread Felipe Almeida Lessa
Em Sex, 2006-04-21 às 18:40 -0700, Clodoaldo Pinto escreveu: Only a small problem when I try to evaluate this: safe_eval('True') Change def visitName(self,node, **kw): raise Unsafe_Source_Error(Strings must be quoted, node.name, node) To

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-22 às 03:16 +, Edward Elliott escreveu: If that level of accuracy matters, you might consider generating your rands as integers and then fp-dividing by the sum (or just store them as integers/fractions). Or using decimal module:

Re: Method Call in Exception

2006-04-19 Thread Felipe Almeida Lessa
Em Qua, 2006-04-19 às 16:54 -0700, mwt escreveu: This works when I try it, but I feel vaguely uneasy about putting method calls in exception blocks. What do you put in exception blocks?! So tell me, Brave Pythoneers, is this evil sorcery that I will end up regretting, or is it just plain

Re: Uniquifying a list?

2006-04-18 Thread Felipe Almeida Lessa
Em Ter, 2006-04-18 às 10:31 -0500, Tim Chase escreveu: Is there an obvious/pythonic way to remove duplicates from a list (resulting order doesn't matter, or can be sorted postfacto)? My first-pass hack was something of the form myList = [3,1,4,1,5,9,2,6,5,3,5] uniq = dict([k,None for

Re: extracting a substring

2006-04-18 Thread Felipe Almeida Lessa
Em Ter, 2006-04-18 às 17:25 -0700, [EMAIL PROTECTED] escreveu: Hi, I have a bunch of strings like a53bc_531.txt a53bc_2285.txt ... a53bc_359.txt and I want to extract the numbers 531, 2285, ...,359. Some ways: 1) Regular expressions, as you said: from re import compile find =

Re: filling today's date in a form

2006-04-16 Thread Felipe Almeida Lessa
Em Dom, 2006-04-16 às 19:22 -0400, Kun escreveu: i have a form Which kind of form? Which toolkit? which takes in inputs for a mysql query. one of the inputs is 'date'. normally, a user has to manually enter a date, Enter the date in which kind of control? but i am wondering if there

Re: How to Convert a string into binary

2006-04-15 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-15 às 19:25 +, HNT20 escreveu: is there a way to convert a string into its binary representation of the ascii table.?? I'm very curious... why? And no, I don't have the answer. -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Convert a string into binary

2006-04-15 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-15 às 18:09 -0400, Terry Reedy escreveu: # given string s binchars = [] for c in s: binchars.append(a2b[ord(c)]) Faster: binchars = [a2b[ord(c)] for c in s] -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: requestion regarding regular expression

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 07:47 -0700, BartlebyScrivener escreveu: starts = [i for i, line in enumerate(lines) if line.startswith('(defun')] This line makes a list of integers. enumerate gives you a generator that yields tuples consisting of (integer, object), and by i for i, line you unpack the

Re: zlib and zip files

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 17:14 +0200, Jan Prochazka escreveu: Here is my module for parsing zip files: 1) Have you checked the source of Python's zipfile module? import struct, zlib class ZipHeaderEntry: name = '' offset = 0 uncomlen = 0 comlen = 0 2) You know that those

Re: PEP 359: The make Statement

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 09:31 -0600, Steven Bethard escreveu: [1] Here's the code I used to test it. def make(callable, name, args, block_string): ... try: ... make_dict = callable.__make_dict__ ... except AttributeError: ... make_dict = dict ... block_dict =

Re: instance variable weirdness

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 09:18 -0700, wietse escreveu: def __init__(self, name, collection=[]): Never, ever, use the default as a list. self.collection = collection This will just make a reference of self.collection to the collection argument. inst.collection.append(i) As

Re: instance variable weirdness

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 13:30 -0300, Felipe Almeida Lessa escreveu: To solve your problem, change def __init__(self, name, collection=[]): BaseClass.__init__(self) self.name = name self.collection = collection # Will reuse the list to def __init__(self, name

Re: instance variable weirdness

2006-04-14 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-15 às 04:03 +1000, Steven D'Aprano escreveu: Sometimes you want the default to mutate each time it is used, for example that is a good technique for caching a result: def fact(n, _cache=[1, 1, 2]): Iterative factorial with a cache. try: return _cache[n]

Re: Writing backwards compatible code

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 13:28 -0500, Robert Kern escreveu: Steven D'Aprano wrote: I came across an interesting (as in the Chinese curse) problem today. I had to modify a piece of code using generator expressions written with Python 2.4 in mind to run under version 2.3, but I wanted the code

Re: skip item in list for loop

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 20:33 +0200, Diez B. Roggisch escreveu: def read_lines(inFile): fg = iter(inFile) for line in fg: if pmos4_highv in line: fg.next() else: yield line Just be aware that the fb.next() line can raise an StopIteration

Re: Writing backwards compatible code

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 13:37 -0500, Robert Kern escreveu: Felipe Almeida Lessa wrote: Em Sex, 2006-04-14 às 13:28 -0500, Robert Kern escreveu: Steven D'Aprano wrote: I came across an interesting (as in the Chinese curse) problem today. I had to modify a piece of code using generator

Re: Problem involving sets...

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 15:43 -0700, flamesrock escreveu: Does anyone have a simple solution $ python2.4 Python 2.4.3 (#2, Mar 30 2006, 21:52:26) [GCC 4.0.3 (Debian 4.0.3-1)] on linux2 Type help, copyright, credits or license for more information. l1 = [['c1',1],['c2',2],['c3',4]] l2 =

Re: Remove Whitespace

2006-04-13 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 12:46 +1000, Steven D'Aprano escreveu: Why would you want to call in the heavy sledgehammer of regular expressions for cracking this peanut? And put heavy on that! $ python2.4 -mtimeit -s str = 'D c a V e r \ = d w o r d : 0 0 0 0 0 6 4 0' 'str.replace( , )' 10 loops,

Re: PEP 359: The make Statement

2006-04-13 Thread Felipe Almeida Lessa
Em Qui, 2006-04-13 às 23:17 -0400, Nicolas Fleury escreveu: The callable could have something like a __namespacetype__ that could be use instead of dict. That type would have to implement __setitem__. Or the namespace variable could be a list of tuples. -- Felipe. --

Re: list.clear() missing?!?

2006-04-13 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 09:17 +0400, Sergei Organov escreveu: I, as a newcomer, don't have much trouble understanding the binding vs the assignment by themselves. What does somewhat confuse is dual role of the = operator, -- sometimes it means bind and other times it means assign, right? For me

Re: reading files in small chunks?

2006-04-13 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 13:45 +0800, Rajesh Sathyamoorthy escreveu: I wanted to know why it is more efficient to read a file in smaller chunks ( using file() or open() )? It's more efficient in some cases, and worse on others. It also depends on how you implement the read loop. I won't elaborate

Re: list.clear() missing?!?

2006-04-12 Thread Felipe Almeida Lessa
Em Qua, 2006-04-12 às 12:40 -0700, Raymond Hettinger escreveu: * the existing alternatives are a bit perlish I love this argument =D! perlish... lol... Cheers, -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why new Python 2.5 feature class C() return old-style class ?

2006-04-11 Thread Felipe Almeida Lessa
Em Ter, 2006-04-11 às 06:49 -0700, looping escreveu: But in an other hand, I believe that new-style class are faster to instanciate (maybe I'm wrong...). $ python2.4 -m timeit -s 'class x: pass' 'x()' 100 loops, best of 3: 0.435 usec per loop $ python2.4 -m timeit -s 'class x(object):

Re: Why new Python 2.5 feature class C() return old-style class ?

2006-04-11 Thread Felipe Almeida Lessa
Em Ter, 2006-04-11 às 07:17 -0700, Aahz escreveu: Can, yes. But should it? The whole point of adding the () option to classes was to ease the learning process for newbies who don't understand why classes have a different syntax from functions. Having class C(): pass behave differently

Re: list.clear() missing?!?

2006-04-11 Thread Felipe Almeida Lessa
Em Ter, 2006-04-11 às 10:42 -0600, Steven Bethard escreveu: one of:: del lst[:] lst[:] = [] or if you don't need to modify the list in place, lst = [] Personally, I tend to go Fredrik's route and use the first. I love benchmarks, so as I was testing the options, I

Re: Manipulating sets from the 2.4 C API?

2006-04-11 Thread Felipe Almeida Lessa
Em Ter, 2006-04-11 às 18:55 +0200, Martin v. Löwis escreveu: Dave Opstad wrote: If I want to handle sets should I just use a dictionary's keys and ignore the values, or is there some more explicit set support somewhere I'm not seeing? Indeed, there is. To create a new set, do

Re: list.clear() missing?!?

2006-04-11 Thread Felipe Almeida Lessa
Em Ter, 2006-04-11 às 17:56 +, John Salerno escreveu: Steven Bethard wrote: lst[:] = [] lst = [] What's the difference here? lst[:] = [] makes the specified slice become []. As we specified :, it transforms the entire list into []. lst = [] assigns the value [] to the

Re: Memory limit to dict?

2006-04-11 Thread Felipe Almeida Lessa
Em Ter, 2006-04-11 às 19:45 +0200, Peter Beattie escreveu: I was wondering whether certain data structures in Python, e.g. dict, might have limits as to the amount of memory they're allowed to take up. Is there any documentation on that? Why am I asking? I'm reading 3.6 GB worth of BLAST

Re: list.clear() missing?!?

2006-04-11 Thread Felipe Almeida Lessa
Em Qua, 2006-04-12 às 11:36 +1000, Steven D'Aprano escreveu: On Tue, 11 Apr 2006 19:15:18 +0200, Martin v. Löwis wrote: Felipe Almeida Lessa wrote: I love benchmarks, so as I was testing the options, I saw something very strange: $ python2.4 -mtimeit 'x = range(10); ' 100 loops

Re: python + access + odbc + linux

2006-04-10 Thread Felipe Almeida Lessa
Em Seg, 2006-04-10 às 10:38 -0500, Philippe Martin escreveu: I understand that access can be accessed through an ODBC driver under windows (instead of Jet). I am wondering if the same can be done under Linux. As far as I know, no. But there is that http://mdbtools.sourceforge.net/ that may

Re: About classes and OOP in Python

2006-04-10 Thread Felipe Almeida Lessa
Em Seg, 2006-04-10 às 07:19 -0700, fyhuang escreveu: class PythonClass: private foo = bar private var = 42 allow_readwrite( [ foo, var ] ) You are aware that foo and var would become class-variables, not instance-variables, right? But you can always do: class PythonClass(object):

Re: Is this code snippet pythonic

2006-04-10 Thread Felipe Almeida Lessa
Em Seg, 2006-04-10 às 03:52 -0700, [EMAIL PROTECTED] escreveu: My Tead Lead my object counter code seen below is not pythonic As Peter said, you should really ask your Tead Lead, but what about: class E(object): Holds a class-wide counter incremented when it's instantiated. count =

Re: how to make a generator use the last yielded value when it regains control

2006-04-10 Thread Felipe Almeida Lessa
Em Seg, 2006-04-10 às 10:05 -0700, Lonnie Princehouse escreveu: I happen to think the recursive version is more elegant, but that's just me ;-) It may be elegant, but it's not efficient when you talk about Python. Method calls are expensive: $ python2.4 -mtimeit 'pass' 1000 loops, best of

Re: unboundlocalerror with cgi module

2006-04-10 Thread Felipe Almeida Lessa
Em Seg, 2006-04-10 às 11:29 -0700, David Bear escreveu: However, the except block does not seem to catch the exception and an unboundlocalerror is thrown anyway. What am I missing? See http://docs.python.org/tut/node10.html : A try statement may have more than one except clause, to specify

  1   2   3   >