Re: Diff of Text

2010-06-04 Thread GZ
On Jun 4, 8:37 pm, Lie Ryan  wrote:
> On06/05/10 07:51, GZ wrote:
>
>
>
>
>
> > Hi Pat,
>
> > On Jun 4, 2:55 pm, Patrick Maupin  wrote:
> >> On Jun 3, 9:54 pm, GZ  wrote:
>
> >>> Hi All,
>
> >>> I am looking for an algorithm that can compare to source code files
> >>> line by line and find the minimum diff. I have looked at the difflib
> >>> included in python. The problem is that it is designed to make the
> >>> diff results easier for humans to read, instead of minimize the size
> >>> of the output differencial. I would like an algorithm implementation
> >>> that gives the absolute minimum difference between the two files.
>
> >>> Can you help me?
>
> >>> Thanks,
> >>> gz
>
> >> There's an "rsync.py" module in pypi -- one would think that would
> >> have to solve that same problem...
>
> >> Regards,
> >> Pat
>
> > No, rsync does not solve my problem.
>
> > I want a library that does unix 'diff' like function, i.e. compare two
> > strings line by line and output the difference. Python's difflib does
> > not work perfectly for me, because the resulting differences are
> > pretty big. I would like an algorithm that generates the smallest
> > differences.
>
> is n=0 not short enough?
>
> pprint.pprint(list(difflib.context_diff(s, t, n=0)))

This still does not do what I want it to do. It only displays the diff
results in a different format. I want a different algorithm to
generate a smaller diff -- in other words less differences
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An empty object with dynamic attributes (expando)

2010-06-04 Thread Terry Reedy

On 6/4/2010 10:25 PM, Alf P. Steinbach wrote:


As far as I can think of now, one cannot add attributes to *any*
builtin-class instance, but can add attributes to any user class which
does not have them disabled.

>>> [].a = 3
Traceback (most recent call last):
File "", line 1, in 
[].a = 3
AttributeError: 'list' object has no attribute 'a'
>>> class L(list): pass

>>> i = L(); i; i.a = 3; i.a
[]
3

Terry Jan Reedy


You can add attributes to functions.

I'm not sure, but I think it was you who once provided me with a
reference to the relevant PEP (thanks!), so I guess it just slipped your
mind on a late Friday night. :-)


Right on both counts. Function attributes are exceptions, and they were 
added after I learned Python.



Regarding user defined classes, I gather that by "have them [attributes]
disabled" you're including the case of a class with slots?


Yes. or custom __setattr__ or something.

tjr



--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
Steven D'Aprano  writes:

> On Fri, 04 Jun 2010 08:56:34 -0500, Jim Byrnes wrote:
>
>> I thought his point was they are big enough to have the resources to
>> offer newsgroups but don't.  If I want fast internet I must use Comcast
>> and Comcast doesn't offer newsgroups either.  Sadly is seems getting
>> access to newsgroups is getting harder and harder.
>
> I'm sorry for all you people who don't live in a place with a genuinely 
> free market,

If such a thing exists it still doesn't mean that each and every place
where one can live has plenty of choice. Even in the Netherlands, where
I am originally from, which is quite crowded there are plenty of places
where the number of provider options are limited. But I don't think you
should feel sorry for those people, because the majority is not
interested in Usenet (well, the "text" part) and the few who do will
find a way. On top of that, not every provider has the expertise to
handle Usenet resulting in a very crappy service nobody cares about.

> and instead have to suffer with the lack of competition and 
> poor service of a monopoly or duopoly masquerading as a free market. But 
> *my* point was that your woes are not universal, and Usenet is alive and 
> well. It might be declining, but it's a long, slow decline and, like 
> Cobol, it will probably still be around a decade after the cool kids 
> declared it dead.

Well, I've noticed quite some groups I used to follow have become "dead"
in less than a year, so while I have no doubt you're correct with the
decade, I don't think there is much fun in being subscribed to 20 groups
only to find one message a month :-D. I use email to stay in contact
with some regulars of groups that indeed do have just one message /
month. I doubt it has anything to do with being a cool kid or not. Some
groups also dry up because the topic has been discussed to dead and/or
it's easier to nowadays find the information on line somewhere else. And
yet others, in my opinion, dry up because the people who are holding the
fort are IMO sitting in ivory towers and have extremely little patience
with newbies but are also somewhat tired with each other because they
don't want to end up in the same discussion again.

So, yeah, Usenet will be around for decades, I don't doubt it. I am
convinced that in a decade from now the total number of users will still
be higher than 20 years ago so it's far from dead then. But I guess that
will make it only more so that one has to pay for access.

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Steven D'Aprano
On Fri, 04 Jun 2010 15:55:08 -0500, John Bokma wrote:

> "Alf P. Steinbach"  writes:
[...]
>> It started, as I see it, back in the early 90's with Playboy attempting
>> to sue anyone who used the Lena picture in photo processing tests etc.
>> (it's the standard image for that). They failed in that particular
>> endeavour, but did succeed in shutting down thousands of sites
>> worldwide displaying Playboy pictures.
> 
> I know of the use of Lena. And to be honest, I agree with Playboy that
> they have the copyright. 

I don't think that anyone argues that Playboy don't own the copyright. 
What they don't own is the principle of fair use.


> Some of the articles published on image
> processing end up behind a paywall or in a book. 

Perhaps. So what? Publishing dozens of photos from Playboy isn't fair 
use. Publishing a single copy of Lena is. Fair use doesn't cease to be 
fair use if you put it in a book.


> And I don't think the
> authors will be very happy if I convert their work in PDFs and offer it
> as free download on my site. Everybody wants a free ride until they have
> to create and maintain the rides in their own precious time with their
> own money.

I'm sorry, Playboy took that photo of Lena, what, thirty years ago? In 
what possible sense do they have to maintain it? Do they have to 
photoshop out the wrinkles each year to maintain the photo's youthful 
appearance?



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
Lie Ryan  writes:

> If you look at Stack Overflow, the highest voted questions are:
>
> - Hidden Features of C#?
> - What is the single most influential book every programmer should read?
> - What's your favorite "programmer" cartoon?
> - What is your best programmer joke?
> ... and so on
>
> many of them are nearly out-of-topic.

What do you mean with out-of-topic? (off topic?)

http://stackoverflow.com/questions/tagged/python

But to be honest I mostly end up on Stack Overflow when I google for a
specific problem, and most of the time I find a nice concise answer
without much noise.

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
Grant Edwards  writes:

> On 2010-06-04, John Bokma  wrote:
>> Lie Ryan  writes:
>>
>>> On 06/05/10 04:19, John Bokma wrote:
 Steven D'Aprano  writes:
 
> But the really sad thing is that you think that "bigger" automatically 
> equals "better".
 
 I don't think that was the point.
 
 Anyway, not everbody can pick a provider, there are plenty of places
 that have only one or maybe two. And if that's the choice and neither
 carries Usenet you have to pay for Usenet like I do. Note that I
 consider it well worth the 10 euros I pay for it.
>>>
>>> Isn't gmane available where you live? I've used gmane for newsgroups
>>> that my local server doesn't carry. The only problem is that there's a
>>> slight delay in opening new posts (0.5 seconds or so).
>>
>> I am aware of Gmane [1] but in their own words: "Gmane is a mailing list
>> archive.", so it's not Usenet. It's a Usenet server which provides
>> access to mailing lists. (A very cool idea).
>
> No, it's not a Usenet server.

OK, it's an NNTP server, but on the other hand I think one can argue
that an NNTP server also implies Usenet since Usenet doesn't imply that
all groups available on Usenet should be available, nor does it imply
-- like you already mentioned below (snipped) -- how exactly that data
arrives or that is has to be complete. Since this posting ends up on
Gmane, I think it's correct to call Gmane part of Usenet, and hence,
they're running a Usenet server.

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Steven D'Aprano
On Fri, 04 Jun 2010 02:29:58 -0400, D'Arcy J.M. Cain wrote:

> On 04 Jun 2010 05:41:17 GMT
> Steven D'Aprano  wrote:
>> Sure, a lot of those 1,800 posts are spam, but the spammers wouldn't
>> waste their time if they didn't think there were people still on
>> Usenet.
> 
> Kidding, right?  Cost to spam is virtually zero so the ROI is pretty
> close to infinite no matter how many people they reach.

What, you think the Russian mob hands out their botnets for free?

Spam is a business. An evil, unethical, immoral, scum-sucking business, 
but still a business, and like all businesses, spammers care about cost 
and profit. The marginal cost of sending spam might be approaching zero, 
but the total cost isn't, and spammers try to maximise the number of 
eyeballs they reach while minimising the cost. If they weren't, they 
would still be using the same spam techniques from the 90s, instead of 
engaged in an arms race with anti-spam apps.

This is why things like picture spam comes in waves. Every few months, 
some newbie spammer hits on the brilliant idea of putting his spam in a 
jpg image, carefully obfuscating it so that OCR software can't recognise 
the URL but humans can, pays his $200 (or whatever it is) to rent a 
botnet, and for two weeks everybody gets an uptick in spam because the 
anti-spam apps can't filter picture spam very well.

And then they discover that the morons who buy from spammers aren't just 
stupid, they're lazy too. Nobody is going to type the URL into their 
browser, that's too much like actual work. So the spammer learns that his 
investment didn't make him any profit, and he tries something else, or 
gives up, and the picture spam disappears for a few more months until 
some other newbie fails to think things through.

If there weren't people reading the spam on Usenet and buying whatever 
junk is being sold, the spammers would move on.




-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An empty object with dynamic attributes (expando)

2010-06-04 Thread Alf P. Steinbach

* Terry Reedy, on 05.06.2010 03:01:

On 6/4/2010 8:01 PM, dmtr wrote:

Why does it have to be a one-liner? Is the Enter key on your keyboard
broken?


Nah. I was simply looking for something natural and intuitive, like: m
= object(); m.a = 1;
Usually python is pretty good providing these natural and intuitive
solutions.


As far as I can think of now, one cannot add attributes to *any*
builtin-class instance, but can add attributes to any user class which
does not have them disabled.

 >>> [].a = 3
Traceback (most recent call last):
File "", line 1, in 
[].a = 3
AttributeError: 'list' object has no attribute 'a'
 >>> class L(list): pass

 >>> i = L(); i; i.a = 3; i.a
[]
3

Terry Jan Reedy


You can add attributes to functions.

I'm not sure, but I think it was you who once provided me with a reference to 
the relevant PEP (thanks!), so I guess it just slipped your mind on a late 
Friday night. :-)


See my earlier reply in this thread regarding that.

Regarding user defined classes, I gather that by "have them [attributes] 
disabled" you're including the case of a class with slots?


There was an article recently in DDJ where the author seemed to be unaware of 
this, but I'm not going to pay for the privilege of commenting on articles.



Cheers & hth.,

- Alf


PS: How come that when I post a blog entry proving mathematically that the 
reader is really really smart, the number of views dropped like a stone? Huh. 
But OK, it was just a late-night posting, I couldn't sleep so I posted a bit of 
what I, late at night, thought was some funny or at least amusing philosophy...


--
blog at http://alfps.wordpress.com>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Steven D'Aprano
On Sat, 05 Jun 2010 05:22:21 +1000, Lie Ryan wrote:

> Probably. A vote up/down feature tend to highlight popular problems, but
> it also buries less popular problems that might have perfectly good
> answers. I think Google Groups have 5-star-rating system? You might want
> to check on that.

I don't remember the URL, but I read an article about Yahoo Answers which 
explained that the Yahoo team started off with 5-star ratings for 
answers, but quickly discovered that most ratings were either 0 or 5, and 
so changed to a Vote Up/Down system. According to Yahoo's experience, the 
extra complexity just adds an illusionary sense of precision with no 
additional benefit.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Steven D'Aprano
On Fri, 04 Jun 2010 08:56:34 -0500, Jim Byrnes wrote:

> I thought his point was they are big enough to have the resources to
> offer newsgroups but don't.  If I want fast internet I must use Comcast
> and Comcast doesn't offer newsgroups either.  Sadly is seems getting
> access to newsgroups is getting harder and harder.

I'm sorry for all you people who don't live in a place with a genuinely 
free market, and instead have to suffer with the lack of competition and 
poor service of a monopoly or duopoly masquerading as a free market. But 
*my* point was that your woes are not universal, and Usenet is alive and 
well. It might be declining, but it's a long, slow decline and, like 
Cobol, it will probably still be around a decade after the cool kids 
declared it dead.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bz2 module doesn't work properly with all bz2 files

2010-06-04 Thread Steven D'Aprano
On Fri, 04 Jun 2010 12:53:26 -0700, Magdoll wrote:

> I'm not sure what's causing this, but depending on the compression
> program used, the bz2 module sometimes exits earlier.
[...]

The current bz2 module only supports files written as a single stream, 
and not multiple stream files. This is why the BZ2File class has no 
"append" mode. See this bug report:

http://bugs.python.org/issue1625

Here's an example:

>>> bz2.BZ2File('a.bz2', 'w').write('this is the first chunk of text')
>>> bz2.BZ2File('b.bz2', 'w').write('this is the second chunk of text')
>>> bz2.BZ2File('c.bz2', 'w').write('this is the third chunk of text')
>>> # concatenate the files
... d = file('concate.bz2', 'w')
>>> for name in "abc":
...     f = file('%c.bz2' % name, 'rb')
...     d.write(f.read())
...
>>> d.close()
>>>
>>> bz2.BZ2File('concate.bz2', 'r').read()
'this is the first chunk of text'

Sure enough, BZ2File only sees the first chunk of text, but if I open it 
in (e.g.) KDE's Ark application, I see all the text.

So this is a known bug, sorry.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diff of Text

