Help on Swig

2005-08-05 Thread Gurpreet Sachdeva

Hi,
I am facing a problem with swig while using Pointers:

Array.c
#includestdio.h
void Array(int *ptr)
{
int i;
for (i = 0; i  6; i++)
{
printf(Index: %d - %d\n,i, *(ptr + i));
}
}
Array.i
%module Array
%{
extern void Array(int *ptr);
#includestdio.h
%}
extern void Array(int *ptr);

While running:

 import Array
 a=[1,3,2,4,5,6,7,9]
 Array.Array(a)
Traceback (most recent call last):
 File stdin, line 1, in ?
TypeError: argument number 1: a 'int *' is expected, 'list([1, 3, 2, 4, 5, 6, 7, 9])' is received

Do I need to make some changes in Interface file?
Also I need to return that array after sorting it. How do I return it and collect the same in python.

Thanks and Regards,





Cheers!


«·´`·.(*·.¸(`·.¸ ¸.·´)¸.·*).·´`·»

   «.[ Garry].» 

«·´`·.(¸.·*(¸.·´ `·.¸)*·.¸).·´`·»

Blogging athttp://garrythegambler.blogspot.com/

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

Operator Overloading

2005-08-01 Thread Gurpreet Sachdeva

 
Hi,

Is there any provision in python which allows me to make my own operators?

My problem is that I need to combine two dictonaries with their keys and I don't want to use any of the existing operators like '+','-','*'.
So is there a way I can make '**' or '~' as my operators to add two dictonaries? If not which all operators can I overoad?

Thanks,
Garry

http://garrythegambler.blogspot.com



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

Re: Friend wants to learn python

2005-07-27 Thread Gurpreet Sachdeva

 
http://www.byteofpython.info/download

Wonderful book for newbie!

Regards,
G
Blogs: http://garrythegambler.blogspot.com/



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

Re: f*cking re module

2005-07-04 Thread Gurpreet Sachdeva
try:
re.search((python)(/python), str).group()
except:
print 'not found'

otherwise,

 re.search((python).*?(\/python), str).group()

this is will help!

Regards,
Gurpreet Singh

Blogging [at] http://garrythegambler.blogspot.com

On 4 Jul 2005 01:04:47 -0700, jwaixs [EMAIL PROTECTED] wrote:
 arg... I've lost 1.5 hours of my precious time to try letting re work
 correcty. There's really not a single good re tutorial or documentation
 I could found! There are only reference, and if you don't know how a
 module work you won't learn it from a reference!
 
 This is the problem:
 
  import re
  str = blablapythonRe modules sucks!/pythonblabla
  re.search((python)(/python), str).group()
 Traceback (most recent call last):
   File stdin, line 1, in ?
 AttributeError: 'NoneType' object has no attribute 'group'
 
 the only thing I want are the number of places blabla, Re modules
 sucks! and blabla are.
 
 Noud
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 


-- 
Thanks and Regards,
GSS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting into Python, comming from Perl.

2005-04-25 Thread Gurpreet Sachdeva
I also coded for more than 3 years and eventually I got that I was not
coding but writting poems in perl... Even after 3 months, I go back
and check my hand written code, I had to think twice about the logic
used...
Now its pretty much systematic which incode dcoumentation and
programming structure.

Rest both are blessed by open source...

Regards,
Garry

On 4/24/05, Miguel Manso [EMAIL PROTECTED] wrote:
 Hi, list.
 
 I'm into a psicological doubt that I would like to share with you
 (you'll know why later on this mail).
 
 I'm a programmer with 5 year of experience into Perl. I'm on that point
 where you resolve problems without thinking on HOW you'll do it with
 that language but only on the problem itself.
 
 Since Perl 6 started I've been following it. The conclusion I have is
 they're making a whole new language and I'll have to learn it. This
 being said and, since I've to learn a new language, I've started
 thinking in a new language. I've noticed Python is getting more and more
 developers and many projects are being made.
 
 I've tryed to use python some times but I get frustrated very quick. I
 get myself many times needing to figure out how to loop through a list,
 declare an associative array, checking how to pass named parameters to
 functions, and simple things like that.
 
 What I would like to know is if anyone had these problems and if you can
 share that experience with me. I'm trying to minimize my frustration :)
 
 Thanks a lot.
 
 --
 Miguel Manso [EMAIL PROTECTED]
 
 Amplitude Net
 Net - Rua dos Salazares, 842
 4100-442 Porto
 
 Phone: +351 22 532 2000
 Fax: +351 22 618 2157
 Web: www.amplitudenet.pt
 
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 


-- 
Thanks and Regards,
GSS
--
http://mail.python.org/mailman/listinfo/python-list


Module for handling Nested Tables in HTML

2005-04-12 Thread Gurpreet Sachdeva
Hi guys,

Can anyone suggest some good tool for handling nested
tables in a HTML page... BeautifulSoup is somehow not working with
Nested Tables.

Thanks and Regards,
Garry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expressions: large amount of or's

2005-03-02 Thread Gurpreet Sachdeva
Can divide the regex on the bases of alphabets they are starting with
or can iterate on the list.

Regards,
Garry

http://garrythegambler.blogspot.com/


On Wed, 02 Mar 2005 12:50:01 +0100, André Søreng [EMAIL PROTECTED] wrote:
 Ola Natvig wrote:
  André Søreng wrote:
 
 
 
  Yes, but I was looking for a solution which would scale. Searching
  through the same string 1+++ times does not seem like a suitable
  solution.
 
  André
 
 
  Just for curiosity, what would a regexp do? Perhaps it's a clue in how
  you could do this in the way regexp's are executed.
 
  ola
 
 
 I think this article provides me with what I was looking for:
 
 http://alexandria.tue.nl/extra1/wskrap/publichtml/200407.pdf
 
 Enough info there to keep me going for some while.
 --
 http://mail.python.org/mailman/listinfo/python-list
 


-- 
Thanks and Regards,
GSS
--
http://mail.python.org/mailman/listinfo/python-list


Re: Google Technology

2005-03-01 Thread Gurpreet Sachdeva
 : I am just wondering which technologies google is using for gmail and
 : Google Groups???


Check this:
http://tools.devshed.com/c/a/Search%20Engine%20Tricks/To-the-next-level-with-Google-Groups-2

Regards,
Garry

http://garrythegambler.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Error in pywordnet

2005-02-26 Thread Gurpreet Sachdeva
I am using pywordnet and when ever I import the package
from wordnet import *, I get an error:

Exception exceptions.AttributeError: DbfilenameShelf instance has no
attribute 'writeback' in  ignored

Now the package works fine until I tried to use that in Apache via
CGI. Apache is showing a Server Error and the error_logs states that:

[Fri Feb 25 16:06:08 2005] [error] [client 192.168.1.125] from
wordnet import *, referer: http://garry/cgi-bin/test.py
[Fri Feb 25 16:06:08 2005] [error] [client 192.168.1.125] ImportError:
No module named wordnet, referer: http://garry/cgi-bin/test.py

While googling, I found:
It is a simple fix that adds the writeback argument to shelve.open calls.

Source:
http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?forum=185thread=72747cat=11

Do anyone have any idea about that? Is there any fix or workaround?

Thanks and Regards,
Garry

http://garrythegambler.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Two classes problem

2005-02-02 Thread Gurpreet Sachdeva
I have two classes;

a.py --

#!/usr/bin/python
global test
test =''
class a(b):
def __init__(self,test):
print test
print 'Outside: '+test

b.py --

#!/usr/bin/python
import a
a.a('Garry')

I want to pass this string (or any object later) to a.py and that too
outside the scope of class a.
Is that possible??? If yes, how???

Thanks,

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


Problem in importing MySQLdb

2005-01-20 Thread Gurpreet Sachdeva
I am using Mysql version 5.0.2-alpha on RedHat 9.0 (python2.2)

When I try to import MySQldb

I get:
Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type help, copyright, credits or license for more information.
 import MySQLdb
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /usr/lib/python2.2/site-packages/MySQLdb/__init__.py, line 27, in ?
import _mysql
ImportError: /usr/lib/libmysqlclient.so.10: symbol errno, version
GLIBC_2.0 not defined in file libc.so.6 with link time reference

Is there any problem in library files?? Do I need to install anything
I have installed MySQL-shared-3.23.54a-1.i386.rpm,
MySQL-devel-5.0.2-0.i386.rpm, MySQL-client-5.0.2-0.i386.rpm,
MySQL-server-5.0.2-0.i386.rpm

Please help,
Garry
-- 
http://mail.python.org/mailman/listinfo/python-list


pyPgSQL giving error!

2005-01-13 Thread Gurpreet Sachdeva
I am using Redhat 9.0/python2.3. I installed pyPgSQL-2.4.tar.gz and it
was successfull. Now when I am trying to import that module, I got:

Python 2.3.3 (#1, Jan 11 2005, 15:24:09)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type help, copyright, credits or license for more information.
 from pyPgSQL import PgSQL
Traceback (most recent call last):
  File stdin, line 1, in ?
  File pyPgSQL/PgSQL.py, line 391, in ?
from libpq import *
  File pyPgSQL/libpq/__init__.py, line 23, in ?
from libpq import *
ImportError: No module named libpq

I tried googling also but couldn't get the answere.
Please help...

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


Re: pyPgSQL giving error!

2005-01-13 Thread Gurpreet Sachdeva
 did you really do ./configure, make and make install?
No, I did python setup.py build and python setup.py install

 where is libpq.*
linpq is there in /usr/lib/python2.3/site-packages/pyPgSQL/

 was a postgres installation present while doing ./configure et all?

No, But I installed postgresql-libs before installing pyPgSQL

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


Re: pyPgSQL giving error!

2005-01-13 Thread Gurpreet Sachdeva
And now when I did...

cd /usr/local/lib/python2.3/site-packages/pyPgSQL/libpq/

[EMAIL PROTECTED] libpq]# python __init__.py
Traceback (most recent call last):
  File __init__.py, line 23, in ?
from libpq import *
ImportError: ./libpqmodule.so: undefined symbol: PyUnicodeUCS2_EncodeDecimal

What is this error??? I saw this error sometimes back... Please help...

Thanks,
Garry
-- 
http://mail.python.org/mailman/listinfo/python-list


Upgraded to python2.3 but httpd taking old version

2005-01-11 Thread Gurpreet Sachdeva
I upgraded my python to 2.3 from 2.2 but Apache (V 2.0.4) is taking
old libraries for processing. I also made a soft link redirecting the
old files to new files but of no help... These error logs shows that
it is still using 2.2 :o(

[Tue Jan 11 16:18:45 2005] [error] [client 127.0.0.1] import cgi
[Tue Jan 11 16:18:45 2005] [error] [client 127.0.0.1]   File
/usr/lib/python2.2/cgi.py, line 38, in ?

Please help
-- Garry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file.readlines() - gives me error (bad file descriptor)

2005-01-06 Thread Gurpreet Sachdeva
On Thu, 6 Jan 2005 14:27:40 +0530, Binu K S [EMAIL PROTECTED] wrote:
 I'm sorry, I didn't get what you trying to say here. Where do you see
 a read altering the file? An example might help.

Please try:

logfile=file(r'test.txt','w+')
logfile.write('datetime')

Check the contents of test.txt, you will get what ever was required...

Now Run:

logfile=file(r'test.txt','w+')
logfile.write('datetime')
logfile.readlines()

and check the contents of test.txt???
My doubt is that logfile.write('datetime') will write datetime that is
universaly accepted but why all that junk is appending to that when I
add logfile.readlines()

Strange or Am I on drugs??? :o)

Please Comment...

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


Re: file.readlines() - gives me error (bad file descriptor)

2005-01-05 Thread Gurpreet Sachdeva
I tried 
logfile=file(r'test.txt','w+')
logfile.write('datetime')
test=logfile.readlines()
print test

I got :
Open an encoded file using the given mode and return
a wrapped version providing transparent encoding/decoding.

Note: The wrapped version will only accept the object format
defined by the codecs, i.e. Unicode objects for most builtin
codecs. Output is also codec dependent and will usually by
Unicode as well.

Files are always opened in binary mode, even if no binary mode
was specified. This is done to avoid data loss due to encodings
using 8-bit values. The default file mode is 'rb' meaning to
open the file in binary read mode.

encoding specifies the encoding which is to be used for the
file.

errors may be given to define the error handling. It defaults
to 'strict' which causes ValueErrors to be raised in case an
encoding 
and a hell lot of junk. Can anyone explain that???
AFAIK w+ was ment for opening a file for both writting and reading...

Regards,
Garry


On Thu, 6 Jan 2005 12:03:27 +0530, Vishnu [EMAIL PROTECTED] wrote:
 logfile = file(r'test.txt','w')
 logfile.write('datetime')
 logfile.close() # - close the file
 
 logfile = file(r'test.txt','r') # - Open the file in read mode
 test=logfile.readlines()
 
 
 ~Vishnu.
 
 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of
 [EMAIL PROTECTED]
 Sent: Thursday, January 06, 2005 11:53 AM
 To: python-list@python.org
 Subject: file.readlines() - gives me error (bad file descriptor)
 
 Hey guys,
 
 I can't figure this one out, why is this simple script giving me
 problems?
 
 logfile=file(r'test.txt','w')
 logfile.write('datetime')
 test=logfile.readlines()
 
 When I run it I get the error message:
 Traceback (most recent call last):
 File C:\Documents and Settings\Gregory\My Documents\Get New Great
 Job\testfile.py, line 3, in ?
 test=logfile.readlines()
 IOError: [Errno 9] Bad file descriptor
 
 I'm running Windows XP, Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC
 v.1200 32 bit (Intel)] on win32
 Any help would be greatly appricated.
 
 Thanks,
 
 Greg
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 


-- 
Thanks and Regards,
GSS
--
http://mail.python.org/mailman/listinfo/python-list


Re: file.readlines() - gives me error (bad file descriptor)

2005-01-05 Thread Gurpreet Sachdeva
logfile=file(r'test.txt','a+')
logfile.write('datetime')
logfile.flush()
test=logfile.readlines()
print test

I added logfile.flush(), the 'datetime' was written in the file
correctly but I couldn't get any result...

Crazy!
Garry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file.readlines() - gives me error (bad file descriptor)

2005-01-05 Thread Gurpreet Sachdeva
On Thu, 6 Jan 2005 12:55:22 +0530, Binu K S [EMAIL PROTECTED] wrote:
The file's current position moves as you write into it.
I concure and have figured out the solution BUT while reading from the
file from the position where the file handler is, should return
Null/Blank/Anything in this world BUT should not write into the
file...
The information written was that in the Buffer of the handler... Does
that mean reading a file will actually release the buffer by throwing
the contents in the file???

Please Comment...

You normally wouldn't read from the file that you are writing into.

May be applicable in handling logs...

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


Problem in threading

2004-12-29 Thread Gurpreet Sachdeva
I have written a code to figure out the difference in excecution time
of a func before and after using threading...

[CODE]
#!/usr/bin/env python

import threading
import time
loops = [5000,5000]

def loop(self, nsec):
for i in range(1,nsec):
t=i*5000
s=t/10*1

def main():
threads = []
nloops = [0,1]
for i in nloops:
print '\nSpawning Thread',i,' value: ',loops[i]
t = threading.Thread(target=loop,args=(i, loops[i]))
threads.append(t)

for i in nloops: # start threads
threads[i].start()

for i in nloops: # wait for all
threads[i].join

if __name__ == '__main__':
start = time.clock()
loop(1,5000)
print 'Time Taken: ', time.clock()-start
start = time.clock()
main()
print 'Time Taken: ', time.clock()-start
[/CODE]

Some times this code executes and some times it hangs to death :o(
Am I am doing something wrong?? Also the difference of time is not much...
How do we best optimize our task by using threads... please help...

Thanks and Regards,
Gurpreet Singh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem in threading

2004-12-29 Thread Gurpreet Sachdeva
threads[i].join()

Oh thanks I corrected that but still the time taken after using thread
is more without using them

Please Advice...
Thanks,
Gurpreet Singh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem in threading

2004-12-29 Thread Gurpreet Sachdeva
I wrote:
 Also the difference of time is not much...
 How do we best optimize our task by using threads... please help...

Duncan Booth Wrote:
The only times when it may result in a decrease
in the running time... are when the time the task...when
 multiple CPU's are involved.
I fotgot to mention that I am running that script on a 4 node Open SSI
cluster with 8 processors to do the job...

 Unfortunately the latter case isn't handled well by Python
Very Strange!

 A good use of threads is to improve responsiveness of a system. For example
 if you ensure that GUI processing happens on a separate thread from some
 CPU intensive computation then you can ensure that the GUI remains
 responsive while the computation is running. It won't make the computation
 complete any faster (in fact it will probably be slower), but the user will
 remain happier. Similarly network applications are usually multi-threaded
 so that all requests get a fair chance to complete instead of having to
 wait for the slowest to complete before others can run.

So That means blindly using threads on any process won't help!

probably have to look at multiple processes rather than
 multiple threads.

How do I do that??? Does that mean forking the processes or does that
mean to change the entire architecture to do small tasks in different
processes???

Alternatively you could move parts of the processing out
 of the Python environment by rewriting inner loops in C

Any reference/documentation for that???

Thanks and Regards
Gurpreet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem in threading

2004-12-29 Thread Gurpreet Sachdeva
 So That means blindly using threads on any process won't help!
 It depends on what help means to you.

Help means to improve processing speed in achieving a particular
task... *Help* here also means that I have a processor farm, how do I
best use them to get maximum processing speed out of them...

 The example you listed isn't a good use of thread for performance

The example was a dummy one to become friendly with Threads and to
understand the working/power of them... The example which will be
finally used with threads take 5 Days to complete... I want to convert
that in few hours!

Long Journey ahead...

Thanks,
Garry
-- 
http://mail.python.org/mailman/listinfo/python-list


Python on Linux Cluster

2004-12-22 Thread Gurpreet Sachdeva
I have shifted my python script on a 4 node open ssi cluster. Please
guide me what changes do I have to do in my python scripts to fully
utilize the cluster. How do we introduce parralel processing in
python???

-- 
Thanks and Regards,
GSS
-- 
http://mail.python.org/mailman/listinfo/python-list


word to digit module

2004-12-21 Thread Gurpreet Sachdeva
Is there any module available that converts word like 'one', 'two',
'three' to corresponding digits 1, 2, 3??

Thanks and Regards,
GSS
-- 
http://mail.python.org/mailman/listinfo/python-list