Absolultely confused...

2005-10-06 Thread Jeremy Moles
So, here is my relevant code:

PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)

And here ismy error message:

argument 1 must be pylf.core.vector3d, not pylf.core.vector3d

I know PyType_vector3d "works" (as I can use them in the interpreter all
day long), and I know I'm passing a pylf.core.vector3d (well, apparently
not...)

I've spent hours and hours on this and I'm finally just giving up and
asking. I've tried everything to get my program to verify that arg1 is
really a PyType_vector3d, but to no avail.

If I take out the "!" in the format string and just use "O", I can at
least get past PyArg_ParseTuple. Then I try something like...

PyObject_TypeCheck(arg1, &PyType_vector3d)

Which also fails, but I know for a fact that arg1's PyObject_Repr is
what it should be. (pylf.core.vector3d)

I guess my question is: what in the world could be causing this to fail?
It seems like I'm just not able to use ParseType or BuildValue to create
objects of my own type.

I know I haven't provided a lot of information, but does anyone have any
ideas or where I should start looking?

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


Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
All of these are runtime errors. Using GCC4 and compiling perfectly with
-Wall.

On Thu, 2005-10-06 at 09:12 -0500, Brandon K wrote:
> > If I take out the "!" in the format string and just use "O", I can at
> > least get past PyArg_ParseTuple. 
> 
> Is this a compile-time error? Or a runtime error?
> 
> 
> 
> == Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups 
> ==
> Get Anonymous, Uncensored, Access to West and East Coast Server Farms! 
> == Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM 
> ==
> 
> 

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


Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
Thanks for the reply. :)

I may be missing something critical here, but I don't exactly grok what
you're saying; how is it even possible to have two instances of
PyType_vector3d? It is (like all the examples show and all the extension
modules I've done in the past) a static structure declared and assigned
to all at once, only once.

Am I misunderstanding the point? :)

/me ducks

On Thu, 2005-10-06 at 16:26 +0200, Thomas Heller wrote:
> Jeremy Moles <[EMAIL PROTECTED]> writes:
> 
> > So, here is my relevant code:
> >
> > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
> >
> > And here ismy error message:
> >
> > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
> >
> > I know PyType_vector3d "works" (as I can use them in the interpreter all
> > day long), and I know I'm passing a pylf.core.vector3d (well, apparently
> > not...)
> >
> > I've spent hours and hours on this and I'm finally just giving up and
> > asking. I've tried everything to get my program to verify that arg1 is
> > really a PyType_vector3d, but to no avail.
> >
> > If I take out the "!" in the format string and just use "O", I can at
> > least get past PyArg_ParseTuple. Then I try something like...
> >
> > PyObject_TypeCheck(arg1, &PyType_vector3d)
> >
> > Which also fails, but I know for a fact that arg1's PyObject_Repr is
> > what it should be. (pylf.core.vector3d)
> >
> > I guess my question is: what in the world could be causing this to fail?
> > It seems like I'm just not able to use ParseType or BuildValue to create
> > objects of my own type.
> >
> > I know I haven't provided a lot of information, but does anyone have any
> > ideas or where I should start looking?
> 
> Can it be that you have TWO instances of the pylf.core.vector3d object?
> Debugging should reveal it...
> 
> Thomas

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


Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
Well, there's certainly no doubting that all of you are right. I guess
now I need to track down how this is happening and either fix it or
understand it so that I can explain why I'm having to work around it. :)

Many, many thanks. :)

On Thu, 2005-10-06 at 16:48 +0200, Daniel Dittmar wrote:
> Jeremy Moles wrote:
> > So, here is my relevant code:
> > 
> > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
> > 
> > And here ismy error message:
> > 
> > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
> > 
> 
> It looks as if two PyType_vector3d exist in your system
> - the one that created the object passed to your routine
> - the one in your extension code
> 
> As PyType_vector3d probably comes from a shared object/DLL
> - does your code accesses really the same shared object that is also 
> loaded by the Python interpreter? It could be that you linked with a 
> specific file, but Python loads something different from $PYTHONPATH
> - on Windows, you couldn't simply import a variable from a DLL, you had 
> to call a special routine to get the pointer
> 
> One possible portable solution: in your module initialization
> - import pylf.core
> - create an object of type vector3d
> - use your knowledge about the inner structure of Python objects and get 
> the pointer to the PyType from the object
> - store it in a module static variable TypeVector3D
> - pass that variable to PyArg_ParseTuple
> 
> Browse the Python Extension API, maybe partts or all of this are already 
> available.
> 
> There's still a problem left when pylf.core gets reloaded (rare, but 
> possible). I assume the shared object also gets reloaded, which means 
> that the type objects gets loaded to a new address and PyArg_ParseTuple 
> will complain again. I'm not sure if there is a solution to this, 
> because there still could be objects create from the old module.
> 
> Maybe you should just check the type yourself by comparing the class 
> names buried in the PyType. You could cache one or two type pointers to 
> speed this up.
> 
> Daniel

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


Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
WELL, I figured it out--thanks to everyone's help. There were instances
of the object and I am a total moron.

Thanks again to everyone who helped me stomp this out. :)

On Wed, 2005-10-05 at 21:58 -0400, Jeremy Moles wrote:
> So, here is my relevant code:
> 
>   PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
> 
> And here ismy error message:
> 
>   argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
> 
> I know PyType_vector3d "works" (as I can use them in the interpreter all
> day long), and I know I'm passing a pylf.core.vector3d (well, apparently
> not...)
> 
> I've spent hours and hours on this and I'm finally just giving up and
> asking. I've tried everything to get my program to verify that arg1 is
> really a PyType_vector3d, but to no avail.
> 
> If I take out the "!" in the format string and just use "O", I can at
> least get past PyArg_ParseTuple. Then I try something like...
> 
>   PyObject_TypeCheck(arg1, &PyType_vector3d)
> 
> Which also fails, but I know for a fact that arg1's PyObject_Repr is
> what it should be. (pylf.core.vector3d)
> 
> I guess my question is: what in the world could be causing this to fail?
> It seems like I'm just not able to use ParseType or BuildValue to create
> objects of my own type.
> 
> I know I haven't provided a lot of information, but does anyone have any
> ideas or where I should start looking?
> 

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


PyObject_New

2005-10-06 Thread Jeremy Moles
Hey guys, sorry to ask another question of this nature, but I can't find
the answer or a single example of it anywhere. I'm sure it's been asked
before, but my google-fu isn't strong enough to find anything.

