[RELEASED] Python 3.1 final

2009-06-27 Thread Benjamin Peterson
On behalf of the Python development team, I'm thrilled to announce the first
production release of Python 3.1.

Python 3.1 focuses on the stabilization and optimization of the features and
changes that Python 3.0 introduced.  For example, the new I/O system has been
rewritten in C for speed.  File system APIs that use unicode strings now handle
paths with undecodable bytes in them. Other features include an ordered
dictionary implementation, a condensed syntax for nested with statements, and
support for ttk Tile in Tkinter.  For a more extensive list of changes in 3.1,
see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python
distribution.

To download Python 3.1 visit:

 http://www.python.org/download/releases/3.1/

The 3.1 documentation can be found at:

 http://docs.python.org/3.1

Bugs can always be reported to:

 http://bugs.python.org


Enjoy!

--
Benjamin Peterson
Release Manager
benjamin at python.org
(on behalf of the entire python-dev team and 3.1's contributors)
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Replacing a built-in method of a module object instance

2009-06-27 Thread Peter Otten
David Hirschfield wrote:

 I have a need to replace one of the built-in methods of an arbitrary
 instance of a module in some python code I'm writing.
 
 Specifically, I want to replace the __getattribute__() method of the
 module I'm handed with my own __getattribute__() method which will do
 some special work on the attribute before letting the normal attribute
 lookup continue.
 
 I'm not sure how this would be done. I've looked at all the
 documentation on customizing classes and creating instance methods...but
 I think I'm missing something about how built-in methods are defined for
 built-in types, and where I'd have to replace it. I tried this naive
 approach, which doesn't work:
 
 m = module instance
 
 def __getattribute__(self, attr):
 print modified getattribute:,attr
 return object.__getattribute__(self, attr)
 
 import types
 m.__getattribute__ = types.MethodType(__getattribute__,m)
 
 It seems to create an appropriately named method on the module instance,
 but that method isn't called when doing any attribute lookups, so
 something's not right.
 Any ideas? Is this even possible?

Special methods are looked up in the type, not the instance, and you cannot 
set attributes of the module type.

As a workaround you can write a wrapper class and put that into the 
sys.modules module cache:

 class Module(object):
... def __init__(self, module):
... self.__module = module
... def __getattr__(self, name):
... try:
... return getattr(self.__module, name.lower())
... except AttributeError:
... def dummy(*args): pass
... return dummy
...
 import shutil
 import sys
 sys.modules[shutil] = Module(shutil)
 import shutil
 shutil.MOVE
function move at 0x7f20f9b7d5f0
 shutil.yadda
function dummy at 0x7f20f9b7d6e0

Peter

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


Re: No trees in the stdlib?

2009-06-27 Thread Stefan Behnel
João Valverde wrote:
 I wouldn't consider anything other than C for such a module on
 efficiency alone, unless it was a prototype of course. But I have little
 knowledge about the Python C API.

Cython is your true friend, if only for rapid prototyping.

http://cython.org/

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


Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-27 Thread Stefan Behnel
Kee Nethery wrote:
 On Jun 25, 2009, at 11:39 PM, Stefan Behnel wrote:
 parsing a
 document from a string does not have its own function, because it is
 trivial to write

 tree = parse(BytesIO(some_byte_string))
 
 :-) Trivial for someone familiar with the language. For a newbie like
 me, that step was non-obvious.

I actually meant the code complexity, not the fact that you need to know
BytesIO to do the above.


 If what you meant is actually parsing from a byte string, this is easily
 done using BytesIO(), or StringIO() in Py2.x (x6).
 
 Yes, thanks! Looks like BytesIO is a v.3.x enhancement.

It should be available in 2.6 AFAIR, simply as an alias for StringIO.


 Looks like the
 StringIO does what I need since all I'm doing is pulling the unicode
 string into et.parse.

As I said, this won't work, unless you are either

a) passing a unicode string with plain ASCII characters in Py2.x
or
b) confusing UTF-8 and Unicode


 theXmlDataTree =
 et.parse(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData))

 This will not work because ET cannot parse from unicode strings (unless
 they only contain plain ASCII characters and you happen to be using
 Python
 2.x). lxml can parse from unicode strings, but it requires that the XML
 must not have an encoding declaration (which would render it non
 well-formed). This is convenient for parsing HTML, it's less
 convenient for XML usually.
 
 Right for my example, if the data is coming in as UTF-8 I believe I can do:
theXmlDataTree = et.parse(StringIO.StringIO(theXmlData), encoding
 ='utf-8')

Yes, although in this case you are not parsing a unicode string but a UTF-8
encoded byte string. Plus, passing 'UTF-8' as encoding to the parser is
redundant, as it is the default for XML.

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


Re: Python simple web development

2009-06-27 Thread laplacia...@gmail.com
On Jun 26, 6:08 pm, Thomas Allen thomasmal...@gmail.com wrote:
 On Jun 25, 3:29 am, Private Private mail...@gmail.com wrote:


  Can you suggest anything ?

 I don't think anything's lighter than web.py.

 http://webpy.org/


My impression is that webpy is intended for experienced users who
might otherwise just write all their own code, but who might as well
use webpy instead because it's there. It's tutorial is very brief, and
(if memory serves) webpy didn't even have any docs at all for a while.

As Thomas suggests, maybe have a look at Werkzeug http://werkzeug.pocoo.org/
. They've got substantial docs (which look quite good) and even a
nifty screencast.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: It's ...

2009-06-27 Thread Gabriel Genellina
En Thu, 25 Jun 2009 14:07:19 -0300, Angus Rodgers twir...@bigfoot.com  
escribió:



On Thu, 25 Jun 2009 17:56:47 +0100, I burbled incoherently:


[...] does the new feature,
by which a file becomes iterable, operate by some kind of coercion
of a file object to a list object, via something like x.readlines()?


