Re: [OT] Free software versus software idea patents

2011-04-07 Thread Chris Angelico
that nothing can ever be patented, because it's all just mathematics? At what point is there valid, patentable creativity to be found in combining known elements in previously unknown ways? Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused about __prepare__

2011-04-07 Thread Chris Rebert
() is a special method. The default __getattribute__() implementation consults an object's __dict__. type.__new__() presumably does an implicit special method lookup for __init__() behind the scenes. Hence, your custom __dict__ is bypassed. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Chris Angelico
ynchronous I/O and select(), but I couldn't see a way to do that with urllib/urllib2. If you're using sockets directly, this ought to be an option. I don't know what's the most Pythonesque option, but if you already have specific Python code for each of your functions, it

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Chris Angelico
On Sat, Apr 9, 2011 at 12:41 AM, MRAB wrote: > On 08/04/2011 08:25, Chris Angelico wrote: > [snip] >> >> I don't know what's the most Pythonesque option, but if you already >> have specific Python code for each of your functions, it's probably >> goin

Re: Python 3.2 vs Java 1.6

2011-04-08 Thread Chris Angelico
On Sat, Apr 9, 2011 at 1:21 AM, km wrote: > Hi All, > > How does python 3.2 fare compared to Java 1.6 in terms of performance ? > any pointers or observations ? Hi All, How do apples compare to oranges in terms of performance? Chris Angelico -- http://mail.python.org/mailman/lis

Re: How to get a PID of a child process from a process openden with Popen()

2011-04-08 Thread Chris Angelico
ect forks and follow the child. But I think that's getting into some serious esoteria that's unlikely to be of much practical use here. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.2 vs Java 1.6

2011-04-09 Thread Chris Rebert
t; [By the way, does anyone know why the number of languages in the shootout > seems to have dropped drastically?] Probably related to this: http://www.reddit.com/r/programming/comments/glvgk/lua_jit_pypy_tracemonkey_python_27_jruby_and/ Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Retrieving Python Keywords

2011-04-09 Thread Chris Angelico
"foo") File "", line 1, in NameError: name 'foo' is not defined >>> eval("lambda") Traceback (most recent call last): File "", line 1, in eval("lambda") File "", line 1 lambda ^ SyntaxError

Re: Argument of the bool function

2011-04-10 Thread Chris Angelico
On Sun, Apr 10, 2011 at 10:54 PM, candide wrote: > Anyway, passing x as a keyword argument to the bool function appears to be > very rare : i did a regexp search for about 3 source-code Python files > (among them official Python source-code, Django, Sphinx, Eric source-code > and many more sou

Re: How to program in Python to run system commands in 1000s of servers

2011-04-10 Thread Chris Angelico
could be a simple .HTML file that you have on your hard disk; otherwise, you may want to consider another web server that lets you tick which ones to query, and builds an iframe list from your selections. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Free software versus software idea patents

2011-04-10 Thread Chris Angelico
uot;). Feel free to continue discussing the merits of these donations, but it is definitely substantiable and knowable. Microsoft has money, and they're prepared to spend it on what they believe in. (My view is that they believe in positive PR more than they believe in Python or Apache or w

Re: [OT] Free software versus software idea patents

2011-04-11 Thread Chris Angelico
otal data though. We use Linux for technological reasons more than anything else. Windows doesn't give us the power of iptables, for instance. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: [Feature Request] dict.setdefault()

2011-04-11 Thread Chris Angelico
t; like "update" except that it wouldn't overwrite existing values. Wouldn't x.updatedefault(y) be pretty much y.update(x) ? Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: [Feature Request] dict.setdefault()

2011-04-11 Thread Chris Rebert
blah, blah: blah, blah: blah, blah: blah} defaults.update(d) # clobber defaults with specified vals d = defaults # swap in, assuming not aliased # if aliased, then instead: # d.clear() # d.update(defaults) if blah is not blah: d.setdefault(blah, blah) Cheers, Chris -- http://blog.rebertia.com -- http:

Re: Feature suggestion -- return if true

2011-04-11 Thread Chris Angelico
discussion that the return? expr is a complex one, such that it's well worth evaluating only once (maybe even has side effects). Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Feature suggestion -- return if true

2011-04-11 Thread Chris Angelico
On Tue, Apr 12, 2011 at 10:46 AM, Chris Angelico wrote: > def fac(n): >    return cache[n] or (cache[n]=1 if n<=1 else fac(n-1)*n) Hmm. The function-call version of dictionary assignment IS legal in an expression, but it's getting stupid... def fac(n): return cache.ge

Re: Feature suggestion -- return if true

2011-04-11 Thread Chris Angelico
gt; But hey let's argue the point to death! That's still not equivalent. "return expr or None" will always terminate the function. The OP's request was for something which would terminate the function if and only if expr is non-false. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Feature suggestion -- return if true

2011-04-11 Thread Chris Angelico
an idea that is. Inside an if, 'it' is the value of the condition. Might actually be useful in a few places.... Naw, I think it's still a stupid idea. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with regex needed

2011-04-11 Thread Chris Rebert
^^^ This trailing " +" *requires* that the lines have trailing spaces. Do they? Such files typically don't, and your example input doesn't either (although that may be due to email formatting lossage). Cheers, Chris -- http://blog.rebertia.com > hhh = open("file_wi

Re: Help with regex needed

2011-04-11 Thread Chris Rebert
d to use regexes to parse such a simple file format. Just use str.split() [without any arguments] on each line of the file, and do the field equality checks yourself; your code will simpler. Relevant docs: http://docs.python.org/library/stdtypes.html#str.split Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: download web pages that are updated by ajax

2011-04-12 Thread Chris Rebert
X > version of the page. I've heard you can drive a web browser using Selenium (http://code.google.com/p/selenium/ ), have it visit the webpage and run the JavaScript on it, and then grab the final result. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Feature suggestion -- return if true

2011-04-12 Thread Chris Rebert
and you're just going to end up with oceans of slurry, as indeed we have. It's like giving someone a stack of paper and a [pen] and claiming that that's as good as the latest [New York Times] bestseller." IOW, a language is usually better for having such discussions and having a

Re: Feature suggestion -- return if true

2011-04-12 Thread Chris Angelico
ocate a loop, but that method could work too. It all depends on the actual code being executed. I'd still be in favour of shor-circuit Or operators for this, although it does cost readability. Side point: Interesting that I'm referred to by surname here. Seems there's a large number o

Re: Feature suggestion -- return if true

2011-04-12 Thread Chris Angelico
g a different comedy source for my references. Sometimes even a python has to get smart...) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: pyc to py

2011-04-13 Thread Chris Rebert
On Wed, Apr 13, 2011 at 2:46 AM, luca72 wrote: > I have pyc file written with python 2.6.5 and i need to return to py > file, can you give me some ideas tools script etc. http://www.crazy-compilers.com/decompyle/ Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Egos, heartlessness, and limitations

2011-04-14 Thread Chris Angelico
On Thu, Apr 14, 2011 at 12:03 PM, Ryan Kelly wrote: > On Thu, 2011-04-14 at 11:46 +1000, Chris Angelico wrote: >> Wait... so where do the Python experts hang out? > > Don't panic, there are plenty of experts here :-) > > It's an oft-cited troll complaint t

Re: [OT] Free software versus software idea patents

2011-04-14 Thread Chris Angelico
ich is more popular, Coca-Cola or Pepsi? Do more people vote Liberal or Labour, Republican or Democrat, Whig or Tory? Statisticking is a huge science. Most of it involves figuring out what's important - anyone can get data, but getting useful information out of the data takes some work. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: about soaplib demo's time latency

2011-04-14 Thread Chris Angelico
h your hosts file (/etc/hosts or c:\windows\system32\drivers\etc\hosts) instead - just put in an entry for your client computer and some hostname. Hope that helps! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: about soaplib demo's time latency

2011-04-14 Thread Chris Angelico
On Thu, Apr 14, 2011 at 11:30 PM, Stephen.Wu <[email protected]> wrote: > Thanks Chris. > I recheck the logic line by line and I find it is this sentence drag > speed down :  hello_client = Client('http://localhost:7789/?wsdl'). > To initialize a suds.client.Client ins

Re: [OT] Free software versus software idea patents

2011-04-14 Thread Chris Angelico
f people who will just go "Oh, I need to download something to make this work? Okay. *click*" - now THAT is the real risk. They don't know (or care) whether they're getting Adobe Flash Player version 123, or Acrobat Reader 234, or Java Applet Engine By Bob's Dodgy Coders

Re: [OT] Free software versus software idea patents

2011-04-14 Thread Chris Angelico
On Fri, Apr 15, 2011 at 7:36 AM, Martin Gregorie wrote: > I think the only real evil is to set out to make a non-standards- > compliant server and then design client software that seeks to lock in > people to your server. FWIW I'm not certain that is anything that MS > deliberately set out to do.

Re: about soaplib demo's time latency

2011-04-14 Thread Chris Angelico
config. I don't know if other DNS software comes nicely preconfigured like that, but it should, since nobody ever assigns localhost to be anything else (imagine the confusion THAT would cause - even if you set it to something relatively innocuous like 127.0.0.2). Chris Angelico -- http://mail

Pythonic infinite for loop?

2011-04-14 Thread Chris Angelico
ds of Adam Savage: "Am I about to feel really, really stupid?" Thanks in advance for help... even if it is just "hey you idiot, you forgot about X"! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Free software versus software idea patents

2011-04-14 Thread Chris Angelico
hemselves with rusty forks and code using their own blood, I think it'd be an improvement over the current one. And from the other end... leaving Flash sites up in my browser is one of the best ways to destroy my battery life. It sucks... power. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic infinite for loop?

2011-04-14 Thread Chris Angelico
l.) If not, I think I'll go with: for i in xrange(1,len(dct)+1): and otherwise as per OP. Having a check for "if key%d in dct" going all the way up seems like an odd waste of effort (or maybe I'm wrong there). Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic infinite for loop?

2011-04-15 Thread Chris Angelico
: x != sentinel, seq)) If I understand this code correctly, that's creating generators, right? It won't evaluate past the sentinel at all? That might well be what I'm looking for. A bit ugly, but efficient and compact. And I can bury some of the ugliness away. Chris Angelico -- htt

Re: Pythonic infinite for loop?

2011-04-15 Thread Chris Angelico
On Fri, Apr 15, 2011 at 6:25 PM, Peter Otten <[email protected]> wrote: > The initial data structure seems less than ideal. You might be able to > replace it with a dictionary like > > {"Keyword": [value_for_keyword_1, value_for_keyword_2, ...]} > > if you try hard enough. The initial data structur

Re: PYTHONPATH

2011-04-15 Thread Chris Rebert
cs.python.org/library/site.html Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic infinite for loop?

2011-04-15 Thread Chris Angelico
On Fri, Apr 15, 2011 at 10:52 PM, Steven D'Aprano wrote: > On Fri, 15 Apr 2011 13:58:22 +1000, Chris Angelico wrote: > >> The dictionary is potentially a lot larger than this particular set of >> values (it's a mapping of header:value for a row of a user-provided CS

Questions about GIL and web services from a n00b

2011-04-15 Thread Chris H
SOAP seems to be pretty well supported but I'm not finding the same for quick development of REST based services for exchanging JSON or XML formatted data. This is probably just my n00b status, but what tools are best for building a simple REST data exchange API? Thanks, Chris -- ht

Re: Questions about GIL and web services from a n00b

2011-04-15 Thread Chris H
On 4/15/11 1:03 PM, Tim Wintle wrote: On Fri, 2011-04-15 at 12:33 -0400, Chris H wrote: 1. Are you sure you want to use python because threading is not good due to the Global Lock (GIL)? Is this really an issue for multi-threaded web services as seems to be indicated by the articles from a

Re: Is it possible to execute Python code from C++ without writing to a file?

2011-04-15 Thread Chris Angelico
uot;); Py_DECREF(locals); You now own a reference to whatever the Python code put into its variable "result", in the C variable returned_tuple. Of course, it might not be a tuple at all, and it might not even be present (in which case returned_tuple will be NULL). This is a fairly effective

Re: Questions about GIL and web services from a n00b

2011-04-16 Thread Chris Angelico
l". But ultimately it's still a "worker thread" / "interaction thread" model, which is quite a good one. The interaction thread spends most of its time waiting for the user, maybe waiting for STDIN, maybe waiting for a GUI event, maybe waiting on some I/O device (TCP socket

Re: Python IDE/text-editor

2011-04-16 Thread Chris Angelico
ssh and such). Mastering emacs would definitely take time; I'm not really sure if I can justify it ("Chris, what did you achieve this week?" "I learned how to get emacs to make coffee.")... Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: [Q] ipython: Multiple commands on the same line and newlines

2011-04-16 Thread Chris Angelico
ne entire command, but if that command requires a "prefix statement" to set things up (like initializing a dictionary to empty), that has to be separate. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Python IDE/text-editor

2011-04-16 Thread Chris Angelico
On Sun, Apr 17, 2011 at 2:32 AM, Andrea Crotti wrote: > That of course is an issue, but since you code in many languages I think > is really a pretty good investment for your future. > > And I don't think that you would be unproductive the first weeks with > emacs, just a bit slower maybe, and it'

Re: Python IDE/text-editor

2011-04-16 Thread Chris Angelico
On Sun, Apr 17, 2011 at 3:07 AM, Andrea Crotti wrote: > The only language where an IDE like eclipse imho is the only way is > java, but that is because the language sucks so much that without a > massive help is impossible to write something in a human time. (Now OT) I used Eclipse once, and yes

Re: Equivalent code to the bool() built-in function

2011-04-16 Thread Chris Rebert
, `True if x else False` conceptually gets compiled down to `True if bool(x) == 1 else False` (but without doing a run-time lookup of "bool"). Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python IDE/text-editor

2011-04-16 Thread Chris Angelico
programs without a Python interpreter installed. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-16 Thread Chris Rebert
esting procedure." > -- §5.1 Truth Value Testing in Library Reference This describes "the standard truth testing procedure". Ideally, this section would be linked to in bool()'s docs. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Free software versus software idea patents

2011-04-16 Thread Chris Angelico
On Sun, Apr 17, 2011 at 9:36 AM, Steven D'Aprano wrote: > (If the machine is particularly > simple -- you might be able to exactly simulate a lever in pure > mathematics, but simulating, say, a nuclear bomb or a dialysis machine in > mathematics is more of a challenge...) I can easily model a mas

Re: Feature suggestion -- return if true

2011-04-16 Thread Chris Angelico
y conditional returns. There's not a lot of difference between conditionally returning and conditionally executing all the code between here and the return, except that when you string three conditional returns together by your method, it gets three indentations. Chris Angelico -- http:/

Re: Python IDE/text-editor

2011-04-17 Thread Chris Angelico
crack up laughing in the middle of a church meeting... Yes! We need text editor instructors. "Don't forget that you can press F7 to make." "You could do that more easily with C-x M-c M-butterfly." Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-17 Thread Chris Angelico
integers as strings - REXX manages quite well, and gets some advantages therefrom. But having an explicit bool type has its benefits too. Essential? No. Useful? Certainly. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Feature suggestion -- return if true

2011-04-17 Thread Chris Angelico
On Sun, Apr 17, 2011 at 6:45 PM, Steven D'Aprano wrote: > On Sun, 17 Apr 2011 16:21:53 +1200, Gregory Ewing wrote: > >> Chris Angelico wrote: >> >>> def fac(n): >>>     # attempt to get from a cache >>>     return? cache[n] >>>     # n

Re: Make Python "portable" by default! (Re: Python IDE/text-editor)

2011-04-17 Thread Chris Angelico
day), you need to have a language-specific interpreter or compiler before you can run it. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: An unusual question...

2011-04-17 Thread Chris Angelico
It sounds to me like you're trying to pull off a classic buffer overrun and remote code execution exploit, in someone else's Python program. And all I have to say is Good luck to you. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Namespaces in functions vs classes

2011-04-17 Thread Chris Rebert
such name from within a method, the following scopes are consulted, in order (ignoring some subtleties): 1. Local variables 2. Variables in nested functions 3. Global variables 4. Built-ins For "workarounds" for this, see: http://mail.python.org/pipermail/python-list/2009-December/1228354.html As to why Python works this way, I'm not sure. However, one could cogently argue that this requires you to be more explicit about what the scope is of the name you're referring to; which set of semantics you desire in the face of inheritance, monkey-patching, and instance variable shadowing makes this trickier than you might otherwise think. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-17 Thread Chris Angelico
le would write any of: > >  true = 1; false = 0 >  FALSE = 0; TRUE = not FALSE >  True = -1; False = not True Just as long as someone doesn't use: true = 1; false = -1 which results in the annoying situation that: if x == false: is different from: if x: But on the plus side, TheDailyWTF.com is never short of publishable material... Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: Equivalent code to the bool() built-in function

