Debugging cookielib.CookieJar

2011-07-19 Thread Roy Smith
I've got a unit test suite which instantiates an HTTP client to test our server. We depend on session cookies. To handle this, I've got: def setUp(self): self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj)) This works fine

Re: Debugging cookielib.CookieJar

2011-07-19 Thread Roy Smith
Ah, never mind. I found "cookielib.debug = True", which told me exactly what I needed to know. I did indeed have a hostname problem. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get number of bytes written to nonblocking FIFO when EAGAIN is raised?

2011-07-19 Thread Roy Smith
In article <40996f2a-4ed8-4388-ae1a-6f81f57a4...@f17g2000prf.googlegroups.com>, Aaron Staley wrote: > Scenario. I have a fifo named 'fifo' on my computer (ubuntu linux) > operating in nonblocking mode for both read and write. Under normal > operation all is good: > > Interpreter 1 (writer) >

Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Roy Smith
In article , Terry Reedy wrote: > Whether or not they are intended, the rationale is that lining up does > not work with proportional fonts. There are very few things I am absolutely religious about, but programming in a fixed width font is one of them. -- http://mail.python.org/mailman/list

Another win for profiling.

2011-07-29 Thread Roy Smith
It's often said that you shouldn't try to guess what's slow, but use profiling tools to measure what's slow. I had a great example of that yesterday. We have some web server code that does a big database (MongoDB) query and some post-processing of the data in python. It worked fine in testin

Re: Complex sort on big files

2011-08-05 Thread Roy Smith
Wow. I was going to suggest using the unix command-line sort utility via popen() or subprocess. My arguments were that it's written in C, has 30 years of optimizing in it, etc, etc, etc. It almost certainly has to be faster than anything you could do in Python. Then I tried the experiment.

Re: Restricted attribute writing

2011-08-07 Thread Roy Smith
In article , John O'Hagan wrote: > I'm looking for good ways to ensure that attributes are only writable such > that they retain the characteristics the class requires. Sounds like you're trying to do http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad thing. But, I think

Re: How do I convert String into Date object

2011-08-13 Thread Roy Smith
In article <83822ecb-3643-42c6-a2bf-0187c07d3...@a10g2000yqn.googlegroups.com>, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. You have already received a number of good replies, but let me throw out one more idea. If you ever need t

Re: allow line break at operators

2011-08-14 Thread Roy Smith
In article <4e47db26$0$30002$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Er, most URLs are case insensitive, at least the most common ones, including > HTTP and HTTPS. So I don't quite see why you think this was a Whoops. URLs are most certainly not case insensitive. Parts of

Re: allow line break at operators

2011-08-14 Thread Roy Smith
In article , Dave Angel wrote: > > URLs are most certainly not case insensitive. Parts of them may be > > (i.e. the scheme and host parts), but not the stuff after the hostname. > > > The thing that confuses people is that not only is the part up to and > through the domain name is case-insens

Re: allow line break at operators

2011-08-15 Thread Roy Smith
In article , Chris Angelico wrote: > Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. Computer programming languages follow math conventions only in the most vague ways. For example, standard

Re: allow line break at operators

2011-08-15 Thread Roy Smith
In article , Chris Angelico wrote: > Or: "Blasted PHP, which > operators have precedence between || and or?" which is easy to forget. > > And you're right about the details changing from language to language, > hence the operators table *for each language*. But most languages > follow fairly sa

Re: allow line break at operators

2011-08-15 Thread Roy Smith
In article <4e492d08$0$30003$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > I'm reminded of this quote from John Baez: > > "The real numbers are the dependable breadwinner of the family, the complete > ordered field we all rely on. The complex numbers are a slightly flashier > bu

Re: testing if a list contains a sublist

2011-08-15 Thread Roy Smith
In article , Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 =

Re: Ten rules to becoming a Python community member.

