Nicola Larosa just mentioned “this little script”:http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Tools/scripts/crlf.py?view=markup on the “EDU-SIG”:http://mail.python.org/mailman/listinfo/edu-sig mailing list to convert CRLF line endings to LF. I didn’t know pre-written scripts like these existed in the Python distribution, and hadn’t got far enough learning Python to write one of my own. Very useful ![]()
Entries Tagged 'Python' ↓
Python script to replace CRLF with LF
April 11th, 2005 — Python
Python is… slow?
December 21st, 2004 — Physics, Python
One of the work items that kept me occupied over the past week was writing a computational physics simulation modelling “quantum potential wells using a Monte Carlo simulation”:http://www.phys.soton.ac.uk/teach/year3/notes/ph314/projects/pjtb2.pdf.
I chose to write the simulation in “Python”:http://www.python.org instead of C - my feeling was this would be quicker to get a working simulation with, and I could always rewrite in C if it was very slow. i didn’t expect it to be - I’d read a lot of reports about Scientists using Python, so figured it would fine. I also picked Python as this would force me to learn the language, something that if I pursue “a particular route”:http://www.ses.soton.ac.uk/projects/Comp_Eng_Des/comp_eng_des.html after graduating would be very useful.
Due to some problems, the lecturer overseeing this simulation ended up writing the simulation also, in the departmental version of Basic.
At that point I realised how slow the Python code was. I didn’t expect it to be as fast as C, but was surprised by how much faster the Basic version was. It wasn’t impossibly slow, but running a million random walks of up to 300 steps was taking nearly 2 hours to complete. I tried plugging in Psyco to speed up the Python code, without much luck.
I don’t know if there were ways to get the Python code faster (short of using Pyrex), but I’m posting the code here to see what people think. Given it was the first proper Python program I’ve done I expect it to be a bit slow, but wasn’t expecting it to be this much slower.
One other point that came out was that the Python code produced a greater scatter on the results than the Basic version. I think this has to come down to the random number generator, but thoughts on this would be appreciated as well.
To the code:
* “Python code for a 1 dimensional potential well”:/physics/simulations/rand_walks_qm/1D_0.py
* “New Forest Basic code for a 1 dimensional potential well”:/physics/simulations/rand_walks_qm/1D_0.nfb (slightly more basic than mine - walks aren’t killed after X steps, but continue to arrest). You’ll also need the editor/compiler/interpreter (”Windows”:http://www.phys.soton.ac.uk/teach/year2/notes/lab/software/nfbwin.exe or “Linux”:http://www.phys.soton.ac.uk/teach/year2/notes/lab/software/nfblnx) - which in turn requires “TCL”:http://www.tcl.tk/ to be installed.
* Python code for a 2 dimensional potential well (”ground state”:/physics/simulations/rand_walks_qm/2D_0.py , “first potential”:/physics/simulations/rand_walks_qm/2D_1.py , “second potential”:/physics/simulations/rand_walks_qm/2D_2.py ). Note that this code does not relate well to the real values expected; I didn’t work out what the problem was before I had to hand in the report.
I just ran across dirtSimple’s post “The perception of speed”:http://dirtsimple.org/2004/12/perception-of-speed.html today, so it seems I’ve written this post at a time when the subject’s topical ![]()
Learning Python
June 24th, 2004 — Python
Having free time I decided to convert one of my _”Hmmm that would make a good program”_ ideas into reality. Phase 1 involves navigating a website to download a file; phase 2 involves parsing this file.
Phase 2 involves a GUI and I felt, coming from my PHP background, that using Python for this would be simpler than learning C++ (which I’ve done a little of), Java or Delphi. From my reading I believe the overall speed of development should be faster (and hopefully the time required to learn the langauge should be less) - very important if, like me, you are brimming with ideas but don’t usually have the commitment/patience to finish them!
After a couple of days searching I found (via the #python room on irc.freenode.net) a library that should do phase 1: “mechanize”:http://wwwsearch.sourceforge.net/mechanize/. So I install it, open PythonWin, and set about trying to write a script.
To date I’m not having much luck with this library. I’d like to say this was due to the lack of documentation and the horrendously “crap website”:http://www.bt.com that I’m trying to log into and navigate, but I’m sure most of the problem lies with my lack of Python skills ![]()
I’m finding it much harder to pick up Python than I expected
Like (and this is coloured by my playing with mechanize) how do you know when a method returns an object, when does it modify itself [i.e. when do I need @f = b.x()@, then @g = f.y()@ - and when @b.x()@ then @b.y()@?]? This has been a big puzzler with mechanize. How do you tell the return values (ie an object, tuple, string etc.) to expect? There seems to be no equivalent of PHPDoc/JavaDoc where the return values are listed. I find the “Python library reference”:http://www.python.org/doc/lib/ much harder to understand than the “PHP documentation”:http://www.php.net/manual/en/
I have a copy of “Python in a Nutshell”:http://www.amazon.co.uk/exec/obidos/ASIN/0596001886 and the “Python Cookbook”:http://www.amazon.co.uk/exec/obidos/ASIN/0596001673/peterswebpage08 - neither of which are beginners’ books (which is why I bought them: I don’t consider myself a beginner as I can program, albeit in PHP and Prolog rather than proper, well-respected langauges. Stop sniggering, you in the back row - Prolog wasn’t my choice!). Can anyone recommend anything else?
[Mood: frustrated]
Fast vectors in Python
November 25th, 2003 — Python
numarray (new version of Numeric Python)
Looks very cool - I wonder how fast it is compared with Matlab?
Anyone know of other Python libraries to make it “compete” with Matlab (i.e. for curve fitting etc)? I *hate* Matlab so any other environment I could use instead would be excellent.
The problem with python
July 10th, 2003 — Python
John Lim posted some interesting comments about python in his comment on ArsDigita: An Alternate Perspective.
For me the problem with python is that it’s such a clean language. It makes me think about design. Not a bad idea, but when trying to write a quick program (OK, a dirty hack) it gets in the way. Gimme PHP for that kind of stuff any day ![]()
Mind you, I still think it’s a great language, and look forward to using it lots more in future - particularly in conjunction with PythonCard.