Sorry to follow up my own post yet again (amongst my weapons is
a fanatical attention to detail when it's too late!), but I had
better rephrase that question:

Scratch list object, and replace it with something like: some
kind of iterator object, that is at least already implicit in 2.1
(although the term 'iterator' isn't mentioned in the index to the
2nd edition of Beazley's book).  Something like that!  8-P


Iterators were added in Python 2.2. An iterator is an object that can be  
iterated over; that is, an object for which for item in some_iterator:  
... works.

Files are their own iterators, yielding one line at a time.
See PEP 234 http://www.python.org/dev/peps/pep-0234/

--
Gabriel Genellina

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


Re: looking for a book on python

2009-06-27 Thread laplacia...@gmail.com
On Jun 26, 8:48 pm, Randy Foiles ab...@127.0.0.1 wrote:
 Hello and thank you for taking your time to read this.
         I was interested in learning about python.  In the long ago past I did
 learn some programing but I have not used any of it for years.  I do
 remember some basics however so the book does not have to be for a total
 beginner.  (C, C++, BASIC, Visual BASIC, Pascal and some ADA)
         I have been using Linux for a while and overall still don't know much
 about it but I can find my way.  I have my system dual boot with windows
 vista.
         I do realize that everyone is different but I would like to see some
 suggestions and maybe reasons why you think it is good.  I have looked
 for/searched and found a few different books but as my means are a bit
 limited right now I don't really want to buy several just one or maybe
 two books.
         Oh and if someone knows a place to find some used books of this sort
 that would be great (ebay I guess :)
 Thanks for your thoughts
 Randy theslayers9   gmail

The Oreilly Python in a Nutshell (2006, 2nd ed.) book is very good
and will get you up to speed in short order.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-27 Thread João Valverde

João Valverde wrote:

Aahz wrote:

In article mailman.2170.1246042676.8015.python-l...@python.org,
=?ISO-8859-1?Q?Jo=E3o_Valverde?=  backu...@netcabo.pt wrote:   
Anyway, I'm *not* trying to discourage you, just explain some of the

roadblocks to acceptance that likely are why it hasn't already happened.

If you're serious about pushing this through, you have two options:

* Write the code and corresponding PEP yourself (which leads to the
second option, anyway)

* Lobby on the python-ideas mailing list
  


Currently I don't have a strong need for this. I just believe it would 
be a benefit to a language I like a lot.  Lobbying isn't my thing. I'd 
rather write code, but neither am I the most qualified person for the 
job. It would certainly be interesting and fun and challenging in a 
good way and a great way to learn some new stuff. But I would 
definitely need mentoring or asking some silly questions on the 
mailing list. Maybe I'll seriously consider it some other time.
There's also another issue raise by Paul Rubin I wasn't even aware of, 
that the LGPL is not suitable for the standard library. Having to write 
a complete BST implementation in C is a drag. There are already good C 
libraries available.

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


Re: Python simple web development

2009-06-27 Thread laplacia...@gmail.com
On Jun 27, 2:25 am, laplacia...@gmail.com laplacia...@gmail.com
wrote:

 As Thomas suggests, maybe have a look at Werkzeug ...

Typo: s/Thomas/Petr/

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


Re: os.walk and os.listdir problems python 3.0+

2009-06-27 Thread Gabriel Genellina
En Thu, 25 Jun 2009 11:15:15 -0300, Amos Anderson amosander...@gmail.com  
escribió:


Thank you. That works very well when writing to a text file but what is  
the

equivalent when writing the information to stdout using print?


See this recent post:
http://comments.gmane.org/gmane.comp.python.general/627850

--
Gabriel Genellina

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


Regular Expression Non Capturing Grouping Does Not Work.

2009-06-27 Thread Virtual Buddha
Hello all,

I am having some difficulties with the non-capturing grouping in
python regular expression module.

Even the code from the online documentation (http://docs.python.org/
howto/regex.html#non-capturing-and-named-groups) does not seem to
work.

As per the docs given in the link above this should happen (text
copied from the page):

 m = re.match(([abc])+, abc)
 m.groups()
('c',)
 m = re.match((?:[abc])+, abc)
 m.groups()
()

BUT, this is what I get:

 m = re.match(([abc])+, abc)
 m.group()
'abc'
 m = re.match((?:[abc])+, abc)
 m.group()
'abc'

I am using python 2.6 on opensuse 11.1. Any one know what I might be
doing wrong? Or is this a bug?

Thank you
VB


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


Re: Regular Expression Non Capturing Grouping Does Not Work.

2009-06-27 Thread Miles Kaufmann

On Jun 27, 2009, at 3:28 AM, Virtual Buddha wrote:


Hello all,

I am having some difficulties with the non-capturing grouping in
python regular expression module.

Even the code from the online documentation (http://docs.python.org/
howto/regex.html#non-capturing-and-named-groups) does not seem to
work.

...


Notice that you are calling .group() on the match object instead  
of .groups().  Without any arguments, .group() is equivalent  
to .group(0), which means return the entire matching string.


http://docs.python.org/library/re.html#re.MatchObject.group

-Miles

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


Re: Regular Expression Non Capturing Grouping Does Not Work.

2009-06-27 Thread Peter Otten
Virtual Buddha wrote:

 Hello all,
 
 I am having some difficulties with the non-capturing grouping in
 python regular expression module.
 
 Even the code from the online documentation (http://docs.python.org/
 howto/regex.html#non-capturing-and-named-groups) does not seem to
 work.
 
 As per the docs given in the link above this should happen (text
 copied from the page):
 
 m = re.match(([abc])+, abc)
 m.groups()
 ('c',)
 m = re.match((?:[abc])+, abc)
 m.groups()
 ()
 
 BUT, this is what I get:
 
 m = re.match(([abc])+, abc)
 m.group()
 'abc'
 m = re.match((?:[abc])+, abc)
 m.group()
 'abc'
 
 I am using python 2.6 on opensuse 11.1. Any one know what I might be
 doing wrong? Or is this a bug?

group != groups

match.group() or match.group(0) gives you a special group that comprises the 
whole match. Regular capturing groups start at index 1, and only those are 
returned by match.groups():

 re.match((?:[abc])+, abc).group() # one group
'abc'
 re.match((?:[abc])+, abc).groups() # all capturing groups
()

Peter

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


Re: Beginning with Python; the right choice?

2009-06-27 Thread Terry Reedy

Chris Rebert wrote:

On Fri, Jun 26, 2009 at 10:39 PM, Terry Reedytjre...@udel.edu wrote:

sato.ph...@gmail.com wrote:

Hi,

As you can imagine, I am new, both to this group and to Python.  I
have read various posts on the best book to buy or online tutorial to
read and have started to go through them.  I was wondering, as someone
with virtually no programming experience (I am a photographer by
trade), is Python the right language for me to try and learn?

I do vaguely remember learning what I think was BASIC on some old
Apple's back in elementary school (circa 1992).  Would something like
that (the name at least makes it SOUND easier) be more feasible?

I consider Python the Basic of the 21st century.


I don't know whether that's an insult or a compliment... :P


At one time, Basic was the language that everyone learned, at least 
amateurs and beginners of the time. It was an important part of the 
microcomputer revolution. It made beginning programming available to 
anyone, in spite of its faults.


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


Re: Beginning with Python; the right choice?

2009-06-27 Thread Hendrik van Rooyen
Terry Reedy tjre...@...l.edu wrote:

 I consider Python the Basic of the 21st century.

Oh Dear.

Was it not Dijkstra who said that learning basic
rotted your brain, or words more or less to that effect?

And here I am, feeling rather dull lately...   :-)   

To the OP:   - Learning Python will get you going, and productive
in the sense of actually making programmes that do simple stuff
with files on disk, and so on, faster than anything else I know of.

And the beauty of it is that no matter how far, and in which direction,
you want to go, there is a pythonic way to do it.  So none of your
effort put in to learn some python thing is wasted - you can literally
start small and build up at your own pace.  And when you get stuck,
you can come here or to the tutor list, and you will get friendly help.

- Hendrik



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


Re: looking for a book on python

2009-06-27 Thread OdarR
On 27 juin, 02:48, Randy Foiles ab...@127.0.0.1 wrote:
 Hello and thank you for taking your time to read this.
         I was interested in learning about python.  In the long ago past I did
 learn some programing but I have not used any of it for years.  I do
 remember some basics however so the book does not have to be for a total
 beginner.  (C, C++, BASIC, Visual BASIC, Pascal and some ADA)
         I have been using Linux for a while and overall still don't know much
 about it but I can find my way.  I have my system dual boot with windows
 vista.
         I do realize that everyone is different but I would like to see some
 suggestions and maybe reasons why you think it is good.  I have looked
 for/searched and found a few different books but as my means are a bit
 limited right now I don't really want to buy several just one or maybe
 two books.
         Oh and if someone knows a place to find some used books of this sort
 that would be great (ebay I guess :)
 Thanks for your thoughts
 Randy theslayers9   gmail

Learning Python
http://oreilly.com/catalog/9780596513986/

new issue soon, covering 2.6 and 3
http://oreilly.com/catalog/9780596158064/?CMP=AFC-ak_bookATT=Learning+Python%2c+Fourth+Edition%2c

the best book I read concerning Py understanding, well written.

I would start with web content, then later would buy the fourth
edition of Learning Python.

enjoy,
Olivier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expression Non Capturing Grouping Does Not Work.

2009-06-27 Thread Virtual Buddha

 group != groups

 match.group() or match.group(0) gives you a special group that comprises the
 whole match. Regular capturing groups start at index 1, and only those are
 returned by match.groups():

  re.match((?:[abc])+, abc).group() # one group
 'abc'
  re.match((?:[abc])+, abc).groups() # all capturing groups

 ()

 Peter


Aaargh! Should have caught that myself. Sorry for wasting all your
time. Thank you Peter and Miles! (I am off to bed now. 4:10 am :)


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


Re: YASS (Yet Another Success Story)

2009-06-27 Thread Gabriel Genellina

En Sat, 20 Jun 2009 07:58:02 -0300, k3xji sum...@gmail.com escribió:


Started a project year ago with hard goals in mind : Developing a game
server which can handle thousands of clients simultaneously. [...]
I don't know Python at the time and only coded few simple projects
with it.


And you still could write the server - that's very good (and shows your  
own great skills and Python ease of use...)



After profiling the code, it turns out most of the time is spent on
the following:
[...] 3) Redundant try-except's in all over place(Again our fault to make
the system stable, we have put some debug purposed-assert like try-
excepts in the main server flow.)


I don't think this should make a difference. Setting up a try/except block  
usually has a very small cost (if no exception is actually raised). Care  
to tell us more details?



Just one note
about optimizing Python code: do not optimize Python code based on
your assumptions, just go and test if it really runs faster. I don't
want to go to details of this hint, but believe me making Python code
optimized may be very very tricky.


Yes, specially if you came from a statically typed language; what looks  
innocent may have a significant cost (e.g. resolving obj.name), and what  
looks complicated may be fairly fast (e.g. a list comprehension).



It is then I decided to write up here this as a success story, as I am
very newcomer to Python but come up with a nearly commercial product
in a very short period of time and I don't think this is about my
personal characteristics and intelligence or so:), as I am old enough
to know/meet that there are much much more brilliant people than I am
and they also have similar experiences with Python.


Thanks for sharing your experience!


So, one last note: every software project goes same tasks as above
often much much more officially and carefully, I would suggest
managers to see that just do not listen to the ordinary brain-washes.
Python is a great choice for easy developing, easy debugging, easy
maintaining and most importantly very very time-friendly. Of course
there will be tasks .n which Python is suitable, but hey, if it Python
is in the list, take it seriously.


Nice summary!

--
Gabriel Genellina

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


Re: Beginning with Python; the right choice?

2009-06-27 Thread OdarR
On 27 juin, 04:22, sato.ph...@gmail.com sato.ph...@gmail.com
wrote:
 Hi,

 As you can imagine, I am new, both to this group and to Python.  I
 have read various posts on the best book to buy or online tutorial to
 read and have started to go through them.  I was wondering, as someone
 with virtually no programming experience (I am a photographer by
 trade), is Python the right language for me to try and learn?

 I do vaguely remember learning what I think was BASIC on some old
 Apple's back in elementary school (circa 1992).  Would something like
 that (the name at least makes it SOUND easier) be more feasible?

 If I do choose to learn Python, are there any tutorials for the
 absolute beginner.  I do not mean beginner to Python, but rather,
 beginner to programming.  Someone who hasn't a clue what object
 oriented whatcha-ma-whoozit means.  I ask again because I understand
 that content is always evolving and there might be new tutorials out
 there.

 Thanks!

 -Daniel Sato

hi,

what is for you the purpose of learning programming ?
what do you want to do ?

at first glance, I think Python is a good choice for you, for its
clarity.

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


Re: Beginning with Python; the right choice?

2009-06-27 Thread Joachim Strömbergson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Aloha!

Che M wrote:
 In terms of good tutorials for absolute beginners, here are two:
 
 Alan Gauld's Learning to Program
 http://www.freenetpages.co.uk/hp/alan.gauld/

...

Also, don't miss the great Dive into Python:

http://diveintopython.org/

A well written, easy to understand and fun (yes) introduction to all
fantastic things in Python.

- --
Med vänlig hälsning, Yours

Joachim Strömbergson - Alltid i harmonisk svängning.

Kryptoblog - IT-säkerhet på svenska
http://www.strombergson.com/kryptoblog

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpF3lEACgkQZoPr8HT30QG+jQCgq5ZpTS8ErLA9/YKIPBdJSNGp
F80AoKBZHSCDfzPawcECKsYiIKbmLA5G
=ML8w
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: It's ...

2009-06-27 Thread Angus Rodgers
On Sat, 27 Jun 2009 03:32:12 -0300, Gabriel Genellina
gagsl-...@yahoo.com.ar wrote:

Iterators were added in Python 2.2.

Just my luck.  :-)

See PEP 234 http://www.python.org/dev/peps/pep-0234/

You've got to love a language whose documentation contains 
sentences beginning like this:

 Among its chief virtues are the following four -- no, five
 -- no, six -- points: [...]

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


Re: The system cannot execute the specified program.

2009-06-27 Thread Lawrence D'Oliveiro
In message 1co94553odu2d0dfnn89fdkgbsvo5dv...@4ax.com, Tim Slattery wrote:

 When I googled that message, the links that came up had to do with
 missing DLLs.

Ironic, isn't it, that Microsoft designs these messages to be non-technical 
to avoid putting off ordinary users, and yet it just ends up blanding them 
to the point of unintelligibility, so that you need to resort to Google to 
figure out what they mean.

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


Fast Dictionary Access

2009-06-27 Thread Thomas Lehmann
Hi!

In C++, programming STL you will use the insert method which always
provides a position and a flag which indicates whether the position
results from a new insertion or an exisiting element. Idea is to have
one search only.

code
if  data.has_key(key):
   value = data[key]
/code

But this does mean (does it?) that the dictionary is searched two
times! If so, can somebody show me how to do this in one step?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast Dictionary Access

2009-06-27 Thread Chris Rebert
On Sat, Jun 27, 2009 at 2:47 AM, Thomas
Lehmanniris-und-thomas-lehm...@t-online.de wrote:
 Hi!

 In C++, programming STL you will use the insert method which always
 provides a position and a flag which indicates whether the position
 results from a new insertion or an exisiting element. Idea is to have
 one search only.

 code
 if  data.has_key(key):
   value = data[key]
 /code

 But this does mean (does it?) that the dictionary is searched two
 times! If so, can somebody show me how to do this in one step?

Use exception handling:

try:
value = data[key]
except KeyError:
print No such key
else:
print The value for that key is, value

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


Python Imaging Library download link broken?

