Author |
Message |
Initrd.gz Seasoned Helper
Joined: Sep 18 2008 Posts: 134 Location: Over there ---> Offline
|
Posted: Wed Mar 18, 2009 10:38 pm Post subject: LinkedLists with Python |
|
|
|
|
Hello, again.
I am making a structure that requires use of LinkedLists, however, the main code that uses it is written with python, so I am using pytype. How compatible is LinkedLists with python? Can I use it like a list in python, or do I have to change something?
Thanks. |
|
Back to top |
|
|
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Wed Mar 18, 2009 10:42 pm Post subject: |
|
|
|
|
Heh funny you should ask as one of my ongoing, longer term projects is coming up with a good way to translate arbitrary LinkedLists back and forth from Python. Right now I have lists of just players going back and forth, but it would be considerably more involved to get any list to work, especially from the C side. What specifically are you trying to do? _________________
|
|
Back to top |
|
|
Initrd.gz Seasoned Helper
Joined: Sep 18 2008 Posts: 134 Location: Over there ---> Offline
|
Posted: Wed Mar 18, 2009 10:49 pm Post subject: |
|
|
|
|
Store an arbitrary number of numbers/structures that represent prizes and override keys, as well as pointers. (All in separate linked lists.)
I have a python class that is the equivalent of the structure. Any way I can use that? |
|
Back to top |
|
|
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Wed Mar 18, 2009 11:07 pm Post subject: |
|
|
|
|
Not easily. If you just want to have pointers, essentially a list of opaque types that is probably the quickest thing one could crank out, but for each new structure you wanted to use you would need to have custom conversion functions both ways, and you'd probably have to define a new python class using the C-API. Like I said, its an ongoing project. |
|
Back to top |
|
|
Initrd.gz Seasoned Helper
Joined: Sep 18 2008 Posts: 134 Location: Over there ---> Offline
|
Posted: Wed Mar 18, 2009 11:18 pm Post subject: |
|
|
|
|
I suppose I could write a couple of C wrappers around LL* and functions to get a value out of a linked list. Not exactly converting from LL to list, but it should work. Except maybe for the type... I could make it a single type linked list and have a small header struct defining the type of data... Hmm... |
|
Back to top |
|
|
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Tue Mar 24, 2009 4:40 pm Post subject: |
|
|
|
|
Unfortunately I think the only way this would work right now is if you exposed some sort of AddElement function in your c interface and then called that while iterating through your python lists, or something along those lines. I'm still thinking about ways to implement generic list translations, if you have any ideas. |
|
Back to top |
|
|
Initrd.gz Seasoned Helper
Joined: Sep 18 2008 Posts: 134 Location: Over there ---> Offline
|
Posted: Tue Mar 24, 2009 6:06 pm Post subject: |
|
|
|
|
D1st0rt wrote: | Unfortunately I think the only way this would work right now is if you exposed some sort of AddElement function in your c interface and then called that while iterating through your python lists, or something along those lines. I'm still thinking about ways to implement generic list translations, if you have any ideas. |
Yeah, that's what I was thinking.
I am not familiar with the python C interface, but I could learn and help you out . Pretty much the only thing I know about ATM it is that most of the stuff is stored in PyObject. |
|
Back to top |
|
|
Initrd.gz Seasoned Helper
Joined: Sep 18 2008 Posts: 134 Location: Over there ---> Offline
|
Posted: Mon Apr 06, 2009 6:12 pm Post subject: |
|
|
|
|
Well, another solution.
1. Is there any way to return a pointer to a python object from a python function?
2. Is it possible to typedef a void pointer to use as this and force the pointer returned into a cast?
Really, I just want to return something unique to a certain object in a Python set, so I can just create a GetObjectByName(name) function and iterates through the set, returning the pointer, and extract the values of it with python functions. I guess I could do something with random numbers, but pointers seem more consistent and practical. |
|
Back to top |
|
|
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Tue Apr 07, 2009 4:00 pm Post subject: |
|
|
|
|
I'm not really sure what you're trying to do, there's some ambiguity as to what you want to accomplish in which language. That being said I think I came up with a good way to implement list translation it's just taking longer than I expected to wrap my head around the part of pymod-process that is necessary to get it done. |
|
Back to top |
|
|
Initrd.gz Seasoned Helper
Joined: Sep 18 2008 Posts: 134 Location: Over there ---> Offline
|
|
Back to top |
|
|
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Tue Apr 07, 2009 6:05 pm Post subject: |
|
|
|
|
I appreciate the offer, but I'm not sure if there's anything that can be delegated right now.
You may want to look into ctypes for the time being. |
|
Back to top |
|
|
|