PY3.5 and nnumpy and scipy installation problem

2015-09-27 Thread paul . anton . letnes
I'll heartily recommend anaconda python. It's got everything you need 
prepackaged. 

Remove what you installed before. 

Cheers
Pauk
-- 
https://mail.python.org/mailman/listinfo/python-list


PY3.5 and nnumpy and scipy installation problem

2015-09-27 Thread paul . anton . letnes
Easiest way of installing is removing the python you've installed already and 
installing continuum's anaconda python 3.x (for x = 4 or 5). It has "batteries 
included" - numpy, scipy and many others! 

Paul
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for loop

2015-09-20 Thread paul . anton . letnes
On Sunday, September 20, 2015 at 9:56:06 AM UTC+2, shiva upreti wrote:
> https://ideone.com/BPflPk
> 
> Please tell me why 'print s' statement is being executed inside loop, though 
> I put it outside.
> Please help. I am new to python.

Hi!

Welcome to python, the most awesome programming language!

The code you pasted used both spaces and tabs for indentation. The thing is 
that python, by default, interprets one tab character as 8 spaces, but the 
editor you've used shows it as 4 spaces. To avoid these kinds of headaches, I 
always 1) set my editor to show tabs, so I can detect them, and 2) never use 
tabs when I write code myself. I set my editor to insert 4 spaces whenever I 
hit the "tab" key on my keyboard. If you post the name of your editor, maybe 
someone knows how to do that in yours. You can also detect mixed space/tab 
issues by running "python -t" instead of just "python".

So, your "print s" is in fact inside the loop, since the for loop is indented 
with 4 spaces, and "print s" is indented with 1 tab = 8 spaces. It just doesn't 
look like that to you.

It looks like you're coding in python 2. If you're new to python, I'd recommend 
using a python 3 version, maybe 3.4 or 3.5. You can easily pick up python 2 
later if you need to maintain old code. Of course, it's not a big deal learning 
python 3 if you know python 2 either, but why spend energy on it?

Cheers
Paul
-- 
https://mail.python.org/mailman/listinfo/python-list


Ordering dependent test failures

2015-09-20 Thread paul . anton . letnes
Hi!

Fascinated by the concept of ordering dependent test failures [0], I've run the 
python test suite [1] with 256 different random seeds (took a little more than 
12 hours). The results vary a lot - for instance, the number of tests reported 
as OK varies, the number of skips varies, etc. Since I'm not sure how to report 
or interpret them, I'll just post a summary below.

The test suite was run on arch linux [2] with gcc 5.2.0, with the source code 
taken from a clone of the python repo yesterday [3].

What could I do with all this in order to make more sense of it, and could it 
be of any help what so ever to python development? I'll gladly make the full 
log files available to whomever is interested, in whatever format is 
convenient. In the meantime I'll run more random seeds, because why not.

[0] https://docs.python.org/devguide/buildbots.html#ordering-dependent-failures
[1] ./python -Wd -E -bb -m test -uall -rwW --randseed $k > testlog/${k}.log 2>&1
[2] https://www.archlinux.org/
[3] Python 3.6.0a0 (default:3704cea9fd8e, Sep 19 2015, 16:12:53)

