Re: if statement multiple or

2011-05-06 Thread Chris Rebert
r 'c')  not in line: >>    print line >> > > The expression: >    ('a' or 'b' or 'c') > > evaluates to True Not quite: $ python Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) >>> 'a' or 'b' or 'c' 'a' >>> Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Torek
; be True rather than False. [% This is not at all obvious -- I have written an immutable class, and it is pretty easy to accidentally mutate an instance inside the class implementation. There is nothing to prevent this in CPython, at least. If there were a minor bug in the decimal.Decimal code suc

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Torek
is not promised, for instance, whether the "is" operator is always True for small integers that are equal (although it is in CPython), nor when __del__ is called (if ever), and so on. As with the Python-named-Monty, we have "rigidly defined areas of doubt and uncertainty". These

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Torek
called (if ever), and so on. As >with the Python-named-Monty, we have "rigidly defined areas of >doubt and uncertainty". These exist for good reasons: to allow >different implementations. Oops, attribution error: this comes from Douglas Adams rather than Monty Python. -- In-R

Re: Python 3 dict question

2011-05-06 Thread Chris Rebert
ms()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): >   do_something >   break > but maybe there is any better way? key, val = next(myDict.items()) Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-06 Thread Chris Rebert
qually stupid; `count` would be a lousy name (people would confuse it with what the current .count() does). `length` or `size` would make much more sense. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Angelico
On Sat, May 7, 2011 at 5:25 AM, harrismh777 wrote: > Chris Torek wrote: >>> >>> with the Python-named-Monty, we have "rigidly defined areas of >>> >doubt and uncertainty".  These exist for good reasons: to allow >>> >different implemen

Re: string formatting

2011-05-06 Thread Chris Angelico
On Sat, May 7, 2011 at 6:54 AM, Terry Reedy wrote: > def emsg(x): >  if isinstance(x,tuple): >    x = (x,) >  print(The following object caused a proplem: %s" % x) > Couldn't you just do that unconditionally? print(The following object caused a proplem: %s" %

Re: checking if a list is empty

2011-05-06 Thread Chris Angelico
ll. People assume and expect that this compact syntax will be available, and object heavily to such notation as "add(x,y)" which says exactly what it does. if not li: is perfectly readable; you just need a comprehension of what truth means for a list. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-07 Thread Chris Angelico
other: I think "manipulate" here means things like pointer arithmetic, which are perfectly normal and common in C and assembly, but not in languages where they're references. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Stuck with urllib.quote and Unicode/UTF-8

2011-05-07 Thread Chris Rebert
g? Nope, it's Latin-1 (or similar, e.g. Windows-1252): Python 2.7.1 (r271:86832, Dec 5 2010, 00:12:20) >>> x = u"Köln" >>> x.encode('utf_8') 'K\xc3\xb6ln' >>> x.encode('latin_1') 'K\xf6ln' >>> Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Custom string joining

2011-05-07 Thread Chris Rebert
y accepts iterables of strings: new_string = "|".join(str(x) for x in iterable_of_custom_objects) Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-07 Thread Chris Angelico
und variable as a set of tokens, then evaluate the whole thing again, and is that the name? Because the resulting "name" might not be a valid identifier... Yep, it's good stuff. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: ABC-registered Exceptions are not caught as subclasses

2011-05-07 Thread Chris Rebert
in > __main__.MyException > > If you assume that the ABC "register" class should work likeinheritance (as > it does with issubclass and isinstance then you would, I think, have expected > the exception above to have been caught. Seems worth filing a bug IMO; it pro

Re: What other languages use the same data model as Python?

2011-05-07 Thread Chris Angelico
As Inigo Montoya said, there is too much - let me sum up. Lists/tuples and integers are equally objects, so whether or not you have a 'name' is not affected by what type of object it points to. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary from String?

2011-05-08 Thread Chris Angelico
e=greg#hatsize=7 5/8" dict((field.split('=',1) for field in mystring.split('#'))) I used the hash character as a separator here, but you could just as easily use a non-printing character like \n if you can be sure it never appears in any string value. (It's okay for an equals sign, as long as it's not in the field name.) Hope that's of value! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Development time vs. runtime performance (was: Fibonacci series recursion error)

2011-05-08 Thread Chris Angelico
to grok than a language that has myriad "gotchas" to work around. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: How to access elemenst in a list of lists?

2011-05-08 Thread Chris Angelico
On Mon, May 9, 2011 at 1:15 PM, Chris Roy-Smith wrote: > Just learning python. > I can see that I can address an individual element of a list of lists by > doing something like: > row = list[5] > element = row[3] > > But is there a way to directly address an entry in a s

Re: What other languages use the same data model as Python?

2011-05-09 Thread Chris Angelico
one as squares and one as circles, but don't try that in plain text. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Zope with mySQL

2011-05-09 Thread Chris Withers
Hi Harry, You'd be better off asking this on the [email protected] mailing list... cheers, Chris On 28/04/2011 20:19, harryjatt wrote: Hi, i am doing web development with Zope. My connected database is mySQL. I am new to this combination.I have to upload the files to mySQL with programmi

Re: What other languages use the same data model as Python?

2011-05-10 Thread Chris Angelico
expression - the "current namespace") to your object. That might involve several names, or none at all, but if there's no such path, the object is unreferenced and must be disposed of. IIRC that's not just an implementation detail (the garbage collector), but a language guarant

Re: can't get urllib2 or httplib to work with tor & privoxy

2011-05-10 Thread Chris Angelico
me from the client. Once you've found the difference(s) between Lynx and your script, you can see what's causing the 503 (Service Unavailable) error; it may be that you need to authenticate with the proxy. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: string formatting

2011-05-10 Thread Chris Angelico
nd people can disagree about whether or not something is. (Hi Ken, your continued use of inches is noted. Thank you.) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-10 Thread Chris Angelico
Language is for communication. If we're not using the same meanings for words, we will have problems. Chris Angelico PS. By "mean", I mean average. Except when I mean mean. But now I'm just being mean. -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-10 Thread Chris Angelico
On Wed, May 11, 2011 at 1:40 AM, Hans Georg Schaathun wrote: > On Wed, 11 May 2011 01:27:36 +1000, Chris Angelico >   wrote: > :  Language is for communication. If we're not using the same meanings > :  for words, we will have problems. > > So if you adopt the word c

Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread Chris Angelico
protocol is command-response, like a MUD or a mail server). Once you get your head around the threading module, you'll find the multiprocessing module very similar. For Python, the difference is sometimes quite important, so it's as well to understand both. Hope that helps! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread Chris Angelico
u intend. > to check the status of the thread repeatedly I have the QTimer which would > call the self.sendData() for every minute. > >     self.timer = QTimer() >     self.timer.connect(self.timer, SIGNAL("timeout()"),self.sendData) >     self.timer.start

Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread Chris Angelico
the logic? any other better ways of achieving this? > You'll find it easier to get an event at the end of it; simply have another line of code after the os.system() which will reenable the button. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-11 Thread Chris Angelico
ited extensively with, for instance, the stream I/O objects evaluating as false when in an error or EOF state: while (infile) infile >> *ptr++; // Compact and convenient way to read into an array Actually that one can be combined down even further, but for clarity I leave it like that. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread Chris Angelico
s of QThread? Is it possible (safe) to manipulate QT objects - in this case, the button - from a thread other than the one that created them? (If not, that would be a good reason for using QThread, which will fire an event upon termination.) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-11 Thread Chris Angelico
g a piece of code under someone's nose and saying "I bet you can't figure out what THIS does!". Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-11 Thread Chris Torek
here the result is defined as equivalent. (The biggest problem with answering that tends to be deciding what types x might take.) [% Chocolate with raspberry, or mint, or similar.] -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-11 Thread Chris Torek
turns the canonical bool >values: > >not returns False >not returns True > >Take note of the distinction between lower-case true/false, which are >adjectives, and True/False, which are objects of class bool. (At least as of current versions of Python -- in much older versions

Re: checking if a list is empty

2011-05-11 Thread Chris Angelico
ome and realize you forgot something). Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: lightweight way to create new projects from templates

2011-05-11 Thread Chris Angelico
files and/or directories. That way, your template is all contained in a single file, which is convenient for distribution and such; and the scripting facilities can handle the search and replace operations. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: NewBie Doubt in Python Thread Programming

2011-05-12 Thread Chris Angelico
done with os.system() quite happily. Change that, and it should all work. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: NewBie Doubt in Python Thread Programming

2011-05-12 Thread Chris Angelico
On Thu, May 12, 2011 at 7:42 PM, vijay swaminathan wrote: > Hi Chris, > > I tried using os.system as well but it did not even open up the command > prompt. > > Can you please share the code that worked for you.. just wondering if I'm > missing something very basic. C

Re: checking if a list is empty

2011-05-12 Thread Chris Angelico
would he be expected simply to fulfill his contract and provide me with my structure? Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-12 Thread Chris Angelico
On Thu, May 12, 2011 at 10:43 PM, Hans Georg Schaathun wrote: > On Thu, 12 May 2011 22:16:10 +1000, Chris Angelico >   wrote: > :  Anyone can join. Not everyone wants to join. Me, I'm happy here as a > :  priest of the software industry, and I have no desire to become a &g

Re: checking if a list is empty

2011-05-12 Thread Chris Angelico
On Fri, May 13, 2011 at 12:02 AM, Ethan Furman wrote: > Chris Angelico wrote: >> >> On Thu, May 12, 2011 at 7:02 AM, Ian wrote: >>> >>> In the "real world"  lists of zero items do not exist. >>> You don't go shopping with a shopping lis

Re: checking if a list is empty

2011-05-13 Thread Chris Rebert
ly bool. This line of argument thus fails. The fact that other types are implicitly coercible to bools doesn't make `bool` itself any less first-class. It is also ironic that one of the projects that exploits Python's flexible typing regarding normally-Boolean operators is a scientific one (NumPy). Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Having a problem getting python working...

2011-05-14 Thread Chris Paton
eciated. Need to get into this ASAP as I need to do some stuff for my thesis project! Thanks! Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-14 Thread Chris Angelico
On Sat, May 14, 2011 at 5:45 PM, rusi wrote: > And then we get the interesting result that > (True = True) is False How does this work? In Python, the = sign is illegal there, and if you mean True == True, then it's True (obviously), which is not False. Chris Angelico -- http://mail

Re: checking if a list is empty

2011-05-14 Thread Chris Angelico
viously* there'll be a huge amount that fits into one or the other without being identical. It's not an argument for whether [1,2,3] ought to be True or ought to be False. You could make the exact same argument if they evaluated to False. You have proven nothing and just wasted your time

Re: Converting a set into list

2011-05-14 Thread Chris Angelico
t with one element, the set itself. It's not a copy of the set, it's another reference to the same set; change one and you'll see the change in the other. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: I don't understand generator.send()

2011-05-14 Thread Chris Angelico
u to decide whether that's any use or not.) Hope that helps! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: I don't understand generator.send()

2011-05-14 Thread Chris Rebert
; g = example('a') >>> g.send(3) Traceback (most recent call last): File "", line 1, in TypeError: can't send non-None value to a just-started generator >>> # Ok, so we can't send something back to `yield` >>> # until we hit the first

Re: I don't understand generator.send()

2011-05-14 Thread Chris Angelico
0)) else: sent=(yield i) i+=1 while sent is not None: queue.append(sent) sent=(yield None) # This is the return value from gen.send() That should work. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a set into list

2011-05-14 Thread Chris Torek
e', 'five'] >>> x ['three', 'one', 'four', 'one', 'five'] >>> list(set(x)) ['four', 'five', 'three', 'one'] >>> sorted(list(set(x))) ['five

Re: dict: retrieve the original key by key

2011-05-15 Thread Chris Rebert
such functionality was not considered to be useful enough.) Define "original key". Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: connect SIGINT to custom interrupt handler

2011-05-15 Thread Chris Angelico
siginterrupt' > > Could there be a namespace problem? def interrupt_handler(signal, frame): You're using 'signal' as a parameter here. The local int is masking the global module. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: dict: retrieve the original key by key

2011-05-15 Thread Chris Rebert
. > > It was, however, removed in 3.x as a seldom-externally-used internal > implementation detail. Still exists in sys module though: http://docs.python.org/dev/library/sys.html#sys.intern Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: MySQLdb SEC_TO_TIME function returns datetime.timedelta class