2011-08-15 Thread Roy Smith
In article <9att2bf71...@mid.individual.net>, Gregory Ewing wrote: > rantingrick wrote: > > "Used to" and "supposed to" is the verbiage of children > > and idiots. > > So when we reach a certain age we're meant to abandon > short, concise and idomatic ways of speaking, and substitute > long wor

Re: Ten rules to becoming a Python community member.

2011-08-15 Thread Roy Smith
In article <9att9mf71...@mid.individual.net>, Gregory Ewing wrote: > I don't mind people using e.g. and i.e. as long > as they use them *correctly*. The only correct way to use i.e. is to use it to download a better browser. -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expression

2011-08-16 Thread Roy Smith
In article , Chris Rebert wrote: > pat = re.compile("^ *(\\([^)]+\\))", re.MULTILINE) First rule of regexes in Python is to always use raw strings, to eliminate the doubled backslashes: > pat = re.compile(r"^ *(\([^)]+\))", re.MULTILINE) Is easier to read. -- http://mail.python.org/mailman/

Re: testing if a list contains a sublist

2011-08-16 Thread Roy Smith
In article <8739h18rzj@dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > Roy Smith writes: > > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > [...] > > import re > > &

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-18 Thread Roy Smith
In article <16ea4848-db0c-489a-968c-ca40700f5...@m5g2000prh.googlegroups.com>, gc wrote: > I frequently need to initialize several variables to the same > value, as I'm sure many do. Sometimes the value is a constant, often > zero; sometimes it's more particular, such as defaultdict(list). I us

Re: How to convert a list of strings into a list of variables

2011-08-19 Thread Roy Smith
In article <2ab25f69-6017-42a6-a7ef-c71bc2ee8...@l2g2000vbn.googlegroups.com>, noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] > > Thanks for any help! I'm not sure wh

Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Roy Smith
In article , Christian Heimes wrote: > Am 21.08.2011 19:27, schrieb Andreas Löscher: > > As for using Integers, the first case (line 1319 and 1535) are true and > > there is no difference in Code. However, Python uses a huge switch-case > > construct to execute it's opcodes and INPLACE_ADD cames

Re: try... except with unknown error types

2011-08-21 Thread Roy Smith
In article <7xty9ahb84@ruckus.brouhaha.com>, Paul Rubin wrote: > It's a retail application that would cause some business disruption and > a pissed off customer if the program went down. Also it's in an > embedded box on a customer site. It's not in Antarctica or anything > like that, but

Re: try... except with unknown error types