The command "grep OK *.log", where e.g. 5.log is the output of command [1] with 
"--randseed 5":
0.log:380 tests OK.
0.log:OK (skipped=15)
0.log:OK (skipped=15)
0.log:OK (skipped=15)
0.log:OK (skipped=2)
1.log:383 tests OK.
1.log:OK (skipped=2)
2.log:380 tests OK.
2.log:OK (skipped=15)
2.log:OK (skipped=15)
2.log:OK (skipped=15)
2.log:OK (skipped=2)
3.log:380 tests OK.
3.log:OK (skipped=15)
3.log:OK (skipped=15)
3.log:OK (skipped=2)
3.log:OK (skipped=37)
4.log:381 tests OK.
4.log:OK (skipped=15)
4.log:OK (skipped=15)
4.log:OK (skipped=2)
5.log:380 tests OK.
5.log:OK (skipped=15)
5.log:OK (skipped=15)
5.log:OK (skipped=15)
5.log:OK (skipped=2)
6.log:381 tests OK.
6.log:OK (skipped=15)
6.log:OK (skipped=15)
6.log:OK (skipped=2)
7.log:380 tests OK.
7.log:OK (skipped=15)
7.log:OK (skipped=15)
7.log:OK (skipped=15)
7.log:OK (skipped=2)
8.log:381 tests OK.
8.log:OK (skipped=15)
8.log:OK (skipped=15)
8.log:OK (skipped=2)
9.log:382 tests OK.
9.log:OK (skipped=15)
9.log:OK (skipped=2)
10.log:381 tests OK.
10.log:OK (skipped=15)
10.log:OK (skipped=15)
10.log:OK (skipped=2)
11.log:380 tests OK.
11.log:OK (skipped=15)
11.log:OK (skipped=15)
11.log:OK (skipped=2)
11.log:OK (skipped=37)
12.log:380 tests OK.
12.log:OK (skipped=15)
12.log:OK (skipped=15)
12.log:OK (skipped=15)
12.log:OK (skipped=2)
13.log:383 tests OK.
13.log:OK (skipped=2)
14.log:381 tests OK.
14.log:OK (skipped=15)
14.log:OK (skipped=2)
14.log:OK (skipped=39)
15.log:383 tests OK.
15.log:OK (skipped=2)
16.log:381 tests OK.
16.log:OK (skipped=15)
16.log:OK (skipped=15)
16.log:OK (skipped=2)
17.log:381 tests OK.
17.log:OK (skipped=15)
17.log:OK (skipped=15)
17.log:OK (skipped=2)
18.log:381 tests OK.
18.log:OK (skipped=15)
18.log:OK (skipped=15)
18.log:OK (skipped=2)
19.log:381 tests OK.
19.log:OK (skipped=15)
19.log:OK (skipped=15)
19.log:OK (skipped=2)
20.log:381 tests OK.
20.log:OK (skipped=15)
20.log:OK (skipped=15)
20.log:OK (skipped=2)
21.log:382 tests OK.
21.log:OK (skipped=15)
21.log:OK (skipped=2)
22.log:383 tests OK.
22.log:OK (skipped=2)
23.log:383 tests OK.
23.log:OK (skipped=2)
24.log:382 tests OK.
24.log:OK (skipped=15)
24.log:OK (skipped=2)
25.log:381 tests OK.
25.log:OK (skipped=15)
25.log:OK (skipped=15)
25.log:OK (skipped=2)
26.log:380 tests OK.
26.log:OK (skipped=15)
26.log:OK (skipped=15)
26.log:OK (skipped=15)
26.log:OK (skipped=2)
27.log:382 tests OK.
27.log:OK (skipped=15)
27.log:OK (skipped=2)
28.log:381 tests OK.
28.log:OK (skipped=15)
28.log:OK (skipped=15)
28.log:OK (skipped=2)
29.log:383 tests OK.
29.log:OK (skipped=2)
30.log:380 tests OK.
30.log:OK (skipped=15)
30.log:OK (skipped=15)
30.log:OK (skipped=15)
30.log:OK (skipped=2)
31.log:382 tests OK.
31.log:OK (skipped=15)
31.log:OK (skipped=2)
32.log:382 tests OK.
32.log:OK (skipped=15)
32.log:OK (skipped=2)
33.log:383 tests OK.
33.log:OK (skipped=2)
34.log:383 tests OK.
34.log:OK (skipped=2)
35.log:380 tests OK.
35.log:OK (skipped=15)
35.log:OK (skipped=15)
35.log:OK (skipped=15)
35.log:OK (skipped=2)
36.log:382 tests OK.
36.log:OK (skipped=15)
36.log:OK (skipped=2)
37.log:382 tests OK.
37.log:OK (skipped=15)
37.log:OK (skipped=2)
38.log:380 tests OK.
38.log:OK (skipped=15)
38.log:OK (skipped=15)
38.log:OK (skipped=15)
38.log:OK (skipped=2)
39.log:380 tests OK.
39.log:OK (skipped=15)
39.log:OK (skipped=15)
39.log:OK (skipped=15)
39.log:OK (skipped=2)
40.log:381 tests OK.
40.log:OK (skipped=15)
40.log:OK (skipped=15)
40.log:OK (skipped=2)
41.log:383 tests OK.
41.log:OK (skipped=2)
42.log:380 tests OK.
42.log:OK (skipped=15)
42.log:OK (skipped=15)
42.log:OK (skipped=15)
42.log:OK (skipped=2)
43.log:380 tests OK.
43.log:OK (skipped=15)
43.log:OK (skipped=15)
43.log:OK (skipped=15)
43.log:OK (skipped=2)
44.log:383 tests OK.
44.log:OK (skipped=2)
45.log:383 tests OK.
45.log:OK (skipped=2)
46.log:380 tests OK.
46.log:OK (skipped=15)
46.log:OK (skipped=15)
46.log:OK (skipped=15)
46.log:OK (skipped=2)
47.log:383 tests OK.
47.log:OK (ski

Re: Uninstall

2015-08-04 Thread paul . anton . letnes
Right. Try 
"which python" in the terminal and report back!

Cheers
Paul
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best approach to create humongous amount of files

2015-05-20 Thread paul . anton . letnes
There's a module called "template" that I've used before, for the find/replace 
part. I never investigated its performance, but my script used less than 1 s 
for 100 files IIRC :-)