2009-06-27 Thread peter
Just got a new computer and I'm trying to download my favourite
applications.  All's well until I get to PIL, and here pythonware and
effbot both return a 502 Proxy error.

Is this just a temporary glitch, or something more serious?  And if
it's the latter, is there any alternative source?

Peter

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


Re: Good books in computer science?

2009-06-27 Thread Albert van der Horst
In article 0244e76b$0$20638$c3e8...@news.astraweb.com,
Steven D'Aprano  st...@removethis.cybersource.com.au wrote:
Nathan Stoddard wrote:

 The best way to become a good programmer is to program. Write a lot of
 code; work on some large projects. This will improve your skill more than
 anything else.

I think there are about 100 million VB code-monkeys who prove that theory
wrong.

Seriously, and without denigrating any specific language, you can program by
(almost) mindlessly following a fixed number of recipes and patterns. This
will get the job done, but it won't make you a good programmer.

For programming practice I do the problems of http://projecteuler.net/
I'm on the Eulerians page (best performers on 25 last problems).
There is not a single VB programmer in the top 100.
(Lots of Python programmers, C-family, also Haskel, APL, LISP
Algol, Forth, Perl and I repeat not a single VB programmer.)
Currently the top place is a Python programmer.

These programs may be very demanding, minutes on very fast systems.
Bad algorithms take days, weeks or literally forever.
Interestingly the factor 5 between Python and C is irrelevant compared
to a good algorithm, apparently.

--
Steven

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
alb...@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Good books in computer science?

2009-06-27 Thread Albert van der Horst
In article 0050ecf7$0$9684$c3e8...@news.astraweb.com,
Steven D'Aprano  st...@removethis.cybersource.com.au wrote:
SNIP
 On 2009-06-14 14:04:02 +0100, Steven D'Aprano
 st...@removethis.cybersource.com.au said:

 I think I'm paraphrasing Richard Feynman here, but the
 only way to truly understand something is to do it.

An amazingly inappropriate quote for a *theoretical* physicist to have said.

The remark of Feynman goes to the heart of science and mathematics.
(Try understanding some number theory or string theory by just
reading about it.)


Whether Feynman did or didn't say that, it's clearly untrue: many people do
without understanding. Many people can cook, some people are expert cooks,

This is even a classical lack of logic skills. Feynman says a-b,
and you attack b-a.

SNIP

--
Steven


Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
alb...@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Beginning with Python; the right choice?

2009-06-27 Thread sato.ph...@gmail.com
Thank you for all of the links and advice.

What do I want to learn Python for?

Again, pardon me for my lack of relevant information.  I am also a
journalist (an out of work one at the moment, like so many others) and
I feel that learning python could be useful for computer assisted
reporting, that is, utilizing databases, creating interactive maps and
the like.

http://chicago.everyblock.com/crime/

I also am fond of the Ellington Content Management System, made using
django, which, if I am not mistaken, is related to
Python...in...some...way..lol.  I'll figure it out?  Any additional
advice now that you know what I want to learn and why would be greatly
appreciated.

Oh and, if you need a photographer, www.danielsato.com!

thanks again!

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


Re: Fast Dictionary Access

2009-06-27 Thread Paul Rubin
Thomas Lehmann iris-und-thomas-lehm...@t-online.de writes:
 code
 if  data.has_key(key):
value = data[key]
 /code
 
 But this does mean (does it?) that the dictionary is searched two
 times! If so, can somebody show me how to do this in one step?

  value = data.get(key, None) 

sets value to None if the key is not in the dictionary.  You can use
some other sentinel if None might actually be a value in the
dictionary.  One way to get a unique sentinel is:

   sentinel = object()

You can also use exception handling (this is quite efficient in Python)
as Chris Rebert mentioned.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good books in computer science?

2009-06-27 Thread Albert van der Horst
In article 7xocssvzrh@ruckus.brouhaha.com,
Paul Rubin  http://phr...@nospam.invalid wrote:
koranthala koranth...@gmail.com writes:
 Which are the classic books in computer science which one should
 peruse?
 I have  (a) Code Complete (b) GOF (c) Art of programming.

 Art of programming was too tough for me - and I couldnt understand
 much. The other two were good books - I understood and implemented
 quite a bit from both.
 What are the other books which I should peruse?

Code Complete and GOF are software engineering books but not really
CS books.  TAOCP is a CS book but a bit old fashioned.  Other classics:

Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson,
Ronald L. Rivest, and Clifford Stein.

Thanks. I lost that title a while ago, must buy.

Also Numerical Recipe's in FORTRAN/Pascal/C
(Have they done Python yet?)


Structure and Interpretation of Computer Programs by Harold Abelson
and Gerald Jay Sussman (online at mitpress.mit.edu/sicp)

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
alb...@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Angus Rodgers
On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah 
wong_po...@yahoo.ca wrote:

On Jun 26, 4:51 pm, Chris Rebert c...@rebertia.com wrote:
 On Fri, Jun 26, 2009 at 12:43 PM, powahwong_po...@yahoo.ca wrote:
  How to change the first character of the line to uppercase in a text
  file?
  [...]

 We're not in the business of doing homework. Some hints though:

 `s.upper()` converts the string in variable `s` to all upper case
 (e.g. aBcD.upper() -- ABCD)
 `for line in afile:` iterates over each line in a file object.
 [...]

 And here are the docs on working with files:
 http://docs.python.org/library/functions.html#open
 http://docs.python.org/library/stdtypes.html#file-objects

 That should be enough to get you started.

Thank you for your hint.
This is my solution:
f = open('test', 'r')
for line in f:
print line[0].upper()+line[1:],

I know this is homework, so I didn't want to say anything (especially
as I'm a newcomer, also just starting to learn the language), but it
seems OK to mention that if you hunt around some more in the standard
library documentation, you'll find an even shorter way to write this.
-- 
Angus Rodgers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Angus Rodgers
On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah
wong_po...@yahoo.ca wrote:

Thank you for your hint.
This is my solution:
f = open('test', 'r')
for line in f:
print line[0].upper()+line[1:],

Will your program handle empty lines of input correctly?
-- 
Angus Rodgers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Angus Rodgers
On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically:

On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah
wong_po...@yahoo.ca wrote:

Thank you for your hint.
This is my solution:
f = open('test', 'r')
for line in f:
print line[0].upper()+line[1:],

Will your program handle empty lines of input correctly?

Strangely enough, it seems to do so, but why?
-- 
Angus Rodgers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Peter Otten
Angus Rodgers wrote:

 On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically:
 
On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah
wong_po...@yahoo.ca wrote:

Thank you for your hint.
This is my solution:
f = open('test', 'r')
for line in f:
print line[0].upper()+line[1:],

Will your program handle empty lines of input correctly?
 
 Strangely enough, it seems to do so, but why?

Because there aren't any. When you read lines from a file there will always 
be at least the newline character. Otherwise it would indeed fail:

 for line in peter\npaul\n\nmary.splitlines():
... print line[0].upper() + line[1:]
...
Peter
Paul
Traceback (most recent call last):
  File stdin, line 2, in module
IndexError: string index out of range


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


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Angus Rodgers
On Sat, 27 Jun 2009 13:02:47 +0200, Peter Otten 
__pete...@web.de wrote:

Angus Rodgers wrote:

 On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically:

Will your program handle empty lines of input correctly?
 
 Strangely enough, it seems to do so, but why?

Because there aren't any. When you read lines from a file there will always 
be at least the newline character. Otherwise it would indeed fail:

 for line in peter\npaul\n\nmary.splitlines():
... print line[0].upper() + line[1:]
...
Peter
Paul
Traceback (most recent call last):
  File stdin, line 2, in module
IndexError: string index out of range

Hmm ... the \r\n sequence at the end of a Win/DOS file seems to be
treated as a single character.

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


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Angus Rodgers
On Sat, 27 Jun 2009 12:13:57 +0100, I wrote:

the \r\n sequence at the end of a Win/DOS file

Of course, I meant the end of a line of text, not the end of
the file.

(I promise I'll try to learn to proofread my posts.  This is
getting embarrassing!)
-- 
Angus Rodgers
-- 
http://mail.python.org/mailman/listinfo/python-list


to use unicode strings only

2009-06-27 Thread Gaudha
Hey gentlemen,

I wanna make all the strings in my code unicode strings. How to do it
without giving unicode switch 'u' before every string?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictionary self lookup

2009-06-27 Thread Jure Erznožnik
Norberto,

While certainly useful, this kind of functionality contradicts the way
today's string libraries work.
What you are proposing isn't dict self referencing, but rather strings
referencing other external data (in this case other strings from the
same dict).

When you write code like
config = {home : /home/test}
config[user1] = config[home] + /user1

config[user1] isn't stored in memory as config[home] + /user1,
but as a concatenated string (/home/test/user1), composed of both
those strings. The reference to original composing strings is lost at
the moment the expression itself is evaluated to be inserted into the
dict.
There's no compiler / interpreter that would do this any other way. At
least not that I know of.

So best suggestion would be to simply do an object that would parse
strings before returning them. In the string itself, you can have
special blocks that tell your parser that they are references to other
objects. You can take good old DOS syntax for that: %variable% or
something more elaborate if % is used in your strings too much.

Anyway, your code would then look like (one possible way):
config = {home : /home/test}
config[user1] = %config[home]% + /user1

or

config = {home : /home/test, user1 : %config[\home\]%/user1}

The parser would then just match %(something)% and replace it with
actual value found in referenced variable. Eval() can help you there.
Maybe there's already something in Python's libraries that matches
your need.

But you sure better not expect this to be included in language syntax.
It's a pretty special case.

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


Re: Fast Dictionary Access

2009-06-27 Thread Duncan Booth
Thomas Lehmann iris-und-thomas-lehm...@t-online.de wrote:

 Hi!
 
 In C++, programming STL you will use the insert method which always
 provides a position and a flag which indicates whether the position
 results from a new insertion or an exisiting element. Idea is to have
 one search only.
 
code
 if  data.has_key(key):
value = data[key]
/code
 
 But this does mean (does it?) that the dictionary is searched two
 times! If so, can somebody show me how to do this in one step?

That code actually does 3 dictionary lookups and creates a temporary 
object: the first lookup is to find the 'has_key' method, then it has to 
bind the method to data which involves creating a 'built-in method' object 
and then it calls it. Only then do you get the two lookups you expected.

Replacing your code with:

   if key in data: value = data[key]

reduces the overhead to two dictionary lookups, no temporary objects or 
function calls.

The suggested alternative:

   value = data.get(key, None) 

also has two dictionary lookups: one to find the 'get' method and one to 
find the key, but as in the first case it also has the overhead of binding 
the method and then calling it.

In other words the get method is often the clearest (and therefore best) 
way to write the code, but if performance matters do a check using the 'in' 
operator (or if you know the key lookup will fail only very rarely consider 
using try..except).

