Re: Is it that easy to install Python ?

2013-07-25 Thread Maarten
On Thursday, July 25, 2013 5:11:15 PM UTC+2, [email protected] wrote:
> Hi there,
> 
> I never write any Python program but as a system administrator, I'm often 
> asked to install python on Debian servers.
> 
> I just finished downloading, configuring, making and installing.
> 
> The binary is now installed in :
> /usr/local/Python-2.7.5/bin/python2.7
> (the path is a deliberate administrator choice).
> 
> Is that it?

Probably.

> What else will my users need?

The path must be search $PATH in the environment where Python is used, so that 
standard scripts starting with "#!/usr/bin/env python" will find your python.

Next your users will probably start requesting additional packages (regex, 
lxml, numpy, scipy, matplotlib, ... depending on what they actually do).

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


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Maarten
On Tuesday, July 24, 2012 4:35:29 PM UTC+2, Ben Finney wrote:
> Chris Angelico writes:
> 
> > […] Pi Day, has two different dates (the American and the European -
> > of course, here in Australia, we celebrate both).
> 
> What would be the two days? The 14th day of the 3rd month, and, um,
> what?
> 
> Or do you Australians have the third day of the fourteenth month?

You just missed it:
22/7

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


Re: [Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-08 Thread Maarten
On Tuesday, January 8, 2013 10:07:08 AM UTC+1, Terry Reedy wrote:

> With the line constrained to go through 0,0, a line eyeballed with a 
> clear ruler could easily be better than either regression line, as a 
> human will tend to minimize the deviations *perpendicular to the  line*, 
> which is the proper thing to do (assuming both variables are measured in 
> the same units).

In that case use an appropriate algorithm to perform the fit. ODR comes to 
mind. http://docs.scipy.org/doc/scipy/reference/odr.html

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


Re: advice, python for binary to xml

2013-01-31 Thread Maarten
On Thursday, January 31, 2013 2:33:48 PM UTC+1, noydb wrote:
> I'm looking for knowlegde about how best to go about converting a binary file 
> (from a GPS unit) to GPX/XML.  I am completely clueless on this, so any 
> start-from-the-beginning info would be greatly appreciated!  I'm guessing the 
> level of effort will be huge?

I assume that you've looked into GPSBabel? http://www.gpsbabel.org/

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


Re: advice, python for binary to xml

2013-01-31 Thread Maarten
On Thursday, January 31, 2013 4:05:43 PM UTC+1, noydb wrote:
> > I assume that you've looked into GPSBabel? http://www.gpsbabel.org/
> 
> Yes, I have.  Was hoping to use it, but client is very resistent to adding 
> such things to their system - python is desireable.  So what GPSbabel does is 
> what I need, just one translation, from Garmin's gdb file (binary) to gpx.

They realize that they'll get a much higher bill, and more bugs to boot?

I don't think there is an easy way around this, but at least you have some code 
to start reading gdb - as far as I know the GPSBabel sources are the only 
public description of the gdb file format. It is not trivial, but restricting 
yourself to the parts needed for the application may provide some shortcuts. 

Maarten - pay more, get less: way to go.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newb __init__ inheritance

2012-03-08 Thread Maarten
On Thursday, March 8, 2012 4:25:06 PM UTC+1, hyperboogie wrote:

> My question is if __init__ in the descendant class overrides __init__
> in the parent class how can I call the parent's __init__ from the
> descendant class - I just overrode it didn't I?
> 
> Am I missing something more fundamental here?

No, you're not. 

However, you can explicitly call the __init__() method of a particular class. 
Hard-coding the class gives you:

class A(object):
def __init__(self):
print("In A")

class B(A):
def __init__(self):
A.__init__(self)
print("In B")

Alternatively you can figure out the parent class with a call to super:

class C(A):
def __init__(self):
super(self.__class__, self).__init__()
print("In C")

a = A() (prints "In A")
b = B() (prints "In A", "In B" on two lines)
c = C() (prints "In A", "In C" on two lines)

Hope this helps.

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


Re: Newby Python Programming Question

2012-05-14 Thread Maarten
On Friday, May 11, 2012 5:25:20 PM UTC+2, Coyote wrote:

> I am migrating to Python after a 20+ year career writing IDL programs 
> exclusively. I have a really simple question that I can't find the answer to 
> in any of the books and tutorials I have been reading to get up to speed.

Welcome here.

> I have two programs. The first is in a file I named file_utils.py:
> 
>def pwd():
>import os
>print os.getcwd()

Move the import tot the root level of the file:

import os

def pwd():
print(os.getcwd())

(and print() is a function these days)

> The second is in a file I named pwd.py:
> 
>import os
>print os.getcwd()
> 
> Here is my question. I am using the Spyder IDE to run these programs. If I 
> type these commands, I get exactly what I want, the name of my current 
> directory.
> 
> But, if I "run" the pwd.py script by selecting the "Run" option from the IDE 
> menu, the directory is printed *twice* in the output window. Why is that?

I'd say this is a bug or feature of the IDE. If I use ipython I get:

In [1]: %run mypwd
/nobackup/users/maarten/tmp/coyote

I tried to use Eclipse, but I don't think I'll do that again. I otherwise never 
use an IDE, it makes me confused. I don't know what the IDE is doing. Note that 
there is a standard module (at least on unix/linux) with the name pwd, but I 
guess that the IDE is not confused.

I do recommend you read http://docs.python.org/howto/doanddont.html as a 
starting point to avoid learning some bad habits, especially on importing. You 
probably already found 
https://www.cfa.harvard.edu/~jbattat/computer/python/science/idl-numpy.html

For scripts that are intended to be run from the command line, I use:

#!/usr/bin/env python

import os
def pwd():
return os.getcwd()

if __name__ == "__main__":
print(pwd())

This will allow you to import the module (without side effects) and call the 
function, as well as 'running' the file. This increases the usefullness of the 
module. There are other advantages, especially when the scripts involves (many) 
variables.

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


Re: Design principles: no bool arguments

2011-08-25 Thread Maarten
On Aug 25, 9:13 am, Steven D'Aprano  wrote:
> One design principle often mentioned here (with a certain degree of
> disagreement[1]) is the idea that as a general rule, you shouldn't write
> functions that take a bool argument to switch between two slightly
> different behaviours.
>
> This is a principle often championed by the BDFL, Guido van Rossum.
>
> Here's a Javascript-centric article which discusses the same idea, and gives
> it a name: the Boolean Trap.
>
> http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html
>
> No doubt there are counter arguments as well. The most obvious to me is if
> the flag=True and flag=False functions share a lot of code, it is poor
> practice to implement them as two functions with two copies of almost
> identical code.

A simple one: C and C-like languages only have arguments, not keyword-
parameters. That alone makes a world of difference.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-26 Thread Maarten
On Thursday, September 26, 2013 11:31:29 AM UTC+2, Ferrous Cranus wrote:

> I have tried code and also provided alternative code to solve my problem 
> which also doesn't solve it.
> 
> So, you cannot accuse me that i'm not trying, that would be the case to 
> just ask for a line without trying anything for myself, which i did twice.

I'll accuse you of being a dimwit. The questions you ask do not show you 
trying. The code that _is_ posted is not straightforward or geared towards 
readability.

> Also when a solution is being provided to me i do not only want to use 
> it but want to understand too, so if something similar comes up i will 
> be in a position to solve it that time.

If you really want to do that, then why do you insist on one-liners? Write out 
the logic with a sequence of if statements. That is easy to understand, gives 
clearer error messages. The solution by Nobody is fairly foolproof, and the 
logic is clear. What's not to like? 

Maarten
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To whoever hacked into my Database

2013-11-08 Thread Maarten
On Friday, November 8, 2013 11:00:54 AM UTC+1, Ferrous Cranus wrote:

> I have never exposed my client's data. Prove otherwise.

'Hackers' enter your database. How is that not exposing client's data? Or is 
this just your development machine? That would prove you learnt at least 
something here.

Judging from the questions and the code quality you post here, it is only a 
matter of time before accidents happen.

Maarten
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread Maarten
On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote:
> I want to create a random float array of size 100, with the values in the 
> array ranging from 0 to 5. I have tried random.sample(range(5),100) but that 
> does not work. How can i get what i want to achieve?

Use numpy

import numpy as np
np.random.uniform(0, 5, 100)

# note that the values are from the interval [0, 5)

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


Re: Using SciPy in application

2013-04-24 Thread Maarten
On Wednesday, April 24, 2013 1:40:14 PM UTC+2, Robert Kern wrote:
> On 2013-04-24 17:04, Roozbeh wrote:
> 
> > On Wednesday, April 24, 2013 11:13:45 AM UTC+2, Roozbeh wrote:
> 
> >> Hi all, I want to use spline interpolation function from SciPy in an 
> >> application and at the same time, I don't want the end user to have to 
> >> install SciPy separately. Is there a way around this problem? Thanks in 
> >> advance for your help
> 
> > Any idea where can I find the recipe for the spline interpolation that does 
> > not rely on NumPy and/or SciPy and is written pure Python (no C code)?
> 
> 
> If Google can't find it, it probably doesn't exist. Very few people would do 
> this without numpy.

A trivial 'pure python spline' google search yields this:
http://urchin.earth.li/~twic/splines.py

(Warning: old code, python 2.2 era).

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


Re: Trying to understand the memory occupation of big lists

2013-05-03 Thread Maarten
I made a few changes:

import gc
from memory_profiler import profile

@profile
def test1():
a = [0] * 1024**2
del a
a = [0] * 1024**2
del a
a = [0] * 1024**2
del a
a = [0] * 1024**2
del a
a = [0] * 1024**2
del a
a = [0] * 1024**2
del a
a = [0] * 1024**2
del a
a = [0] * 1024**2
del a
a = [0] * 1024**2
del a
a = [0] * 1024**2
del a
gc.collect()  # nothing change if I comment this


@profile
def test2():
for i in range(10):
a = [0] * 1024**2
del a
del i
gc.collect()  # nothing change if I comment this


test1()
test2() 

# end of code

Output:

Filename: profile.py

Line #Mem usageIncrement   Line Contents

 5 @profile
 6 8.688 MB 0.000 MB   def test1():
 716.691 MB 8.004 MB   a = [0] * 1024**2
 8 8.688 MB-8.004 MB   del a
 916.680 MB 7.992 MB   a = [0] * 1024**2
1016.680 MB 0.000 MB   del a
1116.680 MB 0.000 MB   a = [0] * 1024**2
1216.680 MB 0.000 MB   del a
1316.680 MB 0.000 MB   a = [0] * 1024**2
1416.680 MB 0.000 MB   del a
1516.680 MB 0.000 MB   a = [0] * 1024**2
1616.680 MB 0.000 MB   del a
1716.680 MB 0.000 MB   a = [0] * 1024**2
1816.680 MB 0.000 MB   del a
1916.680 MB 0.000 MB   a = [0] * 1024**2
2016.680 MB 0.000 MB   del a
2116.680 MB 0.000 MB   a = [0] * 1024**2
2216.680 MB 0.000 MB   del a
2316.680 MB 0.000 MB   a = [0] * 1024**2
2416.680 MB 0.000 MB   del a
2516.680 MB 0.000 MB   a = [0] * 1024**2
2616.680 MB 0.000 MB   del a
2716.680 MB 0.000 MB   gc.collect()  # nothing change if I 
comment this


Filename: profile.py

Line #Mem usageIncrement   Line Contents

30 @profile
3116.691 MB 0.000 MB   def test2():
3216.691 MB 0.000 MB   for i in range(10):
3316.691 MB 0.000 MB   a = [0] * 1024**2
3416.691 MB 0.000 MB   del a
3516.691 MB 0.000 MB   del i
3616.691 MB 0.000 MB   gc.collect()  # nothing change if I 
comment this

If I make the two functions identical, the behave the same.

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


Re: Filename case-insensitivity on OS X

2006-01-04 Thread Maarten
Piet van Oostrum wrote:
> It seems that with Tiger, HFS+ can be made case-sensitive. I haven't seen
> it, only read about it.

Yes, indeed, that is possible. I tried it, once. Right now I'm using
the case insensitive version again, which should tell you how well it
works - the canon utilities of my camera refused to work for me, as did
Audacity. I didn't encounter any other problems, but that was enough
for me.

As to UFS: it is apparently way slower than HFS+, and only recommended
in special cases, most of which are now advised to use Case-sensitive
HFS+, I believe.

Maarten

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


Re: Python good for data mining?

2007-11-05 Thread Maarten
On Nov 5, 1:51 pm, Jens <[EMAIL PROTECTED]> wrote:
> On 5 Nov., 04:42, "D.Hering" <[EMAIL PROTECTED]> wrote:
>
> > On Nov 3, 9:02 pm, Jens <[EMAIL PROTECTED]> wrote:
>
> > I then leaned C and then C++. I am now coming home to Python realizing
> > after my self-eduction, that programming in Python is truly a pleasure
> > and the performance is not the concern I first considered to be.
> > Here's why:
>
> > Python is very easily extended to near C speed. The Idea that FINALLY
> > sunk in, was that I should first program my ideas in Python WITHOUT
> > CONCERN FOR PERFOMANCE. Then, profile the application to find the
> > "bottlenecks" and extend those blocks of code to C or C++. Cython/
> > Pyrex/Sip are my preferences for python extension frameworks.
>
> > Numpy/Scipy are excellent libraries for optimized mathematical
> > operations. Pytables is my preferential python database because of
> > it's excellent API to the acclaimed HDF5 database (used by very many
> > scientists and government organizations).
>
> So what you're saying is, don't worry about performance when you start
> coding, but use profiling and optimization in C/C++. Sounds
> reasonable. It's been 10 years ago since I've done any programming in C
> ++, so I have to pick up on that soon I guess.