Paul
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why this difference?

2011-02-24 Thread Paul Anton Letnes

Den 24.02.11 13.41, skrev n00m:

The 1st "False" is not surprising for me.
It's the 2nd "True" is a bit hmmm... ok, it doesn't matter
==
Have a nice day!


I am no expert, but I think python re-uses some integer and string 
objects. For instance, if you create the object int(2) it may be re-used 
later if you have several 2 objects in your code. This is to save some 
memory, or some other performance hack. Don't rely on it.


For instance:
>>> a = 100
>>> b = 100
>>> a is b
True
>>> a = 2**60
>>> b = 2**60
>>> a is b
False

Strange, but it's just like this!

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


Re: Making Line Graphs

2011-02-22 Thread Paul Anton Letnes

Den 21.02.11 10.34, skrev Jean-Michel Pichavant:

spam head wrote:

I'm looking for an easy way to display simple line graphs generated by
a python program in Windows. It could be done from within the
program, or I could write the information out to a file and call an
external program. Either is fine.

Does anybody have any recommendations for a good program from
generating these simple graphs?

http://matplotlib.sourceforge.net/

JM


+1, I like matplotlib a lot. Consider python(x,y) as an easy install 
path. It both shows plots interactively and let you save to file. I even 
use it for publications.


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


Re: python and parsing an xml file

2011-02-22 Thread Paul Anton Letnes

Den 22.02.11 13.29, skrev pyt...@bdurham.com:

Paul,


How about skipping the whole xml thing? You can dynamically import any python 
module, even if it does not have a python filename.


Great example!

Can you do the same with a cStringIO based file that exists in memory
vs. on disk? Your example requires a physical file on disk. Is it
possible to accomplish the same using a string vs. a file or temporary
file?

Thank you,
Malcolm (not the OP)


Malcolm,

I never had the interest, so I did not try. Why don't you just try it? 
Just insert your StringIO file into the function and see if it works, or 
if it crashes and burns. Let me know what you find out!


Anyway, you could always just write a temporary file. It won't consume a 
lot of resources, I imagine.


Cheers,
Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: python and parsing an xml file

2011-02-22 Thread Paul Anton Letnes

Den 21.02.11 18.30, skrev Matt Funk:

Hi,
I was wondering if someone had some advice:
I want to create a set of xml input files to my code that look as follows:





 
 
 
 
 Alg1

 
 ./Alg1.in







 
 c:\tmp

 
 
 
 
 1




So there are comments, whitespace etc ... in it.
I would like to be able to put everything into some sort of structure
such that i can access it as:
structure['Algorithm']['Type'] == Alg1
I was wondering if there is something out there that does this.
I found and tried a few things:
1) http://code.activestate.com/recipes/534109-xml-to-python-data-structure/
It simply doesn't work. I get the following error:
raise exception
xml.sax._exceptions.SAXParseException::1:2: not well-formed
(invalid token)
But i removed everything from the file except:
and i still got the error.

Anyway, i looked at ElementTree, but that error out with:
xml.parsers.expat.ExpatError: junk after document element: line 19, column 0


Anyway, if anyone can give me advice of point me somewhere i'd greatly
appreciate it.

thanks
matt



How about skipping the whole xml thing? You can dynamically import any 
python module, even if it does not have a python filename. I show an 
example from my own code, slightly modified. I just hand the function a 
filename, and it tries to import the file. If the input file now 
contains variables like

algorithm = 'fast'
I can access the variables with
input = getinput('f.txt')
print input.algorithm.