2011-05-15 Thread Chris Angelico
Nov 2nd). The result exceeds a day; in what format do you actually want it? For maximum flexibility, you could ditch the SEC_TO_TIME call and simply work with the integer seconds in Python. You can then format that into H:MM:SS or whatever suits you. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Chris Rebert
): >        # do stuff > > But all I get is: > TypeError: __init__() takes exactly 1 positional argument (2 given) > > I don't understand, I am only sending one variable. What does it think > I am sending two? Please post the *full* exception Traceback. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: obviscating python code for distribution

2011-05-15 Thread Chris Angelico
something that by and large is one person's work, I think it's appropriate to give attribution. But discussion of exactly _which_ open source license to use is a can of worms that's unlikely to be worth opening at this stage. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Chris Rebert
"# do stuff" from earlier isn't doing the right stuff? Posting the actual code would help. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: obviscating python code for distribution

2011-05-15 Thread Chris Angelico
down to do updates. That's considered normal in today's world, but I really don't know why... downtime is SO last century! Chris Angelico happily running servers on fully open source stacks -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert AWK regex to Python

2011-05-16 Thread Chris Angelico
mand, Status: $status, > Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | grep > $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; done Small side point: Instead of "| sort | uniq |", you could use a Python dictionary. That'

Re: Convert AWK regex to Python

2011-05-16 Thread Chris Angelico
oring the intermediate data in a dictionary and then retrieving it at the end. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: obviscating python code for distribution

2011-05-16 Thread Chris Angelico
, you see a ship suddenly yoinked to its new position when the client gets the latest location data. That's a fair compromise, I think; the client predicts where the ship "ought to be", and the server corrects it when it can. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a set into list

2011-05-16 Thread Chris Torek
>Chris Torek wrote: >> >>> x = [3, 1, 4, 1, 5, 9, 2, 6] >> >>> list(set(x)) >> This might not be the best example since the result is sorted >> "by accident", while other list(set(...)) results are not. In article , Duncan Booth

Re: indirect assignment question

2011-05-16 Thread Chris Rebert
w = self.wTree.get_widget # or choose some other similarly short variable name self.window = w("mainWindow") self.outputToggleMenu = w("menuitem_output_on") self.outputToggleButton = w("button_toggle_output") self.logView = w("textview_log") self.logScrollWindow = w("scrolledwindow_log") Python functions/methods are first-class; exploit this feature! Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: obviscating python code for distribution

2011-05-16 Thread Chris Angelico
On Tue, May 17, 2011 at 4:16 PM, Dotan Cohen wrote: > Actually, Chris, those applications are probably no less valuable to > be open source than Linux or Firefox. The reason is that when one goes > to learn a new language it is valuable to look at existing real world > code. Howev

in search of graceful co-routines