2010-06-04 Thread Lie Ryan
On 06/05/10 07:51, GZ wrote:
> Hi Pat,
> 
> On Jun 4, 2:55 pm, Patrick Maupin  wrote:
>> On Jun 3, 9:54 pm, GZ  wrote:
>>
>>> Hi All,
>>
>>> I am looking for an algorithm that can compare to source code files
>>> line by line and find the minimum diff. I have looked at the difflib
>>> included in python. The problem is that it is designed to make the
>>> diff results easier for humans to read, instead of minimize the size
>>> of the output differencial. I would like an algorithm implementation
>>> that gives the absolute minimum difference between the two files.
>>
>>> Can you help me?
>>
>>> Thanks,
>>> gz
>>
>> There's an "rsync.py" module in pypi -- one would think that would
>> have to solve that same problem...
>>
>> Regards,
>> Pat
> 
> No, rsync does not solve my problem.
> 
> I want a library that does unix 'diff' like function, i.e. compare two
> strings line by line and output the difference. Python's difflib does
> not work perfectly for me, because the resulting differences are
> pretty big. I would like an algorithm that generates the smallest
> differences.

is n=0 not short enough?

pprint.pprint(list(difflib.context_diff(s, t, n=0)))

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Lie Ryan
On 06/05/10 06:57, John Bokma wrote:
> Lie Ryan  writes:
> 
>> On 06/04/10 11:56, John Bokma wrote:
>>> Phlip  writes:
>>>
 On Jun 3, 3:20 pm, geremy condra  wrote:

>> You mean like how I never get answers, to my super-easy GED-level
>> questions, here??!
>
> I agree. This proves conclusively that a web forum is the right
> place for you.

 Ah, so you feel up to my "xsl for xmlrunner.py" question?
>>>
>>> Just jumping in the middle, but if you're looking for a web based forum
>>> where you can ask questions, check out Stack Overflow (and sister sites,
>>> depending on your question). I've noticed over the last couple of months
>>> that often things I google for, are answered on Stack Overflow. One
>>> thing that would've been nice to have on Usenet that I like is the
>>> ability to vote answers up or down. I think Usenet would've been a bit
>>> better with that option.
>>
>> Probably. A vote up/down feature tend to highlight popular problems, but
>> it also buries less popular problems that might have perfectly good
>> answers.
> 
> Unless I misunderstand, the voting is for the replies, not for the
> questions. Or maybe the questions can be promoted to a queue, no
> idea. But that's not that different from questions posted to Usenet. The
> popular ones are asked often, the less popular ones once in a while, and
> might also not result in solutions.

If you look at Stack Overflow, the highest voted questions are:

- Hidden Features of C#?
- What is the single most influential book every programmer should read?
- What's your favorite "programmer" cartoon?
- What is your best programmer joke?
... and so on

many of them are nearly out-of-topic.



>> I think Google Groups have 5-star-rating system? You might want
>> to check on that.
> 
> B... no, I really prefer my Usenet via Gnus ;-).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Terry Reedy

On 6/4/2010 3:04 PM, Emile van Sebille wrote:

On 6/4/2010 11:27 AM Terry Reedy said...

On 6/4/2010 12:28 PM, Emile van Sebille wrote:


Is there now a non-email method of posting to this list?


Google <==> comp.lang.python <==> python-list <==>
gmane.comp.python.general

where <==> is a bi-directional gateway.


Yes -- I use gmane as well. But, IIRC, I needed to be on the mail list
in order for my responses to show up because MailMan is the primary back
end and I thought it's set to only accept posts from members.


I think this somewhat depends on the list (admin settings)


Hence, my question. Aren't we all members posting (ultimately)
exclusively through email regardless of preferred reading interfaces?



--
http://mail.python.org/mailman/listinfo/python-list


Re: An empty object with dynamic attributes (expando)

2010-06-04 Thread Terry Reedy

On 6/4/2010 8:01 PM, dmtr wrote:

Why does it have to be a one-liner? Is the Enter key on your keyboard
broken?


Nah. I was simply looking for something natural and intuitive, like: m
= object(); m.a = 1;
Usually python is pretty good providing these natural and intuitive
solutions.


As far as I can think of now, one cannot add attributes to *any* 
builtin-class instance, but can add attributes to any user class which 
does not have them disabled.


>>> [].a = 3
Traceback (most recent call last):
  File "", line 1, in 
[].a = 3
AttributeError: 'list' object has no attribute 'a'
>>> class L(list): pass

>>> i = L(); i; i.a = 3; i.a
[]
3

Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: plac, the easiest command line arguments parser in the world

2010-06-04 Thread Kenny Meyer
On Jun 2, 12:37 am, Michele Simionato 
wrote:
> I would like to announce to the world the first public release of
> plac:
>
>  http://pypi.python.org/pypi/plac
>
> Plac is a wrapper over argparse and works in all versions of
> Python starting from Python 2.3 up to Python 3.1.
>
> With blatant immodesty, plac claims to be the easiest to use command
> line arguments parser module in the Python world. Its goal is to
> reduce the
> learning curve of argparse from hours to minutes. It does so by
> removing the need to build a command line arguments parser by hand:
> actually it is smart enough to infer the parser from function
> annotations.
>
> Here is a simple example (in Python 3) to wet your appetite:
>
> $ cat example.py
> def main(arg: "required argument"):
>     "do something with arg"
>     print('Got %s' % arg)
>
> if __name__ == '__main__':
>     import plac; plac.call(main) # passes sys.argv[1:] to main
>
> $ python example.py -h
> usage: example.py [-h] arg
>
> do something with arg
>
> positional arguments:
>   arg         required argument
>
> optional arguments:
>   -h, --help  show this help message and exit
>
> $ python example.py
> usage: example.py [-h] arg
> example.py: error: too few arguments
>
> $  python example.py arg
> Got arg
>
> $  python example.py arg1 arg2
> usage: example.py [-h] arg
> example.py: error: unrecognized arguments: arg2
>
> You can find in the documentation a lot of other simple and not so
> simple
> examples:
>
>  http://micheles.googlecode.com/hg/plac/doc/plac.html
>
> Enjoy!
>
>              Michele Simionato
>
> P.S. answering an unspoken question: yes, we really needed yet
> another
> command line arguments parser! ;)

I like this approach to command-line argument parsing! Thanks for
sharing your work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An empty object with dynamic attributes (expando)

2010-06-04 Thread dmtr
> Why does it have to be a one-liner? Is the Enter key on your keyboard
> broken?

Nah. I was simply looking for something natural and intuitive, like: m
= object(); m.a = 1;
Usually python is pretty good providing these natural and intuitive
solutions.


> You have a perfectly good solution: define a class, then instantiate it.
> But if you need a one-liner (perhaps to win a game of code golf), then
> this will work:
>
> >>> m = type('', (), {})()
> >>> m.attribute = 2

Heh. Creating it dynamically. Ace. ;)

-- Cheers, Dmitry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting MemoryError with dicts; suspect memory fragmentation

2010-06-04 Thread Dan Stromberg
On Thu, Jun 3, 2010 at 3:43 PM, Emin.shopper Martinian.shopper <
emin.shop...@gmail.com> wrote:

> Dear Experts,
>
> I am getting a MemoryError when creating a dict in a long running
> process and suspect this is due to memory fragmentation. Any
> suggestions would be welcome. Full details of the problem are below.
>
> I have a long running processing which eventually dies to a
> MemoryError exception


Here's something good about Python memory leaks:
http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks

Just
curious: What if you use a gdbm key-value store or treap instead of a
builtin {} dictionary?  gdbm is usually built in, and my treap module is
here, as pure python or partial  CPython+partial cython:
http://stromberg.dnsalias.org/~dstromberg/treap/

