Which SQL module to use?
I'd like to do some basic SQL stuff in Python. It seems like there are a heck of a lot of SQL modules for Python. What's the simplest and easiest one to use? Thanks, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
MinGW building with Python 2.4
Ok, I know there are already a million posts on this group about getting Python to build with MinGW. I've been through many of them, and have still not found a good comprehensive way to accomplish this. I've got Cygwin 5.1 with GCC 3.3.3 on it. I'm using Python 2.4. Note: You invoke the mingwin compiler *indirectly*, by running gcc with the -mno-cygwin option. So first of all, I tried exporting CC='gcc -mno-cygwin', configuring, and making. You end up getting file-not-found errors, because some of the include files aren't present for mingw. Next: I tried pymingw: didn't work :( Any ideas? Thanks in advance, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Re: MinGW building with Python 2.4
> Since the only official way to do this is pymingw, you should at least > give feedback of the steps you followed, and what didn't work (1) I have Cygwin 5.1 with GCC 3.3.1 on it. (2) I unzipped Python 2.4. (3) I unzipped pyMinGW-24-0064.zip into that directory, overwriting the appropriate files. (4) I went into the [Python]/MinGW directory and ran 'make -f python24.mak all'. (5) Here are the results: make -f pythoncore.mak make[1]: Entering directory `/home/Administrator/sgross/Python-2.4/MinGW' gcc.exe -c ../Modules/_bisectmodule.c -o ../Modules/_bisectmodule.o -I"../Include" -I"../PC" -I"../Python" -Wall -s -DNDEBUG -DPy_BUILD_CORE -DPy_ENABLE_SHARED -O2 In file included from ../Include/Python.h:82, from ../Modules/_bisectmodule.c:6: ../Include/intobject.h:41: error: parse error before "PyInt_AsUnsignedLongLongMask" ../Include/intobject.h:41: warning: type defaults to `int' in declaration of `PyInt_AsUnsignedLongLongMask' ../Include/intobject.h:41: warning: data definition has no type or storage class In file included from ../Include/Python.h:84, from ../Modules/_bisectmodule.c:6: ../Include/longobject.h:37: warning: parameter names (without types) in function declaration ../Include/longobject.h:39: error: parse error before "PyLong_AsLongLong" ../Include/longobject.h:39: warning: type defaults to `int' in declaration of `PyLong_AsLongLong' ../Include/longobject.h:39: warning: data definition has no type or storage class ../Include/longobject.h:40: error: parse error before "PyLong_AsUnsignedLongLong" ../Include/longobject.h:40: warning: type defaults to `int' in declaration of `PyLong_AsUnsignedLongLong' ../Include/longobject.h:40: warning: data definition has no type or storage class ../Include/longobject.h:41: error: parse error before "PyLong_AsUnsignedLongLongMask" ../Include/longobject.h:41: warning: type defaults to `int' in declaration of `PyLong_AsUnsignedLongLongMask' ../Include/longobject.h:41: warning: data definition has no type or storage class make[1]: *** [../Modules/_bisectmodule.o] Error 1 make[1]: Leaving directory `/home/Administrator/sgross/Python-2.4/MinGW' make: *** [pythoncore] Error 2 Any ideas? Thanks in advance, --Steve -- http://mail.python.org/mailman/listinfo/python-list
Embedding a binary file in a python script
I want to find a way to embed a tar file *in* my python script, and then use the tarfile module to extract it. That is, instead of distributing two files (extractor.py and archive.tar) I want to be able to distribute *one* file (extractor-with-embedded-archive.py). Is there a way to do this? Thanks, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding a binary file in a python script
Ok, this is a neat idea... The uu module deals with files though, not strings. Is there a way in python to make a string act like a file handle? Example: my_string = "uu-encoded-stuf.." my_out_file_handle = ?? # What should this variable look like? import uu uu.decode(my_string, my_out_file_handle) import tarfile tarfile.open(my_out_file_handle) Thanks again, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding a binary file in a python script
Ok, this looks really cool, but can you explain a little more step-by-step what's going on? In the end, I need to have a single python script that (1) contains the archive and (2) can extract that archive. The example you've given is interesting, but it's not clear to me how to create the actual python script to do it all. Thanks again, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding a binary file in a python script
Good point I appreciate all the help, and apologize if I came across badly. I'm definitely willing to put in the work to understand all this, it's just that it's a lot of new modules for me and I'm a bit overwhelmed. Sorry if I seemed impatient... -- http://mail.python.org/mailman/listinfo/python-list
Simple question about freeze
I'm working with the freeze utility, and I'm trying to learn the basics. For the most part, I think I understand how it works. I have a question about modules, though. I want to make sure that my native executable is entirely standalone. That is, it should have no dynamic linking. I've read through a number of posts on the subject, and think I get it. In order to make this work, I need to do two things: (1) Recompile libpythonXXX.a so that the required modules are indeed compiled into the archive. (2) Modify the freeze-generated Makefile to force gcc to use static linking and to use my custom-built libpythonXXX.a in linking together the native executable. My question is: is it sufficient to carry out the above steps? Freeze is designed to use the version of python installed on the host system, *not* a custom build in a different directory. If freeze looks to the system's default installation, but I've modified the makefile to use my custom-built libpython.a, will that cause problems? My sense is that it will not, but I want to make sure I think things through. Any thoughts? Thanks, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Another simple freeze question
Is there a user manual for freeze.py? --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Building python 2.4.2 on Cygwin
Ok, I'm working on building python 2.4.2 on cygwin. I *think* it's version 3.0 or 3.1 (is there a quick way to find out what version of cygwin is running within a shell?) Anyway, it appears to 'configure' fine, but gcc reports a compile error when it gets to posixmodule.c. Here's the first few lines of the error message: == gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -c ./Modules/posixmodule.c -o Modules/posixmodule.o Modules/posixmodule.c:308: warning: function declaration isn't a prototype Modules/posixmodule.c: In function `posix_ttyname': Modules/posixmodule.c:1162: warning: implicit declaration of function `ttyname' Modules/posixmodule.c:1162: warning: assignment makes pointer from integer without a cast Modules/posixmodule.c: In function `posix_mkdir': Modules/posixmodule.c:1791: too many arguments to function `mkdir' == I've researched this a bit, and it sounds like cygwin gets all confused about system includes and so on. Is there a good, comprehensive explanation somewhere of how to make this all work? (Most of the threads I've found are helpful, but not complete unfortunately). Thanks, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Is there a way to build python without 'posixmodule' ?
I'm working on building python 2.4.2 with the mingw compiler (on cygwin). It runs into problems with Modules/posixmodule.c, because the mingw compiler does *not* provide complex process management functionality. I can exclude posixmodule.c from the python build process, but gcc still fails when it tries to link together the python executable: (Error message follows) = gcc -mno-cygwin -Wl,--out-implib=libpython2.4.dll.a -o python.exe \ Modules/python.o \ libpython2.4.a-lm libpython2.4.a(pystate.o)(.text+0x1e0): In function `PyThreadState_New': C:/cygwin/home/Administrator/sgross/sage/installer/python/i386-mingw-gcc/Python-2.4.2/Python/pystate.c:191: undefined reference to `_PyGILState_NoteThreadState' === It would seem that the python executable is looking for the process management functionality that *would* have been supplied by posixmodule.o. Is there a way around this? Can I build the python executable without building posixmodule.o? Thanks, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Is there a way to build python without 'posixmodule' ?
I'm working on building python 2.4.2 with the mingw compiler (on cygwin). It runs into problems with Modules/posixmodule.c, because the mingw compiler does *not* provide complex process management functionality. I can exclude posixmodule.c from the python build process, but gcc still fails when it tries to link together the python executable: (Error message follows) = gcc -mno-cygwin -Wl,--out-implib=libpython2.4.dll.a -o python.exe \ Modules/python.o \ libpython2.4.a-lm libpython2.4.a(pystate.o)(.text+0x1e0): In function `PyThreadState_New': C:/cygwin/home/Administrator/sgross/sage/installer/python/i386-mingw-gcc/Python-2.4.2/Python/pystate.c:191: undefined reference to `_PyGILState_NoteThreadState' === It would seem that the python executable is looking for the process management functionality that *would* have been supplied by posixmodule.o. Is there a way around this? Can I build the python executable without building posixmodule.o? Thanks, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
How to force creation of a .pyc?
I would like to distribute a python program, but only in .pyc form (so that people cannot simply look at my code). Is there a way to do this? I've read up a little on the logic by which python creates .pyc's, and it sounds like python requires the main executed program to be in .py format. Any ideas? Thanks --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Newbie ZSI / syntax question
I'm getting started working with ZSI. I have a client script that looks like this: === import ZSI.client b = ZSI.client.Binding() b.Send('http://...', 'verifyUserRegistered', '00:00:00:00:00:00') === When I run it, I get the following error: === File "./sage_installer.py", line 13, in ? b.Send('http://...', 'verifyUserRegistered', '00:00:00:00:00:00') File "/usr/local/lib/python2.3/site-packages/ZSI/client.py", line 209, in Send self.h.connect() File "/usr/local/lib/python2.3/httplib.py", line 548, in connect raise socket.error, msg socket.error: (2, 'No such file or directory') === I'm trying to make sure I'm calling the Binding.Send() function correctly. Does it look right? Note that I've replaced the actual url (to the php server-side script) with '...' in the above example. Thanks in advance, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
How to detect a double's significant digits
Hi all... How can I find out the number of significant digits (to the right of the decimal place, that is) in a double? At least, I *think* that's what I'm asking for. For instance: 0.103 --> 3 0.0103 --> 4 0.00103 --> 5 0.000103 --> 6 0.103 --> 7 Thanks in advance! --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to detect a double's significant digits
So how can I get the kind of information I want then? For example: 0.103 --> 3 0.0103 --> 4 0.00103 --> 5 0.000103 --> 6 0.103 --> 7 Any ideas? --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: How to detect a double's significant digits
Ok, that won't work. First of all, str() is not a function. If I want to convert the float into a string, the conversion function will have to use some kind of numeric precision, which will screw things up. Consider this: float f = 1.004; ostringstream s; s << f; cout << s.str(); The above code may produce "1.004", or "1.0040", or "1.00400", depending on the stream's precision setting. I need a way to detect the number of digits to the right of decimal point *prior* to doing any kind of string conversion. --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: How to detect a double's significant digits
>But, assuming you have your numbers as strings, I would suggest looking at str.split() and len(). Well, the numbers are in fact stored as numbers, so string processing won't work. >I'd give you an example, but this sounds kinda like a homework assignment. The task may sound like it comes from class, but I can assure you that I am indeed a professional developer. I'm doing some rather intricate text processing / rendering stuff these days, and C++ is unfortunately none too handy for that sort of thing. Unfortunately, I have to use it for the task. Thanks, --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: How to detect a double's significant digits
>This doesn't look like Python to me. Are you sure you're on the right newsgroup? Er, ok, I'm an idiot. This was all supposed to be on comp.lang.c++, but obviously I posted on the wrong one. Sorry for all the hassle. In python, this stuff is a heck of a lot easier. --Steve -- http://mail.python.org/mailman/listinfo/python-list
Can't refer to base class attribute?
I've got a Base class with an attribute "foo" (of type Foo), and a Derived class (derived from Base). In Derived's constructor, I try to refer to Base.foo, but python complains: AttributeError: class Base has no attribute 'foo' Any ideas? (code below) === CODE === #!/usr/bin/python class Foo: def __init__ (self): self.x = 3 class Base: def __init__ (self): self.foo = Foo() class Derived(Base): def __init__(self): Base.__init__(self) Base.foo.x = 5 Derived() === EOF === -- http://mail.python.org/mailman/listinfo/python-list
How to find out which functions exist?
Let's say I have a python file with a base class, and a few derived classes: class Base: pass class Derived1(Base): pass class Derived2(Base): pass Is there a way I can find out the classes that have been derived from Base? Thanks, --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find out which functions exist?
> Take a look at the `issubclass()` function. Ok, I see how to use issubclass(). How can I get a list of classes present in the file? --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find out which functions exist?
> import module > from inspect import getmembers, isclass > classes = getmembers(module, isclass) Ok, this makes sense. How can I do it inside the .py file I'm working on? That is, consider this: class A: pass class B: pass import inspect print inspect.getmembers(, inspect.isclass) # how can I express ? Thanks again, --Steve -- http://mail.python.org/mailman/listinfo/python-list
Easiest way to get exit code from os.popen()?
Hi folks. I'm using os.popen() to run a command; according to the documentation, the filehandle.close() oepration is suppsoed to return the exit code. However, when I execute something like "exit 5", close() returns 1280. Here's the code: pipe = os.popen("exit 5") print pipe.close() # prints 1280 Am I doing something wrong? Is there an easier way to get the exit code? Thanks, --Steve -- http://mail.python.org/mailman/listinfo/python-list
Print a list to a string?
I would like to get the results of a print operation placed in a string. For instance, you can very easily create a list and print it to stdout: x = [1,2,3] print x # Will print [1,2,3] What if I want the text "[1,2,3]" placed in a string? For instance, something like: x = [1,2,3] str = '' print str x # x = '[1,2,3]' Any ideas? Thanks, --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Print a list to a string?
> >>> import cStringIO > >>> s = cStringIO.StringIO() > >>> print >>s, [1, 2, 1.0/5, 'hello world'] > >>> s.getvalue() Thanks--this works perfectly! -_Steve -- http://mail.python.org/mailman/listinfo/python-list
Urllib2 / add_password method
I'm working on learning how to use urllib2 to use a proxy server. I've looked through the postings on this group, and it's been helpful. I have not, however, found complete documentation on the add_password() functions. Here's what I've got so far: # import urllib2 url = 'http://some.server/form.php' proxy_url = 'http://202.62.252.3:8080' # A publicly available anonymous proxy server proxy_handler = urllib2.ProxyHandler( {'http': proxy_url } ) proxy_auth_handler = urllib2.HTTPBasicAuthHandler() proxy_auth_handler.add_password('realm', 'host', 'username', 'password') opener = urllib2.build_opener(proxy_handler, proxy_auth_handler) urllib2.install_opener(opener) try: handler = urllib2.urlopen(url) except urllib2.URLError: print "whoops!" else: print handler.read() #=== It works, but I don't really know what I'm doing with the proxy_auth_handler part. Specifying username and password make sense, but I haven't found documentation on what 'realm' and 'host' are for. Shouldn't username & password be sufficient? Thanks, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Return value of an assignment statement?
Hi all. In C, an assignment statement returns the value assigned. For instance: int x int y = (x = 3) In the above example, (x=3) returns 3, which is assigned to y. In python, as far as I can tell, assignment statements don't return anything: y = (x = 3) The above example generates a SyntaxError. Is this correct? I just want to make sure I've understood the semantics. Thanks, --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Return value of an assignment statement?
> What you can't do (that I really miss) is have a tree of assign-and-test > expressions: > import re > pat = re.compile('some pattern') > if m = pat.match(some_string): > do_something(m) Yep, this is exactly what I am (was) trying to do. Oh well Any clever ideas on this front? --Steve -- http://mail.python.org/mailman/listinfo/python-list
How to manipulate elements of a list in a single line of code?
I would like to translate the contents of a list. For instance, let's say I've got a list of strings and I want to append "foo" to each element. I might do the following; list1 = ['a', 'b', 'c'] for i in range(0, len(list1)): list1[i] += 'foo' Ok, that much works. But what if I don't want to modify the contents of list1. Instead, I want list2 to hold the modified contents, like so: 1 list1 = ['a', 'b', 'c'] 2 list2 = [] 3 for item in list1: list2.append(item + 'foo') Is there a way to express lines 2-3 sort-of ilke this: list2 = [ for item in list1: item + 'foo' ] Any ideas? Thanks, --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: How to manipulate elements of a list in a single line of code?
> Yes, it's called a "list comprehension", and is many people's favourite Awesome! Thanks, --Steve -- http://mail.python.org/mailman/listinfo/python-list
How to turn a list of tuples into a dictionary?
Let's say I've got a list of tuples, like so: ( ('a', '1'), ('b', '2'), ('c', '3') And I want to turn it into a dictionary in which the first value of each tuple is a key and the second value is a value, like so: { 'a' -> '1', 'b' -> '2', 'c' -> '3' } Is there a way to do this with a single line of code? Currently, I'm doing it like this: tuples = ( ('a', '1'), ('b', '2'), ('c', '3') d = {} for option,value in tuples: d[option] = value Thanks, --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: How to turn a list of tuples into a dictionary?
> How about this? > d = dict(tuples) Aha! I hadn't realized it could be so simple. --Steve -- http://mail.python.org/mailman/listinfo/python-list
Instance of inherited nested class in outer class not allowed?
I've got an interesting problem with my class hierarchy. I have an outer class, in which two nested classes are defined: class Outer: class Parent: def __init__ (self): print "parent!" class Child(Parent): def __init__ (self): Outer.Parent.__init__(self) foo = Child() Note that the second nested class (Outer.Child) inherits from the first nested class (Outer.Parent). When I run the above code, python reports a name error: Traceback (most recent call last): File "./temp.py", line 3, in ? class Outer: File "./temp.py", line 13, in Outer foo = Child() File "./temp.py", line 11, in __init__ Outer.Parent.__init__(self) NameError: global name 'Outer' is not defined Apparently, python doesn't like having an instance of a derived nested class present in the outer class. Interestingly enough, if I change the foo variable to an instance of the parent class: foo = Parent() everything is hunky-dory. Is there some syntax rule I'm breaking here? Thanks! --Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of inherited nested class in outer class not allowed?
> class Foo: > foo = Foo() > > You have to live with that. Just do > Outer.foo = Outer.Parent() > after your class-statement to achieve the same result. Hmmm. Well, I see why that works. It's too bad, though. If I want to keep all executed code safely within a "if __name__ == '__main__'" block, it ends up a bit ugly. Then again, I guess this is just an aspect of python I'll have to get used to. Is there a specific reason it works this way, by chance? --Steve -- http://mail.python.org/mailman/listinfo/python-list
Does __import__ require a module to have a .py suffix?
Hi all. I've got a python file called 'foo' (no extension). I want to be able to load it as a module, like so: m = __import__('foo') However, the interpreter tells me "No module named foo". If I rename it foo.py, I can indeed import it. Is the extension required? Is there any way to override that requirement? Thanks, --Steve -- http://mail.python.org/mailman/listinfo/python-list
McMillan installer on solaris - complains about missing .pkg file
I'm trying to get the mcmillan installer utility to generate a standalone executable for me. I've gotten to work--almost!--but still have one problem. After running Installer's Build.py on my script/spec, it appears to work. I go into the directory generating by Build.py and run my program. It works! Then I copy my program (foo) to a different directory and try to run it there. It complains that: "Cannot open self /home/sgross/foo or archive /home/sgross/foo.pkg". Do I have to distribute the .pkg file with the executable? If so, is there a way around this? I want to distribute a single, standalone executable. Thanks, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Embedding a python module in libpython.a
Ok, I'm trying to build libpython.a. It's version 1.5.2 (I know it's an old version, but I need to get it to work if at all possible). I want to find a way to make sure the module copy_reg is present in the libpython.a. I know all about editing the Modules/Setup file to put in additional modules, but there's no pre-existing line in Modules/Setup for copy_reg. The .py itself is in the Lib directory, though. Is there a straight-forward way to do this? Thanks, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list