Changing Python Opcodes

2009-08-17 Thread Sreejith K
Hi,

I know this is not the best way to do it. But I have to do it at least
to make it *hard* to decompile the python bytecode.

I want to distribute a software written in Python without the source.
So I compiled Python from source changing some opcode values (Taking
care of HAVE_ARGUMENT value) and distributed with the .pyc files. It
did compile but when I'm installing additional python modules using
easy_install, the import fails with a segmentation fault. It worked in
a 32 bit Centos 5.2 but not on 64bit Centos 5.2. I am using python
2.5.4 source.

I changed only the Include/opcode.py source with my jumbled opcode
values. Was I correct here ? I would like to know what all changes to
be made as to successfully compile a custom python with different
opcode values ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML parsing with python

2009-08-17 Thread Stefan Behnel
John Posner wrote:
>> Use the iterparse() function of the xml.etree.ElementTree package.
> 
> iterparse() is too big a hammer for this purpose, IMO. How about this:
> 
>  from xml.etree.ElementTree import ElementTree
>  tree = ElementTree(None, "myfile.xml")
>  for elem in tree.findall('//book/title'):
>  print elem.text

Is that really so much better than an iterparse() version?

  from xml.etree.ElementTree import ElementTree

  for _, elem in ElementTree.iterparse("myfile.xml"):
  if elem.tag == 'book':
  print elem.findtext('title')
  elem.clear()

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


Re: XML parsing with python

2009-08-17 Thread Stefan Behnel
inder wrote:
> On Aug 17, 8:31 pm, John Posner  wrote:
>>> Use the iterparse() function of the xml.etree.ElementTree package.
>>> http://effbot.org/zone/element-iterparse.htm
>>> http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk
>>> Stefan
>> iterparse() is too big a hammer for this purpose, IMO. How about this:
>>
>>   from xml.etree.ElementTree import ElementTree
>>   tree = ElementTree(None, "myfile.xml")
>>   for elem in tree.findall('//book/title'):
>>   print elem.text
>>
>> -John
> 
> Thanks for the prompt reply .
> 
> I feel let me try using iterparse. Will it be slower compared to SAX
> parsing ... ultimately I will have a huge xml file to parse ?

If you use the cElementTree module, it may even be faster.


> Another question , I will also need to validate my xml against xsd . I
> would like to do this validation through the parsing tool  itself .

In that case, you can use lxml instead of ElementTree.

http://codespeak.net/lxml/

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


Re: define class over 2 files

2009-08-17 Thread Steven D'Aprano
On Mon, 17 Aug 2009 21:45:57 -0700, naveen wrote:

> Is it possible to split up a class definition over multiple files?

Not exactly, but you can do variations of this:


In file A.py, create:

class Parent:
def method(self):
return "Method"


In file B.py, do this:

import A
class Child(B.parent):
def another_method(self):
return "Another Method"


Now your class Child has two methods, method() and another_method().


Similarly, you can do this:

# File A.py

def function(x, y):
return x+y  # or something more complicated


# File B.py

import A

def MyClass(object):
def func(self, x, y):
return A.function(x, y)





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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Steven D'Aprano
On Mon, 17 Aug 2009 21:35:48 -0700, Carl Banks wrote:

>> > > > I like how being very friendly means calling people after a guy
>> > > > who tried to blow up the English Parliament.
>>
>> > > So?
>>
>> > I also like how making an amusing pointless observation
>>
>> Pointless, yes, but what was amusing abot the observation?
> 
> The irony that in being friendly that you're calling someone a
> terrorist.  


Please, the term is Freedom Fighter.



> I guess I shouldn't have expected you to get it.

Ouch! Nasty!


Is there something in the air today? People are short-tempered and 
grouchy all over the place... 



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


Re: XML parsing with python

2009-08-17 Thread inder
On Aug 17, 8:31 pm, John Posner  wrote:
> > Use the iterparse() function of the xml.etree.ElementTree package.
>
> >http://effbot.org/zone/element-iterparse.htm
> >http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk
>
> > Stefan
>
> iterparse() is too big a hammer for this purpose, IMO. How about this:
>
>   from xml.etree.ElementTree import ElementTree
>   tree = ElementTree(None, "myfile.xml")
>   for elem in tree.findall('//book/title'):
>       print elem.text
>
> -John

Thanks for the prompt reply .

I feel let me try using iterparse. Will it be slower compared to SAX
parsing ... ultimately I will have a huge xml file to parse ?


Another question , I will also need to validate my xml against xsd . I
would like to do this validation through the parsing tool  itself .

Does there exist an Unix utility which validates or even a python
library call would be fine  ?

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


Re: Data visualization in Python

2009-08-17 Thread abalter
On Aug 17, 12:10 pm, kj  wrote:
> I'm looking for a good Python package for visualizing
> scientific/statistical data.  (FWIW, the OS I'm interested in is
> Mac OS X).
>
> The users of this package will be experimental biologists with
> little programming experience (but currently learning Python).
>
> (I normally visualize data using R or Mathematica, but I don't want
> to saddle these novices with the task of learning yet another
> language.)
>
> TIA!
>
> kynn

You might also look into the pythonxy superpackage, 
http://www.pythonxy.com/foreword.php
and http://enthought.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diversity in Python

2009-08-17 Thread Ben Finney
Steven D'Aprano  writes:

> The comments were made a week ago -- why the sudden flurry of
> attention?

In my case, it's because I was ignoring the thread in which they were
made. The change of subject drew them to my attention, where I saw the
community response was (IMO) insufficient at the time, so I acted to
correct that.

Now that the community response is (IMO) more appropriate, there's no
further need to beat on those particular comments. Additional
transgressions could warrant additional responses, of course.

-- 
 \ “I got some new underwear the other day. Well, new to me.” —Emo |
  `\   Philips |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: define class over 2 files

2009-08-17 Thread Xavier Ho
On Tue, Aug 18, 2009 at 2:45 PM, naveen  wrote:

> Is it possible to split up a class definition over multiple files?
> -


Answer in short, I don't think so.

 Now why would you want to do that?

There is another solution - have a main class for shared methods, and have
other classes [in different files, perhaps] inherit from it.

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


define class over 2 files

2009-08-17 Thread naveen
Is it possible to split up a class definition over multiple files?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Aahz
In article ,
Steven D'Aprano   wrote:
>
>The comments were made a week ago -- why the sudden flurry of attention?

Mainly an opportunity to flog the new diversity list.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there."  --Steve Gonedes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Steven D'Aprano
On Mon, 17 Aug 2009 13:56:13 -0700, Paul Rubin wrote:

> Python 3.0 went overboard by actually removing the cmp argument and
> requiring use of the key argument.  That requires various kludges if the
> key is, say, a tree structure that has to be recursively compared with
> another such structure.  Maybe then can bring back cmp someday.

I'm having trouble understanding this, which may be my weakness rather 
than yours, but could you give an actual (simplified?) example I can run, 
where cmp would work but key wouldn't?



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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Steven D'Aprano
On Mon, 17 Aug 2009 18:04:58 -0700, Carl Banks wrote:

> On Aug 17, 5:40 pm, Mensanator  wrote:
>> On Aug 17, 4:06 pm, Carl Banks  wrote:
>>
>> > On Aug 17, 10:03 am, Jean-Michel Pichavant 
>> > wrote:
>>
>> > > I'm no English native, but I already heard women/men referring to a
>> > > group as "guys", no matter that group gender configuration. It's
>> > > even used for group composed exclusively of women. Moreover it
>> > > looks like a *very* friendly form, so there is really nothing to
>> > > worry about it.
>>
>> > I like how being very friendly means calling people after a guy who
>> > tried to blow up the English Parliament.
>>
>> So?
> 
> I also like how making an amusing pointless observation gets people all
> huffy.
> 
> (BTW, lest anyone is not aware, that is the origin of the word "guy",
> this was not some random association.)


Yes, apparently the slang term "guy" for "man" (and these days, "person") 
was derived from Guy Fawkes:

http://www.worldwidewords.org/weirdwords/ww-guy1.htm


but the name itself is much older, and comes from Old German for "wood" 
or "warrior". In old French, it was "Gy", and in Italian (and presumably 
Dutch) it is "Guido".

http://www.thinkbabynames.com/meaning/1/Guy
http://www.blurtit.com/q113276.html


You'll also note that "guy" the noun has a number of meanings:

http://wordnetweb.princeton.edu/perl/webwn?s=guy


I don't know if there's any point to all this, but it's interesting, even 
if off-topic.




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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Carl Banks
On Aug 17, 8:49 pm, Mensanator  wrote:
> On Aug 17, 8:04 pm, Carl Banks  wrote:
>
>
>
>
>
> > On Aug 17, 5:40 pm, Mensanator  wrote:
>
> > > On Aug 17, 4:06 pm, Carl Banks  wrote:
>
> > > > On Aug 17, 10:03 am, Jean-Michel Pichavant 
> > > > wrote:
>
> > > > > I'm no English native, but I already heard women/men referring to a
> > > > > group as "guys", no matter that group gender configuration. It's even
> > > > > used for group composed exclusively of women. Moreover it looks like a
> > > > > *very* friendly form, so there is really nothing to worry about it.
>
> > > > I like how being very friendly means calling people after a guy who
> > > > tried to blow up the English Parliament.
>
> > > So?
>
> > I also like how making an amusing pointless observation
>
> Pointless, yes, but what was amusing abot the observation?

The irony that in being friendly that you're calling someone a
terrorist.  I guess I shouldn't have expected you to get it.


> > gets people all huffy.
>
> That wasn't huffy. You want to see huffy, make a wisecrack
> comparing mothballs to Zyklon B, you'll REALLY get a load
> of huffy replies.
>
> > (BTW, lest anyone is not aware, that is the origin of the word "guy",
>
> It most certainly is not.

My dictionary disagrees with you.


> Maybe the origin of that
> word's useage as a genric reference to a male, but
> you didn't say that.
>
> > this was not some random association.)
>
> Penny for the guy?

Probably that phrase was part of the word's gradual common adoption.


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


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Steven D'Aprano
On Mon, 17 Aug 2009 14:31:51 -0700, Chris Rebert wrote:

>> Oh come on, one newbie making an off-color joke is not any sort of
>> reflection of the community as a whole.
>>
>> Anyway it's pretty naive to expect what is now a large community to
>> avoid bad eggs altogether.  Price you pay for popularity.
> 
> Agreed on both points, but the lack of any reprimanding for making said
> inappropriate joke /would/ reflect badly on the community. Fortunately,
> said person's behavior has now been condemned by virtue of this thread;
> it's a step in the right direction.

Pardon me, but he has been slapped, a number of times. Check the original 
thread, you'll see that the OP was slapped for his stupid joke, then 
slapped again for another dismissive comment after the first reprimand.

You might argue he wasn't slapped *enough*, but that's another story. 
Personally, I thought he was either trolling for a reaction, or he was an 
old-fuddy-duddy (regardless of biological age), and either way reacting 
to his comments would just draw attention to something which is best 
dealt with with a cold-shoulder. Reinforce the good behaviour, shun the 
bad.

The comments were made a week ago -- why the sudden flurry of attention?



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


Re: Text lost when I write file

2009-08-17 Thread Ben Finney
Chris Rebert  writes:

> On Mon, Aug 17, 2009 at 8:45 PM, roy...@gmail.com wrote:
> > I try to write text into a file but some text lost when the size of
> > the text content is over 32K.
> > Is that relate to the buffer of the python and any setting can solve
> > this problem??.
>
> Please show us the code you're using.

Not the whole danged thing, of course; please show a minimal executable
example that demonstrates the behaviour.

-- 
 \   “I do not believe in immortality of the individual, and I |
  `\consider ethics to be an exclusively human concern with no |
