Re: Mac OS and MySQLdb

2005-01-28 Thread Skip Montanaro
Thomas> is there a MySQLdb-Version for the latest Mac OS (or can I use Thomas> the Linux-tarball)? I just built the latest version from source (1.1.7 or something). Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: [perl-python] 20050127 traverse a dir

2005-01-28 Thread Skip Montanaro
abigail> @@ No. Second, learn Python. Third, learn Perl (optional). :) abigail> Just leave the third option out. Let him learn Python. We don't abigail> want him. ;-) We don't want him either. Perhaps we can persuade him to learn INTERCAL... Skip -- http://mail.python.org/mailman

Re: debugging os.spawn*() calls

2005-01-28 Thread Skip Montanaro
Nick> If using 2.4 the subprocess module is a good solution too. It Nick> lets you catch stdout/stderr easily. Yeah, thought of that already. Currently not an option though. Thx, Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: What's so funny? WAS Re: rotor replacement

2005-01-29 Thread Skip Montanaro
>> http://www.python.org/pypi >> THIS IS ALL PYTHON. Paul> No. Those are programs people have written in Python or as Python Paul> extensions. What's your point? That I have to download and perhaps install them to use them? In that case, how are these two scenarios different:

Re: Who should security issues be reported to?

2005-01-29 Thread Skip Montanaro
Nick> Upgrading your Python interpreter (even to a new maintenance Nick> branch release) in a production environment is usually a fairly Nick> involved exercise requiring a significant amount of testing, and Nick> the fact of the matter is, you're unlikely to do so unless there

Re: What's so funny? WAS Re: rotor replacement

2005-01-29 Thread Skip Montanaro
>> What matters is the code complexity, not whether something is in a >> separate module or not. Martin> A module *is* typically more complex than a single function. And one that deals with cryptography is likely to be even more complex. Skip -- http://mail.python.org/mailman/list

Re: limited python virtual machine

2005-01-29 Thread Skip Montanaro
>> One thing my company has done is written a ``safe_eval()`` that uses >> a regex to disable double-underscore access. Alex> will the regex catch getattr(object, Alex> 'subclasses'.join(['_'*2]*2)...?-) Now he has two problems. ;-) Skip -- http://mail.python.org/mailman/listin

Re: limited python virtual machine

2005-01-29 Thread Skip Montanaro
Alex> I dunno, maybe I'm just being pessimistic, I guess... No, I think you are being realistic. I thought one of the basic tenets of computer security was "that which is not expressly allowed is forbidden". Any attempt at security that attempts to find and plug the security holes while leav

Re: What's so funny? WAS Re: rotor replacement