The gdbm module would require your keys and values to be strings (unless you
wrap it), but it should pretty much take dictionary-related Virtual Memory
(VM) out of the picture by mostly storing your data to disk.  One way of
wrapping one would be to use my (UCI's) cachedb module, which does implicit
to- and from-string conversions using functions you provide to its
constructor, and allows you to control how many values to cache in VM:
http://stromberg.dnsalias.org/~strombrg/cachedb.html

The treap module should be able to store arbitrary objects in VM out of the
box, and is much like a dictionary but implemented quite differently - its
chief difference is a little memory _overhead_ (normally, maybe not this
time due to the significantly different implementation details) in order to
get the "dictionary's" objects always sorted in key order, and to store
things as a (mostly!) self-balanced tree (it sacrifices fastidious balancing
to get better average performance) with a heap invariant.  Because it stores
things as a balanced tree of discrete objects, it should be pretty clear
that it's not looking for contiguous memory unless the backend CPython
memory management does for some reason beyond dictionary specifics.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing DLL in win98

2010-06-04 Thread Spyder42
On Fri, 04 Jun 2010 14:03:48 -0400, Terry Reedy 
wrote:

>On 6/4/2010 9:08 AM, Spyder42 wrote:
>> On Fri, 04 Jun 2010 14:50:28 +0200, Christian Heimes
>
>>> Python 2.6 is not supported on Windows 98 and earlier. You need at least
>>> Windows 2000 with a recent service pack.
>>>
>>> Christian
>>
>> So your response is either, you don't know if there is a fix, or 'No
>> way in h377.' You couldn't figure out by my post that I already knew
>> that?
>
>Get off your high horse. Dumping on volunteer helpers is a good way to 
>drive them away.
>
>It was not obvious, without closely reading your original post, and even 
>then it is not clear, that you *knew* than 2.6 was not supported on 
>Win98. You could have asked 'I know 2.6+ is not officially supported in 
>win98. Does anyone know a workaround other than upgrading windows or 
>sticking with 2.5?". *That* would have been clear.
>
>Terry Jan Reedy
>

I'm sorry, but if I asked where the nearest gas station was, I
wouldn't expect someone to answer, "You can't get there because your
out of gas."

I had a specific question and I got a non-specific non-answer. 
If they didn't know, they should not have answered.

>It was not obvious, without closely reading your original post...

So it WAS obvious to anyone who was PAYING ATTENTION?
Life is not a dress rehersal. If you don't get it right, things like
the BP's oil spill, Chernobyl, and 3 mile island happen. Perhaps I'm
being extreme, but computer programs underly our entire civilization
today. Computers dump stock, and Billions are lost, needlessly
affecting everyones life. Trains crash, boats sink, and psychos like
me go off the deep end, because no-one is paying attention.

L8r
Spyder


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bz2 module doesn't work properly with all bz2 files

2010-06-04 Thread Magdoll
On Jun 4, 3:05 pm, Cameron Simpson  wrote:
> On 04Jun2010 12:53, Magdoll  wrote:
> | I'm not sure what's causing this, but depending on the compression
> | program used, the bz2 module sometimes exits earlier.
> |
> | I used pbzip2 to compress my bz2 files and read through the file using
> | the bz2 module. The file descriptor always exits much earlier than
> | where the actual EOF is. If I use bzip2 instead of pbzip2 to compress
> | the files, then everything is fine.
> |
> | My files are generally big (several GBs) so decompressing them is not
> | a wise choice, and it is a little unfortunate that I can't use pbzip2
> | because it's usually much faster than bz2.
>
> Have you tested the decompression or the problematic files with the
> bunzip2 command? Just to ensure the bug is with the python bz2 module
> and not with the pbzip2 utility?
> --
> Cameron Simpson  DoD#743http://www.cskk.ezoshosting.com/cs/
>
> A lot of people don't know the difference between a violin and a viola, so
> I'll tell you.  A viola burns longer.   - Victor Borge

Yes. Decompressing them with either pbzip2 or bunzip2 are both fine.
So the problem is not with pbzip2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting in batch with no display

2010-06-04 Thread exarkun

On 08:01 pm, h.schaat...@surrey.ac.uk wrote:

Admittedly not the strongest reason, but yet an important one,
for switching from Matlab to python/numpy/scipy/matplotlib,
is that Matlab is very cumbersome to run in batch.

Now I discover that some of the matplotlib.pyplot functions
(incl. plot and contour) insist on opening an X11 window
(just like Matlab does).  I would have preferred just to create
the plot straight on file.  The extra window is a nuisance on my
laptop, it is deep-felt pain if I try to run it remotely.  It fails
completely if I run it without any display at all.

Oddly, the bar() function does not open a window by default.
I was very happy with that.  It works exactly the way I want.
(Why isn't pyplot more consistent?)

Is there something I have missed?  Is it possible to create
standard 2D plots and contour plots without a display, writing
the graphics straight into a PDF file?


It's possible to plot with matplotlib without a display.  I'm not 
surprised you didn't figure out how, though, it's not all that obvious.


Check out the matplotlib.use function.  For example:

   import matplotlib
   matplotlib.use('agg')
   import pylab
   pylab.plot([1, 3, 5])
   fig = file('foo.png', 'wb')
   pylab.savefig(fig, format='png')
   fig.close()

This should work fine without a display.

Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Grant Edwards
On 2010-06-04, John Bokma  wrote:
> Lie Ryan  writes:
>
>> On 06/05/10 04:19, John Bokma wrote:
>>> Steven D'Aprano  writes:
>>> 
 But the really sad thing is that you think that "bigger" automatically 
 equals "better".
>>> 
>>> I don't think that was the point.
>>> 
>>> Anyway, not everbody can pick a provider, there are plenty of places
>>> that have only one or maybe two. And if that's the choice and neither
>>> carries Usenet you have to pay for Usenet like I do. Note that I
>>> consider it well worth the 10 euros I pay for it.
>>
>> Isn't gmane available where you live? I've used gmane for newsgroups
>> that my local server doesn't carry. The only problem is that there's a
>> slight delay in opening new posts (0.5 seconds or so).
>
> I am aware of Gmane [1] but in their own words: "Gmane is a mailing list
> archive.", so it's not Usenet. It's a Usenet server which provides
> access to mailing lists. (A very cool idea).

No, it's not a Usenet server.

It's a mailing-list gateway that provides access via NNTP.  Usenet is
a peer-to-peer system that trasfers articles around between servers.

NNTP is a protocol often used to provide access to Usenet servers
(Usenet was around long before NNTP).  NNTP can be used to provide
access to other things (as Gmane does).

-- 
Grant

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
geremy condra  writes:

> On Fri, Jun 4, 2010 at 1:55 PM, John Bokma  wrote:
>> I know of the use of Lena. And to be honest, I agree with Playboy that
>> they have the copyright. Some of the articles published on image
>> processing end up behind a paywall or in a book. And I don't think the
>> authors will be very happy if I convert their work in PDFs and offer it
>> as free download on my site. Everybody wants a free ride until they have
>> to create and maintain the rides in their own precious time with their
>> own money.
>
> Playboy permits use of the image for research,

OK, then I don't get the issue, and if you can enlighten me on it I will
be thankful.

> so unless you planned
> on getting permission from the authors first this is a totally invalid
> comparison.

Clear. But my free ride remark stands IMO

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bz2 module doesn't work properly with all bz2 files

2010-06-04 Thread Cameron Simpson
On 04Jun2010 12:53, Magdoll  wrote:
| I'm not sure what's causing this, but depending on the compression
| program used, the bz2 module sometimes exits earlier.
| 
| I used pbzip2 to compress my bz2 files and read through the file using
| the bz2 module. The file descriptor always exits much earlier than
| where the actual EOF is. If I use bzip2 instead of pbzip2 to compress
| the files, then everything is fine.
| 
| My files are generally big (several GBs) so decompressing them is not
| a wise choice, and it is a little unfortunate that I can't use pbzip2
| because it's usually much faster than bz2.

Have you tested the decompression or the problematic files with the
bunzip2 command? Just to ensure the bug is with the python bz2 module
and not with the pbzip2 utility?
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

A lot of people don't know the difference between a violin and a viola, so
I'll tell you.  A viola burns longer.   - Victor Borge
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diff of Text

2010-06-04 Thread GZ
Hi Pat,

On Jun 4, 2:55 pm, Patrick Maupin  wrote:
> On Jun 3, 9:54 pm, GZ  wrote:
>
> > Hi All,
>
> > I am looking for an algorithm that can compare to source code files
> > line by line and find the minimum diff. I have looked at the difflib
> > included in python. The problem is that it is designed to make the
> > diff results easier for humans to read, instead of minimize the size
> > of the output differencial. I would like an algorithm implementation
> > that gives the absolute minimum difference between the two files.
>
> > Can you help me?
>
> > Thanks,
> > gz
>
> There's an "rsync.py" module in pypi -- one would think that would
> have to solve that same problem...
>
> Regards,
> Pat

No, rsync does not solve my problem.

I want a library that does unix 'diff' like function, i.e. compare two
strings line by line and output the difference. Python's difflib does
not work perfectly for me, because the resulting differences are
pretty big. I would like an algorithm that generates the smallest
differences.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread geremy condra
On Fri, Jun 4, 2010 at 1:55 PM, John Bokma  wrote:
> I know of the use of Lena. And to be honest, I agree with Playboy that
> they have the copyright. Some of the articles published on image
> processing end up behind a paywall or in a book. And I don't think the
> authors will be very happy if I convert their work in PDFs and offer it
> as free download on my site. Everybody wants a free ride until they have
> to create and maintain the rides in their own precious time with their
> own money.

Playboy permits use of the image for research, so unless you planned
on getting permission from the authors first this is a totally invalid
comparison.

Geremy Condra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: if, continuation and indentation

2010-06-04 Thread Aahz
In article ,
Tim Chase   wrote:
>
>While it's not PEP material, I tend to use the coding standards I 
>learned working for Computer Sciences Corporation (10 yrs ago, so 
>things may have changed) that mandated 2 levels of indentation 
>for continued lines, turning the above into
>
>   if (width == 0 and
>   height == 0 and
>   color == 'red' and
>   emphasis == 'strong' or
>   highlight>  100):
>   # or the closing "):" on this line,
>   # aligned with the previous line
>   raise ValueError("sorry, you lose")

+1
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting in batch with no display

2010-06-04 Thread Emile van Sebille

On 6/4/2010 1:01 PM Hans Georg Schaathun said...

Admittedly not the strongest reason, but yet an important one,
for switching from Matlab to python/numpy/scipy/matplotlib,
is that Matlab is very cumbersome to run in batch.

Now I discover that some of the matplotlib.pyplot functions
(incl. plot and contour) insist on opening an X11 window
(just like Matlab does).


I found the same to be true when running OpenOffice in batch mode. 
Ultimately, the following was key to getting things going:


at the shell:

/usr/bin/vncserver :1


then from within python:

XDISPLAY=':1'

cmd='''cd /usr/ftp/CSV && DISPLAY=%s \
/usr/bin/soffice -norecover -nologo -nodefault \
"macro:///Standard.Module1.csvToXLS(%s)"''' \
% (XDISPLAY,csvfile)

dummy = commands.getoutput(cmd)


Then, if it doesn't run to conclusion, you can vnc to :1 and see where 
it's stalled out.


HTH,

Emile


--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
Lie Ryan  writes:

> On 06/05/10 04:19, John Bokma wrote:
>> Steven D'Aprano  writes:
>> 
>>> But the really sad thing is that you think that "bigger" automatically 
>>> equals "better".
>> 
>> I don't think that was the point.
>> 
>> Anyway, not everbody can pick a provider, there are plenty of places
>> that have only one or maybe two. And if that's the choice and neither
>> carries Usenet you have to pay for Usenet like I do. Note that I
>> consider it well worth the 10 euros I pay for it.
>
> Isn't gmane available where you live? I've used gmane for newsgroups
> that my local server doesn't carry. The only problem is that there's a
> slight delay in opening new posts (0.5 seconds or so).

I am aware of Gmane [1] but in their own words: "Gmane is a mailing list
archive.", so it's not Usenet. It's a Usenet server which provides
access to mailing lists. (A very cool idea).

But I am with Individual.net and IMO very great service for just 10
euro.


[1] http://johnbokma.com/mexit/2005/01/14/gmane-mail-to-news.html

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
Lie Ryan  writes:

> On 06/04/10 11:56, John Bokma wrote:
>> Phlip  writes:
>> 
>>> On Jun 3, 3:20 pm, geremy condra  wrote:
>>>
> You mean like how I never get answers, to my super-easy GED-level
> questions, here??!

 I agree. This proves conclusively that a web forum is the right
 place for you.
>>>
>>> Ah, so you feel up to my "xsl for xmlrunner.py" question?
>> 
>> Just jumping in the middle, but if you're looking for a web based forum
>> where you can ask questions, check out Stack Overflow (and sister sites,
>> depending on your question). I've noticed over the last couple of months
>> that often things I google for, are answered on Stack Overflow. One
>> thing that would've been nice to have on Usenet that I like is the
>> ability to vote answers up or down. I think Usenet would've been a bit
>> better with that option.
>
> Probably. A vote up/down feature tend to highlight popular problems, but
> it also buries less popular problems that might have perfectly good
> answers.

Unless I misunderstand, the voting is for the replies, not for the
questions. Or maybe the questions can be promoted to a queue, no
idea. But that's not that different from questions posted to Usenet. The
popular ones are asked often, the less popular ones once in a while, and
might also not result in solutions.


> I think Google Groups have 5-star-rating system? You might want
> to check on that.

B... no, I really prefer my Usenet via Gnus ;-).

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
"Alf P. Steinbach"  writes:

> * John Bokma, on 04.06.2010 20:19:
>> Steven D'Aprano  writes:
>>
>>> But the really sad thing is that you think that "bigger" automatically
>>> equals "better".
>>
>> I don't think that was the point.
>>
>> Anyway, not everbody can pick a provider, there are plenty of places
>> that have only one or maybe two. And if that's the choice and neither
>> carries Usenet you have to pay for Usenet like I do. Note that I
>> consider it well worth the 10 euros I pay for it.
>>
>> To me, it looks like the use of Usenet for text is on the
>> decline. I've been away from Usenet for like a year or so and could see
>> quite a difference. More and more ISPs in my experience are dropping
>> Usenet from their services. Mind, I think that the number of users on
>> Usenet (text only) still exceeds the number when I first used Usenet
>> (back in the early 90's). But usage is on the decline as far as I can
>> tell. On top of that I see people I know from Usenet now quite active on
>> Stack Overflow and sister sites.
>>
>> Finally, I have to disagree with your disagreement (which is just a
>> personal experience) based on my personal experience: it's harder to
>> find an ISP that carries Usenet. And I have experience with, oh, just 3
>> countries where I have been living in for the past 10 years.
>
> True.
>
> While Usenet traffic is still exponentially increasing, most of that's
> in binary groups, and it's spam.
>
> I think much of the decline of Usenet is correlated with an increase
> of laws designed to limit free speech and support all kinds
> surveillance.

In my experience, as in people I know who've left Usenet, reasons for
leaving Usenet are:

 1) spam, number 1 culprit being Google.
 2) newbies who don't care about posting guidelines
 3) regulars in their ivory towers

Other reasons:

 4) MFA (Made for AdSense) sites that pretend to be a forum but just
harvest all data from Usnet
 5) trolls and kooks.

> It started, as I see it, back in the early 90's with
> Playboy attempting to sue anyone who used the Lena picture in photo
> processing tests etc. (it's the standard image for that). They failed
> in that particular endeavour, but did succeed in shutting down
> thousands of sites worldwide displaying Playboy pictures.

I know of the use of Lena. And to be honest, I agree with Playboy that
they have the copyright. Some of the articles published on image
processing end up behind a paywall or in a book. And I don't think the
authors will be very happy if I convert their work in PDFs and offer it
as free download on my site. Everybody wants a free ride until they have
to create and maintain the rides in their own precious time with their
own money.

[...]

> Until some replacement for Usenet appears, online discussion will in
> general be effectively /local/, unknown to all but the parties
> currently using a given web forum, and it will in general not be
> archived.

I like Stackoverflow and its sister sites a lot.

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tallying occurrences in list

2010-06-04 Thread kj


Thank you all!

~K
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting MemoryError with dicts; suspect memory fragmentation

2010-06-04 Thread Bryan
Philip Semanchuk wrote:
> At PyCon 2010, Brandon Craig Rhodes presented about how dictionaries  
> work under the 
> hood:http://python.mirocommunity.org/video/1591/pycon-2010-the-mighty-dict...
>
> I found that very informative.

That's a fine presentation of hash tables in general and Python's
choices in particular. Also highly informative, while easily readable,
is the Objects/dictnotes.txt file in the Python source.

Fine as those resources may be, the issue here stands. Most of my own
Python issues turn out to be stupid mistakes, and the problem here
might be on that level, but Emin seems to have worked his problem and
gotten a bunch of stuff right. There is no good reason why
constructing a 50 kilobyte dict should fail with a MemoryError while
constructing 50 megabyte lists succeeds.


--
--Bryan Olson
-- 
http://mail.python.org/mailman/listinfo/python-list


Plotting in batch with no display

2010-06-04 Thread Hans Georg Schaathun
Admittedly not the strongest reason, but yet an important one,
for switching from Matlab to python/numpy/scipy/matplotlib,
is that Matlab is very cumbersome to run in batch.

Now I discover that some of the matplotlib.pyplot functions
(incl. plot and contour) insist on opening an X11 window 
(just like Matlab does).  I would have preferred just to create 
the plot straight on file.  The extra window is a nuisance on my 
laptop, it is deep-felt pain if I try to run it remotely.  It fails
completely if I run it without any display at all.

Oddly, the bar() function does not open a window by default.
I was very happy with that.  It works exactly the way I want.
(Why isn't pyplot more consistent?)

Is there something I have missed?  Is it possible to create
standard 2D plots and contour plots without a display, writing
the graphics straight into a PDF file?

I'll be grateful for any pointers and ideas,
:-- George
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to access data attributes of a class object

2010-06-04 Thread namrata
Thanks a lot Peter. It works.

On Jun 4, 12:26 pm, Peter Otten <__pete...@web.de> wrote:
> namrata wrote:
> > I am creating an instance of a class. for example let the class be
> > Temp and the attributes of the class be first_name and last_name.
> > in order to access the attributes i will usually use the following
> > command:
> > a = Temp()
> > a.last_name = "***"
>
> > now, i am using sqlalchemy and mapping a table in postgresql to
> > python. i am trying to implement a method where i can pass the column
> > name and a value to the method. the method will fire a query for that
> > column name and value. the query is as follows:
> > query = session.query(Temp).query.filter(Temp.last_name == some_value)
>
> > the column name passed to the method is stored in a local variable say
> > 'col_name'
> > how do i pass this local variable to the query. when i try the below
> > query it throws an error saying col_name is not an attirbute
> > query = session.query(Temp).query.filter(Temp.col_name == some_value)
>
> I'd guess you can use getattr():
>
> query = session.query(Temp).query.filter(getattr(Temp, col_name) ==
> some_value)
>
> Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: signed vs unsigned int

2010-06-04 Thread John Nagle

johnty wrote:

i'm reading bytes from a serial port, and storing it into an array.


   Try reading into a type "bytearray".  That's the proper data type
for raw bytes.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: tallying occurrences in list

2010-06-04 Thread Lie Ryan
On 06/05/10 04:38, Magdoll wrote:
> On Jun 4, 11:33 am, Peter Otten <__pete...@web.de> wrote:
>> kj wrote:
>>
>>> Task: given a list, produce a tally of all the distinct items in
>>> the list (for some suitable notion of "distinct").
>>
>>> Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b',
>>> 'c', 'a'], then the desired tally would look something like this:
>>
>>> [('a', 4), ('b', 3), ('c', 3)]
>>
>>> I find myself needing this simple operation so often that I wonder:
>>
>>> 1. is there a standard name for it?
>>> 2. is there already a function to do it somewhere in the Python
>>>standard library?
>>
>>> Granted, as long as the list consists only of items that can be
>>> used as dictionary keys (and Python's equality test for hashkeys
>>> agrees with the desired notion of "distinctness" for the tallying),
>>> then the following does the job passably well:
>>
>>> def tally(c):
>>> t = dict()
>>> for x in c:
>>> t[x] = t.get(x, 0) + 1
>>> return sorted(t.items(), key=lambda x: (-x[1], x[0]))
>>
>>> But, of course, if a standard library solution exists it would be
>>> preferable.  Otherwise I either cut-and-paste the above every time
>>> I need it, or I create a module just for it.  (I don't like either
>>> of these, though I suppose that the latter is much better than the
>>> former.)
>>
>>> So anyway, I thought I'd ask. :)
>>
>> Python 3.1 has, and 2.7 will have collections.Counter:
>>
> from collections import Counter
> c = Counter("abcabcabca")
> c.most_common()
>>
>> [('a', 4), ('c', 3), ('b', 3)]
>> 
>> Peter
>
> 
> Thanks Peter, I think you just answered my post :)