Good luck,
Paul

+

import imp
def getinput(inputfilename):
"""Parse inputs to program from the given file."""
try:
# http://docs.python.org/library/imp.html#imp.load_source
parameters = imp.load_source("parameters", inputfilename)
except IOError as err:
print >>sys.stderr, '%s: %s' % (str(err), inputfilename)
print >>sys.stderr, 'The specified input file was not found - 
exiting'

sys.exit(IO_ERROR)
# Verify presence of all required input parameters, see input.py 
example file.

required_parameter_names = ['setting1', 'setting2', 'setting3']
msg = 'Required parameter name not found in input file: {0}'
for parameter_name in required_parameter_names:
assert hasattr(parameters, parameter_name), 
msg.format(parameter_name)

return parameters


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


Re: how to get and search a html file from a website

2011-02-01 Thread Paul Anton Letnes

Den 01.02.11 22.20, skrev Tracubik:

Hi all!
i'm writing a notification program and i'm quite new to python.
The program have to check every 5 minutes a particular website and alert
me when a particular sentence ("user online") is in the html.
i've thinked to use a text browser (lynx) to retrieve the html and parse
the output in python as a normal text file.
Do you have any better idea?

thanks
Medeo


Of course there is a pythonic way :-)

>>> import urllib
>>> urllib.urlretrieve('http://docs.python.org/tutorial/index.html', 
'tut.html')


Good luck,
Paul.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Java or C++?

2008-04-15 Thread Paul Anton Letnes
Well, if you're new - first find the function, then how to use it,  
this funny %d5 (or something, don't remember) syntax - it's hard  
compared to:
cout << 5 or similar stream tricks, or just 5 + "" in Java, or just  
str(5) in Python. Anyway, small tasks are very hard for C newbies.




Den 15. april. 2008 kl. 19.35 skrev [EMAIL PROTECTED]:

> On Apr 15, 3:07 am, Paul Anton Letnes <[EMAIL PROTECTED]>
> wrote:
>
>
>> but C bogs you down with administrative stuff (try converting an int
>> to a string; I found myself googling for an hour!).
>
> It took an hour to find sprintf()?
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: How to import C++ static library?

2008-04-15 Thread Paul Anton Letnes

Den 15. april. 2008 kl. 11.11 skrev Diez B. Roggisch:

> Alexander Dong Back Kim wrote:
>
>> Hi all,
>>
>> I'm very very beginner of python but I'm dare to ask this question
>> straight away. =P
>>
>> Is it possible to import C++ static library compiled by GCC? The
>> target is definitely Linux machine.
>>
>> I found some examples from Google showing the way C++ can import
>> Python so called embedded python. But I want to the opposite way of
>> this. I want to import (or include in C world terminology) the  
>> library
>> which is a blah.a file to reuse in python.
>>
>> Any suggestion or idea for this stupid beginner? ;)
>
> For C++, you need to create a wrapping using C++ wrapper tools.  
> There are a
> few available: SWIG, Boost::Python and SIP.
>
> I can only comment personally on the latter - and can recommend it  
> without
> any doubt.
>
> Diez
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Diez: I tried SWIG, and it works nicely with C. For C++, I didn't  
manage to make it work. I tried SIP; I have some problems compiling  
etc. Would it be too much to ask you to supply a working example of a  
(simple, stupid) C++ class and the necessary SIP files? Preferably for  
Mac OS X, but Linux is also interesting I guess.


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


Re: Java or C++?

2008-04-15 Thread Paul Anton Letnes
Brian: Impressive!


This is the most balanced, well-informed and interesting reply to this  
debate. I would like to make some comments even so.

I have tried all languages, and consider myself agnostic. However, I  
would like to roughly repeat what James Gosling (Java inventor) said  
at a lecture I attended: Java is nice because you can work in Java  
everywhere now - from embedded to desktops to supercomputers and  
servers. And, I would like to make my own comment: Java is the  
language I have tried which gives you the most help as a developer.  
For every crash, there is a complete and useful stack trace. Using  
Eclipse, you can auto-generate much of the 'boilerplate' code which is  
claimed to make Java boring to write (get, set, constructors...). It  
also more or less tells you how to fix small bugs - ';' and } missing  
for example. Even python is less helpful; concider "Unexpected indent"  
or the very informative "incorrect syntax" when you forget a ) or a : .