In all of the above I'm assuming the code is actually inside a function 
accessing local variables otherwise accessing variables might involve yet 
more dictionary lookups.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Angus Rodgers
On Sat, 27 Jun 2009 12:13:57 +0100, I wrote:

Hmm ... the \r\n sequence at the end of a Win/DOS file seems to be
treated as a single character.

For instance, if test001A.txt is this file:

abc xyz
Bd ef

gH ij

and test001E.py is this:

f = open('test001A.txt', 'r')
for line in f:
   print repr(line)

then the output from python test001E.py  temp.txt is this:

'abc xyz\n'
'Bd ef\n'
'\n'
'gH ij\n'

and indeed the output from print repr(f.read()) is this:

'abc xyz\nBd ef\n\ngH ij\n'

How do you actually get to see the raw bytes of a file in Windows?

OK, this seems to work:

f = open('test001A.txt', 'rb')   # Binary mode
print repr(f.read())

Output:

'abc xyz\r\nBd ef\r\n\r\ngH ij\r\n'

Indeed, when a Windows file is opened for reading in binary mode, 
the length of an empty line is returned as 2.  This is starting
to make some sense to me now.

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


Re: to use unicode strings only

2009-06-27 Thread MRAB

Gaudha wrote:

Hey gentlemen,

I wanna make all the strings in my code unicode strings. How to do it
without giving unicode switch 'u' before every string?


Use Python 3.1 instead.
--
http://mail.python.org/mailman/listinfo/python-list


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Peter Otten
Angus Rodgers wrote:

 On Sat, 27 Jun 2009 13:02:47 +0200, Peter Otten
 __pete...@web.de wrote:
 
Angus Rodgers wrote:

 On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically:

Will your program handle empty lines of input correctly?
 
 Strangely enough, it seems to do so, but why?

Because there aren't any. When you read lines from a file there will
always be at least the newline character. Otherwise it would indeed fail:

 for line in peter\npaul\n\nmary.splitlines():
... print line[0].upper() + line[1:]
...
Peter
Paul
Traceback (most recent call last):
  File stdin, line 2, in module
IndexError: string index out of range
 
 Hmm ... the \r\n sequence at the end of a Win/DOS 

line

 seems to be treated as a single character.

Yes, but \n[1:] will return an empty string rather than fail.


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


Re: Python Imaging Library download link broken?

2009-06-27 Thread olivergeorge
Ditto.  Anyone know what's happening with pythonware?  (and why PIL is
such a pain to install for that matter.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: to use unicode strings only

2009-06-27 Thread Peter Otten
MRAB wrote:

 Gaudha wrote:

 I wanna make all the strings in my code unicode strings. How to do it
 without giving unicode switch 'u' before every string?
 
 Use Python 3.1 instead.

or use

from __future__ import unicode_literals 

in Python 2.6.


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


Re: Beginning with Python; the right choice?

2009-06-27 Thread Thomas Lehmann
 read and have started to go through them.  I was wondering, as someone
 with virtually no programming experience (I am a photographer by
 trade), is Python the right language for me to try and learn?

Well, I'm a 100% C++ programmer but I like programming python for
prototyping and tools.

The answer on your question depends on your requirements. Some are
saying
that using Java and Swing are the best way to write applications.
But nothing is for free except the most languages you can download and
install. When you have no idea about software development you should
have a look there first. Do you want some little scripting only to get
some jobs easier done - well - you're right to use python.

However - you should be aware of: When you have learned python a while
and
when you will be forced to programm C++, Java or C# you have to start
again!
Check your requirements...


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


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Angus Rodgers
On Sat, 27 Jun 2009 13:49:57 +0200, Peter Otten 
__pete...@web.de wrote:

Angus Rodgers wrote:

 On Sat, 27 Jun 2009 13:02:47 +0200, Peter Otten
 __pete...@web.de wrote:
 
Angus Rodgers wrote:

 On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically:

Will your program handle empty lines of input correctly?
 
 Strangely enough, it seems to do so, but why?

Because there aren't any. When you read lines from a file there will
always be at least the newline character. Otherwise it would indeed fail:

 for line in peter\npaul\n\nmary.splitlines():
... print line[0].upper() + line[1:]
...
Peter
Paul
Traceback (most recent call last):
  File stdin, line 2, in module
IndexError: string index out of range
 
 Hmm ... the \r\n sequence at the end of a Win/DOS 

line

 seems to be treated as a single character.

Yes, but \n[1:] will return an empty string rather than fail.

Yes, I understood that, and it's logical, but what was worrying me
was how to understand the cross-platform behaviour of Python with
regard to the different representation of text files in Windows
and Unix-like OSs. (I remember getting all in a tizzy about this
the last time I tried to do any programming.  That was in C++,
about eight years ago.  Since then, I've only written a couple of
short BASIC programs for numerical analysis on a TI-84+ calculator,
and I feel as if I don't understand ANYTHING any more, but I expect
it'll come back to me.  Sorry about my recent flurry of confused
posts!  If I have any silly questions of my own, I'll post then to
the Tutor list, but in this instance, I imagined I knew what I was
talking about, and didn't expect to get into difficulties ...)  8-P

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


Animate 3D Surface

2009-06-27 Thread Philip Gröger
Hi,
is there a way to animate a 3D surface in python using matplotlib 0.98 /
mayavi 3 (i have the python(xy) suite for windows) or vpython?

In *vpython* I tried to adjust the included faces_heightfield.py demo. But
didnt find a way to delete the old surface. I just add more...

In *matplotlib* I heard that the 3d features are discontinued in 0.91 (or
something like that)

And in *mayavi* I played around with surf() but with the
surf(fkt(z0,0)).mlab_source.set command the picture won't update + show (the
demo file in the documentation didnt work as well).

I know there are vpython and mayavi mailing lists, but I didn't get an
answer from them.
I just hope someone of you can give me some construct which will work.
Maybe I am just using the wrong methods.

thanks alot!!

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


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Peter Otten
Angus Rodgers wrote:

 Yes, I understood that, and it's logical, but what was worrying me
 was how to understand the cross-platform behaviour of Python with
 regard to the different representation of text files in Windows
 and Unix-like OSs. (I remember getting all in a tizzy about this

If you are concerned about line endings open the file in universal newline 
mode:

f = open(filename, rU)


In addition to the standard fopen values mode may be 'U' or 'rU'. Python is 
usually built with universal newline support; supplying 'U' opens the file 
as a text file, but lines may be terminated by any of the following: the 
Unix end-of-line convention '\n', the Macintosh convention '\r', or the 
Windows convention '\r\n'. All of these external representations are seen as 
'\n' by the Python program. If Python is built without universal newline 
support a mode with 'U' is the same as normal text mode. Note that file 
objects so opened also have an attribute called newlines which has a value 
of None (if no newlines have yet been seen), '\n', '\r', '\r\n', or a tuple 
containing all the newline types seen.


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


Re: postgreSQL python bindings - which one?

2009-06-27 Thread Albert Hopkins
On Fri, 2009-06-26 at 21:10 -0700, Horace Blegg wrote:
 Hi, I'm having a hard time deciding which set of PGSQL python bindings
 to go with. I don't know much about SQL to begin with, so the collage
 of packages of somewhat daunting. I'm starting a pet project in order
 to teach my self more, but I want to avoid getting off on the wrong
 foot and picking a package that is not going to be actively updated in
 the future.
 
 There seem to be several implementations
 * http://pypi.python.org/pypi/python-pgsql/   - last update in 08.
 * http://www.pygresql.org/   - version 4.0 was released beginning of
 this year, update before that was sometime in 06
 ( http://www.pygresql.org/changelog.html )
 * http://python.projects.postgresql.org/   - first release was this
 month?
 
 The last one of those three looks to be the most promising, but I just
 can't tell for sure. Your input is appreciated :)
 

psycopg2: http://initd.org/pub/software/psycopg/

Last release was in May.

-a




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


csv blank fields

2009-06-27 Thread Mag Gam
I am using the csv package to parse a compressed .csv.gz file. So far
its working perfectly fine but it fails when I have a missing value in
on of the fields.

For example, I have this

Abc,def,,jkl

Is it possible to fill the missing column with a null?

I want,
Abc,def,NULL,jkl

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


Re: Good books in computer science?

2009-06-27 Thread Paul Rubin
Albert van der Horst alb...@spenarnc.xs4all.nl writes:
 Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson,
 Ronald L. Rivest, and Clifford Stein.
 
 Thanks. I lost that title a while ago, must buy.

Wait a few months, a third edition is in the works.

 Also Numerical Recipe's in FORTRAN/Pascal/C
 (Have they done Python yet?)

They haven't done Python AFAIK.  I liked the C version but the
licensing of the software is pretty evil and so I'm a bit turned off
to the series these days.  I think the hardcore numerics crowd never
liked the book anyway.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv blank fields

2009-06-27 Thread MRAB

Mag Gam wrote:

I am using the csv package to parse a compressed .csv.gz file. So far
its working perfectly fine but it fails when I have a missing value in
on of the fields.

For example, I have this

Abc,def,,jkl

Is it possible to fill the missing column with a null?

I want,
Abc,def,NULL,jkl


What do you mean by fails? I get an empty string, which is what I'd
expect.
--
http://mail.python.org/mailman/listinfo/python-list


Re: csv blank fields

2009-06-27 Thread Mag Gam
well, I am actually loading the row into a fixed width array

reader=csv.reader(fs)
for s,row in enumerate(reader):
  
t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype)
  d[s]=t


If there is a missing field, I get a problem in one of my rows








On Sat, Jun 27, 2009 at 9:04 AM, MRABpyt...@mrabarnett.plus.com wrote:
 Mag Gam wrote:

 I am using the csv package to parse a compressed .csv.gz file. So far
 its working perfectly fine but it fails when I have a missing value in
 on of the fields.

 For example, I have this

 Abc,def,,jkl

 Is it possible to fill the missing column with a null?

 I want,
 Abc,def,NULL,jkl

 What do you mean by fails? I get an empty string, which is what I'd
 expect.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: to use unicode strings only

2009-06-27 Thread Benjamin Peterson
Gaudha sanal.vikram at gmail.com writes:

 
 Hey gentlemen,
 
 I wanna make all the strings in my code unicode strings. How to do it
 without giving unicode switch 'u' before every string?

Or the -U flag, but that's probably a bad idea.


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


Re: csv blank fields

2009-06-27 Thread Peter Otten
Mag Gam wrote:

 well, I am actually loading the row into a fixed width array
 
 reader=csv.reader(fs)
 for s,row in enumerate(reader):
   
t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype)
   d[s]=t
 
 
 If there is a missing field, I get a problem in one of my rows

Please be specific. Describe what you want and what you get. 

If you give code make it self-contained so that others can run it without 
having to guess the values of the variables you introduce.