If you're using previous versions (2.4 and onwards) then:

[(o, len(list(g))) for o, g in itertools.groupby(sorted(myList))]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diff of Text

2010-06-04 Thread Patrick Maupin
On Jun 3, 9:54 pm, GZ  wrote:
> Hi All,
>
> I am looking for an algorithm that can compare to source code files
> line by line and find the minimum diff. I have looked at the difflib
> included in python. The problem is that it is designed to make the
> diff results easier for humans to read, instead of minimize the size
> of the output differencial. I would like an algorithm implementation
> that gives the absolute minimum difference between the two files.
>
> Can you help me?
>
> Thanks,
> gz

There's an "rsync.py" module in pypi -- one would think that would
have to solve that same problem...

Regards,
Pat

-- 
http://mail.python.org/mailman/listinfo/python-list


bz2 module doesn't work properly with all bz2 files

2010-06-04 Thread Magdoll
I'm not sure what's causing this, but depending on the compression
program used, the bz2 module sometimes exits earlier.

I used pbzip2 to compress my bz2 files and read through the file using
the bz2 module. The file descriptor always exits much earlier than
where the actual EOF is. If I use bzip2 instead of pbzip2 to compress
the files, then everything is fine.

My files are generally big (several GBs) so decompressing them is not
a wise choice, and it is a little unfortunate that I can't use pbzip2
because it's usually much faster than bz2.



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: signed vs unsigned int

2010-06-04 Thread Patrick Maupin
On Jun 2, 6:25 am, John Machin  wrote:
> On Jun 2, 4:43 pm, johnty  wrote:
>
> > i'm reading bytes from a serial port, and storing it into an array.
>
> > each byte represents a signed 8-bit int.
>
> > currently, the code i'm looking at converts them to an unsigned int by
> > doing ord(array[i]). however, what i'd like is to get the _signed_
> > integer value. whats the easiest way to do this?
>
> signed = unsigned if unsigned <= 127 else unsigned - 256

That works, but I prefer not using if/else for things that can be
described in an expression without it.  Other ways of expressing this
include:

signed = (unsigned & 127) - (unsigned & 128)
signed = (unsigned & 127) * 2 - unsigned
signed - unsigned - 2 * (unsigned & 128)

Regards,
Pat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Lie Ryan
On 06/05/10 05:04, Emile van Sebille wrote:
> On 6/4/2010 11:27 AM Terry Reedy said...
>> On 6/4/2010 12:28 PM, Emile van Sebille wrote:
>>
>>> Is there now a non-email method of posting to this list?
>>
>> Google <==> comp.lang.python <==> python-list <==>
>> gmane.comp.python.general
>>
>> where <==> is a bi-directional gateway.
> 
> Yes -- I use gmane as well.  But, IIRC, I needed to be on the mail list
> in order for my responses to show up because MailMan is the primary back
> end and I thought it's set to only accept posts from members.
> 
> Hence, my question.  Aren't we all members posting (ultimately)
> exclusively through email regardless of preferred reading interfaces?

No, I don't.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Lie Ryan
On 06/05/10 04:19, John Bokma wrote:
> Steven D'Aprano  writes:
> 
>> But the really sad thing is that you think that "bigger" automatically 
>> equals "better".
> 
> I don't think that was the point.
> 
> Anyway, not everbody can pick a provider, there are plenty of places
> that have only one or maybe two. And if that's the choice and neither
> carries Usenet you have to pay for Usenet like I do. Note that I
> consider it well worth the 10 euros I pay for it.

Isn't gmane available where you live? I've used gmane for newsgroups
that my local server doesn't carry. The only problem is that there's a
slight delay in opening new posts (0.5 seconds or so).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Street address parsing in Python, again.

2010-06-04 Thread John Nagle

John Nagle wrote:


   The parser at PyParsing:

 http://pyparsing.wikispaces.com/file/view/streetAddressParser.py

..Bad cases...
487 E. Middlefield Rd.  -> streetnumber = 487, streetname = E. MIDDLEFIELD
487 East Middlefield Road -> streetnumber = 487, streetname = EAST MIDDLEFIELD
226 West Wayne Street -> streetnumber = 226, streetname = WEST WAYNE
New Orchard Road -> streetnumber = , streetname = NEW
1 New Orchard Road -> streetnumber = 1 , streetname = NEW
390 Park Avenue -> streetnumber =, streetname = 390



  Here's a system that gets all the above cases right: the USC Deterministic
Address Parser.

https://webgis.usc.edu/Services/AddressNormalization/Interactive/DeterministicNormalization.aspx

This will parse a street address line alone, without a city, state, or ZIP code,
so it's not using a big database.  There's a technical paper

http://gislab.usc.edu/i/publications/gislabtr11.pdf

but it doesn't have that much detail.  However, now we know a solution
exists.  I've asked USC if they'll make the code available.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


RE: [python] pass the name of args

2010-06-04 Thread jyoung79
Would vars() help?  Check out this link:

http://www.daniweb.com/forums/thread134555.html

Jay

--

> def myDef(x)
>   doSomething x
>   result = x.
>   return coolThings
> -
> 
> WhatYourName = ('python','is','cool')
> 
> myDef(WhatYourName)
> 
> so what I am looking for in myDef
> 
>   result = WhatYourName
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to access data attributes of a class object

2010-06-04 Thread Peter Otten
namrata wrote:

> I am creating an instance of a class. for example let the class be
> Temp and the attributes of the class be first_name and last_name.
> in order to access the attributes i will usually use the following
> command:
> a = Temp()
> a.last_name = "***"
> 
> now, i am using sqlalchemy and mapping a table in postgresql to
> python. i am trying to implement a method where i can pass the column
> name and a value to the method. the method will fire a query for that
> column name and value. the query is as follows:
> query = session.query(Temp).query.filter(Temp.last_name == some_value)
> 
> the column name passed to the method is stored in a local variable say
> 'col_name'
> how do i pass this local variable to the query. when i try the below
> query it throws an error saying col_name is not an attirbute
> query = session.query(Temp).query.filter(Temp.col_name == some_value)

I'd guess you can use getattr():

query = session.query(Temp).query.filter(getattr(Temp, col_name) == 
some_value)

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Lie Ryan
On 06/04/10 11:56, John Bokma wrote:
> Phlip  writes:
> 
>> On Jun 3, 3:20 pm, geremy condra  wrote:
>>
 You mean like how I never get answers, to my super-easy GED-level
 questions, here??!
>>>
>>> I agree. This proves conclusively that a web forum is the right
>>> place for you.
>>
>> Ah, so you feel up to my "xsl for xmlrunner.py" question?
> 
> Just jumping in the middle, but if you're looking for a web based forum
> where you can ask questions, check out Stack Overflow (and sister sites,
> depending on your question). I've noticed over the last couple of months
> that often things I google for, are answered on Stack Overflow. One
> thing that would've been nice to have on Usenet that I like is the
> ability to vote answers up or down. I think Usenet would've been a bit
> better with that option.

Probably. A vote up/down feature tend to highlight popular problems, but
it also buries less popular problems that might have perfectly good
answers. I think Google Groups have 5-star-rating system? You might want
to check on that.
-- 
http://mail.python.org/mailman/listinfo/python-list


how to access data attributes of a class object

2010-06-04 Thread namrata
Hi,

i am new to python and sqlalchemy. so my doubt mite be very silly.

I am creating an instance of a class. for example let the class be
Temp and the attributes of the class be first_name and last_name.
in order to access the attributes i will usually use the following
command:
a = Temp()
a.last_name = "***"

now, i am using sqlalchemy and mapping a table in postgresql to
python. i am trying to implement a method where i can pass the column
name and a value to the method. the method will fire a query for that
column name and value. the query is as follows:
query = session.query(Temp).query.filter(Temp.last_name == some_value)

the column name passed to the method is stored in a local variable say
'col_name'
how do i pass this local variable to the query. when i try the below
query it throws an error saying col_name is not an attirbute
query = session.query(Temp).query.filter(Temp.col_name == some_value)

please help.
thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Alf P. Steinbach

* John Bokma, on 04.06.2010 20:19:

Steven D'Aprano  writes:


But the really sad thing is that you think that "bigger" automatically
equals "better".


I don't think that was the point.

Anyway, not everbody can pick a provider, there are plenty of places
that have only one or maybe two. And if that's the choice and neither
carries Usenet you have to pay for Usenet like I do. Note that I
consider it well worth the 10 euros I pay for it.

To me, it looks like the use of Usenet for text is on the
decline. I've been away from Usenet for like a year or so and could see
quite a difference. More and more ISPs in my experience are dropping
Usenet from their services. Mind, I think that the number of users on
Usenet (text only) still exceeds the number when I first used Usenet
(back in the early 90's). But usage is on the decline as far as I can
tell. On top of that I see people I know from Usenet now quite active on
Stack Overflow and sister sites.

Finally, I have to disagree with your disagreement (which is just a
personal experience) based on my personal experience: it's harder to
find an ISP that carries Usenet. And I have experience with, oh, just 3
countries where I have been living in for the past 10 years.


True.

While Usenet traffic is still exponentially increasing, most of that's in binary 
groups, and it's spam.


I think much of the decline of Usenet is correlated with an increase of laws 
designed to limit free speech and support all kinds surveillance. It started, as 
I see it, back in the early 90's with Playboy attempting to sue anyone who used 
the Lena picture in photo processing tests etc. (it's the standard image for 
that). They failed in that particular endeavour, but did succeed in shutting 
down thousands of sites worldwide displaying Playboy pictures. The Church of 
Scientology picked up on the idea that a private company can /control/ net 
content worldwide by way of laws designed for other things. The record and movie 
industry caught on to this. Governments of some special countries such China, 
Saudi-Arabia and Iran, plus, very suprising to me, Australia, caught on to it, 
that is, the idea of controlling net content, or at least access to that 
content. Then finally George W. Bush caught on to it, and with American ISPs 
legally responsible for the content of the traffic, well, the following from 
Wikipedia isn't quite chronological but is quite clear:




In 2008, Verizon Communications, Time Warner Cable and Sprint Nextel signed an 
agreement with Attorney General of New York Andrew Cuomo to shut down access to 
sources of child pornography.[31]  Time Warner Cable stopped offering access to 
Usenet. Verizon reduced its access to the "Big 8" hierarchies. Sprint stopped 
access to the alt.* hierarchies. AT&T stopped access to the alt.binaries.* 
hierarchies. Cuomo never specifically named Usenet in his anti-child pornography 
campaign. David DeJean of PC World said that some worry that the ISPs used 
Cuomo's campaign as an excuse to end portions of Usenet access, as it is costly 
for the internet service providers. In 2008 AOL, which no longer offered Usenet 
access, and the four providers that responded to the Cuomo campaign were the 
five largest internet service providers in the United States; they had more than 
50% of the U.S. ISP marketshare.[32]  On June 8, 2009, AT&T announced that it 
would no longer provide access to the Usenet service as of July 15, 2009.[33]


AOL announced that it would discontinue its integrated Usenet service in early 
2005, citing the growing popularity of weblogs, chat forums and on-line 
conferencing.[34] The AOL community had a tremendous role in popularizing Usenet 
some 11 years earlier,[citation needed] with all of its positive and negative 
aspects. This change marked the end of the legendary Eternal September. Others, 
however, feel that Google Groups, especially with its new user interface, has 
picked up the torch that AOL has dropped—and that the so-called Eternal 
September has yet to end.[citation needed]


In August, 2009, Verizon announced that it would discontinue access to Usenet on 
September 30, 2009.[35][36]


In April 2010, Cox Communications announced (via email) that it would 
discontinue Usenet service, effective June 30, 2010. JANET(UK) announced it will 
discontinue Usenet service, effective July 31, 2010, citing Google Groups as an 
alternative.[37] Microsoft announced that it would discontinue support for it's 
public newsgroups (msnews.microsoft.com) from June 1, 2010, offering web forums 
as an alternative.




In short, in the future you will no longer be able to access old articles via 
archives such as Google Groups (Google picked up that archive from Deja News).


Until some replacement for Usenet appears, online discussion will in general be 
effectively /local/, unknown to all but the parties currently using a given web 
forum, and it will in general not be archived.


As I see it, those who have made and conti

Re: Python Forum

2010-06-04 Thread Emile van Sebille

On 6/4/2010 11:27 AM Terry Reedy said...

On 6/4/2010 12:28 PM, Emile van Sebille wrote:


Is there now a non-email method of posting to this list?


Google <==> comp.lang.python <==> python-list <==>
gmane.comp.python.general

where <==> is a bi-directional gateway.


Yes -- I use gmane as well.  But, IIRC, I needed to be on the mail list 
in order for my responses to show up because MailMan is the primary back 
end and I thought it's set to only accept posts from members.


Hence, my question.  Aren't we all members posting (ultimately) 
exclusively through email regardless of preferred reading interfaces?


Emile

--
http://mail.python.org/mailman/listinfo/python-list


Re: tallying occurrences in list

2010-06-04 Thread MRAB

kj wrote:





Task: given a list, produce a tally of all the distinct items in
the list (for some suitable notion of "distinct").

Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b',
'c', 'a'], then the desired tally would look something like this:

[('a', 4), ('b', 3), ('c', 3)]

I find myself needing this simple operation so often that I wonder:

1. is there a standard name for it?
2. is there already a function to do it somewhere in the Python
   standard library?

Granted, as long as the list consists only of items that can be
used as dictionary keys (and Python's equality test for hashkeys
agrees with the desired notion of "distinctness" for the tallying),
then the following does the job passably well:

def tally(c):
t = dict()
for x in c:
t[x] = t.get(x, 0) + 1
return sorted(t.items(), key=lambda x: (-x[1], x[0]))

But, of course, if a standard library solution exists it would be
preferable.  Otherwise I either cut-and-paste the above every time
I need it, or I create a module just for it.  (I don't like either
of these, though I suppose that the latter is much better than the
former.)

So anyway, I thought I'd ask. :)


In Python 3 there's the 'Counter' class in the 'collections' module.
It'll also be in Python 2.7.

For earlier versions there's this:

http://code.activestate.com/recipes/576611/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Andreas Waldenburger
On Fri, 04 Jun 2010 20:36:02 +0200 "Alf P. Steinbach" 
wrote:

> * Andreas Waldenburger, on 04.06.2010 20:21:
> > On Fri, 04 Jun 2010 00:57:15 +1000 Ben Finney
> >   wrote:
> >
> >> Andreas Waldenburger  writes:
> >>
> >>> But consolidation is the *only* way to go, really. The parallelism
> >>> between c.l.p. and python-list is great already. Now throw some
> >>> sort of Forum in the mix
> >>
> >> This already *is* a forum. Whatever it is you think is needed, it's
> >> already a forum. Can you be more specific about what you would add?
> >>
> >
> > I meant a web forum.
> 
> You can access [comp.lang.python] via Google Groups and other web
> based interfaces.
> 
> So it already is a web forum.
> 
Huh. I've never looked at it that way.

OK, then. Forget what I said about Wave. Oh, you have? Good.

;)
/W

-- 
INVALID? DE!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
Emile van Sebille  writes:

> On 6/3/2010 10:41 PM Steven D'Aprano said...
>> On Thu, 03 Jun 2010 06:15:20 -0400, Adam Tauno Williams wrote:
>>> Most people use this list via e-mail,
>>
>> How do you know? Do you have evidence for this, or are you just making it
>> up?
>>
>
> Is there now a non-email method of posting to this list?

No idea what "this list" is, but I am reading your message in Gnus via Usenet.

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
Steven D'Aprano  writes:

> Sure, a lot of those 1,800 posts are spam, but the spammers wouldn't 
> waste their time if they didn't think there were people still on
> Usenet.

Heh, since spamming goes automatically who cares how many people it
reaches. I also see spam in which people forget to include a URL,
etc. My site is daily hit by badly written spam software.

So, no: spam is not by far any way to measure the number of readers. On
top of that, there is /no way/ to even determine how many people read a
given Usenet group.

> How do you know? Do you have evidence for this, or are you just making it 
> up? 

I guess the same way as your remark regarding spam: guessing (I guess) ;-)

> I happen to know at least one of the Gnus users is using News, so that's 
> 1 definite News, 2 Web, 4 either News or email, and no definite email.

Fwiw: I use Usenet :-).

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange syntax error

2010-06-04 Thread Jerry Hill
On Fri, Jun 4, 2010 at 1:31 PM, _wolf  wrote:
>    File "", line 6
>      #
>      ^
>  SyntaxError: invalid syntax

I believe you're encountering this bug:
http://bugs.python.org/issue1184112

It's been fixed for 2.7 and 3.2.  Until then, you'll need to work
around it.  You can either append a newline to the end of any source
snippets that you are exec-ing, or if you're writing the code snippets
that are being exec-ed yourself, don't write them in such a way that
they trigger the bug.

-- 
Jerry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tallying occurrences in list

2010-06-04 Thread Magdoll
On Jun 4, 11:33 am, Peter Otten <__pete...@web.de> wrote:
> kj wrote:
>
> > Task: given a list, produce a tally of all the distinct items in
> > the list (for some suitable notion of "distinct").
>
> > Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b',
> > 'c', 'a'], then the desired tally would look something like this:
>
> > [('a', 4), ('b', 3), ('c', 3)]
>
> > I find myself needing this simple operation so often that I wonder:
>
> > 1. is there a standard name for it?
> > 2. is there already a function to do it somewhere in the Python
> >    standard library?
>
> > Granted, as long as the list consists only of items that can be
> > used as dictionary keys (and Python's equality test for hashkeys
> > agrees with the desired notion of "distinctness" for the tallying),
> > then the following does the job passably well:
>
> > def tally(c):
> >     t = dict()
> >     for x in c:
> >         t[x] = t.get(x, 0) + 1
> >     return sorted(t.items(), key=lambda x: (-x[1], x[0]))
>
> > But, of course, if a standard library solution exists it would be
> > preferable.  Otherwise I either cut-and-paste the above every time
> > I need it, or I create a module just for it.  (I don't like either
> > of these, though I suppose that the latter is much better than the
> > former.)
>
> > So anyway, I thought I'd ask. :)
>
> Python 3.1 has, and 2.7 will have collections.Counter:
>
> >>> from collections import Counter
> >>> c = Counter("abcabcabca")
> >>> c.most_common()
>
> [('a', 4), ('c', 3), ('b', 3)]
>
> Peter


Thanks Peter, I think you just answered my post :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
Pierre Quentel  writes:

> They certainly *can* distinguish. But it's so easy to make it more
> explicit with syntax highlighting, background color, border etc. that
> most sites about programing languages use it, including the Python
> home site itself, or the Python cookbook on Active State

[..]

> That's 2 different things. When you use a programming language you
> know you have to adopt the syntax defined by the program. When you
> write something in a forum, you expect that the editor will be smart
> enough to know that http://pythonforum.org is a URL

You're using a bad Usenet client. Switch to Gnus, part of Emacs, for
example and you can have both.

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Andreas Waldenburger
On Fri, 04 Jun 2010 09:28:23 -0700 Emile van Sebille 
wrote:

> On 6/3/2010 10:41 PM Steven D'Aprano said...
> > On Thu, 03 Jun 2010 06:15:20 -0400, Adam Tauno Williams wrote:
> >> Most people use this list via e-mail,
> >
> > How do you know? Do you have evidence for this, or are you just
> > making it up?
> >
> 
> Is there now a non-email method of posting to this list?
> 
Te-he. Yes.

In case you're not being ironic:


/W

-- 
INVALID? DE!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tallying occurrences in list

2010-06-04 Thread Magdoll
On Jun 4, 11:28 am, Paul Rubin  wrote:
> kj  writes:
> > 1. is there a standard name for it?
>
> I don't know of one, or a stdlib for it, but it's pretty trivial.
>
> > def tally(c):
> >     t = dict()
> >     for x in c:
> >         t[x] = t.get(x, 0) + 1
> >     return sorted(t.items(), key=lambda x: (-x[1], x[0]))
>
> I like to use defaultdict and tuple unpacking for code like that:
>
>  from collections import defaultdict
>  def tally(c):
>      t = defaultdict(int)
>      for x in c:
>          t[x] += 1
>      return sorted(t.iteritems(), key=lambda (k,v): (-v, k))

I would also very much like to see this become part of the standard
library. Sure the code is easy to write but I use this incredibly
often and I've always wished I would have a one-line function call
that has the same output as the mysql query:

"SELECT id, count(*) FROM table GROUP BY somefield"

or maybe there is already a short solution to this that I'm not aware
of...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Alf P. Steinbach

* Andreas Waldenburger, on 04.06.2010 20:21:

On Fri, 04 Jun 2010 00:57:15 +1000 Ben Finney
  wrote:


Andreas Waldenburger  writes:


But consolidation is the *only* way to go, really. The parallelism
between c.l.p. and python-list is great already. Now throw some sort
of Forum in the mix


This already *is* a forum. Whatever it is you think is needed, it's
already a forum. Can you be more specific about what you would add?



I meant a web forum.


You can access [comp.lang.python] via Google Groups and other web based 
interfaces.

So it already is a web forum.


Cheers & hth.,

- Alf


--
blog at http://alfps.wordpress.com>
--
http://mail.python.org/mailman/listinfo/python-list


Re: tallying occurrences in list

2010-06-04 Thread Peter Otten
kj wrote:

> 
> 
> 
> 
> 
> Task: given a list, produce a tally of all the distinct items in
> the list (for some suitable notion of "distinct").
> 
> Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b',
> 'c', 'a'], then the desired tally would look something like this:
> 
> [('a', 4), ('b', 3), ('c', 3)]
> 
> I find myself needing this simple operation so often that I wonder:
> 
> 1. is there a standard name for it?
> 2. is there already a function to do it somewhere in the Python
>standard library?
> 
> Granted, as long as the list consists only of items that can be
> used as dictionary keys (and Python's equality test for hashkeys
> agrees with the desired notion of "distinctness" for the tallying),
> then the following does the job passably well:
> 
> def tally(c):
> t = dict()
> for x in c:
> t[x] = t.get(x, 0) + 1
> return sorted(t.items(), key=lambda x: (-x[1], x[0]))
> 
> But, of course, if a standard library solution exists it would be
> preferable.  Otherwise I either cut-and-paste the above every time
> I need it, or I create a module just for it.  (I don't like either
> of these, though I suppose that the latter is much better than the
> former.)
> 
> So anyway, I thought I'd ask. :)

Python 3.1 has, and 2.7 will have collections.Counter:

>>> from collections import Counter
>>> c = Counter("abcabcabca")
>>> c.most_common()
[('a', 4), ('c', 3), ('b', 3)]

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tallying occurrences in list

2010-06-04 Thread Paul Rubin
kj  writes:
> 1. is there a standard name for it?

I don't know of one, or a stdlib for it, but it's pretty trivial.

> def tally(c):
> t = dict()
> for x in c:
> t[x] = t.get(x, 0) + 1
> return sorted(t.items(), key=lambda x: (-x[1], x[0]))

I like to use defaultdict and tuple unpacking for code like that:

 from collections import defaultdict
 def tally(c):
 t = defaultdict(int)
 for x in c:
 t[x] += 1
 return sorted(t.iteritems(), key=lambda (k,v): (-v, k))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Terry Reedy

On 6/4/2010 12:28 PM, Emile van Sebille wrote:


Is there now a non-email method of posting to this list?


Google <==> comp.lang.python <==> python-list <==> gmane.comp.python.general

where <==> is a bi-directional gateway.

Gmane mirrors about 250 other Python mailing lists under 
gman.comp.python.xxx. I currently subscibe to 3 others.


gmane does this because many people like to
1) look at a group first without subscribing (in the mail list sense, as 
opposed to the newgroup sense of click a box)
2) keep messages for each group separated (without having to add folders 
and filters to their email reader)

3) only download messages they want to read

Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Andreas Waldenburger
On Fri, 04 Jun 2010 00:57:15 +1000 Ben Finney
 wrote:

> Andreas Waldenburger  writes:
> 
> > But consolidation is the *only* way to go, really. The parallelism
> > between c.l.p. and python-list is great already. Now throw some sort
> > of Forum in the mix
> 
> This already *is* a forum. Whatever it is you think is needed, it's
> already a forum. Can you be more specific about what you would add?
> 

I meant a web forum.

/W

-- 
INVALID? DE!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread John Bokma
Steven D'Aprano  writes:

> But the really sad thing is that you think that "bigger" automatically 
> equals "better".

I don't think that was the point.

Anyway, not everbody can pick a provider, there are plenty of places
that have only one or maybe two. And if that's the choice and neither
carries Usenet you have to pay for Usenet like I do. Note that I
consider it well worth the 10 euros I pay for it.

To me, it looks like the use of Usenet for text is on the
decline. I've been away from Usenet for like a year or so and could see
quite a difference. More and more ISPs in my experience are dropping
Usenet from their services. Mind, I think that the number of users on
Usenet (text only) still exceeds the number when I first used Usenet
(back in the early 90's). But usage is on the decline as far as I can
tell. On top of that I see people I know from Usenet now quite active on
Stack Overflow and sister sites.

Finally, I have to disagree with your disagreement (which is just a
personal experience) based on my personal experience: it's harder to
find an ISP that carries Usenet. And I have experience with, oh, just 3
countries where I have been living in for the past 10 years.

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


tallying occurrences in list

2010-06-04 Thread kj





Task: given a list, produce a tally of all the distinct items in
the list (for some suitable notion of "distinct").

Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b',
'c', 'a'], then the desired tally would look something like this:

[('a', 4), ('b', 3), ('c', 3)]

I find myself needing this simple operation so often that I wonder:

1. is there a standard name for it?
2. is there already a function to do it somewhere in the Python
   standard library?

Granted, as long as the list consists only of items that can be
used as dictionary keys (and Python's equality test for hashkeys
agrees with the desired notion of "distinctness" for the tallying),
then the following does the job passably well:

def tally(c):
t = dict()
for x in c:
t[x] = t.get(x, 0) + 1
return sorted(t.items(), key=lambda x: (-x[1], x[0]))

But, of course, if a standard library solution exists it would be
preferable.  Otherwise I either cut-and-paste the above every time
I need it, or I create a module just for it.  (I don't like either
of these, though I suppose that the latter is much better than the
former.)

So anyway, I thought I'd ask. :)

~K
-- 
http://mail.python.org/mailman/listinfo/python-list


Street address parsing in Python, again.

2010-06-04 Thread John Nagle

   I'm still struggling with street address parsing in Python.
(Previous discussion: 
http://www.velocityreviews.com/forums/t720759-usable-street-address-parser-in-python.html)


   I need something good enough to reliably extract street name and number.
That gives me something I can match against databases.

   There are several parsers available in Perl, and various online services that
have a street name database.  The online parsers are good, but I need to encode
some big databases, and the online ones are either rate-limited or expensive.

   The parser at PyParsing:

 http://pyparsing.wikispaces.com/file/view/streetAddressParser.py

seems to work on about 80% of addresses.  Addresses with "pre-directionals"
and street types before the name seem to give the most trouble:

487 E. Middlefield Rd.  -> streetnumber = 487, streetname = E. MIDDLEFIELD
487 East Middlefield Road -> streetnumber = 487, streetname = EAST MIDDLEFIELD
226 West Wayne Street -> streetnumber = 226, streetname = WEST WAYNE
(Those are all Verisign offices)

New Orchard Road -> streetnumber = , streetname = NEW
1 New Orchard Road -> streetnumber = 1 , streetname = NEW
(IBM corporate HQ)

390 Park Avenue -> streetnumber =, streetname = 390
(Alcoa corporate HQ)

None of those addresses are exotic or corner cases, but they're
all mis-parsed.

   There's a USPS standard on this which might be helpful.

http://pe.usps.com/text/pub28/28c2_003.html

That says "When parsing the Delivery Address Line into the individual 
components, start from the right-most element of the address and work toward the 
left. Place each element in the appropriate field until all address components 
are isolated."  PyParsing works left to right, and trying to do look-ahead to

achieve the effect of right-to-left isn't working.  It may be necessary to split
the input, reverse the tokens, and write a parser that works in reverse.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: Missing DLL in win98

2010-06-04 Thread Terry Reedy

On 6/4/2010 9:08 AM, Spyder42 wrote:

On Fri, 04 Jun 2010 14:50:28 +0200, Christian Heimes



Python 2.6 is not supported on Windows 98 and earlier. You need at least
Windows 2000 with a recent service pack.

Christian


So your response is either, you don't know if there is a fix, or 'No
way in h377.' You couldn't figure out by my post that I already knew
that?


Get off your high horse. Dumping on volunteer helpers is a good way to 
drive them away.


It was not obvious, without closely reading your original post, and even 
then it is not clear, that you *knew* than 2.6 was not supported on 
Win98. You could have asked 'I know 2.6+ is not officially supported in 
win98. Does anyone know a workaround other than upgrading windows or 
sticking with 2.5?". *That* would have been clear.


Terry Jan Reedy


--
http://mail.python.org/mailman/listinfo/python-list


Re: General questions - where & how

2010-06-04 Thread Terry Reedy

On 6/4/2010 1:35 PM, Philip Semanchuk wrote:


On Jun 4, 2010, at 1:22 PM, Uriah Eisenstein wrote:


Hi all,
I'm relatively new to Python and have a few questions. Frankly, it
took me a
while to find on python.org what seems like a suitable place to post my
questions. However, I'd like to check the archives and see if they
haven't
been discussed already...


Good thinking!



But I don't find a Search function. Is there such
a thing?


I use Google's "site" keyword search. e.g. to search the archives for
"banana":
http://www.google.com/search?q=site%3Amail.python.org%2Fpipermail%2Fpython-list%2F++banana


One can also search mailing lists mirrored and archived by gmane
http://search.gmane.org/
This is gmane.comp.python.general. There are about 200 other g.c.python 
lists/groups that are more specialized. I have no idea about comparitive 
performance.


Terry Jan Reedy



--
http://mail.python.org/mailman/listinfo/python-list


Re: [python] pass the name of args

2010-06-04 Thread Terry Reedy

On 6/4/2010 7:32 AM, macm wrote:

A few types of objects have definition names (.__name__ attribute). All 
have 0 to many namespace names. If you want to pass an attribute name, 
pass it -- as a string.



def myDef(x)
doSomething x
result = x.
return coolThings


def f(x. x_attr_name):
  ...
  res = getattr(x, x__attr_name)
  ...

Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: weird pickle behavior in Python 3.1.2 + Eclipse 3.5.2

2010-06-04 Thread kirby.ur...@gmail.com
On Jun 4, 9:47 am, Peter Otten <__pete...@web.de> wrote:

> I can provoke the error in "naked" Python 3 by changing the
> Example.__module__ attribute:
>
> Python 3.1.1+ (r311:74480, Nov  2 2009, 15:45:00)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.

> >>> import pickle
> >>> class Example:
>
> ...     pass
> ...
> >>> pickle.dumps(Example())
>
> b'\x80\x03c__main__\nExample\nq\x00)\x81q\x01}q\x02b.'

> >>> Example.__module__ = "builtins"
> >>> pickle.dumps(Example())
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python3.1/pickle.py", line 1358, in dumps
>     Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
> _pickle.PicklingError: Can't pickle : attribute lookup
> builtins.Example failed
>
> What's the value of __module__ when you run your code in Eclipse?
>
> Peter

Thank you for replying.

Here's from Eclipse console:

>>> Example.__module__
'builtins'

>>> __name__
'builtins'

Duplicating your result in naked Python:

Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> class Example:
pass

>>> import pickle
>>> Example.__module__
'__main__'
>>> f = open('testpickle.pkl','wb')
>>> obj = Example()
>>> obj
<__main__.Example object at 0x02A26690>
>>> pickle.dump(obj, f)

>>> Example.__module__ = 'builtins'
>>> obj2 = Example()

>>> pickle.dump(obj2, f)
Traceback (most recent call last):
  File "", line 1, in 
pickle.dump(obj2, f)
  File "C:\Python31\lib\pickle.py", line 1354, in dump
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle : attribute
lookup builtins.Example failed

So what if I'm in an Eclipse pydev console and
change the Example.__module__ to '__main__'

>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC
v.1500 32 bit (Intel)]
>>> import pickle
>>> class Example:
... pass
...
>>> Example.__module__
'builtins'
>>> Example.__module__ = '__main__'
>>> obj = Example()
>>> obj
<__main__.Example object at 0x029E8FD0>
>>> f = open('testpickle.pkl','wb')
>>> pickle.dump(obj, f)
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python31\lib\pickle.py", line 1354, in dump
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle :
attribute lookup __main__.Example failed
>>>

Dang.

Any insights?

Kirby
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: General questions - where & how

2010-06-04 Thread Philip Semanchuk


On Jun 4, 2010, at 1:22 PM, Uriah Eisenstein wrote:


Hi all,
I'm relatively new to Python and have a few questions. Frankly, it  
took me a
while to find on python.org what seems like a suitable place to post  
my
questions. However, I'd like to check the archives and see if they  
haven't

been discussed already...


Good thinking!



But I don't find a Search function. Is there such
a thing?


I use Google's "site" keyword search. e.g. to search the archives for  
"banana":

http://www.google.com/search?q=site%3Amail.python.org%2Fpipermail%2Fpython-list%2F++banana


Enjoy
P
--
http://mail.python.org/mailman/listinfo/python-list


strange syntax error

2010-06-04 Thread _wolf
this may not be an earth-shattering deficiency of python, but i still
wonder about the rationale behind the following behavior: when i
run ::

  source = """
  print( 'helo' )
  if __name__ == '__main__':
print( 'yeah!' )

  #"""

  print( compile( source, '', 'exec' ) )

i get ::

File "", line 6
  #
  ^
  SyntaxError: invalid syntax

i can avoid this exception by (1) deleting the trailing ``#``; (2)
deleting or outcommenting the ``if __name__ == '__main__':\n
print( 'yeah!' )`` lines; (3) add a newline to very end of the
source.

moreover, if i have the source end without a trailing newline right
behind the ``print( 'yeah!' )``, the source will also compile without
error.

i could also reproduce this behavior with python 2.6, so it’s not new
to the 3k series.

i find this error to be highly irritating, all the more since when i
put above source inside a file and execute it directly or have it
imported, no error will occur—which is the expected behavior.

a ``#`` (hash) outside a string literal should always represent the
start of a (possibly empty) comment in a python source; moreover, the
presence or absence of a  ``if __name__ == '__main__'`` clause should
not change the interpretation of a soure on a syntactical level.

can anyone reproduce the above problem, and/or comment on the
phenomenon?

cheers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: General questions - where & how

2010-06-04 Thread Alex Hall
I am not sure about a search feature for the archives, but I can tell
you about a "tutor" list for those new and somewhat new to Python
(like me). Of course, both that list and this one are excellent
resources, but the tutor list seems to be for questions generally
encountered by relatively new Python programmers. Just FYI.

On 6/4/10, Uriah Eisenstein  wrote:
> Hi all,
> I'm relatively new to Python and have a few questions. Frankly, it took me a
> while to find on python.org what seems like a suitable place to post my
> questions. However, I'd like to check the archives and see if they haven't
> been discussed already... But I don't find a Search function. Is there such
> a thing?
>
> TIA,
> Uriah
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


General questions - where & how

2010-06-04 Thread Uriah Eisenstein
Hi all,
I'm relatively new to Python and have a few questions. Frankly, it took me a
while to find on python.org what seems like a suitable place to post my
questions. However, I'd like to check the archives and see if they haven't
been discussed already... But I don't find a Search function. Is there such
a thing?

TIA,
Uriah
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with xml iterparse

2010-06-04 Thread bfrederi
On Jun 3, 4:13 pm, bfrederi  wrote:
> On Jun 3, 3:59 pm, Chris Rebert  wrote:
>
>
>
> > On Thu, Jun 3, 2010 at 1:44 PM, bfrederi  wrote:
> > > I am using lxml iterparse and running into a very obscure error. When
> > > I run iterparse on a file, it will occasionally return an element that
> > > has a element.text == None when the element clearly has text in it.
>
> > > I copy and pasted the problem xml into a python string, used StringIO
> > > to create a file-like object out of it, and ran a test using iterparse
> > > with expected output, and it ran perfectly fine. So it only happens
> > > when I try to run iterparse on the actual file.
>
> > > So then I tried opening the file, reading the data, turning that data
> > > into a file-like object using StringIO, then running iterparse on it,
> > > and the same problem (element.text == None) occurred.
>
> > > I even tried this:
> > > f = codecs.open(abbyy_filename, 'r', encoding='utf-8')
> > > file_data = f.read()
> > > file_like_object = StringIO.StringIO(file_data)
> > > for event, element in iterparse(file_like_object, events=("start",
> > > "end")):
>
> > IIRC, XML parsers operate on bytes directly (since they have to
> > determine the encoding themselves anyway), not pre-decoded Unicode
> > characters, so I think your manual UTF-8 decoding could be the
> > problem.
> > Have you tried simply:
>
> > f = open(abbyy_filename, 'r')
> > for event, element in iterparse(f, events=("start", "end")):
> >     #whatever
>
> > ?
>
> > Apologies if you already have, but since you didn't include the
> > original, albeit probably trivial, error-causing code, this relatively
> > simple error couldn't be ruled out.
>
> > Cheers,
> > Chris
> > --http://blog.rebertia.com
>
> Sorry for not mentioning it, but I tried that as well and it failed.
> Here is the relevant class. AbbyyLine and Abbyyword just take the
> element's text and writes it to a file/file-like object. parse_doc is
> where I use iterparse. The relevant part is very minimal and there is
> a lot of fluff to ignore, so I didn't initially post it:
>
> class AbbyyDocParse(object):
>
>     """Takes an abbyy filename and parses the contents"""
>     def __init__(self, abbyy_filename, extension=DEFAULT_ABBYY_EXT,
>         format_list=OUTPUT_TYPES, string_only=False):
>         self.extension = extension
>         self.format_list = format_list
>         #Create the file handles for the output files
>         self.create_filehandles(abbyy_filename, string_only)
>         #Parse the document
>         self.parse_doc(abbyy_filename)
>         #Close the output filehandles
>         self.close_filehandles(abbyy_filename, string_only)
>
>     def create_filehandles(self, abbyy_filename, string_only):
>         """Create output filehandles"""
>         #if output goes to a file
>         if not string_only:
>             #Make sure the file is an abbyy file
>             if not abbyy_filename.endswith(self.extension):
>                 raise ParserException, "Bad abbyy filename given: %s"
> \
>                     % (abbyy_filename)
>             #get the base path and filename for output files
>             filename = abbyy_filename.replace(self.extension, '')
>         #Loop through the different formats
>         for format_type in self.format_list:
>             #if output goes to a file
>             if not string_only:
>                 #Create output filename
>                 out_file = "%s%s" % (filename,
> OUTPUT_EXTENSIONS.get(format_type))
>                 #Opens the format type filehandle
>                 try:
>                     setattr(self, "%s_handle" % (format_type),
> open(out_file,'w'))
>                 except:
>                     raise IOError, "Could not open file: %s" %
> (out_file)
>             #if output goes to a string
>             else:
>                 #Opens the format type StringIO
>                 try:
>                     setattr(self, "%s_handle" % (format_type),
> StringIO.StringIO())
>                 except:
>                     raise IOError, "Could not open string output: %s"
> % (out_file)
>
>     def parse_doc(self, abbyy_filename):
>         """Parses the abbyy document"""
>         #Write the first line of the xml doc, if specified
>         if getattr(self, 'xml_handle', None):
>             self.xml_handle.write(' encoding="utf-8"?>\n')
>         #Memory efficient iterparse opens file and loops through
> content
>         for event, element in iterparse(abbyy_filename,
> events=("start", "end")):
>             #ignore the namespace, if it has one
>             if NAMESPACE_REGEX.search(element.tag, 0):
>                 element_tag = NAMESPACE_REGEX.search(element.tag,
> 0).group(1)
>             else:
>                 element_tag = element.tag
>             #if this is the page element
>             if element_tag == 'page':
>                 self.write_page(event, element)
>             #If at the beginning of the line
>             elif element_tag == 'line' an

Re: weird pickle behavior in Python 3.1.2 + Eclipse 3.5.2

2010-06-04 Thread Peter Otten
kirby.ur...@gmail.com wrote:

> Here we are in an Eclipse pydev console, running Python 3.1.2.  For
> the most part, everything is working great.
> 
> However...
> 
 import sys; print('%s %s' % (sys.executable or sys.platform,
 sys.version))
> C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC
> v.1500 32 bit (Intel)]
> 
 import pickle
 class Example:
> ... def __init__(self):
> ... self.name = "Hello"
> ... def __repr__(self):
> ... return "an Example object named {}".format(self.name)
> ...
> ...
 obj = Example()
 obj
> an Example object named Hello
> 
> Note that I'm opening in binary, like I'm supposed to with this
> latest protocol:
> 
 f = open("testpickle.pkl",'wb')
> 
> Should be able to do this, no problemo:
> 
 pickle.dump(obj, f)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\Python31\lib\pickle.py", line 1354, in dump
> Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
> _pickle.PicklingError: Can't pickle : attribute
> lookup builtins.Example failed
> 
> The above works fine in "naked Python" 3.1.2 by the way.
> So this could be a problem with Eclipse / Pydev and/or
> user error.  What am I missing?
> 
> Just normal data structures work:
> 
 test = [1,2,3]
 pickle.dump(test,f)
 f.close()

> 
> Any other Eclipse users out there who can at least duplicate this
> weirdness?

I can provoke the error in "naked" Python 3 by changing the 
Example.__module__ attribute:

Python 3.1.1+ (r311:74480, Nov  2 2009, 15:45:00)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> class Example:
... pass
...
>>> pickle.dumps(Example())
b'\x80\x03c__main__\nExample\nq\x00)\x81q\x01}q\x02b.'
>>> Example.__module__ = "builtins"
>>> pickle.dumps(Example())
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.1/pickle.py", line 1358, in dumps
Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle : attribute lookup 
builtins.Example failed

What's the value of __module__ when you run your code in Eclipse?

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Emile van Sebille

On 6/3/2010 10:41 PM Steven D'Aprano said...

On Thu, 03 Jun 2010 06:15:20 -0400, Adam Tauno Williams wrote:

Most people use this list via e-mail,


How do you know? Do you have evidence for this, or are you just making it
up?



Is there now a non-email method of posting to this list?

Emile



--
http://mail.python.org/mailman/listinfo/python-list


Re: getting MemoryError with dicts; suspect memory fragmentation

2010-06-04 Thread Philip Semanchuk


On Jun 4, 2010, at 12:06 PM, Bryan wrote:


Emin.shopper wrote:

dmtr wrote:
I'm still unconvinced that it is a memory fragmentation problem.  
It's

very rare.


You could be right. I'm not an expert on python memory management.  
But

if it isn't memory fragmentation, then why is it that I can create
lists which use up 600 more MB but if I try to create a dict that  
uses

a couple more MB it dies? My guess is that python dicts want a
contiguous chunk of memory for their hash table. Is there a reason
that you think memroy fragmentation isn't the problem?


Your logic makes some sense. You wrote that you can create a dict with
1300 items, but not 1400 items. If my reading of the Python source is
correct, the dict type decides it's overloaded when 2/3 full, and
enlarges by powers of two, so the 1366'th item will trigger allocation
of an array of 4096 PyDictEntry's.


At PyCon 2010, Brandon Craig Rhodes presented about how dictionaries  
work under the hood:

http://python.mirocommunity.org/video/1591/pycon-2010-the-mighty-dictiona

I found that very informative.

There's also some slides if you don't like the video; I haven't looked  
at 'em myself.

http://us.pycon.org/2010/conference/schedule/event/12/


Cheers
Philip

--
http://mail.python.org/mailman/listinfo/python-list


Re: getting MemoryError with dicts; suspect memory fragmentation

2010-06-04 Thread Bryan
Emin.shopper wrote:
> dmtr wrote:
> > I'm still unconvinced that it is a memory fragmentation problem. It's
> > very rare.
>
> You could be right. I'm not an expert on python memory management. But
> if it isn't memory fragmentation, then why is it that I can create
> lists which use up 600 more MB but if I try to create a dict that uses
> a couple more MB it dies? My guess is that python dicts want a
> contiguous chunk of memory for their hash table. Is there a reason
> that you think memroy fragmentation isn't the problem?

Your logic makes some sense. You wrote that you can create a dict with
1300 items, but not 1400 items. If my reading of the Python source is
correct, the dict type decides it's overloaded when 2/3 full, and
enlarges by powers of two, so the 1366'th item will trigger allocation
of an array of 4096 PyDictEntry's.
http://svn.python.org/view/python/branches/release25-maint/Objects/dictnotes.txt?view=markup
http://svn.python.org/view/python/branches/release25-maint/Objects/dictobject.c?view=markup

On the other hand PyDictEntry is 12 bytes (on 32-bit Python), so the
memory chunk needed is just 48 K. It doesn't seem plausible that you
have have hundreds of megabytes available but can't allocate 48K in
one chunk.

Plus, unless I'm misreading the code, a Python list also uses one
contiguous chunk of memory to store all the item references. I'm
looking at PyList_New() and list_resize() in:
http://svn.python.org/view/python/branches/release25-maint/Objects/listobject.c?view=markup
and the memory allocators in:
http://svn.python.org/view/python/branches/release25-maint/Include/pymem.h?view=markup

> What else could it be?

Unfortunately several things, most of them hard to diagnose. I'd
suggest checking easy stuff first. Make sure 'dict' is still . If you can test again in the debugger in the error case, see
how large a set you can make, as the set implementation is similar to
dict except the hash table entries are one pointer shorter at 8 bytes.


--
--Bryan Olson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to generate execute file that include enthought.traits.api , enthought.traits.ui.api ?

2010-06-04 Thread Robert Kern

On 6/3/10 10:05 PM, ray wrote:

Hi all,
I  code the program that using enthought.traits.api ,
enthought.traits.ui.api.
I want  to genereate execute file.I try PY2EXE,bb-
freeze,cx_freeze,Pyinstaller ,but the execute files  can not run
successful.
The attach file is my source code.
My environment :
1.Python 2.6.2
2. OS platform is MS Windows XP.

Anybody can share the experience ?


Our GUI components use some dynamic imports to provide the backend 
implementations. Most of those tools require you to explicitly state some of 
those backend-specific subpackages since they cannot introspect them directly 
from the import statements. Specifically, enthought.traits.ui.wx and 
enthought.pyface.ui.wx (replace "wx" with "qt4" if you are using PyQt).  The way 
you do this is different for each tool; you will have to consult its documentation.


You will want to ask future questions about ETS on our mailing list:

  https://mail.enthought.com/mailman/listinfo/enthought-dev

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Michael Torrie
On 06/03/2010 04:15 AM, Adam Tauno Williams wrote:
> The best solution I've seen is what is used by the Mono project;
> which provides both a "web forum" and a mail list interface.
> 
>  
> 

I just checked the archives of mono-list vs the forum and it's apparent
that this scheme suffers from the same problem as every other forum
solution.

The threaded flow of discussion is lost, replaced by a flat,
chronological "conversation."  Even though the list archive suggests
there is still a tree structure to posts, when you check into it you
find that it is not a tree at all.  Every message to the forum is taken
to be a reply to the one before, even though it might not be.  The
archive web interface simply abandons nesting at 4 levels or so.

-- 
http://mail.python.org/mailman/listinfo/python-list


weird pickle behavior in Python 3.1.2 + Eclipse 3.5.2

2010-06-04 Thread kirby.ur...@gmail.com
Here we are in an Eclipse pydev console, running Python 3.1.2.  For
the most part, everything is working great.

However...

>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC
v.1500 32 bit (Intel)]

>>> import pickle
>>> class Example:
... def __init__(self):
... self.name = "Hello"
... def __repr__(self):
... return "an Example object named {}".format(self.name)
...
...
>>> obj = Example()
>>> obj
an Example object named Hello

Note that I'm opening in binary, like I'm supposed to with this
latest protocol:

>>> f = open("testpickle.pkl",'wb')

Should be able to do this, no problemo:

>>> pickle.dump(obj, f)
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python31\lib\pickle.py", line 1354, in dump
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle : attribute
lookup builtins.Example failed

The above works fine in "naked Python" 3.1.2 by the way.
So this could be a problem with Eclipse / Pydev and/or
user error.  What am I missing?

Just normal data structures work:

>>> test = [1,2,3]
>>> pickle.dump(test,f)
>>> f.close()
>>>

Any other Eclipse users out there who can at least duplicate this
weirdness?

Kirby Urner
in Portland "Keep Portland Weird" Oregon

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parse xml with invalid chars

2010-06-04 Thread Someone Something
What d'ya mean hang?

On Fri, Jun 4, 2010 at 10:16 AM, Roman Makurin  wrote:

> Hi all
>
> Last time i have a big problem, i need parse xml files
> which have invalid xml chars outside of CDATA and xml
> parser hangs everytime on such files. Is there any way
> to parse such files ???
>
> thanks
>
> --
> If you think of MS-DOS as mono, and Windows as stereo,
>  then Linux is Dolby Digital and all the music is free...
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing DLL in win98

2010-06-04 Thread Chris W
On Jun 4, 8:53 am, Spyder42  wrote:
> On Fri, 04 Jun 2010 15:32:15 +0200, Christian Heimes
>
>  wrote:
> >> So your response is either, you don't know if there is a fix, or 'No
> >> way in h377.' You couldn't figure out by my post that I already knew
> >> that?
>
> >Let me paraphrase my answer:
>
> >You can't run Python 2.6 on Windows 98 because we have dropped support
> >for any Windows older than Windows 2000 SP4. It's documented at
> >http://docs.python.org/whatsnew/2.6.html#port-specific-changes-windows,
> >too.
>
> >Christian
>
> Yes, I get that. So your answer is... You have no idea as to weather
> there is a workaround, or a fix, or patch or anything that would help.
> right? I don't consider buying an OS to be a valid workaround.
>
>         Thanks
>         Spyder

Then the workaround is to use an older version of Python, or use a
modern version of a free OS.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threading and atexit: different behaviour in python2.6 from 2.5

2010-06-04 Thread MRAB

Alan wrote:

Hi there,

That's another try to get help about this issue I am facing. To help you 
to help me here goes a simple example. This is a very simplification of 
a very complex code.


 thread_ping.py  begin
import time
import sys
import atexit
from threading import Thread

class testit(Thread):
   def __init__ (self,ip):
  Thread.__init__(self)
  self.ip = ip
  self.status = 0
   def run(self):
  pingaling = os.popen("ping -q -c2 "+self.ip,"r")
  while 1:
line = pingaling.readline()
if not line: break
igot = re.findall(testit.lifeline,line)
if igot:
   self.status = int(igot[0])

def goodbye(t, report):
print 'Goodbye'
print "Status from ",t.ip,"is",report[t.status]

testit.lifeline = re.compile(r"(\d) packets received")
report = ("No response","Partial Response","Alive")

ip = "209.85.227.104" # www.google.com  # try 
with a failing IP if you want the test to last a bit longer


t = testit(ip)

atexit.register(goodbye, t, report)

t.start()

exit()
 thread_ping.py  end

If one runs like:

amadeus[2579]:~/TMP% time python2.6 thread_ping.py
Goodbye
Status from  209.85.227.104 is Alive
python2.6 thread_ping.py  0.02s user 0.02s system 3% cpu 1.056 total

(i.e., python2.6 wait till the thread finishes and leave... I don't want 
this behaviour, see below)


and

amadeus[2580]:~/TMP% time python2.5 thread_ping.py
Goodbye
Status from  209.85.227.104 is No response
python2.5 thread_ping.py  0.01s user 0.01s system 90% cpu 0.030 total

(i.e., python2.5 promptly quit, as desired)

Could someone tell me how to get python2.6 to have the same behaviour I 
see with python2.5 for this example code?


Any hint would be very much appreciated indeed.

Many thanks in advance.


The script won't exit while there are non-daemon threads running. You
can make a thread a daemon by setting its 'daemon' attribute to True
before starting the thread. If you want the script to be backwards
compatible with Python 2.5 then use the 'setDaemon' method instead.

I don't know why the script exited in Python 2.5 even though a
non-daemon thread was still running.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Missing DLL in win98

2010-06-04 Thread nn
On Jun 4, 9:53 am, Spyder42  wrote:
> On Fri, 04 Jun 2010 15:32:15 +0200, Christian Heimes
>
>  wrote:
> >> So your response is either, you don't know if there is a fix, or 'No
> >> way in h377.' You couldn't figure out by my post that I already knew
> >> that?
>
> >Let me paraphrase my answer:
>
> >You can't run Python 2.6 on Windows 98 because we have dropped support
> >for any Windows older than Windows 2000 SP4. It's documented at
> >http://docs.python.org/whatsnew/2.6.html#port-specific-changes-windows,
> >too.
>
> >Christian
>
> Yes, I get that. So your answer is... You have no idea as to weather
> there is a workaround, or a fix, or patch or anything that would help.
> right? I don't consider buying an OS to be a valid workaround.
>
>         Thanks
>         Spyder

Correct. If you use Windows 98, you are stuck at the 2.5 series of
Python. As far as I know (Christian might correct me) there is no fix
or patch to allow otherwise.

The usual volunteers that build the Windows version of Python don't
care about the extra work of maintaining Windows 98 support anymore
and nobody else has stepped forward to do it or to pay somebody to do
so.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Jim Byrnes

Steven D'Aprano wrote:

On Thu, 03 Jun 2010 22:05:19 -0700, Phlip wrote:


On Jun 3, 9:54 pm, Steven D'Aprano  wrote:


I don't know what rubbish ISPs you're dealing with


You've heard of a little fly-by-night outfit called AT&T?


Yes I have. Aren't they the people who were engaged in a long-running
criminal conspiracy to break the law and commit illegal warrantless
surveillance of American citizens?

If you look at the reviews here:

http://www.dslreports.com/gbu/