C (or C++) for learning to talk to the metal,
Java or Python for object orientation,
Java will give you the most help,
Python gets you started quickly,
C++ is the hardest to understand in every detail,
but C bogs you down with administrative stuff (try converting an int  
to a string; I found myself googling for an hour!).

I tried this infamous "extending in C" and I would forget that until  
you know both C and python a bit more... Also, extending python in C++  
or Java is possible - I didn't manage C++ yet,  and Java I didn't try.


Cheers!
Paul.


Den 15. april. 2008 kl. 05.46 skrev Brian Vanderburg II:

>> My idea, if you really love Python and never think about erasing it
>> from your mind, go for C (not C++). A script language plus C can  
>> solve
>> every problem you need to solve. Also Python works pretty fine with  
>> C.
> I agree mostly with this one.  Scripting is very nice when writing an
> application especially one that needs to change very often.  Plus  
> there
> are several toolkits and existing libraries available for Python.   
> I've
> used wxPython some with it, and it came in handy for a few  
> applications
> that I would have normally written in C++/wxWidgets and have to
> recompile every few weeks to suit my needs (data extraction tools/etc)
>
> However there are cases when a compiled language is better, especially
> anything that needs to be 'fast' and have a lower overhead.  I  
> wouldn't
> use Python to create a very graphics intensive game or anything,  
> though
> it can be used with pygame/PyOpenGL for some nice simple stuff. Also
> everything in Python is an object so it can start to consume memory  
> when
> handling very large data sets.  And since there is no guarantee of  
> when
> garbage collection occurs, simply 'deleting' an item does not ensure  
> it
> is completely gone, especially if there are cyclic references, though
> that can be handled by using 'gc.collect()'.
>
>
>
> I consider C++ just a simplification of C, in the sense that it  
> makes it
> easier to do things that would take more work to be done in C.  One  
> can
> still use C++ without all of the more complicated aspects but still  
> take
> advantages of other aspects.
>
> C has the advantage that it does not to anything behind your back.   
> This
> is very useful especially for any form of system development or where
> you must know exactly what is going on.  It is still possible to do
> 'object oriented' development in C, it just requires some more  
> typing to
> set up whatever is needed. Even things like COM for windows can be  
> done
> in C, it just requires manually building the 'vtable' so to speak.
> Also, C seems to avoid the use of temporaries where as C++ can use  
> them
> in conversions and assignments automatically if needed.
>
> C++ makes some of it easier by doing certain things for you.  Take a
> string object for example.  In C, assignment would only do a memory  
> copy
> operation:
>
> String a, b;
> b = a;
>
> The statement 'b = a' would only copy the memory and pointers from 'b'
> to 'a' which means they would both point to the same buffer.  To avoid
> this, a copy constructor or assignment operator can be implemented  
> when
> using C++.  The same in C would be something like:
>
> String_Assign(&b, &a); /* instead of b = a */
>
> Then if a structure contains objects, more work is needed.  For  
> example,
> in C:
>
> typedef struct Name
> {
>String honorary;
>String first;
>String middle;
>String last;
>String lineage;
> } Name;
>
> void Name_Create(Name* name)
> {
>String_Create(&name->honorary);
>String_Create(&name->first);
>String_Create(&name->middle);
>String_Create(&name->last);
>String_Create(&name->lineage);
> }
>
> void Name_Assign(Name* self, Name* other)
> {
>String_Assign(&self->honorary, &other->honorary);
>String_Assign(&self->first, &other->first);
>String_Assign(&self->middle, &other->middle);
>String_Assign(&self->last, &ot

Re: Process multiple files

2008-04-14 Thread Paul Anton Letnes
Funny,

I'm just doing exactly this:

import os

def main():
dataFolder = 'data/'
fileList = os.listdir(dataFolder)
for file in fileList:
inFile = open(dataFolder + file, 'r')
print 'read inFile & do something useful here'

Clear as an... egg?

Cheers.
Paul.



Den 14. april. 2008 kl. 14.36 skrev Doran, Harold:

> Say I have multiple text files in a single directory, for illustration
> they are called "spam.txt" and "eggs.txt". All of these text files are
> organized in exactly the same way. I have written a program that  
> parses
> each file one at a time. In other words, I need to run my program each
> time I want to process one of these files.
>
> However, because I have hundreds of these files I would like to be  
> able
> to process them all in one fell swoop. The current program is  
> something
> like this:
>
> sample.py
> new_file = open('filename.txt', 'w')
> params = open('eggs.txt', 'r')
>   do all the python stuff here
> new_file.close()
>
> If these files followed a naming convention such as 1.txt and 2.txt I
> can easily see how these could be parsed consecutively in a loop.
> However, they are not and so is it possible to modify this code such
> that I can tell python to parse all .txt files in a certain directory
> and then to save them as separate files? For instance, using the  
> example
> above, python would parse both spam.txt and eggs.txt and then save 2
> different files, say as spam_parsed.txt and eggs_parsed.txt.
>
> Thanks
>
>
>
>
>
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Wrapping C++ class with SWIG, Mac OS X

2008-04-12 Thread Paul Anton Letnes
>
> Thanks a lot for the comments. So, I post the code, which should let  
> you recreate the circumstances. I'm on 10.5.2, python2.5 (from  
> Fink), and got SIP from FINK recently - should be the latest version.
>
> I know C++ to some extent - the linking is the hardest part for me  
> to grasp. I don't have a clear idea on how these things take place,  
> nor what all the words mean.
>
> 
> word.h:
> 
> // Define the interface to the word library.
>
> #ifndef _WORD_H_
> #define _WORD_H_
> class Word {
> public:
>Word(const char *w);
>char *reverse() const;
>
> private:
>const char* the_word;
> };
> #endif /* _WORD_H_ */
> 
> word.cpp:
> 
> #include "word.h"
> Word::Word(const char *w)
> {
>this->the_word = w;
> }
> char* Word::reverse() const
> {
>return this->the_word;
> }
> 
> word.sip:
> 
> // Define the SIP wrapper to the word library.
>
> %Module word 0
>
> class Word {
>
> %TypeHeaderCode
> #include 
> %End
>
> public:
>Word(const char *w);
>
>char *reverse() const;
>
> };
> 
> configure.py:
> 
> import os
> import sipconfig
>
> # The name of the SIP build file generated by SIP and used by the  
> build
> # system.
> build_file = "word.sbf"
>
> # Get the SIP configuration information.
> config = sipconfig.Configuration()
>
> # Run SIP to generate the code.
> os.system(" ".join([config.sip_bin, "-c", ".", "-b", build_file,  
> "word.sip"]))
>
> # Create the Makefile.
> makefile = sipconfig.SIPModuleMakefile(config, build_file)
>
> # Add the library we are wrapping.  The name doesn't include any  
> platform
> # specific prefixes or extensions (e.g. the "lib" prefix on UNIX, or  
> the
> # ".dll" extension on Windows).
> makefile.extra_libs = ["word"]
>
> # Generate the Makefile itself.
> makefile.generate()
> 
>
> As I said, the code is just from this example:
> http://www.riverbankcomputing.com/static/Docs/sip4/sipref.html#using-sip
>
> It is possible that this is not well suited for OSX. The makefile  
> generated includes the flag '-bundle' which, as far as I can tell,  
> is OSX specific. However, the 'TARGET' is 'word.so', which is not  
> 'libword.dylib'.
>
> Do you know a good web resource for learning the basics of linking?  
> Man pages are a bit brief for newbies.
>
>
> Cheers!
> Paul.
>
>
>> Not knowing C/C++ & linking is certainly something that will get you
>> when trying to wrap libs written in these languages.
>>
>> I'm on OSX myself, and can say that as a unixish system, it is rather
>> friendly to self-compliation needs.
>>
>> However, without having the complete sources & libs, I can't really
>> comment much - the only thing that is clear from above is that the
>> linker does not find the file
>>
>> libword.dylib
>>
>> which you of course need to have somewhere. The good news is that  
>> once
>> you've teached the linker where to find it (using LDFLAGS or other
>> means) you are (modulo debugging) done - SIP has apparently grokked  
>> your
>> .sip-file.
>>
>> Of course you also must make the library available at runtime. So it
>> must be installed on a location (or that location given with
>> DYLD_LIBRARY_PATH) where the dynamic loader will find it.
>>
>> Diez
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>

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


