[Tutor] running as generic file type

2005-12-22 Thread Eli Zabielski
HiI'm very new to python, I created my first program, saved it as .py. I wanted to show it to my friends and I tested running it on another computer, one without python, and it didn't work, it gave me a list of programs to try to run it on (ex. word, IE, Mozilla). Is there any way to save it so anyone with windows can use it?
Thanks for the help,Eli Zabielski
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Differnce between java and python

2005-12-22 Thread Alan Gauld
Another example is that Python supports Duck Typing, that is
its type checking  is protocol based.

 I see your point, but duck typing seems awfully implicit and
 behind-the-scenes.

When you first encounter it it is. I came from a C++ and Pascal
background where strict typing was the rule, Python seemed very lax.
But I had the advantage of having worked in Lisp and Smalltalk too
so I kind of relaxed fairly quickly.

 Seems like if I expect a protocol, and you provide something that claims 
 to
 implement said protocol, there ought to be some contract that ensures 
 we're
 dealing with the same protocol. I ought not to be able to pass my car and
 my nose to the same function, just because the both run().

It depends. Obviously in this example its likely that the behaviour would
result in boizarre results but on the other hand if the function was
race(obj1, obj2) then both car and nose could be appropriate,
but in the latter case with rather horrible connotations...

But seriously, Duck Typing allows for a far more expreessive and
powerful use of objects. When you are no longer bound by the limitations
of inheritance heirarchies you can start to build much more powerful 
funcions.
The downside is that there is an onus on the client to sanity check the
usage of the function - will it really do what I expect?

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Differnce between java and python

2005-12-22 Thread Alan Gauld
[Putting this back on the list so others get the context info]

- Original Message - 
From: shivayogi kumbar [EMAIL PROTECTED]
Subject: Re: [Tutor] Differnce between java and python


Sir I have completed  my Msc(c.s).I have worked on java and also done my
project on javaa using swings ,RMI  technology.The thing is now I have
joined the company is working on the Python.So I would ike to know the
difference between Java and Python

--

In that case since you have a good knowledge of Python we 
can focus on a feature comparison with Java.

Python has much in common with Java in that both work by compiling to byte 
code, however Java does so in a traditional comipile first manner whereas 
Python compiles at first run. 

Python is dynamically typed and uses protocol based polymorphism 
rather than inheritance based(so called Duck typing).

Python is a much higher level language than Java, I'd guess the 
ratio of lines of code per function point is around 3:1. Python is 
often called 'executable pseudo code'.

Python has a much more elegant syntax, it is much less based on C 
(Although some C-isms do show through in places)

Python is more object oriented than Java which is predominantly 
class based. By that I mean there are lots of objects around in Python 
where you never see the class. Similarly there are relatively few class 
methods (static in Java). You can't use Java wthout without seeing at 
least one class statement.

Python has much better support for higher order programming, 
functional programming and, more debateably, meta-programming.

There's lots more but that should e enough for now.
Check the refeences others have sent. 
Also check out Jython which combines the best of both worlds with 
remarkably few compromises. 

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running as generic file type

2005-12-22 Thread Kent Johnson
Eli Zabielski wrote:
 Hi
 I'm very new to python, I created my first program, saved it as .py. I 
 wanted to show it to my friends and I tested running it on another 
 computer, one without python, and it didn't work, it gave me a list of 
 programs to try to run it on (ex. word, IE, Mozilla). Is there any way 
 to save it so anyone with windows can use it?

Eli,

The .py file is just a text file containing the program, it requires Python to 
run. Just 
like you would not give a friend a Word file and expect them to be able to open 
it without 
the Word program on their computer, to run a Python program you need the Python 
interpreter. You have a few options:

- Install Python on the other computer. If you have done this already on your 
computer you 
know it is not very hard.
- Create an executable program that includes your program and the Python 
interpreter in 
one bundle. The program to do this is called py2exe, you can find it here:
http://www.py2exe.org/

The disadvantage of this is that there is a bit to learn and the resulting 
executables are 
much larger than the original program (typically several megabytes) because 
they include 
the Python interpreter as well as your program.

- Movable Python is a way of building a Python environment on a memory stick. 
You can 
bring it to another computer just by plugging in the memory stick. This might 
be a good 
solution for you especially if you already have a memory stick.
http://www.voidspace.org.uk/python/movpy/

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Books

2005-12-22 Thread daniel.brown
While we are on the topic of books, what book would you recommend for
the experienced C++/C# programmer looking to pick up Python?  I've been
looking at 'Python in a Nutshell' and 'Programming Python' on
amazon.co.uk, as I've found O'Reilly books good in the past.  I'm mainly
looking to use Python for general scripting tasks as I'm finding that
batch files just aren't flexible or powerful enough on WinXP...

Cheers,

Daniel

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Tim Johnson
Sent: 22 December 2005 03:47
To: tutor@python.org
Subject: Re: [Tutor] Books

* Kent Johnson [EMAIL PROTECTED] [051221 13:40]:
 Johan Geldenhuys wrote:
  Are here any new books on web programming with Python?
 
  I have Python Web Programming by Steve Holden, written in
  2002 covering up to python 2.0 - I believe.

 
http://www.amazon.com/gp/product/0735710902/qid=1135222880/sr=2-1/ref=pd
_bbs_b_2_1/103-3865586-6854221?s=booksv=glancen=283155

  Foundations of Python Network Programming:
 
http://www.amazon.com/gp/product/1590593715/qid=1135222941/sr=2-1/ref=pd
_bbs_b_2_1/103-3865586-6854221?s=booksv=glancen=283155

-- 
Tim Johnson [EMAIL PROTECTED]
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


This email has been scanned by the MessageLabs Email Security System





DISCLAIMER
This message and any attachments contain privileged and confidential 
information intended for the use of the addressee named above. If you are not 
the intended recipient of this message, you are hereby notified that any use, 
dissemination, distribution or reproduction of this message is prohibited. 
Please note that we cannot guarantee that this message or any attachment is 
virus free or that it has not been intercepted and amended. The views of the 
author may not necessarily reflect those of Real Time Worlds Ltd.

This email has been scanned by the MessageLabs Email Security System
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Numeric import error

2005-12-22 Thread Johan Geldenhuys
Hi all,

I have installed Numeric (Suse 10.0) and it is in my site-packages 
folder, but I can't import the module.

Any idea how to fix this/

TIA

Johan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running as generic file type

2005-12-22 Thread Alan Gauld
Hi Eli,

 I'm very new to python, I created my first program, saved it as .py.
 I wanted to show it to my friends and I tested running it on another
 computer, one without python, and it didn't work,

That's because Python is an interpreted language so it needs an interpreter
to be present. This is the same as Java and most Visual Basic programs,
the difference being that Microsoft provide Visual Basic and Java 
interpreters
on Windows as standard.

One of the easiest ways for you to write code that works on any machine
is to use Jython. It is a vesion of Python written in Java that comes with a
compiler for converting the Python code into a Java program. That will
then run on any computer with Java installed. The snag is that some of
the standard modules that come with Python don't work with Jython!
(Thats because Java provides similar modules so you can use them instead).
Most beginner programs will work in Jython but as you progress you might
start hitting problems. But by then you are ready for option 2...

Another way to get the programs to run is to convert the python program
into a standalone executable file (a .exe) which can be done using a
downloadable tool called py2exe. Py2exe just bundles a copy of the
interpreter and all the modules you use into one file. Unfortunately
this is not the simplest tool for a beginner to use... Also it creates quite
big files - too big for a floppy disk.

Of course if your friends had Apple Macs or Linux boxes then Python
would be installed already.

And there is a version of Python for Microsoft's new .NET framework
called IronPython. But I haven't tried it and don't know how well it works.
Also your friends will need to have the .NET framework installed.

Finally, you could just install Python on your friends PCs too and
maybe get them interested in programming :-)

So there is no perfect answer (yet), sorry. But there are some options
for you to try...

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] md5 message digest algorithm

2005-12-22 Thread Ales Zemene
hi, suprising for me is that making .py file:
import md5
hash = md5.new()
and running it produces :
AttributeError: 'module' object has no attribute 'new'

and similar : 
from Crypto.Hash import MD5
ImportError: cannot import name MD5

but in both cases it works on python command line intepretter.

Ales
-- 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Performance of Python loops vs multiple MySQL queries

2005-12-22 Thread Bernard Lebel
On 12/21/05, Kent Johnson [EMAIL PROTECTED] wrote:
 Bernard Lebel wrote:
  Hello,
 
  Finally, after a year and a half of learning and messing around with
  Python, I'm writing THE code that made learn Python in the first
  place: a render farm client management software. I may have several
  questions regarding this, but for now I only have one.

 Congratulations Bernard, you have come a long way!

[Bernard] Thanks a lot Kent, without and all the other gurus of this
list, I wouldn't made it that far!

 
  The script I'm writing is the client script that runs on render nodes.
  It checks a database for a job to do, then based on some factors like
  pooling, priority, age and stuff, will determine what job it can work
  on. The client connects, performs evaluation of jobs, get a job,
  update the database, and starts the actual job.
 
  Now, there might be up to 80 clients connecting to the database at any
  moment to get a job to do. So understandably, I want the evaluation
  step to be as fast as possible.
 
  Right now, my script works this way: it selects a bunch of rows based
  on a few factors. Then when this is done, everything else is done in
  the script, that is, doesn't rely on a MySQL query. The script builds
  a variety of sorted lists and dictionaries, to ultimately end up with
  a single job.
 
  So I am wondering this: in case there are only a handful of jobs to
  evaluate, then I understand the script may run fast. But if it has to
  build lists and dictionary on thousands of jobs, then I'm affrait that
  it might become slower than simply running a series of queries to the
  database using various ordering schemes.
 
 
  Any advice on this?

 I haven't looked at your code closely so I will just offer some general 
 advice.

 - Don't assume there is going to be a problem.

[Bernard] Okay perhaps by problem I have not been very accurate. I
meant sync problems. You see, when the script finds a job, it makes
updates in the database, that is, it adds an entry into another table,
and updates a certain field in the main jobs table. Other clients then
testing if there is something to do rely on information that must be
totally up-to-date. I just wanted to make sure I would not run into
the case of multiple clients getting incorrect results because of not
so up-to-date informations. Perhaps I should investigate table locks?


 Python dicts are very fast - they are the data structure underlying 
 namespaces and they
 have been heavily optimized for years.

[Bernard] Okay, good to know!


 - Measure! The only way to truly answer your question is to try it both ways 
 and time it.

[Bernard] You are right.


 My guess is that the dictionary approach will be faster. I assume the 
 database is on a
 remote host since it is serving multiple clients. So at a minimum you will 
 have the
 network round-trip delay for each query.

 - Your getJob() code seems to use some variables before they are assigned, 
 such as
 tPoolIDs and aJob. Is this working code? Also it would be easier to read if 
 you broke it
 up into smaller functions that each do a small piece of the problem.

[Bernard] This is not working code. tPoolIDs is bound after the first
query of the function, but aJob is an error of mine.

Indeed I could break down the getJob() function into smaller
functions. It's just that since the class is already having a fair
amount of methods and this is becoming some long code, I wanted to
keep everything into a single function.

Also there was a consideration of performance. I have one question on
the topic breaking code into small functions and performance. I have
read somewhere that *any* call whatoever, that is, methods, functions
and such, involve a performance cost. Is that right?
In the case it is true, the performance deterioration would be
proportional with the number of calls being made, so the larger the
number of iterations and the more function calls, the slower the code
would run, is that correct?


Thanks
Bernard


 Kent
 
 
  Here is a link to the current code (that build lists and
  dictionaries). Keep in mind it's in early alpha stage. The section to
  look for is the function getJob(), that starts at line 776. I have
  changed the extention to txt for security purposes.
  http://www.bernardlebel.com/scripts/nonxsi/farmclient_2.0_beta03.txt
 
 
 
  Thanks in advance
  Bernard
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Numeric import error

2005-12-22 Thread Pujo Aji
Can you open the python interpreter and write:import NumericWhat kind of error message you have?Cheers,pujoOn 12/22/05, Johan Geldenhuys
 [EMAIL PROTECTED] wrote:Hi all,
I have installed Numeric (Suse 10.0) and it is in my site-packagesfolder, but I can't import the module.Any idea how to fix this/TIAJohan___
Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Numeric import error

2005-12-22 Thread Johan Geldenhuys




 import Numeric
Traceback (most recent call last):
 File "stdin", line 1, in ?
ImportError: No module named Numeric

Pujo Aji wrote:
Can you open the python interpreter and write:
import Numeric
  
What kind of error message you have?
Cheers,
pujo
  
  On 12/22/05, Johan Geldenhuys
   [EMAIL PROTECTED]
wrote:
  Hi
all,


I have installed Numeric (Suse 10.0) and it is in my site-packages
folder, but I can't import the module.

Any idea how to fix this/

TIA

Johan
___

Tutor maillist-Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  
  
  



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Numeric import error

2005-12-22 Thread Pujo Aji
Do you have other modules in your site-packages directory ?Such as spe, pyro, pyrobot etc.On 12/22/05, Johan Geldenhuys 
[EMAIL PROTECTED] wrote:


  
  


 import Numeric
Traceback (most recent call last):
 File stdin, line 1, in ?
ImportError: No module named Numeric

Pujo Aji wrote:
Can you open the python interpreter and write:
import Numeric
  
What kind of error message you have?
Cheers,
pujo
  
  On 12/22/05, Johan Geldenhuys
   [EMAIL PROTECTED]
wrote:
  Hi
all,


I have installed Numeric (Suse 10.0) and it is in my site-packages
folder, but I can't import the module.

Any idea how to fix this/

TIA

Johan
___

Tutor maillist-Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  
  
  




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Numeric import error

2005-12-22 Thread Pujo Aji
Can you find numeric.py inside your numeric folder ?On 12/22/05, Pujo Aji [EMAIL PROTECTED] wrote:
Do you have other modules in your site-packages directory ?Such as spe, pyro, pyrobot etc.
On 12/22/05, Johan Geldenhuys 

[EMAIL PROTECTED] wrote:


  
  


 import Numeric
Traceback (most recent call last):
 File stdin, line 1, in ?
ImportError: No module named Numeric

Pujo Aji wrote:
Can you open the python interpreter and write:
import Numeric
  
What kind of error message you have?
Cheers,
pujo
  
  On 12/22/05, Johan Geldenhuys
   [EMAIL PROTECTED]
wrote:
  Hi
all,


I have installed Numeric (Suse 10.0) and it is in my site-packages
folder, but I can't import the module.

Any idea how to fix this/

TIA

Johan
___

Tutor maillist-Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  
  
  






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Books

2005-12-22 Thread Brian van den Broek
[EMAIL PROTECTED] said unto the world upon 2005-12-22 05:00:
 While we are on the topic of books, what book would you recommend for
 the experienced C++/C# programmer looking to pick up Python?  I've been
 looking at 'Python in a Nutshell' and 'Programming Python' on
 amazon.co.uk, as I've found O'Reilly books good in the past.  I'm mainly
 looking to use Python for general scripting tasks as I'm finding that
 batch files just aren't flexible or powerful enough on WinXP...
 
 Cheers,
 
 Daniel

Hi Daniel,

the Nutshell is the one to have at hand when coding. I don't know if 
one could learn from it. Dive into Python is targeted at the 
experienced programmer and is available both in dead tree and 
electronic form http://diveintopython.org/.

Best,

Brian vdB

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] md5 message digest algorithm

2005-12-22 Thread Kent Johnson
Ales Zemene wrote:
 hi, suprising for me is that making .py file:
 import md5
 hash = md5.new()
 and running it produces :
 AttributeError: 'module' object has no attribute 'new'

By any chance is your program called md5.py? If so it is being imported instead 
of the md5 
library module.

 
 and similar : 
 from Crypto.Hash import MD5
 ImportError: cannot import name MD5
 
 but in both cases it works on python command line intepretter.

Are you sure you are using the same interpreter in both cases? Maybe try
import sys
print sys.path

to make sure the directory containing Crypto.Hash is in sys.path...

HTH
Kent

 
 Ales


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Performance of Python loops vs multiple MySQL queries

2005-12-22 Thread Kent Johnson
Bernard Lebel wrote:
 On 12/21/05, Kent Johnson [EMAIL PROTECTED] wrote:
- Don't assume there is going to be a problem.
 
 
 [Bernard] Okay perhaps by problem I have not been very accurate. I
 meant sync problems. You see, when the script finds a job, it makes
 updates in the database, that is, it adds an entry into another table,
 and updates a certain field in the main jobs table. Other clients then
 testing if there is something to do rely on information that must be
 totally up-to-date. I just wanted to make sure I would not run into
 the case of multiple clients getting incorrect results because of not
 so up-to-date informations. Perhaps I should investigate table locks?

Yes, you should have a plan to avoid that kind of problem. Does your database 
support 
transactions? If so that is the easy way to ensure this - just put the whole 
getJob() into 
a transaction.

- Your getJob() code seems to use some variables before they are assigned, 
such as
tPoolIDs and aJob. Is this working code? Also it would be easier to read if 
you broke it
up into smaller functions that each do a small piece of the problem.
 
 
 [Bernard] This is not working code. tPoolIDs is bound after the first
 query of the function, but aJob is an error of mine.
 
 Indeed I could break down the getJob() function into smaller
 functions. It's just that since the class is already having a fair
 amount of methods and this is becoming some long code, I wanted to
 keep everything into a single function.

hmm, not a good choice. The code will be more readable and maintainable if it 
is broken 
up. If the class gets to big, think about making a helper class for some of the 
code. For 
example you might put the whole getJob() function into a class or module whose 
job it is 
to talk to the database and figure out the next job.

One hallmark of a good design is that each class or module has a single 
responsibility. In 
your class you have several responsibilities that could possibly be broken out 
into 
separate modules
- maintain the state of a single client - this is the job of the Client class
- low-level database access - the query() function could be in a separate module
- details of a single job might fit well in a Job class, this would greatly 
simplify 
Client.setJob()
- getJob() might move to a utility module that just accesses the database and 
returns a 
Job object.

 
 Also there was a consideration of performance. I have one question on
 the topic breaking code into small functions and performance. I have
 read somewhere that *any* call whatoever, that is, methods, functions
 and such, involve a performance cost. Is that right?

Yes.

 In the case it is true, the performance deterioration would be
 proportional with the number of calls being made, so the larger the
 number of iterations and the more function calls, the slower the code
 would run, is that correct?

Yes, it is correct. Worrying about it at this point is gross premature 
optimization. It 
will only be a problem if you have many many function calls in a 
performance-critical loop.

First make working code whose design clearly expresses the intent of the code. 
If it is 
too slow, then profile to find the hot spots and address them.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Performance of Python loops vs multiple MySQL queries

2005-12-22 Thread Bernard Lebel
Thanks for all the advice Kent.


Bernard



On 12/22/05, Kent Johnson [EMAIL PROTECTED] wrote:
 Bernard Lebel wrote:
  On 12/21/05, Kent Johnson [EMAIL PROTECTED] wrote:
 - Don't assume there is going to be a problem.
 
 
  [Bernard] Okay perhaps by problem I have not been very accurate. I
  meant sync problems. You see, when the script finds a job, it makes
  updates in the database, that is, it adds an entry into another table,
  and updates a certain field in the main jobs table. Other clients then
  testing if there is something to do rely on information that must be
  totally up-to-date. I just wanted to make sure I would not run into
  the case of multiple clients getting incorrect results because of not
  so up-to-date informations. Perhaps I should investigate table locks?

 Yes, you should have a plan to avoid that kind of problem. Does your database 
 support
 transactions? If so that is the easy way to ensure this - just put the whole 
 getJob() into
 a transaction.

 - Your getJob() code seems to use some variables before they are assigned, 
 such as
 tPoolIDs and aJob. Is this working code? Also it would be easier to read if 
 you broke it
 up into smaller functions that each do a small piece of the problem.
 
 
  [Bernard] This is not working code. tPoolIDs is bound after the first
  query of the function, but aJob is an error of mine.
 
  Indeed I could break down the getJob() function into smaller
  functions. It's just that since the class is already having a fair
  amount of methods and this is becoming some long code, I wanted to
  keep everything into a single function.

 hmm, not a good choice. The code will be more readable and maintainable if it 
 is broken
 up. If the class gets to big, think about making a helper class for some of 
 the code. For
 example you might put the whole getJob() function into a class or module 
 whose job it is
 to talk to the database and figure out the next job.

 One hallmark of a good design is that each class or module has a single 
 responsibility. In
 your class you have several responsibilities that could possibly be broken 
 out into
 separate modules
 - maintain the state of a single client - this is the job of the Client class
 - low-level database access - the query() function could be in a separate 
 module
 - details of a single job might fit well in a Job class, this would greatly 
 simplify
 Client.setJob()
 - getJob() might move to a utility module that just accesses the database and 
 returns a
 Job object.

 
  Also there was a consideration of performance. I have one question on
  the topic breaking code into small functions and performance. I have
  read somewhere that *any* call whatoever, that is, methods, functions
  and such, involve a performance cost. Is that right?

 Yes.

  In the case it is true, the performance deterioration would be
  proportional with the number of calls being made, so the larger the
  number of iterations and the more function calls, the slower the code
  would run, is that correct?

 Yes, it is correct. Worrying about it at this point is gross premature 
 optimization. It
 will only be a problem if you have many many function calls in a 
 performance-critical loop.

 First make working code whose design clearly expresses the intent of the 
 code. If it is
 too slow, then profile to find the hot spots and address them.

 Kent

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Books

