Re: Get IP address of WIFI interface

2011-05-13 Thread Ishwor Gurung
Hi.

On 14 May 2011 14:46, Far.Runner  wrote:
> Hi Python Experts:
> There are two network interfaces on my laptop, one is
> 100M Ethernet interface, the other is wifi interface, both are connected and
> has an IP address. then the question is: how to get the ip address of the
> wifi interface in a python script?
> OS: Windows or Linux

Detect the OS with os.name and branch out to specific use case.

The specific functionality can be implemented 2 ways:
1/ Regular expression pattern match
2/ Substring match and splits

The subprocess module will then let you run those commands.
1/ posix - (Linux in your case) will use ifconfig
2/ nt - (windows in your ase) will use ipconfig.

HTH.



-- 

Regards
Ishwor Gurung
Key id:0xa98db35e
Key fingerprint:FBEF 0D69 6DE1 C72B A5A8  35FE 5A9B F3BB 4E5E 17B5
-- 
http://mail.python.org/mailman/listinfo/python-list


hello all

2004-12-03 Thread Ishwor Gurung
Hello all,
  I am just starting out on learning Python and joined this list. I
have grabbed the Learning Perl book by Mark & David. This book really
seems good so far.. the concepts are explained pretty nicely. :) I
have a background a bit in Java but Python seems so cooler. The
concept of Dynamically assigning values n the objects springing into
existence is really nice to see especially you don't have to declare
variable everytime its used. In this book though it says Python 3.0 as
upcoming python version but all i see so far is Python 2.4 ?? Any
hints anyone has? So contrasting with Java  which is a bit like C++
where values and object has to be "created" before assigning, Python
seems very typical of "on the edge" language, "ready to go" language
:)
cheers,
Ishwor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: window size in IDLE

2004-12-03 Thread Ishwor Gurung
hi kosina although i am new to this list as well, please CC to the
python list as well. That way not only 'we' but everyone benefits. :)

On Fri, 03 Dec 2004 11:30:06 +0100, gen2n <[EMAIL PROTECTED]> wrote:
> Thanks a lot. Could you help me once more with beginners question?
> In IDLE, when saving a file, I have to always add .py to to name. Otherwise
> it didnt work then.
> Could it also be somehow automatically?

 I don't really understand what you mean by 'automatically' but i
tried the following in my machine :

test ( i didn't put .py as extension to test)
*
print "Hello";

Then at the prompt i did
python test

hello 

It seems that it works for me both at the prompt (using Python
interpreter as well as in IDLE's Run > Run Module (F5)
 :)
> I have IDLE 1.0.2.

IDLE 1.1 is pretty good. If you have chance grab it :)
[snip]
 
cheers,
Ishwor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple python installations on opensuse?

2009-12-17 Thread Ishwor Gurung
2009/12/17 Johan Ekh :
> Hi all,
> I use the finite element package ABAQUS that is partly built around python
> 2.4.3.
> ABAQUS ships with its own version of python 2.4.3 but it comes without third
> party
> libraries, e.g. numpy and scipy. In order to load these modules into ABAQUS
> python
> I must install python 2.4.3. on my opensuse laptop. How can I do this
> without interference
> with my python 2.6 installation that I use for all my non-ABAQUS python
> work?

Go to python.org, and download appropriate source (shjould be one for
2.4 final release).

$ mkdir $HOME/my2.4build/
$ ./configure --prefix=$HOME/my2.4build && make && make install;


To run-
$ cd $HOME/my2.4build/bin
$ ./python

I am assuming you've got the C/C++ libraries installed.
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Multiple python installations on opensuse?

2009-12-17 Thread Ishwor Gurung
Scipy needs various libraries. On Ubuntu (which I use) -

Depends: python (< 2.7), python (>= 2.5), python-central (>= 0.6.11),
 python-numpy (>= 1:1.2.0), libblas3gf | libblas.so.3gf |
 libatlas3gf-base, libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libgfortran3
 (>= 4.3), liblapack3gf | liblapack.so.3gf | libatlas3gf-base,
 libstdc++6 (>= 4.1.1), libsuitesparse-3.2.0 (>= 1:3.2.0)