If an exception occurs cut and paste the traceback into your post, too.

Peter

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


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread D'Arcy J.M. Cain
On Sat, 27 Jun 2009 11:54:43 +0100
Angus Rodgers twir...@bigfoot.com wrote:
 On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically:
 f = open('test', 'r')
 for line in f:
 print line[0].upper()+line[1:],
 
 Will your program handle empty lines of input correctly?
 
 Strangely enough, it seems to do so, but why?

The clue is the comma at the end of the print statement.  It is there
because no lines are empty.  They have at least a newline.

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginning with Python; the right choice?

2009-06-27 Thread 疯图灵
On 6月27日, 上午10时22分, sato.ph...@gmail.com sato.ph...@gmail.com
wrote:
 Hi,

 As you can imagine, I am new, both to this group and to Python.  I
 have read various posts on the best book to buy or online tutorial to
 read and have started to go through them.  I was wondering, as someone
 with virtually no programming experience (I am a photographer by
 trade), is Python the right language for me to try and learn?

 I do vaguely remember learning what I think was BASIC on some old
 Apple's back in elementary school (circa 1992).  Would something like
 that (the name at least makes it SOUND easier) be more feasible?

 If I do choose to learn Python, are there any tutorials for the
 absolute beginner.  I do not mean beginner to Python, but rather,
 beginner to programming.  Someone who hasn't a clue what object
 oriented whatcha-ma-whoozit means.  I ask again because I understand
 that content is always evolving and there might be new tutorials out
 there.

 Thanks!

 -Daniel Sato

Oh, i think python is the best programing language for you !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file transfer in python

2009-06-27 Thread vasudevram
On Jun 26, 5:07 pm, Francesco Bochicchio bieff...@gmail.com wrote:
 On 26 Giu, 13:38, jayesh bhardwaj bhardwajjay...@gmail.com wrote:

  i am trying to find something useful in python to transfer html files
  from one terminal to other. Can this be done with some module or shall
  i start coding my own module using low level socket interface. If u
  know about some books on this topic or any online help then plz help.

 In the standard library there is ftplib, which allows your program to
 act as a FTP client. Of course
 the receiver end should have an FTP server installing and running. I
 don't tink it can handle SFTP protocol, so
 if you are concerned with security you should opt for someting else,
 or protect your connection somehow (e.g. SSH tunneling).

 Or, if you have ssh (client and server) installed, you could simply
 spawn a subprocess ( see the subprocess module for that ) which
 execute one or more 'scp' commands.

 Ciao
 
 FB

There are many ways to do it; each may have it's own pros and cons.

The low level sockets approach is feasible, as you said, and not too
difficult, either. Read from each file and write the data to a socket
from one end; read the data from the other end, and write it to a
file.

For the FTP approach, as Francesco said, the Python standard library
has ftplib, which can help you with the client side, i.e. the sending
side. If you don't have an FTP server on the receiving side, you could
try using pyftpdlib to implement your own FTP server in Python:

  http://code.google.com/p/pyftpdlib/

Quoting from that URL:

 Python FTP server library provides a high-level portable interface
to easily write asynchronous FTP servers with Python.
pyftpdlib is currently the most complete RFC-959 FTP server
implementation available for Python programming language.
It is used in projects like Google Chromium and Bazaar and included in
Linux Fedora and FreeBSD package repositories. 

Of course all that could be too much overhead; also, you would need
permission to install your FTP daemon program written using pyftpdlib,
on the receiving computer.

As Francesco said, you could use the subprocess module and spawn a
process that runs instances of scp.

Another fairly easy way could be to write an XML-RPC client and
server. The client, on the sending side, can send the data of each
file to the server via an XML-RPC method call (in chunks, if needed,
if the file is large); the server, on the receiving side, can read
that data, and write it to a file on the file system. The client could
send the file name of each file first, via a separate method call,
before the data of each file, so the server would know under what name
to save the file on its file system.

By using the Binary data type supported by XML-RPC, you could send any
type of file, whether text or binary, and irrespective of the
operating system of the sender or receiver, whether Windows or UNIX.

I've done this in some code of mine, so I know it works.

You might have to take care about newline conversions (LF to CR + LF
or vice versa), though, if one side is UNIX and the other is Windows,
and do that conversion only for files that are text files. (For binary
files, you actually have to make sure that you DO NOT do that
conversion, or you will corrupt the data.)
And do a similar conversion if one side is Mac and the other is
Windows or Linux. On Mac, line endings are marked with a CR.

LF = Line Feed (ASCII 10)
CR = Carriage Return (ASCII 13)

The subprocess + scp method may be slower than the XML-RPC method,
since it will have to spawn a new scp process for each file sent,
unless you use wildcards and transfer all or many files in one call.

One the other hand, the XML-RPC method may be slower, since it
transfers the data over HTTP (which rides on TCP which rides on IP),
whereas scp probably uses a lower level protocol such as TCP packets
directly, or something similar to what FTP uses - those protocols may
have less overhead per unit of data sent.

Which approach is best depends on your needs, whether it is a one-off
job, or whether you need to repeat the job regularly, etc., how much
time you have to write the code, etc.

HTH,
Vasudev
---
Vasudev Ram
Biz: www.dancingbison.com
xtopdf: fast and easy PDF creation from other file formats:
www.dancingbison.com/products.html
Blog (on software innovation): jugad2.blogspot.com


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


Re: csv blank fields

2009-06-27 Thread jkv
Mag Gam wrote:

  well, I am actually loading the row into a fixed width array
 
  reader=csv.reader(fs)
  for s,row in enumerate(reader):

  t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype)
d[s]=t
 
 
  If there is a missing field, I get a problem in one of my rows

   

I had a similar problem, my problem was that in my source data (csv
file) sometimes the last cell was left out, so i ended up doing a try to
check if the row existed, if not i appended to the row.

Something like:

try:
row[11]
except IndexError:
row.append()

If you want to insert a value into empty cells you can do something like
this:

if row[10] == ''
row[10] = 'NULL'



-- 
Regards,
jkv
http://unixcluster.dk/public.key

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


Re: to use unicode strings only

2009-06-27 Thread Gaudha
On Jun 27, 4:54 pm, Peter Otten __pete...@web.de wrote:
 MRAB wrote:
  Gaudha wrote:
  I wanna make all the strings in my code unicode strings. How to do it
  without giving unicode switch 'u' before every string?

  Use Python 3.1 instead.

 or use

 from __future__ import unicode_literals

 in Python 2.6.

I know about Python 3.1 have the capability. But, unfortunately the
community for which I'm working do not prefer Python 3.*...

And Peter, I tried importing the __future__ module. It's also not
working...
-- 
http://mail.python.org/mailman/listinfo/python-list


Buffer pair for lexical analysis of raw binary data

2009-06-27 Thread Angus Rodgers

Partly as an educational exercise, and partly for its practical
benefit, I'm trying to pick up a programming project from where
I left off in 2001.  It implemented in slightly generalised form
the buffer pair scheme for lexical analysis described on pp.
88--92 of Aho et al., /Compilers: Principles, Techniques and 
Tools/ (1986). (I'm afraid I don't have a page reference for the
2007 second edition.  Presumably it's also in Knuth somewhere.)

Documentation for one of the C++ header files describes it thus
(but I never quite got the hang of C++, so some of the language-
specific details may be very poorly conceived):

An ipfile object incorporates a handle to a file, opened in 
read-only mode, and a buffer containing (by default) raw binary
data from that file. The constructor also has an option to open
a file in text mode.

The buffer may, optionally, consist of several segments, linked
to one another in cyclic sequence. The number of segments is a
constant class member, nblocks (1 = nblocks = 32,767). A second
constant class member, block (1 = block = 32,767) gives the size
of each of the segments in bytes.

The purpose of creating a buffer in cyclically linked segments
is to allow reference to the history of reading the file, even
though it is being read sequentially. The bare class ipfile 
does not do this itself, but is designed so that classes derived
from it may incorporate one or more pointers to parts of the buffer
that have already been read (assuming these parts have not yet been
overwritten).

If there were only one segment, the length of available history
would periodically be reduced to zero, when the buffer is re-
freshed. In general, the available history occupies at least 
a fraction (nblocks - 1)/nblocks of a full buffer.

Aho et al. describe the scheme thus (p. 90):

Two pointers to the input buffer are maintained.  The string
of characters between the two pointers is the current lexeme.
Initially, both pointers point to the first character of the
next lexeme to be found.  One, called the forward pointer, scans
ahead until a match for a pattern is found.  Once the next lexeme
is determined, the forward pointer is set to the character at
its right end.  After the lexeme is processed, both pointers
are set to the character immediately past the lexeme.

[There follows a description of the use of sentinels to test
efficiently for pointers moving past the end of input to date.]

I seem to remember (but my memory is still very hazy) that there
was some annoying difficulty in coding the raw binary input file
reading operation in C++ in an implementation-independent way;
and I'm reluctant to go back and perhaps get bogged down again
in whatever way I got bogged down before; so I would prefer to
use Python for the whole thing, if possible (either using some
existing library, or else by recoding it all myself in Python).

Does some Python library already provide some functionality like
this?  (It's enough to do it with nblocks = 2, as in Aho et al.)

If not, is this a reasonable thing to try to program in Python?
(At the same time as learning the language, and partly as a
fairly demanding exercise intended to help me to learn it.)

Or should I just get my hands dirty with some C++ compiler or
other, and get my original code working on my present machine
(possibly in ANSI C instead of C++), and call it from Python?

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


Re: csv blank fields

2009-06-27 Thread Mag Gam
Peter:

Sorry if I wasn't clear before.

While reading my csv file, notice I am putting the content in an array.

If lets say, row[5] has nothing in it, python gives an exception.
Instead of the exception, I would like to assign 'NULL' to row[5].

Does that help?


On Sat, Jun 27, 2009 at 10:03 AM, Peter Otten__pete...@web.de wrote:
 Mag Gam wrote:

 well, I am actually loading the row into a fixed width array

 reader=csv.reader(fs)
 for s,row in enumerate(reader):

 t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype)
   d[s]=t


 If there is a missing field, I get a problem in one of my rows

 Please be specific. Describe what you want and what you get.

 If you give code make it self-contained so that others can run it without
 having to guess the values of the variables you introduce.

 If an exception occurs cut and paste the traceback into your post, too.

 Peter

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

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


Re: to use unicode strings only

2009-06-27 Thread Benjamin Peterson
Gaudha sanal.vikram at gmail.com writes:

 And Peter, I tried importing the __future__ module. It's also not
 working...

How so?



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


Re: Fast Dictionary Access

2009-06-27 Thread Rachel P
[Thomas Lehmann]
 In C++, programming STL you will use the insert method which always
 provides a position and a flag which indicates whether the position
 results from a new insertion or an exisiting element. Idea is to have
 one search only.

 code
 if  data.has_key(key):
    value = data[key]
 /code

 But this does mean (does it?) that the dictionary is searched two
 times! If so, can somebody show me how to do this in one step?

Several thoughts for you:

* Python isn't C++

* Dict lookups in Python are ubiquitous

* Trying to avoid them is often an exercise in futility

* Because of cache effects, double lookups are *very* cheap

* If this particular fragment is critical, consider using get():

data_get = data.get
...
# inner-loop code
value = data_get(key) # assigns None for missing values

* Another alternative is a try-block:

try:   # setup is cheap
 value = data[key]
except KeyError:   # matching is expensive
 ...

* Or you can use collections.defaultdict() or a dict subclass that
defines __missing__().

* In general though, think of dicts as one of Python's most optimized
structures, one that should be embraced rather than avoided.

* Tim Peter's take on the subject from year's ago (paraphrased):
Anything written using Python dictionaries is a gazillion times
faster than C.



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


Re: Beginning with Python; the right choice?

2009-06-27 Thread Charles Yeomans


On Jun 26, 2009, at 10:22 PM, sato.ph...@gmail.com wrote:


Hi,

As you can imagine, I am new, both to this group and to Python.  I
have read various posts on the best book to buy or online tutorial to
read and have started to go through them.  I was wondering, as someone
with virtually no programming experience (I am a photographer by
trade), is Python the right language for me to try and learn?

I do vaguely remember learning what I think was BASIC on some old
Apple's back in elementary school (circa 1992).  Would something like
that (the name at least makes it SOUND easier) be more feasible?

If I do choose to learn Python, are there any tutorials for the
absolute beginner.  I do not mean beginner to Python, but rather,
beginner to programming.  Someone who hasn't a clue what object
oriented whatcha-ma-whoozit means.  I ask again because I understand
that content is always evolving and there might be new tutorials out
there.



As an alternative to Python, I'd suggest REALbasic.  Its main  
disadvantage is that it is not free. But you get a language, editor,  
and two application frameworks in one package.


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


What does Guido want in a GUI toolkit for Python?

2009-06-27 Thread laplacia...@gmail.com
I just read a blog post of Guido's
http://neopythonic.blogspot.com/2009/06/ironpython-in-action-and-decline-of.html
and notice that he doesn't comment on what he wants in a GUI toolkit
for Python.

I sorta' wish he'd just come out and say, This is what I think would
be suitable for a GUI toolkit for Python:  That way, someone
could then just come along and implement it. (Or maybe he's said this
and I missed it?)

So, what *does* Guido want in a GUI toolkit for Python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv blank fields

2009-06-27 Thread MRAB

Mag Gam wrote:

Peter:

Sorry if I wasn't clear before.

While reading my csv file, notice I am putting the content in an array.

If lets say, row[5] has nothing in it, python gives an exception.
Instead of the exception, I would like to assign 'NULL' to row[5].

Does that help?


You still didn't say what the exception was!

Anyway, if you expect 'row' to contain 11 items, then you could append
the missing ones:

for s, row in enumerate(reader):
# Fill any empty slots with NULL.
row = [r or NULL for r in row]
# Append missing (empty) slots on the end.
row += [NULL] * (11 - len(row))
d[s] = np.array([tuple(row)], dtype=mtype)



On Sat, Jun 27, 2009 at 10:03 AM, Peter Otten__pete...@web.de wrote:

Mag Gam wrote:


well, I am actually loading the row into a fixed width array

reader=csv.reader(fs)
for s,row in enumerate(reader):


t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype)

  d[s]=t