2011-05-17 Thread Chris Withers
is? (I'm particularly interested in a sane way to use the two way communication that PEP 342 introduced) cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list

Re: if statement on lenght of a list

2011-05-17 Thread Chris Rebert
straightforwardly write it as: if not isinstance(value, list) or len(value) != 19: Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: best way to extract sentence from txt file

2011-05-17 Thread Chris Angelico
On Wed, May 18, 2011 at 4:40 AM, Michiel Overtoom wrote: > Until then we have to guess, and my E.S.P. is notoriously bad. Roll d20 and add your ESP skill and your Wisdom modifier. The DC for this test is 20 if you're familiar with D&D, or 25 if you are not. Chris Angelico Du

Re: English Idiom in Unix: Directory Recursively

2011-05-17 Thread Chris Angelico
rithmically accurate, it carries the meaning. The "mind-space" requirement is quite compact; you can ignore the "into subdirectories" part and just think "-r means recurse", whereas the alternative is "-r means files in this directory and all its subdirectories". Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: in search of graceful co-routines

2011-05-17 Thread Chris Angelico
On Wed, May 18, 2011 at 3:04 AM, Chris Withers wrote: > Hi All, > > I'm looking for a graceful pattern for the situation where I have a provider > of a sequence, the consumer of a sequence and code to moderate the two, and > where I'd like to consumer to be able to signa

Re: in search of graceful co-routines

2011-05-17 Thread Chris Withers
s kind of birds nest I'm trying to avoid... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list

Re: in search of graceful co-routines

2011-05-17 Thread Chris Withers
end('hello') TypeError: can't send non-None value to a just-started generator ...which is, in itself, a little weird, given that it doesn't protect against: provider = Provider(1,2,3) val = provider.next() provider.send("don't want this to be possible") pro

Re: obviscating python code for distribution

2011-05-18 Thread Chris Angelico
now every detail about your comms protocol, because chances are he will know most of it. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: obviscating python code for distribution

2011-05-18 Thread Chris Angelico
s going to impose 500ms latency on all packets just to prevent the one chance in 1E50 that you get some particular attack, then it's really not worthwhile. However, it IS possible to ensure that the server doesn't, for instance, trust the client; those extremely basic protections are well

Re: obviscating python code for distribution

2011-05-18 Thread Chris Angelico
rvices and depend on the underlying libraries to deal with malformed packets and such. On Linux, I generally whip up a quick script to do whatever job on the spot (Python and Pike are both extremely well suited to this), but on Windows, I use my MUD client, RosMud, which has a "passive mode" option for playing the part of the server. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Chris Angelico
On Thu, May 19, 2011 at 2:16 AM, Thomas A. Russ wrote: > Well, unless you have a tree with backpointers, you have to keep the > entire parent chain of nodes visited.  Otherwise, you won't be able to > find the parent node when you need to backtrack.  A standard tree > representation has only direc

Re: obviscating python code for distribution

2011-05-18 Thread Chris Angelico
On Thu, May 19, 2011 at 4:31 AM, Dotan Cohen wrote: > The python code should not be concerned with DDoS, that is what > iptables is for. Remember, never do in code what Linux will do for > you. In general, yes. Denial of service is a fairly broad term, though, and if there's a computationally-exp

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Chris Angelico
x27;t know how much memory is available to you... Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: obviscating python code for distribution

2011-05-18 Thread Chris Angelico
for a few good names!), so if you have specific questions regarding your Python code, do ask. Alternatively, if it's not particularly Python-related, I would be happy for you to email me privately; I'm a gamer, and run an online game, so I'd be quite willing to have a bit of a poke at your code. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Faster Recursive Fibonacci Numbers

2011-05-19 Thread Chris Angelico
x27;t have arbitrary precision non-integers, does it? So this is going to be done with floats. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: obviscating python code for distribution

2011-05-19 Thread Chris Angelico
deploy it, they have to take ultimate responsibility (although they will legitimately expect you to provide an install script and/or instructions). There are idiots in this world. Have you met them? Met them? I listen to you every week! -- The Goon Show, and so absolutely true Chris Angeli

Re: obviscating python code for distribution

