Re: Website data-mining.
Miki wrote: > Hello, > >> I'm using Python for the first time to make a plug-in for Firefox. >> The goal of this plug-in is to take the source code from a website >> and use the metadata and body text for different kinds of analysis. >> My question is: How can I retrieve data from a website? I'm not even >> sure if this is possible through Python. Any help? > Have a look at > http://www.myinterestingfiles.com/2007/03/playboy-germany-ads.html Well, it's certainly interesting, but I'm not sure how it might help the OP get data from a website... > for getting the data and at http://www.crummy.com/software/BeautifulSoup/ > for handling it. > > HTH. > > -- > Miki Tebeka <[EMAIL PROTECTED]> > http://pythonwise.blogspot.com > -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
Paul Rubin wrote: > Hmm, it's a pain that there's no clean way to get at the current > module. PEP 3130 shows some icky and unreliable ways, e.g. > >func = getattr(sys.modules[__name__], 'f') > > PEP 3130's goal was to add a clean way to do this. Unfortunately it > was rejected. Yes, this is the essence of the problem. At least I'm not the only one to have needed (or at least wanted) this. James -- http://mail.python.org/mailman/listinfo/python-list
Re: Help: GIS
On 8 3 , 9 34 , [EMAIL PROTECTED] wrote: > On Aug 2, 10:46 pm, zxo102 <[EMAIL PROTECTED]> wrote: > > > Hi, > > I am new in GIS area and need your suggestions for where I can > > start from. I have a python based web application with a database. > > Now I would like to add a GIS map into my application. When a user > > clicks a certain area in the GIS map, it can grab the data from the > > database via my python based application. Do I have to use MapServer > > or Grass or some other backends for this purpose? > >Thanks a lot. > > > Ouyang > > While I am not a part of our GIS department, they use ArcGIS which has > Python support built in. If that's what you're using, you should be > able to use the examples given on ESRI's > website:http://www.spatialvision.com.au/html/tips-python-arc9.htm > > Hmmm...not much there. Here are some other links I found: > > http://nrm.salrm.uaf.edu/~dverbyla/arcgis_python/index.htmlhttp://www.ollivier.co.nz/publication/uc2004/python_workshop/sld008.htmhttp://www.3dartist.com/WP/python/pycode.htm > > I don't know if these will be much help. You really need to just dig > in and start coding. I would recommend "Programming Python 3rd Ed." by > Lutz if you want something in hard copy. "Dive Into Python" is a free > book that's online that I'm told is very good. Both have good > examples, some of which are involved. All the web oriented Python > books are a few years old, but the code in them still works, for the > most part. > > Mike Mike, Thanks for your suggestion. I am looking for a python GIS package (without any other GIS backends like mapserver) which can be simply imported into my current python web application. I am not sure if it is available. So far, the close one I found is Python Cartographic Lab. But I can not find any examples for PCL. Anyway, I am still on the way of the deep learning curve for GIS. Ouyang Ouyang -- http://mail.python.org/mailman/listinfo/python-list
Re: Website data-mining.
Hello, > I'm using Python for the first time to make a plug-in for Firefox. > The goal of this plug-in is to take the source code from a website > and use the metadata and body text for different kinds of analysis. > My question is: How can I retrieve data from a website? I'm not even > sure if this is possible through Python. Any help? Have a look at http://www.myinterestingfiles.com/2007/03/playboy-germany-ads.html for getting the data and at http://www.crummy.com/software/BeautifulSoup/ for handling it. HTH. -- Miki Tebeka <[EMAIL PROTECTED]> http://pythonwise.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp problem in Python
On Aug 4, 1:36 am, Dave Hansen <[EMAIL PROTECTED]> wrote: > On Aug 3, 4:41 pm, Ehsan <[EMAIL PROTECTED]> wrote: > > > I want to find "http://www.2shared.com/download/1716611/e2000f22/ > [...] > > I use this pattern : > > "http.*?\.(wmv|3gp).*"" > > > but it returns only 'wmv' and '3gp' instead of "http://www.2shared.com/ > > download/1716611/e2000f22/Jadeed_Mlak14.wmv? > > tsid=20070803-164051-9d637d11" > > > what can I do? what's wrong whit this pattern? thanx for your comments > > Just a guess, based on too little information: Try "(http.*?\.(wmv| > 3gp).*)" > > Regards, > >-=Dave no, it doesn't work -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to find zip codes/rest example
VanL wrote: > Hello, > > A couple months ago there was an example posted in a blog of a rest > interface for validating zip codes. If I recall correctly, the backend > validator was written in python. > > The validator demo page had a single text input; next to the text input > would appear either a green check or a red X depending on whether the > zip code was valid. > > On the backend, the explanation of the demo included a discussion of > using HTTP status codes (200 for a valid zip, 406? for invalid) so that > the service could be used from a console as well. > > I now cannot find this demo and the associated discussion. Does anybody > remember this demo and where I might be able to find it? I don't remember the demo, but a little creative googling turned up http://bitworking.org/news/132/REST-Tips-URI-space-is-infinite Which matches the description above perfectly, so I assume it's what you were after :-) -Jay -- http://mail.python.org/mailman/listinfo/python-list
Re: Script that Navigates Page needs Javascript Functionality
On Aug 3, 7:58 pm, SMERSH009 <[EMAIL PROTECTED]> wrote: > I have a script that navigates pages and scrapes the HTML source of > the page. > in order to view the results I need I need python to "navigate to" > this Javascript link: > javascript:__doPostBack('ctl00$cpMain$pagerTop','4') This basically > translates into "go to page 4." > I read the posts on this group, and from what I understand, the > functionality I need is with simplejson? If so, what is the syntax i > would use to execute that Javascript? > Or am I completely off base with using simplejson altogether? > > Thanks for the help > -Sam json is a specific way of formatting strings. If an application expects to receive a string as input and the string is supposed be formatted according to json, then you need to send the app a json formatted string. >From the brief description I just read of simplejson, it allows you to convert python objects to a string. What makes you think that simplejson has anything to do with executing javascript code? When html pages are sent to a browser, there is software in the browser that executes any javascript on the page. If you use python to download source code from a server, you are not loading anything in a browser, so no javascript executes. -- http://mail.python.org/mailman/listinfo/python-list
Re: bias in random.normalvariate??
[EMAIL PROTECTED] wrote: > I'm a Python newbie and certainly no expert on statistics, but my wife > was taking a statistics course this summer and to illustrate that > sampling random numbers from a distribution and taking an average of > the samples gives you a random number as the result (bigger sample -> > smaller variance in the calculated random number, converging in on the > mean of the original distribution), I threw together this program: > > #! /usr/bin/python > > import random; > > i=1 > samplen=100 > mean=130 > lo=mean > hi=mean > sd=10 > sum=0 > while(i<=samplen): > x=random.normalvariate(mean,sd) > #print x > if x if x>hi: high=x > sum+=x > i+=1 > print 'sample mean=', sum/samplen, '\n' > print 'low value =', lo > print 'high value=', high Your code has an error. In the middle of your code, you changed "hi" to "high". -- 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
Weekly Python Patch/Bug Summary
Patch / Bug Summary ___ Patches : 404 open ( +5) / 3847 closed (+11) / 4251 total (+16) Bugs: 1059 open ( +3) / 6784 closed ( +8) / 7843 total (+11) RFE : 263 open ( +0) / 295 closed ( +1) / 558 total ( +1) New / Reopened Patches __ struni: Fix test_aepack by converting 4cc's to bytes (2007-07-26) CLOSED http://python.org/sf/1761465 reopened by gvanrossum distutils.util.get_platform() return value on 64bit Windows (2007-07-27) http://python.org/sf/1761786 opened by Mark Hammond Some fix abount _WIN32_WINNT (2007-07-27) CLOSED http://python.org/sf/1761803 opened by Hirokazu Yamamoto struni: test_xml_etree.py (2007-07-27) CLOSED http://python.org/sf/1762412 opened by Joe Gregorio unable to serialize Infinity or NaN on ARM using marshal (2007-07-28) http://python.org/sf/1762561 opened by Matthias Klose struni: test_urllib2, test_cookielib (2007-07-29) CLOSED http://python.org/sf/1762940 opened by Joe Gregorio socket close fixed (2007-07-29) CLOSED http://python.org/sf/1763387 opened by Hasan Diwan tiny addition to peephole optimizer (2007-07-31) http://python.org/sf/1764087 opened by Paul Pogonyshev Fix for test_socketserver for Py3k (2007-07-31) CLOSED http://python.org/sf/1764815 opened by ??PC?? generic and more efficient removal of unreachable code (2007-08-01) http://python.org/sf/1764986 opened by Paul Pogonyshev logging: delay_fh option and configuration kwargs (2007-08-01) http://python.org/sf/1765140 opened by Chris Leary small improvement for peephole conditional jump optimizer (2007-08-01) http://python.org/sf/1765558 opened by Paul Pogonyshev urllib2-howto - correction (2007-08-02) http://python.org/sf/1765839 opened by O.R.Senthil Kumaran improve xrange.__contains__ (2007-08-02) http://python.org/sf/1766304 opened by Stargaming Fix for test_zipimport (2007-08-03) CLOSED http://python.org/sf/1766592 opened by ??PC?? Make xmlrpc use HTTP/1.1 and keepalive (2007-08-04) http://python.org/sf/1767370 opened by Donovan Baarda test_csv struni fixes + unicode support in _csv (2007-08-03) http://python.org/sf/1767398 opened by Adam Hupp Patches Closed __ struni: Fix test_aepack by converting 4cc's to bytes (2007-07-26) http://python.org/sf/1761465 closed by gvanrossum struni: Fix test_aepack by converting 4cc's to bytes (2007-07-26) http://python.org/sf/1761465 closed by gvanrossum Some fix abount _WIN32_WINNT (2007-07-27) http://python.org/sf/1761803 closed by mhammond struni pulldom: Don't use 'types' to check strings (2007-07-24) http://python.org/sf/1759922 closed by gvanrossum struni: test_xml_etree.py (2007-07-27) http://python.org/sf/1762412 closed by loewis struni: test_urllib2, test_cookielib (2007-07-28) http://python.org/sf/1762940 closed by gvanrossum socket close fixed (2007-07-30) http://python.org/sf/1763387 closed by facundobatista itertools.getitem() (2007-07-08) http://python.org/sf/1749857 closed by rhettinger Fix for test_socketserver for Py3k (2007-07-31) http://python.org/sf/1764815 closed by gvanrossum Fix Decimal.sqrt bugs described in #1725899 (2007-06-22) http://python.org/sf/1741308 closed by facundobatista Fix for test_zipimport (2007-08-03) http://python.org/sf/1766592 closed by gvanrossum urllib2 tests pass (2007-07-16) http://python.org/sf/1755133 closed by gvanrossum New / Reopened Bugs ___ 'exec' does not accept what 'open' returns (2007-07-28) http://python.org/sf/1762972 opened by Brett Cannon S.find documentation uses s[start, end] vs. s[start:end] (2007-07-29) CLOSED http://python.org/sf/1763149 opened by Rob copy 2 (2007-07-30) http://python.org/sf/1764044 opened by robs pythonid _RLock.__repr__ throws exception (2007-07-30) CLOSED http://python.org/sf/1764059 opened by Greg Kochanski The -m switch does not use the builtin __main__ module (2007-07-31) http://python.org/sf/1764407 opened by Nick Coghlan Decimal comparison with None fails in Windows (2007-07-31) CLOSED http://python.org/sf/1764761 opened by pablohoffman.com setup.py trashes LDFLAGS (2007-08-01) http://python.org/sf/1765375 opened by Harald Koenig poll() returns "status code", not "return code" (2007-08-02) http://python.org/sf/1766421 opened by sjbrown os.chmod failure (2007-08-03) http://python.org/sf/1767242 reopened by rgheck os.chmod failure (2007-08-03) http://python.org/sf/1767242 opened by Richard Heck String.capwords() does not capitalize first word (2007-08-03) http://python.org/sf/1767363 opened by Saatvik Agarwal Bugs Closed ___ No docs for list comparison (2007-07-25) http://python.org/sf/1760423 closed by gbrandl SSL-ed soc
Re: How to pass a reference to the current module
Steven D'Aprano <[EMAIL PROTECTED]> writes: > I'll point at the difficulty in using getattr for extracting a function > from the current module: > >>> func = getattr(???, 'f') # what should go there? Hmm, it's a pain that there's no clean way to get at the current module. PEP 3130 shows some icky and unreliable ways, e.g. func = getattr(sys.modules[__name__], 'f') PEP 3130's goal was to add a clean way to do this. Unfortunately it was rejected. -- http://mail.python.org/mailman/listinfo/python-list
Re: (no) fast boolean evaluation ?
Ian Clark wrote: > Stef Mientki wrote: >> hello, >> >> I discovered that boolean evaluation in Python is done "fast" >> (as soon as the condition is ok, the rest of the expression is ignored). >> >> Is this standard behavior or is there a compiler switch to turn it >> on/off ? > > It's called short circuit evaluation and as far as I know it's standard > in most all languages. This only occurs if a conditional evaluates to > True and the only other operators that still need to be evaluated are > 'or's or the condition evaluates to False and all the other operators > are 'and's. The reason is those other operators will never change the > outcome: True or'd with any number of False's will still be True and > False and'ed to any number of Trues will still be False. > > My question would be why would you *not* want this? Pascal, and apparently Fortran, do not use short-circuit evaluation. I remember learning this gotcha in my seventh-grade Pascal class (plus I just googled it to make sure my memory was correct!). Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
On Fri, 03 Aug 2007 21:06:23 -0700, James Stroud wrote: > Its very close. However, there is the possibiltiy that main.py and > UserDefined1.py are the same module. In such a case I'm guessing that I > need to resort to the gymnastics of frame inspection I mentioned > earlier. I suggest you're falling for the anti-pattern of "Big Design Up Front", and are overly complicating your system "just in case it's useful". Why not just _insist_ that main.py and UserDefined1.py must be different modules? You're the application developer, you're allowed to do that. > The problem is when this combination of possibilities exists: > > 1. main.py is named without the .py (e.g. `main`) as would be >the convention for "programs"), and is not a true python >module as a result--perhaps python has a mechanism for >importing such files? I don't believe it does. > 2. foo is defined in `main` Maybe you should just prohibit that? Do you really want to allow users to call arbitrary code in your main application at arbitrary times and places? Maybe you do. Okay, it's your gun and your foot. But in any case, it shouldn't matter. main is the program running -- it has to be, because you can't import it from another program -- so globals()['foo'] will work. > Possibility two (even when it is a properly named module) sets the stage > for a circular import, but I believe in python this is not entirely > worrisome. However, the combination above makes it difficult to pass a > reference to the `main` namespace without some sort of introspection. That's what globals() is for. > Ideally, I would prefer to not require the user to provide some mapping > as it detracts from the convenience of the API. For example: > > from UserDefined1 import some_function > def foo(): [etc.] > def doit(): [etc.] > mapping = { > 'foo' : foo, > 'doit' : doit, > 'some_function' : some_function > } > > The idea would be that the above mapping would be specified in the > configuration file: > > [foo] > param1 = float > param2 = 4 > > [option1] > __module__ = 'UserDefined1' > __function__ = 'doit' I'm not sure why you need the quotation marks around the module and function names. What else could UserDefined1 be, other than a string? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
On Fri, 03 Aug 2007 18:45:21 -0700, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> namespace = module.__dict__ >> return namespace[name] > > Am I missing something? It's likely that I just don't understand > the problem, but I don't understand these dictionary extractions > for what I thought would be an attribute lookup: Well, the *real* reason I used a __dict__ extraction was because I didn't think of using getattr at the time, but as a post facto justification, I'll point at the difficulty in using getattr for extracting a function from the current module: >>> def f(x): ... return x + 1 ... >>> func = getattr(???, 'f') # what should go there? Maybe I've just got a blind spot, but I can't think of a way to use getattr to get something from the current module. That would lead to something like this: def get_function_from_name(name, module=None): if module is None: return globals()[name] # or use locals() else: return getattr(name, module) which is fine, I suppose, and I would have used it earlier if I had thought of it *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
Paul Rubin wrote: > James Stroud <[EMAIL PROTECTED]> writes: > >> ModuleBehavior >> == >>UserDefined1 Imports FunctionUser >>ThirdParty Contains User Functions (May be ==UserDefined1) >>FunctionUser do_something_with() and/or get_function_from_name() >> >>So the name-to-function mapping is done in FunctionUser but the >>function is actually defined in UserDefined1 (or ThirdParty if >>ThirdParty is different than UserDefined1). > > > I'm still completely confused. Does FunctionUser know what module the > user functions are supposed to come from? Could you give an example > of what you want the actual contents of those 3 modules to look like? > E.g.: > > UserDefined1.py: > import FunctionUser > > def foo(x): > print x+3 > > FunctionUser.py: >def do_something_with (module, funcname, *args, **kw): > func = getattr(module, funcname) > func (*args, **kw) > > main.py: >import UserDefined1, FunctionUser > ># the following should print 10 >FunctionUser.do_something_with(UserDefined1, 'foo', 7) > > I don't think the above is quite what you want, but is it somewhere > close? Its very close. However, there is the possibiltiy that main.py and UserDefined1.py are the same module. In such a case I'm guessing that I need to resort to the gymnastics of frame inspection I mentioned earlier. The problem is when this combination of possibilities exists: 1. main.py is named without the .py (e.g. `main`) as would be the convention for "programs"), and is not a true python module as a result--perhaps python has a mechanism for importing such files? 2. foo is defined in `main` Possibility two (even when it is a properly named module) sets the stage for a circular import, but I believe in python this is not entirely worrisome. However, the combination above makes it difficult to pass a reference to the `main` namespace without some sort of introspection. Ideally, I would prefer to not require the user to provide some mapping as it detracts from the convenience of the API. For example: from UserDefined1 import some_function def foo(): [etc.] def doit(): [etc.] mapping = { 'foo' : foo, 'doit' : doit, 'some_function' : some_function } The idea would be that the above mapping would be specified in the configuration file: [foo] param1 = float param2 = 4 [option1] __module__ = 'UserDefined1' __function__ = 'doit' param1 = str param2 = 30.0 [doit] param1 = float param2 = float [etc.] James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
Carsten Haese wrote: > On Fri, 2007-08-03 at 18:31 -0700, James Stroud wrote: >>Carsten Haese wrote: >>You sound like my former thesis adviser. > > > Thanks. I guess. Yes, its a compliment in disguise--just check his CV. >>OK. From an external source, such as configuration file, the user will >>specify the *name* of a function somehow with the assumption that the >>function will be coded somewhere (in the present or other modules) by >>that name. > > Does the configuration file indicate which module contains the function? > It is possible. Please see my latest response to Paul Rubin. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: bias in random.normalvariate??
On Aug 3, 10:38 pm, [EMAIL PROTECTED] wrote: > I'm a Python newbie and certainly no expert on statistics, but my wife > was taking a statistics course this summer and to illustrate that > sampling random numbers from a distribution and taking an average of > the samples gives you a random number as the result (bigger sample -> > smaller variance in the calculated random number, converging in on the > mean of the original distribution), I threw together this program: > ... > > I added the lo and high stuff to my test program out of fear that I > was running into something funky in adding up 100 floating point > numbers. That would be more of a worry if the sample size was much > bigger, but lo and high showed apparent bias quite aside from the > calculation of the mean. > > Am I committing some other obvious statistical or Python blunder? > e.g. Am I mis-understanding what random.normalvariate is supposed to > do? Doing some testing with mu=0, sigma=1, and n=100 gives me means of -0.00096407536711885962 -0.0015179019121429708 +6.9223244807378563e-05 +0.0017483897464631625 -0.0011148444018505548 +0.0015367250480148183 There appears to be no consistent bias. -- http://mail.python.org/mailman/listinfo/python-list
Re: Relative-importing *
Thanks to everybody for replying. (I apologize for the delayed response: my connection's been down for a week.) Yes, I'm importing * for a reason, a good one, I think. I have a set of modules (the number planned to reach about 400) that would be dynamically loaded by my program as needed, and they're somewhat similar to each other. I wish each of them to import * from a certain "parent" module, so that they'll receive whatever functions and variables I want all of them to share (using the parent module's __all__), which may be overrided by the "child" modules at their discretion. Sort of like class inheritance, but I'm not doing that because implementing that would be a lot more tedious and less elegant. But if this doesn't seem to be documented, and unintended...is it a bug? If so, how do I file it? Thanks again! -- http://mail.python.org/mailman/listinfo/python-list
bias in random.normalvariate??
I'm a Python newbie and certainly no expert on statistics, but my wife was taking a statistics course this summer and to illustrate that sampling random numbers from a distribution and taking an average of the samples gives you a random number as the result (bigger sample -> smaller variance in the calculated random number, converging in on the mean of the original distribution), I threw together this program: #! /usr/bin/python import random; i=1 samplen=100 mean=130 lo=mean hi=mean sd=10 sum=0 while(i<=samplen): x=random.normalvariate(mean,sd) #print x if xhi: high=x sum+=x i+=1 print 'sample mean=', sum/samplen, '\n' print 'low value =', lo print 'high value=', high - But the more I run the darn thing, the stranger the results look to me. random.normalvariate is defined on page 89 of http://www-acc.kek.jp/WWW-ACC-exp/KEKB/Control/Python%20Documents/lib.pdf as generating points from a normal distribution with mean and standard deviation given by the arguments. But my test program consistently comes up with sample means that are less than the mean of the distribution. The lo value is consistently much lower relative to the mean than the high value is higher than the mean. That is, it looks to me like the normalvariate function is biased. Part of my being a Python newbie is I'm not really sure where to go to discuss this problem. If this group isn't the right place, do feel free to point me to where I ought to go. I'm running Ubuntu Dapper and "python -V" says I've got Python 2.4.3. I tried looking in random.py down under /usr/lib but find no clues there as to the version of the random module on my machine. Am I missing something? /usr/lib/python2.4$ ls -l random.py -rw-r--r-- 1 root root 30508 2006-10-06 04:34 random.py I added the lo and high stuff to my test program out of fear that I was running into something funky in adding up 100 floating point numbers. That would be more of a worry if the sample size was much bigger, but lo and high showed apparent bias quite aside from the calculation of the mean. Am I committing some other obvious statistical or Python blunder? e.g. Am I mis-understanding what random.normalvariate is supposed to do? -- http://mail.python.org/mailman/listinfo/python-list
Re: Website data-mining.
On Aug 3, 7:50 pm, Coogan <[EMAIL PROTECTED]> wrote: > Hi-- > > I'm using Python for the first time to make a plug-in for Firefox. > The goal of this plug-in is to take the source code from a website > and use the metadata and body text for different kinds of analysis. > My question is: How can I retrieve data from a website? I'm not even > sure if this is possible through Python. Any help? > > nieu How about this? it will fetch the HTML source of the page. import datetime, time, re, os, sys, traceback, smtplib, string,\ urllib2, urllib, inspect from urllib2 import build_opener, HTTPCookieProcessor, Request opener = build_opener(HTTPCookieProcessor) from urllib import urlencode def urlopen2(url, data=None, user_agent='urlopen2'): """Opens Our URLS """ if hasattr(data, "__iter__"): data = urlencode(data) headers = {'User-Agent' : user_agent} return opener.open(Request(url, data, headers)) ###TESTCASES START HERE### def publishedNotes(): page = urlopen2("http://www.yourURL.com";, ()) pageRead = page.read() print pageRead if __name__ == '__main__': publishedNotes() sys.exit() -- http://mail.python.org/mailman/listinfo/python-list
Re: I am giving up perl because of assholes on clpm -- switching to Python
In most of the technical computer newsgroups which I frequent, there is a handful of knowledgeable and helpful but irritable regulars, and often one or two saints who contribute usefully, ignore rudeness and almost never post off topic. Ain't that the truth!! You will find rudeness everywhere you go. If you really like the language. Don't let party poopers spoil your fun. Always demand respect. But if you don't get it.. it is not the end of the world. I have also learned that text has little emotion. I have actually had to pull some people aside as ask them about a post directed towards me. -- http://mail.python.org/mailman/listinfo/python-list
Website data-mining.
Hi-- I'm using Python for the first time to make a plug-in for Firefox. The goal of this plug-in is to take the source code from a website and use the metadata and body text for different kinds of analysis. My question is: How can I retrieve data from a website? I'm not even sure if this is possible through Python. Any help? nieu -- http://mail.python.org/mailman/listinfo/python-list
Re: I am giving up perl because of assholes on clpm -- switching to Python
On Thu, 26 Jul 2007 14:56:13 GMT, zentara <[EMAIL PROTECTED]> wrote: >On Wed, 25 Jul 2007 14:45:29 -0500, [EMAIL PROTECTED] wrote: > >>Python is a better language, with php support, anyway, but I am fed up >>with attitudes of comp.lang.perl.misc. Assholes in this newsgroup ruin >>Perl experience for everyone. Instead of being helpful, snide remarks, >>back-biting, scare tactings, and so on proliferate and self >>reinforce. All honest people have left this sad newsgroup. Buy bye, >>assholes, I am not going to miss you!!! >> >>Martha > >sihT si erehw eht gib syob yalp, uoy evah ot eb elba ot eb elba ot >elffucs dna ekat tnemhsinup fi uoy era gnorw ro yludnu tnarongi. >uoY osla deen ot hsauqs wohemos ohw skcatta uoy, nehw uoy >wonk uoy era thgir. > >I saw gnihctaw a CBNC yadretsey, dna yeht deweivretni a gnidael >ralos lenap ynapmoc's OEC. enO yug tsuj detsalb mih rof on nosaer >rehto naht eh steg a tnemnrevog ydisbus, dna neve eht rotaredom tlef >dab rof eht yaw eht evitucexe saw detsalb. TUB.. yeht era eht gib >syob, gniyalp rof laer yenom, dna fi uoy yalp ereht, uoy evah ot tcepxe >ot evah ruoy ssenhguot detset. ti snaem laer tiforp dna ssol. > >fI uoy tnaw a retteb ecalp ot ksa rennigeb snoitseuq, ro ot eb detaert >htiw erom tcepser, yrt eht lrep-srennigeb tsilliam ro >ptth://sknomlrep.gro. ehT sknom era yllausu yrev etilop. > > >aratnez There you go again, always twisting things around. A little hatred is good for the world, grow some balls, if it hurts that much, cut your throat, not somebody elses. Sln -- http://mail.python.org/mailman/listinfo/python-list
Re: downloading files
Ehsan wrote: > On Aug 3, 10:10 pm, Steve Holden <[EMAIL PROTECTED]> wrote: [...] >> I'm guessing there are binary files and you are running on Windows, >> which is inserting a carriage return before ebery newline. Try >> >> localFile = open(fileName, 'wb') >> >> to avoid thus behavior. [...] > thanx Steve > It works but could you explain more what's wrong with just 'w'? > Hmm, I thought I had. 'b' stand for 'binary', and the system sends out exactly the bytes you right. Without the 'b' it assumes you are handling text, so Windows "CR/LF" line endings are converted to "LF" or reading, and "LF" is converted to "CR/LF" on writing. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden --- Asciimercial -- Get on the web: Blog, lens and tag the Internet Many services currently offer free registration --- Thank You for Reading - -- http://mail.python.org/mailman/listinfo/python-list
Re: Email
On Aug 3, 9:47 am, Rohan <[EMAIL PROTECTED]> wrote: > On Aug 2, 1:06 pm, Laurent Pointal <[EMAIL PROTECTED]> wrote: > > > > > Rohan wrote: > > > I was wondering if there could be an arrangement where a file could be > > > attached and send as an email. > > > For ex > > > f = open(add.txt,w) > > > f.write('python') > > > f.close() > > > > Now I would like to send an email with add.txt as an attachment, is it > > > possible ? > > > some one give me a pointer towards this. > > > You can use iMailer as an example script to get parts: > > >http://nojhan.free.fr/article.php3?id_article=22 > > > A+ > > > Laurent. > > Laurent the link you gave me is in a language unknown to me if you > have anything that expalains in english, then let me know. > thanks Did you try Google translate? Here is the tiny url of the page you wanted translated http://tinyurl.com/3xlcmc -- http://mail.python.org/mailman/listinfo/python-list
Re: PYTHON PROGRAMMING HELP PLSSS !!
On Aug 2, 6:24 pm, "Dennis" <[EMAIL PROTECTED]> wrote: > HI All, > i am a 4th year business student and i took web design online course > for fun however i did not see that last 2 chapters were python > programming.This has no relevance to my major nor does it have any > contribution to my degree. My fun turned out to be my nightmare since > i literally can not grasp the main idea like other computer science > students. To sum up , i need help with the following code, please do > not send me emails telling me that outside class help is not provided > or etc, this is not my major related course and this might also affect > my graduation date. > This is the working sample program > ;http://cmpt165.cs.sfu.ca/~ggbaker/examples/chequebook.html > If interested please email me, i am ready to make it up for your time > that you spend to get me out of this mess. > thanks What exactly do you need done? Be more specific instead of just pasting a link to a page Also, you might want to state how much you are willing to 'compensate' someone. Maybe you will get more responses this way :) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
On Fri, 2007-08-03 at 18:31 -0700, James Stroud wrote: > Carsten Haese wrote: > > please describe less abstractly what you're trying to do. > > You sound like my former thesis adviser. Thanks. I guess. > OK. From an external source, such as configuration file, the user will > specify the *name* of a function somehow with the assumption that the > function will be coded somewhere (in the present or other modules) by > that name. Does the configuration file indicate which module contains the function? -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse and Python
Thanks to all! Danyelle On 8/3/07, Lukasz <[EMAIL PROTECTED]> wrote: > Użytkownik Danyelle Gragsone napisał: > > Does anyone have any suggested websites for learning Eclipse the python way? > > > > thanks, > > Danyelle > > http://www.showmedo.com/videos/series?name=PyDevEclipseList > > > -- > Opole - Miasto Bez Granic. > http://www.opole.pl - tu znajdziesz nowe miejsca, nowe mozliwosci, nowe > inspiracje... > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
James Stroud <[EMAIL PROTECTED]> writes: > ModuleBehavior >== > UserDefined1 Imports FunctionUser > ThirdParty Contains User Functions (May be ==UserDefined1) > FunctionUser do_something_with() and/or get_function_from_name() > > So the name-to-function mapping is done in FunctionUser but the > function is actually defined in UserDefined1 (or ThirdParty if > ThirdParty is different than UserDefined1). I'm still completely confused. Does FunctionUser know what module the user functions are supposed to come from? Could you give an example of what you want the actual contents of those 3 modules to look like? E.g.: UserDefined1.py: import FunctionUser def foo(x): print x+3 FunctionUser.py: def do_something_with (module, funcname, *args, **kw): func = getattr(module, funcname) func (*args, **kw) main.py: import UserDefined1, FunctionUser # the following should print 10 FunctionUser.do_something_with(UserDefined1, 'foo', 7) I don't think the above is quite what you want, but is it somewhere close? -- http://mail.python.org/mailman/listinfo/python-list
Script that Navigates Page needs Javascript Functionality
I have a script that navigates pages and scrapes the HTML source of the page. in order to view the results I need I need python to "navigate to" this Javascript link: javascript:__doPostBack('ctl00$cpMain$pagerTop','4') This basically translates into "go to page 4." I read the posts on this group, and from what I understand, the functionality I need is with simplejson? If so, what is the syntax i would use to execute that Javascript? Or am I completely off base with using simplejson altogether? Thanks for the help -Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
Steven D'Aprano wrote: > On Fri, 03 Aug 2007 17:22:40 -0700, James Stroud wrote: > > >>Basically, what I am trying to acomplish is to be able to do this in any >>arbitrary module or __main__: >> >> >>funcname = determined_externally() >>ModuleUser.do_something_with(AModule, funcname) >> >> >>Ideally, it would be nice to leave out AModule if the functions were >>designed in the same namespace in which do_something_with is called. > > > I second Carsten Haese's suggestion that instead of passing function > names, you pass function objects, in which case you don't need the module. > But perhaps you need some way of finding the function, given its name. > > def get_function_from_name(name, module=None): > if module is None: > # use the current namespace > namespace = locals() # or globals() if you prefer > else: > namespace = module.__dict__ > return namespace[name] > > This assumes that get_function_from_name is defined in the same module as the function named by name. However, I want this: ModuleBehavior == UserDefined1 Imports FunctionUser ThirdParty Contains User Functions (May be ==UserDefined1) FunctionUser do_something_with() and/or get_function_from_name() So the name-to-function mapping is done in FunctionUser but the function is actually defined in UserDefined1 (or ThirdParty if ThirdParty is different than UserDefined1). James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
Steven D'Aprano <[EMAIL PROTECTED]> writes: > namespace = module.__dict__ > return namespace[name] Am I missing something? It's likely that I just don't understand the problem, but I don't understand these dictionary extractions for what I thought would be an attribute lookup: Python 2.4.4 (#1, Oct 23 2006, 13:58:00) >>> import math >>> parrot = getattr(math, 'sqrt') >>> print parrot(3) 1.73205080757 >>> That just seems like a cleaner way to access stuff in a module, using the published interface instead of an implementation detail. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
On Fri, 03 Aug 2007 18:32:54 -0700, James Stroud wrote: > Carsten Haese wrote: >> This seems to confirm my suspicion that the do_something_with function >> doesn't actually need a reference to the module, it only needs a >> reference to the function to call. >> >> Maybe your hurdle is how to obtain a reference to a function from the >> current module when all you have is the name of the function in a >> string. The answer to that would be "globals()[funcname]". > > This is like a bad case of phone-tag. Please see my response to your > previous post for why this does not seem feasible to me. I've read your previous post, and I don't understand why you consider it unfeasible. The user provides a function name in a config file, which gives you funcname as a string. You already know which module it comes from (you didn't specify how, but all your examples show that). Carsten is simply showing you how to get the function from the function name without the nasty hack using sys._getframe. Why is in unfeasible? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
James Stroud <[EMAIL PROTECTED]> writes: > > please describe less abstractly what you're trying to do. > You sound like my former thesis adviser. I couldn't understand what you were trying to do either. > OK. From an external source, such as configuration file, the user will > specify the *name* of a function somehow with the assumption that the > function will be coded somewhere (in the present or other modules) by > that name. Is something wrong with import some_module func = getattr(some_module, func_name) ? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
On Fri, 03 Aug 2007 17:22:40 -0700, James Stroud wrote: > Basically, what I am trying to acomplish is to be able to do this in any > arbitrary module or __main__: > > > funcname = determined_externally() > ModuleUser.do_something_with(AModule, funcname) > > > Ideally, it would be nice to leave out AModule if the functions were > designed in the same namespace in which do_something_with is called. I second Carsten Haese's suggestion that instead of passing function names, you pass function objects, in which case you don't need the module. But perhaps you need some way of finding the function, given its name. def get_function_from_name(name, module=None): if module is None: # use the current namespace namespace = locals() # or globals() if you prefer else: namespace = module.__dict__ return namespace[name] -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
Carsten Haese wrote: > This seems to confirm my suspicion that the do_something_with function > doesn't actually need a reference to the module, it only needs a > reference to the function to call. > > Maybe your hurdle is how to obtain a reference to a function from the > current module when all you have is the name of the function in a > string. The answer to that would be "globals()[funcname]". This is like a bad case of phone-tag. Please see my response to your previous post for why this does not seem feasible to me. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
Carsten Haese wrote: > please describe less abstractly what you're trying to do. You sound like my former thesis adviser. OK. From an external source, such as configuration file, the user will specify the *name* of a function somehow with the assumption that the function will be coded somewhere (in the present or other modules) by that name. This behavior is to be implemented in a very primitive pythoncard-like application wherein the user can specify hooks via a configuration file. The configuration file will describe the GUI. To go one more step deeper into the rationale, the idea would be to replace optparse type behavior with a gui wherein one can type input parameters into fields rather than specify them at the command line with optional flags. Please take a look at my previous response to myself for one possible solution I devised. I don't particularly like it much, however, because it seems unnatural. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
On Fri, 2007-08-03 at 17:53 -0700, James Stroud wrote: > James Stroud wrote: > > Basically, what I am trying to acomplish is to be able to do this in any > > arbitrary module or __main__: > > > > > > funcname = determined_externally() > > ModuleUser.do_something_with(AModule, funcname) > > > > > > Ideally, it would be nice to leave out AModule if the functions were > > designed in the same namespace in which do_something_with is called. > > > Is this the preferred way? > > > import sys > def do_something_with(funcname, amodule=None): >if amodule is None: > function = sys._getframe(1).f_locals[funcname] >else: > function = getattr(amodule, funcname) >[etc.] This seems to confirm my suspicion that the do_something_with function doesn't actually need a reference to the module, it only needs a reference to the function to call. Maybe your hurdle is how to obtain a reference to a function from the current module when all you have is the name of the function in a string. The answer to that would be "globals()[funcname]". -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
On Fri, 2007-08-03 at 17:22 -0700, James Stroud wrote: > Hello All, > > Say I have this code: > > > import AModule > import ModuleUser > > ModuleUser.do_something_with(AModule, 'some_function_name') > > > But say the functions are defined in the same module that contains the > above code. I can imagine this hack: > > > import AModule > import ModuleUser > > ModuleUser.do_something_with(AModule.__name__, 'some_name') > > > Where AModule.__name__ could be substituted for __name__ under the > proper circumstances. Then, I would have this code in ModuleUser: > > > import sys > def do_something_with(modname, funcname): > afunction = sys.modules[modname].funcname > [etc.] > > > Which is terribly ugly to me and makes for a pretty miserable API in my > opinion, requiring the programmer to type underscores. > > > Basically, what I am trying to acomplish is to be able to do this in any > arbitrary module or __main__: > > > funcname = determined_externally() > ModuleUser.do_something_with(AModule, funcname) > > > Ideally, it would be nice to leave out AModule if the functions were > designed in the same namespace in which do_something_with is called. > > Thanks in advance for any suggestions. I can't be too sure because you may have abstracted away too much of what you're actually trying to accomplish, but it seems to me that instead of passing a reference to the current module and a function name, you should just pass a reference to the function that you want do_something_with to call. If I missed the point of your question, please describe less abstractly what you're trying to do. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
James Stroud wrote: > James Stroud wrote: > >> Basically, what I am trying to acomplish is to be able to do this in >> any arbitrary module or __main__: >> >> >> funcname = determined_externally() >> ModuleUser.do_something_with(AModule, funcname) >> >> >> Ideally, it would be nice to leave out AModule if the functions were >> designed in the same namespace in which do_something_with is called. > > > > Is this the preferred way? > > > import sys > def do_something_with(funcname, amodule=None): > if amodule is None: > function = sys._getframe(1).f_locals[funcname] > else: > function = getattr(amodule, funcname) > [etc.] > > > James > _.replace('locals', 'globals') James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass a reference to the current module
James Stroud wrote: > Basically, what I am trying to acomplish is to be able to do this in any > arbitrary module or __main__: > > > funcname = determined_externally() > ModuleUser.do_something_with(AModule, funcname) > > > Ideally, it would be nice to leave out AModule if the functions were > designed in the same namespace in which do_something_with is called. Is this the preferred way? import sys def do_something_with(funcname, amodule=None): if amodule is None: function = sys._getframe(1).f_locals[funcname] else: function = getattr(amodule, funcname) [etc.] James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Emacs + python
hg <[EMAIL PROTECTED]> writes: > how about a cscope equivalent ? How about reading what was posted earlier in the thread, and give us a description of what you want instead of a name that people might not recognise? -- \ "The judge asked, 'What do you plead?' I said, 'Insanity, your | `\ honour. Who in their right mind would park in the passing | _o__)lane?'" -- Steven Wright | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
RE:xlrd question
Hi John, Thanks very much for your reply. And thanks for taking the time to create xlrd... this is a very cool and impressive program!! :-) I ran your code which gave me this: >>> import sys, xlrd; print sys.version; print xlrd.__file__ 2.3.5 (#1, Jan 30 2006, 13:30:29) [GCC 3.3 20030304 (Apple Computer, Inc. build 1819)] /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/ xlrd/__init__.pyc and as far as I can tell, the runxlrd.py file is located here (where I had drug this folder originally): Macintosh HD/xlrd-0.6.1/scripts/runxlrd.py So if I'm understanding this correctly, xlrd only uses the folder you download (xlrd-0.6.1) and then moves the '__init__.pyc' file to the location mentioned above? I apologize if I don't sound very intelligent with this - I'm completely new to Python. There's definitely no problems or concerns. :-)I'm doing a bit of research to see if this might be something I use down the road at work. Our I/T department is extremely strict as to what we put on employees machines so I want to have a good understanding as to where files are installed so I can let i/T know all the details. One department in particular that I support uses a lot of Excel macros that I wrote quite awhile back. Unfortunately, I've heard that Microsoft is planning on taking VBA out of the next version of Excel on the Mac platform. I don't mind converting everything over to AppleScript but I'm researching other alternatives. I just installed xlrd on my home machine last night and was really impressed with the few things I was able to figure out. While I'm talking about Excel, is there any other program (for Python) that can edit Excel files? Will xlrd ever get this capability (I believe someone mentioned xlwr on another post)? Thanks again for replying to my post and thank you very much for sharing your awesome program! :-) Jay -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug in time, part 2
Joshua J. Kugler wrote: > Or could I entitle this, "A Wrinkle in time.py," with apologies to Madeleine > L'Engle. Either I've found a bug (or rather room for improvement) in > time.py, or I *really* need a time module that doesn't assume so much. I'd be inclined to use the datetime module to avoid certain underlying library assumptions. I originally tried to retrace your steps and make comments about what is going on, but the UNIX time API is so bizarre that it's better for me to suggest a few things instead. First of all, you managed to get things working nicely in a GMT/UTC environment. Sadly, the time module doesn't provide all the functions you'd need to work with UTC without such hacks as calling tzset, although I've been trying to refine some patches which do provide such functions - see this link for more details: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1667546&group_id=5470 Although I suggested setting tm_isdst to zero previously, I'm more convinced now that it's quite difficult to do the right thing with such simple measures alone. Again, the time module doesn't provide access to timezone offsets on individual time structures in its current form, nor does it support the %z format option for strftime and strptime, although the patches mentioned above do provide it; both of these things provide the foundations to convert localtimes to UTC times and to convert back only when needed, a bit like the way you're supposed to work with Unicode and only produce specific textual encodings once you're finished. [...] Anyway, here are some suggestions: In your original test case (or problem), it looked like you were seeing a DST "boundary" which then made the times appear further apart than they actually were. Adjusting this test case for my timezone, I can reproduce the issue but then add the %z format option (see the patches) to demonstrate that with access to timezone offsets there's nothing really wrong: >>> nondst = time.mktime(time.strptime('2007-03-25 02:00:00', '%Y-%m-%d >>> %H:%M:%S')) >>> dst = time.mktime(time.strptime('2007-03-25 03:00:00', '%Y-%m-%d %H:%M:%S')) >>> time.strftime('%Y-%m-%d %H:%M:%S %z', time.localtime(nondst)) '2007-03-25 03:00:00 +0200' >>> time.strftime('%Y-%m-%d %H:%M:%S %z', time.localtime(dst)) '2007-03-25 03:00:00 +0200' Certainly, the localtime (with undecided timezone) of 2am on 25th March gets converted to the DST timezone, but we can be more specific and make informed guesses as to what happens: >>> nondst = time.mktime(time.strptime('2007-03-25 02:00:00 CET', '%Y-%m-%d >>> %H:%M:%S %Z')) >>> time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime(nondst)) '2007-03-25 03:00:00 CEST' And trying with 1:59am gives us what we'd expect: >>> nondst = time.mktime(time.strptime('2007-03-25 01:59:00', '%Y-%m-%d >>> %H:%M:%S')) >>> time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime(nondst)) '2007-03-25 01:59:00 CET' Now, we might like to avoid dealing with localtime altogether, and for such work I've introduced a function called mktimetz which attempts to use the timezone offset to calculate a time value which works with localtime and gmtime mostly without surprises - something which mktime doesn't guarantee. However, since strptime tends to sit on the fence and not assert any knowledge about DST, and since mktimetz depends on reliable timezone information, you do need to be careful about supplying vague information in the first place: >>> tz2am = time.mktimetz(time.strptime('2007-03-25 02:00:00', '%Y-%m-%d >>> %H:%M:%S')) >>> time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime(tz2am)) '2007-03-25 05:00:00 CEST' (I can only speculate as to what happens here, but it really isn't worth too much consideration.) Here, you really need mktime instead, because it will probably make the right guesses about the presumed localtime given. However, if you indicate the timezone, the result will be better: >>> tz2am = time.mktimetz(time.strptime('2007-03-25 02:00:00 CET', '%Y-%m-%d >>> %H:%M:%S %Z')) >>> time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime(tz2am)) '2007-03-25 03:00:00 CEST' >>> time.strftime('%Y-%m-%d %H:%M:%S %Z', time.gmtime(tz2am)) '2007-03-25 01:00:00 GMT' Here, an offset wouldn't be precise enough in the input (something like +0100) because it wouldn't tell strptime about DST. I could go on for a very long time about all this, and I've spent a very long time messing around with the different time functions. My personal opinion is that Python's time/datetime support needs a boost if only in terms of useful additional library endorsements and better documentation. Perhaps we just need to give the datetime module the support it deserves and treat the time module as legacy code. > In other news, setting time.tzname = ('GMT', 'GMT') does nothing. You have > to set the environment variable, then call tzset. Is there a rational for > this? Seems odd. It's the bizarre, even perverse way of the old UNIX time API. Various enhancement
How to pass a reference to the current module
Hello All, Say I have this code: import AModule import ModuleUser ModuleUser.do_something_with(AModule, 'some_function_name') But say the functions are defined in the same module that contains the above code. I can imagine this hack: import AModule import ModuleUser ModuleUser.do_something_with(AModule.__name__, 'some_name') Where AModule.__name__ could be substituted for __name__ under the proper circumstances. Then, I would have this code in ModuleUser: import sys def do_something_with(modname, funcname): afunction = sys.modules[modname].funcname [etc.] Which is terribly ugly to me and makes for a pretty miserable API in my opinion, requiring the programmer to type underscores. Basically, what I am trying to acomplish is to be able to do this in any arbitrary module or __main__: funcname = determined_externally() ModuleUser.do_something_with(AModule, funcname) Ideally, it would be nice to leave out AModule if the functions were designed in the same namespace in which do_something_with is called. Thanks in advance for any suggestions. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: xlrd question
On Aug 4, 1:22 am, [EMAIL PROTECTED] wrote: > When running 'python setup.py install' to install items for xlrd to work, > does anybody know > what items are > installed and where items are installed at on a Mac (OS 10.4)? I'm assuming > it mainly uses > things out of the xlrd > folder, but was curious if it copies files to other locations. > Background: I'm the xlrd author. I've never even sat down in front of a Mac. xlrd is a pure-Python package. The setup.py is close to vanilla. Consequently (I'm guessing) the files should be installed on a Mac in a folder called P/lib/site-packages/xlrd where P is the folder containing the Python executable etc. It's easy to find out exactly where. Result on my Windows box: >>> import sys, xlrd; print sys.version; print xlrd.__file__ 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] C:\python25\lib\site-packages\xlrd\__init__.pyc At some stage in the distant past, the hierarchy was somewhat flatter, e.g. >>> import sys, xlrd; print sys.version; print xlrd.__file__ 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] C:\python21\xlrd\__init__.pyc Script files like runxlrd.py should end up somewhere else, probably in P/Scripts. If all else fails, use the shell find command. BTW, I've never had anyone else ask where files are installed, on any platform. What is your problem/concern? Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: __call__ considered harmful or indispensable?
Terry Reedy udel.edu> writes: > > The bug went something like this: > > > > obj = some.default_class > > ... > > if some_other_rare_condition_met: > > ... several lines ... > > obj = some.other_class() > > Should that have been some.other_class (without the ()s?). Either that or default value should have been an instance of some.default_class. Didn't really matter in this case... Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp problem in Python
On Aug 3, 4:41 pm, Ehsan <[EMAIL PROTECTED]> wrote: > I want to find "http://www.2shared.com/download/1716611/e2000f22/ [...] > I use this pattern : > "http.*?\.(wmv|3gp).*"" > > but it returns only 'wmv' and '3gp' instead of "http://www.2shared.com/ > download/1716611/e2000f22/Jadeed_Mlak14.wmv? > tsid=20070803-164051-9d637d11" > > what can I do? what's wrong whit this pattern? thanx for your comments Just a guess, based on too little information: Try "(http.*?\.(wmv| 3gp).*)" Regards, -=Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse/PyDev question.
king kikapu wrote: > Hi, > this is actually a question to those of us who use Eclipse and Pydev > as their main Python developing environment. As i use Eclipse (3.3 > Europa) only for Python and i have nothing to do with Java, is there a > way to disable/uninstall some Java-specific stuff and make the > environment actually more snappy ?? > > thanks for any help I like pydev and purchased the extensions ... there are bugs of course but what stopped me from using it is a project were I had some very large files (my fault). I stopped using it and went for wing dev (I need Windows and Linux access) and "there are bugs of course" ... but it is snappier. I still like pydev and will try it again ... once I can afford a faster PC / or have the time to re-factor my code. PS: I just got today news about a "free" version of wing dev .. .worth the try. hg -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse/PyDev question.
On Aug 3, 5:46 pm, "Danyelle Gragsone" <[EMAIL PROTECTED]> wrote: > I wonder how long before they come out with a python version of > eclipse. I know there is a C/C++ now. > > Danyelle The only problem i see in Eclipse/Pydev solution is that Eclipse is bulky...I was not designed for specific Python usage and because of that we have a lot of stuff that does not concern us. I started to look at Eric4 and i must way i like it a lot. I am not sure if i switch yet but it seems very nice. -- http://mail.python.org/mailman/listinfo/python-list
Re: downloading files
Il Fri, 03 Aug 2007 14:32:19 -0700, Ehsan ha scritto: > It works but could you explain more what's wrong with just 'w'? On Unix-like systems newline means '\n' On Window newline means '\r\n' So, when you open a file on Window with 'w' option, Win replace downloaded '\n' with a local '\r\n' and the file isn't readable. If you use 'wb' you say that you want a binary copy ('b' option) and Win doesn't replace anything. Hope it is useful, bye Fabio -- http://mail.python.org/mailman/listinfo/python-list
regexp problem in Python
I want to find "http://www.2shared.com/download/1716611/e2000f22/ Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11" or 3gp instead of wmv in the text file like this : ""some code"" function reportAbuse() { var windowname="abuse"; var url="/abuse.jsp?link=" + "http://www.2shared.com/file/1716611/ e2000f22/Jadeed_Mlak14.html"; OpenWindow = window.open(url,windowname,'toolbar=no,scrollbars=no,resizable=no,width=500,height=500,left=50,top=50'); OpenWindow.focus(); } function startDownload(){ window.location = "http://www.2shared.com/download/1716611/ e2000f22/Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11"; //document.downloadForm.submit(); } http://www.2shared.com/download/1716611/e2000f22/ Jadeed_Mlak14.3gp?tsid=20070803-164051-9d637d11"sfgsfgsfgv I use this pattern : "http.*?\.(wmv|3gp).*"" but it returns only 'wmv' and '3gp' instead of "http://www.2shared.com/ download/1716611/e2000f22/Jadeed_Mlak14.wmv? tsid=20070803-164051-9d637d11" what can I do? what's wrong whit this pattern? thanx for your comments -- http://mail.python.org/mailman/listinfo/python-list
Re: downloading files
On Aug 3, 10:10 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Ehsan wrote: > > I foundd this code in ASPN Python Cookbook for downloading files in > > python but when it finished downloading files the files became > > corrupted and didn't open, the files in internet havn't any problem: > > > def download(url,fileName): > >"""Copy the contents of a file from a given URL > >to a local file. > >""" > >import urllib > >webFile = urllib.urlopen(url) > >localFile = open(fileName, 'w') > >localFile.write(webFile.read()) > >webFile.close() > >localFile.close() > > download('http://www.2shared.com/download/1839752/cd520048/ > > xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' ) > > I'm guessing there are binary files and you are running on Windows, > which is inserting a carriage return before ebery newline. Try > > localFile = open(fileName, 'wb') > > to avoid thus behavior. > > regards > Steve > -- > Steve Holden+1 571 484 6266 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenweb http://del.icio.us/steve.holden > --- Asciimercial -- > Get on the web: Blog, lens and tag the Internet > Many services currently offer free registration > --- Thank You for Reading -- Hide quoted text - > > - Show quoted text - thanx Steve It works but could you explain more what's wrong with just 'w'? -- http://mail.python.org/mailman/listinfo/python-list
Re: Global package variable, is it possible?
> Only for knowing more about modules: is there a way to dinamically reload > an already imported module? > > bye > Fabio Yeah you can reload modules with the reload builtin function. -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse/PyDev question.
On 8/3/07, king kikapu <[EMAIL PROTECTED]> wrote: > > Hi, > this is actually a question to those of us who use Eclipse and Pydev > as their main Python developing environment. As i use Eclipse (3.3 > Europa) only for Python and i have nothing to do with Java, is there a > way to disable/uninstall some Java-specific stuff and make the > environment actually more snappy ?? > > thanks for any help > > You can actually just get the Eclipse 'runtime' distribution (without java stuff) and install pydev with it (latest version -- previous versions had a dependency on some java stuff). Reference: http://pydev.blogspot.com/2007/06/pydev-and-jdt-sdk-not-required-anymore.html Cheers, Fabio -- http://mail.python.org/mailman/listinfo/python-list
amra and py2exe
Hi i am having trouble creating exe using py2exe for amara package i saw some posts related to this talking about amara cat file but i dont have any cat file for amara on my machine. the standalone script runs fine. i am using python on windows here is the error i am getting while creating the exe The following modules appear to be missing ['amara', 'ext.IsDOMString', 'ext.SplitQName'] can anybody please help me with this? Thanks, Vinod -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse and Python
Użytkownik Danyelle Gragsone napisał: > Does anyone have any suggested websites for learning Eclipse the python way? > > thanks, > Danyelle http://www.showmedo.com/videos/series?name=PyDevEclipseList -- Opole - Miasto Bez Granic. http://www.opole.pl - tu znajdziesz nowe miejsca, nowe mozliwosci, nowe inspiracje... -- http://mail.python.org/mailman/listinfo/python-list
Re: Global package variable, is it possible?
Il Fri, 03 Aug 2007 14:16:59 -0400, Carsten Haese ha scritto: > Right idea, wrong execution. Note that the OP said "I'd like to be able > to reload the config file dynamically and have all my modules > automatically receive the new config." You are obviously right ... I haven't read all the post, sorry! Only for knowing more about modules: is there a way to dinamically reload an already imported module? bye Fabio -- http://mail.python.org/mailman/listinfo/python-list
ANNOUNCE: Spiff Workflow 0.0.1 (Initial Release)
Introduction Spiff Workflow is a library implementing a framework for workflows. It is based on http://www.workflowpatterns.com and implemented in pure Python. Supported workflow patterns include (at least) the following: 1. Sequence 2. Parallel Split 3. Synchronization 4. Exclusive Choice 5. Simple Merge 6. Multi-Choice 7. Structured Synchronizing Merge 8. Multi-Merge 9. Structured Discriminator 10. Arbitrary Cycles Spiff Workflow is part of the Spiff platform, which aims to produce a number of generic libraries generally needed in enterprise applications. This release is the initial release and SHOULD NOT BE USED IN PRODUCTION ENVIRONMENTS - this release is meant for development only. Spiff Workflow is free software and distributed under the GNU LGPLv2.1. Dependencies - Python >= 2.4 Download - The release page is here: http://pypi.python.org/pypi/Spiff%20Workflow/0.0.1 You can also check the code out of SVN: svn checkout http://spiff.googlecode.com/svn/trunk/libs/Workflow/ Links: --- Spiff project page: http://code.google.com/p/spiff/ Mailing list: http://groups.google.com/group/spiff-devel Bug tracker: http://code.google.com/p/spiff/issues/list Documentation: http://spiff.googlecode.com/svn/trunk/libs/Workflow/README Browse the source: http://spiff.googlecode.com/svn/trunk/libs/Workflow/ If you have any questions, please do not hesitate to ask. -Samuel -- http://mail.python.org/mailman/listinfo/python-list
libpq.dll for pgdb
the module PGDB which gives Python access to PostgreSql currently wants for a copy of a properly located or proper libpq.dll library, on Windows. anyone know what the current story on this is? thanks, -- jt -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange set of errors
On 8/3/07, Stephen Webb <[EMAIL PROTECTED]> wrote: > Greetings all, > > I've recently begun using Python to do scientific computation, and I wrote > the following script to find approximate eigenvalues for a semi-infinite > matrix: > > > from pylab import * > from numpy import * > from scipy import * > > def bandstructure(N,s): > > b = s/4.0 > > jmax = 10 + N**2 > > spectrum1 = [0]*2*N > spectrum2 = [0]*2*N > spectrum3 = [0]*2*N > > > for k in arange(1, 2*N+1, 1): > > A = zeros( (jmax,jmax) ) > > i = 0 > while i <= jmax-1: > if i <= jmax-2: > A[i,i+1] = b > A[i+1,i] = b > A[i,i] = ((k + 2.0*i*N)/N)**2 > i = i+1 > else: > A[i,i] = ((k + 2.0*i*N)/N)**2 > i = i+1 > > #This portion of the code builds a matrix twice as large to check > against > > B = zeros( (2*jmax,2*jmax) ) > > i = 0 > while i <= 2*jmax-1: > if i <= 2*jmax-2: > B[i,i+1] = b > B[i+1,i] = b > B[i,i] = ((k + 2.0*i*N)/N)**2 > i = i+1 > else: > B[i,i] = ((k + 2.0*i*N)/N)**2 > i = i+1 > > x = linalg.eigvals(A) > y = linalg.eigvals(B) > > j = 1 > while j<=3: > if abs(y[j]-x[j]) <= 10.0**(-5): > j = j + 1 > else: > print 'jmax not large enough to obtain accurate results' > > spectrum1[k-1] = x[0] + 0.5*s > spectrum2[k-1] = x[1] + 0.5*s > spectrum3[k-1] = x[2] + 0.5*s > > plot (k, spectrum1, k, spectrum2, k, spectrum3) > > xlabel('k (energy level)') > ylabel('E/E_r') > title('Finite Size Band Structure, N = %d, s = %f' % (N, s)) > grid(true) > > > When I run this script, I get the following message, which I can't figure > out: > > Traceback (most recent call last): > File "", line 1, in > File "bandstruc.py", line 61, in bandstructure > plot (k, spectrum1, k, spectrum2, k, spectrum3) > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pylab.py", > line 2028, in plot > ret = gca().plot(*args, **kwargs) > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", > line 2535, in plot > for line in self._get_lines(*args, **kwargs): > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", > line 437, in _grab_next_args > for seg in self._plot_2_args(remaining[:2], **kwargs): > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", > line 337, in _plot_2_args > x, y, multicol = self._xy_from_xy(x, y) > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", > line 266, in _xy_from_xy > nrx, ncx = x.shape > ValueError: need more than 0 values to unpack > Basically, you're trying to plot spectrum[123] vs. k: the spectra are lists, but k is an integer. I made some modifications to get things working more smoothly. Note the ion() function call at the beginning, and the use of "indx = arange(1,2*N+1)" instead of plotting vs. k. There's probably some other things that could be cleaned up, but I'm short on time right now; this will get your code working at least. Hope this helps, (From a fellow physicist) Kurt ## from pylab import * from numpy import * ion() def bandstructure(N,s): b = s/4.0 jmax = 10 + N**2 spectrum1 = [0]*2*N spectrum2 = [0]*2*N spectrum3 = [0]*2*N for k in arange(1, 2*N+1, 1): A = zeros( (jmax,jmax) ) i = 0 while i <= jmax-1: if i <= jmax-2: A[i,i+1] = b A[i+1,i] = b A[i,i] = ((k + 2.0*i*N)/N)**2 i = i+1 else: A[i,i] = ((k + 2.0*i*N)/N)**2 i = i+1 #This portion of the code builds a matrix twice as large to check against B = zeros( (2*jmax,2*jmax) ) i = 0 while i <= 2*jmax-1: if i <= 2*jmax-2: B[i,i+1] = b B[i+1,i] = b B[i,i] = ((k + 2.0*i*N)/N)**2 i = i+1 else: B[i,i] = ((k + 2.0*i*N)/N)**2 i = i+1 x = linalg.eigvals(A) y = linalg.eigvals(B) j = 1 while j<=3: if abs(y[j]-x[j]) <= 10.0**(-5): j = j + 1 else: print 'jmax not large enough to obtain accurate results' spectrum1[k-1] = x[0] + 0.5*s spectrum2[k-1] = x[1] + 0.5*s spectrum3[k-1] = x[2] + 0.5*s indx = arange(1,2*N+1, 1) plot (indx, spectr
Re: Trying to find zip codes/rest example
Terry Reedy wrote: > No, but does the localflavor entry on > http://code.djangoproject.com/browser/django/trunk/docs/add_ons.txt?rev=5118 > help? (found with Google) Thanks, but no. A friend asked for advice about implementing a password-checking interface; I remembered that the method described in the article seemed particularly slick. I wanted to refer it to him as a sample "best practices" link. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.listdir path error
On Aug 3, 2:50 pm, [EMAIL PROTECTED] wrote: > Hello > > Here is my simple listdir example: > > >>> import os > >>> os.listdir("C:\Python24\") # This directory relly exists > > Here is my error: > > WindowsError: [Errno 3] The system cannot find the path specified: 'l/ > *.*' > > Regards, > Vedran I get "SyntaxError: EOL while scanning single-quoted string", which is what should happen when you escape the double-quotes at the end. Not sure how you're getting that WindowsErrors. If I do os.listdir('c:\python24') instead, it works fine. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: os.listdir path error
On 8/3/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello > > Here is my simple listdir example: > > >>> import os > >>> os.listdir("C:\Python24\") # This directory relly exists > > Here is my error: > > WindowsError: [Errno 3] The system cannot find the path specified: 'l/ > *.*' That's a somewhat surprising error. Under 2.5, I get a more helpful error message: >>> import os >>> os.listdir("C:\Python25\") SyntaxError: EOL while scanning single-quoted string That's because I've escaped the closing quote of the string with \". Use this instead: >>> os.listdir("C:\\Python25\\") or >>> os.listdir("C:/Python25/") since windows is usually happy to use forward slashes instead of backslashes in directory names. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange set of errors
Sorry, forgot to "Reply to all." On 8/3/07, Stephen Webb <[EMAIL PROTECTED]> wrote: > Greetings all, <> > Also, I've been having trouble with the plot function in matplotlib. For > example, I enter the following in the terminal: > > >>> from pylab import * > >>> plot([1,2,3]) > [] > I can help you with your second problem: matplotlib is doing what it should, all you need to do is tell it to show() the figure you created (with the plot on it.) Note -- if you call the show() function, you will turn control over to the backend (in my case, TkAgg), and lose the ability to issue interactive commands afterwards. A solution is to use the ion() (stands for "interactive-on") function call before issuing plotting commands: >>> from pylab import * >>> ion() >>> plot([1,2,3]) [] >>> # image is shown here See http://matplotlib.sourceforge.net/interactive.html for an exhaustive explanation. > Every time I run the plot([1,2,3]) I get a different ending number that > seems to vary randomly. The "[]" is what the plot() function returns -- a list of instances of the Line2D class, and it tells you their locations in memory (hence the hex number starting with 0x). The hex number can be used to uniquely identify this object, as in the id(object) call. Hope this helps, Kurt -- http://mail.python.org/mailman/listinfo/python-list
os.listdir path error
Hello Here is my simple listdir example: >>> import os >>> os.listdir("C:\Python24\") # This directory relly exists Here is my error: WindowsError: [Errno 3] The system cannot find the path specified: 'l/ *.*' Regards, Vedran -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse and Python
On Aug 3, 11:22 am, "Danyelle Gragsone" <[EMAIL PROTECTED]> wrote: > Does anyone have any suggested websites for learning Eclipse the python way? > > thanks, > Danyelle This article is a little old, but it might be helpful to you: http://www.ibm.com/developerworks/library/os-ecant/ I found this too. It looks a little better: http://pydev.sourceforge.net/ Have fun! Mike -- http://mail.python.org/mailman/listinfo/python-list
draggable Tkinter.Text widget
Inspired by effbot's recent Vroom! editor, I have been toying with my own version. I'd like to make the Text widget "draggable", kind of like how you can drag a PDF document up and down in Adobe Reader. Here's what I have so far: from Tkinter import * class Draggable(Text, object): def __init__(self, parent, **options): Text.__init__(self, parent, **options) self.config( borderwidth=0, font="{Lucida Console} 10", foreground="green", background="black", insertbackground="white", # cursor selectforeground="green", # selection selectbackground="#008000", wrap=WORD, # use word wrapping undo=True, width=80, ) self.bind('', self.handle_mousedown3) self.bind('', self.handle_drag3) def handle_mousedown3(self, event=None): self._y = event.y def handle_drag3(self, event=None): self.yview_scroll(self._y - event.y, UNITS) self._y = event.y if __name__ == '__main__': root = Tk() root.protocol("WM_DELETE_WINDOW", root.quit) root.config(background='black') root.wm_state("zoomed") text = Draggable(root) text.delete(1.0, END) text.insert(END, '\n'.join(str(x) for x in xrange(1, 1001))) text.pack(fill=Y, expand=True) root.mainloop() This works fine, but because the mouse movements are in pixels and scroll actions are in lines, the 'magnitude' of the scrolling is much larger than the mouse movements causing them. This isn't all bad, it makes scanning a long document quickly easier, but I was wondering if there was a simple way to add some "friction" to the scrolling so a tiny mouse movement doesn't cause the text to go zipping by in a flash. Thanks, infidel -- http://mail.python.org/mailman/listinfo/python-list
Re: downloading files
On Aug 3, 1:48 pm, Ehsan <[EMAIL PROTECTED]> wrote: > I foundd this code in ASPN Python Cookbook for downloading files in > python but when it finished downloading files the files became > corrupted and didn't open, the files in internet havn't any problem: > > def download(url,fileName): > """Copy the contents of a file from a given URL > to a local file. > """ > import urllib > webFile = urllib.urlopen(url) > localFile = open(fileName, 'w') > localFile.write(webFile.read()) > webFile.close() > localFile.close() > download('http://www.2shared.com/download/1839752/cd520048/ > xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' ) Uhhh...you probably need to change the open() command to binary mode. Replace that line with this: localFile = open(fileName, mode='wb') I tried it on my PC to download a photo from one of my sites and it worked great. Mike -- http://mail.python.org/mailman/listinfo/python-list
Announcing Wing IDE 101 for teaching intro programming courses
Hi, We're pleased to announce the first public beta release of Wing IDE 101, a free scaled back edition of Wing IDE that was designed for teaching introductory programming courses. We are releasing Wing IDE 101 to the general public in the hopes that it may help others teach with or learn Python. Wingware also offers educational pricing for Wing IDE Professional, including steep discounts for class room use. If you are interested in teaching Python with Wing IDE, please email [EMAIL PROTECTED] for more information. Key features of Wing IDE 101 include: * Powerful Editor -- Syntax highlighting, goto-definition, navigation menus, error indicators, auto-indent, and keyboard emulation for Visual Studio, VI/Vim, Emacs, and Brief. * Python Shell -- Evaluate files and selections in the integrated Python shell. * Graphical Debugger -- Set breakpoints and view stack and program data. Note that Wing IDE 101 omits auto-completion and most other code intelligence features found in the other Wing IDE products. This was by design, so that students are more conscious of the details of the language and the modules that they are learning about. Wing IDE 101 is available on Windows, Linux, and Mac OS X. It is free for all non-commercial uses and does not require a license code to run. Wing 101 is not, however, open source. The current release is 3.0 beta1 and is available here: http://wingware.com/downloads/wingide-101 General information for beta testers is here: http://wingware.com/wingide/beta More details on Wing 101's features are here: http://wingware.com/wingide-101 http://wingware.com/wingide/features Please direct bug reports and suggestions to [EMAIL PROTECTED] Thanks! The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to find zip codes/rest example
"VanL" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | | I now cannot find this demo and the associated discussion. Does anybody | remember this demo and where I might be able to find it? No, but does the localflavor entry on http://code.djangoproject.com/browser/django/trunk/docs/add_ons.txt?rev=5118 help? (found with Google) -- http://mail.python.org/mailman/listinfo/python-list
Re: (no) fast boolean evaluation ? missing NOT
"Stef Mientki" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | John Machin wrote: | So now I'm left with just one question: | for bitwise operations I should use &, |, ^ | for boolean operations I should use and, or, xor | but after doing some test I find strange effects: | >>> A = 4 | >>> B = 5 | >>> A and B | 5 >>> B and A 4 | >>> A & B | 4 | >>> A or B | 4 >>> B or A 5 | >>> A | B | 5 | | So if I use the bitwise operation on integers, | "and" changes into (bitwise) "or" and vise versa. No, you hypnotised yourself by generalizing from insufficient data. Repeat experiment with, for instance, 3 and 4 instead of 4 and 5. Then 3&4 = 0, 3|4 = 7. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: downloading files
On Fri, 2007-08-03 at 11:48 -0700, Ehsan wrote: > I foundd this code in ASPN Python Cookbook for downloading files in > python but when it finished downloading files the files became > corrupted and didn't open, the files in internet havn't any problem: > > > def download(url,fileName): > """Copy the contents of a file from a given URL > to a local file. > """ > import urllib > webFile = urllib.urlopen(url) > localFile = open(fileName, 'w') > [...] Try 'wb' instead of 'w'. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: downloading files
Ehsan wrote: > I foundd this code in ASPN Python Cookbook for downloading files in > python but when it finished downloading files the files became > corrupted and didn't open, the files in internet havn't any problem: > > > def download(url,fileName): > """Copy the contents of a file from a given URL > to a local file. > """ > import urllib > webFile = urllib.urlopen(url) > localFile = open(fileName, 'w') > localFile.write(webFile.read()) > webFile.close() > localFile.close() > download('http://www.2shared.com/download/1839752/cd520048/ > xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' ) > I'm guessing there are binary files and you are running on Windows, which is inserting a carriage return before ebery newline. Try localFile = open(fileName, 'wb') to avoid thus behavior. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden --- Asciimercial -- Get on the web: Blog, lens and tag the Internet Many services currently offer free registration --- Thank You for Reading - -- http://mail.python.org/mailman/listinfo/python-list
Re: Global package variable, is it possible?
On Aug 3, 10:51 am, Fabio Z Tessitore <[EMAIL PROTECTED]> wrote: > Heve you tried to do something like: > > # module configure.py > value1 = 10 > value2 = 20 > ... > > # other module > from configure import * > > # now I'm able to use value1 value2 etc. > var = value1 * value2 > > bye Thanks for the response Fabio. I thought about this, but I don't think this will work well in my situation either. Take a look at the following: __init__py: ### _default_cfgfile = 'config.conf' from configure import * cfg = loadcfg(_default_cfgfile) import pkg_module1 import pkg_module2 # EOF configure.py: from ConfigParser import SafeConfigParser def loadcfg(filename): file = open(filename) cfg = SafeConfigParser() cfg.readfp(file) return cfg # EOF pkg_module1: _default_cfgfile = 'config.conf' from configure import * cfg = loadcfg(_default_cfgfile) # EOF One problem I see with this approach is that we must define the configuration file in every module. Alternatively a better approach would be to only define the configuration file within configure.py, however this also seems less than ideal. I don't like it because I believe something as important as the location of the package configuration file, used by all modules, should defined in __init__ not tucked away in one of it's modules. Another problem is that after the package is loaded and we want to load in a new config file, what will happen? With this approach we'll have to reload every module the package uses for them to read the new config. And even then, how do we tell each module what the new config file is? If I did define the configuration file in configure.py then I suppose what I could do is set a cfgfile variable in configure.py to the new file location and reload all the modules. If there is no global package variables, then maybe this isn't so bad... Hmm. So maybe something like this makes sense: __init__py: ### _default_cfg_file = 'config.conf' import configure def loadcfg(filename): configure.cfgfile = filename try: reload(pkg_module1) reload(pkg_module2) except NameError: pass cfg = loadcfg(_default_cfg_file) import pkg_module1 import pkg_module2 # EOF confgure.py: ### cfgfile = None def loadcfg() global cfgfile if not cfgfile: return None file = open(cfgfile) cfg = SafeConfigParser() cfg.readfp(file) return cfg # EOF pkg_module1: ### import configure cfg = configure.loadcfg() # EOF It's a little bit convoluted, but I think it solves most of my gripes. Anybody have a better idea of how to do this? Thanks again Fabio. -- http://mail.python.org/mailman/listinfo/python-list
Re: Global package variable, is it possible?
On Aug 3, 11:16 am, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Fri, 2007-08-03 at 17:51 +, Fabio Z Tessitore wrote: > > Heve you tried to do something like: > > > # module configure.py > > value1 = 10 > > value2 = 20 > > ... > > > # other module > > from configure import * > > > # now I'm able to use value1 value2 etc. > > var = value1 * value2 > > Right idea, wrong execution. Note that the OP said "I'd like to be able > to reload the config file dynamically and have all my modules > automatically receive the new config." > > "from configure import *" will import the settings into the current > namespace, and subsequent changes in the original namespace will, in > general, not have any effect in the current namespace. > > This should do the trick: > > # module configure.py > value1 = 10 > value2 = 20 > ... > > # other module > import configure > > var = configure.value1 * configure.value2 > > HTH, > > -- > Carsten Haesehttp://informixdb.sourceforge.net It does help thanks. Okay now after reading your post I really need to do some experimenting. I was under the impression when I wrote my last post that changing an attribute in one modules instance in __init__.py would not effect other modules. Sorry, I'm relatively new to python, and things like this are still sometimes "gotchas!" for me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Global package variable, is it possible?
> Hmm. So maybe something like this makes sense: > > __init__py: > ### > _default_cfg_file = 'config.conf' > > import configure > def loadcfg(filename): > configure.cfgfile = filename > try: > reload(pkg_module1) > reload(pkg_module2) > except NameError: > pass > cfg = loadcfg(_default_cfg_file) > > import pkg_module1 > import pkg_module2 > # EOF > > confgure.py: > ### > cfgfile = None > def loadcfg() > global cfgfile > if not cfgfile: > return None > file = open(cfgfile) > cfg = SafeConfigParser() > cfg.readfp(file) > return cfg > # EOF > > pkg_module1: > ### > import configure > cfg = configure.loadcfg() > # EOF > > It's a little bit convoluted, but I think it solves most of my > gripes. Anybody have a better idea of how to do this? Thanks again > Fabio. Ugh... I wasn't thinking... Of course this won't work either for the same reasons above. changing configure.cfgfile from __init__.py will have no effect on the separate configure instances loaded in other modules. I still don't understand why python's __init__.py namespace isn't global to all modules in the package. Is this a feature, to prevent sloppy code? I think there are certain instances when it would make sense. -- http://mail.python.org/mailman/listinfo/python-list
downloading files
I foundd this code in ASPN Python Cookbook for downloading files in python but when it finished downloading files the files became corrupted and didn't open, the files in internet havn't any problem: def download(url,fileName): """Copy the contents of a file from a given URL to a local file. """ import urllib webFile = urllib.urlopen(url) localFile = open(fileName, 'w') localFile.write(webFile.read()) webFile.close() localFile.close() download('http://www.2shared.com/download/1839752/cd520048/ xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' ) -- http://mail.python.org/mailman/listinfo/python-list
Re: __call__ considered harmful or indispensable?
Skip Montanaro a écrit : >>> In this case there was a bug. Depending on inputs, sometimes obj >>> initialized to a class, sometimes an instance of that class. (I fixed >>> that too while I was at it.) The problem was that the use of __call__ >>> obscured the underlying bug by making the instance as well as the class >>> callable. > >> I don't quite get the point here. A concrete example would be welcome. > > The bug went something like this: > > obj = some.default_class > ... > if some_other_rare_condition_met: > ... several lines ... > obj = some.other_class() Should that have been some.other_class (without the ()s?). It is in the nature of Python's dynamic typing that mis-typing errors sometimes show up later than one would wish. Hence the need for unit testing. Consider i = condition and 1 or '2' # whoops, should have been 2, without the 's ... k = j * i # j an int; whoops, bad i value passes silently ... use of k as string raises exception I do not think __call__ should be specifically blamed for this general downside of Python's design. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
RE: File Handling & TRY/EXCEPT
"Robert Rawlins - Think Blue" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Thanks for your ideas guys, > > I'm unfortunately tied to 2.4 so don't have the full try except > status, but I'm now working with the following code: > > def addApp(self, event): > try: >logfile = > open('/pblue/new/Logs/Application.csv','a') > >now = datetime.datetime.now() >logstring = '%s,%s \n' % (event, str(now)) > >try: > logfile.write(logstring) >finally: > logfile.close() > except: >self.addApp(event) > > I'm trying to slowly debug my app and get rid of all the memory leaks, > but its pain staking work, any help you can offer on that stuff would > be a god send, I'm a little reluctant about posting all my app code on > the lists as I'd like to keep some of it private. > > How does that new version look? A little tidier? > > Thanks guys, > Now, you are sure the file is always close. What I don't think is correct is to retry to re-write the event (cause if opening the file crashed ones there are very good chances that it will throw the 2nd time). ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list
►►►Get FREE Satellite TV on your PC ◄◄◄
Watch Satellite TV On Your Computer Without Paying Monthly Fees... FOR FREE? Watch all your favorite shows on your Computer from anywhere in the World! Save 1000's of $$$ over many years on cable and satellite bills. INSTANT DOWNLOAD Plus Free Unlimited Downloads Movies, MP3s Music, etc !!! More Details: http://tvonpc.us.to/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Global package variable, is it possible?
On Fri, 2007-08-03 at 17:51 +, Fabio Z Tessitore wrote: > Heve you tried to do something like: > > # module configure.py > value1 = 10 > value2 = 20 > ... > > > # other module > from configure import * > > # now I'm able to use value1 value2 etc. > var = value1 * value2 Right idea, wrong execution. Note that the OP said "I'd like to be able to reload the config file dynamically and have all my modules automatically receive the new config." "from configure import *" will import the settings into the current namespace, and subsequent changes in the original namespace will, in general, not have any effect in the current namespace. This should do the trick: # module configure.py value1 = 10 value2 = 20 ... # other module import configure var = configure.value1 * configure.value2 HTH, -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: i am new to python-Please somebody help
BTW - on the subject of polite discussions, how about this one as an example of opinions politely expressed. Oh, and does anyone know how to use zip in Python. Yes+1. -- http://mail.python.org/mailman/listinfo/python-list
Strange set of errors
Greetings all, I've recently begun using Python to do scientific computation, and I wrote the following script to find approximate eigenvalues for a semi-infinite matrix: from pylab import * from numpy import * from scipy import * def bandstructure(N,s): b = s/4.0 jmax = 10 + N**2 spectrum1 = [0]*2*N spectrum2 = [0]*2*N spectrum3 = [0]*2*N for k in arange(1, 2*N+1, 1): A = zeros( (jmax,jmax) ) i = 0 while i <= jmax-1: if i <= jmax-2: A[i,i+1] = b A[i+1,i] = b A[i,i] = ((k + 2.0*i*N)/N)**2 i = i+1 else: A[i,i] = ((k + 2.0*i*N)/N)**2 i = i+1 #This portion of the code builds a matrix twice as large to check against B = zeros( (2*jmax,2*jmax) ) i = 0 while i <= 2*jmax-1: if i <= 2*jmax-2: B[i,i+1] = b B[i+1,i] = b B[i,i] = ((k + 2.0*i*N)/N)**2 i = i+1 else: B[i,i] = ((k + 2.0*i*N)/N)**2 i = i+1 x = linalg.eigvals(A) y = linalg.eigvals(B) j = 1 while j<=3: if abs(y[j]-x[j]) <= 10.0**(-5): j = j + 1 else: print 'jmax not large enough to obtain accurate results' spectrum1[k-1] = x[0] + 0.5*s spectrum2[k-1] = x[1] + 0.5*s spectrum3[k-1] = x[2] + 0.5*s plot (k, spectrum1, k, spectrum2, k, spectrum3) xlabel('k (energy level)') ylabel('E/E_r') title('Finite Size Band Structure, N = %d, s = %f' % (N, s)) grid(true) When I run this script, I get the following message, which I can't figure out: Traceback (most recent call last): File "", line 1, in File "bandstruc.py", line 61, in bandstructure plot (k, spectrum1, k, spectrum2, k, spectrum3) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pylab.py", line 2028, in plot ret = gca().plot(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", line 2535, in plot for line in self._get_lines(*args, **kwargs): File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", line 437, in _grab_next_args for seg in self._plot_2_args(remaining[:2], **kwargs): File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", line 337, in _plot_2_args x, y, multicol = self._xy_from_xy(x, y) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", line 266, in _xy_from_xy nrx, ncx = x.shape ValueError: need more than 0 values to unpack Also, I've been having trouble with the plot function in matplotlib. For example, I enter the following in the terminal: >>> from pylab import * >>> plot([1,2,3]) [] I'm reasonably sure that the issue in the first big error message is just an indexing error on my part, but I have no idea what the second thing means. Every time I run the plot([1,2,3]) I get a different ending number that seems to vary randomly. Could anybody please help me out with these problems? Thanks, Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: i am new to python-Please somebody help
On the discussion of rudeness, we have to include the OP. He/She/it did not even attempt a Google before posting, and posted with a meaningless subject. We'll chalk that up to newness, but some sort of retort was called for IMHO. How else do we learn the conventions that govern rudeness. Personally, there is only one form of rudeness that can not be overlooked and that is the prima donna that says "My Way Is The Only Way", or posts some nonsense like "that is not correct" with no other explanation. Any attempt to sincerely help, I can live with. -- http://mail.python.org/mailman/listinfo/python-list
Re: Global package variable, is it possible?
Heve you tried to do something like: # module configure.py value1 = 10 value2 = 20 ... # other module from configure import * # now I'm able to use value1 value2 etc. var = value1 * value2 bye -- http://mail.python.org/mailman/listinfo/python-list
Re: (no) fast boolean evaluation ?
John Machin wrote: > > (you_are_confused and/or > function_returns_bool_but_has__side_effects()) > That above expression should be written more explicitly like: function_result = function_returning_bool_but_with_side_effects() if you_are_confused or function_result: do_something_nice() --irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: (no) fast boolean evaluation ?
On 2007-08-03, Ed Leafe <[EMAIL PROTECTED]> wrote: > On Aug 3, 2007, at 11:57 AM, Bruno Desthuilliers wrote: > >> Sorry, I forgot to mention the language did not allow to have else >> & if >> in the same statement. IOW : >> >> if some_condition then >>do_sometehing >> else >>if some_other_condition then >> do_something_else >>else >> if yet_another_condition then >>do_yet_another_thing >> else >>if your_still_here then >> give_up('this language is definitively brain dead') >>end if >> end if >>end if >> end if > > Usually that's because the language provides a switch/case > statement construct. If it does and you try to write the above > code, it isn't the language that's brain-dead! ;-) The switch statements I'm aware of are less generally applicable than a tower of "if { else if }* else". For example, with a switch statement you have to dispatch on the one value for every case. In some languages, it's even of more limited, e.g., C, which can switch on only integers. -- Neil Cerutti Next Sunday Mrs. Vinson will be soloist for the morning service. The pastor will then speak on "It's a Terrible Experience." --Church Bulletin Blooper -- http://mail.python.org/mailman/listinfo/python-list
Re: Using cursor.callproc with zxJDBC
On Fri, 2007-08-03 at 17:31 +0100, Vaughan V Ashe wrote: > Hi > > We would like to use the store proc. We are using a postgreql > database. what we have working so far is: > > params = [4,4,2] > > curs.callproc("update_job_status",params) > > db.commit() > > #print db > > #print curs.description > > result = curs.fetchall() > > if result == 1: > > print "good one" > > else: > > print "shite" > > > > we are using the beta version of jython. Would be very happy to get a > response from you You haven't asked a question, and you're not describing what your problem is. I'm going to guess what your problem is: You're always getting the result "shite" regardless of whether the procedure worked or not. curs.fetchall() returns a list, which is never going to be equal to 1. If this doesn't help you, please describe what exactly your problem is. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Global package variable, is it possible?
Hello fellow pythoneers. I'm stumped on something, and I was hoping maybe someone in here would have an elegant solution to my problem. This is the first time I've played around with packages, so I'm probably misunderstanding something here... Here's what I'd like to do in my package. I want my package to use a configuration file, and what I'd like is for the config file to appear magically in each module so I can just grab values from it without having to load and parse the config file in each package module. Not quite understanding how the __init__.py file works, I expected it to be as easy as just setting up the ConfigParser object and then I figured (since a package is a module) that it would now be global to my package and I could access it in my modules, but I was wrong... I don't want to have to pass it in to each module upon init, or anything lame like that. A main reason for this is that I'd like to be able to reload the config file dynamically and have all my modules automatically receive the new config. There must be a way to do this, but seeing how __init__.py's namespace is not available within the package modules, I don't see a simple and elegant way to do this. Does anybody have any suggestions? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Email
On Aug 2, 1:06 pm, Laurent Pointal <[EMAIL PROTECTED]> wrote: > Rohan wrote: > > I was wondering if there could be an arrangement where a file could be > > attached and send as an email. > > For ex > > f = open(add.txt,w) > > f.write('python') > > f.close() > > > Now I would like to send an email with add.txt as an attachment, is it > > possible ? > > some one give me a pointer towards this. > > You can use iMailer as an example script to get parts: > > http://nojhan.free.fr/article.php3?id_article=22 > > A+ > > Laurent. Laurent the link you gave me is in a language unknown to me if you have anything that expalains in english, then let me know. thanks -- http://mail.python.org/mailman/listinfo/python-list
Using cursor.callproc with zxJDBC
Hi We would like to use the store proc. We are using a postgreql database. what we have working so far is: params = [4,4,2] curs.callproc("update_job_status",params) db.commit() #print db #print curs.description result = curs.fetchall() if result == 1: print "good one" else: print "shite" we are using the beta version of jython. Would be very happy to get a response from you Regards Vaughan -- http://mail.python.org/mailman/listinfo/python-list
Devloper Wanted For Debugging / Optimizing
Hello Chaps, I've been writing (with your help) a small application over the past couple of months but I'm really struggling to iron out all of the creases and its seems to spring a few memory leaks that I'm unable to find and plug. It's only a small app, around 500 lines of code I would guess, aside from the usual python type things it deals with dbus and XML parsing using element tree, But it's for an embedded Linux platform so keeping it lightweight and memory leak free is an absolute must. Is anyone interested to take this small project on to have a look at my code? Perhaps give me a little bit of advice on where I'm going wrong? I would be willing to pay someone for their much needed time to get the final few creases ironed out, this isn't really stuff we can deal with on the boards so something private is a must, hence I'm exploring the idea of a paid contract. If anyone is interested then please feel free to contact me off list. Thanks again guys, Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: (no) fast boolean evaluation ?
On Aug 3, 2007, at 11:57 AM, Bruno Desthuilliers wrote: > Sorry, I forgot to mention the language did not allow to have else > & if > in the same statement. IOW : > > if some_condition then >do_sometehing > else >if some_other_condition then > do_something_else >else > if yet_another_condition then >do_yet_another_thing > else >if your_still_here then > give_up('this language is definitively brain dead') >end if > end if >end if > end if Usually that's because the language provides a switch/case statement construct. If it does and you try to write the above code, it isn't the language that's brain-dead! ;-) -- Ed Leafe -- http://leafe.com -- http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list
Idlelib TreeWidget (UNCLASSIFIED)
Classification: UNCLASSIFIED Caveats: NONE Does anyone have any experience using the idlelib TreeWidget module? I am using it to display XML files and would like to include some editing capabilities. Does anyone have any examples I could take a look at? Thanks, John Classification: UNCLASSIFIED Caveats: NONE -- http://mail.python.org/mailman/listinfo/python-list
Re: Efficient Rank Ordering of Nested Lists
On Aug 2, 10:20 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > A naive approach to rank ordering (handling ties as well) of nested > lists may be accomplished via: > >def rankLists(nestedList): > def rankList(singleList): > sortedList = list(singleList) > sortedList.sort() > return map(sortedList.index, singleList) > return map(rankList, nestedList) > >>>> unranked = [ [ 1, 2, 3, 4, 5 ], [ 3, 1, 5, 2, 4 ], [ -1.1, 2.2, > 0, -1.1, 13 ] ] >>>> print rankLists(unranked) > >[[0, 1, 2, 3, 4], [2, 0, 4, 1, 3], [0, 3, 2, 0, 4]] > > This works nicely when the dimensions of the nested list are small. > It is slow when they are big. Can someone suggest a clever way to > speed it up? Isn't there something wrong with the ordering? Pablo's answers are: [ 1, 2, 3, 4, 5 ] == [0, 1, 2, 3, 4] correct [ 3, 1, 5, 2, 4 ] == [2, 0, 4, 1, 3] wrong? [ -1.1, 2.2, 0, -1.1, 13 ] == [0, 3, 2, 0, 4] wrong? Doing it in my head I get: [ 3, 1, 5, 2, 4 ] == [ 1, 3, 0, 4, 2 ] [ -1.1, 2.2, 0, -1.1, 13 ] == [0, 3, 2, 1, 4] What gives? Did I misunderstand what "rank ordering (handling ties as well)" means? -- http://mail.python.org/mailman/listinfo/python-list
Eclipse and Python
Does anyone have any suggested websites for learning Eclipse the python way? thanks, Danyelle -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse/PyDev question.
I just found this: http://www.easyeclipse.org/site/distributions/python.html -- http://mail.python.org/mailman/listinfo/python-list
Re: (no) fast boolean evaluation ?
Steven D'Aprano a écrit : > On Fri, 03 Aug 2007 10:20:59 +0200, Bruno Desthuilliers wrote: > >> Joshua J. Kugler a écrit : >>> On Thursday 02 August 2007 15:19, Evan Klitzke wrote: > I discovered that boolean evaluation in Python is done "fast" > (as soon as the condition is ok, the rest of the expression is ignored). This is standard behavior in every language I've ever encountered. >>> Then you've never programmed in VB (at least 6, don't know if .net still >>> does this). Nested IF statements. CK! >> I do remember an even brain-deadiest language that not only didn't >> short-circuit boolean operators but also didn't have an "elif" statement... > > > Is it a secret? > > I'm a little perplexed at why you say a language without "elif" is a good > sign of brain-death in a programming language. I understand that, given > the parsing rules of Python, it is better to use elif than the equivalent: > > if condition: > pass > else: > if another_condition: > pass > > > But that's specific to the syntax of the language. You could, if you > choose, design a language where elif was unnecessary: > > if condition: > pass > else if another_condition: > pass > > What advantage is there to "elif", apart from it needing three fewer > characters to type? > Sorry, I forgot to mention the language did not allow to have else & if in the same statement. IOW : if some_condition then do_sometehing else if some_other_condition then do_something_else else if yet_another_condition then do_yet_another_thing else if your_still_here then give_up('this language is definitively brain dead') end if end if end if end if -- http://mail.python.org/mailman/listinfo/python-list
Coroutine API
I was talking to some other people, who all were working on different schedulers and such for coroutines. We decided to work out a common API to give coroutines, and common rules to passing data between them, etc. I am wondering now if there is already work on this, or some schedulers I'm not aware of that have any deployment and a good, simple design. We also setup a group to discuss this and iron out our details and some common coroutines. [EMAIL PROTECTED] We came up with this basic rule set: 1) A coroutine can be any iterable 2) A coroutine yielding None is suspending to allow others to run 3) A coroutine yielding something else is yielding another coroutine and needs to stay suspended until that coroutine has a value to pass to the send() method of the coroutine. 4) In the above case, if the yielded coroutine raises an exception, it is passed to the waiting coroutine's throw() method. 5) A coroutine raising StopIteration(arg), where arg is its final result, expects arg to be passed to the send() method of any coroutine which is waiting for its completion. The idea is that we don't rely on defining any new types or functions and we keep it extremely simple. I'd like to consider it WSGI for coroutines. -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacing _xmlplus.dom.minidom with xml.dom.minidom
Robert Rawlins - Think Blue wrote: > Just as a heads up, minidom is pretty inefficient and difficult to work with > too. > > On someone else's advice I switched over to ElementTree and have been really > pleased with the results, its much simpler to work with and more efficient > too. /and/ lxml.etree is compatible to ElementTree, so once you have written your code for ElementTree, you can switch to lxml.etree if ever you need things like XPath, XSLT or validation. However, as I understand the OP, the question deals with old code, so porting it to ET (i.e. reimplementing it) might not be that easy... Stefan -- http://mail.python.org/mailman/listinfo/python-list