_o__)  superhuman authority behind it.” —Albert Einstein, letter, 1953 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Text lost when I write file

2009-08-17 Thread Chris Rebert
On Mon, Aug 17, 2009 at 8:45 PM, roy...@gmail.com wrote:
> Dear All,
>
> I try to write text into a file but some text lost when the size of
> the text content is over 32K.
> Is that relate to the buffer of the python and any setting can solve
> this problem??.

Please show us the code you're using.

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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Terry Reedy

Nathan Keel wrote:

idiot ... asshole 
absolutely clueless ... idiot ...incredibly

arrogant, yet incredibly clueless.


To me, such name-calling is as obnoxious as the intended target.

tjr


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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Terry Reedy

exar...@twistedmatrix.com wrote:

There's a lot of things in Python that I don't strictly *need*.  That 
doesn't mean that they wouldn't be welcome if I could have them. Getting 
rid of the range/xrange dichotomy would improve things.


The developers agreed a couple of years ago. Starting using 3.1 if you 
want this.


Since 'range' could refer to a user-defined object, rather than the 
builtin function, there is no way the interpreter should substitute 
'xrange'.


tjr

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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Mensanator
On Aug 17, 8:04�pm, Carl Banks  wrote:
> On Aug 17, 5:40�pm, Mensanator  wrote:
>
> > On Aug 17, 4:06�pm, Carl Banks  wrote:
>
> > > On Aug 17, 10:03�am, Jean-Michel Pichavant 
> > > wrote:
>
> > > > I'm no English native, but I already heard women/men referring to a
> > > > group as "guys", no matter that group gender configuration. It's even
> > > > used for group composed exclusively of women. Moreover it looks like a
> > > > *very* friendly form, so there is really nothing to worry about it.
>
> > > I like how being very friendly means calling people after a guy who
> > > tried to blow up the English Parliament.
>
> > So?
>
> I also like how making an amusing pointless observation

Pointless, yes, but what was amusing abot the observation?

> gets people all huffy.

That wasn't huffy. You want to see huffy, make a wisecrack
comparing mothballs to Zyklon B, you'll REALLY get a load
of huffy replies.

>
> (BTW, lest anyone is not aware, that is the origin of the word "guy",

It most certainly is not. Maybe the origin of that
word's useage as a genric reference to a male, but
you didn't say that.

> this was not some random association.)

Penny for the guy?

>
> Carl Banks

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


Text lost when I write file

2009-08-17 Thread roy...@gmail.com
Dear All,

I try to write text into a file but some text lost when the size of
the text content is over 32K.
Is that relate to the buffer of the python and any setting can solve
this problem??.

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


Re: New to python

2009-08-17 Thread Chris Rebert
On Mon, Aug 17, 2009 at 7:49 PM, Allan Fong wrote:
> Hi! I'm fairly new to Python.  I understand the basics basics but I'm been
> trying to write a simple python code that will let me read input data from
> my USB drive and write it in a text file and I am so lost.  Can anyone help
> or direct me to some resources?  Thank you!

Working with files: http://docs.python.org/library/stdtypes.html#file-objects

Reading+writing common file formats:
JSON: http://docs.python.org/library/json.html
CSV: http://docs.python.org/library/csv.html

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


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Rami Chowdhury



My sample interactive session (locale.setlocale and all) was on a 32-bit Vista 
install of Python 2.5, so it works on that...

---
Rami Chowdhury
"A man with a watch knows what time it is. A man with two watches is never 
sure". -- Segal's Law
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

On Monday 17 August 2009 19:46:24 Ben Finney wrote:
> Jonathan Gardner  writes:
> > On Aug 17, 5:20 pm, Ben Finney  wrote:
> > > Instead, you should generate the map based on the standard library (in
> > > this case, the underlying C standard library) locale database
> > > http://docs.python.org/library/locale.html?highlight=locale%20date
> > >#lo...>:
> >
> > Does Windows support POSIX locales?
>
> If it does not, it should :-) since it addresses the problem in one
> standard place. It would be foolish for Python to re-implement that
> functionality when presumably the operating system already knows how to
> map between dates and locale-specific text representations.
>
> You'll need to check the operating system documentation for what
> alternative it might provide.
>
> --
>  \“I got fired from my job the other day. They said my |
>   `\  personality was weird. … That's okay, I have four more.” |
> _o__)   —Bug-Eyed Earl, _Red Meat_ |
> Ben Finney

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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread rurpy
On 08/13/2009 08:46 AM, Paul Boddie wrote:
> On 13 Aug, 16:05, ru...@yahoo.com wrote:
>> All the above not withstanding, I too think a wiki is worth
>> trying.  But without doing a lot more than just "setting up
>> a wiki", I sadly believe even a python.org supported wiki
>> is doomed to failure.
>
> The ones on python.org seem to function reasonably well. I accept that
> they could be more aggressively edited, but this isn't done because
> there's a compromise between letting people contribute and keeping
> things moderately coherent, with the former being favoured. For other
> purposes, it would be quite acceptable to favour editorial control.

Yes, I agree.  I should have mentioned this as an exception
in my "wikis suck" diatribe.  Although it far better than
most wiki's I've seen, it is still pretty easy to find signs
of typical wiki-ness.  On the Documentation page my first
click was on AnnotableDocumentation: 404.  Second try,
DoumentationDiscussion: two very short paragraphs dated 2003.
After that I found some useful (in general though not what I
was looking for) information but not a good first impression.
(Well not exactly first, in fairness I have used other wiki
sections such as the Templating page and found them very
useful.)

> I won't argue that providing infrastructure solves a problem - that's
> precisely the kind of thing I was criticising when I noted that some
> people will readily criticise the choice of tools to do a job instead
> of focusing on the job that has to be done - and you need people who
> are reasonably competent editors, but Wiki solutions remove a lot of
> technical barriers. I'm not arguing for the flavour of Wiki which
> implies unfettered, anonymous access from everyone on the Internet,
> either: the kind of Wiki that detractors portray all Wiki solutions as
> being in order to further their super-special "it has to fit like a
> glove or it's totally unusable" software agenda. It's quite possible
> to have people with somewhat more privileges than others in order to
> keep the peace, and they don't all need to have an entrenched
> editorial interest: on the current python.org Wiki sites, most of the
> administrators don't have an active interest in most of the content,
> but they are able to exercise control when it's clear that some
> contributors aren't particularly interested in actually improving the
> content.
>
> As well as having an active community effort around the existing
> python.org Wiki sites, there are also people who are interested in
> improving these offerings. What worries me is that despite such
> activity and such interest, many people will continue to lament the
> lack of vitality (or whatever other metric) of the general python.org
> offering, whilst retaining a blind spot for the obvious contribution
> that the Wikis can make to such improvement efforts. I encourage
> people to use wiki.python.org a lot more, should they be looking to
> improve the wealth of information provided by the community.

Again, I agree with all of that.  But my main interest is
in improving the standard docs that are distributed with
Python and I question a wiki's role in that.

I took a look at the PHP docs last night which seem
pretty well done.  The User Comments looked rather as I
expected, there was useful info but most did not contain
documentation quality writing.  So if they are used as
a source for improving the docs, there clearly must be a
pretty large amount of editorial effort required, although
much of it is probably just filtering out comments that
don't provide any information appropriate for inclusion
in the docs.  They list 38 names under "User Note Maintainers"
(http://www.php.net/manual/en/preface.php)
Unfortunately I couldn't find a description of what these
people actually do.  I don't know how much work was involved
in removing the comments that are no longer there.

Again, I don't mean to sound like I am dissing the idea
of annotatable docs -- I think it is a good idea and will
provide useful supplementary information.

But I continue to question whether this will result in
improvements in the docs themselves (which is my main
interest) unless:

   1. The purpose of the wiki is clearly "marketed" as
soliciting suggestions, rewrites, etc destined ultimately
for inclusion in the docs.

   2. There is a dedicated core of doc-competent volunteers
focused on extracting, condensing and editing the user
comments and getting them into the docs, either directly
(if the volunteers are committers -- unlikely) or through
the existing tracker system.  And this still fails to
address the problems with the docs that aren't amenable
to fixing via the tracker system.  At least two of those
problems are:
1. Difficultly in making large organizational changes.
2. Prevalent opinion among doc approvers that the current
 excessively terse style is desirerable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Ben Finney
Jonathan Gardner  writes:

> On Aug 17, 5:20 pm, Ben Finney  wrote:
> > Instead, you should generate the map based on the standard library (in
> > this case, the underlying C standard library) locale database
> > http://docs.python.org/library/locale.html?highlight=locale%20date#lo...>:
>
> Does Windows support POSIX locales?

If it does not, it should :-) since it addresses the problem in one
standard place. It would be foolish for Python to re-implement that
functionality when presumably the operating system already knows how to
map between dates and locale-specific text representations.

You'll need to check the operating system documentation for what
alternative it might provide.

-- 
 \“I got fired from my job the other day. They said my |
  `\  personality was weird. … That's okay, I have four more.” |
_o__)   —Bug-Eyed Earl, _Red Meat_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


New to python

2009-08-17 Thread Allan Fong
Hi! I'm fairly new to Python.  I understand the basics basics but I'm been
trying to write a simple python code that will let me read input data from
my USB drive and write it in a text file and I am so lost.  Can anyone help
or direct me to some resources?  Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 5:18 pm, "Rami Chowdhury"  wrote:
>
> >>> import locale
> >>> locale.setlocale(locale.LC_ALL, 'FR')

locale is nice when you only have a single thread.