they are a distinct second-class ISP, with average B scores. Perhaps
that's better than "rubbish", but it's nothing to be proud about when you
are a company the size of AT&T. When you have that many resources,
anything less than straight A+ is a failure.

And that's not even mentioning their lack of News access, their ham-
fisted and clueless blocking of 4chan (whether in legitimate self-defence
or not), or their stance on net neutrality.

But the really sad thing is that you think that "bigger" automatically
equals "better".





I thought his point was they are big enough to have the resources to 
offer newsgroups but don't.  If I want fast internet I must use Comcast 
and Comcast doesn't offer newsgroups either.  Sadly is seems getting 
access to newsgroups is getting harder and harder.  I much prefer 
newsgroups or email lists to web forums.


Regards,  Jim
--
http://mail.python.org/mailman/listinfo/python-list


Re: Missing DLL in win98

2010-06-04 Thread Spyder42
On Fri, 04 Jun 2010 15:32:15 +0200, Christian Heimes
 wrote:

>> So your response is either, you don't know if there is a fix, or 'No
>> way in h377.' You couldn't figure out by my post that I already knew
>> that? 
>
>Let me paraphrase my answer:
>
>You can't run Python 2.6 on Windows 98 because we have dropped support
>for any Windows older than Windows 2000 SP4. It's documented at
>http://docs.python.org/whatsnew/2.6.html#port-specific-changes-windows ,
>too.
>
>Christian

Yes, I get that. So your answer is... You have no idea as to weather
there is a workaround, or a fix, or patch or anything that would help.
right? I don't consider buying an OS to be a valid workaround.

Thanks
Spyder
-- 
http://mail.python.org/mailman/listinfo/python-list


Wing IDE 3.2.8 released: Adds Python 2.7 support

2010-06-04 Thread Wingware

Hi,

Wingware has released version 3.2.8 of Wing IDE, an integrated development
environment designed specifically for the Python programming language.

This release includes the following minor features and improvements:

* Support for Python 2.7
* Partially updated French localization of the GUI (thanks to Jean Sanchez)
* Avoid hanging up the debugger in some Python code
* Fixed VI mode copy/paste, p after yj and dj, and Ctrl-S to save
* Correctly analyze 'with' statements and dictionary comprehensions
* Fixed help() in the shells under Python 3.x
* Reopen project after patch installation at startup
* Several other minor bug fixes

See the change log at http://wingware.com/pub/wingide/3.2.8/CHANGELOG.txt
for details

*Downloads*

Wing IDE Professional and Wing IDE Personal are commercial software and
require a license to run.  A free trial license can be obtained directly 
from

the product when launched.  Wing IDE 101 can be used free of charge.

Wing IDE Pro 3.2.8http://wingware.com/downloads/wingide/3.2

Wing IDE Personal 3.2.8   http://wingware.com/downloads/wingide-personal/3.2

Wing IDE 101 3.2.8http://wingware.com/downloads/wingide-101/3.2

*About Wing IDE*

Wing IDE is an integrated development environment designed specifically for
the Python programming language. It provides powerful editing, testing, and
debugging features that help reduce development and debugging time, cut down
on coding errors, and make it easier to understand and navigate Python code.
Wing IDE can be used to develop Python code for web, GUI, and embedded
scripting applications.

Wing IDE is available in three product levels:  Wing IDE Professional is
the full-featured Python IDE, Wing IDE Personal offers a reduced feature
set at a low price, and Wing IDE 101 is a free simplified version designed
for teaching entry level programming courses with Python.

Version 3.2 of Wing IDE Professional includes the following major features:

* Professional quality code editor with vi, emacs, and other keyboard 
personalities
* Code intelligence for Python:  Auto-completion, call tips, 
goto-definition,

 error indicators, smart indent and rewrapping, and source navigation
* Advanced multi-threaded debugger with graphical UI, command line 
interaction,

 conditional breakpoints, data value tooltips over code, watch tool, and
 externally launched and remote debugging
* Powerful search and replace options including keyboard driven and 
graphical

 UIs, multi-file, wild card, and regular expression search and replace
* Version control integration for Subversion, CVS, Bazaar, git, 
Mercurial, and

 Perforce
* Integrated unit testing with unittest, nose, and doctest frameworks
* Many other features including project manager, bookmarks, code snippets,
 OS command integration, indentation manager, PyLint integration, and 
perspectives

* Extremely configurable and may be extended with Python scripts

Please refer to the feature list at http://wingware.com/wingide/features for
a detailed listing of features by product level.

System requirements are Windows 2000 or later, OS X 10.3.9 or later for 
PPC or

Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit).
Wing IDE supports Python versions 2.0.x through 3.1.x and Stackless Python.

For more information, see http://wingware.com/products

*Purchasing and Upgrading*

Wing 3.2 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Version 2.x
licenses cost 1/2 the normal price to upgrade.

Upgrade a 2.x license: https://wingware.com/store/upgrade

Purchase a 3.x license:https://wingware.com/store/purchase

--

The Wingware Team
Wingware | Python IDE
Advancing Software Development

www.wingware.com

--
http://mail.python.org/mailman/listinfo/python-list


Re: Plain simple unix timestamp with an HTTP GET

2010-06-04 Thread Ross
On Jun 3, 11:20 pm, livibetter  wrote:
> This?
>
> hwclock --utc --set --date="$(datestr="$(curlhttp://208.66.175.36:13/
> 2>/dev/null | cut -d \  -f 2-3)" ; echo ${datestr//-//})"
>
> Only hwclock, curl, cut, and Bash.
>
> PS. I didn't know I can set the time via hwclock, learned from Paul's
> post, but still didn't try to see if it does work.
>
>

Thanks for the info.  Yes, I like the port 13 stuff from NIST et al
which is  RFC 867 formatted, but on the hdwe the parsing is more
work.

Found a bit of port 37  RFC 868 stuff that sounds interesting. I am
able to get a long int from it now I think (e.g. 64.236.96.53:37 in
Virginia), though it seems to be a bit mangled, and doesn't work out
to the number I'd expect for a 1900 epoch. Still, I think it's usable,
and is just a single number.

I hear NIST is gradually getting away from RFC868 stuff tho' which is
too bad. Some of us don't need pS accuracy. +/- 5min is fine.

Thx for the input!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing DLL in win98

2010-06-04 Thread Christian Heimes
> So your response is either, you don't know if there is a fix, or 'No
> way in h377.' You couldn't figure out by my post that I already knew
> that? 

Let me paraphrase my answer:

You can't run Python 2.6 on Windows 98 because we have dropped support
for any Windows older than Windows 2000 SP4. It's documented at
http://docs.python.org/whatsnew/2.6.html#port-specific-changes-windows ,
too.

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing DLL in win98

2010-06-04 Thread Spyder42
On Fri, 04 Jun 2010 14:50:28 +0200, Christian Heimes
 wrote:


>
>Python 2.6 is not supported on Windows 98 and earlier. You need at least
>Windows 2000 with a recent service pack.
>
>Christian

So your response is either, you don't know if there is a fix, or 'No
way in h377.' You couldn't figure out by my post that I already knew
that? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-04 Thread Pierre Quentel
On 4 juin, 07:11, Steven D'Aprano  wrote:
> On Thu, 03 Jun 2010 03:16:03 -0700, Pierre Quentel wrote:
> > So the OP's initiative should be an incentive to think on the format of
> > the interaction between all the range of Python users, from newbees to
> > gurus. We are in the 2.0 era, with social networks all over the place
> > using a pleasant interface,
>
> Really? I can't think of any 2.0 era social networks using pleasant
> interfaces. All the ones I've seen or used start with mediocre interfaces
> and get worse from there.
>
> > while c.l.p has a rather austere look and feel, with text only,
>
> Thank goodness for that!
>
> > no way to present code snippets in a different
> > font / background than discussions,
>
> If somebody can't distinguish code from comments in a post by the
> context, they aren't cut out to be a programmer and should probably stick
> to posting "OMG LOL" on a social networking site.

They certainly *can* distinguish. But it's so easy to make it more
explicit with syntax highlighting, background color, border etc. that
most sites about programing languages use it, including the Python
home site itself, or the Python cookbook on Active State

>
> > and even an unintuitive way of entering links...
>
> Pasting or typing a URL is unintuitive?
>
> If somebody can't take the time and effort to post a URL in a form that
> is not broken, well, that doesn't say much for their skills as a coder
> does it? If you can't handle the fact that URLs can't be broken over
> multiple lines in email and news posts, how do you expect to handle even
> more vigorous requirements while programming?

That's 2 different things. When you use a programming language you
know you have to adopt the syntax defined by the program. When you
write something in a forum, you expect that the editor will be smart
enough to know that http://pythonforum.org is a URL

>
> > I'm not saying that pythonforum.org is the best solution but it
> > certainly looks more attractive than c.l.p. to the new generation of
> > Python users
>
> I get:
>
> While trying to retrieve the URL:http://pythonforum.org/
>  The following error was encountered:
>  Connection to 173.83.46.254 Failed  
>  The system returned:
>     (111) Connection refused
>
> Oops. Looks like they can't handle the millions of new users joining up.
>
> Despite my sarcasm, I actually do wish them the best. I'm not too worried
> about fragmenting the community -- the community is already fragmented,
> and that's a *good thing*. There are forums for newbies, for development
> *of* Python (rather than development *in* Python), for numeric work in
> Python, for Italian-speakers, for game development, etc. This is the way
> it should be, and I don't fear a competing general Python forum or
> forums. If they're better than comp.lang.python, they will attract more
> users and become the place to be, and if they're not, they won't.
>
> --
> Steven

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [python] pass the name of args

2010-06-04 Thread Chris Rebert
On Fri, Jun 4, 2010 at 4:32 AM, macm  wrote:
> Hi Folks
>
> def myDef(x)
>        doSomething x
>        result = x.
>        return coolThings
> -
>
> WhatYourName = ('python','is','cool')
>
> myDef(WhatYourName)
>
> so what I am looking for in myDef
>
>        result = WhatYourName
>
> --
> again :
> IhaveOtherName = ('some','thing')
>
> myDef(IhaveOtherName)
>
> so what I am looking for in myDef
>
>        result = IhaveOtherName
>
> --
>
> Is it possible with python?

Not without very evil black-magic hackery. Explain /why/ you want this
magic myDef() and someone will probably be able to suggest a better,
alternative approach.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing DLL in win98

2010-06-04 Thread Christian Heimes
Am 04.06.2010 14:38, schrieb Spyder42:
> I hope this is the right place to ask this, and appologise if it's
> not. I'm trying to install 2.6.5 in Win98 se final. It says "a
> required dll could not be run". Do I have to upgrade my whole OS just
> to install this, or is there a fix I can apply to 98 to make it work.
> The installer doesn't say what dll is missing, just that it is.

Python 2.6 is not supported on Windows 98 and earlier. You need at least
Windows 2000 with a recent service pack.

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Missing DLL in win98

2010-06-04 Thread Spyder42
I hope this is the right place to ask this, and appologise if it's
not. I'm trying to install 2.6.5 in Win98 se final. It says "a
required dll could not be run". Do I have to upgrade my whole OS just
to install this, or is there a fix I can apply to 98 to make it work.
The installer doesn't say what dll is missing, just that it is.

Thanks in advance.
L8r
Spyder

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: one more exception newbie query

2010-06-04 Thread Alf P. Steinbach

* Payal, on 04.06.2010 12:10:

Hi all,
In http://docs.python.org/tutorial/errors.html#handling-exceptions it
says,

|>>>  try:
| ...raise Exception('spam', 'eggs')

Why would I want to use a class for exception? I could simply use raise
w/o it?
Also the help() says,
class Exception(BaseException)
But we have used 'spam' and 'eggs'. Why?

| ... except Exception as inst:

Now what does "as inst" do here? (Is it making an instance, but how?
Aren't instances made with this, inst = Klass() ?)


These questions are like "why is the door rectangular when sheep are known to 
dance in the moonlight only on dates divisible by cinnamon?".


It's rather difficult to answer.

I guess it's back to basics: read up on classes, instances, constructors. 
Experiment, create a lot of small programs. Don't think about exceptions just 
yet: you lack the fundamentals.



Cheers & hth.,

- Alf

--
blog at http://alfps.wordpress.com>
--
http://mail.python.org/mailman/listinfo/python-list


Re: questions about how to parse a string and put it in a dictionary

2010-06-04 Thread Tim Chase

On 06/03/2010 09:21 PM, joblack wrote:

I've got a string which (without any CR or LF) consists of

'attribute1=attribute_value;attribute2=attribute_value2; ...'

and I want them to read in a dictionary so that the attribute name is
the key and the attribute value is the data.

Any ideas for an implementation?


While I agree with Bryan that this looks suspiciously like a URL 
query-string (and thus you likely want to use his suggestion for 
the built-in tools to parse them), I haven't seen the one-liner 
version float by, so here it is just for fun:


  s = "hello=world;this=that;foo=bar"
  results = dict((k,v) for (k,_,v) in (pair.partition('=') for 
pair in s.split(';')))


As Bryan cautions, URL query-strings can have multiple values for 
the same key, and your example doesn't address that case:


  foo=bar;foo=baz;hello=world;this=that

so the code examples you're getting don't address it either :)

-tkc





--
http://mail.python.org/mailman/listinfo/python-list


[python] pass the name of args

2010-06-04 Thread macm
Hi Folks

def myDef(x)
doSomething x
result = x.
return coolThings
-

WhatYourName = ('python','is','cool')

myDef(WhatYourName)

so what I am looking for in myDef

result = WhatYourName

--
again :
IhaveOtherName = ('some','thing')

myDef(IhaveOtherName)

so what I am looking for in myDef

result = IhaveOtherName

--

Is it possible with python?

Regards

macm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: great

2010-06-04 Thread Jean-Michel Pichavant

joblack wrote:

Great - it works.

Thanks a lot.

  

Thread of the week :)

JM
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >