extract Infobox contents

2009-04-06 Thread Anish Chapagain
Hi,
I was trying to extract wikipedia Infobox contents which is in format
like given below, from the opened URL page in Python.

{{ Infobox Software
| name   = Bash
| logo   = [[Image:bash-org.png|165px]]
| screenshot = [[Image:Bash demo.png|250px]]
| caption= Screenshot of bash and [[Bourne shell|sh]]
sessions demonstrating some features
| developer  = [[Chet Ramey]]
| latest release version = 4.0
| latest release date= {{release date|mf=yes|2009|02|20}}
| programming language   = [[C (programming language)|C]]
| operating system   = [[Cross-platform]]
| platform   = [[GNU]]
| language   = English, multilingual ([[gettext]])
| status = Active
| genre  = [[Unix shell]]
| source model   = [[Free software]]
| license= [[GNU General Public License]]
| website= [http://tiswww.case.edu/php/chet/bash/
bashtop.html Home page]
}} //upto this line

I need to extract all data between {{ Infobox ...to }}

Thank's if anyone can help,
am trying with

s1='{{ Infobox'
s2=len(s1)
pos1=data.find("{{ Infobox")
pos2=data.find("\n",pos2)

pat1=data.find("}}")

but am ending up getting one line at top only.

thank you,
--
http://mail.python.org/mailman/listinfo/python-list


Re: installing matplotlib with numpy and scipy for Python in Cygwin

2008-09-03 Thread Anish Chapagain
On Sep 3, 12:39 pm, Uwe Schmitt <[EMAIL PROTECTED]>
wrote:
> On 3 Sep., 11:42, "chapagainanish" <[EMAIL PROTECTED]> wrote:
>
> > Hi!!
> > I'm having installation problem for installing numpy and scipy in
> > Cygwin for Python, and am obstruct in madway for project, i followed
> > scipy.org guidelines but there's few error thrown as
> >         failed..with exit status 1
>
> > please if someone has installed these module help me
> > thank's and regard's
> > Anish
>
> http://cens.ioc.ee/~pearu/scipy/BUILD_WIN32.html
> may help you.
>
> Do you really want a cygwin based installation ?
> You could download enthoughts python edition which
> includes lots of math stuff.
>
> Greetings, Uwe

Hi,
thank's i'm looking through the link cens.ioc.ee
and am in need of using matplotlib and to run few system call, so i
installed cygwin baically for system call in linux/unix and matplotlib
for GUI(graph,chart) but matplotlib is not getting installed in
cygwin..

any further help will be heartly accepted

thank's
anish
--
http://mail.python.org/mailman/listinfo/python-list


installing matplotlib with cygwiin

2008-09-03 Thread Anish Chapagain
Hi!!
I need to run matplotlib for one project with pylab and scipy module,
i'm using cygwin so as to link system call operation with few GUI
support,
but am unable to install numpy and scipy without these matplotlib is
also not installed

Please help me for proper installation of these module in cygwin for
python, i followed scipy.org installation guidelines but having done
so, am not able to proper installation.

regard's
anish
--
http://mail.python.org/mailman/listinfo/python-list


Multiple window handling

2008-09-01 Thread Anish Chapagain
Hi!!
I'm trying to program an application which have multiple windows and
is capable of executing method defined inside class of one another, i
tries a simpel frame work here and am creating Toplevel inside method
as the new window to be genereated, and again want another window to
be loaded when the widget inside toplevel is executed as
necessary..but am feeling lost to either create a class for such new
window or write function again..

also, when running clearentry() it is not working...have i missed
something here..

Programming with multiple window is main task for me..so how it can be
done???

the code i tried is here,

from Tkinter import *
import sys
import os

class toplevel1(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.parent=parent
self.initialize()

def initialize(self):
label=Label(self, text="Toplevel Practice").pack(side=TOP)
button1=Button(self,text="Child
1",command=self.openchild1).pack(side=LEFT)
button2=Button(self,text="Child
2",command=self.openchild2).pack(side=LEFT)
self.resizable(width=NO,height=YES)
self.geometry('300x300')

def openchild1(self):
c1 =
Toplevel(self,bg="#aabbcc",height=300,width=300,borderwidth=1)
c1.title("Child One")

   c1.resizable(width=NO,height=NO)
F = Frame(c1,height=40,width=300)
F.pack(side=TOP,fill=X,expand=1)
llb=Label(F,text="Enter command..")
llb.pack(side=LEFT,padx=1)
ent = Entry(F,width=50)
ent.pack(side=LEFT,padx=2,expand=1)
bCl = Button(F,text="Clear Text",command=self.clearentry)
bCl.pack(side=LEFT,padx=2, pady=0)
bQt = Button(F,text="Quit", command=F.quit)
bQt.pack(side=RIGHT,padx=1, pady=0)

F1=Frame(c1,relief=SUNKEN,height=330,width=300)
txt=Text(F1)
 
scr=Scrollbar(F1,orient=VERTICAL,command=txt.yview,bg="green",width=20)
txt.insert(END,"inside txt...")
txt.config(yscrollcommand=scr.set)
F1.pack(side=TOP,fill=X,expand=1)
txt.pack(side=LEFT,fill=BOTH,padx=1)
scr.pack(side=RIGHT,fill=Y)

F2=Frame(c1,height=30,width=300,relief=RAISED)
F2.pack(side=BOTTOM,fill=X,expand=1)
llb1=Label(F2,text=" Low Down statusbar")
llb1.pack(side=LEFT)

def clearentry(self):
self.ent.delete(0,END)

def openchild2(self):
c2 =
Toplevel(self,bg="red",height=200,width=200,borderwidth=1)
c2.geometry('200x200')
c2.resizable(width=NO,height=NO)
c2.title("Child Two")
Label(c2, text="This is a regular toplevel
window.").pack(side=TOP)


if __name__=="__main__":
obj=toplevel1(None)
obj.title('Main Window')
obj.mainloop()
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with plotting

2008-08-29 Thread Anish Chapagain
On Aug 29, 12:24 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Aug 29, 6:01 am, Anish Chapagain <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > hi,
> > I'm getting problem with the code below which after displaying graph
> > plotted in external window, doesnot closes itself, even after closing
> > the window of plotting the main python window shows processing.
> > code goes like this...
>
> > plot(col1, col2, linewidth=1.0)
> > xlabel('col1')
> > ylabel('col2')
> > title('Values from List created with file read')
> > grid(True)
> > savefig('col1 col2.pdf')
> > show()
>
> > is there any other function to be called after show() to close it
> > properly.
>
> > thank's for any help.
>
> > anish
>
> what library/system are you using???- Hide quoted text -
>
> - Show quoted text -



Hi..
am using pylab

and have added the
 print "plotting finished"
after show() which get's printed in python main window but then
doesnot return to prompt and have to kill the window again.

regard's#
anish
--
http://mail.python.org/mailman/listinfo/python-list


problem with plotting

2008-08-29 Thread Anish Chapagain
hi,
I'm getting problem with the code below which after displaying graph
plotted in external window, doesnot closes itself, even after closing
the window of plotting the main python window shows processing.
code goes like this...

plot(col1, col2, linewidth=1.0)
xlabel('col1')
ylabel('col2')
title('Values from List created with file read')
grid(True)
savefig('col1 col2.pdf')
show()


is there any other function to be called after show() to close it
properly.

thank's for any help.

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


file data to list

2008-08-28 Thread Anish Chapagain
Hi!!
I am facing problem for extracting file data to the list so as to have
graph plotted through list.
my file(eg: data.txt) is having data like this,

cnt0001a 29000 xretya 01
cnt0002a 29850 brishal 02
cnt0003a 31250 kristal 03

from here, I need to copy data 29000, 29850, 31250 into a single list
and
01, 02, 03 to another so as to plot graph using these value.

regard's
NepaliWorld
--
http://mail.python.org/mailman/listinfo/python-list


Re: handling Struct and global function for C module

2008-08-18 Thread Anish Chapagain
On Aug 18, 8:43 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Anish Chapagain wrote:
> > but while running setup.py build with distutils it's showing error as
>
> > _ex.o: In function 'init_arguments':
> >      _ex.c :89: undefined reference to _TLM_read_model
> >      _ex.c :95:  undefined reference to _TLM_set_tag
>
> > for all the global function declared within .h file and the calling
> > method from .c file,
>
> your code doesn't match the error messages, and doesn't seem to be a
> Python extension at all.  are you sure you posted this to the right
> newsgroup?
>
> 

hi,
i am thinking now that may be it;s realted to the cygwin package that
i'm using with python in win XP, but still mine .c file has structure
element and structure is in .h file so how can i pass on value to
structure element,
it shows as ex_debugType_get(), ex_debugType_set()...can i assign
value to member creating own function..want some help for this...

thank's
--
http://mail.python.org/mailman/listinfo/python-list


handling Struct and global function for C module

2008-08-18 Thread Anish Chapagain
Hi,
I have Structure in C, program and the structure is being used with
various function inside C coding but am getting undefined referenced
to global method and few of them too uses the sturct module.
my problem goes like this,

ex.h
---
#define NIL 0   /* Indicates ptr is nil */
#define NO_CODER 0  /* Means do not use an arithmetic
coder */
#define DEFAULT_CODER 1 /* Default arithmetic coder */
#define FALSE 0 /* For boolean expressions */
#define TRUE 1  /* For boolean expressions */

typedef unsigned int boolean;
extern unsigned int debugModel;

typedef struct debugType
{
   unsigned int level;
   unsigned int level1;
   unsigned int progress;
   unsigned int range;
   unsigned int coder;
   unsigned int coder_target;
   unsigned int codelengths;
}debugType;
extern struct debugType Debug;

//main function for .c file
void usage(void);
void loadModels(FILE *fp);
void init_arguments(int argc, char *argv[]);
unsigned int *getText (FILE *fp, unsigned int eoln, unsigned int
del_last_eoln, unsigned int *len);
float codelengthText (unsigned int model, unsigned int *text, unsigned
int textlen);
void codelengthModels (unsigned int *text, unsigned int textlen);

//gloabal function for .c file running with local function
extern unsigned int TLM_create_context (unsigned int model);
extern void TLM_set_context_operation (unsigned int
context_operation);
extern void TLM_update_context (unsigned int model, unsigned int
context, unsigned int symbol);
extern void TLM_release_context (unsigned int model, unsigned int
context);
extern void TLM_dump_models (unsigned int file, void
(*dump_symbol_function) (unsigned int, unsigned int));
extern void TLM_set_tag (unsigned int model, char *tag);
-
ex.c

#include "ex.h"
int Exclude_eolns = 0;/* For incuding/excluding eolns in the input
*/
int Delete_last_eoln = 0; /* For deleting the last eoln read in from
the input */
int Debug_model = 0;  /* For dumping out the model */
int Debug_chars = 0;  /* For dumping out the codelength character
by character */
int Display_entropy = 0;  /* For displaying cross-entropies and not
codelengths */

unsigned int TLM_Coderanges;
float TLM_Codelength;
unsigned int TLM_Context_Operation;


void loadModels (FILE * fp)
/* Load the models from file FP. */
{
   char tag [MAX_TAG], filename [MAX_FILENAME];
//char tag [256], filename [256];

unsigned int model;

while ((fscanf (fp, "%s %s", tag, filename) != EOF))
{
model = TLM_read_model(filename, "Loading model from file",
"Codelength: can't open model file");
TLM_set_tag (model, tag);
}
}

void init_arguments (int argc, char *argv[])
{
char *optarg; //extern char *optarg;
int optind; //extern int optind;
FILE *fp;
unsigned int models_found;
int opt;

/* get the argument options */

models_found = 0;
Exclude_eolns = 0;
Delete_last_eoln = 1;
while ((opt = getopt (argc, argv, "ELcd:em:r")) != -1)
switch (opt)
{
case 'E':
Exclude_eolns = 1;
break;
case 'L':
Delete_last_eoln = 1;
break;
case 'c':
Debug_chars = 1;
break;
case 'd':
Debug_model = atoi (optarg);
break;
case 'e':
Display_entropy = 1;
break;
case 'm':
fprintf (stderr, "Loading models from file %s\n",
optarg);
if ((fp = fopen (optarg, "r")) == NULL)
{
fprintf (stderr, "Encode: can't open models file %s\n",
 optarg);
exit (1);
}
loadModels (fp);
models_found = 1;
break;
case 'r':
Debug.range = 1; //uses structure element range.
break;
default:
usage ();
break;
}
if (!models_found)
{
fprintf (stderr, "\nFatal error: missing models\n\n");
usage ();
}
for (; optind < argc; optind++)
usage ();
}
--

but while running setup.py build with distutils it's showing error as

_ex.o: In function 'init_arguments':
 _ex.c :89: undefined reference to _TLM_read_model
 _ex.c :95:  undefined reference to _TLM_set_tag

for all the global function declared within .h file and the calling
method from .c file,
also how can the Debug.range can be used...

thank's
anish
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to access an Array and a struct within a struct wrapped by Swig ?

2008-08-16 Thread Anish Chapagain
Hi,
If you have struct defined in .h file then it's ok or can dea easyily
with struct written with .i file,
in .h file,
 struct def
{
 int a;
char name[10];
};
can be referenced as
  >>strvar=new_def() //now strvar is your
object for struct def
  and can access a and name as, get and
set for individual member see,
 >>def_a_set(strvar,10)
 >>def_a_get(strvar) will return 10.
or you can define struct as,

typedef struct
{
int sage;
}coll;
within .h file and access similarly.

regard's
Anish Chapagain
www.mysticnepal.com

On Aug 16, 11:38 am, [EMAIL PROTECTED] wrote:
> Hello,
>
> I spent almost a week to be able to embed Python within my C++ game
> engine.
> I wrote a mini-tutorial of what I was able to do so far here 
> :http://forums.indiegamer.com/showpost.php?p=169352&postcount=9
>
> At the end of my tutorial, I wrote : "You can do the same with C++
> classes, and with structures within structures. Swig can parse & wrap
> most C/C++ declarations."
>
> Gloups, I was so wrong..! :-S
>
> It seems that I can read a struct within my struct, but I cannot write
> values to it.
> Also, I cannot access the array from within my struct.
>
> Any help to achieve this would be very welcome.
>
> Here the problem in detail :
> I'm using Python 2.5.2 & Swig 1.3.36.
>
> The structures :
> struct SIn
> {
>         int in1, in2;
>
> };
>
> struct SPythoned
> {
>         SIn Inner;
>         float Skill[16];
>
> };
>
> The python code :
> ===
> def TestObject(o):
>         print(type(o))
>         print(type(o.Skill))
>         print(o.Skill)
>         print(type(o.Inner))
>         print(type(o.Inner.in1))
>         print(o.Inner.in1)
>         print(o.Inner.in2)
>
>         o.Inner.in1 = 12
>         o.Inner.in2 = 17
>
>         print(o.Inner.in1)
>         print(o.Inner.in2)
> ===
>
> It gives me this output :
> ===
> 
> 
> _20fd1300_p_float
> 
> 
> 2
> 22
> 2
> 22
> ===
>
> So althought I can read the value, the "o.Inner.inX = Y" are without
> effect..! (and checking the value in the object in the C part confirms
> this).
>
> Moreover, if I add these lines :
>         for i in range(16) :
>                 print(o.Skill[i])
>
> I get this error :
> Traceback (most recent call last):
>   File "d:\TE 2008\PyTest.py", line 32, in TestObject
>     print(o.Skill[i])
> TypeError: 'PySwigObject' object is unsubscriptable
>
> Any idea how to make this work ..?

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


Parse error befor % token

2008-08-13 Thread Anish Chapagain
Hi,
i tried to compile the swig .i file but am having probel with the
error: parse error before % token

example.i

1. %module example
2. %{
3. #include 
4. %}
5.
6. %include "header.h"

i have setup.py file and am running through,
>>python setup.py build_ext

but is showing parse error before % token in example.i in line 1 and
also in 4.
Thank's for any help on this matter in advance
also, is there any live example having multiple .i files in single
interface SWIG file.

cheer's
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapping C API

2008-08-04 Thread Anish Chapagain
On 4 Aug, 14:20, Ulrich Eckhardt <[EMAIL PROTECTED]> wrote:
> Anish Chapagain wrote:
> > I'm new to python and have a task for Wrapping up an old program
> > written in C(20.c files), to provide GUI and chart,graph feature in
> > Python. I've tried using SWIG but am not getting well in windows
> > system, wish to receive guidelines for initiating the task...
>
> Two ways come to mind:
> 1. ctypes
> 2. popen
>
> The former is basically an interface to the C language types which makes it
> rather easy to load C DLLs and call functions therein. The latter is a way
> to start a program with redirected input and output, something that can be
> used to remote-control any commandline application.
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

For, plotting chart and graph through C, dll in pyhton will ctype be
more easy..
if there any example would like to see once..
thank's
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapping C with Python

2008-08-04 Thread Anish Chapagain
On 4 Aug, 14:14, brad <[EMAIL PROTECTED]> wrote:
> RPM1 wrote:
>
> ...
>
> > Basically you just compile your C code as a regular C code dll.  ctypes
> > then allows you to access the functions in the dll very easily.
>
> Does that work with C++ code too or just C?

Hi..
I havenot tried..before with dll, is there any help material and for
me my API in C has almost 20 c files, so will it be feasible

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


Wrapping C API

2008-08-04 Thread Anish Chapagain
Hi!!
I'm new to python and have a task for Wrapping up an old program
written in C(20.c files), to provide GUI and chart,graph feature in
Python. I've tried using SWIG but am not getting well in windows
system, wish to receive guidelines for initiating the task...

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


Wrapping C with Python

2008-08-04 Thread Anish Chapagain
Hi!!
I tried wrapping a simple C code suing SWIG to Python, but am having
problem,
my .c file is,

Step 1:
example.c
--
double val=3.0;
int fact(int n)
{
if(n<=1)
return 1;
else
return n*fact(n-1);
}

int mod(int x, int y)
{
return (x%y);
}

Step 2:
I then created interface file as.
example.i
--
%module example
%{
%}
extern int fact(int n);
extern int mod(int x,int y);

Step 3:
I compiled the .i file with SWIG,
   c:\python25\swig> swig -
python example.i
It creates example.py and example_wrap.c

Step 4:
I compiled example.c and example_wrap.c individually
 c:\python25\mingw\bin>   gcc -c example.c  (it create
example.o)
 c:\python25\mingw\bin>   gcc -c example_wrap.c -Ic:
\python25\include(it create example_wrap.o)

Step 5:
building .pyd for windows,
 c:\python25\mingw\bin>   gcc -shared *.o -o _example.pyd -Lc:
\python25\libs -lpython25 (it creates _example.pyd)


Then, i imported example module by palcing it in python25 directory,
it get's imported but i'm not able to use function, when i called
 >>>print example.fact(4)
 >>>print example.mod(4,2)
It is nither showing any error nor message...
even i tried simple void fact() by printf inside .c file and is not
showing ...

hope for help...
regard's
Anish
--
http://mail.python.org/mailman/listinfo/python-list


Re: automating python programs

2008-07-22 Thread Anish Chapagain
On Jul 21, 7:28 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote:
> On Mon, Jul 21, 2008 at 2:12 PM, Zach Hobesh <[EMAIL PROTECTED]> wrote:
> > Hi,
>
> > I'm trying to figure out how to run a python program on a schedule, maybe
> > every half an hour...  Is this possible?
>
> > Thanks!
>
> > -Zach
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> On Linux, man cron.

Hi!!
I hope if you have written the Python code in Class and module then
you can call the execution of module
in main module using yourroot.after(millisecond,moduletobe executed)
like,
 parent_root.after(3000, child1_root.destroy)#will destroy the
child1_root module after 3second at this stage in mainmodule.
 parent_root.mainloop()

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


regarding SWIG

2008-07-22 Thread Anish Chapagain
Hi..
I'm new to SWIG and need to create Wrapper for C code,
so, I have installed the SWIG already but doesnot know how to run it
for generating Interface file...
My C code is in message.c so what do i need to do the first
step..uisng SWIG..i read the documentation but cannot grasp creating
interface file.

thank's anish
--
http://mail.python.org/mailman/listinfo/python-list


Re: error

2008-07-21 Thread Anish Chapagain
On Jul 21, 1:47 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Anish Chapagain wrote:
> > from Tkinter import *
> > root=Tk()
> > f=Frame(root,height=200,width=200)
> > b=Button(f,text="quit",command=f.quit)
> > f.pack()
> > root.mainloop()
>
> > --
> > from Tkinter import *
> > import sys
> > root=Tk()
> > f=Frame(root,height=200,width=200)
> > b=Button(f,text="quit",command=sys.exit)
> > f.pack()
> > root.mainloop()
>
> > I am wondering that why the button after clikcing is not closing the
> > window..please any suggestion..
> > i tries command=f.quit, sys.quit also..
> > if there is something i'm missing please help
>
> Assuming you accidentally left out the line where you're displaying the
> button (e.g. "b.pack()"), both your samples work when running this from
> the command line.
>
> Are you perhaps running this code from inside IDLE?  IDLE is itself
> written in Tkinter, and it doesn't always shut down the Tkinter
> subsystem properly.
>
> ... and I have to admit that I don't know what the currently recommended
> workaround is -- you'll find plenty of documentation on the net that
> just says "don't do that" (run Tkinter programs from within IDLE, that
> is), but surely someone should have fixed that issue by now?.
>
> - Hide quoted text -
>
> - Show quoted text -

hi thank's i probably missed the b.pack() but it's till the window is
not closed and error message of Windows Appear
--
http://mail.python.org/mailman/listinfo/python-list


error

2008-07-21 Thread Anish Chapagain
from Tkinter import *
root=Tk()
f=Frame(root,height=200,width=200)
b=Button(f,text="quit",command=f.quit)
f.pack()
root.mainloop()

--
from Tkinter import *
import sys
root=Tk()
f=Frame(root,height=200,width=200)
b=Button(f,text="quit",command=sys.exit)
f.pack()
root.mainloop()

I am wondering that why the button after clikcing is not closing the
window..please any suggestion..
i tries command=f.quit, sys.quit also..
if there is something i'm missing please help
--
http://mail.python.org/mailman/listinfo/python-list