Webservers aren't single threaded. You can't serve up one page for one
locale and then another in another locale without seeing very, very
weird behavior.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 7:06 pm, Ben Finney  wrote:
> Jonathan Gardner  writes:
> > Unfortunately, there isn't any string to date parsers in the built-
> > ins.
>
> Fortunately, Python 2.5 or later has the ‘datetime.strptime’ function.
>

Hate to weasel out of this one, but the language that strptime
provides is pretty limited. I don't find it useful except in the
trivial cases. Same goes for strftime. Also, both of these are very
Western European centric. Yes, Asian languages are supported but not
naturally.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittest

2009-08-17 Thread Ben Finney
Mag Gam  writes:

> all, thank you very much!!!
>
> Now my question is

You would do well to ask more about testing in Python on the focussed
forum for that topic, the ‘testing-in-python’ mailing list
http://lists.idyll.org/listinfo/testing-in-python>.

-- 
 \“If it ain't bust don't fix it is a very sound principle and |
  `\  remains so despite the fact that I have slavishly ignored it |
_o__) all my life.” —Douglas Adams |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 5:20 pm, Ben Finney  wrote:
>
> Instead, you should generate the map based on the standard library (in
> this case, the underlying C standard library) locale database
> http://docs.python.org/library/locale.html?highlight=locale%20date#lo...>:
>

Does Windows support POSIX locales?

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


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Ben Finney
Jonathan Gardner  writes:

> Unfortunately, there isn't any string to date parsers in the built-
> ins.

Fortunately, Python 2.5 or later has the ‘datetime.strptime’ function.

-- 
 \   “You could augment an earwig to the point where it understood |
  `\ nuclear physics, but it would still be a very stupid thing to |
_o__)  do!” —The Doctor, _The Two Doctors_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittest

2009-08-17 Thread Mag Gam
all, thank you very much!!!

Now my question is, how do I simulate a argv? My program has take an
argv, like "foo.py File" is necessary. How and where do I put it in my
test? I suppose in the setUp(), but I am not sure how.

any thoughts or ideas?

TIA

On Sun, Aug 16, 2009 at 9:25 AM, Mag Gam wrote:
> John:
>
> Well, this is actually a script which wraps around another application. :-)
> My goal is when I introduce a new feature I don't want to break old
> stuff so instead of me testing manually I want to build a framework of
> tests.
>
>
>
> On Sat, Aug 15, 2009 at 11:37 PM, John Haggerty wrote:
>> This is an interesting question. I am just wondering: do you really have
>> that many features that it would be impossible to just have a shell script
>> run specific types of input or tests?
>>
>> When I did programming in the past for education they just had lists of
>> input data and we ran the program against the test data.
>>
>> I just get slightly confused when "test suites" start to have to apply?
>>
>> On Fri, Aug 14, 2009 at 9:28 PM, Mag Gam  wrote:
>>>
>>> I am writing an application which has many command line arguments.
>>> For example: foo.py -args "bar bee"
>>>
>>> I would like to create a test suit using unittest so when I add
>>> features to "foo.py" I don't want to break other things. I just heard
>>> about unittest and would love to use it for this type of thing.
>>>
>>> so my question is, when I do these tests do I have to code them into
>>> foo.py? I prefer having a footest.py which will run the regression
>>> tests. Any thoughts about this?
>>>
>>> TIA
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need cleanup advice for multiline string

2009-08-17 Thread Carl Banks
On Aug 17, 5:40 pm, Mensanator  wrote:
> On Aug 17, 4:06 pm, Carl Banks  wrote:
>
> > On Aug 17, 10:03 am, Jean-Michel Pichavant 
> > wrote:
>
> > > I'm no English native, but I already heard women/men referring to a
> > > group as "guys", no matter that group gender configuration. It's even
> > > used for group composed exclusively of women. Moreover it looks like a
> > > *very* friendly form, so there is really nothing to worry about it.
>
> > I like how being very friendly means calling people after a guy who
> > tried to blow up the English Parliament.
>
> So?

I also like how making an amusing pointless observation gets people
all huffy.

(BTW, lest anyone is not aware, that is the origin of the word "guy",
this was not some random association.)

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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Mensanator
On Aug 17, 4:06 pm, Carl Banks  wrote:
> On Aug 17, 10:03 am, Jean-Michel Pichavant 
> wrote:
>
> > I'm no English native, but I already heard women/men referring to a
> > group as "guys", no matter that group gender configuration. It's even
> > used for group composed exclusively of women. Moreover it looks like a
> > *very* friendly form, so there is really nothing to worry about it.
>
> I like how being very friendly means calling people after a guy who
> tried to blow up the English Parliament.

So?

>
> Carl Banks

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


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Ben Finney
Gilles Ganault  writes:

>   I need to convert DD MM  dates into the MySQL-friendly
> -MM-DD

This is not specific to MySQL. It is the common international standard
date representation format defined by ISO 8601.

> and translate the month name from literal French to its numeric
> equivalent (eg. "Janvier" into "01").

The simplest way to do this would be by a mapping from month-name to
month-number.

An obvious, and wrong, approach to this would be to hard-code the twelve
month names into your program data.

Instead, you should generate the map based on the standard library (in
this case, the underlying C standard library) locale database
http://docs.python.org/library/locale.html?highlight=locale%20date#locale.nl_langinfo>:

>>> import locale
>>> locale.setlocale(locale.LC_TIME, "en_AU.UTF-8")
>>> months = dict(
... (locale.nl_langinfo(getattr(locale, key)), i)
... for (key, i) in (
... ('MON_%(i)d' % vars(), i)
... for i in range(1, 12+1)))

>>> import pprint
>>> pprint.pprint(months)
{'April': 4,
 'August': 8,
 'December': 12,
 'February': 2,
 'January': 1,
 'July': 7,
 'June': 6,
 'March': 3,
 'May': 5,
 'November': 11,
 'October': 10,
 'September': 9}

Of course, if you can avoid having to generate this mapping at all in
your program, that's best; see below.

> Here's an example:
>
> SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
> 26 Mai 2007|17 Août 2009 - 09h20
>
> I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
> respectively.

Storing a timestamp as a text attribute in a database seems perverse and
begging for trouble. Doesn't the database have a timestamp data type? Or
perhaps that's what you're trying to achieve?

> What is the best way to do this in Python?

The ‘datetime.strptime’ function will create a Python ‘datetime’ object
from a string, parsed according to a format
http://docs.python.org/library/datetime.html?highlight=parse%20date%20time#datetime.datetime.strptime>.

I don't know whether that function allows for month names in the current
locale (as set by ‘locale.setlocale(locale.LC_TIME, …)’). If it does,
that's the right way, since it doesn't involve explciitly generating the
mapping as shown above.

Use your preferred Python-to-database library to feed that ‘datetime’
object directly to the database and store it in an attribute of the
native database timestamp type.

Then, format the timestamp value at the point of outputting that value,
instead of storing the text representation in the database.