Re: Wrapping C++ class with SWIG, Mac OS X

2008-04-12 Thread Paul Anton Letnes
Okay, installed SIP. Looks promising, following the tutorial on
http://www.riverbankcomputing.com/static/Docs/sip4/sipref.html#using-sip
It should be noted that I am working on a Mac - I know there are some  
differences, but it's still UNIX and should work somehow.

Anyway, I copy-paste and create the Word.h header, write an  
implementation in Word.cpp, the SIP wrapper Word.sip and the  
configure.py script. I now run configure and make, creating the  
following error:

~/Desktop/SIP_example $ python configure.py
~/Desktop/SIP_example $ make
c++ -c -pipe -fPIC -Os -Wall -W -I. -I/sw/include/python2.5 -o  
sipwordcmodule.o sipwordcmodule.cpp
c++ -c -pipe -fPIC -Os -Wall -W -I. -I/sw/include/python2.5 -o  
sipwordWord.o sipwordWord.cpp
c++ -headerpad_max_install_names -bundle -undefined dynamic_lookup -o  
word.so sipwordcmodule.o sipwordWord.o -lword
ld: library not found for -lword
collect2: ld returned 1 exit status
make: *** [word.so] Error 1
~/Desktop/SIP_example $

SWIG at least works nicely with C... Too bad I know so little about  
compilers and libraries, I don't quite understand what the linker (ld)  
is complaining about. The simplest tutorial should anyway work?


