dynamically loaded libraries

2006-05-28 Thread mhearne808
I have a question about how dynamically loaded C++ modules work, which
I will phrase as a hypothetical scenario involving the Numeric module.
 Please understand that I don't really care about Numeric per se, it's
just a useful example of a module that defines a generally useful data
type.

Let's say I want to create a C++ Python extension module that has
methods accepting the Numeric array type as input, and also create
these arrays as output. 

In order to make this work, do I have to statically link against the
Numeric source, or do I only have to include the headers, under the
assumption (??) that the Numeric functionality will be available
because the Python executable has dynamically loaded it?

Thanks!

Mike



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


Re: where do I put resources (images, audio files) when I wrote Python program?

2009-07-27 Thread mhearne808
On Jul 27, 12:43 pm, Piotrek  wrote:
> Hello,
>
> I write a Python program. It will contain some images (in .png format), some
> audio files (as .ogg) etc. Now I think where should my installer put these
> files and how should I access them. What is the normal Python way of doing
> that? I think about puting these files in /usr/share/myprogram and then
> reading it the normal way (so the path "/usr/share/myprogram" would be just
> hardwired in my program). Is it the way one usually does it in Python
> program or is there any more sofisticated way?

Usually the preferred method is either distutils (http://
docs.python.org/library/distutils.html#module-distutils) or setuptools
(http://peak.telecommunity.com/DevCenter/setuptools).  Either of these
will allow you to create source (".tar.gz") or binary distributions
that can be installed relatively easily on a target machine.

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


Decorator behavior

2011-07-22 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I am just trying to wrap my head around decorators in Python, and I'm
confused about some behavior I'm seeing.  Run the code below (slightly
adapted from a Bruce Eckel article), and I get the following output:

inside myDecorator.__init__()
inside aFunction()
Finished decorating aFunction()
inside myDecorator.__call__()

My question: Why isn't the first print statement in "__main__" the
first line of code executed?  Is aFunction() not closed somehow?

#!/usr/bin/env python

class myDecorator(object):
def __init__(self, f):
print "inside myDecorator.__init__()"
f() # Prove that function definition has completed

def __call__(self):
print "inside myDecorator.__call__()"

@myDecorator
def aFunction():
print "inside aFunction()"

if __name__ == '__main__':
print "Finished decorating aFunction()"
aFunction()
-- 
http://mail.python.org/mailman/listinfo/python-list


accessing parts of large files with File.seek()

2007-08-08 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I'm having a problem with the File object's seek() method.
Specifically, I cannot use it to seek to a location in a binary file
that is greater than 2^31 (2147483648).  This seems unnecessarily
limiting, as it is common these days to have files larger than 2 GB.

Is there some LargeFile object out there that I can use to read my
file, which is approximately 3.3 GB in size?

Python version (freshly built from source this morning):
Python 2.5.1 (r251:54863, Aug  8 2007, 09:23:05)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin

Thanks,

Mike

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


Re: accessing parts of large files with File.seek()

2007-08-08 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
On Aug 8, 7:37 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Aug 8, 11:46 am, "mhearne808[insert-at-sign-here]gmail[insert-dot-
>
>
>
> here]com" <[EMAIL PROTECTED]> wrote:
> > I'm having a problem with the File object's seek() method.
> > Specifically, I cannot use it to seek to a location in a binary file
> > that is greater than 2^31 (2147483648).  This seems unnecessarily
> > limiting, as it is common these days to have files larger than 2 GB.
>
> > Is there some LargeFile object out there that I can use to read my
> > file, which is approximately 3.3 GB in size?
>
> > Python version (freshly built from source this morning):
> > Python 2.5.1 (r251:54863, Aug  8 2007, 09:23:05)
> > [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
>
> > Thanks,
>
> > Mike
>
> I use large files quite a bit, but in Windows & Linux.  Here's a quick
> excerpt of a local ubuntu-linux session...
>
> [EMAIL PROTECTED]:/var/virtualbox/VDI$ ls -l
> total 1682536
> -rw-rwx--- 1 jaime vboxusers  40960 2007-07-20 21:41 windows
> xp.vdi
> -rw-rwx--- 1 jaime vboxusers 3591387136 2007-07-20 21:53 winxp.vdi
> [EMAIL PROTECTED]:/var/virtualbox/VDI$ ipython
> Python 2.5.1 (r251:54863, May  2 2007, 16:27:44)
> Type "copyright", "credits" or "license" for more information.
>
> IPython 0.7.3 -- An enhanced Interactive Python.
> ?   -> Introduction to IPython's features.
> %magic  -> Information about IPython's 'magic' % functions.
> help-> Python's own help system.
> object? -> Details about 'object'. ?object also works, ?? prints more.
>
> In [1]: f = file('winxp.vdi')
>
> In [2]: f.seek(3591387132)
>
> In [3]: f.read()
> Out[3]: '\x00\x00\x00\x00'
>
> In [4]:
>
> What exception are you receiving?  (Not that I can offer any advice,
> as I don't have a Mac to use for testing.)...
>
> jw

I think I've figured out what the problem must be (not at Mac anymore,
so will have to test tomorrow).  According to this link:
http://docs.python.org/lib/posix-large-files.html

I probably need to compile in large file support on my Mac.  I get it
for free on my Ubuntu linux box...

FYI, it was an OverFlow Error.

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


fcntl problems

2007-08-30 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I'm having a number of problems with the fcntl module.  First off, my
system info:

Mac OS X
Darwin igskcicglthearn.cr.usgs.gov 8.10.1 Darwin Kernel Version
8.10.1: Wed May 23 16:33:00 PDT 2007; root:xnu-792.22.5~1/RELEASE_I386
i386 i386
Python 2.5.1 (built from source)

OK, the weirdness:

First of all, if I try this:
file = open("counter.txt","w+")
fcntl.flock(file.fileno(), fcntl.LOCK_NB)

I get this:
---
   Traceback (most recent call
last)
/Users/mhearne/src/python/ in ()
: [Errno 9] Bad file descriptor

However, if I try this:
fcntl.flock(file.fileno(), fcntl.LOCK_EX)

I get no errors.

Proceeding forward with the locked file, let's say I do the above in
Python interactive Process A.  Then in python interactive Process B, I
repeat the "open" function on the same file with the same
permissions.  Then, in each process, I write some text to the file
using the write() method.  After closing the file in both processes,
the only text I see in the file is from Process B!

According to my Python Cookbook:
"Exclusive lock: This denies all _other_ processes both read and write
access to the file."

I seem to be experiencing the reverse of that description.  Is this my
lack of understanding, or have I discovered a bug?

Thanks,

Mike

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


Re: fcntl problems

2007-08-30 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
On Aug 30, 4:19 pm, "mhearne808[insert-at-sign-here]gmail[insert-dot-
here]com" <[EMAIL PROTECTED]> wrote:
> I'm having a number of problems with the fcntl module.  First off, my
> system info:
>
> Mac OS X
> Darwin igskcicglthearn.cr.usgs.gov 8.10.1 Darwin Kernel Version
> 8.10.1: Wed May 23 16:33:00 PDT 2007; root:xnu-792.22.5~1/RELEASE_I386
> i386 i386
> Python 2.5.1 (built from source)
>
> OK, the weirdness:
>
> First of all, if I try this:
> file = open("counter.txt","w+")
> fcntl.flock(file.fileno(), fcntl.LOCK_NB)
>
> I get this:
> ---
>Traceback (most recent call
> last)
> /Users/mhearne/src/python/ in ()
> : [Errno 9] Bad file descriptor
>
> However, if I try this:
> fcntl.flock(file.fileno(), fcntl.LOCK_EX)
>
> I get no errors.
>
> Proceeding forward with the locked file, let's say I do the above in
> Python interactive Process A.  Then in python interactive Process B, I
> repeat the "open" function on the same file with the same
> permissions.  Then, in each process, I write some text to the file
> using the write() method.  After closing the file in both processes,
> the only text I see in the file is from Process B!
>
> According to my Python Cookbook:
> "Exclusive lock: This denies all _other_ processes both read and write
> access to the file."
>
> I seem to be experiencing the reverse of that description.  Is this my
> lack of understanding, or have I discovered a bug?
>
> Thanks,
>
> Mike

