read text file byte by byte
Hello everybody, I need to read a text file byte after byte. Eache byte is sent to a function that scramble it and I need to write the result to binary file. I've got some questions - 1) How do I read the file byte by byte 2) Should I use streams? If so and I get my entire scrambled text in stream can I just write it to the binary file? Thanks Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: power of explicit self?
En Sat, 12 Dec 2009 01:04:42 -0300, Fire Crow escribió: I'm looking for an explanation of how explicit self is implimented and what features are only possible because of, or are greatly improved, because of it. I've always liked explicit self and am looking for the computer science behind it, so that I can explain the benefits that I see. See the FAQ [1] I'm also interested in the files/lines of the python source that shows how explicit self is implemented if anyone can point out where that takes place. Nowhere, I'd say. An *implicit* self would have to be implemented somewhere in the compiler -- but an explicit self doesn't. It's homogeneous, always name-dot-attribute; the name 'self' is not special at all. [1] http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Spawning an interactive interpreter in a running python process?
En Sat, 12 Dec 2009 02:11:27 -0300, Horace Blegg escribió: I wonder if I could cook something up with PyRun_SimpleString("import pdb; pdb.set_trace()"). This bears investigation! pdb is a debugger, and provides a lot more than you're looking for, I presume. You may want to look at the code [1] and cmd [2] modules too. [1] http://docs.python.org/library/code.html [2] http://docs.python.org/library/cmd.html -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: eiger replacement?
Steven D'Aprano wrote: >On Fri, 11 Dec 2009 17:45:24 +, Robin Becker wrote: > >> The current hardware >> >> CPU: Intel(R) Pentium(R) 4 CPU 2.40GHz (2394.01-MHz 686-class CPU) >[...] > >What does this have to do with Python? I'm guessing Robin had a slight address book malfunction when he sent this. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Spawning an interactive interpreter in a running python process?
*I really must get in the habit of replying to all, and not just replying*. Ahh, I didn't know it could do that. I will go experiment. But from what you said, it doesn't seem like one could do that on the fly. It actually requires altering the app, and then running it again. I wonder if I could cook something up with PyRun_SimpleString("import pdb; pdb.set_trace()"). This bears investigation! Cheers! -- http://mail.python.org/mailman/listinfo/python-list
Re: Spawning an interactive interpreter in a running python process?
I'm curious, in an academic sense, if it's possible to spawn the interactive interpreter (>>>) in a running python application. Ideally, I would like to be able to access the modules, functions and variables the application can. Is something like this possible? While not exactly "the interactive interpreter", you can use pdb to drop to a debugging prompt where you can "access the modules, functions and variables the application can". The common idiom is to insert a line like import pdb; pdb.set_trace() in your code to have a break-point stop execution at the designated point and leave you at a prompt where you can explore. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Caps Lock State on Windows
En Thu, 10 Dec 2009 21:58:40 -0300, N3wCr4Zy escribió: how to i get Caps Lock state (on/off) on windows with win32api? py> from win32api import GetKeyState py> from win32con import VK_CAPITAL py> GetKeyState(VK_CAPITAL) # normal 0 py> GetKeyState(VK_CAPITAL) # CAPS LOCK set 1 See http://msdn.microsoft.com/en-us/library/ms645530(VS.85).aspx -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: umath import error for Numpy builds on OSX 10.6
On 2009-12-11 20:55 PM, hardcoreUFO wrote: On Dec 11, 5:47 pm, Robert Kern wrote: Right, when the -lnpymath stuff got checked in. Looking at the build log you posted to numpy-discusson, it does appear that the $LDFLAGS is obliterating the intended flags. Please post a build log without setting those flags to numpy-discussion. A correct link line should look something like this: gcc -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g -bundle -undefined dynamic_lookup build/temp.macosx-10.3-i386-2.5/numpy/core/src/umath/umathmodule_onefile.o -Lbuild/temp.macosx-10.3-i386-2.5 -lnpymath -o build/lib.macosx-10.3-i386-2.5/numpy/core/umath.so Thanks Robert, Here is the log from a build without the LDFLAGS set. Having a quick look, all I can see are a few warnings and a CAPI version mismatch message. Any insight most appreciated. The build still gives the same umath error. On numpy-discussion, please. But first, start with a clean checkout. I think you have stale files. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Spawning an interactive interpreter in a running python process?
Hello List, I'm curious, in an academic sense, if it's possible to spawn the interactive interpreter (>>>) in a running python application. Ideally, I would like to be able to access the modules, functions and variables the application can. Is something like this possible? If not, would I be able to implement something like this on my own? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: switch
On Dec 11, 1:38 am, Tim Chase wrote: > It's clean if it were the solution to my problem Picking out that line first, just to be clear about this. You missed the disclaimer. This was never meant to be a solution to your problem. It was solution to the problem contained in the code you posted. Carl, asked a question, in response you provided an example, and I wrote a solution. I did so to in order to illustrate how something resembling a dispatch mechansism can save a programmer from ending up with a "rat's-nest" of elif chainage. I hope you did not misunderstand me as advocating your pulling apart working production code. Heck, I wouldn't, err ...don't, do this. Which is _not_ to say that it isn't actually a solution your problem as well! :) >>[One guy analogy] > > This is where you make a false assumption Again "I don't really know your problem only the code you've posted." If I misunderstood the record types as originating from different providers, I'm sure you will find that my code, which faithfully reimplements yours, does not. > -- the contents and > parsing of the "switch" are provider-specific in this case, > mapping to a common ontology of the Phone object: > > class MonopolyProvider1Parser: > ... > switch row['recordtype']: > case '01': > phone.international += Decimal(row['internationalcost']) > // optionally a "break" here depending on > // C/C++/Java/PHP syntax vs. Pascal syntax which > // doesn't have fall-through > case '02': > phone.text_messaging += ( > int(row['textmessages sent']) + > int(row['pages received']) + > int(row['textmessages sent']) + > int(row['pages received']) > ... > default: > raise WhatTheHeckIsThis() > > class MonopolyProvider2Parser: > ... > switch row['recordtype']: > case 'abc': > phone.international += ( > Decimal(row['canada cost']) + > Decimal(row['eu cost']) + > Decimal(row['mexico cost']) + > Decimal(row['other intl cost']) > ) > case 'xyz': > phone.text_messaging += int(row['textmessages']) > ... > default: > raise WhatTheHeckIsThis() > Fair enough. What you posted was a subset of your overall problem. Obviously! Inasmuch as the code that you posted accurately represents a subset of your problem, the solution given is still applicable, at least to that subset of your problem. It's just that each inidividual MonopolyProvider will require its own set of data sources. In any case, I'm sure you could work out it could be applied, if you put your mind to it. I agree this involves more code than the example required, possibly for less gain and I believe it is still advantageous to organise the code in a way which separates knowledge from logic. At least when that knowledge is non-trivial. > > # The one thing I'm sure I don't understand from the code is where the > > original rectypes comes into the process. > Sorry, my worrying there about whether we need to look the appropriate RecType up in that dict was just a distraction. The problem isn't in the dict, but with that the try should only be trapping unknown types, not problems of instantiation. I should have written: try : AppropriateRecType = rectypes[rectype] except KeyError : raise WhatTheHeckIsThisError('unknown rectype: %s' % rectype) record = ApproriateRecType(row) > From the provider data -- sometimes CSV files, sometimes > tab-delimited text files, sometimes MS Access MDB files, > sometimes a web service... > varies per-provider (and some providers > have multiple formats, like Verizon has MyBIZ and IBAS; ATT has > their WinCD and Premier; etc). No two formats are the same, so > the logic needed to parse the data into our internal homogenized > Phone data structure varies per each one. And the logic (or lack > thereof) used by many providers in creating their formats require > reverse-engineering most of them through trial-and-error, and > huge ugly if/elif/else chains. I feel your pain, I really do ... and a dispatch mechanism could relieve some of it. ;) Now I'm not saying you should implement it on extant production code. As I wrote above, I still use, and unfortunately maintain, older code which is a hideous mess of elif chains. The task of challenging these elif chains is daunting, and rewriting such working code won't rank in my work priorities for the foreseeable future. This is why, elif chains, when they first arise, or better perhaps, when they first begin to grow, should be examined to see whether they are a bud that ought to be nipped, whether they sensibly can be nipped, and if so how. They are, in Carl's words, "red flags," at least they are if your're "not a very good progammer," like me. I invite all my fellow NVGPs to treat them as such as w
power of explicit self?
I'm looking for an explanation of how explicit self is implimented and what features are only possible because of, or are greatly improved, because of it. I've always liked explicit self and am looking for the computer science behind it, so that I can explain the benefits that I see. I'm also interested in the files/lines of the python source that shows how explicit self is implemented if anyone can point out where that takes place. all help welcome -- http://mail.python.org/mailman/listinfo/python-list
Re: Open source projects
Someone Something wrote: I'm a pretty okay python programmer and I really want to start developing for an open source project. I'm looking for one that preferably deals with networking and isn't as huge as twisted (that's just a preference, not extremely important). Could anyone suggest any projects? I also know C, Perl, Ruby and Java (java least preferred). Helping port some 3rd party package to Python 3, twisted or otherwise, would be a great contribution to the community. The barrier for some groups is that they have just enough energy to maintain the package and forward port to 2.6 and the upcoming 2.7, but not enough extra to also make changes for 3.1. I am sure you can find some project of interest who people would welcome the extra help. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: umath import error for Numpy builds on OSX 10.6
On Dec 12, 3:55 pm, hardcoreUFO wrote: > Here is the log from a build without the LDFLAGS set. Having a quick > look, all I can see are a few warnings and a CAPI version mismatch > message. Any insight most appreciated. The build still gives the same > umath error. Sorry, forgot to post the log: http://files.me.com/fonnesbeck/giaoql -- http://mail.python.org/mailman/listinfo/python-list
Re: umath import error for Numpy builds on OSX 10.6
On Dec 11, 5:47 pm, Robert Kern wrote: > Right, when the -lnpymath stuff got checked in. Looking at the build log you > posted to numpy-discusson, it does appear that the $LDFLAGS is obliterating > the > intended flags. Please post a build log without setting those flags to > numpy-discussion. A correct link line should look something like this: > > gcc -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g -bundle > -undefined dynamic_lookup > build/temp.macosx-10.3-i386-2.5/numpy/core/src/umath/umathmodule_onefile.o > -Lbuild/temp.macosx-10.3-i386-2.5 -lnpymath -o > build/lib.macosx-10.3-i386-2.5/numpy/core/umath.so Thanks Robert, Here is the log from a build without the LDFLAGS set. Having a quick look, all I can see are a few warnings and a CAPI version mismatch message. Any insight most appreciated. The build still gives the same umath error. cf -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with debugging Lists
En Fri, 11 Dec 2009 19:11:38 -0300, Sancar Saran escribió: In php we had print_r function to see entire array structure. After some search I found some equal module named pprint. And some how this module wont work with mod_wsgi it was something about mod_wsgi portability standards. After some research there where some thing about putting some variables in apache config to disable this. And now I can see some dictionary structure in my apache log and I got some errors like r += pprint.pprint(self.data) TypeError: cannot concatenate 'str' and 'NoneType' objects The pprint function in the pprint module (that is, pprint.pprint) *prints* its argument, and returns nothing -- or, better said, it returns None (same as print_r in PHP, without the return parameter set to true) So is there any way to get dictionary structure in string format ? You don't need anything special for that. There are two built-in functions that convert any object to string: str and repr. str(x) provides a simple representation of x (whatever it is), and repr(x) provides a more technical view; when possible, eval(repr(x)) should return x. For debugging purposes, repr() is your friend. pprint.pformat is like the built-in repr(), but provides a better formatted representation, with indenting, a maximum width, etc. Another question is. When I import a module from top is it available for later imported modules Each module contains its own, separate namespace. If you `import foo` in some module, the name `foo` becomes available to be used in that module -- if you want to use `foo` in another module, you have to `import foo` in that other module too. Don't worry; after the very first import (which involves locating the module, loading and compiling it if necesary, and writing the .pyc file) any subsequent imports of the same module just return a new reference to the existing, in-memory module object. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Open source projects
I'm a pretty okay python programmer and I really want to start developing for an open source project. I'm looking for one that preferably deals with networking and isn't as huge as twisted (that's just a preference, not extremely important). Could anyone suggest any projects? I also know C, Perl, Ruby and Java (java least preferred). -- http://mail.python.org/mailman/listinfo/python-list
Re: Which graph library is best suited for large graphs?
On Fri, Dec 11, 2009 at 5:12 AM, Wolodja Wentland wrote: > Hi all, > > I am writing a library for accessing Wikipedia data and include a module > that generates graphs from the Link structure between articles and other > pages (like categories). > > These graphs could easily contain some million nodes which are frequently > linked. The graphs I am building right now have around 300.000 nodes > with an average in/out degree of - say - 4 and already need around 1-2GB of > memory. I use networkx to model the graphs and serialise them to files on > the disk. (using adjacency list format, pickle and/or graphml). Huh. Using graphine- which should be somewhat more memory hungry than networkx- I generated a naive million node 4-cycle graph and wound up using something under 600 meg of ram. Can you post some code? Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I get the target platform info of a dll with Python 3.1.1?
En Fri, 11 Dec 2009 16:39:37 -0300, Isti escribió: I have many dll files and I would like to select them into two different folders (PC and PPC). For this I need to know the target platform of the dll file or any other details about its platform. Look at sys.platform and the platform module. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Recommendation for small, fast, Python based web server
Le Fri, 11 Dec 2009 19:40:21 +0100, Irmen de Jong a écrit : > > I don't think that number is fair for Python. I think a well written > Python web server can perform in the same ballpark as most mainstream > web servers written in C. Especially Apache, which really isn't a top > performer. And I'm pretty sure a well written Python server can > outperform a badly written C based server easily. The order of magnitude I gave is based on real-world testing. You are under-estimating how much of an impact Python's interpretation speed has on low-level code. Even Apache *is* a top performer compared to Python web servers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Object Relational Mappers are evil (a meditation)
On Fri, 11 Dec 2009 19:20:21 -0500, Steve Holden wrote: > Simon Forman wrote: > [...] >> As far as the OP rant goes, my $0.02: bad programmers will write bad >> code in any language, with any tool or system or environment they're >> given. If you want to avoid bad code there's (apparently) no >> substitute for smrt programmers who are familiar with the tools they're >> using, not just the syntax but the underlying conceptual models as >> well. >> > Hear, hear! That's all very well, but some languages and techniques encourage the programmer to write bad code. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: a list/re problem
On Fri, 11 Dec 2009 12:49:42 -0800, Ed Keith wrote: > I have a problem and I am trying to find a solution to it that is both > efficient and elegant. > > I have a list call it 'l': > > l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] > > Notice that some of the items in the list start and end with an '*'. I > wish to construct a new list, call it 'n' which is all the members of l > that start and end with '*', with the '*'s removed. > > So in the case above n would be ['nbh', 'jkjsdfjasd'] > > the following works: > > r = re.compile('\*(.+)\*') [snip] Others have suggested using a list comp. Just to be different, here's a version using filter and map. l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] l = map( lambda s: s[1:-1] if s.startswith('*') and s.endswith('*') else '', l) l = filter(None, l) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Using hash to see if object's attributes have changed
On Fri, 11 Dec 2009 10:03:06 -0800, Bryan wrote: > When a user submits a request to update an object in my web app, I make > the changes in the DB, along w/ who last updated it and when. I only > want to update the updated/updatedBy columns in the DB if the data has > actually changed however. > > I'm thinking of having the object in question be able to return a list > of its values that constitute its state. Then I can take a hash of that > list as the object exists in the database before the request, Storing the entire object instead of the hash is not likely to be *that* much more expensive. We're probably talking about [handwaves] a few dozen bytes versus a few more dozen bytes -- trivial in the large scheme of things. So give the object a __ne__ method, store a copy of the object, and do this: if current_object != existing_object: update(...) > and then > on the object that the user has made changes to. If they are not equal, > the user has changed the object. If all you care about is a flag that says whether the state has changed or not, why don't you add a flag "changed" to the object and update it as needed? if current_object.changed: update(...) current_object.changed = False That would require all attributes be turned into properties, but that shouldn't be hard. Or use a datestamp instead of a flag: if current_object.last_changed > database_last_changed: update(...) > I imagine it working something like this: > > def getValues(obj): > return [obj.a, obj.b, obj.c] > > foo = Obj() > foo.a = foo.b = foo.c = 1 > stateBefore = hashlib.sha1(str(getValues(foo))) > foo.b = 'changed' > stateNow = hashlib.sha1(str(getValues(foo))) > assert stateBefore != stateNow You probably don't need a cryptographically strong hash. Just add a __hash__(self) method to your class: def MyObject(object): # or whatever it is called def __hash__(self): t = (self.a, self.b, self.c) return hash(t) stateNow = hash(foo) In fact, why bother with hashing it? Just store the tuple itself, or a serialized version of it, and compare that. > I originally thought about running the hash on the __dict__ attribute, > but there may be things in there that don't actually constitute the > object's state as far as the database is concerned, so I thought it > better to have each object be responsible for returning a list of values > that constitute its state as far as the DB is concerned. > > I would appreciate any insight into why this is a good/bad idea given > your past experiences. Call me paranoid if you like, but I fear collisions. Even cryptographically strong hashes aren't collision-free (mathematically, they can't be). Even though the chances of a collision might only be one in a trillion-trillion-trillion, some user might be unlucky and stumble across such a collision, leading to a bug that might cause loss of data. As negligible as the risk is, why take that chance if there are ways of detecting changes that are just as good and probably faster? Hash functions have their uses, but I don't think that this is one of them. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: When to use mechanize and Windmill library during WebScraping ?
On Fri, 11 Dec 2009, Raji Seetharaman wrote: > Hi > > For 'Webscraping with Python' mechanize or urllib2 and windmill or selenium > libraries are used to download the webpages. > > http://www.packtpub.com/article/web-scraping-with-python Be sure to look at Scrapy too: http://scrapy.org Cheers, -R. Tyler Ballance -- Jabber: rty...@jabber.org GitHub: http://github.com/rtyler Twitter: http://twitter.com/agentdero Blog: http://unethicalblogger.com pgpBd1omxDfvT.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQL set and enum, calling values
En Fri, 11 Dec 2009 16:28:23 -0300, Victor Subervi escribió: On Fri, Dec 11, 2009 at 3:12 PM, Carsten Haese wrote: Victor Subervi wrote: > [...] if I go to print, say, > colFieldValues[20], which is a set, it prints out the whole set: > set('Extra-small','Small','Medium','Large','XLarge','XXLarge','XXXLarge') > But if I print out colFieldValues[20][0], it prints out "s". > Also, how can I test > for it? It's an instance of string. How do I know if it's a set? That's a fantastic question. Python thinks it's a string. What makes you think it's a set? Right. I'm doing it the ugly way with the truncating tuple and string replace. Are you sure the column is declared as SET and not, say, VARCHAR? Anyway, I don't think MySQLdb is able to handle the SET data type correctly. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: a list/re problem
Grant Edwards wrote: > On 2009-12-11, Ed Keith wrote: >> I have a problem and I am trying to find a solution to it that is both >> efficient and elegant. >> >> I have a list call it 'l': >> >> l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] > >> Notice that some of the items in the list start and end with >> an '*'. I wish to construct a new list, call it 'n' which is >> all the members of l that start and end with '*', with the >> '*'s removed. >> >> So in the case above n would be ['nbh', 'jkjsdfjasd'] > > [s[1:-1] for s in l if (s[0] == s[-1] == '*')] s[0] and s[-1] raise an IndexError if l contains an empty string. Better something like: >>> [s[1:-1] for s in l if (s[:1] == s[-1:] == '*')] Or just the slightly more verbose startswith/endswith version. -- Matt Nordhoff -- http://mail.python.org/mailman/listinfo/python-list
Re: Object Relational Mappers are evil (a meditation)
Simon Forman wrote: [...] > As far as the OP rant goes, my $0.02: bad programmers will write bad > code in any language, with any tool or system or environment they're > given. If you want to avoid bad code there's (apparently) no > substitute for smrt programmers who are familiar with the tools > they're using, not just the syntax but the underlying conceptual > models as well. > Hear, hear! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Object Relational Mappers are evil (a meditation)
Paul Rubin wrote: > Mick Krippendorf writes: If I knew what First Anormal Form was I (hope!) >> I read it somewhere once, I just can't find or even remember the source. >> I definitely didn't make it up, though I wish I had. > > I found exactly one google hit for it, which is this clpy thread. It's a pun on First Normal Form. To transform a schema into First Normal Form you remove repeating groups from the entity and place them in a newly-created entity, leaving a copy of the identifier column behind to express a relationship between the two. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial - escape codes transportation
On Dec 11, 7:58 pm, Grant Edwards wrote: > On 2009-12-11, Grant Edwards wrote: > > > On 2009-12-11, ObservantP wrote: > >> need help. newbie. pyserial and dot matrix printer. issue- > >> escape codes arrive at printer ( verified from hex dump) but > >> do not get applied. > > > What you're saying is your printer isn't working correctly. > > BTW, I (among others) filter out all posts made from google > groups. I only stumbled across your posting by accident while > playing with my newsreader configuration. I won't see any > follow-up postings you make if they're from google groups. > > -- > Grant Edwards grante Yow! ! Everybody out of > at the GENETIC POOL! > visi.com Hi Grant Thanks for the tip. Had used the hex version alright. Looking again at the code, one realizes the difference between 'W' and 'w'... Sorted. All is well. Delighted to get this resolved. John -- http://mail.python.org/mailman/listinfo/python-list
Re: Which graph library is best suited for large graphs?
On Fri, Dec 11, 2009 at 3:12 AM, Wolodja Wentland < wentl...@cl.uni-heidelberg.de> wrote: > Hi all, > > I am writing a library for accessing Wikipedia data and include a module > that generates graphs from the Link structure between articles and other > pages (like categories). > > These graphs could easily contain some million nodes which are frequently > linked. The graphs I am building right now have around 300.000 nodes > with an average in/out degree of - say - 4 and already need around 1-2GB of > memory. I use networkx to model the graphs and serialise them to files on > the disk. (using adjacency list format, pickle and/or graphml). > > The recent thread on including a graph library in the stdlib spurred my > interest and introduced me to a number of libraries I have not seen > before. I would like to reevaluate my choice of networkx and need some > help in doing so. > > I really like the API of networkx but have no problem in switching to > another one (right now) I have the impression that graph-tool might > be faster and have a smaller memory footprint than networkx, but am > unsure about that. > > Which library would you choose? This decision is quite important for me > as the choice will influence my libraries external interface. Or is > there something like WSGI for graph libraries? > > kind regards > I once computed the PageRank of the English Wikipedia. I ended up using the Boost graph library, of which there is a parallel implementation that runs on clusters. I tried to do it using Python but failed as the memory requirements were so large. Boost and the parallel version both have python interfaces. -- http://mail.python.org/mailman/listinfo/python-list
Re: datetime 'NoneType' sporadic error
On Dec 11, 12:33 pm, bfrederi wrote: > When using the datetime module, I sporadically get " 'NoneType' object > has no attribute 'datetime' " on line 40:http://dpaste.com/hold/132156/ > > Sorry, I don't have the traceback, this is an error that was sent to > me by one of the users. It only happens occasionally. My guess is somewhere in your code the symbol datetime is being used as a variable. That is, you're doing something like datetime = x. This shadows the module. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: eiger replacement?
On Fri, 11 Dec 2009 17:45:24 +, Robin Becker wrote: > The current hardware > > CPU: Intel(R) Pentium(R) 4 CPU 2.40GHz (2394.01-MHz 686-class CPU) [...] What does this have to do with Python? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: a list/re problem
--- On Fri, 12/11/09, Peter Otten <__pete...@web.de> wrote: > From: Peter Otten <__pete...@web.de> > Subject: Re: a list/re problem > To: python-list@python.org > Date: Friday, December 11, 2009, 4:24 PM > Ed Keith wrote: > > > I have a problem and I am trying to find a solution to > it that is both > > efficient and elegant. > > > > I have a list call it 'l': > > > > l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', > '*jkjsdfjasd*', 'rewr'] > > > > Notice that some of the items in the list start and > end with an '*'. I > > wish to construct a new list, call it 'n' which is all > the members of l > > that start and end with '*', with the '*'s removed. > > > > So in the case above n would be ['nbh', 'jkjsdfjasd'] > > > > the following works: > > > > r = re.compile('\*(.+)\*') > > > > def f(s): > > m = r.match(s) > > if m: > > return > m.group(1) > > else: > > return '' > > > > n = [f(x) for x in l if r.match(x)] > > > > > > > > But it is inefficient, because it is matching the > regex twice for each > > item, and it is a bit ugly. > > > > I could use: > > > > > > n = [] > > for x in keys: > > m = r.match(x) > > if m: > > > n.append(m.group(1)) > > > > > > It is more efficient, but much uglier. > > It's efficient and easy to understand; maybe you have to > readjust your > taste. > > > Does anyone have a better solution? > > In this case an approach based on string slicing is > probably best. When the > regular expression gets more complex you can use a nested a > generator > expression: > > >>> items = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', > '*jkjsdfjasd*', 'rewr'] > >>> match = re.compile(r"\*(.+)\*").match > >>> [m.group(1) for m in (match(s) for s in items) > if m is not None] > ['nbh', 'jkjsdfjasd'] > I am going to use string slicing, re is the wrong tool for the job. But this is what I was looking for when I posted. Simple, elegant and efficient. Thanks all, -EdK Ed Keith e_...@yahoo.com Blog: edkeith.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Problems with debugging Lists
Hello again. I wrote small class for generating and accessing globalized Dictionary. And of course I want to add some kind of debug ability to check what is inside... In php we had print_r function to see entire array structure. After some search I found some equal module named pprint. And some how this module wont work with mod_wsgi it was something about mod_wsgi portability standards. After some research there where some thing about putting some variables in apache config to disable this. And now I can see some dictionary structure in my apache log and I got some errors like r += pprint.pprint(self.data) TypeError: cannot concatenate 'str' and 'NoneType' objects So is there any way to get dictionary structure in string format ? Another question is. When I import a module from top is it available for later imported modules # -*- coding: utf-8 -*- import os, sys, cgi, pprint import cgitb cgitb.enable() def application(environ, start_response): sys.path.append(environ['DOCUMENT_ROOT']+"core") #sys.path.append(environ['DOCUMENT_ROOT']+"util") import registry, k5 #from print_r import print_r # new registry r = registry.Registry(environ) r.set_entry('hede','hodo') #response_headers = [('Content-type',k5.headers['content-type']+'; charset='+k5.headers['charset'])] #start_response(kk5.headers['status'], response_headers) # build the response body possibly using the environ dictionary response_body = 'The request method was %s' % environ['REQUEST_METHOD'] response_body += '' response_body += str(r.debug()) # HTTP response code and message status = '200 OK' # These are HTTP headers expected by the client. # They must be wrapped as a list of tupled pairs: # [(Header name, Header value)]. response_headers = [('Content-Type', 'text/plain'), ('Content-Length', str(len(response_body)))] # Send them to the server using the supplied function start_response(status, response_headers) # Return the response body. # Notice it is wrapped in a list although it could be any iterable. return [response_body] Following script was not working. I have to re import pprint from registry. Is it normal or what is my problem :) Regards -- http://mail.python.org/mailman/listinfo/python-list
Re: expat having problems with entities (&)
On Dec 11, 4:39 pm, Rami Chowdhury wrote: > On Fri, Dec 11, 2009 at 13:23, nnguyen wrote: > > > Any ideas on any expat tricks I'm missing out on? I'm also inclined to > > try another parser that can keep the string together when there are > > entities, or at least ampersands. > > IIRC expat explicitly does not guarantee that character data will be > handed to the CharacterDataHandler in complete blocks. If you're > certain you want to stay at such a low level, I would just modify your > char_data method to append character data to self.current_data rather > than replacing it. Personally, if I had the option (e.g. Python 2.5+) > I'd use ElementTree... > Well the appending trick worked. From some logging I figured out that it was reading through those bits of current_data before getting to the subfield ending element (which is kinda obvious when you think about it). So I just used a += and made sure to clear out current_data when it hits a subfield ending element. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to implement Varient/Tagged Unions/Pattern Matching in Python?
In article <358b227c-d836-4243-b79a-57258590a...@a10g2000pre.googlegroups.com>, metal wrote: > >I want to get pattern matching like OCaml in python(ref:http:// >en.wikipedia.org/wiki/Tagged_union) > >I consider the syntax: > >def decl(): > def Plus(expr, expr): pass > def Minus(expr, expr): pass > def Times(expr, expr): pass > def Divide(expr, expr): pass > def Value(str): pass > @enum > def expr(Plus, Minus, Times, Divide, Value): pass > declare_types(locals()) > >def f(e): > def _Plus(l, r): > return '(%s+%s)' % (l, r) > def _Minus(l, r): > return '(%s-%s)' % (l, r) > def _Times(l, r): > return '(%s*%s)' % (l, r) > def _Divide(l, r): > return '(%s/%s)' % (l, r) > def _Value(x): > return x > try: > match(e, locals()) # visitor pattern > except NoMatchedError: > pass Perhaps you want to define what match() does? -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. -- http://mail.python.org/mailman/listinfo/python-list
Re: expat having problems with entities (&)
On Dec 11, 4:23 pm, nnguyen wrote: > I need expat to parse this block of xml: > > > c-P&P > LOT 3677 > (F) > > > I need to parse the xml and return a dictionary that follows roughly > the same layout as the xml. Currently the code for the class handling > this is: > > class XML2Map(): > > def __init__(self): > """ """ > self.parser = expat.ParserCreate() > > self.parser.StartElementHandler = self.start_element > self.parser.EndElementHandler = self.end_element > self.parser.CharacterDataHandler = self.char_data > > self.map = [] #not a dictionary > > self.current_tag = '' > self.current_subfields = [] > self.current_sub = '' > self.current_data = '' > > def parse_xml(self, xml_text): > self.parser.Parse(xml_text, 1) > > def start_element(self, name, attrs): > if name == 'datafield': > self.current_tag = attrs['tag'] > > elif name == 'subfield': > self.current_sub = attrs['code'] > > def char_data(self, data): > self.current_data = data > > def end_element(self, name): > if name == 'subfield': > self.current_subfields.append([self.current_sub, > self.current_data]) > > elif name == 'datafield': > self.map.append({'tag': self.current_tag, 'subfields': > self.current_subfields}) > self.current_subfields = [] #resetting the values for next > subfields > > Right now my problem is that when it's parsing the subfield element > with the data "c-P&P", it's not taking the whole data, but instead > it's breaking it into "c-P", "&", "P". i'm not an expert with expat, > and I couldn't find a lot of information on how it handles specific > entities. > > In the resulting map, instead of: > > {'tag': u'991', 'subfields': [[u'b', u'c-P&P'], [u'h', u'LOT 3677'], > [u'm', u'(F)']], 'inds': [u' ', u' ']} > > I get this: > > {'tag': u'991', 'subfields': [[u'b', u'P'], [u'h', u'LOT 3677'], > [u'm', u'(F)']], 'inds': [u' ', u' ']} > > In the debugger, I can see that current_data gets assigned "c-P", then > "&", and then "P". > > Any ideas on any expat tricks I'm missing out on? I'm also inclined to > try another parser that can keep the string together when there are > entities, or at least ampersands. I forgot, ignore the "'inds':..." in the output above, it's just another part of the xml I had to parse that isn't important to this discussion. -- http://mail.python.org/mailman/listinfo/python-list
Re: expat having problems with entities (&)
On Fri, Dec 11, 2009 at 13:23, nnguyen wrote: > > Any ideas on any expat tricks I'm missing out on? I'm also inclined to > try another parser that can keep the string together when there are > entities, or at least ampersands. IIRC expat explicitly does not guarantee that character data will be handed to the CharacterDataHandler in complete blocks. If you're certain you want to stay at such a low level, I would just modify your char_data method to append character data to self.current_data rather than replacing it. Personally, if I had the option (e.g. Python 2.5+) I'd use ElementTree... -- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: a list/re problem
Ed Keith wrote: > I have a problem and I am trying to find a solution to it that is both > efficient and elegant. > > I have a list call it 'l': > > l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] > > Notice that some of the items in the list start and end with an '*'. I > wish to construct a new list, call it 'n' which is all the members of l > that start and end with '*', with the '*'s removed. > > So in the case above n would be ['nbh', 'jkjsdfjasd'] > > the following works: > > r = re.compile('\*(.+)\*') > > def f(s): > m = r.match(s) > if m: > return m.group(1) > else: > return '' > > n = [f(x) for x in l if r.match(x)] > > > > But it is inefficient, because it is matching the regex twice for each > item, and it is a bit ugly. > > I could use: > > > n = [] > for x in keys: > m = r.match(x) > if m: > n.append(m.group(1)) > > > It is more efficient, but much uglier. It's efficient and easy to understand; maybe you have to readjust your taste. > Does anyone have a better solution? In this case an approach based on string slicing is probably best. When the regular expression gets more complex you can use a nested a generator expression: >>> items = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] >>> match = re.compile(r"\*(.+)\*").match >>> [m.group(1) for m in (match(s) for s in items) if m is not None] ['nbh', 'jkjsdfjasd'] Peter -- http://mail.python.org/mailman/listinfo/python-list
expat having problems with entities (&)
I need expat to parse this block of xml: c-P&P LOT 3677 (F) I need to parse the xml and return a dictionary that follows roughly the same layout as the xml. Currently the code for the class handling this is: class XML2Map(): def __init__(self): """ """ self.parser = expat.ParserCreate() self.parser.StartElementHandler = self.start_element self.parser.EndElementHandler = self.end_element self.parser.CharacterDataHandler = self.char_data self.map = [] #not a dictionary self.current_tag = '' self.current_subfields = [] self.current_sub = '' self.current_data = '' def parse_xml(self, xml_text): self.parser.Parse(xml_text, 1) def start_element(self, name, attrs): if name == 'datafield': self.current_tag = attrs['tag'] elif name == 'subfield': self.current_sub = attrs['code'] def char_data(self, data): self.current_data = data def end_element(self, name): if name == 'subfield': self.current_subfields.append([self.current_sub, self.current_data]) elif name == 'datafield': self.map.append({'tag': self.current_tag, 'subfields': self.current_subfields}) self.current_subfields = [] #resetting the values for next subfields Right now my problem is that when it's parsing the subfield element with the data "c-P&P", it's not taking the whole data, but instead it's breaking it into "c-P", "&", "P". i'm not an expert with expat, and I couldn't find a lot of information on how it handles specific entities. In the resulting map, instead of: {'tag': u'991', 'subfields': [[u'b', u'c-P&P'], [u'h', u'LOT 3677'], [u'm', u'(F)']], 'inds': [u' ', u' ']} I get this: {'tag': u'991', 'subfields': [[u'b', u'P'], [u'h', u'LOT 3677'], [u'm', u'(F)']], 'inds': [u' ', u' ']} In the debugger, I can see that current_data gets assigned "c-P", then "&", and then "P". Any ideas on any expat tricks I'm missing out on? I'm also inclined to try another parser that can keep the string together when there are entities, or at least ampersands. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which graph library is best suited for large graphs?
On 12/11/2009 10:27 PM, Neal Becker wrote: Which library would you choose? Hmm i have tried python-graph and was happy with itbut the most use i did was for complete graphs of 60-65 nodes.. Also there is an experimental branch for faster implementations, which is under development. -- == Anand J http://sites.google.com/a/cbcs.ac.in/students/anand == The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie -- http://mail.python.org/mailman/listinfo/python-list
Re: a list/re problem
l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] Notice that some of the items in the list start and end with an '*'. I wish to construct a new list, call it 'n' which is all the members of l that start and end with '*', with the '*'s removed. So in the case above n would be ['nbh', 'jkjsdfjasd'] the following works: r = re.compile('\*(.+)\*') def f(s): m = r.match(s) if m: return m.group(1) else: return '' n = [f(x) for x in l if r.match(x)] But it is inefficient, because it is matching the regex twice for each item, and it is a bit ugly. You can skip the function by writing that as n = [r.match(s).group(1) for s in l if r.match(s)] but it doesn't solve your match-twice problem. I'd skip regexps completely and do something like n = [s[1:-1] for s in l if s.startswith('*') and s.endswith('*') ] And this is coming from a guy that tends to overuse regexps :) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: a list/re problem
On 2009-12-11, Ed Keith wrote: > I have a problem and I am trying to find a solution to it that is both > efficient and elegant. > > I have a list call it 'l': > > l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] > Notice that some of the items in the list start and end with > an '*'. I wish to construct a new list, call it 'n' which is > all the members of l that start and end with '*', with the > '*'s removed. > > So in the case above n would be ['nbh', 'jkjsdfjasd'] [s[1:-1] for s in l if (s[0] == s[-1] == '*')] -- Grant Edwards grante Yow! Used staples are good at with SOY SAUCE! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: a list/re problem
2009/12/11 Ed Keith : > I have a problem and I am trying to find a solution to it that is both > efficient and elegant. > > I have a list call it 'l': > > l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] > > Notice that some of the items in the list start and end with an '*'. I wish > to construct a new list, call it 'n' which is all the members of l that start > and end with '*', with the '*'s removed. > > So in the case above n would be ['nbh', 'jkjsdfjasd'] > > the following works: > > r = re.compile('\*(.+)\*') > > def f(s): > m = r.match(s) > if m: > return m.group(1) > else: > return '' > > n = [f(x) for x in l if r.match(x)] > > > > But it is inefficient, because it is matching the regex twice for each item, > and it is a bit ugly. > > I could use: > > > n = [] > for x in keys: > m = r.match(x) > if m: > n.append(m.group(1)) > > > It is more efficient, but much uglier. > > Does anyone have a better solution? > > Thank, > > -EdK > > > Ed Keith > e_...@yahoo.com > > Blog: edkeith.blogspot.com > > > > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, maybe you could use a list comprehension or the equivalent loop just using the string methods and slicing? >>> lst = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] >>> [item[1:-1] for item in lst if (item.startswith("*") and >>> item.endswith("*"))] ['nbh', 'jkjsdfjasd'] >>> hth, vbr -- http://mail.python.org/mailman/listinfo/python-list
Re: a list/re problem
On Fri, Dec 11, 2009 at 9:49 PM, Ed Keith wrote: > I have a problem and I am trying to find a solution to it that is both > efficient and elegant. > > I have a list call it 'l': > > l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] > > Notice that some of the items in the list start and end with an '*'. I wish > to construct a new list, call it 'n' which is all the members of l that start > and end with '*', with the '*'s removed. > > So in the case above n would be ['nbh', 'jkjsdfjasd'] > > the following works: > > r = re.compile('\*(.+)\*') > > def f(s): > m = r.match(s) > if m: > return m.group(1) > else: > return '' > > n = [f(x) for x in l if r.match(x)] > > > > But it is inefficient, because it is matching the regex twice for each item, > and it is a bit ugly. > > I could use: > > > n = [] > for x in keys: > m = r.match(x) > if m: > n.append(m.group(1)) > > > It is more efficient, but much uglier. > > Does anyone have a better solution? Regexes seem like the proverbial sledgehammer to crack a nut here. Note that '*' if it is present, is always 1 character, so we can write: n = [x[1:-1] for x in l if x.startswith("*") and x.endswith("*")] -- André Engels, andreeng...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
a list/re problem
I have a problem and I am trying to find a solution to it that is both efficient and elegant. I have a list call it 'l': l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr'] Notice that some of the items in the list start and end with an '*'. I wish to construct a new list, call it 'n' which is all the members of l that start and end with '*', with the '*'s removed. So in the case above n would be ['nbh', 'jkjsdfjasd'] the following works: r = re.compile('\*(.+)\*') def f(s): m = r.match(s) if m: return m.group(1) else: return '' n = [f(x) for x in l if r.match(x)] But it is inefficient, because it is matching the regex twice for each item, and it is a bit ugly. I could use: n = [] for x in keys: m = r.match(x) if m: n.append(m.group(1)) It is more efficient, but much uglier. Does anyone have a better solution? Thank, -EdK Ed Keith e_...@yahoo.com Blog: edkeith.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
datetime 'NoneType' sporadic error
When using the datetime module, I sporadically get " 'NoneType' object has no attribute 'datetime' " on line 40: http://dpaste.com/hold/132156/ Sorry, I don't have the traceback, this is an error that was sent to me by one of the users. It only happens occasionally. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving from PHP to Python. Is it Possible
On Dec 11, 8:58 am, MRAB wrote: > output = [''] > output.append('My Page') > output.append('') > output.append('Powers of two\n') > for n in range(1, 11): > output.append('%s' % (2 ** n)) > > output.append('') > print ''.join(output) Agreed (I might join on '\n' though), I was just trying to introduce as few new concepts as possible :) -- http://mail.python.org/mailman/listinfo/python-list
Re: __mul__ vs __rmul__ (and others) priority for different classes
dmitrey wrote: hi all, I have created a class MyClass and defined methods like __add__, __mul__, __pow__, __radd__, __rmul__ etc. Also, they are defined to work with numbers, Python lists and numpy.arrays. Both Python lists and numpy arrays have their own methods __add__, __mul__, __pow__, __radd__, __rmul__ etc. If I involve myPythonList * myClassInstance it returns just result of my __rmul__; but when I invoke nuumpy_arr*myClassInstance it returns another numpy array with elements [nuumpy_arr[0]*myClassInstance, nuumpy_arr[1]*myClassInstance, ...]. Can I somehow prevent numpy array of using it __mul__ etc methods? (and use only my __rmul__, __radd__, etc instead)? No. you have to put your class instance first to get priority. Given a op b, python first calls a.__op__(b) and only if that fails, which it will for most builtin objects when b is MyClass, b.__rop__(a). Numpy arrays, however, are more broadminded about what they will work with. If your operations are not commutative, you will either have to wrap numpy arrays in a class that disables the special methods or use explicit function calls. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial - escape codes transportation
On 2009-12-11, Grant Edwards wrote: > On 2009-12-11, ObservantP wrote: >> need help. newbie. pyserial and dot matrix printer. issue- >> escape codes arrive at printer ( verified from hex dump) but >> do not get applied. > > What you're saying is your printer isn't working correctly. BTW, I (among others) filter out all posts made from google groups. I only stumbled across your posting by accident while playing with my newsreader configuration. I won't see any follow-up postings you make if they're from google groups. -- Grant Edwards grante Yow! ! Everybody out of at the GENETIC POOL! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial - escape codes transportation
On 2009-12-11, ObservantP wrote: > need help. newbie. pyserial and dot matrix printer. > issue- escape codes arrive at printer ( verified from hex dump) but do > not get applied. What you're saying is your printer isn't working correctly. > printer make/model STAR POS printer SP500. oddly, printer > commands not initiated with the escape code .i.e. a symbol, > work fine. > > > import serial > ser=serial.Serial(0) > > ser.bytesize=7 > ser.timeout=1 > ser.dsrdtr=1 > ser.write('PySerial'+'\n') > ser.write('Star SP500'+'\n') > > > > #Double Width On 14 SO = Or ESC W 1 / 0 > # Off 20 DC4= > > ser.write('' +'Double Width-Symbol\n') #Good > ser.write('' +'Reset\n') #Good > ser.write('\n') #Good > > ser.write('Xw1\n'+'Double Width-ESC\n')#Nope ( Nor CHR(027) FWIW, that's _not_ sending an ASCII escape character. It's sending a string starting with a caret and a square bracket. I don't know what you're actually trying to send, but my guess is that you want is '\033w1' or '\x1Bw1' -- Grant Edwards grante Yow! I'm also against at BODY-SURFING!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
How can I get the target platform info of a dll with Python 3.1.1?
I have many dll files and I would like to select them into two different folders (PC and PPC). For this I need to know the target platform of the dll file or any other details about its platform. I use Python 3.1.1. I have tried the win32api which does not compatible with this Python version. So, I try to use the ctypes.windll with try-except method where the try is true the loaded- in dll is "PC" and if not, unable to load the dll that is "PPC". But, I have a problem with this idea. There are some dll files which I know that "PC" dll but unable to load in memory. The try-except does not work with them. So, I need to request info from the dll file about the target platform of itself. Do you have any idea about this problem? Many thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list
How can I get the target platform info of a dll with Python 3.1.1?
I have many dll files and I would like to select them into two different folders (PC and PPC). For this I need to know the target platform of the dll file or any other details about its platform. I use Python 3.1.1. I have tried the win32api which does not compatible with this Python version. So, I try to use the ctypes.windll with try-except method where the try is true the loaded- in dll is "PC" and if not, unable to load the dll that is "PPC". But, I have a problem with this idea. There are some dll files which I know that "PC" dll but unable to load in memory. The try-except does not work with them. So, I need to request info from the dll file about the target platform of itself. Do you have any idea about this problem? Many thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQL set and enum, calling values
On Fri, Dec 11, 2009 at 3:12 PM, Carsten Haese wrote: > Victor Subervi wrote: > > [...] if I go to print, say, > > colFieldValues[20], which is a set, it prints out the whole set: > > set('Extra-small','Small','Medium','Large','XLarge','XXLarge','XXXLarge') > > But if I print out colFieldValues[20][0], it prints out "s". > > The only reasonable explanation of this behavior is that despite all > your wishing for it to be a set, colFieldValues[20] is in fact not a > set, but rather a string. It is a string containing the letter s, > followed by the letter e, followed by the letter t, followed by an > openening parenthesis, and so on. > > > Also, how can I test > > for it? It's an instance of string. How do I know if it's a set? > > That's a fantastic question. Python thinks it's a string. What makes you > think it's a set? > Right. I'm doing it the ugly way with the truncating tuple and string replace. V -- http://mail.python.org/mailman/listinfo/python-list
Re: Virtual file for subprocess
On 2009-12-11, Lie Ryan wrote: > On 12/12/2009 4:07 AM, bobnotbob wrote: >> I am calling external executable from my python program (using >> subprocess). This external program's output is a text file which I >> then read and parse. Is there any way to "sandbox" the calling of >> this external program so that it writes to a virtual file instead of >> the hardcoded text? > > If the program writes its outputs to the stdout, you can > redirect the program's stdout using subprocess, try to find a > switch that will tell it to write to stdout. Otherwise, you're > pretty much stuck to using a real file AFAIK. Most Unix systems have paths that you can pass to programs which think they need to write to "files". Accessing those files actually access already open file descriptors such as stdin, stdout, and stderr. On Linux, for example, you can tell the program to write to /proc/self/fd/1 and that's actually stdout which can then be a pipe connected to the Python program that invoked the program. This can be very useful when executing a program which can be told what file to write to, but who's author was too narrow-minded to provide the option to send output to stdout. If you need to get fancy you can create multiple input/output pipes that are inherited by the child program and then references as /proc/self/fd/. -- Grant Edwards grante Yow! These PRESERVES should at be FORCE-FED to PENTAGON visi.comOFFICIALS!! -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQL set and enum, calling values
Victor Subervi wrote: > [...] if I go to print, say, > colFieldValues[20], which is a set, it prints out the whole set: > set('Extra-small','Small','Medium','Large','XLarge','XXLarge','XXXLarge') > But if I print out colFieldValues[20][0], it prints out "s". The only reasonable explanation of this behavior is that despite all your wishing for it to be a set, colFieldValues[20] is in fact not a set, but rather a string. It is a string containing the letter s, followed by the letter e, followed by the letter t, followed by an openening parenthesis, and so on. > Also, how can I test > for it? It's an instance of string. How do I know if it's a set? That's a fantastic question. Python thinks it's a string. What makes you think it's a set? -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: pyZui - anyone know about this?
Donn wrote: On Friday 11 December 2009 12:38:46 Daniel Fetchinson wrote: Youtube has a link 'Send message' on the profile of users, maybe sending a message to the person who uploaded the video will give you a useful response. I'm a Tube-tard so that never crossed my mind. Will give it a go. \d please let us know when you find more information about the project. thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: Virtual file for subprocess
On 12/12/2009 4:07 AM, bobnotbob wrote: I am calling external executable from my python program (using subprocess). This external program's output is a text file which I then read and parse. Is there any way to "sandbox" the calling of this external program so that it writes to a virtual file instead of the hardcoded text? If the program writes its outputs to the stdout, you can redirect the program's stdout using subprocess, try to find a switch that will tell it to write to stdout. Otherwise, you're pretty much stuck to using a real file AFAIK. -- http://mail.python.org/mailman/listinfo/python-list
HTTPS - HTTPPasswordMgrWithDefaultRealm
1) I have an application that accesses a web site via HTTPS using a certificate. The primary url returns a 302 redirect, urllib2 then goes to this address and gets a 401, which if the passwordMgr has be setup properly then connects. I have been able to determine a set of uri's that if fed to the passwordMgr.add_password() make things work. The problem is that depending on where the application is run from the redirect may be to different url's. I would like to dynamically catch the redirect and then format add_password() properly to add this uri and the user/password information rather than having to determine all possible uri's and load passwordMgr at init time. If I overload the redirect handler when it gets there I don't have access to the passwordMgr. Following is a snipit of the code: passwordMgr = urllib2.HTTPPasswordMgrWithDefaultRealm() Here I am setting passwordMgr up with all known uri's, but if I get redirected to some other address It no longer works for uri in ('payex.adp.com','agateway.adp.com','bgateway.adp.com','.adp.com '): passwordMgr.add_password(None, uri, usr, pwd) basicAuthHndlr = urllib2.HTTPBasicAuthHandler(passwordMgr) cookies = cookielib.CookieJar() cookieHndlr = urllib2.HTTPCookieProcessor(cookies) self.opener = urllib2.build_opener(MultipartPostHandler, HTTPSClientAuthHandler(httpDebug),basicAuthHndlr,cookieHndlr,urllib2.HTTPRedirectHandler()) I then call: self.opener(request) 2) I have a second problem, for which I have created an ugly workaround, Namely I need a way to give the HTTPSConnection.__ini__() a reference to the cert file. The HTTPSClientAuthHandler do_open method takes a ref to the HTTPSClientAuthConnection not an instance, so I overloaded this class and get the cert_file via a previously set global ref. I would like a better way to feed the cert file. Here is the code I am using: class HTTPSClientAuthConnection(httplib.HTTPSConnection): def __init__(self, host, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): # nb cert_file is global and set in UrllibPX httplib.HTTPSConnection.__init__(self, host, cert_file=cert_file) doseq = 1 class HTTPSClientAuthHandler(urllib2.HTTPSHandler): def https_open(self, req): for tries in range(3): try: ret = self.do_open(HTTPSClientAuthConnection, req) return ret except URLError: log = logging.getLogger() log.warn("problem connecting") raise thanks, -- Max Slimmer -- http://mail.python.org/mailman/listinfo/python-list
__mul__ vs __rmul__ (and others) priority for different classes
hi all, I have created a class MyClass and defined methods like __add__, __mul__, __pow__, __radd__, __rmul__ etc. Also, they are defined to work with numbers, Python lists and numpy.arrays. Both Python lists and numpy arrays have their own methods __add__, __mul__, __pow__, __radd__, __rmul__ etc. If I involve myPythonList * myClassInstance it returns just result of my __rmul__; but when I invoke nuumpy_arr*myClassInstance it returns another numpy array with elements [nuumpy_arr[0]*myClassInstance, nuumpy_arr[1]*myClassInstance, ...]. Can I somehow prevent numpy array of using it __mul__ etc methods? (and use only my __rmul__, __radd__, etc instead)? Thank you in advance, D. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using hash to see if object's attributes have changed
On Dec 11, 10:17 am, Robert Kern wrote: > On 2009-12-11 12:03 PM, Bryan wrote: > > > When a user submits a request to update an object in my web app, I > > make the changes in the DB, along w/ who last updated it and when. I > > only want to update the updated/updatedBy columns in the DB if the > > data has actually changed however. > > > I'm thinking of having the object in question be able to return a list > > of its values that constitute its state. Then I can take a hash of > > that list as the object exists in the database before the request, and > > then on the object that the user has made changes to. If they are not > > equal, the user has changed the object. > > It *might* work, but probably won't be robust especially as you are relying on > the string representation. You would be much better off using an ORM, which > will > do all of this for you. This is exactly what they are for. > > They usually determine whether attributes have change by instrumentation > rather > than inspection. If you still don't want to use a full ORM, you should at > least > emulate that strategy. Add descriptors to your classes for each attribute you > want to map to a column. On __set__, they should compare the new value to the > old, and set a "dirty" flag if the the attribute changes value. Or just > implement __setattr__ on your classes to do a similar check. > > -- > Robert Kern I am using sqlalchemy, and it does a pretty good job of this. The problem is that it considers an object changed whenever an attribute gets set after the object is loaded, even if the attribute is being set to the same value. Another thing I could do is when applying the user's changes to the object that was loaded from the db, only apply the change if the value is actually different. In that case I could use the ORM's isDirty() test that keeps track of what was set since being loaded. Then the object doesn't know anything about its state or isDirty() tests, only the controller would, which I like as it is less intrusive, but it also is dependent on a ORM. Instrumentation would require a bit more work. I would have to watch for changes using set/get and __dict__ access. Also, I would have to be able to say, "Has this object changed since time x". Imagine loading an object from the db. Depending on the ORM implementation, it may instantiate an object, then set all its attributes from the DB row, which would trigger my isDirty instrumentation. So it would look dirty even fresh out of the DB w/ no changes. So I would have to be able to manually clear the isDirty flag. Not that any of this is impossible, just more complex. -- http://mail.python.org/mailman/listinfo/python-list
Re: Recommendation for small, fast, Python based web server
On 11-12-2009 14:52, Antoine Pitrou wrote: Hello, I've looked at the web servers that come bundled with the Python standard library[1] and they are too slow. Apparently you have debugged your speed issue so I suppose you don't have performance problems anymore. Do note, however, that Python is generally not as fast as C -- especially for low-level stuff -- and a Python Web server will probably serve around 10x less requests per second than a C Web server like Apache (this will still give you hundreds of simple requests per second on a modern machine). I don't think that number is fair for Python. I think a well written Python web server can perform in the same ballpark as most mainstream web servers written in C. Especially Apache, which really isn't a top performer. And I'm pretty sure a well written Python server can outperform a badly written C based server easily. -irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving from PHP to Python. Is it Possible
> So My question is. > For example I had this kind of python file and we want to use this as plugin > template > > > <% > for n in range(3): > # This indent will persist > %> > This paragraph will be > repeated 3 times. > <% > # This line will cause the block to end > %> > This line will only be shown once. > > > on execution time, I want to import this template file, execute as python > script and store output in a GLOBAL dictionary for later usage. > > Is it possible ? > Have you checked out one of the templating systems modules ? I have used Cheetah quite successfully, but there a numerous other options. http://www.cheetahtemplate.org/ I think you will find that a template system (like Cheetah) will give you the best results with the most maintainable structure. g. -- http://mail.python.org/mailman/listinfo/python-list
A try with WebScraping using Python
Hi >From the tutorial found on the net i came to know about WebScraping using Python. I thought to give a try with it. My wish is to extract the contact mail id's from all the posts published till now in the below link http://fossjobs.wordpress.com/ With Firebug add-on its easy to find the location of mail id's inside HTML DOM tree. I dont know how to download all the web pages i.e., the coding part Which library i can use to download ? ( mechanize or windmill ) Help me Thanks Raji. S http://sraji.wordpress.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: switch
On 12/10/2009 09:22 PM, John Bokma wrote: Tim Chase writes: Please don't delete attribution line(s), added: Asun Friere writes: I tend to prune them because a good newsreader will thread messages and put my reply in the context of the message to which I'm replying. Both Thunderbird and Claws Mail seem to have correctly placed my message under Asun's message. However your reply to mine failed to show up under my message in either program (it showed up under the top-level post by Hong Zhang in both apps). Looks like you're sending from Gnus...a threading/reply bug in Gnus perhaps? Anyways...I'll leave them in for this reply. phone.update_from_record(record) This switch statement belongs to one guy. One guy who wants to know how to do everything that needs to be done to Phones no matter who asks This is where you make a false assumption -- the contents and parsing of the "switch" are provider-specific in this case, mapping to a common ontology of the Phone object: In that case, why not give the classes Asun suggested all the same base class: Phone? Whether the logic gets put in a subclass of Phone, or whether it gets put in a provider Phone-factory (as it currently does...the Provider superclass also knows how to auto-detect the format of a filename/path passed to it and know whether it can handle it), there's still a rat's-nest of if/else/switch type logic, each branch of which usually involves a single assignment, or further sub-branch checking. So I often have things that would pseudo-code like switch rectype: case '01': phone.textmessaging += row['txtmsgcost'] count = row['count'] switch subtype: case 'a': phone.textmessagessent += count case 'b': phone.textmessagesreceived += count case 'c': phone.pagessent += count case 'd': phone.pagesreceived += count case '02': ... which is fairly readable. However, with a method-dispatch dictionary, this flattens the hierarchy to "def"s at the same level (class definition scope), leaving the hierarchy visible only in the call-graph. Turning each of these a function would - obfuscate the flow and processing hierarchy - create a profusion of 1-3 line functions (about 50 Phone attributes, times currently about 15 provider formats, plus a duplication factor of about 10% where certain fields aggregate from various sources in the data, accumulating in a single Phone field) - have the overhead of several million function-calls Yes, having been programming since I was in middle-school (quick calculation yields a "boy I'm old" estimate of about 20 years...does anybody miss 360k 5.25" floppy disks? :) I do miss cassette tapes and the wheee kkkrggrggrgrgrg of a program loading. Heh, one of the other things I miss: booting my Apple ][+ and hitting the button, resulting in a prompt where I could code in under 2 seconds from power-on. Can't say I miss tape at all though :) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Using hash to see if object's attributes have changed
On 2009-12-11 12:03 PM, Bryan wrote: When a user submits a request to update an object in my web app, I make the changes in the DB, along w/ who last updated it and when. I only want to update the updated/updatedBy columns in the DB if the data has actually changed however. I'm thinking of having the object in question be able to return a list of its values that constitute its state. Then I can take a hash of that list as the object exists in the database before the request, and then on the object that the user has made changes to. If they are not equal, the user has changed the object. It *might* work, but probably won't be robust especially as you are relying on the string representation. You would be much better off using an ORM, which will do all of this for you. This is exactly what they are for. They usually determine whether attributes have change by instrumentation rather than inspection. If you still don't want to use a full ORM, you should at least emulate that strategy. Add descriptors to your classes for each attribute you want to map to a column. On __set__, they should compare the new value to the old, and set a "dirty" flag if the the attribute changes value. Or just implement __setattr__ on your classes to do a similar check. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
MySQL set and enum, calling values
Hi; I have the following code: cursor.execute('describe %s;' % store) colFields, colFieldValues = [itm[0] for itm in cursor], [itm[1] for itm in cursor] ... for col in colFields: ... print '%s: %s\n' % (col, colValue[0]) Don't worry about the colValue[0]. In fact, the code throws no errors. However, when colValue[0] (which is called from the MySQL table) is a set as opposed to, say, a string, it prints out: Set([]) which is natural, because there isn't anything in the set. What I'm trying to accomplish, however, is to offer a select of the possible values of that set as are available from the describe and caught in the tuple colFieldValues. For example, if I go to print, say, colFieldValues[20], which is a set, it prints out the whole set: set('Extra-small','Small','Medium','Large','XLarge','XXLarge','XXXLarge') But if I print out colFieldValues[20][0], it prints out "s". Now, I suppose I could do something like lop off the ends of colFieldValues[20] thus: tmp = string.split(colFieldValues[20][4:-2], "','") but boy that's inelegant! Any better suggestions? Also, how can I test for it? It's an instance of string. How do I know if it's a set? TIA, Victor -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: WHIFF.0.7 += GAE + jQueryUI + internationalization + testdrive = (last beta?)
Aaron Watters wrote: That was a joke in the tree view. You clicked on the "science link" in the tree hierarchy. I will fix it due to your complaint. Fixed. Now clicking on the same link goes to "Scientific American". Perhaps I was not clear enough. I am using FireFox 3.5 with Flashblock which blocks Flash content until one clicks twice on the space to explicitly open the Flash content. When I clicked on the space for your OpenFlashChart example, that is when the new window opended up, without warning, before I even saw the chart. I cannot reproduce this now because the chart seems to be in the local cache. If I had clcked on the link that is formatted as a link, that would have been a different matter, and I would have merely suggested a change such as the one you made, which I do approve of. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Using hash to see if object's attributes have changed
When a user submits a request to update an object in my web app, I make the changes in the DB, along w/ who last updated it and when. I only want to update the updated/updatedBy columns in the DB if the data has actually changed however. I'm thinking of having the object in question be able to return a list of its values that constitute its state. Then I can take a hash of that list as the object exists in the database before the request, and then on the object that the user has made changes to. If they are not equal, the user has changed the object. I imagine it working something like this: def getValues(obj): return [obj.a, obj.b, obj.c] foo = Obj() foo.a = foo.b = foo.c = 1 stateBefore = hashlib.sha1(str(getValues(foo))) foo.b = 'changed' stateNow = hashlib.sha1(str(getValues(foo))) assert stateBefore != stateNow I originally thought about running the hash on the __dict__ attribute, but there may be things in there that don't actually constitute the object's state as far as the database is concerned, so I thought it better to have each object be responsible for returning a list of values that constitute its state as far as the DB is concerned. I would appreciate any insight into why this is a good/bad idea given your past experiences. -- http://mail.python.org/mailman/listinfo/python-list
When to use mechanize and Windmill library during WebScraping ?
Hi For 'Webscraping with Python' mechanize or urllib2 and windmill or selenium libraries are used to download the webpages. http://www.packtpub.com/article/web-scraping-with-python The above link makes use of mechanize library to download the web pages. The below link uses windmill library to download the web pages. http://www.packtpub.com/article/web-scraping-with-python-part-2 I dont know when to use mechanize or windmill library It has been said that Windmill library is used when the HTML file is auto generated by the JavaScript code. Also i dont know how to identify whether the HTML file is auto generated by the JavaScript code or not ? Suggest me Thanks Raji. S http://sraji.wordpress.com/ -- http://mail.python.org/mailman/listinfo/python-list
eiger replacement?
The current hardware CPU: Intel(R) Pentium(R) 4 CPU 2.40GHz (2394.01-MHz 686-class CPU) Device Model: Hitachi HDT725025VLAT80 Serial Number:VF1100R107LS4K Firmware Version: V5DOA42A User Capacity:250,059,350,016 bytes available here http://www.kikatek.com/product_info.php?products_id=18618&source=froogle. real memory = 1073168384 (1023 MB) The machine is Dell PowerEdge 400SC. Memory will cost about £78 for a 2Gb upgrade kit. -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Virtual file for subprocess
I am calling external executable from my python program (using subprocess). This external program's output is a text file which I then read and parse. Is there any way to "sandbox" the calling of this external program so that it writes to a virtual file instead of the hardcoded text? -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving from PHP to Python. Is it Possible
On Friday 11 December 2009 05:11:12 pm zeph wrote: > Hi Sancar, Hi zeph, Thanks for reply. And here my needs about those 2 two programming technique. > 1) PHP does some really nasty things in how it treats globals, and you > will have to break yourself of those sorts of habits -- Python offers > much cleaner alternatives, like grouping similar functionality into > modules which can be imported; the import functionality in python is > pretty flexible. > Python won't pack a ton of garbage into a giant, global > 'dictionary' (what python calls associative arrays). There are > modules (bundled of code) which you can import to handle your needs. PHP was doing tons of nasty things. 10 years after I'm starting to understand some those and still not understand most programmers point of view to GLOBALS are evil. Anyhow I'm self learner plus I got heavy English limitation or probably I'm too narrow minded to see right thing. In my usage GLOBALS are too much useful to discard it. Anyway, I need to save my lots and lots of config variables in dictionary style global accessible location. Because. In my design We got lots of plugins, and those plugins may show in multiple times and multiple locations in a page. Each plugin may have setup values to affect entire page output. Because of this. I have to put those values in global location for future use. Is it possible If so ? how ? Is there any way to access directly or I have to wrote some kind of class like acting Windows registry in global scope ? > 2) Check out the traceback[1] module for retrieving the traceback info > for logging to a file, and cgitb[2] modules for printing the traceback > as HTML to your browser. > > 3) http://docs.python.org/ is a great place to start - it has a lot of > well written and generally thorough documentation with examples > > 4) It's better to collect all your eventual output into a string that > you print - there are examples at [3]. You can import from other > modules as needed (even conditionally), grow your string for output, > then finally print it like (this example was adapted from one found on > [3]): > > output = '' > output += 'My Page' > output += '' > output += 'Powers of two\n' > for n in range(1,11): > output += ''+str(2**n)+'' > > output += '' > print output > > > You can copy-paste this right into your Python interactive shell to > see the output. Note: += is inline string concatenation. Yes, I'm aware about this usage. We got similar syntax in php. Problem is we cannot give this kind of structure to our html designers. In php world our fine solution was using phtml mixed files for templates. It has two benefits. 1-) You dont need to string replace in templates (like in marker based templates) 2-) with php opcode caches your template will stored in ram. I believe second benefit was not available in python and my point of view escaping string replacement was good for performance. So My question is. For example I had this kind of python file and we want to use this as plugin template <% for n in range(3): # This indent will persist %> This paragraph will be repeated 3 times. <% # This line will cause the block to end %> This line will only be shown once. on execution time, I want to import this template file, execute as python script and store output in a GLOBAL dictionary for later usage. Is it possible ? > > 5) You can get form state from the cgi module[4] and FormStorage > object, and you can get server environment data from the os.environ[5] > dictionary; > > Good luck and keep on learning! :-) > > - zeph > > > References: > 1: http://docs.python.org/library/traceback.html > 2: http://docs.python.org/library/cgitb.html > 3: http://gnosis.cx/publish/programming/feature_5min_python.html > 4: http://docs.python.org/library/cgi.html > 5: http://docs.python.org/library/os.html#process-parameters > And thanks for those links. Regards... -- http://mail.python.org/mailman/listinfo/python-list
Re: Which graph library is best suited for large graphs?
Wolodja Wentland wrote: > On Fri, Dec 11, 2009 at 08:55 -0500, Neal Becker wrote: >> Bearophile wrote: >> > Wolodja Wentland: >> >> Which library would you choose? > >> > This one probably uses low memory, but I don't know if it works still: >> > http://osl.iu.edu/~dgregor/bgl-python/ > >> How about python interface to igraph? > > Don't know :-) as I have not yet worked with it. Why do you recommend it? My understanding is that igraph is a high performance graph library (all implemented in C). It seems to have a very active user community. There is also boost graph library, which IIRC also has a python interface. -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving from PHP to Python. Is it Possible
zeph wrote: [snip] 4) It's better to collect all your eventual output into a string that you print - there are examples at [3]. You can import from other modules as needed (even conditionally), grow your string for output, then finally print it like (this example was adapted from one found on [3]): output = '' output += 'My Page' output += '' output += 'Powers of two\n' for n in range(1,11): output += ''+str(2**n)+'' output += '' print output You can copy-paste this right into your Python interactive shell to see the output. Note: += is inline string concatenation. It's better to put the strings into a list and then concatenate them in one go: output = [''] output.append('My Page') output.append('') output.append('Powers of two\n') for n in range(1, 11): output.append('%s' % (2 ** n)) output.append('') print ''.join(output) -- http://mail.python.org/mailman/listinfo/python-list
Re: Which graph library is best suited for large graphs?
On Fri, Dec 11, 2009 at 07:31 -0800, IngoognI wrote: > On Dec 11, 11:12 am, Wolodja Wentland > wrote: > > Which library would you choose? > > looking at the galery at networx, it seems to be all balls 'n sticks, > how about writing the data to a file POV-Ray can read and render it > there? Huh? I am not really concerned about rendering the graphs but after a library with a small memory footprint. Preferably one that contains a number of typical algorithms. -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: C to Python
Benjamin Peterson, 10.12.2009 20:26: > Emeka writes: >> I am finding it difficult getting my head around PyObject_CallObject(x,y). I > need a gentle and thorough introduction to it. I also need examples. Could > someone come to my need? > > PyObject_CallFunction is probably easier to use. Hmm, I didn't see the original e-mail, but when it comes to "easier to use", I think the answer is basically Cython. http://cython.org Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Which graph library is best suited for large graphs?
On Dec 11, 11:12 am, Wolodja Wentland wrote: > > Which library would you choose? looking at the galery at networx, it seems to be all balls 'n sticks, how about writing the data to a file POV-Ray can read and render it there? -- http://mail.python.org/mailman/listinfo/python-list
Re: plain text parsing to html (newbie problem)
Lie Ryan wrote: > You can set MIME type and encoding from the MIME constructor > email.mime.Text.MIMEText("Bold Text", "html", "utf-8") > > are you importing "import mime" or "import email.mime" or "import > email.MIMEMultipart"? Hi Lie. I was importing as, 'from email.mime.text import MIMEText' which was returning that error because I don't have a mime subdir in my /usr/lib64/python2.4/email/ as I was expecting. 'import email.MIMEMultipart' worked perfectly (the mime methods are in the /email/ root). I'll try to redo my script right after I get some urgent things done. Thanks :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving from PHP to Python. Is it Possible
Hi Sancar, 1) PHP does some really nasty things in how it treats globals, and you will have to break yourself of those sorts of habits -- Python offers much cleaner alternatives, like grouping similar functionality into modules which can be imported; the import functionality in python is pretty flexible. Python won't pack a ton of garbage into a giant, global 'dictionary' (what python calls associative arrays). There are modules (bundled of code) which you can import to handle your needs. 2) Check out the traceback[1] module for retrieving the traceback info for logging to a file, and cgitb[2] modules for printing the traceback as HTML to your browser. 3) http://docs.python.org/ is a great place to start - it has a lot of well written and generally thorough documentation with examples 4) It's better to collect all your eventual output into a string that you print - there are examples at [3]. You can import from other modules as needed (even conditionally), grow your string for output, then finally print it like (this example was adapted from one found on [3]): output = '' output += 'My Page' output += '' output += 'Powers of two\n' for n in range(1,11): output += ''+str(2**n)+'' output += '' print output You can copy-paste this right into your Python interactive shell to see the output. Note: += is inline string concatenation. 5) You can get form state from the cgi module[4] and FormStorage object, and you can get server environment data from the os.environ[5] dictionary; Good luck and keep on learning! :-) - zeph References: 1: http://docs.python.org/library/traceback.html 2: http://docs.python.org/library/cgitb.html 3: http://gnosis.cx/publish/programming/feature_5min_python.html 4: http://docs.python.org/library/cgi.html 5: http://docs.python.org/library/os.html#process-parameters -- http://mail.python.org/mailman/listinfo/python-list
Re: extending dictonary
On Sat, 21 Nov 2009 09:25:38 +0100, nospam <"knutjbj(nospam)"@online.no> wrote: > Is there any way to extend the dictonary in such manner that I can > insert muliplay value to each keys and return one of the value as the > default value. I would like to have similar syste that I drawed out below. > > > tree[nucelotide_postionc][nucleotide]=default(value subtree) This should > be returned when doing lookup without any > tree[nucelotide_postionc][nucleotide]=Postive value > tree[nucelotide_postionc][nucleotide]=Negative value You could use the collections.defaultdict method. >>> >>> import collections >>> >>> example1 = collections.defaultdict(int) >>> >>> example1[1] 0 >>> >>> example2 = collections.defaultdict(list) >>> >>> example2[1] [] >>> >>> example3 = collections.defaultdict(dict) >>> >>> example3[1] {} >>> >>> # Make nested default dictionary >>> >>> def getNewOuterDictionary(): ...return collections.defaultdict(getNewInnerDictionary) >>> >>> def getNewInnerDictionary(): ...return collections.defaultdict([]) >>> >>> example4[1][1] [] Hope that helps. -- Roy Hyunjin Han http://invisibleroads.com We train people to become software developers and connect them to jobs and projects for local businesses. -- http://mail.python.org/mailman/listinfo/python-list
Re: extending dictonary
On Sat, 21 Nov 2009 09:25:38 +0100, nospam <"knutjbj(nospam)"@online.no> wrote: > Is there any way to extend the dictonary in such manner that I can > insert muliplay value to each keys and return one of the value as the > default value. I would like to have similar syste that I drawed out below. > > > tree[nucelotide_postionc][nucleotide]=default(value subtree) This should > be returned when doing lookup without any > tree[nucelotide_postionc][nucleotide]=Postive value > tree[nucelotide_postionc][nucleotide]=Negative value You could use the collections.defaultdict method. >>> import collections >>> example1 = collections.defaultdict(int) >>> example1[1] 0 >>> example2 = collections.defaultdict(list) >>> example2[1] [] >>> example3 = collections.defaultdict(dict) >>> example3[1] {} >>> # Make nested default dictionary >>> def getNewOuterDictionary(): ...return collections.defaultdict(getNewInnerDictionary) >>> def getNewInnerDictionary(): ...return collections.defaultdict([]) >>> example4[1][1] [] Hope that helps. -- Roy Hyunjin Han http://invisibleroads.com Training people to become software developers and connecting them to jobs and projects for local businesses -- http://mail.python.org/mailman/listinfo/python-list
Re: Python tricks with applescript in OS-X
On 12/11/09 3:13 AM, joa...@gmail.com wrote: Greetings, I've written a short document with some working examples of how to interface python with other applications in OS-X via applescript (had to spend some time figuring it out, and thought I might as well write it down). The examples include asking Google Earth for the latitude and longitude of the point at the center of its screen, or using the finder to pop-up a dialog window to get input from the user: http://juanreyero.com/article/python/os-x-python.html Cheers, Juan http://juanreyero.com Thanks for these examples. There is also a Python package that allows you to interface with an application's AppleScript dictionary via Python itself, without the intermediate step of using the osascript command-line tool: http://appscript.sourceforge.net/ You might find that of interest. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Active Directory ADO strange objects returned
Hi, I have a script that returns data from active directory using ADO. Everything works except for any fields that use a time value I get an instance of an object returned called . I know it's a time object because if I do object.HighPart or object.LowPart I get a value back. The bit I don't understand is how I inspect the object to work out what it is programmatically. Do I need to do some sort of makepy trickery so that the object is understood by Python? I have already makepy'd MS ActiveX Data Object 2.8. thanks, Marc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which graph library is best suited for large graphs?
On Fri, Dec 11, 2009 at 08:55 -0500, Neal Becker wrote: > Bearophile wrote: > > Wolodja Wentland: > >> Which library would you choose? > > This one probably uses low memory, but I don't know if it works still: > > http://osl.iu.edu/~dgregor/bgl-python/ > How about python interface to igraph? Don't know :-) as I have not yet worked with it. Why do you recommend it? -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: a huge shared read-only data in parallel accesses -- How? multithreading? multiprocessing?
Le Wed, 09 Dec 2009 06:58:11 -0800, Valery a écrit : > > I have a huge data structure that takes >50% of RAM. My goal is to have > many computational threads (or processes) that can have an efficient > read-access to the huge and complex data structure. > > "Efficient" in particular means "without serialization" and "without > unneeded lockings on read-only data" I was going to suggest memcached but it probably serializes non-atomic types. It doesn't mean it will be slow, though. Serialization implemented in C may well be faster than any "smart" non-serializing scheme implemented in Python. > 2. multi-threading > => d. CPython is told to have problems here because of GIL -- any > comments? What do you call "problems because of the GIL"? It is quite a vague statement, and an answer would depend on your OS, the number of threads you're willing to run, and whether you want to extract throughput from multiple threads or are just concerned about latency. In any case, you have to do some homework and compare the various approaches on your own data, and decide whether the numbers are satisfying to you. > I am a big fan of parallel map() approach I don't see what map() has to do with accessing data. map() is for *processing* of data. In other words, whether or not you use a map()-like primitive does not say anything about how the underlying data should be accessed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which graph library is best suited for large graphs?
Bearophile wrote: > Wolodja Wentland: >> Which library would you choose? > > This one probably uses low memory, but I don't know if it works still: > http://osl.iu.edu/~dgregor/bgl-python/ > > Bye, > bearophile How about python interface to igraph? -- http://mail.python.org/mailman/listinfo/python-list
Re: Recommendation for small, fast, Python based web server
Hello, > I've looked at the web servers that come bundled with the Python > standard library[1] and they are too slow. Apparently you have debugged your speed issue so I suppose you don't have performance problems anymore. Do note, however, that Python is generally not as fast as C -- especially for low-level stuff -- and a Python Web server will probably serve around 10x less requests per second than a C Web server like Apache (this will still give you hundreds of simple requests per second on a modern machine). In any case, as far as functionality, robustness, portability and community support are concerned, you probably can't go wrong with Twisted. Regards Antoine. -- http://mail.python.org/mailman/listinfo/python-list
Moving from PHP to Python. Is it Possible
Greetings. I'm 35 yrs old self learner and who do daily PHP coding for food more than a decade. After ten years of PHP coding I'm getting bored and give try for learning new things. After 3 days of crawling google, diving in python and cursing, now I can show something on my linux/apache/mod_wsgi setup. And i'm struck on something. I had CMS design. It works with PHP very well. And I want to transfer my design in Python. My design depends on a Global Array. A huge array which store everything about requested Web page for a final rendering. In PHP accessing globals is easy. You may do direct access or use class something like ZEND Registry. I'm looking for similar facility in python world. Also I have couple of questions. 1-) Can I create Global (read/write access anywhere from my code) Multi dimensional, associative array (or hash) and store any kind of variable type. 2-) Is there any error trigger for mod_wsgi. When something go bad I god Internal Server error. Looking for error log was't nice. Is there any way to shows errors in the web page ? 3-) Any documents books sites about helping moving from php to python 4-) In php we had someting like ob_start(); // start Output buffering require('hede.php'); // include phtml similar to psp. mixed language and html (to avoiding string replacement (or marker based) html templates) $var = ob_get_clean(); // get rendered output and use anywhere can find a similar abilities in Python ? 5-) is there any Python documentation based on examples. When I give up about to finding php's $_REQUEST or $_SERVER equivalents in python some demo code in Twisted docs are much helpful than any other words. Me and my kind already have problem with English language. Example code much more helpful than full academic description. Thanks for support and patience for this old noob. Regards... -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about 'remote objects'
Frank Millman wrote: > > I am writing a multi-user business/accounting application. It is getting > rather complex and I am looking at how to, not exactly simplify it, but > find a way to manage the complexity. > [...] > > Is there any particular benefit in using remote objects as opposed to > writing a SocketServer? > Many thanks for the very useful replies. Irmen - thanks for clearing up my misconception about how Pyro works. This is still definitely an option. Diez - plenty of food for thought. Your cautionary tale about premature optimisation is salutary. J Kenneth King - also plenty of food for thought, but in fact the most important part of your post was the following - - Find the clear boundaries of each component. - Build an API along those boundaries. - Add a network layer in front of the boundaries. I should know this, but I confess I do need reminding. I had a useful brainstorming session with a colleague this morning focussing on this, and this is where I shall concentrate my attention for the next few days. I suspect that, once this has become clearer, it will not matter much whether I use remote objects, write a SocketServer, or keep it all on one machine. I really appreciate the feedback - it helps a lot. Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: no module named error
Joe schrieb: Your installation process is botched (no idea why, you don't show us setup.py or anything else I asked for). Sorry, but I do know how it's currently installed is exactly the way I need it to be installed. It is? It wasn't working until you fiddled with sys.path - which you needed help to find out. How's that exactly the way it is needed? All that is missing is what I've asked you now several times before: _moda.so is *NOT* alongside moda.py inside your python's site-packages directory. Copy it in there, and the import will work *without* any sys.path-hackery. Yeah, that's something I don't want to do. But you've given me enough info to help me understand what's going on and how to fix it. Thanks. So it's ok that the installation copies moda.py, but not that it copies _moda.so to the same destination? Looks all very strange to me. But then - it's your system. Glad it works for you. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: which pi formula is given in the decimal module documentation?
On Dec 11, 8:16 am, Anh Hai Trinh wrote: > I'm just curious which formula for pi is given here: docs.python.org/library/decimal.html#recipes>? > > def pi(): > """Compute Pi to the current precision. > > >>> print pi() > 3.141592653589793238462643383 > > """ > getcontext().prec += 2 # extra digits for intermediate steps > three = Decimal(3) # substitute "three=3.0" for regular > floats > lasts, t, s, n, na, d, da = 0, three, 3, 1, 0, 0, 24 > while s != lasts: > lasts = s > n, na = n+na, na+8 > d, da = d+da, da+32 > t = (t * n) / d > s += t > getcontext().prec -= 2 > return +s # unary plus applies the new precision And just for fun, here's a one-liner (well, okay, two lines including the import) that uses Decimal to print the first 28 digits of pi: Python 2.6.4 (r264:75706, Nov 16 2009, 15:42:08) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from decimal import Decimal as D >>> print reduce(lambda x,k:2+k/2*x/k,range(999,1,-2),D()) 3.141592653589793238462643383 -- Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: accessing local variables from the pdb debugger
Lie Ryan wrote: On 12/11/2009 12:37 AM, Jean-Michel Pichavant wrote: Diez B. Roggisch wrote: By just inserting the print foo statement right after changing foo's value, I've rolled back the value to 'foo' ??? A hell of a wtf pdb feature ! Apparently it's fixed in 2.7 and 3.1 D:\Lie Ryan\Desktop>python27 d.py > d:\lie ryan\desktop\d.py(6)test() -> print(foo) (Pdb) foo = "bar" (Pdb) pp foo 'bar' (Pdb) c bar D:\Lie Ryan\Desktop>python27 d.py > d:\lie ryan\desktop\d.py(6)test() -> print(foo) (Pdb) foo = "bar" (Pdb) c bar Thanks, that could mean it is a bug from pdb in python 2.5. I tried with ipython & python, same issue. I'll keep that in mind, sadly it concerns a basic feature of the debugger. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Overriding the >> builtin
On Fri, Dec 11, 2009 at 12:05 PM, Kevin Ar18 wrote: > I am aware of the fact that you can somehow replace the __builtins__ in > Python. There is a library here that modifies the >> binary builtins: > http://github.com/aht/stream.py/blob/master/stream.py > > Question: Is there anywhere that explains in detail how to modify the > builtins in Python like this library did? > I did some google and I didn't find anything useful, either. The unofficial doc on effbot.org gives "See __add__", which is fair enough. I believe you're after __rshift__ [that is >>], __lshift__ [which is <<], as starters. There are also __rrshift__ and __rlshift__, but not as useful. What did you need this anyway? Just curious. Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError
On 12/10/2009 6:32 AM, hong zhang wrote: List, I got error says IndentationError in end of line. I could not figure out why. See following: $ ./cont-mcs File "./cont-mcs", line 264 mcs1 = ht_val+cck_val+green_val+fat_val+sgi_val ^ IndentationError: unindent does not match any outer indentation level Look at the surrounding code. Indentation Errors often lies on the previous few lines. Possibly caused by unmatching parentheses. -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError
hong zhang writes: > I got error says IndentationError in end of line. > I could not figure out why. Nor can we, without seeing the code to compare indentation levels. > Thanks for help. Please construct a minimal example (not a whole huge program), that we can run to show the behaviour you're seeing. -- \ “Any intelligent fool can make things bigger and more complex… | `\It takes a touch of genius – and a lot of courage – to move in | _o__)the opposite direction.” —Albert Einstein | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: switch
Bruno Desthuilliers: > Well, obviously such business rules must by no mean be hardcoded. You > really need a "rule engine", configurable by your domain experts thru a > DSL that we'll design specially for you. The rule engine will generate > an AbstractScoreFactory that will instanciate appropriate IScore > implementation objects that knows what to do. [snip] Thank you very much for bringing back some sanity in this newsgroup, sometimes a good antiexample like yours is better than many explanations. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Variable class instantiation
On Fri, 11 Dec 2009 11:36:13 +, Sion Arrowsmith wrote: > Steven D'Aprano wrote: >>thisModule = __import__(__name__) >>classToUse = thisModule.__dict__['C1'] > > Any reason to prefer this over: > > classToUse = getattr(thisModule, 'C1') > > ? (I think, for a module, they should do exactly the same thing. > Personally, I prefer keeping explicit references to __special names__ to > a minimum.) No, no reason at all. I just forgot about getttr. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Variable class instantiation
Steven D'Aprano wrote: >thisModule = __import__(__name__) >classToUse = thisModule.__dict__['C1'] Any reason to prefer this over: classToUse = getattr(thisModule, 'C1') ? (I think, for a module, they should do exactly the same thing. Personally, I prefer keeping explicit references to __special names__ to a minimum.) -- \S under construction -- http://mail.python.org/mailman/listinfo/python-list
Re: pyZui - anyone know about this?
On Friday 11 December 2009 12:38:46 Daniel Fetchinson wrote: > Youtube has a link 'Send message' on the profile of users, maybe > sending a message to the person who uploaded the video will give you a > useful response. > I'm a Tube-tard so that never crossed my mind. Will give it a go. \d -- http://mail.python.org/mailman/listinfo/python-list
Re: Which graph library is best suited for large graphs?
On Fri, Dec 11, 2009 at 03:03 -0800, Bearophile wrote: > Wolodja Wentland: > > Which library would you choose? > > This one probably uses low memory, but I don't know if it works still: > http://osl.iu.edu/~dgregor/bgl-python/ That project looks not that maintained and graph-tool [1] is based on boost as well, so I don't see the advantage in choosing bgl-python over graph-tool. The point is, that I am not sure if using graph-tool has any advantages over networkx at all. It looks like a great library, supports filtered graphs which I find pretty useful, but have not used it yet. [1] http://projects.forked.de/graph-tool/ -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list