-- 
 \ “To succeed in the world it is not enough to be stupid, you |
  `\must also be well-mannered.” —Voltaire |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI interface builder for python

2009-08-17 Thread Che M
On Aug 17, 2:26 pm, axl456  wrote:
> On Aug 17, 1:59 am, "l...@d@n"  wrote:
>
> > Which is the best GUI interface builder with drag and drop
> > capabilities.
> > I am using Ubuntu GNU/Linux.
> > Please help me.
> > Thank you.
>
> boa is really nice..

Boa (Boa Constructor) is really nice for wxPython GUI
work, but it has some bugs when using Linux that might
be dealbreakers for the user.  At least I have had
problems on Ubuntu 8.10 64 bit (but none or very few
with WinXP).

For those that might care, they are (as of now, Boa
0.6.1-4) are:

- The File -> New option is cut off in the menu.  But
that can be gotten around by using the Palette to choose
the same options.

- No gridlines in the Frame Designer (makes it harder
  to use)

- Some problems with the height of the rows in the
  Inspector, at least with 64 bit Ubuntu, some of which
  can be fixed with this workaround:
https://bugs.launchpad.net/ubuntu/+source/boa-constructor/+bug/313952
  and there is a note there saying it has been patched
  in a 0.6.1-6 version in a Debian repository.  Haven't tried.

- I have had some random shutdowns, but not many.

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


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Rami Chowdhury
Correct me if I'm wrong, but doesn't  
http://docs.python.org/library/datetime.html#datetime.datetime.strptime do  
this?



import locale
locale.setlocale(locale.LC_ALL, 'FR')

  'French_France.1252'

date_str = '05 Mai 2009 - 18h25'
fmt = '%d %B %Y - %Hh%M'
date_obj = datetime.strptime(date_str, fmt)
date_obj

  datetime.datetime(2009, 5, 5, 18, 25)

date_obj.strftime('%Y-%m-%d %H:%M')

  '2009-05-05 18:25'

If you're using a recent enough version of Python (2.5 and up) I'd imagine  
that's the best way to do it?


On Mon, 17 Aug 2009 16:58:28 -0700, Che M  wrote:


On Aug 17, 6:26 pm, Gilles Ganault  wrote:

Hello,

        I need to convert DD MM  dates into the MySQL-friendly
-MM-DD, and translate the month name from literal French to its
numeric equivalent (eg. "Janvier" into "01").

Here's an example:

SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
26 Mai 2007|17 Août 2009 - 09h20

I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
respectively.

What is the best way to do this in Python?

Thank you.


Likely this is not the best way, but I would do, for
the first one (and the same idea for the second):

def convert(date):
frenchdict = {'Mai':'May'} #etc...
day = mystring[:2]
month = frenchdict[ mystring[3:6] ]
year = mystring[7:11]
newdate = year+'-'+month+'-'+day
print 'newdate is ', newdate





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strongly typed list

2009-08-17 Thread Jonathan Gardner
On Aug 17, 2:19 pm, هاني الموصلي  wrote:
> Please could you lead me to a way or a good IDE that makes developing
> huge projects in python more easier than what i found.Now i am using
> eclips. Actually it is very hard to remember all my classes methods
> and attributes or copy and paste them each time.
> Thanks very much for your interest
> Hani Almousli.

You're relying on your IDE too much. You should rely on the code and
on your own notes. Your project should never get big because there is
no reason to throw in a bunch of useless code.

Think of the simplest way to get your job done. Then write that in
pseudo-code. Finally, run it in Python to see if it actually works.
You may be surprised with how far that will get you.

If you are having problems remembering the attributes and methods of
your instances, you are probably using too many attributes and
methods, their names are too long, or you have too many arguments to
each method. Keep the interfaces between parts as simple as possible.

If you still have a big project, then break it up into several
smaller, re-usable, and independent modules. Keep the interfaces as
simple as possible, and never write code that does anything but Duck-
Typing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 3:26 pm, Gilles Ganault  wrote:
>         I need to convert DD MM  dates into the MySQL-friendly
> -MM-DD, and translate the month name from literal French to its
> numeric equivalent (eg. "Janvier" into "01").
>
> Here's an example:
>
> SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
> 26 Mai 2007|17 Août 2009 - 09h20
>
> I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
> respectively.
>
> What is the best way to do this in Python?
>

Unfortunately, there isn't any string to date parsers in the built-
ins. Not to worry, though, since writing your own is easy, especially
if you use regular expressions from the re module. I suggest using an
RE such as:

r"(?P\d+)\s+(?P\w+)\s+(?P\d+)"

If you want to translate month names to month numbers, then you need
some sort of dict to do so. Unfortunately, there isn't a terrific
standard for this, so your best bet is to put it in some file
somewhere, or even hard-code it in your code. (Month names won't
change over the lifetime of your program, so it's reasonable to put
them in your code somewhere.)

month_names_to_numbers = {
'jan':1, ... }

Once you have the year, month, and date, formatting it is trivial with
the built-in formatter.

"%04d-%02d%02d %02d:%02d" % (year, month, date, hour, minute)

The variety of date formats out there have prevented a universal,
clean solution to this problem. Until we all start sticking to the
same conventions, we will always have to write code to translate dates
from one format to another.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need cleanup advice for multiline string

2009-08-17 Thread John Machin
On Aug 12, 6:52 am, Robert Dailey  wrote:
> On Aug 11, 3:40 pm, Bearophile  wrote:
>
> > Robert Dailey:
>
> > > This breaks the flow of scope. Would you guys solve this
> > > problem by moving failMsg into global scope?
> > > Perhaps through some other type of syntax?
>
> > There are gals too here.
> > This may help:http://docs.python.org/library/textwrap.html#textwrap.dedent
>
> > Bye,
> > bearophile
>
> It's a figure of speech. And besides, why would I want programming
> advice from a woman? lol. Thanks for the help.

Please consider having an attitude transplant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Che M
On Aug 17, 6:26 pm, Gilles Ganault  wrote:
> Hello,
>
>         I need to convert DD MM  dates into the MySQL-friendly
> -MM-DD, and translate the month name from literal French to its
> numeric equivalent (eg. "Janvier" into "01").
>
> Here's an example:
>
> SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
> 26 Mai 2007|17 Août 2009 - 09h20
>
> I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
> respectively.
>
> What is the best way to do this in Python?
>
> Thank you.

Likely this is not the best way, but I would do, for
the first one (and the same idea for the second):

def convert(date):
frenchdict = {'Mai':'May'} #etc...
day = mystring[:2]
month = frenchdict[ mystring[3:6] ]
year = mystring[7:11]
newdate = year+'-'+month+'-'+day
print 'newdate is ', newdate

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


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 3:26 pm, Gilles Ganault  wrote:
> Hello,
>
>         I need to convert DD MM  dates into the MySQL-friendly
> -MM-DD, and translate the month name from literal French to its
> numeric equivalent (eg. "Janvier" into "01").
>
> Here's an example:
>
> SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
> 26 Mai 2007|17 Août 2009 - 09h20
>
> I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
> respectively.
>
> What is the best way to do this in Python?
>
> Thank you.

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


Re: A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

2009-08-17 Thread Jason Earl
Xah Lee  writes:

> Fresh out of the oven:
>
> • How to use and setup Emacs's whitespace-mode
>   http://xahlee.org/emacs/whitespace-mode.html
>
>   Xah
> ∑ http://xahlee.org/

Xah,

I disagree with you about the usefulness of whitespace-mode's defaults,
and I certainly disagree with the need to use profanity on your usenet
post on the subject, but it is hard to argue against your
whitespace-mode.html page.  Very well done.

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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Ben Finney
Robert Dailey  writes:

> On Aug 11, 3:40 pm, Bearophile  wrote:
> > Robert Dailey:
> > > This breaks the flow of scope. Would you guys solve this
> > > problem by […]

> > There are gals too here.
>
> It's a figure of speech.

Indeed. When I use the term “guys” as a form of address, it's intended
to be gender-neutral.

> And besides, why would I want programming advice from a woman? lol.

No, that's not worth any laughter, especially because there are still
too many people who seriously think that way. It's totally unacceptable.
Please don't promote sexist garbage like that here.

-- 
 \“With Lisp or Forth, a master programmer has unlimited power |
  `\ and expressiveness. With Python, even a regular guy can reach |
_o__)   for the stars.” —Raymond Hettinger |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting a string into substrings of equal size

2009-08-17 Thread Gregor Lingl

Simon Forman schrieb:

On Aug 14, 8:22 pm, candide  wrote:

Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a decimal string with thousands
separator.

What is the pythonic way to do this ?


...

Thanks


FWIW:

def chunks(s, length=3):
stop = len(s)
start = stop - length
while start > 0:
yield s[start:stop]
stop, start = start, start - length
yield s[:stop]