"Premature optimization is the root of all evil", to quote a famous
person. And he's right, as most people working larger codes will
confirm.

As for pytables: it is the most elegant programming interface for HDF
on any platform that I've encountered so far. Most other platforms
stay close the HDF5 library C-interface, which is low-level, and quite
complex. PyTables was written with the end-user in mind, and it shows.
One correction though: PyTables is not a database: it is a storage for
(large) arrays, datablocks that you don't want in a database. Use a
database for the metadata to find the right file and field within that
file. Keep in mind though that I mostly work with externally created
HDF-5 files, not with files created in pytables. PyTables Pro has an
indexing feature which may be helpful for datamining (if you write the
hdf-5 files from python).

Maarten

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


Re: Why the inconsistent of those two base64 methods?

2010-05-12 Thread Maarten
On May 12, 6:04 am, Leo Jay  wrote:
> I'd like to encode a string in base64, but I found a inconsistent of
> two methods:
>
> >>> 'aaa'.encode('base64')
> 'YWFh\n'
> >>> import base64
> >>> base64.b64encode('aaa')
> 'YWFh'
>
> as you can see, the result of
> 'aaa'.encode('base64')
> has a '\n' at the end, but the other method doesn't.
>
> Why the inconsistent?

Don't know. Does it matter?

>>> import base64
>>> base64.decodestring(base64.b64encode('aaa'))
'aaa'

