Is python.org blocking traffic from the ibm.com domain?

2007-11-19 Thread scott . h . snyder
issue please let me know. Thanks, Scott -- http://mail.python.org/mailman/listinfo/python-list

Re: implement random selection in Python

2007-11-19 Thread Scott David Daniels
alues()) for i in range(N): score = random.random() * total for choice, weight in cp.iteritems(): if weight < score: score -= weight else: result.append(choice) total -= cp.pop(choice) bre

Re: Problems with if/elif statement syntax

2007-11-22 Thread Scott David Daniels
a < 100: if c == "c": radius = 500 else: radius = 250 else: for limit, radius in bounds: if a < limit: break on the theory that it makes it easier to see what you are driving the number towards. I'd even add an upper bound check myself, so I could see other garbage coming in. -Scott -- http://mail.python.org/mailman/listinfo/python-list

Re: 100% CPU Usage when a tcp client is disconnected

2007-11-22 Thread Scott David Daniels
hanging it to ... > data = "dummy" > while data: > ... Even better: from functools import partial def handle(self): for data in iter(partial(self.request.recv, 1024), ''): self.request.send(data) if data.strip() == '

Re: python vs perl performance test

2007-12-14 Thread Scott David Daniels
x27;'.join([chr(randrange(128)) for i in range(1024)]) -Scott -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding overlapping times...

2007-12-14 Thread Scott David Daniels
ng (outer to inner), so a single scan of the result can reveal nesting violations. -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing backwards compatible code - when?

2006-04-18 Thread Scott David Daniels
free.fr/PQR2.3.html --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: datetime question

2006-04-18 Thread Scott David Daniels
;>> print datetime.datetime.now() # local 2006-04-18 15:25:03.14 >>> print datetime.datetime.utcnow() # zulu / utc / gmt 2006-04-18 22:25:13.625000 --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: MinGW and Python

2006-04-25 Thread Scott David Daniels
tise available to support people to do things like that (nor does it need to). They don't need (or want) to become wed to one architecture, but to do the best optimization you must at some point get married. The gcc team does a great job at what they do; blind defense of them discredits

Re: python application ideas.

2006-04-25 Thread Scott David Daniels
hon is to get 3-D solved for you so you can work on the position and momentum updates. It even will do anaglyph (colored glasses) and cross-eyed 3-D rendering, though the default is to simply give you a 2-D window into the 3-D world. If you do this, you might play with designing a virtual skate park.

Re: help finding

2006-04-25 Thread Scott David Daniels
there a online ref and how to access it? Yes. Your install may have one, what OS? Start here: http://www.python.org/about/gettingstarted/ or http://www.python.org/doc/faq/ or http://wiki.python.org/moin/ or http://www.python.org/doc/ --Scott David Daniels [EMAIL PROTECTED] --

Re: print names of dictionaries

2006-04-26 Thread Scott David Daniels
ey of '_name', or '_name_', because 'name' is a fairly likely name to encounter. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Inherit from array

2006-04-27 Thread Scott David Daniels
array, that is the element type), and __init__ does any further initialization (initialization should be re-runnable). In the case of array, filling the array with data seems a great use of __init__. -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: os.startfile() - one or two arguments?

2006-04-28 Thread Scott David Daniels
ost recent call last): > File "", line 1, in ? > TypeError: startfile() takes exactly 1 argument (2 given) Works fine for me with Python 2.5a2 on Win2K I ran: os.startfile('c:/','explore') And an explorer window popped up. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Add file to zip, or replace file in zip

2006-04-30 Thread Scott David Daniels
k some files "deleted" in the directory, add new files (possibly the replacements for the deleted files), and, in one pass, copy all non-deleted files to a new zip (which you can then swap for the original zip). Shortcutting this process puts all data in your zip file at risk. --Scott D

Re: Add file to zip, or replace file in zip

2006-05-01 Thread Scott David Daniels
Edward Elliott wrote: > Scott David Daniels wrote: >>... > ... You windows kids and your crazy data formats. There were a few oth OS's than Linux and Windows. Maybe you should call me "you crazy Tenex kid." Knuth says, "the fastest way to search is to know wher

Re: Add file to zip, or replace file in zip

2006-05-01 Thread Scott David Daniels
Edward Elliott wrote: > Scott David Daniels wrote: > >> Edward Elliott wrote: >>> Scott David Daniels wrote: >>>> ... >> > ... You windows kids and your crazy data formats. >> There were a few oth OS's than Linux and Windows. Maybe you &g

Re: stripping blanks

2006-05-02 Thread Scott David Daniels
Line A little better: f = open("test.dat") for line in f: printLine = line.rstrip("\n") if printLine: print printLine --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Anaglyph 3D Stereo Imaging with PIL and numpy

2006-05-03 Thread Scott David Daniels
t VPython -- there you can build 3-D models and display them in real time while viewing with your glasses. See: http://www.vpython.org/FAQ.html --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Mutable String

2006-05-03 Thread Scott David Daniels
x27;dudes') print stringish.tostring() -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: __init__.py, __path__ and packaging

2006-05-03 Thread Scott David Daniels
to anything in dbg.lib.debug. The "from dbg.lib.debug import *" statement can be seen as a module import followed by a fancy multiple assignment, where module dbg.lib.debug is first imported, then its globals are assigned to globals of the same names in module dbg. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: sort a list of files

2006-05-06 Thread Scott David Daniels
3, 4, 5, 9] If you are using an old version of Python (2.3.X or before), the you just need to break your statement up: Instead of: 6 print os.listdir(sys.argv[1]).sort() use: 6 files = os.listdir(sys.argv[1]) 7 files.sort() 8 print files --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Graphics Library

2006-05-08 Thread Scott David Daniels
Python can also put out POV-Ray source ( http://www.povray.org ). --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with iterators and inheritance

2006-05-08 Thread Scott David Daniels
New-style classes control object attribute lookups, and messages go to the class first (ignoring the instance dictionary). That is also how "properties" work, which (if you think about it right) could not otherwise survive the first assignment of the property. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: utility functions within a class?

2006-05-08 Thread Scott David Daniels
ntally collide with names in subclasses, for example). IMO, distutils, for example, over-uses the double leading underscore names; it makes it awkward for me to get to information that I'd like to obtain. The double leading underscore should be there if there is no reasonable use to getting

Re: Getting HTTP responses - a python linkchecking script.

2006-05-08 Thread Scott David Daniels
available somewhere online, I > can't see it to obviously in the library reference? You can help by mentioning where you'd most expect to find it in a Python documentation bug (or enhancement) report. Then you to can be a Python contributor. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: utility functions within a class?

2006-05-08 Thread Scott David Daniels
contents, and is a completely separate issue. If you define a module with a variable name '__all__' which is a list (or tuple) of strings, only module elements with those names will be imported with a "from module import *". If you fail to define the '__all__' eleme

Re: connect file object to standard output?

2006-05-08 Thread Scott David Daniels
If you are only using "print >>x"-style statements, simply set fp to None (which means "write on stdout"). That makes it easier to only close the file you opened later., say by ending the routine above with: if fp is not None: fp.close() --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Global utility module/package

2006-05-08 Thread Scott David Daniels
>print debugFlag The global line is not needed: global declarations are only required if you need to _write_ on globals w/in the function. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: utility functions within a class?

2006-05-08 Thread Scott David Daniels
John Salerno wrote: > Scott David Daniels wrote: >> John Salerno wrote: >>> ... But isn't there something about a single leading underscore >>> that doesn't import when you use from X import *? Or am I thinking of >>> something else? Is that also th

Re: group for pure startups...

2006-05-08 Thread Scott David Daniels
m > basically talking about meetings where you could form your team, join a > team, etc... Every startup I've been involved in began by recruiting trusted people; Forming a team involves several people risking each other's livelihoods, and is almost always begun with an "old boy

Re: Multi-line lambda proposal.

2006-05-08 Thread Scott David Daniels
thousands of lines of unmaintainable code. Essentially, a rule that says, "if it is not a simple expression, pick a name for it" is just not a bad idea. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: multiline strings and proper indentation/alignment

2006-05-09 Thread Scott David Daniels
w.w3.org/TR/html4/strict.dtd";>\n\n''' > > ..., but I don't want the extra newline or tabs to be > a part of the string when it's printed. The easiest way: self.DTD = ('http://www.w3.org/TR/html4/strict.dtd";>\n\n') Adjacent strings are

Re: Dictionaries -- ahh the fun.. (newbie help)

2006-05-09 Thread Scott David Daniels
You might prefer .iteritems rather than .items if the lists get huge. * I use the dict(name=val [, name=val)*) form if the keys are symbols. * Don't get any more indirect than you need to. * A list of single-entry dictionaries is almost never a good idea; if you mean a list of pairs, use t

Re: which windows python to use?

2006-05-11 Thread Scott David Daniels
Brian Blais wrote: > Are there any recommendations for which Windows python version to use? Only if you have criteria. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: find all index positions

2006-05-11 Thread Scott David Daniels
pos = -1 try: while True: pos = source.index(target, pos + 1) yield pos except ValueError: pass print list(positions('1234', 'abcd efgd 1234 fsdf gfds abcde 1234')) prints: [10, 31] --Scott David

Re: [ANN] PyYAML-3.02: YAML parser and emitter for Python

2006-05-15 Thread Scott David Daniels
Kirill Simonov wrote: > > Announcing PyYAML-3.02 > > > A new bug-fix release of PyYAML is now available: > > http://pyyaml.org/wiki/PyYAML Another fix provided for Python 2.5 and friends. -- -Scott David Daniels [EMAI

Re: common practice for creating utility functions?

2006-05-15 Thread Scott David Daniels
y you _can_ do that. I wouldn't, however. If (to you) the four functions above "mean" something different, I'd implement convert_quote with: convert_quote = make_code -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: common practice for creating utility functions?

2006-05-15 Thread Scott David Daniels
tertools for char in itertools.chain(onesource, anothersource, yetanother): ... --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Unable to extract Python source code using Windows

2006-05-16 Thread Scott David Daniels
tor.update(data) else: break finally: source.close() print 'md5 checksum =', accumulator.hexdigest() Compare that result to the published checksum for the archive to make sure you don't have a garbled archive. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Unable to extract Python source code using Windows

2006-05-16 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > Scott , > I tried downloading for different archives, (different versions of > Python) I can't believe they are all garbled. But they all don't work > with WinZip. And what checksum did you get? --Scott David Daniels [EMAIL PROTECTED] --

Re: Unable to extract Python source code using Windows

2006-05-16 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > Scott , > I tried downloading for different archives, (different versions of > Python) I can't believe they are all garbled. But they all don't work > with WinZip. > OK, against my better judgment (you haven't shown your work so far):

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Scott David Daniels
t to string from unicode in: ... map(str, Topamax) ) ) float works on all string types (including unicode), and will accept some non-ASCII digit values. -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: calling upper() on a string, not working?

2006-05-16 Thread Scott David Daniels
else: trans_table = string.maketrans(original_letters, trans_letters) > break > return original.translate(trans_table) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: IDLE confusion

2006-05-17 Thread Scott David Daniels
tive firewall settings, because no socket is allocated for communication. It is also useful for experimenting with Tkinter, because a Tkinter display loop is already running, so you can see the effects of your Tkinter commands as they are entered. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: constucting a lookup table

2006-05-17 Thread Scott David Daniels
ight - 60][weight - 80] = size; return result; } int getsize(int height, int weight, int size) { assert(60 <= height && height<= 88 && 80 <= weight && weight<= 400); return hwdict[height - 60][weight - 80]; } --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-17 Thread Scott David Daniels
quot;head"): > *!*title("title): > *=*text = "Page Title" > *!*body("body"): > *=*bgcolor = "#ff" > *=*text = "Hello, World!" Hunt up PyYAML. It might be what you want. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Name conflict in class hierarchy

2006-05-21 Thread Scott David Daniels
ou need a special-case work-around: class Bb(A): def __init__(self, *args, **kwargs): super(Bb, self).__init__(*args, **kwargs) self._recursed_func = 0 def f1(self): self._recursed_func += 1 try: return super(Bb, self).f1() finall

Re: performance difference between OSx and Windows

2006-05-22 Thread Scott David Daniels
e to explore. Since the GIL is released from time to time (on any system call that may wait, for example), it is a single core at any one instant, but is not necessarily the same core over time. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Name conflict in class hierarchy

2006-05-22 Thread Scott David Daniels
lse simply annoys those of us who may need to get access to those instances and methods. -- --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Running script in __main__ shows no output in IDLE

2006-05-22 Thread Scott David Daniels
else: main([r"\\Iceman\propod\flash\xml\webService\XmlData\Authors\Heidi"]) To investigate the idle environment, simply add: if __name__ == "__main__": print "to main" main([r"\\Iceman\propod\flash\xml\webService\XmlData\Authors\Heidi"]) else: print 'Sorry, __name was %r, not "__main__".' % __name__ --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Running script in __main__ shows no output in IDLE

2006-05-24 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > Thanks for your help! Shouldn't Idle have shown an error when trying to > read the string constant if it's not interpretable as a normal string, > then? I suspect it should. The error probably got lost in the start-script handling somewhere. --

Re: Use of lambda functions in OOP, any alternative?

2006-05-24 Thread Scott David Daniels
self, attr): self._attr = attr def getattr(self): return self._attr def attr(self): return self.getattr() attr = property(fget=attr) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with itertools.groupby.

2006-05-25 Thread Scott David Daniels
first): print k, [i for i in g] "groupby" depends on the source stream having the clustering you need. Otherwise it could not work "on the fly" for arbitrarily large sources. Often you can arrange for your data source to be clustered; when you cannot, the groupby arg is a great sort key. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Multi-dimensional list initialization trouble

2006-05-25 Thread Scott David Daniels
a frequently made mistake. try also: >>> bumble = [[0]*2 for 0 in xrange(2)] Think hard about why that might be. Then try: >>> [id(x) for x in foo] >>> [id(x) for x in baz] >>> [id(x) for x in bumble] Now check your upper scalp for lightbulbs. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Modify one character in a string

2006-05-26 Thread Scott David Daniels
haracter edit of the file. > > Why seeking to EOF after writing the byte? Because some operating systems may create an EOF (thus truncating the file) after a write, close sequence. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for triangulator/interpolator

2006-05-26 Thread Scott David Daniels
that work). Sounds like a great opportunity for you to contribute. The easiest contribution would be to find as small a case as you can that demonstrates the problem, fixing it and add a test case would be, obviously, a greater contribution. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Array? Please help.

2006-05-27 Thread Scott David Daniels
Dr. Pastor wrote: > I need a row of 127 bytes that I will use as a > circular buffer. Into the bytes (at unspecified times) > a mark (0 After some time the "buffer" will contain the last 127 marks. Sounds a lot like homework. -- --Scott David Daniels [EMAIL PROTECTED] -- htt

Re: Cheat sheet

2007-12-27 Thread Scott David Daniels
t; Classes Instances This probably wants to be Class Instances "file" objects are generally supposed to be built with the open function, not instantiated as shown. Also note iterating on a file gets the lines. Do you know about seq[i:] and seq[::-1]? --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Cheat sheet

2007-12-28 Thread Scott David Daniels
Riccardo T. wrote: > Scott David Daniels ha scritto: >> [in the .png] >>> ... >>> Callable types >>>... >>>User-definet methods >> I personally prefer "User-defined methods" > > That's a typo, thank you. Hope I didn&

Re: Cheat sheet

2007-12-28 Thread Scott David Daniels
Riccardo T. wrote: > Scott David Daniels ha scritto: >> Riccardo T. wrote: >>> Scott David Daniels ha scritto: >>>> [in the .png] >>>>> ... >>>>> Callable types >>>>>... >>>>>User-definet methods >

Re: using super

2007-12-31 Thread Scott David Daniels
sts the chaining happens." The recursion- like call to the super method is placed explicitly in Python so you can see how it works. If super is too tough to explain, I expect single inheritance is all you are using. simply remind people to call A.foo(self, ) within the definition of foo in B. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Trajectory Module?

2007-12-31 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > Greetings, > > I was wondering if there was a python Module/Library out there that > handles some trajectory/physics stuff like moving an object along a > straight path in an X,Y 2D (or 3D) plane or calculating parabolic > arcs. I'd really settle for just the moving of a

Re: using super

2007-12-31 Thread Scott David Daniels
Steven D'Aprano wrote: > On Mon, 31 Dec 2007 08:03:22 -0800, Scott David Daniels wrote: >> Steven D'Aprano wrote: ... >>> def chain(meth): # A decorator for calling super. >>> def f(self, *args, **kwargs): >>> result = meth(self, *args,

Re: using super

2007-12-31 Thread Scott David Daniels
Steven D'Aprano wrote: > On Mon, 31 Dec 2007 16:19:11 -0800, Scott David Daniels wrote: > >> Steven D'Aprano wrote: >>> On Mon, 31 Dec 2007 08:03:22 -0800, Scott David Daniels wrote: >>>> Steven D'Aprano wrote: ... >>>>> def chai

Re: using super

2008-01-01 Thread Scott David Daniels
ide a method, and the disposition of its results makes experimentation with different ways to use the result tempting. There is a temptation to play with the arguments as well, that runs afoul of the vagaries of multiple inheritance, that is the reason that I said "if they don't want t

Re: Using mouse

2008-01-01 Thread Scott David Daniels
mice, and so, inevitably, the answer to your question (and, indeed whether such a thing is even possible) depends on the OS and display packages you are using. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: confusion about package/module imports

2008-01-01 Thread Scott David Daniels
in most of these cases you will have imported the code for b twice, once as a main program, and once as a module in the hierarchy, which is probably your actual problem (and why I use "print __name__, __file__"). --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: confusion about package/module imports

2008-01-01 Thread Scott David Daniels
bol table (the packages __dict__) when the module has been completely imported. -Scott -- http://mail.python.org/mailman/listinfo/python-list

Re: how to use bool

2008-01-06 Thread Scott David Daniels
methode(self): try: mymethod() except MyError,myerr: stuff_only_for_exceptional_cases() raise # Note that this keeps the original traceback. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: use fileinput to read a specific line

2008-01-08 Thread Scott David Daniels
(filename) as f: for n, line in enumerate(f): if n == position: break else: line = None # indicate a short file yield filename, line ... for name, line in pairing(glob.glo

Re: Converting a bidimensional list in a bidimensional array

2008-01-09 Thread Scott David Daniels
h, tiles ): self.width, self.height = bw, bh self.tilemap = [array.array('b', [0]) * bw for row in range(bh)] self.clipboard = [array.array('b', [0]) * bw for row in range(bh)] Gives a list of arrays. I punted on the type arg here; you should make a definite d

Re: Converting a bidimensional list in a bidimensional array

2008-01-09 Thread Scott David Daniels
[0]*1000) for n in range(100)]" "v = a[1][2] + a[2][1] + a[3][3]" You can also use: C:\> \python25\python -m -s "import m; m.setup()" "m.my_fun(123)" Try it, you'll be addicted in no time. Check the documentation on package "timeit." --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Structure of packages

2008-01-09 Thread Scott David Daniels
-v whatever.py You can see all the imports that are done and in what order. Also realize that import a file executes it, so you can sprinkle prints at points where you are confused. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Collecting Rich Data Structures for students

2008-01-09 Thread Scott David Daniels
s. Also, a few screen-scraping programs that suck _current_ information from some sources should also delight; the students have a shot at getting ahead of the teacher. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: What is "lambda x=x : ... " ?

2008-01-10 Thread Scott David Daniels
a x=x : x+10 > > print y(2) > ## > > It prints 12, so it doesn't bind the variable in the outer scope. Primary use: funcs = [lambda x=x: x+2 for x in range(10)] print funcs[3]() _or_ funcs = [] for x in range(10): funcs.append(lambda x=x: x

Re: print >> to a derived file

2008-01-15 Thread Scott David Daniels
te(text) def __init__(self, *files): self._files = files def close(self): for dest in self._files: dest.close() f1 = MultiWrite(open('1.txt', 'w'), sys.stdout) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: next line (data parsing)

2008-01-16 Thread Scott David Daniels
in whatever: ... then you can do: source = iter(whatever) for intro in source: if intro.startswith('Schedule '): for line in source: if line.startswith('Total'): break process(intro, line) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a portable way to tell if data is available on a pipe?

2008-01-21 Thread Scott David Daniels
in front" of each pipe. The per-pipe thread reads a chunk, waiting if it has to, and then writes to the queue. To read from a pipe w/o waiting from one of these assemblies, you can use the get_nowait method on the associated queue. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.

Re: Ignore exceptions

2008-01-24 Thread Scott David Daniels
h by context mangers in 2.5 or later -- see with_statement. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Index of maximum element in list

2008-01-25 Thread Scott David Daniels
Hexamorph wrote: > ... > What's about l.index(max(l)) ? What about max((x,i) for i,x in enumerate(lst))[1] -- http://mail.python.org/mailman/listinfo/python-list

Re: Can my own objects support tuple unpacking?

2008-03-26 Thread Scott David Daniels
'Zapped') # The secret -- run out. -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: if-else statement

2009-01-10 Thread Scott David Daniels
er if checking: my_var = 'string' else: my_var = 'other string' remember, vertical space only kills trees if printed. --Scott David Daniels (who still prints this too frequently). scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Python logging rollover

2009-01-12 Thread Scott David Daniels
nfused. You need to show us enough so that we can discover what might, or might not, be going wrong. At the least, what was your code, what happened, and what did you expect to happen. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Python tricks

2009-01-12 Thread Scott David Daniels
for i in range(count): yield None raise exception You can do your loop as: check_infinite = Fuse(200, ValueError('Infinite Loop')).next while True: ... check_infinite() but I agree with Tim that a for ... else loop for the limit is clearer. --

Re: efficient interval containment lookup

2009-01-12 Thread Scott David Daniels
p numpy arrays to test the set of ranges in listA in a pair of operations. I hope I haven't helped you with your homework. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

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

2009-01-13 Thread Scott David Daniels
imageguy wrote: 1) >>> n = None 2) >>> c,d = n if n is not None else 0,0 ... This is more easily expressed as: c, d = n or (0, 0) -- http://mail.python.org/mailman/listinfo/python-list

Re: Problems in Using C-API for Unicode handling

2009-01-13 Thread Scott David Daniels
an encoded form (bytes) from the abstract "Unicode is characters". What you want in Python is: u'abc'.encode('UTF-16') So look for something returning a string by invoking the decode method. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: exec in a nested function yields an error

2009-01-13 Thread Scott David Daniels
vailable as locals that encompasses the locals of both f and f_nested, so you'll have to be explicit about what you mean. So, the code wants you to say something like: def f(): def f_nested(): exec "a=2" in globals(), locals() print a return f

Re: can someone tell me why this doesn't work please python 3

2009-01-14 Thread Scott David Daniels
lusively in the headers. Readers sometimes select by subject, but only read content. However the answer the OP is looking for with his ill-formed question could be revealed if his final print were: print('%s on reply %r' % (complaint, password)) He'd realize he wanted: password = input(prompt).rstrip() --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-14 Thread Scott David Daniels
the code you write naturally. The way to get to such performance on Python is through efforts like PyPy. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: optimizing large dictionaries

2009-01-15 Thread Scott David Daniels
= defaultdict(lambda: defaultdict(int)) or my_dict = defaultdict(functools.partial(defaultdict, int)) --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Scott David Daniels
ehaviour? It is the defined behavior. For what you want: import itertools as it def count_from(base): for n in it.count(): yield n + base itlist = [count_from(n) for n in range(2)] --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinf

Re: *Advanced* Python book?

2009-01-16 Thread Scott David Daniels
a favor and go to a bookstore and read a chapter or two of the cookbook. While you can see the recipes on activestate, there is a _lot_ of value added in (1) the selection, (2) the editing for a more consistent style, and (3) the chapter intros by people chosen for their knowledge on the chapter'

Re: uninstall before upgrade?

2009-01-19 Thread Scott David Daniels
waltbrad wrote: I want to upgrade from 2.5 to 2.6. Do I need to uninstall 2.5 before I do that? If so, what's the best way to uninstall it? Thanks. The answer to your question may depend on your operating system and setup. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and threads

2009-01-19 Thread Scott David Daniels
vedrandeko...@yahoo.com said: > ... when I run these two threads, > I think they don't start at the same time In response, Diez B. Roggisch wrote: ... Even if you managed to get two threads started simultaneously (which the OS doesn't even offer IINM), the would soon run out of sync And th

Re: function to find the modification date of the project

2009-01-19 Thread Scott David Daniels
ng it, he has accidentally changed the version of the code. This you could forestall by invoking your function at packaging time, and writing a file with the version string in it. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: what's the point of rpython?

2009-01-21 Thread Scott David Daniels
seems like there should be very little additional bus contention vs a normal add instruction. The opcode cannot simply talk to its cache, it must either go directly to off-chip memory or communicate to other processors that it (and it alone) owns the increment target. --Scott David Daniel

Re: How to write a simple shell loop in python?

2009-01-21 Thread Scott David Daniels
ine as the $. one The space separates the 'one' from the '$ ' that it output to stdout above. one one --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-21 Thread Scott David Daniels
ure allows simple implementation of debugging software, rather than the black arcana that is the normal fare of trying to weld debuggers into the compilers. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

<    9   10   11   12   13   14   15   16   17   18   >