Cheers
Paul.


>
> Can't help on SWIG - all I can say is that SIP which is used to wrap  
> the
> large and template-ridden C++-GUI-Toolkit Qt worked flawlessly for me.
> Maybe you should try that.
>
> Diez
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Wrapping C++ class with SWIG, Mac OS X

2008-04-11 Thread Paul Anton Letnes
Hello guys,


(related to previous thread on wrapping C/C++ in Python, trying the  
SWIG approach.)
Trying to map a C++ class to python, one method for now. Running the  
following commands to "compile":

--
#!/usr/bin/env bash

MOD_NAME=Wavelet


swig -c++ -python -o ${MOD_NAME}_wrap.cpp ${MOD_NAME}.i

gcc -c++ -fPIC -c ${MOD_NAME}.cpp -o ${MOD_NAME}.o -I/usr/include/ 
python2.5 -I/usr/lib/python2.5

gcc -c++ -fPIC -c ${MOD_NAME}_wrap.cpp -o ${MOD_NAME}_wrap.o -I/usr/ 
include/python2.5 -I/usr/lib/python2.5

gcc -bundle -flat_namespace -undefined suppress -o _${MOD_NAME}.so $ 
{MOD_NAME}.o  ${MOD_NAME}_wrap.o
--

The source code is:
--
Wavelet.h
--
#ifndef _WAVELET_H_
#define _WAVELET_H_

#include 
#include 

using namespace std;

class Wavelet
{

public:
 Wavelet(vector theV);
 ~Wavelet();
 vector GetDaub4Trans();

private:
 vector v;

};


#endif /*_WAVELET_H_*/
--
and Wavelet.cpp:
--
#include "wavelet.h"

Wavelet::Wavelet(vector theV)
{
 this->v = theV;
}

Wavelet::~Wavelet()
{
 // Nothing for now
}

vector Wavelet::GetDaub4Trans()
{
 vector retV = vector();
 retV.push_back(3.14);
 retV.push_back(2.71);
 retV.push_back(1.62);
 return retV;
// just to test the approach - everything in here I can fix later.
}
--
This seems to compile, but in python I get:
--
$ python
imPython 2.5.2 (r252:60911, Mar 30 2008, 22:49:33)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import Wavelet
Traceback (most recent call last):
   File "", line 1, in 
   File "Wavelet.py", line 7, in 
 import _Wavelet
ImportError: dlopen(./_Wavelet.so, 2): Symbol not found:  
__ZNKSt11logic_error4whatEv
   Referenced from: /Users/paul/Desktop/Wavelet_SWIG_Cpp/_Wavelet.so
   Expected in: flat namespace

 >>>
--

Any ideas or tips? SWIG seems very nice for simple C methods where you  
pass an int and return an int, but I can't seem to figure out the  
syntaxes etc for more complicated stuff - arrays, vector, C++, ...  
Appreciate any help!


Cheers,
Paul.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with using gnuplot/demo.py

2008-04-10 Thread Paul Anton Letnes

Could you include some code around line 39 in demo.py?

Also, you could try to comment out the stuff before that point, and  
see if the demo runs that far.


Paul.



hi
i want to use gnuplot with python
i installed it  seemingly successfully
but when i try to run demo.py it gives the following error