I have the following:

struct MyType {
PyObject_HEAD
...
};

PyTypeObject PyType_MyType = { ... }

Now, elsewhere in the code I want to create an instance of this custom
type in C/C++ (rather than in the Python interpreter, where this all
seems to happen magically) and return it from a method. What I'm trying
now is the following:

PyObject* obj = _PyObject_New(&PyType_MyType);
obj = PyObject_Init(obj, &PyType_MyType);

...

return obj;

When "obj" gets back to the interpreter, Python sees it (or rather, it's
__repr__) in accordance with what it "should" be. However, any attempt
to USE the object results in a segfault. I feel my problem is simply
that I'm not allocating "obj" correctly in the C++ function.

If anyone has any advice, I would really appreciate it.

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


C/API Clarification

2005-10-07 Thread Jeremy Moles
First of all, let me say I really do appreciate--and frequently use--the
ample and easy to read Python documentation. However, there are a few
things I'm still unclear on, even after asking multiple questions here
on the list (thanks everyone!) and reading the "Extending" and
"Reference" docs from start to finish. I'm new to Python extension
writing--but I'm learning fast. Still, I have a few questions that would
make my weekend so much better if I had some guidance on them or,
better, examples of other people's working code. :) (Real code, not
over-simplified examples that don't ever make sense in the real
world) :) 

Most of my woes are the result of trying to wrap some highly dynamic C++
code. People, of course, are quick to say "use Boost"--which I'm sure is
great--but doesn't actually teach me anything about Python. :)

1. Nowhere in the docs was I able to see an example of a custom object
using anything but a METH_NOARGS method. This is pretty silly since I
would assume that most class methods take a few arguments. I'm using:

PyObject* foo(cstruct* self, PyObject* args, PyObject* kargs)

...and it works, but I'm not even really sure if this is right or where
in the world I got the idea from! According to the docs, METH_VARARGS is
(PyObject*, PyObject*)? My prototype shouldn't even compile... but it
does, even at -Wall. This is an area I really feel like the docs should
elaborate on. All of the tp_* functions are infinitely easier to
implement as they have very specific purposes. However, very little
attention is given to just general type methods, though it could be just
me missing something. :)

2. No where in the docs does it show how to "correctly" create an
instance of your custom PyTypeObject in C (rather than in the
interpreter). I'm using:

PyObject* newobject = _PyObject_New(&PyType_myType);
PyObject* nulltuple = Py_BuildValue("()");
myType_init((cstruct*)(newobject), nulltuple, NULL);

...and it works (or appears to so far), but I really doubt this is how
it's done. I'm guessing I'm not supposed to go anywhere near the
_PyObject_New function. :)

3. I'm not able to return the "self" argument (useful, for instance,
when you want to chain a group of method calls) without screwing things
up really, really bad. For example:

PyObject* somefunc(cstruct* self, PyObject* args, PyObject* kargs) {
self->pointerToData->doSomeStuff();

return (PyObject*)(self);
}

...returns "something"; it has the methods you would expect, but trying
to use the object when it gets back to the interpreter is pretty much
undefined behavior. :) It's seen as a "" instance in the
interpreter, even though a dir() shows it still has the methods you
would expect.

I'm sorry if I come off as a newb or sound preachy--it certainly isn't
my intention. I love Python and will continue using it even if I never
quite grok it's C API. :)

Weee.

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


Re: PyObject_New

2005-10-07 Thread Jeremy Moles
I just noticed this response right as I sent my other message. For some
reason my news reader didn't thread it, so it was all by itself...
Please disregard the rant concerning creation of objects in C. :)

/me hugs Martin
/me ducks and hides!

On Fri, 2005-10-07 at 09:57 +0200, "Martin v. Löwis" wrote:
> Jeremy Moles wrote:
> > PyObject* obj = _PyObject_New(&PyType_MyType);
> > obj = PyObject_Init(obj, &PyType_MyType);
> > 
> > ...
> > 
> > return obj;
> 
> The call to PyObject_Init is redundant: _PyObject_New
> is malloc+init. However, this shouldn't cause any crashes (except in the
> debug build). PyObject_Init is documented as
> 
> Initialize a newly-allocated object op with its type and initial 
> reference. Returns the initialized object. If type  indicates that the 
> object participates in the cyclic garbage detector, it is added to the 
> detector's set of observed objects. Other fields of the object are not 
> affected.
> 
> [I don't know where the mentioning of GC comes from - it appears to be
>   incorrect]
> 
> > When "obj" gets back to the interpreter, Python sees it (or rather, it's
> > __repr__) in accordance with what it "should" be. However, any attempt
> > to USE the object results in a segfault. I feel my problem is simply
> > that I'm not allocating "obj" correctly in the C++ function.
> 
> It doesn't crash because of the allocation - this code is correct.
> However, it is also incomplete: none of the state of the new object
> gets initialized in the fragment you are showing. So it likely crashes
> because the members of the object are stray pointers or some such,
> and accessing them causes a crash.
> 
> Regards,
> Martin

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

Re: Pass a tuple (or list) to a C wrapper function

2005-10-12 Thread Jeremy Moles
It depends on how you want to manipulate the data in C. If you want
compile-time variable access to each float, yeah, 50 floats. :) 

Probably what you want to do though is just keep the tuple as is and
iterate over it using the PySequence_* protocol:

http://docs.python.org/api/sequence.html

On Wed, 2005-10-12 at 13:06 -0700, Java and Swing wrote:
> I have a C function which takes an array of long values..
> 
> I understand that I can pass a tuple to a C wrapper function and in the
> C wrapper function have..
> 
> int ok = PyArg_ParseTuple(args, "s(ll)", &a, &b, &c);
> 
> ..that's great if my tuple only contained two longs..but what if it
> contained 50
> would I have to do..
> 
> int ok = PyArg_ParseTuple(args, "s(llll)", &a, &b,
> &c, &d...) ??
> 
> how can I handle this?
> 

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


Re: How to get a raised exception from other thread

2005-10-14 Thread Jeremy Moles
On non-Windows system there are a ton of ways to do it--this is almost a
whole field unto itself. :) (D-BUS, fifos, sockets, shmfs, etc.) In
Windows, I wouldn't have a clue. 

I guess this is a hard question to answer without a bit more
information. :)