2011-08-21 Thread Roy Smith
In article <4e51a205$0$29974$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > http://www.codinghorror.com/blog/2011/04/working-with-the-chaos-monkey.html I *love* being the Chaos Monkey! A few jobs ago, I had already turned in my resignation and was a short-timer, counting down t

Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Roy Smith
In article <356978ef-e9c1-48fd-bb87-849fe8e27...@p5g2000vbl.googlegroups.com>, Tomas Lidén wrote: > In what order are the addresses returned by socket.gethostbyname_ex()? > > We know that gethostbyname() is indeterministic but hope that > gethostbyname_ex() has a specified order. Why would yo

Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Roy Smith
In article , Tomas Lidén wrote: > In this particular case we have a host with several connections (LAN, > WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare > adapter but we wanted to get the LAN (or the "best" connection to our > server). Figuring out which is the best con

Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Roy Smith
In article <034ff4bf-e3e4-47ff-9a6c-195412431...@s20g2000yql.googlegroups.com>, Tomas Lidén wrote: > Basically I was asking about the contract for this method.. hoping > that it is deterministic. The contract for socket.gethostbyname_ex() is described at http://docs.python.org/library/socket.

Re: is there any principle when writing python function

2011-08-23 Thread Roy Smith
In article , smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Enough lin

Re: is there any principle when writing python function

2011-08-23 Thread Roy Smith
In article , Peter Otten <__pete...@web.de> wrote: > smith jack wrote: > > > i have heard that function invocation in python is expensive, but make > > lots of functions are a good design habit in many other languages, so > > is there any principle when writing python function? > > for example,

truncating strings

2011-08-23 Thread Roy Smith
I want to log a string but only the first bunch of it, and add "..." to the end if it got truncated. This certainly works: log_message = message if len(log_message) >= 50: log_message = log_message[:50] + '...' logger.error("FAILED: '%s', '%s', %s, %s" %

Re: [OT-ish] Design principles: no bool arguments

2011-08-25 Thread Roy Smith
In article <4e55f604$0$29973$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > [1] This is the Internet. There's *always* a certain amount of disagreement. No there's not. -- http://mail.python.org/mailman/listinfo/python-list

Re: is there any principle when writing python function

2011-08-26 Thread Roy Smith
In article , t...@thsu.org wrote: > On Aug 23, 7:59 am, smith jack wrote: > > i have heard that function invocation in python is expensive, but make > > lots of functions are a good design habit in many other languages, so > > is there any principle when writing python function? > > for example

Re: Mastering Python... Best Resources?

2011-08-26 Thread Roy Smith
In article <2309ec4b-e9a3-4330-9983-1c621ac16...@ea4g2000vbb.googlegroups.com>, Travis Parks wrote: > I know the Python syntax pretty well. I know a lot of the libraries > and tools. When I see professional Python programmer's code, I am > often blown away with the code. I realized that even th

Re: how to format long if conditions

2011-08-27 Thread Roy Smith
In article , Arnaud Delobelle wrote: > Hi all, > > I'm wondering what advice you have about formatting if statements with > long conditions (I always format my code to <80 colums) > [...] > if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.compl

Re: is there any principle when writing python function

2011-08-27 Thread Roy Smith
Chris Angelico wrote: > the important > considerations are not "will it take two extra nanoseconds to execute" > but "can my successor understand what the code's doing" and "will he, > if he edits my code, have a reasonable expectation that he's not > breaking stuff". These are always important.

Re: Record seperator

2011-08-27 Thread Roy Smith
In article <4e592852$0$29965$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > open("file.txt") # opens the file > .read() # reads the contents of the file > .split("\n\n")# splits the text on double-newlines. The biggest problem with this code is that read() slurp

Re: Record seperator

2011-08-27 Thread Roy Smith
In article , Terry Reedy wrote: > On 8/27/2011 1:45 PM, Roy Smith wrote: > > In article<4e592852$0$29965$c3e8da3$54964...@news.astraweb.com>, > > Steven D'Aprano wrote: > > > >> open("file.txt") # opens the file > >> .read()

Re: is there any principle when writing python function

2011-08-27 Thread Roy Smith
In article <4e595334$0$3$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > and then there are languages with few, or no, design principles to speak of Oh, like PHP? -- http://mail.python.org/mailman/listinfo/python-list

Re: is there any principle when writing python function

2011-08-27 Thread Roy Smith
In article , Emile van Sebille wrote: > code that doesn't execute will need to be read to be understood, and > to be fixed so that it does run. That is certainly true, but it's not the whole story. Even code that works perfectly today will need to be modified in the future. Business requir

Help me understand this logging config

2011-08-29 Thread Roy Smith
I'm using django 1.3 and python 2.6. My logging config is: LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(asctime)s: %(name)s %(levelname)s % (funcName)s %(message)s' } }, 'handlers':

Re: Help me understand this logging config

2011-08-30 Thread Roy Smith
In article , Peter Otten <__pete...@web.de> wrote: > Roy Smith wrote: > > > I'm using django 1.3 and python 2.6. > > Isn't dictConfig() new in 2.7? It looks like that is what you are using... Oh, my, it turns out that django includes: # This is a copy of th

Re: Optparse buggy?

2011-09-01 Thread Roy Smith
In article , Terry Reedy wrote: > Do note "The optparse module is deprecated and will not be developed > further; development will continue with the argparse module." One of the unfortunate things about optparse and argparse is the names. I can never remember which is the new one and which i

