Re: Measuring Fractal Dimension ?

2009-06-27 Thread Paul Rubin
Steven D'Aprano  writes:
> Depends on how you define "discontinuous". 

The mathematical way, of course.  For any epsilon > 0, etc.

> Catastrophe theory is full of discontinuous changes in state. Animal
> (by which I include human) behaviour often displays discontinuous
> changes.  So does chemistry: one minute the grenade is sitting there,
> stable as can be, the next it's an expanding cloud of gas and metal
> fragments.

If that transition from grenade to gas cloud takes a minute (or even a
femtosecond), it's not a mathematical discontinuity.  The other
examples work out about the same way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginning with Python; the right choice?

2009-06-27 Thread Zaphod
snip
> 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/
> 
> ShowMeDo.com has lots of Python instructional videos, including this one
> for absolute beginners:
> http://showmedo.com/videotutorials/series?name=irgGc9ChS
> 
> I also recommend the Python tutor list, which you can sign up for here:
> http://mail.python.org/mailman/listinfo/tutor
> 
> So what is it that you want to use Python for?
> 
> Che

Also have a look at http://openbookproject.net/thinkcs/python/english2e/ 
which is a bit less in depth but faster and also fun way to get started.  
I teach high school programming and although I do teach Visual Basic at 
the lower levels (grade 9/10) I use Python for my grade 11/12 students.  
It's an easy language to learn and has an incredible amount of 
functionality through importable libraries.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-27 Thread Steven D'Aprano
On Thu, 25 Jun 2009 12:23:07 +0100, Robin Becker wrote:

> Paul Rubin wrote:
[...]
>> No really, it is just set theory, which is a pretty bogus subject in
>> some sense.  There aren't many discontinuous functions in nature. 

Depends on how you define "discontinuous". Catastrophe theory is full of 
discontinuous changes in state. Animal (by which I include human) 
behaviour often displays discontinuous changes. So does chemistry: one 
minute the grenade is sitting there, stable as can be, the next it's an 
expanding cloud of gas and metal fragments. Then there's spontaneous 
symmetry breaking. At an atomic level, it's difficult to think of things 
which *aren't* discontinuous.

And of course, if quantum mechanics is right, nature is *nothing but* 
discontinuous functions.


>> There
>> is a philosophy of mathematics (intuitionism) that says classical set
>> theory is wrong and in fact there are NO discontinuous functions.  They
>> have their own mathematical axioms which allow developing calculus in a
>> way that all functions are continuous.

On the other hand, there's also discrete mathematics, including discrete 
versions of calculus. 


> so does this render all the discreteness implied by quantum theory
> unreliable? or is it that we just cannot see(measure) the continuity
> that really happens?

That's a question for scientific investigation, not mathematics or 
philosophy.

It may be that the universe is fundamentally discontinuous, and the 
continuous functions we see are only because of our insufficiently high 
resolution senses and instruments. Or it may be that the discontinuities 
we see are only because we're not capable of looking closely enough to 
see the smooth function passing between the two ends of the discontinuity.

My money is on the universe being fundamentally discontinuous. We can 
explain the continuous behaviour of classical-scale phenomenon in terms 
of discontinuous quantum behaviour, but it doesn't seem possible to 
explain discontinuous quantum behaviour in terms of lower-level 
continuous behaviour.


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


Re: Fast Dictionary Access

2009-06-27 Thread Steven D'Aprano
On Sat, 27 Jun 2009 09:41:13 -0700, Rachel P wrote:
[...]
> Raymond

Raymond, does Rachel know you're using her gmail account?

*wink*


-- 
Steven
-- 
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 Steven D'Aprano
On Sat, 27 Jun 2009 19:55:17 +0200, Piet van Oostrum wrote:

>> Terry Reedy  (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' :=)


I try to always write file-handling files under the assumption that some 
day somebody (possibly me) will pass the function a file-like object, and 
therefore make the minimum number of assumptions about each line.

For example, I wouldn't assume that lines can't be empty, or that they 
must end in a newline. The later is violated even by ordinary files, but 
the former could be violated by a file-like object which iterated over 
(say) ['first line', 'second line', '', 'the previous line was blank'].



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


Re: The Python Way for module configuration?

2009-06-27 Thread Steven D'Aprano
On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote:

> (Even if you don't want to receive email, could you please give your
> actual name in the ‘From’ field instead of just initials? It makes
> conversation less confusing.)

Some people prefer to be known by their initials.

Some people's legal names *are* initials.

There's nothing confusing about addressing somebody by their initials. 
The only complication in this case is knowing the correct way to 
capitalise it -- should it be K.J. or Kj or something else?


> kj  writes:

Apart from capitalisation, it works perfectly.



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


Re: Measuring Fractal Dimension ?

2009-06-27 Thread Paul Rubin
Robin Becker  writes:
> > There is a philosophy of mathematics (intuitionism) that says...
> > there are NO discontinuous functions.

> so does this render all the discreteness implied by quantum theory
> unreliable? or is it that we just cannot see(measure) the continuity
> that really happens? 

I think the latter.  Quantum theory anyway describes continuous operators
that have discrete eigenvalues, not the same thing as discontinuous
functions.  
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2009-06-27 Thread Kay Schluehr
On 27 Jun., 23:06, "Martin v. Löwis"  wrote:
> > 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.

... which isn't all that different today. One might just take a look
at JavaFX and how gracefully it handles declarative data flow a.k.a.
data binding. The evolution of programming languages goes on, with or
rather without Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Python Way for module configuration?

2009-06-27 Thread Carl Banks
On Jun 27, 3:18 pm, kj  wrote:
> In  Aaron 
> Sherman  writes:
>
> >On Jun 27, 4:38=A0pm, MRAB  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.

The best way to do this totally depends on how complex these
parameters are.

Are they simple one-to-one key-value pairs?  Then the frontend should
explose a dict interface.  There are probably existing third-party
libraries that expose dict-like interfaces to all of your imagined
backends.
Check pypi.python.org, and also Python cookbook.

If the configuration is more complex, such as if it is hierarchical,
if it includes many-to-many relationships, if it is graph-like, then a
more sophisticated frontend will be needed.  For these situations I
second the recommendation to consider an ORM (such as SqlAlchemy).  I
am not aware of any ORMs that can use SQL, XML, and tab-delimited text
all as backends, though.  I am not a big database guy though.

Also, I exhort to you consider whether you really need so many
different backends for a configuration file.  Might your time be
better spent improving some other aspect of your application?


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


Re: No trees in the stdlib?

2009-06-27 Thread João Valverde

Miles Kaufmann wrote:

João Valverde wrote:
To answer the question of what I need the BSTs for, without getting 
into too many boring details it is to merge and sort IP blocklists, 
that is, large datasets of ranges in the form of (IP address, IP 
address, string). Originally I was also serializing them in a binary 
format (but no more after a redesign). I kept the "merge and sort" 
part as a helper script, but that is considerably simpler to implement.


...

As an anecdotal data point (honestly not trying to raise the "Python 
is slow" strawman), I implemented the same algorithm in C and Python, 
using pyavl. Round numbers were 4 mins vs 4 seconds, against Python 
(plus pyavl). Even considering I'm a worse Python programmer than C 
programmer, it's a lot. I know many will probably think I tried to do 
"C in Python" but that's not the case, at least I don' t think so. 
Anyway like I said, not really relevant to this discussion.


What format were you using to represent the IP addresses?  (Is it a 
Python class?)  And why wouldn't you use a network address/subnet mask 
pair to represent block ranges?  (It seems like being able to 
represent ranges that don't fit into a subnet's 2^n block wouldn't be 
that common of an occurrence, and that it might be more useful to make 
those ranges easier to manipulate.)
I was using a bytes subclass. I'm not free to choose CIDR notation, 
range boundaries must be arbitrary.




One of the major disadvantages of using a tree container is that 
usually multiple comparisons must be done for every tree operation.  
When that comparison involves a call into Python bytecode (for custom 
cmp/lt methods) the cost can be substantial.  Compare that to Python's 
hash-based containers, which only need to call comparison methods in 
the event of hash collisions (and that's hash collisions, not hash 
table bucket collisions, since the containers cache each object's hash 
value).  I would imagine that tree-based containers would only be 
worth using with objects with comparison methods implemented in C.
I would flip your statement and say one of the advantages of using trees 
is that they efficiently keep random input sorted. Obviously no 
algorithm can do that with single comparisons. And not requiring a hash 
function is a desirable quality for non-hashable objects. There's a 
world beyond dicts. :)


I profiled the code and indeed the comparisons dominated the execution 
time. Trimming the comparison function to the bare minimum, a single 
python operation, almost doubled the program's speed.




Not that I'm trying to be an apologist, or reject your arguments; I 
can definitely see the use case for a well-implemented, fast 
tree-based container for Python.  And so much the better if, when you 
need one, there was a clear consensus about what package to use (like 
PIL for image manipulation--it won't meet every need, and there are 
others out there, but it's usually the first recommended), rather than 
having to search out and evaluate a dozen different ones.



Thanks, and I'm not trying to start a religion either. ;)

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


Re: The Python Way for module configuration?

2009-06-27 Thread Ben Finney
(Even if you don't want to receive email, could you please give your
actual name in the ‘From’ field instead of just initials? It makes
conversation less confusing.)

kj  writes:

> But, minimally, the module needs to have some configuration details to
> know where to get the data. There are many ways to provide this
> configuration data to the module, but I would like to know what's
> considered "best practice" for this type of problem in the Python
> world.
> 
> Ideally, I'm looking for a system that is unobtrusive under normal
> operations, but easy to override during testing and debugging.

The standard library provides the ability to parse plain text
configuration files and populate a collection of values for
configuration. The module's name is changing to conform to the library
standards; see http://docs.python.org/library/configparser>.

This way, you can customise the execution of your program by modifying
configuration settings in a non-executable configuration file. It also
allows a cascade of overrides, for e.g. user-specific configuration
overrides or test-specific overrides, etc.

-- 
 \  “It is well to remember that the entire universe, with one |
  `\   trifling exception, is composed of others.” —John Andrew Holmes |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-27 Thread Miles Kaufmann

João Valverde wrote:
To answer the question of what I need the BSTs for, without getting  
into too many boring details it is to merge and sort IP blocklists,  
that is, large datasets of ranges in the form of (IP address, IP  
address, string). Originally I was also serializing them in a binary  
format (but no more after a redesign). I kept the "merge and sort"  
part as a helper script, but that is considerably simpler to  
implement.


...

As an anecdotal data point (honestly not trying to raise the "Python  
is slow" strawman), I implemented the same algorithm in C and  
Python, using pyavl. Round numbers were 4 mins vs 4 seconds, against  
Python (plus pyavl). Even considering I'm a worse Python programmer  
than C programmer, it's a lot. I know many will probably think I  
tried to do "C in Python" but that's not the case, at least I don' t  
think so. Anyway like I said, not really relevant to this discussion.


What format were you using to represent the IP addresses?  (Is it a  
Python class?)  And why wouldn't you use a network address/subnet mask  
pair to represent block ranges?  (It seems like being able to  
represent ranges that don't fit into a subnet's 2^n block wouldn't be  
that common of an occurrence, and that it might be more useful to make  
those ranges easier to manipulate.)


One of the major disadvantages of using a tree container is that  
usually multiple comparisons must be done for every tree operation.   
When that comparison involves a call into Python bytecode (for custom  
cmp/lt methods) the cost can be substantial.  Compare that to Python's  
hash-based containers, which only need to call comparison methods in  
the event of hash collisions (and that's hash collisions, not hash  
table bucket collisions, since the containers cache each object's hash  
value).  I would imagine that tree-based containers would only be  
worth using with objects with comparison methods implemented in C.


Not that I'm trying to be an apologist, or reject your arguments; I  
can definitely see the use case for a well-implemented, fast tree- 
based container for Python.  And so much the better if, when you need  
one, there was a clear consensus about what package to use (like PIL  
for image manipulation--it won't meet every need, and there are others  
out there, but it's usually the first recommended), rather than having  
to search out and evaluate a dozen different ones.


-Miles

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


Re: The Python Way for module configuration?

2009-06-27 Thread Dave Angel

kj wrote:

In  Aaron Sherman 
 writes:

  

On Jun 27, 4:38=A0pm, MRAB  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


  
Check out the ConfigParser module, a standard module.  In Python 3.0, 
it's renamed to configparser, but still part of the standard distribution.


This module interprets a file that's in roughly the  INI format.




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


Re: No trees in the stdlib?

2009-06-27 Thread João Valverde

alex23 wrote:

João Valverde  wrote:
  

Currently I don't have a strong need for this.



And clearly neither has anyone else, hence the absence from the
stdlib. As others have pointed out, there are alternative approaches,
and plenty of recipes on ActiveState, which seem to have scratched
whatever itch there is for the data structure you're advocating.
  


Propose such alternative then. There are none that offer the same 
performance. At best they're workarounds.


I don't care about recipes. That's called research.

If people don't find it to be useful, that's fine. Surprising, but fine.

And I don't have a need because I'm not using Python for my project. If 
I wanted to I couldn't, without implementing myself or porting to Python 
3 a basic computer science data structure.



While Python's motto is "batteries included" I've always felt there
was an implicit "but not the kitchen sink" following it. Just because
something "could" be useful shouldn't be grounds for inclusion. That's
what pypi & the recipes are for. Ideally, little should be created
wholesale for the stdlib, what should be added are the existing 3rd
party modules that have become so ubiquitous that their presence on
any python platform is just expected.
  


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


Re: No trees in the stdlib?

2009-06-27 Thread alex23
João Valverde  wrote:
> Currently I don't have a strong need for this.

And clearly neither has anyone else, hence the absence from the
stdlib. As others have pointed out, there are alternative approaches,
and plenty of recipes on ActiveState, which seem to have scratched
whatever itch there is for the data structure you're advocating.

While Python's motto is "batteries included" I've always felt there
was an implicit "but not the kitchen sink" following it. Just because
something "could" be useful shouldn't be grounds for inclusion. That's
what pypi & the recipes are for. Ideally, little should be created
wholesale for the stdlib, what should be added are the existing 3rd
party modules that have become so ubiquitous that their presence on
any python platform is just expected.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clobbered 2.6 binary under Frameworks.python, reinstall fails

2009-06-27 Thread ChollaPete
On Jun 27, 5:32 pm, ChollaPete  wrote:
> Mac OS  X (Tiger 10.4), running Python 2.6 downloaded from python.org
> as a DMG installer.
>
> I clobbered the python binary in /Library/Frameworks/Python.frameworks/
> Versions/Current/bin, so I tried to reinstall from the python.org
> 2.6.2 DMG installer.  No joy.  Install fails at the end with no
> helpful diagnostic message.
>
> So, I deleted everything in /Applications/Python2.6, in /Library/
> Frameworks/Python.frameworks and /usr/local/bin.  The install still
> fails.
>
> Any help would be appreciated.  I realize that the upgraders often
> aren't intended to be used to repair an existing installation.  My
> thinking now is that I may need to delete existing package receipts or
> plists, but this is just wild speculation.
>
> Thanks.
>
> Mark

Well, upon inspection of the various directories, everything seemed to
be there, so I ran the interpreter and it seemed to work.  Evaluated a
simple expression at the >>> prompt, imported a module and ran its
function.  So, I don't know what part of the install failed.  If
anyone can tell me where to find the various scripts that the MPKG
runs, that would help.

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


Re: [Python-Dev] [RELEASED] Python 3.1 final

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

Excellent news!

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Clobbered 2.6 binary under Frameworks.python, reinstall fails

2009-06-27 Thread ChollaPete
Mac OS  X (Tiger 10.4), running Python 2.6 downloaded from python.org
as a DMG installer.

I clobbered the python binary in /Library/Frameworks/Python.frameworks/
Versions/Current/bin, so I tried to reinstall from the python.org
2.6.2 DMG installer.  No joy.  Install fails at the end with no
helpful diagnostic message.

So, I deleted everything in /Applications/Python2.6, in /Library/
Frameworks/Python.frameworks and /usr/local/bin.  The install still
fails.

Any help would be appreciated.  I realize that the upgraders often
aren't intended to be used to repair an existing installation.  My
thinking now is that I may need to delete existing package receipts or
plists, but this is just wild speculation.

Thanks.

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


Re: looking for a book on python

2009-06-27 Thread Aahz
In article ,
Randy Foiles   wrote:
>OdarR wrote:
>> 
>> "Learning Python"
>> http://oreilly.com/catalog/9780596513986/
>> 
>> new issue soon, covering 2.6 and 3
>> http://oreilly.com/catalog/9780596158064/?CMP=AFC-ak_book&ATT=Learning+Python%2c+Fourth+Edition%2c
> 
>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?

There are lots of differences between 2.6 and the just-released 3.1, but
opinions are split about which is better for learning: some people say
that you should learn 3.x first because it's the future of Python and
it's simpler/cleaner; others (including me) say you should learn 2.x
first because that's where the bulk of current code is and many 3rd-party
libraries have not yet been ported to 3.x.

In the end, it doesn't make a lot of difference, as long as you stick
with only 2.x or 3.x during your initial learning: the core Python
syntax changes very little between the 2.x and 3.x, and there are only
two critical differences that will hit you up-front:

* Python 2.x has ``print`` as a statement; 3.x has ``print()`` as a
function

* Python 2.x has 8-bit strings by default; 3.x uses Unicode and has no
way to access 8-bit strings except as byte arrays

You might want to bookmark this, though:
http://docs.python.org/3.1/whatsnew/index.html
-- 
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: 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


Re: The Python Way for module configuration?

2009-06-27 Thread Petr Messner
Hi,

2009/6/28 kj :
...
> 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: 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  wrote:
> > netpork  (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 
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: p...@vanoostrum.org

-- 
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  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: looking for a book on python

2009-06-27 Thread Randy Foiles

Aahz wrote:

In article ,
Randy Foiles   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 B&N has it.

--
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  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_book&ATT=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: 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: The Python Way for module configuration?

2009-06-27 Thread kj
In  Aaron 
Sherman  writes:

>On Jun 27, 4:38=A0pm, MRAB  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


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: Good books in computer science?

2009-06-27 Thread Robert Kern

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

Albert van der Horst  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


Re: postgreSQL python bindings - which one?

2009-06-27 Thread Horace Blegg
On Sat, Jun 27, 2009 at 10:23 AM, Philip Semanchuk wrote:

>
> 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
>> sycopg/ 
>>
>
>
> +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


[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: 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


Re: The Python Way for module configuration?

2009-06-27 Thread Aaron Sherman
On Jun 27, 4:38 pm, MRAB  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: 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
 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 MRAB

kj wrote:



[PYTHON NOOB ALERT] 


I want to write a module that serves as a Python front-end to a
database.  This database can be either in the form of tab-delimited
flat files, XML files, or a PostgreSQL server.  The module is meant
to hide these database implementation details from its users.

But, minimally, the module needs to have some configuration details
to know where to get the data.  There are many ways to provide this
configuration data to the module, but I would like to know what's
considered "best practice" for this type of problem in the Python
world.

Ideally, I'm looking for a system that is unobtrusive under normal
operations, but easy to override during testing and debugging.

I would appreciate your comments and suggestions.


There are already modules which provide access to databases.
--
http://mail.python.org/mailman/listinfo/python-list


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

2009-06-27 Thread laplacia...@gmail.com
On Jun 27, 1:47 pm, Terry Reedy  wrote:
> laplacia...@gmail.com wrote:
>
> > 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?"

Long ago I did some Java programming and tried out Swing. I think the
complaints about it are that it's a very large toolkit that requires a
lot of inheritance to use. However, the underlying premise used by the
layout managers seemed sound:

1. Choose a layout manager.

2. Put one or more containers in it.

3. Fill the containers with widgets (or other containers), letting
them decide how to lay out the widgets.

That aspect, I liked. Seems a lot like nested elements in an html
page. Perhaps this was what Guido was alluding to?
-- 
http://mail.python.org/mailman/listinfo/python-list


The Python Way for module configuration?

2009-06-27 Thread kj



[PYTHON NOOB ALERT] 

I want to write a module that serves as a Python front-end to a
database.  This database can be either in the form of tab-delimited
flat files, XML files, or a PostgreSQL server.  The module is meant
to hide these database implementation details from its users.

But, minimally, the module needs to have some configuration details
to know where to get the data.  There are many ways to provide this
configuration data to the module, but I would like to know what's
considered "best practice" for this type of problem in the Python
world.

Ideally, I'm looking for a system that is unobtrusive under normal
operations, but easy to override during testing and debugging.

I would appreciate your comments and suggestions.

TIA!

kynn
-- 
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 MRAB

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
 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.

--
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: 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.


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


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: 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
 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: 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 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: change the first character of the line to uppercase in a text file

2009-06-27 Thread Piet van Oostrum
> Terry Reedy  (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 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a book on python

2009-06-27 Thread Aahz
In article ,
Kee Nethery   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: 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: encoding problem

2009-06-27 Thread Piet van Oostrum
> netpork  (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 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
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: 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: Good books in computer science?

2009-06-27 Thread Terry Reedy

A

Steven D'Aprano   wrote:


On 2009-06-14 14:04:02 +0100, Steven D'Aprano
 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: 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


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: 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


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: 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


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: 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


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: 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


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.
>
> 
> if  data.has_key(key):
>    value = data[key]
> 
>
> 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: to use unicode strings only

2009-06-27 Thread Benjamin Peterson
Gaudha  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: 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


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  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  
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: 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


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: file transfer in python

2009-06-27 Thread vasudevram
On Jun 26, 5:07 pm, Francesco Bochicchio  wrote:
> On 26 Giu, 13:38, jayesh bhardwaj  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: Beginning with Python; the right choice?

2009-06-27 Thread 疯图灵
On 6月27日, 上午10时22分, "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: 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  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  |  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: 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: to use unicode strings only

2009-06-27 Thread Benjamin Peterson
Gaudha  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 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, MRAB 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: 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: Good books in computer science?

2009-06-27 Thread Paul Rubin
Albert van der Horst  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


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: 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


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


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 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 "", line 2, in 
>>>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


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: 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: 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: 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 "", line 2, in 
>>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: 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 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: Fast Dictionary Access

2009-06-27 Thread Duncan Booth
Thomas Lehmann  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.
> 
>
> if  data.has_key(key):
>value = data[key]
>
> 
> 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: 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


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: 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


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 "", line 2, in 
>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 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
>> 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 "", line 2, in 
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 11:39:28 +0100, I asked rhetorically:

>On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah
> 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 Angus Rodgers
On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah
 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 Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah 
 wrote:

>On Jun 26, 4:51 pm, Chris Rebert  wrote:
>> On Fri, Jun 26, 2009 at 12:43 PM, powah 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: Good books in computer science?

2009-06-27 Thread Albert van der Horst
In article <7xocssvzrh@ruckus.brouhaha.com>,
Paul Rubin   wrote:
>koranthala  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...@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Fast Dictionary Access

2009-06-27 Thread Paul Rubin
Thomas Lehmann  writes:
> 
> if  data.has_key(key):
>value = data[key]
> 
> 
> 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: 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: 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   wrote:

>> On 2009-06-14 14:04:02 +0100, Steven D'Aprano
>>  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.



>--
>Steven
>

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
alb...@spe&ar&c.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 <0244e76b$0$20638$c3e8...@news.astraweb.com>,
Steven D'Aprano   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...@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

-- 
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: Fast Dictionary Access

2009-06-27 Thread Chris Rebert
On Sat, Jun 27, 2009 at 2:47 AM, Thomas
Lehmann 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.
>
> 
> if  data.has_key(key):
>   value = data[key]
> 
>
> 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


  1   2   >