s = '1234567890'
print ','.join(reversed(list(chunks(s
# prints '1,234,567,890'


or:

>>> def chunks(s, length=3):
i, j = 0, len(s) % length or length
while i < len(s):
yield s[i:j]
i, j = j, j + length

>>> print(','.join(list(chunks(s
1,234,567,890
>>> print(','.join(list(chunks(s,2
12,34,56,78,90
>>> print(','.join(list(chunks(s,4
12,3456,7890

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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Raymond Hettinger
[Xah Lee]
> This part i don't particular agree:
>
> > * The reason for implementing the key= parameter had nothing to do
> > with limitations of Python's compiler.  Instead, it was inspired by
> > the
> > decorate-sort-undecorate pattern.
>
> The decorate-sort-undecorate pattern is a compiler limitation, for
> most of today's langs. I'm not sure, but i think some of the fancy
> functional langs automatically detect such and optimize it away, to
> various degrees.
>
> ... my criticism is usually written in a style catered to irritate a
> particular class of coder i call tech geekers (they think of themselfs
> with their idiotic term “hackers”). So, parts are exaggerated. It'd be
> more clear to say, that the reason for python's “key”, and as a
> “solution” or need of the decorate-sort-undecorate issue, can be
> attributed to the current state of the art of popular imperative
> language's compilers (induced by such lang's semantics).

I'm not following you here.  If you're saying that it is possible
for a compiler to automatically transform a cmp argument into
a key argument, transforming O(n log n) calls into O(n) calls, then
I don't see how that could be done (a cmp argument can be a C function
that is not introspectable or an arbitrarily complex python function
that may be difficult to analyze and transform programmatically).

The key function was introduced as a simpler way for programmers
to write the commonly used decorate-sort-undecorate pattern --
compiler
limitations had nothing to do with it.

In general, key functions are not a terribly new or inflexible
concept.
The SORT BY clauses in SQL are an example.

That being said, it is a fair criticism of Python's compiler that it
does not do much in the way of optimizations.  It does a handful of
basic peephole optimizations but that is about it.  Other languages
like Haskell fair better in this regard.


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


Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Gilles Ganault
Hello,

I need to convert DD MM  dates into the MySQL-friendly
-MM-DD, and translate the month name from literal French to its
numeric equivalent (eg. "Janvier" into "01").

Here's an example:

SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
26 Mai 2007|17 Août 2009 - 09h20

I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
respectively.

What is the best way to do this in Python?

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


Re: Embedding a python console inside a python application

2009-08-17 Thread Zorigaman
On 17 août, 20:46, Zorigaman  wrote:
> Hi,
>
> I am starting an application in which I would like to have some
> scripting functionality. It will obviously be done in Python. The
> thing is that I would like my scripts to have access to the rest of
> the application as an object it could manipulate.
> I made some research and I found the code module, which allows to have
> a Python interpreter inside an application, but I am not sure if I can
> access to the "parent" which created this interpreter. A solution
> could be to launch my application through an interpreter, but the
> problem there is how to integrate it back into the GUI, redirecting
> streams ?
> Another option is the cmd module, but here, same problem, I am not
> sure if can have access to my application's objects.
> I am using PyQt with Python 2.6.1, I could switch to Python 3.0 if
> necessary.
> I am familiar with programming, but that's my first script-enabled
> application, tell me if I am missing something obvious.
>
> http://docs.python.org/library/code.htmlhttp://docs.python.org/library/cmd.html

D'oh. The code module offers exactly what I need, you can specify
object in the interpreter's constructor. D'oh.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Nathan Keel
Jon Harrop wrote:

> Xah Lee wrote:
>> On Aug 12, 12:15 pm, Raymond Hettinger  wrote:
>>> * The reason for implementing the key= parameter had nothing to do
>>> with limitations of Python's compiler.  Instead, it was inspired by
>>> the
>>> decorate-sort-undecorate pattern.
>> 
>> The decorate-sort-undecorate pattern is a compiler limitation, for
>> most of today's langs. I'm not sure, but i think some of the fancy
>> functional langs automatically detect such and optimize it away, to
>> various degrees.
> 
> You mean people use that pattern as a fast alternative in languages
> where user-defined functions are very slow, like Python and
> Mathematica?
> 


Do not give this "Xah Lee" idiot any attention. This asshole posts only
self-serving nonsense, because he thinks it makes him sound important
(when in reality, he is absolutely clueless).  This idiot always cross
posts to 5 or more different groups that have nothing to do with his
attempts to impress people (which always fail).  He's incredibly
arrogant, yet incredibly clueless.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need cleanup advice for multiline string

2009-08-17 Thread MRAB

Carl Banks wrote:

On Aug 17, 10:03 am, Jean-Michel Pichavant 
wrote:

I'm no English native, but I already heard women/men referring to a
group as "guys", no matter that group gender configuration. It's even
used for group composed exclusively of women. Moreover it looks like a
*very* friendly form, so there is really nothing to worry about it.


I like how being very friendly means calling people after a guy who
tried to blow up the English Parliament.


Guy Fawkes adopted the name Guido while fighting for the Spanish in the
Low Countries:

http://en.wikipedia.org/wiki/Guy_Fawkes

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


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Chris Rebert
On Mon, Aug 17, 2009 at 2:12 PM, Carl Banks wrote:
> On Aug 17, 8:44 am, a...@pythoncraft.com (Aahz) wrote:
>> In article 
>> <461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,
>> Robert Dailey   wrote:
>> >It's a figure of speech. And besides, why would I want programming
>> >advice from a woman? lol. Thanks for the help.
>>
>> Well, I'm sorry to see this, it means I was wrong about the lack of
>> sexism in the Python community.
>
> Oh come on, one newbie making an off-color joke is not any sort of
> reflection of the community as a whole.
>
> Anyway it's pretty naive to expect what is now a large community to
> avoid bad eggs altogether.  Price you pay for popularity.

Agreed on both points, but the lack of any reprimanding for making
said inappropriate joke /would/ reflect badly on the community.
Fortunately, said person's behavior has now been condemned by virtue
of this thread; it's a step in the right direction.

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


Re: python doc available in emacs info format?

2009-08-17 Thread Xah Lee
> Please do not slag off a project if you want people to help;
> it tends to put the goat up.

a healthy community needs both positive comment as well as negative to
grow.

emacs's user base has been rotting off from i estimate more than 50%
of programers to less that 1% today.

the particular observation about info doc in this thread is a specific
example.

You can help FSF and emacs to improve, by, for example, trying to help
it to evolve with the rapidly changing computing industry, In this
case, document formats, provided if you see some of my points as
valid. Or, at least consider this eroding awareness of the gnu info
format among average programers worth discussing. No disrespect to
you, but dismissing it as “troll” or similiar sentiment is not
helpful.

emacs community is too much cult and pride. FSF and its product the
GNU was highly successful in the 1980 and 1990s, with its gcc, emacs,
and slew of gnu version of unix tools. A significant part of the
reason is because these products at the time is truely better products
in comparison to existing ones, that there are almost no substitute.
Today, for many variety and complexity of reasons, almost none of this
is true, except possiblly a few such as gcc and GPG. The unix shells
ways and sed, awk, etc tools has largely been replaced by perl,
python, ruby etc, partly due to the changing nature of computing. For
GCC itself, and make, yacc, bison etc there are tens of competiting
products either commercial or open source. Then there's Java, with its
entire suite of tools and libs, and there are tens of truely quality
languages out there today other then the ones that GCC can handle.

emacs 23, although is fantastic to us emacs fans, but if you look
carefully at its feature list, most of it is widely in commericial
software about 10 years ago.

  Xah
∑ http://xahlee.org/

☄


On Aug 17, 4:32 am, "Colin S. Miller"  wrote:
> Xah Lee wrote:
> > btw, is there still info format for python doc?
>
> > i feel kinda sad that emacs info format has pretty much been
> > deprecated over the past decade. About a decade ago, you still will
> > see now and then people asking for emacs info format of docs (was the
> > days of perl). Today, one don't hear of it.
>
> > Part of this is due to emacs cult problem. See:
>
> Xah,
>
> Please do not slag off a project if you want people to help;
> it tends to put the goat up.
>
> It is not "Emacs Info" format, it is FSF Info format.
> There is a stand-alone program to read the Info documentation.
> The program is called "info".
>
> Ubuntu maintains a package search site, it is onhttp://packages.ubuntu.com/
>
> However, there seems to be no files named
> python.*info   (regexp)
>
> There is a
> python-docutils package
> which does contain information in several
> other formats.
>
> This package can be found either via the above site
> or using "apt-cache search python-doc".
>
> As "info" is a FSF format, all FSF produced programs
> will provide documentation in this format. However Python
> is not under the auspices of the FSF, so does not need to use
> this format.
>
> BTW,
> HTML versions of INFO documentation can be generated by
> info2html or info_to_html on them, or texi2html on the source.
>
> Have a nice day,
> Colin S. Miller
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Carl Banks
On Aug 17, 8:44 am, a...@pythoncraft.com (Aahz) wrote:
> In article 
> <461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,
> Robert Dailey   wrote:
>
>
>
> >It's a figure of speech. And besides, why would I want programming
> >advice from a woman? lol. Thanks for the help.
>
> Well, I'm sorry to see this, it means I was wrong about the lack of
> sexism in the Python community.

Oh come on, one newbie making an off-color joke is not any sort of
reflection of the community as a whole.

Anyway it's pretty naive to expect what is now a large community to
avoid bad eggs altogether.  Price you pay for popularity.


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


Re: Strongly typed list

2009-08-17 Thread Fabio Zadrozny
> Hello, I am using eclips for python and i am facing a problem. I have
> many classes with many properties and want a list of objects from one
> of my declared classes. The problem is:When i am accessing any item
> from the list, the IDE does not know it's type because in python we do
> not declare the variable with it's type, so there is no auto complete
> and i have to go to the class to copy the attribute name. To make idea
> more clear:
>
> class AutomataBranch(object):
>    def __init__(selfparams):
>        self.Name="";
>        self.nodes=[];
>
> class LanguageAutomata(object):
>    def __init__(selfparams):
>        self.cfgAutomata=[];#This has AutomaBranch Type
> Now in any method in LanguageAutomata class if i wrote: cfgAutomata.
> Then it wont give me the Name attribute Is there any solution for
> that?
> Perhaps of there is some thing like C# List
> cfgAutomata such that the list wont accept items unless they are
> AutomataBranch will be good.


Hello,

Unfortunately, right now there is no way to gather that specific code
completion in pydev -- because of the dynamic nature of python, that
info is very hard to get.

Best Regards,

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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Carl Banks
On Aug 17, 10:03 am, Jean-Michel Pichavant 
wrote:
> I'm no English native, but I already heard women/men referring to a
> group as "guys", no matter that group gender configuration. It's even
> used for group composed exclusively of women. Moreover it looks like a
> *very* friendly form, so there is really nothing to worry about it.

I like how being very friendly means calling people after a guy who
tried to blow up the English Parliament.


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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Paul Rubin
Jon Harrop  writes:
> You mean people use that pattern as a fast alternative in languages where
> user-defined functions are very slow, like Python and Mathematica?

It really doesn't matter whether the language is fast or slow--there
are going to be applications where calling the comparison function
multiple times per element is slower than calling it once per element
and storing the result.

Note the Haskell idiom (sortBy (compare`on`f) xs) is similar to DSU
but calls the comparison function multiple times.

Python 3.0 went overboard by actually removing the cmp argument and
requiring use of the key argument.  That requires various kludges if
the key is, say, a tree structure that has to be recursively compared
with another such structure.  Maybe then can bring back cmp someday.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Barcodes

2009-08-17 Thread Tim Chase

My company needs a small inventory management app. Does
python have any libraries to help with reading and writing
bar codes?


I've written bar code apps and python really doesn't enter
into that part of things.  Printers generally have bar code
printing capabilities so you just send the right escape
sequences and you get the bar codes. To read them, bar code
readers scan and translate before sending the values through
typically a keyboard wedge or serial port.


To add to what Emile mentions, most barcode readers present a 
keyboard-wedge interface, so that scanning a barcode merely 
appears as if you typed it at the keyboard (USB readers show up 
as a HID profile).  Often they'll have configuration barcodes 
that you can scan to tweak the profile (such as pressing , 
 or an arrow-key after sending the barcode; controlling beep 
tone & volume, etc).


For printing barcodes, you can use any number of solutions -- the 
most popular usually just involves installing a "barcode font" 
and then rendering text in that font to your desired output 
canvas.  I believe there are some native rendering solutions as 
well, but I've not investigated since the font method was more 
than sufficient for my wants.


-tkc



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


Strongly typed list

2009-08-17 Thread هاني الموصلي
Hello, I am using eclips for python and i am facing a problem. I have
many classes with many properties and want a list of objects from one
of my declared classes. The problem is:When i am accessing any item
from the list, the IDE does not know it's type because in python we do
not declare the variable with it's type, so there is no auto complete
and i have to go to the class to copy the attribute name. To make idea
more clear:

class AutomataBranch(object):
def __init__(selfparams):
self.Name="";
self.nodes=[];

class LanguageAutomata(object):
def __init__(selfparams):
self.cfgAutomata=[];#This has AutomaBranch Type
Now in any method in LanguageAutomata class if i wrote: cfgAutomata.
Then it wont give me the Name attribute Is there any solution for
that?
Perhaps of there is some thing like C# List
cfgAutomata such that the list wont accept items unless they are
AutomataBranch will be good.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Barcodes

2009-08-17 Thread Emile van Sebille

On 8/17/2009 1:18 PM Ronn Ross said...
My company needs a small inventory management app. Does python have any 
libraries to help with reading and writing bar codes?


I've written bar code apps and python really doesn't enter into that 
part of things.  Printers generally have bar code printing capabilities 
so you just send the right escape sequences and you get the bar codes. 
To read them, bar code readers scan and translate before sending the 
values through typically a keyboard wedge or serial port.


Emile

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


Re: Data visualization in Python

2009-08-17 Thread jordilin
On 17 ago, 21:10, kj  wrote:
> I'm looking for a good Python package for visualizing
> scientific/statistical data.  (FWIW, the OS I'm interested in is
> Mac OS X).
>
> The users of this package will be experimental biologists with
> little programming experience (but currently learning Python).
>
> (I normally visualize data using R or Mathematica, but I don't want
> to saddle these novices with the task of learning yet another
> language.)
>
> TIA!
>
> kynn
Matplotlib is the one. There is Google Chart api which seems fairly
easy to understand and use thanks to pygooglechart bindings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: off topic: google groups sucks?

2009-08-17 Thread Aaron Watters
On Aug 17, 1:44 pm, John Yeung  wrote:
> Thanks, Aaron, for confirming that it's not just me!

yea, unfortunately this kind of thing happens in monopolies
that have no viable competition anymore... Sometimes I begin
to suspect that I'm seeing the results that I should want
rather than the results I want.

(Lucene has this property
too -- you get the results the algorithm wants you to get,
rather than the results you want to get.)

-- Aaron Watters

===
In communism the future is certain,
but the past is ever changing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Barcodes

2009-08-17 Thread Ronn Ross
My company needs a small inventory management app. Does python have any
libraries to help with reading and writing bar codes?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: zip codes

2009-08-17 Thread Piet van Oostrum
> Grant Edwards  (GE) wrote:

>GE> On 2009-08-16, Shailen  wrote:
>>> Thanks Martin and Aahz. Anyone know if zip code information is
>>> copyrighted for the US?

>GE> You can't copyright "information" as such.  Only concrete
>GE> expressions of information.  A particular publication
>GE> containing zip code information can be copyrighted.  The
>GE> underlying facts themselve cannot be.

But that doesn't help you if you need that information and the only way
to obtain it is from copyrighted sources.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Carl Banks
On Aug 17, 12:59 pm, Carl Banks  wrote:
> The cost doesn't even remotely justify it.

I mean, it doesn't even remotely justify the cost.

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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Carl Banks
On Aug 17, 12:41 pm, exar...@twistedmatrix.com wrote:
> There's a lot of things in Python that I don't strictly *need*.  That
> doesn't mean that they wouldn't be welcome if I could have them.
> Getting rid of the range/xrange dichotomy would improve things.  Yes, I
> can work around it until the runtime is good enough to let me think
> about an *interesting* problem instead.

You don't have to think about using xrange in a for loop, you just
always use it.

> That makes it a legitimate
> complaint in my eyes.  You're welcome to disagree, of course, but do you
> have an argument more compelling than the one you give here?

I am not arguing in favor of range/xrange, I am saying that it's silly
to complain that the compiler isn't a whole lot more complex than it
is just so it can implemnent a semantically-diconnected special case
just so that you can avoid typing an extra "x".  The cost doesn't even
remotely justify it.


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


comparing XML files to eachother

2009-08-17 Thread David Brochu
I need to compare one xml document to another to see if the content matches.
Unfortunately, the formatting (spacing) and order of elements may change
between files from run to run. I have looked into xml dom minidom but can't
seem to find how to accomplish this. Does anyone know how I can do a compare
between two XML documents using the STL?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread exarkun

On 06:32 pm, pavlovevide...@gmail.com wrote:

On Aug 17, 4:40�am, exar...@twistedmatrix.com wrote:

On 02:12 am, pavlovevide...@gmail.com wrote:



>On Aug 16, 3:35�pm, sturlamolden  wrote:
>>On 16 Aug, 14:57, Dennis Lee Bieber  wrote:

>> > � � � � Well, the alternative would be to have two keywords for
>>looping: one
>> > for your "simple" incrementing integer loop, and another for a 
loop

>>that
>> > operates over the elements of some collection type.

>>A compiler could easily recognise a statement like

>>� �for i in range(n):

>>as a simple integer loop.

>It would be a simple to do if you were writing it for a different
>langauge was a lot less dynamic than Python is. �It'd be quite a
>complex hack to add it to CPython's compiler while maintaing the
>current highly dynamic runtime semantics and backwards compatibility,
>which is a design constraint of Python whether you like it or not.

In your other message, you said this wasn't a legitimate CPython
complaint.  Here, you say that it would be a "complex hack" to 
implement

this in CPython. �"complex hack" has negative connotations in my mind.
This seems contradictory to me.


Well, you missed the point, chief.

It's not a legitimate complaint because you can use xrange, you don't
need compiler magic to recognize and optimize range.


There's a lot of things in Python that I don't strictly *need*.  That 
doesn't mean that they wouldn't be welcome if I could have them. 
Getting rid of the range/xrange dichotomy would improve things.  Yes, I 
can work around it until the runtime is good enough to let me think 
about an *interesting* problem instead.  That makes it a legitimate 
complaint in my eyes.  You're welcome to disagree, of course, but do you 
have an argument more compelling than the one you give here?  It seems 
to me one could use it to argue a lot of Python out of existence. 
Chief.  (Seriously, "chief"?  What are you going for?  It sounds like 
condescension to me; what's the point of that?  I hope I'm just 
misreading you.)


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


Re: Data visualization in Python

2009-08-17 Thread Grant Edwards
On 2009-08-17, Grant Edwards  wrote:
> On 2009-08-17, kj  wrote:
>
>> I'm looking for a good Python package for visualizing
>> scientific/statistical data.  (FWIW, the OS I'm interested in
>> is Mac OS X).
>
> Both matplotlib and gnuplot-py can produce pretty good results
> with a minimum of effort:

Oh, just in case you haven't found them, you might also be
interested in the SciPy and Scientific Python projects:

   http://www.scipy.org/

   http://sourcesup.cru.fr/projects/scientific-py/

Though they have deceptively similar names, they're two
separate projects.  Unfortunately, some rather promenent
documentation conflates the two.  For example,

  http://docs.python.org/3.1/tutorial/whatnow.html

refers to www.scipy.org as "the Scientific Python" project.

-- 
Grant Edwards   grante Yow! I hope the
  at   ``Eurythmics'' practice
   visi.combirth control ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data visualization in Python

2009-08-17 Thread Grant Edwards
On 2009-08-17, kj  wrote:

> I'm looking for a good Python package for visualizing
> scientific/statistical data.  (FWIW, the OS I'm interested in
> is Mac OS X).

Both matplotlib and gnuplot-py can produce pretty good results
with a minimum of effort:

  http://matplotlib.sourceforge.net/
  http://gnuplot-py.sourceforge.net/  

I lean more towards gnuplot, but that's probably just a bias
from having used Gnuplot for 10+ years before learning Python.
Both matplotlib and gnuplot are basically 2D packages with some
3D features.
  
There's also a Python binding for VTK.  I found it a bit harder
to use for the stuff I did, but sophisticated 3D stuff it's
probably the winner:

  http://www.vtk.org/

[It also has the only Delaunay triangulation module (of the 3
that I tried) that worked reliably, but you probably don't care
about that.]
  
-- 
Grant Edwards   grante Yow! Let me do my TRIBUTE
  at   to FISHNET STOCKINGS ...
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Paul Boddie
On 17 Aug, 19:23, Jean-Michel Pichavant 
wrote:
>
> Are you suggesting this list reject part of the community regarding its
> sexual orientation, ethnicity, size, culture? If that was the case I'd
> like to know about it.

Careful: you probably meant to write "rejects", not "reject". That
changes the meaning of what you've written somewhat.

> I would really want to know how you'd guess my gender (could be some
> clue somewhere), my sexual orientation, my religion and so on.
> How can you reject someone regarding informations you don't have ?

Well, everyone can of course hide their actual identity on the
Internet, but when someone references a group of people with a
juvenile remark (if we are being charitable about the matter), it has
nothing to do with guessing the characteristics of individuals. The
whole excuse that anonymity defends against insults and harassment is
a bit like saying that slinging mud at everyone is acceptable as long
as everyone is encouraged to do it and nobody is wearing their nicest
clothes. And unless your idea of a Python-related conference is
something close to a fancy-dress event with everyone "in character" -
which would obviously limit the effectiveness of such an event - you
presumably understand that there is a genuine need for continuity
between interactions on and off the Internet. This somewhat undermines
your argument.

> That's the beauty of this mailing list, it has diversity, by design.

An explanation is needed here for this not to sound like
conversational padding.

> We even welcome people that mixes up joke with sexist aggression, not to
> mention how open minded we are :o)

Well, jokes actually need an amusing side, regardless of how
"edgy" ("juvenile" is typically the more accurate term) the joke-
teller is trying to be, and that was completely absent from the remark
in question. There's little room for error in communication over a
medium like this one, as I pointed out with your opening sentence. And
much as it probably upsets the "unfettered free speech" advocates, we
should be able to assert that "sexist aggression" is not acceptable
behaviour amongst those who seek to participate in our community.

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


Re: python doc available in emacs info format?

2009-08-17 Thread Bruce Stephens
"Colin S. Miller"  writes:

[...]

> Ubuntu maintains a package search site, it is on
> http://packages.ubuntu.com/
>
> However, there seems to be no files named
> python.*info   (regexp)

And yet there are info files in python2.5-doc:
.

[...]

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


Data visualization in Python

2009-08-17 Thread kj



I'm looking for a good Python package for visualizing
scientific/statistical data.  (FWIW, the OS I'm interested in is
Mac OS X).

The users of this package will be experimental biologists with
little programming experience (but currently learning Python).

(I normally visualize data using R or Mathematica, but I don't want
to saddle these novices with the task of learning yet another
language.)

TIA!

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


Re: XPath support?

2009-08-17 Thread kj
In  Kev Dwyer 
 writes:

>On Sun, 16 Aug 2009 20:29:15 +, kj wrote:

>> I'm looking for a XML parser that produces an object with full XPath
>> support.  What I've been using up to now, xml.etree.ElementTree, fails
>> to support Xpath predicates, as in "sp...@eggs='3']/ham".
>> 
>> What I'm trying to do is to read-in a large XML string, and parse it
>> into an object from which I can extract nodes matching selectors that
>> include such predicates.
>> 
>> Any suggestions would be greatly appreciated.
>> 
>> TIA!
>> 
>> kynn


>Have you tried lxml (http://codespeak.net/lxml/)?

Thanks!  (To Diez too!)

kynn

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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread J�rgen Exner
Jon Harrop  wrote:
>Xah Lee wrote:
[...]

Please do not feed this well-known troll.

He is known to spew some remotely on-topic junk into a bunch of
unrelated NGs and to enjoy the ensuing confusion.

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


Embedding a python console inside a python application

2009-08-17 Thread Zorigaman
Hi,

I am starting an application in which I would like to have some
scripting functionality. It will obviously be done in Python. The
thing is that I would like my scripts to have access to the rest of
the application as an object it could manipulate.
I made some research and I found the code module, which allows to have
a Python interpreter inside an application, but I am not sure if I can
access to the "parent" which created this interpreter. A solution
could be to launch my application through an interpreter, but the
problem there is how to integrate it back into the GUI, redirecting
streams ?
Another option is the cmd module, but here, same problem, I am not
sure if can have access to my application's objects.
I am using PyQt with Python 2.6.1, I could switch to Python 3.0 if
necessary.
I am familiar with programming, but that's my first script-enabled
application, tell me if I am missing something obvious.

http://docs.python.org/library/code.html
http://docs.python.org/library/cmd.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Carl Banks
On Aug 17, 4:40 am, exar...@twistedmatrix.com wrote:
> On 02:12 am, pavlovevide...@gmail.com wrote:
>
>
>
> >On Aug 16, 3:35 pm, sturlamolden  wrote:
> >>On 16 Aug, 14:57, Dennis Lee Bieber  wrote:
>
> >> >         Well, the alternative would be to have two keywords for
> >>looping: one
> >> > for your "simple" incrementing integer loop, and another for a loop
> >>that
> >> > operates over the elements of some collection type.
>
> >>A compiler could easily recognise a statement like
>
> >>   for i in range(n):
>
> >>as a simple integer loop.
>
> >It would be a simple to do if you were writing it for a different
> >langauge was a lot less dynamic than Python is.  It'd be quite a
> >complex hack to add it to CPython's compiler while maintaing the
> >current highly dynamic runtime semantics and backwards compatibility,
> >which is a design constraint of Python whether you like it or not.
>
> In your other message, you said this wasn't a legitimate CPython
> complaint.  Here, you say that it would be a "complex hack" to implement
> this in CPython.  "complex hack" has negative connotations in my mind.
> This seems contradictory to me.

Well, you missed the point, chief.

It's not a legitimate complaint because you can use xrange, you don't
need compiler magic to recognize and optimize range.


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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Jon Harrop
Xah Lee wrote:
> On Aug 12, 12:15 pm, Raymond Hettinger  wrote:
>> * The reason for implementing the key= parameter had nothing to do
>> with limitations of Python's compiler.  Instead, it was inspired by
>> the
>> decorate-sort-undecorate pattern.
> 
> The decorate-sort-undecorate pattern is a compiler limitation, for
> most of today's langs. I'm not sure, but i think some of the fancy
> functional langs automatically detect such and optimize it away, to
> various degrees.

You mean people use that pattern as a fast alternative in languages where
user-defined functions are very slow, like Python and Mathematica?

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI interface builder for python

2009-08-17 Thread axl456
On Aug 17, 1:59 am, "l...@d@n"  wrote:
> Which is the best GUI interface builder with drag and drop
> capabilities.
> I am using Ubuntu GNU/Linux.
> Please help me.
> Thank you.

boa is really nice..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Uninstalling mac python2.5 to install python2.6

2009-08-17 Thread Ned Deily
In article <83423f73-83da-436b-a3ba-e83cd61cd...@cs.stir.ac.uk>,
 Farhan Sheikh  wrote:
> i originally had python2.5 on my mac at the univeristy and had to get  
> 2.6 to get NEST and pyNN to work together. however now as those are  
> now installed, i had to install numpy.
> 
> As i installed numpy, it only installed its directories into the  
> python2.5 folders and as i am new to to mac terminals i don't know how  
> to change its directories to be installed into python2.6. my question  
> is, do i have to uninstall python 2.5 so that only python2.6 is on the  
> machine or is there a way to change the path so it saves into python2.5?

There appears to be a NumPy installer image for Python 2.6 and OX 10.5 
here:

http://sourceforge.net/projects/numpy/files/

Multiple versions of python can co-exist on OS X.  You definitely should 
not remove the Apple-supplied python2.5 (linked to from /usr/bin/python) 
in 10.5.

-- 
 Ned Deily,
 n...@acm.org

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


Re: Using a Callback Function - ftplib

2009-08-17 Thread seldan24
On Aug 17, 1:51 pm, David <71da...@libero.it> wrote:
> Il Mon, 17 Aug 2009 10:43:33 -0700 (PDT), seldan24 ha scritto:
>
> > Hello,
>
> > I'm utterly confused by something which is most likely trivial.  I'm
> > attempting to connect to an FTP server, retrieve a list of files, and
> > store than in an array.  I.e.:
>
> > import ftplib
>
> > ftp = ftplib.FTP(server)
> > ftp.login(user, pass)
> > ftp.cwd(conf['testdir'])
>
> Why bother with retrlines? Use the provided higer level fuctions:
>
> remotefiles = []
> ftp.dir(remotefiles.append)
>
> or, if you prefer nlst
>
> remotefiles = ftp.nlst()
>
> regards
> david

I didn't even notice the higher level methods.  I changed the
retrieval line to:

ftp.nlst("testfile*.txt")

This works great.  The result is even captured in an array.  I really
have no idea what the difference between a LIST and NLST is within
FTP.  Never delved that deep into it.  I did notice that an NLST will
return a specific FTP code if a file doesn't exist, whereas a LIST
doesn't.  So, I ended up using NLST as that'll generate an
ftplib.error_perm exception.  Based on if the job cares if a file is
not available or not (some do, some don't), I'll either exit, or
continue on with the file loop.

Anyway, thanks again, works perfectly, next time I'll try to scroll
down and read a bit more prior to posting!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a Callback Function - ftplib

2009-08-17 Thread David
Il Mon, 17 Aug 2009 10:43:33 -0700 (PDT), seldan24 ha scritto:

> Hello,
> 
> I'm utterly confused by something which is most likely trivial.  I'm
> attempting to connect to an FTP server, retrieve a list of files, and
> store than in an array.  I.e.:
> 
> import ftplib
> 
> ftp = ftplib.FTP(server)
> ftp.login(user, pass)
> ftp.cwd(conf['testdir'])

Why bother with retrlines? Use the provided higer level fuctions:

remotefiles = []
ftp.dir(remotefiles.append)

or, if you prefer nlst

remotefiles = ftp.nlst()

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


Re: off topic: google groups sucks?

2009-08-17 Thread John Yeung
On Aug 17, 12:41 pm, Aaron Watters  wrote:
> I'm having better luck now using the advanced search option
> with queries like
>
>    gadfly group:comp.lang.python
>
> The "search this group" feature still needs fixing, however.

Thanks, Aaron, for confirming that it's not just me!  I've been
noticing spotty or missing results searching groups for a while now,
actually, to the point that I gave up trying.  Can't remember exactly
when it started, but I do remember that it used to work pretty well
and then suddenly got significantly worse.

Also, thanks for the tip of trying advanced searches.

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


Using a Callback Function - ftplib

2009-08-17 Thread seldan24
Hello,

I'm utterly confused by something which is most likely trivial.  I'm
attempting to connect to an FTP server, retrieve a list of files, and
store than in an array.  I.e.:

import ftplib

ftp = ftplib.FTP(server)
ftp.login(user, pass)
ftp.cwd(conf['testdir'])
ftp.retrlines('NLST ' + "testfile*.txt")
ftp.quit()

The above example works fine... and would return a list of any files
that match "testfile*.txt" to standard out.  The issue is I don't want
that to go to stdout, I'd rather capture them within an array so I can
retrieve them later.

If I try something like:

my_files = ftp.retrlines('NLST ' + "testfile*.txt")

Then, my_files, will just print out the return code of the FTP NLST
command.  I'm trying to get the file names themselves.  Now, I've read
through the ftplib module section of the Python documentation and it
says that, by default, the output goes to sys.stdout unless a callback
function is used.  Here is where I get utterly lost.  I can certainly
see the files being outputted to sys.stdout, but don't know how to
capture that output... i.e.

testfile1.txt
testfile2.txt
testfile3.txt

Will show to the screen, but I can't catch it!  I'm sure this is
trivial... any help would be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: flatten a list of list

2009-08-17 Thread Tim Cook
On Aug 16, 6:47 am, Terry  wrote:
> Hi,
>
> Is there a simple way (the pythonic way) to flatten a list of list?
> rather than my current solution:
>
> new_list=[]
> for l in list_of_list:
>     new_list.extend(l)
>
> or,
>
> new_list=reduce(lambda x,y:x.extend(y), list_of_list)
>
> br, Terry

Well, This is not simple but it is comprhensive in that it has to do
several things.  I am using it to decompose deeply nested lists from
Pyparsing output that may have strings in a variety of languages.
Performance wise I do not know how it stacks up against the other
examples but it works for me.  :-)

def flatten(x):
"""flatten(sequence) -> list

Returns a single, flat list which contains all elements retrieved
from the sequence and all recursively contained sub-sequences
(iterables). All strings are converted to unicode.

"""
result = []
for el in x:
#if isinstance(el, (list, tuple)):
if hasattr(el, "__iter__") and not isinstance(el, basestring):
result.extend(flatten(el))
else:
result.append(el)


# all strings must be unicode
rtnlist=[]
for x in result:
if isinstance(x,str):
# replace any brackets so Python doesn't think it's a list
and we still have a seperator.
x=x.replace('[','_')
x=x.replace(']','_')
try:
x=unicode(x, "utf8")  # need more decode types here
except UnicodeDecodeError:
x=unicode(x, "latin1")
except UnicodeDecodeError:
x=unicode(x,"iso-8859-1")
except UnicodeDecodeError:
x=unicode(x,"eucJP")

rtnlist.append(x)

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


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Rami Chowdhury
You'll know that Python is sexist the day you'll find the title 'No  
women allowed' on the python main document page.


Good God I hope you're being ironic.

On Mon, 17 Aug 2009 10:23:39 -0700, Jean-Michel Pichavant  
 wrote:



Aahz wrote:
In article  
<461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,

Robert Dailey   wrote:


It's a figure of speech. And besides, why would I want programming
advice from a woman? lol. Thanks for the help.



Well, I'm sorry to see this, it means I was wrong about the lack of
sexism in the Python community.  I encourage anyone who wants to improve
the situation to join the new diversity list:

http://mail.python.org/mailman/listinfo/diversity

Are you suggesting this list reject part of the community regarding its  
sexual orientation, ethnicity, size, culture? If that was the case I'd  
like to know about it.
I would really want to know how you'd guess my gender (could be some  
clue somewhere), my sexual orientation, my religion and so on.

How can you reject someone regarding informations you don't have ?

That's the beauty of this mailing list, it has diversity, by design.
We even welcome people that mixes up joke with sexist aggression, not to  
mention how open minded we are :o)


Beside, the day you'll meet a real act of sexism in this list, please  
know that people talk and act on their own, do not assign their attitude  
to the whole community.
You'll know that Python is sexist the day you'll find the title 'No  
women allowed' on the python main document page.


JM

PS : Newbies are not welcome here !






--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Jean-Michel Pichavant

Aahz wrote:

In article <461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,
Robert Dailey   wrote:
  

It's a figure of speech. And besides, why would I want programming
advice from a woman? lol. Thanks for the help.



Well, I'm sorry to see this, it means I was wrong about the lack of
sexism in the Python community.  I encourage anyone who wants to improve
the situation to join the new diversity list:

http://mail.python.org/mailman/listinfo/diversity
  
Are you suggesting this list reject part of the community regarding its 
sexual orientation, ethnicity, size, culture? If that was the case I'd 
like to know about it.
I would really want to know how you'd guess my gender (could be some 
clue somewhere), my sexual orientation, my religion and so on.

How can you reject someone regarding informations you don't have ?

That's the beauty of this mailing list, it has diversity, by design.
We even welcome people that mixes up joke with sexist aggression, not to 
mention how open minded we are :o)


Beside, the day you'll meet a real act of sexism in this list, please 
know that people talk and act on their own, do not assign their attitude 
to the whole community.
You'll know that Python is sexist the day you'll find the title 'No 
women allowed' on the python main document page.


JM

PS : Newbies are not welcome here !


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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Ethan Furman

Emmanuel Surleau wrote:

Dr. Phillip M. Feldman wrote:



[snip]



def is_prime(n):
  for j in range(2,n):
 if (n % j) == 0: return False
  return True

It seems as though Python is actually expanding range(2,n) into a list of
numbers, even though this is incredibly wasteful of memory. There should
be a looping mechanism that generates the index variable values
incrementally as they are needed.



[snip]
>>

I will also observe that if you were to stop programming whatever
language you are more familiar with in Python, and start programming
Python in Python, you'll have an easier time of it.



I don't see what's particularly un-Pythonic with this code. Not using xrange() 
is a mistake, certainly, but it remains clear, easily understandable code 
which correctly demonstrates the naive algorithm for detecting whether n is a 
prime. It doesn't call for condescension



[snip]
>

Cheers,

Emm


My comment about programming Python in Python was geared more towards 
the subject line than the actual code, and the biases evident in his 
comments in both this thread and earlier ones.


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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Piet van Oostrum
> Simon Brunning  (SB) wrote:

>SB> 2009/8/11 Robert Dailey :
>>> On Aug 11, 3:40 pm, Bearophile  wrote:
 There are gals too here.
>>> 
>>> It's a figure of speech. And besides, why would I want programming
>>> advice from a woman? lol. Thanks for the help.

>SB> Give the attitudes still prevalent in our industry (cf
>SB>  and many more), I'm sorry to say that I
>SB> don't think this is funny.

seconded
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need cleanup advice for multiline string

2009-08-17 Thread Jean-Michel Pichavant

Grant Edwards wrote:

On 2009-08-11, Bearophile  wrote:
  

Robert Dailey:



This breaks the flow of scope. Would you guys solve this
problem by moving failMsg into global scope? Perhaps through
some other type of syntax?
  

There are gals too here.



Straying a bit OT, but I find this particular issue rather
fascinating.

At least in the US, "guys" is now pretty much gender-neutral
according to my casual research (mostly just paying attention
to informal speach).

Oddly, it still seems to be masculine when singular. Though one
commonly hears a group of females addressed as "you guys" or
refered to as "those guys", one never hears a single female
referred to as "a guy" or "that guy".

It is a bit tricky, however, since a phrase like "a group of
guys" still seems to refer to just males since the word "guys"
in that case is being applied individually to a plurality of
persons rather being applied collectivelly to a single group --
if that makes any sense.

I've actually discussed this with a a number of female friends,
and they almost all thought the term "gals" was condescending
and actually preferred to be referred to collectively as
"guys".

  
I'm no English native, but I already heard women/men referring to a 
group as "guys", no matter that group gender configuration. It's even 
used for group composed exclusively of women. Moreover it looks like a 
*very* friendly form, so there is really nothing to worry about it.


Forms like:
"Hi guys", "You guys should do something...", "Come on guys..." are very 
friendly and gender-neutral.


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


Re: off topic: google groups sucks?

2009-08-17 Thread Aaron Watters
On Aug 17, 10:05 am, Aaron Watters  wrote:
> Just a note.  It seems that google groups is increasing the
> sucks coefficient.

I'm having better luck now using the advanced search option
with queries like

   gadfly group:comp.lang.python

which become

   http://groups.google.com/groups/search?q=gadfly+group:comp.lang.python

The "search this group" feature still needs fixing, however.

  -- Aaron Watters

===
if you lined up all economists end to end
they'd still point in different directions.
   -- stolen from somewhere
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need cleanup advice for multiline string

2009-08-17 Thread Grant Edwards
On 2009-08-11, Bearophile  wrote:
> Robert Dailey:
>
>> This breaks the flow of scope. Would you guys solve this
>> problem by moving failMsg into global scope? Perhaps through
>> some other type of syntax?
>
> There are gals too here.

Straying a bit OT, but I find this particular issue rather
fascinating.

At least in the US, "guys" is now pretty much gender-neutral
according to my casual research (mostly just paying attention
to informal speach).

Oddly, it still seems to be masculine when singular. Though one
commonly hears a group of females addressed as "you guys" or
refered to as "those guys", one never hears a single female
referred to as "a guy" or "that guy".

It is a bit tricky, however, since a phrase like "a group of
guys" still seems to refer to just males since the word "guys"
in that case is being applied individually to a plurality of
persons rather being applied collectivelly to a single group --
if that makes any sense.

I've actually discussed this with a a number of female friends,
and they almost all thought the term "gals" was condescending
and actually preferred to be referred to collectively as
"guys".

-- 
Grant Edwards   grante Yow! You can't hurt me!!
  at   I have an ASSUMABLE
   visi.comMORTGAGE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Aahz
In article <461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,
Robert Dailey   wrote:
>
>It's a figure of speech. And besides, why would I want programming
>advice from a woman? lol. Thanks for the help.

Well, I'm sorry to see this, it means I was wrong about the lack of
sexism in the Python community.  I encourage anyone who wants to improve
the situation to join the new diversity list:

http://mail.python.org/mailman/listinfo/diversity
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there."  --Steve Gonedes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: zip codes

2009-08-17 Thread Nigel Rantor

MRAB wrote:

Sjoerd Mullender wrote:

Martin P. Hellwig wrote:

Shailen wrote:

Is there any Python module that helps with US and foreign zip-code
lookups? I'm thinking of something that provides basic mappings of zip
to cities, city to zips, etc. Since this kind of information is so
often used for basic user-registration, I'm assuming functionality of
this sort must be available for Python. Any suggestions will be much
appreciated.


There might be an associated can of worms here, for example in the
Netherlands zip codes are actually copyrighted and require a license if
you want to do something with them, on the other hand you get a nice SQL
formatted db to use it. I don't know how this works in other countries
but I imagine that it is likely to be generally the same.



Also in The Netherlands, ZIP codes are much more fine-grained than in
some other countries: ZIP code plus house number together are sufficient
to uniquely identify an address.  I.e. you don't need the street name.
E.g., my work address has ZIP code 1098 XG and house number 123, so
together they indicate that I work at Science Park 123, Amsterdam.

In other words, a simple city <-> ZIP mapping is not sufficient.


The same comment applies to UK postcodes, which are also alphanumeric.
My home postcode, for example, is shared with only 3 other houses, IIRC.


Kind of off-topic...but nevertheless...

Yes, the UK postcode database (PAF) can be bought from the Royal Mail 
for a fee.


The data cannot be copyright, but the version they maintain and 
distribute is.


As an aside, the PAF has finer grained information than simply the 
postal code, every letterbox in the UK has (or is meant to) a DPS 
(delivery point suffix), so that given a post code and DPS you can 
uniquely identify individual letterbox even when, for example, a house 
has been split into multiple flats.


So, nastily, you *can* identify individual letterboxes, but the Royal 
Mail does not publicise the fact, so you cannot actually look at a post 
code on a letter and determine the letterbox it is intended for.


Shame really.

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


Re: XML parsing with python

2009-08-17 Thread John Posner



Use the iterparse() function of the xml.etree.ElementTree package.

http://effbot.org/zone/element-iterparse.htm
http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk

Stefan
  


iterparse() is too big a hammer for this purpose, IMO. How about this:

 from xml.etree.ElementTree import ElementTree
 tree = ElementTree(None, "myfile.xml")
 for elem in tree.findall('//book/title'):
 print elem.text


-John

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


Re: off topic: google groups sucks?

2009-08-17 Thread Stefan Behnel
jkn wrote:
> On Aug 17, 3:05 pm, Aaron Watters  wrote:
>> Just a note.  It seems that google groups is increasing the
>> sucks coefficient.
>>
>> I search for things using "group search" for comp.lang.python
>> and I get no results even though I know there are results from
>> a few months or weeks ago.
> 
> There seems to be a problem with Google Searching 'at the moment'. I
> have seen it with other groups, but not noticed it to date on c.l.p.
> 
> 
> http://groups.google.com/group/groupsknownissues/browse_thread/thread/d88d02f269a7d20d#

I noticed a problem with Google in general this weekend, not even related
to mailing lists. I can't remember getting similarly bad results from a web
search for years. Even trivial queries that worked for months returned
completely unrelated pages and lacked the "obvious" target page in the
result set.

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


Re: httplib incredibly slow :-(

2009-08-17 Thread Chris Withers

i3dmaster wrote:

Just wanted to check if you can try turning on the debug mode for
httplib and see if you can read a bit more debug info on where the
calls get hung. In your example, it would be conn.set_debuglevel(1)


I had a look through the code this debug level controls and I don't see 
any information that this provides which would help here...


Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: off topic: google groups sucks?

2009-08-17 Thread jkn
On Aug 17, 3:05 pm, Aaron Watters  wrote:
> Just a note.  It seems that google groups is increasing the
> sucks coefficient.
>
> I search for things using "group search" for comp.lang.python
> and I get no results even though I know there are results from
> a few months or weeks ago.

There seems to be a problem with Google Searching 'at the moment'. I
have seen it with other groups, but not noticed it to date on c.l.p.


http://groups.google.com/group/groupsknownissues/browse_thread/thread/d88d02f269a7d20d#

J^n
-- 
http://mail.python.org/mailman/listinfo/python-list


off topic: google groups sucks?

2009-08-17 Thread Aaron Watters
Just a note.  It seems that google groups is increasing the
sucks coefficient.

I search for things using "group search" for comp.lang.python
and I get no results even though I know there are results from
a few months or weeks ago.

What is the best alternative for this kind of trawling?  gmane?

With all the smart people working at google how can they
 up like this?

Inquiring minds want to know.

   -- Aaron Watters

===
Sisyphus got ripped.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread David Robinow
On Sun, Aug 16, 2009 at 11:10 PM, Nobody wrote:
> Java also has iterators; it's more a case of people coming from C and BASIC.
>
> Although, some of those may have come *through* Java without abandoning
> old habits. You see the same thing with people coming from BASIC to C and
> writing:
>
>        #define NUM_DATES 50
>        int day[NUM_DATES], month[NUM_DATES], year[NUM_DATES];
>
> rather than defining a "struct".
>
> Sometimes referred to as "I know ten languages and can write in BASIC in
> all of them".

Ha, ha. I learned that pattern in Fortran. I confess to having written
code like that in C. I think I've gotten over it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ignored test cases in unittest

2009-08-17 Thread Terry Yin
On Aug 17, 8:23 pm, David House  wrote: > > Note that the
unittest module now supports the `skip' and > `expectedFailure' decorators,
which seem to describe some of the > solutions here. > > Seehttp://
docs.python.org/3.1/library/unittest.html#skipping-tests-and-e... > > -- >
-David Yes, indeed! I'm using 2.6 now. It seemed I need to copy untitest.py
from 3.1. But the docs.python.org is hell slow from where I am (China), not
even working except the title:-( br, Terry

On Mon, Aug 17, 2009 at 8:23 PM, David House  wrote:

> 2009/8/16 Terry :
> > Thanks for the solutions. I think the decorator idea is what I'm look
> > for:-)
>
> Note that the unittest module now supports the `skip' and
> `expectedFailure' decorators, which seem to describe some of the
> solutions here.
>
> See
> http://docs.python.org/3.1/library/unittest.html#skipping-tests-and-expected-failures
>
> --
> -David
>



-- 
-
Blog: http://terry-yinzhe.spaces.live.com/
twitter: http://twitter.com/terryyin
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >