Re: C-API: A beginner's problem

2006-03-24 Thread baalbek
Fabian Steiner wrote: > What do I have to change in order to make the code work? I'm afraid to say: your knowledge of C :-) But don't worry, C is an easy language to learn, and a very valuable skill to have. Baalbek -- http://mail.python.org/mailman/listinfo/python-list

Re: C-API: A beginner's problem

2006-03-19 Thread Georg Brandl
Fabian Steiner wrote: > Georg Brandl wrote: >> Fabian Steiner wrote: >>> [...] >>> for (i = 0; i <= seqlen; i++) { >> >> That is one iteration too much. Use >> >> for (i = 0; i < seglen; i++) >> >>> item = PySequence_Fast_GET_ITEM(seq, i); >> >> Now item is a PyObject*.

Re: C-API: A beginner's problem

2006-03-19 Thread Fabian Steiner
Georg Brandl wrote: > Fabian Steiner wrote: >> [...] >> for (i = 0; i <= seqlen; i++) { > > That is one iteration too much. Use > > for (i = 0; i < seglen; i++) > >> item = PySequence_Fast_GET_ITEM(seq, i); > > Now item is a PyObject*. You'll have to convert it to an i

Re: C-API: A beginner's problem

2006-03-19 Thread Georg Brandl
Fabian Steiner wrote: > I recently started learning C since I want to be able to write Python > extension modules. In fact, there is no need for it, but I simply want > to try something new ... > > I tried to implement the bubblesort algorithm in C and to use it in > python; bubblesort.c compil

Re: C-API: A beginner's problem

2006-03-19 Thread Fabian Steiner
Heikki Salo wrote: > Heikki Salo wrote: >> Fabian Steiner wrote: >>> What did I do wrong? As I am quite new to C, I probably made many >>> mistakes, so please feel free to correct me. >> >> The following line: >> >> > for (i = 0; i <= seqlen; i++) { >> >> Should be "for (i = 0; i < seqlen; i+

Re: C-API: A beginner's problem

2006-03-19 Thread Duncan Booth
Nick Smallbone wrote: > Duncan Booth wrote: >> Heikki Salo wrote: >> >> > >> > And closer look tells that the code should not even compile. Is the >> > code cut & pasted directly? Line "list[i] = item;" tries to assign a >> > pointer to an int-array, which should not compile. There are other >> >

Re: C-API: A beginner's problem

2006-03-19 Thread Nick Smallbone
Duncan Booth wrote: > Heikki Salo wrote: > > > > > And closer look tells that the code should not even compile. Is the > > code cut & pasted directly? Line "list[i] = item;" tries to assign a > > pointer to an int-array, which should not compile. There are other > > similar oddities. > > ... such a

Re: C-API: A beginner's problem

2006-03-19 Thread Duncan Booth
Heikki Salo wrote: > > And closer look tells that the code should not even compile. Is the > code cut & pasted directly? Line "list[i] = item;" tries to assign a > pointer to an int-array, which should not compile. There are other > similar oddities. ... such as the declaration of list at a poi

Re: C-API: A beginner's problem

2006-03-19 Thread Heikki Salo
Heikki Salo wrote: > Fabian Steiner wrote: >> What did I do wrong? As I am quite new to C, I probably made many >> mistakes, so please feel free to correct me. > > The following line: > > > for (i = 0; i <= seqlen; i++) { > > Should be "for (i = 0; i < seqlen; i++) {". Otherwise the last

Re: C-API: A beginner's problem

2006-03-19 Thread Heikki Salo
Fabian Steiner wrote: > What did I do wrong? As I am quite new to C, I probably made many > mistakes, so please feel free to correct me. The following line: > for (i = 0; i <= seqlen; i++) { Should be "for (i = 0; i < seqlen; i++) {". Otherwise the last assignment will be out of bounds an

C-API: A beginner's problem

2006-03-19 Thread Fabian Steiner
I recently started learning C since I want to be able to write Python extension modules. In fact, there is no need for it, but I simply want to try something new ... I tried to implement the bubblesort algorithm in C and to use it in python; bubblesort.c compiles fine, but whenever I want to im

Re: A beginner's problem...

2004-12-18 Thread Nick Coghlan
Amir Dekel wrote: Mike Meyer wrote: Doing a second import will find the module in sys.modules and not bother looking in the file system. The solution is to reload(module) instead of import module. What if I import using "from module import class"? It seems to me that I can't use reload the

Re: A beginner's problem...

2004-12-18 Thread Mike Meyer
Amir Dekel <[EMAIL PROTECTED]> writes: > Mike Meyer wrote: >> Doing a second import will find the module in sys.modules and not >> bother looking in the file system. The solution is to reload(module) >> instead of import module. >> What if I import using "from module import class"? It see

Re: A beginner's problem...

2004-12-18 Thread Amir Dekel
Mike Meyer wrote: Doing a second import will find the module in sys.modules and not bother looking in the file system. The solution is to reload(module) instead of import module. What if I import using "from module import class"? It seems to me that I can't use reload then, or I just could

Re: A beginner's problem...

2004-12-18 Thread Mike Meyer
[Format recovered from top posting.] "James Martin" <[EMAIL PROTECTED]> writes: > > > "Amir Dekel" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Hello everyone, >> First, I have to say that Python is one of the coolest programing >> languages I have seen. >> And now for the prob

Re: A beginner's problem...

2004-12-18 Thread James Martin
Try deleting the Compiled Python File that was created during import -- extension pyc. Then import again. It seems to me (I'm a novice too) that, when you import a module, Python automatically compiles it. Then when you import it later, the compiled version is imported if it exists. "Amir Dek

Re: A beginner's problem...

2004-12-16 Thread Christian Ergh
DogWalker wrote: "Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> said: In <[EMAIL PROTECTED]>, Amir Dekel wrote: When I import a module I have wrote, and then I find bugs, it seems that I can't import it again after a fix it. It always shows the same problem. I try del module but it doesn't work

Re: A beginner's problem...

2004-12-15 Thread DogWalker
"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> said: >In <[EMAIL PROTECTED]>, Amir Dekel wrote: > >> When I import a module I have wrote, and then I find bugs, it seems that >> I can't import it again after a fix it. It always shows the same >> problem. I try del module but it doesn't work. >> (

Re: A beginner's problem...

2004-12-15 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Amir Dekel wrote: > When I import a module I have wrote, and then I find bugs, it seems that > I can't import it again after a fix it. It always shows the same > problem. I try del module but it doesn't work. > (I use Python 2.4 with the ActivePython pack (PythonWin IDE)

Re: A beginner's problem...

2004-12-15 Thread Robert P. J. Day
On Wed, 15 Dec 2004, Amir Dekel wrote: > Hello everyone, > > First, I have to say that Python is one of the coolest programing languages I > have seen. > And now for the problem (must be a silly one): > When I import a module I have wrote, and then I find bugs, it seems that I > can't import it ag

A beginner's problem...

2004-12-15 Thread Amir Dekel
Hello everyone, First, I have to say that Python is one of the coolest programing languages I have seen. And now for the problem (must be a silly one): When I import a module I have wrote, and then I find bugs, it seems that I can't import it again after a fix it. It always shows the same proble