sorted
Hi NG I what to used the sorted function, and im getting this error Traceback (most recent call last): File "F:\home\thomas\src\guisample\test1.py", line 59, in ? main() File "F:\home\thomas\src\guisample\test1.py", line 31, in main sorted(cords, key=operator.itemgetter(1)) NameError: global name 'sorted' is not defined what do I needs to import, to use this function ? regards thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython Grid Question
>> I'm wonderg if there is a way to make a subclass of wx.grid.Grid in >> which the coloumn labels for the grid appear on the bottom of the grid >> instead of the top. > > follow that lead. But jean-michel has two good points: it could be > easier to use 2 grids and http://wxpython.org/maillist.php would give > you better answers :) After a while, I think in the case where you'd want to use 2 grids, it could be tricky to reproduce scrollings and events across the two grids... and there are probably other inconvenients, particularly if you include it in sizers. Its probably not a so much good point. rgds jm -- http://mail.python.org/mailman/listinfo/python-list
Re: sorted
Dennis Lee Bieber skrev: > On Fri, 18 Aug 2006 09:31:54 +0200, thomas <[EMAIL PROTECTED]> declaimed > the following in comp.lang.python: > >> I what to used the sorted function, and im getting this error >> > >> what do I needs to import, to use this function ? >> > Uhm... the entire 2.4 version of Python? > > You don't mention what version you have, but sorted() is new with > 2.4 Sorry I am using 2.3. So now I know what to do :) Thanks for the quick answer regards thomas -- http://mail.python.org/mailman/listinfo/python-list
RE: Looking For mp3 ID Tag Module
[Tim Daneliuk] | >> audio["title'] = Something based on the filename that has unicode | >> chars in it | >> | >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc | in position | >> 56: ordinal not in range(128) | I am trying to set the title based on the filename. The file | is in a Win32 | NTFS filesystem, so it could have non-ASCII chars in it. | What I am stumbling | on it how to coerce it into unicode. I have tried: How are you getting the filename? If it's os.listdir, try passing the path name as a unicode string: import os filenames = os.listdir (u".") This will return a list of unicode strings, which you can then decode at will or pass along direct. If you're using, say, glob which doesn't return Unicode, I suggest you try decoding via sys.stdin.encoding (cp437 on my machine) or cp1252, which is commonly used under (Western) Windows. I'm sure there is some more canonical way of getting the encoding the filesystem has returned, but I'm afraid I've no idea what it is. Best bet is probably the listdir (u".") approach. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: It is __del__ calling twice for some instances?
Max Yuzhakov wrote: > Why for some instance __del__ called twice? > Such behaviour of __del__ seems to me unpredictable. Here's a slightly modified version of your code. The 51st object destroyed gets its __del__ method called twice. It doesn't matter how long your loop is, every 50th object gets special treatment (or perhaps it is the 49th). The good news is that there is a way to stop it happening: just add an explicit "del self.other" at the end of __del__. The bad news is that if your list is too long that will cause a flood of error messages and won't call the destructors at all past the first 1000. As to why it happens, there is a mechanism in Python to stop unlimited stack being used when objects are freed: when the stack gets too deep then instead of being released, the Py_DECREF call puts the object into a trashcan list and the objects aren't released until the stack has unwound. It looks like there must be a bug round the trashcan mechanism somewhere. BTW, the behaviour is completely different if you use a new style class, but still somewhat bizarre: for new style classes only the first 25 objects get freed when you clear a, the remainder are only released by the garbage collector. #!/usr/local/bin/python -d # -*- coding: koi8-u -*- class foo: def __init__(self, other): self.other = other self._deleted = False global ini_cnt ini_cnt +=1 def __del__(self): if self._deleted: print "aargh!" self._deleted = True global del_cnt del_cnt +=1 print "del",del_cnt,"at",id(self) def stat(): print "-"*20 print "ini_cnt = %d" % ini_cnt print "del_cnt = %d" % del_cnt print "difference = %d" % (ini_cnt-del_cnt) ini_cnt = 0 del_cnt = 0 loop_cnt = 54 a = foo(None) for i in xrange(loop_cnt): a = foo(a) stat() a = None stat() -- http://mail.python.org/mailman/listinfo/python-list
Re: python-dev and setting up setting up f2py on Windows XP
Hi John, Thank you very much for your help and resolving my issue with "python-dev". I'll hopefully get my problem sorted today, if not I'm sure I'll be back with more questions! The C compiler I'm using is Microsoft Visual Studio 8. I have been told there are potential compatibility issues between this, my version of python and my fortran compiler. I have to use python 2.3 as it is compatible with a CFD package I'm using. I've resinstalled python properley so I'll persevere with my exsisting C compiler this morning and try MINGW32 if I have no joy. Thanks again, Sile John Machin wrote: > Sile wrote: > > Hi, > > > > I've been trying to get f2py working on Windows XP, I am using Python > > 2.3. I'm new to python so I'm not too sure what I'm doing yet. I need > > the python-dev package to run f2py. I have been told this is just the > > header files and .dll and I need to put them somewhere my C compiler > > can find them. I've searched the web and none of the python-dev > > packages I've found are for windows. I was wondering is this > > automatically part of the windows version and if so how I set it up so > > my C compiler can find them. If it is not part of the standard package > > does anyone know where I can find it??? > > > > Any help at all would be much appreciated. > > The concept of "python-dev package" is a Debian concept which doesn't > apply to Windows. The standard installation on Windows provides the > header and library files that you need for interfacing with C. > > Don't put things where your C compiler can find them; do a standard > no-frills install of Python2.4 using the .msi installer and tell your C > compiler where the goodies are. > > E.g. using the MinGW32 gcc, you'd need things like: > > gcc -I\python24\include -lpython24 -L\python24\libs > [first is "i".upper(), second is "L".lower()] > > Which C compiler are you using? > > You will need to add "C:\Python24" to the path so that you can invoke > python easily; that will also enable anything else finding python24.dll > if you do a "me only" install of Python. > > So give that a whirl and if you have any dramas, come back with > questions ... > > HTH, > John -- http://mail.python.org/mailman/listinfo/python-list
Re: python-dev and setting up setting up f2py on Windows XP
Hi John, Thank you very much for your help and resolving my issue with "python-dev". I'll hopefully get my problem sorted today, if not I'm sure I'll be back with more questions! The C compiler I'm using is Microsoft Visual Studio 8. I have been told there are potential compatibility issues between this, my version of python and my fortran compiler. I have to use python 2.3 as it is compatible with a CFD package I'm using. I've resinstalled python properley so I'll persevere with my exsisting C compiler this morning and try MINGW32 if I have no joy. Thanks again, Sile John Machin wrote: > Sile wrote: > > Hi, > > > > I've been trying to get f2py working on Windows XP, I am using Python > > 2.3. I'm new to python so I'm not too sure what I'm doing yet. I need > > the python-dev package to run f2py. I have been told this is just the > > header files and .dll and I need to put them somewhere my C compiler > > can find them. I've searched the web and none of the python-dev > > packages I've found are for windows. I was wondering is this > > automatically part of the windows version and if so how I set it up so > > my C compiler can find them. If it is not part of the standard package > > does anyone know where I can find it??? > > > > Any help at all would be much appreciated. > > The concept of "python-dev package" is a Debian concept which doesn't > apply to Windows. The standard installation on Windows provides the > header and library files that you need for interfacing with C. > > Don't put things where your C compiler can find them; do a standard > no-frills install of Python2.4 using the .msi installer and tell your C > compiler where the goodies are. > > E.g. using the MinGW32 gcc, you'd need things like: > > gcc -I\python24\include -lpython24 -L\python24\libs > [first is "i".upper(), second is "L".lower()] > > Which C compiler are you using? > > You will need to add "C:\Python24" to the path so that you can invoke > python easily; that will also enable anything else finding python24.dll > if you do a "me only" install of Python. > > So give that a whirl and if you have any dramas, come back with > questions ... > > HTH, > John -- http://mail.python.org/mailman/listinfo/python-list
Re: python-dev and setting up setting up f2py on Windows XP
Thanks Anand ! -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess confusion: how file-like must stdin be?
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Thu, 17 Aug 2006 17:16:25 +, [EMAIL PROTECTED] (Cameron Laird) > declaimed the following in comp.lang.python: > > > Question: > > import subprocess, StringIO > > > > input = StringIO.StringIO("abcdefgh\nabc\n") > > Here you override the builtin function "input()" > > # I don't know of a compact, evocative, and > > # cross-platform way to exhibit this behavior. > > # For now, depend on cat(1). > > p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, > > stdin = response) > > Here you specify the non-existant "response" Assume the OP meant to write this >>> import subprocess, StringIO >>> inp = StringIO.StringIO("abcdefgh\nabc\n") >>> p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, stdin = inp) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/subprocess.py", line 534, in __init__ (p2cread, p2cwrite, File "/usr/lib/python2.4/subprocess.py", line 830, in _get_handles p2cread = stdin.fileno() AttributeError: StringIO instance has no attribute 'fileno' >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Which field is Python suitable to do some tasks?
many_years_after wrote: > hello , members: > I have basic knowledge of python programming. But i don't know > what to do next step. > I don't know in which field I should learn more about python and > finally finish some tasks. > Can you give me some ideas? http://www.pyweek.org/ Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: It is __del__ calling twice for some instances?
Duncan Booth wrote: > As to why it happens, there is a mechanism in Python to stop unlimited > stack being used when objects are freed: when the stack gets too deep > then instead of being released, the Py_DECREF call puts the object > into a trashcan list and the objects aren't released until the stack > has unwound. It looks like there must be a bug round the trashcan > mechanism somewhere. I figured out what is going on in the code to deallocate an old-style class instance: The reference count is temporarily incremented. If the class has a __del__ method then a descriptor is created for the method and called. When the call returns, the descriptor is released. Then the object itself is released using special code to avoid a recursive call to the deallocator. However, if the trashcan mechanism is invoked by the attempt to release the descriptor, it actually queues the descriptor in the trashcan. Since the descriptor contains a reference to the object it has effectively resurrected it. This means the special code to avoid the recursive call simply decrements the reference count but does not release anything (the object has been resurrected by the descriptor). When the descriptor is later released the __del__ method is triggered a second time. -- http://mail.python.org/mailman/listinfo/python-list
crash in wx.TreeListCtrl SelectItem()
Hello list, I have a strange crash (segfault on FreeBSD) that I can not reliably reproduce and therefore unfortunately can not provide a self contained test case at the moment. Here is what I do (and what works almost always, but sometimes crashes): 1) find an item in a wx.TreeListCtrl by its pydata (code posted to this list) 2) if the item is found: a) call EnsureVisible(foundItem) b) call SelectItem(foundItem) The call to EnsureVisible() always returns, but SelectItem() crashes python sometimes. foundItem on a crash is something like this: calling GetPyData(foundItem) returns the correct pydate. Any ideas what could be happening or how to further debug this? Thank you in advance for your time! Johannes -- http://mail.python.org/mailman/listinfo/python-list
MS SQL Server: NT Authentication. Possible?
Hi! Is it somehow possible to access an MS SQL Server database from python by NT-Authentication or do I have only the possibility to use an SQL-Account with DB = odbc.odbc(myDB/myAccount/myPW) ? Kind regards Dirk -- http://mail.python.org/mailman/listinfo/python-list
find item in wx.TreeListCtrl by pydata code snippet
Hello list, here is a small code snippet to recursively search a wx.TreeListCtrl for an item with specific pydata. Feel free to comment! def recursiveFindItemByPydata(self, parent, pydata): item, cookie = self.GetFirstChild(parent) while item: if self.GetPyData(item) == pydata: return item if self.ItemHasChildren(item): found = self.recursiveFindItemByPydata(item, pydata) if found is not None: return found item, cookie = self.GetNextChild(parent, cookie) return None HAND Johannes -- http://mail.python.org/mailman/listinfo/python-list
who needs python when u have happs?
What applications benefit from HAppS? HTTP requests and SMTP envelopes encapsulate transactions and not vice versa. Note: doing otherwise with LAMP is considered bad design because it implies a requirement to maintain and garbage collect database connections arbitrarily. So this should not be a high hurdle. All operating data fits in memory (store blobs on disk.) Note: Although this seems like a high hurdle, COTS servers with 12gb of memory are readily accessible and some vendors let you reach up to 500gb of RAM. FYI, eBay has around 50M active users. If you maintained 1k of queryable data for each of their users, you would need only 50GB. (You would also need to recompile your app for 64bits so the math is a little more involved but you get my point). You don't need more CPU power to server your app than you can obtain in a single machine. Note: I have not benchmarked this code yet, but another Haskell server was benchmarked at near 1000 HTTP transactions per second on a Pentium 4 in 2000. Modern web servers with similar architecture can serve 10k HTTP transactions per second. eBay serves 400M page views per day, which comes to an average load of 5000 hps and a peak load of perhaps 50k hps. In other words, an OTS 8 CPUs system, could handle all of eBay's HTTP traffic. I am not saying that using HAppS, you could serve all of eBay on a single box. I am saying that your application is likely to be well within the constraints required for HAppS to make sense for it. -- http://mail.python.org/mailman/listinfo/python-list
RE: MS SQL Server: NT Authentication. Possible?
[Dirk Hagemann] | Hi! | Is it somehow possible to access an MS SQL Server database from python | by NT-Authentication or do I have only the possibility to use an | SQL-Account with DB = odbc.odbc(myDB/myAccount/myPW) ? (dsn examples from http://www.connectionstrings.com/) + Object Craft MSSQL module: http://www.object-craft.com.au/projects/mssql/ can do by specifying blank username/pwd <= Python 2.3 only + adodbapi: http://adodbapi.sourceforge.net can use Trusted Connection eg "Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" + pymssql: http://pymssql.sourceforge.net/ can only do named user + mx.ODBC: http://www.egenix.com/files/python/mxODBC.html should be able to use Trusted Connection eg "Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;" Commercial License may be needed TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Subprocess quote problem
Hi Folks, I'm working on a script that executes a command with arbitrary options. Most of its options works fine with subprocess, but at least one (as far as I know) is giving me a headache. The program that I'm trying to execute is Nmap, and the problematic option is the -iL, that is used to indicate a file with the targets that nmap should scan. If I open my terminal, and write: nmap -iL "/tmp/target_list" , nmap picks the file, read it and scan every target written inside it. But, if I try to use the same scan on my command execution script, it makes nmap raise a strange error: "Failed to open input file "/home/adriano/umit/test/targets" for reading QUITTING!" This is not a permission issue. I put this target_file file on /tmp and set chmod 777 on it. The script: _stdout_handler = open(self.stdout_output, "w+") _stderr_handler = open(self.stderr_output, "w+") command = ['nmap', '-T', 'Aggressive', '-n', '-F', '-iL', '"/home/adriano/umit/test/targets"'] command_process = Popen(command, bufsize=1, stdin=PIPE, stdout=_stdout_handler.fileno(), stderr=_stderr_handler.fileno(), shell=False) The problem seens to be the double quoted path. But it doesn't make any sense for me, as any other command that I put there works fine. Any clue? Cheeers! -- Adriano Monteiro Marques http://umit.sourceforge.net [EMAIL PROTECTED] "Don't stay in bed, unless you can make money in bed." - George Burns -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking For mp3 ID Tag Module
Tim Daneliuk wrote: > Iñigo Serna wrote: > > On 8/18/06, Tim Daneliuk <[EMAIL PROTECTED]> wrote: > >> > try mutagen. > >> http://www.sacredchao.net/quodlibet/wiki/Development/Mutagen > >> > >> This module is more-or-less exactly what I needed. However, I am running > >> into problems when the filenames or ID tags have unicode characters in > >> them. > >> > >> Typically, I do something like: > >> > >> from mutagen.easyid3 import EasyID3 > >> > >> audio["title'] = Something based on the filename that has unicode > >> chars in it > >> > >> I then get this: > >> > >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position > >> 56: ordinal not in range(128) > > > >> From the docs: > > """Mutagen has full Unicode support for all formats. When you assign > > text strings, we strongly recommend using Python unicode objects > > rather than str objects. If you use str objects, Mutagen will assume > > they are in UTF-8.""" > > > > So I suppose the value you try to assign as title is not unicode, > > check the encoding used in the file system. > > > > Iñigo > > I am trying to set the title based on the filename. The file is in a Win32 > NTFS filesystem, so it could have non-ASCII chars in it. What I am stumbling > on it how to coerce it into unicode. I have tried: > > name = filename.split() blah blah blah > audio["title"] = unicode(name) > > But I still get this error. I am not real up to speed on the whole unicode > end of things, so any kind suggestions would be most welcome. > > By the way, I believe the offending string contains a German umlaut, at least > in one > of the cases. > > To get the MP3's name, use os.path.basename (I'm guessing that's what your split() is for?) Looking at the mutagen tutorial, most of the tags are lists of unicode strings, so you might want to try audio["title"] = [unicode(name)], instead of audio["title"] = unicode(name). This might be your problem when reading the tags, too. Iain -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess quote problem
Adriano Monteiro wrote: > I'm working on a script that executes a command with arbitrary > options. Most of its options works fine with subprocess, but at least > one (as far as I know) is giving me a headache. The program that I'm > trying to execute is Nmap, and the problematic option is the -iL, that > is used to indicate a file with the targets that nmap should scan. > > If I open my terminal, and write: nmap -iL "/tmp/target_list" , nmap > picks the file, read it and scan every target written inside it. when you do this, the shell strips away the quotes and passes the strings "-iL" and "/tmp/target_list" to the nmap executable. > But, if I try to use the same scan on my command execution script, it > makes nmap raise a strange error: > > "Failed to open input file "/home/adriano/umit/test/targets" for reading > QUITTING!" subprocess does quoting itself, so those extra quotes are passed through to nmap itself. try removing them from the string literal; they're not really part of the argument value. -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Sybren Stuvel wrote: >> Why not make sum work for strings too? > > Because of "there should only be one way to do it, and that way should > be obvious". I would have thought that "performance" and "proper use of English" was more relevant, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Sybren Stuvel <[EMAIL PROTECTED]> writes: > Because of "there should only be one way to do it, and that way should > be obvious". There are already the str.join and unicode.join methods, Those are obvious??? -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess confusion: how file-like must stdin be?
In article <[EMAIL PROTECTED]>, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: >Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: >> On Thu, 17 Aug 2006 17:16:25 +, [EMAIL PROTECTED] (Cameron Laird) >> declaimed the following in comp.lang.python: >> >> > Question: >> > import subprocess, StringIO >> > >> > input = StringIO.StringIO("abcdefgh\nabc\n") >> >> Here you override the builtin function "input()" >> > # I don't know of a compact, evocative, and >> > # cross-platform way to exhibit this behavior. >> > # For now, depend on cat(1). >> > p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, >> >stdin = response) >> >> Here you specify the non-existant "response" > >Assume the OP meant to write this > import subprocess, StringIO inp = StringIO.StringIO("abcdefgh\nabc\n") p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, stdin = inp) >Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.4/subprocess.py", line 534, in __init__ >(p2cread, p2cwrite, > File "/usr/lib/python2.4/subprocess.py", line 830, in _get_handles >p2cread = stdin.fileno() >AttributeError: StringIO instance has no attribute 'fileno' . . . Yes; my apologies for the confusion I introduced by "editing for publication", and doing it badly. Your interactive session does indeed exhibit the behavior that puzzles me. My expectation was that StringIO and the std* parameters to Popen() were made for each other; certainly there are many cases where stdout and stderr can be redirected *to* a StringIO. Is it simply the case that stdin demands a more file-like object? While that disappoints me, I certainly can program around it. My question, then: does stdin effectively require something really in the filesystem, or perhaps the stdout of a previous subprocess? Is there no built-in way to feed it an in-memory construct? -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Paul Rubin wrote: > Sybren Stuvel <[EMAIL PROTECTED]> writes: >> Because of "there should only be one way to do it, and that way should >> be obvious". There are already the str.join and unicode.join methods, > > Those are obvious??? Why would you try to sum up strings? Besides, the ''.join idiom is quite common in Python. In this special case, ''.join is much faster than sum() which is why sum() denies to concat strings. Georg -- http://mail.python.org/mailman/listinfo/python-list
RE: MS SQL Server: NT Authentication. Possible?
[Dirk Hagemann] | I think the adodbapi module is interesting. I just tried it | out but got this error: | 'Exception occurred.', (0, 'Microsoft OLE DB Provider for ODBC | Drivers', "[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed | for user '(null)'. Reason: Not associated with a trusted SQL Server | connection.", None, 0, -2147217843), None) | Do I have to make some settings at the MS SQL Server? Yes: your (Windows) user has to be set up by one means or another to allow trusted connection to the db. I'm not really a SQL Server DBA but I believe it's easy enough to set up. | I just can't find a simple example how to use adodbapi | with NT authentication... This works for me against a database I know I have trusted access to (eg via Query Analyzer). The server is VODEV1, the database is EVOBACK. The rest is boilerplate. import adodbapi db = adodbapi.connect ("Provider=sqloledb;Data Source=VODEV1;Initial Catalog=EVOBACK;Integrated Security=SSPI;") q = db.cursor () q.execute ("SELECT SYSTEM_USER") print q.fetchone () q.close () TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Clean way to not get object back from instantiation attempt gone bad
tobiah wrote: > Suppose I do: > > > myfoo = Foo('grapes', 'oranges') > > And in the __init__() of Foo, there is > a real problem with the consumption of fruit. > Is there a clean way to ensure that myfoo > will be None after the call? Would the > __init__() just do del(self), or is there > a better way to think about this? There is a way, of course, that results in myfoo being None in case of an error, but it is not a one-liner and I'd not recommend it. If something goes wrong, raising an exception is the best thing to do. Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: Optimizing Inner Loop Copy
"Mark E. Fenner" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello all, > > > Here's my class of the objects being copied: > > class Rule(list): > def __init__(self, lhs=None, rhs=None, nClasses=0, nCases=0): > self.nClasses = nClasses > self.nCases = nCases > Ok, so here are some "bigger picture" kind of questions. 1. Do you need to construct all these Rule objects in the first place? One of the optimizations I did in pyparsing was to pre-construct exception objects, and to reuse them over and over instead of creating them once, raising them, and then discarding them. (There is a trade-off with thread-safety when you do this, but we deal with that separately.) This gave me about a 30% reduction in processing time, since pyparsing does a lot of exception raising/catching internally. So you might look at your larger app and see if you could memoize your Rule objects or something similar, and avoid the whole object create/init/delete overhead in the first place. 2. More of an OO question than a performance question, but why does Rule inherit from list in the first place? Is Rule *really* a list, or is it just implemented using a list? If the latter, then you might look at moving Rule's list contents into an instance variable, maybe something called self.contents. Then you can be more explicit about appending to self.contents when you want to add lhs to the contents of the Rule. For example, why are you calling extend, instead of just using slice notation to copy lhs? Ah, because then you would have to write something like "self = lhs[:]", which doesn't look like it will work very well. On the other hand, if you use containment/delegation instead of inheritance, you can use the more explicit "self.contents = lhs[:]". In fact now you have much more control over the assemblage of rules from other rules. In the original post, you state: "the left hand side of a rule (e.g., a rule is a & b & c -> d) is self and three other pieces of information are kept around, two ints and a right hand side" What other aspects of list are you using in Rule? Are you iterating over its contents somewhere? Then implement __iter__ and return iter(self.contents). Are you using "if rule1:" and implicitly testing if its length is nonzero? Then implement __nonzero__ and return operator.truth(self.contents). Do you want to build up rules incrementally using += operator? Then implement __iadd__ and do self.contents.extend(other.contents), or self.contents += other.contents[:] (no need to test for None-ness of other.contents, we ensure in our constructor that self.contents is always a list, even if its an empty one). Save inheritance for the true "is-a" relationships among your problem domain classes. For instance, define a base Rule class, and then you can extend it with things like DeterministicRule, ProbabilisticRule, ArbitraryRule, etc. But don't confuse "is-implemented-using-a" with "is-a". -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Text to MP3 using pyTTS - Non-programmer question
I'm not a programmer, but I'd like to make a program that will open and read a txt file and output to a mp3 file. I don't need to ever hear the voice, but I'd like the program to direct I've been google'ing around and have found a few tutorials about converting pdfs to mp3 and converting typed text (in the source file) to wave, but I'm looking for the ability to directly convert from txt to mp3/ogg/wma. Currently I'm running on WinXP, but I also have access to a Linux box. Any help would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: MS SQL Server: NT Authentication. Possible?
Hi Tim! I think the adodbapi module is interesting. I just tried it out but got this error: 'Exception occurred.', (0, 'Microsoft OLE DB Provider for ODBC Drivers', "[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.", None, 0, -2147217843), None) Do I have to make some settings at the MS SQL Server? I just can't find a simple example how to use adodbapi with NT authentication... Dirk -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess confusion: how file-like must stdin be?
Cameron Laird a écrit : > In article <[EMAIL PROTECTED]>, > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: >> Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: >>> On Thu, 17 Aug 2006 17:16:25 +, [EMAIL PROTECTED] (Cameron Laird) >>> declaimed the following in comp.lang.python: >>> Question: import subprocess, StringIO input = StringIO.StringIO("abcdefgh\nabc\n") >>> Here you override the builtin function "input()" # I don't know of a compact, evocative, and # cross-platform way to exhibit this behavior. # For now, depend on cat(1). p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, stdin = response) >>> Here you specify the non-existant "response" >> Assume the OP meant to write this >> > import subprocess, StringIO > inp = StringIO.StringIO("abcdefgh\nabc\n") > p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, stdin = inp) >> Traceback (most recent call last): >> File "", line 1, in ? >> File "/usr/lib/python2.4/subprocess.py", line 534, in __init__ >>(p2cread, p2cwrite, >> File "/usr/lib/python2.4/subprocess.py", line 830, in _get_handles >>p2cread = stdin.fileno() >> AttributeError: StringIO instance has no attribute 'fileno' > . > . > . > Yes; my apologies for the confusion I introduced by "editing > for publication", and doing it badly. > > Your interactive session does indeed exhibit the behavior that > puzzles me. My expectation was that StringIO and the std* > parameters to Popen() were made for each other; certainly there > are many cases where stdout and stderr can be redirected *to* a > StringIO. Is it simply the case that stdin demands a more > file-like object? While that disappoints me, I certainly can > program around it. My question, then: does stdin effectively > require something really in the filesystem, or perhaps the > stdout of a previous subprocess? Is there no built-in way to > feed it an in-memory construct? As this is a pipe at OS level, there may be no other way than using os-level tools (ie. real files with fileno), maybe creating an anonymous pipe, writing to it (relying on pipe buffering by the OS to avoid the creation of a writer thread), and giving this pipe (which should have a fileno) to the subprocess.Popen stdin parameter. Such a construction (pipe/writer thread) would be welcome as standard subprocess tool. A+ Laurent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Clean way to not get object back from instantiation attempt gone bad
tobiah wrote: > Suppose I do: > > > myfoo = Foo('grapes', 'oranges') > > And in the __init__() of Foo, there is > a real problem with the consumption of fruit. > Is there a clean way to ensure that myfoo > will be None after the call? Would the > __init__() just do del(self), or is there > a better way to think about this? > > Thanks, > > Toby As others have said, just raise an exception. You can hide instantiation inside a factory function to simulate the behaviour you're specifically talking about: class Foo: def __init__(self, *args): for arg in args: if is_fruit(arg): raise RuntimeError("I don't like fruit") def FooFactory(*args): try: return Foo(*args) except RuntimeError: return None -Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Optimizing Inner Loop Copy
Paul McGuire wrote: > "Mark E. Fenner" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Hello all, >> > >> >> Here's my class of the objects being copied: >> >> class Rule(list): >> def __init__(self, lhs=None, rhs=None, nClasses=0, nCases=0): >> self.nClasses = nClasses >> self.nCases = nCases >> > Ok, so here are some "bigger picture" kind of questions. > > 1. Do you need to construct all these Rule objects in the first place? Sorry, I had a nice response written out ... and I lost it. Here's the summary. Unfortunately, yes, the algorithm this code implements goes to great lengths to ensure that each possible Rule is generated only once. > > 2. More of an OO question than a performance question, but why does Rule > inherit from list in the first place? Is Rule *really* a list, or is it > just implemented using a list? It is the later. And it is a moderate abuse to say that the Rule _isa_ list. Aside from the two integer statistics (nClasses, nCounts), the RHS and LHS can be merged and we can say that the rule is [(tuple1), ..., (tupleN), (tupleRHS)] with the RHS being Rule[-1]. However, in that case, I went for OO principles and kept the two logical parts separate. B/c of the frequency of list operations, it's better to be able to use thisRule.append() or thisRule[i] then thisRule.lhs.append() or thisRule.lhs[i]. Where speed doesn't matter, I have the more appropriate thisRule.addLHS(). Yes, I could do "dot removal" (i.e., localize the attribute lookups), but when we iterate over a whole set of Rules, this still leave the localization assignment inside an inner loop. > If the latter, then you might look at > moving Rule's list contents into an instance variable, maybe something > called > self.contents. Then you can be more explicit about appending to > self.contents when you want to add lhs to the contents of the Rule. For > example, why are you calling extend, instead of just using slice notation > to > copy lhs? Ah, because then you would have to write something like "self = > lhs[:]", which doesn't look like it will work very well. On the other > hand, if you use containment/delegation instead of inheritance, you can > use the > more explicit "self.contents = lhs[:]". In fact now you have much more > control over the assemblage of rules from other rules. > Fortunately, the Rules are only assembled in one way ... appending to that copy that started the thread. Incidentally, by speeding up Rule.__init__ and inlining it (instead of calling Rule.copy which called Rule.__init__), that is no longer my bottleneck *phew*. > In the original post, you state: "the left hand side of a rule (e.g., a > rule is a & b & c -> d) is self and three other pieces of information are > kept around, two ints and a right hand side" > > What other aspects of list are you using in Rule? Are you iterating over > its contents somewhere? Then implement __iter__ and return > iter(self.contents). Are you using "if rule1:" and implicitly testing if > its length is nonzero? Then implement __nonzero__ and return > operator.truth(self.contents). Do you want to build up rules > incrementally > using += operator? Then implement __iadd__ and do > self.contents.extend(other.contents), or self.contents += > other.contents[:] (no need to test for None-ness of other.contents, we > ensure in our constructor that self.contents is always a list, even if its > an empty one). > Well, I do several of these things ... many of them inside inner loops (there's a sequence of inner loops ... the algorithms choice, not mine). Each of these that are implemented (and not left to Python's builtin list methods), is an extra level of function call overhead. This has been a secondary project for me over a number of years ... so I have to look at my early revisions, but I think my original architecture was an explicit self.lhs = [] attribute. And it was REALLY slow. When Python allowed inheritence from builtin objects, I tried it and got a nice win (I think!). > Save inheritance for the true "is-a" relationships among your problem > domain > classes. For instance, define a base Rule class, and then you can extend > it with things like DeterministicRule, ProbabilisticRule, ArbitraryRule, > etc. But don't confuse "is-implemented-using-a" with "is-a". > Well, I know the difference and choose to break the rule intentionally *chuckle*. After the initial prototype, speed trumped OO. > -- Paul Thanks for your comments, Paul. Regards, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Optimizing Inner Loop Copy
"Mark E. Fenner" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Save inheritance for the true "is-a" relationships among your problem > > domain > > classes. For instance, define a base Rule class, and then you can extend > > it with things like DeterministicRule, ProbabilisticRule, ArbitraryRule, > > etc. But don't confuse "is-implemented-using-a" with "is-a". > > > > Well, I know the difference and choose to break the rule intentionally > *chuckle*. After the initial prototype, speed trumped OO. > > > -- Paul > > Thanks for your comments, Paul. > > Regards, > Mark hmm... maybe I should consider making ParseResults inherit from list... -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Charts in Excel with pyExcelerator.ExcelMagic
Gentlemen, Thanks for your responses. I also found some additional threads on this newsgroup that gave me insight into how to use the MS Excel com objects (or whatever they are called)... So I used this: xl = win32com.client.Dispatch("Excel.Application") wb = xl.Workbooks.Open(outfile01) prodws = wb.Worksheets(1) wc_prod = wb.Charts.Add() wc_prod.ChartWizard(Source=prodws.Range("b1", "g30"), Gallery=11, Format=5, CategoryLabels=3, SeriesLabels=3, PlotBy=None, Title="Prod" ) Does a pretty decent job of creating charts (we can change the chart type by changing the Gallery and Format values) So I use pyExcelerator to generate the workbook with various worksheets and then use win32com.client to generate the charts. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 or mysqldb?
Paul Boddie wrote: > There's plenty of scope for writing non-standard SQL even in the most > common operations. Moreover, defining tables can be awkward because the > set of supported data types and the names used can vary in a seemingly > unnecessary fashion between systems. Good point. I forgot that sqlite doesn't have as strict of data typing as mysql, so that might cause some problems as well. Oh well, basically I'm just looking for something to learn from, so it's still probably better to go with a simpler one that I will still be able to apply to the more complex ones if needed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess confusion: how file-like must stdin be?
Cameron Laird wrote: > Your interactive session does indeed exhibit the behavior that > puzzles me. My expectation was that StringIO and the std* > parameters to Popen() were made for each other; certainly there > are many cases where stdout and stderr can be redirected *to* a > StringIO. Is it simply the case that stdin demands a more > file-like object? While that disappoints me, I certainly can > program around it. My question, then: does stdin effectively > require something really in the filesystem, or perhaps the > stdout of a previous subprocess? Is there no built-in way to > feed it an in-memory construct? set the appropriate stream to subprocess.PIPE, and write to it. p = subprocess.Popen(..., stdin=subprocess.PIPE) p.stdin.write("hello") p.stdin.close() # signal end of file -- http://mail.python.org/mailman/listinfo/python-list
Documenting a package with Pydoc
I have searched this group and the wider net to find an answer to this, but I haven't been successful. Pydoc seems to be capable of writing documentation for all modules within a package by simply pointing it to the package on the command line... pydoc -w Certainly, the method writedocs() appears to descend into a directory and create docs for each importable object. Perhaps I'm doing something wrong but when I do this, pydoc reports that no Python documentation can be found for each of the contents of the package. Of course, if I point pydoc directly to the modules, it succeeds. Am I doing something wrong? Cheers, Rob C -- http://mail.python.org/mailman/listinfo/python-list
How to draw line on Image?
Hello all: I want to draw some shapes, such as lines, circles on an image. The input to the program is an image and the output from the program is a superimposed image. what kind of document or functions I should take a look for searching this question? The program doesn't show the image, but draws some shapes on the input image. Thank you -daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: How to draw line on Image?
"Daniel Mark" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I want to draw some shapes, such as lines, circles on an image. http://www.pythonware.com/library/pil/handbook/psdraw.htm hth, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: crash in wx.TreeListCtrl SelectItem()
Hi, > I have a strange crash (segfault on FreeBSD) that I can not reliably > reproduce > and therefore unfortunately can not provide a self contained test case at the > moment. > > Here is what I do (and what works almost always, but sometimes crashes): > > 1) find an item in a wx.TreeListCtrl by its pydata (code posted to this list) > 2) if the item is found: > a) call EnsureVisible(foundItem) > b) call SelectItem(foundItem) > > The call to EnsureVisible() always returns, but SelectItem() crashes python > sometimes. > > foundItem on a crash is something like this: > _a0d0c708_p_wxTreeItemId> > > calling GetPyData(foundItem) returns the correct pydate. > > Any ideas what could be happening or how to further debug this? Try anyway to reproduce with a sample. The only way I know in this case is to split the code and see if it happens again. If so, split again, and again, and so on... It can be long, but the only way. Very often, you'll find yourself the buggy part. Once time you'll have a sample, post it, I can try on linux and windows. Also please give the versions of the softwares you use. rgds jm -- http://mail.python.org/mailman/listinfo/python-list
Re: Text to MP3 using pyTTS - Non-programmer question
[EMAIL PROTECTED] writes: > I'm not a programmer, but I'd like to make a program that will open and > read a txt file and output to a mp3 file. I don't need to ever hear the > voice, but I'd like the program to direct > > I've been google'ing around and have found a few tutorials about > converting pdfs to mp3 and converting typed text (in the source file) > to wave, but I'm looking for the ability to directly convert from txt > to mp3/ogg/wma. > > Currently I'm running on WinXP, but I also have access to a Linux box. > > Any help would be appreciated. I have written a script to convert .pdf to .wma, which may get you started: #! /usr/bin/env python # -*- coding: iso-latin-1 -*- import os import sys basename, suffix = os.path.splitext(sys.argv[1]) suffix = suffix.lower() pdfname = basename + ".pdf" txtname = basename + ".txt" wavname = basename + ".wav" # pdf --> txt if suffix == ".pdf": os.system('pdftotext "%s"' % (pdfname, )) suffix = ".txt" # txt --> wav if suffix == ".txt": import re data = open(txtname).read() data = data.replace(". . .", "") data = data.replace("<", "") data = data.replace(">", "") data = data.replace("Mr.", "Mister") data = data.replace("«", '"') data = data.replace("»", '"') data = data.replace(',,', '"') data = re.sub("\\d+\\s*", "", data) data = re.sub("\n\\s*\\d+\\.*\\s*\n", "\n", data) data = re.sub("\n\\s*\n\\s*\n", "\n\n", data) data = re.sub("-([a-z])", "\\1", data) open(txtname, "w").write(data) import pyTTS tts = pyTTS.Create() tts.SetRate(0) tts.Volume = 100 tts.SetVoiceByName("ATT-DT-14-Klara16") tts.SpeakToWave(wavname, data) suffix = ".wav" # split, wav --> mp3/ogg/wma if suffix == ".wav": import wave os.mkdir(basename) fi = wave.open(wavname, "r") nchannels, sampwidth, framerate, nframes, comptype, compname = fi.getparams() n = 0 while 1: n += 1 data = fi.readframes(600 * framerate) if not data: break fo = wave.open("tmp.wav", "w") fo.setparams((nchannels, sampwidth, framerate, 0, comptype, compname)) fo.writeframes(data) fo.close() # os.system('lame -m m --cbr -b 32 -q 0 -S tmp.wav "%s\\%02d.mp3" "%s"' % (basename, n)) # os.system('oggenc -q -1 -o "%s\\%02d.ogg" tmp.wav' % (basename, n)) os.system('cscript WMCmd.vbs -profile a20_1 -input tmp.wav -output "%s\\%02d.wma' % (basename, n)) fi.close() os.remove("tmp.wav") os.remove(wavname) ### This is just too big to keep around -- Dieter Deyke mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Vs lbh pna ernq guvf, lbh unir jnl gbb zhpu gvzr. -- http://mail.python.org/mailman/listinfo/python-list
Re: MS SQL Server: NT Authentication. Possible?
My windows-user has already access-permission to the database. Thanks for the exmaple - I will try it out on monday! :-) Enjoy your weekend! Dirk -- http://mail.python.org/mailman/listinfo/python-list
Type conversion?
I have the following code... import array len32 = array.array('L') len16 = array.array('H') len32.append(0) len16.append(0) y = len32[0] print y.__class__ z = len16[0] print z.__class__ how can I change Zs type to long? Or how how can I change an arrays type? -- http://mail.python.org/mailman/listinfo/python-list
Simple Python App Server
I use the pyGTD script to manage my todo lists and such. From Vim, I shell out a call to the gtd.py script, which updates my todo.txt file after update one of the related pyGTD files. Since I make a lot of updates to the related pyGTD files, I execute the gtd.py script dozens of times a day. The problem is that this script can be a little slow. It usually takes at least 5 seconds to run, time that I can't use Vim (and running it in the background from Vim isn't a usable option for me). I tried making it run faster by adding the following lines at the top of the __main__ method: import psyco psyco.full() This change, however, didn't shave off any noticeable amount of time. I was wondering if there was a way in which I could run the python interpreter all of the time so that I wouldn't have to invoke it each time that I want to run the gtd.py script. Is there a way to do this?o Thanks in advance! Tom Purl -- http://mail.python.org/mailman/listinfo/python-list
Re: Type conversion?
KraftDiner wrote: > I have the following code... > > import array > len32 = array.array('L') > len16 = array.array('H') > > len32.append(0) > len16.append(0) > > y = len32[0] > print y.__class__ > > z = len16[0] > print z.__class__ > > > how can I change Zs type to long? z_long = long(z) type(z_long) > Or how how can I change an arrays type? -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Paul Rubin: > Sybren Stuvel: > > Because of "there should only be one way to do it, and that way should > > be obvious". There are already the str.join and unicode.join methods, > > Those are obvious??? They aren't fully obvious (because they are methods of the separator string), but after reading some documentation about string methods, and after some tests done on the Python shell, you too can probably use then without much problems. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
[EMAIL PROTECTED] wrote: > Paul Rubin: > >>Sybren Stuvel: >> >>>Because of "there should only be one way to do it, and that way should >>>be obvious". There are already the str.join and unicode.join methods, >> >>Those are obvious??? > > > They aren't fully obvious (because they are methods of the separator > string), but after reading some documentation about string methods, and > after some tests done on the Python shell, you too can probably use > then without much problems. > Using a bound method can make it a little more obvious. >>> cat = "".join >>> cat(['one', 'two', 'three']) 'onetwothree' >>> cat([u'one', u'two', u'three']) u'onetwothree' >>> regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: How to draw line on Image?
"David Isaac" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Daniel Mark" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > I want to draw some shapes, such as lines, circles on an image. > > > http://www.pythonware.com/library/pil/handbook/psdraw.htm > > hth, > Alan Isaac > > ImageDraw (http://www.pythonware.com/library/pil/handbook/imagedraw.htm) might be more generally helpful than PSDraw. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Need a compelling argument to use Django instead of Rails
Damjan wrote:> > Starting a new Apache process with python included (trough mod_python) is > even worse than CGI. Yes, but I think only for the first interaction after being dormant for a period. In fact I've noticed that hitting http://www.xfeedme.com the first time is usually slow. But once the apache is up it seems to stay up until it has been inactive for a good while, and it's fast. I'm inferring all this from what I see using "ps" and other indirect tools. -- Aaron Watters === as the poet said: "Everybody have fun tonight Everybody Wang Chung tonight" -- http://mail.python.org/mailman/listinfo/python-list
amd64
Does anyone know if it's possible to run python as a 32 bit app on AMD64's? One of our host providers AMD Athlon 64 3000+ and we are currently using a celeron which is real slow. The problem is that this machine would be a backup for another which is 32 pentium 4. If I have to recompile/debug all the extensions etc etc for another architecture it might not seem so attractive. -not ready for 64bitly yrs- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess confusion: how file-like must stdin be?
In article <[EMAIL PROTECTED]>, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Cameron Laird wrote: > >> Your interactive session does indeed exhibit the behavior that >> puzzles me. My expectation was that StringIO and the std* >> parameters to Popen() were made for each other; certainly there >> are many cases where stdout and stderr can be redirected *to* a >> StringIO. Is it simply the case that stdin demands a more >> file-like object? While that disappoints me, I certainly can >> program around it. My question, then: does stdin effectively >> require something really in the filesystem, or perhaps the >> stdout of a previous subprocess? Is there no built-in way to >> feed it an in-memory construct? > >set the appropriate stream to subprocess.PIPE, and write to it. > >p = subprocess.Popen(..., stdin=subprocess.PIPE) >p.stdin.write("hello") >p.stdin.close() # signal end of file . . . Of course! My; it's a sign of how far I was from the right subprocess mentality that I so missed what is obvious after the fact. The source code (for the 2.4 release) also comes close to making it clear, as I realized about the time you posted your follow-up, Fredrik. Is this--streaming data to a subprocess--too lightweight to deserve write-up in the (online) Cookbook? I'll volunteer. In retrospect, I see there are plenty of examples on-line of the usage, but I don't think an ignorant searcher (like me) will find them on his own. Thanks, Fredrik. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to draw line on Image?
Paul McGuire wrote: > "David Isaac" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>"Daniel Mark" <[EMAIL PROTECTED]> wrote in message >>news:[EMAIL PROTECTED] >> >>>I want to draw some shapes, such as lines, circles on an image. >> >> >>http://www.pythonware.com/library/pil/handbook/psdraw.htm >> >>hth, >>Alan Isaac >> >> > > > ImageDraw (http://www.pythonware.com/library/pil/handbook/imagedraw.htm) > might be more generally helpful than PSDraw. > > -- Paul > > And if the quality of the result is important maybe (maybe, because I haven't used it yet myself) aggdraw an add-on to the PIL library that supports anti-aliased drawing http://effbot.org/zone/draw-agg.htm Claudio Grondi -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Sybren Stuvel wrote: > Paddy enlightened us with: > > Well, after all the above, there is a question: > > > > Why not make sum work for strings too? > > Because of "there should only be one way to do it, and that way should > be obvious". There are already the str.join and unicode.join methods, > which are more powerful than sum. > > Sybren I get where you are coming from, but in this case we have a function, sum, that is not as geeral as it could be. sum is already here, and works for some types but not for strings which seems an arbitrary limitation that impede duck typing. - Pad. P.S. I can see why, and am used to the ''.join method. A newbie introduced to sum for integers might naturally try and concatenate strings using sum too. -- http://mail.python.org/mailman/listinfo/python-list
Re: Type conversion?
Rob Cowie wrote: > KraftDiner wrote: > > I have the following code... > > > > import array > > len32 = array.array('L') > > len16 = array.array('H') > > > > len32.append(0) > > len16.append(0) > > > > y = len32[0] > > print y.__class__ > > > > z = len16[0] > > print z.__class__ > > > > > > how can I change Zs type to long? > > z_long = long(z) > type(z_long) > > > > Or how how can I change an arrays type? In C++ you can cast one class type to another if you override the operator= Then you can convert one class type to another... In Python it would appear that the left hand side of the assignment operator is not used to determine if a cast is necessary. So how would I do this in python? a = classA() b = classB() b = a In the end b would end up just being a refrence to a no conversion would have been done. -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Sybren Stuvel wrote: > Paddy enlightened us with: > > Well, after all the above, there is a question: > > > > Why not make sum work for strings too? > > Because of "there should only be one way to do it, and that way should > be obvious". There are already the str.join and unicode.join methods, > which are more powerful than sum. > > Sybren > -- > The problem with the world is stupidity. Not saying there should be a > capital punishment for stupidity, but why don't we just take the > safety labels off of everything and let the problem solve itself? > Frank Zappa Here is where I see the break in the 'flow': >>> 1+2+3 6 >>> sum([1,2,3], 0) 6 >>> [1] + [2] +[3] [1, 2, 3] >>> sum([[1],[2],[3]], []) [1, 2, 3] >>> '1' + '2' + '3' '123' >>> sum(['1','2','3'], '') Traceback (most recent call last): File "", line 1, in ? TypeError: sum() can't sum strings [use ''.join(seq) instead] >>> - Pad. -- http://mail.python.org/mailman/listinfo/python-list
Re: Type conversion?
KraftDiner wrote: > In C++ you can cast one class type to another if you override the > operator= > Then you can convert one class type to another... > In Python it would appear that the left hand side of the assignment > operator > is not used to determine if a cast is necessary. > So how would I do this in python? > > a = classA() > b = classB() > b = a > > In the end b would end up just being a refrence to a (You aren't quite correct there: the name 'b' would refer to the same object as is referred to by the name 'a'. However there is nothing associating the two names 'b' and 'a', so no reference from 'b' to 'a'.) > no conversion would have been done. You just have to call the appropriate constructor: b = classB(a) So long as the constructor for classB knows how to create an instance from a classA instance this will have the desired effect. So: aStr = str(anInt) aFloat = float(anInt) ...and so on... -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python App Server
On 2006-08-18, tom.purl <[EMAIL PROTECTED]> wrote: > I use the pyGTD script to manage my todo lists and such. From > Vim, I shell out a call to the gtd.py script, which updates my > todo.txt file after update one of the related pyGTD files. > Since I make a lot of updates to the related pyGTD files, I > execute the gtd.py script dozens of times a day. Was your Vim compiled with the +python feature (this enables several Vim commands to run python code directly in Vim)? I don't know if that would speed things up or not, but it's worth a try. If the feature is present, you can run a Python script with the :pyfile command. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python App Server
tom.purl schrieb: > I use the pyGTD script to manage my todo lists and such. From Vim, I > shell out a call to the gtd.py script, which updates my todo.txt file > after update one of the related pyGTD files. Since I make a lot of > updates to the related pyGTD files, I execute the gtd.py script dozens > of times a day. > > The problem is that this script can be a little slow. It usually takes > at least 5 seconds to run, time that I can't use Vim (and running it in > the background from Vim isn't a usable option for me). I tried making > it run faster by adding the following lines at the top of the __main__ > method: > > import psyco > psyco.full() > > This change, however, didn't shave off any noticeable amount of time. > > I was wondering if there was a way in which I could run the python > interpreter all of the time so that I wouldn't have to invoke it each > time that I want to run the gtd.py script. Is there a way to do this?o Sure. Just enter a loop. Incidentially, common application server frameworks as SimpleXMLRPC or pyro come with a main event loop which will of course prevent the interpreter to stop. Together with the daemonize-recipe from apsn, you have your server. I suggest you use pyro - that will most probably cause the least fuss. Diez -- http://mail.python.org/mailman/listinfo/python-list
soap comlex data to plain xml
Hi all,would anyone give me a hint how to get SOAP data as plain XML and not as complex datathis is sample code: myProxy = SOAPpy.SOAPProxy(MY_SERVICE_PATH, header = my_headers) query = SOAPpy.structType () result = myProxy.callMyProcedure(query) result returned as complex data, but i need plain xml text - kind of you see when myProxy.config.dumpSOAPIn = 1thank you in advance.~GB -- http://mail.python.org/mailman/listinfo/python-list
couple more questions about sqlite
I've been looking around and reading, and I have a few more questions about SQLite in particular, as it relates to Python. 1. What is the current module to use for sqlite? sqlite3? or is that not out until Python 2.5? 2. What's the difference between sqlite and pysqlite? Do you need both, just one, or is one an older version of the same thing? 3. What's the difference between the command line program called sqlite3 and the module you would use with Python? (I know that the former let's you do normal database things without dealing with Python, but is it necessary if you are using Python to interact with the DB?) Thanks! -- http://mail.python.org/mailman/listinfo/python-list
a bug in list.remove?
Hi all, I have 2 lists. What Im doing is check the first list and remove all occurances of the elements in the second list from the first list, like so: >>> ps = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] >>> qs = [6,7,8,9,10,11,12,1,2] >>> for p in ps: if p in qs: ps.remove(p) The problem Im having is that when I do >>> print ps it gives me [2, 3, 4, 5, 7, 9, 11, 13, 14, 15] which is incorrect since 2,7,9,11 shouldnt be in that list. Is this a bug in .remove? or is my algorithm somewhat flawed? Thanks for your help! Cheers Astan -- http://mail.python.org/mailman/listinfo/python-list
how do you get the name of a dictionary?
Hello! Does anyone know how to find the name of a python data type. Conside a dictionary: Banana = {} Then, how do i ask python for a string representing the name of the above dictionary (i.e. 'Banana')? thanks to anyone who has time to answer this nube question! jojoba -- http://mail.python.org/mailman/listinfo/python-list
Disable close button in management window.(KDE- pyQT)
Hi,,, Is possible disable the close button in KDE management window? Using python+qt? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: amd64
"Robin Becker" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Does anyone know if it's possible to run python as a 32 bit app on AMD64's? One > of our host providers AMD Athlon 64 3000+ and we are currently using a celeron > which is real slow. The problem is that this machine would be a backup for > another which is 32 pentium 4. > > If I have to recompile/debug all the extensions etc etc for another architecture > it might not seem so attractive. > -not ready for 64bitly yrs- > Robin Becker > Running just fine on my AMD64 processor on this machine... I'm pretty sure AMD worked pretty hard for their AMD64's to run 32-bit apps - by contrast with Intel's previous 64-bit offerings which would not. But in this mode, you don't get 64-bits of "roominess", it looks just like a 32-bit CPU. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
> Does anyone know how to find the name of a python data type. > > Conside a dictionary: > > Banana = {} > > Then, how do i ask python for a string representing the name of the > above dictionary (i.e. 'Banana')? AFAIK, there's no easy/good way of doing this because that name is just a handle to an internal object. Observe: >>> banana = {} >>> spatula = banana >>> spatula[42] = 'drangle' >>> banana {42: 'drangle'} >>> id(spatula) 10304800 >>> id(banana) 10304800 What does it mean to ask for the name of object ID 10304800? it's both "banana" and "spatula". One might be able to use the decompiler libraries and wend one's way through the dark recesses of python's internals to extract such information, but this is certainly not a beginner's task. How would you ask for the object? >>> print get_name(banana) you might as well write >>> print "banana" :) Hope this makes sense... -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: amd64
Robin Becker wrote: > Does anyone know if it's possible to run python as a 32 bit app on AMD64's? > One > of our host providers AMD Athlon 64 3000+ and we are currently using a celeron > which is real slow. The problem is that this machine would be a backup for > another which is 32 pentium 4. > > If I have to recompile/debug all the extensions etc etc for another > architecture > it might not seem so attractive. > -not ready for 64bitly yrs- > Robin Becker Most 64 bit processors can run 32 bit apps natively, so the short answer would be yes. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
jojoba wrote: > Hello! > > Does anyone know how to find the name of a python data type. > > Conside a dictionary: > > Banana = {} > > Then, how do i ask python for a string representing the name of the > above dictionary (i.e. 'Banana')? > > thanks to anyone who has time to answer this nube question! > jojoba here is an easy hack, I don't know if there is an explicit function. for i in dir(): if eval(i) == Banana: print i -- http://mail.python.org/mailman/listinfo/python-list
Re: a bug in list.remove?
Astan Chee: (This is a small trap of Python, that it shares with some other languages, and it shows that it may exist a language with a higher level than Python.) Generally in Python you can't modify a sequence that you are iterating on. There are some ways to avoid the problem. You can create a duplicate of the ps list: ps = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] qs = [6,7,8,9,10,11,12,1,2] for p in ps[:]: if p in qs: ps.remove(p) print ps Or: for p in list(ps): if p in qs: ps.remove(p) print ps Or: import copy for p in copy.copy(ps): if p in qs: ps.remove(p) print ps Or you can adopt a different strategy: print [el for el in ps if p not in qs] This algorithm is O(n*m), so if the two lists are long, you may need too much time to run that. To speed up the program you can do this (Python 2.4): sqs = set(qs) print [el for el in ps if p not in sqs] Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: a bug in list.remove?
> I have 2 lists. What Im doing is check the first list and remove all > occurances of the elements in the second list from the first list, like so: > >>> ps = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] > >>> qs = [6,7,8,9,10,11,12,1,2] > >>> for p in ps: > if p in qs: > ps.remove(p) > > The problem Im having is that when I do > >>> print ps > it gives me > [2, 3, 4, 5, 7, 9, 11, 13, 14, 15] > which is incorrect since 2,7,9,11 shouldnt be in that list. Is this a > bug in .remove? or is my algorithm somewhat flawed? I'd go with the "somewhat flawed" answer. I'd just use ps = [x for x in ps if x not in qs] which will remove *all* instances of x from ps if it exists in qs. There's a subtle difference from the remove() method, which will only remove the first instance: >>> help([].remove) Help on built-in function remove: remove(...) L.remove(value) -- remove first occurrence of value If qs is large, you'll get improved performance by converting it to a set first: >>> s = set(qs) >>> ps = [x for x in ps if x not in s] As for your algorithm, you're modifying the list over which you're iterating--at best, often considered bad form...at worst, I've had Python throw exceptions at me for attempting it. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: The decentralized nature of the Python community is driving me crazy
[EMAIL PROTECTED] wrote: > hi everyone, > > I am the first of what may be hundreds of refugees from the Perl > community. Not only is Python a more productive language, with many > more nice apps, but the people are friendly as well... waaay more > friendly than the Perl crowd. > > But I must say the one thing I miss about Perl is my ability to stay on > top of all the latest modules and apps in one place: CPAN. With Python, > code is EVERYWHERE - people's local boxes, sourceforge, freshmeat, > codezoo, parnassus, etc, etc. Different approaches to documentation. A > much nicer install utility (python setup.py install r0x). But I am > finding it hard to keep on top and browse all the wares that are out > there because they are literally all over the net! > > And then you have discussion and yet again, there is no perlmonks.org > for Python. We have this, IRC, and what else? > > So, I guess this is my way of letting you know how lost I feel about > this de-centralized community. Dont get me wrong. I'm glad to be part > but I was thinking it would be nice if there were a one-stop-shop for > all my chat and wares needs. But for now, I guess I need to just add > few more bookmarks to main places to keep on top of daily besides > pythonware.com/daily. Hi Metaperl, glad you're enjoying our language. :) I left Perl in the mid 90s and came to Python after a year with Java. So I don't know what perlmonks.org is. The lack of a CPAN equivalent has been a persistent lament of Pythoneers over the years, and there have been several attempts to build a Python one or a multilingual one. The Cheeseshop and easy_install are the most successful attempts. There's a project aimed at integrating easy_install into Python itself, but with the technical and compatibility issues it will take several months. More and more packages are being listed in the Cheeseshop. If there's anything of importance that's *not* listed there (and I can't think of anything), you would do well to prod the owners to get with the program. You can pretty much ignore Parnassus and Freshmeat etc unless you have a fondness for old software that will never be in the Cheeseshop. comp.lang.python is where most of the discussion takes place, and the best place to ask questions. It's so big I read it the weekly Python-URL summary instead, which is how I found your message.I've never read the daily Python-URL much, but it looks like a good place if you want more "input" [Number 5 voice; "Short Circuit" movie]. Other good sources of information are local users' groups and conferences. I attend PyCon every year, and find that something always happens somehow that sets my direction for the year. Some really good idea you collaborate on at the conference, then work on during the next several months. If you're plugged into users' groups, I don't see a real need to have lots of bookmarks to read every day. There are a ton of Python books now too that might be helpful. There are also some good articles on O'Reilly's OnLamp (http://www.onlamp.com/python/) by several Python bigwigs, including Cameron Laird who founded the Python-URL. Plus there's Guido's blog of course (http://www.artima.com/weblogs/index.jsp?blogger=guido). As for "different approaches to documentation", that's something the Python community has not come to any consensus on. There are tools that convert docstrings into documentation, and tools that run tests embedded in docstrings, and these impose a syntax on the docstrings, but in each area there are multiple programs and it's too soon to say which approach will win out. But they are gradually converging. --Mike <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: Type conversion?
"KraftDiner" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > In C++ you can cast one class type to another if you override the > operator= > Then you can convert one class type to another... > In Python it would appear that the left hand side of the assignment > operator > is not used to determine if a cast is necessary. > So how would I do this in python? Start by repeating 50 times: "Python is not C++". In Python, '=' is not an operator, it is a name binder, and is defined at the language level, not at the class level. > > a = classA() > b = classB() > b = a > > In the end b would end up just being a refrence to a > no conversion would have been done. > Just as you say, '=' will completely rebind the rhs value to the lhs name. Now one thing you *could* do is to do something tricky, like use one of the overridable inplace operators, like "<<=", which *is* definable by class. Here is a type casting class that does something like you are asking for. (Back in the CORBA days, <<= was used in the C++ binding to insert values into a CORBA::Any variable - I guess it looks like some sort of typographic hypodermic needle...) -- Paul class Caster(object): def __init__(self,typ): self.castType = typ self.value = self.castType() def cast(self,other): try: return self.castType(other) except Exception,e: print "Failed to cast '%s' as %s" % (other, self.castType.__name__) # define behavior for <<= operator def __ilshift__(self,other): self.value = self.cast(other) return self def __str__(self): return "(%s) %s" % (self.castType.__name__,self.value) z = Caster(int) print z z <<= 100 print z z <<= 3.14159 print z z <<= 'what the heck?' print z Prints: (int) 0 (int) 100 (int) 3 Failed to cast 'what the heck?' as int (int) None -- http://mail.python.org/mailman/listinfo/python-list
Re: Text to MP3 using pyTTS - Non-programmer question
Thanks for the script. Are there any online python intrepreters? I'd like to play around with the script. I don't have access to my home PC. -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Paddy wrote: > Sybren Stuvel wrote: >> Paddy enlightened us with: >> > Well, after all the above, there is a question: >> > >> > Why not make sum work for strings too? >> >> Because of "there should only be one way to do it, and that way should >> be obvious". There are already the str.join and unicode.join methods, >> which are more powerful than sum. >> >> Sybren > I get where you are coming from, but in this case we have a function, > sum, that is not as geeral as it could be. sum is already here, and > works for some types but not for strings which seems an arbitrary > limitation that impede duck typing. Only that it isn't arbitrary. > - Pad. > > P.S. I can see why, and am used to the ''.join method. A newbie > introduced to sum for integers might naturally try and concatenate > strings using sum too. Yes, and he's immediately told what to do instead. Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: a bug in list.remove?
Tim Chase wrote: >> I have 2 lists. What Im doing is check the first list and remove all >> occurances of the elements in the second list from the first list, >> like so: >> >>> ps = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] >> >>> qs = [6,7,8,9,10,11,12,1,2] >> >>> for p in ps: >> if p in qs: >> ps.remove(p) >> >> The problem Im having is that when I do >> >>> print ps >> it gives me >> [2, 3, 4, 5, 7, 9, 11, 13, 14, 15] >> which is incorrect since 2,7,9,11 shouldnt be in that list. Is this a >> bug in .remove? or is my algorithm somewhat flawed? > > > > I'd go with the "somewhat flawed" answer. > > I'd just use > > ps = [x for x in ps if x not in qs] > > which will remove *all* instances of x from ps if it exists in qs. > There's a subtle difference from the remove() method, which will only > remove the first instance: > > >>> help([].remove) > Help on built-in function remove: > > remove(...) > L.remove(value) -- remove first occurrence of value > > > > If qs is large, you'll get improved performance by converting it to a > set first: > > >>> s = set(qs) > >>> ps = [x for x in ps if x not in s] > > > As for your algorithm, you're modifying the list over which you're > iterating--at best, often considered bad form...at worst, I've had > Python throw exceptions at me for attempting it. > > -tkc Thanks for that. Really helpful! Cheers Astan -- http://mail.python.org/mailman/listinfo/python-list
Re: MS SQL Server: NT Authentication. Possible?
Dirk Hagemann napisał(a): > 'Exception occurred.', (0, 'Microsoft OLE DB Provider for ODBC > Drivers', "[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed > for user '(null)'. Reason: Not associated with a trusted SQL Server > connection.", None, 0, -2147217843), None) This indicates, that user credentials was not retrieved from ActiveDirectory server. > Do I have to make some settings at the MS SQL Server? I just can't find > a simple example how to use adodbapi with NT authentication... I tried few times but I gave up. Now I authenticate my users against AD using LDAP queries. They have to provide their credentials, though, and I know it's suboptimal. -- Jarek Zgoda http://jpa.berlios.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: MS SQL Server: NT Authentication. Possible?
Tim Golden napisał(a): > import adodbapi > > db = adodbapi.connect ("Provider=sqloledb;Data Source=VODEV1;Initial > Catalog=EVOBACK;Integrated Security=SSPI;") This kind of connection doesn't work for me. I think it's some misconfiguration on AD side, but I still get "not associated with trusted connection" and I don't know what to ask my sysadmin, so I'd rather stay with SQL login. -- Jarek Zgoda http://jpa.berlios.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Paddy wrote: > Here is where I see the break in the 'flow': > 1+2+3 > 6 sum([1,2,3], 0) > 6 [1] + [2] +[3] > [1, 2, 3] sum([[1],[2],[3]], []) > [1, 2, 3] '1' + '2' + '3' > '123' sum(['1','2','3'], '') > Traceback (most recent call last): > File "", line 1, in ? > TypeError: sum() can't sum strings [use ''.join(seq) instead] do you often write programs that "sums" various kinds of data types, and for which performance issues are irrelevant? or are you just stuck in a "I have this idea" loop? -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
Andy Terrel wrote: > for i in dir(): > if eval(i) == Banana: > print i (sound of head hitting desk) -- http://mail.python.org/mailman/listinfo/python-list
Re: couple more questions about sqlite
> 2. What's the difference between sqlite and pysqlite? Do you need both, > just one, or is one an older version of the same thing? To access your database from python you need both (or some alternative to pysqlite) > 3. What's the difference between the command line program called sqlite3 > and the module you would use with Python? (I know that the former let's > you do normal database things without dealing with Python, but is it > necessary if you are using Python to interact with the DB?) slqite comes with a library which other programs can call, and a command line interface that you can use from the shell. pysqlite needs the library but I don't think it is possible to get one without the other. Regards, Andy -- http://mail.python.org/mailman/listinfo/python-list
efficient memoize decorator?
im plugging away at the problems at http://www.mathschallenge.net/index.php?section=project im trying to use them as a motivator to get into advanced topics in python. one thing that Structure And Interpretation Of Computer Programs teaches is that memoisation is good. all of the memoize decorators at the python cookbook seem to make my code slower. is using a decorator a lazy and inefficient way of doing memoization? can anyone point me to where would explain how to do it quickly. or is my function at fault? the code in question is as follows """ from memoize import memoize,memoize2 @memoize def col(n, count): if n == 1: return count elif n % 2 == 0: return col(n/2, count+1) else: return col((3*n+1)/2, count+2) import psyco psyco.full() start = time() maxlength = 0 best = 0 for i in range(1, 101): length = col(i,1) if length > maxlength: maxlength = length best = i print maxlength, best end = time() print 'took', end-start -- http://mail.python.org/mailman/listinfo/python-list
timezones and time_t
Hi, I've got a Python application that (as well as lots of other stuff!) has to translate time_t values into strings in the TZ of the users choice. Looking at the Python Library Reference, I can see no platform independent way of setting the TZ that time.localtime() returns - tzset() is marked as only available on Unix and that is indeed the case. Is there really nothing "shipped as standard"? I'm using Python 2.4.3 on Windows XP. If not, what's the de-facto standard... pytz? Ta! John -- http://mail.python.org/mailman/listinfo/python-list
Re: efficient memoize decorator?
sorry memoize is http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496879 memoize2 is http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466320 > im plugging away at the problems at > http://www.mathschallenge.net/index.php?section=project > im trying to use them as a motivator to get into advanced topics in > python. > one thing that Structure And Interpretation Of Computer Programs > teaches is that memoisation is good. > all of the memoize decorators at the python cookbook seem to make my > code slower. > is using a decorator a lazy and inefficient way of doing memoization? > can anyone point me to where would explain how to do it quickly. or is > my function at fault? > > the code in question is as follows > """ > from memoize import memoize,memoize2 > > @memoize > def col(n, count): > if n == 1: > return count > elif n % 2 == 0: > return col(n/2, count+1) > else: > return col((3*n+1)/2, count+2) > > import psyco > psyco.full() > > start = time() > maxlength = 0 > best = 0 > for i in range(1, 101): > length = col(i,1) > if length > maxlength: > maxlength = length > best = i > print maxlength, best > end = time() > print 'took', end-start -- http://mail.python.org/mailman/listinfo/python-list
Re: amd64
if the install is 64 bit, you will hit trouble i used the guide here http://www.debian-administration.org/articles/356 on my 64 bit debian system to get 32bit apps available if they have a particular distro install, usually the package management tools for it can add most python modules you will need hope that helps, add more details if you want more help tom > Robin Becker wrote: > > Does anyone know if it's possible to run python as a 32 bit app on AMD64's? > > One > > of our host providers AMD Athlon 64 3000+ and we are currently using a > > celeron > > which is real slow. The problem is that this machine would be a backup for > > another which is 32 pentium 4. > > > > If I have to recompile/debug all the extensions etc etc for another > > architecture > > it might not seem so attractive. > > -not ready for 64bitly yrs- > > Robin Becker > Most 64 bit processors can run 32 bit apps natively, so the short > answer would be yes. -- http://mail.python.org/mailman/listinfo/python-list
Re: The decentralized nature of the Python community is driving me crazy
> And then you have discussion and yet again, there is no perlmonks.org > for Python. We have this, IRC, and what else? There's also http://planet.python.org, which is an aggregator of python blogs that I check many times a day for new posts. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
Fredrik Lundh wrote: > Andy Terrel wrote: > >> for i in dir(): >> if eval(i) == Banana: >> print i > > (sound of head hitting desk) > > > lol -- http://mail.python.org/mailman/listinfo/python-list
Re: couple more questions about sqlite
[EMAIL PROTECTED] wrote: >> 2. What's the difference between sqlite and pysqlite? Do you need both, >> just one, or is one an older version of the same thing? > > To access your database from python you need both (or some alternative > to pysqlite) I can understand this in terms of MySQL being one thing, and mysqldb being the necessary module for Python to use MySQL. But in 2.5, for example, which comes with sqlite3, is this all you need, or do you still need pysqlite? Or are these two different things that can access the sqlite system? (I guess I kind of thought there would be just one standard module used for each type of database, such as mysqldb being the one used for MySQL.) -- http://mail.python.org/mailman/listinfo/python-list
Safearray question
Hi I'm using win32com.client to dispatch a COM serverone of the interface methods has the below parameter: ..., [in, out] SAFEARRAY(BYTE) *Buffer, ... This method goes and queries something and puts it in this buffer...how can I use this method in Python? What type of variable needs to be passed in when calling this method? Thanks in advance. AC -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
>>> for i in dir(): >>> if eval(i) == Banana: >>> print i >> (sound of head hitting desk) >> >> >> > lol As freakish as the solution was, it's not too far off from something that actually works (mostly, kinda sorta): >>> banana = {} >>> spatula = banana >>> propane = {} >>> [name for name in dir() if id(eval(name)) == id(banana)] ['banana', 'spatula'] >>> dir() ['__builtins__', '__doc__', '__name__', 'banana', 'name', 'propane', 'spatula'] While the original just compared on value (and thus, with the original "solution", "propane" would also be found), it should be pretty safe to compare on id() equality. Okay, it's semi-obcene in my book, but it's an actual solution in a way. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 or mysqldb?
> To learn SQL SQLite should be enough - it has all the basics, just as > MySQL, while it doesn't require any server/client configuration > (encoding configuration in MySQL is real PITA). But if you want any > "serious SQL", go with any freely available *real SQL server*, like > Firebird or PostgreSQL. I'd consider Firebird, as it's pretty lightweight. Firebird can be used as an embedded database just like SQLite as well. This gives a much more powerful database that can still be used without the administration overhead. Aside from flexibility, the reason I prefer FireBird is that it has much more sophisticated visual tools available. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Semicolon Wars as a software industry and human condition
On 17 Aug 2006 06:42:55 -0700, "Xah Lee" <[EMAIL PROTECTED]> wrote: >Of interest: > > The Semicolon Wars, by Brian Hayes. 2006. > http://www.americanscientist.org/template/AssetDetail/assetid/51982 [snip] > What Languages to Hate, Xah Lee, 2002 >http://xahlee.org/UnixResource_dir/writ/language_to_hate.html Cool! From the former: : Today's missionaries take an upbeat approach, spending more time in promoting their own religion and less in dissing the other person's beliefs. The message is no longer "You'll burn in hell if you write C." It's "Look what a paradise Python offers you!" (I think maybe I liked the old sermons better.) Michele -- {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^http://mail.python.org/mailman/listinfo/python-list
Search or compai problem
I am new to python and I want to compare 2 strings, here is my code: [start] import active_directory import re lstUsers = [] users = active_directory.root() for user in users.search ("sn='gallagher'"): lstUsers.append(user.samAccountName) print "" lstUsers.sort() ## Printing out what is inside of the arrar(list) x = 0 while x < len(lstUsers): if re.compile(lstUsers[x]).match("None",0): print "Somthing here" x = x + 1 [/end] When I do the: if re.compile(lstUsers[x]).match("None",0): print "Somthing here" Some of the items in lstUsers[x] are the word None. I am not sure why I cant do this I want to compare lstUsers[x] to the word "None", how can I do this. Thanks Timothy F. Gallagher CSC Systems Engineer -- http://mail.python.org/mailman/listinfo/python-list
Re: It is __del__ calling twice for some instances?
Duncan Booth wrote: > Duncan Booth wrote: > > > As to why it happens, there is a mechanism in Python to stop unlimited > > stack being used when objects are freed: when the stack gets too deep > > then instead of being released, the Py_DECREF call puts the object > > into a trashcan list and the objects aren't released until the stack > > has unwound. It looks like there must be a bug round the trashcan > > mechanism somewhere. > > I figured out what is going on in the code to deallocate an old-style class > instance: > > The reference count is temporarily incremented. > > If the class has a __del__ method then a descriptor is created for the > method and called. When the call returns, the descriptor is released. > > Then the object itself is released using special code to avoid a recursive > call to the deallocator. > > However, if the trashcan mechanism is invoked by the attempt to release the > descriptor, it actually queues the descriptor in the trashcan. Since the > descriptor contains a reference to the object it has effectively > resurrected it. This means the special code to avoid the recursive call > simply decrements the reference count but does not release anything (the > object has been resurrected by the descriptor). When the descriptor is > later released the __del__ method is triggered a second time. This looks like some good code to add to the python unit tests. >From your description, it appears the problem is that the object is placed in the trashcan after calling __del__ once. Perhaps the choice to place it in the trashcan could be made instead of calling __del__ the first time, rather than after calling __del__? Regards, Pat -- http://mail.python.org/mailman/listinfo/python-list
Python for EXIF-info-additions ?
Is there somewhere some Python-module that can be used for adding EXIF-info to JPEG files? (Modules for extraction of EXIF-data are easily found, but lacks - as I see it - capacity to add new tags.) /BJ -- http://mail.python.org/mailman/listinfo/python-list
PyThreadState_Swap(NULL)
hi, i've written a program that uses python c api code that lives in a shared library that is loaded by a custom apache module (mod_xxx). this python c api code all works correctly under our test server and under apache but only if mod_python isn't loaded. when apache loads mod_python as shown in the http.conf snippet below, PyThreadState_Swap(NULL) in mod_xxx returns NULL. when the snippet of code in http.conf is commented out, it works again. what do i have to do to have mod_xxx code work correctly when apache loads mod_python? failure case when apache loads mod_python: Py_Initialize() succeeded PyThreadState_Swap(NULL) failed sucess case when apache doesn't load mod_python: Py_Initialize() succeeded PyThreadState_Swap(NULL) succeeded thanks, bryan --- mod_xxx --- Py_Initialize(); if (Py_IsInitialized()) { log("Py_Initialize() succeeded"); } else { log("Py_Initialize() failed"); } PyEval_InitThreads(); g_py_main_interpreter = PyThreadState_Swap(NULL); PyThreadState_Swap(g_py_main_interpreter); PyEval_ReleaseLock(); if (g_py_main_interpreter) { log("PyThreadState_Swap(NULL) succeeded"); } else { log("PyThreadState_Swap(NULL) failed"); } apache's http.conf LoadModule python_module "../apache/bin/mod_python.so" Listen 4119 SetHandlermod_python PythonHandler mod_python.publisher PythonDebug Off -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
Why bang your head? It was a stupid hack that has lots of problems, but done in a way that is readable. Sure I could do something more functional or one lined like: Banana={} names = filter(lambda x:id(eval(x))==id(Banana),dir()) but I am guessing that it is harder to read by many. Anywho I can think of plenty of reasons it would fail, but it really depends on the app. Fredrik Lundh wrote: > Andy Terrel wrote: > > > for i in dir(): > > if eval(i) == Banana: > > print i > > (sound of head hitting desk) > > -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
Andy Terrel wrote: > Why bang your head? Because there's no chance that the original request is sane. If you want your objects to know their name, give them a name as an attribute. > It was a stupid hack that has lots of problems, > but done in a way that is readable. Sure I could do something more > functional or one lined like: > > Banana={} > names = filter(lambda x:id(eval(x))==id(Banana),dir()) > > but I am guessing that it is harder to read by many. Anywho I can > think of plenty of reasons it would fail, but it really depends on the > app. Georg -- http://mail.python.org/mailman/listinfo/python-list
urllib2, proxies and https
Hi again, According to https://demo.launchpad.net/products/python/+bug/56872 or more specifically, the example of its working code: http://librarian.demo.launchpad.net/3507227/urllib2_proxy_auth.py I can use urllib2 via proxy to access a https site(specifically hooking it up to libgmail). The problem is that the proxy that is accessible to me is http/port8080 only. Is it possible to use urllib2 with this proxy to access a https site? (im guessing no, but im sure there are ways around it). I've tried modifying the code to point to a https site (https://mail.google.com/mail/) without changing the http proxy and it produces a HTTP timeout error. Despite this, if I manually use a web browser to access these sites it prompts me with the proxy login and lets me through. So im also puzzled here why my browser lets this happen but urllib2 doesnt. Thanks again for all your help. Cheers Astan -- http://mail.python.org/mailman/listinfo/python-list
Re: It is __del__ calling twice for some instances?
Duncan Booth wrote: DB> I figured out what is going on in the code to deallocate an old-style class DB> instance: DB> DB> The reference count is temporarily incremented. DB> DB> If the class has a __del__ method then a descriptor is created for the DB> method and called. When the call returns, the descriptor is released. DB> DB> Then the object itself is released using special code to avoid a recursive DB> call to the deallocator. DB> DB> However, if the trashcan mechanism is invoked by the attempt to release the DB> descriptor, it actually queues the descriptor in the trashcan. Since the DB> descriptor contains a reference to the object it has effectively DB> resurrected it. This means the special code to avoid the recursive call DB> simply decrements the reference count but does not release anything (the DB> object has been resurrected by the descriptor). When the descriptor is DB> later released the __del__ method is triggered a second time. Thank You for so detailed explanation! -- GMT More Then ... -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
Georg Brandl wrote: > Andy Terrel wrote: > > Why bang your head? > > Because there's no chance that the original request is sane. > > If you want your objects to know their name, give them a name as an attribute. > This is true but sometimes it is just fun to hack around. -- http://mail.python.org/mailman/listinfo/python-list
Re: It is __del__ calling twice for some instances?
Duncan Booth wrote: DB> BTW, the behaviour is completely different if you use a new style class, DB> but still somewhat bizarre: for new style classes only the first 25 objects DB> get freed when you clear a, the remainder are only released by the garbage DB> collector. If to add the third call of stat() after the second, the result became such: ini_cnt = 51 del_cnt = 0 difference = 51 ini_cnt = 51 del_cnt = 25 difference = 499976 ini_cnt = 51 del_cnt = 51 difference = 0 Preceding call to gc.disable() has no influence on result. -- GMT More Then ... -- http://mail.python.org/mailman/listinfo/python-list
Re: plpython and pickle
On 2006-08-17, Gerardo Herzig <[EMAIL PROTECTED]> wrote: > Hi all, sory if this is kind of [OT], but cannot find the answer for > this behaviour > Might try on a postgres mailing list. I'd say it is more on topic there... > You are now connected to database "sessions". > sessions=# select * from > getsessiondata('QQtEpLoKHnvbKGSpgJgYMPyCdHgXSi'); > > > getsessiondata > > > > > > (dp0--ENTER--S---alucod-ENTER--p1--ENTER--S---32009436-ENTER--p2--ENTER--sS---respuestas_1-ENTER--p3--ENTER--S---3-ENTER--p4--ENTER--sS---respuestas_2-ENTER--p5--ENTER--S---2-ENTER--p6--ENTER--sS---respuestas_3-ENTER--p7--ENTER--S---4-ENTER--p8--ENTER--sS---submit-ENTER--p9--ENTER--S---Responder-ENTER--p10--ENTER--s. > data = plpy.execute("SELECT * from dblink('dbname=sessions', 'select * from > getsessiondata(\'\'%s\'\')') as t1(session_data name); " % > session_id)[0]["session_data"]; > plpy.notice(data) > """ > i got this > NOTICE: > ("'(dp0--ENTER--S---alucod-ENTER--p1--ENTER--S---32009436-'",) Can you try just... SELECT * from dblink('dbname=sessions', 'select * from getsessiondata('QQtEpLoKHnvbKGSpgJgYMPyCdHgXSi'); > Im not even sure if this is a pickle, plpython nor postgresql issue or a dblink issue? -- http://mail.python.org/mailman/listinfo/python-list