I've been doing some experiments, and here are some specific examples
to try.  I'll designate the two interactive python processes as PA and
PB.  Both processes were started in the same directory.  Here goes:
PA: import fcntl
PA: f = open("foo.txt","w+")
PA: fcntl.flock(f.fileno(),fcntl.LOCK_EX)
PA: f.write("text1\n")
PB: f = open("foo.txt","w+")
PB: f.write("text2\n")
PA: f.close()
PB: f.close()

contents of foo.txt are:
text2

Second experiment:

PA: f = open("foo.txt","w+")
PA: fcntl.flock(f.fileno(),fcntl.LOCK_EX)
PB: f = open("foo.txt","w+")
PA: f.write("text1\n")
PB: f.write("text2\n")
PA: f.write("text3\n")
PB: f.close()
PA: f.write("text4\n")
PA: f.close()

contents of foo.txt are:
text1
text3
text4

Third experiment:
PA: f = open("foo.txt","w+")
PA: fcntl.flock(f.fileno(),fcntl.LOCK_EX)
PA: f.write("text1\n")
PB: f = open("foo.txt","w+")
PB: f.write("text2\n")
PB: f.close()
PA: f.close()

contents of foo.txt are:
text1

Fourth experiment:
PA: f = open("foo.txt","w+")
PA: f.write("text1\n")
PB: f = open("foo.txt","w+")
PB: f.write("text2\n")
PB: f.close()
PA: f.close()

contents of foo.txt are:
text1

>From these last two experiments I can only conclude that file locking
isn't doing a durned thing.

What's going on?

--Mike

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


Re: fcntl problems

2007-08-31 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
On Aug 31, 12:23 am, Miles <[EMAIL PROTECTED]> wrote:
> Sorry, that last quote-only reply was accidental. :)
>
> On 8/30/07, mhearne808 wrote:
> > I've been doing some experiments, and here are some specific examples
> > to try.
>
> [snipped examples]
>
> > From these last two experiments I can only conclude that file locking
> > isn't doing a durned thing.
>
> > What's going on?
>
> File locking isn't doing a durned thing in those cases because you're
> only obtaining the lock from a single process.
>
> > According to my Python Cookbook:
> > "Exclusive lock: This denies all _other_ processes both read and write
> > access to the file."
>
> This is only for mandatory locking; POSIX flock is advisory locking,
> which states: "Only one process may hold an exclusive lock for a given
> file at a given time."  Advisory locks don't have any effect on
> processes that don't use locks.  Mandatory locks are kernel enforced,
> but non-POSIX and not available in Mac OS X.
>
> -Miles

I think I'm still confused.  Maybe I should explain the behavior that
I want, and then figure out if it is possible.

I have a script that will be run from a cron job once a minute.  One
of the things this script will do is open a file to stash some
temporary results.  I expect that this script will always finish its
work in less than 15 seconds, but I didn't want to depend on that.
Thus I started to look into file locking, which I had hoped I could
use in the following fashion:

Process A opens file foo
Process A locks file foo
Process A takes more than a minute to do its work
Process B wakes up
Process B determines that file foo is locked
Process B quits in disgust
Process A finishes its work

Since I couldn't figure out file locking, I decided to just have
Process A create a "pid" file in the directory - analogous to the
"Occupied" sign on an airplane bathroom.  This works, but it seems a
little hacky.

--Mike

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


Re: fcntl problems

2007-08-31 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
On Aug 31, 8:42 am, Miles <[EMAIL PROTECTED]> wrote:
> On 8/31/07, mhearne808 wrote:
> > I have a script that will be run from a cron job once a minute.  One
> > of the things this script will do is open a file to stash some
> > temporary results.  I expect that this script will always finish its
> > work in less than 15 seconds, but I didn't want to depend on that.
> > Thus I started to look into file locking, which I had hoped I could
> > use in the following fashion:
>
> > Process A opens file foo
> > Process A locks file foo
> > Process A takes more than a minute to do its work
> > Process B wakes up
> > Process B determines that file foo is locked
> > Process B quits in disgust
> > Process A finishes its work
>
> That would look like (untested):
>
> importfcntl, sys
> f = open('foo', 'w+')
> try:
>fcntl.flock(f.fileno(),fcntl.LOCK_EX |fcntl.LOCK_NB)
> except IOError, e:
> if e.args[0] == 35:
> sys.exit(1)
> else:
> raise
> f.seek(0, 2) # seek to end
> # do your thing with the file
> f.flush()fcntl.flock(f.fileno(),fcntl.LOCK_UN)
> f.close()
>
> -Miles

I tested that, and it works!  Thanks!

Looking at my flock(3) man page, I'm guessing that "35" is the error
code for EWOULDBLOCK.  Which system header file am I supposed to look
in to figure that magic number out?

I would make the argument that this module could be either more
pythonic, or simply documented more completely.  The open source
response, of course, would be "go for it!".

--Mike

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


Don't understand module search path...

2007-10-04 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I think I don't understand how the module search path works...

Let's say I have a folders called 'test'.  Underneath it, I create two
more folders called 'foo' and 'bar'.

In 'foo', I create an empty '__init__.py' file, indicating that this
folder is a package 'foo'.  I then create a simple python script
'foo.py' consisting of the following code:


#!/usr/bin/python

def printhello():
print 'Hello world!'


Then in test/bar, I create 'bar.py' consisting of the following code:

#!/usr/bin/python
import sys
import os
(curpath,thisdir) = os.path.split(os.getcwd())
foopath = os.path.join(curpath,'foo')
sys.path.append(foopath)
print sys.path
os.chdir(os.path.join(os.getcwd(),'..'))
print os.getcwd()
from foo.foo import printhello


When I try to run bar.py, I get the following:


[sys.path search path, including full path to 'foo' folder]
path/to/test
Traceback (most recent call last):
  File "/path/to/test/bar/testfoo.py", line 16, in 
from foo.foo import printhello
ImportError: No module named foo


Why?  If 'foo' is in sys.path, shouldn't it appear when I try to
import the foo module from it?  Incidentally, when I move the script
up to 'test' and modify it so that it just says:

#!/usr/bin/python

from foo.foo import printhello


I get no errors.  I don't understand the difference...

Incidentally, my platform info:
Python 2.5.1
Darwin Kernel Version 8.10.1 (Mac OS X)

Help!

--Mike

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


PYTHONPATH on OS X

2007-10-10 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I'm missing something major here.  I'm trying to add a directory to my
python path using the PYTHONPATH environment variable, and it's being
ignored by the Python interactive shell.

Below is a capture of what I did.  Note that my newfolder appears
nowhere on the list of directories in sys.path.  How do I get Python
to pay attention to my shell variables?

Using bash on OS X 10.4.10.

%:~ user$ echo $PYTHONPATH

%:~ user$ PYTHONPATH=/Users/user/newfolder
%:~ user$ echo $PYTHONPATH
/Users/user/newfolder
%:~ user$ python
Python 2.5.1 (r251:54863, Aug 10 2007, 10:46:58)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python2.5/site-packages/
setuptools-0.7a1dev_r56320-py2.5.egg', '/usr/local/lib/python2.5/site-
packages/ipython1-0.9alpha2-py2.5.egg', '/usr/local/lib/python2.5/site-
packages/SQLAlchemy-0.4.0beta5-py2.5.egg', '/usr/local/lib/python2.5/
site-packages/MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg', '/usr/
local/lib/python25.zip', '/usr/local/lib/python2.5', '/usr/local/lib/
python2.5/plat-darwin', '/usr/local/lib/python2.5/plat-mac', '/usr/
local/lib/python2.5/plat-mac/lib-scriptpackages', '/usr/local/lib/
python2.5/lib-tk', '/usr/local/lib/python2.5/lib-dynload', '/usr/local/
lib/python2.5/site-packages', '/usr/local/lib/python2.5/site-packages/
PIL']

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


Re: PYTHONPATH on OS X

2007-10-11 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
On Oct 10, 4:59 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Oct 11, 8:00 am, "mhearne808[insert-at-sign-here]gmail[insert-dot-
>
>
>
> here]com" <[EMAIL PROTECTED]> wrote:
> > I'm missing something major here.  I'm trying to add a directory to my
> > python path using the PYTHONPATH environment variable, and it's being
> > ignored by the Python interactive shell.
>
> > Below is a capture of what I did.  Note that my newfolder appears
> > nowhere on the list of directories in sys.path.  How do I get Python
> > to pay attention to my shell variables?
>
> > Using bash on OS X 10.4.10.
>
> > %:~ user$ echo $PYTHONPATH
>
> > %:~ user$ PYTHONPATH=/Users/user/newfolder
> > %:~ user$ echo $PYTHONPATH
> > /Users/user/newfolder
> > %:~ user$ python
> > Python 2.5.1 (r251:54863, Aug 10 2007, 10:46:58)
> > [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> > Type "help", "copyright", "credits" or "license" for more information.>>> 
> > import sys
> > >>> sys.path
>
> > ['', '/usr/local/lib/python2.5/site-packages/
> > setuptools-0.7a1dev_r56320-py2.5.egg', '/usr/local/lib/python2.5/site-
> > packages/ipython1-0.9alpha2-py2.5.egg', '/usr/local/lib/python2.5/site-
> > packages/SQLAlchemy-0.4.0beta5-py2.5.egg', '/usr/local/lib/python2.5/
> > site-packages/MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg', '/usr/
> > local/lib/python25.zip', '/usr/local/lib/python2.5', '/usr/local/lib/
> > python2.5/plat-darwin', '/usr/local/lib/python2.5/plat-mac', '/usr/
> > local/lib/python2.5/plat-mac/lib-scriptpackages', '/usr/local/lib/
> > python2.5/lib-tk', '/usr/local/lib/python2.5/lib-dynload', '/usr/local/
> > lib/python2.5/site-packages', '/usr/local/lib/python2.5/site-packages/
> > PIL']
>
> You need to export the environment variable.
>
>   export PYTHONPATH
>
> Graham

Thanks all - I'm recently back to using Unix (Mac) after 5 years of
being on a PC.  I guess I thought export was just another way of doing
assignment.  My bad.

--Mike

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


Creating installer with external extension modules

2007-11-09 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I'm creating a piece of software which will be used by in-house
users.  My code will all be written in pure Python; however, it
depends heavily on a number of third-party Python modules, many of
which have C/C++ dependencies (numpy, scipy, etc.)  Installing these
packages on my machine involved a morning of several serial "./
configure;make;sudo make install" steps.  I'd prefer to automate all
of this for my users, but I'm not clear how to do this - I'm in an
environment of mixed Mac (desktops) and Linux (servers) and I'll need
to install on both platforms, and would prefer not to run around to
each computer making sure the dependencies are met.

I've looked through the documentation for distutils and setuptools,
and it's not obvious to me that there are hooks in either one for
passing in configure and make calls.

The fallback, I suppose, presuming that the correct version of Python
is already installed, is to write a custom Python script that "knows"
about each dependency, and takes the appropriate action.  I should be
able to depend on everyone having gcc and make installed, I think.

Does anyone have any suggestions on the best way to approach this?

Thanks,

Mike

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


Getting file timestamp from url

2007-11-16 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
Is is possible to get the timestamp of a file on a web server if it
has a URL?

For example, let's say that I want to know when the following file was
created:

http://www.w3schools.com/xml/note.xml

I can get an HTTPMessage object using urllib2, like this:

---
#!/usr/bin/python
import urllib2
url = 'http://www.w3schools.com/xml/note.xml'
f = urllib2.urlopen(url)
finfo = f.info()
---

My finfo is an HTTPMessage object, which has getdate() and
getdate_tz() methods.  However, they both require a 'name' argument.
I can't figure out what this is...

Am I going down the wrong path?  Is there a path I can go down to get
what I want?

Thanks,

Mike

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


compiling python 2.5, missing zlib

2007-11-19 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I'm trying to compile Python 2.5 on a RHEL system, using "./
configure;make;make install".  The build seems to go alright, but the
zlib module is missing.

I've tried the following:
1) Download and build the zlib libraries myself
2) Specify '--without-system-zlib' to ./configure

Neither seems to work.  What am I missing here?

Thanks,

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


Re: compiling python 2.5, missing zlib

2007-11-19 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
On Nov 19, 2:19 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > Neither seems to work.  What am I missing here?
>
> You forgot to install the zlib header files, which come in
> an RPM provided by Redhat (probably called zlib-dev or some
> such).
>
> Regards,
> Martin

Those headers are already installed, according to "up2date". Is there
a way to specify the header files used?

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


Re: compiling python 2.5, missing zlib

2007-11-21 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
On Nov 19, 8:22 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > Those headers are already installed, according to "up2date". Is there
> > a way to specify the header files used?
>
> It will automatically use them if they are good. What's the value of
> ZLIB_VERSION in /usr/include/zlib.h?
>
> Regards,
> Martin

I got my Python compile to work, by setting recompiling the zlib
source I downloaded with a --shared configure option.

Now I'm having trouble getting the Python MySQL module to install.
That'll be a separate post!

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


Problems building zlib module on RHEL

2008-03-18 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I can't seem to get the zlib module to build on an RHEL box.

I did the following:
1) Download zlib 1.2.3
2) configure;make;make install
3) Download python 2.5.2
4) configure;make;make install
5) >>> import zlib => "ImportError: No module named zlib"

In the make install step for python, I notice there are the following
errors:

building 'zlib' extension
gcc -pthread -shared build/temp.linux-x86_64-2.5/home/shake/python/
Python-2.5.2/Modules/zlibmodule.o -L/usr/local/lib -lz -o build/
lib.linux-x86_64-2.5/zlib.so
/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32
against `a local symbol' can not be used when making a shared object;
recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

Does anyone have any hints on how to get around this?

system info:
kernel : 2.6.9-67.0.1.ELsmp
gcc : 3.4.6

Thanks,

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


Re: Problems building zlib module on RHEL

2008-03-18 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
On Mar 18, 8:42 am, "mhearne808[insert-at-sign-here]gmail[insert-dot-
here]com" <[EMAIL PROTECTED]> wrote:
> I can't seem to get the zlib module to build on an RHEL box.
>
> I did the following:
> 1) Download zlib 1.2.3
> 2) configure;make;make install
> 3) Download python 2.5.2
> 4) configure;make;make install
> 5) >>> import zlib => "ImportError: No module named zlib"
>
> In the make install step for python, I notice there are the following
> errors:
>
> building 'zlib' extension
> gcc -pthread -shared build/temp.linux-x86_64-2.5/home/shake/python/
> Python-2.5.2/Modules/zlibmodule.o -L/usr/local/lib -lz -o build/
> lib.linux-x86_64-2.5/zlib.so
> /usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32
> against `a local symbol' can not be used when making a shared object;
> recompile with -fPIC
> /usr/local/lib/libz.a: could not read symbols: Bad value
> collect2: ld returned 1 exit status
>
> Does anyone have any hints on how to get around this?
>
> system info:
> kernel : 2.6.9-67.0.1.ELsmp
> gcc : 3.4.6
>
> Thanks,
>
> Mike

I figured it out, although it wasn't obvious... You have to compile
zlib as a shared library by running "configure -s".
-- 
http://mail.python.org/mailman/listinfo/python-list


Appending to sys.path

2009-03-24 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I have an application where I would like to append to the python path
dynamically.  Below is a test script I wrote.  Here's what I thought
would happen:

1) I run this script in a folder that is NOT already in PYTHONPATH
2) The script creates a subfolder called foo.
3) The script creates a file called foo.py, with a foo() method
defined in it.
4) The script attempts to import this module, which fails because the
current folder is not in PYTHONPATH.
5) The script then adds the current folder to the end of sys.path
6) The script again attempts to import foo.foo, and succeeds.

#6 never happens, but I can't figure out why.  I'm running on Mac OS
10.5, with python 2.5.1.

Anybody have any tips?

Thanks,

Mike

Here's the script:
#!/usr/bin/python

import sys
import os.path

txt = 'def foo(): print "Hello world!"\n'
if not os.path.isdir('foo'):
os.mkdir('foo')
f = open('foo/foo.py','wt')
f.write(txt)
f.close()

try:
__import__('foo.foo')
except ImportError:
homedir = os.path.abspath(sys.path[0]) #where is this script?
print 'Adding %s to sys.path' % (homedir)
sys.path.append(homedir)
try:
__import__('foo.foo')
print 'Import now successful'
except ImportError:
print "Why didn't this work?"
sys.exit(1)
--
http://mail.python.org/mailman/listinfo/python-list


returning all matching groups with re.search()

2011-02-03 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
Here's a scenario:

import re
m = re.search('e','fredbarneybettywilma')

Now, here's a stupid question:
why doesn't m.groups() return ('e','e','e').

I'm trying to figure out how to match ALL of the instances of a
pattern in one call - the group() and groups() return subgroups... how
do I get my search to get me all of the matching subgroups?
-- 
http://mail.python.org/mailman/listinfo/python-list