Why doesn't threading.join() return a value?

2011-09-02 Thread Roy Smith
I have a function I want to run in a thread and return a value. It seems like the most obvious way to do this is to have my target function return the value, the Thread object stash that someplace, and return it as the return value for join(). Yes, I know there's other ways for a thread to return

Re: Why doesn't threading.join() return a value?

2011-09-02 Thread Roy Smith
In article <5da6bf87-9412-46c4-ad32-f8337d56b...@o15g2000vbe.googlegroups.com>, Adam Skutt wrote: > On Sep 2, 10:53 am, Roy Smith wrote: > > I have a function I want to run in a thread and return a value.  It > > seems like the most obvious way to do this is to have m

Re: Why doesn't threading.join() return a value?

2011-09-03 Thread Roy Smith
In article , Chris Torek wrote: > For that matter, you can use the following to get what the OP asked > for. (Change all the instance variables to __-prefixed versions > if you want them to be Mostly Private.) > > import threading > > class ValThread(threading.Thread): > "like threading.T

Re: [Python-ideas] allow line break at operators

2011-09-03 Thread Roy Smith
In article , Matt Joiner wrote: > I guess the issue here is that you can't tell if an expression is > complete without checking the indent of the following line. This is > likely not desirable. I wrote a weird bug the other day. I had a function that returned a 4-tuple and wanted to unpack it

Re: Extracting subsequences composed of the same character

2011-03-31 Thread Roy Smith
In article <4d952008$0$3943$426a7...@news.free.fr>, candide wrote: > Suppose you have a string, for instance > > "pyyythhooonnn ---> " > > and you search for the subquences composed of the same character, here > you get : > > 'yyy', 'hh', 'ooo', 'nnn', '---', '' I got the following.

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

2011-04-05 Thread Roy Smith
In article , geremy condra wrote: > On Tue, Apr 5, 2011 at 7:51 AM, Babu wrote: > > > > Here is my problem:  Want to program in python to run sysadmin > > commands across 1000s of servers and gather the result in one place. > > Many times the commands need to be run as root.  We cannot use ssh

Creating unit tests on the fly

2011-04-08 Thread Roy Smith
I've got a suite of unit tests for a web application. There's an (abstract) base test class from which all test cases derive: class BaseSmokeTest(unittest.TestCase): BaseSmokeTest.setUpClass() fetches a UR (from a class attribute "route", which must be defined in the derived classes), and there'

Re: Creating unit tests on the fly

2011-04-08 Thread Roy Smith
In article <87fwpse4zt@benfinney.id.au>, Ben Finney wrote: > Raymond Hettinger writes: > > > I think you're going to need a queue of tests, with your own test > > runner consuming the queue, and your on-the-fly test creator running > > as a producer thread. > > I have found the ‘testsce

Re: Creating unit tests on the fly

2011-04-10 Thread Roy Smith
In article , Raymond Hettinger wrote: > I think you're going to need a queue of tests, with your own test > runner consuming the queue, and your on-the-fly test creator running > as a producer thread. > > Writing your own test runner isn't difficult. 1) wait on the queue > for a new test case

Re: [OT] Free software versus software idea patents

2011-04-14 Thread Roy Smith
In article <4da7a8f5$0$29986$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 14 Apr 2011 13:50:24 -0700, Westley Martínez wrote: > > > Also, why aren't Opera and Google criticized for their proprietary > > browsers (Chrome is essentially a proprietary front-end)? Is it be

Re: [OT] Free software versus software idea patents

2011-04-14 Thread Roy Smith
In article <4da7abad$0$29986$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > What they give is ubiquity, which is a point in their favour. But just > because something is common doesn't make it useful: for the most part > both are used for style over substance, of sizzle without

Re: Pythonic infinite for loop?