Traceback (most recent call last):
  File "C:\Python23\Lib\site-packages\Gnuplot\demo.py", line 113, in ?
demo()
  File "C:\Python23\Lib\site-packages\Gnuplot\demo.py", line 39, in  
demo

g.reset()
  File "C:\Python23\Lib\site-packages\Gnuplot\_Gnuplot.py", line  
355, in reset

self('reset')
  File "C:\Python23\Lib\site-packages\Gnuplot\_Gnuplot.py", line  
199, in __call__

self.gnuplot(s)
  File "C:\Python23\Lib\site-packages\Gnuplot\gp_win32.py", line  
125, in __call__

self.write(s + '\n')


im using python23 & gnuplot1.7

please help

From Chandigarh to Chennai - find friends all over India. Click  
here.--

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


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

Re: wrapping C functions in python

2008-04-09 Thread Paul Anton Letnes
Brian and Diez:

First of all, thanks for the advice.

Brian:

I have installed NumPy and SciPy, but I can't seem to find a wavelet  
transform there.

The main point of this was more to learn C wrapping than to actually  
get a calculation done. I will probably be starting a PhD soon, doing  
really heavy computations. If I want to manipulate data (input /  
results), python is very nice, especially with gnuplot-py. However,  
heavy calculations should probably be done in C(++), especially as  
some code for this already exists.

I will look into SWIG.


Diez:

I will look into it. Do you know a good tutorial for this? I found the  
"standard" tutorial on C extensions, http://www.python.org/doc/ext/intro.html 
  , but as I mentioned, it seems to be a bit complicated to wrap heavy  
data structures like arrays.



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


Re: wrapping C functions in python

2008-04-09 Thread Paul Anton Letnes
Hi, and thanks.


However, being a newbie, I now have to ask: What is SWIG? I have heard  
the name before, but haven't understood what it is, why I need it, or  
similar. Could you please supply some hints?


-Paul


Den 9. april. 2008 kl. 22.22 skrev Brian Cole:

> We use the following SWIG (www.swig.org) typemap to perform such  
> operations:
>
> %typemap(in) (int argc, char **argv) {
> if (!PySequence_Check($input)) {
>  PyErr_SetString(PyExc_ValueError,"Expected a sequence");
>  return NULL;
> }
> $1 = PySequence_Length($input);
> $2 = (char**)alloca($1*sizeof(char*));
> for (Py_ssize_t i = 0; i < $1; ++i) {
>  PyObject *o = PySequence_GetItem($input, i);
>  $2[i] = PyString_AsString(o);
> }
> }
>
> That one works for mapping a python sequence (such as a list) into the
> argc, argv arguments commonly passed into main.
>
> -Brian
>
> On Wed, Apr 9, 2008 at 2:13 PM, Paul Anton Letnes
> <[EMAIL PROTECTED]> wrote:
>> Hello etc.
>>
>>
>> I am a "scientific" user of Python, and hence have to write some  
>> performance
>> critical algorithms. Right now, I am learning Python, so this is a  
>> "newbie"
>> question.
>>
>> I would like to wrap some heavy C functions inside Python,  
>> specifically a
>> wavelet transform. I am beginning to become aquainted with the  
>> functions
>> PyArg_ParseTuple() and Py_BuildValue(). However, I am unable to  
>> figure out
>> how to pass Python list -> C function or C array -> return value in  
>> Python.
>> I manage to build and run the C function, print to screen, pass  
>> string as
>> argument, return an int, etc. The thing which is missing is the magic
>> array/list...
>>
>>
>> Thanks in advance! I fart in your general direction.
>> Paul.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


wrapping C functions in python

2008-04-09 Thread Paul Anton Letnes

Hello etc.


I am a "scientific" user of Python, and hence have to write some  
performance critical algorithms. Right now, I am learning Python, so  
this is a "newbie" question.


I would like to wrap some heavy C functions inside Python,  
specifically a wavelet transform. I am beginning to become aquainted  
with the functions PyArg_ParseTuple() and Py_BuildValue(). However, I  
am unable to figure out how to pass Python list -> C function or C  
array -> return value in Python. I manage to build and run the C  
function, print to screen, pass string as argument, return an int,  
etc. The thing which is missing is the magic array/list...



Thanks in advance! I fart in your general direction.
Paul.-- 
http://mail.python.org/mailman/listinfo/python-list