If there is a missing field, I get a problem in one of my rows

Please be specific. Describe what you want and what you get.

If you give code make it self-contained so that others can run it without
having to guess the values of the variables you introduce.

If an exception occurs cut and paste the traceback into your post, too.


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


encoding problem

2009-06-27 Thread netpork
Hello,

I have ssl socket with server and client, on my development machine
everything works pretty well.
Database which I have to use is mssql on ms server 2003, so I decided
to install the same python config there and run my python server
script.

Now here is the problem, server is returning strange characters
although default encoding is the same on both development and server
machines.


Any hints?

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


Re: What does Guido want in a GUI toolkit for Python?

2009-06-27 Thread Casey Hawthorne
So, what *does* Guido want in a GUI toolkit for Python?

I saw a talk by a school teacher on pyFLTK: GUI programming made easy.

On another note: I#: Groovy makes it easy to tie into the Java Swing
GUI, so if Python could do that, with the added complication being the
user would need a JVM.

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


Re: csv blank fields

2009-06-27 Thread Peter Otten
Mag Gam wrote:

Please don't top-post.

 Sorry if I wasn't clear before.
 
 While reading my csv file, notice I am putting the content in an array.

That's already in the code you posted. What's missing is the value of 
mtypes. I really meant it when I asked you to provide a self-contained 
example, i. e. one that I can run on my computer.
 
 If lets say, row[5] has nothing in it

No, it containes an empty string as MRAB already inferred.

 , python gives an exception.

What exception? What traceback? Please take the time to read
http://catb.org/esr/faqs/smart-questions.html

 Instead of the exception, I would like to assign 'NULL' to row[5].

The string NULL? That would be

# untested
for s, row in enumerate(reader):
row = tuple(c if c else NULL for c in row)
t = np.array([row], dtype=mtype)
...

I'm not a numpy expert, but creating a lot of temporary arrays does look 
wasteful...

 Does that help?