2005-12-22 Thread Alan Gauld

 While we are on the topic of books, what book would you recommend for
 the experienced C++/C# programmer looking to pick up Python?
 looking to use Python for general scripting tasks as I'm finding that
 batch files just aren't flexible or powerful enough on WinXP...

For your particular interest I'd recommend using the official tutorial plus
this list to learn the language and buy

Python Programming on Win32 by Mark Hammond (O'Reilly)

as a reference book.

It is essential reading for the serious XP Python programmer because
many of the native Python stuff is very Unix biased. Hammond shows
how to avoid the pitfalls and adapt to Win32 environments.

The book is a little old now (Python 1.5.2) but the vast bulk of it is still
absolutely relevant, being based largely on the win32 extensions written
by Hammond and found in the winall python package(or included by
default in the ActiveState download). Its not all win32 specific, it 
includes
coverage of Tkinter etc too. Still a new version would be welcome!

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Performance of Python loops vs multiple MySQL queries

2005-12-22 Thread Alan Gauld
 Also there was a consideration of performance. I have one question on
 the topic breaking code into small functions and performance. I have
 read somewhere that *any* call whatoever, that is, methods, functions
 and such, involve a performance cost. Is that right?

Yes it is, but its not a huge cost. Unless you have a very time critical 
loop
calling lots of functions calling functions then don't worry unduly. And if
there is a problem use the profiler to tune the bits that need tuning.

The benefits of breaking code into functions in terms of readability and
maintenance far outweigh the performance hit in 99% of cases. Even in
the 1% its better to get it working slowly first then optimise later, 
exactly
where needed.

 proportional with the number of calls being made, so the larger the
 number of iterations and the more function calls, the slower the code
 would run, is that correct?

More or less, but a badly designed loop, or list comprehension will cancel
out any function call overhead very quickly. And disk reads or network
access will be order of magnitude slower still. Worrying about low level
performance tuning before you have a problem is usually a wasted effort.
High level performance tuning - getting the design clean - is another 
matter.
In all of the cases (bar one) where I've had major performamce issues to
fix they have been resolved at the architecture level (minimising network
or database accesses) not at the low level code.

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Differnce between java and python (fwd)

2005-12-22 Thread Danny Yoo
[Keeping tutor@python.org in CC.  Ok, so now we know that Shivayogi
already has Java experience.

Shivayogi might also be a little annoyed that he has to learn a new
language.  We have to tread more carefully in making claims like Python
is easier than Java, because for anyone starting on another language, the
language we already know is obviously easier than the one we are trying to
learn.  *grin*]


Hi Shivayogi,

There are a few nice things about Python that make common tasks easier to
do.  We can go through a few examples, and if you have questions on them
or would like to see more examples, please ask and folks on the list will
be happy to talk with you.  (Please make sure to keep tutor@python.org in
CC by using your email client's Reply to All  feature.)


For example, Java has an iterator protocol, but until Java 1.5, it
didn't have much syntactic support.  As an example, writing loops to go
across iterators involved manually next()ing the iterable and calling
hasNext():


/*** Java ***/
import java.util.*;

// ... within some method body

List words = Arrays.asList(new String[] {hello, world,
 this, is,
 a, test});
for (Iterator iter = words.iterator(); iter.hasNext(); ) {
String word = (String) iter.next();
System.out.println(word.toUpperCase());
}
/**/


Python's for loop, on the other hand, natively works across iterables: the
'for' loop itself is responsible for doing things like 'next()':

### Python ###
words = [hello, world, this, is, a, test]
for word in words:
print word.upper()
##

I understand that Java's for loop finally has iterator support, but from
the examples I've seen, it looks a bit syntactically heavyweight.


Another casual example where Python and Java differ is the treatment of
common types.  Python doesn't have a notion of primitive types, whereas
in Java, we sometimes have to think about 'int' vs. Integer.

For example, we know that the Java method:

/**/
int double(int x) {
return x * 2;
}
/**/

breaks on large input because the declared types are primitive ints.  To
make this really work, we have to use BigIntegers:

/**/
BigInteger double(BigInteger x) {
return x.multiply(new BigInteger(2));
}
/**/


On the other hand, Python integers also automatically promote themselves
to bignums rather than overflow, so the function:

##
def double(x):
return x * 2
##

just works.


Does this make sense so far?  Please feel free to ask more questions.
There's also a book by Bruce Tate called Beyond Java that talks about
these issues.

Best of wishes!



-- Forwarded message --
Date: Thu, 22 Dec 2005 10:40:13 +0530
From: shivayogi kumbar [EMAIL PROTECTED]
To: Danny Yoo [EMAIL PROTECTED]
Subject: Re: [Tutor] Differnce between java and python

Sir,
 I hve done my MSc(c.s).I did my project on Java.Know I have joined
the company where they work on Python.So It has forced to me learn
PYthon.SoI have approaced you
people.What are the advntages of Python over java.
   Thank you

On 12/22/05, Danny Yoo [EMAIL PROTECTED] wrote:



 On Wed, 21 Dec 2005, shivayogi kumbar wrote:

  sir plz tell me the main differnces between java and python?  And What
  are the advantages of python?

 Hi Shivayogi,

 When you post on a mailing list that's dedicated to help teach programming
 with Python, you do anticipate what kind of answers you're going to get
 here, right?  *grin*

 Are you a beginner programmer?  Do you have any previous experience with
 programming?  I'd really like us to turn the discussion toward what you
 really want to learn.  Advocacy and cheerleading is fun, of course, but
 let's see if we can help you too.  What are you trying to do?



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] running a .exe

2005-12-22 Thread Robin Buyer



How do you run a .exe from inside a python 
program.
randomexample:
print "What would you like to do today? 
" print "E - email" print "I - 
internet" what = input("Choose: ") 
if what == "E":
  Heres where i 
would need torun IEXPLORE.exe 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running a .exe

2005-12-22 Thread Kent Johnson
Robin Buyer wrote:
 How do you run a .exe from inside a python program.
 random example:
 print What would you like to do today? 
 print E - email
 print I - internet
 what = input(Choose: )
 if what == E:
 Heres where i would need to run IEXPLORE.exe

Look at os.system() (simple) and the subprocess module (more complicated and 
flexible).

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Books

2005-12-22 Thread Nick Lunt
Web/Network programming here
http://www.amazon.com/gp/product/0596100329/qid=1135198935/sr=2-1/ref=pd_bbs
_b_2_1/103-4720029-4050242?s=booksv=glancen=283155

Not CGI specific, and I haven't bought it yet, but I bet it's a blinder :)



 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Behalf Of Johan Geldenhuys
 Sent: 21 December 2005 20:59
 To: David Holland
 Cc: tutor@python.org
 Subject: Re: [Tutor] Books


 Are here any new books on web programming with Python?

 Johan

 David Holland wrote:

 I would recommend python programming for the absolute beginner.
 
 
 
 
 
 ___
 Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide
 with voicemail http://uk.messenger.yahoo.com
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 
 
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor


 --
 No virus found in this incoming message.
 Checked by AVG Free Edition.
 Version: 7.1.371 / Virus Database: 267.14.3/209 - Release Date: 21/12/2005



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running a .exe

