Re: Generator vs functools.partial?

2012-06-21 Thread J. Cliff Dyer
On Thu, 2012-06-21 at 21:25 +1000, John O'Hagan wrote: > Sometimes a function gets called repeatedly with the same expensive argument: > > def some_func(arg, i): > (do_something with arg and i) > > same_old_arg = big_calculation() > for i in lots_of_items: > some_func(same_old_arg, i) >

Re: Academic citation of Python

2012-06-16 Thread J. Cliff Dyer
That's a rather vague question. What do you want to cite about python? If you're just mentioning python, that shouldn't warrant a citation, though a parenthetical note linking to python.org might be useful. The standard documentation should be acceptable, or possibly a link to the source code at

Re: Interprocess comunication

2012-06-07 Thread J. Cliff Dyer
It is for reading all the lines from a complete file. If the file is still being written to, it doesn't have an end yet. File objects do many things besides RPC. Also, there are instances where all you want to do is block until the file is done, and then get all the content. readlines will do th

Re: Interprocess comunication

2012-06-07 Thread J. Cliff Dyer
On Thu, 2012-06-07 at 16:04 +, Julio Sergio wrote: > Up to this point it worked as expected. However, when I tryied with the > methods > that write and read several lines, apparently the process got stalled: > > ->>> fi.writelines(["uno\n","dos\n","tres\n"]) > ->>> fi.flush() > ->>> s = fo.

Re: I look for a package to make some simple console "form"

2012-04-02 Thread J. Cliff Dyer
You might look into formencode. It basically takes the philosophy that a form is nothing more and nothing less than an interface between user input and python data. It doesn't make assumptions about how you present the form to the user. It just handles validation and conversion of that data into

Re: help needed to understand an error message.

2012-03-30 Thread J. Cliff Dyer
So the problem is that python doesn't know what you're trying to do. It doesn't know that you meant to say "print." When the parser is looking at the word Print, it assumes you are referencing an object named Print, which is completely legal. It's only once you've created the next token, a strin

Re: Is there any difference between print 3 and print '3' in Python ?

2012-03-26 Thread J. Cliff Dyer
As others have pointed out, the output is the same, because the result of converting an integer to a string is the string of that integer. However, other numeric literals might not do what you want, due to the fact that they are converted to an internal numeric representation, then converted back t

Re: Python classes: Simplify?

2012-03-22 Thread J. Cliff Dyer
The issue of explicitly naming a "self" parameter has been discussed in depth on a number of occasions. I recommend a google search for "python implicit self" for some of the reasons why it exists. Here's what Guido has to say about it: http://neopythonic.blogspot.com/2008/10/why-explicit-self-h

Re: Best way to disconnect from ldap?

2012-03-21 Thread J. Cliff Dyer
Write a context manager. Then you just do with MyLDAPWrapper() as ldap ldap.this() ldap.that() and when you leave the scope of the with statement, your ldap __exit__ method will get called regardless of how you left. Cheers, Cliff On Wed, 2012-03-21 at 19:30 +, John Gordon wrote:

Re: List comprehension/genexp inconsistency.

2012-03-21 Thread J. Cliff Dyer
Binding" http://www.python.org/dev/peps/pep-0289/#early-binding-versus-late-binding Cheers, Cliff On Tue, 2012-03-20 at 16:50 -0600, Ian Kelly wrote: > On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber > wrote: > > On Tue, 20 Mar 2012 16:23:22 -0400,

List comprehension/genexp inconsistency.