2011-04-15 Thread Roy Smith
In article <4da83f8f$0$29986$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > for key in dct: > if key.startswith("Keyword"): > maxkey = max(maxkey, int(key[7:])) I would make that a little easier to read, and less prone to "Did I count correctly?" bugs with something

Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Roy Smith
In article , Grant Edwards wrote: > I'm trying to implement a device discovery/configuration protocol that > uses UDP broadcast packets to discover specific types of devices on > the local Ethernet segment. The management program broadcasts a > discovery command to a particular UDP port. All d

Re: dictionary size changed during iteration

2011-04-22 Thread Roy Smith
In article , Peter Otten <__pete...@web.de> wrote: > You now have to create the list explicitly to avoid the error: > > >>> d = dict(a=1) > >>> keys = list(d.keys()) > >>> for k in keys: > ... d["b"] = 42 > ... That works, but if d is large, it won't be very efficient because it has to gen

Re: learnpython.org - an online interactive Python tutorial

2011-04-22 Thread Roy Smith
In article , Mel wrote: > > Strings should auto-type-promote to numbers if appropriate. > > "Appropriate" is the problem. This is why Perl needs two completely > different kinds of comparison -- one that works as though its operands are > numbers, and one that works as though they're strings

Re: Changing baud rate doesn't allow second command

2011-04-25 Thread Roy Smith
In article <224f6621-2fc4-4827-8a19-3a12371f3...@l14g2000pre.googlegroups.com>, rjmccorkle wrote: > hi - I need to open a serial port in 9600 and send a command followed > by closing it, open serial port again and send a second command at > 115200. I have both commands working separately from

Re: Development tools and practices for Pythonistas

2011-04-29 Thread Roy Smith
In article , CM wrote: > While we're on the topic, when should a lone developer bother to start > using a VCS? No need to use VCS at the very beginning of a project. You can easily wait until you've written 10 or 20 lines of code :-) > Should I bother to try a VCS? Absolutely. Even if you

skipping one unittest assertion?

2011-05-01 Thread Roy Smith
Is there any way to skip a single assertion in a unittest test method? I know I can @skip or @expectedFailure the method, but I'm looking for something finer-grain than that. There's one particular assertion in a test method which depends on production code that hasn't been written yet. I cou

Re: skipping one unittest assertion?

2011-05-01 Thread Roy Smith
In article <87wriah4qg@benfinney.id.au>, Ben Finney wrote: > Roy Smith writes: > > > There's one particular assertion in a test method which depends on > > production code that hasn't been written yet. I could factor that out > > into its own t

Re: skipping one unittest assertion?

2011-05-01 Thread Roy Smith
In article , "OKB (not okblacke)" wrote: > Roy Smith wrote: > > > Is there any way to skip a single assertion in a unittest test > > method? I know I can @skip or @expectedFailure the method, but I'm > > looking for something finer-grain than that. >

Re: vertical ordering of functions

2011-05-03 Thread Roy Smith
In article , Jabba Laci wrote: > I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. > 5 he says that a function that is called should be below a function > that does the calling. This creates a nice flow down from top to > bottom. There may have been some logic to this when

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

2011-05-05 Thread Roy Smith
In article , Grant Edwards wrote: > That's what I was trying to say, but probably not as clearly. The "&" > operatore returnas a _value_ that the OP passes _by_value_ to a > function. That function then uses the "*" operator to use that value > to access some data. Then, of course, there's re

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

2011-05-05 Thread Roy Smith
In article <4dc29cdd$0$29991$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > C is better described as a high-level assembler, or a low-level language. > It is too close to the hardware to describe it as high-level, it has no > memory management, few data abstractions, and little

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

2011-05-05 Thread Roy Smith
In article <92fsvjfkg...@mid.individual.net>, Neil Cerutti wrote: > On 2011-05-05, Roy Smith wrote: > > Of course, C++ lets you go off the deep end with abominations > > like references to pointers. Come to think of it, C++ let's > > you go off the deep end in

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

