Selenium/SauceLabs Open Space Session at Pycon in Atlanta
The Sauce Labs team, http://saucelabs.com/about/team, is hosting two free tutorial open space sessions at Pycon in Atlanta. In the short session, people bringing their laptops should be able to record a web session in their browser, convert the recorded activity to a Python script, modify the script to accept a number of inputs , and replay the script locally on their laptops. Once you've learned how to fully automate your own browser, submit the same script to the Sauce Labs cloud to run the tests in parallel across multiple browsers and operating systems, and view the results with instant video playback. The tutorials should be of interest to web developers wanting fast, cross-browser testing and it should be of general interest to anyone wanting to use Python to automate browser sessions. The tutorials are being led by Jason Huggins, the creator of Selenium (an open source web app testing tool http://seleniumhq.org/ ). Several familiar names from the Python community will also be on-hand: http://saucelabs.com/about/news/feb-03-2010 Raymond -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Python-URL! - weekly Python news and links (Feb 3)
QOTW: I think, in the spirit of the topic, they should hold it at both places at the same time. - Brian Blais, on whether the Python Concurrency Workshop, v2.0, should be in Chicago or Denver (in January!) The fastest way to consume an iterable until exhaustion: http://groups.google.com/group/comp.lang.python/t/c1ae3513a31eb63e/ When inheriting from a built-in class, it isn't obvious which of __new__ / __init__ should be overriden: http://groups.google.com/group/comp.lang.python/t/a453c65be4e0f355/ When importing a module, Python may pick the wrong one due to name clashes -- is this avoidable? http://groups.google.com/group/comp.lang.python/t/fe6430e7980e2a96/ Setting a default encoding for 'print' statements: http://groups.google.com/group/comp.lang.python/t/2fb77c8989f63f9d/ Despite its name, the iglob function (in module glob) isn't completely lazy: http://groups.google.com/group/comp.lang.python/t/d9a8617ec85e926d/ list.pop(0) has very poor performance; collections.deque works better in some cases; patch to allow lists to free elements from head (not just from tail): http://groups.google.com/group/comp.lang.python/t/9221d87f93748b3f/ How to parse ill-formed postal addresses: http://groups.google.com/group/comp.lang.python/t/76a4ab9fd7279a4e/ The future of Python 3: Adoption by Linux distros and package maintainers: http://groups.google.com/group/comp.lang.python/t/69463c4b9b1ecd8f/ Library support: http://groups.google.com/group/comp.lang.python/t/ae138cefffed0d6b/ Myths and fallacies: http://groups.google.com/group/comp.lang.python/t/8b8f4a9f999e33e8/ Why choose Python (and not Ruby) in an introductory course to programming: http://groups.google.com/group/comp.lang.python/t/dfe4f6c60032755e/ How an extension module (written in C) may perform cleaning tasks: http://groups.google.com/group/comp.lang.python/t/fbcb22b4401eaef1/ Really, the built-in scope is just a built-in module called builtins, but you have to import builtins to query built-ins because the name builtins is not itself built-in... (Lutz Ascher, 'Programming Python') http://groups.google.com/group/comp.lang.python/t/dc719a4d922f2f87/ A new implementation of the GIL allows for much better performance in multicore architectures: http://groups.google.com/group/comp.lang.python/t/586ef2d3685fa7ea/ After a year of work with relative success, Unladen Swallow (a Google sponsored CPython improvement project) asks to be officially recognized: http://comments.gmane.org/gmane.comp.python.devel/109919 Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish the efforts of Python enthusiasts: http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the Planet site: http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes podcasts ... to help people learn Python ... Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions.
Re: PyChecker under python's virtualenv
Am 04.02.10 01:52, schrieb Steve Holden: Diez B. Roggisch wrote: Am 03.02.10 22:46, schrieb soltys: Hi Everybody, I've been doing some test on pythons' virtualenv and recently I've decided to run PyChecker. But I'm having some difficulties with importing modules available only on virtualenv by pychecker. As if it was trying to use systemwide python. I've googled about it, and found nothing in this area. I installed pychecker using python setup.py install from virtualenv. I looked at pychecker script - it uses correct python. I doubt that it uses the correct python, because then you wouldn't have the problems you have. I don't use pychecker, but pylint. And there, the system-wide command uses the system's python - which of course doesn't know anything about virtualenv. There are two solutions to this problem: - install py(lint|checker) into your virtualenv. See the OP's original assertion: I installed pychecker using python setup.py install from virtualenv. I looked at pychecker script - it uses correct python. Isn't that installing into his virtualenv? You are right, it reads like that. I should have read it better. All I can say is that even a system-wide pylint with my recipe above gives me no troubles. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Dreaming of new generation IDE
This is obvious even in the Python documentation itself where one frequently asks oneself Uhh... so what is parameter X supposed to be... a string... a list... ? That is partially why I created this search engine for python, to see what parameters other people feed in. http://nullege.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
I'm not sure what you mean by that. Obviously if users want to record their own conversations, then I can't stop them, but that's much different than a non-participant in the conversation leaving a recorder running 24/7. Is that so hard to understand? Is it so hard to understand that this is not about laws and rights, but about technical properties of the HTTP-protocol? Your web-based chat uses HTTP, no P2P-protocol, and thus the service provider *can* log conversations. I don't say he should, I don't say I want that, I don't say there are now laws that prevent them from doing so, all I say is he *can*. I certainly didn't feel that saving or not saving client conversations on the server side was up to my discretion. When I found that the default server configuration caused conversations to be logged then I was appalled. Then stop logging. Or get a hosting-provider that allows you to configure it to strip QUERY_STRINGS from log-entries. And if they refuse to, maybe using POST solves the issue. But wait, there is http://www.cyberciti.biz/faq/apache-mod_dumpio-log-post-data/ So what if they run that? So, for the umpteenth time: data sent over the wire can be recorded. From the user's POV, your nitpicking of who's the actual culprit - the IT-guys, or the programmers - is fruitless. You have a nice anecdote where switching from GET to POST allowed you to trick whoever wasn't acting to your wishes. Good for you. But John B. and your posts indicate that using POST is inherently more secure. It *isn't*. Do you think the phone company has the right to record all your phone calls if they feel like it (absent something like a law enforcement investigation)? What about coffee shops that you visit with your friends? It is not up to their discretion. They have a positive obligation to not do it. If you think they are doing it on purpose without your authorization, you should notify the FBI or your equivalent, not just don't use it. If they find they are doing it inadvertently, they have to take measures to make it stop. That is the situation I found myself in, because of the difference in how servers treat GET vs. POST. If they have a positive obligation not to do it, it doesn't matter if they run their service over GET or POST. Again, this is not about laws and what service providers should or must do. It's about POST vs. GET, and if either of them is more secure or not. It isn't. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: How to guard against bugs like this one?
On 03/02/2010 16:17, kj wrote: Boy, that was dumb of me. The above apology was meant for Stephen Hansen, not Steve Holden. I guess this is now a meta-apology... (Sheesh.) You see? That's what I like about the Python community: people even apologise for apologising :) TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: test -- please ignore
kj no.em...@please.post wrote: In 87wryumvff@benfinney.id.au Ben Finney ben+pyt...@benfinney.id.au writes: kj no.em...@please.post writes: (my replies in a different comp.lang.python thread are getting rejected by the server; i have no problem posting to alt.test; and i'm trying to toubleshoot the problem further.) Thank you for this explanation. It is important to know that you've tried the less obtrusive diagnostics first. Good hunting. I figured out the immediate reason for the failure: when replying to *certain posts*, my newsreader omits the Newsgroups header from the response. Why it does this is still a mystery to me, but at least now I know what to look out for. Then again, I use the venerable (i.e. decrepit) nn as newsreader, so this discovery probably won't help many of those reading this... I used to use nn, now I use tin which is fairly similar and still being maintained. -- Chris Green -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Alan Harris-Reid a...@baselinedata.co.uk writes: I have a web-page where each row in a grid has edit/delete buttons to enable the user to maintain a selected record on another page. The buttons are in the form of a link with href='/item_edit?id=123', but this string appears in the URL and gives clues as to how to bypass the correct sequence of events, and could be risky if they entered the URL directly (especially when it comes to deleting records). You should *never* use a GET request to do actions like deleting records. You already are aware of it being risky, so don't do this. You should use GET for getting information, and POST for modifying information. Is there another way of passing a record-id to a method a) without it appearing in the URL? Use a POST request. Note that the user still has to select something, and that this information is send by the browser, and hence the user can see this information (and maybe others), and repeat the action with, for example, a Python program. b) without the user being able to fathom-out how to attach which id to which URL? I am not sure what you want to prevent here. If you're afraid that user A can delete things that belong user B, than hiding things or making them hard to guess are not going to help much. If you have several users, you must use some login procedure (and sessions). As each link contains row-id, I guess there is nothing to stop someone from getting the id from the page source-code. Is it safe to use the above href method if I test for authorised credentials (user/password stored as session variables, perhaps?) before performing the edit/delete action? Yes. But still make sure that session ids are not easy to guess, and expire. And make very sure that session ids can't leak to others. Moreover, each time you modify a database use POST. One could argue to also use POST for logging out, otherwise another site might be able to log your users out if they visit that site. -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Diez B. Roggisch de...@nospam.web.de writes: Am 03.02.10 19:11, schrieb John Bokma: Alan Harris-Reida...@baselinedata.co.uk writes: I have a web-page where each row in a grid has edit/delete buttons to enable the user to maintain a selected record on another page. The buttons are in the form of a link with href='/item_edit?id=123', but this string appears in the URL and gives clues as to how to bypass the correct sequence of events, and could be risky if they entered the URL directly (especially when it comes to deleting records). You should *never* use a GET request to do actions like deleting records. You already are aware of it being risky, so don't do this. You should use GET for getting information, and POST for modifying information. You should *never* say never, because there might be situations where exceptions from rules are valid. This is one such cases. Making this a post means that you need to resort to javascript to populate submit a hidden HTML-form. Just for the sake of a POST. Make each edit/delete button a submit button and optionally style it. Also, your claim of it being more risky is simply nonsense. GET is a tiny bit more prone to tinkering by the average user. But calling this less risky is promoting security by obscurity, at most. Maybe you should think about what happens if someone posts: img src=http://example.com/item_delete?id=123; to a popular forum... -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Am 03.02.10 19:11, schrieb John Bokma: Alan Harris-Reida...@baselinedata.co.uk writes: I have a web-page where each row in a grid has edit/delete buttons to enable the user to maintain a selected record on another page. The buttons are in the form of a link with href='/item_edit?id=123', but this string appears in the URL and gives clues as to how to bypass the correct sequence of events, and could be risky if they entered the URL directly (especially when it comes to deleting records). You should *never* use a GET request to do actions like deleting records. You already are aware of it being risky, so don't do this. You should use GET for getting information, and POST for modifying information. You should *never* say never, because there might be situations where exceptions from rules are valid. This is one such cases. Making this a post means that you need to resort to javascript to populate submit a hidden HTML-form. Just for the sake of a POST. And there are people who say you should *never* write web-apps that only work with enabled javascript... catch 22. Also, your claim of it being more risky is simply nonsense. GET is a tiny bit more prone to tinkering by the average user. But calling this less risky is promoting security by obscurity, at most. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Am 03.02.10 23:09, schrieb Paul Rubin: Diez B. Roggischde...@nospam.web.de writes: Also, your claim of it being more risky is simply nonsense. GET is a tiny bit more prone to tinkering by the average user. But calling this less risky is promoting security by obscurity, at most. GET parameters also tend to get recorded in the http logs of web proxies and web servers while POST parameters usually aren't. This was an annoyance in a web chat package I fooled with for a while. Because the package sent user messages by GET, if I ran the software the way the developers set it up, the contents of all the user conversations stayed in my server logs. I was unable to convince the chat package maintainers that this was a bug. I ended up doing some fairly kludgy hack to prevent the logging. If somebody happens to have access to a proxy it's logs, he can as well log the request body. Don't get me wrong, I don't want to propagate the use of GET as one and only method for parameter passing. But whatever is transmitted clear text over the wire is subject to inspection of all hops in between. Use SSL if you bother. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Am 04.02.10 00:39, schrieb Paul Rubin: Diez B. Roggischde...@nospam.web.de writes: Of course only information not gathered is really safe information. But every operation that has side-effects is reproducable anyway, and if e.g. your chat-app has a history, you can as well log the parameters. No I can't. The chat-app history would be on the client, not the server, so I'd have no access to it. Put another way: as server operator, I'm like the owner of a coffee shop. I can't stop patrons from recording their own conversations with each other, and it's not even really my business whether they do that. But it would be outrageous for the shop owner to record the conversations of patrons. Which is the exact thing that happens when you use an email-provider with IMAP. Or google wave. Or groups. Or facebook. Or twitter. Which I wouldn't call outrageous. This discussion moves away from the original question: is there anything inherently less secure when using GET vs. POST. There isn't. Users can forge both kind of requests easy enough, whoever sits in the middle can access both, and it's at the discretion of the service provider to only save what it needs to. If you don't trust it, don't use it. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Alan Harris-Reid a...@baselinedata.co.uk writes: As each link contains row-id, I guess there is nothing to stop someone from getting the id from the page source-code. Is it safe to use the above href method if I test for authorised credentials (user/password stored as session variables, perhaps?) before performing the edit/delete action? Well, if it's really ok for them to delete records programmatically even if it's ok for them to delete through the web site. I'd probably encrypt the post parameters if this was a concern. -- http://mail.python.org/mailman/listinfo/python-list
Re: simple and fast platform independent IPC
News123 news...@free.fr writes: Perhaps I'll stick initially with xmlrpc, as it is quite simple, though a little heavy. I just have to see how to deal with servers which are not up, no more up, being restarted. Something wrong wtih nagios? -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Diez B. Roggisch de...@nospam.web.de writes: Also, your claim of it being more risky is simply nonsense. GET is a tiny bit more prone to tinkering by the average user. But calling this less risky is promoting security by obscurity, at most. GET parameters also tend to get recorded in the http logs of web proxies and web servers while POST parameters usually aren't. This was an annoyance in a web chat package I fooled with for a while. Because the package sent user messages by GET, if I ran the software the way the developers set it up, the contents of all the user conversations stayed in my server logs. I was unable to convince the chat package maintainers that this was a bug. I ended up doing some fairly kludgy hack to prevent the logging. -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Diez B. Roggisch de...@nospam.web.de writes: But it would be outrageous for the shop owner to record the conversations of patrons. Which is the exact thing that happens when you use an email-provider with IMAP. Or google wave. Or groups. Or facebook. Or twitter. Which I wouldn't call outrageous. Those are not comparable. IMAP is a storage service, and groups, facebook, and twitter are publishing systems (ok, I've never understood quite what Google Wave is). Yes, by definition, your voice mail provider (like IMAP) has to save recordings of messages people leave you, but that's a heck of a lot different than your phone carrier recording your real-time conversations. Recording live phone conversations by a third party is called a wiretap and doing it without suitable authorization can get you in a heck of a lot of trouble. This discussion moves away from the original question: is there anything inherently less secure when using GET vs. POST. There isn't. Well, the extra logging of GET parameters is not inherent to the protocol, but it's an accidental side effect that server ops may have to watch out for. Users can forge both kind of requests easy enough, whoever sits in the middle can access both, I'm not sure what you mean by that. Obviously if users want to record their own conversations, then I can't stop them, but that's much different than a non-participant in the conversation leaving a recorder running 24/7. Is that so hard to understand? Interception from the middle is addressed by SSL, though that relies on the PKI certificate infrastructure, which while somewhat dubious, is better than nothing. and it's at the discretion of the service provider to only save what it needs to. If you don't trust it, don't use it. I certainly didn't feel that saving or not saving client conversations on the server side was up to my discretion. When I found that the default server configuration caused conversations to be logged then I was appalled. Do you think the phone company has the right to record all your phone calls if they feel like it (absent something like a law enforcement investigation)? What about coffee shops that you visit with your friends? It is not up to their discretion. They have a positive obligation to not do it. If you think they are doing it on purpose without your authorization, you should notify the FBI or your equivalent, not just don't use it. If they find they are doing it inadvertently, they have to take measures to make it stop. That is the situation I found myself in, because of the difference in how servers treat GET vs. POST. -- http://mail.python.org/mailman/listinfo/python-list
Re: Overcoming python performance penalty for multicore CPU
John Nagle na...@animats.com writes: Analysis of each domain is performed in a separate process, but each process uses multiple threads to read process several web pages simultaneously. Some of the threads go compute-bound for a second or two at a time as they parse web pages. You're probably better off using separate processes for the different pages. If I remember, you were using BeautifulSoup, which while very cool, is pretty doggone slow for use on large volumes of pages. I don't know if there's much that can be done about that without going off on a fairly messy C or C++ coding adventure. Maybe someday someone will do that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Overcoming python performance penalty for multicore CPU
John Nagle na...@animats.com writes: There's enough intercommunication between the threads working on a single site that it's a pain to do them as subprocesses. And I definitely don't want to launch subprocesses for each page; the Python load time would be worse than the actual work. The subprocess module assumes you're willing to launch a subprocess for each transaction. Why not just use socketserver and have something like a fastcgi? -- http://mail.python.org/mailman/listinfo/python-list
Re: test -- please ignore
In 87wryumvff@benfinney.id.au Ben Finney ben+pyt...@benfinney.id.au writes: kj no.em...@please.post writes: (my replies in a different comp.lang.python thread are getting rejected by the server; i have no problem posting to alt.test; and i'm trying to toubleshoot the problem further.) Thank you for this explanation. It is important to know that you've tried the less obtrusive diagnostics first. Good hunting. I figured out the immediate reason for the failure: when replying to *certain posts*, my newsreader omits the Newsgroups header from the response. Why it does this is still a mystery to me, but at least now I know what to look out for. Then again, I use the venerable (i.e. decrepit) nn as newsreader, so this discovery probably won't help many of those reading this... -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Am 04.02.10 03:52, schrieb Nobody: On Wed, 03 Feb 2010 14:09:07 -0800, Paul Rubin wrote: Also, your claim of it being more risky is simply nonsense. GET is a tiny bit more prone to tinkering by the average user. But calling this less risky is promoting security by obscurity, at most. GET parameters also tend to get recorded in the http logs of web proxies and web servers while POST parameters usually aren't. More significantly, they'll appear in the Referer: header for any link the user follows from the page, so they're visible to anyone who can get a link to their site onto the page (whethera href=...,img src=... or whatever). Even if this isn't possible at the moment, will you remember to fix it the first time you allow an off-site link? You should assume that anything which goes into a GET request is visible to the entire world. Don't put anything even remotely private in there. You mean like http://www.google.de/search?q=dirty+buttsex ? Which is the key example for when to use GET - non-modifying queries. I agree though that you have to be cautious about that, and using POST makes it easier to do so. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Dreaming of new generation IDE
That is partially why I created this search engine for python, to see what parameters other people feed in. http://nullege.com/ Thank you for excellent effort! I found it very useful and start using it on almost everyday basis. It's much simple to learn from real live examples. Vladimir Ignatov -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Alan Harris-Reid a écrit : I have a web-page where each row in a grid has edit/delete buttons to enable the user to maintain a selected record on another page. The buttons are in the form of a link with href='/item_edit?id=123', but this string appears in the URL and gives clues as to how to bypass the correct sequence of events, and could be risky if they entered the URL directly (especially when it comes to deleting records). Basic HTTP stuff - this is definitely not Python-related. OT Do yourself (and your users / customers / etc) a favor and read the HTTP rfc. GET requests should NOT modify the server state. At least use POST requests for anything that Create/Update/Delete resources. For the record, someone once had serious problems with GET requests deleting records - turned out to be a very bad idea when a robot started following these links... /OT Is there another way of passing a record-id to a method href=/item/23/edit href=/item/edit/23 etc a) without it appearing in the URL? b) without the user being able to fathom-out how to attach which id to which URL? Wrong solution. The correct solution is to 1/ make correct use of the request method (GET and POST at least). 2/ make sure the user performing the action has the permission to do it. 1/ won't protect your data from malicious users, but will at least avoid accidental mistakes. 2/ by checking the user's perms when handling the POST request of course - not by hidding forbidden urls. As each link contains row-id, I guess there is nothing to stop someone from getting the id from the page source-code. Nor even from trying any other id (brute-force attack). Is it safe to use the above href method if I test for authorised credentials (user/password stored as session variables, perhaps?) before performing the edit/delete action? cf above. I am currently using CherryPy 3.2, but I guess the theory could apply to any HTTP framework or web app.. Indeed. /OT -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Diez B. Roggisch de...@nospam.web.de writes: Your web-based chat uses HTTP, no P2P-protocol, and thus the service provider *can* log conversations. I don't say he should, I don't say I want that, I don't say there are now laws that prevent them from doing so, all I say is he *can*. Sure, my complaint is that the default setup caused this to actually happen so lots of people using that software were recording user conversations without realizing it and maybe without caring. This is a bad erosion as I see it. Then stop logging. Or get a hosting-provider that allows you to configure it to strip QUERY_STRINGS from log-entries. And if they refuse to, maybe using POST solves the issue. I did stop logging. There wasn't an issue with the hosting provider since I was running the server myself. But I had to resort to some ugly software kludge to stop logging those particular strings. More frustratingly, I filed a bug report about the issue against the chat software but the conversation was sort of like the one you and I are having now. I just couldn't convince them that there was a problem and that they should change the default. http://www.cyberciti.biz/faq/apache-mod_dumpio-log-post-data/ So what if they run that? That sounds like something someone would have to go out of their way to install and use. It's not the default. Of course if someone is malicious they can do all sorts of nasty stuff. A coffeeshop that wanted to mess with me on purpose wouldn't have to do high tech crap like recording my conversations--they could just poison my coffee. I have to trust them to not do this on purpose, but then I see a situation where their coffee sweetener accidentaly has a harmful chemical, so of course I'd ask them to do something about it. So, for the umpteenth time: data sent over the wire can be recorded. And for the umpteenth time, I'm less concerned about can be than is. POST isn't logged unless you go to some lengths to have it logged. GET is logged unless you go to some lengths to prevent it. It's not enough in a software deployment to only consider what actions are possible. It's important to make sure that the default actions are the right ones. If they have a positive obligation not to do it, it doesn't matter if they run their service over GET or POST. GET makes it harder for them to fulfill their obligations. As a security nerd, I saw what was happening and took measures against it, but a more typical operator might never notice or care. There is also the matter of the referer header which an anon mentioned, though it didn't apply to this particular situation because of how the application worked. -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid writes: The buttons are in the form of a link with href='/item_edit?id=123', ...At least use POST requests for anything that Create/Update/Delete resources. There's also the issue that a user can change 123 to 125 and possibly mess with someone else's resource, unless you use some server side authentication. Or just seeing how often the numbers change could reveal patterns about what other users are doing. I always think it's best to encrypt anything sensitive like that, to avoid leaking any info. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dreaming of new generation IDE
http://sourceforge.net/mailarchive/message.php?msg_name=9c768dc61001121642t5bd1a7ddmd1fe9e088e1d9...@mail.gmail.com Thanks a lot! That is a great reference (a must read for everybody interested). Reading just this: Internally at Google we have a language-neutral representation shared by all our language analyzers, make me jumping ;-) Googlers can't be wrong. Vladimir Ignatov -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Paul Rubin a écrit : Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid writes: The buttons are in the form of a link with href='/item_edit?id=123', ...At least use POST requests for anything that Create/Update/Delete resources. There's also the issue that a user can change 123 to 125 and possibly mess with someone else's resource, unless you use some server side authentication. What I said IIRC. Or just seeing how often the numbers change could reveal patterns about what other users are doing. I always think it's best to encrypt anything sensitive like that, to avoid leaking any info. Depends on how sensitive it really is. -- http://mail.python.org/mailman/listinfo/python-list
Common area of circles
Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. hope the picture makes it clear http://imagebin.us/images/p5qeo7hgc3547pnyrb6.gif -- http://mail.python.org/mailman/listinfo/python-list
Re: Overcoming python performance penalty for multicore CPU
On Feb 4, 10:46 am, John Nagle na...@animats.com wrote: There's enough intercommunication between the threads working on a single site that it's a pain to do them as subprocesses. And I definitely don't want to launch subprocesses for each page; the Python load time would be worse than the actual work. The subprocess module assumes you're willing to launch a subprocess for each transaction. You could perhaps use a process pool inside each domain worker to work on the pages? There is multiprocessing.Pool and other implementations. For examples, in this library, you can s/ThreadPool/ProcessPool/g and this example would work: http://www.onideas.ws/stream.py/#retrieving- web-pages-concurrently. If you want to DIY, with multiprocessing.Lock/Pipe/Queue, I don't understand why it would be more of a pain to write your threads as processes. // aht http://blog.onideas.ws -- http://mail.python.org/mailman/listinfo/python-list
learn Sql Server 2000 2005 2008
www.sqlserver.learn.net.in http://www.sqlserver.learn.net.in/ sql server http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server sql server 2005 http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+20\ 05 sql server 2008 http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+20\ 08 sql server 2000 http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+20\ 00 microsoft sql server http://www.sqlserver.learn.net.in/videos/index.php?search=microsoft+sql\ +server sql server management studio http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+ma\ nagement+studio microsoft sql server 2005 http://www.sqlserver.learn.net.in/videos/index.php?search=microsoft+sql\ +server+2005 ms sql server http://www.sqlserver.learn.net.in/videos/index.php?search=ms+sql+server\ microsoft sql server 2000 http://www.sqlserver.learn.net.in/videos/index.php?search=microsoft+sql\ +server+2000 sql server 2005 download http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+20\ 05+download sql server hosting http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+ho\ sting microsoft sql server 2008 http://www.sqlserver.learn.net.in/videos/index.php?search=microsoft+sql\ +server+2008 sql server jobs http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+jo\ bs sql server stored procedure http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+st\ ored+procedure sql server 2005 tutorial http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+20\ 05+tutorial sql server query http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+qu\ ery sql server reporting services http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+re\ porting+services sql server tutorial http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+tu\ torial ms sql server 2005 http://www.sqlserver.learn.net.in/videos/index.php?search=ms+sql+server\ +2005 download sql server http://www.sqlserver.learn.net.in/videos/index.php?search=download+sql+\ server microsoft sql server management studio express http://www.sqlserver.learn.net.in/videos/index.php?search=microsoft+sql\ +server+management+studio+express sql server 2003 http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+20\ 03 sql server enterprise manager http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+en\ terprise+manager sql server integration services http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+in\ tegration+services sql server backup http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+ba\ ckup sql server data types http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+da\ ta+types sql server dba http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+db\ a sql server management http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+ma\ nagement sql server replication http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+re\ plication microsoft sql server 2005 express edition http://www.sqlserver.learn.net.in/videos/index.php?search=microsoft+sql\ +server+2005+express+edition ms sql server 2000 http://www.sqlserver.learn.net.in/videos/index.php?search=ms+sql+server\ +2000 mssql server http://www.sqlserver.learn.net.in/videos/index.php?search=mssql+server sql server 2005 reporting services http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+20\ 05+reporting+services sql server client http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+cl\ ient sql server cursor http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+cu\ rsor sql server database http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+da\ tabase sql server performance http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+pe\ rformance sql server profiler http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+pr\ ofiler sql server training http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+tr\ aining ms sql server 2008 http://www.sqlserver.learn.net.in/videos/index.php?search=ms+sql+server\ +2008 sql server 2008 developer edition http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+20\ 08+developer+edition sql server developer http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+de\ veloper sql server manager http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+ma\ nager sql server trigger http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+tr\ igger sql server update http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server+up\ date sql server2005 http://www.sqlserver.learn.net.in/videos/index.php?search=sql+server200\ 5 microsoft sql server download
Building a multiline string
Hello Maybe that's already documented, but it seems the parser accepts to build a long string w/o really using the first method: # Method1 x = line1 + \ # cannot use comments! line2+ \ line3 and instead using a list with one element like this: # Method2 x = [ line1 # can use comments line2 line3 ][0] Or: # Method3 x = ( line1 # can use comments line2 line3 ) (Not that I don't want new lines in the strings) Now should I be using method 2 or 3 in production code? -- Elias -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand anand.shash...@gmail.com wrote: Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. How is this at all specific to Python? This also sounds suspiciously like homework, which you should know this list is unlikely to give direct answers to, though you might be able to get a few pointers or some general suggestions. Cheers, Chris -- Back to toiling away on CSE 105 HW#3 http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
I wanted some general suggestion/tips only On Thu, Feb 4, 2010 at 5:11 PM, Chris Rebert c...@rebertia.com wrote: On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand anand.shash...@gmail.com wrote: Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. How is this at all specific to Python? This also sounds suspiciously like homework, which you should know this list is unlikely to give direct answers to, though you might be able to get a few pointers or some general suggestions. Cheers, Chris -- Back to toiling away on CSE 105 HW#3 http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
I'm not sure what you're after. Are you after how to calculate the area? Or are you trying to graph it? Or an analytical solution? What do you mean by take out the intersection? -Xav On Thu, Feb 4, 2010 at 9:47 PM, Shashwat Anand anand.shash...@gmail.comwrote: I wanted some general suggestion/tips only On Thu, Feb 4, 2010 at 5:11 PM, Chris Rebert c...@rebertia.com wrote: On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand anand.shash...@gmail.com wrote: Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. How is this at all specific to Python? This also sounds suspiciously like homework, which you should know this list is unlikely to give direct answers to, though you might be able to get a few pointers or some general suggestions. Cheers, Chris -- Back to toiling away on CSE 105 HW#3 http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to guard against bugs like this one?
Tim Golden wrote: On 03/02/2010 16:17, kj wrote: Boy, that was dumb of me. The above apology was meant for Stephen Hansen, not Steve Holden. I guess this is now a meta-apology... (Sheesh.) You see? That's what I like about the Python community: people even apologise for apologising :) QOTW? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. On Thu, Feb 4, 2010 at 5:24 PM, Xavier Ho cont...@xavierho.com wrote: I'm not sure what you're after. Are you after how to calculate the area? Or are you trying to graph it? Or an analytical solution? What do you mean by take out the intersection? -Xav On Thu, Feb 4, 2010 at 9:47 PM, Shashwat Anand anand.shash...@gmail.comwrote: I wanted some general suggestion/tips only On Thu, Feb 4, 2010 at 5:11 PM, Chris Rebert c...@rebertia.com wrote: On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand anand.shash...@gmail.com wrote: Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. How is this at all specific to Python? This also sounds suspiciously like homework, which you should know this list is unlikely to give direct answers to, though you might be able to get a few pointers or some general suggestions. Cheers, Chris -- Back to toiling away on CSE 105 HW#3 http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Paul Rubin wrote: Diez B. Roggisch de...@nospam.web.de writes: But it would be outrageous for the shop owner to record the conversations of patrons. Which is the exact thing that happens when you use an email-provider with IMAP. Or google wave. Or groups. Or facebook. Or twitter. Which I wouldn't call outrageous. Those are not comparable. IMAP is a storage service, and groups, facebook, and twitter are publishing systems (ok, I've never understood quite what Google Wave is). Yes, by definition, your voice mail provider (like IMAP) has to save recordings of messages people leave you, but that's a heck of a lot different than your phone carrier recording your real-time conversations. Recording live phone conversations by a third party is called a wiretap and doing it without suitable authorization can get you in a heck of a lot of trouble. Unless you happen to be following the illegal instructions of the President of the United States, in which case Congress will retro-actively alter the law to void your offenses and provide you with legal immunity for your wrong-doing. Assuming you are a large telephone company and not a private individual. This discussion moves away from the original question: is there anything inherently less secure when using GET vs. POST. There isn't. Well, the extra logging of GET parameters is not inherent to the protocol, but it's an accidental side effect that server ops may have to watch out for. Users can forge both kind of requests easy enough, whoever sits in the middle can access both, I'm not sure what you mean by that. Obviously if users want to record their own conversations, then I can't stop them, but that's much different than a non-participant in the conversation leaving a recorder running 24/7. Is that so hard to understand? Interception from the middle is addressed by SSL, though that relies on the PKI certificate infrastructure, which while somewhat dubious, is better than nothing. and it's at the discretion of the service provider to only save what it needs to. If you don't trust it, don't use it. I certainly didn't feel that saving or not saving client conversations on the server side was up to my discretion. When I found that the default server configuration caused conversations to be logged then I was appalled. Do you think the phone company has the right to record all your phone calls if they feel like it (absent something like a law enforcement investigation)? What about coffee shops that you visit with your friends? It is not up to their discretion. They have a positive obligation to not do it. If you think they are doing it on purpose without your authorization, you should notify the FBI or your equivalent, not just don't use it. If they find they are doing it inadvertently, they have to take measures to make it stop. That is the situation I found myself in, because of the difference in how servers treat GET vs. POST. A lot will depend on the terms of service of the network supply contract. Most vendors take pains to ensure that such innocent logging (i.e. the maintenance by their servers of logging information, which may under subpoena or similar legal coercion be given up to law enforcement authorities as business records) is permitted. If you have signed the contract, then they have the right to log that data. Caveat emptor. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Building a multiline string
Just for the record: Neither of the below methods actually produce a multiline string. They only spread a string containing one line over multiple lines of source code. lallous wrote: Maybe that's already documented, but it seems the parser accepts to build a long string w/o really using the first method: # Method1 x = line1 + \ # cannot use comments! line2+ \ line3 Well, obviously you can't use comments like that there. The point of the backslash is that it continues the current logical line over the _immediately_ _following_ newline. If anything follows, that obviously doesn't work. and instead using a list with one element like this: # Method2 x = [ line1 # can use comments line2 line3 ][0] This basically makes use of the fact that this is one string and not four strings. # Method3 x = ( line1 # can use comments line2 line3 ) This uses the same, only that this time it uses brackets which cause an expression to extend to multiple lines. (Not that I don't want new lines in the strings) You don't not want or you don't want newlines? Depending on that, you could also do this: # method 4 x = line1\ line2\ line3 or maybe # method 5 x = line1 line2 line3 Now should I be using method 2 or 3 in production code? I'd go for 3 or 4. 2 is basically a hack (you could do the same with a dictionary, or a tuple, not only a list). 1 will actually create strings and then concatenate them (unless Python is smart enough to optimize that), but it allows adding expressions in the middle. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
Shashwat Anand: Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. I can see two possible solutions, both approximate. In both solutions you first look if there are a pair of circles that don't intersect, in this case the intersect area is zero. You also remove all circles fully contained in another circle. The first strategy is easy to do, but it probably leads to a lower precision. Then you can sample randomly many times the rectangular area that surely contains all circles. You count how many of those random points are inside all circles. This gives you an approximate area of their intersection. Increasing the points numbers slowly increases the result precision. The second strategy is more complex. You convert your circles into polygons with a fixed number of vertices (like 50 or 100 or 1000 or more. This number is constant even if the circles don't have all the same radius). So you can turn this circle into a simple mesh of triangles (all vertices are on the circumference). Then you subtract the second polygonalized circle, this can create a hole and split triangles in pieces, and so on with successive circles. At the end you can compute the total area of the triangles left. This is doable, but you need time to do implement this. The advantage is that the numerical precision of the result is probably higher. If you implement this second solution you can implement the first one too, and use it as a test to avoid bugs. Visualizing the triangles with Pygame or MatPlotLib can be useful to look for bugs. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
I needed 6 decimal places of accuracy, so first way of solution will not work for my case. However, your second strategy seems promising. Working on it. Thanks :D ~l0nwlf On Thu, Feb 4, 2010 at 5:49 PM, Bearophile bearophileh...@lycos.com wrote: Shashwat Anand: Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. I can see two possible solutions, both approximate. In both solutions you first look if there are a pair of circles that don't intersect, in this case the intersect area is zero. You also remove all circles fully contained in another circle. The first strategy is easy to do, but it probably leads to a lower precision. Then you can sample randomly many times the rectangular area that surely contains all circles. You count how many of those random points are inside all circles. This gives you an approximate area of their intersection. Increasing the points numbers slowly increases the result precision. The second strategy is more complex. You convert your circles into polygons with a fixed number of vertices (like 50 or 100 or 1000 or more. This number is constant even if the circles don't have all the same radius). So you can turn this circle into a simple mesh of triangles (all vertices are on the circumference). Then you subtract the second polygonalized circle, this can create a hole and split triangles in pieces, and so on with successive circles. At the end you can compute the total area of the triangles left. This is doable, but you need time to do implement this. The advantage is that the numerical precision of the result is probably higher. If you implement this second solution you can implement the first one too, and use it as a test to avoid bugs. Visualizing the triangles with Pygame or MatPlotLib can be useful to look for bugs. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
read a process output with subprocess.Popen
Hi, I m trying a read the output of a process which is running continuously with subprocess.Popen. However the readline() method hangs for the process to finish. Please let me know if the following code can be made to work with subprocess.Popen with threads or queues. I tried a lot of methods but to no avail. It would be great if someone can make it work. import subprocess p1 = subprocess.Popen('tail -f /var/log/ messages',stdout=subprocess.PIPE,shell=True) p2 = subprocess.Popen('grep something',stdin=p1.stdout,stdout=subprocess.PIPE,shell=True) while 1: line = p2.stdout.readline() print line Thanks, ~Ashok. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Ruby
On Feb 4, 1:03 am, John Bokma j...@castleamber.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: I can explain all of Python in an hour; OK, in that case I would say give it a go. Put it on YouTube, or write a blog post about it (or post it here). I am sure you will help a lot of people that way. Someone already did: Advanced Python or Understanding Python http://video.google.com/videoplay?docid=7760178035196894549 (76 minutes). Worth watching. Regards, -- Marius Gedminas -- http://mail.python.org/mailman/listinfo/python-list
Re: Building a multiline string
lallous wrote: Hello Maybe that's already documented, but it seems the parser accepts to build a long string w/o really using the first method: # Method1 x = line1 + \ # cannot use comments! line2+ \ line3 and instead using a list with one element like this: # Method2 x = [ line1 # can use comments line2 line3 ][0] Or: # Method3 x = ( line1 # can use comments line2 line3 ) (Not that I don't want new lines in the strings) Now should I be using method 2 or 3 in production code? I should have thought it was pretty obvious that method 2 creates a list and then performs an indexing operation on it. These are completely unnecessary operations, which are avoided in method 3 which is a simple parenthesised expression. So why anyone would want to adopt method 2, which is also mess clear as source code, is beyond me. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Repeat an exception
MRAB wrote: In other words: for attempt in range(2): try: spanish_field = translate(english_field, lang_to='es', lang_from='en') break except TranslationError: pass else: # Didn't break out of the loop, therefore not successful. print Translation failed What the hell is this 'for else' loop !! :D First time I see this statement for years. I'd never thought I'd still learn something that basic. My first impression is that the mechansim is not that obvious. MRAB's need for a comment tends to confirm this. I'll try to remember that anyway. Nice addition. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Building a multiline string
On 02/04/2010 12:34 PM, lallous wrote: Now should I be using method 2 or 3 in production code? Another way... depending on what you are using the string for, of course. If it's an HTML/XML/SQL/whatever piece of code: from textwrap import dedent sql = dedent( ... SELECT * ...FROM table ... WHERE foo=bar ... ) print sql SELECT * FROM table WHERE foo=bar And if you don't want the starting/ending newlines: sql = dedent(\ ... SELECT * ...FROM table ... WHERE foo=bar\ ... ) print sql SELECT * FROM table WHERE foo=bar I use this sometimes to keep both python and the embedded code readable while preserving indentation. -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
It's an interesting problem. Never thought it was this difficult. I can't account for all geometrical enumerations, but assuming all 4 circles intersect, here's the solution for this particular senario. It's probably not going to be useful to you since you're working on geometrical approximations now, but it is precise to the exact value. I don't have it worked out here, but it goes like this. 1. Find the area covered by all 4 circles, unioned. Method here: http://stackoverflow.com/questions/1667310/combined-area-of-overlapping-circles 2: Follow this chart I made up: http://xavierho.com/media/images/Misc/IntersectionOfFourCircles.png And there you go. I'm sure there are way better, faster ways, and covers a lot more senarios, but this is the best I can come up with, without counting the rasterised pixels ratio =P. I like Bearophile's solution. Have fun! Cheers, Xav On Thu, Feb 4, 2010 at 10:27 PM, Shashwat Anand anand.shash...@gmail.comwrote: I needed 6 decimal places of accuracy, so first way of solution will not work for my case. However, your second strategy seems promising. Working on it. Thanks :D ~l0nwlf On Thu, Feb 4, 2010 at 5:49 PM, Bearophile bearophileh...@lycos.comwrote: Shashwat Anand: Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. I can see two possible solutions, both approximate. In both solutions you first look if there are a pair of circles that don't intersect, in this case the intersect area is zero. You also remove all circles fully contained in another circle. The first strategy is easy to do, but it probably leads to a lower precision. Then you can sample randomly many times the rectangular area that surely contains all circles. You count how many of those random points are inside all circles. This gives you an approximate area of their intersection. Increasing the points numbers slowly increases the result precision. The second strategy is more complex. You convert your circles into polygons with a fixed number of vertices (like 50 or 100 or 1000 or more. This number is constant even if the circles don't have all the same radius). So you can turn this circle into a simple mesh of triangles (all vertices are on the circumference). Then you subtract the second polygonalized circle, this can create a hole and split triangles in pieces, and so on with successive circles. At the end you can compute the total area of the triangles left. This is doable, but you need time to do implement this. The advantage is that the numerical precision of the result is probably higher. If you implement this second solution you can implement the first one too, and use it as a test to avoid bugs. Visualizing the triangles with Pygame or MatPlotLib can be useful to look for bugs. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
On 2/4/2010 7:05 AM, Shashwat Anand wrote: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. There is a method for calculating the area of a polygon by traversing its boundary. I forget the formula, but you should be able to find it. So *if* you can find the arcs that bound the area, you can approximate each by a series of short lines and apply the polygon method. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
thanks, all of you On Thu, Feb 4, 2010 at 7:31 PM, Terry Reedy tjre...@udel.edu wrote: On 2/4/2010 7:05 AM, Shashwat Anand wrote: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. There is a method for calculating the area of a polygon by traversing its boundary. I forget the formula, but you should be able to find it. So *if* you can find the arcs that bound the area, you can approximate each by a series of short lines and apply the polygon method. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: YAML (was: Python and Ruby)
In article 87eil1ddjp.fsf...@castleamber.com, John Bokma j...@castleamber.com wrote: Lou Pecora pec...@anvil.nrl.navy.mil writes: That's a pretty accurate description of how I transitioned to Python from C and Fortran. Not C, but C++ (but there are also C implementations): YAML, see: http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument I use YAML now and then with Perl for both reading/writing data and for debugging purposes (YAML is quite human readable, for programmers at least) Of course there is also YAML support for Python: http://pyyaml.org/. Well, that looks a bit more complicated than I would like, but maybe it's doing more stuff than I can grok. Here's what I needed and how I did it in Python: # Make some variables x=1.234e-8 y=2 astr=An output string...whatever z=4.5+1j*1.3456 # a complex number # Output them to a file already opened as fp outlist=[x, y, astr, z] repvars= repr(outlist)+\n fp.write(repvars) # Reading same list in: instr=fp.readline() inlist=eval(instr) x1,y1,astr1,z1= inlist That's what I needed. 3 lines to write or read a inhomogeneous collection of variables. I can add more variables, shuffle the order, whatever without messing with formatting, etc. That's pretty easy for me and it's easy for anyone to see and understand what's being done. Not trying to start an argument, just showing how the former messasge I was replying to made a good point about Python's way of doing things and the effort to shake off old habits from other languages. -- -- Lou Pecora -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Ruby
In article 7x8wb9j4r2@ruckus.brouhaha.com, Paul Rubin no.em...@nospam.invalid wrote: Lou Pecora pec...@anvil.nrl.navy.mil writes: after much noodling around and reading it hit me that I could just put all that output of different types of variables into a list, hit it with a repr() function to get a string version, and write the string to a file -- no formatting necessary-- three lines of code. Later reading in the string version (no formatting necessary), and hitting it with an eval() function returned all the values I originally had in those variables. How simple, but beautiful. FYI: I do that too sometimes, but in general using repr/eval that way is poor style and not very reliable. It's better to use the pickle module, which is intended for that sort of thing, or the json module if your datatypes are suitable and you want to follow a semi-standard. Yeah, I should look into pickle. Haven't messed with that. Most of what I do is numerical calculations for my consumption/research so quick and easy comes first. Thanks for the hint. -- -- Lou Pecora -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with __init__.py in Python3.1
Thanks, I read it and try to put my code in the correct form, but now give me another error, inside the Writer Package says: ValueError: Attempted relative import in non-package, if somebody knows a clue of how fix it i will glad to read opinions. [?] On Thu, Feb 4, 2010 at 2:11 AM, Gabriel Genellina gagsl-...@yahoo.com.arwrote: En Thu, 04 Feb 2010 01:00:56 -0300, Hidura hid...@gmail.com escribió: Good evening list, I have a really big trouble with the imports in the 3.1 version(Notes: In the older 2.64 theres no problems), I have two packages, the first package Utilities who contains Writer the second package, Writers contain the module tagmanip(What is imported in the best way inside the __init__.py of the Writer), when i make the import inside the writer everything is ok, but from the Utilities package the errors says: ImportError: No module named tagsmanip. I don't understand why this is happening, if somebody could help me i will glad to hear any suggestion. In Python 3.x, absolute import is enabled by default (2.6 uses a mix of relative and absolute imports). To import sibling modules in a package, or modules in a subpackage, you have to use relative imports: from . import tagmanip from .Writers import tagmanip See PEP328 http://www.python.org/dev/peps/pep-0328/ -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- Hidura 330.png-- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
On 2/4/2010 7:05 AM, Shashwat Anand wrote: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. A brute force approach - create a grid of small squares and calculate which squares are in all circles. I don't know whether it is any better than monte-carlo: for two circles, delta=0.001 takes about a minute and delta=0.0001 is still running after 30 minutes :-) 1.22 1.2281 1.2283479 -- import math class Circle: def __init__(self, x, y, r=1): self.x = float(x) self.y = float(y) self.r = float(r) def contains(self, a, b): return math.sqrt((self.x-a)**2 + (self.y-b)**2) = self.r class Grid: def __init__(self, circles): self.X1 = min(c.x-c.r for c in circles) self.Y1 = max(c.y+c.r for c in circles) self.X2 = max(c.x+c.r for c in circles) self.Y2 = min(c.y-c.r for c in circles) self.circles = circles def iter_boxes(self, delta): X2 = self.X2 Y2 = self.Y2 a = self.X1 while a X2: a += delta b = self.Y1 while b Y2: b -= delta #print a, b yield a, b def intersection(self, delta=0.1): S = 0 s = delta**2 #box area circles = self.circles for a, b in self.iter_boxes(delta): if all(c.contains(a, b) for c in circles): S += s return S c = Circle(0, 1) assert c.contains(0, 1) assert c.contains(0, 1.5) assert c.contains(math.sqrt(2)/2, math.sqrt(2)/2) assert c.contains(0, 2) assert not c.contains(0, 2.01) assert not c.contains(0, 2.1) assert not c.contains(0, 3) circles = [ Circle(0, 0), Circle(0, 1), ] g = Grid(circles) print '-'*30 print g.intersection() print g.intersection(0.01) print g.intersection(0.001) print g.intersection(0.0001) -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Repeat an exception
Jean-Michel Pichavant wrote: MRAB wrote: In other words: for attempt in range(2): try: spanish_field = translate(english_field, lang_to='es', lang_from='en') break except TranslationError: pass else: # Didn't break out of the loop, therefore not successful. print Translation failed What the hell is this 'for else' loop !! :D First time I see this statement for years. I'd never thought I'd still learn something that basic. My first impression is that the mechansim is not that obvious. MRAB's need for a comment tends to confirm this. I'll try to remember that anyway. Nice addition. The comment is there for the OP. _I_ don't need it! :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Repeat an exception
On Thu, Feb 4, 2010 at 4:59 AM, Jean-Michel Pichavant jeanmic...@sequans.com wrote: What the hell is this 'for else' loop !! :D First time I see this statement for years. I'd never thought I'd still learn something that basic. Its one of the least used constructs in Python, I think, and leads to periodic statements like this on the list where people who think they know all about Python suddenly see it and go WTF :) But in Python, all loops have an else clause that is fired when the loop terminates-- but *only* if it terminates normally, where 'normally' is basically, 'if you don't use break to exit the loop prematurely'. It allows you to do certain things in a way which is (arguably, and I so don't want to start an argument about this) a bit cleaner, where the normal method would require a flag or some such. For example, if you need want to loop over a sequence to test to see if they all match some criteria, you can use a for..else, or some flag variable. --S -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
Gerard Flanagan wrote: On 2/4/2010 7:05 AM, Shashwat Anand wrote: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. A brute force approach - create a grid of small squares and calculate which squares are in all circles. I don't know whether it is any better than monte-carlo: That's just what the monte-carlo method is -- except the full family of monte-carlo methods can be quite sophisticated, including being more general (pseudo or quasi random points instead of a regular grid) and can provide a theoretical basis for calculating the rate of convergence, and so on. Gary Herron for two circles, delta=0.001 takes about a minute and delta=0.0001 is still running after 30 minutes :-) 1.22 1.2281 1.2283479 -- import math class Circle: def __init__(self, x, y, r=1): self.x = float(x) self.y = float(y) self.r = float(r) def contains(self, a, b): return math.sqrt((self.x-a)**2 + (self.y-b)**2) = self.r class Grid: def __init__(self, circles): self.X1 = min(c.x-c.r for c in circles) self.Y1 = max(c.y+c.r for c in circles) self.X2 = max(c.x+c.r for c in circles) self.Y2 = min(c.y-c.r for c in circles) self.circles = circles def iter_boxes(self, delta): X2 = self.X2 Y2 = self.Y2 a = self.X1 while a X2: a += delta b = self.Y1 while b Y2: b -= delta #print a, b yield a, b def intersection(self, delta=0.1): S = 0 s = delta**2 #box area circles = self.circles for a, b in self.iter_boxes(delta): if all(c.contains(a, b) for c in circles): S += s return S c = Circle(0, 1) assert c.contains(0, 1) assert c.contains(0, 1.5) assert c.contains(math.sqrt(2)/2, math.sqrt(2)/2) assert c.contains(0, 2) assert not c.contains(0, 2.01) assert not c.contains(0, 2.1) assert not c.contains(0, 3) circles = [ Circle(0, 0), Circle(0, 1), ] g = Grid(circles) print '-'*30 print g.intersection() print g.intersection(0.01) print g.intersection(0.001) print g.intersection(0.0001) -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Refreshing of urllib.urlopen()
On Wed, 03 Feb 2010 21:33:08 -0600, Michael Gruenstaeudl wrote: I am fairly new to Python and need advice on the urllib.urlopen() function. The website I am trying to open automatically refreshes after 5 seconds and remains stable thereafter. With urllib.urlopen().read() I can only read the initial but not the refreshed page. How can I access the refreshed page via urlopen().read()? I have already tried to intermediate with time.sleep() before invoking .read() (see below), but this does not work. In all probability, the server is instructing the browser to load a different URL via either a Refresh: header or a meta http-equiv=refresh tag in the page. You will have to retrieve that information then issue a request for the new URL. It might even be redirecting via JavaScript, in which case, you lose (it's possible to handle this case, but it's difficult). -- http://mail.python.org/mailman/listinfo/python-list
Re: read a process output with subprocess.Popen
On Thu, 04 Feb 2010 04:28:20 -0800, Ashok Prabhu wrote: I m trying a read the output of a process which is running continuously with subprocess.Popen. However the readline() method hangs for the process to finish. Please let me know if the following code can be made to work with subprocess.Popen with threads or queues. I tried a lot of methods but to no avail. It would be great if someone can make it work. This is an issue with grep, not Python per se. By default, stdout (in the C library) is line-buffered if it refers to a TTY, and block-buffered otherwise (e.g. if it refers to a pipe). grep doesn't change the default buffering, so when it's stdout is a pipe, its output is written in 4K blocks. If you only need this to work with GNU grep, you can use the --line-buffered switch to force stdout to be flushed after each line. If it needs to be portable, you can implement the grep part in Python (i.e. read p1.stdout and ignore any lines which don't contain a given string or which don't match a given regex). -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Diez B. Roggisch de...@nospam.web.de writes: Am 04.02.10 01:42, schrieb John Bokma: [..] Maybe you should think about what happens if someone posts: img src=http://example.com/item_delete?id=123; to a popular forum... And the difference to posting from urrlib2 import open from urllib import encode open(http://example.com/item_delete;, data=encode([(id, 123)])) to that same public hacker forum is exactly what? Imagine that a user of example.com, logged in at example.com (i.e. with a valid session ID in a cookie), visits the aforementioned (by me) forum, and that he has an item 123. It will be deleted. If your webapp happens to allow item_delete to be called without authentication authorization, then *that's* your problem. You now understand that *with* a a a GET request can be *still* harmful? -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
Gary Herron wrote: Gerard Flanagan wrote: A brute force approach - create a grid of small squares and calculate which squares are in all circles. I don't know whether it is any better than monte-carlo: That's just what the monte-carlo method is -- except the full family of monte-carlo methods can be quite sophisticated, including being more general (pseudo or quasi random points instead of a regular grid) and can provide a theoretical basis for calculating the rate of convergence, and so on. I would have said a Monte Carlo method necessarily involves random sampling in some shape or form, no? (Casinos, Chance etc..) And as I've previously understood Monte Carlo Integration, the technique involves rather the ratio hits/total sample rather than the sum of small areas. That's how I remember it, at least - it's been a while though. Regards G.F -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
Shashwat Anand wrote: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. You start with a list of circles, each having center (a,b), and radius (r). As you stated the problem, r is always 1, but I'll keep the algorithm general. This is untested, and probably contains typos, at least. I would do it with successively smaller squares. A square can be described using center coordinates (x,y) , and length (s) of a side. Each square can have three states: not included, partially included, and fully included. You build a list of squares, starting with one, the bounding square for the first circle. For each square in the list, you go through all the circles (each with center a,b, and radius r), and for each circle decide if the square is entirely within the circle, or partially. If it's fully included in all of them, you add its area to the the accumulator, and drop it from your list. if it's not included at all in one of them, you just drop it from the list. (Note, be careful about modifying a list you're iterating through -- make a copy) After a pass through the list, the accumulator is a lower-bound for the area, and the accumulator plus the areas of all the squares is an upper bound. If these are close enough together, you terminate. Otherwise you take the remaining squares in the list, split each into four pieces, and end up with a list 4 times as long. And repeat the loop, checking each square against each circle. The only remaining question is how you decide for a given circle and a given square which of the three states it's in. And it turns out you can be pretty approximate in this, and it'll still converge. So you can take a distance between (a,b) and (x,y), and compare it to r-s/2 and to r+(s*0.707106781187). If it's greater than r+s*0.707106781187, no intersection. If it's less than r-s/2, then the square's entirely inside. Note that I used 0.707106781187 above, but you'd actually use sqr(0.5) to whatever precision you needed. And if it's convenient to round it, round it upwards; again it won't affect the result. I doubt if it would matter in Python code, but you could even do the whole thing in integers (avoiding the sqrt for distance calc), if you were careful about the bounding formulas. That's premature optimization, however. HTH, DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Ruby
Marius Gedminas mged...@gmail.com writes: On Feb 4, 1:03 am, John Bokma j...@castleamber.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: I can explain all of Python in an hour; OK, in that case I would say give it a go. Put it on YouTube, or write a blog post about it (or post it here). I am sure you will help a lot of people that way. Someone already did: Advanced Python or Understanding Python http://video.google.com/videoplay?docid=7760178035196894549 (76 minutes). Worth watching. Thanks, I will. And let you know if it succeeds at explain all of Python in 76 minutes. It's not a fair test, since I am not new to Python, but let me see first ;-) -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: YAML
Lou Pecora pec...@anvil.nrl.navy.mil writes: In article 87eil1ddjp.fsf...@castleamber.com, John Bokma j...@castleamber.com wrote: Lou Pecora pec...@anvil.nrl.navy.mil writes: That's a pretty accurate description of how I transitioned to Python from C and Fortran. Not C, but C++ (but there are also C implementations): YAML, see: http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument I use YAML now and then with Perl for both reading/writing data and for debugging purposes (YAML is quite human readable, for programmers at least) Of course there is also YAML support for Python: http://pyyaml.org/. Well, that looks a bit more complicated than I would like, but maybe it's doing more stuff than I can grok. Here's what I needed and how I did it in Python: # Make some variables x=1.234e-8 y=2 astr=An output string...whatever z=4.5+1j*1.3456 # a complex number # Output them to a file already opened as fp outlist=[x, y, astr, z] repvars= repr(outlist)+\n fp.write(repvars) # Reading same list in: instr=fp.readline() inlist=eval(instr) x1,y1,astr1,z1= inlist That's what I needed. 3 lines to write or read a inhomogeneous collection of variables. I can add more variables, shuffle the order, whatever without messing with formatting, etc. That's pretty easy for me and it's easy for anyone to see and understand what's being done. Not trying to start an argument, just showing how the former messasge I was replying to made a good point about Python's way of doing things and the effort to shake off old habits from other languages. My C++ is rusty to say the least, so I can't give you an example in C++, and the C++ version will be longer than the Python version for sure. I use YAML, YAML::Syck to be precise, now and then in Perl. In Perl, if $data is a reference to an arbitrary (complex) datastructure: DumpFile( 'filename', $data ); writes it out and $data = LoadFile( 'filename' ); reads it back in. Since YAML is to some extent human readable, I now and then use it for debugging purposes over Data::Dumper, also because the output is more compact, e.g. die Dump $data; Personally I think it's good to be aware of YAML, since it's supported by several languages and it should in general be possible to exchange the generated YAML between them. -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters in URL
Am 04.02.10 18:22, schrieb John Bokma: Diez B. Roggischde...@nospam.web.de writes: Am 04.02.10 01:42, schrieb John Bokma: [..] Maybe you should think about what happens if someone posts: img src=http://example.com/item_delete?id=123; to a popular forum... And the difference to posting from urrlib2 import open from urllib import encode open(http://example.com/item_delete;, data=encode([(id, 123)])) to that same public hacker forum is exactly what? Imagine that a user of example.com, logged in at example.com (i.e. with a valid session ID in a cookie), visits the aforementioned (by me) forum, and that he has an item 123. It will be deleted. The webapp must be actually preventing the processing of GET-requests for the aciton in question. This isn't the case by default for many of them, in fact at least e.g. TurboGears, as well as PHP offer you ways to treat GET and POSTvars the exact same way. So unless the programmer is aware of this potential problem, it won't help. And in the same way one can embed a form with a post-action that leads to the full http://example.com-url into an external page. So it is equally as dangerous. Yes, links are easier, no doubt about that. But POST doesn't magically make you safe from those kinds of attacks. The only way to prevent this are short-lived sessions, or action-tokens of some kind, as Paul mentioned before. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Selenium/SauceLabs OpenSpace at Pycon
For those who are interested, the Sauce Labs team, http://saucelabs.com/about/team, is hosting two free tutorial open space sessions at Pycon in Atlanta. [Aahz] Congrats on the new job! Thanks. I'm really enjoying working with Jim Baker and Frank Wierzbicki. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
On 2/4/2010 7:05 AM, Shashwat Anand wrote: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. How much accuracy do you need? How fast does the algorithm need to be? How many circles are typically involved? Is the intersection necessarily non-empty for the configurations of circles that you use? How much code are you prepared to write? How much mathematics do you want to use? Besides the Monte-Carlo and grid-based approaches already mentioned, I see a couple of other possibilities: (1) It should be entirely possible to do this analytically. The hard part would be identifying the intersection points that form the vertices of the intersection (and especially, doing this robustly in the face of numerical errors and triple intersections or near-triple intersections). Once you've got the vertices, it should be straightforward to compute the area: compute the area of the polygon given by the convex hull of the vertices, then add on the extra areas for the segments bounded by the (straight) sides of the polygon and the corresponding outer arcs. (2) For a numerical approach that might be slightly better than the 2d brute-force approaches described by others: make use of the fact that the intersection is convex. Pick a point P in the intersection (if it exists: finding such a point is an issue in itself). For each angle t, 0 = t = 2*pi, define f(t) to be the distance from P to the boundary of the region, in the direction of the angle t. We always have 0 = f(t) = 1, so f(t) can be quickly and accurately computed with a bisection search. Now find the definite integral of 0.5 * (f(t))**2, as t goes from 0 to 2*pi, using your favourite quadrature method (but avoid methods that would be very sensitive to continuity of derivatives: f(t) will be continuous, but f'(t) will not). Simpson's rule is probably good enough. Good luck! -- Mark -- http://mail.python.org/mailman/listinfo/python-list
how to run part of my python code as root
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hey, is there possibility how to run part of my code (function for example) as superuser. Or only way how to do this is create a wrapper and run is with Popen through sudo (but I have to configure sudo to run whole python as root). Thanks for advice. - -- Tom Key fingerprint = 06C0 23C6 9EB7 0761 9807 65F4 7F6F 7EAB 496B 28AA -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAktrGoYACgkQf29+q0lrKKqaNACdEvfg+g0n3DzFr/7R33y2Nesy hK8An3ZlpUEEibf0Q1wVET/KpXnsv/PO =JKro -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Common area of circles
maximum number of circles = 10**6 runtime = 5 sec center of circles , -1000=xi,yi=1000 (float) [for int it was easier] intersection is there and the area will be non-zero (it can always be checked if intersection is taking place and if no, then area = 0.00) This was a programming contest problem, so code will be short Maths, I'm eager to use. I attempted this problem because I saw scope of maths in it. (I learnt python while doing ProjectEuler because C/C++ was cumbersome for PE IMHO). I tried monte-carlo, but the time-limit exceeds if i go for required accuracy. The same happens with grid approach. On Fri, Feb 5, 2010 at 12:25 AM, Mark Dickinson dicki...@gmail.com wrote: On 2/4/2010 7:05 AM, Shashwat Anand wrote: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. How much accuracy do you need? How fast does the algorithm need to be? How many circles are typically involved? Is the intersection necessarily non-empty for the configurations of circles that you use? How much code are you prepared to write? How much mathematics do you want to use? Besides the Monte-Carlo and grid-based approaches already mentioned, I see a couple of other possibilities: (1) It should be entirely possible to do this analytically. The hard part would be identifying the intersection points that form the vertices of the intersection (and especially, doing this robustly in the face of numerical errors and triple intersections or near-triple intersections). Once you've got the vertices, it should be straightforward to compute the area: compute the area of the polygon given by the convex hull of the vertices, then add on the extra areas for the segments bounded by the (straight) sides of the polygon and the corresponding outer arcs. (2) For a numerical approach that might be slightly better than the 2d brute-force approaches described by others: make use of the fact that the intersection is convex. Pick a point P in the intersection (if it exists: finding such a point is an issue in itself). For each angle t, 0 = t = 2*pi, define f(t) to be the distance from P to the boundary of the region, in the direction of the angle t. We always have 0 = f(t) = 1, so f(t) can be quickly and accurately computed with a bisection search. Now find the definite integral of 0.5 * (f(t))**2, as t goes from 0 to 2*pi, using your favourite quadrature method (but avoid methods that would be very sensitive to continuity of derivatives: f(t) will be continuous, but f'(t) will not). Simpson's rule is probably good enough. Good luck! -- Mark -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with __init__.py in Python3.1
En Thu, 04 Feb 2010 12:40:41 -0300, Hidura hid...@gmail.com escribió: Thanks, I read it and try to put my code in the correct form, but now give me another error, inside the Writer Package says: ValueError: Attempted relative import in non-package, if somebody knows a clue of how fix it i will glad to read opinions. [?] You say that Writer is a package, but apparently Python disagrees. A package is not just a directory containing an __init__.py file, this is half the truth. Python must be *aware* of such file, and this happens when you import the package. If you directly run a script from inside a package, Python does not know that it belongs to a package, and treats it as a simple, lonely script. In that case, relative imports won't work. Put the main script (the one that you directly execute) outside the package. It can be as small as this, if you want: from some.package import main main() -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Selenium/SauceLabs OpenSpace at Pycon
a...@pythoncraft.com (Aahz) writes: Raymond Hettinger pyt...@rcn.com wrote: For those who are interested, the Sauce Labs team, http://saucelabs.com/about/team, is hosting two free tutorial open space sessions at Pycon in Atlanta. Congrats on the new job! Yes, cool! I don't recognize several of these logos, but maybe Sauce can help: http://aasi.ebm.fi/5742/browsers.jpg ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to run part of my python code as root
On Feb 4, 2:05 pm, Tomas Pelka tompe...@gmail.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hey, is there possibility how to run part of my code (function for example) as superuser. Or only way how to do this is create a wrapper and run is with Popen through sudo (but I have to configure sudo to run whole python as root). In decreasing order of desirability: 1. Find a way to not need root access (e.g. grant another user or group access to whatever resource you're trying to access). 2. Isolate the stuff that needs root access into a small helper program that does strict validation of all input (including arguments, environment, etc); when needed, run that process under sudo or similar. 2a. Have some sort of well-verified helper daemon that has access to the resource you need and mediates use of that resource. 3. Run the process as root, using seteuid() to switch between user and root privs. The entire program must be heavily verified and do strict validation of all inputs. Any attacker who gets control over the process can easily switch to root privs and do damage. This is generally a bad idea. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Ruby
Marius Gedminas mged...@gmail.com writes: On Feb 4, 1:03 am, John Bokma j...@castleamber.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: I can explain all of Python in an hour; OK, in that case I would say give it a go. Put it on YouTube, or write a blog post about it (or post it here). I am sure you will help a lot of people that way. Someone already did: Advanced Python or Understanding Python http://video.google.com/videoplay?docid=7760178035196894549 (76 minutes). Worth watching. Certainly worth watching (I learned some stuff), but in my opinion you /need to have some Python experience/ to be able to follow so no (IMO), someone didn't do it already. -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3 minor irritation
Gabriel Genellina wrote: But the associated program might change the current directory - that's not the case with the default associations created by the Python installer, but one should verify this. To the OP: please create this small test script import os print(curdir=, os.getcwd()) print(__file__=, __file__) input() and post what you get when you double-click on it. Also, from the command line, execute: D:\tempreg query HKCR\.py ! REG.EXE VERSION 3.0 HKEY_CLASSES_ROOT\.py Sin nombreREG_SZ Python.File Content TypeREG_SZ text/plain HKEY_CLASSES_ROOT\.py\PersistentHandler I'm interested in this, because I'm using Windows XP, and when I execute this command I see the first part but not the second (with PersistentHandler). Is this related to the fact that when I double-click on a .py file the command window disappears after the execution is completed? -- http://mail.python.org/mailman/listinfo/python-list
Passing command line argument to program from within IDLE?
Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. -- Alan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Ruby
On Feb 3, 3:39 pm, Steve Holden st...@holdenweb.com wrote: Robert Kern wrote: On 2010-02-03 15:32 PM, Jonathan Gardner wrote: I can explain all of Python in an hour; I doubt anyone will understand all of Python in an hour. With all respect, talking about a subject without a reasonable chance of your audience understanding the subject afterwards is not explaining. It's just exposition. I agree. If the audience doesn't understand then you haven't explained it. On the contrary, that explanation would have everything you need. It would take an hour to read or listen to the explanation, but much more than that time to truly understand everything that was said. -- http://mail.python.org/mailman/listinfo/python-list
Re: YAML (was: Python and Ruby)
On Thu, 04 Feb 2010 09:57:59 -0500, Lou Pecora wrote: Well, that looks a bit more complicated than I would like, but maybe it's doing more stuff than I can grok. Here's what I needed and how I did it in Python: [...] # Reading same list in: instr=fp.readline() inlist=eval(instr) x1,y1,astr1,z1= inlist That's what I needed. 3 lines to write or read a inhomogeneous collection of variables. Easy, but also quick and dirty -- good enough for small scripts, but not really good enough for production applications. I can add more variables, shuffle the order, whatever without messing with formatting, etc. This is nice and easy. But there are at least four catches: * you can't safely treat the data file as human-editable (although a sufficiently careful and Python-aware user could edit it) * you can't use any data that isn't a built-in, or that contains something that is not a built-in * there may be reliability issues with floats - you're at the mercy of changes to the underlying repr of float objects, and it almost certainly will blow up in your face if you get an inf or nan (at least prior to Python 2.6) * you're using eval, which is a security risk if you can't trust the source of the data file. However, be aware that neither marshal nor pickle guarantees to be safe against malicious data either. The docs for both warn against using them on untrusted data. YAML or JSON *might* be safer, I haven't looked. That's pretty easy for me and it's easy for anyone to see and understand what's being done. Not trying to start an argument, just showing how the former messasge I was replying to made a good point about Python's way of doing things and the effort to shake off old habits from other languages. These are all good points. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing command line argument to program from within IDLE?
On 2/4/2010 3:55 PM, Alan Biddle wrote: Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. I presume you mean edit, F5-run, see result in shell window. Set sys.argv in test function or __name__=='__main__' In 3.1 idle shell: import sys sys.argv [''] sys.argv = ['abc','dev'] sys.argv ['abc', 'dev'] I did not know it was writable, either, until I tried it. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: YAML
Steven D'Aprano st...@remove-this-cybersource.com.au writes: However, be aware that neither marshal nor pickle guarantees to be safe against malicious data either. The docs for both warn against using them on untrusted data. YAML or JSON *might* be safer, I haven't looked. Regarding malicious data, from the Loading YAML section of PyYAML: Warning: It is not safe to call yaml.load with any data received from an untrusted source! yaml.load is as powerful as pickle.load and so may call any Python function. Check the yaml.safe_load function though. http://pyyaml.org/wiki/PyYAMLDocumentation#LoadingYAML yaml.safe_load however, limits to simple Python objects and Python objects you mark as safe. -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing command line argument to program from within IDLE?
Terry Reedy wrote: On 2/4/2010 3:55 PM, Alan Biddle wrote: Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. I presume you mean edit, F5-run, see result in shell window. Set sys.argv in test function or __name__=='__main__' In 3.1 idle shell: import sys sys.argv [''] sys.argv = ['abc','dev'] sys.argv ['abc', 'dev'] I did not know it was writable, either, until I tried it. As a solution, however, that sucks, wouldn't you agree? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python admin abuse complaint
2010-02-04 Hi Steve, thank you for the reply. I appreciate that you taking this more seriously than normal newsgroups postings. In fact, for this complaint, the response you made is all i asked for. I have a lot things to say about the various political struggle that one sees everyday in just about every communication channels that are predominantly young male groups, of relatively few people, in online posting forums, ircs, online massive multiplayer games... as you may know, the quarrels, accusations, bans, happen every hour. But to be concrete and constructive, i would suggest that in freenode's python irc channel: • when a admin bans someone, the admin needs to tell the person the reason, and not in some rude way. (a single sentence will do.) • The list of ban'd person's names, the reason for banning, and the name of admin who ban'd them, should be public. (irc already provides means for this that allows admins to annotate in the ban list.) In particular, if you are going to ban someone by ip address, make sure the person's handle (or preferably real life name), be listed together with it. (again, this needs not elaborate. A single sentence will do, e.g. “repeatedly asking same question”, “continously raising controversial issues”, “refused to use paste bin when requested” will do. Again, be as precise in description as possible. For example, “ban'd for trolling”, “annoying others”, are not a meaningful reason.) • additionally, i would suggest that bans be temporary. The following period seems a good start: 5 min ban, 1 hour ban, 1 day ban, 1 week ban, 1 month ban. Each can be executed according to severity per the admin's judgement. There should be no permanent ban, unless it's machine generated commercial spam. Thank you. For anyone reading this thread and interested in my opinions, i have written many essays related to this and netiquette. Many of which detail other similar incidences that i personally experienced, such as freenode's irc ban in #emacs channel. If you are interested, they can be found on my website, search for “ban xah lee”. Xah ∑ http://xahlee.org/ ☄ On Feb 2, 2:23 pm, Steve Holden, Chairman, PSF chair...@python.org wrote: Xah Lee wrote: This is a short complaint on admin abuse on #python irc channel on freenode.net. Here's a log: 2010-02-02 (12:11:57 PM) The topic for #python is: NO LOL |http://pound-python.org/ | It's too early to use Python 3.x | Pasting 3 lines? Pastebin: http://paste.pocoo.org/| Tutorial:http://docs.python.org/tut/| FAQ: http://effbot.org/pyfaq/| New Programmer? Readhttp://tinyurl.com/thinkcspy | #python.web #wsgi #python-fr #python.de #python-es #python.tw #python.pl #python-br #python-jp #python-nl #python-ir #python- offtopic (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, actually. (12:12:01 PM) jarray52: Jarray (12:12:11 PM) _habnabit: jarray52, yes, you are. (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops etc) right is quite tricky (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just wondering whats up with the python verison :D (12:12:24 PM) mode (+o dash) by ChanServ (12:12:30 PM) You have been kicked by dash: (No.) --- I have not been using irc for the past about 2 year. (possibly perhaps 2 times in i think #web channel) In particular, i have not been in in freenode.net's #python channel. I don't know who is dash. Xah ∑http://xahlee.org/ ☄ Frankly, Xah Lee, I find it ironic that you see fit to complain about abuse of the IRC channel when you have apparently felt free to ignore the many complaints about your behavior on this and other newsgroups over many years. As ye sew, so shall ye reap. I imagine that your reputation has preceded you, and that dash (whom I *do* know) is simply looking to keep a well-known nuisance from bothering the rest of the users on the channel. For the present my sympathies are all with him. The PSF will, however, investigate this issue and I will report back to you off-list in due course. regards Steve -- Steve Holden Chairman, Python Software Foundation The Python Community Conference http://python.org/psf/ PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/ Watch PyCon on video now! http://pycon.blip.tv/ -- http://mail.python.org/mailman/listinfo/python-list
xmlrpc slow in windows 7 if hostnames are used
Hi, I wrote a small xmlrpc client on Windows 7 with python 2.6 srv = xmlrpclib.Server('http://localhost:80') I was able to perform about 1 rpc call per second After changing to srv = xmlrpclib.Server('http://127.0.0.1:80') I was able to perform about 10 to 16 rpc calls per second. So it seems, that under windows 7 the host name lookup occurs for every RPC call (which is of course necessary for long running processes, as the target host might change it's ip during the scripts execution) For my use cases however I could live with one IP-address lookup at the beginning of the script. I wonder now about how I could deal with virtual web servers. ( a web server running with one ip-adress and one port, which behaves differntly depending on the host name of the url request) I'm just curious, as currently I don't have to access virtual servers via xmlrpc, Is there any way to 'pre-lookup the IP address', and to keep the host name in the http POST request? thanks for any ideas N -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with __init__.py in Python3.1
Gabriel Genellina gagsl-...@yahoo.com.ar writes: If you directly run a script from inside a package, Python does not know that it belongs to a package, and treats it as a simple, lonely script. In that case, relative imports won't work. Which I consider to be a bug. Fortunately, it's already addressed in PEP 366 URL:http://www.python.org/dev/peps/pep-0366/. Unfortunately, it involves more hackish boilerplate at the top of the program, and is only available in Python 2.6+. -- \ “Ignorance more frequently begets confidence than does | `\ knowledge.” —Charles Darwin, _The Descent of Man_, 1871 | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Background Zones in Pylab Plot
On Feb 3, 10:50 pm, CM cmpyt...@gmail.com wrote: On Feb 3, 10:49 am, Wanderer wande...@dialup4less.com wrote: I would like to add background zones in pylab plots. Colored sections of the background that the curves pass through. Is this possible? My google searches don't turn up anything but maybe my search terms aren't the right ones. Thanks If you look at the matplotlib gallery, I think there may be some images that show something like what you want, and then you can look at the code. It's here: http://matplotlib.sourceforge.net/gallery.html HTH, Che That helped. There should be something in there I can use. Thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Ruby
On 2010-02-04 14:55 PM, Jonathan Gardner wrote: On Feb 3, 3:39 pm, Steve Holdenst...@holdenweb.com wrote: Robert Kern wrote: On 2010-02-03 15:32 PM, Jonathan Gardner wrote: I can explain all of Python in an hour; I doubt anyone will understand all of Python in an hour. With all respect, talking about a subject without a reasonable chance of your audience understanding the subject afterwards is not explaining. It's just exposition. I agree. If the audience doesn't understand then you haven't explained it. On the contrary, that explanation would have everything you need. It would take an hour to read or listen to the explanation, but much more than that time to truly understand everything that was said. Like I said, that's exposition, not explanation. There is an important distinction between the two words. Simply providing information is not explanation. If it takes four hours for your audience to understand it, then you explained it in four hours no matter when you stopped talking. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Pixel control
Hello everyone. For example i am using a screen resolution of 800x600 is it possible to make python control the color of the pixels? For example paint the pixel (100,200) in red! And it would stay red when i am seeing a webpage, a movie, playing a game... etc.. Regards, João Abrantes. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt4 designer custom properties - combo box style
On Tuesday 02 February 2010 22:25, Andrew wrote: I am creating custom widgets for the PyQt4 Designer. I can create custom properties, but I'm looking for how to create a custom property that has a combo box drop down. I've seen them in the example widgets and tried following them, but they are using pre-defined items to populate their property, so it's not a very clear example of how to get the combo box property to work. Can you explain a bit more about what you have seen and what you are trying to do. Are you trying to create a property that is treated specially by Designer or do you want to get the data for the combo box from somewhere else? Is there any other examples or help for this kind of setup? Have you seen this article? http://qt.nokia.com/doc/qq/qq26-pyqtdesigner.html David -- http://mail.python.org/mailman/listinfo/python-list
Re: python admin abuse complaint
Xah Lee wrote: 2010-02-04 Hi Steve, thank you for the reply. I appreciate that you taking this more seriously than normal newsgroups postings. In fact, for this complaint, the response you made is all i asked for. OK, in that case I won't trouble anyone else about it. I have a lot things to say about the various political struggle that one sees everyday in just about every communication channels that are predominantly young male groups, of relatively few people, in online posting forums, ircs, online massive multiplayer games... as you may know, the quarrels, accusations, bans, happen every hour. I understand that the diversity of the various channels available to Python users (and indeed of the Python community overall) is not as high as it could be. This does from time to time lead to inappropriate behaviors. I suspect dash kicked you off #python simply because of the reputation you have established on comp.lang.python, but of course I cannot speak for him. But to be concrete and constructive, i would suggest that in freenode's python irc channel: • when a admin bans someone, the admin needs to tell the person the reason, and not in some rude way. (a single sentence will do.) That would, I agree, be appropriate. • The list of ban'd person's names, the reason for banning, and the name of admin who ban'd them, should be public. (irc already provides means for this that allows admins to annotate in the ban list.) In particular, if you are going to ban someone by ip address, make sure the person's handle (or preferably real life name), be listed together with it. (again, this needs not elaborate. A single sentence will do, e.g. “repeatedly asking same question”, “continously raising controversial issues”, “refused to use paste bin when requested” will do. Again, be as precise in description as possible. For example, “ban'd for trolling”, “annoying others”, are not a meaningful reason.) This is perhaps a little formal for something that (as far as I know) happens less than once a month. I am reluctant to start up any kind of bureaucracy around bannings unless they become too frequent (in which case your suggestions above seem reasonable). • additionally, i would suggest that bans be temporary. The following period seems a good start: 5 min ban, 1 hour ban, 1 day ban, 1 week ban, 1 month ban. Each can be executed according to severity per the admin's judgement. There should be no permanent ban, unless it's machine generated commercial spam. Again, this is probably over-formal for the current levels of banning, but a reasonable idea in principle. Thank you. For anyone reading this thread and interested in my opinions, i have written many essays related to this and netiquette. Many of which detail other similar incidences that i personally experienced, such as freenode's irc ban in #emacs channel. If you are interested, they can be found on my website, search for “ban xah lee”. Xah, your opinions are I think pretty well-known around here. I understand that you consider yourself an authority on netiquette, but as I mentioned in my last response I have personally observed you on many occasions indulging in inappropriate behavior such as cross-posting irrelevant material to many newsgroups at the same time. It is actions like that, combined with your use of intemperate and abusive language, that caused you to get banned before you had chance to say much. It's a bit like the boy who cried 'wolf'. People see you doing these things, and so when you appear on an IRC channel where this is known about you get banned as a pre-emptive measure. I have discussed this matter with dash, and he has agreed not to kick you off without reason the next time you join #python. This will only last as long as your behavior remains acceptable, so please don't abuse the privilege I have won back for you. If you do, that will make me feel (and look) like a real dick, and get you banned again straight away. regards Steve Xah ∑ http://xahlee.org/ ☄ On Feb 2, 2:23 pm, Steve Holden, Chairman, PSF chair...@python.org wrote: Xah Lee wrote: This is a short complaint on admin abuse on #python irc channel on freenode.net. Here's a log: 2010-02-02 (12:11:57 PM) The topic for #python is: NO LOL |http://pound-python.org/ | It's too early to use Python 3.x | Pasting 3 lines? Pastebin: http://paste.pocoo.org/| Tutorial:http://docs.python.org/tut/| FAQ: http://effbot.org/pyfaq/| New Programmer? Readhttp://tinyurl.com/thinkcspy | #python.web #wsgi #python-fr #python.de #python-es #python.tw #python.pl #python-br #python-jp #python-nl #python-ir #python- offtopic (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, actually. (12:12:01 PM) jarray52: Jarray (12:12:11 PM) _habnabit: jarray52, yes, you are. (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops etc) right
Your beloved python features
Hello, I've asked this question at stackoverflow a few weeks ago, and to make it clear: this should NOT be a copy of the stackoverflow-thread hidden features of Python. I want to design a poster for an open source conference, the local usergroup will have a table there, and in the past years there were some people that came to the python-table just to ask why should I use python?. For those guys would be a poster quite cool which describes the most popular and beloved python features. So, may you help me please? If there's a similar thread/blogpost/ whatever, please give it to me, google couldn't. Regards Julian -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing command line argument to program from within IDLE?
On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: Terry Reedy wrote: On 2/4/2010 3:55 PM, Alan Biddle wrote: Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. I presume you mean edit, F5-run, see result in shell window. Set sys.argv in test function or __name__=='__main__' In 3.1 idle shell: import sys sys.argv [''] sys.argv = ['abc','dev'] sys.argv ['abc', 'dev'] I did not know it was writable, either, until I tried it. As a solution, however, that sucks, wouldn't you agree? [scratches head] Do you mean setting sys.argv as a solution sucks? No, I don't, I think it is grand. If sys.argv was unmodifiable, *that* would suck. Or do you mean that trying it as a solution to the problem of answering the OP's question sucks? Well, no, experimentation is good for answering these sorts of questions, and I can't assume that the documentation will cover every imaginable use-case, or that users will find it. In the absence of any documentation stating otherwise, I would have assumed that sys.argv was an ordinary list which you can modify at will, but having been caught out on faulty assumptions before, I would try it and see before commenting publicly. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Your beloved python features
My favorite feature is its readability. It's as near to pseudo-code as any language we have, and that's valuable in open source projects or when I return to code to modify it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing command line argument to program from within IDLE?
Steven D'Aprano wrote: On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: Terry Reedy wrote: On 2/4/2010 3:55 PM, Alan Biddle wrote: Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. I presume you mean edit, F5-run, see result in shell window. Set sys.argv in test function or __name__=='__main__' In 3.1 idle shell: import sys sys.argv [''] sys.argv = ['abc','dev'] sys.argv ['abc', 'dev'] I did not know it was writable, either, until I tried it. As a solution, however, that sucks, wouldn't you agree? [scratches head] Do you mean setting sys.argv as a solution sucks? No, I don't, I think it is grand. If sys.argv was unmodifiable, *that* would suck. Or do you mean that trying it as a solution to the problem of answering the OP's question sucks? Well, no, experimentation is good for answering these sorts of questions, and I can't assume that the documentation will cover every imaginable use-case, or that users will find it. In the absence of any documentation stating otherwise, I would have assumed that sys.argv was an ordinary list which you can modify at will, but having been caught out on faulty assumptions before, I would try it and see before commenting publicly. What I meant was it sucks that IDLE has no way to fill in sys.argv as a part of its Run Module functionality - something that is present in both PythonWin and Wing IDE, for example. But then I have come to the conclusion that IDLE doesn't fit my brain, or my brain doesn't fit it. That sys.argv is mutable simply reflects the fact that it's a list. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Your beloved python features
Julian maili...@julianmoritz.de writes: I want to design a poster for an open source conference, the local usergroup will have a table there, and in the past years there were some people that came to the python-table just to ask why should I use python?. It's terrible, but all the alternatives are even worse. ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing command line argument to program from within IDLE?
Steven D'Aprano st...@remove-this-cybersource.com.au writes: On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: Terry Reedy wrote: On 2/4/2010 3:55 PM, Alan Biddle wrote: Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. I presume you mean edit, F5-run, see result in shell window. Set sys.argv in test function or __name__=='__main__' In 3.1 idle shell: import sys sys.argv [''] sys.argv = ['abc','dev'] sys.argv ['abc', 'dev'] I did not know it was writable, either, until I tried it. As a solution, however, that sucks, wouldn't you agree? [scratches head] Do you mean setting sys.argv as a solution sucks? No, I don't, I think it is grand. If sys.argv was unmodifiable, *that* would suck. Or do you mean that trying it as a solution to the problem of answering the OP's question sucks? Well, no, experimentation is good for answering these sorts of questions, and I can't assume that the documentation will cover every imaginable use-case, or that users will find it. In the absence of any documentation stating otherwise, I would have assumed that sys.argv was an ordinary list which you can modify at will, but having been caught out on faulty assumptions before, I would try it and see before commenting publicly. I guess that Terry means that a solution that makes it possible to specify in IDLE *outside* of the Python code the arguments would be better. Hardcoding the command line arguments isn't something I would do for testing. -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing command line argument to program from within IDLE?
John Bokma j...@castleamber.com writes: Steven D'Aprano st...@remove-this-cybersource.com.au writes: On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: Terry Reedy wrote: On 2/4/2010 3:55 PM, Alan Biddle wrote: Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. I presume you mean edit, F5-run, see result in shell window. Set sys.argv in test function or __name__=='__main__' In 3.1 idle shell: import sys sys.argv [''] sys.argv = ['abc','dev'] sys.argv ['abc', 'dev'] I did not know it was writable, either, until I tried it. As a solution, however, that sucks, wouldn't you agree? [scratches head] Do you mean setting sys.argv as a solution sucks? No, I don't, I think it is grand. If sys.argv was unmodifiable, *that* would suck. Or do you mean that trying it as a solution to the problem of answering the OP's question sucks? Well, no, experimentation is good for answering these sorts of questions, and I can't assume that the documentation will cover every imaginable use-case, or that users will find it. In the absence of any documentation stating otherwise, I would have assumed that sys.argv was an ordinary list which you can modify at will, but having been caught out on faulty assumptions before, I would try it and see before commenting publicly. I guess that Terry means that a solution that makes it possible to specify in IDLE *outside* of the Python code the arguments would be better. Hardcoding the command line arguments isn't something I would do for testing. Oops, that should've been Steve, my apologies. -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3 minor irritation
En Thu, 04 Feb 2010 17:50:29 -0300, Gib Bogle g.bo...@auckland.no.spam.ac.nz escribió: Gabriel Genellina wrote: Also, from the command line, execute: D:\tempreg query HKCR\.py ! REG.EXE VERSION 3.0 HKEY_CLASSES_ROOT\.py Sin nombreREG_SZ Python.File Content TypeREG_SZ text/plain HKEY_CLASSES_ROOT\.py\PersistentHandler I'm interested in this, because I'm using Windows XP, and when I execute this command I see the first part but not the second (with PersistentHandler). Sorry, I should have removed that line. This is just my setup; a normal Python install doesn't create that registry entry. It allows Desktop Search (or Windows Search, or whatever it is called nowadays; the F3 key) to search inside .py files (default behavior is to just ignore their contents). See http://support.microsoft.com/kb/309173 Is this related to the fact that when I double-click on a .py file the command window disappears after the execution is completed? (I bet the Persistent word confused you.) No, as you can see, it's completely unrelated. AFAIK, there is no way (on XP and later at least) to keep a console window open after the program exited. Three choices: - Open a cmd window and execute the script there. You may dragdrop the file over the window to avoid typing the full path (I think this last part does not work on Vista nor Win7) - Add a raw_input() [2.x] or input() [3.x] line at the end of the script - Rename it with a '.cmd' extension and add this line at the very top: @(C:\Python26\Python -x %~f0 %* || pause) goto:EOF (see this post by Duncan Booth last month: http://comments.gmane.org/gmane.comp.python.general/650913 ) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing command line argument to program from within IDLE?
En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma j...@castleamber.com escribió: John Bokma j...@castleamber.com writes: On 2/4/2010 3:55 PM, Alan Biddle wrote: Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. I guess that Terry means that a solution that makes it possible to specify in IDLE *outside* of the Python code the arguments would be better. Hardcoding the command line arguments isn't something I would do for testing. Oops, that should've been Steve, my apologies. See http://bugs.python.org/issue5680 -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Code snippet: dualmethod descriptor
On Thu, 04 Feb 2010 00:09:02 -0300, Gabriel Genellina wrote: En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano st...@remove-this-cybersource.com.au escribió: class dualmethod(object): [...] Seems useful! Perhaps a better place to post it would be http://code.activestate.com/recipes/langs/python/, at least it's easier to search. Thank you for the encouragement. The recipe is now posted: http://code.activestate.com/recipes/577030/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing command line argument to program from within IDLE?
On 2/4/2010 6:29 PM, Steve Holden wrote: Steven D'Aprano wrote: On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: Terry Reedy wrote: On 2/4/2010 3:55 PM, Alan Biddle wrote: Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. I presume you mean edit, F5-run, see result in shell window. Set sys.argv in test function or __name__=='__main__' In 3.1 idle shell: import sys sys.argv [''] sys.argv = ['abc','dev'] sys.argv ['abc', 'dev'] I did not know it was writable, either, until I tried it. As a solution, however, that sucks, wouldn't you agree? No, see below. [scratches head] Do you mean setting sys.argv as a solution sucks? No, I don't, I think it is grand. If sys.argv was unmodifiable, *that* would suck. Or do you mean that trying it as a solution to the problem of answering the OP's question sucks? Well, no, experimentation is good for answering these sorts of questions, and I can't assume that the documentation will cover every imaginable use-case, or that users will find it. In the absence of any documentation stating otherwise, I would have assumed that sys.argv was an ordinary list which you can modify at will, but having been caught out on faulty assumptions before, I would try it and see before commenting publicly. What I meant was it sucks that IDLE has no way to fill in sys.argv as a part of its Run Module functionality - something that is present in both PythonWin and Wing IDE, for example. The first thing I did was to check for such an option on the run tab. The second thing I thought of was to suggest to OP that he file a feature request (which would likely take years, if ever). But then the test line would not be fetched from the file (unless some ##cmdline convention were invented), but would have to be hand-entered each time the editor were run. Also, a given run of a program can have only one command line, and changing the run line for each test case would suck. Then I tried sys.argv. Why that does not suck: A Python program, as far as I know, cannot process a command lines directly, but only processed command line args in the form of a list of strings -- sys.argv. Therefore, the need for testing is not to simulate a command line but to set sys.argv. I assume the programmer knows the mapping from command line to argv since he otherwise cannot sensibly proceed. I believe it is sensible, if not recommended, to put an arg processing in a defined function that returns, for instance, a dict, rather than to do it at top-level in the main script. So in use, process_args() will be called in a context with sys.argv set. So let it be tested. For instance, something like: def _test_arg_processing: arg_dict_pairs - ( (['arg1', 'arg2'], {'speed':int('arg1'), 'range':float('arg2'}), (['-v'], {'verbose': True}, ) for args,dic in arg_dict_pairs: sys.argv = args assert process_args() == dic Repeatable automatic testing of multiple test cases. I just starting doing this a year ago and love it. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Your beloved python features
Iterators, and in particular, generators. A killer feature. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrap a function
In article mailman.1885.1265261952.28905.python-l...@python.org, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On 3 Feb 2010 08:38:47 -0800, a...@pythoncraft.com (Aahz) declaimed the following in gmane.comp.python.general: In article mailman.1585.1264743912.28905.python-l...@python.org, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: I shall blaspheme, and suggest that maybe the language you want to use is REXX (ooREXX or Regina). By default, ANY statement that can not be confused for a REXX language statement is sent to the currently defined command handler (Which on most OSs is equivalent to Python's os.system() call; the late Amiga, and IBM's mainframe OS had features that support defining other applications as command handlers). How is that different from bash scripting? Uhm... Does a bash script support inlining statements from some other language? Python's shutil library essentially disappears in REXX as one can plug in the native command line statement for those functions. But in bash scripting, you'd just use rsync or cp or rm -- maybe an example would make clearer how REXX differs from bash. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ import antigravity -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing command line argument to program from within IDLE?
Gabriel Genellina wrote: En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma j...@castleamber.com escribió: John Bokma j...@castleamber.com writes: On 2/4/2010 3:55 PM, Alan Biddle wrote: Just finishing my first Python (2.6 on Win XP) program, which is working fine. My Duh? question is about how to run it from within IDLE and pass it command line arguments. I guess that Terry means that a solution that makes it possible to specify in IDLE *outside* of the Python code the arguments would be better. Hardcoding the command line arguments isn't something I would do for testing. Oops, that should've been Steve, my apologies. See http://bugs.python.org/issue5680 So we've had a patch since April and it still didn't make it into 3.1? That's disappointing. I wonder if there's any chance it'll get into 2.7. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3 minor irritation
Gabriel Genellina wrote: Sorry, I should have removed that line. This is just my setup; a normal Python install doesn't create that registry entry. It allows Desktop Search (or Windows Search, or whatever it is called nowadays; the F3 key) to search inside .py files (default behavior is to just ignore their contents). See http://support.microsoft.com/kb/309173 Is this related to the fact that when I double-click on a .py file the command window disappears after the execution is completed? (I bet the Persistent word confused you.) No, as you can see, it's completely unrelated. AFAIK, there is no way (on XP and later at least) to keep a console window open after the program exited. Three choices: - Open a cmd window and execute the script there. You may dragdrop the file over the window to avoid typing the full path (I think this last part does not work on Vista nor Win7) - Add a raw_input() [2.x] or input() [3.x] line at the end of the script - Rename it with a '.cmd' extension and add this line at the very top: @(C:\Python26\Python -x %~f0 %* || pause) goto:EOF (see this post by Duncan Booth last month: http://comments.gmane.org/gmane.comp.python.general/650913 ) Thanks Gabriel. I didn't know about the dragdrop capability (learn something every day, forget two things). BTW input() works for me in 2.5. Cheers Gib -- http://mail.python.org/mailman/listinfo/python-list