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


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


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


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


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: 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: Read header and data from a binary file [LONG]

2009-09-23 Thread Ishwor
> char is 1 bytes long on Python (as per struct modules' definition)

Also, this is also another option for you to use instead of built-in struct.
http://www.sis.nl/python/xstruct/xstruct.shtml

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


Re: Read header and data from a binary file [LONG]

2009-09-23 Thread Ishwor
Jose,
Hi

Note: I've worked with struct but a while ago so might be rusty a bit.
Also, this sounds a bit like a homework. If it is a homework please do
it yourself(or at least try) as you'd otherwise never know the
knowledge behind it on real-world scenario :-)

Having said that I am giving you below an example on top of my reply.

> import struct
> name = "myaudio.dat"
> f = open(name,'rb')
> f.seek(0)

f.seek(0) line is not explicitly needed afaik but you can if you want to.

> chain = "< 4s 4s I 4s I 20s I I i 4s I 67s s 4s I"
> s = f.read(4*1+4*1+4*1+4*1+4*1+20*
> 1+4*1+4*1+4*1+4*1+4*1+67*1+1+4*1+4*1)

which is 136 bytes.

> a = struct.unpack(chain, s)

Yep. little-endian ordering pack 136 bytes of `s' in `a' according to chain.

> header = {'identifier' : a[0],
>           'cid'  : a[1],
>           'clength'   : a[2],
>   'hident' : a[3],
>   'hcid32' : a[4],
>   'hdate'  : a[5],
>   'sampling' : a[6],
>   'length_B'  : a[7],
>   'max_cA'   : a[8],
>   'max_cA1' : a[9],
>   'identNOTE'  : a[10],
>   'c2len'  : a[11],}
>
> It produces:
>
> {'length_B': 150001, 'sampling': 5, 'max_cA1': 'NOTE', 'hident': 'HEDR',
> 'c2len': "Normal Sustained Vowel 'A', Voice and Speech Lab., MEEI, Boston,
> MA", 'hdate': 'Jul 13 11:57:41 1994', 'identNOTE': 68, 'max_cA': -44076,
> 'cid': 'DS16', 'hcid32': 32, 'identifier': 'FORM', 'clength': 300126}
>
> So far when I run f.tell()
>>>f.tell()
> 136L

tell( ) gives you current position of the file descriptor (you read
136 bytes so tell( ) says that you read in 136 so far as the position
of the current file descriptor or position in the binary file).

> The audio data length is 300126, now I need a clue to build an array with
> the audio data (The Chunk SDA_), would it possible with struct?, any help ?

clength above is 300126. Maybe you can use that to get Data? :-)

SDA_'s format: does it mean it starts at offset 8 bytes-EOF?

If it starts at 8 bytes after the header then what is stored in
between the lengthOf(header)+8?

In anycase, as I understand, to get all the values from the offset
8(called `Data' as per your protocol spec), you can do:

reading_after_136_file_pos_to_eof = f.read(); #continue from 136L above.
clen_fs = '<%ds' % clength; # I assume here that is a character
x = struct.unpack(clen_fs, reading_after_136_file_pos_to_eof [8:]);
#start at index 8 onwards

Now, `x' will have stored unpacked value of the
reading_after_136_file_pos_to_eof starting from 8'th byte and wil only
store 300126 bytes of characters (1 byte each so 300136 bytes long)
i.e., starting from 8'th byte file descriptor position assuming each
char is 1 bytes long on Python (as per struct modules' definition)

[ ... ]

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


Re: delete items from list by indices

2009-09-23 Thread Ishwor
Hi

2009/9/23 blumenkraft :
> Hi,
>
> I have some list:
> x = [8, 9, 1, 7]
> and list of indices I want to delete from x:
> indices_to_delete = [0, 3], so after deletion x must be equal to [9,
> 1].
>
> What is the fastest way to do this? Is there any builtin?

Try this-
>>> x = [8, 9, 1, 7]
>>> [x.pop(i) for i in sorted(indices_to_delete,reverse=True)]
[7, 8]
>>> x
[9, 1]

Built-in used here is `sorted' and method on list used here is `pop'.
With regards to efficiency you may want to use the methods of list
which is more intuitive afaik and useful as its more reflective of
effect on the type list. It's a trivial choice here but later it might
help.
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Not this one the other one, from a dictionary

2009-09-18 Thread Ishwor
Ross
Hi.

> So I have this dictionary:
>
> aDict = {'a': 'bob', 'b': 'stu'}

Yes.

> I know that the dictionary contains two keys/value pairs,  but I don't know
> the values nor that the keys will be 'a' and 'b'.   I finally get one of the
> keys passed to me as variable BigOne. e.g.:
>
> BigOne = "a"

Right. aDict[BigOne] will give you - 'bob' which may/maynot be what
you want by the looks of it, you want aDict[BigOne].

>>> aDict.keys()
['a', 'b']
>>> aDict.values()
['bob', 'stu']

keys() / values() return list so you do not have to worry about
explicitly getting list.

> The other key, call it  littleOne remains unknown.  It might be "b" but
> could be "c", "x", etc...   I later need to access both values...
>
> I have something that works, with list comprehension - but wonder if there's
> a more brief/elegant way to get there:

If you know the dictionary name in this case aDict (which you don't
mention you know or not), you can just traverse it using easily as
such:
>>>for k in aDict:
     print k, aDict[k];

>>> [[i,a[i]] for i in aDict]
[['a', 'bob'], ['b', 'stu']]
>>> [[i,a[i]] for i in aDict][0]
['a', 'stu']
>>> [[i,a[i]] for i in aDict][0][0]
'a'
>>> [[i,a[i]] for i in aDict][0][1]
'bob'


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


Re: detmining name during an assignment

2009-09-18 Thread Ishwor
Jamie,
Hi.

> I have an app that uses Python scripting. When a user creates a new object:
>
> objName = newObject()

newObject should technically speaking be newClass() but nevermind :-)

> I'd like the newObject be able to use objName as its internal name.
> So, if a user says:
>
> cube1 = Cube()
>
>  A "cube1" object should apear in the scene list. I believe this means I need
> to determine that a namespace assignment is going on from inside the
> object's init code
> or by using properties.

A class's init code is like a constructor (guessing you know about
ctors here). Basically, initialising all the variables that particular
class uses. In this instance calling Cube( ) would cause it to call up
the __init__(self) function in Cube class and do whatever it does
there such as defining a variable, calling other initialisation
functions etc...

> I've searched the web but can't find a simple answer. Is there some
> way to use the inspect
> module get source code functoins? How would I get the code for "the

To get the source code for a function, you can manually inspect it. To
get the functions that a class exports, use can use
dir(object_of_a_class) in Python shell (this may not be what you want
but I write it anyway because I feel like writing today). You can also
run help(module_name_here) to see the docs+functions.

> current interpreter line"
> causing the init code to execute?

I am starting to suspect that you are very much asking for a debugger
;-) Look up pdb;a Python debugger.
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to test that an exception is raised ?

2005-01-28 Thread Ishwor
[snipped alot of codes that doesn't mean much ]

if you want to check for exception then it goes like this

try:
 
catch IOError:
 

sorry i won't bother to read your code because i can't read, i think i
am tired and need to go to bed. ;-)

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


Re: list addition methods compared.

2004-12-28 Thread Ishwor
On Mon, 27 Dec 2004 18:49:14 +0100, François Granger
<[EMAIL PROTECTED]> wrote:
> Le 27/12/04 1:03, « Ishwor » <[EMAIL PROTECTED]> a écrit :
> 
> > so indeed method 2 (l2.extend() ) is the fastest ?? In 2/3 times,
> > method 3 (l3 += [x] seems faster than method 1/2 in my P2.4GHZ machine
> > with 512mb??? :-(
> > Could u run the code in your machine and perhaps and let me know what
> > the average speed is??
> 
> On a iBook G4 à 1.2 Ghz loaded with tons of other softwares running.
> 
> fgranger:/develop/python scripts fgranger$ python listspeed.py
> @@@
> Method 1 done in (average finish time(out of 3)) - 5.6365475655
> Method 2 done in (average finish time(out of 3)) - 0.0562076569
> Method 3 done in (average finish time(out of 3)) - 0.0455052853
> @@@
> fgranger:/develop/python scripts fgranger$ python listspeed.py
> @@@
> Method 1 done in (average finish time(out of 3)) - 6.1534483433
> Method 2 done in (average finish time(out of 3)) - 0.0637686253
> Method 3 done in (average finish time(out of 3)) - 0.0500767231
> @@@
> fgranger:/develop/python scripts fgranger$ python listspeed.py
> @@@
> Method 1 done in (average finish time(out of 3)) - 5.5850391388
> Method 2 done in (average finish time(out of 3)) - 0.0594174862
> Method 3 done in (average finish time(out of 3)) - 0.0549054146
> @@@
> 
Thank you. ;-) method 3 ( l += [x] which maps to l.extend([x]) )
indeed seems fastest. well anyway i'll be using timeit module from now
onwards as Steve pointed out. Thank you.

[snip]
-- 
"On a cold day please heat your laptop using
>>>while 1: pass " ;-)
cheers,
Ishwor Gurung
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tricks to install/run Python on Windows ?

2004-12-26 Thread Ishwor
On Sun, 26 Dec 2004 19:43:24 +0100, StepH
<[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I'm new to Python.  I'm working under XP, and I've alot of prob. (not
> with the langage itself, but with the tools):
> 
> I've install Pyhton 2.4 in C:\Python24, using the .msi windows installer.
> Then, I've install "PythonWin" (the last build-203).
> 
Doesn't IDLE come with Python2.4??? Its pretty good if you haven't tried it ;-)
If you haven't searched for it yet, try looking in
C:\Python24\lib\idlelib for "idle.py".
To start it simply do "python idle.py" in the prompt. You should also
probably have a batch script named idle.bat which wraps the idle.py.

> I'll try to summerize my prob.:
> 
> 1./ The PythonWin IDE is not stable at all.  Sometimes it exit without
> reason, or don't stop on breakpoint, etc...  Are some of you aware of
> bugs in the last PyhtonWin IDE release ?  I've to open the TaskManager.
>  AT some point, i'm not able to (p.e.) open a file under it !!!
> 
> 2./ I've try to download Komode (he 3.1 personnal).  I've also prob.
> with it !  Also, the breakpoint seems to not always work...
> 
> 3./ So, i've try to use the command line, but i've to manualy change the
> code page od my dos box from 437 to 1252 (i'm live in belgium).  And
> i've not try how to do that permanently !
> 
> 4./ Before, I had Python23 and it seems that when unstalling it, all the
> keys in the registry are not removed at all.  When i've install the 2.4,
> I had a mismatch which force me to complety re-install the machine (I'm
> not an expert of the registry)...
> 
> 5./ Installing komodo seems to "block" pythonwinIDE completly...
> 
> What's wrong ?  Python seems terific, but the tools...
> 
I have no clue what the *tools* are doing for you and i feel sorry for
that but as i said if you try IDLE its pretty good.
the link http://www.python.org/idle/ should be able to provide you with info.



> So... maybe i've to try BlackAdder ?
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


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


Re: list addition methods compared.

2004-12-26 Thread Ishwor
On Sun, 26 Dec 2004 18:37:35 -0500, Terry Reedy <[EMAIL PROTECTED]> wrote:
> 
> "Ishwor" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> > On Sun, 26 Dec 2004 04:57:17 -0500, Terry Reedy <[EMAIL PROTECTED]> wrote:
> >>
> >> "Ishwor" <[EMAIL PROTECTED]> wrote in message
> >> news:[EMAIL PROTECTED]
> >> > Hi all
> >> > I have just wrote a small script to compare the speed of list addition
> >> > methods.
> >>
> >> There are two meanings of 'list addition':
> >>
> >> li = li+[item] *copies* the list and adds item
> >>
> >> li += [item] is the same as li.extend([item]) which add item to the end
> >> of
> >> the list *without* copying.
> >>
> >> Of course, extending a list is faster than copying + one more.
> >>
> >
> > I agree with you that list extending is faster way to add as compared
> > to method 1. also that method 2 is mapped to 'extend()' anyway,
> 
> As near as I could tell from what you posted (and I snipped), method 2 was
> about the same as 1 and not mapped to extend().
ah.. wellwhat to tell?? i wanted the method 2 to be l2.extend() @[EMAIL 
PROTECTED]
hhah.. thanks for that anyway.
 
> > but
> > why is the method 3 ( l3.extend() ) in my example code talking only
> > nearly 1% of time to complete as compared to method 1/2???
> 
> Because writing 1 pointer takes 1/100th as long as writing 100 pointers (in
> the C code of CPython).  You used lists long enough for the difference
> between O(n) and O(n**2) behavior to show.

theres the correct output AFAIK is -

C:\Python24\file\PyFiles>python -O listadditioncompare.py
@@@
Method 1 done in (average finish time(out of 3)) - 1.358676
Method 2 done in (average finish time(out of 3)) - 0.0213334560
Method 3 done in (average finish time(out of 3)) - 0.0256667137
@@@

C:\Python24\file\PyFiles>python -O listadditioncompare.py
@@@
Method 1 done in (average finish time(out of 3)) - 1.3593332767
Method 2 done in (average finish time(out of 3)) - 0.0306665897
Method 3 done in (average finish time(out of 3)) - 0.0213334560
@@@

C:\Python24\file\PyFiles>python -O listadditioncompare.py
@@@
Method 1 done in (average finish time(out of 3)) - 1.3593332767
Method 2 done in (average finish time(out of 3)) - 0.0203335285
Method 3 done in (average finish time(out of 3)) - 0.0203332901
@@@

so indeed method 2 (l2.extend() ) is the fastest ?? In 2/3 times,
method 3 (l3 += [x] seems faster than method 1/2 in my P2.4GHZ machine
with 512mb??? :-(
Could u run the code in your machine and perhaps and let me know what
the average speed is??
The code is -

#compare the speeds of 3 different type of list element addition
import time
def method(TYPE):
if TYPE == 1:
l1 = [];
finish = 0;
start = 0;
start = time.time();
for y in range(0,3):
for x in range(0,1):
l1 = l1 + [x];# type 1
l1 = [];
finish += time.time();
averageFinish = finish/3;
#m = float(finish-start);
print "Method 1 done in (average finish time(out of 3)) -
%.10f" %(averageFinish-start);

if TYPE == 2:
l2 = [];
finish = 0;
start = 0;
start = time.time();
for y in range(0,3):
for x in range(0,1):
l2.extend([x]);# type 2
l2 = [];
finish += time.time();  
averageFinish = finish/3;
#m = float(finish-start);
print "Method 2 done in (average finish time(out of 3)) -
%.10f" %(averageFinish-start);

if TYPE == 3:
l3 = [];
finish = 0;
start = 0;
start = time.time();
for y in range(0,3):
for x in range(0,1):
l3 +=  [x];# type 3
    l3 = [];
finish += time.time();
averageFinish = finish/3;
#m = float(finish-start);
print "Method 3 done in (average finish time(out of 3)) -
%.10f" %(averageFinish-start);

print "@@@";
method(1);
method(2);
method(3);
print "@@@";


[snip]


Thanks. ;-)
-- 
cheers,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE question

2004-12-26 Thread Ishwor
On Sun, 26 Dec 2004 13:02:01 +0100, Rolf Wester <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I would like to use IDLE as interactively as I can with Emacs. In Emacs
> I can send a marked region to the Python interpreter. Is there any way
> to do the same thing with IDLE?
Although i don't use anything much beside IDLE,  vim for coding, AFAIK
IDLE can't do that.
IDLE opens up python shell. Within that shell you type in your script
, commands and create objects as such..The interpreter will
execute your code then.
IDLE looks like this when you fire it up.

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.


Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface.  This connection is not visible on any external
interface and no data is sent to or received from the Internet.


IDLE 1.1  
>>> # this is the Python shell.
>>> 
>>> l = ['spam','eggs'] # you assign and create a list variable called l
>>> l # prints the content of l. 
['spam', 'eggs']

[snip]

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


Re: list addition methods compared.

2004-12-26 Thread Ishwor
On Sun, 26 Dec 2004 04:57:17 -0500, Terry Reedy <[EMAIL PROTECTED]> wrote:
> 
> "Ishwor" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Hi all
> > I have just wrote a small script to compare the speed of list addition
> > methods.
> 
> There are two meanings of 'list addition':
> 
> li = li+[item] *copies* the list and adds item
> 
> li += [item] is the same as li.extend([item]) which add item to the end of
> the list *without* copying.
> 
> Of course, extending a list is faster than copying + one more.
> 

I agree with you that list extending is faster way to add as compared
to method 1. also that method 2 is mapped to 'extend()' anyway, but
why is the method 3 ( l3.extend() ) in my example code talking only
nearly 1% of time to complete as compared to method 1/2??? I think
there is a problem with the code but i don't see where. :-(

> Terry J. Reedy
Thanks Terry for yet another small (really small) step towards enlightment. 

[snip]

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


methods of addition in Python

2004-12-25 Thread Ishwor
As my earlier mail didn't make it c.l.py because it had the heading
"LIST Addition compared", probably it was blocked by the mail server.
;-)
anyway heres it again.. Sorry for people reading it again. Its the same post.

Hi all
I have just wrote a small script to compare the speed of list addition methods.
heres what it looks like.

#listadditioncompare.py
#compare the speeds of 3 different type of list element addition
import time
def method(TYPE):
   l1 = [];
   l2 = [];
   l3 = [];

   if TYPE == 1:
   finish = 0;
   start = 0;
   start = time.time();
   for y in range(0,3):
   for x in range(0,1):
   l1 = l1 + [x];# type 1
   l1 = [];
   finish += time.time();
   averageFinish = finish/3;
   #m = float(finish-start);
   print "Method 1 done in (average finish time(out of 3)) -
%.10f" %(averageFinish-start);

   if TYPE == 2:
   finish = 0;
   start = 0;
   start = time.time();
   for y in range(0,3):
   for x in range(0,1):
   l2 = l2 + [x];# type 2
   l2 = [];
   finish += time.time();
   averageFinish = finish/3;
   #m = float(finish-start);
   print "Method 2 done in (average finish time(out of 3)) -
%.10f" %(averageFinish-start);

   if TYPE == 3:
   finish = 0;
   start = 0;
   start = time.time();
   for y in range(0,3):
   for x in range(0,1):
   l3 +=  [x];# type 3
   l3 = [];
   finish += time.time();
   averageFinish = finish/3;
   #m = float(finish-start);
   print "Method 3 done in (average finish time(out of 3)) -
%.10f" %(averageFinish-start);

print "@@@";
method(1);
method(2);
method(3);
print "@@@";

So far i think it does good. Running it 3 times gives

>>>
@@@
Method 1 done in (average finish time(out of 3)) - 1.1560001373
Method 2 done in (average finish time(out of 3)) - 1.161409
Method 3 done in (average finish time(out of 3)) - 0.010088
@@@

>>>
@@@
Method 1 done in (average finish time(out of 3)) - 1.161134
Method 2 done in (average finish time(out of 3)) - 1.125092
Method 3 done in (average finish time(out of 3)) - 0.0156667233
@@@
>>>

>>>
@@@
Method 1 done in (average finish time(out of 3)) - 1.1563334465
Method 2 done in (average finish time(out of 3)) - 1.1716668606
Method 3 done in (average finish time(out of 3)) - 0.0106668472
@@@
>>>

So i can assume that type 3 ( l3 += [x] ) addition is the fastest . Is
there anything i am doing wrong?? Also could this code be beautified
&& shortened??
Thanks.


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


Re: gridbaglayout

2004-12-25 Thread Ishwor
On 26 Dec 2004 04:05:54 GMT, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2004-12-24, Ishwor <[EMAIL PROTECTED]> wrote:
> 
> > heh? whats this gridbaglayout in Python-list?? Is this what my grandpa
> > calls "christmas fever"?? ;-)
> 
> heh? what's this top-posting in comp.lang.python?
> 
> gridbagsizer is a wxPython/wxWidgets sizer class.  Why shouldn't it be
> discussed here?
haha..
I was just fooling around on Christmas eve. I didn't mean to insult
anyone thats why i top -posted it without referencing anyone's msg.
;-)

> 
> --
> Grant Edwards   grante Yow!  With YOU, I can be
>  at   MYSELF... We don't NEED
>   visi.com    Dan Rather...
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


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


list addition methods compared.

2004-12-25 Thread Ishwor
Hi all
I have just wrote a small script to compare the speed of list addition methods.
heres what it looks like.

#listadditioncompare.py
#compare the speeds of 3 different type of list element addition
import time
def method(TYPE):
l1 = [];
l2 = [];
l3 = [];

if TYPE == 1:
finish = 0;
start = 0;
start = time.time();
for y in range(0,3):
for x in range(0,1):
l1 = l1 + [x];# type 1
l1 = [];
finish += time.time();
averageFinish = finish/3;
#m = float(finish-start);
print "Method 1 done in (average finish time(out of 3)) -
%.10f" %(averageFinish-start);

if TYPE == 2:
finish = 0;
start = 0;
start = time.time();
for y in range(0,3):
for x in range(0,1):
l2 = l2 + [x];# type 2
l2 = [];
finish += time.time();
averageFinish = finish/3;
#m = float(finish-start);
print "Method 2 done in (average finish time(out of 3)) -
%.10f" %(averageFinish-start);

if TYPE == 3:
finish = 0;
start = 0;
start = time.time();
for y in range(0,3):
for x in range(0,1):
l3 +=  [x];# type 3
l3 = [];
finish += time.time();
averageFinish = finish/3;
#m = float(finish-start);
print "Method 3 done in (average finish time(out of 3)) -
%.10f" %(averageFinish-start);

print "@@@";
method(1);
method(2);
method(3);
print "@@@";

So far i think it does good. Running it 3 times gives

>>> 
@@@
Method 1 done in (average finish time(out of 3)) - 1.1560001373
Method 2 done in (average finish time(out of 3)) - 1.161409
Method 3 done in (average finish time(out of 3)) - 0.010088
@@@

>>> 
@@@
Method 1 done in (average finish time(out of 3)) - 1.161134
Method 2 done in (average finish time(out of 3)) - 1.125092
Method 3 done in (average finish time(out of 3)) - 0.0156667233
@@@
>>> 

>>> 
@@@
Method 1 done in (average finish time(out of 3)) - 1.1563334465
Method 2 done in (average finish time(out of 3)) - 1.1716668606
Method 3 done in (average finish time(out of 3)) - 0.0106668472
@@@
>>> 

So i can assume that type 3 ( l3 += [x] ) addition is the fastest . Is
there anything i am doing wrong?? Also could this code be beautified
&& shortened??
Thanks.

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


Re: Clearing the screen

2004-12-25 Thread Ishwor
On Sun, 26 Dec 2004 13:07:56 +1030, Ishwor <[EMAIL PROTECTED]> wrote:
> On 25 Dec 2004 18:20:39 -0800, John Machin <[EMAIL PROTECTED]> wrote:
> >
> > Ishwor wrote:
> >
> > > i was just tinkering with it actually. ;-)
> > > In your command prompt just do
> > > Pythonwin.exe /run "C:\Python24\file\PyFiles\clear.py"
> >
> > It's not a very good idea to store your own scripts in the PythonXY
> > directory -- other than tested working modules which you install in
> > PythonXY\lib\site-packages.
> > E.g. what will you do when Python 2.5 arrives?
> okay. ;-)
> First of all, the question Steve posted was "Anyone know if there is a
> similar option to PythonWin?  I looked around a bit, but couldn't find
> one..."
> Second of all, the script doesn't pollute Python*XY* directory because
> it doesn't live there ;-)
> I created the pythonwin.bat in C:\
> Inside the pythonwin.bat i added the following lines
> @echo off
> start C:\Python24\Lib\site-packages\pythonwin\Pythonwin.exe /run
If you mean for the pythonwin.exe then remove the pythonwin package
from the computer and reinstall it for python25 ( ofcourse
pythonwin25.exe or something like that) ;-)
then update the batch script.

> "C:\Python24\file\PyFiles\clear.py" (sorry i put extra "" in earlier
> post. This is the right one)
> Thirdly when Python2.5 arrives, i just change the directory in the
> batch script. ;-)

I mean for my script (clear.py) in short do something like 
C:\Python25\file\PyFiles\clear.py

> Thank you.
> 
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> 
> 
> --
> cheers,
> Ishwor Gurung
> 


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


Re: Clearing the screen

2004-12-25 Thread Ishwor
On 25 Dec 2004 18:20:39 -0800, John Machin <[EMAIL PROTECTED]> wrote:
> 
> Ishwor wrote:
> 
> > i was just tinkering with it actually. ;-)
> > In your command prompt just do
> > Pythonwin.exe /run "C:\Python24\file\PyFiles\clear.py"
> 
> It's not a very good idea to store your own scripts in the PythonXY
> directory -- other than tested working modules which you install in
> PythonXY\lib\site-packages.
> E.g. what will you do when Python 2.5 arrives?
okay. ;-)
First of all, the question Steve posted was "Anyone know if there is a
similar option to PythonWin?  I looked around a bit, but couldn't find
one..."
Second of all, the script doesn't pollute Python*XY* directory because
it doesn't live there ;-)
I created the pythonwin.bat in C:\ 
Inside the pythonwin.bat i added the following lines
@echo off
start C:\Python24\Lib\site-packages\pythonwin\Pythonwin.exe /run
"C:\Python24\file\PyFiles\clear.py" (sorry i put extra "" in earlier
post. This is the right one)
Thirdly when Python2.5 arrives, i just change the directory in the
batch script. ;-)
Thank you.

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


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


Re: Clearing the screen

2004-12-25 Thread Ishwor
heres the shell i forgot to show 

PythonWin 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED])
- see 'Help/About PythonWin' for further copyright information.
>>> clear.cls()
[40 more lines of "\n"]
>>>


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


Re: Clearing the screen

2004-12-25 Thread Ishwor
On Sun, 26 Dec 2004 01:47:42 GMT, Steven Bethard
<[EMAIL PROTECTED]> wrote:
> Scott David Daniels wrote:
> > Nick Coghlan wrote:
> >
> >> Jeff Epler wrote:
> >>
> >>> I don't know about idle, but the "real" python supports the
> >>> PYTHONSTARTUP environment variable.
> >>
> >>
> >> I just tried it - IDLE ignores PYTHONSTARTUP, as does PythonWin (I
> >> just started using PYTHONSTARTUP to switch the standard prompt from
> >> '>>>' to "Py>').
> >>
> >> I believe PYTHONSTARTUP is handled by CPython's main function before
> >> it gets to the interactive interpreter.
> >>
> >> Cheers,
> >> Nick.
> >>
> >  From the Fine Manual:
> > Command line usage
> > idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
> >
> > -c command  run this command
> > -d  enable debugger
> > -e  edit mode; arguments are files to be edited
> > -s  run $IDLESTARTUP or $PYTHONSTARTUP first
> > -t titleset title of shell window
> >
> > On Windows, it is likely to be idle.pyw.  So, add a -s to the command
> > line used in the shortcut to start Idle.
> 
> Anyone know if there is a similar option to PythonWin?  I looked around
> a bit, but couldn't find one...

i was just tinkering with it actually. ;-)
In your command prompt just do
Pythonwin.exe /run "C:\Python24\file\PyFiles\clear.py"

or if you hate doing that then just create a batch  script (.bat) as such-

@echo off
start "C:\Python24\Lib\site-packages\pythonwin\Pythonwin.exe /run
"C:\Python24\file\PyFiles\clear.py" "

see the pythonwin reference manual for more option ;)
> 
> Steve
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


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


Re: Clearing the screen

2004-12-25 Thread Ishwor
On Sat, 25 Dec 2004 16:34:26 -0800, Scott David Daniels
<[EMAIL PROTECTED]> wrote:
> Nick Coghlan wrote:
> > Jeff Epler wrote:
> >
> >> I don't know about idle, but the "real" python supports the
> >> PYTHONSTARTUP environment variable.
> >
> > I just tried it - IDLE ignores PYTHONSTARTUP, as does PythonWin (I just
> > started using PYTHONSTARTUP to switch the standard prompt from '>>>' to
> > "Py>').
> >
> > I believe PYTHONSTARTUP is handled by CPython's main function before it
> > gets to the interactive interpreter.
> >
> > Cheers,
> > Nick.
> > 
> From the Fine Manual:
> Command line usage
> idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
> 
> -c command  run this command
> -d  enable debugger
> -e  edit mode; arguments are files to be edited
> -s  run $IDLESTARTUP or $PYTHONSTARTUP first
> -t titleset title of shell window
> 
> On Windows, it is likely to be idle.pyw.  So, add a -s to the command
> line used in the shortcut to start Idle.

okay since i couldn't find .pythonrc in my computer. what i did in the
idle.bat which starts idle.pyw is added the '-r' switch which
basically runs the script from the file -
@echo off
rem Working IDLE bat for Windows - uses start instead of absolute pathname
start idle.pyw -s -r "C:\Python24\file\Pyfiles\clear.py" %1 %2 %3 %4
%5 %6 %7 %8 %9

and it works fine but i have to do
>>>clear.cls();
instead of just plain
>>> cls();
but i'll walk with that. ;-)

I hope this will be clear as i gradually read the text. It has to do
something with the
__builtins__ probably.
Thanks everyone. ;-)

> 
> --Scott David Daniels
> [EMAIL PROTECTED]
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


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


Re: Tinkering with py2exe

2004-12-25 Thread Ishwor
On 25 Dec 2004 16:26:01 -0800, John Machin <[EMAIL PROTECTED]> wrote:
> 
> Ishwor wrote:
> > Having coded 1.72kb python test file, i decided to convert it to .exe
> > file using py2exe.
> > Having succeded doing it, i found the need to distribute the whole
> > directory including these files ?!!!???
> > 26/12/2004  09:16 AM   203,096 library.zip
> > 26/11/2004  09:16 AM 1,867,776 python24.dll
> > 26/12/2004  09:16 AM11,264 simpletable.exe
> > 26/11/2004  09:16 AM 4,608 w9xpopen.exe
> > 4 File(s)  2,086,744 bytes
> >
> > i assume w9xpopen.exe does the work around to run the code in
> windows.
> 
> No, it is required to make the popen* functions work correctly on "w9x"
> platforms (Windows 95, 98, & ME).

okay.. double clicking it returns the same remarks.

> 
> > python24.dll (which is massive 1.78mb!!)- has the Python VM i guess.
> > what does the library.zip do??
> 
> (1) Aren't you curious enough to try peeking into it with WinZip or
> similar?
> 

i didn't find anything to peek. all the files were compiled .pyc's
inside the zip file.. :-(

> (2) Perhaps you should have read all the way through the py2exe home
> page:

yup. i should have read everything from top to bottom but i was
extremely eager to see py2exe in action and just copy pasted the
setup.py and alikes.
 
> 
> """
> How does it work?
> py2exe uses python's modulefinder to examine your script and find all
> python and extension modules needed to run it. Pure python modules are
> compiled into .pyc or .pyo files in a temporary directory. Compiled
> extension modules (.pyd) are also found and parsed for binary
> dependencies.
> 
> A zip-compatible archive is built, containing all python files from
> this directory. Your main script is inserted as a resource into a
> custom embedded python interpreter supplied with py2exe, and the
> zip-archive is installed as the only item on sys.path.
> """
> 
> >
> > Currently to convert such a small script to exe why the nuances of
> 1.98mb??
> 
> It's not compiling and linking, as with (say) C. It's packaging,
> providing the minimum (more or less) bundle of resources that you can
> distribute to users who want/need to run your script but
> can't/don't/shouldn't have a full Python distribution. The overhead of
> the pythonXY.dll etc can be spread over multiple scripts.

Yup reading the page. Thanks heaps for that.. Sorry if i was a bit balmy. :-)

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


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


Tinkering with py2exe

2004-12-25 Thread Ishwor
Having coded 1.72kb python test file, i decided to convert it to .exe
file using py2exe.
Having succeded doing it, i found the need to distribute the whole
directory including these files ?!!!???
26/12/2004  09:16 AM   203,096 library.zip
26/11/2004  09:16 AM 1,867,776 python24.dll
26/12/2004  09:16 AM11,264 simpletable.exe
26/11/2004  09:16 AM 4,608 w9xpopen.exe
4 File(s)  2,086,744 bytes

i assume w9xpopen.exe does the work around to run the code in windows.
python24.dll (which is massive 1.78mb!!)- has the Python VM i guess.
what does the library.zip do??

Currently to convert such a small script to exe why the nuances of 1.98mb?? 
Thanks 
-- 
cheers,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE problem :-(

2004-12-25 Thread Ishwor
Sorry IDLE's source ...;P
[snip]

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


Re: IDLE problem :-(

2004-12-25 Thread Ishwor
On Sat, 25 Dec 2004 17:45:02 GMT, Steven Bethard
<[EMAIL PROTECTED]> wrote:
> Ishwor wrote:
> > I don't know if this has been a problem with other people using IDLE
> > but when i press the home key then the cursor jumps to the beginning
> > of the line and not after the prompt. If google prints the right
> > indentation then here how i want the IDLE prompt to work ->
> >
> >  |>>> |(r,b,g).__class__
> >  ^  ^
> >  ^  ^-> want cursor here instead.
> > cursor
> > goes
> > here
> >
> > Any work around??
> 
> If you're on windows, you can try PythonWin instead.  The first time you
> hit home, the cursor will go your second |.  If you then hit home again,
> the cursor will go to your first |.

Yeah  i got the PythonWin and it does what you say but i am so used to
IDLE ( which was created originally by GvR). Its a different kind of
feeling when you are a sort of Python "Evangelist". ;-)
Moreover if i am right, this was mentioned as a sort of #fixme in
Python's source??

Thanks.

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


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


Re: Clearing the screen

2004-12-24 Thread Ishwor
On 24 Dec 2004 15:33:26 -0800, Lars <[EMAIL PROTECTED]> wrote:
> Hi Iswor,
> 
> If I understand you correctly then your program is writing output to a
> console/terminal window and you want to clear that window.
> I don't know of any library methods for that, but you might just do:

well i am not doing any console i/o. Just simple one. i am trying to
clear the IDLE (one of python IDE distributed with the original
distribution) screen which is pretty easy but having to do
>>>import cls
>>> cls()
everytime is boring (2 lines of boredom!!) so what i want is to be
able to do just
>>>cls()
and nothing more or even less!! ;-) 

> 
> os.system("cls")  #for windows
> or
> os.system("clear")   #for unix
yeah i have used the 'os' module's system() method but that wasn't what i meant.

> Not the most advanced solution though.
;-) Thanx anyway mate. 

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


Re: gridbaglayout

2004-12-24 Thread Ishwor
heh? whats this gridbaglayout in Python-list?? Is this what my grandpa
calls "christmas fever"?? ;-)



On Fri, 24 Dec 2004 12:47:26 -0500, Sells, Fred <[EMAIL PROTECTED]> wrote:
> gridbag is a pain.  google for tablelayout which is easier (to me)
> 
> -Original Message-
> From: Diez B. Roggisch [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 20, 2004 1:17 PM
> To: python-list@python.org
> Subject: Re: gridbaglayout
> 
> [EMAIL PROTECTED] wrote:
> 
> > Friends - I have tried to do abolute positioning using gridbaglayout,
> > but am having no success in jython. One book I have been referencing
> > says that it only works with JPanels. Could someone post a snippet of
> > code that works for a button? I am so close so just a hint would help.
> 
> Google for java-examples and translat to jython. Ist straight forward.
> --
> Regards,
> 
> Diez B. Roggisch
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


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


IDLE problem :-(

2004-12-24 Thread Ishwor
I don't know if this has been a problem with other people using IDLE
but when i press the home key then the cursor jumps to the beginning
of the line and not after the prompt. If google prints the right
indentation then here how i want the IDLE prompt to work ->

 |>>> |(r,b,g).__class__
 ^  ^
 ^  ^-> want cursor here instead.
cursor
goes
here

Any work around??
Thank you.
-- 
cheers,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Clearing the screen

2004-12-24 Thread Ishwor
Hi i use IDLE to code Python in my machine. What i haven't been able
to do is call an in-built function called clear()/cls()/clr() because
it mightn't exist. so what i did is coded my own function called cls()
as such
>>> def cls():
for i in range(1,40):
print " ";

now that does the job very nicely and i get cleared screen but what i
really want to achieve it everytime i start IDLE, without importing
any module, i want to be able to do just cls() and be able to clear
the screen. Is that achievable? Does that have mean i have to tinker a
bit with in-builts??

Thank you.

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


Re: list Integer indexing dies??

2004-12-24 Thread Ishwor
On Fri, 24 Dec 2004 05:44:50 -0600, Mike Meyer <[EMAIL PROTECTED]> wrote:
> Ishwor <[EMAIL PROTECTED]> writes:
> 
> > On 23 Dec 2004 14:28:37 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> > My experience as a learner here is that there should be some
> > automagics & say like "okay you want to do indexing on integers (
> > context dependent); i'll give you the index of 0th position in that
> > integer" ???
> 
> Python doesn't do things automagically. The rules for pythonic
> behavior include "Explicit is better than implicit" and "In the face
> of ambiguity, refuse the tempation to guess." Both of those are
> violated by automatic conversions and the like.
> 

Well *shrugs* that was just an opionion though a bad one from a
beginner :-)... No hard feeling pythoner friends. ;-) and Merry
Christmas to you all ;-)
Then gingerbread is ready at
http://www.mediatinker.com/blog/archives/008798.html 
;-)

[snip]

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


Re: list IndexError

2004-12-23 Thread Ishwor
On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
<[EMAIL PROTECTED]> wrote:
> 
> 
> [Steven Bethard] 
> 
> #- True, true.  Maybe you could lobby for copy as a builtin in 
> #- Python 3000? 
> 
> That's a good idea to me. But copy() as a builtin is not clear if it's
> shallow or deep. 

IMHO its preferable to use shallow one as the built-in because deep is
expensive op. for CPU. ~;-)


> 
> .   Facundo 
> 
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

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


Re: list Integer indexing dies??

2004-12-23 Thread Ishwor
On Thu, 23 Dec 2004 13:33:16 -0300, Batista, Facundo
<[EMAIL PROTECTED]> wrote:
> 
> 
> [Ishwor] 
> 
> #- > What should 035[0] cough up? Be carefull it should 
> #- 
> #- >>>035[0] 
> #- 3 # my own opinion. 
why 3? The reason we get 3 and not 0 here is the *fact* that Python
knows that its an octal rep. and not decimal ;-)
035[2] could return error here. Same for hex. No idea for binary. ~;-(

> #- 
> #- > cough up the same as 29[0]. 
> #- 
> #- >>>29[0] 
> #- 2 #again my own opinion 
since it's decimal its fine to get 2 which is at offset 0. 

[snip]

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


Re: list Integer indexing dies??

2004-12-23 Thread Ishwor
On Thu, 23 Dec 2004 13:33:16 -0300, Batista, Facundo
<[EMAIL PROTECTED]> wrote:
> 
> 
> [Ishwor] 
> 
> #- > What should 035[0] cough up? Be carefull it should 
> #- 
> #- >>>035[0] 
> #- 3 # my own opinion. 
> #- 
> #- > cough up the same as 29[0]. 
> #- 
> #- >>>29[0] 
> #- 2 #again my own opinion 
> 
> Be aware that: 
> 
> >>> 035 == 29 
> True 
> >>> 

Yup. Octal variation of 29. But that wasn't my point.

> 
> .   Facundo 
> 
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> . . . . . . . . . . . . . . .
> 
[snip]

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


Re: list Integer indexing dies??

2004-12-23 Thread Ishwor
On 23 Dec 2004 15:05:20 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> Op 2004-12-23, Ishwor schreef <[EMAIL PROTECTED]>:
> > On 23 Dec 2004 14:28:37 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> >> Op 2004-12-23, Ishwor schreef <[EMAIL PROTECTED]>:
> >> > Hi all. Look at this snippet of code.
> >> >
> >> >>>> l = ['a','b','c','d']
> >> >>>> l
> >> > ['a', 'b', 'c', 'd']
> >> >>>> l[0][0][0]
> >> > 'a'
> >> > It prints the value 'a'. Fine so far :-)
> >> > l[0] ---> 'a' .
> >> > l[0][0]---> 'a'[0] --> 'a'.
> >> > l[0][0][0] ---> 'a'[0][0] --> 'a'[0] --> 'a'
> >> >
> >> > Now why doesnt this list which holds integer seem to work??
> >>
> >> Because this only works with strings.
> >>
> >> String is the only object in python which has an implied
> >> equivallence between an element and a squence of one.
> >>
> >> So one character is a string and a string is a sequence
> >> of characters.
> >>
> >> So 'a'[0] is again 'a' which can again be indexed by
> >> 0 as many times as you want.
> >
> > ;-) gotcha. But shouldn't this be valid too??
> >>>> 123232[0]
> 
> Well if it should become valid, it should just return 123232 IMO.
> 
Im not sure i understand u but what i meant was that 
>>> 123 + 2
125  # nice n good 

now it would be nice if integer could also be *subscripted* too 
>>> 123[0] + 2
3
;-) But as i said in earlier post said, i'll stick with import this's
#2 by Tim Peters. Its better to leave these design issues with other
**senior pythoneers**.


> > in which basically python can infer from the object type and print out
> > 1 instead of coughing up those errors?
> 
> Why do you feel it should cough up 1?
> 


>>>123232[0] #hypothetical 0th position in the integer.
1


> Suppose I write a number in octal notation.
> 
> What should 035[0] cough up? Be carefull it should

>>>035[0]
3 # my own opinion. 

> cough up the same as 29[0].

>>>29[0] 
2 #again my own opinion


[snip]

> by starting indexing from the back we get a nice correspondence between
> the index of the number and the power of 10 it represents.
> 
> --
> Antoon Pardon
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

As in my view if python could treat object in context sensitive
manner, it would be better world but its just my own beginners
opinion.
Happy hunting with Python. ;-)

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


Re: urllib and sites that require passwds

2004-12-23 Thread Ishwor
On 23 Dec 2004 06:46:50 -0800, Fuzzyman <[EMAIL PROTECTED]> wrote:
> damn... I'm losing my leading spaces indentation should be obvious
We'll forgive you for that. It was from "top-of-your-head" ~;-)

> anyway... (everything below except is indented at least one step).
> Fuzzy
Its nice that urllib2 returns errcode to process further. doesn't
urllib do that?
Anyway i wanted to know if any website which is similar to CPAN
library website? I mean i want to be able find modules n stuff for
Python.. It would be really great to know.

Thanks.

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


Re: list Integer indexing dies??

2004-12-23 Thread Ishwor
On Thu, 23 Dec 2004 11:40:12 -0300, Batista, Facundo
<[EMAIL PROTECTED]> wrote:
> 
> 
> [Ishwor] 
> 
> #- >>> 'invalid'[0] 
> #- 'i' 
> #- >>> 123232[-1] 
> #- # Python should automagically infer here that user 
> #- # means indexing and *not* the number per se. 
> #- # (i mean list in context of the line :-) ) 
> 
> Python never should automagically infer nothing! 
> 
> Type "import this" in the interactive interpreter and look at rule #2. 
> 
> 
It would be too much sometimes.. its like saying "do only as much as i
say and nothing much. If you are trying to give some gift to me, i
won't take it "
Anyway i'll go with import this's #2. 

> #- > IOW, the string is a sequence of characters, and the 
> #- integer is not sequence 
> #- > at all. 
> #- > 
> #- 
> #- strings are immutable sequence of collections in Python. Integers are 
> #- numbers. ;-) 
> 
> Nop. Strings are not a sequence of collections, just a sequence of
> characters. 

Sorry i'll rephrase it. strings are **immutable sequence** of
characters which fall under Collections type.  ;-)


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


Re: list Integer indexing dies??

2004-12-23 Thread Ishwor
On 23 Dec 2004 14:28:37 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> Op 2004-12-23, Ishwor schreef <[EMAIL PROTECTED]>:
> > Hi all. Look at this snippet of code.
> >
> >>>> l = ['a','b','c','d']
> >>>> l
> > ['a', 'b', 'c', 'd']
> >>>> l[0][0][0]
> > 'a'
> > It prints the value 'a'. Fine so far :-)
> > l[0] ---> 'a' .
> > l[0][0]---> 'a'[0] --> 'a'.
> > l[0][0][0] ---> 'a'[0][0] --> 'a'[0] --> 'a'
> >
> > Now why doesnt this list which holds integer seem to work??
> 
> Because this only works with strings.
> 
> String is the only object in python which has an implied
> equivallence between an element and a squence of one.
> 
> So one character is a string and a string is a sequence
> of characters.
> 
> So 'a'[0] is again 'a' which can again be indexed by
> 0 as many times as you want.

;-) gotcha. But shouldn't this be valid too?? 
>>> 123232[0] 
in which basically python can infer from the object type and print out
1 instead of coughing up those errors? My experience as a learner here
is that there should be some automagics  & say like "okay you want to
do indexing on integers ( context dependent); i'll give you the index
of 0th position in that integer" ???
 

[snip]

Thanks Antoon.
-- 
cheers,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list Integer indexing dies??

2004-12-23 Thread Ishwor
On Thu, 23 Dec 2004 11:17:57 -0300, Batista, Facundo
<[EMAIL PROTECTED]> wrote:
> 
[snip]

> #- >>> 1[0] 
> #- 
> #- Traceback (most recent call last): 
> #-   File "", line 1, in -toplevel- 
> #- 1[0] 
> #- TypeError: unsubscriptable object 
> #- >>> 
> 
> Well, because the integer is not a subscriptable object 
> 
If i see this code 'a'[0] then what does it really say about semantics
?? Really its hard for me to digest that 'a'[0] is supported by Python
where as 1[0] isn't.
look at this
>>> 'invalid'[0]
'i'
>>> 123232[-1] 
# Python should automagically infer here that user
# means indexing and *not* the number per se. 
# (i mean list in context of the line :-) )

Traceback (most recent call last):
  File "", line 1, in -toplevel-
123232[-1]
TypeError: unsubscriptable object


> IOW, the string is a sequence of characters, and the integer is not sequence
> at all. 
> 

strings are immutable sequence of collections in Python. Integers are
numbers. ;-)

> >>> 'a'[0] 
> 'a' 
> >>> 'ab'[0] 
> 'a' 
> >>> 'ab'[1] 
> 'b' 
> 
> What behaviour did you expect when subscripting an integer? 
>

I got unscriptable object TypeError (extract below) which is *now*
with your enlightment clear to me ;-)

>>> 1[0]

Traceback (most recent call last):
 File "", line 1, in -toplevel-
   1[0]
TypeError: unsubscriptable object
>>>


 
> .Facundo 
> 
> Bitácora De Vuelo: http://www.taniquetil.com.ar/plog 
> PyAr - Python Argentina: http://pyar.decode.com.ar/ 
> 

[snip]

Thanks Batista.

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


list Integer indexing dies??

2004-12-23 Thread Ishwor
Hi all. Look at this snippet of code.

>>> l = ['a','b','c','d']
>>> l
['a', 'b', 'c', 'd']
>>> l[0][0][0]
'a'
It prints the value 'a'. Fine so far :-)
l[0] ---> 'a' . 
l[0][0]---> 'a'[0] --> 'a'.
l[0][0][0] ---> 'a'[0][0] --> 'a'[0] --> 'a'

Now why doesnt this list which holds integer seem to work??

>>> l = [1,2,3]
>>> l[0]
1
>>> l[0][0]

Traceback (most recent call last):
  File "", line 1, in -toplevel-
l[0][0]
TypeError: unsubscriptable object
>>> l[0] 
1
>>> 1[0] 

Traceback (most recent call last):
  File "", line 1, in -toplevel-
1[0]
TypeError: unsubscriptable object
>>>

The compiler reports unsubscriptable object ?? confused , dazzled i am ???!!??
The same list now holds integer instead of strings and l[0][0][0]
which worked fine  earlier on strings doesn't seem to work on
integers???
Any help is greatly appreciated.



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


Re: list IndexError

2004-12-22 Thread Ishwor
On Thu, 23 Dec 2004 08:35:57 +0100, Fredrik Lundh
<[EMAIL PROTECTED]> wrote:
> Mike C. Fletcher wrote:
> 
> >>yeah actually i saw what Fedrik had to say above. I created a sliced
> >>copy of the l & did my homework within the for loop
> >>
> > You might want to check it again before you hand it in ;) ...
> >
> > >>> def ishwor( source ):
> > ---for item in source:
> >+++  for item in source[:]:
  if item == 'd':
> > ...source.remove( item )
> 
> that's not the code he quoted in the mail you replied to, though...
> 
;-)

[snip]

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


Re: list IndexError

2004-12-22 Thread Ishwor
On Wed, 22 Dec 2004 21:42:16 GMT, Steven Bethard
<[EMAIL PROTECTED]> wrote:
> Ishwor wrote:
> > i am trying to remove an item 'e' from the list l
> 
> I thought it might be helpful to code some of the alternatives you've
> been given and look at the timings to put things into perspective.  The
> code:
> 
>  remove.py 
> def remove_lc(x, lst):
> lst[:] = [item for item in lst if item != x]
> 
> def remove_list(x, lst):
> result = []
> for item in lst:
> if item != x:
> result.append(item)
> lst[:] = result
> 
> def remove_filter(x, lst):
> lst[:] = filter(lambda item: item != x, lst)
> 
> def remove_xrange(x, lst):
> for i in xrange(len(lst)-1, -1, -1):
> if lst[i] == x:
> del lst[i]
> 
> def remove_remove(x, lst):
> while x in lst:
> lst.remove(x)
> 
> def remove_try(x, lst):
> try:
> while True:
> lst.remove(x)
> except ValueError:
> pass
> 
> def remove_ishwor(x, lst):
> for item in lst[:]:
> if item == x:
> lst.remove(x);
> --
> 
> First, some timings when only 1 out of every 1000 elements needs to be
> removed.  Timings were taken with Python 2.4 on a 2.26 Ghz Windows box
> using:
> $ python -m timeit -s "import remove; lst = [x % 1000 for x in
> xrange(1)]" "remove.remove_(500, lst)"
> 
> remove_remove:  516 usec per loop
> remove_try: 604 usec per loop
> remove_ishwor: 1.61 msec per loop
> remove_xrange: 2.29 msec per loop
> remove_lc: 2.37 msec per loop
> remove_list:   5.3  msec per loop
> remove_filter: 5.65 msec per loop
> 
> Now, some timings when 1 out of every 10 elements needs to be removed.
> Timings were taken using:
> $ python -m timeit -s "import remove; lst = [x % 10 for x in
> xrange(1)]" "remove.remove_(5, lst)"
> 
> remove_lc:  2.03 msec per loop
> remove_xrange:  2.08 msec per loop
> remove_list:4.72 msec per loop
> remove_filter:  5.17 msec per loop
> remove_try:30.7  msec per loop
> remove_ishwor: 31.5  msec per loop
> remove_remove: 60.2  msec per loop
> 
> The moral of the story here is that, if the items to be removed only
> make up a very small percentage of the list, an approach like
> remove_remove or remove_try might be okay.  On the other hand, if you
> expect the items to be removed will make up even a moderate percentage
> of the list (e.g. 10%), then remove_lc or remove_xrange is a vastly
> better alternative.
> 
> Steve
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
umm... looks good.. i am running these task sets on my box as well
slightly slower than yours 2.4Ghz... thanx Steve. :-) now i'll sit
back and dwell a bit deeper into it now.


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


Re: list IndexError

2004-12-22 Thread Ishwor
On Thu, 23 Dec 2004 07:27:52 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote:
> On Thu, 23 Dec 2004 06:56:02 +1030, Ishwor <[EMAIL PROTECTED]> wrote:
> 
> >>>> l
> > ['a', 'b', 'c', 'd', 'e']
> >>>> for x in l[:]:
> >if x == 'd':
> >l.remove('d');
> >
> >>>> l
> > ['a', 'b', 'c', 'e']
> > This code is so clean and looks very healthy.  Python will live a
> > long way because its a cute language.
> 
> imho the code is very unhealthy, i would write
> l = ['a', 'b', 'c', 'd', 'e']
> l.remove('d')
> print l
> 
> btw what are you using ';' for

I am learning Python. I used 'for' specifically so that i could
iterate over the list and delete the values. It was a dumb one.. thanx
for pointing it out but i specifically wanted to understand how
slicing work. :-)
thanks anyway.

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


Re: list IndexError

2004-12-22 Thread Ishwor
On Wed, 22 Dec 2004 14:59:32 -0500, Mike C. Fletcher
<[EMAIL PROTECTED]> wrote:

[snip]

>
> Probably the most pythonic approach to this problem when dealing with
> small lists is this:
>
>result = [ item for item in source if item != 'e' ]
>
> or, if you're using an older version of Python without list comprehensions:
>
>filter( lambda item: item!='e', source )
>

I believe lamda's are unnamed functions aren't they?? Still learning... ;-)

> or even (expanding the list comprehension):
>
>result = []
>for item in source:
>   if item != 'e':
>  result.append( item )
>
> The "python"-ness of the solutions is that we are using filtering to
> create a new list, which is often a cleaner approach than modifying a
> list in-place.  If you want to modify the original list you can simply
> do source[:] = result[:] with any of those patterns.
>

yeah actually i saw what Fedrik had to say above. I created a sliced
copy of the l & did my homework within the for loop

>>> l
['a', 'b', 'c', 'd', 'e']
>>> for x in l[:]:
   if x == 'd':
   l.remove('d');

>>> l
['a', 'b', 'c', 'e']

This code is so clean and looks very healthy. :) Python will live a
long way because its a cute language. :-)

> If you really do need/want in-place modification, these patterns are
> quite serviceable in many instances:
>
># keep in mind, scans list multiple times, can be slow
>while 'e' in source:
>   source.remove('e')
>
> or (and this is evil C-like code):
>
>for index in xrange( len(source)-1, -1, -1 ):
>   if source[i] == 'e':
>  del source[i]
> 
thanx Mike, i have tried this C-ish way as well . :-) it seemed quiete
ok for my  small list but dont know about huge lists.

> Keep in mind that, in the presence of threading, any index-based scheme
> is likely to blow up in your face (even the filtering solutions can
> produce unexpected results, but they are generally not going to raise
> IndexErrors due to off-the-end-of-the-list operations).
>

Every 2-4 hours i check the c.l.py ... Its so nice that i learn new
things everyday in this list.. (some are goood but some are extremely
subjective!!)
Lastly i personally feel that Python's way of trying things out before
implementing is really healthy way of programming. Especially towards
XP oriented projects. :-)

Thanks Fredrik and Mike.
-- 
http://mail.python.org/mailman/listinfo/python-list


list IndexError

2004-12-22 Thread Ishwor
i am trying to remove an item 'e' from the list l but i keep getting IndexError.
I know the size of the list l is changing in the for loop & its sort
of trivial task but i found no other way than to suppress the
IndexError by doing a pass. any other ways you guys can suggest? Also
is this a good or bad habit in Python? someone may perhaps suggest a
better way which i am unaware of?? the deletion could be invoked from
user input (command line) as well so its not limited to 'e'( as in my
code)

>>> l
['a', 'b', 'c', 'e', 'm']
>>> for i in range(0,len(l)):
if l[i] == 'e': 
l.pop(i);


'e'

Traceback (most recent call last):
  File "", line 2, in -toplevel-
if l[i] == 'e':
IndexError: list index out of range
>>> l
['a', 'b', 'c', 'm']


==Using suppressing technique( a bad one though :-) )==
>>> l
['a', 'b', 'c', 'm', 'd']
>> for i in range(0,len(l)):
try:
if l[i] == 'e':
l.pop(i);
except IndexError:
pass;

>>> l
['a', 'b', 'c', 'm', 'd']

==Using suppressing technique

Any type of code changing/improving ways is heartily welcomed ;-)

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


Re: Threading Problem

2004-12-22 Thread Ishwor
On Wed, 22 Dec 2004 12:55:46 +, Alan Kennedy <[EMAIL PROTECTED]> wrote:
> [Norbert]
> > i am experimenting with threads and get puzzling results.
> > Consider the following example:
> > #
> > import threading, time
> >
> > def threadfunction():
> > print "threadfunction: entered"
> > x = 10
> > while x < 40:
> > time.sleep(1) # time unit is seconds
> > print "threadfunction x=%d" % x
> > x += 10
> >
> >
> >
> > print "start"
> > th = threading.Thread(target = threadfunction())
> 
> The problem is here^^
> 
> You are *invoking* threadfunction, and passing its return value as the
> target, rather than passing the function itself as the target. That's
> why threadfunction's output appears in the output stream before the
> thread has even started.
> 
> Try this instead
> 
> #---
> 
> import threading, time
> 
> def threadfunction():
>   print "threadfunction: entered"
>   x = 10
>   while x < 40:
> time.sleep(1) # time unit is seconds
> print "threadfunction x=%d" % x
> x += 10
> 
> print "start"
> th = threading.Thread(target = threadfunction)
> th.start()
> print "start completed"
> 
> #
> 
> Which should output the expected
> 
> >
> start
> threadfunction: entered
> start completed
> threadfunction x=10
> threadfunction x=20
> threadfunction x=30
> 
> regards,
> 
> --
> alan kennedy
> --
> email alan:  http://xhaus.com/contact/alan

nice chum ;) liked the way you explained. Clear and easy to
understand.. why doesn't the keyboardInterrupt seem to work? I am
working in IDLE and it doesn't seem to stop the thread ???!!??
output of above code in IDLE shell:

threadfunction x=75

KeyboardInterrupt
>>> 
threadfunction x=80



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


TwistedMatrix everywhere!!

2004-12-07 Thread Ishwor
Hello all,
  Since i see alot of talks abt TwistedMatrix these days, i just
checked its website to see what it is all about ( I am still learning
Python). Anyway my point here is that for running the examples
( in http://twistedmatrix.com/documents/current/examples/ ), I'll have
to get the various different Twisted modules ( from Twisted import
Transport etc...) . I was wondering if that could be done like Java's
WebStart like loading all the modules on the fly?? Is there any such
implementation which exists in Python- any module which can load any
Python Source and compile any other dependent modules on the fly at
client side?? Any ideas are greatly welcomed ~:-)


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


Re: win32 extensions for Python 2.4

2004-12-07 Thread Ishwor
On Tue, 07 Dec 2004 21:00:22 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote:
> Ishwor wrote:
> 
> 
> > Hello all,
> >   I was looking through Mark Hammond's website for win32 extensions
> > for Python 2.4 but couldn't find it. If i am not wrong has anyone any
> > idea when it will be available or is it being worked on? The
> > activestate's version of Python has win32 extension but i won't be
> > bothered to download it. :)
> > 
> It's on the sourceforge download page. So long as you don't want to use
> Pythonwin, version 203 should work fine.
> 

arggh... got the wrong version.. ;-)
Thanks heaps.

> Cheers,
> Nick.
[snip]

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


win32 extensions for Python 2.4

2004-12-07 Thread Ishwor
Hello all,
  I was looking through Mark Hammond's website for win32 extensions
for Python 2.4 but couldn't find it. If i am not wrong has anyone any
idea when it will be available or is it being worked on? The
activestate's version of Python has win32 extension but i won't be
bothered to download it. :)

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


Re: string slicing

2004-12-05 Thread Ishwor
I didn't mean to be extremely rude. Just a little bit..~:-). sorry.

On Sun, 05 Dec 2004 12:09:22 -0800, Josiah Carlson <[EMAIL PROTECTED]> wrote:
> 
[snip]

> 
> Goodness, you got right snippy with the 'intellectual property' thing.
> I'm sorry if it sounded as if I had meant "I came up with this before",
> I did not mean it that way.  What I meant was "good advice", "I've seen
> this advice before", and "I've previously taken note of it".  As an
> aside, I also believe that if Fredrik were concerned about my supposed
> theft of his 'advice IP', he would mention it
> 
> Confusions about 'is' are quite common.  Perhaps every week a new thread
> in regards to object identity is offered, usually asking about integer,
> string or list identity.  I'm not having much luck with the google
> incantation right now, but my email archive is spitting back a thread on
> "interning strings" from early November, which discusses strings and
> identity.
> 
> Really, everyone who is thinking of using 'is' should ask themselves
> whether or not it is truely important to have the same object.  In some
> cases it matters, and in others cases it doesn't matter.  The more
> experience one has with Python and the implementations of algorithms,
> the more obvious such choices will become.
> 
> A perfect example of a case when using 'is' is proper is by Barry Warsaw
> (http://mail.python.org/pipermail/python-dev/2004-March/043224.html):
> 
> missing = object()
> 
> if d.get('somekey', missing) is missing:
>   # it ain't there
> 
> In the case of it not mattering, there was a series of threads in March
> of this year in python-dev, discussing replacing the 'is' operator
> strictly comparing object identity with a 'can be replaced by' operator,
> spelled 'is'.  See the threads entitled "redefining is" here:
> http://mail.python.org/pipermail/python-dev/2004-March/thread.html
> Of course it came out that it didn't happen ('is' is much faster, and
> doesn't require objects to define a mechanism to get at their contents,
> etc.), but it is not uncommon for people who think they want 'is' to
> really want 'can be replaced by', especially in the case of tuples:
> 
> >>> a = tuple(list('hello'))
> >>> b = tuple(list('hello'))
> >>> a == b
> True
> >>> a is b
> False
> >>> CanBeReplacedBy(a, b)
> True
> >>>
> 
> (of course you need a proper implementation of CanBeReplacedBy, of which
> a few are offered in the previously mentioned 'replacing is' threads).
> 
> Now, whether or not knowing what 'is' does, or whether knowing the
> internals in regards to how object identity works, is necessary for
> learning the language, I don't know.  It's been a few years since I was
> a newb, but considering all of the questions regarding 'is' usually
> resulting with python-list saying "you want '=='", I'd offer, 'it is not
> necessary'.
> 
> 
> - Josiah

Thanx. Appreciate it. :)

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


Re: Please help here: python <==> COM

2004-12-05 Thread Ishwor
heheh... this was funny in your posting. :)
 >The following *pythong* ( so this is what a Python wearing a thong
is called ..
 > hmmm...) code NOT work.. 

On Sun, 5 Dec 2004 16:18:33 +0800, mep <[EMAIL PROTECTED]> wrote:
> Resolved. Thanks anyway

[snip]

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


Re: string slicing

2004-12-05 Thread Ishwor
On Sun, 05 Dec 2004 10:31:12 -0800, Josiah Carlson <[EMAIL PROTECTED]> wrote:
> 
> "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> > a suggestion: if you really want to be productive in python, forget about
> > "is" for a while.

I know what Fredrik means here (Thanx Frederick :) ) but IMHO if the
pattern of forgetting something is taken everytime someone tries to
scratch under the hood, then seriously it'll take ages before someone
seriously learns a language!
 
> The above two tips are in my "top-10 things to tell newbs" list.

You should consider having your own *nice* nifty things to say about
newbs (like me) rather than try to point at someone else's
intellectual property. If you are running out of ideas consider
reading one of those "Complete Idiot's guide to " :)

> - Josiah
[snip]

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


Re: string slicing

2004-12-05 Thread Ishwor
On Sun, 05 Dec 2004 09:44:13 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:

[snip]

> 
> This behaviour is due to the way strings are handled. In some cases strings 
> are 'interned' which
> lets the interpreter keep only a single copy of a string. If you try it with 
> a list you get a
> different result:
> 
> >>> s=list('hello')
> >>> s
> ['h', 'e', 'l', 'l', 'o']
> >>> m=s[:]
> >>> m
> ['h', 'e', 'l', 'l', 'o']
> >>> m is s
> False
> 
> Kent

Thanx Kent.  so for lists Python doesn't keep the same object in the
cache??? So in that case it is not interned & hence any objects
created will **point** to seperate area in memory as seen by your
>>> m is s  #( for lists) 
>>> False

Thanx again :)
[snip]

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


string slicing

2004-12-05 Thread Ishwor
Hello all ,
  I am trying some interactive examples here where i have come across
inconsistencies??? :O
Anyway heres whats bothering me

>>> s = 'hello'
>>> s[0]
'h'
>>> s[:]
'hello'
>>> m = s[:]
>>> m
'hello'
>>> m is s
True

 I discussed the *is* operator with some of the pythoners before as
well but it is somewhat different than what i intended it to do. The
LP2E by Mark & David says -
" m gets a *full top-level copy* of a sequence object- an object with
the same value but distinct piece of memory." but when i test them
with *is* operator then the result is True. Why is this happening??
Any help is appreciated.. Thanx


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


Re: os.listdir("\\\\delta\\public")

2004-12-04 Thread Ishwor
On Sat, 04 Dec 2004 11:40:15 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:

> As Michael points out, there's no reason to think that should
> have worked.  You can't do a directory of a computer, only
> a drive on the computer, and likewise you can't do a directory
> of a computer on a network, only of the resources is shares.
> 
> Try grabbing the output of os.popen(r"net view \\delta") and
> parse it to get a list of the shares:
> 
> c:\>net view \\monolith
> Shared resources at \\monolith
> Share name  Type   Used as  Comment
> ---
> Printer Print   Microsoft Office Document Image Writer
> Printer2Print   hp psc 1310 series
> Printer3Print   HP LaserJet 4
> shared  Disk   I:
> SharedDocs  Disk
> The command completed successfully.
> 
> No doubt you can also do this much more easily with the pywin32
> package, or via COM (using pywin32 or ctypes), but I'll leave
> that response to someone else.  Or you could figure it out yourself
> if you are motivated enough.
> 
> -Peter
[snip]

sorry my mistake :)
-- 
cheers,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Opening a file in Python using windows.

2004-12-04 Thread Ishwor
On 3 Dec 2004 08:38:37 -0800, ed <[EMAIL PROTECTED]> wrote:
> I do have  permission toa ccess the file as that file is careted and read my 
> me.
> I have read/write access to that location. regards

That shouldn't be really hard. :)
okay imagine you have a file called test.txt in C:\Python24\
now go to the IDLE prompt if you have one or just use Python prompt.
I am assuming you know what they are & how to do them. :) If you don't
then go read some books. :)

There  are two basic in-built operations to open a file.
The first one is open & the the obvious other one is called file.
file is just an alias for open.

type these lines in the prompt

>>> open("C:\\Python24\\test.txt",'r').readlines()
['This is test file. :)']

So thats there.. the whole file in a line :).. However remember that
it returns a list for further processing if you want to or just forget
it. if you break up those above line into 2 lines then they become

>>> test = open("C:\\Python24\\test.txt",'r') # read-only
>>> test.readlines()
['This is test file. :)']

So there you have it. The power of Python. The first line opens a file
object & places
the output at certain address in the computer memory & test
*references* that address. The second line (test.readlines()) reads
the actuall stream of bytes from that location. :)

> > If you do not have permission to access the files, switching to a
> > different language will not help you.  You need to determine the cause
> > of your access errors first.

Agreed but the OP does have permission so this assumption doesn't hold!

[snip]


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


os.listdir("\\\\delta\\public")

2004-12-04 Thread Ishwor
hi check your seperator variable in the os module.
:)
for example

>>> import os
>>> os.sep
'\\'
Now what you do is :-
>> os.listdir("D:" + os.sep + "any_other_folder_name" + os.sep);
:)

Have a look at the error below which is same as yours. The seperator
variable is put after the drive name and not before the drive name.
>>> os.listdir("\\c");

Traceback (most recent call last):
 File "", line 1, in -toplevel-
   os.listdir("\\c");
WindowsError: [Errno 3] The system cannot find the path specified: '\\c/*.*'

In Linux this would be somewhat like this
>>> os.listdir("/dev");
In general use the most platform independent variable names (e.g
os.sep) unless you intend the program to be used only by yourself. :)

[snip]

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


distinction between float & int

2004-12-03 Thread Ishwor
hi all,
 can anyone tell me why this distinction? i mean why it returns False
on floats??
>>> a = 1
>>> b = 1
>>> a is b
True
>>> a = 1.1
>>> b = 1.1
>>> a is b
False
>>> 

thanx .
-- 
cheers,
Ishwor Gurung
-- 
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


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