2011-05-07 Thread Roy Smith
In article <87aaeymfww@benfinney.id.au>, Ben Finney wrote: > No, I think not. The term “variable” usually comes with a strong > expectation that every variable has exactly one name. Heh. You've never used common blocks in Fortran? Or, for that matter, references in C++? I would call

Re: dictionary size changed during iteration

2011-05-07 Thread Roy Smith
In article <7xd3jukyn9@ruckus.brouhaha.com>, Paul Rubin wrote: > Roy Smith writes: > > changes = [ ] > > for key in d.iterkeys(): > > if is_bad(key): > > changes.append(key) > > changes = list(k for k in d if is_bad(k)) > > is a li

Re: Development tools and practices for Pythonistas

2011-05-08 Thread Roy Smith
In article <58a6bb1b-a98e-4c4a-86ea-09e040cb2...@r35g2000prj.googlegroups.com>, snorble wrote: > [standard tale of chaotic software development elided] > > I am aware of tools like version control systems, bug trackers, and > things like these, but I'm not really sure if I need them, or how to

Re: Proper way to handle errors in a module

2011-05-11 Thread Roy Smith
In article , Andrew Berg wrote: > I'm a bit new to programming outside of shell scripts (and I'm no expert > there), so I was wondering what is considered the best way to handle > errors when writing a module. Do I just let exceptions go and raise > custom exceptions for errors that don't trigge

Re: checking if a list is empty

2011-05-12 Thread Roy Smith
In article <931adaf9g...@mid.individual.net>, Gregory Ewing wrote: > Roy Smith wrote: > >>If both are numbers, they are converted to a common type. Otherwise, > >>objects of different types always compare unequal > > That's just the default treatment

list equal to subclass of list?

2011-05-12 Thread Roy Smith
I have a vague feeling this may have been discussed a long time ago, but I can't find the thread, so I'll bring it up again. I recently observed in the "checking if a list is empty" thread that a list and a subclass of list can compare equal: class MyList(list):

Re: list equal to subclass of list?

2011-05-12 Thread Roy Smith
On May 12, 2011, at 11:30 AM, Eric Snow wrote: > On Thu, May 12, 2011 at 6:23 AM, Roy Smith wrote: > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types and different > string types, never compar

Re: list equal to subclass of list?

2011-05-12 Thread Roy Smith
On May 12, 2:29 pm, Ethan Furman wrote: > While it is wrong (it should have 'built-in' precede the word 'types'), > it is not wrong in the way you think -- a subclass *is* a type of its > superclass. Well, consider this: class List_A(list): "A list subclass" class List_B(list): "Anothe

Re: list equal to subclass of list?

