AttributeError: 'module' object has no attribute 'setdefaulttimeout'
I get those errors when I run: /usr/local/bin/SquidClamAV_Redirector.py -c /etc/squid/SquidClamAV_Redirector.conf ## Traceback (most recent call last): File "/usr/local/bin/SquidClamAV_Redirector.py", line 573, in ? redirector = SquidClamAV_Redirector(config) File "/usr/local/bin/SquidClamAV_Redirector.py", line 145, in __init__ self.__start_urlhandler__() File "/usr/local/bin/SquidClamAV_Redirector.py", line 454, in __start_urlhandler__ urllib.socket.setdefaulttimeout(self.timeout) AttributeError: 'module' object has no attribute 'setdefaulttimeout' # the line that is the problem looks like this: # urllib.socket.setdefaulttimeout(self.timeout) # from the global sintax: ## def __start_urlhandler__(self): """ create the urlhandler object """ # set timeout urllib.socket.setdefaulttimeout(self.timeout) self.urlhandler = urllib.URLopener() if self.proxy != {}: self.urlhandler.proxies = self.proxy self.urlhandler.addheaders = [('User-agent', ModuleName + ' ' + str(version))] ## can you give me a hint with this matter? -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] PEP 383: Non-decodable Bytes in System Character Interfaces
How about another str-like type, a sequence of char-or-bytes? Could be called strbytes or stringwithinvalidcharacters. It would support whatever subset of str functionality makes sense / is easy to implement plus a to_escaped_str() method (that does the escaping the PEP talks about) for people who want to use regexes or other str-only stuff. Here is a description by example: os.listdir('.') -> [strbytes('normal_file'), strbytes('bad', 128, 'file')] strbytes('a')[0] -> strbytes('a') strbytes('bad', 128, 'file')[3] -> strbytes(128) strbytes('bad', 128, 'file').to_escaped_str() -> 'bad?128file' Having a separate type is cleaner than a "str that isn't exactly what it represents". And making the escaping an explicit (but rarely-needed) step would be less surprising for users. Anyway, I don't know a whole lot about this issue so there may an obvious reason this is a bad idea. On Wed, Apr 22, 2009 at 6:50 AM, "Martin v. Löwis" wrote: > I'm proposing the following PEP for inclusion into Python 3.1. > Please comment. > > Regards, > Martin > > PEP: 383 > Title: Non-decodable Bytes in System Character Interfaces > Version: $Revision: 71793 $ > Last-Modified: $Date: 2009-04-22 08:42:06 +0200 (Mi, 22. Apr 2009) $ > Author: Martin v. Löwis > Status: Draft > Type: Standards Track > Content-Type: text/x-rst > Created: 22-Apr-2009 > Python-Version: 3.1 > Post-History: > > Abstract > > > File names, environment variables, and command line arguments are > defined as being character data in POSIX; the C APIs however allow > passing arbitrary bytes - whether these conform to a certain encoding > or not. This PEP proposes a means of dealing with such irregularities > by embedding the bytes in character strings in such a way that allows > recreation of the original byte string. > > Rationale > = > > The C char type is a data type that is commonly used to represent both > character data and bytes. Certain POSIX interfaces are specified and > widely understood as operating on character data, however, the system > call interfaces make no assumption on the encoding of these data, and > pass them on as-is. With Python 3, character strings use a > Unicode-based internal representation, making it difficult to ignore > the encoding of byte strings in the same way that the C interfaces can > ignore the encoding. > > On the other hand, Microsoft Windows NT has correct the original > design limitation of Unix, and made it explicit in its system > interfaces that these data (file names, environment variables, command > line arguments) are indeed character data, by providing a > Unicode-based API (keeping a C-char-based one for backwards > compatibility). > > For Python 3, one proposed solution is to provide two sets of APIs: a > byte-oriented one, and a character-oriented one, where the > character-oriented one would be limited to not being able to represent > all data accurately. Unfortunately, for Windows, the situation would > be exactly the opposite: the byte-oriented interface cannot represent > all data; only the character-oriented API can. As a consequence, > libraries and applications that want to support all user data in a > cross-platform manner have to accept mish-mash of bytes and characters > exactly in the way that caused endless troubles for Python 2.x. > > With this PEP, a uniform treatment of these data as characters becomes > possible. The uniformity is achieved by using specific encoding > algorithms, meaning that the data can be converted back to bytes on > POSIX systems only if the same encoding is used. > > Specification > = > > On Windows, Python uses the wide character APIs to access > character-oriented APIs, allowing direct conversion of the > environmental data to Python str objects. > > On POSIX systems, Python currently applies the locale's encoding to > convert the byte data to Unicode. If the locale's encoding is UTF-8, > it can represent the full set of Unicode characters, otherwise, only a > subset is representable. In the latter case, using private-use > characters to represent these bytes would be an option. For UTF-8, > doing so would create an ambiguity, as the private-use characters may > regularly occur in the input also. > > To convert non-decodable bytes, a new error handler "python-escape" is > introduced, which decodes non-decodable bytes using into a private-use > character U+F01xx, which is believed to not conflict with private-use > characters that currently exist in Python codecs. > > The error handler interface is extended to allow the encode error > handler to return byte strings immediately, in addition to returning > Unicode strings which then get encoded again. > > If the locale's encoding is UTF-8, the file system encoding is set to > a new encoding "utf-8b". The UTF-8b codec decodes non-decodable bytes > (which must be >= 0x80) into half surrogate codes U+DC80..U+DCFF. > > Discussion > == > > While providing a uniform API to non-decodable bytes,
Re: [pyxl] xlrd 0.7.2 released!
On Wednesday, February 22, 2012 5:22:45 am Chris Withers wrote: > On 22/02/2012 00:37, python-ex...@raf.org wrote: > > was good for previous versions. two reasons that spring to mind > > > > immediately are: > > - it makes it much easier to tell what version is installed > > - it makes it much easier to uninstall the package > > > > i know that both of these are things that the python community > > does not yet seem to find useful but everyone else seems to. > > That's because it's no longer best practice to polute the global python > installation by installing packages directly into it. > > The recommended wisdom nowadays is to use a virtualenv and then pip > install the package. I can see where that would be preferred when managing multiple versions of Python, but not when using a single version. The pip system does a good job of managing package installs in the global context. As to the OPs original post, I see the point. On Windows the installer is the point of entry for 'package' management, going outside that can get confusing. I also understand setting up a Windows installer is non-trivial. Assuming a Windows installer is not in the offing, the OP might find it easier to use the Python packaging from here on out. For an example, to find out information on a package: aklaver@tucker:~/.pip$ pip search xlrd xlutils - Utilities for working with Excel files that require both xlrd and xlwt xlrd - Library for developers to extract data from Microsoft Excel (tm) spreadsheet files INSTALLED: 0.7.2 (latest) xlrd3 - Library for developers to extract data from Microsoft Excel (tm) spreadsheet files xlrd1 - library for extracting data from Microsoft Excel spreadsheet files > > I believe that will give you everything you need, please explain if it > doesn't. > > cheers, > > Chris -- Adrian Klaver adrian.kla...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
RE: string interpolation for python
Hi Yingjie, Consider this snippet of "safe" code: | enc = bobsencryption.Encoder('Some secret key') | | username = raw_input('Enter your username:') | password = raw_input('Enter your password:') | | print | print username + ', please wait while we dial-up and log you in...' | | connection = server.dialup(00441635074745) | connection.send('login ' + enc([username, password])) Code like this could already be out there and safe-ish (well, if they've included a little validation and error-checking.) Now consider that your $formatting$ is added and the "company" upgrades Python, resulting in the following: | Enter your username: $enc.key$ | Enter your password: dontneedone | | Some secret key, please wait while we dial-up and log you in... It could break old code... okay you may say you should’nt allow certain characters but if they're printable and used in a controlled environment those characters can dramatically increase the security of a username and password. Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: [pyxl] Re: xlrd 0.7.4 released!
On 04/03/2012 01:46 PM, Josh English wrote: Maybe it's just me, but I tried to upgrade my previous versions of xlrd, xlwt, an xlutils and now some of the modules aren't loading properly. I am currently using Portable Python 2.7 at this workstation. I ran "easy_install --upgrade xlrd" and the result said it had updated. If I try to update again, it says it's already there. When I try to import xlrd, I get an error IOError: [Errno 2] No such file or directory: 'C:\\Users\\josh\\Desktop\\Portable Python\\App\\lib\\site-packages\\xlrd-0.7.5-py2.7.egg\\xlrd\\version.txt' I also noticed that in my Site Packages folder, I have xlrd-0.7.1-py2.7-win32.egg as an egg file, but xlrd-0.7.5-py2.7.egg as a folder. This in on a Windows 7 machine. I didn't think EGG files could be folders. Is there a change in the way the EGG file was meant to be distributed? Interesting the below seemed to have got lost on way to Google Groups: From Chris: " As pointed out, I stuffed up the release by not including a new file in the MANIFEST. My bad. I've just release a 0.7.5 that fixes this. cheers, Chris " Josh English Confused Data Geek -- Adrian Klaver adrian.kla...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Open Source: you're doing it wrong - the Pyjamas hijack
Hi, I'm not big Python user but like to keep a eye on this mailing list as there are a few subjects that can be applied to other languages and just for general interest (Yes, I'm a geek!!! lol) This message thread has really shocked me: I've been a programmer for some thirty years and yes in the past I've had code/intellectual property stolen mainly by corporate bodies (well more like little upstart twats that cannot come up with ideas for themselves, acting in the name of a company.) I've never been able to do anything about it, proving that code and/or an idea has been stolen is not a simple thing to do... But surely in this case, as the project is so visibly the intellectual property of Luke that Risinger and his sheep are standing on the edge of a very large and loose cliff! > To: python-list@python.org > From: tjre...@udel.edu > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > Date: Tue, 8 May 2012 21:35:22 -0400 > > On 5/8/2012 5:47 PM, Terry Reedy wrote: > > > From what others have posted, it has a new code repository (that being > > the ostensible reason for the fork), project site, and mailing list -- > > the latter two incompetently. Apparently, the only thing he has kept are > > the domain and project names (the latter for sure not legitimately). > > Update: the pyjs.org group (or member thereof) has registered pyjs as a > new project name on pypi and released pyjames0.8.1 as pyjs0.8.1. So they > seem not to be claiming the name 'pyjames', at least not on pypi. > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Open Source: you're doing it wrong - the Pyjamas hijack
Hi ya, Not to be confrontative but just because a project is open-source, it doesn't mean IP is open too!! The original idea is still property of the originator... It just has the global community adding their own IP and fixes. This is a core of corporate contracts ensuring that a developers IP become freely usable by the company they work for at the time, but their IP is still their IP. In the UK at least, a developers IP cannot be hijacked by a company contract. If you write some code while working for X, then X has free usage of that IP and may restrict you from using the same IP for company Y, but only for a limited time (ie 5 years)… The IP you came up with is still yours and a contract that claims your IP can (and has been in a court of law) judged to be null and void. The problem is proving it!!! > From: jeanpierr...@gmail.com > Date: Wed, 9 May 2012 15:00:11 -0400 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > To: lamial...@cleverpun.com > CC: python-list@python.org > > On Wed, May 9, 2012 at 2:45 PM, Temia Eszteri wrote: > > And you know what? Leighton was right to threaten legal action. What > > you did was not only in violation of his IP, but also multiple data > > theft laws. > > As far as copyright goes, it was open source, so he's allowed to > continue making modifications. I don't think Luke had any patents. > > There might be something with stealing the name "PyJS" (which was, > AFAIK, used as a synonym for "PyJamas") -- apparently "common law > trademark" is a thing. Otherwise... > > The domain was apparently not directly owned by Luke (but pointed to a > server luke administered), and its transfer was apparently consensual. > > It seems like nearly every evil thing the hijacker did is legally > permissible. The one other thing was the way he created the new > mailing list might not have been legal, apparently. (See > http://mail.python.org/pipermail/python-list/2012-May/1291804.html ). > > -- Devin > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Open Source: you're doing it wrong - the Pyjamas hijack
Hi Ian, Well there you have me... You release code under a license, you bound by it even if later you think better of it... Seller be ware!! > From: ian.g.ke...@gmail.com > Date: Wed, 9 May 2012 16:59:00 -0600 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > To: cybor...@hotmail.com > > On Wed, May 9, 2012 at 4:30 PM, Adrian Hunt wrote: > > > > Hi ya, > > > > Not to be confrontative but just because a project is open-source, it > > doesn't mean IP is open too!! The original idea is still property of the > > originator... It just has the global community adding their own IP and > > fixes. This is a core of corporate contracts ensuring that a developers IP > > become freely usable by the company they work for at the time, but their IP > > is still their IP. > > Luke Leighton was not the originator of the project. James Tauber > was, and his original code was a port of Google Web Toolkit. Even if > Luke could somehow be considered the "owner" of the project, it was > released under the Apache License, which includes a "/perpetual/, > worldwide, non-exclusive, no-charge, royalty-free, /irrevocable/ > copyright license to reproduce, /prepare Derivative Works of/, > publicly display, publicly perform, sublicense, and distribute the > Work and such Derivative Works". I don't agree with what Anthony has > done, but I don't see how it violates the license in any way or how > Luke has any possible recourse through IP claims. -- http://mail.python.org/mailman/listinfo/python-list
RE: Open Source: you're doing it wrong - the Pyjamas hijack
Hi there Mark There has been a few that I know of but going back quite a long time... Soon after I got my qualifications, a small company called Merlio, not only did the court case get passed in UK courts by it went to the European court too... I wasn't directly involved but I know the EU court upheld the decision of the UK courts. Still there are was little to no enforcement of what they decided!!! Any how IP IS the IP of the developer... Proving it and enforcing it is another matter!! > To: python-list@python.org > From: breamore...@yahoo.co.uk > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > Date: Wed, 9 May 2012 23:44:01 +0100 > > On 09/05/2012 23:30, Adrian Hunt wrote: > > > > In the UK at least, a developers IP cannot be hijacked by a company > > contract. If you write some code while working for X, then X has free usage > > of that IP and may restrict you from using the same IP for company Y, but > > only for a limited time (ie 5 years)… The IP you came up with is still > > yours and a contract that claims your IP can (and has been in a court of > > law) judged to be null and void. > > > > References please, as this is completely opposite to my understanding. > > -- > Cheers. > > Mark Lawrence. > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Open Source: you're doing it wrong - the Pyjamas hijack
Hi ya, Please don't attack me or pull me into the centre of this conflict... I don't have any idea of what is really happening here; other than that I've read on the python-list mailing list. Your right, I have never released any code, under any license of any description. I have only offered snippets of code to people/projects to be used as they see fit (besides my professional developments and private projects.) All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor have ever had any prior contact with) about releasing code under a license... And, what I said stands: once anyone releases code, they are bound by the license they released it under as much as anyone else that may use it and cannot then withdraw that code from the domain they released it to (except by maybe creating a new and different version.) Being dyslexic, my message (and this one) may not be worded in the best way but that is no reason to start on me! Date: Wed, 9 May 2012 22:56:43 -0300 From: ricar...@gmail.com To: cybor...@hotmail.com Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack On 09/05/12 20:04, Adrian Hunt wrote: Hi Ian, Well there you have me... You release code under a license, you bound by it even if later you think better of it... Seller be ware!! Sorry, but you are not being accurate. "You" don't release code under a license, James Tauber did, or the Google Web Toolkit did. So you are in no positon to "think better of it" even if it was allowed to the original releaser. -- http://mail.python.org/mailman/listinfo/python-list
RE: Open Source: you're doing it wrong - the Pyjamas hijack
Hi there, Yes, it's very messy by what I understand and is why Merlio never had it's judgements enforced. Although, employment contracts that were in place at the time (including mine), were declared null and void... I think it was something like: if a programmer has an idea and uses it within an employers project then the employer has a legal claim to that implementation but not to the original idea. And, a contract that claims IP rights would stop a developer from ever working again as a programmer: this again, being illegal and making the contract null and void. With internationalization, the problem is compounded as different countries have different laws. Since my days at Merlio, I have managed to avoid singing any contract that claims IP and I have worked for some large international companies (from within the UK.) > Date: Thu, 10 May 2012 10:27:27 +1000 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > From: ros...@gmail.com > To: python-list@python.org > > On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence > wrote: > > Google was a right PITA but eventually I found this > > http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ > > It appears to contradict what you've said above, or have I misread it? E.g > > "Under the (Patents) Act (1977), there is a presumption that an employer > > will own the patent of an invention made by its employee if the invention > > was made in the employee’s normal or specifically assigned duties and > > either, an invention might reasonably be expected to result from such duties > > or, the employee has a special obligation to further the employee’s > > interests, arising from the nature of those duties and responsibilities and > > the employee’s status." > > That's patents... intellectual property goes by other rules I think. I > am not a lawyer, and I try to avoid getting placed in any position > where this sort of thing will come up, because it's messy... > especially with internationalization. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Open Source: you're doing it wrong - the Pyjamas hijack
lol, Cheers Chris. Just so you know, I care about what and how I write... I almost always run my emails though a word-processor before sending. And, that has paid off for me: thanks to MS Word, MS Works and Open Office, I have better understanding of "correct" punctuation use (if not spelling and grammar) than most school leavers!!! PS. It hasn't gone a miss that you are one of the core python-list responders (and I bet this goes for most of the python-list users): your responses, time and knowledge is appreciated... Thank you. > Date: Fri, 11 May 2012 09:57:49 +1000 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > From: ros...@gmail.com > To: python-list@python.org > > On Fri, May 11, 2012 at 9:36 AM, Adrian Hunt wrote: > > All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor > > have ever had any prior contact with) about releasing code under a > > license... And, what I said stands: once anyone releases code, they are > > bound by the license they released it under as much as anyone else that may > > use it and cannot then withdraw that code from the domain they released it > > to (except by maybe creating a new and different version.) > > And that's absolutely correct. Open source licenses are deliberately > worded to guarantee rights in perpetuity, so there's no way to > withdraw it or change the license (though of course a copyright owner > can release the same code under an additional license). > > > Being dyslexic, my message (and this one) may not be worded in the best way > > but that is no reason to start on me! > > Your message is fine. Believe you me, I'd much rather read a message > posted by a non-native English speaker, or a dyslexic person, or > someone who has a clinical aversion to the letter 'q', than someone > who's simply sloppy and doesn't care about their language at all. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Creating a Windows installer for Python + a set of dependencies
Hi there, I've use NSIS for quite a few projects... NSIS will do it with ease. You write a script that gets "compiled" into a install exe and the scripting language is not too hard to learn. You can do it in several different ways: 1. You can include the Python installer as a file compressed into your installer (that is decompressed to a temp directory before being run.) 2. The Python installer could be a included along side you installer and run as needed 3. You can specify a URL to the Python install to be downloaded and installed (again using a temp directory.) You can even use a mix... If an internet connection is available download it, if not fall back to one of the other methods. If you can come up with yet another method, it wouldn't be simple to write a script to handle it. If you really need to you can write a dynamic link library that the final NSIS installer will make calls to. If you need any more help on this subject, email me directly... Although I try to keep an eye on python-list, I can't guarantee a quick reply. > Date: Thu, 10 May 2012 16:26:25 +0200 > Subject: Creating a Windows installer for Python + a set of dependencies > From: g.rod...@gmail.com > To: python-list@python.org > > Hi all, > I need to create an installer for Windows which should be able to > install a specific version of the Python interpreter (2.7) plus a set > a dependencies such as ipython, numpy, pandas, etc. > Basically this is the same thing Active State did for their Active > Python distribution: a single bundle including interpreter + deps. > Not being a Windows user I'm not sure where to start with this except > maybe looking into NSIS (could that be of any help?). > > Thanks in advance, > > --- Giampaolo > http://code.google.com/p/pyftpdlib/ > http://code.google.com/p/psutil/ > http://code.google.com/p/pysendfile/ > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
logging and PyQt4
I have a multi-threaded PyQt4 application which has both a GUI and command- line interface. I am using Qt4's threading because from what I have read, it is more efficient than the native python threading module. Also, given most users will probably use the GUI, it seemed to make sense. I want a flexible, threadsafe logging facility for my application so I was thinking of using python's logging module. I need a logger that can log to the GUI or a terminal depending on how the application is invoked. So, my question is -: Is it wise to use python's logging module in conjunction with Qt4 threads? If not, what are my options apart from writing my own logging module? If it is OK, then I would like to know how to subclass the logging class so that instead of sending output to stdout (as in StreamHandler), it emits Qt4 signals instead. Any help would be appreciated. Thank you. Adrian Casey. -- http://mail.python.org/mailman/listinfo/python-list
QCoreApplication will not quit
Can someone please explain why this simple PyQt4 application never exits? #!/usr/bin/env python from PyQt4 import QtCore import sys class foo(QtCore.QObject): def __init__(self, parent): QtCore.QObject.__init__(self, parent) self.parent = parent self.end_job() def end_job(self): QtCore.QCoreApplication.quit() if __name__ == '__main__': app = QtCore.QCoreApplication(sys.argv) myFoo = foo(parent=None) sys.exit(app.exec_()) This is just a very simple, cut-down example to demonstrate a problem I have with an application I am writing. If I call QCoreApplication.hasPendingEvents(), the result is always True. Even if I call QCoreApplication.processEvents(), the application still does not quit. It just hangs forever. I'd appreciate some help in finding out how to make it quit. Thanks. Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: QCoreApplication will not quit
Dennis Lee Bieber wrote: > On Sat, 02 Apr 2011 14:12:38 +0930, Adrian Casey > declaimed the following in gmane.comp.python.general: > >> Can someone please explain why this simple PyQt4 application never exits? >> >> #!/usr/bin/env python >> from PyQt4 import QtCore >> import sys >> class foo(QtCore.QObject): >> def __init__(self, parent): >> QtCore.QObject.__init__(self, parent) >> self.parent = parent >> self.end_job() >> >> def end_job(self): >> QtCore.QCoreApplication.quit() >> >> if __name__ == '__main__': >> app = QtCore.QCoreApplication(sys.argv) >> myFoo = foo(parent=None) >> sys.exit(app.exec_()) >> > Uhm... Could it be because you've shut down the application before > ever starting it? > > Note that your __init__() method -- invoked when you create "myFoo", > ENDS with a call to end_job() which invokes the framework quit() method. > > THEN after all this framework shut down, you invoke the app.exec_() > on a framework that has nothing left to run? Thanks Dennis. I should have seen that! Cheers. Adrian. -- http://mail.python.org/mailman/listinfo/python-list
pexpect: TIMEOUT no longer clears child.before
The behaviour of pexpect has changed between version 2.1 and 2.3. In version 2.1, the following code would result in child.before being cleared -: >>>child.expect(pexpect.TIMEOUT,1) In version 2.3, this is no longer the case. No matter how many times the above code is run, child.before continues to hold the output from previous commands. It is important to be able to clear the contents of child.before between each command. What is the correct way to do this in version 2.3? Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML templating tools
On Thu, 20 Oct 2016 11:34:36 +0200, Tony van der Hoff wrote: > Can anyone recommend a suitable replacement (preferably > compatible with htmltmpl)? I don't think anything is going to be compatible with htmltmpl, but Jinja2 is a very widely-used, well-supported and easy-to-learn templating engine for Python: http://jinja.pocoo.org/docs/dev/ There's nothing specific to HTML about it, but that is its most common use case. -- https://mail.python.org/mailman/listinfo/python-list
Missing python36.dll
Hi - just downloaded the latest version of Python (3.6.4) but keep getting an error because of missing .dll file. i tried uninstalling and reinstalling it but still getting the same error. Search online for the file but to no avail. Can someone direct me as to where to download the missing dll file or help me with the issue. thanks, Adrian -- https://mail.python.org/mailman/listinfo/python-list
Using Python with a website
G'day All, I have just discovered Python and thanks to a script by Ethan I can read a foxpro database and change the required values. However my next big step is to be able to use this python feature within a website. Basically I want to be able to click on a button and call the script. This would in turn display some information on the webpage but do what it needs to do on the server. I have setup Apache and it all works on the server, my stumbling block is calling it from a website. I am using Server 2012 R2 Python 3.7 Apache 2.4 I can run the Python scripts from the command line prompt. Can anyone help? Regards, Adrian Taylor InfoHub - ICT - Helpdesk A : 5 Faith Avenue, Plainland , QLD 4341 T : 07 5466 9900 E : atay...@faithlc.qld.edu.au<mailto:atay...@faithlc.qld.edu.au> W : www.faithlc.qld.edu.au<http://www.faithlc.qld.edu.au/> [cid:image005.png@01D2CD7E.0F6F4710] The information contained in this e-mail message and any attached files may be confidential information, and may also be the subject of legal professional privilege. If you are not the intended recipient any use, disclosure or copying of this e-mail is unauthorised. If you have received this e-mail in error, please notify the sender immediately by reply e-mail and delete all copies of this transmission together with any attachments. -- https://mail.python.org/mailman/listinfo/python-list
Re: Exercize to understand from three numbers which is more high
i'm also a beginner reading all the replies helps. i was trying the problem myself and came up with the below code with a users input. num1 = int(input("Enter first number: "))num2 = int(input("Enter second number: "))num3 = int(input("Enter third number: "))if num1 > num2 and num1 > num3: print(num1, " is th max number")elif num2 > num1 and num2 > num3: print(num2, " is the max number")else: print(num3, "is the max number") On Tue, Jan 29, 2019 at 1:48 PM Schachner, Joseph < joseph.schach...@teledyne.com> wrote: > Explanation: 5 > 4 so it goes into the first if. 5 is not greater than 6, > so it does not assign N1 to MaxNum. The elif (because of the lack of > indent) applies to the first if, so nothing further is executed. Nothing > has been assigned to MaxNum, so that variable does not exist. You're > right, it does not work. > > How about this: > Mylist = [ N1, N2, N3] > Maxnum = N1 > for value in Mylist: > if value > Maxnum: > Maxnum = value > print(Maxnum) > > Or were lists and for loops excluded from this exercise? > --- Joe S. > > On 1/29/19 9:27 AM, Jack Dangler wrote: > > > wow. Seems like a lot going on. You have 3 ints and need to determine > > the max? Doesn't this work? > > > > N1, N2, N3 > > > > if N1>N2 > >if N1>N3 > > MaxNum = N1 > > elif N2>N3 > >MaxNum = N2 > > elif N1 >MaxNum = N3 > > No. Assuing that you meant to include colons where I think you did, what > if (N1, N2, N3) == (5, 4, 6)? > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Exercize to understand from three numbers which is more high
The code actually works just the way i copy and pasted Sent from my iPhone > On Jan 29, 2019, at 12:34, Ian Clark wrote: > > just the pure number of letters next to parenthesis would cause the Parser to > error out > >> On Tue, Jan 29, 2019 at 12:32 PM Schachner, Joseph >> wrote: >> Yes, that works. Assuming it was correctly formatted when you ran it. >> The formatting could not possibly be run in a Python interpreter, I think. >> >> --- Joseph S. >> >> From: Adrian Ordona >> Sent: Tuesday, January 29, 2019 2:52 PM >> To: Schachner, Joseph >> Cc: Dan Sommers <2qdxy4rzwzuui...@potatochowder.com>; python-list@python.org >> Subject: Re: Exercize to understand from three numbers which is more high >> >> i'm also a beginner reading all the replies helps. >> i was trying the problem myself and came up with the below code with a users >> input. >> >> >> num1 = int(input("Enter first number: "))num2 = int(input("Enter second >> number: "))num3 = int(input("Enter third number: "))if num1 > num2 and num1 >> > num3:print(num1, " is th max number")elif num2 > num1 and num2 > num3: >>print(num2, " is the max number")else: print(num3, "is the max >> number") >> >> On Tue, Jan 29, 2019 at 1:48 PM Schachner, Joseph >> mailto:joseph.schach...@teledyne.com>> wrote: >> Explanation: 5 > 4 so it goes into the first if. 5 is not greater than 6, >> so it does not assign N1 to MaxNum. The elif (because of the lack of >> indent) applies to the first if, so nothing further is executed. Nothing has >> been assigned to MaxNum, so that variable does not exist. You're right, it >> does not work. >> >> How about this: >> Mylist = [ N1, N2, N3] >> Maxnum = N1 >> for value in Mylist: >> if value > Maxnum: >> Maxnum = value >> print(Maxnum) >> >> Or were lists and for loops excluded from this exercise? >> --- Joe S. >> >> On 1/29/19 9:27 AM, Jack Dangler wrote: >> >> > wow. Seems like a lot going on. You have 3 ints and need to determine >> > the max? Doesn't this work? >> > >> > N1, N2, N3 >> > >> > if N1>N2 >> >if N1>N3 >> > MaxNum = N1 >> > elif N2>N3 >> >MaxNum = N2 >> > elif N1> >MaxNum = N3 >> >> No. Assuing that you meant to include colons where I think you did, what if >> (N1, N2, N3) == (5, 4, 6)? >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> -- >> https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
WebScrapping
Hi, I’m learning how to code and interested in web scrapping to gather data. I’m running on Mac OS X 10.9.5 and python 3.7 terminal. I’m trying to capture the name of the brand and price but i keep getting an error (see below). Traceback (most recent call last): File "", line 1, in File "/anaconda3/lib/python3.7/site-packages/bs4/element.py", line 1884, in __getattr__ "ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()? Here’s what i got and thanks for the help import bs4 from urllib.request import urlopen as uReq from bs4 import BeautifulSoup as soup my_url = 'https://www.newegg.com/Desktop-Graphics-Cards/SubCategory/ID-48?Tid=7709' uClient = uReq(my_url) page_html = uClient.read() uClient.close() page_soup = soup(page_html, "html.parser") records = [] containers = page_soup.findAll("div",{"class":"item-container"}) for container in containers: brand = container.find('div', attrs={'class':'item-branding'}) price = container.find('div', attrs={'class':'item-action'}) records.append((brand, price)) -- https://mail.python.org/mailman/listinfo/python-list
Re: WebScrapping
Thanks Piet for the quick response. Yes, i was running it line by line. When i ran >>> len(containers), the output is giving me 37 but when i ran the code as a py file, it was only showing one result. Thanks in advance. Adrian On Feb 19, 2019, at 4:38 AM, Piet van Oostrum wrote: > Adrian Ordona writes: > >> Hi, >> >> I’m learning how to code and interested in web scrapping to gather data. >> I’m running on Mac OS X 10.9.5 and python 3.7 terminal. >> I’m trying to capture the name of the brand and price but i keep getting an >> error (see below). >> Traceback (most recent call last): >> File "", line 1, in >> File "/anaconda3/lib/python3.7/site-packages/bs4/element.py", line 1884, in >> __getattr__ >>"ResultSet object has no attribute '%s'. You're probably treating a list >> of items like a single item. Did you call find_all() when you meant to call >> find()?" % key >> AttributeError: ResultSet object has no attribute 'find'. You're probably >> treating a list of items like a single item. Did you call find_all() when >> you meant to call find()? >> >> >> Here’s what i got and thanks for the help >> >> import bs4 >> from urllib.request import urlopen as uReq >> from bs4 import BeautifulSoup as soup >> >> my_url = >> 'https://www.newegg.com/Desktop-Graphics-Cards/SubCategory/ID-48?Tid=7709' >> >> uClient = uReq(my_url) >> page_html = uClient.read() >> uClient.close() >> page_soup = soup(page_html, "html.parser") >> records = [] >> >> containers = page_soup.findAll("div",{"class":"item-container"}) >> >> for container in containers: >> brand = container.find('div', attrs={'class':'item-branding'}) >> price = container.find('div', attrs={'class':'item-action'}) >> records.append((brand, price)) >> > When I put this in a python file, and run it under python3.7, it works. > It seems you were running this line by line interactively, tight? > > Could it be that you accidentally entered > brand = containers.find('div', attrs={'class':'item-branding'}) > i.e containers rather than container, because that would generate the error > that you copied. > -- > Piet van Oostrum > WWW: http://piet.vanoostrum.org/ > PGP key: [8DAE142BE17999C4] > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
ANN: Internationalization in Django
Thanks to great contributions from the community, Django now has full internationalization support. (Django is a full-stack Python Web framework that encourages rapid development and clean, pragmatic design. See http://www.djangoproject.com/ .) Django now has: * Full support for specifying translation strings -- both in Python code and in Django templates. * Full support for detecting users' language preferences and using the appropriate translation. * Support for 12 languages in validation messages, core Django models and the automatically created Django admin site. This update is fully backwards-compatible. We're grateful that translators have submitted translations for the following languages: * cs (Czech) * de (German) * en (English) * es (Spanish) * fr (French) * gl (Galician) * it (Italian) * no (Norwegian) * pt-br (Brazilian) * ru (Russian) * sr (Serbian) * zh-cn (Simplified Chinese) * sk (Slovak) See the full documentation here: http://www.djangoproject.com/documentation/i18n/ Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org -- http://mail.python.org/mailman/listinfo/python-list
ANN: Django 0.90
After a months-long "pre-release" period, we're pleased to announce the first release of Django, the Web framework for perfectionists (with deadlines). Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. It lets you write high-quality Web apps very quickly, with very little code. It gives you: * An object-relational mapper, which currently works with PostgreSQL, MySQL and SQLite. (Oracle and MS-SQL support are coming.) This lets you query databases in Python; there's no need to write SQL if you don't want to. * A template system. * A beautiful, production-ready admin interface -- for free. * Full internationalization (i18n) support. * A super-cool community! * An RSS/Atom-producing framework. * Tons of other niceties, such as generic views (which abstract common Web-development patterns), based on several years' worth of solving Real Problems in the Real World. Django has been used on production sites -- lawrence.com, ljworld.com, 6newslawrence.com, kusports.com, visitlawrence.com -- since late 2003. It also powers chicagocrime.org and a host of other sites all over the world. See http://code.djangoproject.com/wiki/DjangoPoweredSites . This release is version 0.90. Our goal is to wrap up remaining changes for 1.0 in the coming weeks/month, and release 1.0 with a guarantee of backwards compatibility. There's not yet a guarantee of backwards compatibility between releases. http://www.djangoproject.com/ http://www.djangoproject.com/download/ Enjoy! Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org -- http://mail.python.org/mailman/listinfo/python-list
ANN: Django 0.90
After a months-long "pre-release" period, we're pleased to announce the first release of Django, the Web framework for perfectionists (with deadlines). Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. It lets you write high-quality Web apps very quickly, with very little code. It gives you: * An object-relational mapper, which currently works with PostgreSQL, MySQL and SQLite. (Oracle and MS-SQL support are coming.) This lets you query databases in Python; there's no need to write SQL if you don't want to. * A template system. * A beautiful, production-ready admin interface -- for free. * Full internationalization (i18n) support. * A super-cool community! * An RSS/Atom-producing framework. * Tons of other niceties, such as generic views (which abstract common Web-development patterns), based on several years' worth of solving Real Problems in the Real World. Django has been used on production sites -- lawrence.com, ljworld.com, 6newslawrence.com, kusports.com, visitlawrence.com -- since late 2003. It also powers chicagocrime.org and a host of other sites all over the world. See http://code.djangoproject.com/wiki/DjangoPoweredSites . This release is version 0.90. Our goal is to wrap up remaining changes for 1.0 in the coming weeks/month, and release 1.0 with a guarantee of backwards compatibility. There's not yet a guarantee of backwards compatibility between releases. http://www.djangoproject.com/ http://www.djangoproject.com/download/ Enjoy! Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Ruby on Rails Job Site -- Is there a Python equivalent?
Ray wrote: > I just found a job listing site for Ruby on Rails. > > http://jobs.rubynow.com/ > > I wonder if there's an equivalent one for Django? Here ya go: http://code.djangoproject.com/wiki/DevelopersForHire See the "Django-powered jobs" section. We could definitely advertise this page more, as it's a bit hidden at the moment on the Django wiki. There are three Django jobs on that page now, and I know of at least two others. See http://www.djangoproject.com/weblog/2005/nov/27/weekinreview/ . Hope this helps! Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org -- http://mail.python.org/mailman/listinfo/python-list
Command line and GUI tools : need a single threading solution
I have a collection of multi-threaded command line tools which I want wrap a PyQt gui around. I'm using queues to route messages from the command line tools to the PyQt gui. The command line tools use python threads to do their work. The gui uses a QThread object to read incoming messages. This does not work consistently - and I've since read that mixing python threads and QThreads is a bad idea. The command line tools work well using python threads. I don't want to maintain two copies of the tools - one for command line and another for the PyQt version. I'm thinking it may be possible to modify the command line tools to use qt threads instead of native python threads. Is this the way to go? Are there other options? Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: Command line and GUI tools : need a single threading solution
Diez B. Roggisch wrote: >> I'm thinking it may be possible to modify the command line tools to use >> qt >> threads instead of native python threads. Is this the way to go? Are >> there other options? > > Why don't you use python threads in qt - I do so and so far it didn't make > any troubles for me. And I would strongly advise against using qthreads > with your commandline-tools, as these then would only run on machines > where pyqt is installed - which opens a small part of "dependency hell" > for your users. > I have a QThread which polls a queue object via queue.get(). The command line tools spawn a number of threads each of which writes its output to this queue using queue.put(). As soon as the gui gets something off the queue, it creates a QCustomEvent and sets the data property with the data read from the queue. My application has a customEvent() method which reads the data item from the customEvent and processes it accordingly. The odd thing is, I have a non-threaded version of the command line tools which work 100% with the gui. The multi-threaded version of the command line tools all work OK at the console - just not with the gui. I will try your suggestion and replace my QCustomEvent mechanism with a plain python queue. -- http://mail.python.org/mailman/listinfo/python-list
Re: Command line and GUI tools : need a single threading solution
Phil Thompson wrote: >> I have a collection of multi-threaded command line tools which I want >> wrap a >> PyQt gui around. I'm using queues to route messages from the command >> line tools to the PyQt gui. The command line tools use python threads to >> do >> their work. The gui uses a QThread object to read incoming messages. >> >> This does not work consistently - and I've since read that mixing python >> threads and QThreads is a bad idea. The command line tools work well >> using >> python threads. > > How well mixing the two threading APIs works depends on version numbers. A > PyQt generated with SIP v4.x (rather than SIP v3.x) with Python v2.4 > should be Ok. > >> I don't want to maintain two copies of the tools - one for command line >> and >> another for the PyQt version. >> >> I'm thinking it may be possible to modify the command line tools to use >> qt >> threads instead of native python threads. Is this the way to go? Are >> there other options? > > Using QThreads only should work - just tell the QApplication ctor that you > have a console application. > > Phil Phil, I'm running python 2.4, sip-4.0 and PyQt-x11-gpl-3.11 (or .13 - not sure as I'm not at work). A little more detail. My script, if invoked from the command line, creates a queue object (let's call it logQueue) which is used to take the output from each individual thread. If invoked via the gui, the script is passed a logQueue created by the gui. Each thread dumps its output using logQueue.put(). There are other queues which are used to service threaded access to a database etc. The scripts use the pexpect module to login to remote systems and do sysadmin tasks (e.g. reset passwords). This works like a charm in console mode. The gui uses a QThread to poll logQueue (logQueue.get()). When it gets something, it creates a QCustomEvent and sets the data portion using the data read from the logQueue. I have a customEvent method in my application which grabs the data from the customEvent and processes it accrodingly (writing output to a QTable). The gui locks up after an arbitrary number of rows have been inserted in the QTable. It is not consistent. Sometimes it does not lock at all. I have a non-threaded set of the command line tools which run perfectly with the gui. Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: Command line and GUI tools : need a single threading solution
Adrian Casey wrote: > Diez B. Roggisch wrote: > >>> I'm thinking it may be possible to modify the command line tools to use >>> qt >>> threads instead of native python threads. Is this the way to go? Are >>> there other options? >> >> Why don't you use python threads in qt - I do so and so far it didn't >> make any troubles for me. And I would strongly advise against using >> qthreads with your commandline-tools, as these then would only run on >> machines where pyqt is installed - which opens a small part of >> "dependency hell" for your users. >> > I have a QThread which polls a queue object via queue.get(). The command > line tools spawn a number of threads each of which writes its output to > this queue using queue.put(). As soon as the gui gets something off the > queue, it creates a QCustomEvent and sets the data property with the data > read from the queue. My application has a customEvent() method which > reads the data item from the customEvent and processes it accordingly. > > The odd thing is, I have a non-threaded version of the command line tools > which work 100% with the gui. The multi-threaded version of the command > line tools all work OK at the console - just not with the gui. > > I will try your suggestion and replace my QCustomEvent mechanism with a > plain python queue. I tried replacing the QThread part with native python threads and, although it worked for a few minutes, I started to see XWindow errors and my application would then crash. On Phil Thompson's advice, I updated PyQt and sip. The problem appears to be fixed. Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: short programming projects for kids
André Roberge wrote: > bobdc wrote: >> I will be teaching an "Introduction to Programming" class to some >> middle school aged children and will be using Python, obviously. Does >> anyone have suggestions for simple little programs to create and >> analyze with them after I get past turtle graphics? >> >> Turtle graphics will be plenty for the first session, and I will leave >> time to ask them what they'd like to do in later sessions, but I was >> curious if anyone on the list has experience picking pedagogical >> programming examples appropriate for twelve-year-olds' attention spans. >> thanks, >> >> Bob >> > While it is not python per se, I suggest you have a look at GvR > (Guido van Robot) (The app is written in Python but is too complicated > for beginners). It is hosted on sourceforge (gvr.sourceforge.net). > It is a very interesting way (imho) to learn about programming, in > a pythonic way. > > (somewhat shameless plug follows:) > A 'more advanced version' of GvR which uses the full Python syntax > is RUR-PLE (rur-ple.sourceforge.net). The version currently hosted > there does NOT work under Linux (untested on Mac). > It uses wxPython 2.4 and will not work with 2.5. > An updated release that will work under both Linux and Windows, > and under both wxPython 2.4 and 2.5 will come out very soon, I hope. > > I'm working on it :-) I have two kids (ages 11 and 13) and plan to use > rur-ple to teach them about programming. Note that, even though > I plan it to be suitable for motivated children (with some guidance), > the end product (to be finished in a year?) is planned to be suitable > for a complete first-year university computer science. > > Andre Roberge I started teaching my 11 year old first of all by doing silly stuff like -: for i in range(10): print "Silly me!" Moving on to more useful stuff like times tables (which they have to learn anyway). After times tables, I plan to work on a simple number guessing game where the computer picks a random number between 1 and 100 and asks the user to take a guess. This will help demonstrate many basic programming concepts. Not sure how to introduce graphics though as so much is relatively abstract. Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: python certification
[EMAIL PROTECTED] wrote: > i want to get a small certificate or diploma in python. I can recommend brainbench.com (http://www.brainbench.com, of course) for certifications that are both respected and reasonably priced. Only drawback: their Python certification is for version 1.5! They have got to update that. Lloyd Flanagan (Brainbench Master Certified in Python) -- http://mail.python.org/mailman/listinfo/python-list
How to start a DTS Package on MS-SQL-Server?
I found this subject line in a post to this list on Jan 30, 2004. Does anybody know if this is possible? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
Aahz wrote: > In article <[EMAIL PROTECTED]>, > Frans Englich <[EMAIL PROTECTED]> wrote: >> >>Personally I need a solution which touches this discussion. I need to run >>multiple processes, which I communicate with via stdin/out, >>simultaneously, and my plan was to do this with threads. Any favorite >>document pointers, common traps, or something else which could be good to >>know? > > Threads and forks tend to be problematic. This is one case I'd recommend > against threads. Multiple threads interacting with stdin/stdout? I've done it with 2 queues. One for feeding the threads input and one for them to use for output. In fact, using queues takes care of the serialization problems generally associated with many threads trying to access a single resource (e.g. stdout). Python Queues are thread-safe so you don't have to worry about such issues. -- http://mail.python.org/mailman/listinfo/python-list
Python 2.4 & PostgreSQL 8 segfault
hello, i have compiled and installed postgres8 --with-prefix=/usr/local/postgres8 (& several other options) and have no other version of postgres on my system. python is compiled and make'd --with-prefix=/usr. i have added the libpath of postgres to /etc/ld.so.conf and a ldconfig -v also told me that the libraries are found. i tried to install PyGreSQL, pyPgSQL and psycoPG. after i found out how to tell all those make systems where my libraries and includes are i got it installed. but no matter which module i try to use ... it segfaults. even if i try to view the documentation via pydoc -p in my browser, as soon as i click on such a module the pydoc server shuts down with segfault. what is wrong ? do i have to compile those modules against a postgres7 and then connect to a postgres8? any ideas ? thanks -- http://mail.python.org/mailman/listinfo/python-list
ANN: Greasemonkey compiler
Greasemonkey (http://greasemonkey.mozdev.org/) is a Mozilla Firefox extension that allows you to write scripts, in JavaScript, that alter specific Web pages. I've written a "compiler" for these scripts. It's a Python module that takes a user script as input and creates a full-fledged Firefox extension. This is useful if you're a script developer and want to distribute your work to people without having to ask them to install Greasemonkey. It can also be a helpful starting point if you want to write a more advanced Firefox extension. Python code (GPL): http://www.letitblog.com/code/python/greasemonkey.py.txt Web interface: http://www.letitblog.com/greasemonkey-compiler/ Feel free to e-mail comments, bug fixes, etc. Adrian Holovaty [EMAIL PROTECTED] http://www.holovaty.com/ -- http://mail.python.org/mailman/listinfo/python-list
platform issues?
I'm new to python and I'm trying to get a twitter client running on a new machine but it keeps on failing. I tracked the problem down to an issue opening URLs and wrote this little test case: import urllib2 url = 'http://www.google.com/' opener = urllib2.build_opener() url_data = opener.open(url).read url_data When I run that on a dev machine it works fine, but when it's on one of our servers it crashes: >>> import urllib2 >>> url = 'http://www.google.com/' >>> opener = urllib2.build_opener() >>> url_data = opener.open(url).read Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/urllib2.py", line 391, in open response = self._open(req, data) File "/usr/lib/python2.7/urllib2.py", line 409, in _open '_open', req) File "/usr/lib/python2.7/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 1173, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/lib/python2.7/urllib2.py", line 1148, in do_open raise URLError(err) urllib2.URLError: Our servers have the same version of python and we're running the same OS (Fedora 14). Can anyone think of what might be causing this problem, or why it works on most (but not all) machines? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: platform issues?
to run the tests, I sit at my dev machine and SSH to the server where I can copy & paste the test case directly into the python interpreter. If there's a typo, it's going to both of them equally. I am concerned about the name lookup since our servers have had some network glitches in the past and I'm not confident in our DNS. We can browse the net on the server without a problem but to be sure, I tried this: On the server: >>> socket.gethostbyaddr(socket.gethostbyname('www.google.com')) ('yyz06s07-in-f20.1e100.net', [], ['74.125.226.84']) >>> socket.gethostbyaddr(socket.gethostbyname('www.twitter.com')) ('www2.twitter.com', [], ['199.59.149.198']) On the dev environment: >>> socket.gethostbyaddr(socket.gethostbyname('www.google.com')) ('sea09s02-in-f16.1e100.net', [], ['173.194.33.48']) >>> socket.gethostbyaddr(socket.gethostbyname('www.twitter.com')) ('www4.twitter.com', [], ['199.59.149.230']) Since I'm actually trying to write a twitter client, I was more focused on the results from twitter. Since google and twitter are so huge and so distributed, I'd bet neither are good tests for this, but they look approximately right. Are there better ways to test if our network setup is good? At least that would be a relatively easy thing to fix. Adrian. -Original Message- From: "Redcat" [red...@catfolks.net] Date: 12/01/2011 01:05 PM To: python-list@python.org Subject: Re: platform issues? > Our servers have the same version of python and we're running the same > OS (Fedora 14). Can anyone think of what might be causing this problem, > or why it works on most (but not all) machines? > > Thanks Is the server able to resolve www.google.com properly? If so, are you POSITIVE that the "url = " line on the server has no typos? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: platform issues?
The curl & dig ideas were great, thanks. Turns out the machine's network was badly configured and that's probably what was causing this problem. Curiously firefox could browse these sites without any problem despite not having any proxy defined and it took the command line to reveal the issue. Thank you for your help, this had been bugging us for days! Adrian. -Original Message- From: "Redcat" [red...@catfolks.net] Date: 12/01/2011 02:05 PM To: python-list@python.org Subject: Re: platform issues? On Thu, 01 Dec 2011 13:43:38 -0500, Adrian Powell wrote: > Since I'm actually trying to write a twitter client, I was more focused > on the results from twitter. Since google and twitter are so huge and so > distributed, I'd bet neither are good tests for this, but they look > approximately right. > > Are there better ways to test if our network setup is good? At least > that would be a relatively easy thing to fix. I think I'd first try "dig www.google.com" to be sure that it is resolving, then I believe I'd try to fetch the URL from your code sample using cUrl. If both of those work then I'm not sure what I'd look at next. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: RoR like (was : SPE 0.8.1.b Python IDE...)
bruno at modulix wrote: > RoR is not an IDE, it's a web framework. The closest things in Python > are TurboGears (good Ajax/js support via Mochikit), Subway (never > tested), and Django (no Ajax support AFAIK). Note that "no Ajax support" is misleading. Of course you can use Ajax with Django, just as you can use it with *any* Web framework. That's because Ajax is a browser-side technology (JavaScript), not a server-side technology (Python). Django is just as capable of producing JavaScript as it is of producing (X)HTML or whatever else. Hope that clears things up! Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org -- http://mail.python.org/mailman/listinfo/python-list
Re: RoR like (was : SPE 0.8.1.b Python IDE...)
bruno at modulix wrote: > Adrian, what you describe here is *exactly* what I call "no Ajax > support": you have to handle the whole thing manually, the framework > doesn't provide anything by itself. Would you say the CGI module offers > support for templating, data persistance and Ajax as well ?-) Hey Bruno, Sorry for the misunderstanding. Here's the Django code I use on the Ajax bit of the chicagocrime.org "Find your District" page (http://www.chicagocrime.org/districts/). See the "Guess district" button on that page. """ def rpc_guess_district(request, longitude, latitude): try: b = beats.guess_by_coordinates(float(longitude), float(latitude)) except beats.BeatDoesNotExist: return HttpResponse("Looks like you're not centered on a point in Chicago. " + \ "Please move the map to Chicago and try again.") return HttpResponse("You're centered on %s" % b.get_name_and_district()) """ My point is, you don't need a huge serialization framework to do Ajax easily. As long as a server can return snippets of code (or even plain text), you can do it. These pages work the same way: http://www.chicagocrime.org/map/ http://www.chicagocrime.org/wards/ http://www.chicagocrime.org/route/ Hope that clears up my point of view, Adrian -- http://mail.python.org/mailman/listinfo/python-list
ANN: Django 0.91 released
We're pleased to announce Django 0.91, the result of a month and a half of feature additions, bug fixes, usability changes and other improvements to the Django Web framework. http://www.djangoproject.com/ There are literally hundreds of improvements since version 0.90 -- but some of the most notable are: * Merged the "new-admin" branch, which heavily refactored the way the admin works, to make it more extensible. * Changed passwords to be stored with a salt, and with a tighter (and swappable) encryption algorithm. http://www.djangoproject.com/weblog/2005/nov/20/passwordchange/ * URLconfs no longer require named groups; you can use simple parentheses. http://www.djangoproject.com/weblog/2005/nov/28/urls/ * Changed the default project layout to add a manage.py utility, which avoids frustration with DJANGO_SETTINGS_MODULE. * Added a gorgeous template-debugging error page in the case of template syntax errors. http://www.djangoproject.com/weblog/2005/nov/23/template_errors/ * Added an {% include %} template tag. http://www.djangoproject.com/documentation/templates/#include * Added a framework for template context processors. http://www.djangoproject.com/documentation/templates_python/#subclassing-context-djangocontext * Improved the e-mail library to prevent header injections. http://www.djangoproject.com/documentation/email/#preventing-header-injection * Added OR lookups to the database API. http://www.djangoproject.com/weblog/2005/nov/30/or/ * Made the template system scoped to the parser instead of the template module. Also changed the way tags/filters are registered and added support for multiple arguments to the {% load %} tag. In addition to the many, many changes, we've reworked the tutorial to simplify things -- namely using the new manage.py utility instead of futzing with the Python path and environment variables. http://www.djangoproject.com/documentation/tutorial1/ Many thanks to all the great people who've contributed to this project. You can check them out in the AUTHORS file: http://code.djangoproject.com/browser/django/trunk/AUTHORS About Django Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. It lets you write high-quality Web apps very quickly, with very little code. It gives you: * An object-relational mapper, which currently works with PostgreSQL, MySQL and SQLite. (Oracle and MS-SQL support are coming.) This lets you query databases in Python; there's no need to write SQL if you don't want to. * A template system. * A beautiful, production-ready admin interface -- for free. * Full internationalization (i18n) support. * A super-cool community! * An RSS/Atom-producing framework. * Tons of other niceties, such as generic views (which abstract common Web-development patterns), based on several years' worth of solving Real Problems in the Real World. Enjoy! The Django team -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me in this please--is Python the answer?
Ray wrote: > Yes, but this is more of a web application though--something that I've > never developed in Python before, so... I'll be evaluating Django > shortly--let me see how it compares to Tomcat. Performance is one of the key features of Django. For example, I'm using Django at washingtonpost.com for the U.S. Congress Votes Database, which has more than 4 million records and is linked-to from the washingtonpost.com home page whenever there's a key congressional vote. (http://projects.washingtonpost.com/congress/) The server doesn't break a sweat, thanks to Django's very-convenient-and-powerful cache system: http://www.djangoproject.com/documentation/cache/ Also, the developers at grono.net, a Polish social networking site with more than half a million users, have converted various bits of their Java code to Python/Django. They've found that Django is not only much quicker (and more fun) to develop in, it's also *faster* than Java and requires less hardware. E-mail me personally if you want their contact information for direct testimonials; we'll be publishing some more testimonials publically as we get closer to Django 1.0. I would never use TurboGears or Ruby on Rails over Django for any performance-intensive Web app. In my opinion, both frameworks make some poor design decisions regarding the importance of performance. Adrian -- Adrian Holovaty holovaty.com | chicagocrime.org | djangoproject.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me in this please--is Python the answer?
Ray wrote: > Does the comparison between dynamic and static language carry over to > comparison between Django and Turbogear too? Is this what is meant by > "Turbogear is much more flexible than Django"? Nah, the difference is more than Django is a complete product whereas TurboGears is a collection of unrelated parts glued together. For more on this topic, see here: http://www.oreillynet.com/pub/wlg/8986 Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: Being unjust
Fuzzyman wrote: > web.py has the great advantage that (allegedly) you can migrate apps > from CGI to FastCGI, mod_python, WSGI. This isn't an advantage of web.py over other frameworks. You can do the same thing with Django, because it has a WSGI backend; people run Django with mod_python, FastCGI, etc. I believe the same flexibility applies to TurboGears. > There are a few fundamental "philosophy differences" in web apps which > makes it a bit of a religious war. This means getting something into > the standard library is likely to be the cause of intractable > discussions. *sigh* As much as I'd like to see the core bits of Django (which wouldn't require a database or include other fancy high-level features) included in the standard library, I do think it'd devolve into a religious war inevitably. A better goal, I think, would be to add some WSGI code to the standard library -- for instance, code that runs a development server for a WSGI-compliant framework, etc. Perhaps wsgiref: http://svn.eby-sarna.com/wsgiref/ Just my two cents, Adrian -- Adrian Holovaty holovaty.com | chicagocrime.org | djangoproject.com -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Fredrik Lundh wrote: > (or maybe the entire site should be a run via a web framework with good > support for caching, such as > > http://www.djangoproject.com/documentation/cache/ > > any django hackers around with some cycles to spare ? ) Yeah, I or other Django folks would be quite happy to set that up. Just let me know! Adrian -- Adrian Holovaty holovaty.com | chicagocrime.org | djangoproject.com -- http://mail.python.org/mailman/listinfo/python-list
Using signal.alarm to terminate a thread
I have a multi-threaded python application which uses pexpect to connect to multiple systems concurrently. Each thread within my application is a connection to a remote system. The problem is when one of the child threads runs a command which generates an unlimited amount of output. The classic example of this is the "yes" command. If you execute "pexpect.run('yes')", your cpu will sit at 100% forever. Here is a simple multi-threaded program using pexpect which demonstrates the problem. The command 'yes' is run in a thread. The parent says that when the alarm goes off, run the handler function. The thread sets the alarm to trigger after 5 seconds. #!/usr/bin/env python import signal, os, pexpect, threading def handler(signum, frame): # This should get called after 5 seconds when the alarm fires. os.system('killall yes') print "The yes command has been killed!" def runyes(): # Run the 'yes' command in a thread. Set an alarm # to fire in 5 seconds. signal.alarm(5) print "Running yes command..." # If you run 'sleep 10' instead, this works. pexpect.run('yes') # Re-set the alarm. (This is never reached. The 'yes' # command runs forever and is not interrupted by the alarm) signal.alarm(0) signal.signal(signal.SIGALRM, handler) t = threading.Thread(target=runyes) t.start() t.join() # END of code Note that if the 'yes' command is substituted for 'sleep 10', the code works perfectly. Why can't the 'yes' command be interrupted using the SIGALRM method when the sleep command can? I realize that noone would really run 'yes' but what if a user account has a buggy .bashrc and loops forever? Just one thread locking up like this holds up all the others. Any ideas or suggestions on how to handle such situations in a multi-threaded way would be appreciated. Cheers. Adrian Casey. Alice Springs Linux User Goup. http://www.aslug.org.au -- http://mail.python.org/mailman/listinfo/python-list
Re: Using signal.alarm to terminate a thread
Nick Craig-Wood wrote: > Adrian Casey <[EMAIL PROTECTED]> wrote: >> I have a multi-threaded python application which uses pexpect to connect >> to >> multiple systems concurrently. Each thread within my application is a >> connection to a remote system. The problem is when one of the child >> threads runs a command which generates an unlimited amount of output. >> The >> classic example of this is the "yes" command. If you >> execute "pexpect.run('yes')", your cpu will sit at 100% forever. >> >> Here is a simple multi-threaded program using pexpect which demonstrates >> the >> problem. The command 'yes' is run in a thread. The parent says that >> when >> the alarm goes off, run the handler function. The thread sets the alarm >> to trigger after 5 seconds. > > 1) Don't ever mix threads and signals - you are heading for trouble! > > 2) pexpect has a timeout parameter exactly for this case > > import os, pexpect, threading > > def runyes(): > print "Running yes command..." > pexpect.run('yes', timeout=5) > > t = threading.Thread(target=runyes) > t.start() > t.join() > The timeout parameter will not work in this case. If you run the sample code above, it will run forever. The 'yes' command presents a class of command which can not be easily be handled by pexpect. As far as I know, mixing threads and signals is OK provided the parent creates the alarm. Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using signal.alarm to terminate a thread
Nick Craig-Wood wrote: > Adrian Casey <[EMAIL PROTECTED]> wrote: >> > Adrian Casey <[EMAIL PROTECTED]> wrote: >> > import os, pexpect, threading >> > >> > def runyes(): >> > print "Running yes command..." >> > pexpect.run('yes', timeout=5) >> > >> > t = threading.Thread(target=runyes) >> > t.start() >> > t.join() >> > >> The timeout parameter will not work in this case. If you run the sample >> code above, it will run forever. > > The above runs just fine for me, stopping after 5 seconds. Did you > try it? > >> The 'yes' command presents a class of command which can not be >> easily be handled by pexpect. > > Worked for me under Debian/testing. > >> As far as I know, mixing threads and signals is OK provided the >> parent creates the alarm. > > There are so many pitfalls here that I advise you not to try. From > the linuxthreads FAQ > > J.3: How shall I go about mixing signals and threads in my program? > > The less you mix them, the better. Notice that all pthread_* > functions are not async-signal safe, meaning that you should not > call them from signal handlers. This recommendation is not to be > taken lightly: your program can deadlock if you call a pthread_* > function from a signal handler! > > The only sensible things you can do from a signal handler is set a > global flag, or call sem_post on a semaphore, to record the delivery > of the signal. The remainder of the program can then either poll the > global flag, or use sem_wait() and sem_trywait() on the semaphore. > > Another option is to do nothing in the signal handler, and dedicate > one thread (preferably the initial thread) to wait synchronously for > signals, using sigwait(), and send messages to the other threads > accordingly. > > Note also that the signal can be delivered to any thread which > complicates things. > I'm running Kubuntu 06-06 with python 2.4.3 and the above code runs forever at 100% cpu utilization. I shall look into semaphores. However, that means another thread whose sole purpose is to watch the semaphore. Thanks for you help. Cheers. Adrian. -- http://mail.python.org/mailman/listinfo/python-list
How to measure memory footprint of Python objects?
Hello everybody, I try to solve the following problem: I have a python program that takes a lot of memory (>hundred Mb). I made an improvement (I hope) and I want to measure the gain (if possible on several platforms). I would like to be able to print the max memory taken during the run upon exiting my Python program (like I already do for the time taken to run). I can see the total process size of the Python process (Task manager on MS Win or Unix "ps" command) but that is not precise enough for me and also not convenient. I don't care about the python interpreter overhead, I'm interested only in the total size of Python objects allocated by my program. Is there a Python way to get that (meaning without resorting to non-portable, less precise OS features)? I would like to get that size at different given moments in time to make up a timeline of memory consumption. But, if that is too tricky, I would be happy to just get the maximum. Any suggestion welcome, Adrian. -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python interface to Microsoft Outlook Web Access
Hi all, Because I telecommute, I'm limited to using my company's webmail interface, Microsoft Outlook Web Access, rather than having direct POP or IMAP access to e-mail. This isn't ideal, for several reasons: * Outlook Web Access has a horrendous user interface in any browser other than Internet Explorer. (And I'm on Linux, so I can't use Internet Explorer.) It's hard to search, the icons are unintuitive, it encourages top-posting and doesn't have the basic benefits of a desktop e-mail app, such as spell-checking and address auto-completion. * Using webmail forces me to keep a browser window/tab open to check messages. And Outlook Web Access doesn't auto-refresh, so I have to remember to click "Inbox" every so often to get the latest messages. This is a huge disruption. * It's just simpler and more efficient to have all my e-mail in one place. So I figured I'd do a bit of programming to make my life easier. The result: weboutlook, a Python library that screen-scrapes Outlook Web Access. It can: * Log into a Microsoft Outlook Web Access account on a given server with a given username and password. * Retrieve all e-mail IDs from the first page of your Inbox. * Retrieve all e-mail IDs from the first page of any folder in your webmail (such as "Sent Items"). * Retrieve the full, raw source of the e-mail with a given ID. * Delete an e-mail with a given ID (technically, move it to the "Deleted Items" folder). Also, I've included a Python implementation of a POP server that provides a POP interface to the scraper. This means I can point my desktop e-mail client at the script, my e-mail client will think it's a normal POP server, and my e-mails will download nicely into my desktop app, with the screen-scraper running silently behind the scenes. I put this together in my free time, and it's been working nicely for a week, so I'm open-sourcing it for other poor souls who've been sentenced to use Outlook Web Access. I presented this at yesterday's Chicago Python Users Group meeting and was surprised to see that, even in a group of only 30 people, 5 or 6 people used Outlook Web Access through their company. I hope somebody finds this useful. http://www.holovaty.com/code/weboutlook/ Please send comments and improvements to [EMAIL PROTECTED] Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org -- http://mail.python.org/mailman/listinfo/python-list
pexpect: TIMEOUT exception never raised
I have a python script which uses pexpect and I want to timeout (i.e. raise pexpect.TIMEOUT) if a long running command does not produce the output I am expecting. To simulate the 'long running command', consider the following example which simply runs the 'yes' command which prints an endless series of 'y' characters to the terminal. I want to timeout after 10 seconds -: child=pexpect.spawn('ssh [EMAIL PROTECTED]') child.sendline('yes') child.expect([pexpect.TIMEOUT, "the pattern I'm expecting"],10) In this situation, pexpect.TIMEOUT will never be raised. The TIMEOUT exception is only raised if *no* output is received or the output has completed and the pattern expected is not matched within the timeout period. But what about situations where a command produces an infinite amount of output? In the above example, the child.expect statement will hang forever. I thought about using signal.signal to set an alarm that fires a few seconds after timeout and explicitly closes the session. However, my application is multi-threaded (i.e. each thread respresents a connection to a remote host) and signals can not be used outside the main thread :-( Any ideas? Cheers. Adrian Casey. -- http://mail.python.org/mailman/listinfo/python-list
mysteries of urllib/urllib2
I'm trying to use urllib2 to download a page (I'd rather use urllib, but I need to change the User-Agent header to look like a browser or G**gle won't send it to me, the big meanies). The following (pinched from Dive Into Python) seems to work perfectly in Idle, but falls at the final hurdle when run as a cgi script - can anyone suggest anything I may have overlooked? request = urllib2.Request(some_URL) request.add_header('User-Agent', 'some_plausible_string') opener = urllib2.build_opener() data = opener.open(request).read() -- http://mail.python.org/mailman/listinfo/python-list
Re: mysteries of urllib/urllib2
On Jul 3, 11:25 pm, Ben Cartwright <[EMAIL PROTECTED]> wrote: > On Jul 3, 9:43 am, Adrian Smith <[EMAIL PROTECTED]> wrote: > > > The following (pinched > > from Dive Into Python) seems to work perfectly in Idle, but > > falls at the final hurdle when run as a cgi script - can > > anyone suggest anything I may have overlooked? > > > request = urllib2.Request(some_URL) > > request.add_header('User-Agent', 'some_plausible_string') > > opener = urllib2.build_opener() > > data = opener.open(request).read() > > Most likely the account that cgi script is running as does not > have permissions to access the net. Check the traceback to be > sure. Put this at the top of your cgi script: > > import cgitb; cgitb.enable() Well, it worked with urllib (resulting in a G**gle 403 your-client- does-not-have-permission-to-get-urlX page), so I think it must have some access. Apparently there's a way to change the user-agent string by subclassing urllib's URLopener class, but that's beyond my comfort zone at present. -- http://mail.python.org/mailman/listinfo/python-list
Re: mysteries of urllib/urllib2
On Jul 4, 12:42 am, Ben Cartwright <[EMAIL PROTECTED]> wrote: > On Jul 3, 11:14 am, Adrian Smith <[EMAIL PROTECTED]> wrote: > > > > > The following (pinched > > > > from Dive Into Python) seems to work perfectly in Idle, but > > > > falls at the final hurdle when run as a cgi script > > > Put this at the top of your cgi script: > > > > import cgitb; cgitb.enable() > > Did you even try this? Asking for Python help without posting the > traceback is like phoning your mechanic and saying, "My car is > making a generic rattling noise, can you tell me what the problem > is without looking under the hood?" Sorry, I thought as the cgi did appear to have web access it wasn't applicable, and it's amazing what some mechanics can infer from engine noise. cgitb certainly does send back an impressive amount of information, I'll be sure to use it in future. > > Apparently there's a way to change the user-agent string > > by subclassing urllib's URLopener class, but that's beyond my > > comfort zone at present. > > Untested: > > import urllib > url = 'http://groups.google.com/group/Google-AJAX-Search-API/ > browse_thread/thread/a0eb87ad13b11762' > opener = urllib.FancyURLopener() > opener.addheaders = [('User-Agent', 'Fauxzilla 4.0')] > data = opener.open(url).read() That works a treat, thanks! -- http://mail.python.org/mailman/listinfo/python-list
Client-side cookies on Python in Mac OSX
Hi, all. I'm writing an app for OS X; therefore I'd prefer to use only the default python install that comes with Tiger. For the moment, however, this means: NaviOSX:~ adrianpetrescu$ python -V Python 2.3.5 Therefore, I was not surprised to find out that cookielib did not exist here, since I knew that it was a 2.4+ feature. However, I *was* shocked to find out that ClientCookie, which I'd thought was a Python 2.0+ feature, also cannot be found: >>> import ClientCookie Traceback (most recent call last): File "", line 1, in ? ImportError: No module named ClientCookie Why would Apple go out of their way to remove this functionality from their shipped version of Python? More importantly, considering I need to programatically access a website that uses cookies for authentication, how can I do this in OSX's Python install? Do they provide some other library they'd prefer you to use? I'm sure SOMEONE in the world has used cookies on Macs so I'm hoping there is a solution for this... Thanks in advance! -- Adrian Petrescu -- http://mail.python.org/mailman/listinfo/python-list
Re: Client-side cookies on Python in Mac OSX
Oh, you're right! Silly me, I had always thought it was standard. Thanks for pointing this out! I went and downloaded ClientCookie and it works great on OS X. And since it is BSD-licensed, I can use it in my app without any fear. Perfect. Thank you, Graham! On Jul 12, 10:28 pm, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > On Jul 13, 12:14 pm, Adrian Petrescu <[EMAIL PROTECTED]> wrote: > > > > > Hi, all. I'm writing an app for OS X; therefore I'd prefer to use only > > the default python install that comes with Tiger. For the moment, > > however, this means: > > > NaviOSX:~ adrianpetrescu$ python -V > > Python 2.3.5 > > > Therefore, I was not surprised to find out that cookielib did not > > exist here, since I knew that it was a 2.4+ feature. > > > However, I *was* shocked to find out that ClientCookie, which I'd > > thought was a Python 2.0+ feature, also cannot be found: > > > >>> import ClientCookie > > > Traceback (most recent call last): > > File "", line 1, in ? > > ImportError: No module named ClientCookie > > > Why would Apple go out of their way to remove this functionality from > > their shipped version of Python? More importantly, considering I need > > to programatically access a website that uses cookies for > > authentication, how can I do this in OSX's Python install? Do they > > provide some other library they'd prefer you to use? > > > I'm sure SOMEONE in the world has used cookies on Macs so I'm hoping > > there is a solution for this... > > They didn't remove it, it was never there in the first place. > > The ClientCookie site says 'Python 2.0 or above is required'. It > doesn't say it is included with Python distributions. The package > still has to be installed separately. See: > > http://wwwsearch.sourceforge.net/ClientCookie/ > > Graham -- http://mail.python.org/mailman/listinfo/python-list
Interpreting os.lstat()
I'm playing with FUSE's python bindings, and I'm expected to return a list that matches the structure of a python os.lstat() call. So, for example: >>> import os >>> os.lstat("/home/adrian/fuse_test") (16877, 1036L, 2050L, 4, 1000, 1000, 4096L, 1184803155, 1184170289, 1184170289) The problem is, I'm not sure how to recreate this kind of structure because I have no idea about the significance of the entries. The docstring wasn't much help: >>> print os.lstat.__doc__ lstat(path) -> stat result Like stat(path), but do not follow symbolic links. >>> print os.stat.__doc__ stat(path) -> stat result Perform a stat system call on the given path. I checked the online Python documentation at http://python.org/doc/1.5.2/lib/module-stat.html but it just says to "consult the documentation for your system.". At this point I'm guessing that os.lstat is nothing more than a wrapper for some Linux system call, so I looked up the results of running 'stat' on the same file, and I get: [EMAIL PROTECTED]:~$ stat fuse_test/ File: `fuse_test/' Size: 4096Blocks: 8 IO Block: 4096 directory Device: 802h/2050d Inode: 1036Links: 4 Access: (0755/drwxr-xr-x) Uid: ( 1000/ adrian) Gid: ( 1000/ adrian) Access: 2007-07-18 19:59:15.0 -0400 Modify: 2007-07-11 12:11:29.0 -0400 Change: 2007-07-11 12:11:29.0 -0400 I can see some correspondence between the "stat" call and os.lstat (for example, I'm guessing os.lstat(path)[6] represents the filesize), but I can't see the correspondence between some of the other fields. What does os.lstat(path)[0] represent? Are those last three the created/modified/accessed times in unix time or what? Basically, what does each field of os.lstat(path) represent? My system is Linux 2.6.20 and I'm using Python 2.5.1 Thanks in advance, guys! =) -- http://mail.python.org/mailman/listinfo/python-list
Re: Posted messages not appearing in this group
On Jul 18, 3:05 am, Sanjay <[EMAIL PROTECTED]> wrote: > Hi All, > > I tried posting in this group twice since last week, but the messages > did not appear in the forum. Don't know why. Trying this message > again... > > Sanjay I think I'm having the exact same problem. I posted a new thread last night and it still hasn't shown up for me. I'm using Google Groups for both posting and reading. Maybe it has shown up and Google simply isn't showing it yet. Can anyone confirm that a thread posted yesterday (July 18th, 2007) whose title was something like "interpreting os.lstat() output" exists or not? This is quite distressing :( -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting os.lstat()
On Jul 19, 4:27 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Adrian Petrescu <[EMAIL PROTECTED]> writes: > > I checked the online Python documentation > > athttp://python.org/doc/1.5.2/lib/module-stat.html > > but it just says to "consult the documentation for your system.". > > The page you're looking for is > athttp://www.python.org/doc/current/lib/os-file-dir.html. For lstat it > says "Like stat(), but do not follow symbolic links." For stat it > says: > > Perform a stat() system call on the given path. The return value > is an object whose attributes correspond to the members of the > stat structure, namely: st_mode (protection bits), st_ino (inode > number), st_dev (device), st_nlink (number of hard links), st_uid > (user ID of owner), st_gid (group ID of owner), st_size (size of > file, in bytes), st_atime (time of most recent access), st_mtime > (time of most recent content modification), st_ctime (platform > dependent; time of most recent metadata change on Unix, or the > time of creation on Windows) > [...] > For backward compatibility, the return value of stat() is also > accessible as a tuple of at least 10 integers giving the most > important (and portable) members of the stat structure, in the > order st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, > st_atime, st_mtime, st_ctime. More items may be added at the end > by some implementations. The standard module stat defines > functions and constants that are useful for extracting information > from a stat structure. (On Windows, some items are filled with > dummy values.) Thank you, both Will and Hrvoje. Those links answer my questions. :) -- http://mail.python.org/mailman/listinfo/python-list
python cgi problem with textarea
This may be more a cgi thing than a Python one, but I'm trying to get this page: http://adrian10.phpwebhosting.com/trial.html consisting basically of this: ...to print out the contents of the textarea with this cgi script: #!/usr/bin/python import cgi print "Content-type: text/html\n" form = cgi.FieldStorage() print form["essay"].value ...and I get an internal server error if I have any spaces in the textarea, which is really going to limit its usefulness to me. Oddly, it seems to work for a friend in the UK who's looked at it, but it doesn't work for me here in Japan. -- http://mail.python.org/mailman/listinfo/python-list
Re: python cgi problem with textarea
On Apr 22, 11:40 pm, Jim <[EMAIL PROTECTED]> wrote: > On Apr 22, 2:08 am, Adrian Smith <[EMAIL PROTECTED]> wrote:> ...and I > > get an internal server error if I have any spaces in the textarea, > > And what error appears in the server error log? I've just asked my web provider why I don't appear to have a server error log, as a matter of fact - I'll post it if and when they reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: python cgi problem with textarea
On Apr 22, 10:09 pm, placid <[EMAIL PROTECTED]> wrote: > i just tried it and its working. here it is > > http://yallara.cs.rmit.edu.au/~bevcimen/form.html > > maybe the internal server error is because mod_python isn't installed > assuming your using Apache as your web server Yeah, but it wouldn't work *at all* in that case, would it? ATM it seems to work as long as the textarea input has no spaces. -- http://mail.python.org/mailman/listinfo/python-list
Re: python cgi problem with textarea
On Apr 24, 8:00 pm, placid <[EMAIL PROTECTED]> wrote: > oops...i did read the problem description, but i when i tried the code > it worked for me and when i put spaces into the TextArea it wasn't > reflected correctly back. So i thought this was the problem. > > Adrian, can you still try replacing spaces with via the > following; > > #!/usr/bin/python > import cgi > import urllib > import cgitb > cgitb.enable() > print "Content-type: text/html\n" > form = cgi.FieldStorage() > #print urllib.quote_plus(form["essay"].value) > > for char in form["essay"].value: >if char == ' ': > print " " >else: > print char > > Cheers I'll try it...but I think it may be a problem on the server end. It's not showing up in the server logs, either. -- http://mail.python.org/mailman/listinfo/python-list
CGI python use "under a curse"
While waiting for my paid-for web-hosting company to get back to me about my difficulties running python scripts on their servers... http://groups.google.com/group/comp.lang.python/browse_frm/thread/39b52bcf0dffec4c/4ff805bf283acc15?lnk=gst&q=adrian+smith&rnum=1&hl=en#4ff805bf283acc15 ...I went and found a free one as a stopgap. And it worked! I was as happy as a clam. But then it stopped working. Ah. I stripped the script down to the same minimalist hello-world effort I used previously: #!/usr/local/bin/python import cgi print "Content-type: text/html\n" form = cgi.FieldStorage() print form["essay"].value (page here: http://essays.profusehost.net/) As before, this should print out the contents of a textarea going by the name of "essay". But it does nothing but throw internal server errors. The support guy looked at it and gave me this: Traceback (most recent call last): File "python1.cgi", line 6, in ? print form["essay"].value File "/usr/local/lib/python2.4/cgi.py", line 559, in __getitem__ raise KeyError, key KeyError: 'essay' (http://www.profusehost.net/forum/support/10894-cgi-blink.html) He says I have a syntax error, though I'm b*ed if I can see where it could be. Can anyone here suggest anything? TIA for your forbearance etc. -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI python use "under a curse"
On May 7, 2:30 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 06 May 2007 21:30:16 -0700, Adrian Smith wrote: > It is NOT the same error. There are NO syntax errors in the script, there > is a runtime error. The so-called administrator is wrong: you can't use > Perl to test just any old CGI scripts. They have to be written in Perl. Well, I thought that, but you know what happens to newbies who come out with such opinions forcefully. Maybe they have special magic perl which parses python. > I see from the source code on your page that you have a line: > > > > You have two lines in your cgi script: > > form = cgi.FieldStorage() > print form["essay"].value > > Having never done cgi programming, I'm not sure what the problem is, but > after reading help(cgi) I'll take a stab in the dark and say try this: > > print form.value > > It might also help for you to try this: > > print form.keys() Both give me the same ISE, alas. > Good luck with the "admins" at your hosting company. Well, it *is* free, and there aren't that many free ones that offer Python. My paid-for host has sent me a message to say they're ruminating on my issues, though, so I live in hope. -- http://mail.python.org/mailman/listinfo/python-list
Re: File access
On Aug 2, 12:41 pm, JD <[EMAIL PROTECTED]> wrote: > Hi, > > What I am trying to do is to run a subprocess on another machine using > subprocess.Popen, this subprocess contuinue writing something into a > file when it is runing. > > After submit this subprocess, I tried to open the file and readlines() > in the loop (with a delay) in the loop) when the subprocess was > runing. > > The problem is I could not get anything untill the subprocess > finished. > > I also tried to run another python programm when the subprocess is > runing, I could get what I want. > > Does anyone know why? Thanks! > > JD Could the problem be that the subprocess only flushes the output buffer when it terminates, and so until the subprocess "finishes", as you say, the file is empty because the data is still in the buffer? Trying throwing some flushes into the code and see if it helps. Or am I misunderstanding your question? -- http://mail.python.org/mailman/listinfo/python-list
Re: Islam, the Religion of Ease
On Mar 29, 11:36 am, "moslim" <[EMAIL PROTECTED]> wrote: > Excuse me!! > Would you stop for a moment?! > O...man...Haven't you thought-one day- about yourself ? > Who has made it? > Have you seen a design which hasn't a designer ?! > Have you seen a wonderful,delicate work without a worker ?! > It's you and the whole universe!.. > Who has made them all ?!! > You know who ?.. It's "ALLAH",prise be to him. > Just think for a moment. > How are you going to be after death ?! > Can you believe that this exact system of the universe and all of > these great creation will end in in nothing...just after death! > Have you thought, for a second, How to save your soul from Allah's > punishment?! > Haven't you thought about what is the right religion?! > Read ... and think deeply before you answer.. > It is religion of Islam. > It is the religion that Mohammad-peace upon him- the last prophet, had > been sent by. > It is the religion that the right Bible- which is not distorted-has > preached. > Just have a look at The Bible of (Bernaba). > Don't be emstional. > Be rational and judge.. > Just look..listen...compare..and then judge and say your word. > We advise you visiting > :http://www.islam-guide.comhttp://www.thetruereligion.orghttp://www.beconvinced.comhttp://www.plaintruth.orghttp://english.islamway.comhttp://www.todayislam.comhttp://www.prophetmuhammed.orghttp://www.islamtoday.net/english/http://www.islamunveiled.orghttp://www.islamic-knowledge.com > > We willingly recive any inquries at the e-mail : > > [EMAIL PROTECTED] Respectofully: 1.- Use the right place for your propaganda. 2.- Stop with religions, and militarism 3.- Free the World of religious and Militars and you will get the Peace for everybody 4.- Use your time for usefull matters Regards Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Magazine: Issue 1 Free!
Steve Holden <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > I've just been told by the editors at Python Magazine that > the first issue is out. It's all-electronic so anyone can > download and read it. Let them know what you think: > >http://www.pythonmagazine.com/c/issue/2007/10 > > regards > Steve Thanks for that, initial impression looks good, I peruse it later when the boss isn't watching. Unfortunately there seems to be a few horror pictures crept in on page 4!. One initial comment is the end of the magazine. It just seems to stop abruptly. No back page commentry, cartoon or teaser for the next issue. Regards Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Magazine: Issue 1 Free!
Paul McGuire <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > I thought Steve Holden's Random Hits column was the "back > page commentry". after re-reading it then yes I can see your point, I suppose I was just hoping for some pythonesque humour to close the show! Regards Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple HTML template engine?
"allen.fowler" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Hello, > > Can anyone recommend a simple python template engine for > generating HTML that relies only on the Pyhon Core modules? > > No need for caching, template compilation, etc. > > Speed is not a major issue. > > I just need looping and conditionals. Template inheritance > would be a bonus. > > I've seen Genshi and Cheetah, but they seem way too complex. > > Any ideas? > Did you try Cheetah? I've just started using it for a simple job, just looping and conditionals and it seemed quite simple to me. Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple HTML template engine?
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > > Did you read the OP's question ?-) Yup, as much as anyone else has. Why? Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: Why did no one tell me about import antigravity?
Ant <[EMAIL PROTECTED]> wrote in news:52f0eca3-e807-4890-b21d- [EMAIL PROTECTED]: > Python on xkcd: > > http://xkcd.com/353/ > Another good comic from xkcd, I'm surprised by the muted response on here. Don't forget to check out the alt. text on the comic Alt text: "I wrote 20 short programs in Python yesterday. It was wonderful. Perl, I'm leaving you." Regards Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: "Python" is not a good name, should rename to "Athon"
"Russ P." <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED] ups.com: > Speaking of stupid names, what does "C++" mean? I think it's > the grade you get when you just barely missed a "B--". But I > can't deny that it *is* good for searching. > For that matter C# is no better, I thought that # was pronounced hash, I still refer to C# as C-hash. Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: "Python" is not a good name, should rename to "Athon"
Piet van Oostrum <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: >>>>>> "Adrian Cherry" <[EMAIL PROTECTED]> (AC) wrote: > >>AC> For that matter C# is no better, I thought that # was >>pronounced AC> hash, I still refer to C# as C-hash. > > Are you musically illiterate? Yup! The limits of my musically ability is Spam, spam, spam, spam. Lovely spam! Wonderful spaaam! Lovely spam! Wonderful spam. Spa-a-a-a-a-a-a-am! Spa-a-a-a-a-a-a-am! Is that a problem? It's still a hash sign to me. Adrian -- http://mail.python.org/mailman/listinfo/python-list
Newbie question on Classes
Hi al! I'm new to the list, and reasonably new to Python, so be gentle. Long story short, I'm having a hard time finding a way to call a function on every object of a class at once. Example: I have a class Person, which has a function state(). This prints a basic string about the Person (position, for example). In the program, I have created two objects of class Person, called man and woman. I can call man.state() and then woman.state() or Person.state(man) and Person.state(woman) to print the status of each. This takes time and space however, and becomes unmanageable if we start talking about a large number of objects, and unworkable if there is an unknown number. What I'm after is a way to call the status of every instance of Man, without knowing their exact names or number. I've gone through the relevant parts of the online docs, tried to find information elsewhere online, and looked for code samples, but the ionformation either isn't there, or just isn't clicking with me. I've tried tracking the names of each object in a list, and even creating each object within a list, but don't seem to be able to find the right syntax to make it all work. I'd appreciate anyone who could help, especially if they could include a short sample. My apologies if I'm not following the etiquette of the group in some way my making this request. Thank you, Adrian -- http://mail.python.org/mailman/listinfo/python-list
Fwd: Python-list Digest, Vol 52, Issue 128
Fredrik Lundh wrote: > > Adrian Wood wrote: > > > > I can call man.state() and then woman.state() or Person.state(man) and > > Person.state(woman) to print the status of each. This takes time and > > space however, and becomes unmanageable if we start talking about a > > large number of objects, and unworkable if there is an unknown number. > > What I'm after is a way to call the status of every instance of Man, > > without knowing their exact names or number. > > > > I've gone through the relevant parts of the online docs, tried to find > > information elsewhere online, and looked for code samples, but the > > ionformation either isn't there, or just isn't clicking with me. I've > > tried tracking the names of each object in a list, and even creating > > each object within a list, but don't seem to be able to find the right > > syntax to make it all work. > > For a start, how about: > > class Person: > ... your class ... > > persons = [] > > man = Person() > persons.add(man) > > woman = Person() > persons.add(woman) > > for p in persons: > print p, p.state() It didn't like using .add for some reason, but once I swapped out all instances of that for .append that worked a treat! Thank you very much, I'll check out your other suggestions later once I feel comfortable with what I have so far. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's popularity
r wrote in news:ae1bb365-7755-4c5f-8166-e704c51a7...@i20g2000prf.googlegro ups.com: > > Oh Steve... Listen, my words are ment as a wake-up-call to > all who still love Python, and i believe you are one of > them. Maybe old age has slowed your hand, that's OK, Us > "youngsters" will take the helm. And be serious, do you > really think this group is read by "hundreds-of- thousands > of news readers? I wish it were, but I highly doubt it. > Thus spake the artilleryman from Horsell Common! Adrian Cherry -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Django forum-building software Snap/SCT, any reviews?
John Crawford wrote in news:newztoolz_rulz!_www.techsono.com_3319721838_653...@speakea sy.net: > > Two packages that are Django-based that I have found, are > Snap and SCT. They both look pretty good (and Snap was > influenced by Vanilla). Does anyone have any experience with > these packages, and comments about them? Thanks > I've not got any experience yet of using SCT. However I've been looking at forum apps for use with in Django and settled on SCT to experiment with. I had a query about the features of SCT, I got a very quick and positive reply from the author. The feature I was after isn't built in to SCT but he had a number of positive suggestions for getting it working. So the support from SCT was very encouraging for me and hence why I'm trying it out. For info the feature required was for developing a forum area for a specialist group I'm involved in. They currently just have a mailing list for the group. Half the people are clamouring for a web forum and the other half want the convenience of posting and receiving posts via email. I asked if SCT could receive posts and send out a daily digest via email. The answer appears to be not yet but no reason why it couldn't. Probably going to be an itch I have to scratch myself. Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: modifying a list element from a function
Could you explain your high level goal for this? It looks like a very wicked way of doing things. Have You tried to read the list methods' documentation? Maybe there you find something you need (like list.index)? -- Adrian -- http://mail.python.org/mailman/listinfo/python-list
using Winpdb in an embedded python interpreter
Hi there, I have a problem using Winpdb in Pythonscripts running in a program which uses an embedded Python interpreter. After linking all needed modules statically to python, "import rpdb2" can be done and leads to no error. But on using the next line "rpdb2.start_embedded_debugger('password')". an error occurs: Exception in thread ioserver: Traceback (most recent call last): File "C:\Program Files\Python30\lib\threading.py", line 507, in _bootstrap_inn er self.run() File "S:\dev\adge\build\r3804\Debug_Win32\py\rpdb2.py", line 4570, in run threading.Thread.run(self) File "C:\Program Files\Python30\lib\threading.py", line 462, in run self._target(*self._args, **self._kwargs) File "S:\dev\adge\build\r3804\Debug_Win32\py\rpdb2.py", line 9639, in run (self.m_port, self.m_server) = self.__StartXMLRPCServer() File "S:\dev\adge\build\r3804\Debug_Win32\py\rpdb2.py", line 9730, in __StartX MLRPCServer server = CXMLRPCServer((host, port), logRequests = 0) File "C:\Program Files\Python30\lib\xmlrpc\server.py", line 530, in __init__ socketserver.TCPServer.__init__(self, addr, requestHandler, bind_and_activat e) File "C:\Program Files\Python30\lib\socketserver.py", line 400, in __init__ self.server_bind() File "C:\Program Files\Python30\lib\socketserver.py", line 411, in server_bind self.socket.bind(self.server_address) LookupError: unknown encoding: idna Does someone have an idea why this error occurs? Funny thing is that module "socketserver" is taken from "C:\Program Files\Python30\lib\xmlrpc\server.py", although the module search path does not contain "C:\Program Files\Python30\lib". Maybe this has something to do with the problem... Thanks, Adrian -- http://mail.python.org/mailman/listinfo/python-list
scoping problem with list comprehension // learning Python
I just started to learn python (first posting to the list). I have a list of dates as strings that I want to convert to a list of datetime objects. Here is my debugging session from inside a method. (Pdb) formatIndex '%Y-%m-%d' (Pdb) [datetime.strptime(i, formatIndex) for i in self.index[0:3]] *** NameError: global name 'formatIndex' is not defined (Pdb) [datetime.strptime(i, '%Y-%m-%d') for i in self.index[0:3]] [datetime.datetime(2007, 1, 3, 0, 0), datetime.datetime(2007, 1, 4, 0, 0), datetime.datetime(2007, 1, 5, 0, 0)] (Pdb) How come I get an error that formatIndex is not defined? I just show that it has value '%Y-%m-%d', in the same method scope. Not sure why it says "global name", as I am in a method. If I run it as a stand-alone, it works: index = ['2007-01-01', '2007-01-02', '2007-01-03'] formatIndex = '%Y-%m-%d' print([datetime.strptime(i, formatIndex) for i in index]) Any suggestions much appreciated. I'm sure it's something trivial. I'm using Python30. Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: extended setattr()
Diez B. Roggisch nospam.web.de> writes: > > def ext_setattr(obj, attr, val): > > for subattr in attr.split("."): > > obj = getattr(obj, subattr) > > obj = val > > > import test > a = A() > > Traceback (most recent call last): > > File "", line 1, in > > NameError: name 'A' is not defined > a = test.A() > a.B.C.txt > > 'foo' > ext_setattr(a, 'B.C.txt', 'bar') > a.B.C.txt > > 'foo' > > > > What am i doing wrong? > > obj = val won't work. Why is this so? Shouldn't it be the same? > You need to use a setattr(obj, name, val) > on the last attribute-name. Ok, so this works: def ext_setattr(obj, attr, val): attributes = attr.split('.') for subattr in attributes[:-1]: obj = getattr(obj, subattr) setattr(obj, attributes[-1], val) -- http://mail.python.org/mailman/listinfo/python-list
Re: Randall Munroe loves Python
Paul McGuire <[EMAIL PROTECTED]> wrote in news:869c25d9-e4d3- [EMAIL PROTECTED]: > Another xkcd plug for Python: http://xkcd.com/409/ > So Python is on a collision course with Calvin and Hobbes! Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML Tables
On Aug 18, 7:16 pm, Amie <[EMAIL PROTECTED]> wrote: > Afternoon all. > > Just want to know how to create html tables using a for loop. > I need to display 34 html tables, so I figured a for loop will do. > Please show me an example of how to do that. for i in range(33): print "" for j in range(numberofrows-1): print "stuffstuffstuff" print "" Or something like that. You could have for loops for the individual rows, too. -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML Tables
On Aug 19, 6:49 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Adrian Smith wrote: > >> Just want to know how to create html tables using a for loop. > >> I need to display 34 html tables, so I figured a for loop will do. > >> Please show me an example of how to do that. > > > for i in range(33): > > range(33) returns 33 numbers, not 34 (the upper bound is not inclusive). Oops! Thought it went over 0-33, my bad. -- http://mail.python.org/mailman/listinfo/python-list
smart quotes
Can anyone tell me how to get rid of smart quotes in html using Python? I've tried variations on stuff = string.replace(stuff, "\“", "\""), but to no avail, presumably because they're not standard ASCII. -- http://mail.python.org/mailman/listinfo/python-list
Re: smart quotes
On Aug 26, 4:13 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > Adrian Smith wrote: > > Can anyone tell me how to get rid of smart quotes in html using > > Python? I've tried variations on > > stuff = string.replace(stuff, "\“", "\""), but to no avail, presumably > > because they're not standard ASCII. > > Convert the string to unicode. For that you have to know its encoding. I > assume UTF-8: > > >>> s = "a “smart quote” example" > >>> u = s.decode("utf-8") > > Now you can replace the quotes (I looked up the codes in wikipedia): > > >>> u.replace(u"\u201c", "").replace(u"\u201d", "") > > u'a smart quote example' > > Alternatively, if you have many characters to remove translate() is more > efficient: > > >>> u.translate(dict.fromkeys([0x201c, 0x201d, 0x2018, 0x2019])) > > u'a smart quote example' > > If necessary convert the result back to the original encoding: > > >>> clean = u.translate(dict.fromkeys([0x201c, 0x201d, 0x2018, 0x2019])) > >>> clean.encode("utf-8") > > 'a smart quote example' > > Peter Brilliant, thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax?
Steve Ferg wrote in news:ff92db5b-9cb0-4a72-b339-2c5ac02fb...@p36g2000vbn.googlegro ups.com: > This is a question for the language mavens that I know hang > out here. It is not Python related, except that recent > comparisons of Python to Google's new Go language brought it > to mind. > > NOTE that this is *not* a suggestion to change Python. I > like Python just the way it is. I'm just curious about > language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse > statements. > > I've often thought that a language with this kind of > block-free syntax would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using > a colon rather then "then" for the condition terminator. > You could make it more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than > that I don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* > language- design idea? I believe MATLAB has similar if syntax - please correct me if I'm wrong. From http://www.mathworks.com/access/helpdesk/help/techdoc/ref/if.html "The if function can be used alone or with the else and elseif functions. When using elseif and/or else within an if statement, the general form of the statement is" if expression1 statements1 elseif expression2 statements2 else statements3 end Adrian -- http://mail.python.org/mailman/listinfo/python-list
pyqt4: multi-threaded database access
I have a PyQt4 multi-threaded application which accesses many hosts concurrently via ssh. I would like each thread to have access to a database so that it can look up details about the particular system it is connected to. The easy way is to have each thread create a connection to the database. However, this is wasteful and likely to exhaust the maximum number of connections the database (postgresql) allows. Instead, I would like to share a single database connection between all threads. In PyQt4, this is not possible since the database connection can only be used by the thread which created it. So, I'm thinking I'll create a thread to just handle database queries. The worker threads will communicate with the database thread using signals and slots. My question is, if I have 20 worker threads who have emitted a signal which results in a database query, how do I ensure that the query results are sent back to the originating thread? Ideas, examples anyone? Thanks. Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: older pythons
The recommended Debian way is update-alternatives. I find it a bit unintuitive, so I have to read through the documentation every time I use it, but it should be able link a chosen version of python to /usr/ bin/python. I don't know if it's set up by default, I have only one version installed. -- Adrian -- http://mail.python.org/mailman/listinfo/python-list
Re: Python code for testing well parenthesized expression
Strings are immutable, so your method of slicing one letter at time will be building lots of them. That shouldn't hurt you here, but it will when you hit a bigger problem. In the i() there should be "return op == 0" on the end. def well(expr): mapping = {'(':1, ')':-1} count = 0 for s in expr: if s in mapping: count += mapping[s] if s < 0: return False return count == 0 def test_well(): examples = [ ('zx4er(1(er(Yy)ol)ol)ik', True), ('x(x)x(x(x)xx(xx(x)x(x(x)xx)())x(x(x)xx)()x)()', True), ('a(ty(y(y(bn)))lokl)kl', True), ('xc(er(tgy(rf(yh)()uj)ki))', True), ('e', True), ('rf(tgt)juj)jkik(jun)', False), ('zx(4er(1(er(Yy)ol)ol)ik', False), ] for expr, expected in examples: assert well(expr) == expected -- http://mail.python.org/mailman/listinfo/python-list
Re: Python code for testing well parenthesized expression
> Don't you want to just test that the number of "("s equals the number of > ")"s or am I missing the point? I had this idea too, but there is additional requirement that any beginning must have greater or equal number of '(' than ')'. -- Adrian -- http://mail.python.org/mailman/listinfo/python-list
RE: new to python and programming at large
Hello, you have to use the same parameter, not self which is used in classes def squareroot(n): return sqrt(n) -- Adrián Espinosa. Engineering Support, Wholesale Systems. Jazztel.com De: kwakukwat...@gmail.com [mailto:kwakukwat...@gmail.com] Enviado el: miércoles, 09 de enero de 2013 22:06 Para: python-list@python.org Asunto: new to python and programming at large pls I want to write a function that can compute for the sqrt root of any number.bt it not working pls help. from math import sqrt def squareroot(self): x = sqrt(y) print x Este mensaje es privado y CONFIDENCIAL y se dirige exclusivamente a su destinatario. Si usted ha recibido este mensaje por error, no debe revelar, copiar, distribuir o usarlo en ningún sentido. Le rogamos lo comunique al remitente y borre dicho mensaje y cualquier documento adjunto que pudiera contener. El correo electrónico via Internet no permite asegurar la confidencialidad de los mensajes que se transmiten ni su integridad o correcta recepción. JAZZTEL no asume responsabilidad por estas circunstancias. Si el destinatario de este mensaje no consintiera la utilización del correo electrónico via Internet y la grabación de los mensajes, rogamos lo ponga en nuestro conocimiento de forma inmediata.Cualquier opinión expresada en este mensaje pertenece únicamente al autor remitente, y no representa necesariamente la opinión de JAZZTEL, a no ser que expresamente se diga y el remitente esté autorizado para hacerlo. This message is private and CONFIDENTIAL and it is intended exclusively for its addressee. If you receive this message in error, you should not disclose, copy, distribute this e-mail or use it in any other way. Please inform the sender and delete the message and attachments from your system.Internet e-mail neither guarantees the confidentiality nor the integrity or proper receipt of the messages sent. JAZZTEL does not assume any liability for those circumstances. If the addressee of this message does not consent to the use of Internet e-mail and message recording, please notify us immediately.Any views or opinions contained in this message are solely those of the author, and do not necessarily represent those of JAZZTEL, unless otherwise specifically stated and the sender is authorised to do so. -- http://mail.python.org/mailman/listinfo/python-list
infinite loop
Hi all, I have a question with some code I'm writting: def main(): if option == 1: function_a() elif option == 2: function_b() else: raise 'option has to be either 1 or 2' if iteration == True: main() def function_a(): print 'hello from function a' return None def function_b(): print 'hello from function b' return None iteration = True option = 1 main() I want an infinite loop, but after some iterations (996) it breaks: [EMAIL PROTECTED] tmp]$ python test.py hello from function a hello from function a hello from function a . . . hello from function a hello from function a Traceback (most recent call last): File "test.py", line 35, in ? main() File "test.py", line 17, in main main() File "test.py", line 17, in main . . . . File "test.py", line 17, in main main() File "test.py", line 17, in main main() File "test.py", line 5, in main function_a() RuntimeError: maximum recursion depth exceeded I don't understand it. Why am I not allowed to iterate infinitely? Something about the functions? What should I do for having an infinite loop? Thanks in advance for your help, Adrián. -- http://mail.python.org/mailman/listinfo/python-list