On Fri, 2005-10-14 at 14:45 -0700, dcrespo wrote:
> Hi all,
> 
> How can I get a raised exception from other thread that is in an
> imported module?
> 
> For example:
> 
> ---
> programA.py
> ---
> 
> import programB
> 
> thread = programB.MakeThread()
> thread.start()
> 
> ---
> programB.py
> ---
> import threading, time
> 
> class SomeException(Exception):
> pass
> 
> class MakeThread(threading.Thread):
> def __init__(self):
> threading.Thread.__init__(self)
> 
> def run(self):
> i = 0
> while 1:
> print i
> i += 1
> time.sleep(1) #wait a second to continue
> if i>10:
> raise SomeException()
> 
> 
> Thanks
> 
> Daniel
> 

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


Why doesn't this work? :)

2005-10-28 Thread Jeremy Moles
Jumping right into the code (which should speak for itself):

# ---

try:
# this will fail and be caught
# below, w
import foobar

except ImportError, error:
class foobar:
@staticmethod
def __getattr__(*args, **kargs):
return None

print foobar.bg

# ---

This doesn't work and I'm just curious as to why? I can, of course, make
__getattr__ non-static, instantiate a foolbar object, and everything
works; but, the "idea" above seems cleaner and whatnot. :)

Am I misunderstanding something fundamental about the builtin __*
functions? Can they not be "static?"

No rush on this, just curious. I'm using the following in a more general
way, and it works fine for now... :)

# ---

try:
import foobar

except ImportError, error:
class Foobar:
def __getattr__(*args, **kargs):
return None

foobar = Foobar()

print foobar.bg

# ---


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


Re: Why doesn't this work? :)

2005-10-28 Thread Jeremy Moles
On Fri, 2005-10-28 at 14:50 -0400, Chris Lambacher wrote:
> I think what you really want is:
> 
> try:
>   # this will fail and be caught
>   # below, w
>   import foobar
> 
> except ImportError, error:
>   class foobarclass:
>   def __getattr__(*args, **kargs):
>   return None
> foobar = foobarclass()
> 
> print foobar.bg
>
> foobar in your version is a class.  By making it an instance, the __getattr__ 
> method is properly called.
> 
> 
> -Chris

:)

Well, that's what I am using. :) What I'm wondering is if the other
method could work, of if it simply impossible in Python considering it's
underlying implementation.

> On Fri, Oct 28, 2005 at 02:02:29PM -0400, Jeremy Moles wrote:
> > Jumping right into the code (which should speak for itself):
> > 
> > # ---
> > 
> > try:
> > # this will fail and be caught
> > # below, w
> > import foobar
> > 
> > except ImportError, error:
> > class foobar:
> > @staticmethod
> > def __getattr__(*args, **kargs):
> > return None
> > 
> > print foobar.bg
> > 
> > # ---
> > 
> > This doesn't work and I'm just curious as to why? I can, of course, make
> > __getattr__ non-static, instantiate a foolbar object, and everything
> > works; but, the "idea" above seems cleaner and whatnot. :)
> > 
> > Am I misunderstanding something fundamental about the builtin __*
> > functions? Can they not be "static?"
> > 
> > No rush on this, just curious. I'm using the following in a more general
> > way, and it works fine for now... :)
> > 
> > # ---
> > 
> > try:
> > import foobar
> > 
> > except ImportError, error:
> > class Foobar:
> > def __getattr__(*args, **kargs):
> > return None
> > 
> > foobar = Foobar()
> > 
> > print foobar.bg
> > 
> > # ---
> > 
> > 
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list

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


Re: Floating numbers and str

2005-11-09 Thread Jeremy Moles
I think you answered your own question. :)

x = 0.12345678
y = "%.4f something here" % x

On Wed, 2005-11-09 at 11:52 -0800, Tuvas wrote:
> I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
> 
> 
> x=.13241414515
> y=str(x)+" something here"
> 
> But somehow limiting that to 4 sign. digits. I know that if you use the
> print statement, you can do something like %.4d, but how can I do this
> with converting the number to a string? Thanks!
> 

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


ncurses' Dark Devilry

2005-11-29 Thread Jeremy Moles
I'm working on a project using ncurses w/ Python. As an aside, I
implemented addchstr in the cursesmodule.c file in Python SVN, if anyone
wants me to try and get that made permanent.

AT ANY RATE...

I was wondering--and this is more a general curses question rather than
a Python one, but I know there are some old-timers here who have made
curses obey before--is there a way to "repaint" a portion of screen
without stealing the "cursor?" That is:

I have a focus "wheel" of sorts that allows the user to do input on
various wigets and windows and whatnot. However, if I want to quickly
call addstr somewhere else in the application I have to:

1. Store the YX coords of the cursor currently
2. Use the cursor in the "current" action
3. Restore the old cursor location

I know there are ways around this as I have seen curses apps that, for
example, have a clock that updates every second without stealing
"focus."

I tried implementing/using addchstr (mentioned above) to no success.

Any ideas? Is this just the plain wrong place to ask this? :)

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


Re: ncurses' Dark Devilry

2005-11-29 Thread Jeremy Moles
On Tue, 2005-11-29 at 20:50 +, Tony Nelson wrote:
> In article <[EMAIL PROTECTED]>,
>  Jeremy Moles <[EMAIL PROTECTED]> wrote:
> 
> > I'm working on a project using ncurses w/ Python. As an aside, I
> > implemented addchstr in the cursesmodule.c file in Python SVN, if anyone
> > wants me to try and get that made permanent.
> > 
> > AT ANY RATE...
> > 
> > I was wondering--and this is more a general curses question rather than
> > a Python one, but I know there are some old-timers here who have made
> > curses obey before--is there a way to "repaint" a portion of screen
> > without stealing the "cursor?" That is:
> > 
> > I have a focus "wheel" of sorts that allows the user to do input on
> > various wigets and windows and whatnot. However, if I want to quickly
> > call addstr somewhere else in the application I have to:
> > 
> > 1. Store the YX coords of the cursor currently
> > 2. Use the cursor in the "current" action
> > 3. Restore the old cursor location
> > 
> > I know there are ways around this as I have seen curses apps that, for
> > example, have a clock that updates every second without stealing
> > "focus."
> > 
> > I tried implementing/using addchstr (mentioned above) to no success.
> > 
> > Any ideas? Is this just the plain wrong place to ask this? :)
> 
> I've only tried to read the Python Library Curses docs, but I thought 
> that the Window object method addstr() would do what you want.

Perhaps I should have been more specific. :)