2012-03-20 Thread J. Cliff Dyer
One of my coworkers just stumbled across an interesting issue. I'm hoping someone here can explain why it's happening. When trying to create a class with a dual-loop generator expression in a class definition, there is a strange scoping issue where the inner variable is not found, (but the outer

Re: super() woes (n00b)

2010-06-17 Thread J. Cliff Dyer
On Thu, 2010-06-17 at 16:36 +, Deadly Dirk wrote: > I cannot get right the super() function: > Python 3.1.1+ (r311:74480, Nov 2 2009, 14:49:22) > [GCC 4.4.1] on linux2 > Type "copyright", "credits" or "license()" for more information. > No Subprocess > >>> class P: > def __init_

Re: optional optional args vs optional positional options

2010-06-02 Thread J. Cliff Dyer
+1 Options are options, arguments are arguments. An optional argument is not an option. It is an argument that can be left out. On Wed, 2010-06-02 at 12:42 +0200, Antoine Pitrou wrote: > On Wed, 2 Jun 2010 01:49:18 -0700 (PDT) > Michele Simionato wrote: > > > > Notice that optparse is bas

Re: how to preserve hex value

2010-05-19 Thread J. Cliff Dyer
On Wed, 2010-05-19 at 11:38 -0700, Back9 wrote: > Hi, > > When converting a hex value, I'd like to preserve the decimal > position. > For example, 0x0A is converted to 0A not just A in string. > > How do I do this? > > TIA I'm not sure I understand what your use case is, but generally speaking,

Re: Regular expression

2010-05-18 Thread J. Cliff Dyer
Don't use regular expressions for that. s = '0x340x5A0x9B0xBA' return '0x' + ''.join(s.split('0x')) On Tue, 2010-05-18 at 06:48 -0700, Back9 wrote: > Hi, > > I have a string like this: > 0x340x5A0x9B0xBA > I want to extract 0x from the string but the first one. > > How I can use re for this cas

Re: unittest not being run

2010-05-10 Thread J. Cliff Dyer
My guess is you mixed tabs and spaces. One tab is always treated by the python interpreter as being equal to eight spaces, which is two indentation levels in your code. Though if it were exactly as you show it, you'd be getting a syntax error, because even there, it looks like the indentation of

Re: Frustration debugging serial code

2010-05-07 Thread J. Cliff Dyer
On Fri, 2010-05-07 at 15:36 -0400, William R. Wing wrote: > > Maybe I should have been more explicit. The first line in the Python > file is: > > > #!/usr/bin/env Python (alternatively #!/usr/bin/Python - same results > either way). > python should be lowercased when referring to the name of

Re: Frustration debugging serial code

2010-05-07 Thread J. Cliff Dyer
On Fri, 2010-05-07 at 15:36 -0400, William R. Wing wrote: > > Maybe I should have been more explicit. The first line in the Python > file is: > > > #!/usr/bin/env Python (alternatively #!/usr/bin/Python - same results > either way). > python should be lowercased when referring to the name of

Re: Python dot-equals (syntax proposal)

2010-04-30 Thread J. Cliff Dyer
That's kind of a nifty idea. However, python is currently under a syntax moratorium. No syntax changes will be accepted for at least 24 months starting from the release date of Python 3.1. See more details here: http://www.python.org/dev/peps/pep-3003/ Cheers, Cliff On Fri, 2010-04-30 at 09:0

Re: how to select column

2010-04-26 Thread J. Cliff Dyer
It depends on what you mean by a column. I assume your data is more complex than what you've shown us. If your data is really single words separated by spaces, you can do: for line in open('file'): columns = line.split() return columns[0], columns[3] If your columns can ha

Re: Difficulty w/json keys

2010-04-23 Thread J. Cliff Dyer
You need to know what your input data actually looks like, and the best thing for that is a little bit of formatting. I bet you can figure out the problem yourself, once you see the structure of your data more clearly. I've reformatted the JSON for you to help out. On Fri, 2010-04-23 at 07:20

Re: Globally override built-in print function?

2010-04-16 Thread J. Cliff Dyer
On Fri, 2010-04-16 at 09:50 -0700, Dave W. wrote: > >>> old_print = __builtins__.print > >>> __builtins__.print = printhook > >>> yield > >>> __builtins__.print = old_print > > > >> I'm pretty sure this is semantically equivalent to my original > >> code, but I gave it a try anyway.

Re: question about list extension

2010-04-16 Thread J. Cliff Dyer
On Sat, 2010-04-17 at 00:37 +1000, Lie Ryan wrote: > On 04/16/10 23:41, J wrote: > > So, what I'm curious about, is there a list comprehension or other > > means to reduce that to a single line? > > from itertools import chain > def printout(*info): > print '\n'.join(map(str, chain(*info))) >

Re: Urllib2 urlopen and read - difference

2010-04-15 Thread J. Cliff Dyer
On Thu, 2010-04-15 at 11:25 -0700, koranthala wrote: > Hi, >Suppose I am doing the following: > req = urllib2.urlopen('http://www.python.org') > data = req.read() > >When is the actual data received? is it done by the first line? or > is it done only when req.read() is used? > My underst

Re: Urllib2 urlopen and read - difference

2010-04-15 Thread J. Cliff Dyer
On Thu, 2010-04-15 at 11:25 -0700, koranthala wrote: > Hi, >Suppose I am doing the following: > req = urllib2.urlopen('http://www.python.org') > data = req.read() > >When is the actual data received? is it done by the first line? or > is it done only when req.read() is used? > My underst

Re: Unit testing errors (testing the platform module)

2010-04-14 Thread J. Cliff Dyer
On Wed, 2010-04-14 at 15:51 +0100, john maclean wrote: > self.assertEqual(platform.__builtins__.__class__, dict, > "platform.__class__ supposed to be dict") > self.assertEqual(platform.__name__, 'platform' ) The preferred spelling for: platform.__builtins__.__class__ would be type(pla

Re: Unit testing errors (testing the platform module)

2010-04-13 Thread J. Cliff Dyer
The problem is that the class of platform.__builtins__ is a dict, not a string containing the text "". Try replacing line 16 with this: self.assertEqual(type(platform.__builtins__), dict) Cheers, Cliff On Tue, 2010-04-13 at 15:01 +0100, John Maclean wrote: > I normally use languages uni

Re: New to Python

2010-02-10 Thread J. Cliff Dyer
On Wed, 2010-02-10 at 13:18 -0800, Stephen Hansen wrote: > > The original code: > > > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > > > ... will only work on Python 2.x, as print is being used

Re: Another Screwy Problem

2010-01-09 Thread J. Cliff Dyer
On Sat, 2010-01-09 at 07:59 -0500, Victor Subervi wrote: > On Fri, Jan 8, 2010 at 4:44 PM, J. Clifford Dyer > wrote: > Victor Subervi wrote: > > Hi; > > I have this line of code: > > sql = 'select Name, Price from %sPackages where ID=%s;' % > (store, pid) >

Re: Help with cumulative sum

2009-09-08 Thread J. Cliff Dyer
If I gave you a list of numbers, could you come up with a summifier function that returns another list of numbers that are a cumulative sum? You've got the information in place to create a file def summifier(nums): """Returns a list of numbers that are the running sum totals of nums"""

Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread J. Cliff Dyer
I had an objection to using spaces in numeric literals last time around and it still stands, and it still stands in the new one. What happens if you use a literal like 0x10f 304? Is 304 treated as decimal or hexadecimal? It's not clear how you would begin to combine it The way string concatena

Re: How to create functors?

2009-08-19 Thread J. Cliff Dyer
On Wed, 2009-08-19 at 15:56 +0200, Bruno Desthuilliers wrote: > Terry Reedy a écrit : > > Robert Dailey wrote: > > > >> I'm using Python 2.6. And using the legacy syntax in the lambda does > >> not work either. I want to avoid using a def if possible. Thanks. > > > > In Python, writing > > > > n

Re: dictionary help

2009-08-10 Thread J. Cliff Dyer
On Mon, 2009-08-10 at 22:11 -0400, Krishna Pacifici wrote: > Hi, > kind of a newbie here, but I have two questions that are probably > pretty simple. > > 1. I need to get rid of duplicate values that are associated with > different keys in a dictionary. For example I have the following > code. >

Re: variable & scoping question.

2009-08-10 Thread J. Cliff Dyer
On Mon, 2009-08-10 at 08:46 -0700, Cornelius Keller wrote: > On 10 Aug., 17:12, "Diez B. Roggisch" wrote: > > Cornelius Keller wrote: > [snip] > > > > http://effbot.org/zone/default-values.htm > > > > Diez > > Ok thank you. > I' understand now why. > I still think this is very confusing, because

Re: A Bug By Any Other Name ...

2009-08-03 Thread J. Cliff Dyer
On Sun, 2009-08-02 at 14:14 +, Albert van der Horst wrote: > >This is actually quite thoroughly untrue. In python, *indentation* > is > >significant. Whitespace (internal to a line) is not. You can even > call > >methods like this if you want: > > You totally don't get it. You describe how

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread J. Cliff Dyer
On Mon, 2009-07-20 at 12:26 -0700, Phillip B Oldham wrote: > On Jul 20, 6:08 pm, Duncan Booth wrote: > > The main reason why you need both lists and tuples is that because a tuple > > of immutable objects is itself immutable you can use it as a dictionary > > key. > > Really? That sounds interest

Re: A Bug By Any Other Name ...

2009-07-17 Thread J. Cliff Dyer
On Fri, 2009-07-17 at 20:53 +, Albert van der Horst wrote: > Because unlike in algol 68 in python whitespace is relevant, > we could get by with requiring whitespace: > x= -q # okay > a 8 ** -2 # okay This is actually quite thor

Re: mail

2009-07-15 Thread J. Cliff Dyer
On Thu, 2009-07-16 at 00:16 +0530, amr...@iisermohali.ac.in wrote: > Dear all, > > Sorry that I am disturbing you all again and again but this is the way I > am trying to solve my problem:--- > > >>> import re > >>> exp = re.compile("CA") > >>> infile = open("file1.txt") > >>> for line in infile:

Re: Nested Classes and Instances

2009-07-10 Thread J. Cliff Dyer
On Fri, 2009-07-10 at 19:00 +0200, Manuel Graune wrote: > Hello, > > as an example of what I would like to achieve, think of a street > where each house has a door and a sign with a unique (per house) > number on it. I tried to model this like this: > > class House(object): > class Door(objec

Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-10 Thread J. Cliff Dyer
On Thu, 2009-07-09 at 13:53 +, Friðrik Már Jónsson wrote: > Look at: > >len = len(text) > > You're overriding `len` (a built-in method), with an integer > (`len(text)`). You then call: > >for i in range(len(fields)): > > But `len` is no longer a callable, but merely an integer. >

Re: Clarity vs. code reuse/generality

2009-07-10 Thread J. Cliff Dyer
On Fri, 2009-07-10 at 11:57 -0500, Robert Kern wrote: > On 2009-07-10 11:50, J. Cliff Dyer wrote: > > On Fri, 2009-07-10 at 02:57 +, Steven D'Aprano wrote: > >> On Fri, 10 Jul 2009 03:28:04 +0100, Nobody wrote: > >> > >>> On Thu, 09 Jul

Re: Clarity vs. code reuse/generality

2009-07-10 Thread J. Cliff Dyer
On Fri, 2009-07-10 at 02:57 +, Steven D'Aprano wrote: > On Fri, 10 Jul 2009 03:28:04 +0100, Nobody wrote: > > > On Thu, 09 Jul 2009 04:57:15 -0300, Gabriel Genellina wrote: > > > >> Nobody says you shouldn't check your data. Only that "assert" is not > >> the right way to do that. > > > > "a

Re: tough-to-explain Python

2009-07-09 Thread J. Cliff Dyer
On Thu, 2009-07-09 at 18:10 +, Steven D'Aprano wrote: > If programming is symbol manipulation, then you should remember that > the > user interface is also symbol manipulation, and it is a MUCH harder > problem than databases, sorting, searching, and all the other > problems > you learn abou

Re: count

2009-07-09 Thread J. Cliff Dyer
Bearophile wins! (This only times the loop itself. It doesn't check for __len__) summer:5 0:00:00.51 bearophile:5 0:00:00.09 summer:50 0:00:00.30 bearophile:50 0:00:00.13 summer:500 0:00:00.77 bearophile:500 0:00:00.53 summer:5000 0:00:00.000575 bearophile:5000 0:00:00.00

Re: Idioms and Anti-Idioms Question

2009-07-02 Thread J. Cliff Dyer
On Wed, 2009-07-01 at 17:19 +1200, Lawrence D'Oliveiro wrote: > In message , J. Cliff > Dyer wrote: > > > If the lines got separated, a leading + could disappear into its line > > without any errors showing up. A trailing + would raise a syntax error. > > Unle

Re: It's ...

2009-07-01 Thread J. Cliff Dyer
On Tue, 2009-06-30 at 13:24 -0700, Beni Cherniavsky wrote: > On Jun 24, 11:40 pm, "J. Cliff Dyer" wrote: > > Also note that you can iterate over a file several times: > > > > f = open('foo.txt') > > for line in f: > > print line[0] # print

Re: It's ...

2009-06-24 Thread J. Cliff Dyer
On Wed, 2009-06-24 at 20:53 +0100, Angus Rodgers wrote: > ... my first Python program! So please be gentle (no fifty ton > weights on the head!), but tell me if it's properly "Pythonic", > or if it's a dead parrot (and if the latter, how to revive it). > Yay. Welcome to Python. > I'm working

Re: Get name of class without instance

2009-06-24 Thread J. Cliff Dyer
On Wed, 2009-06-24 at 09:17 -0700, Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don

Re: Idioms and Anti-Idioms Question

2009-06-23 Thread J. Cliff Dyer
On Mon, 2009-06-22 at 22:52 +, Peter Billam wrote: > I wonder on what grounds PEP8 > says "The preferred place to break around a binary operator is > *after* the operator" ? > Perhaps it's just the "continutation marker" rationale? > > Regards, Peter > > -- > Peter Billam www.pjb.com

Re: Procedures

2009-06-23 Thread J. Cliff Dyer
Please keep the discussion on-list. (Reply-all, rather than just replying to me.) On Mon, 2009-06-22 at 15:36 -0700, Greg Reyna wrote: > It's not the error that concerned me. The fact that there is an > error of this type makes clear that there's something wrong with the > way the scripts are

Re: Procedures

2009-06-22 Thread J. Cliff Dyer
On Mon, 2009-06-22 at 12:13 -0700, Greg Reyna wrote: > Learning Python (on a Mac), with the massive help of Mark Lutz's > excellent book, "Learning Python". > > What I want to do is this: > I've got a Class Object that begins with a def. It's designed to be > fed a string that looks like this:

Re: How to output a complex List object to a file.

2009-06-22 Thread J. Cliff Dyer
Have you looked at the JSON module? On Mon, 2009-06-22 at 21:17 +0800, Jim Qiu wrote: > Hi all, > > I have a object list list this: > > from bots.botsconfig import * > from D96Arecords import recorddefs > from edifactsyntax3 import syntax > > structure=[ > {ID:'UNH',MIN:1,MAX:1,LEVEL:[ > {I

Re: Perl's @foo[3,7,1,-1] ?

2009-06-22 Thread J. Cliff Dyer
On Mon, 2009-06-22 at 14:57 +0200, Jean-Michel Pichavant wrote: > J. Cliff Dyer wrote: > > On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: > > > >> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: > >> > >>>> What&

Re: Perl's @foo[3,7,1,-1] ?

2009-06-17 Thread J. Cliff Dyer
On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: > On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: > >> What's np.arange? > >> > > > > import numpy as np > > > > -- > > Pierre "delroth" Bourdon > > Étudiant à l'EPITA / Student at EPITA > > > > Perfect example of why r

Re: Perl's @foo[3,7,1,-1] ?

2009-06-15 Thread J. Cliff Dyer
On Sun, 2009-06-14 at 23:01 +1000, Steven D'Aprano wrote: > Write a helper function: > > def getitems(L, *indexes): > if len(indexes) == 1: > indexes = indexes[0] > return [L[i] for i in indexes] > Whoops! Your example is broken: >>> cars = ['Ford', 'Toyota', 'Edsel'] >>> getit

Re: reseting an iterator

2009-05-22 Thread J. Cliff Dyer
On Fri, 2009-05-22 at 10:54 -0700, Jan wrote: > On May 22, 9:46 am, "J. Cliff Dyer" wrote: > > > You don't need a reset method. There is no hard and fast rule that > > __iter__ must return the object itself. It just needs to return an > > iterator.

Re: Question about locals()

2009-05-22 Thread J. Cliff Dyer
Top-posting corrected. On Fri, 2009-05-22 at 10:00 -0500, Gökhan SEVER wrote: > On Fri, May 22, 2009 at 9:43 AM, David Robinow > wrote: > On Fri, May 22, 2009 at 10:27 AM, Gökhan SEVER > wrote: > ... > > serialc = np.loadtxt(sys.argv[1], skiprows=skiprows).T >

Re: While Statement

2009-05-22 Thread J. Cliff Dyer
On Fri, 2009-05-22 at 09:59 -0400, Dave Angel wrote: > > Tim Wintle wrote: > > On Fri, 2009-05-22 at 13:19 +0200, Andre Engels wrote: > > > >> number/total = 998/999 = 0 > >> number/total*100 = 0*100 = 0 > >> float(number/total*100) = float(0) = 0.0 > >> > >> Change "float(number/total*100)" to

Re: reseting an iterator

2009-05-22 Thread J. Cliff Dyer
On Wed, 2009-05-20 at 11:35 -0700, Jan wrote: > Wouldn't it be easy for Python to implement generating functions so > that the iterators they return are equipped with a __reset__() method? > > Here is the context of this question. > > Python documentation defines a "iterator" as an object ITERAT

Re: Sorting a dictionary

2009-05-15 Thread J. Cliff Dyer
On Fri, 2009-05-15 at 09:57 -0700, Tobiah wrote: > On Tue, 12 May 2009 14:17:54 +0200, Jaime Fernandez del Rio wrote: > > > This one I think I know... Try with: > > > > for k in sorted(word_count) : > > print k,"=",word_count[k] > > > > You need to do the sorting before iterating over the ke

Re: How to see the code definiton in the shell ?

2009-05-13 Thread J. Cliff Dyer
On Wed, 2009-05-13 at 09:40 -0700, Mohan Parthasarathy wrote: > Hi, > > I am new to Python. I tried searching this but could not find an > answer. In the interactive shell, I write a new function and I want to > be able to see all the code that I wrote at a later time. Just typing > the function n

Re: php to python code converter

2009-05-08 Thread J. Cliff Dyer
On Fri, 2009-05-08 at 17:19 +0200, Pascal Chambon wrote: > PS : Am I the only one having most of answers rejected by the > antispam > system of python-list ? That's humiliating :p > I've had several messages not make it through. :( -- http://mail.python.org/mailman/listinfo/python-list

Re: unicode bit me

2009-05-08 Thread J. Cliff Dyer
On Fri, 2009-05-08 at 07:53 -0700, anuraguni...@yahoo.com wrote: > #how can I print a list of object which may return unicode > representation? > # -*- coding: utf-8 -*- > > class A(object): > > def __unicode__(self): > return u"©au" > > __str__ = __repr__ = __unicode__ > Your

Re: list comprehension question

2009-05-05 Thread J. Cliff Dyer
On Tue, 2009-05-05 at 12:15 -0400, J Kenneth King wrote: > Emile van Sebille writes: > > > On 5/1/2009 7:31 AM J Kenneth King said... > >> Chris Rebert writes: > >>> b = [] > >>> for pair in a: > >>> for item in pair: > >>> b.append(item) > >> > >> This is much more clear than a nest

Re: Re: list comprehension question

2009-05-05 Thread J. Cliff Dyer
On Fri, 2009-05-01 at 13:00 -0400, John Posner wrote: > Shane Geiger wrote: > >if type(el) == list or type(el) is tuple: > A tiny improvement: > > if type(el) in (list, tuple): > Another alternative, which might be useful in some cases: if hasattr(el, '__iter__'): This co

Re: for with decimal values?

2009-05-05 Thread J. Cliff Dyer
On Sun, 2009-05-03 at 19:48 -0700, alex23 wrote: > On May 4, 11:41 am, Esmail wrote: > > All this discussion makes me wonder if it would be a good idea > > for Python to have this feature (batteries included and all) - it > > would have its uses, no? > > Well, sometimes more discussion == less co

Re: dict is really slow for big truck

2009-04-29 Thread J. Cliff Dyer
On Wed, 2009-04-29 at 10:05 -0700, Scott David Daniels wrote: > Bruno Desthuilliers wrote: > > d = {} > > for line in open(thefile): > >arr = line.strip().split() > >d[arr[0]] = arr > > Sorry, not picking on Bruno in particular, but I keep seeing > this formulation around various places. >

Re: Restart generator when it is exhausted.

2009-04-28 Thread J. Cliff Dyer
On Tue, 2009-04-28 at 10:41 +, Duncan Booth wrote: > Lacrima wrote: > > > If it is not possible what are common techniques to use iterator or > > generator objects that allow restarting when it is needed? > > The usual thing if you want to use the generator's output more than once > woul

Re: [OT] large db question about no joins

2009-04-17 Thread J. Cliff Dyer
On Thu, 2009-04-16 at 14:11 -0700, John Fabiani wrote: > Daniel Fetchinson wrote: > > > Hi folks, I've come across many times the claim that 'joins are bad' > > for large databases because they don't scale > > IMO that's bull... OK. That makes four legs so far > -- > http://mail.python.org

Re: Lambda alternative?

2009-04-17 Thread J. Cliff Dyer
On Thu, 2009-04-16 at 13:33 +0200, Hrvoje Niksic wrote: > mousemeat writes: > > > Correct me if i am wrong, but i can pickle an object that contains a > > bound method (it's own bound method). > > No, you can't: > > >>> import cPickle as p > >>> p.dumps([]) > '(l.' > >>> p.dumps([].append) > Tr

Re: extract Infobox contents

2009-04-08 Thread J. Cliff Dyer
On Wed, 2009-04-08 at 01:57 +0100, Rhodri James wrote: > On Tue, 07 Apr 2009 12:46:18 +0100, J. Clifford Dyer > wrote: > > > On Mon, 2009-04-06 at 23:41 +0100, Rhodri James wrote: > >> On Mon, 06 Apr 2009 23:12:14 +0100, Anish Chapagain > >> wrote: > >> > >> > Hi, > >> > I was trying to extrac

Re: Eval Problem

2009-04-07 Thread J. Cliff Dyer
OK. You still haven't shown the code where tableTop gets defined, so your code is unrunnable. However, I think your problem is that wherever tableTop lives, it isn't part of your globals or locals in eval. See the documentation on evals here: http://www.python.org/doc/1.4/lib/node26.html Somet

Re: Introducing Python to others

2009-03-26 Thread J. Cliff Dyer
On Thu, 2009-03-26 at 09:35 +, Paddy O'Loughlin wrote: > Hi, > As our resident python advocate, I've been asked by my team leader to > give a bit of a presentation as an introduction to python to the rest > of our department. > It'll be less than an hour, with time for taking questions at the

Re: Mangle function name with decorator?

2009-03-25 Thread J. Cliff Dyer
On Wed, 2009-03-18 at 08:18 -0700, Adam wrote: > On Mar 18, 10:33 am, "J. Cliff Dyer" wrote: > > You might be interested in redefining __getattribute__(self, attr) on > > your class. This could operate in conjunction with the hash tables > > (dictionaries)

Re: Another of those "is" issues.

2009-03-24 Thread J. Cliff Dyer
On Fri, 2009-03-20 at 11:20 -0700, Emanuele D'Arrigo wrote: > Hi everybody, > > I was unit testing some code today and I eventually stumbled on one of > those "is" issues quickly solved replacing the "is" with "==". Still, > I don't quite see the sense of why these two cases are different: > > >>

Re: Mangle function name with decorator?

2009-03-18 Thread J. Cliff Dyer
You might be interested in redefining __getattribute__(self, attr) on your class. This could operate in conjunction with the hash tables (dictionaries) mentioned by andrew cooke. i.e. (untested code): class C(object): def __init__(self): self._get_table = {} self._post_table

Re: "Battleship" style game

2009-02-25 Thread J. Cliff Dyer
On Wed, 2009-02-25 at 15:54 -0500, Shawn Milochik wrote: > On Wed, Feb 25, 2009 at 3:15 PM, Diez B. Roggisch wrote: > > > Not really. The point about properties is that you *can* make attribute > > access trigger getter or setter code. > > > > But not that you do unless there is an actual reason

Re: Is there something easier than ORM?

2009-02-17 Thread J. Cliff Dyer
On Tue, 2009-02-17 at 06:15 -0800, 一首诗 wrote: > Thanks for your reply. > > With sqlalchemy, an mapped must living in a session, you have no way > to disconnect it with its session. > > For example : > > #- > user = session.query(User).first() > session.expung

Re: wxPython and Croatian characters

2009-02-16 Thread J. Cliff Dyer
On Mon, 2009-02-16 at 20:06 +0100, Diez B. Roggisch wrote: > vedrandeko...@gmail.com schrieb: > > Hello, > > > > I have problem with configuring my wxPython script to work with > > Croatian characters like: đ,š,ž,č,ć. > > Here is my simple script without wxPython (this script works): > > > >

Re: Pythonic way to determine if one char of many in a string

2009-02-16 Thread J. Cliff Dyer
On Mon, 2009-02-16 at 00:28 -0500, Nicolas Dandrimont wrote: > * pyt...@bdurham.com [2009-02-16 00:17:37 -0500]: > > > I need to test strings to determine if one of a list of chars is > > in the string. A simple example would be to test strings to > > determine if they have a vowel (aeiouAEIOU)

Re: RedHat 4

2009-02-16 Thread J. Cliff Dyer
It *works* in RHEL 4, but it doesn't come as a package. RHEL4 ships with Python 2.3, and RHEL 5 only ships with Python 2.4, even though 2.5 had been out for god knows how long when it came out. Though I haven't tested it, I wouldn't recommend replacing the system's python binary with 2.5 if you d

Re: English-like Python

2009-02-03 Thread J. Cliff Dyer
On Tue, 2009-02-03 at 08:33 -0700, Joe Strout wrote: > J. Cliff Dyer wrote: > > > But what if your language allows functions to be used as first class > > objects? (Mine does :)) > > > > x = Beep > > > > Does that assign the name x to the Beep ob

Re: English-like Python

2009-02-03 Thread J. Cliff Dyer
On Thu, 2009-01-22 at 09:07 -0700, Joe Strout wrote: > >> Beep > >> > >> Doesn't get much more readable and syntax-free than that. > > > > readable doesn't mean smallest amount of syntax possible sometimes > syntax > > increases the readability of a text as you would see if we for > example

Re: v = json.loads("{'test':'test'}")

2009-01-27 Thread J. Cliff Dyer
On Sun, 2009-01-25 at 14:28 -0800, gert wrote: > On Jan 25, 11:16 pm, Дамјан Георгиевски wrote: > > > raise ValueError(errmsg("Expecting property name", s, end)) > > >http://docs.python.org/library/json.html > > > What am I doing wrong ? > > > > try this > > v = json.loads('{"test":"test"}') > >

Re: is None vs. == None

2009-01-27 Thread J. Cliff Dyer
On Fri, 2009-01-23 at 19:31 -0500, Benjamin Kaplan wrote: > > > On Fri, Jan 23, 2009 at 7:28 PM, Gary Herron > wrote: > Steven D'Aprano wrote: > > On Fri, 23 Jan 2009 14:58:34 -0500, Gerald Britton wrote: > > > > > >> Hi -- Some time ago I ran across a co

Re: I'm a python addict !

2009-01-26 Thread J. Cliff Dyer
On Mon, 2009-01-26 at 12:37 -0800, Paul McGuire wrote: > On Jan 26, 2:06 pm, "J. Cliff Dyer" wrote: > > > > Thanks. That makes sense. But your example creates a new instance of > > the new class each time, rather than changing the class of a persistent > >

Re: I'm a python addict !

2009-01-26 Thread J. Cliff Dyer
On Mon, 2009-01-26 at 09:52 -0800, Paul McGuire wrote: > On Jan 26, 10:54 am, "J. Cliff Dyer" wrote: > > On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: > > > Want to change the type/behavior of an object from class A to class > > > B? H

Re: I'm a python addict !

2009-01-26 Thread J. Cliff Dyer
On Fri, 2009-01-23 at 20:25 -0800, Paul McGuire wrote: > Want to change the type/behavior of an object from class A to class > B? How about this: > > aobj = A() > aobj.__class__ = B > > Try *that* in as simple-looking C++ or Java! Wow. That looks very powerful and fun. But scary. An

Re: I'm a python addict !

2009-01-26 Thread J. Cliff Dyer
On Mon, 2009-01-26 at 14:43 -0800, J Kenneth King wrote: > Linuxguy123 writes: > > > I just started using python last week and I'm addicted. > > > > I hate Perl. I never did learn to use it with any competence. I has to > > be the most obfuscated, cryptic language I've ever seen. Making it >

Re: Newby: how to transform text into lines of text

2009-01-26 Thread J. Cliff Dyer
On Sun, 2009-01-25 at 18:23 -0800, John Machin wrote: > On Jan 26, 1:03 pm, "Gabriel Genellina" > wrote: > > En Sun, 25 Jan 2009 23:30:33 -0200, Tim Chase > > escribió: > > > > > > > > > Unfortunately, a raw rstrip() eats other whitespace that may be > > > important. I frequently get tab-de

Re: The First Law Of comp.lang.python Dynamics

2009-01-23 Thread J. Cliff Dyer
I dub it Schluehr's law. On Thu, 2009-01-22 at 21:39 -0800, Kay Schluehr wrote: > Whatever sufficiently sophisticated topic was the initially discussed > it ends all up in a request for removing reference counting and the > GIL. > > -- > http://mail.python.org/mailman/listinfo/python-list > --

Skull Socks (was Re: Convention vs. fascism)

2009-01-16 Thread J. Cliff Dyer
On Fri, 2009-01-16 at 08:57 +, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote: > > > Oh come on you lot - you are carrying on as if Diez were wearing his > > skull socks again - do me a favour and give him a break! > And... skull socks? Cool. Where can

Re: Problem with -3 switch

2009-01-09 Thread J. Cliff Dyer
On Fri, 2009-01-09 at 13:13 -0500, Steve Holden wrote: > Aivar Annamaa wrote: > >> As was recently pointed out in a nearly identical thread, the -3 > >> switch only points out problems that the 2to3 converter tool can't > >> automatically fix. Changing print to print() on the other hand is > >> ea

Re: Creating new instances of subclasses.

2009-01-09 Thread J. Cliff Dyer
Thanks for the solutions everyone! I'm not sure which I'll end up using, but I think I've got a better grasp of the problem now. Cool stuff. Cheers, Cliff On Thu, 2009-01-08 at 06:52 -0800, Paul McGuire wrote: > On Jan 7, 12:00 pm, Paul McGuire wrote: > > On Jan 7,

Creating new instances of subclasses.

2009-01-07 Thread J. Cliff Dyer
eld(Field): def __new__(cls, a): return object.__new__(cls, a) Is there a cleaner way to do this? The main problem is that Field.__new__ gets in the way of properly constructing the subclasses once I've used it to select the proper subclass in the first place. Cheers, Cliff -- Oook, J. Cliff Dyer Carolina Digital Library and Archives UNC Chapel Hill -- http://mail.python.org/mailman/listinfo/python-list

Re: subclassing 'list'

2009-01-06 Thread J. Cliff Dyer
On Tue, 2009-01-06 at 12:34 -0800, akineko wrote: > Hello everyone, > > I'm creating a class which is subclassed from list (Bulit-in type). > > It works great. > However, I'm having a hard time finding a way to set a new value to > the object (within the class). > There are methods that alter a

Re: python is great

2009-01-06 Thread J. Cliff Dyer
On Tue, 2009-01-06 at 10:36 -0700, Joe Strout wrote: > I've actually been rather frustrated by Python lately. OFF TOPIC!!! Please try to stay within the subject presented by the subject header. The subject in question is "python is great," not "python is frustrating." Speaking of which, python

Re: __init__.py and package help

2009-01-05 Thread J. Cliff Dyer
On Mon, 2009-01-05 at 11:49 -0800, TechieInsights wrote: > Ok I have read all of the tutorials and documents I could find. I am > running Python 2.6 on windows. The problem I am having with packages > is that they don't show up! > > Simple example of what isn't working... > Structure- > > pyte

Re: confused about __str__ vs. __repr__

2008-12-18 Thread J. Cliff Dyer
On Thu, 2008-12-18 at 13:35 -0500, Neal Becker wrote: > Mel wrote: > > > Neal Becker wrote: > > > >> Tino Wildenhain wrote: > >> > >>> Neal Becker wrote: > Reading some FAQ, I see that __str__ is "meant for human eyes". > > But it seems that: > class X(object): > d

Re: Factoring Polynomials

2008-12-18 Thread J. Cliff Dyer
On Thu, 2008-12-18 at 11:52 -0800, eric wrote: > On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: > > I am trying to write a simple application to factor polynomials. I > > wrote (simple) raw_input lines to collect the a, b, and c values from > > the user, but I dont know how to implement the qua

  1   2   3   >