2011-04-17 Thread Chris Angelico
On Mon, Apr 18, 2011 at 11:46 AM, Dave Angel wrote: >>>> bool = int > Any language that allows you to do this is either awesome or terrifying. Come to think of it, there's not a lot of difference. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Feature suggestion -- return if true

2011-04-17 Thread Chris Angelico
On Mon, Apr 18, 2011 at 12:04 PM, Dave Angel wrote: > On 01/-10/-28163 02:59 PM, Chris Angelico wrote: >> >>   >> >> Sure. In my (somewhat contrived) example of factorials, that's going >> to be true (apart from 0! = 0); and if the function returns a st

Re: Equivalent code to the bool() built-in function

2011-04-17 Thread Chris Angelico
On Mon, Apr 18, 2011 at 2:40 PM, Ned Deily wrote: > Chris Angelico: >>  Dave Angel: >> >>>> bool = int >> Any language that allows you to do this is either awesome or >> terrifying. Come to think of it, there's not a lot of difference. > > Even b

Re: Equivalent code to the bool() built-in function

2011-04-17 Thread Chris Rebert
On Sun, Apr 17, 2011 at 9:53 PM, Chris Angelico wrote: > On Mon, Apr 18, 2011 at 2:40 PM, Ned Deily wrote: >> Even better: >> $ python2.7 -c 'False = True; print False' >> True > > http://bofh.ch/bofh/bofh13.html > >> Alas: >> $ python3

Re: Equivalent code to the bool() built-in function

2011-04-17 Thread Chris Angelico
On Mon, Apr 18, 2011 at 3:49 PM, Chris Rebert wrote: >> Pro: You can do anything. >> Con: You can do anything. > > I think someone already beat you to it. They call their invention "Lisp". :-P Bah! Lisp comes, out of the box, with far too many features! No no no. I

Re: [Q] ipython: Multiple commands on the same line and newlines

2011-04-17 Thread Chris Angelico
nate (more C-like) blocking syntax. > You can do that with a future directive. from __future__ import braces That's two underscores before and after the word "future". http://docs.python.org/reference/simple_stmts.html#future-statements Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: An unusual question...

2011-04-17 Thread Chris Angelico
On Mon, Apr 18, 2011 at 4:21 PM, wrote: > Hi Rhodri... > >> You do realise that what id() returns is implementation-dependent, don't >> you?  In particular, what IronPython returns isn't an address. > > I'm pretty sure I wrote "standard Python" install in one of my replies. > > Yeah here it is in

Re: Make Python "portable" by default! (Re: Python IDE/text-editor)

2011-04-18 Thread Chris Angelico
s this mean they need to be "installed" only under Windows? No. They need to be installed to be run, it's just that the installer is unzip or tar. (FYI, we "installed" a new minister in the church's manse a few weeks ago. Didn't involve anything more than a mv.) Chr

Re: strange use of %s

2011-04-18 Thread Chris Angelico
_injection If it's just a toy for demonstrative purposes that's fine, but it's good to be aware of these issues. Check out the library you're using for database access; it's quite possible that you'll be able to embed variable references in a different way, and let the library escape them for you - otherwise, look for some kind of escape_string function. Hope that helps! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: An unusual question...

2011-04-18 Thread Chris Angelico
We have an isolation environment in which we'll be allowing our clients to provide Python scripts - which means we have to be sure it'll all be safe. BTW, the point at which it bombs is defined by ulimit/rlimit, unless you fiddle with the memory allocator. See previous thread on the subject. :D Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Can you advice a Python library to query a lan subnet with SNMP and collect MAC addresses of nodes?

2011-04-18 Thread Chris Angelico
rther processing to get exact > filtered records with MAC addresses I needed I don't know if it's significant, but if I want to process a command's output using Python, I'll generally use: nmap -sP | /path/to/script.py rather than os.system() and temporary files. YMMV thou

Re: Popen to get stdout and stderr for ffmpeg - No such file or directory ?

2011-04-18 Thread Chris Rebert
he name or path of the program to execute; ***this will only work if the program is being given no arguments.***" (emphasis added) The system is interpreting the entire command string as the path to an executable; obviously there's no directory named "ffmpeg -i ", so the pat

Re: [Tutor] working with strings in python3

2011-04-18 Thread Chris Angelico
our data up in XML, send it to the other end, they unpack it and turn it into what they want. End of XMLness. And if you want anything binary ("hey guys, here's the icon that I want you to display with this thing", for instance), it gets messier. Much neater to avoid it altogether. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Python IDE/text-editor

2011-04-18 Thread Chris Angelico
W emacs can be morphed into vi The emacs-vi wars... where the men were real men, the women were real women, and vi was just emacs in disguise... Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: strange use of %s

2011-04-18 Thread Chris Angelico
IKE '%' + 'value' + '%'" which is perhaps overkill (it forces the database engine to concatenate three strings), but at least it's safe. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-18 Thread Chris Angelico
On Tue, Apr 19, 2011 at 4:23 PM, Kushal Kumaran wrote: >> if a + b + c + d != 1: >>    raise ValueError("Exactly one of a, b, c or d must be true.") >> > > Unless you're sure all of a, b, c, and d are boolean values, an int > with a negative value slipping in could result in the sum equaling 1, >

Re: Feature suggestion -- return if true

2011-04-19 Thread Chris Angelico
sometimes you need a simple and well-known algorithm to demonstrate a language feature with. Maybe we should switch to Fibonacci instead... Anyone for caramel sauce? http://www.dangermouse.net/esoteric/chef_fib.html (As a side point, I have become somewhat noted around the house for always saying &

Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Chris Angelico
(greylist[ip]>time()) + (++spewcnt>10))>=3) // flag this packet as suspicious Contrived example as I don't recall any specifics right now, but this will pick up any packets where three or more of the conditions are met. Useful only in fairly specific situations, but I don't know of any w

Re: Looking for a urllib(2) cookie handler

2011-04-19 Thread Chris Rebert
ace: from pysqlite2 import dbapi2 as sqlite With: import sqlite3 as sqlite You'll also have to figure out where Firefox's `cookies.sqlite` file is located on your system. Cheers, Chris -- My compiler is compiling, I swear! http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for a urllib(2) cookie handler

2011-04-19 Thread Chris Rebert
$ME and $URL are replaced with suitable values. It doesn't > appear to acutally be "using" the cookies. http://wwwsearch.sourceforge.net/mechanize/doc.html : "Firefox since version 3 persists cookies in an sqlite database, which is not supported by MozillaCookieJar." Pleas

Re: Pickling over a socket

2011-04-19 Thread Chris Rebert
ete of this suggestion.] Have you tried removing line #21 and/or #32? http://docs.python.org/library/socket.html#socket.socket.shutdown : "socket.shutdown(how) - Shut down one or both halves of the connection. [...] Depending on the platform, shutting down one half of the connection c

Re: Pickling over a socket

2011-04-19 Thread Chris Angelico
the file-from-socket method, and simply using pickle.dumps() and pickle.loads() to pickle to/from strings; those strings can then be sent/received over the socket using standard recv/send functions. Also, Chris Rebert's idea is a good one, and worth trying. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Pickling over a socket

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 5:30 AM, Dan Stromberg wrote: > I played around with it until something worked, and ended up with the > below.  The most significant change was probably using sc.makefile > instead of s.makefile in the server... Oh! I didn't notice that in the OP. Yep, that would do it! C

Re: Namespaces in functions vs classes

2011-04-19 Thread Chris Angelico
st a foreign tragedy. There are destitute persons right near us. Donate NOW to end the hunger! All donations go 100% to the needy. * Chris Angelico * After processing fees and my cut, of course. Hey, these list advertisements don't come free! -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Chris Angelico
at a higher level? Presumably there's a full protocol stack with application data getting wrapped up inside (ultimately) ethernet frames; can you cut it somewhere else and make, say, a TCP/IP connection to the remote system? Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: My stupidity / strange inconsistency overriding class methods

2011-04-19 Thread Chris Rebert
s foo.  Yet C can override foo, but A is > unable to override the instance check. The difference is in the __special__-ness of the method names in question. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Chris Angelico
/1 that picks up all the IP ranges? That way, the source-IP check wouldn't fail. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Remote Connection

2011-04-19 Thread Chris Rebert
chine > is . . . right now an XP Pro but will change to a Windows 7 Pro.  I do > not have a cell for this; I am waiting to see if any solution may > dictate the cell details. How does this specifically involve Python at all, pray tell? Regards, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Chris Angelico
casts send to subnets it's not on.  That pretty much > clinches the requirement to use a raw socket. :/ Sounds to me like someone majorly abused IP to do weird things. Looks like you're stuck doing the same weirdness, in whatever way you can manage :| Sorry. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

List comprehension vs filter()

2011-04-19 Thread Chris Angelico
estrict to that one type lst=[i for i in lst if i["type"].lower()==type] # Restrict to that one type If I use the filter() method, the resulting list is completely empty. If I use the list comprehension, it works perfectly. Oddly, either version works in the stand-alone interpreter

Re: List comprehension vs filter()

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 1:10 PM, Chris Angelico wrote: > type=lst[0]["type"].lower() > > lst=filter(lambda x: x["type"].lower()==type,lst) # Restrict to that one type After posting, I realised that "type" is a built-in identifier, and did a quick v

Re: List comprehension vs filter()

2011-04-19 Thread Chris Rebert
On Tue, Apr 19, 2011 at 8:10 PM, Chris Angelico wrote: > type=lst[0]["type"].lower() Tangent: Don't call it "type"; you're shadowing the built-in class of the same name. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension vs filter()

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 1:22 PM, Chris Rebert wrote: > On Tue, Apr 19, 2011 at 8:10 PM, Chris Angelico wrote: > >> type=lst[0]["type"].lower() > > Tangent: Don't call it "type"; you're shadowing the built-in class of > the same name. By

Re: List comprehension vs filter()

2011-04-19 Thread Chris Rebert
On Tue, Apr 19, 2011 at 8:23 PM, Chris Angelico wrote: > On Wed, Apr 20, 2011 at 1:22 PM, Chris Rebert wrote: >> On Tue, Apr 19, 2011 at 8:10 PM, Chris Angelico wrote: >> >>> type=lst[0]["type"].lower() >> >> Tangent: Don't call it "t

Re: List comprehension vs filter()

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 1:45 PM, Chris Rebert wrote: > Built-ins aren't quite the same as globals, but essentially yes: Sure. That might explain some of the weirdness, but it doesn't explain why things were still weird with the variable named posttype. However, since the list co

Re: Teaching Python

2011-04-19 Thread Chris Angelico
terms of tinkering with the language itself (Python scripting is writing .py files and running them, Python hacking is grabbing the source, fiddling with it, and running make). Unfortunately the second sense of the word is the only one a lot of people know. Chris Angelico -- http://mail.python.or

Re: List comprehension vs filter()

2011-04-19 Thread Chris Angelico
ll. The body of the code has: if len(lst): posttype=... lst=... No other structural elements to get in the way - unless calling the code as described is creating one. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Pickling over a socket

2011-04-20 Thread Chris Angelico
network transmission. Also, I like to use a MUD client to test my servers, ergo textual protocols similar to SMTP. Sure, it may be a tad more verbose than some, but it's usually easy to parse and verify. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing Exif File

2011-04-20 Thread Chris Rebert
sing the php > exif_read_data function (http://php.net/manual/fr/book.exif.php) Possibilities: pyexif - http://pypi.python.org/pypi/pyexif/ pexif - http://pypi.python.org/pypi/pexif/ In the future, try searching PyPI, Python's rough equivalent of Perl's CPAN: http://pypi.python.org/pyp

Re: Vectors

2011-04-20 Thread Chris Rebert
c features, but NumPy is the gold standard for matrix-y stuff in Python: http://numpy.scipy.org/ And apparently it's even Python 3.1-compatible now; that's quite a feat. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension vs filter()

2011-04-20 Thread Chris Angelico
thinking, or I do. And it's usually easier to change me, except that I use so many languages. :) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

<    30   31   32   33   34   35   36   37   38   39   >