addstr (or any of it's brothers, even those bound to a subwin instance)
write values to an internal buffer/object that then gets flipped
(refreshed()) onto the physical screen.

However.

All of the routines I can find in the ncurses library want to take
control of the "cursor" object. That is: they either want to advance
it's position (addstr) or not (addchstr), but they both certainly grab
"control" of it; at least, visually.

Basically what I'm looking for is a way to refresh a portion of a
curses-controlled "window" without affecting the current location of the
cursor or having to manually move it and move it back.

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


Most SHAMEFUL one-liner:

2005-12-04 Thread Jeremy Moles
I was looking through some code of my today and noticed this little gem
I wrote a few days back that I had totally forgot about:

fill = [("%%-%ds\n" % (columns - 1)) % " " for i in range(yoffset - 2)]

...and then I went on to do:

"".join(fill)

Talk about using the wrong tool for the job... :(

All I needed was:

" " * (columns - 1) * (yoffset - 2)

Anyone else remember any shameful one-liners like this? :) I'm just
curious to see what kinda mistakes people make you think about a
solution WAY TO HARD... :)

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


Inheritance/Late Private Binding

2005-07-06 Thread Jeremy Moles
class BaseClass:
def __init__(self):
self.__data = None

def getMember(self):
return self.__data

class GoodSubClass(BaseClass):
def __init__(self):
BaseClass.__init__(self)

class BadSubClass(BaseClass):
def __init__(self):
self.__x = None

gsc = GoodSubClass()
print dir(gsc)
gsc.getMember()

bsc = BadSubClass()
print dir(bsc)
bsc.getMember()



Forgive me if this topic has been brought up before, but I was curious
as to why I was getting this behavior and was hoping someone
knowledgeable could explain. :)

I "feel" like even without the explicit call to a simple base ctor(),
mangling should still happen correctly. This doesnt, however, seem to be
the case...

Of note: simply doing a 'pass' in BadSubClass seems to be sufficient as
well; so, it has something to do with defining a ctor() in the child and
not explicitly invoking the parent's ctor.

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


Polling, Fifos, and Linux

2005-07-07 Thread Jeremy Moles
This is my first time working with some of the more lower-level python
"stuff." I was wondering if someone could tell me what I'm doing wrong
with my simple test here?

Basically, what I need is an easy way for application in userspace to
simply echo values "down" to this fifo similar to the way proc files are
used. Is my understanding of fifo's and their capabilities just totally
off base?

I've implemented something very similar in the past in C which works
fine; however, this app immediately takes up 100% of my CPU after the
first read from the fifo, regardless of whatever options I pass to
os.open(). Am I not actually reading the data out of the fifo? Is that
what's causing it to poll infinite thereafter?

Any help would be greatly appreciate, though I'll keep reading and
experimenting in the meantime.

#!/usr/bin/env python

import select
import os

poller = select.poll()
fifo   = os.open("fifo", os.O_RDONLY | os.O_NONBLOCK)

poller.register(fifo, select.POLLIN)

while True:
p = poller.poll()
# only have one file
string = os.read(p[0][0], 1)
if len(string):
print string

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


Re: Help with mass remove in text file

2005-07-13 Thread Jeremy Moles
On Wed, 2005-07-13 at 09:00 -0700, [EMAIL PROTECTED] wrote: 
> I'm trying to open a text file, remove all instances of the words
> "f=x;" and "i=x;" where x can be any number 0-14.  Also, I want to
> remove all {   " or ) or ( or '   } each time one of those characters
> occurs respectively.  This is what I've been able to piece together...

Does this do what you're wanting?

---

finds = ("{", "}", "(", ")")
lines = file("foo.txt", "r").readlines()

for line in lines:
for find in finds:
if find in line:
line.replace(find, "")

print lines

---

> 
> import os, string
> x = ("f=;")
> y = ("i=;)
> inputFile = open('abcd.txt','r')
>data = inputFile.read()
>inputFile.close()
>search = string.find(data, x)
>if search >=1:
>   data = data.replace(x)
>   data = data.replace(y)
>   outputFile = open('abcd.txt','w')
>   outputFile.write(data)
>   outputFile.close()
> 
> 
> This doesn't work, even to just remove "f=;".  Any help would be great.
> 
> Thanks,
> Reece
> 

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


Re: multiple inheritance super()

2005-07-26 Thread Jeremy Moles
Thought I'm not sure (and don't have time to test) I'd guess it's
because you haven't explicitly called the __init__ method chain.

i.e., B calls A, C calls B, etc.

This is probably where the actual data gets pulled into scope.

On Wed, 2005-07-27 at 12:44 +0530, km wrote:
> Hi all,
> 
> In the following code why am i not able to access class A's object attribute 
> - 'a' ? I wishto extent  class D with all the attributes of its base classes. 
> how do i do that ?
> 
> thanks in advance for enlightment ... 
> 
> here's the snippet 
> 
> #!/usr/bin/python
> 
> class A(object):
> def __init__(self):
> self.a = 1
> 
> class B(object):
> def __init__(self):
> self.b = 2
> 
> class C(object):
> def __init__(self):
>self.c = 3
>
> class D(B, A, C):
> def __init__(self):
> self.d = 4
> super(D, self).__init__()
> 
> if __name__ == '__main__':
> x =  D()
> print x.a # errs with - AttributeError
> 

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


Re: multiple inheritance super()

2005-07-26 Thread Jeremy Moles
Ignore my last response; just read it fully and realized how dumb my
response was. :)

On Wed, 2005-07-27 at 12:44 +0530, km wrote:
> Hi all,
> 
> In the following code why am i not able to access class A's object attribute 
> - 'a' ? I wishto extent  class D with all the attributes of its base classes. 
> how do i do that ?
> 
> thanks in advance for enlightment ... 
> 
> here's the snippet 
> 
> #!/usr/bin/python
> 
> class A(object):
> def __init__(self):
> self.a = 1
> 
> class B(object):
> def __init__(self):
> self.b = 2
> 
> class C(object):
> def __init__(self):
>self.c = 3
>
> class D(B, A, C):
> def __init__(self):
> self.d = 4
> super(D, self).__init__()
> 
> if __name__ == '__main__':
> x =  D()
> print x.a # errs with - AttributeError
> 

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


Bash Helper Script

2005-07-27 Thread Jeremy Moles
I wrote something real quick this morning that I thought might be
somewhat useful to someone else. It's just a bash script that lets you
do a few things do a "project directory" (in my case, python subversion
projects) in a decently sensible way. Usage is:

# cp pypadmin MyProjectDir/pypadmin
# ./pypadmin skel
# ./pypadmin clean
# ./pypadmin package
# ./pypadmin publish

The actual targets are kept in ./.pypadmin/NAME, where NAME is one of:

- package_name (name of the tarball that will be created)
- publish_host (name of the host to scp to)
- clean_files  (globs of filenames to delete when clean is invoked)

Running ./pypadmin skel will create a skeleton layout into which you put
these values. For instance:

# ./pypadmin skel
# echo "foo.tar.bz2" > .pypadmin/package_name
# echo "*.pyc" > .pypadmin/clean_files
# echo "emperorlinux.com:~" > .pypadmin/publish_host


pypadmin
Description: application/shellscript
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Problems with permissions etc

2005-07-27 Thread Jeremy Moles
On Wed, 2005-07-27 at 00:36 -0700, Frank Millman wrote:
> Hi all
> 
> This is not strictly a Python question, but this newsgroup feels like a
> family to me, so I hope that someone will be kind enough to respond to
> this, or at least point me in the right direction.
> 
> While developing under linux, I use my own computer, as the only user,
> so it has become my habit to login as root and do all my work as a
> superuser. I know that this is not desirable, but it has become a
> habit, which I am now trying to get out of.
> 
> Now that I am logging in as an ordinary user, I find that a number of
> things that previously 'just worked' have now stopped working. I can
> usually find the cause, and tweak whatever is needed to get it working
> again, but I am wondering how most people work. Is it normal to
> experience these kinds of problems, or am I missing a trick somewhere
> and making my life more complicated than it need be?
> 
> I will give two examples. I would like advice on the best way to fix
> them, but I would prefer a more general reply that explains how
> experienced unix/linux users go about handling these kinds of issues.
> 
> 1. The application I am developing will eventually be deployed as a
> multi-user accounting/business system. I want to identify the physical
> workstation that generates each transaction, so I am using the mac
> address. My method for extracting this is as follows -
>   mac = os.popen("ifconfig|grep Ether|awk {print '$5'}").read()[:-1]  #
> I did not come up with this myself, I cribbed it from somewhere
> 
> As root, this works fine. As non-root, ifconfig is not found. The
> reason is that it is in /sbin, and this is not included in the default
> path for non-root users. I could either include /sbin in my path, or I
> could change the above line to /sbin/ifconfig ... Alternatively, there
> may be a better way of getting the mac address or identifying the
> workstation.

I <3 sysfs; case in point:

cat /sys/class/net/eth*/address

..we..

> 2. I am using wxPython, which was compiled from source. It so happens
> that I did this with a colleague who also has a user account on my
> machine, so the compile and install of wxPython was done from his home
> directory.
> 
> When I start my app as non-root, the import of wx fails, as it cannot
> find certain files. They are in the other user's home directory, but as
> the top-level directory has permissions of drwx--, my user cannot
> read anything in that directory. I can change the directory
> permissions, or I can move the files to another area which all users
> can read. If the latter, is there a 'correct' place to put them?
> 
> I think that these problems are a result of my lack of experience as a
> system administrator. On the other hand, the various books and articles
> I have read to try and improve my knowledge have not covered these
> kinds of issues. Is it just something that one learns the hard way?
> 
> Any advice, especially pointers to reading matter that covers this
> topic, will be much appreciated.
> 
> Thanks
> 
> Frank Millman
> 

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


Re: Trigger pygtk drawingarea redraw

2005-07-28 Thread Jeremy Moles
Call the gtk.Widget method queue_draw(); if you derive from DrawingArea
then simply:

self.queue_draw()

Of if the DrawingArea is some kind of "has-a" member:

self.DrawableThing.queue_draw()

On Thu, 2005-07-28 at 02:52 -0700, ch424 wrote:
> Hi,
> 
> Does anybody know the fastest way to trigger a DrawingArea redaw in
> pygtk? At the moment, I'm using a bit of a hack:
> 
> def redraw(self):
> self.area.hide()
> self.area.show()
> 
> Is there a better way to trigger a redraw? This causes flickering when
> the window gets bigger than 400x400 pixels, which is a nuisance...
> there must be a better way of clearing the area and letting it redraw
> itself?
> 
> 
> Many thanks for any help,
> 
> Alex
> 

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


Re: Ten Essential Development Practices

2005-07-28 Thread Jeremy Moles

> He spends so much space on "Create Consistent Command-Line Interfaces," 
> a section that, in Python, could be replaced with a simple "Use optparse."

Haha... I don't know why but that really made me laugh. :) Might even
use it as a sig or something... :)


> -- 
> Michael Hoffman

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


Re: Wheel-reinvention with Python (was: Ten Essential Development Practices)

2005-07-29 Thread Jeremy Moles
On Fri, 2005-07-29 at 17:59 +0200, Torsten Bronger wrote:
> Hallöchen!
> 
> Michael Hoffman <[EMAIL PROTECTED]> writes:
> 
> > Dark Cowherd wrote:
> >
> >> GUI, Web development, Application Framework - it is shambles.
> >
> > Yeah, I agree. When I finally make that GUI application I still
> > don't know whether I am going to use wx or PyGTK.
> 
> I agree, too, although I can only talk about GUI toolkits.  At first
> one thinks "well, perfect, I have the choice between four 

Four?

1. wx
2. PyGTK
3. Tk (Are you including this one even?)
4. ???

Of the few I can think of, only one would qualify as great. :)

>>wink<<

> great GUI
> systems".  However, except for very special demands, there is no
> clear winner.  You start learning one, and immediately wonder
> whether the other might be better.  Although it sounds paradoxical,
> this can be quite frustrating.  After all, most of us don't have the
> energy or motivation to test all candidates thoroughly.
> 
> Besides, development resources are shared between all projects.
> This is especially sad with regard to IDEs.  There are even more
> IDEs/dialog editors/widget builders than Toolkits, none of them
> being mature.
> 
> >> Is there some place to discuss topics like this? Is this the right place?
> >
> > Sure, although you might want to start a new thread. ;)
> 
> At least a new subject ...
> 
> Tschö,
> Torsten.
> 
> -- 
> Torsten Bronger, aquisgrana, europa vetus
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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

Re: Wheel-reinvention with Python (was: Ten Essential Development Practices)

