Re: What's the best way to write this base class?

2011-06-17 Thread Chris Angelico
On Sat, Jun 18, 2011 at 2:17 PM, John Salerno wrote: > 1) > class Character: > >    def __init__(self, name, base_health=50, base_resource=10): >        self.name = name >        self.health = base_health >        self.resource = base_resource If you expect to override the health/resource, I'd us

Re: break in a module

2011-06-17 Thread Chris Angelico
On Sat, Jun 18, 2011 at 2:49 PM, Steven D'Aprano wrote: > Not quite. In my config language, "ignored" means ignored. There was no > way of accessing the rest of the file, short of guessing the file name, > opening it and reading it as text. > > In Perl, the __END__ and __DATA__ keywords mark the e

Re: What's the best way to write this base class?

2011-06-18 Thread Chris Angelico
s, but if you want it to be a good game, sometimes you need to go back on decisions like that. And that's where mailing lists like this are awesome. I've learned so much from the wisdom here... there is an amazing amount of expertise being offered freely! Chris Angelico -- http://mail.

Re: Strategy to Verify Python Program is POST'ing to a web server.

2011-06-18 Thread Chris Angelico
art from requiring about three times as much data from /dev/random, it wasn't materially different from a simple SSL cert check... Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Improper creating of logger instances or a Memory Leak?

2011-06-18 Thread Chris Torek
dler(filehandler) del logging.Logger.manager.loggerDict[self.logger.name] del self.logger # optional I am curious as to why you create a new logger for each thread. The logging module has thread synchronization in it, so that you can share one log (or several logs) amongst all threads

Re: Strategy to Verify Python Program is POST'ing to a web server.

2011-06-18 Thread Chris Angelico
On Sun, Jun 19, 2011 at 6:40 AM, Michael Hrivnak wrote: > On Sat, Jun 18, 2011 at 1:26 PM, Chris Angelico wrote: >> SSL certificates are good, but they can be stolen (very easily if the >> client is open source). Anything algorithmic suffers from the same >> issue. > &g

Re: NEED HELP-process words in a text file

2011-06-18 Thread Chris Rebert
unction. I commented on my program as to what it should do, but > nothing is printing. I know I am off, but not sure where. Please > help:( Netiquette comment: Please avoid SHOUTING and including unnecessary entreaties in your subject lines in the future. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: NEED HELP-process words in a text file

2011-06-18 Thread Chris Rebert
ths, not the actual words themselves, as keys. Corrected version (there are several ways to do this): length = len(word) freq[length] = freq.get(length, 0) + 1 # See dict.get() docs for details >        for word in freq.items(): Items returns a collection of key-value pairs, not a collection of keys. If you just want the keys, omit the `.items()`. Also, this seems to be indented wrong. You're running the output loop once per line rather than once per file. Finally, the dictionary yields its keys/items in no particular order; based on the sample output, you'll need to sort the word lengths if you want to output the table's rows in ascending order. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Strategy to Verify Python Program is POST'ing to a web server.

2011-06-18 Thread Chris Angelico
On Sun, Jun 19, 2011 at 10:38 AM, Gregory Ewing wrote: > And that only if the attacker isn't a Python programmer. > If he is, he's probably writing his attack program in > Python anyway. :-) > I was thinking you'd have it call on various functions defined elsewhere in the program, forcing him to

Re: import from environment path

2011-06-18 Thread Chris Torek
ight also want to take a look at PEP 302: http://www.python.org/dev/peps/pep-0302/ If you use "subprocess" to run program B, it cannot affect program A in any way that program A does not allow. This gives you a lot more control, with the price you pay being that you need to open some

Re: print header for output

2011-06-18 Thread Chris Rebert
he mailinglist digest, or at the very least please trim off the irrelevant quoted posts in your reply. >        #print ("Length \t" + "Count\n")#print header for all numbers. >        for word, count in freq.items(): >            print(len(word), count) > > fileProcess() Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Lisp : car and cdr

2011-06-19 Thread Chris Angelico
On Sun, Jun 19, 2011 at 10:56 PM, Ethan Furman wrote: > Lie Ryan wrote: >> def cdr(L): >>    return L[1] > > IANAL (I am not a Lisper), but shouldn't that be 'return L[1:]' ? In LISP, a list is a series of two-item units (conses). >> L = (a, (b, (c, (d, None This represents the LISP equival

Re: What is this syntax ?

2011-06-19 Thread Chris Angelico
raw_input() "Ha ha! 'Tis mine!", he said. >>> print repr(x) '"Ha ha! \'Tis mine!", he said.' In this instance, repr chose to use single quotes, but the same applies. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: threading : make stop the caller

2011-06-19 Thread Chris Angelico
On Mon, Jun 20, 2011 at 1:39 AM, Laurent Claessens wrote: > My problem is that when FileToCopyTask raises an error, the program does not > stop. > In fact when the error is Disk Full, I want to stop the whole program > because I know that the next task will fail too. If you're starting a thread f

Re: How to iterate on a changing dictionary

2011-06-19 Thread Chris Angelico
.It'll keep some and not others, and then you can make use of just the ones you get back. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: threading : make stop the caller

2011-06-19 Thread Chris Angelico
d's run() method one by one, which should propagate any exceptions in the same way that function calls usually do. Can you share the code for one of the tasks, and show what happens when it raises an exception? Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: What's the best way to write this base class?

2011-06-19 Thread Chris Kaynor
On Jun 18, 2011, at 9:26, John Salerno wrote: > Whew, thanks for all the responses! I will think about it carefully > and decide on a way. I was leaning toward simply assigning the health, > resource, etc. variables in the __init__ method, like this: > > def __init__(self, name): >self.name

Re: running multiple scripts -- which way is more elegant?

2011-06-19 Thread Chris Angelico
#x27;ve already hit on the two broad types (import the code, or use stdout/rc). Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: opening a file

2011-06-19 Thread Chris Rebert
to make ~-paths work: http://docs.python.org/library/os.path.html#os.path.expanduser Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Python scoping

2011-06-20 Thread Chris Angelico
declaring variables. In my opinion it's better to declare them, except in interactive code (eg IDLE or just typing "python"). But Python isn't that. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Boolean result of divmod

2011-06-20 Thread Chris Torek
efore, you can subscript the return value to get either element: >>> divmod(99.6,30.1)[0] 3.0 Thus, you can call bool() on the subscripted value to convert this to True-if-not-zero False-if-zero: >>> bool(divmod(99.6,30.1)[0]) True -- In-Real-Life: Chris Torek,

Re: Python scoping

2011-06-20 Thread Chris Angelico
On Tue, Jun 21, 2011 at 10:39 AM, Ben Finney wrote: > gervaz writes: > Python doesn't have variables the way C or many other languages have > them. > > Instead, Python has objects, and references to those objects so you can > get at them. The Python documentation, much to my frustration, calls >

those darn exceptions

2011-06-20 Thread Chris Torek
n classes that are only defined in user-provided code -- but to raise them, those functions have to include whatever code defines them, so I think this all just works.) The key thing needed to make this work, though, is the base cases for system-provided code written in C, which pylint by definitio

Re: those darn exceptions

2011-06-20 Thread Chris Angelico
On Tue, Jun 21, 2011 at 11:43 AM, Chris Torek wrote: > It can be pretty obvious.  For instance, the os.* modules raise > OSError on errors.  The examples here are slightly silly until > I reach the "real" code at the bottom, but perhaps one will get > the point

Re: Python scoping

2011-06-20 Thread Chris Angelico
On Tue, Jun 21, 2011 at 12:38 PM, Ben Finney wrote: > The *binding* is scoped. > And the binding follows the exact same rules as anything else would. It has scope and visibility. In terms of the OP, the binding IS like a variable. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: those darn exceptions

2011-06-20 Thread Chris Torek
In article Chris Angelico wrote: >Interesting concept of pulling out all possible exceptions. Would be >theoretically possible to build a table that keeps track of them, but >automated tools may have problems: > >a=5; b=7; c=12 >d=1/(a+b-c) # This could throw ZeroDivisionError

Re: Instances' __setitem__ methods

2011-06-20 Thread Chris Rebert
d so on) has a class attribute called > "f", and if it does, calls f(x, *args)? See the first paragraph under the "Classes" entry on http://docs.python.org/reference/datamodel.html#objects-values-and-types for perfect accuracy. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: [JOB] Python Programmer, Newport Beach, CA | 6-24 months - Relo OK

2011-06-20 Thread Chris Withers
ggest submitting to the Python Job Board: http://www.python.org/community/jobs/howto/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get return values of a forked process

2011-06-21 Thread Chris Torek
came from, but note that on Unix, the "os" module also provides os.WIFSIGNALED, os.WTERMSIG, os.WIFEXITED, and os.WEXITSTATUS for dissecting the "status" integer returned from the various os.wait* calls. Again, if you use the subprocess module, you are insulated from this sort of det

Re: those darn exceptions

2011-06-21 Thread Chris Torek
>On Tue, 21 Jun 2011 01:43:39 +0000, Chris Torek wrote: >> But how can I know a priori >> that os.kill() could raise OverflowError in the first place? In article <[email protected]> Steven D'Aprano wrote: >You can't. Even i

Finding greatest prime factor, was Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Chris Angelico
On Wed, Jun 22, 2011 at 7:48 AM, John Salerno wrote: > Thanks for the all the advice everyone. Now I'm on to problem #4, and > I'm stumped again, but that's what's fun! :) So now that you've solved it, I'd like to see some fast one-liners to do the job. (Since Python cares about whitespace, it mi

Re: Finding greatest prime factor, was Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Chris Angelico
Oops, realized after posting that there's a bug in my code - it returns 1 for a perfect square. Need another check in the 'while' loop, thus: On Wed, Jun 22, 2011 at 8:59 AM, Chris Angelico wrote: > exec 600851475143; for (int i=2;ii) ret/=i > >  while not ret%i and ret

Security test of embedded Python

2011-06-21 Thread Chris Angelico
pythontest.com:8000/ Find a bug, get noted as a contributor! :) Thanks! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Security test of embedded Python

2011-06-21 Thread Chris Angelico
On Wed, Jun 22, 2011 at 12:02 PM, Paul Rubin wrote: > Chris Angelico writes: >> users to supply scripts which will then run on our servers... >> The environment is Python 3.3a0 embedded in C++, running on Linux. > > This doesn't sound like a bright idea, given the

Re: Security test of embedded Python

2011-06-21 Thread Chris Angelico
nline for another shot once things are sorted out! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Security test of embedded Python

2011-06-21 Thread Chris Angelico
and how much dev time it's going to take me to change languages... Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Unicode codepoints

2011-06-21 Thread Chris Angelico
, so it may as well iterate over the generator instead. But I don't really understand what codePoints() does. Is it expecting the parameter to be a string of bytes or of Unicode characters? Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Handling import errors

2011-06-21 Thread Chris Rebert
#x27;t technical, then you should have a top-level try...except around almost the entire program that displays a simple error message in the event of an unhandled exception, preferably with an option to display the gory details (i.e. exception & stack trace). Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter/scrollbar/canvas question

2011-06-21 Thread Chris Angelico
On Wed, Jun 22, 2011 at 1:50 PM, Saul Spatz wrote: > This is the third time I've tried to post this reply.  If you see multiple > answers from me, that's why. > All three came through on the mailing list, but out of order - this one came in second. Chris Angelico -- htt

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Chris Torek
while r == 0: yield p if q == 1: return num = q q, r = divmod(num, p) if __name__ == '__main__': for arg in (sys.argv[1:] if len(sys.argv) > 1 else ['600851475143']): try: arg = int(arg) ex

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-22 Thread Chris Angelico
On Wed, Jun 22, 2011 at 10:01 PM, Anny Mous wrote: >            prime = table[i] >            del table[i] > I don't fully understand your algorithm, but I think these two lines can be rewritten as: prime=table.pop(i) Interesting algo. A recursive generator, not sure I've seen one of those befor

Re: running an existing script

2011-06-22 Thread Chris Rebert
` instead. Based on this, I'd say that nfold.py was written for Python 2.x rather than Python 3.x; so you'll either need to port it to Python 3.x, or install Python 2.x and run it under that. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: writable iterators?

2011-06-22 Thread Chris Kaynor
) lastValue = iterator.next() while True: print lastValue try: lastValue = iterator.send(lastValue + 1) except StopIteration: break print data >>> execute() 0 1 2 3 4 5 6 7 8 9 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Chris On Wed, Jun 22, 2011 at 4:10 PM, Ne

Re: Need help about for loop in python 3.2

2011-06-23 Thread Chris Rebert
On Wed, Jun 22, 2011 at 11:50 PM, kkiranmca wrote: > Hi i am new for this version and could please help me . You didn't pose an actual question... Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: python 3 constant

2011-06-23 Thread Chris Angelico
On Thu, Jun 23, 2011 at 9:58 PM, Waldek M. wrote: > Of course, it is just my personal opinion. It might be not pythonic, > I may be wrong, yet - concept of constants is not something new and > if other languages, like C/C++/Java/Perl/ (bash even) have them, > I can't see the reason not to have the

Re: writable iterators?

2011-06-23 Thread Chris Torek
== '__main__': d = {'one': 1, 'two': 2, 'three': 3} l = [9, 8, 7] print 'modify dict %r' % d for i in IndirectIter(d): i.set(-i.get()) print 'result: %r' % d print print 'modify list %r' % l

Re: performance critical Python features

2011-06-23 Thread Chris Angelico
On Fri, Jun 24, 2011 at 2:58 AM, Eric Snow wrote: > So, which are the other pieces of Python that really need the heavy > optimization and which are those that don't?  Thanks. > Things that are executed once (imports, class/func definitions) and things that primarily wait for user input don't nee

Re: those darn exceptions

2011-06-23 Thread Chris Torek
In article <[email protected]>, Gregory Ewing wrote: >Chris Torek wrote: > >> Oops! It turns out that os.kill() can raise OverflowError (at >> least in this version of Python, not sure what Python 3.x does). > >Seems to me that if this happens it ind

Re: python 3 constant

2011-06-23 Thread Chris Angelico
2011/6/24 Waldek M. : > Dnia Fri, 24 Jun 2011 01:29:38 +1000, Chris Angelico napisał(a): >> You can have them in Python. Just run your code through cpp (the C >> preprocessor) first. Voila! >> >> It's handy for other things too. Don't like Python's lac

Re: writable iterators?

2011-06-23 Thread Chris Torek
the above into an iterator, and handling container classes that have an __iter__ callable that produces an iterator that defines an appropriate index-and-value-getter, is left as an exercise. :-) ) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of W

Re: performance critical Python features

2011-06-23 Thread Chris Angelico
On Fri, Jun 24, 2011 at 10:07 AM, Steven D'Aprano wrote: > On Fri, 24 Jun 2011 04:00:17 +1000, Chris Angelico wrote: > >> On Fri, Jun 24, 2011 at 2:58 AM, Eric Snow >> wrote: >>> So, which are the other pieces of Python that really need the heavy >>> op

Re: Interpreting Left to right?

2011-06-23 Thread Chris Angelico
On Fri, Jun 24, 2011 at 2:32 PM, Chetan Harjani wrote: > x=y="some string" > And we know that python interprets from left to right. so why it doesnt > raise a name error here saying name 'y' is not defined? In most languages, the answer is that the = operator associates right to left, even though

Re: Interpreting Left to right?

2011-06-24 Thread Chris Angelico
On Fri, Jun 24, 2011 at 5:14 PM, Ethan Furman wrote: > --> x = x['huh'] = {} > --> x > {'huh': {...}} > I would have to call that dodgy practice... unless you have a lot of places where you need a dictionary with itself as an element, I would avoid assignments that depend on each other. Perhaps

Re: those darn exceptions

2011-06-24 Thread Chris Torek
>Chris Torek wrote: >> I can then check the now-valid >> pid via os.kill(). However, it turns out that one form of "trash" >> is a pid that does not fit within sys.maxint. This was a surprise >> that turned up only in testing, and even then, only because I &g

Re: Interpreting Left to right?

2011-06-24 Thread Chris Angelico
On Sat, Jun 25, 2011 at 7:02 AM, Terry Reedy wrote: > If I have ever used this sort of multiple assignment, it has been for simple > unambiguous things like "a = b = 0". For which it's extremely useful. Initialize a whole bunch of variables to zero... or to a couple of values: minfoo=minbar=minq

Re: those darn exceptions

2011-06-24 Thread Chris Angelico
" would be FooException + Y.__exceptions__ + Z.__exceptions__. It won't be perfect, but it'd be something that could go into an autodoc-style facility. Obviously you can fiddle with things, but in _ordinary usage_ this is what it's _most likely_ to produce. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: python 3 constant

2011-06-25 Thread Chris Angelico
2011/6/25 Waldek M. : > Dnia Fri, 24 Jun 2011 08:00:06 +1000, Chris Angelico napisał(a): >>> Yup, got the sarcasm, that's for sure. >>> But your point was...? >> >> That if you want something, there's usually a way to get it. >> Sometimes, giving so

Re: those darn exceptions

2011-06-25 Thread Chris Angelico
On Sun, Jun 26, 2011 at 12:28 AM, wrote: > Chris Angelico wrote: > >> Sure it can. And KeyboardInterrupt could be raised at any time, too. >> But this is a TOOL, not a deity. If Function X is known to call >> Function Y and built-in method Z, > > Known by whom? Yo

Re: Interpreting Left to right?

2011-06-25 Thread Chris Torek
ent (not expression) has the form: and the evaluation order is, in effect and using pseudo-Python: 1. -- the (single) RHS tmp = eval() 2. for in : # left-to-right = tmp When there is only one item in the (i.e., just one "x =" part in the whole stateme

Re: Significant figures calculation

2011-06-25 Thread Chris Torek
al for x in ( '1', '1.00', '1.23400e-8', '0.003' ): print 'sigdig(%s): %d' % (x, sigdig(D(x))) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City,

Re: Python 3 syntax error question

2011-06-26 Thread Chris Angelico
On Mon, Jun 27, 2011 at 1:28 AM, rzed wrote: > As to 2to3, I have to say that: > > -def a(b, (c,d)): > +def a(b, xxx_todo_changeme): > +    (c,d) = xxx_todo_changeme > > ... is not terribly revealing if one is unaware of what about it > needs changing. I know, I know: RTFM Sure, but you don't

Re: Struggling with sorted dict of word lengths and count

2011-06-27 Thread Chris Angelico
rrently you're printing out one word and one length from each line, which isn't terribly useful. Try this: for wordlen, wordfreq in freq.enumerate(): print(wordlen+"\t"+wordfreq); This should be outside the 'for line in' loop. There's a few other improvements po

Re: Struggling with sorted dict of word lengths and count

2011-06-27 Thread Chris Angelico
On Tue, Jun 28, 2011 at 3:00 AM, Cathy James wrote: > for word in line.lower().split( ):#split lines into words and make lower > case By the way, side point: There's not much point lower-casing the line when all you care about is the lengths of words :) ChrisA -- http://mail.python.org/mailman/

Re: Significant figures calculation

2011-06-27 Thread Chris Angelico
On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano wrote: > Zero sig figure: 0 > Is 0.0 one sig fig or two? (Just vaguely curious. Also curious as to whether a zero sig figures value is ever useful.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to chain processes together on a pipeline

2011-06-27 Thread Chris Rebert
the bright side, I think in part due to this /exact/ misunderstanding, in bleeding-edge Python v3.3 you can now write: >>> subprocess.call(["ls"], stdout=subprocess.DEVNULL) http://docs.python.org/dev/library/subprocess.html#subprocess.DEVNULL Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Significant figures calculation

2011-06-28 Thread Chris Angelico
On Tue, Jun 28, 2011 at 9:47 PM, Mel wrote: > > By convention, nobody ever talks about 1 x 9.97^6 . Unless you're a British politician of indeterminate party allegiance famous line, quoted as #6 in here: http://www.telegraph.co.uk/culture/tvandradio/7309332/The-ten-funniest-ever-Yes-Minister-

Re: Suppressing newline writing to file after variable

2011-06-28 Thread Chris Angelico
, same as the prefix. This is completely untested, but it should be a start. (Replace the calls to the imaginary "emit" function with whatever you do to emit results - for the intermediate passes, that's probably appending to a list.) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Suppressing newline writing to file after variable

2011-06-28 Thread Chris Angelico
On Wed, Jun 29, 2011 at 8:56 AM, Chris Angelico wrote: >      else emit(lastprefix+tails) >  else emit(lastprefix+tails) Typo in the above code. The else needs a colon after it, both times. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Change the name with the random names in a text file

2011-06-28 Thread Chris Rebert
be useful to those trying to help you. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Safely modify a file in place -- am I doing it right?

2011-06-29 Thread Chris Torek
your own mkstemp() (this can be a bit of a challenge!). Finally, as I implied above in talking about the os.link()-then- os.rename() sequence, if the original file has multiple links to it, note that this "breaks the links". If this is not what you want, the problem has no fully general solut

mortar_rdb 1.2.0 released!

2011-06-30 Thread Chris Withers
l Full package details including mailing list, irc and bug tracker details can be found here: http://www.simplistix.co.uk/software/python/mortar_rdb cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- htt

Re: how to call a function for evry 10 secs

2011-06-30 Thread Chris Angelico
On Fri, Jul 1, 2011 at 3:18 AM, MRAB wrote: > Looks like it hasn't changed even in WinXP, Python 3.2. > > Is IOError what you'd expect, anyway? > > What should it do in Python 3.2? Exception or max(seconds, 0)? The obvious thing for it to do is to go back in time and resume executing that many se

Re: Is the Usenet to mailing list gateway borked?

2011-06-30 Thread Chris Rebert
m willing to provide >> assistance, see also my suggestion in >> <news:[email protected]>. > > Hi, > > Who is responsible? I would assume those named in the footer of http://mail.python.org/mailman/listinfo/python-list , for whom python-list-ow...@py

Re: urllib, urlretrieve method, how to get headers?

2011-07-01 Thread Chris Rebert
regular urlopen(), get the headers using the .info() method of the resulting object, and do the file writing manually. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to chain processes together on a pipeline

2011-07-01 Thread Chris Rebert
s waiting for the OS pipe buffer to accept more data. ***Use communicate() to avoid that.***" [emphasis added] Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: urllib, urlretrieve method, how to get headers?

2011-07-01 Thread Chris Rebert
th an actual file object. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Is the Usenet to mailing list gateway borked?

2011-07-01 Thread Chris Angelico
On Fri, Jul 1, 2011 at 8:33 PM, TP wrote: > Not sure if this is relevant. I use mail.google.com to follow mailing > lists and a large proportion of python-list traffic ends up in my > gmail spam folder for some reason? Set a filter (you can "Filter messages like this") that says "Never spam". Tha

Re: subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import?

2011-07-01 Thread Chris Torek
ithout using import" but all you have to do is arrange for python to import this module before running any of your own code, e.g., with $PYTHONHOME and a modified site file. -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Sa

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Rebert
ange(1,10)) def clearSet(self): # ...rest same as before... Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Rebert
def __init__(self): >>         self.mySet = sets.Set(range(1,10)) >> >>     def clearSet(self): >> # ...rest same as before... > > > Thanks Chris. That was certainly very helpful!! > > So just out of curiosity, why does it work as I had expected when the >

Re: The end to all language wars and the great unity API to come!

2011-07-02 Thread Chris Angelico
mand that other people write your glue for you, because chances are they won't do as good a job as an expert in the language. C or C++ bindings will cover most languages. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: The end to all language wars and the great unity API to come!

2011-07-02 Thread Chris Angelico
On Sun, Jul 3, 2011 at 10:21 AM, rantingrick wrote: > No. Aspell should offer bindings for THE "Unity API" and the > respective "abstraction communities" are then responsible for > maintaining a plugin for their "abstraction" into THE Unity API. > Your proposed "Unity API" (which I assume has not

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Angelico
'Test']) But: >>> c=['Foobar'] >>> c,d (['Foobar'], ['Test']) When you do a=2 or c=['Foobar'], you're rebinding the name to a new object. But c.append() changes that object, so it changes it regardless of which name you look for it by. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Rebert
On Sat, Jul 2, 2011 at 5:46 PM, Chris Angelico wrote: > On Sun, Jul 3, 2011 at 8:23 AM, Saqib Ali wrote: >> So just out of curiosity, why does it work as I had expected when the >> member contains an integer, but not when the member contains a set? > > It's no

Re: The end to all language wars and the great unity API to come!

2011-07-02 Thread Chris Angelico
On Sun, Jul 3, 2011 at 10:58 AM, rantingrick wrote: > > Take Pidgin[1] as an example. Pidgin is a universal chat client. It's > a glue between the many chat clients that exist... It's a monkey patch > for chat multiplicity but you get the idea. However the Unity API > cannot be a monkey patch. It

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Angelico
On Sun, Jul 3, 2011 at 11:07 AM, Chris Rebert wrote: >>>>> c,d >> ({}, []) > > Nasty typo in your pseudo-interpreter-session there... Whoops! This is what I get for trying to be too smart! >>> c,d ([], []) Thanks for catching that, Chris. :) (another) Chri

Re: The end to all language wars and the great unity API to come!

2011-07-02 Thread Chris Angelico
learning. It means you can transfer knowledge from one language to another. It doesn't make either useless. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: web browsing short cut

2011-07-02 Thread Chris Rebert
invoke some COM API that does window positioning+resizing. I am unable to give more details as I'm on a Mac. Sidenote: Have you tried Firefox's "Bookmark All Tabs" feature? Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyone want to critique this program?

2011-07-02 Thread Chris Angelico
mend change. Use try/except to catch exceptional situations, not normalities. If your code is going through the except block most of the time, there's probably something wrong. Note I don't say there IS something wrong; it's an example of code smell, and can be correct. Your code has much in its favour. I've been wordy in suggestions but that doesn't mean you have bad code! :) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: web browsing short cut

2011-07-02 Thread Chris Rebert
> On Sat, Jul 2, 2011 at 7:10 PM, Chris Rebert wrote: >> On Sat, Jul 2, 2011 at 6:21 PM, Dustin Cheung wrote: >> > Hey guys, >> > I am new to python. I want to make a shortcut that opens my websites >> > and re-sizes them to >> > point to to the ri

Re: The end to all language wars and the great unity API to come!

2011-07-02 Thread Chris Angelico
("wait wha? This programmer's defined + and * in opposite precedence to usual!"). But hey, there's only one language that you need to learn! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyone want to critique this program?

2011-07-02 Thread Chris Angelico
On Sun, Jul 3, 2011 at 1:41 PM, John Salerno wrote: > Yeah, I considered that, but I just hate the way it looks when the > line wraps around to the left margin. I wanted to line it all up under > the opening quotation mark. The wrapping may not be as much of an > issue when assigning a variable li

Re: Implicit initialization is EVIL!

2011-07-03 Thread Chris Angelico
A new user should learn from day one that variables need to be stored somewhere, so Python should stop coddling its newbies and actually get them to do things right: var(0x14205359) x # Don't forget to provide an address where the object will be located x=42 After all, everyone's gotta l

Re: Problem!!

2011-07-03 Thread Chris Angelico
acters. If you divide the contents of the file on the "\n" character, and then try to work with the end of each line, you may find that the string has a "\r" character at the end. 3) What Irmen de Jong said. :) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EVIL!

2011-07-04 Thread Chris Angelico
> windows should have equal status. I don't know Tkinter, but from the look of the example code, he's creating a Label that's not attached to a window, and then packing it into nothing. The toolkit kindly creates him a window. Is that the "root GUI window" that he means? A basic top-level window? Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EVIL!

2011-07-04 Thread Chris Angelico
On Tue, Jul 5, 2011 at 1:19 AM, rantingrick wrote: > But let's dig a little deeper here. Your comment suggests that you > "personally" need to create multiple windows for your applications. Is > this correct? If so i pity any users of such application as they would > be thoroughly confused. Most a

Re: Implicit initialization is EVIL!

2011-07-04 Thread Chris Angelico
On Tue, Jul 5, 2011 at 1:46 AM, rantingrick wrote: > On Jul 4, 10:40 am, Chris Angelico wrote: > >> Uhh, sorry. No. There are plenty of good reasons for one application >> to make multiple top-level windows, and if I ever find myself using a >> toolkit that makes this d

Re: The end to all language wars and the great unity API to come!

2011-07-04 Thread Chris Angelico
Has anyone ever used a very-high-level language (like Python or Ruby or Lua) to write, say, a video driver? There is a place for the languages that take most of the work away from the programmer, and a place for languages that basically give you the hardware and say "have fun". There will never be a universal language that does both jobs perfectly. *returns the crystal ball* Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyone want to critique this program?

2011-07-04 Thread Chris Angelico
On Tue, Jul 5, 2011 at 2:37 AM, OKB (not okblacke) wrote: >        Well, what I'm saying is I use an editor that lets me make the > lines as long as I want, and it still wraps them right, so I never > explicitly hit enter to break a line except at the end of a string (or > paragraph). In this ins

Re: Implicit initialization is EVIL!

2011-07-04 Thread Chris Angelico
On Tue, Jul 5, 2011 at 3:09 AM, rantingrick wrote: > On Jul 4, 11:01 am, Chris Angelico wrote: >> This is not >> a modal dialog; it's not even a modeless dialog - it's a completely >> stand-alone window that can be moved around the Z order independently >> of

<    24   25   26   27   28   29   30   31   32   33   >