Sorry, no. I (or someone else who doesn't bother to guess) could have come 
up with a better answer in a shorter time if you had actually answered my 
questions.

Peter

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


Re: postgreSQL python bindings - which one?

2009-06-27 Thread Philip Semanchuk


On Jun 27, 2009, at 8:27 AM, Albert Hopkins wrote:


On Fri, 2009-06-26 at 21:10 -0700, Horace Blegg wrote:
Hi, I'm having a hard time deciding which set of PGSQL python  
bindings

to go with. I don't know much about SQL to begin with, so the collage
of packages of somewhat daunting. I'm starting a pet project in order
to teach my self more, but I want to avoid getting off on the wrong
foot and picking a package that is not going to be actively updated  
in

the future.

There seem to be several implementations
* http://pypi.python.org/pypi/python-pgsql/   - last update in 08.
* http://www.pygresql.org/   - version 4.0 was released beginning of
this year, update before that was sometime in 06
( http://www.pygresql.org/changelog.html )
* http://python.projects.postgresql.org/   - first release was this
month?

The last one of those three looks to be the most promising, but I  
just

can't tell for sure. Your input is appreciated :)



psycopg2: http://initd.org/pub/software/psycopg/



+1

Although I'm not using it anymore, I had good success with psycopg2  
and strongly recommend it.





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


Looking for developer to help me

2009-06-27 Thread Daniel Gerzo

Hello guys,

I have started to work on a new python library (called PySubLib), which 
is intended to allow applications to work with subtitles (the most 
common formats) easily.


As I am pretty new to Python programming, I would appreciate if somebody 
with some spare time and Python foo could help/mentor me with this effort.


In case there's somebody with Python skills willing to guide me, please 
let me know. I have already written some code, and if you're interested 
you may find it at http://bitbucket.org/danger/pysublib/src/.


Thanks,

--
S pozdravom / Best regards
  Daniel Gerzo
--
http://mail.python.org/mailman/listinfo/python-list


Re: Beginning with Python; the right choice?

2009-06-27 Thread Kee Nethery
I'll give you the same advice I used to give to people when they  
wanted to decide whether to get a Mac or a PC, go with what your local  
group of friends is using.


In general, if you have a local friend who can come over weekly (or  
you can visit weekly) and have them help you with the stumbling  
blocks, that is way more important than whether one language is better  
than another. If there is someone at work who can stop by your desk on  
a daily basis, that is even better.


All computer languages have a learning curve and a whole set of quirks  
that are things that everyone knows (-: unless you are new to the  
language). Eventually you will grok the language and know all the  
weird gotchas that make no sense to a new person and from that point  
forward the documentation will make sense and you'll be able to go  
very far without having to ask others for help. Until that time,  
something as simple as the use of a colon instead of a semi-colon can  
halt your project for weeks. Having someone who can look at your code  
and say there's your problem ... is way more important than the  
language itself.


With all that background, here are my personal choices.

I started a long time ago with FORTRAN, BASIC, assembly language for  
single chip micros, and ultimately Hypercard and AppleScript (on the  
Mac), and finally the language used by the Arduino micros.


I've built a ton of code using Hypercard all the way from web server  
CGIs to standalone user applications, to unattended code that runs  
forever doing a task when needed. Hypercard is no longer a viable  
coding platform so I had to find alternatives.


For GUI stuff on a Mac or PC, I use RunRev.

For all the Hypercard stuff I've built in the past I migrated to  
Runtime Revolution (RunRev) which can be described as a multi-platform  
Hypercard on steroids. The workflow is similar to Cocoa on the Mac.  
You first create the user interface by dragging buttons and fields and  
controllers and such onto windows and then when you like the way the  
user interface works, you write code to have the various interface  
elements do what they are supposed to when a user interacts with them.  
For GUI type applications, things that run on a user's computer,  
sometimes referred to as a heavy client, I find Runtime Revolution to  
be extremely easy and I'm very productive in that environment. I have  
web CGIs built in RunRev and it works quite well but ... it is a  
single threaded system so a web site with tons simultaneous hits will  
have scaling up problems. That said, high traffic web sites do use  
RunRev but I wanted something that was not single threaded for web  
stuff.


For web stuff I have used RunRev but am moving towards Python.

I went with Python mostly because a friend of mine who knows me and  
who writes in many languages, thought it was the best fit for the way  
my mind works, and he volunteered to help me when I get stuck on  
stuff. He helped me find the Komodo IDE and got me set up to where I  
had a very simple hello world CGI that I could expand upon.


Python has a proven ability to scale up and support more users than I  
will ever need to support. It is what Google and many others run on.  
The philosophy is for there to be only one way to perform a function.  
A competent Python programmer can follow the code written by another  
because there is only one dialect of Python (unlike Perl). These are  
things I like about Python.


I'm using Python 2.6.2 with the Komodo IDE and I'm limiting myself to  
the packages that come with the standard install of Python. So I'm not  
using TurboGears or Django or WSGI or any of those, I just use cgi and  
urllib (and urllib2). Until I know enough to really understand what my  
code is doing, and more importantly what those packages are doing or  
not, I'm not going to use add-on packages. So far I have not needed  
them.


All that said, right now I am extremely inefficient in Python as  
compared to RunRev. I can build a fairly complex CGI in RunRev in a  
day, with Python, it takes me a month. Much of that has to do with  
RunRev being a variation of Hypercard (both use a HyperTalk style  
language) and I'm way past the 10,000 hour usage level on the  
HyperTalk language. I'm barely at 100 hours with Python so right now  
everything is a struggle. But I like Python and plan to stick with it.


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


Re: Good books in computer science?

2009-06-27 Thread Terry Reedy

A

Steven D'Aprano  st...@removethis.cybersource.com.au wrote:
SNIP

On 2009-06-14 14:04:02 +0100, Steven D'Aprano
st...@removethis.cybersource.com.au said:
I think I'm paraphrasing Richard Feynman here, but the
only way to truly understand something is to do it.

An amazingly inappropriate quote for a *theoretical* physicist to have said.


Who got his start *doing* calculations for the Manhattan (atomic bomb) 
project, and checking them against real results.  Like it or not, they 
'did' it is a big way.


He got his Nobel Prize for finding out how to *do* calculations that 
matched quantum mechanics experiments. (or something like that).


His early bobby was picking locks and cracking safes -- mostly as a way 
to understand them.  It was not enough for him to just read about them.


tjr

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


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Terry Reedy

Peter Otten wrote:


Will your program handle empty lines of input correctly?

Strangely enough, it seems to do so, but why?


Because there aren't any. When you read lines from a file there will always 
be at least the newline character. Otherwise it would indeed fail:


Except possibly for the last line.

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


Re: looking for a book on python

2009-06-27 Thread Kee Nethery
I'm a newbie and I need examples and I find that Python for Dummies is  
my best paper source for examples.


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


Re: encoding problem

2009-06-27 Thread Piet van Oostrum
 netpork todorovic.de...@gmail.com (n) wrote:

n Hello,
n I have ssl socket with server and client, on my development machine
n everything works pretty well.
n Database which I have to use is mssql on ms server 2003, so I decided
n to install the same python config there and run my python server
n script.

n Now here is the problem, server is returning strange characters
n although default encoding is the same on both development and server
n machines.


n Any hints?

Yes, read http://catb.org/esr/faqs/smart-questions.html
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does Guido want in a GUI toolkit for Python?

2009-06-27 Thread Terry Reedy

laplacia...@gmail.com wrote:

I just read a blog post of Guido's
http://neopythonic.blogspot.com/2009/06/ironpython-in-action-and-decline-of.html
and notice that he doesn't comment on what he wants in a GUI toolkit
for Python.

I sorta' wish he'd just come out and say, This is what I think would
be suitable for a GUI toolkit for Python:  That way, someone
could then just come along and implement it. (Or maybe he's said this
and I missed it?)

So, what *does* Guido want in a GUI toolkit for Python?


What he did say is But it hasn't really gotten any less complex to 
create the simplest of simple UIs. And that's a shame. When is Microsoft 
going to learn the real lesson about simplicity of HTML?


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


Re: looking for a book on python

2009-06-27 Thread Aahz
In article mailman.2224.1246124498.8015.python-l...@python.org,
Kee Nethery  k...@kagi.com wrote:

I'm a newbie and I need examples and I find that Python for Dummies is  
my best paper source for examples.

Thank you!  That's one thing we worked hard on.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Piet van Oostrum
 Terry Reedy tjre...@udel.edu (TR) wrote:

TR Peter Otten wrote:
 Will your program handle empty lines of input correctly?
 Strangely enough, it seems to do so, but why?
 
 Because there aren't any. When you read lines from a file there will
 always be at least the newline character. Otherwise it would indeed fail:

TR Except possibly for the last line.

But then that line wouldn't be empty either. 

If there is an empty line not terminated by a newline after the last
newline, then that is called 'end-of-file' :=)
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Peter Otten
Terry Reedy wrote:

 Peter Otten wrote:
 
 Will your program handle empty lines of input correctly?
 Strangely enough, it seems to do so, but why?
 
 Because there aren't any. When you read lines from a file there will
 always be at least the newline character. Otherwise it would indeed fail:
 
 Except possibly for the last line.

It may not end with a newline, but it will still contain at least one 
character.


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


Re: Python simple web development

2009-06-27 Thread Kee Nethery
Until I'm an experience Python coder, I'm sticking with built-in  
packages only. My simple CGI is:



#!/usr/bin/env python

# this simple CGI responds to a GET or a POST
# send anything you want to this and it will parrot it back.

# a line that starts with #2 is the old-style code you should use that  
works
# with versions less than Python 2.6. I'm using 2.6.2 and am trying to  
use

# code that works with Python 3.x and up.

import cgi ## so that I can be a web server CGI
import os ## only purpose is for getting the CGI client values like IP  
and URL


def main():
# create the output variable and then add stuff to it that gets  
returned

cgiResponseData = 'stuff from the client browser connection:\n'

# so that there is something to return, go through the CGI client  
data

#2 for cgiKey in os.environ.keys():
for cgiKey in list(os.environ.keys()):
# for each client data value, add a line to the output
cgiResponseData = cgiResponseData + \
str(cgiKey) + ' = ' + os.environ[cgiKey] + '\n'

# this says give me a list of all the user inputs posted to the cgi
formPostData = cgi.FieldStorage()

cgiResponseData = cgiResponseData + '\n\nstuff from the URL POST  
or GET:\n'


# cycle through those inputs and output them right back
#2 for keyValue in formPostData:
for keyValue in list(formPostData):
cgiResponseData = cgiResponseData + \
str(keyValue) + ' = ' + formPostData[keyValue].value + '\n'

#2 print 'Content-type: text/html'
#2 print
#2 print cgiResponseData
print('Content-type: text/html')
print('')
print(cgiResponseData)

main()


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


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Emile van Sebille

On 6/27/2009 3:39 AM Angus Rodgers said...

On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah
wong_po...@yahoo.ca wrote:


Thank you for your hint.
This is my solution:
f = open('test', 'r')
for line in f:
   print line[0].upper()+line[1:],


Will your program handle empty lines of input correctly?



It will when the final line is changed to:

print line[:1].upper()+line[1:]


Emile

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


Re: Fast Dictionary Access

2009-06-27 Thread Scott David Daniels

Thomas Lehmann wrote:

In C++, programming STL you will use the insert method which always
provides a position and a flag which indicates whether the position
results from a new insertion or an exisiting element. Idea is to have
one search only.

code
if  data.has_key(key):
   value = data[key]
/code

But this does mean (does it?) that the dictionary is searched two
times! If so, can somebody show me how to do this in one step?


To get almost the same result (assuming value is already loaded):

 value = data.get(key, value)

Otherwise, as others have said:

 if key in data:
 value = data[key]

The form:

try:
value = data[key]
except KeyError:
pass

works, but is not terribly efficient unless failures are rare.
And this is a micro-optimization, measure before changing your
program structure away from the clearest code you can write.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library download link broken?

2009-06-27 Thread Scott David Daniels

olivergeorge wrote:

Ditto.  Anyone know what's happening with pythonware?  (and why PIL is
such a pain to install for that matter.)


(1) It is usually there; be patient.
(2) I suggest you demand a refund.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Emile van Sebille

On 6/27/2009 1:25 PM MRAB said...

Emile van Sebille wrote:

On 6/27/2009 3:39 AM Angus Rodgers said...

On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah
wong_po...@yahoo.ca wrote:


Thank you for your hint.
This is my solution:
f = open('test', 'r')
for line in f:
   print line[0].upper()+line[1:],


Will your program handle empty lines of input correctly?



It will when the final line is changed to:

print line[:1].upper()+line[1:]


'line' will _never_ be ''. If a line ends with a newline then that will
be preserved returned as part of the string. This applies to the 'file'
methods 'readline', 'readlines', etc, and the iterator, which returns a
line. 'readline' will return '' only when it has reached the end of the
file.

Sorry -- habit.  I tend to use that technique to avoid IndexErrors as a 
matter of course.


Emile

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


Re: The Python Way for module configuration?

2009-06-27 Thread Aaron Sherman
On Jun 27, 4:38 pm, MRAB pyt...@mrabarnett.plus.com wrote:

  I would appreciate your comments and suggestions.

 There are already modules which provide access to databases.

As you can see the Python Way is to be rude ;-)

Anyway, your answer is that there are some abstraction layers called
ORMs. You can grab one of these and write a back end for it.
However, you might first want to look at SQLLite and see if it already
has what you want (e.g. a light-weight, zero-install database
interface).

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


Re: What does Guido want in a GUI toolkit for Python?

2009-06-27 Thread Martin v. Löwis
 I sorta' wish he'd just come out and say, This is what I think would
 be suitable for a GUI toolkit for Python: 

He is not in the business of designing GUI toolkits, but in the business
of designing programming languages. So he abstains from specifying
(or even recommending) a GUI library.

What he makes clear is the point that Terry cites: no matter what the
GUI toolkit is or what features it has - it should be simple to create
GUIs, as simple as creating HTML.

 So, what *does* Guido want in a GUI toolkit for Python?

His concern really isn't what is in the toolkit, but what isn't.
It must not require lots of lines of code to produce a simple
GUI, it must not require specification of absolute coordinates,
... - you should be able to continue the list yourself.

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


[RELEASED] Python 3.1 final

2009-06-27 Thread Benjamin Peterson
On behalf of the Python development team, I'm thrilled to announce the first
production release of Python 3.1.

Python 3.1 focuses on the stabilization and optimization of the features and
changes that Python 3.0 introduced.  For example, the new I/O system has been
rewritten in C for speed.  File system APIs that use unicode strings now handle
paths with undecodable bytes in them. Other features include an ordered
dictionary implementation, a condensed syntax for nested with statements, and
support for ttk Tile in Tkinter.  For a more extensive list of changes in 3.1,
see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python
distribution.

To download Python 3.1 visit:

 http://www.python.org/download/releases/3.1/

The 3.1 documentation can be found at:

 http://docs.python.org/3.1

Bugs can always be reported to:

 http://bugs.python.org


Enjoy!