2005-07-29 Thread Jeremy Moles
On Fri, 2005-07-29 at 14:19 -0300, Jorge Godoy wrote:
> Jeremy Moles wrote:
> 
> > Four?
> > 
> > 1. wx
> > 2. PyGTK
> > 3. Tk (Are you including this one even?)
> > 4. ???
> 
> PyQt / PyKDE.

Ah! Can't believe I forgot that one! :)

> > Of the few I can think of, only one would qualify as great. :)
> 
> The fourth one? ;-)

Hehe. :) I was going to say PyGTK... but in all honesty I'm just a GTK
fanboy who hasn't really even TRIED anything else. I remember
experimenting a few years back with compiled Qt apps in C/C++, but the
whole notion of a MOC just scared me--not that I knew enough back then
to really label it as "a bad thing", nor do I now. :)

> -- 
> Jorge Godoy  <[EMAIL PROTECTED]>
> 

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


PyConn--anyone needing roommates?

2006-01-11 Thread Jeremy Moles
There's a specific list, I believe, for this sort of question, but it
has been surprisingly quiet since I registered. :)

My employer has agreed to send me to PyConn this year (yay!) but I'm on
my own as far as roomage is concerned. If anyone needs another body--or
wants to find another body--I'm game. Anything to keep costs down is
good by me. :)

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


Linux NETLINK Sockets

2006-01-11 Thread Jeremy Moles
http://mail.python.org/pipermail/python-dev/2005-January/050834.html

^^ From a year ago or so--did this never get put into Python trunk? As
far as I can tell the answer is no. It's something I'd like to use in
Python if available, though, writing a small wrapper wouldn't be out of
the question if need be.

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


Module Extension C/CPI Question

2005-08-09 Thread Jeremy Moles
Just a quick question before I waste time doing something that will
immediately be disregarded as unacceptable code... :)

When using the C API and writing extension modules, how do you normally
pass a structure up into the python module? For instance, if I have a
structure:

typedef struct Foo {
int x;
int y;
int z;
char xyz[100];
} Foo;

Is there an "accepted" way of propagating this upstream? I was thinking
one of these two:

1. Returning a enormous tuple of the struct's members using
Py_BuildValue("(iiis)", f.x, f.y, f.z, f.xyz) which would later be
converted to a similar object in Python for clients of my module to use.

2. Creating a PyObject and calling PyObject_SetAttrString(O, "x",
Py_BuildValue("i", f.x)) for each member, finally returning a generic
PyObject using the "O" flag in BuildValue.

Option 1 I "know" is possible; 2 I haven't tried. The object is
substantially larger and more complicated than what I used here as an
example, so Option 2 would require a bit more work. However, I'd be more
than glad to do it if the community sees it as being a cleaner solution.

Or, perhaps, there's even a better way? I'm getting more and more
experienced with the Python/C API, so I don't need a walk-through or
anything. :) Just an experienced recommendation...

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


Re: Adding and attribute to an instance

2005-08-09 Thread Jeremy Moles
Hmmm--I would also be interested in knowing the answer to this. I get
the exact same behavior as the OP (probably because it's the intended
behavior?)

On Tue, 2005-08-09 at 14:38 -0700, J wrote:
> Hi,
> 
> 
> I am trying to add new data attributes to my extension classes from
> within a script. I am under the impression that python allows
> that implicity
> 
> 
> This is the definition of my class
> 
> PyTypeObject CmdPlace::PyType =
> {
> PyObject_HEAD_INIT(NULL)
> 0,  /*ob_size*/
> "Place",/*tp_name*/
> sizeof(CmdPlace::PyStruct), /*tp_basicsize*/
> 0,  /*tp_itemsize*/
> 0,  /*tp_dealloc*/
> 0,  /*tp_print*/
> 0,  /*tp_getattr*/
> 0,  /*tp_setattr*/
> 0,  /*tp_compare*/
> 0,  /*tp_repr*/
> 0,  /*tp_as_number*/
> 0,  /*tp_as_sequence*/
> 0,  /*tp_as_mapping*/
> 0,  /*tp_hash */
> 0,  /*tp_call*/
> 0,  /*tp_str*/
> PyObject_GenericGetAttr,/*tp_getattro*/
> PyObject_GenericSetAttr,/*tp_setattro*/
> 0,  /*tp_as_buffer*/
> Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
> "CmdPlace", /* tp_doc */
> 0,/* tp_traverse */
> 0,/* tp_clear */
> 0,/* tp_richcompare */
> 0,/* tp_weaklistoffset */
> 0,/* tp_iter */
> 0,/* tp_iternext */
> CmdPlace::sPyMethods,   /* tp_methods */
> CmdPlace::sPyMembers,   /* tp_members */
> CmdPlace::sPyGetSeters, /* tp_getset */
> 0,  /* tp_base */
> 0,  /* tp_dict */
> 0,  /* tp_descr_get */
> 0,  /* tp_descr_set */
> 0,  /* tp_dictoffset */
> 0,  /* tp_init */
> 0,  /* tp_alloc */
> 0,  /* tp_new */
> };
> 
> I call
> 
> PyType_Ready(&PyType);
> Py_INCREF(&PyType);
> 
> to initialize the type, and
> 
> PyObject_INIT((PyObject*)&mPyObject, &CmdPlace::PyType);
> 
> to initialize an object. Objects of this type are only ever
> instantiated from C++. When I evaluate a sript I just add the object as
> "MyObject" to the dicitonary passed to Py_Eval... All the
> members and methods work fine, but when I do
> 
> MyObject.aNewAttribue = 12
> 
> I get at an error saying
> 
> object has no attribute "aNewAttribue".
> 
> I have looked at some of the source code in PyObject_GenericGetAttr and
> it turns out that the object has no dictionary. It seens that the
> address of the dictionary is computed somehow via tp_dictoffset in the
> type object.
> 
> Basically my question is, how can I make this work.
> 
> 
> Cheers
> Jochen
> 

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


Python Wireless Extension Module (pyiw)

2005-08-11 Thread Jeremy Moles
I am mostly done with writing an extension module in C that wraps (and
makes easier) interfacing with libiw (the library that powers iwconfig,
iwlist, and friends on Linux). We're using this internally for a tool to
manage wireless connectivity. This is a million times better than
hundreds of invocations of the iw* suite of tools. :)

Would anyone else find something like this useful? I know a few distros
maintain their own suite of config tools, but I don't think there is yet
an actual binding for python.