So, doing a source/binary install similarly and then install Scipy again.

-- Forwarded message --
From: Johan Ekh 
Date: 2009/12/17
Subject: Re: Multiple python installations on opensuse?
To: Ishwor Gurung 


Thanks guys,
I installed it as root without the --prefix option using "make
altinstall" instead of "make install".
It worked and I can now execute python2.4.6 with "python2.4 while
python2.6 is still executed
with "python".

I also managed to install numpy with "python2.4 setup.py install".
However, installing scipy
in the same way failed with the error below. Most of my libraries
appears to be in /usr/lib64/
or /usr/local/lib64 and the install script can't find them because it
searched /usr/lib/ and /usr/local/lib/.

How can I fix this?

Sorry for newbiesh questions...

//Johan

== Output from "python2.4 setup.py install"

Warning: No configuration returned, assuming unavailable.
blas_opt_info:
blas_mkl_info:
  libraries mkl,vml,guide not found in /usr/local/lib
  libraries mkl,vml,guide not found in /usr/lib
  NOT AVAILABLE

atlas_blas_threads_info:
Setting PTATLAS=ATLAS
  libraries ptf77blas,ptcblas,atlas not found in /usr/local/lib
  libraries ptf77blas,ptcblas,atlas not found in /usr/lib
  NOT AVAILABLE

atlas_blas_info:
  libraries f77blas,cblas,atlas not found in /usr/local/lib
  libraries f77blas,cblas,atlas not found in /usr/lib
  NOT AVAILABLE

/usr/local/lib/python2.4/site-packages/numpy/distutils/system_info.py:1340:
UserWarning:
    Atlas (http://math-atlas.sourceforge.net/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [atlas]) or by setting
    the ATLAS environment variable.
  warnings.warn(AtlasNotFoundError.__doc__)
blas_info:
  libraries blas not found in /usr/local/lib
  libraries blas not found in /usr/lib
  NOT AVAILABLE

/usr/local/lib/python2.4/site-packages/numpy/distutils/system_info.py:1349:
UserWarning:
    Blas (http://www.netlib.org/blas/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [blas]) or by setting
    the BLAS environment variable.
  warnings.warn(BlasNotFoundError.__doc__)
blas_src_info:
  NOT AVAILABLE

/usr/local/lib/python2.4/site-packages/numpy/distutils/system_info.py:1352:
UserWarning:
    Blas (http://www.netlib.org/blas/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [blas_src]) or by setting
    the BLAS_SRC environment variable.
  warnings.warn(BlasSrcNotFoundError.__doc__)
Traceback (most recent call last):
  File "setup.py", line 92, in ?
    setup_package()
  File "setup.py", line 84, in setup_package
    configuration=configuration )
  File "/usr/local/lib/python2.4/site-packages/numpy/distutils/core.py",
line 150, in setup
    config = configuration()
  File "setup.py", line 54, in configuration
    config.add_subpackage('scipy')
  File "/usr/local/lib/python2.4/site-packages/numpy/distutils/misc_util.py",
line 851, in add_subpackage
    caller_level = 2)
  File "/usr/local/lib/python2.4/site-packages/numpy/distutils/misc_util.py",
line 834, in get_subpackage
    caller_level = caller_level + 1)
  File "/usr/local/lib/python2.4/site-packages/numpy/distutils/misc_util.py",
line 781, in _get_configuration_from_setup_py
    config = setup_module.configuration(*args)
  File "scipy/setup.py", line 8, in configuration
    config.add_subpackage('integrate')
  File "/usr/local/lib/python2.4/site-packages/numpy/distutils/misc_util.py",
line 851, in add_subpackage
    caller_level = 2)
  File "/usr/local/lib/python2.4/site-packages/numpy/distutils/misc_util.py",
line 834, in get_subpackage
    caller_level = caller_level + 1)
  File "/usr/local/lib/python2.4/site-packages/numpy/distutils/misc_util.py",
line 781, in _get_configuration_from_setup_py
    config = setup_module.configuration(*args)
  File "scipy/integrate/setup.py", line 10, in configuration
    blas_opt = get_info('blas_opt',notfound_action=2)
  File "/usr/local/lib/python2.4/site-packages/numpy/distutils/system_info.py",
line 267, in get_info
    return cl().get_info(notfound_action)
  File "/usr/local/lib/python2.4/site-packages/numpy/distutils/system_info.py",
line 

Re: Multiple python installations on opensuse?

2009-12-17 Thread Ishwor Gurung
2009/12/17 Johan Ekh :
> But I have them installed already! I have scipy installed under python 2.6
> and everything runs perfect.

ok

> It is only under python 2.4 that the install script can not find the
> libraries. I need to tell the script to
> lookin /usr/lib64 instead /usr/lib, how can I do this?

As root, tell linker to look for libraries in /usr/lib64:
$ echo /usr/lib64 >> /etc/ld.so.conf
$ ldconfig
$ ./configure

Please send email to the mailing list. I am subscribed to it :>

[...]
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prepend to logging message

2010-01-09 Thread Ishwor Gurung
Joan,

2010/1/10 Joan Miller :
> How to prepend anything to a logging message? Is possible to do it
> from the dictionary object (ExtraLog) or is there is that override
> process() [1]?
>
> --
> class ExtraLog(object):
>
>    def __getitem__(self, name):
>        if name == 'foo':
>            result = 'testing'
>        return result
>
>    def __iter__(self):
>        keys = ['foo',]
>        keys.extend(self.__dict__.keys())
>        return iter(keys)
>
> logger = logging.LoggerAdapter(logging.getLogger('foo'), ExtraLog())
> --

Yep. Just subclass LoggerAdapter and override process(..)
Read this: 
http://docs.python.org/library/logging.html#adding-contextual-information-to-your-logging-output
--
Regards
Ishwor Gurung
Key id:0xa98db35e
Key fingerprint:FBEF 0D69 6DE1 C72B A5A8  35FE 5A9B F3BB 4E5E 17B5
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to schedule system calls with Python

2009-10-15 Thread Ishwor Gurung
Jeremy,
Hi

> I need to write a Python script that will call some command line
> programs (using os.system).  I will have many such calls, but I want
> to control when the calls are made.  I won't know in advance how long
> each program will run and I don't want to have 10 programs running
> when I only have one or two processors.  I want to run one at a time
> (or two if I have two processors), wait until it's finished, and then
> call the next one.

Right.

> How can I use Python to schedule these commands?
If I were as lucky as you, I would have used multiprocessing module[1]
(my platform does not have sem_open() syscall). Others suggestions are
as good as it can be but yeah you could get a lot of work done using
multiprocessing module(all the relevant bits are explained in the
module doc).

[1] http://docs.python.org/library/multiprocessing.html
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to schedule system calls with Python

2009-10-15 Thread Ishwor Gurung
>> How can I use Python to schedule these commands?
> If I were as lucky as you, I would have used multiprocessing module[1]
> (my platform does not have sem_open() syscall). Others suggestions are
s/have/implement/g

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


Re: How to schedule system calls with Python

2009-10-15 Thread Ishwor Gurung
>> How can I use Python to schedule these commands?
> If I were as lucky as you, I would have used multiprocessing module[1]
> (my platform does not have sem_open() syscall). Others suggestions are
> as good as it can be but yeah you could get a lot of work done using
> multiprocessing module(all the relevant bits are explained in the
> module doc).
My bad, I assumed Win32. Make sure _your_ platform also supports
sem_open syscall before you used the core feature of multiprocessing
module. >.<
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a splitting headache

2009-10-15 Thread Ishwor Gurung
Hi

2009/10/16 Mensanator :
> All I wanted to do is split a binary number into two lists,
> a list of blocks of consecutive ones and another list of
> blocks of consecutive zeroes.
Just briefly looked at your problem. Try this:
http://www.builderau.com.au/program/python/soa/Run-length-encoding-in-Python/0,264084,339280649,00.htm

[...]
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a splitting headache

2009-10-15 Thread Ishwor Gurung
2009/10/16 Paul Rubin <http://phr...@nospam.invalid>:
[...]
> You might also like:
>
>    from itertools import groupby
>    c = '001110'
>    print list(list(xs) for k,xs in groupby(c))
Too bad groupby is only available in Python2.6+
Since you're here, any chance of getting your NDK team to look into
getting some small subset of STL, Boost into Android? :-P That'd be
awesome thing you know.
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a splitting headache

2009-10-15 Thread Ishwor Gurung
2009/10/16 Ishwor Gurung :
> 2009/10/16 Paul Rubin <http://phr...@nospam.invalid>:
> [...]
>> You might also like:
>>
>>    from itertools import groupby
>>    c = '001110'
>>    print list(list(xs) for k,xs in groupby(c))
> Too bad groupby is only available in Python2.6+
OK. I stand corrected ;-)

> Since you're here, any chance of getting your NDK team to look into
> getting some small subset of STL, Boost into Android? :-P That'd be
> awesome thing you know.
Yeah? Anything forthcoming in the releases to address this? thanks.
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a splitting headache

2009-10-15 Thread Ishwor Gurung
I think I am getting old :-( Should have Googled already.

> My what who where?  You are confusing me with someone else.
Andy Rubin- http://en.wikipedia.org/wiki/Andy_Rubin

Sorry to bother you.
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to knock a page out of file cache

2009-10-21 Thread Ishwor Gurung
[...]
> I thought of simply opening and writing to the file to dirty it's
> pages, but there no guarantee that pdflush will have already written
> the dirty pages to disk -pretty sure it depends on all the dirty ratio
> and intervals.
>
> Does anybody know of a system call that will 'knock' the file out of
> file cache?  Can madvise or fadvise do this?

Does this help http://www.westnet.com/~gsmith/content/linux-pdflush.htm ?
(Getting hold of procfs and doing it in Python?)

Also, are you looking for sync(2) http://linux.die.net/man/2/sync?

[...]
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to knock a page out of file cache

2009-10-21 Thread Ishwor Gurung
[...]

> Also, are you looking for sync(2) http://linux.die.net/man/2/sync?

Also, maybe mmap.flush([offset, size]) @
http://docs.python.org/library/mmap.html ?
Get the file, mmap it and flush it. The docs has more info on flush(...)

Afaik, ultimately the kernel will control the writebacks of dirty
pages and their frequency of writebacks.
So if you want the shortest path, you can choose to go the /proc path.

[...]
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing deadlock

2009-10-24 Thread Ishwor Gurung
Hi Brian,
I think there could be a slight problem (if I've understood your code).

> import multiprocessing
> import queue
>
> def _process_worker(q):
>    while True:
do you really want to run it indefinitely here?

>        try:
>            something = q.get(block=True, timeout=0.1)
>        except queue.Empty:
>            return
So, if your queue is empty, why do you want to just return?

>        else:
>            print('Grabbed item from queue:', something)
>
>
> def _make_some_processes(q):
>    processes = []
>    for _ in range(10):
This is going to loop q*10 many times. Do you really want that?

>        p = multiprocessing.Process(target=_process_worker, args=(q,))
OK.
>        p.start()
>        processes.append(p)
Here. Do you want to add it to processes list? why?

>    return processes
OK.

> def _do(i):
>    print('Run:', i)
>    q = multiprocessing.Queue()
>    for j in range(30):
>        q.put(i*30+j)
30 items in the queue for each i (i*30). Cool.

>    processes = _make_some_processes(q)
>
>    while not q.empty():
>        pass
why are you checking q.empty( ) here again?

> #    The deadlock only occurs on Mac OS X and only when these lines
> #    are commented out:
> #    for p in processes:
> #        p.join()
Why are you joining down here? Why not in the loop itself? I tested it
on Linux and Win32. Works fine for me. I don't know about OSX.

> for i in range(100):
>    _do(i)
_do(i) is ran 100 times. Why? Is that what you want?

> Output (on Mac OS X using the svn version of py3k):
> % ~/bin/python3.2 moprocessmoproblems.py
> Run: 0
> Grabbed item from queue: 0
> Grabbed item from queue: 1
> Grabbed item from queue: 2
> ...
> Grabbed item from queue: 29
> Run: 1

And this is strange. Now, I happened to be hacking away some
multiprocessing code meself. I saw your thread so I whipped up
something that you can have a look.

> At this point the script produces no additional output. If I uncomment the
> lines above then the script produces the expected output. I don't see any
> docs that would explain this problem and I don't know what the rule would be
> e.g. you just join every process that uses a queue before  the queue is
> garbage collected.

You join the processes when you want it to return with or without
optional parameter `timeout' in this case. Let me be more specific.
The doc for Process says:

"join([timeout])
Block the calling thread until the process whose join() method is
called terminates or until the optional timeout occurs."

Right. Now, the join( ) here is going to be the the called process'
join( ). If this particular join( ) waits indefinitely, then your
parent process' join( ) will _also_ wait indefinitely waiting for the
child processes' join( ) to finish up __unless__ you define a timeout
value.

> Any ideas why this is happening?

Have a look below. If I've understood your code, then it will be
reflective of your situation but with different take on the
implementation side of things (ran on Python2.6):

from multiprocessing import Process, Queue;
from Queue import Empty;
import sys;

def _process_worker(q):
try:
something = q.get(block=False, timeout=None);
except Empty:
print sys.exc_info();
else:
print 'Removed %d from the queue' %something;

def _make_some_processes():
q = Queue();

for i in range(3):
for j in range(3):
q.put(i*30+j);

while not q.empty():
p = Process(target=_process_worker, args=(q,));
p.start();
p.join();

if __name__ == "__main__":
_make_some_processes();

'''
Removed 0 from the queue
    Removed 1 from the queue
Removed 2 from the queue
Removed 30 from the queue
Removed 31 from the queue
Removed 32 from the queue
Removed 60 from the queue
Removed 61 from the queue
Removed 62 from the queue
'''
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: transpose array

2009-10-27 Thread Ishwor Gurung
Hi,

>> xVec=[a1,a2,a3,a4,a5]
>> yVec=[b1.b2.b3.b4.b5]
>> zVec=[c1,c2,c3,c4,c5]
>>
>> and i want to output them to a ascii file like so
>>
>> a1,b1,c1
>> a2,b2,c2
>> a3,b3,c3
>> ...
>>
>> now i'm using
>>
>>    print >>f, str(xVec).replace('[',' ').replace(']', ' ')
>>    print >>f, str(yVec).replace('[',' ').replace(']', ' ')
>>    print >>f, str(zVec).replace('[',' ').replace(']', ' ')
>>
>> which dumps them like
>>
>>  a1,a2,a3,a4,a5
>>  b1.b2.b3.b4.b5
>>  c1,c2,c3,c4,c5
>
>>>> xVec=[a1,a2,a3,a4,a5]
>>>> yVec=[b1,b2,b3,b4,b5]
>>>> zVec=[c1,c2,c3,c4,c5]
>>>> import sys, csv
>>>> from itertools import izip
>>>> csv.writer(sys.stdout).writerows(izip(xVec, yVec, zVec))
> a1,b1,c1
> a2,b2,c2
> a3,b3,c3
> a4,b4,c4
> a5,b5,c5

Or, http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html :-)
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Migrating from R to Python

2009-11-02 Thread Ishwor Gurung
Hi,

2009/11/3 Ryan :
> I am a long time user of "R" for statistical analysis and find it an
[...]

> My question is to people who have used zoo and xts in R, what has
> their experience been with Python? Would you recommend using native
> Python to do time series analysis, or rPy to link back to R for
> analysis?

Although I haven't used 'zoo' nor 'xts' in R I use Rpy/Rpy2 because it
seems to expose almost all(iirc) the necessary R space within Python
space. So, if I need features in R - for e.g., importing modules -
library('foo'), I can still have it in Python via the Rpy/Rpy2 bridge.
On the other hand with pytseries Python library, I'd be limited to
only run time-series analysis wouldn't I? In the end though, it all
depends on your project requirements, resources and so forth..
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem in installing wxwidgets for python..

2009-11-04 Thread Ishwor Gurung
Hi,

2009/11/4 Jebagnana Das :
> Hello friends,
>   I've tried to install wxwidgets in my mandriva 2009 spring
> for GUI interaction with python. In the installation instruction it said
> that i need gtk+ library. So i downloaded GTK+. When i configured GTK+ i got
> the message

You probably want wxpython binding instead - http://www.wxpython.org/
Use binaries provided by Mandriva's package manager where possible
unless you _really_ want to do a source installation.

> checking for BASE_DEPENDENCIES... configure: error: Package requirements
> (glib-2.0 >= 2.21.3atk >= 1.13.0pango >= 1.20cairo >= 1.6) were
> not met:
>
>
> Requested 'glib-2.0 >= 2.21.3' but version of GLib is 2.20.1
>
> Consider adjusting the PKG_CONFIG_PATH environment variable if you
> installed software in a non-standard prefix.

$ export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig
(considering that your local installs went to those directories. Try
replacing those directories accordingly for glib, atk, pango and
cairo). The files you're after is a ".pc" (pkg-config need them) file.
A quick find will tell you where it is if it is installed.

Run configure script again.

> Alternatively, you may set the environment variables
> BASE_DEPENDENCIES_CFLAGS
>
> and BASE_DEPENDENCIES_LIBS to avoid the need to call pkg-config.
> See the pkg-config man page for more details.
>
> Then i downloaded glib2.21.3,atk 1.13.0,pango 1.20 and cairo 1.6. I
> installed all the packages using the following commands.

[...]
> tar xvzf filename.tar.gz
> cd folder
> ./configure
>
> make
> make install

Yep. Check where it installed them one by one. In short, you need
access to a ".pc" file that they provide. If not, write one yourself.

> I've not specified anf options like --prefix and i installed in the folder
> itself.

man pkg-config for further info.

> when i tried to install gtk+ after installing all this it showed the same
> error. What should i do to install wxwidgets? Plz. reply as soon as
> possible.. Coz. i've to finish my proj. quickly.. Thanks and regards...

See above.
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When will Python go mainstream like Java?

2010-02-23 Thread Ishwor Gurung
On 23 February 2010 08:56, AON LAZIO  wrote:
> That will be superb
Yes it would - but I'll just add in few words.

Java - Monstrous language that was Sun's flagship language. Now, it's Oracles.
Python - Hobby-ish hacking language that we all love so much (that we
wish everything was written using Python).

Java - The JVM code been hacked to death by Sun engineers (optimised)
Python - The PVM code has seen speed-ups in Unladen or via Pyrex..
ad-infinitum but nowhere as near to JVM

I like both Python and Java but given the amount of resources put into
JVM and Java (JEE is _huge_ in Enterprise if you didn't know that
already and there are universities that speak Java fluently), it's
kind of sad that Python till the day hasn't seen speedup in mainline
releases.

I see Python more as a hacker's language which will gradually evolve
and support SMEs and alike in the long run than Java (and of course we
write our weekend-only hacking projects in it :-) but for a
market-uptake like Java requires universities, colleges and students
to learn this wonderful little language and requests energetic hackers
to fix lock-contention issues and the like in the core implementation.

Perhaps I see a light, perhaps I see nothing.. but I feel the day is
coming nearer when Python would run as fast as Java/C. Only time can
tell - I hope the time is right about this.
--
Regards
Ishwor Gurung
Key id:0xa98db35e
Key fingerprint:FBEF 0D69 6DE1 C72B A5A8  35FE 5A9B F3BB 4E5E 17B5
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: importing with .m instead of .py

2009-09-25 Thread Ishwor Gurung
Wanderer
Hi
Refer to http://docs.python.org/tutorial/modules.html#the-module-search-path.

Particularly-
"
When a module named spam is imported, the interpreter searches for a
file named spam.py in the current directory, and then in the list of
directories specified by the environment variable PYTHONPATH. This has
the same syntax as the shell variable PATH, that is, a list of
directory names. When PYTHONPATH is not set, or when the file is not
found there, the search continues in an installation-dependent default
path; on Unix, this is usually .:/usr/local/lib/python.
"

Having said that, please see below.

> I would like to import Matlab/Octave files of the .m sort into Python
> that look like this.
>
> # comment
> y=[1,2,3,4,5\
> ,6,7,8,9];
> # comment
>
> The only problem is I have to change the extensions from .m to .py. Is
> there a way to get python to import files that don't end in .py?

You can try this for single file. Pretty trivial-
$ cat foo.m
y=[1,2,3]
$ export PYTHONSTARTUP=foo.m
$ python
Python 2.6.1 (r261:826, Sep 17 2009, 01:16:52)
[GCC 4.3.2] on linux2
[Unladen Swallow 2009Q3]
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'y']
>>> y
[1, 2, 3]

Another way:
>>> f_ = open('foo.m','r');
>>> j = f_.xreadlines()
>>> for i in j.xreadlines():
... print i
...
y=[1,2,3]

Another way:
>>> import os;
>>> matlab_files=[];
>>> for root, dirs, files in os.walk('.'):
... for i in files:
... if i.endswith(".m"):
... matlab_files.append(i);
...
>>> matlab_files
['foo.m', 'bar.m']
>>> for x in matlab_files:
... execfile(x);
>>> dir()
['__builtins__', '__doc__', '__name__', 'dirs', 'files', 'i',
'matlab_files', 'os', 'root', 'x', 'y', 'z']
>>> x
'b.m'
>>> y
[1, 2, 3]
>>> z
[3, 2, 1]

$ cat foo.m
y=[1,2,3]
$ cat bar.m
z=[3,2,1]

These sort of task are pretty trivial to do. You should take some time
to read through the documentation.. and oh don't be such a wanderer
loosing sight of such good resource such as http://docs.python.org :-)
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New books: Learning Python, Python Pocket Reference 4th Eds

2009-09-25 Thread Ishwor Gurung
Thanks Mark.

2009/9/26 Mark Lutz :
> I'm happy to announce new, 4th editions of the O'Reilly books
> Learning Python and Python Pocket Reference.
[]

It was pleasant and such a fun going through LP(2nd ed for me). Python
Cook book was a nice complement too.

I miss those days when I hurriedly used to look up materials through
it finding novel and cool ways of doing things (I still do find it
very helpful) :-)

Thanks for such a wonderful resource.

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


Re: Pipelining tar create and tar extract the "Python" way...

2009-09-25 Thread Ishwor Gurung
Ray.
Hi
>> >   tar cvf - SrcDir | (cd /dest ; tar xvf -)

Check this out Ray if you haven't done it already
http://docs.python.org/library/tarfile.html
"
The tarfile module makes it possible to __read__ and write tar
archives, including those using gzip or bz2 compression.
"
Try breaking it up the functionality.
That's how shell achieves this functionality as whole, why wouldn't
you apply same technique in Python :-)

Some modules that could help for your specific situations are tarfile and os.

Popen is one way(It's what your spec says) but you'd want to do purely
in Python. Aren't you curious? :-) It's late and TGIF! Need sleep.
Goodluck.

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