2005-01-29 Thread Skip Montanaro
Paul> I've had this discussion here before, maybe not with you. What I Paul> really want is zero installations of anything. Fine. Go build a sumo distribution and track the normal CPython. The problem isn't all that new. (Take a look at scipy.org for one take on that theme. Of cours

Re: {Spam?} Re: naive doc question

2005-01-30 Thread Skip Montanaro
>> I wanted a list of all the methods of dict for example... where can i >> find it? Terry> Lib Ref 2.3.8 Mapping Types. Do browse chapter 2 so you know Terry> what is there. I think the best doc page to bookmark is the global module index: http://docs.python.org/lib/modind

Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread Skip Montanaro
Nick> I think one of the special things about Python is its batteries Nick> included approach, and a crypto library would seem to be an Nick> obvious battery to install since it doesn't (or needn't) depend on Nick> any other library or application. Obvious for some I suppose (I've

Re: [ANN] Spike Asset Manager release 0.13

2005-01-31 Thread Skip Montanaro
r example, "rpm -aq | grep httpd"? -- Skip Montanaro [EMAIL PROTECTED] http://www.mojam.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Request for Feedback; a module making it easier to use regular expressions.

2005-01-31 Thread Skip Montanaro
Ken> rex is a module intended to make regular expressions easier to Ken> create and use... Have you checked out Ping's rxb module? http://lfw.org/python/ Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Where are list methods documented?

2005-02-01 Thread Skip Montanaro
Grant> where are the methods of basic types documented? The other day I suggested the most valuable doc page to bookmark is the global module index. Here's a demonstration. Start at: http://www.python.org/dev/doc/devel/modindex.html Click "__builtin__", which takes you to http:

Re: Next step after pychecker

2005-02-01 Thread Skip Montanaro
Francis> "Every well-formed expression of the language can be assigned a Francis> type that can be deduced from the constituents of the Francis> expression alone." Bird and Wadler, Introduction to Functional Francis> Programming, 1988 Francis> This is certainly not the case fo

Re: Python Code Auditing Tool

2005-02-02 Thread Skip Montanaro
>> 246 ValueError >> 227 aetools.Error >> 216 Error >> 124 TypeError >> 101 error >> 75 RuntimeError >> 53 IOError >> 36 NotImplementedError >> 36 ImportError >> 36 EOFError >> 31 SyntaxError >> 23 KeyError >> 23 AttributeError >> 22 Distutil

Re: managing multiple subprocesses

2005-02-03 Thread Skip Montanaro
> "Marcos" == Marcos <[EMAIL PROTECTED]> writes: Marcos> I have tried all sorts of popens / excevs / os.systems / Marcos> commands etc etc. I think os.spawn* and os.wait will do what you want. I have trouble with os.spawn* myself, so may just fall back to fork/exec + os.wait in the

Re: bytecode obfuscation

2005-02-03 Thread Skip Montanaro
snacktime> How difficult is it to turn python bytecode into it's snacktime> original source? Not very. Google for "python decompyle". Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: python-mode tab completion problem

2005-02-03 Thread Skip Montanaro
test1dellboy3> I am exploring python-mode on emacs. When I open foo.py test1dellboy3> in emacs and hit C-!, it starts the python interpreter in test1dellboy3> another window. Next, I execute - ... That's not really intended to be used as an interactive session with all sorts of b

Re: OT: why are LAMP sites slow?

2005-02-03 Thread Skip Montanaro
Paul> I'm talking about the very familiar experience of clicking a link Paul> and then waiting, waiting, waiting for the page to load. You Paul> rarely see that happen with Ebay or Google. It happens all the Paul> time with Wikipedia. It's more than a bit unfair to compare Wikip

Re: FAQ: __str__ vs __repr__

2005-06-21 Thread Skip Montanaro
>> __repr__ shouldn't be anything, if you don't have an actual need for >> it. Neither should __str__. Simon> Oh, I don't know. __str__ is so frequently useful in debugging Simon> and logging that I always try and do something useful with it. And sometimes __repr__ inherited fro

PEP 304 - is anyone really interested?

2005-06-22 Thread Skip Montanaro
I wrote PEP 304, "Controlling Generation of Bytecode Files": http://www.python.org/peps/pep-0304.html quite awhile ago. The first version appeared in January 2003 in response to questions from people about controlling/suppressing bytecode generation in certain situations. It sat idle for a

Re: case/switch statement?

2005-06-22 Thread Skip Montanaro
Martin> The namespace issue alluded to doesn't exist when using the very Martin> similar approach suggested earlier in this thread by Andrew Martin> Durdin Sure, but I don't think I want to pay the cost of the exec statement. if/else would probably be quicker. -- shown again below i

Re: pydoc - suppressing builtins?

2005-06-23 Thread Skip Montanaro
Alan> Is it possible to persuade pydoc not to include documentation for Alan> methods inherited from built-in classes? Alan> I'm sure I could qite easily write something to post-process the Alan> HTML files; just wondering if there might be an easier way. If you're going to

Re: Running Python interpreter in Emacs

2005-06-23 Thread Skip Montanaro
Rex> I'm interested in running a Python interpreter in Emacs. I have Rex> Python extensions for Emacs, and my python menu lists "C-c !" as Rex> the command to run the interpreter. Yet when I run it I get the Rex> message "Spawning Child Process: invalid argument." What do I need

Re: string capitalize sentence

2005-06-23 Thread Skip Montanaro
dimitri> I came up with the following solution: dimitri> a = 'harry is a strange guy. so is his sister, but at least she is not a dimitri> guy. i am.' dimitri> b = a.replace('. ', '.') dimitri> splitlist = b.split('.') dimitri> newlist = [] dimitri> for i in range(le

Re: Excellent Site for Developers

2005-06-25 Thread Skip Montanaro
Philippe> Not being from anglo-saxon heritage, I keep wondering why Philippe> spammers always (or very often) get called 'trolls' ? Fishing from a boat that is moving slowly is called "trolling". You're slowly dragging bait or a lure through the water to entice a fish to bite your hook.

Re: Escaping commas within parens in CSV parsing?

2005-06-30 Thread Skip Montanaro
Ramon> I am trying to use the csv module to parse a column of values Ramon> containing comma-delimited values with unusual escaping: Ramon> AAA, BBB, CCC (some text, right here), DDD Ramon> I want this to come back as: Ramon> ["AAA", "BBB", "CCC (some text, right here)", "DD

Re: Re:

2005-07-01 Thread Skip Montanaro
Adriaan> I'm not a very experienced Python programmer yet, so I might be Adriaan> mistaken, but there are a few things that would make me prefer Adriaan> C++ over Python for large (over 500.000 LOC) projects. Adriaan> - namespaces Python's go packages, modules, classes. Plenty o

Re: Where can I get the new version of python-mode for emacs?

2005-07-04 Thread Skip Montanaro
Marcio> I have version 4.70 installed in my debian system (installed Marcio> with apt-get, so I don't know where the sources are from). After Marcio> reading the thread_ at sourceforge, I did a google search for Marcio> "python emacs" and found the `Emacs goodies`_ page at python.o

Re: Calculating average time

2005-07-07 Thread Skip Montanaro
greg> 1. Is there a better time function to use? For this particular scenario I think time.time() is probably what you want: cumulative = 0.0 n = 0 for link in links: t = time.time() ie.Navigate(link) cumulative += time.time() - t n += 1 print

Re: Snakespell

2005-07-08 Thread Skip Montanaro
peter> I used to use Snakespell from scriptfoundry to do spellchecking peter> on my website (www.peterbe.com/search?q=pyton) but now that I've peter> moved server and wiped the old machine I forgot to take with me peter> the Snakespell code. peter> www.scriptfoundry.com where

Re: automatically assigning names to indexes

2005-07-13 Thread Skip Montanaro
George> What 'magic' ? The (x,y,z) notation is used only for 3D George> vectors. (x,y) is also common for 2D and perhaps (t,x,y,z) for George> 4D, with t for time. Don't forget (w,x,y,z) for quaternions... Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Installation error on Solaris-9-SPARC

2005-07-14 Thread Skip Montanaro
Madhu> I did... Madhu> 1. wget http://www.python.org/ftp/python/2.4.1/Python-2.4.1.tgz Madhu> 2. gunzip -c Python-2.4.1.tgz | tar xvf - Madhu> the above step errors: Madhu> Madhu> tar: directory checksum error Madhu> gunzip: stdout: Broken pipe Madhu> ---

Re: negative integer division

2005-02-07 Thread Skip Montanaro
Imbaud> integer division and modulo gives different results in c and Imbaud> python, when negative numbers are involved. http://www.python.org/doc/faq/programming.html#why-does-22-10-return-3 Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Python mail filter

2005-02-09 Thread Skip Montanaro
>> (P.S. I am very much aware of the existence of procmail, TMDA etc. My >> requirements are very specific and requires integration with another >> program, so I am only interested in getting a custom solution). Tim> But are you aware that a procmail recipe can feed a message thro

Re: hard_decoding

2005-02-10 Thread Skip Montanaro
Tamas> Do you have a convinient, easy way to remove special charachters Tamas> from u'strings'? Tamas> Replacing: Tamas> ÀÁÂÃÄÅ => A ... etc ... See if my latscii codec works for you: http://www.musi-cal.com/~skip/python/latscii.py Skip -- http://mail.python.org/m

Re: Install MySQLdb on Mac OS X (10.3)

2005-02-10 Thread Skip Montanaro
TK> I can't install MySQLdb on Mac OS X (Ver. 10.3) properly. Here's my TK> environment: TK> 1. MySQL-python-1.0.0 ... Try a more recent version of mysql-python. I think 1.1.7 is the latest. Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: is there a safe marshaler?

2005-02-11 Thread Skip Montanaro
Carl> but can't effbot's fast cElementree be used for PYROs XML_PICKLE Carl> and would it be safe and fast enough? It's not clear to me that if marshal is unsafe how XML could be safe. In this context they are both just serializations of basic Python data structures. Skip -- http://ma

Re: Install MySQLdb on Mac OS X (10.3)

2005-02-11 Thread Skip Montanaro
>> Try a more recent version of mysql-python. I think 1.1.7 is the latest. TK> It now works with MySQL-python-1.2.0 Andy's a busy guy... ;-) Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Alternative to raw_input ?

2005-02-11 Thread Skip Montanaro
> Err, why? >> It looks to ugly this way. I want to press >> any key without ENTER to continue How about modifying it to raw_input("Press ENTER to continue ") Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: hard_decoding

2005-02-15 Thread Skip Montanaro
Andrew> for another variation see that "Unicode Hammer" at Andrew> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/251871 Andrew> It doesn't do the registry hooks that Skip does, and I see I Andrew> need to learn more about the functions in the codes module. Note that l

Re: Why doesn't join() call str() on its arguments?

2005-02-16 Thread Skip Montanaro
John> 4. For consistency, would you like "1" + 2 to produce "12"? No, the correct answer is obviously 3. ;-) S -- http://mail.python.org/mailman/listinfo/python-list

Re: naming convention for scalars, lists, dictionaries ...

2005-02-28 Thread Skip Montanaro
beliavsky> Since Python does not have declarations, I wonder if people beliavsky> think it is good to name function arguments according to the beliavsky> type of data structure expected, with names like "xlist" or beliavsky> "xdict". In general, no. I think variable names should

Re: Validating A User/Password Pair + Getting Groups On Unix

2005-03-01 Thread Skip Montanaro
>> 1) Validate that the password is correct for that user *without >>actually logging in*. >> Kanenas> The 'pwd' module probably won't be able (and won't try) to read Kanenas> the shadow password file, so 'pwd' won't be of use. Note that an spwd module was recently added

Re: smtplib Segfaults Python under Debian

2005-03-01 Thread Skip Montanaro
Alex> localhost:~alex#python Alex> Python 2.3.3 (#2, Feb 24 2004, 09:29:20) Alex> [GCC 3.3.3 (Debian)] on linux2 Alex> Type "help", "copyright", "credits" or "license" for more information. import smtplib Alex> Segmentation fault (core dumped) Can you file a bug repor

Re: yield_all needed in Python

2005-03-01 Thread Skip Montanaro
Doug>def foogen(arg1): Doug> def foogen1(arg2): Doug> # Some code here Doug> # Some code here Doug> yield_all foogen1(arg3) Doug> # Some code here Doug> yield_all foogen1(arg4) Doug> # Some code here Doug>

Re: creating csv file from

2005-03-02 Thread Skip Montanaro
> "Sandeep" == Sandeep Avinash Gohad <[EMAIL PROTECTED]> writes: Sandeep> How can i use the url as an input so that I can save data from Sandeep> that particular webpage to comma seperated file (csv). This worked for me: import urllib, csv reader = csv.reader(urllib.urlopen("

Re: yield_all needed in Python

2005-03-02 Thread Skip Montanaro
Jeremy> At first I liked this, but the reason that is a syntax error is Jeremy> that it is "supposed" to be Jeremy> def f(): Jeremy> yield (x for x in gen1(arg)) Jeremy> which today on 2.4 returns a generator instance which will in Jeremy> turn yield one generator ins

Re: Impersonating other broswers...

2005-03-05 Thread Skip Montanaro
sboyle> I'm using urlopen, and it works fine. But I'd like to be able sboyle> to change my browser string from "Python-urllib/1.15" to instead sboyle> impersonate Internet Explorer. sboyle> I know this can be done very easily with Perl, so I'm assuming sboyle> it's also easy

Re: Is there a short-circuiting dictionary "get" method?

2005-03-10 Thread Skip Montanaro
Dave> In this snippet: Dave> d = {'x': 1} Dave> value = d.get('x', bigscaryfunction()) Dave> the bigscaryfunction is always called, even though 'x' is a valid Dave> key. I sometimes use value = d.get('x') or bsf() Of course, this bsf() will get called if d['x'] evaluat

Re: select random entry from dictionary

2005-03-10 Thread Skip Montanaro
>> d.popitem() Removes and returns an arbitrary (key, value) pair from d >> If this isn't random enough, then you can generate a random number in >> range(len(d)) Peter> Although this idea may suit the OP, "arbitrary" is most Peter> definitely not "random". Correct. The libr

injecting "set" into 2.3's builtins?

2005-03-10 Thread Skip Montanaro
I use sets a lot in my Python 2.3 code at work and have been using this hideous import to make the future move to 2.4's set type transparent: try: x = set except NameError: from sets import Set as set else: del x Of course, while it's transparent at one

Re: injecting "set" into 2.3's builtins?

2005-03-11 Thread Skip Montanaro
Stephen> I have: Stephen> try: Stephen> set Stephen> except NameError: Stephen> from sets import Set as set Stephen> in my code in a few places. Yes, but then pychecker complains about a statement with no apparent effect, hence the extra verbiage. My question was

Re: injecting "set" into 2.3's builtins?

2005-03-11 Thread Skip Montanaro
>> I have: >> try: >> set >> except NameError: >> from sets import Set as set >> in my code in a few places. Sion> Is there any reason to prefer this over the idiom I have: Sion> if sys.version_info < (2, 4): Sion> from sets import Set as set No,

Re: injecting "set" into 2.3's builtins?

2005-03-11 Thread Skip Montanaro
>> caused problems in the past. A module might sniff for 'set' and >> assume it is running on 2.4 if it sees it, with unpredictable results >> if it relies on any other 2.4 behaviour. John> Aarrgghh! When there's a documented API (sys.version_info) for John> determining the ve

Re: csv module and unicode, when or workaround?

2005-03-11 Thread Skip Montanaro
Chris> the current csv module cannot handle unicode the docs say, is Chris> there any workaround or is unicode support planned for the near Chris> future? True, it can't. Chris> obviously I am not a python pro, i did not even find the py Chris> source for the module, it seeme

Re: csv module and unicode, when or workaround?

2005-03-11 Thread Skip Montanaro
Chris> the current csv module cannot handle unicode the docs say, is Chris> there any workaround or is unicode support planned for the near Chris> future? Skip> True, it can't. Hmmm... I think the following should be a reasonable workaround in most situations: #!/usr/bin/en

Re: Installation Guide

2005-03-12 Thread Skip Montanaro
Kevin> I'm in critical need to install Python Imaging Library on my Kevin> linux/cpanel server. I'm not very experienced and I almost always Kevin> have to use instalation guides. Take a look at the BUILDME and README files in the top-level directory. Skip -- http://mail.python.org/

Re: _conditionally_ returning to point where exception was raised?

2005-03-16 Thread Skip Montanaro
>> ... The calling method detects the exception, but needs to get input >> from the user before deciding whether A.CalledMethod() should >> continue being executed or permantently stop/cancel the execution of >> the remaining code in A.CalledMethod(). Can this be done? Bengt>

Re: PyGoogle featured on Google Code

2005-03-18 Thread Skip Montanaro
Michael> I took a look at goopy and I found that much of the stuff in it Michael> could be done more efficiently with an itertools recipe. But Michael> then again, it also had sum() and maximum() functions so it Michael> must have been written for an older version of Python. I th

Re: Database connection caching

2005-03-18 Thread Skip Montanaro
Lorenzo> is there an alternative way of: Lorenzo> - create a connection object Lorenzo> - open the connection Lorenzo> - close the connection Lorenzo> every time one has to run a query. Sure, create a Queue.Queue object and stuff a number of connections into it. When you wan

Re: [python-sybase] Sybase module 0.37pre1 released

2005-03-19 Thread Skip Montanaro
e module I have available. (Some users at work have old code that expects times to be floats in epoch seconds as returned by time.time(). This allows them to easily use that with minimal changes to their code.) -- Skip Montanaro [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: date diff calc

2004-11-29 Thread Skip Montanaro
tertius> Is there a more pythonic way to write or do a date difference tertius> calculation? I have as input two date fields in the form tertius> '-MM-DD' How about: import datetime import time bd = "2004-11-25" ed = "2004-11-30" start = datetime.date.fromti

From xemacs-beta mailing list

2004-11-30 Thread Skip Montanaro
Stephen Turnbull had this to say to a correspondent on the xemacs-beta mailing list this morning. I think it would be just as accurate if you replaced "XEmacs" with "Python". Many of the things you request are prima facie reasonable, and we'll certainly consider them in the light of what

Re: comment out more than 1 line at once?

2004-11-30 Thread Skip Montanaro
Riko> I'm using emacs (with python-mode) to do most of my editing. C-c # is bound to py-comment-region in python-mode. Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: comment out more than 1 line at once?

2004-11-30 Thread Skip Montanaro
>> if False: >> >> (indented) block of code here is commented out >> I've no idea how efficient it is compared to triple-quoted strings or >> line by line comments. Gustavo> Actually, it's infinitly [sp?] more defficient (contrary of Gustavo> efficient?) than triple-

Re: Help With Hiring Python Developers

2004-12-01 Thread Skip Montanaro
fuego> We've posted at Monster, Dice, jobs.perl.org and fuego> python.jobmart.com. Can anyone advise other job boards that fuego> might be helpful? http://www.python.org/Jobs-howto.html Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: decorators ?

2004-12-01 Thread Skip Montanaro
Jacek> Anything you can do with decorators, you could do before (with Jacek> the exception of rebinding the __name__ of functions). And while that feature was added because we realized it would be nice if the decorated function could have the same name as the original function, it seems l

Re: Python xmlrpc servers?

2004-12-01 Thread Skip Montanaro
ted> The example given in the Python documentation for ted> SimpleXMLRPCServer is more or less incomprehensible. Agreed, there is a doc fix needed. Try mentally adding from math import * to the start of the example. That will get you the pow function. It's still incorrect thoug

Re: Python xmlrpc servers?

2004-12-01 Thread Skip Montanaro
ted> Would several web services on the same server listen on different ted> ports (, 8889, 8890...) or on the same port? Port numbers are never implicit. You need to provide a listen port each time you start the server. Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Python xmlrpc servers?

2004-12-01 Thread Skip Montanaro
ted> The only other real question is what about the cgi servers? I'd ted> assume I'd take the example given: ted> class MyFuncs: ted> def div(self, x, y) : return div(x,y) ted> handler = CGIXMLRPCRequestHandler() ted> handler.register_function(pow) ted> handler.re

Re: Python xmlrpc servers?

2004-12-01 Thread Skip Montanaro
>> Have you looked in your web server's error log file? ted> Shoulda thought of that It's telling me that the name ted> CGIXMLRPCRequestHandler is not found. In other words, it is trying ted> to execute the proper file at least. I'd have that that importing ted> SimpleX

Re: Pythonic use of CSV module to skip headers?

2004-12-03 Thread Skip Montanaro
Ramon> I'm using the csv module to parse a tab-delimited file and Ramon> wondered whether there was a more elegant way to skip an possible Ramon> header line. Assuming the header line has descriptive titles, I prefer the DictReader class. Unfortunately, it requires you to specify the

Re: python-mode question

2004-12-04 Thread Skip Montanaro
Thomas> When I edit a Python script with XEmacs, then hit C-c C-c, the Thomas> script is executed, the output is shown in a *Python Output* Thomas> buffer, and the cursor is moved into this buffer. Thomas> How can I change the behaviour so that the cursor stays where it Thomas

Re: Pythonic use of CSV module to skip headers?

2004-12-04 Thread Skip Montanaro
>> Assuming the header line has descriptive titles, I prefer the >> DictReader class. Unfortunately, it requires you to specify the >> titles in its constructor. My usual idiom is the following: Michael> I deal so much with tab-delimited CSV files that I found it Michael> us

Re: Pythonic use of CSV module to skip headers?

2004-12-04 Thread Skip Montanaro
>> I don't find the couple extra lines of code in my original example >> all that cumbersome to type though. Michael> If you started about half of the programs you write with those Michael> extra lines, you might . I'm a strong believer in Michael> OnceAndOnlyOnce. You're rig

Re: python-mode question

2004-12-06 Thread Skip Montanaro
Thomas> I assume you meant the python-mode project? Whoops. Yeah. Thanks. Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: [dictionary] how to get key by item

2004-12-13 Thread Skip Montanaro
Egor> i know how to get item by key ... Egor> but i wonder how to get key by item Assuming your dictionary defines a one-to-one mapping, just invert it: >>> forward = {10 : 50, 2 : 12, 4 : 43} >>> reverse = dict([(v,k) for (k,v) in forward.iteritems()]) >>> print forward

Re: [dictionary] how to get key by item

2004-12-13 Thread Skip Montanaro
>> That doubles your storage, so you'll have to trade that off against >> the speed gain of not having to loop over the entire dictionary. Roy> Well, you *do* loop over the entire dictionary, but you only do it Roy> once, when you create the reverse dict. If you are only going to

Re: [dictionary] how to get key by item

2004-12-13 Thread Skip Montanaro
Fredrik> Skip Montanaro wrote: >> That doubles your storage Fredrik> careful: it creates another dictionary structure with the same Fredrik> size as the first one, but it doesn't copy the objects in the Fredrik> dictionary. Yes, sorry. The OP

Re: how do I "peek" into the next line?

2004-12-13 Thread Skip Montanaro
les> suppose I am reading lines from a file or stdin. I want to just les> "peek" in to the next line, and if it starts with a special les> character I want to break out of a for loop, other wise I want to les> do readline(). Create a wrapper around the file object: class Pee

RE: [dictionary] how to get key by item

2004-12-14 Thread Skip Montanaro
Tim> Python will do what you tell it. In the above case, it will build a Tim> list. Whoops, yeah. I called .iteritems() then forgot to use a generator expression... Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: [dictionary] how to get key by item

2004-12-14 Thread Skip Montanaro
Ola> If some keys has the same value as the item this will cause Ola> problems because keys in your result dictionary can be Ola> overwritten. That's why I said, "assuming your dictionary defines a one-to-one mapping...". Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-15 Thread Skip Montanaro
Dan> I also see an 8-10% speed decrease in 2.4 (I built) from 2.3.3 Dan> (shipped w/Fedora2) in the program I'm writing (best of 3 trials Dan> each). Memory use seems to be about the same. How do you how the compiler flags were the same if you didn't compile both versions yourself?

Switch statement (was: Lambda going out of fashion)

2004-12-23 Thread Skip Montanaro
Stephen> { Stephen> 'one': lambda x:x.blat(), Stephen> 'two': lambda x:x.blah(), Stephen> }.get(someValue, lambda x:0)(someOtherValue) One thing to remember is that function calls in Python are pretty damn expensive. If x.blat() or x.blah() are themselves only one or two lines

Improving Python (was: Lambda going out of fashion)

2004-12-23 Thread Skip Montanaro
Keith> My personal gripe is this. I think the core language, as of 2.3 Keith> or 2.4 is very good, has more features than most people will ever Keith> use, and they (Guido, et al.) can stop tinkering with it now and Keith> concentrate more on the standard libraries. What keeps you

Re: Lambda going out of fashion

2004-12-23 Thread Skip Montanaro
Craig> IMO the reference behaviour of functions in the C API could be Craig> clearer. One often has to simply know, or refer to the docs, to Craig> tell whether a particular call steals a reference or is reference Craig> neutral. Take, for example, PyDict_SetItemString vs Crai

Re: Lambda going out of fashion

2004-12-23 Thread Skip Montanaro
>> readability. Pythonic lambdas are just syntactic sugar in practice, Paul> Actually it's the other way around: it's named functions that are Paul> the syntactic sugar. While I'm sure it can be done, I'd hate to see a non-trivial Python program written with lambda instead of def. (

Re: Lambda going out of fashion

2004-12-23 Thread Skip Montanaro
>> While I'm sure it can be done, I'd hate to see a non-trivial Python >> program written with lambda instead of def. Jp> What, like this? Jp> (lambda r,p,b:... Jp> OTOH, maybe that's still trivial, it's only a multiuser network Jp> chat server, after all. You che

Re: Lambda going out of fashion

2004-12-23 Thread Skip Montanaro
Jp> PyStones may be short (and be nearly lambda free!) but it is one Jp> opaque blob to me. I'd be hard pressed to rewrite it in any style, Jp> given its perverse use of global state. It's written that way on purpose, of course. Pystone is almost a direct translation of a similar pr

Re: Lambda going out of fashion

2004-12-24 Thread Skip Montanaro
Mike> Perl 6.0 is going to include even more drastic changes. It will Mike> also include a Perl 5.x interpreter, and will have to be switched Mike> to 6.0 mode by a magic cookie of some kind in the source. Possibly Mike> Python 3.0 could do something similar. -1 Things are compl

Re: A Revised Rational Proposal

2004-12-27 Thread Skip Montanaro
Mike> ... or making them old-style classes, which is discouraged. Since when is use of old-style classes discouraged? Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: PyHeartBeat Client in PERL?

2004-12-27 Thread Skip Montanaro
Dave> While reading the Python Cookbook as a means of learning Python, I Dave> came across the script by Dave Larosa. Not knowing anything about Dave> PERL, I was wondering if there were a translation in PERL so I Dave> could have my Netware servers send heartbeats to the heartbea

Re: DB-API format string conventions

2004-12-28 Thread Skip Montanaro
Craig> IMO it'd also be very nice to support **kw calling style, ie to Craig> make: Craig> cursor.execute("SELECT somerow FROM table WHERE otherrow = %(name)s", Craig>{'name': 'fred'}) Craig> equivalent to: Craig> cursor.execute("SELECT somerow FROM table

Re: Securing a future for anonymous functions in Python

2004-12-30 Thread Skip Montanaro
John> In other words, an anonymous function looks like: John> {p1, p2, p3 | John> stmt1 John> stmt2 John> } John> There are two reasons for using braces. One is that it's the John> common syntax for blocks in a large number of languages. Yeah, bu

Re: .pth files?

2005-03-22 Thread Skip Montanaro
Ben> I'm unclear on how .pth files work. Some posts imply they can be Ben> arbitrarily named, as long as they include the .pth extension, and Ben> can exist anywhere in the current sys.path. Other documentation Ben> seems to imply that they must be named .pth, although I'm Be

Re: Confirm: compiled re(gexps) are thread safe?

2005-03-22 Thread Skip Montanaro
Johan> Subject says it all, really. Yes, searching using a compiled regular expression is thread-safe. Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: The Running Time of +=

2005-03-22 Thread Skip Montanaro
> "Haz" == MyHaz <[EMAIL PROTECTED]> writes: Haz> Teach me how to fish, where would i find out more about the Haz> internal representations of data types in python The source. Experimentally you can use the timeit command to see how it performs: % for i in 10 20 40 80 160 320 640 1

Re: .pth files?

2005-03-23 Thread Skip Montanaro
>> I have a mojam.pth file but no "mojam" package on my server. Works >> just fine. Ben> Where does it call home? site-packages? Yup. -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   7   8   9   10   >