>>> 'aaa'.encode('base64').decode('base64')
'aaa'

(so far so good, and as expected)

>>> base64.decodestring('aaa'.encode('base64'))
'aaa'

>>> base64.b64encode('aaa').decode('base64')
'aaa'

(As far as I can see, both methods are completely consistent)

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


Re: modifiable config files in compiled code?

2005-03-11 Thread Maarten Sneep
In article <[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> Since this utility will also be ported to the linux world, does anyone
> know what the linux/unix counterpart of a Windows .INI configuration
> file is?

ConfigParser works on Linux and Mac as well. Configuration files on 
Linux/Unix have a high 'roll your own' value: the format basically 
depends on the needs of the program.

> I suppose I could get away with using XML for my config files and avoid
> having two different tools altogether.

I think you could do worse than adopt the Apple .plist format. There 
is already a pure python module for these:

   http://sarwat.net/opensource/

The advantage of the plist module is that the type of the variables is 
stored as well, and that you can store complex variables (lists, 
dictionaries) without mangling.

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


Re: regarding ignore case sensitive of a string using regular expressions

2005-03-22 Thread Maarten Sneep
Mosas wrote:

>   In Perl when we are checking some conditions
> using regular expression we can ignore the case
> sensitive of a string using the following regular 
> expression  /(^[^a-z])|/|(\.\.)/i.
>   But If I try to do this in Python I couldn't get
> any result.
>   So Any body know regarding this Kindly mail me
> with example.

RTFM: http://www.python.org/doc/2.3.4/lib/re-syntax.html
(What you want is described under the (?iLmsux) heading)
or http://www.python.org/doc/2.3.4/lib/node106.html

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


Re: trouble using \ to escape %

2005-04-15 Thread Maarten Sneep
In article <[EMAIL PROTECTED]>,
 "Lucas Machado" <[EMAIL PROTECTED]> wrote:

> I'm writing a python script that modifies the smb.conf file, and i need
> to write the characters '%U' in the file.  

print "%s = %%U" % "a" yields a = %U for me.

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


distutils, PyBison and Mac OS X

2005-04-18 Thread Maarten Sneep
I'm trying to build PyBison[1] on Mac OS X, and I'm running into some
problems with the distutils.

Just for starters: PyBison requires Pyrex[2]. This is not a problem,
and Pyrex seems to work without problems, at least the primes sample
module shows a nice 25 to 30 fold speed increase over the pure python
version.

I used the distutils to create the module from the primes.pyx sample,
following the setup.py from the PyBison distrubution:

[code]
from distutils.core import setup, Extension
from Pyrex.Distutils import build_ext

setup( name = "primes", version = "1.0",
  description="Pyrex sample for calculating prime numbers",
  author='Greg Ewing', 
  url='http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/',
  ext_modules=[Extension("primes", ["primes.pyx"])],
  cmdclass = {'build_ext': build_ext}
)
[/code]

I mention this, because PyBison seems to use the distutils to compile
the bison and flex source code on the fly, but fails to pick up some
parameters, which prevents it from working correctly.

Although Mac OS X uses gcc, and is an otherwise pretty complete unix
install, it is missing some components: shared libraries are not
linked with -shared but use -bundle instead. A succesful build of
primes is linked with:

export MACOSX_DEPLOYMENT_TARGET=10.3; gcc -Wl,-F. -Wl,-F. \
-bundle -undefined dynamic_lookup \
build/temp.darwin-7.9.0-Power_Macintosh-2.3/primes.o \
-o primes.so

(Another difference that caused major headaches: the absense of a
'dl' library has been resolved with version 10.3 ("Panther"). A dl
library is included as a wrapper around the bundles mechanism that
were present all along. Since the linux version uses the dl library,
I tried to compile the same source, and that part seems to run just
fine).

The issues: 

- distutils.ccompiler uses the unixcompiler, which has hard coded a
  cc -shared to create shared objects. I've tried to override this,
  but no luck there (other issues seem to crop up). Is this a known
  issue with distutils?
  
  I installed pybison using the linux C-source, and tried it out
  using the 'calc' example. After setting verbose=1 in the run.py,
  and enabling the "int lineno = 0" in calc.py, the compilation phase
  finishes without a hitch, but linking fails badly:
  
bisonCmd=['bison', '-d', '-v', '-t', 'tmp.y']
renaming bison output files
tmp.tab.c => tmp.bison.c
tmp.tab.h => tokens.h
cc: unrecognized option `-shared'
ld: Undefined symbols:
_main
_PyInt_FromLong
_PyObject_GetAttrString
_PyObject_HasAttrString
_PyObject_SetAttrString
_PyString_AsString
_PyString_FromString
_PyTuple_New
_PyTuple_SetItem
__Py_NoneStruct
Traceback (most recent call last):
  File "run.py", line 7, in ?
parser = calc.Parser(verbose=1, keepfiles=1)
  File ". . ./python2.3/site-packages/bison.py", line 308, 
in __init__ self.engine = ParserEngine(self)
  File "bison_.pyx", line 187, in bison_.ParserEngine.__init__
  File "bison_.pyx", line 202, in 
bison_.ParserEngine.openCurrentLib
  File "bison_.pyx", line 540, in bison_.ParserEngine.buildLib
  File ". . ./python2.3/distutils/ccompiler.py", line 843, 
in link_shared_object extra_preargs, extra_postargs, 
build_temp, target_lang)
  File ". . ./python2.3/distutils/unixccompiler.py", line 178, 
in link raise LinkError, msg
distutils.errors.LinkError: command 'cc' failed with exit status 1
  
- Would it be possible to modify PyBison to use a call to the 
  distutils.core.setup(. . .) function and call that as if 'python 
  setup.py build_ext --inplace' had been called from the command line, 
  since that seems to pick up the correct options.
  
- Where do I start: distutils is pretty large, and it seems to have
  the right options, but they just aren't used in PyBison.

Thanks in advance for any insights that get me going,

Maarten

Links:
[1] http://www.freenet.org.nz/python/pybison/
[2] http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't compile with --enable-shared on MacOSX

2005-04-18 Thread Maarten Sneep
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Lothar Scholz) wrote:

> i tried to generate a dynamic library from the official
> Python-2.4.0.tgz on MacOSX 10.3 but when i do the
> 
> ./configure --enable-shared ; make ; sudo make install
> 
> It links statically. It's also strange that i can't find a
> libpython2.4.a in my
> /usr/local/lib. It's not installed by the install command.

On Mac OS X the shared library functionality is obtained through 
frameworks. It may detect this by default, but I'm not sure about 
that. In any case read the install documentation, the correct options 
are mentioned there, or you could just use the pre-built binary 
install from python.org

> I get an error that TK/TCL was not found. Is this the reason, i
> thought i can simply ignore this error message.

Is not the reason, will go away once tcl/tk is installed (there is a 
nice binary installer in the mac os x downloads section at apple.com

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


Re: DIAGNOSIS: Racism moves back to Denmark from South Africa

2007-10-19 Thread Maarten Bergvelt
On 2007-10-19, mich <[EMAIL PROTECTED]> wrote:
>
><[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>>
>> INCISIVE ANALYSIS: The dismantlement of Apartheid Regime in South
>> Africa sent the racist Dutch Afrikaners back to Denmark where they are
>> spreading their racist ideology -- The Apartheid "Christianity" :
>
>
> The Dutch went back to Denmark? 

Sure, Copenhagen is the capital of the Netherlands, any American
school child knows that.

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


Re: how to improve simple python shell script (to compile list of files)

2005-10-15 Thread Maarten van Reeuwijk
Jari Aalto wrote:

> 
> [Keep CC, thank you]
> 
> Please suggest comments how can I make this script to work
> from bash. Also how can I skip better the [0] argument from
> command line without hte extra variable i?

Didn't check, but something like this?

#!/bin/python
import os, sys, py_compile;
i = 0;
for arg in sys.argv:
  file  = os.path.basename(arg);
  dir   = os.path.dirname(arg);
  i += 1;
  if i > 1  and os.path.exists(dir):
  os.chdir(dir);
 print "compiling %s\n" % (file);
 py_compile.compile(file);

-- 
===
Maarten van Reeuwijkdept. of Multiscale Physics
Phd student Faculty of Applied Sciences
maarten.ws.tn.tudelft.nl Delft University of Technology
-- 
http://mail.python.org/mailman/listinfo/python-list


cgi and popen

2006-06-07 Thread Maarten van Veen
A long story made short, I've build a python/cgi website consisting of 
two pages. Page1 has a html form in which you can input a series of 
queries. Then via Popen it starts a pythons search script, which stores 
the results in a python shelve.
As the Popen command is given it should redirect to page2, which will 
check if the shelve is ready (search finished) and if not displays a 
search page, refreshing itself after 10 seconds.
The Popen command works nice when tried out in the console. The script 
isueing the Popen quits, and the other process keeps on running till 
finished.
But when embedded in page1.cgi, page 1 waits till the search is 
finished, resulting in a browser timeout when big queries are done. It 
was this problem in the first place why I split up the page in two and 
added Popen.
Does anybody know how to get the page not waiting on Popen to finish?

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


Re: cgi and popen

2006-06-07 Thread Maarten van Veen
In article <[EMAIL PROTECTED]>,
 Thomas Guettler <[EMAIL PROTECTED]> wrote:

> Am Wed, 07 Jun 2006 14:54:41 +0200 schrieb Maarten van Veen:
> 
> > A long story made short, I've build a python/cgi website consisting of 
> > two pages. Page1 has a html form in which you can input a series of 
> > queries. Then via Popen it starts a pythons search script, which stores 
> > the results in a python shelve.
> > As the Popen command is given it should redirect to page2, which will 
> > check if the shelve is ready (search finished) and if not displays a 
> > search page, refreshing itself after 10 seconds.
> > The Popen command works nice when tried out in the console. The script 
> > isueing the Popen quits, and the other process keeps on running till 
> > finished.
> 
> Hi,
> 
> You can find out where the process hangs, by
> sending SIGINT to the python script:
> 
> kill -SIGINT PID
> 
> This is like ctrl-c, you should get a traceback.
> 
> If the page1 script is not alive anymore, during
> the unwanted waiting, this does not work.
> 
> Which form of popen do you use? Popen4 is the best,
> because you cannot get a deadlock if there is output
> on stdout and stderr.
> 
> I guess you have the same strange thing, if you
> ssh to the server, start the script1 and you want
> to logoff before the subprocesses is finished.
> 
> You can try to start the script like this:
> 
> nohup nice mein-script >> $HOME/log/mein-script.log 2>&1  
>  HTH,
>   Thomas

Thx for your reply Thomas. I use subprocess.Popen, because popen 1t/m 4 
are deprecated. 
I found a dodgy way around my problem though. By inserting another page 
between the input and the results page,a user sees a "i'm searching" 
page which wants to redirect to the results page directly, but keeps 
waiting for the search process to finish.
So I put what used to be my problem to good use. :D

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


Re: creating and naming objects

2006-06-07 Thread Maarten van Veen
In article <[EMAIL PROTECTED]>,
 "Brian" <[EMAIL PROTECTED]> wrote:

> I have a question that some may consider silly, but it has me a bit
> stuck and I would appreciate some help in understanding what is going
> on.
> 
> For example, lets say that I have a class that creates a student
> object.
> 
> Class Student:
> def setName(self, name)
> self.name = name
> def setId(self, id)
> self.id = id
> 
> Then I instantiate that object in a method:
> 
> def createStudent():
> foo = Student()
> /add stuff
> 
> Now, suppose that I want to create another Student.  Do I need to name
> that Student something other than foo?  What happens to the original
> object?  If I do not supplant the original data of Student (maybe no id
> for this student) does it retain the data of the previous Student
> object that was not altered?  I guess I am asking how do I
> differentiate between objects when I do not know how many I need to
> create and do not want to hard code names like Student1, Student2 etc.
> 
> I hope that I am clear about what I am asking.
> 
> Thanks,
> Brian

Hi Brian,

If you would do it like this:
Class Student:
def setName(self, name)
self.name = name
def setId(self, id)
self.id = id


def createStudent():
foo = Student()
foo.setName("Brian")
foo = Student()
print foo.getName()

You would get an error here, because foo now equals the second Student 
object which has no name. And you can't get to the first one. 
Perhaps you could do something like this.

Class Student:
def setName(self, name)
self.name = name
def setId(self, id)
self.id = id

listWithStudents = []

def createStudent():
listWithStudent.append(Student())

Now every student you create is put in the list with students so you can 
access them but don't have to give them names.
You could do something to all of them like this:
for student in listWithStudent:
   student.doSomething()

Or change just one student:
listWithStudent[23].doSomething()  # this is the 24th student though!!!

Hope this is what you're looking for.
Maarten
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About alternatives to Matlab

2006-11-17 Thread Maarten van Reeuwijk
sturlamolden wrote:

> Sorry Mathworks, I have used your product for years, but you cannot
> compete with NumPy.

Funny. I went exactly the other way. Had a full OO postprocessing library
for Python/Scipy/HDF etc which worked brilliantly. Then changed to a 64 bit
machine and spent three days trying to install all the additional libraries
that I had become dependent on over the year. In the end, I gave up
completely frustrated (something to do with a Fortran compiler in
combination with SciPy or something). Then I tried MATLAB  and was
completely delighted that there was a program with all MY batteries
included :-).

BTW, I have the impression that MATLAB and SciPy have about the same
performance.

Cheers, Maarten
-- 
===
Maarten van Reeuwijkdept. of Multiscale Physics
Phd student Faculty of Applied Sciences
maarten.vanreeuwijk.net  Delft University of Technology
-- 
http://mail.python.org/mailman/listinfo/python-list