2011-05-12 Thread Roy Smith
In article , Ethan Furman wrote: > > [http://docs.python.org/library/stdtypes.html] > > Objects of different types, except different numeric types and different > > string types, never compare equal > > This part of the documentation is talking about built-in types, which > your MyList is not

Re: checking if a list is empty

2011-05-14 Thread Roy Smith
In article , David Robinow wrote: > On Fri, May 13, 2011 at 10:34 PM, Gregory Ewing > wrote: > > rusi wrote: > > > >> Dijkstra's problem (paraphrased) is that python, by choosing the > >> FORTRAN alternative of having a non-first-class boolean type, hinders > >> scientific/mathematical thinking

Re: Converting a set into list

2011-05-15 Thread Roy Smith
In article <34fc571c-f382-405d-94b1-0a673da5f...@t16g2000vbi.googlegroups.com>, SigmundV wrote: > I think the OP wants to find the intersection of two lists. > list(set(list1) & set(list2)) is indeed one way to achieve this. [i > for i in list1 if i in list2] is another one. Both ways work, bu

Re: count strangeness

2011-05-22 Thread Roy Smith
In article , James Stroud wrote: > tal 65% python2.7 > Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > py> class C(object): > ... def __init__(self): > ... se

Re: Unit testing beginner question

2011-05-23 Thread Roy Smith
In article , Ian Kelly wrote: > This would work: > > self.assertRaises(TypeError, lambda: self.testListNone[:1]) If you're using the version of unittest from python 2.7, there's an even nicer way to write this: with self.assertRaises(TypeError): self.testListNone[:1] -- http://mail.pyth

Re: Why did Quora choose Python for its development?

2011-05-25 Thread Roy Smith
In article , Dennis Lee Bieber wrote: > On Tue, 24 May 2011 13:39:02 -0400, "D'Arcy J.M. Cain" > declaimed the following in gmane.comp.python.general: > > > > My point was that even proponents of the language can make a > > significant error based on the way the variable is named. It's like

Re: Why did Quora choose Python for its development?

2011-05-25 Thread Roy Smith
In article , Chris Angelico wrote: > On Wed, May 25, 2011 at 9:36 PM, Roy Smith wrote: > > Remembering that I, J, K, L, M, and N were integer was trivial if you > > came from a math background.  And, of course, Fortran was all about > > math, so that was natural.  Those

Re: Why did Quora choose Python for its development?

2011-05-26 Thread Roy Smith
In article <94709uf99...@mid.individual.net>, Neil Cerutti wrote: > On 2011-05-25, Matty Sarro wrote: > > General readability is a farce. If it was true we would only > > have one section to the library. Different people enjoy > > reading, and can comprehend better in different ways. THat's > >

Re: bug in str.startswith() and str.endswith()

2011-05-26 Thread Roy Smith
In article , Ethan Furman wrote: > --> 'this is a test'.startswith('this') > True > --> 'this is a test'.startswith('this', None, None) > Traceback (most recent call last): >File "", line 1, in > TypeError: slice indices must be integers or None or have an __index__ > method [...] > Any re

Re: The worth of comments

2011-05-26 Thread Roy Smith
In article , Richard Parker wrote: > On May 26, 2011, at 4:28 AM, python-list-requ...@python.org wrote: > > > My experience is that comments in Python are of relatively low > > usefulness. (For avoidance of doubt: not *zero* usefulness, merely low.) > > I can name variables, functions and cla

Re: The worth of comments

2011-05-27 Thread Roy Smith
In article , Chris Angelico wrote: > (Did I *really* write that code? It has my name on it.) Most version control systems have an annotate command which lets you see who wrote a given line of code. Some of them are even honest enough to call the command "blame" instead of "annotate" :-)

Re: Why did Quora choose Python for its development?

2011-05-27 Thread Roy Smith
In article <948l8nf33...@mid.individual.net>, Gregory Ewing wrote: > John Bokma wrote: > > > A Perl programmer will call this line noise: > > > > double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", > > re.IGNORECASE) One of the truly awesome things about th

Re: bug in str.startswith() and str.endswith()

2011-05-27 Thread Roy Smith
In article , Stefan Behnel wrote: > Roy Smith, 27.05.2011 03:13: > > Ethan Furman wrote: > > > >> --> 'this is a test'.startswith('this') > >> True > >> --> 'this is a test'.startswith('this', None, N

Re: Why did Quora choose Python for its development?

2011-05-28 Thread Roy Smith
In article , Carl Banks wrote: > On Friday, May 27, 2011 6:47:21 AM UTC-7, Roy Smith wrote: > > One of the truly awesome things about the Python re library is that it > > lets you write complex regexes like this: > > > > pattern = r"""

Re: The worth of comments

2011-05-28 Thread Roy Smith
In article , Grant Edwards wrote: > When trying to find a bug in code written by sombody else, I often > first go through and delete all of the comments so as not to be > mislead. I've heard people say that before. While I get the concept, I don't like doing things that way myself. >> The co

Re: Weird problem matching with REs

2011-05-29 Thread Roy Smith
In article , Andrew Berg wrote: > Kodos is written in Python and uses Python's regex engine. In fact, it > is specifically intended to debug Python regexes. Named after the governor of Tarsus IV? -- http://mail.python.org/mailman/listinfo/python-list

Re: The worth of comments

2011-05-29 Thread Roy Smith
In article , Grant Edwards wrote: > On 2011-05-29, Gregory Ewing wrote: > > Ben Finney wrote: > > > >> You omit the common third possibility: *both* the comment and the code > >> are wrong. > > > > In that case, the correct response is to fix both of them. :-) > > Only as a last resort. IMO, t

Re: float("nan") in set or as key

2011-05-31 Thread Roy Smith
In article Carl Banks wrote: > pretty much everyone uses IEEE format Is there *any* hardware in use today which supports floating point using a format other than IEEE? -- http://mail.python.org/mailman/listinfo/python-list

Re: What is "self"?

2005-09-23 Thread Roy Smith
Ron Adam <[EMAIL PROTECTED]> wrote: > You can actually call it anything you want but "self" is sort of a > tradition. That's true, but I think needs to be said a bit more emphatically. There's no reason to call it anything other than "self" and a newcomer to the language would be well advised

Re: Carrying variables over from function to function

2005-09-25 Thread Roy Smith
"Ivan Shevanski" <[EMAIL PROTECTED]> wrote: > Alright heres my problem. . .Say I want to carry over a variable from one > function to another or even another run of the same function. Is that > possible? You want one of two things. The most obvious would be a global variable. Something like th

Virgin keyword (Was: Will python never intend to support private, protected and public?)

2005-10-02 Thread Roy Smith
"El Pitonero" <[EMAIL PROTECTED]> wrote: > Python's lack of Java-style "private" surely has its drawback: name > collisions can happen. But, that's just one side. Name collisions are > allowed in many dynamic languages, where you can override the default > system behavior (in some languages, you ca

Re: "no variable or argument declarations are necessary."

2005-10-07 Thread Roy Smith
"Ben Sizer" <[EMAIL PROTECTED]> wrote: > It's started to get very misleading - Python gives you plenty of > type-checking, as we all know, just not at compile-time. There's more to it than just that. Python's type checking is not just not done at compile time, it's done as late in run time as po

Re: "no variable or argument declarations are necessary."

2005-10-07 Thread Roy Smith
Paul Rubin wrote: > What this is about (to me at least) is the edit-debug cycle. Let's > say I write some Python code, using assert to validate datatypes. > Maybe I've made 4 errors. I then write a test function and run it. > Boom, the first assert fails. I fix the fir

Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-12 Thread Roy Smith
Chris Smith <[EMAIL PROTECTED]> wrote: >What I really want to do is take four lines of conditional, and put >them into one, as well as blow off dealing with a 'filler' variable: > >return "the answer is " + "yes" if X==0 else "no" I would write this as: return "the answer is " + ("yes" if X==0 e

Re: Python vs Ruby

2005-10-19 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "Amol Vaidya" <[EMAIL PROTECTED]> wrote: > Hi. I am interested in learning a new programming language, and have been > debating whether to learn Ruby or Python. How do these compare and contrast > with one another, and what advantages does one language provide ov

Re: Python vs Ruby

2005-10-19 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "jean-marc" <[EMAIL PROTECTED]> wrote: > I'd believe that would be Lua, but then again what is common to one > might not be to another ;-) Dang, you're right! Lua's got Ruby beat two-fold! -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs Ruby

2005-10-21 Thread Roy Smith
Robert Boyd <[EMAIL PROTECTED]> wrote: > As if Plone, Zope, and (non-Python) Shibboleth weren't getting me > enough funny looks. And I haven't even started telling co-workers > about Django. A couple of years ago, a head-hunter asked me if I knew Plone. I figured he was just being an idiot and d

<    1   2   3   4   5   6   7   8   9   10   >