--
Benjamin Peterson
Release Manager
benjamin at python.org
(on behalf of the entire python-dev team and 3.1's contributors)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: postgreSQL python bindings - which one?

2009-06-27 Thread Horace Blegg
On Sat, Jun 27, 2009 at 10:23 AM, Philip Semanchuk phi...@semanchuk.comwrote:


 On Jun 27, 2009, at 8:27 AM, Albert Hopkins wrote:

  On Fri, 2009-06-26 at 21:10 -0700, Horace Blegg wrote:

 Hi, I'm having a hard time deciding which set of PGSQL python bindings
 to go with. I don't know much about SQL to begin with, so the collage
 of packages of somewhat daunting. I'm starting a pet project in order
 to teach my self more, but I want to avoid getting off on the wrong
 foot and picking a package that is not going to be actively updated in
 the future.

 There seem to be several implementations
 * http://pypi.python.org/pypi/python-pgsql/   - last update in 08.
 * http://www.pygresql.org/   - version 4.0 was released beginning of
 this year, update before that was sometime in 06
 ( http://www.pygresql.org/changelog.html )
 * http://python.projects.postgresql.org/   - first release was this
 month?

 The last one of those three looks to be the most promising, but I just
 can't tell for sure. Your input is appreciated :)


 psycopg2: http://initd.org/pub/software/pPhilip Semanchuk
 phi...@semanchuk.comsycopg/ http://initd.org/pub/software/psycopg/



 +1

 Although I'm not using it anymore, I had good success with psycopg2 and
 strongly recommend it.





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



Awesome, thank you very much for the link!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good books in computer science?

2009-06-27 Thread Robert Kern

On 2009-06-27 07:58, Paul Rubin wrote:

Albert van der Horstalb...@spenarnc.xs4all.nl  writes:

Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson,
Ronald L. Rivest, and Clifford Stein.

Thanks. I lost that title a while ago, must buy.


Wait a few months, a third edition is in the works.


Also Numerical Recipe's in FORTRAN/Pascal/C
(Have they done Python yet?)


They haven't done Python AFAIK.  I liked the C version but the
licensing of the software is pretty evil and so I'm a bit turned off
to the series these days.  I think the hardcore numerics crowd never
liked the book anyway.


My opinion is that the text itself is a pretty good introduction to the workings 
of a broad variety of numerical algorithms. For any particular area, there are 
probably better books that go into more depth and are closer to the state of the 
art, but I don't think there are any books that cover the wide swath numerical 
algorithms that NR does. In that regard, I treat it like Wikipedia: a good place 
to start, not the best place to stop.


I think the code succeeds reasonably well for teaching the algorithms, but I 
don't think they are well-engineered for production use. There are usually 
better libraries with better licenses.


--
Robert Kern

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

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


tokenize module

2009-06-27 Thread Jim
I'm trying to understand the output of the tokenize.generate_tokens()
generator.  The token types returned seem to be more general than I'd
expect.  For example, when fed the following line of code:

def func_a():

the (abbreviated) returned token tuples are as follows:

(NAME,def, ...,  def func_a():)
(NAME ,   func_a,...,  def func_a():)
(OP,(, ...,  def func_a():)
(OP,), ...,  def func_a():)
(OP,:, ...,  def func_a():)
(NEWLINE,  NEWLINE,   ...,  def func_a():)

It seems to me that the token '(' should be identified as 'LPAR' and
')' as 'RPAR', as found in the dictionary token.tok_name.  What am I
missing here?

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


Re: The Python Way for module configuration?

2009-06-27 Thread kj
In c91011ad-b52c-4fb7-8e2c-1de165636...@d32g2000yqh.googlegroups.com Aaron 
Sherman aaronjsher...@gmail.com writes:

On Jun 27, 4:38=A0pm, MRAB pyt...@mrabarnett.plus.com wrote:

  I would appreciate your comments and suggestions.

 There are already modules which provide access to databases.

As you can see the Python Way is to be rude ;-)

Anyway, your answer is that there are some abstraction layers called
ORMs. You can grab one of these and write a back end for it.
However, you might first want to look at SQLLite and see if it already
has what you want (e.g. a light-weight, zero-install database
interface).


Hi, thanks, but the database aspect of my question is tangential.
What I'm interested in is the general problem of providing
configuration parameters to a module.

TIA!

kynn

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


Re: Good books in computer science?

2009-06-27 Thread Bearophile
Albert van der Horst:
 For programming practice I do the problems of
 http://projecteuler.net/

Time ago I have solved some of them with Python, D and C (some of them
are quite hard for me), I have tried to produce very fast code (like a
D generator for prime numbers that's like 100 times faster of some
'fast' C# prime generators I've seen in that forum).

But then I have stopped because to me they seem a waste of time, they
look too much academic, they don't exercise the right muscles of the
mind. They may be good if you want to become good in performing
numerical number theory, and bad for everyone else.

Seeing how many people like to do those Project Euler puzzles, I
presume my ideas aren't shared by most people.

I am now using some solutions of mine of those problems to spot
performance bugs in a new D compiler (and even in ShedSkin), so they
are somewhat useful again :-)

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a book on python

2009-06-27 Thread Randy Foiles

OdarR wrote:

On 27 juin, 02:48, Randy Foiles ab...@127.0.0.1 wrote:

Hello and thank you for taking your time to read this.
I was interested in learning about python.  In the long ago past I did
learn some programing but I have not used any of it for years.  I do
remember some basics however so the book does not have to be for a total
beginner.  (C, C++, BASIC, Visual BASIC, Pascal and some ADA)
I have been using Linux for a while and overall still don't know much
about it but I can find my way.  I have my system dual boot with windows
vista.
I do realize that everyone is different but I would like to see some
suggestions and maybe reasons why you think it is good.  I have looked
for/searched and found a few different books but as my means are a bit
limited right now I don't really want to buy several just one or maybe
two books.
Oh and if someone knows a place to find some used books of this sort
that would be great (ebay I guess :)
Thanks for your thoughts
Randy theslayers9   gmail


Learning Python
http://oreilly.com/catalog/9780596513986/

new issue soon, covering 2.6 and 3
http://oreilly.com/catalog/9780596158064/?CMP=AFC-ak_bookATT=Learning+Python%2c+Fourth+Edition%2c

the best book I read concerning Py understanding, well written.

I would start with web content, then later would buy the fourth
edition of Learning Python.

enjoy,
Olivier

Thank you.
I was thinking of that book and a few others.  I am not sure at this 
point what the difference is in 2.6 and 3?

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


Re: looking for a book on python

2009-06-27 Thread Randy Foiles

Aahz wrote:

In article s%d1m.1325$9l4@nwrddc01.gnilink.net,
Randy Foiles  ab...@127.0.0.1 wrote:
	I do realize that everyone is different but I would like to see some 
suggestions and maybe reasons why you think it is good.  I have looked 
for/searched and found a few different books but as my means are a bit 
limited right now I don't really want to buy several just one or maybe 
two books.


You could get the book I co-wrote (Python for Dummies), but honestly, I
think you should try using some of the online tutorials first.  The
standard Python tutorial is aimed at people with some programing
experience:

http://docs.python.org/tutorial/index.html


I had not thought about the dummies books for this I will look and see 
if my local BN has it.

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


Re: looking for a book on python

2009-06-27 Thread Randy Foiles

laplacia...@gmail.com wrote:

On Jun 26, 8:48 pm, Randy Foiles ab...@127.0.0.1 wrote:

Hello and thank you for taking your time to read this.
I was interested in learning about python.  In the long ago past I did
learn some programing but I have not used any of it for years.  I do
remember some basics however so the book does not have to be for a total
beginner.  (C, C++, BASIC, Visual BASIC, Pascal and some ADA)
I have been using Linux for a while and overall still don't know much
about it but I can find my way.  I have my system dual boot with windows
vista.
I do realize that everyone is different but I would like to see some
suggestions and maybe reasons why you think it is good.  I have looked
for/searched and found a few different books but as my means are a bit
limited right now I don't really want to buy several just one or maybe
two books.
Oh and if someone knows a place to find some used books of this sort
that would be great (ebay I guess :)
Thanks for your thoughts
Randy theslayers9   gmail


The Oreilly Python in a Nutshell (2006, 2nd ed.) book is very good
and will get you up to speed in short order.


This is one of the books I see around and it does seem that O'Reilly is 
where most people go for them :)

What is it that you like about this one?
--
http://mail.python.org/mailman/listinfo/python-list


Re: encoding problem

2009-06-27 Thread dejan todorović
It was problem with pymssql that not supports unicode, switched to
pyodbc, everything is fine.

Thanks for your swift reply. ;)



On Jun 27, 7:44 pm, Piet van Oostrum p...@cs.uu.nl wrote:
  netpork todorovic.de...@gmail.com (n) wrote:
 n Hello,
 n I have ssl socket with server and client, on my development machine
 n everything works pretty well.
 n Database which I have to use is mssql on ms server 2003, so I decided
 n to install the same python config there and run my python server
 n script.
 n Now here is the problem, server is returning strange characters
 n although default encoding is the same on both development and server
 n machines.
 n Any hints?

 Yes, readhttp://catb.org/esr/faqs/smart-questions.html
 --
 Piet van Oostrum p...@cs.uu.nl
 URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
 Private email: p...@vanoostrum.org

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


Re: The Python Way for module configuration?

2009-06-27 Thread Petr Messner
Hi,

2009/6/28 kj no.em...@please.post:
...
 What I'm interested in is the general problem of providing
 configuration parameters to a module.


Some database/ORM libraries are configured via simple strings in the
form dialect://user:passw...@host/dbname[?key=value..], for example
mysql://me:topsec...@localhost/test?encoding=utf8. Is this what you
want to know?

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


Re: Beginning with Python; the right choice?

2009-06-27 Thread Dave Angel

sato.ph...@gmail.com wrote:

Hi,

As you can imagine, I am new, both to this group and to Python.  I
have read various posts on the best book to buy or online tutorial to
read and have started to go through them.  I was wondering, as someone
with virtually no programming experience (I am a photographer by
trade), is Python the right language for me to try and learn?

I do vaguely remember learning what I think was BASIC on some old
Apple's back in elementary school (circa 1992).  Would something like
that (the name at least makes it SOUND easier) be more feasible?

If I do choose to learn Python, are there any tutorials for the
absolute beginner.  I do not mean beginner to Python, but rather,
beginner to programming.  Someone who hasn't a clue what object
oriented whatcha-ma-whoozit means.  I ask again because I understand
that content is always evolving and there might be new tutorials out
there.

Thanks!

-Daniel Sato

  
I am also a photographer (portraits, weddings, parties, ...).  But my 
previous career was computer software (9 patents).  So I know a bit 
about both.


I only learned Python in the past year, having used 35 languages 
professionally previously.  And although Python wasn't the easiest to 
learn, it was in the top 3, and it has the best ratio of power to 
difficulty of learning.


The real point is that unless you're trying to make a career in 
software, you're unlikely to need any of these more powerful 
languages.  And you can probably write a useful utility in your first 24 
hours with the language.  Don't worry too much about object oriented 
at the start.  And don't worry much about using old tutorials.  Until 
Python 3, the language has been quite stable for many years.  So my 
advice would be to download Python 2.6 for your operating system, and 
start playing.


Pick something simple for your first tasks, preferably something useful 
in your main career.  For example, try writing a utility that examines a 
directory tree of image files, looking for some anomaly that you come up 
with.  For example, I use Nikon cameras, so my raw files have a .NEF 
extension.  I never delete the NEF file, but instead move it into a 
subdirectory Culled.   So I could write a script that searches all 
subdirectories of directory   images/2009-05, looking for gaps in the 
filenames found.  Or look for .psd files that don't have a corresponding 
.NEF file above them.  Or check the .xmp files to make sure the business 
copyright is in all  files.


I don't know what operating system you're using, but it would be a big 
help if you're familiar with the use of the command prompt.



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


  1   2   >