2011-05-19 Thread Chris Angelico
sponsible for the computer's security; and if you have the root filesystem password, there's no way that something can be made unmisconfigurable. (You CAN, however, make something that's out-of-the-box secure, so someone just does a 'sudo apt-get install yoursystem' and i

Re: Recursion in Computer Science

2011-05-19 Thread Chris Angelico
On Fri, May 20, 2011 at 3:05 PM, rusi wrote: >  - data can be code -- viruses It's not JUST viruses. There's plenty of legitimate reasons for your data to actually be code... that's how compilers work! :) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Faster Recursive Fibonacci Numbers

2011-05-19 Thread Chris Angelico
same if there's a fractional part on it. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: hash values and equality

2011-05-19 Thread Chris Rebert
.. self.n = n ... def __eq__(self, other): ... return self.n == other.n ... >>> Naughty(5) == Naughty(5) True >>> Naughty(5) is Naughty(5) False >>> bad = Naughty(3) >>> y = {bad : 'foo'} >>> y[bad] # just happens to work 'foo' >>> del bad >>> # ok, how do we get to 'foo' now? >>> y[Naughty(3)] # try the obvious way Traceback (most recent call last): File "", line 1, in KeyError: <__main__.Naughty object at 0x2a1cb0> >>> # We're screwed. Naughty instances (and similar) can't be used sensibly as hash keys (unless you /only/ care about object identity; this is often not the case). Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Faster Recursive Fibonacci Numbers

2011-05-19 Thread Chris Angelico
onsecutive digits in it? All 10 digits? (That is, it has '0123456789' somewhere in its decimal representation.) Like I said, completely useless... but how many of you immediately pondered which language to implement the search in? Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: English Idiom in Unix: Directory Recursively

2011-05-20 Thread Chris Angelico
On Wed, 18 May 2011 12:59:45 -0500, Victor Eijkhout wrote: > Recursion: (N). See recursion. See also tail recursion. caching proxy (n): If you already know what recursion is, this is the same. Otherwise, see recursion. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Python sets which support multiple same elements

2011-05-20 Thread Chris Angelico
 return False >    else: >      w2.remove(c) >  return True You may find it helpful to simply sort the lists, keeping them as lists. If they're anagrams of each other, their sorted versions will be equal. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: hash values and equality

2011-05-20 Thread Chris Angelico
the same index, and objects with different hashes could be > stored in the same 'bucket'. There can always be hash collisions between different objects, but the assumption is that two identical objects will _always_ "collide". Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: hash values and equality

2011-05-20 Thread Chris Kaynor
On Fri, May 20, 2011 at 9:20 AM, Chris Angelico wrote: > On Sat, May 21, 2011 at 1:50 AM, MRAB wrote: > > [snip] > > Is this strictly true? I thought that the hash value, an integer, is > > moduloed (Is that how you spell it? Looks weird!) with the number of > > arra

Re: hash values and equality

2011-05-20 Thread Chris Rebert
On Fri, May 20, 2011 at 10:56 AM, Ethan Furman wrote: > Chris Rebert wrote: >> On Thu, May 19, 2011 at 10:43 PM, Ethan Furman wrote: >>> Several folk have said that objects that compare equal must hash equal, >>> and >>> the docs also state this >

Re: Faster Recursive Fibonacci Numbers

2011-05-20 Thread Chris Angelico
On Sat, May 21, 2011 at 3:07 AM, Steven D'Aprano wrote: > On Fri, 20 May 2011 16:54:06 +1000, Chris Angelico wrote: > >> If someone has time to kill (as if!), it'd be awesome to get a new >> numeric type that uses bc's code; any other numeric type (int, long,

Re: Problem in using subprocess module and communicate()

2011-05-21 Thread Chris Rebert
tting this all together, here's an improved version: def runMonitor(command): proc = subprocess.Popen([command, '/k', 'dir'], cwd='C:/Python26/WorkSpace/FunctionExamples/src', stdin=subprocess.PIPE, creationflags=subprocess.CREATE_NEW_

Re: checking if a list is empty

2011-05-21 Thread Chris Angelico
cstring / autodoc comment that says what the function wants and gives. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-21 Thread Chris Angelico
the consequences of trivia - you can't really name it descriptively.) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Why did Quora choose Python for its development?

2011-05-21 Thread Chris Angelico
W. Perl: The Swiss Army Knife of programming languages, including the bit where you can never find the right blade to open up. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-21 Thread Chris Angelico
over ssh, afaik), so it's worth learning more than one. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: count strangeness

2011-05-21 Thread Chris Rebert
ce what happens when we use a statement instead of an expression: >>> final = c.doit() 1 2 4 8 16 32 64 128 256 512 1024 >>> final 1024 >>> And if we comment out the `print` in C.doit() and run your example again: >>> c = C() >>> c.data = [C() for i in xrange(10)] >>> c.doit() 1024 >>> Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a better way to solve this?

2011-05-21 Thread Chris Rebert
\n' try: length = int(raw_input(Q)) except ValueError: print 'Invalid input detected' exit(0) Also, as a sidenote: > if type(length) is int: Is normally written: if isinstance(length, int): Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: count strangeness

2011-05-22 Thread Chris Rebert
On Sat, May 21, 2011 at 11:32 PM, James Stroud wrote: > Chris Rebert wrote: >>> >>> WTF? >> >> Assuming your question is "Why is 1024 there twice?", the answer is > > The question is "Why is 1024 there at all?" It should be 10. Ah.

Re: TK program problem

2011-05-22 Thread Chris Angelico
'm a little mad and generally silly, so my opinion doesn't matter (matter matter matter matter). But it did work, and the code was nice and clean! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: English Idiom in Unix: Directory Recursively

2011-05-22 Thread Chris Angelico
sense to offer the user a choice, and if recursive action is the only one that makes sense, at least acknowledge that the operation might take an arbitrarily long time. (Ever done a recursive operation on / on a large file system? Takes just a little bit longer than a non-recursive one under t

<    32   33   34   35   36   37   38   39   40   41   >