Anyway, I am just curious... we plan on using it, at any rate. It's
already made the code easier to read, faster, and more reliable.

# example usage -

wlan = pyiw.WirelessInfo("wlan0")

nets = wlan.Scan()

for net in nets:
print net.signal_quality

wlan.essid
wlan.key
wlan.protocol

wlan.essid = "LV-426"

wlan.Reconfigure()

--

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


Re: Printing literal text of an argument

2005-08-11 Thread Jeremy Moles
def debug(s):
print "s"
exec(s)

The line thing i'm not so sure about. Er. Hmmm.

On Thu, 2005-08-11 at 14:04 -0700, Rex Eastbourne wrote:
> Hi all,
> 
> I've written the following simple macro called debug(aname, avalue)
> that prints out the name of an expression and its value:
> 
> def debug(aname, avalue):
> print aname, 'is':
> pprint.pprint(avalue)
> 
> An example call is:
> 
> debug('compose(f1,f2)', compose(f1,f2))
> 
> Writing the exact same thing twice (one in quotes and the other not)
> sets off an alarm in my head. Is there a way to make this function take
> only one argument, and use both its value and its literal form? On a
> slightly different topic, is it also possible to make the macro print
> the line number where the function was first called?
> 
> Thanks,
> 
> Rex
> 

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


Py_DECREF Question:

2005-08-15 Thread Jeremy Moles
When I add an object created locally to a mapping or sequence (that will
be returned from a function into an running instance of the Python
interpreter), I need to call Py_DECREF on the object, right?
Unfortunately, I really feel like the following code leaks memory...

--- for example ---

PyObject* list = Py_Buildvalue("[]");

while(go) {
PyObject* num  = Py_BuildValue("i", 10);

PyList_Append(list, num);

Py_DECREF(num);
}

return list;

/* The responsibility of decrementing the list now lies within the scope
of Python. */

--- end example ---

Secondly, __and most importantly__, does anyone have any tools and/or
recommendations for detecting memory leaks when writing extension
modules in C? I've been using printf() and showing the OBJECT->ob_refcnt
(which, is always 1 when I'm "done" with the pointer?) but this seems
fairly newb.

I'm mostly asking so I can cleanup any craziness in my code before I try
and release pyiw (the Python bindings for Wireless Networking in Linux).
I really want it to be as clean as possible before showing anyone
else. :)

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


Re: Invoking GUI for app running in background with a keypress

2005-08-15 Thread Jeremy Moles
If you want to get crazy you can poll() on one of the evdev nodes
(/dev/input/event*) and behave accordingly. I do this in a C application
we use to do the exact same thing you're talking about. 

Each successful read from the device returns a 16-byte input_event
struct (or similar, I'm going from memory here) that represents a key
action.

A google search returned this:

http://svn.navi.cx/misc/trunk/python/evdev/evdev.py

On Mon, 2005-08-15 at 12:22 +0200, Mathias Dahl wrote:
> I am creating a small app called PyQe
> (http://klibb.com/cgi-bin/wiki.pl/PyQe) to launch commands and
> programs quickly. I works more or less as I want it now and I have
> managed to make my window manager (Metacity) under Mandrake GNU/Linux
> start my program so that it can be started easily with just a
> keypress.
> 
> Now, the only annoyance I have is that when I have not started the
> program for a while, the OS seems to not have Python or the program in
> "the cache" (or whatever, what I mean is that if I have started the
> program "recently" it starts fast the next time) anymore, which means
> that the program, even though quite small, takes about a second to
> start. This is too slow to feel good given the nature of the program
> (a quick launcher).
> 
> I have tried making it start faster by calling python with the -S
> switch and by compiling my program to a .pyc file. It has not helped
> much.
> 
> So, I was wondering if I could have my program running in the
> background and instead capture a certain keystroke (the same one I
> have my window manager to capture now) to make the GUI appear.
> 
> How does one go about doing this? I found a small program written in C
> (xbindkeys) that can do this and understand that it probably involves
> a lot of "low-level" stuff in X which feels a bit "scary" :). Any
> clues of doing this "easily" in Python + some module?
> 
> /Mathias
> 

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


Re: Implementing class methods in C

2005-08-18 Thread Jeremy Moles
I honestly don't know the answer to this and I am entirely guessing
but--does it work without using the new module? That is:



import _test

class Foo:
pass

foo = Foo()

foo.bar = _test.func2

foo.bar()

On Thu, 2005-08-18 at 12:09 -0400, [EMAIL PROTECTED] wrote:
> I am having a problem implementing some methods of a python class in C.
> The class is defined in python, but I would like to rewrite some methods
> in c. Here is an example of what I want to do:
> 
> file _test.c:
> 
> #include 
> 
> static PyObject *
> func2(PyObject *self, PyObject *args)
> {
>   if (self == NULL) {
> PyErr_SetString(PyExc_SystemError, "self is NULL");
> return NULL;
>   }
> 
>   // Parse arguments
>   if (!PyArg_ParseTuple(args, ""))
>   {
> return NULL;
>   }
> 
>   Py_INCREF(Py_None);
>   return Py_None;
> }
> 
> static PyMethodDef TestMethods[] = {
>   {"func2", func2, METH_VARARGS, "func2."},
>   {NULL, NULL, 0, NULL} /* Sentinel */
> };
> 
> PyMODINIT_FUNC
> init_test(void)
> {
>   (void) Py_InitModule("_test", TestMethods);
> }
> 
> 
> test.py:
> 
> class Test:
>   def func1(self):
> print "I am in func 1"
> 
> import _test
> import new
> Test.func2 = new.instancemethod(_test.func2, None, Test)
> del(new)
> 
> t = Test()
> t.func2()
> 
> 
> When I run test.py, I get a SystemError exception (which is what I raise
> if self is NULL). I think my confusion lies in the use of PyObject* self
> in the function declaration. Shouldn't this be set to point to the
> instance of class Test that I am calling it from? Am I misunderstanding
> the purpose of PyObject* self? Thanks.
> 
> Naveen
> 
> -
> Naveen Michaud-Agrawal
> Program in Molecular Biophysics
> Johns Hopkins University
> (410) 614 4435

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


Strange Extension Module Behavior

2005-09-28 Thread Jeremy Moles
Hey guys. I have an extension module written in C that abstracts and
simplifies a lot of what we do here. I'm observing some strange behavior
and wanted to know if anyone had any advice as to how I should start
tracking this down. More specific suggestions are obviously appreciated,
but I really don't have a lot of information to provide so I'm not
hoping for a lot. :)