2005-12-22 Thread Robin Buyer
The internet was just an example. I'm just looking at how to open .exe from
python.
- Original Message -
From: Liam Clarke-Hutchinson [EMAIL PROTECTED]
To: 'Robin Buyer' [EMAIL PROTECTED]; tutor@python.org
Sent: Thursday, December 22, 2005 7:35 PM
Subject: RE: [Tutor] running a .exe


 Hi Robin,

 Normally you would use

 import os

 os.system(c:/windows/iexplore.exe) # Or wherever it lives

 Build as you're attempting to run internet explorer you could use  -

 import webbrowser

 webbrowser.open(http://www.google.co.nz;) #Assuming IE is system default
 broswe


 Liam Clarke-Hutchinson| Contact Centre Advisor| Ministry of Economic
 Development
 DDI +64 3 962 2639 | Fax +64 3 962 6220
 www.med.govt.nz
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
 Of Robin Buyer
 Sent: Friday, 23 December 2005 11:50 a.m.
 To: Tutor@python.org
 Subject: [Tutor] running a .exe


 How do you run a .exe from inside a python program.
 random example:
 print What would you like to do today? 
 print E - email
 print I - internet
 what = input(Choose: )
 if what == E:
 Heres where i would need to run IEXPLORE.exe

 A new monthly electronic newsletter covering all aspects of MED's work is
now available.  Subscribers can choose to receive news from any or all of
seven categories, free of charge: Growth and Innovation, Strategic
Directions, Energy and Resources, Business News, ICT, Consumer Issues and
Tourism.  See http://news.business.govt.nz for more details.




 http://www.govt.nz - connecting you to New Zealand central  local
government services

 Any opinions expressed in this message are not necessarily those of the
Ministry of Economic Development. This message and any files transmitted
with it are confidential and solely for the use of the intended recipient.
If you are not the intended recipient or the person responsible for delivery
to the intended recipient, be advised that you have received this message in
error and that any use is strictly prohibited. Please contact the sender and
delete the message and any attachment from your computer.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running a .exe

2005-12-22 Thread Kent Johnson
Robin Buyer wrote:
 I created a small program to test os.system:
 
 import os.path
 os.system(C:\Program Files\Internet Explorer\IEXPLORE.EXE)
 
 when i run this from the command line I get an error message:
 'C:\Program' is not recognized as an internal or external command, operable
 program or batch file.
 
 How do you put spaces into a path name?

The same way you do if you are typing the command directly to the shell - put 
it in 
quotes. So now there are two sets of quotes - one to tell Python it is a 
string, and one 
to pass to the shell:
os.system('C:\Program Files\Internet Explorer\IEXPLORE.EXE')

Alternately use subprocess.call() which takes a list of command-line parameters 
so it 
knows to quote the first arg:
   import subprocess
   subprocess.call([r'C:\Program Files\Internet Explorer\IEXPLORE.EXE'])

Also note that if you want to use paths with \ in them in Python strings you 
should use a 
raw string, otherwise the \ start escape sequences that you don't intend:
os.system(r'C:\Program Files\Internet Explorer\IEXPLORE.EXE')

Kent

PS please respond to the list.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running a .exe

2005-12-22 Thread Robin Buyer
Ahh. That helps a lot. Thanks.
-Robin
- Original Message -
From: Kent Johnson [EMAIL PROTECTED]
To: Python Tutor tutor@python.org
Sent: Thursday, December 22, 2005 7:46 PM
Subject: Re: [Tutor] running a .exe


 Robin Buyer wrote:
  I created a small program to test os.system:
 
  import os.path
  os.system(C:\Program Files\Internet Explorer\IEXPLORE.EXE)
 
  when i run this from the command line I get an error message:
  'C:\Program' is not recognized as an internal or external command,
operable
  program or batch file.
 
  How do you put spaces into a path name?

 The same way you do if you are typing the command directly to the shell -
put it in
 quotes. So now there are two sets of quotes - one to tell Python it is a
string, and one
 to pass to the shell:
 os.system('C:\Program Files\Internet Explorer\IEXPLORE.EXE')

 Alternately use subprocess.call() which takes a list of command-line
parameters so it
 knows to quote the first arg:
import subprocess
subprocess.call([r'C:\Program Files\Internet
Explorer\IEXPLORE.EXE'])

 Also note that if you want to use paths with \ in them in Python strings
you should use a
 raw string, otherwise the \ start escape sequences that you don't intend:
 os.system(r'C:\Program Files\Internet Explorer\IEXPLORE.EXE')

 Kent

 PS please respond to the list.

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor