Re: psycopg2 for insertion of binary data to PostgreSQL database
How can I assign the result of a SQL query to a variable? The following code snippet doesn't work: query_result=cur.execute("SELECT column_name FROM table_name WHERE my_variable = 'my_value'",) > Thomas Jollans wrote: * get the record you're interested in -- http://mail.python.org/mailman/listinfo/python-list
Re: Open a command pipe for reading
Hi Rodrick, On 2010-08-17 18:40, Rodrick Brown wrote: > I have a fairly large file 1-2GB in size that I need to > process line by line but I first need to convert the file > to text using a 3rd party tool that prints the records > also line by line. > > I've tried using Popen to do this with no luck. I'm trying > to simulate > > /bin/foo myfile.dat Is foo the 3rd-party conversion tool you've mentioned? It would be good to have a bit more context, e. g. an actual snippet from your code. > And as the records are being printed do some calculations. > > pipe = Popen(exttool,shell=True,stdout=PIPE).stdout > > for data in pipe.readlines(): > print data, > > This operation blocks forever I'm guessing it's trying to > process the entire file at once. If you use `readlines` on a file object it reads the whole file at once and returns a list of the lines (including line end characters, by the way). What you probably want is for line in pipe: print line, which reads and prints the file contents line by line. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 for insertion of binary data to PostgreSQL database
Julia Jacobson wrote: > How can I assign the result of a SQL query to a variable? > The following code snippet doesn't work: > query_result=cur.execute("SELECT column_name FROM table_name WHERE > my_variable = 'my_value'",) To retrieve an image from a table "images" by its name you could do (untested): name = "image001.jpg" row = cur.execute("select image from images where name = %s", (name,)).fetchone() if row is None: raise ValueError("no image %r found" % name) image = row[0] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Developer - HFT Trading firm - Chicago, IL
In message <8dbb89fi3...@mid.individual.net>, Gregory Ewing wrote: > Lawrence D'Oliveiro wrote: > >> Someone who doesn’t understand how positive feedback can lead to >> instabilities in a dynamical system. > > Let's hope the person they hire makes it his first task > to introduce a big dollop of negative feedback into the > system! Actually the normal way to prevent instabilities is to add damping to leak the energy away. In an economic system, that’s generally called “Government regulation”. -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 for insertion of binary data to PostgreSQL database
On Aug 23, 9:37 am, Julia Jacobson wrote: > How can I assign the result of a SQL query to a variable? > The following code snippet doesn't work: > query_result=cur.execute("SELECT column_name FROM table_name WHERE > my_variable = 'my_value'",) > > > Thomas Jollans wrote: > > > > > * get the record you're interested in You need to go and fetch the data now. query_result.fetchone() Take a look at the docs here, on how to fetch one vs many rows (fetchmany) http://initd.org/psycopg/docs/cursor.html#cursor.fetchone hth, Graeme -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a PYD file
Rony wrote: > Is a PYD file created from Pyrex faster in execution then a PYD file > created from python source ? What do you mean? An African or European swallow? Of course it depends on your choice of algorithm, programmer ability.familarity with the respective langugage, ... cu Philipp -- Dr. Philipp Pagel Lehrstuhl f. Genomorientierte Bioinformatik Technische Universität München http://webclu.bio.wzw.tum.de/~pagel/ -- http://mail.python.org/mailman/listinfo/python-list
Re: vpython
On Aug 22, 7:38 am, Anssi Saari wrote: > kimjeng writes: > > the thing is i have installed gtkglextmm both from source and via a > > slackbuilds package script and i still get the same error, > > help would be a appreciated > > You'll just have to check what it is configure actually tests for and > figure out from that why your system doesn't pass. thanks here's something i noticed ... Package gtkglextmm-1.2 was not found in the pkg-config search path. Perhaps you should add the directory containing `gtkglextmm-1.2.pc' to the PKG_CONFIG_PATH environment variable No package 'gtkglextmm-1.2' found ... the configure script is looking for gtkglextmm-1.2.pc , a file that does not exist, what i do have is gtkglext-1.0.pc , im wondering why i have the 1.0. version while i built the 1.2. source , plus the 'mm' in the name is missing from the name of my .pc files thanks -- http://mail.python.org/mailman/listinfo/python-list
Global Hook for Window Creation and Destruction
hello, I'm looking for a sample using a Global Hook for Window Creation and Destruction in python 2.6 in win32 env... I've found some samples in c# or delphi but nothing in python. I'll try to catch any WM_CREATE events, like pyHook do to catch event from keyboard and mouse... any idea ? thx -- http://mail.python.org/mailman/listinfo/python-list
Gentoo, Cygwin: Import Error time, cStringIO, Permission denied
Hello all, I freshly subscribed to this list, because I search a solution for a very special problem. Is this the appropriate list? Context == I try if it is possible to bootstrap Gentoo Prefix, upon the Cygwin compatibility layer on Windows. Gentoo Prefix is not a virtual machine but a bundle of Gentoo programs compiled into a nonstandard directory on a host OS. IT is similar to Cygwin itself, but compiled from sources. I try to compile Prefix into Cygwin on Windows. This involves compiling python. The gentoo management tool "emerge" is done in python. However I am not a Python programmer myself, so I have some difficulties to understand what is going on. Problem == After compiling pyhton I run into errors when I start to use it in form of emerge. It says something like this in the logger module: Import Error sys, os, types, time, string, cStringIO, traceback. Permission denied. I researched the web. One discssion told to try it on the pyhton shell. I did the same. Only "time" and "cStringIO" are not imported. Looking into the compiled sources i find cStringIO.dll and time.dll. Both have the permissions 755. Hence permission to run them should be given. Is it a path problem? Are environment variables wrong? I would expect in that case python would complain "Modules not found" instead of "Permission denied". I am at the end of my wits now. Al -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a PYD file
Thomas Jollans, 19.08.2010 20:47: On Thursday 19 August 2010, it occurred to Rony to exclaim: Is a PYD file created from Pyrex faster in execution then a PYD file created from python source ? How do you plan to create an extension module (*.so, *.pyd on Windows) from Python source then? You can try to compile it using Cython. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Gentoo, Cygwin: Import Error time, cStringIO, Permission denied
> Problem > == > > After compiling pyhton I run into errors when I start to use it in > form of emerge. It says something like this in the logger module: > > Import Error sys, os, types, time, string, cStringIO, traceback. > Permission denied. > > I researched the web. One discssion told to try it on the pyhton > shell. I did the same. Only "time" and "cStringIO" are not imported. > > Looking into the compiled sources i find cStringIO.dll and time.dll. > Both have the permissions 755. Hence permission to run them should be > given. > I tried something different. I tried to run emerge with Cygwins precompiled python. In this case I get a related but different error: fatal error - unable to map \\?\F:\cygwin\lib\pyhton2.6\lib-dynload\time.dll to same address as parent: 0x33 != 0x3A What does this mean? Is there a naming conflict between pythons time.dll and a time.dll of the windows system? Al -- http://mail.python.org/mailman/listinfo/python-list
Helper classes design question
I want to know the best way to organise a bunch of functions designed to operate on instances of a given class without cluttering the class itself with a bunch of unrelated methods. What I've done is make what I think are called helper classes, each of which are initialized with an instance of the main class and has methods which are all of the same type (insofar as they return a boolean, or modify the object in place, or whatever). I'm not sure if I'm on the right track here design-wise. Maybe this could be better done with inheritance (not my forte), but my first thought is that no, the helper classes (if that's what they are) are not actually a type of the main class, but are auxiliary to it. Here's what I've done: I have a class MySequence which is initialized with a number sequence (in a list), which has a bunch of methods which deal with various (musical) properties of the sequence. Toy example: class MySequence(object): """MySequence, a representation musical sequences as numbers. Its methods return various characteristics of the sequence.""" def __init__(self, sequence): self.pitches = sequence[:] def pcset(self): """Example method: The pitch class set derived from the sequence""" return sorted(list(set([ i % 12 for i in self.pitches]))) A generator function spits out MySequence objects, and I want to filter them (i.e. reject those which do not meet certain criteria) and then be able to modify them in various ways. For that I have two classes; toy examples: class SeqTest(object): """SeqTest, initialized with a MySequence object. Its methods return the boolean result of tests against the Sequence object.""" def __init__(self, myseq_obj): self.seq = myseq_obj def degrees(self, degrees): """Example method: Test for certain members, passed as list""" return all(i in self.seq.pcset() for i in degrees) class SeqMod(object): """A SeqMod object's methods modify in place the MySequence object with which it is initialized """ def __init__(self, myseq_obj): self.seq = myseq_obj def rotate(self, num): """Example method: Rotate pitches by n steps""" self.seq.pitches = self.seq.pitches[-num:] + self.seq.pitches[:-num] And here is a toy version of how I'm using them with the generator: def seq_factory(generator_func, test_opts, mod_opts): """Yields Sequence objects, filtered and modified. Opts are dictionaries.""" for sequence in generator_func: seq = MySequence(sequence) tester = SeqTest(seq) if any (not getattr(tester, opt)(value) for opt, value in test_opts.items()): continue modifier = SeqMod(seq) for opt, value in mod_opts.items(): getattr(modifier, opt)(value) yield seq Used, say, like this: generator_func = (range(n, n+5) for n in range(5)) test_opts = {'degrees': [5,7]} mod_opts = {'rotate': 3} for i in seq_factory(generator_func, test_opts, mod_opts): print i.pitches Which yields: [5, 6, 7, 3, 4] [6, 7, 8, 4, 5] It actually works well, so there's no real problem apart from wanting to know if this is a good way to do what I want. Thanks for any wise words, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a PYD file
Rony, 19.08.2010 21:41: The question actually is, is a PYD file created from C faster then a PYD file from Pyrex ? Most likely, yes. However, when comparing to Cython instead of Pyrex, the answer really depends on your code. Cython cannot be faster than the equivalent C code, simply because it generates C code. However, if the Python call overhead matters (e.g. in thin wrappers around simple C functions), Cython easily wins because it uses various tweaks that you simply wouldn't write in your own C code. If the overhead can be ignored, hand tuned C code wins often but not always, with the obvious drawback of being much harder to write and much longer in lines of code. Generally speaking, if you can avoid it, don't write the extension in C. You'll have your Cython code hand optimised long before your C code is even close to running. And in the long run, the maintenance cost will always be the dominating factor anyway. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Helper classes design question
John O'Hagan wrote: > I want to know the best way to organise a bunch of functions designed to > operate on instances of a given class without cluttering the class itself > with a bunch of unrelated methods. > > What I've done is make what I think are called helper classes, each of > which are initialized with an instance of the main class and has methods > which are all of the same type (insofar as they return a boolean, or > modify the object in place, or whatever). > > I'm not sure if I'm on the right track here design-wise. Maybe this could > be better done with inheritance (not my forte), but my first thought is > that no, the helper classes (if that's what they are) are not actually a > type of the main class, but are auxiliary to it. > > Here's what I've done: > > I have a class MySequence which is initialized with a number sequence (in > a list), which has a bunch of methods which deal with various (musical) > properties of the sequence. Toy example: > > class MySequence(object): > """MySequence, a representation musical sequences as numbers. > Its methods return various characteristics of the sequence.""" > def __init__(self, sequence): > self.pitches = sequence[:] > def pcset(self): > """Example method: The pitch class set > derived from the sequence""" > return sorted(list(set([ i % 12 for i in self.pitches]))) > > A generator function spits out MySequence objects, and I want to filter > them (i.e. reject those which do not meet certain criteria) and then be > able to modify them in various ways. For that I have two classes; toy > examples: > > class SeqTest(object): > """SeqTest, initialized with a MySequence object. Its methods > return the boolean result of tests against the Sequence object.""" > def __init__(self, myseq_obj): > self.seq = myseq_obj > def degrees(self, degrees): > """Example method: Test for certain members, passed as list""" > return all(i in self.seq.pcset() for i in degrees) > > class SeqMod(object): > """A SeqMod object's methods modify in place > the MySequence object with which it is initialized """ > def __init__(self, myseq_obj): > self.seq = myseq_obj > def rotate(self, num): > """Example method: Rotate pitches by n steps""" > self.seq.pitches = self.seq.pitches[-num:] + > self.seq.pitches[:-num] > > > And here is a toy version of how I'm using them with the generator: > > def seq_factory(generator_func, test_opts, mod_opts): > """Yields Sequence objects, filtered and modified. > Opts are dictionaries.""" > for sequence in generator_func: > seq = MySequence(sequence) > tester = SeqTest(seq) > if any (not getattr(tester, opt)(value) > for opt, value in test_opts.items()): > continue > modifier = SeqMod(seq) > for opt, value in mod_opts.items(): > getattr(modifier, opt)(value) > yield seq > > > Used, say, like this: > > generator_func = (range(n, n+5) for n in range(5)) > test_opts = {'degrees': [5,7]} > mod_opts = {'rotate': 3} > > for i in seq_factory(generator_func, test_opts, mod_opts): > print i.pitches > > Which yields: > > [5, 6, 7, 3, 4] > [6, 7, 8, 4, 5] > > It actually works well, so there's no real problem apart from wanting to > know if this is a good way to do what I want. > > Thanks for any wise words, As far as I can see the SeqMod and SeqTest classes don't keep any state apart from the sequence instance. Therefore functions instead of methods would do as well: from functools import partial class MySequence(object): def __init__(self, sequence): self.pitches = sequence[:] def pcset(self): return sorted(list(set([ i % 12 for i in self.pitches]))) def degrees(seq, degrees): return all(i in seq.pcset() for i in degrees) def rotate(seq, num): seq.pitches = seq.pitches[-num:] + seq.pitches[:-num] def seq_factory(sequences, tests, modifications): for seq in sequences: if all(test(seq) for test in tests): for modify in modifications: modify(seq) yield seq sequences = (MySequence(range(n, n+5)) for n in range(5)) tests = [ partial(degrees, degrees=[5,7]), # ... ] modifications = [ partial(rotate, num=3), # ... ] for i in seq_factory(sequences, tests, modifications): print i.pitches When you see that your module becomes too messy move the testing and modifying functions into separate modules that are part of the same package. Peter -- http://mail.python.org/mailman/listinfo/python-list
SOLVED: Gentoo, Cygwin: Import Error time, cStringIO, Permission denied
I seem to talk to myself. So for the archives: This is no python thingy. It is a windows/cygwin one. The second error message brings good search results in the web. Search for: "cygwin, dll to same address as parent, rebaseall" Al -- http://mail.python.org/mailman/listinfo/python-list
DDE Module for Python 3.1.2
Hi Members, I am learning python 3.1.2 on windows XP. I wanted to do experiments on importing real time data from QuoteCenter with DDE. After searching relevant module, I found dde module only for Python 2.6, but not for 3.1.2. Kindly guide me if there is any other way I can communicate with DDE server for requesting data with Python 3.X. Thanks and Regards madhusoodan -- http://mail.python.org/mailman/listinfo/python-list
import a module in a destructor of a class
Dear All, I have a python module named "book.py" I want to import it in a destructor of a class. class Excel: def __init__( self, ... ): . . . def __del__( self ): import book but I got error. Would you please help me? Can I import a module in a destructor? Thank you in advance. Regards, Navid -- http://mail.python.org/mailman/listinfo/python-list
Re: DDE Module for Python 3.1.2
Madhusoodan, 23.08.2010 13:50: I am learning python 3.1.2 on windows XP. I wanted to do experiments on importing real time data from QuoteCenter with DDE. What's DDE here? After searching relevant module, I found dde module only for Python 2.6, but not for 3.1.2. Could you provide a link to the module, so that we know what module you are actually talking about? Also, if the project that provides the module has a mailing list, you might want to ask there. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: DDE Module for Python 3.1.2
On 23/08/2010 13:02, Stefan Behnel wrote: Madhusoodan, 23.08.2010 13:50: I am learning python 3.1.2 on windows XP. I wanted to do experiments on importing real time data from QuoteCenter with DDE. What's DDE here? It'll be Microsoft's Dynamic Data Exchange : http://msdn.microsoft.com/en-us/library/ms648711%28VS.85%29.aspx Didn't know anyone was still using it explicitly. After searching relevant module, I found dde module only for Python 2.6, but not for 3.1.2. Could you provide a link to the module, so that we know what module you are actually talking about? I expect that'll be the dde module in the pywin32 packages: http://pywin32.cvs.sourceforge.net/viewvc/pywin32/pywin32/win32/Demos/dde/ I haven't run any tests against it, but it imports ok on my 3.1.2 instance (albeit after importing win32ui) TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: import a module in a destructor of a class
On Mon, Aug 23, 2010 at 5:00 AM, Navid Parvini wrote: > Dear All, > > I have a python module named "book.py" I want to import it in a destructor of > a class. > > class Excel: > > def __init__( self, ... ): > . . . > > def __del__( self ): > import book > > but I got error. And the exact error message and exception traceback were...? Cheers, Chris -- Vagueness makes questions harder to answer. http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: import a module in a destructor of a class
Navid Parvini wrote: > I have a python module named "book.py" I want to import it in a destructor > of a class. Why would you do that? > class Excel: > > def __init__( self, ... ): > . . . > > def __del__( self ): > import book > > but I got error. Would you please help me? Can I import a module in a > destructor? > > Thank you in advance. You may be able to avoid the ImportError by moving the instance from the global scope into a function, e. g. instead of e = Excel() # work with e do def main(): e = Excel() # work with e main() but the more appropriate answer is likely: Don't use __del__() at all. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Sphinx cross reference question
Laszlo Nagy wrote: In my shopzeus.db.pivot.convert.py file, in the run() method of my Data2Facts class, I can write this into the docstring: ...you may have more joy asking about this on the Sphinx list: http://groups.google.com/group/sphinx-dev cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
nested subparsers with argparse
Hi All, I'm looking to build a script that has command line options as follows: ./myscript.py command subcommand [options] I can do up to the command [options] bit with add_subparsers in argparse, but how do I then add a second level of subparsers? cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an appropriate encoding standard that supports all languages
On Aug 20, 10:04 pm, Thomas Jollans wrote: > On Thursday 19 August 2010, it occurred to ata.jaf to exclaim: > > > > > On Aug 17, 11:55 pm, Thomas Jollans wrote: > > > On Tuesday 17 August 2010, it occurred to ata.jaf to exclaim: > > > > I am developing a little program in Mac with wxPython. > > > > But I have problems with the characters that are not in ASCII. Like > > > > some special characters in French or Turkish. > > > > So I am looking for a way to solve this. Like an encoding standard > > > > that supports all languages. Or some other way. > > > > Anything that supports all of Unicode will do. Like UTF-8. If your text > > > is mostly Latin, then just go for UTF-8, if you use other alphabets > > > extensively, you might want to consider UTF-16, which might the use a > > > little less space. > > > OK, I used UTF-8. > > I write a line of strings in the source code and I want my program to > > show that as an output on GUI. And this line of strings includes a > > character like "ü". But I see that in GUI this character is replaced > > with another strange characters. I mean it doesn't work. > > And when I try to use UTF-16, I get an syntax error that declares > > "UTF-16 stream does not start with BOM". > > I get the feeling you're not actually using the encoding you say you're using, > or not telling every program involved what you're doing. > > 1. Save the file in the correct encoding. Either tell your text editor to use > a specific encoding (UTF-8 would be a good choice), or find out what encoding > your text editor is using and use that encoding during the rest of the > process. > > 2. Tell Python which encoding you're using. The coding: line will do the > trick, *provided* you don't lie, and the encoding your specify in the file is > actually the encoding you're using to store the file on disk. > > 3. Instruct your GUI library to do the right thing. If you use unicode strings > (either by using Python 3 or by using the u"Käse" syntax in Python 2), that > should be enough, otherwise, if you're using byte strings, which you shouldn't > be doing in this case, you might have to tell the library what you're doing, > or use the customary encoding. (For GTK+, this is UTF-8. For other libraries, > it might be Latin-1, or system-dependent) Finally I did it. I was doing some stupid mistakes. Thanks alot. Ata -- http://mail.python.org/mailman/listinfo/python-list
IDLE will not startup after upgrading Python on Mac OS X
I have snow leopard and a brand new mac book pro. After running python from x11, I saw that I had python 2.5.1 installed on this laptop, so went to python.org to download Python 2.7, as I was "strongly encouraged" to do on the website. The problem is that Mac doesn't come with a text editor for writing programs. TextEdit won't allow you to save files with the ".py" extension. So IDLE is really my only choice. The only problem is, whenever I start it up (I've tried starting it from the Terminal and double clicking the icon) I get the following message: "Idle's subprocess cannot make connection. Either Idle can't start a subprocess or a personal firewall is blocking the connection." Searching various programming forums came up with similar problems users have had in windows, but I couldn't find any information on how to fix this problem on a mac with OSX. Please help. Thanks, Fred -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading the access attributes of directories in Windows
On Aug 21, 8:10 am, Tim Golden wrote: > On 20/08/2010 11:54 PM, vsoler wrote: > > > I'am testing your library. I am mainly interested in knowing the > > access attributes of directories in the local(C:\) or shared unit(W:\) > > of my system. > > > Using your script with 'c:\\' I get an error message saying... 'file > > exists but it is a directory' and I cannot go any further. > > > Of course, the problem is that I am using "fs.file" when I should be > > using something different. > > Either use fs.dir (if you know it's a directory) or fs.entry (if it > could be a file or a directory; the code will dispatch to the right one). > > If you only want the directories immediately some directory, > you could do this: > > > from winsys import fs, security > > root = fs.file (sys.executable).path # or fs.dir ("w:/") etc. > for d in root.dirs (ignore_access_errors=True): > print (d, "=>", d.security ()) # or whatever > > > > If you want to walk the tree of directories looking at permissions, then: > > > import os, sys > from winsys import fs > > root = fs.file (sys.executable).path > for dirpath, _, _ in root.walk (): > print (dirpath, "=>", dirpath.security ()) > > > > > Reading the doc I have found that I should be using os.walk(...), > > which works, but then I cannot use fs.file > > In fact, even if you did for some reason use os.walk, you can > easily wrap the returned filenames using fs.entry: > > > import os, sys > from winsys import fs > > root = os.path.dirname (sys.executable) > for dirpath, filenames, dirnames in os.walk (root): > print (dirpath, "=>", fs.entry (dirpath).security ()) > > > > TKG Tim, One of your scripts still does not work on my system: ==> If you want to walk the tree of directories looking at permissions, then: import os, sys from winsys import fs root = fs.file (sys.executable).path for dirpath, _, _ in root.walk (): print (dirpath, "=>", dirpath.security ()) However, I get the following error: Traceback (most recent call last): File "C:/Local/test4.py", line 5, in root = fs.file (r'W:\FRIB\ELPR\$DATA\DPT-FINANZAS').path File "C:\Program Files\Python31\lib\site-packages\winsys\fs.py", line 1775, in file raise x_fs (None, "file", "%s exists but is a directory" % filepath) winsys.fs.x_fs: (None, 'file', 'W:\\FRIB\\ELPR\\$DATA\\DPT-FINANZAS exists but is a directory') That is, I am interested in looking for directories, but the problem is that the path is a directory. I'm sure there must be some way to get around this problem. Thank you Vicente Soler -- http://mail.python.org/mailman/listinfo/python-list
problem with simple multiprocessing script on OS X
The following script runs without problems on Ubuntu and Windows 7. h5py is a package wrapping the hdf5 library (http://code.google.com/p/ h5py/): from multiprocessing import Pool import h5py def update(i): print i def f(i): "hello foo" return i*i if __name__ == '__main__': pool = Pool() for i in range(10): pool.apply_async(f, [i], callback=update) pool.close() pool.join() On OS X 10.6 (tested using python-2.6.5 from MacPorts), I have to comment out the as-yet unused h5py import, otherwise I get a traceback: Exception in thread Thread-1: Traceback (most recent call last): File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/threading.py", line 532, in __bootstrap_inner self.run() File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/threading.py", line 484, in run self.__target(*self.__args, **self.__kwargs) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/multiprocessing/pool.py", line 226, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.function failed I've searched that pickle error and found some references to pickling a lambda, but I don't think that is the issue. There are no lambdas in the h5py module, and the script runs fine on windows and linux. I need access to both multiprocessing and h5py objects in the same module, so I can register a callback that saves the results to an hdf5 file. Are there any suggestions as to what could be the problem, or suggestions on how I can track it down? Thanks, Darren -- http://mail.python.org/mailman/listinfo/python-list
comp.lang.python
www.127760.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE will not startup after upgrading Python on Mac OS X
On Mon, Aug 23, 2010 at 9:45 AM, Frederick Manley wrote: > I have snow leopard and a brand new mac book pro. After running python from > x11, I saw that I had python 2.5.1 installed on this laptop, That should be 2.6.1 if you're on Snow Leopard. Also, why were you running Python from an xterm? Just use Terminal.app. > so went to > python.org to download Python 2.7, as I was "strongly encouraged" to do on > the website. > The problem is that Mac doesn't come with a text editor for writing > programs. TextEdit won't allow you to save files with the ".py" extension. Yes it will. You just have to turn it to plain text mode first. It's in the format menu. Then, just add the .py extension to the file name when you go to save it. You'll get an annoying little "do you want to use .py or .txt" message box. > So IDLE is really my only choice. Vim and emacs are both installed on the machine. Or you can install MacVim. Or whatever GUI version of Emacs there is. Or you can install TextMate if you don't want to learn those. Or you can install XCode or Eclipse+PyDev if you want an IDE. Or Eric or Komodo Edit. Or any of a dozen others. >The only problem is, whenever I start it > up (I've tried starting it from the Terminal and double clicking the icon) I > get the following message: > "Idle's subprocess cannot make connection. Either Idle can't start a > subprocess or a personal firewall is blocking the connection." > Searching various programming forums came up with similar problems users > have had in windows, but I couldn't find any information on how to fix this > problem on a mac with OSX. Please help. >From the title, this may be relevant, but I'm not sure because I'm having trouble accessing the bug tracker right now. http://bugs.python.org/issue9227 Also, this one: http://bugs.python.org/issue9620 > Thanks, > Fred > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading the access attributes of directories in Windows
On 23/08/2010 14:55, vsoler wrote: On Aug 21, 8:10 am, Tim Golden wrote: On 20/08/2010 11:54 PM, vsoler wrote: I'am testing your library. I am mainly interested in knowing the access attributes of directories in the local(C:\) or shared unit(W:\) of my system. Using your script with 'c:\\' I get an error message saying... 'file exists but it is a directory' and I cannot go any further. Of course, the problem is that I am using "fs.file" when I should be using something different. Either use fs.dir (if you know it's a directory) or fs.entry (if it could be a file or a directory; the code will dispatch to the right one). If you only want the directories immediately some directory, you could do this: from winsys import fs, security root = fs.file (sys.executable).path # or fs.dir ("w:/") etc. for d in root.dirs (ignore_access_errors=True): print (d, "=>", d.security ()) # or whatever If you want to walk the tree of directories looking at permissions, then: import os, sys from winsys import fs root = fs.file (sys.executable).path for dirpath, _, _ in root.walk (): print (dirpath, "=>", dirpath.security ()) Reading the doc I have found that I should be using os.walk(...), which works, but then I cannot use fs.file In fact, even if you did for some reason use os.walk, you can easily wrap the returned filenames using fs.entry: import os, sys from winsys import fs root = os.path.dirname (sys.executable) for dirpath, filenames, dirnames in os.walk (root): print (dirpath, "=>", fs.entry (dirpath).security ()) TKG Tim, One of your scripts still does not work on my system: ==> If you want to walk the tree of directories looking at permissions, then: import os, sys from winsys import fs root = fs.file (sys.executable).path for dirpath, _, _ in root.walk (): print (dirpath, "=>", dirpath.security ()) However, I get the following error: Traceback (most recent call last): File "C:/Local/test4.py", line 5, in root = fs.file (r'W:\FRIB\ELPR\$DATA\DPT-FINANZAS').path File "C:\Program Files\Python31\lib\site-packages\winsys\fs.py", line 1775, in file raise x_fs (None, "file", "%s exists but is a directory" % filepath) winsys.fs.x_fs: (None, 'file', 'W:\\FRIB\\ELPR\\$DATA\\DPT-FINANZAS exists but is a directory') That is, I am interested in looking for directories, but the problem is that the path is a directory. I'm sure there must be some way to get around this problem. Replace fs.file by fs.entry: the latter detects automatically whether it's looking at a file or at a directory. I used fs.file in my example because I *know&* what sys.executable must be a file (python.exe). In your case, either use fs.dir if you know it's a directory or fs.entry if it could be either. (Obviously fs.entry must do some work to determine which it is, so you can optimise slightly by specifying fs.dir / fs.file) TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: nested subparsers with argparse
Chris Withers wrote: Hi All, I'm looking to build a script that has command line options as follows: ./myscript.py command subcommand [options] I can do up to the command [options] bit with add_subparsers in argparse, but how do I then add a second level of subparsers? Answering my own question, here's what worked for me: """ from argparse import ArgumentParser from mock import Mock m = Mock() parser = ArgumentParser() subparsers = parser.add_subparsers() agroup = subparsers.add_parser('a') command = subparsers.add_parser('b') command.set_defaults(func=m.b) subparsers = agroup.add_subparsers() command = subparsers.add_parser('aa') command.set_defaults(func=m.a.a) command = subparsers.add_parser('ab') command.set_defaults(func=m.a.b) options = parser.parse_args() options.func(options) print m.method_calls """ If there's anything I could have done better, please let me know! Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: nested subparsers with argparse
Chris Withers wrote: > I'm looking to build a script that has command line options as follows: > > ./myscript.py command subcommand [options] > > I can do up to the command [options] bit with add_subparsers in > argparse, but how do I then add a second level of subparsers? It looks like subparsers behave like the toplevel parsers -- you can invoke add_subparsers() on them, too. -- http://mail.python.org/mailman/listinfo/python-list
Re: vpython
kimjeng writes: > On Aug 22, 7:38 am, Anssi Saari wrote: >> kimjeng writes: >> > the thing is i have installed gtkglextmm both from source and via a >> > slackbuilds package script and i still get the same error, >> > help would be a appreciated >> >> You'll just have to check what it is configure actually tests for and >> figure out from that why your system doesn't pass. > > thanks > here's something i noticed > > ... > Package gtkglextmm-1.2 was not found in the pkg-config search path. > Perhaps you should add the directory containing `gtkglextmm-1.2.pc' > to the PKG_CONFIG_PATH environment variable > No package 'gtkglextmm-1.2' found > ... > > the configure script is looking for gtkglextmm-1.2.pc , a file that > does not exist, what i do have is gtkglext-1.0.pc , im wondering why > i have the 1.0. version while i built the 1.2. source , plus the 'mm' > in the name is missing from the name of my .pc files > thanks The mm in the name is for a C++ binding for the library. Make sure you install both gtkglext and gtkglextmm packages. -- Burton -- http://mail.python.org/mailman/listinfo/python-list
Re: Using String Methods In Jump Tables
On 20 Aug, 01:51, Tim Daneliuk wrote: > On 8/19/2010 7:23 PM, Steven D'Aprano wrote: > > > On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: > > >> Problem: > > >> Given tuples in the form (key, string), use 'key' to determine what > >> string method to apply to the string: > > table = {'l': str.lower, 'u': str.upper} > table['u']('hello world') > > 'HELLO WORLD' > > Aha! That's just what I was looking for. > > > > > [...] > >> As I said, I know I could do this as a set of cascading ifs or even as > >> an eval, but I'm loathe to use such approaches. I like jump tables as a > >> structural construct because they are easy to understand and maintain. I > >> also realize that what I'm asking may be violating some deeply held > >> notion of OO purity, but, well, now I'm just curious if there is a way > >> to do this > > > This is Python, not some "pure" OO language. We have functional > > programming constructs, procedural constructs, and probably other > > programming models as well. Screw the deeply held notion of OO purity :) > > Yeah, I've never been much impressed with the OO purists. One of > the best speeches on the subject I ever saw was by David Korn (of > ksh fame) who did a presentation at USENIX one year called "Objecting > To Objects". He documented an attempt to write a compiler using > purely OO constructs and the many rings of hell that ensued. > > > > > But seriously, Python's object model includes bound and unbound methods > > precisely so you can do this sort of thing, and the above table-based > > approach is very common and recommended as an alternative to case/switch > > statements. It's a very common Pythonic idiom, so never fear that people > > will stone you for using it. > > +1 > > > > > The only thing that is a bit unusual is that you call it a jump table. In > > my experience, "Jump Table" is used for low-level languages where the > > table values are memory addresses. > > Yeah ... those old assembler memories never quite fade do they. > I dunno what you might call this. A Function Dispatch Table > perhaps? > > Thanks to both you and Chris for setting me straight :) > > -- > > Tim Daneliuk > tun...@tundraware.com Another more generic option would be to use methodcaller from the operator module. Just my 2p, Jon. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using String Methods In Jump Tables
On 8/23/2010 10:35 AM, Jon Clements wrote: > On 20 Aug, 01:51, Tim Daneliuk wrote: >> On 8/19/2010 7:23 PM, Steven D'Aprano wrote: >> >>> On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: >> Problem: >> Given tuples in the form (key, string), use 'key' to determine what string method to apply to the string: >> >> table = {'l': str.lower, 'u': str.upper} >> table['u']('hello world') >>> 'HELLO WORLD' >> >> Aha! That's just what I was looking for. >> >> >> >>> [...] As I said, I know I could do this as a set of cascading ifs or even as an eval, but I'm loathe to use such approaches. I like jump tables as a structural construct because they are easy to understand and maintain. I also realize that what I'm asking may be violating some deeply held notion of OO purity, but, well, now I'm just curious if there is a way to do this >> >>> This is Python, not some "pure" OO language. We have functional >>> programming constructs, procedural constructs, and probably other >>> programming models as well. Screw the deeply held notion of OO purity :) >> >> Yeah, I've never been much impressed with the OO purists. One of >> the best speeches on the subject I ever saw was by David Korn (of >> ksh fame) who did a presentation at USENIX one year called "Objecting >> To Objects". He documented an attempt to write a compiler using >> purely OO constructs and the many rings of hell that ensued. >> >> >> >>> But seriously, Python's object model includes bound and unbound methods >>> precisely so you can do this sort of thing, and the above table-based >>> approach is very common and recommended as an alternative to case/switch >>> statements. It's a very common Pythonic idiom, so never fear that people >>> will stone you for using it. >> >> +1 >> >> >> >>> The only thing that is a bit unusual is that you call it a jump table. In >>> my experience, "Jump Table" is used for low-level languages where the >>> table values are memory addresses. >> >> Yeah ... those old assembler memories never quite fade do they. >> I dunno what you might call this. A Function Dispatch Table >> perhaps? >> >> Thanks to both you and Chris for setting me straight :) >> >> -- >> >> Tim Daneliuk >> tun...@tundraware.com > > Another more generic option would be to use methodcaller from the > operator module. > > Just my 2p, > > Jon. Could you say a bit more about just why you prefer this approach? Clearly, it *is* more generic, but in looking it over, it seems that methodcaller is less readable and intuitive ... at least to my eyes ... -- Tim Daneliuk tun...@tundraware.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a class method?
Em 23-08-2010 06:16, Ian Kelly escreveu: > On Sun, Aug 22, 2010 at 9:53 PM, Paulo da Silva > wrote: >> Em 23-08-2010 04:30, James Mills escreveu: >>> On Mon, Aug 23, 2010 at 12:49 PM, Paulo da Silva >>> wrote: I understand the concept of a static method. However I don't know what is a class method. Would anybody pls. explain me? >>> >>> Please read this first: >>> http://docs.python.org/library/functions.html#classmethod >>> >>> Then ask us questions :) >> >> I did it before posting ... >> The "explanation" is not very clear. It is more like "how to use it". > > Consider this: > > class A(object): > @staticmethod > def new(): > return A() > > class B(A): > pass > > versus this: > > class C(object): > @classmethod > def new(cls): > return cls() > > class D(C): > pass > > B.new() will return a new instance of A, not B. D.new() will return a > new instance of D. > > Does this answer your question? Yes. Thank you very much. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a class method?
John, I agree with you and I also think the definition given on the official python site is somewhat confusing, at least for an engineer like myself. But I'll take a stab at explaning it using what I know thus far. I think to understand what a class method is you have to first understand what a class variable is. Take this code snippet for example. class foo(object): x=10 def __init__(self): self.x=20 In this example if you create an instance of foo and call it f. You can access the instance attribute x by using f.x or you can access the class variable using the notation foo.x. These two will give you two different results. Now lets do something a bit more interesting. Say you have the following snippet. class foo(object): x=0 def __init__(self): self.x=10 foo.x+=1 >>>f=foo() >>>g=goo() >>>f.x 10 >>>g.x 10 >>>foo.x 2 What happened here is that the class variable foo.x is used to keep a count of the total number of instances created. So we see that a class variable can be looked at as what "connects" the two instances in a way, so that data can be shared between instances of the same class. This defintion may very well only apply to this case, but I think the mechanics is fundamentally the same. Keeping this in mind, lets make the jump to class methods. When an instance of a class is created, the methods are just functions that "work on" the attributes (the variables). Similarly, a class method is a method that works on a class variable. For example, class foo(object): x=10 def __init__(self): self.x=20 @classmethod def change(self): self.x=15 >>>f=foo() >>>f.x 20 >>>foo.x 10 >>>f.change() >>>f.x 20 >>>foo.x 15 So this is my explanation for what a classmethod is. Hope it helps. Good luck. Denis On Mon, Aug 23, 2010 at 2:24 AM, John Nagle wrote: > On 8/22/2010 9:16 PM, James Mills wrote: > >> On Mon, Aug 23, 2010 at 1:53 PM, Paulo da Silva >> >> wrote: >> >>> I did it before posting ... >>> >>> The "explanation" is not very clear. It is more like "how to use it". >>> >> >> Without going into the semantics of languages basically the >> differences are quite clear: >> >> @classmethod is a decorator that warps a function with >> passes the class as it's first argument. >> >> @staticmethod (much like C++/Java) is also a decorator that >> wraps a function but does not pass a class or instance as >> it's first argument. >> > >That reads like something the C++ standards revision committee > would dream up as they add unnecessary template gimmicks to the > language. > >John Nagle > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE will not startup after upgrading Python on Mac OS X
On 8/23/2010 10:05 AM, Benjamin Kaplan wrote: From the title, this may be relevant, but I'm not sure because I'm having trouble accessing the bug tracker right now. http://bugs.python.org/issue9227 Also, this one: http://bugs.python.org/issue9620 Tracker is still down (site maintainers have been informed). I believe one of those may have helpful info when it is back up. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Helper classes design question
On Monday 23 August 2010, it occurred to John O'Hagan to exclaim: > I want to know the best way to organise a bunch of functions designed to > operate on instances of a given class without cluttering the class itself > with a bunch of unrelated methods. > > What I've done is make what I think are called helper classes, each of > which are initialized with an instance of the main class and has methods > which are all of the same type (insofar as they return a boolean, or > modify the object in place, or whatever). > > I'm not sure if I'm on the right track here design-wise. Maybe this could > be better done with inheritance (not my forte), but my first thought is > that no, the helper classes (if that's what they are) are not actually a > type of the main class, but are auxiliary to it. You could try using mixins. I don't know how well this fits with the problem at hand, but what you'd do is this: Instead of thinking of the bits you're writing as helper classes, think of them as more or less isolated pieces of the functionality you'd like the final object to have. You can implement these independently, operating on self instead of on self.seq or something like that. Have a look at the abc module (abstract base classes) for a nifty way to prevent instantiation of these classes. If the functionality you're implementing only makes sense for a sequence, or for a sequence with certain characteristics, you can define an ABC that represents/specifies those characteristics and inherit from that. Or maybe not. Then, you have a bunch of largely independent classes providing isolated pieces of functionality, which you can then combine into one class by inheriting from ALL of them, and implementing the missing methods, like a constructor. Let's draw a graph: MySuperDuperCoolSequenceThing / / \ \ Filtered RotatedTap\ \/ / \ | AbstractSequenceKitchenSink \ / object I hope you understood at least a bit of my ramblings. Cheers, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Discarding STDERR generated during subprocess.popen
Hi, I would like to run an external program, and discard anything written to stderr during its execution, capturing only stdout. My code currently looks like: def blaheta_tag(filename): blaheta_dir = '/home/leon/signal_annotation/parsers/blaheta/' process = subprocess.Popen([blaheta_dir + 'exec/funcTag', blaheta_dir + 'data/', filename], cwd=blaheta_dir, stdout=subprocess.PIPE) process.wait() return process.communicate()[0] This returns stdout, and stderr ends up printing to the console. How can I disregard anything sent to stderr such that it doesn't appear on the console? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Using String Methods In Jump Tables
On 8/23/2010 11:57 AM, Tim Daneliuk wrote: On 8/23/2010 10:35 AM, Jon Clements wrote: Another more generic option would be to use methodcaller from the operator module. Could you say a bit more about just why you prefer this approach? Clearly, it *is* more generic, but in looking it over, it seems that methodcaller is less readable and intuitive ... at least to my eyes ... He did not say 'preferable', only more generic, as you agree, and the generic solution, buried away in operator, is a good thing to know about. The OP wanted to convert (methodname, string) pairs to a call of methodname on strings. Since there is only one class, str, involved, mapping methodname to str.methodname works. If, for instance, the OP instead had to map (methodname, bytes_or_string) to a call, a not unreasonable generalization, str.methodname does not work (with bytes) but methodcaller(methodname) will, with bytes or string. >>> methodcaller('upper')(b'abc') b'ABC' >>> methodcaller('upper')('abc') 'ABC' -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: make install DESTDIR
Thanks for reply Thomas. I am running make install DESTDIR=/home/foo/ bar. Martin- Asking for help :) On Aug 21, 4:43 am, "Martin v. Loewis" wrote: > > The whole point of DESTDIR is that it should be prepended to all > > installed paths, but the binaries should not contain any references to > > it.DESTDIR is commonly used by packagers, for example, to allow > > installation without superuser privileges. > > So what is the point of your messages? Do you want to report a problem? > Are you asking for help? Do you want to vent frustration? > > Regards, > Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Discarding STDERR generated during subprocess.popen
On Monday 23 August 2010, it occurred to Leon Derczynski to exclaim: > Hi, > > I would like to run an external program, and discard anything written > to stderr during its execution, capturing only stdout. My code > currently looks like: > > def blaheta_tag(filename): > blaheta_dir = '/home/leon/signal_annotation/parsers/blaheta/' > process = subprocess.Popen([blaheta_dir + 'exec/funcTag', > blaheta_dir + 'data/', filename], cwd=blaheta_dir, > stdout=subprocess.PIPE) > process.wait() > return process.communicate()[0] > > This returns stdout, and stderr ends up printing to the console. How > can I disregard anything sent to stderr such that it doesn't appear on > the console? Read it into a pipe as well, and then ignore. Or, if you're targeting only UNIX-like systems, open /dev/null for writing and redirect the output there. -- http://mail.python.org/mailman/listinfo/python-list
Save/load like matlab?
I wonder if there is a way to save and load all python variables just like matlab does, so I can build a code step by step by loading previous states. I am handling a python processing code for very large files and multiple processing steps. Each time I find a bug, I have to run the whole thing again, which is time consuming. Thank you, Sang-Ho -- http://mail.python.org/mailman/listinfo/python-list
Re: Discarding STDERR generated during subprocess.popen
On Tue, Aug 24, 2010 at 4:38 AM, Leon Derczynski wrote: > Hi, > > I would like to run an external program, and discard anything written > to stderr during its execution, capturing only stdout. My code > currently looks like: > > def blaheta_tag(filename): >blaheta_dir = '/home/leon/signal_annotation/parsers/blaheta/' >process = subprocess.Popen([blaheta_dir + 'exec/funcTag', > blaheta_dir + 'data/', filename], cwd=blaheta_dir, > stdout=subprocess.PIPE) >process.wait() >return process.communicate()[0] > > This returns stdout, and stderr ends up printing to the console. How > can I disregard anything sent to stderr such that it doesn't appear on > the console? > Just add `stderr=subprocess.PIPE` keyword in the Popen call. -- With best regards, Daniel Kluev -- http://mail.python.org/mailman/listinfo/python-list
Replace multiple lines in a txt file.
Hi everybody, I would like to know if its possible to modify a list of entry that is define into a list and replace it by another list ? I try this piece of code, but Im pretty sure I messed something: http://pastebin.com/HfdkGeB3 Any help appreciated, Thank you :) -- http://mail.python.org/mailman/listinfo/python-list
Start up company is looking for an experianced Django web developer .
Hi Everyone, Our company is looking for an experienced full time Django programmer to work with our development team on a contract basis. We are a start up that is developing a large web application with extensive database interfaces. We are based in the US so living in the US is a plus. The existing application is partially completed using Django, Centos 5, Postgresql 8.4, SVN, and Jquery. This contract position could lead to a full time position with our new company. If you’ve got expert skills in Django, HTML, Jquery, CSS and overall web development and design, we’d like to hear from you. If you are interested please send your resume or work experience to empwan...@cox.net Please include your expected hourly or weekly rate. Accepted applicants will be required to sign a non-disclosure agreement. -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace multiple lines in a txt file.
On 8/23/2010 11:22 AM Alban Nona said... Hi everybody, I would like to know if its possible to modify a list of entry that is define into a list and replace it by another list ? I try this piece of code, but Im pretty sure I messed something: http://pastebin.com/HfdkGeB3 The code you posted references variables not defined within the snippet, so it's hard to guess what may be wrong. Emile -- http://mail.python.org/mailman/listinfo/python-list
RE: Working with PDFs?
> writes: >> - Pull out text from each PDF page (to search for specific words) >> - Combine separate pdf documents into one document >> - Add bookmarks (with destination settings) > PDF Shuffler is a Python app which does PDF merging and splitting very > well. I don't think it does anything else, though, but maybe that's > where your code comes in? Thank you Anssi, MRAB, Terry and Geremy for your replies. I've been researching the apps you have recommended. Just curious if anyone has used pyPdf? While testing this, it seems to work pretty well for combining pdf files (seems to keep the annotation notes nicely also) and pulling out the text contents. I'm not sure I'm going to be able to find anything that can add bookmarks though. If you have used pyPdf, would you mind sharing your thoughts about it? Thanks. Jay -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace multiple lines in a txt file.
On 8/23/2010 12:13 PM Emile van Sebille said... On 8/23/2010 11:22 AM Alban Nona said... Hi everybody, I would like to know if its possible to modify a list of entry that is define into a list and replace it by another list ? I try this piece of code, but Im pretty sure I messed something: http://pastebin.com/HfdkGeB3 The code you posted references variables not defined within the snippet, so it's hard to guess what may be wrong. Emile One thing stands out -- fopen = open(_path).read() for passe in _passeFettel: fopen.write(re.sub(passe, _fileFettel) fopen contains the data read from _path and certainly has no write method. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Save/load like matlab?
> I wonder if there is a way to save and load all python variables just like > matlab does, so I can build a code step by step by loading previous states. > > I am handling a python processing code for very large files and multiple > processing steps. Each time I find a bug, I have to run the whole thing > again, which is time consuming. Perhaps pickle is the thing you are looking for? http://docs.python.org/library/pickle.html HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Save/load like matlab?
On 23-08-2010 21:44, Daniel Fetchinson wrote: >> I wonder if there is a way to save and load all python variables just like >> matlab does, so I can build a code step by step by loading previous states. >> >> I am handling a python processing code for very large files and multiple >> processing steps. Each time I find a bug, I have to run the whole thing >> again, which is time consuming. > Perhaps pickle is the thing you are looking for? > > http://docs.python.org/library/pickle.html or even cpickle which is lot faster cheers, Stef > HTH, > Daniel > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Save/load like matlab?
On Mon, Aug 23, 2010 at 10:37 AM, Sang-Ho Yun wrote: > I wonder if there is a way to save and load all python variables just like > matlab does, so I can build a code step by step by loading previous states. > > I am handling a python processing code for very large files and multiple > processing steps. Each time I find a bug, I have to run the whole thing > again, which is time consuming. > > Thank you, > Sang-Ho You may also be interested in Sage if you're trying to do Matlab-like things in Python. http://www.sagemath.org/ Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: Using String Methods In Jump Tables
On 23 Aug, 16:57, Tim Daneliuk wrote: > On 8/23/2010 10:35 AM, Jon Clements wrote: > > > > > On 20 Aug, 01:51, Tim Daneliuk wrote: > >> On 8/19/2010 7:23 PM, Steven D'Aprano wrote: > > >>> On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: > > Problem: > > Given tuples in the form (key, string), use 'key' to determine what > string method to apply to the string: > > >> table = {'l': str.lower, 'u': str.upper} > >> table['u']('hello world') > >>> 'HELLO WORLD' > > >> Aha! That's just what I was looking for. > > >>> [...] > As I said, I know I could do this as a set of cascading ifs or even as > an eval, but I'm loathe to use such approaches. I like jump tables as a > structural construct because they are easy to understand and maintain. I > also realize that what I'm asking may be violating some deeply held > notion of OO purity, but, well, now I'm just curious if there is a way > to do this > > >>> This is Python, not some "pure" OO language. We have functional > >>> programming constructs, procedural constructs, and probably other > >>> programming models as well. Screw the deeply held notion of OO purity :) > > >> Yeah, I've never been much impressed with the OO purists. One of > >> the best speeches on the subject I ever saw was by David Korn (of > >> ksh fame) who did a presentation at USENIX one year called "Objecting > >> To Objects". He documented an attempt to write a compiler using > >> purely OO constructs and the many rings of hell that ensued. > > >>> But seriously, Python's object model includes bound and unbound methods > >>> precisely so you can do this sort of thing, and the above table-based > >>> approach is very common and recommended as an alternative to case/switch > >>> statements. It's a very common Pythonic idiom, so never fear that people > >>> will stone you for using it. > > >> +1 > > >>> The only thing that is a bit unusual is that you call it a jump table. In > >>> my experience, "Jump Table" is used for low-level languages where the > >>> table values are memory addresses. > > >> Yeah ... those old assembler memories never quite fade do they. > >> I dunno what you might call this. A Function Dispatch Table > >> perhaps? > > >> Thanks to both you and Chris for setting me straight :) > > >> -- > >> > >> Tim Daneliuk > >> tun...@tundraware.com > > > Another more generic option would be to use methodcaller from the > > operator module. > > > Just my 2p, > > > Jon. > > Could you say a bit more about just why you prefer this approach? > Clearly, it *is* more generic, but in looking it over, it seems that > methodcaller is less readable and intuitive ... at least to my eyes ... In addition to Terry's informative response... Using methodcaller allows you to 'preserve' Python's duck-typing as well as any over-ridden methods in subclasses. In your example, this is probably overkill as you're only dealing with one class: but Terry did provide a nice example of when it could fail. Another (convoluted) example: class mystr(str): def lower(self): return self.upper() >>> s = mystr('abc') >>> s.lower() 'ABC' >>> lower = methodcaller('lower') >>> lower(s) 'ABC' >>> str.lower(s) 'abc' ^^^ Most likely incorrect It also adds a further bit of flexibility (which can be emulated with functools.partial admittedly): split_tab = methodcaller('split', '\t') split_comma = methodcaller('split', ',') ... etc ... Cheers, Jon. -- http://mail.python.org/mailman/listinfo/python-list
Re: Save/load like matlab?
On 8/23/10 12:37 PM, Sang-Ho Yun wrote: I wonder if there is a way to save and load all python variables just like matlab does, so I can build a code step by step by loading previous states. I am handling a python processing code for very large files and multiple processing steps. Each time I find a bug, I have to run the whole thing again, which is time consuming. Test each piece of code in isolation from the rest rather than relying on a complete run to test everything in one go. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE will not startup after upgrading Python on Mac OS X
In article , Benjamin Kaplan wrote: > On Mon, Aug 23, 2010 at 9:45 AM, Frederick Manley wrote: > > so went to > > python.org to download Python 2.7, as I was "strongly encouraged" to do on > > the website. [...] > >The only problem is, whenever I start it > > up (I've tried starting it from the Terminal and double clicking the icon) I > > get the following message: > > "Idle's subprocess cannot make connection. Either Idle can't start a > > subprocess or a personal firewall is blocking the connection." > > Searching various programming forums came up with similar problems users > > have had in windows, but I couldn't find any information on how to fix this > > problem on a mac with OSX. Please help. > >From the title, this may be relevant, but I'm not sure because I'm > having trouble accessing the bug tracker right now. > http://bugs.python.org/issue9227 Yes, you are undoubtedly running into Issue9227. This is a known problem with IDLE and Tkinter on OS X 10.6 when using the python.org 2.7 installer "for OS X 10.5 and later". Until a replacement installer is made available, the simplest workaround is to just re-install 2.7 using the 32-bit OS X installer "for OS X 10.3 and later" (available here http://www.python.org/download/releases/2.7/). -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Installing pymssql
Hello, I am new to the python world. I'm trying the install the pymssql package and have been unsuccessful. I am running Win7 x64. Here is the output I get when I try to build the pymssql package: running build running build_ext cythoning _mssql.pyx to _mssql.c building '_mssql' extension creating build creating build\temp.win-amd64-2.6 creating build\temp.win-amd64-2.6\Release C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN \amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Iwin32\free tds\include -IC:\Python26\include -IC:\Python26\PC /Tc_mssql.c /Fobuild \temp.win-amd64-2.6\Release\_mssql.obj -DMSDBLIB _mssql.c _mssql.c(643) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'long', possible loss of data _mssql.c(663) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'long', possible loss of data _mssql.c(685) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'long', possible loss of data _mssql.c(712) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'long', possible loss of data _mssql.c(6192) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data _mssql.c(9967) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data c:\pythonmods\pymssql-1.9.908\_mssql.c(4652) : warning C4700: uninitialized local variable '__pyx_v_dbcol' used creating build\lib.win-amd64-2.6 C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN \amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:win32\fre etds\lib /LIBPATH:C:\Python26\libs /LIBPATH:C:\Python26\PCbuild\amd64 msvcrt.lib kernel32.lib user32.lib gdi32.lib winsp ool.lib ws2_32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libTDS. lib dblib.lib /EXPORT:init_mssql build\temp.win-amd64-2.6\Release \_mssql.obj /OUT:build\lib.win-amd64-2.6\_mssql.pyd /IM PLIB:build\temp.win-amd64-2.6\Release\_mssql.lib /MANIFESTFILE:build \temp.win-amd64-2.6\Release\_mssql.pyd.manifest _mssql.obj : warning LNK4197: export 'init_mssql' specified multiple times; using first specification Creating library build\temp.win-amd64-2.6\Release\_mssql.lib and object build\temp.win-amd64-2.6\Release\_mssql.exp _mssql.obj : error LNK2019: unresolved external symbol dbsqlexec referenced in function __pyx_f_6_mssql_db_sqlexec _mssql.obj : error LNK2019: unresolved external symbol dbadata referenced in function __pyx_f_6_mssql_get_data _mssql.obj : error LNK2019: unresolved external symbol dbdata referenced in function __pyx_f_6_mssql_get_data _mssql.obj : error LNK2019: unresolved external symbol dbalttype referenced in function __pyx_f_6_mssql_get_type _mssql.obj : error LNK2019: unresolved external symbol dbcoltype referenced in function __pyx_f_6_mssql_get_type _mssql.obj : error LNK2019: unresolved external symbol dbadlen referenced in function __pyx_f_6_mssql_get_length _mssql.obj : error LNK2019: unresolved external symbol dbdatlen referenced in function __pyx_f_6_mssql_get_length _mssql.obj : error LNK2019: unresolved external symbol dbcancel referenced in function __pyx_f_6_mssql_db_cancel _mssql.obj : error LNK2019: unresolved external symbol dbtds referenced in function __pyx_pf_6_mssql_15MSSQLConnection_1 1tds_version___get__ _mssql.obj : error LNK2019: unresolved external symbol dbclose referenced in function __pyx_pf_6_mssql_15MSSQLConnection _close _mssql.obj : error LNK2019: unresolved external symbol dbuse referenced in function __pyx_pf_6_mssql_15MSSQLConnection_s elect_db _mssql.obj : error LNK2019: unresolved external symbol dbgetmaxprocs referenced in function __pyx_pf_6_mssql_get_max_con nections _mssql.obj : error LNK2019: unresolved external symbol dbcount referenced in function __pyx_f_6_mssql_15MSSQLConnection_ execute_scalar _mssql.obj : error LNK2019: unresolved external symbol dbnextrow referenced in function __pyx_f_6_mssql_15MSSQLConnectio n_execute_scalar _mssql.obj : error LNK2019: unresolved external symbol dbsettime referenced in function __pyx_pf_6_mssql_15MSSQLConnecti on_13query_timeout___set__ _mssql.obj : error LNK2019: unresolved external symbol dbcmd referenced in function __pyx_pf_6_mssql_15MSSQLConnection__ _init__ _mssql.obj : error LNK2019: unresolved external symbol dbloginfree referenced in function __pyx_pf_6_mssql_15MSSQLConnec tion___init__ _mssql.obj : error LNK2019: unresolved external symbol tdsdbopen referenced in function __pyx_pf_6_mssql_15MSSQLConnecti on___init__ _mssql.obj : error LNK2019: unresolved external symbol dbsetlogintime referenced in function __pyx_pf_6_mssql_15MSSQLCon nection___init__ _mssql.obj : error LNK2019: unresolved external symbol dbsetlname referenced in function __pyx_pf_6_mssql_15MSSQLConnect ion___init__ _mssql.obj : error LNK2019: unresolved external symbol dblogin referenced in function __pyx_pf_6_mssql_15MSSQLConnection ___init__ _mssql.obj : error LNK2019: unresolved external symbol dbdatecrack referenced in function __pyx_f_6_mssql_15MSSQLConnect
Re: Save/load like matlab?
On 23 August 2010 19:37, Sang-Ho Yun wrote: > I wonder if there is a way to save and load all python variables just like > matlab does, so I can build a code step by step by loading previous states. > > I am handling a python processing code for very large files and multiple > processing steps. Each time I find a bug, I have to run the whole thing > again, which is time consuming. > > Thank you, > Sang-Ho > > -- > http://mail.python.org/mailman/listinfo/python-list > A year ago or so I designed a simple file format that could do that and is also human readable (binary data is compressed and then base64 encoded). I use it extensively to store experiment data for my research and also for configuration files for two open source projects that I own: http://code.google.com/p/ssdf/ Almar -- http://mail.python.org/mailman/listinfo/python-list
Re: make install DESTDIR
> Martin- Asking for help :) Ok. Please try the patch below. If this works, please make a bug report. Regards, Martin Index: Lib/distutils/util.py === --- Lib/distutils/util.py (Revision 84197) +++ Lib/distutils/util.py (Arbeitskopie) @@ -220,7 +220,7 @@ if not os.path.isabs(pathname): return os.path.join(new_root, pathname) else: -return os.path.join(new_root, pathname[1:]) +return os.path.join(new_root, pathname.lstrip('/')) elif os.name == 'nt': (drive, path) = os.path.splitdrive(pathname) -- http://mail.python.org/mailman/listinfo/python-list
Re: Save/load like matlab?
On 8/23/10 3:18 PM, Robert Kern wrote: On 8/23/10 12:37 PM, Sang-Ho Yun wrote: I wonder if there is a way to save and load all python variables just like matlab does, so I can build a code step by step by loading previous states. I am handling a python processing code for very large files and multiple processing steps. Each time I find a bug, I have to run the whole thing again, which is time consuming. Test each piece of code in isolation from the rest rather than relying on a complete run to test everything in one go. Having said that, you will want to take a look into using joblib to structure your larger runs: http://pypi.python.org/pypi/joblib -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an appropriate encoding standard that supports all languages
Ata Jafari writes: > Finally I did it. > I was doing some stupid mistakes. > Thanks alot. For the benefit of future readers of this thread, could you please describe what the errors were and how you discovered them? Also what the eventual solution was. -- \ “When I get new information, I change my position. What, sir, | `\ do you do with new information?” —John Maynard Keynes | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing pymssql
On Monday 23 August 2010, it occurred to f1crazed to exclaim: > Hello, > > I am new to the python world. I'm trying the install the pymssql > package and have been unsuccessful. I am running Win7 x64. Here is > the output I get when I try to build the pymssql package: > > [snip: missing symbols 64 bit blah] This appears to be a known bug: http://code.google.com/p/pymssql/issues/detail?id=11 There is a comment by the reporter: " This is likely because the 'freetds.zip' included in the source distribution only has 32-bit libraries (lib/libTDS.lib). " Assuming this analysis is correct, maybe you can find (or, more likely, create) a 64-bit build of libTDS and use that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Start up company is looking for an experianced Django web developer .
writes: > Our company is looking for an experienced full time Django programmer […] Please don't use the Python forum for this. Instead, post it to the Python Jobs Board http://www.python.org/community/jobs/>. > Accepted applicants will be required to sign a non-disclosure agreement. I would strongly recommend that IT workers not sign such agreements. http://www.myintervals.com/blog/2009/11/10/project-management-three-reasons-why-not-to-sign-non-disclosure-agreements/> http://www.feld.com/wp/archives/2006/02/why-most-vcs-dont-sign-ndas.html> http://mixergy.com/why-i-wont-sign-your-nda/> Instead, both parties can rely on existing law (which already heavily favours the employer), and don't sign away more of your rights just to get a job. -- \ “I am amazed, O Wall, that you have not collapsed and fallen, | `\since you must bear the tedious stupidities of so many | _o__) scrawlers.” —anonymous graffiti, Pompeii, 79 CE | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Using String Methods In Jump Tables
Tim Daneliuk writes: >You can get away with this because all string objects appear to point to > common >method objects. That is,: id("a".lower) == id("b".lower) A side note: your use of `id' has misled you. id(X)==id(Y) is not a perfect substitue for the X is Y. :) "a".lower and "b".lower obviously cannot be the same object, because in that case, how could they behave differently when called? >>> "a".lower() 'a' >>> "b".lower()# this should also return 'a' if "b".lower is the # same object 'b' Yet, id("a".lower) == id("b".lower) evaluates as True. What happens is, when the expression id("a".lower) == id("b.lower") is evaluated, each of the bound method objects created with subexpressions "a".lower" and "b".lower is referenced and thrown away as soon as "id" is called (i.e. pretty much immediately), so the two never exist at the same time. By the time "b".lower needs to be created, "a".lower is freshly deceased, and the memory it used to occupy is ready for use, and waiting at the top of the freelist. If CPython happened to use a different allocation/garbage collection strategy and failed to reuse the same memory address immediately, your code would just (happen to) work. -- http://mail.python.org/mailman/listinfo/python-list
Proper set-up for a co-existant python 2.6 & 3.1 installation
I started learning python with ver 2.6. Then I switched to 3.1 after uninstalling the previous version. Now I find that many of the code snippets that I would need are written for py 2.6. Sometimes the automatic converter 2to3 doesn't help, because it is not able to complete its objective and request manual "tuning" from the user. This is to tell you that I would like to have both versions running on my PC. I am using Windows 7 at home, and Windows Vista in the office. Right now, the two versions are installed on the PC I have at home. If I go to the directory C:\python26 or C:\python31 and I type "python", the correct version of python is launched. I need the pywin32 extensions in either case. I was about to feel happy that everything worked when I found that I cannot change the file associations. If I want to work with py 3.1, I want that a double click on a *.py file launches python 3.1, and not 2.6. On the other hand, when I pan to work with py 2.6 I want that a double click on a*.py file launches python 3.1. I keep source files (*.py) for either version in different directories. I tried to change file associations, first manually, in a CMD window. But the system was responding "access denied" even when I used an Administrator account (I was using FTYPE python.file="C: \Python26\python.exe" "%1" %*). So I directed my efforts towards the Control Panel. But here I got lost. I am not able to find the python file associations (I can find others, but not python's). Perhaps I am focussing my efforts in the wrong direction, but I am not aware of any alternative one. Perhaps you can help me. Thank you Vicente Soler -- http://mail.python.org/mailman/listinfo/python-list
Re: Proper set-up for a co-existant python 2.6 & 3.1 installation
> I tried to change file associations, first manually, in a CMD window. > But the system was responding "access denied" even when I used an > Administrator account (I was using FTYPE python.file="C: > \Python26\python.exe" "%1" %*). That works, in principle. Put that command into py26.bat, then, in Explorer, Run As Administrator. Make sure to double-escape the percent signs. Alternatively, you can also write a program that writes to HKEY_CURRENT_USER; that would take precedence over HKEY_LOCAL_MACHINE. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Proper set-up for a co-existant python 2.6 & 3.1 installation
On 24 ago, 00:55, "Martin v. Loewis" wrote: > > I tried to change file associations, first manually, in a CMD window. > > But the system was responding "access denied" even when I used an > > Administrator account (I was using FTYPE python.file="C: > > \Python26\python.exe" "%1" %*). > > That works, in principle. Put that command into py26.bat, then, in > Explorer, Run As Administrator. Make sure to double-escape the percent > signs. > > Alternatively, you can also write a program that writes to > HKEY_CURRENT_USER; that would take precedence over HKEY_LOCAL_MACHINE. > > Regards, > Martin When I am logged-in in a session as an administrator, the BAT file on the Desktop, and I double-click on it, it does not work. However, if instead of double-clicking on the BAT file, I enter the Explorer and I run the BAT file as administrator, then something seems to start working. Excellent! When you say to double-escape the percent signs, do you mean that in my BAT file I should write... FTYPE python.file="C:\Python26\python.exe" "%%1" %%* and the inverted commas around %%*, are they not necessary? Vicente Soler -- http://mail.python.org/mailman/listinfo/python-list
Re: Proper set-up for a co-existant python 2.6 & 3.1 installation
> When I am logged-in in a session as an administrator, the BAT file on > the Desktop, and I double-click on it, it does not work. This is not what I meant. Instead, right-click on the BAT file, and select "run as administrator". > When you say to double-escape the percent signs, do you mean that in > my BAT file I should write... > > FTYPE python.file="C:\Python26\python.exe" "%%1" %%* > > and the inverted commas around %%*, are they not necessary? No, I don't think so. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Proper set-up for a co-existant python 2.6 & 3.1 installation
On Aug 24, 1:33 am, "Martin v. Loewis" wrote: > > When I am logged-in in a session as an administrator, the BAT file on > > the Desktop, and I double-click on it, it does not work. > > This is not what I meant. Instead, right-click on the BAT file, > and select "run as administrator". > > > When you say to double-escape the percent signs, do you mean that in > > my BAT file I should write... > > > FTYPE python.file="C:\Python26\python.exe" "%%1" %%* > > > and the inverted commas around %%*, are they not necessary? > > No, I don't think so. > > Regards, > Martin Martin (or anybody else), The problem with FTYPE is solved. However, after having switched to py 3.1 with the help of the BAT script (which only changes FTYPE) I have another problem. (Just for reference, here is my batch file) @ECHO OFF ECHO ECHO Cambia a Python 3.1 ECHO ECHO * ECHO FTYPES: ECHO * ECHO .py=Python.File ECHO .pyc=Python.CompiledFile ECHO .pyo=Python.CompiledFile ECHO .pys=pysFile ECHO .pyw=Python.NoConFile ECHO * ECHO ECHO * FTYPE python.file="C:\Python31\python.exe" "%%1" %%* FTYPE python.compiledfile="C:\Python31\python.exe" "%%1" %%* FTYPE python.NoConFile="C:\Python31\pythonw.exe" "%%1" %%* ECHO * Pause @ECHO ON The problem is that, if I am on top of a .py file, and, with the mouse, I click on the right button, then I click on "Edit with IDLE", I get the 2.6 system, not the 3.1 one (which was supposed to be the correct one after the change). My question is: are there any other changes that I should do in order to fully switch from one version to another? Thank you in advance. Vicente Soler -- http://mail.python.org/mailman/listinfo/python-list
Re: How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?
On Aug 21, 12:32 pm, Alex McDonald wrote: > "Scintilla" gets about 2,080,000 results on google; "blather" gets > about 876,000 results. O Hugh, you pseudo-intellectual you! > > > with gutter language such as > > "turd" > > About 5,910,000 results. It has a long history, even getting a mention > in the Wyclif's 13th century bible. You looked up "blather" and "turd" on google *AND* you are not a pseudo-intellectual??? That is funny! I don't consider myself to be a pseudo-intellectual. I don't have any education however, so a pseudo-intellectual is the only kind of intellectual that I could be. -- http://mail.python.org/mailman/listinfo/python-list
Re: Proper set-up for a co-existant python 2.6 & 3.1 installation
Martin v. Loewis wrote: When I am logged-in in a session as an administrator, the BAT file on the Desktop, and I double-click on it, it does not work. This is not what I meant. Instead, right-click on the BAT file, and select "run as administrator". When you say to double-escape the percent signs, do you mean that in my BAT file I should write... FTYPE python.file="C:\Python26\python.exe" "%%1" %%* and the inverted commas around %%*, are they not necessary? No, I don't think so. %1 is the placeholder for parameter 1, which you do want quoted. %* is the placeholder for all the remaining parameters, which you don't want quoted as single string. -- http://mail.python.org/mailman/listinfo/python-list
Re: How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?
On Aug 22, 3:40 pm, 1001nuits <1001nu...@gmail.com> wrote: > Another thing you learn in studying in University is the fact that you can > be wrong, which is quite difficult to accept for self taught people. Yet another thing you learn in studying in University, is the art of apple polishing! LOL If a person has graduated from college, it is not clear what if anything he has learned of a technical nature --- but it can be assumed that he has learned to be a head-bobber (someone who habitually bobs his head up and down in agreement when the boss is speaking) and has learned to readily admit to being wrong when pressured (when the boss looks at him without smiling for more than two seconds). These are the traits that bosses want in an employee --- that prove the employee to be "trainable." BTW, has anybody actually looked at my software? http://www.forth.org/novice.html All this pseudo-intellectual nonsense (including this post) is getting boring. Why don't we try discussing software for a while? I wrote that slide-rule program as a showcase of Forth. I've been thinking of porting it over to another language, possibly C. Maybe one of you C experts could write the C program though, as a comparison --- to show how much better C is than Forth. You can demonstrate that my code was badly written and strangely designed --- with a concrete example, rather than just a lot hand-waving and chest-thumping. -- http://mail.python.org/mailman/listinfo/python-list
Re: make install DESTDIR
On Aug 23, 2:23 pm, "Martin v. Loewis" wrote: > > Martin- Asking for help :) > > Ok. Please try the patch below. > > If this works, please make a bug report. > > Regards, > Martin > > Index: Lib/distutils/util.py > === > --- Lib/distutils/util.py (Revision 84197) > +++ Lib/distutils/util.py (Arbeitskopie) > @@ -220,7 +220,7 @@ > if not os.path.isabs(pathname): > return os.path.join(new_root, pathname) > else: > - return os.path.join(new_root, pathname[1:]) > + return os.path.join(new_root, pathname.lstrip('/')) > > elif os.name == 'nt': > (drive, path) = os.path.splitdrive(pathname) Thanks Martin. That seems to work. I will file a bug report. Also, can you describe what the problem was? -- http://mail.python.org/mailman/listinfo/python-list
Re: Save/load like matlab?
On Aug 23, 2010, at 16:47 , Almar Klein wrote: A year ago or so I designed a simple file format that could do that and is also human readable (binary data is compressed and then base64 encoded). I use it extensively to store experiment data for my research and also for configuration files for two open source projects that I own: http://code.google.com/p/ssdf/ this is fantastic! what a great format! I've been looking for something like this for quite some time. thanks! bb -- Brian Blais bbl...@bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Iran's self-defense options 'limitless' - against the YANQUI and KHAZAR Bustards - Brilliant ANALYSIS
Iran's self-defense options 'limitless' - against the YANQUI and KHAZAR Bustards - Brilliant ANALYSIS Iran's self-defense options 'limitless' Tue Aug 24, 2010 12:9AM President Mahmoud AhmadinejadIran's President Mahmoud Ahmadinejad says no military action is expected to be taken against the Islamic Republic since enemies are aware of Iran's reaction. "Iran is not concerned by a prospective military attack by any country, although it is always prepared to defend itself," Ahmadinejad said in an interview with Qatar's al-Sharq and the Peninsula newspapers on Monday. "Enemies know well that Iran is an invincible fortress and I do not believe the US masters of the Zionists will allow the regime [in Tel Aviv] to take any measures against Iran," noted the Iranian chief executive. Asked about Iran's options in the case it is attacked, Ahmadinejad said, "Iran has limitless options which extends to all parts of the world." Commenting on the Israeli threats against Iran's sovereignty over the county's nuclear enrichment program, the Iranian president pointed out that "Israel is too weak to stage a military strike against Iran, but if it attacks, it will receive a devastating response, which will make it regret its aggression." He also dismissed the idea that Arab countries' soil would be used to launch attacks on Iran, saying that the "leaders of these countries are more prudent than that.” Ahmadinejad further downplayed US military might in its current wars in the Middle East region and rejected the speculations that an imminent war against Iran was the cause of the US troops' withdrawal from Iraq. GHN/MGH BRILLIANT ANALYSIS http://www.tehrantimes.com/index_View.asp?code=225469 View Rate : 1531 # News Code : TTime- 225469 Print Date : Tuesday, August 24, 2010 ‘Iran will stand beside any country threatened in region’ Ahmadinejad: Israel lacks courage to attack Iran TEHRAN – Iranian President Mahmoud Ahmadinejad says that Iran will stand beside any country in the region that is threatened. “Iran will stand on the side of any country in the region which comes under pressure or is threatened,” Ahmadinejad said in an interview with Arabic satellite television network Al Jazeera aired on Sunday. He also said he doesn’t think the threats by the United States and Israel to attack Iran are “serious”. “Israel does not have the courage to do it… I do not think the threat is serious.” Ahmadinejad also stated that Israel is “too weak” to attack the Islamic Republic. The Iranian president said that any military adventure by the Zionist regime targeting Iran would receive a “crushing” response that would make Israel regret the decision. He went on to say that Persian Gulf states are “too smart” to allow the U.S. to use bases on their territory for a strike on Iran. “We regard the Persian Gulf countries as brothers and friends. They are smarter than that.” In the interview, the president also said he does not fear an attack by the U.S. because it could not even defeat a small army in Iraq. “There are no logical reasons for the United States to carry out such an act,” President Ahmadinejad told Al Jazeera. “Do you believe an army that has been defeated by a small army in Iraq can enter into a war with a large and well trained army like the Iranian army?” he asked, referring to the insurgents in Iraq. Iran will only “look to the views of wise people” in the U.S. and not to those whose minds are obsessed with “hatred and animosity”, the president said when asked about former U.S. ambassador to the UN John Bolton’s remarks, which had apparently encouraged Israel to attack the Bushehr plant before its start-up. Washington has no real motive to attack Iran and would not benefit from hostilities, he added. “The friendship of Iran is much better than its hostility,” he said. He went on to say that Iran is working to produce nuclear fuel independently “because receiving it from an outside source is conditioned on diplomatic criteria.” To prevent Iran from using the Bushehr reactor to produce plutonium, inspectors from the International Atomic Energy Agency and Russia, which built the power plant, are making sure Iran returns the fuel rods it receives after they are spent. “There is a difference between those who produce and those who buy. We must make sure our nuclear power plant continues to operate. We do not trust the West, despite our good relations with Russia,” Ahmadinejad said. “We need 20 power plants like the one in Bushehr,” he added. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python "why" questions
"Russ P." wrote: > However, I've switched from Python to > Scala, so I really don't care. Really? Your endless whining in this thread would seem to indicate otherwise. -- http://mail.python.org/mailman/listinfo/python-list
Re: Discarding STDERR generated during subprocess.popen
On Mon, 23 Aug 2010 10:38:02 -0700, Leon Derczynski wrote: > I would like to run an external program, and discard anything written > to stderr during its execution, capturing only stdout. My code > currently looks like: > > def blaheta_tag(filename): > blaheta_dir = '/home/leon/signal_annotation/parsers/blaheta/' > process = subprocess.Popen([blaheta_dir + 'exec/funcTag', > blaheta_dir + 'data/', filename], cwd=blaheta_dir, > stdout=subprocess.PIPE) > process.wait() > return process.communicate()[0] > > This returns stdout, and stderr ends up printing to the console. How > can I disregard anything sent to stderr such that it doesn't appear on > the console? Either: 1. Add "stderr=subprocess.PIPE" to the Popen() call. The communicate() method will read both stdout and stderr, and you just ignore stderr. 2. Redirect stderr to the null device: nul_f = open(os.devnull, 'w') process = subprocess.Popen(..., stderr = nul_f) nul_f.close() return process.communicate()[0] [os.devnull will be "/dev/null" on Unix, "nul" on Windows.] BTW: you shouldn't call process.wait() here. The communicate() method will call the wait() method when it receives EOF. If you call wait(), and the process tries to write more than a buffer's worth of output (the exact figure is platform-specific), your script will deadlock. The child process will block waiting for the script to consume its output, while the script will block waiting for the child process to terminate. -- http://mail.python.org/mailman/listinfo/python-list
YANQUI cry babies concerned that Iran has achieved parity in DRONES and against the massive AIRCRAFT carriers which are like SITTING DUCKS. A nation needs AIRCRAFT carriers to venture out for IMPERIAL
YANQUI cry babies concerned that Iran has achieved parity in DRONES and against the massive AIRCRAFT carriers which are like SITTING DUCKS. A nation needs AIRCRAFT carriers to venture out for IMPERIALISTIC assaults but cant go out on speed boats. Yet the NUMEROUS fast boats can sink the AIRCRAFT carrier and make it a SAILING COFFIN. http://www.google.com/hostednews/afp/article/ALeqM5gYlBmnQz28otk-w_hvx1pZ5C= bl0w US concerned about Iran's assault boats, drone (AFP) =96 5 hours ago WASHINGTON =97 The United States voiced concern Monday over Iran's unveiling of new assault boats and an aerial drone, but said Iran's arms buildup will backfire as its neighbors gang up against it. Iran began mass-producing two high-speed variants of missile-launching assault boats on Monday, a day after Iranian President Mahmoud Ahmadinejad revealed a home-built bomber drone. "This is... something that is of concern to us and... concern to Iran's neighbors," State Department spokesman Philip Crowley told reporters. He said that while every country had the right to provide for its self- defense, the United States takes into account "systems that can potentially... threaten particular countries or peace and stability in the region." Faced with "the growth of Iran's capabilities over a number of years, we've stepped up our military cooperation with other countries in the region," Crowley said. "This is one of the reasons why... we believe that if Iran continues on the path that it's on... (it) might find itself less secure because you'll have countries in the region that join together to offset Iran's growing capabilities." He added that the United States is still open to "constructive dialogue" with Iran to answer questions it and the world community have about its nuclear program, which Washington fears is aimed at building a bomb. "But in the meantime, we will work with other countries to try to do everything that we can to maintain peace and stability in the region," Crowley said. Copyright =A9 2010 AFP. All rights reserved -- http://mail.python.org/mailman/listinfo/python-list
Re: Python "why" questions
On Aug 23, 7:46 pm, alex23 wrote: > "Russ P." wrote: > > However, I've switched from Python to > > Scala, so I really don't care. > > Really? Your endless whining in this thread would seem to indicate > otherwise. Yes, I guess I care some, but not much. I still use Python for some things, and I still have lots of "legacy" Python code that I still use. I just like to "whine" about zero-based indexing (but Scala is no different in that regard). It's my number one gripe. (My number zero gripe is semicolons after each statement -- but both Python and Scala got that one right, thank goodness.) -- http://mail.python.org/mailman/listinfo/python-list
help in code
I am new to python .I have a corpus which is written in Bengali and i want to read that file using python code.Can anyone help me in this matter. Thank You -- http://mail.python.org/mailman/listinfo/python-list
Re: make install DESTDIR
> Thanks Martin. That seems to work. I will file a bug report. Also, can > you describe what the problem was? If you have / as the prefix, you get two leading slashes, e.g. for //lib/python2.x. Any other prefix would have given you only a single slash: e.g. if it had been /usr, then you end up with /usr/lib/python2.x. Now, the code strips the first character to make it a relative path name (so that join can be used), which fails to work correctly if there are two leading slashes. HTH, Martin -- http://mail.python.org/mailman/listinfo/python-list