void * C array to a Numpy array using Swig

2006-01-11 Thread Krish
Hello People

I hope I am On Topic. Anyways, here is my problem. Any insights would
be really appreciated.

I have wrapped a C IO module using SWIG -> Python Module. Suppose the
name of the module is "imageio" and the reader function from the file
is image_read() which returns an object ( "filled" C structure) with a
lot of members.

Let

a = imageio.image_read("testfile.image")

Now a is the object which contains pointer to data of the image. ( void
* pdata). ( a also contains the datatype which I need to typecast to
get the data pointed by pdata). My question is how to access the data
pointed by pdata in *Python*.

Ideally I want the data to be converted into a Scipy(Numpy) Array
object so that I can perform further operations in Python. Any pointers
will be appreciated.

I think this has to do with PyArrayObjects, TypeMaps etc. but I
couldn't consolidate the whole information. If anyone has done this
kinda stuff before or if anyone can point me to a correct/better way,
it would be really great.

Regards
Krish Subramaniam

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


Re: void * C array to a Numpy array using Swig

2006-01-13 Thread Krish
Thanks Jon Much

I will implement your method for the time being. I am sure there is
some method which doesn't copy the data but uses the existing data.

I mean essentially we should build a PyArrayObject with the data intact
and other parameters filled. If someone sheds some light, would be
awesome. I am gonna try it  this weekend. 

Appreciated
Krish

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


Tabs for indentation & Spaces for alignment in Python 3?

2014-12-05 Thread Aahan Krish
I have two general questions regarding Python that I couldn't find any good
answers for. This is not the often-asked Tabs vs Spaces question, so kindly
read it in whole.

*Q1.* This is not to debate the decision, but I really wanted to know the
reason why PEP 8 chose to go with spaces instead of tabs. I read that tabs
were initially preferred over spaces (esp. Mr. Rossum)? What caused the
decision that spaces are better?

According to Core Python Programming (Book):

...because tabs vary in the number of spaces depending on your system, we
> recommend not using tabs if there is any hint of cross-platform development.
>

Isn't that a feature of tabs? (i.e. allowing the user to configure the size
of a tab stop in his editor, which has no affect whatsoever on the tab
character itself or how it displays in another user's editor.)

Is it the difficulty to adhere to the Maximum Line Length (79) when using
tabs? or is it simply because most of the Python programmers were using
spaces (or were adamant on using them) at the time of the decision-making
process?

*Q2.* PEP 8 also reads, "Python 3 disallows mixing the use of tabs and
spaces for indentation."

So, if I am using tabs for indentation and spaces for alignment, is it
still considered "mixing the use of tabs and spaces" in Python 3? (Please
see this example
.)

Thank you very much for your time!


Best
Aahan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tabs for indentation & Spaces for alignment in Python 3?

2014-12-05 Thread Aahan Krish
Hello Ian,

So, wrt Q2, what you are saying is, the following would cause issues in
Python 3?

int f(int x,
..int y) {
--->return g(x,
--->.y);
}

Where:

---> for tabs (used for indentation)
 for spaces (used for alignment)


Best
Aahan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tabs for indentation & Spaces for alignment in Python 3?

2014-12-05 Thread Aahan Krish
Hello Ned,

I thought that the use of tabs and spaces in the manner I suggested is
pretty common. Linux Kernel follows the same technique, for example:
https://github.com/torvalds/linux/blob/master/kernel/async.c#L100

Of course, I understand the gist of what you are saying—if people don't
understand this technique properly and start mixing up tabs and spaces
interchangeably or wrongly the code'd get mangled pretty quickly.

Thank you for the heads up!


Best,
Aahan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tabs for indentation & Spaces for alignment in Python 3?

2014-12-05 Thread Aahan Krish
Hello Ned, I didn't notice that he was using tabs more than as needed for
indentation. Guess I trusted the wrong guy. :P Anyway, it's one more thing
to keep in mind. G!

--
Aahan Krish
-- 
https://mail.python.org/mailman/listinfo/python-list


Maintaining Maximum Line Length When Using Tabs Instead of Spaces?

2014-12-07 Thread Aahan Krish
My understanding from talking to different people is that many do use
tabs (instead of spaces) for indentation in their code.

My question is to them (because I want to use tabs too) is: how do you
maintain a line-length of 79 characters?

E.g. scenario: The tab setting in your editor could be 2 or 4, and in
other developer's browser it could be 8. The code will be longer than
79 chars in the latter's editor.

I want to know if it's at all possible or if you use some simple and
realistic (practical) hacks.

*PS: Please avoid, "That's why you should use spaces," type of
comments. I would like to avoid flame wars.*

TY,
Aahan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Maintaining Maximum Line Length When Using Tabs Instead of Spaces?

2014-12-07 Thread Aahan Krish
Hi Ned,

> I'm curious why you care about the "79 characters" part of PEP8 if you don't 
> care about the "use spaces" part of PEP8.

It's just that I don't like arbitrary rules. IMHO, spaces aren't
"better than" tabs, and people should refrain from saying that. Both
have their fair bit of disadvantages and it finally comes down to
personal/team preference or consistency.

I like tabs because they are flexible. As of now I am still
considering spaces for two reasons—(1) maintaining a standard
line-length of 79-120 characters; (2) Even if I use tabs, I "may" need
spaces for aligning.

I have no major projects now, so I am free to decide, and am taking my
time for a well-thought decision.

As for why I care the "79 chars" part of PEP 8:

- Coding in terminals and VIM with multiple windows open.

- Avoiding horizontal scrollbars for code blocks on the web; GitHub
for instance. E.g.
https://github.com/torvalds/linux/blob/master/kernel/async.c -- That
is good!

- Readability; The same reason why people suggest "short paragraphs",
i.e. allow readers to quickly go through your content, or in my case,
code.

Best,
Aahan
-- 
https://mail.python.org/mailman/listinfo/python-list