The module works 100% of the time if I run it non-interactively.
However, any attempt to run it in the "interactive" python interpreter
fails, in some cases silently and in other cases raising exceptions that
really shouldn't be appearing.

Anyways, I guess the core issue here is:

   What could cause an extension module to work within a script
   and not interactively? Are there fundamental issues with the
   standard Python infrastructure I'm not grasping?

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


Re: return own type from Python extention?

2005-09-29 Thread Jeremy Moles
Building a fully-fledged, custom Python object in C isn't a trivial
task; it isn't a hard one either, but it isn't trivial. :) Basically, as
far as I know, you'll need to create a PyTypeObject structure, populate
it accordingly, and then call a few setup functions on it...

// 

static PyTypeObject WEE = {
...
};

Py_TypeReady(&WEE);

module = Py_InitModule*(...) // There are a few versions of this

PyModule_AddObject(module, "WEE", (PyObject*)(&WEE));

// -

This is all from memory--I know I left out having to at least INCREF the
static WEE. At any rate, I'm sure you can find some samples easy enough.
And if not, I can let you try and grok some of my extension code...

On Thu, 2005-09-29 at 15:59 +0200, elho wrote:
> Thx, but my Problem is to get my own type before.
> If I have a C-Type, I know how tu return it from the Python extention, 
> but how will it work with my own type?
> I expect something like the following:
> 
> static PyObject* wrap_MyFunction (PyObject* self, PyObject* args)
> {
>:
>MyPyType *myType = MyTypeNew ();
>return (PyObject*)myType;
> }
> 
> How will the Konstructor-Funktion look for MyPyType to call this in C-Code.
> 
> ...If I explain my problem to confuesed here more informations:
> I have one function for MyPyType to construct it by calling from python:
> 
> static PyObject* PyMyType_new(PyTypeObject *type, PyObject *args, 
> PyObject *kwds)
> {
>  PyMyType *self;
>  self = (PyMyType*)type->tp_alloc(type, 0);
>  if (self != NULL) {
>  self->test = 0;
>  }
>  return (PyObject *)self;
> }
> 
> ..but how do I have to call this from C-Code or how will another 
> Funktion for this look like?
> 
> 
> 
> Jeremy Moles wrote:
> > You can use Py_BuildValue for most what you're probably going to need.
> > 
> > http://docs.python.org/api/arg-parsing.html
> > 
> > On Thu, 2005-09-29 at 15:39 +0200, elho wrote:
> > 
> >>I used the examples from the "Extending and Embedding the Python 
> >>Interpreter" tutorial and this works. I can use my types with python.
> >>But I do not know how to creat my own Python variable in an python 
> >>extending c-code. What will I have to creat this and return it to my 
> >>python programm?
> > 
> > 

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


Re: return own type from Python extention?

2005-09-29 Thread Jeremy Moles
One more thing! :)

The _new method probably isn't what you want to modify the actual interl
C object; the initproc method actually gives you a pointer to it as it's
first object... (it's the tp_init member in the PyTypeObject sturcture.)

On Thu, 2005-09-29 at 15:59 +0200, elho wrote:
> Thx, but my Problem is to get my own type before.
> If I have a C-Type, I know how tu return it from the Python extention, 
> but how will it work with my own type?
> I expect something like the following:
> 
> static PyObject* wrap_MyFunction (PyObject* self, PyObject* args)
> {
>:
>MyPyType *myType = MyTypeNew ();
>return (PyObject*)myType;
> }
> 
> How will the Konstructor-Funktion look for MyPyType to call this in C-Code.
> 
> ...If I explain my problem to confuesed here more informations:
> I have one function for MyPyType to construct it by calling from python:
> 
> static PyObject* PyMyType_new(PyTypeObject *type, PyObject *args, 
> PyObject *kwds)
> {
>  PyMyType *self;
>  self = (PyMyType*)type->tp_alloc(type, 0);
>  if (self != NULL) {
>  self->test = 0;
>  }
>  return (PyObject *)self;
> }
> 
> ..but how do I have to call this from C-Code or how will another 
> Funktion for this look like?
> 
> 
> 
> Jeremy Moles wrote:
> > You can use Py_BuildValue for most what you're probably going to need.
> > 
> > http://docs.python.org/api/arg-parsing.html
> > 
> > On Thu, 2005-09-29 at 15:39 +0200, elho wrote:
> > 
> >>I used the examples from the "Extending and Embedding the Python 
> >>Interpreter" tutorial and this works. I can use my types with python.
> >>But I do not know how to creat my own Python variable in an python 
> >>extending c-code. What will I have to creat this and return it to my 
> >>python programm?
> > 
> > 

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


[ANNOUNCE] PyIW and PyWPA

2006-03-03 Thread Jeremy Moles
Many updates to the modules I'm writing for interacting with wireless
networking in Linux using Python.

PyIW  - Python bindings to libiw.
PyWPA - Python bindings/wrapper for wpa_supplicant.

They can be found here:

http://downloads.emperorlinux.com/contrib/pyiw
http://downloads.emperorlinux.com/contrib/pywpa

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


[ANNOUNCE] PyIW and PyWPA

2006-03-03 Thread Jeremy Moles
Sorry for the double-post; that's what I get for using busted, Dapper
Evolution. :)



Many updates to the modules I'm writing for interacting with wireless
networking in Linux using Python.

PyIW  - Python bindings to libiw.
PyWPA - Python bindings/wrapper for wpa_supplicant.

They can be found here:

http://downloads.emperorlinux.com/contrib/pyiw
http://downloads.emperorlinux.com/contrib/pywpa

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


Wrapping A Shell

2006-11-28 Thread Jeremy Moles
I'm not sure if this is really the right place to ask this question, but
since the implementation is in Python, I figured I'd give it a shot.

I want to "wrap" a shell process using popen inside of python program
rather than creating a new shell process for each line I process in the
app. For example, the code might look like:


std = stdin, stdout, stderr = os.popen3("bash")

print >> stdin, "ls"

print stdout.readline()

However, it appears my understanding of popen (or perhaps buffered IO)
is off somewhere, because this certainly doesn't work anything like I
expect it to (it hangs on stdout.readline).

Obviously the example above is very contrived, but eventually I'll be
using this in an OpenGL "terminal" widget. Am I approaching this the
wrong way?

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