Re: How did you learn Python?

2004-12-03 Thread Miles
ound the book to be very well-paced. Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: a cx_Oracle ORA-01036 problem

2005-05-06 Thread Miles
function name; I suspect your problem may be that you are assiging that function to the variable rather than your intended value... Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: "assert" annoyance

2007-06-21 Thread Miles
On Jun 22, 1:31 am, Paul Rubin wrote: > What I really want is for any assertion failure, anywhere in the > program, to trap to the debugger WITHOUT blowing out of the scope > where the failure happened, so I can examine the local frame. That > just seems natural, but I d

Re: "assert" annoyance

2007-06-22 Thread Miles
On Jun 22, 2:45 am, "Evan Klitzke" <[EMAIL PROTECTED]> wrote: > On 6/21/07, Miles <[EMAIL PROTECTED]> wrote: > > > On Jun 22, 1:31 am, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > > > What I really want is for any assertion failure, anywhere in t

Re: "Empty" text

2007-07-09 Thread Miles
On Jul 9, 4:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > On Sun, 08 Jul 2007 22:23:20 +0200, Jan Danielsson wrote: > > >Firefox is very unhappy about the textarea not having separate > > > opening and a closing tags. i.e. I need th

Re: bool behavior in Python 3000?

2007-07-11 Thread Miles
On Jul 11, 2:50 am, Alan Isaac <[EMAIL PROTECTED]> wrote: > >>> bool(False-True) > > True What boolean operation does '-' represent? -- http://mail.python.org/mailman/listinfo/python-list

Re: Where does str class represent its data?

2007-07-11 Thread Miles
On Jul 11, 7:21 pm, [EMAIL PROTECTED] wrote: > I'd like to implement a subclass of string that works like this: > > >>>m = MyString('mail') > >>>m == 'fail' > True > >>>m == 'mail' > False > >>>m in ['fail', hail'] > > True > > My best attempt for something like this is: > > class MyString(str): >

Re: bool behavior in Python 3000?

2007-07-12 Thread Miles
this: >>> if user.registered * (user.age > 13) - user.banned: ... I don't mind that arithmatic operations are _possible_ with bools, but I would strongly prefer to see the boolean keywords used for operations on booleans. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Fetching a clean copy of a changing web page

2007-07-15 Thread Miles
you're using a suitable strict parser. If it's mixed old data and new data, but still manages to be well-formed XML, then yes, you'll probably have to read it twice. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Miles
rm an automatic string conversion. >>> '%s %s %s %s' % ('Hello!', 3.14, 42+1j, object()) 'Hello! 3.14 (42+1j) ' -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: How to check if an item exist in a nested list

2007-07-19 Thread Miles
Arash Arfaee wrote: > is there any way to check if "IndexError: list index out of > range" happened or going to happen and stop program from terminating? Use a try/except block to catch the IndexError http://docs.python.org/tut/node10.html#SECTION001030 try: do_something_0(M_l

Re: Sorting dict keys

2007-07-20 Thread Miles
pointed out, the sort() method returns None. > If you just want to keep a list of ordered keys you can probably do > something like: > > key_list = list(my_dict.keys()) > key_list.sort() Creating a copy with list() is unnecessary, as keys() already returns a copy. -Miles -- http://mai

Re: Lazy "for line in f" ?

2007-07-22 Thread Miles
d the entire file, but it does use internal buffering for performance. On my system, it waits until it gets about 8K of input before it yields anything. If you need each line as it's entered at a terminal, you're back to the while/readline (or raw_input) loop. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: URL parsing for the hard cases

2007-07-22 Thread Miles
On 7/22/07, John Nagle wrote: > Is there something available that will parse the "netloc" field as > returned by URLparse, including all the hard cases? The "netloc" field > can potentially contain a port number and a numeric IP address. The > IP address may take many forms, including an IPv6

Re: URL parsing for the hard cases

2007-07-22 Thread Miles
es the term "netloc"), and the username/password > should have been parsed and moved to the "username" and "password" fields > of the object. So it looks like urlparse doesn't really understand FTP URLs. Those values aren't "moved" to the fields; they're extracted on the fly from the netloc. Use the .hostname property of the result tuple to get just the hostname. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: URL parsing for the hard cases

2007-07-23 Thread Miles
ation could be stricter if match and match.group(2): return True else: return False return True The first function, I'd imagine, is the more interesting of the two. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Maintaining leading zeros with the lstrip string function?

2007-07-23 Thread Miles
robably be using split (or basename) in the os.path module. Also, use raw strings ( r'\path\to\file' ) to avoid problems with backslashes being interpreted in strings. -Miles [1] http://docs.python.org/lib/string-methods.html [2] http://docs.python.org/lib/node42.html -- http://mail.python.org/mailman/listinfo/python-list

Re: URL parsing for the hard cases

2007-07-23 Thread Miles
On 7/23/07, Miles wrote: > On 7/22/07, John Nagle wrote: > > Is there any library function that correctly tests for an IP address vs. a > > domain name based on syntax, i.e. without looking it up in DNS? > > import re, string > > NETLOC_RE = re.compile(r''&#x

Re: datetime.time() class - How to pass it a time string?

2007-07-24 Thread Miles
On 7/24/07, Robert Dailey wrote: > Hi, > > I have a string in the following format: > > "00:00:25.886411" > > I would like to pass this string into the datetime.time() class and > have it parse the string and use the values. However, the __init__() > method only takes integers (which means I'd be f

Re: idiom for RE matching

2007-07-24 Thread Miles
Equivalent to: 'spam' or ('ham' in line) 'spam' AFAIK, the (Python 2.5) idiom for what you want is: >>> any(s in line for s in ('spam', 'ham')) False >>> line = 'Spam, spam, spam, spam' >>> any(s in line for s in ('spam', 'ham')) True -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: What order does info get returned in by os.listdir()

2007-08-14 Thread Miles
lls. If you rely on the order being sorted, you should do it yourself. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: What order does info get returned in by os.listdir()

2007-08-15 Thread Miles
On 8/15/07, Jeremy C B Nicoll wrote: > Marc 'BlackJack' Rintsch wrote: > > > How would I sort leaflist in a way that mimics the sort order that XP > > > shows me things under? > > > > This depends on what XP is. Which program? Which locale? How does the > > locale influence that programs sorting

Re: Getting the result of a process after exec*()

2007-08-17 Thread Miles
Python; /once the external processing is > completed/? Assuming you're looking at the docs for the os module, instead of the exec*() functions, check out the spawn*() functions, or, to use a subshell, system(). Better yet, take a look at the subprocess module: http://docs.python.org/lib/modu

Re: fcntl problems

2007-08-30 Thread Miles
EOF, but from that point on the offset is not externally influenced. The correct sequence of events should be: - open file in mode w+ - obtain exclusive lock - f.seek(0, 2) # (to end of file) - write to file - f.flush() # or f.close() - release lock > Is this my lack of understanding, or h

Re: fcntl problems

2007-08-30 Thread Miles
access to the file." This is only for mandatory locking; POSIX flock is advisory locking, which states: "Only one process may hold an exclusive lock for a given file at a given time." Advisory locks don't have any effect on processes that don't use locks. Mandatory locks

Re: fcntl problems

2007-08-31 Thread Miles
sys.exit(1) else: raise f.seek(0, 2) # seek to end # do your thing with the file f.flush() fcntl.flock(f.fileno(), fcntl.LOCK_UN) f.close() -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: fcntl problems

2007-08-31 Thread Miles
raised when playing with the interactive interpreter, but I really should have written: from errno import EWOULDBLOCK ... if e.args[0] == EWOULDBLOCK: ... - Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Printing lists in columns

2007-09-04 Thread Miles
or row in izip_longest(fillvalue='*', *d): print ', '.join(row) -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: sys.argv index out of range error

2007-09-13 Thread Miles
ce init.sh" to use the same shell context; * use "./init.sh $1" to use a new context; or * save the needed parameters in other variables before clobbering them. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Miles
arantee that the XML is well-formed, then this should work: pattern = r'<([^/>][^>]*(?]+>' replace = r'<\1/>' -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Miles
On 9/25/07, Paul McGuire wrote: > On Sep 24, 11:23 pm, Gabriel Genellina wrote: > > py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source) > > And let's hope the OP doesn't have to parse anything truly nasty like: > >

Re: Ternary operator and tuple unpacking -- What am I missing ?

2009-01-12 Thread Miles
want, is to use your line 10: > 10) >>> c,d = n if n is not None else (0,0) But if you're struggling with the precedence issues, I'd recommend ditching ternary expressions altogether and using full conditional blocks. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: v = json.loads("{'test':'test'}")

2009-01-26 Thread Miles
x27;s Postel's Law: http://en.wikipedia.org/wiki/Robustness_Principle -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Rounding to the nearest 5

2009-01-29 Thread Miles
ve those results. def bogoround(n): n1 = n / 5.0 return int(round(n1) if n1 % 2 > 1 else n1) * 5 best-I-could-do-ly y'rs, -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: select.poll.poll() never blocks

2009-02-11 Thread Miles
the file is in sync with how much you've > read! See also this recipe: http://code.activestate.com/recipes/157035/ -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6

2009-02-17 Thread Miles
"credits" or "license" for more information. >>>> import gdal > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named gdal What about "from osgeo import gdal"? -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: print string as raw string

2009-02-17 Thread Miles
t;"' not in s: quote = '"""' if not quote: raise ValueError('No raw string representation; ' 'string contains unescapable quote characters') return 'r' + quote + s + quote >>&

Re: why cannot assign to function call

2008-12-29 Thread Miles
are immutable. def foo(): b = 0 bar(b) print b # will always be 0 * There are stupid [ctypes/getframe/etc.] tricks, though I think all are implementation-specific -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this a bug in Python or something I do not understand.

2009-01-01 Thread Miles
a Python bug. Does this help illuminate the difference? >>> L1 = [object() for j in range(3)] >>> L2 = [object()] * 3 >>> [id(o) for o in L1] [164968, 164976, 164984] >>> L1[0] is L1[1] False >>> [id(o) for o in L2] [164992, 164992, 164992] >>> L2[0] is L2[1] True -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a better/simpler way to filter blank lines?

2008-11-05 Thread Miles
;s also worth remembering that list comprehensions are distinct from generator expressions and don't require the creation of a generator object. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: end child process when parent dies (on Unix)

2008-11-17 Thread Miles
SIGKILL. >> >> A Linux-specific solution is prctl(2). > > I've tried this in a test C program... exactly what I need. Now if I > could slip this between the fork and exec in subprocess.Popen() preexec_fn, perhaps? http://docs.python.org/library/subprocess.html#using-the-s

Re: Raw String Question

2009-03-12 Thread Miles
gt; parenthetical side-comment. There is no exception. All backslashes are left in the string. The impossibility of ending a raw string in an unescaped backslash is also rendered in italics. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re:

2009-03-13 Thread Miles
2), (2, 4)] b = [2, 4, 1, 3] bdict = dict((v,k) for (k,v) in enumerate(b)) a.sort(key=lambda k: bdict[k[1]]) If you don't want to build the intermediary dict, a less efficient version that runs in O(n^2): a.sort(key=lambda k: b.index(k[1])) Which is mostly similar to John's solutio

Re:

2009-03-13 Thread Miles
On Fri, Mar 13, 2009 at 3:13 PM, Miles wrote: > [snip] Sorry, didn't see the original thread on this. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: don't understand behaviour of recursive structure

2009-03-14 Thread Miles
a FAQ: http://effbot.org/zone/default-values.htm http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this type of forward referencing possible?

2009-03-15 Thread Miles
d to point out that A and B likely both inherit from db.Model). The Django solution is to allow forward references in the form of strings of class names (e.g., ReferenceType('B')). It doesn't look like App Engine has a solution for this situation: http://code.google.com/p/goo

Re: How evil is this use of sys.getrefcount?

2009-03-20 Thread Miles
self._object) # Define your own methods to wrap those of the object, # or maybe define __getattr__ -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I do bit operation on python float value

2009-03-23 Thread Miles
_to_float(x): ... return cast(ctypes.c_uint64(x), ctypes.c_double) ... >>> float_to_int(5) 4617315517961601024 >>> bin(float_to_int(5)) '0b1010100' >>> int_to_float(float_to_int(5) & float_to_int(10)) 2.5 -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Syntax error when importing a file which starts with a number

2009-03-23 Thread Miles
ry/functions.html#__import__ But a far better solution is to fix your naming scheme—it's completely illogical to have a Python module naming scheme where the names aren't valid identifiers. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: dict view to list

2009-03-27 Thread Miles
vert to a flat sequence but rather a list tree. I don't see the special case for dict views, at all. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Python print and types selection

2009-03-27 Thread Miles
t_hex does the long conversion) > -- redefine __str__ and use %s Or make your class a subclass of long. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Generators/iterators, Pythonicity, and primes

2009-04-04 Thread Miles
eld n break elif n % p == 0: break else: raise Exception("Shouldn't have run out of primes!") When generating the first 1000 primes, this version's approximately 20 times faster; for the first 10,000 primes, ~80x (but

Re: Tab completion

2009-04-05 Thread Miles
' else: return None return rlcompleter.Completer.complete(self, text, state) readline.set_completer(TabCompleter().complete) -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: more fun with iterators (mux, demux)

2009-04-06 Thread Miles
mped.  The demux should return a tuple of N generators. from itertools import islice, tee def demux(iterable, n): return tuple(islice(it, i, None, n) for (i, it) in enumerate(tee(iterable, n))) -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: more fun with iterators (mux, demux)

2009-04-06 Thread Miles
  yield i.next() > > > This is like a zip, and can be re-written using itertools.izip. > > def mux(*iterables): >    for i in itertools.izip(*iterables): >        for item in i: >            yield item In Python 2.6, you could also do this: def mux(*iterables): return iterto

Re: more fun with iterators (mux, demux)

2009-04-08 Thread Miles
then skips over, whereas your version places items only into the deque of the generator that needs it. However, for small n, the tee-based solution has the advantage of having most of the work done in C instead of in Python generator functions; in my limited benchmarking, the point where your vers

Re: is there a rwlock implementation in python library?

2009-04-08 Thread Miles
/ http://code.activestate.com/recipes/465156/ -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Why does Python show the whole array?

2009-04-09 Thread Miles
Clearly, any comparison with a boolean literal should be illegal. ;) -Miles P.S. ... really, though. -- http://mail.python.org/mailman/listinfo/python-list

Re: Unsupported operand types in if/else list comprehension

2009-04-10 Thread Miles
nsert the parameters into the SQL query for you; it will look something like this (though the exact details will vary depending on what module you're using): cursor.execute('INSERT INTO my_table VALUES (?, ?, ?)', ['test',1,'two']) -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding a Badge to an Icon in Mac OS X

2009-04-10 Thread Miles
gure out how it is done! I believe those programs are able to do so because they are Finder plugins--it's not something that a separate program could do. This isn't really a Python question, though; you'd probably have better luck finding answers on a OS X-related list. -Mile

Re: How to check all elements of a list are same or different

2009-04-15 Thread Miles
crowd: from functools import partial from operator import eq from itertools import imap def all_same(iterable): it = iter(iterable) return all(imap(partial(eq, it.next()), it)) -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: struct unpack issue

2008-06-13 Thread Miles
rce the data to be packed (unaligned), and will also make your code more portable: struct.unpack('<2s1i', ...) -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: socket.connect() hangs in SYN_SENT state.

2008-07-13 Thread Miles
r machine has odd DNS settings causing buzkor.hopto.org to resolve to the wrong address. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: socket.connect() hangs in SYN_SENT state.

2008-07-13 Thread Miles
On Sun, Jul 13, 2008 at 2:32 PM, bukzor <[EMAIL PROTECTED]> wrote: > On Jul 13, 1:14 am, Miles <[EMAIL PROTECTED]> wrote: >> On Sat, Jul 12, 2008 at 11:23 PM, bukzor <[EMAIL PROTECTED]> wrote: >> > I'm connecting to an apache2 process on the same machine,

Re: heapq question

2008-07-13 Thread Miles
implementation.) > And if instead of removing an element I'd want to change its value? > E.g.: > > >>> heap = [0, 2, 1, 4, 5, 6, 7, 8, 9] > >>> heapify(heap) > >>> heap > [0, 2, 1, 4, 5, 6, 7, 8, 9] > >>> heap[4] = 12 Don't do that; you must first remove the element and then reinsert it. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: heapq question

2008-07-13 Thread Miles
hat heaps in general are ideally suited for timeouts; it's just that the Python heapq implementation is lacking if you ever need to cancel a timeout before it expires. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Magic?

2008-07-13 Thread Miles
erty setter that raises an error to make a property read-only; you can simply not define a setter method. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: socket.connect() hangs in SYN_SENT state.

2008-07-13 Thread Miles
why I thought you were confused, and increases my own suspicion that DNS settings are to blame. I let the script run for about five minutes without it failing. Does your luck change if you use "localhost" or a numeric IP address in the ServerProxy URL? -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: socket.connect() hangs in SYN_SENT state.

2008-07-13 Thread Miles
On Sun, Jul 13, 2008 at 9:31 PM, Miles <[EMAIL PROTECTED]> wrote: > On Sun, Jul 13, 2008 at 8:35 PM, bukzor <[EMAIL PROTECTED]> wrote: >> The problem only manifests about 1 in 20 runs. Below there's code for >> a client that shows the problem 100% of the time. >&

Re: socket.connect() hangs in SYN_SENT state.

2008-07-13 Thread Miles
t work out the root cause, but it only happens every once in a while, you could try changing your client code to catch the socket exception and retry a limited number of times. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: socket.connect() hangs in SYN_SENT state.

2008-07-13 Thread Miles
On Sun, Jul 13, 2008 at 10:29 PM, Miles <[EMAIL PROTECTED]> wrote: > On Sat, Jul 12, 2008 at 11:23 PM, bukzor <[EMAIL PROTECTED]> wrote: >> Anyone know a general reason this might happen? Even better, a way to >> fix it? > > Maybe your client has an unusually l

Re: __del__ methods

2008-07-18 Thread Miles
to guess a safe order in which to run the __del__() methods." The uncollectable objects are stored in gc.garbage and will not be freed until their reference cycles are broken and they are removed from that list. http://docs.python.org/lib/module-gc.html -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Not entirely serious: recursive lambda?

2008-07-19 Thread Miles
've studied lambda calculus or had experience with "real" functional languages (I haven't). For fun, try throwing a Y combinator in there. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: MethodChain

2008-07-20 Thread Miles
omposition chain = MethodChain().lower().replace('ello,', 'ey').title().split() print chain('HELLO, world') func = compose(chain, partial(map, lambda s: s+'!'), ' '.join) print func('HELLO, world') ### -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: how to split text into lines?

2008-07-30 Thread Miles
there a way to achieve the same > effect using re.split? Not directly: re.split doesn't split on zero-length matches. http://mail.python.org/pipermail/python-dev/2004-August/047272.html http://bugs.python.org/issue852532 http://bugs.python.org/issue988761 http://bugs.python.org/iss

Re: overriding file.readline: "an integer is required"

2008-07-30 Thread Miles
line = self.file.readline(*args) # etc., etc. But this has its drawbacks. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Optimizing size of very large dictionaries

2008-07-30 Thread Miles
tionary key. This > works great except for several files whose size is such that their > associated checksum dictionaries are too big for my workstation's 2G of RAM. What are the values of this dictionary? You can save memory by representing the checksums as long integers, if you're

Re: Difference between type and class

2008-07-31 Thread Miles
gt;> type(newstyle) >>> type(newstyle()) Further reading: http://www.python.org/download/releases/2.2.3/descrintro/ http://svn.python.org/view?rev=23331&view=rev http://bugs.python.org/issue2565 -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Class definition attribute order

2008-08-01 Thread Miles
ct(22) where FrameworkObject is assigned a number from an incrementing counter on initialization, and FrameworkClass has a metaclass that sorts those objects when the class is created. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: string to type object (C)

2008-08-05 Thread Miles
bunch of > strcmp( "tuple" ) { return &PyTuple_Type; } commands, provided > &PyTuple_Type; will be linking the right address. Something along the lines of this? b = PyImport_Import("__builtin__"); return PyObject_GetAttrString(b, typestring); -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: how to find out if an object is a class?

2008-08-08 Thread Miles
t > being a function, not just a callable object. I had to pull quite a number of > tricks to reimplement the wrapper class as a function (thank god, it's > Python!). You really only needed one trick: def functionize(callable): return lambda *args, **kwargs: callable(*args

Re: style question - hasattr

2008-04-08 Thread Miles
nge across releases. ... [hasattr] is implemented by calling getattr(object, name) and seeing whether it raises an exception or not." http://docs.python.org/lib/built-in-funcs.html > Which style is preferred?? Don't test for the existence of the attribute if you're

Re: class definition

2008-05-07 Thread Miles
on_types_and_objects/python_types_and_objects.html A guide to descriptors: http://users.rcn.com/python/download/Descriptor.htm The reference manual on the distinction: http://docs.python.org/ref/node33.html The technical explanation: http://www.python.org/download/releases/2.2.3/descrintro/ -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: slicing lists

2008-05-07 Thread Miles
st.__getitem__(self, s) if isinstance(s, slice) else [list.__getitem__(self, s)] for s in slices])) p = open('/etc/passwd') q = [multisliceable(e.strip().split(':'))[0,2:] for e in p] -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting pid of a remote process

2008-08-19 Thread Miles
(subprocess.Popen(['ssh', , 'cat', ], stdout=subprocess.PIPE).stdout.read()) -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: os.readlink() doco snafu?

2008-08-20 Thread Miles
e(path) assumes that you pass in an > absolute path to the readlink function. That documentation should probably say, "if it is relative, it may be converted to a pathname valid from the current working directory using ..." -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: property() usage - is this as good as it gets?

2008-08-22 Thread Miles
f).__init__() self._x = self.x self.z = None def _set_x(self, x): # An example subclass 'set' override. if x == 10: raise Exception('%r is invalid!' % x) self._x = x x = property(attrgetter('_x'), _set_x) ### It

Re: Python multimap

2008-08-27 Thread Miles
append to. That's what a multimap is. If you really need the syntactic sugar, it's simple to implement: class multidict(dict): def __setitem__(self, key, value): try: self[key].append(value) except KeyError: dict.__setitem__(self, key, [value]) -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking if the file is a symlink fails

2008-08-28 Thread Miles
stat information for the file that the symbolic link points to, which is *not* a symbolic link. Like the documentation for lstat says: "Like stat(), but do not follow symbolic links." But why not just use os.path.islink? -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: help needed with dictionary

2008-08-29 Thread Miles
t/2008-August/505584.html -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Picking up resource forks and extended attributes on Mac OS X ?!

2008-08-30 Thread Miles
27;t recall for sure and I don't have access to it to check. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Inquiry regarding the name of subprocess.Popen class

2008-09-02 Thread Miles
communication). All rationalizations aside, I think Popen is a poor name for the class. But I would imagine the odds of it ever being changed are miniscule (Python 4?). -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are "broken iterators" broken?

2008-09-21 Thread Miles
don't have to conform to the iterator protocol. Strictly speaking, file objects are broken iterators: Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16) >>> f = open('foo') >>> it = iter(f) >>> it.next() 'hi\n' >>> it.next() 'bye\n'

Re: dict generator question

2008-09-21 Thread Miles
en(yes()) and len(rand(100)) return? Clearly, len(yes()) would never return, and len(rand(100)) would return a random integer not less than 101. -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Borg vs Singleton vs OddClass

2008-09-27 Thread Miles
ich seems fragile), you get behavior like this: >>> s = OddClass() >>> s is OddClass() True >>> a = A() >>> s is OddClass() False >>> a is OddClass() True >>> a is A() False >>> a is OddClass() False -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Urgent:Serial Port Read/Write

2013-05-09 Thread Frank Miles
On Thu, 09 May 2013 23:35:53 +0800, chandan kumar wrote: > Hi all,I'm new to python and facing issue using serial in python.I'm > facing the below error >     ser.write(port,command)NameError: global name 'ser' is not defined > Please find the attached script and let me know whats wrong in my scri

Re: PDF generator decision

2013-05-14 Thread Frank Miles
On Tue, 14 May 2013 08:05:53 -0700, Christian Jurk wrote: > Hi folks, > > This questions may be asked several times already, but the development > of relevant software continues day-for-day. For some time now I've been > using xhtml2pdf [1] to generate PDF documents from HTML templates (which > a

Re: Python Interview Questions

2012-08-14 Thread Robert Miles
On 7/10/2012 1:08 PM, Demian Brecht wrote: I also judge candidates on their beards (http://www.wired.com/wiredenterprise/2012/06/beard-gallery/). If the beard's awesome enough, no questions needed. They're pro. You should hire me quickly, then, since I have a beard, already turning partly gr

Re: lambda in list comprehension acting funny

2012-08-15 Thread Robert Miles
n has a version of Python available, in case you're interested. Robert Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation, inheritance and polymorphism

2012-08-18 Thread Robert Miles
On 7/23/2012 11:18 AM, Albert van der Horst wrote: In article <5006b48a$0$29978$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: Even with a break, why bother continuing through the body of the function when you already have the result? When your calculation is done, it's done, just

  1   2   >