Re: strange subprocess behavior when calling ps

2010-11-16 Thread Chris Rebert
On Tue, Nov 16, 2010 at 6:33 PM, Roger Davis r...@hawaii.edu wrote: Hi all, I have encountered a strange problem with some code I am writing to search the system process list for certain running processes. I am using subprocess.Popen() to call '/bin/ps -e'. When I save my code to the file

Re: How can I catch segmentation fault in python?

2010-11-16 Thread Chris Rebert
On Tue, Nov 16, 2010 at 9:26 PM, justin justpar...@gmail.com wrote: Hi all, I am calling a program written in C inside Python using ctypes, and it seems that sometimes the program in C crashes while it's being used in Python. Even under the circumstances, I want to get the Python program

Re: Noob question on 2 vs 3 Python releases

2010-11-14 Thread Chris Rebert
On Sun, Nov 14, 2010 at 1:03 AM, Franck Ditter fra...@ditter.org wrote: Pardon my noobness (?) but why is there a 2.x and 3.x development teams working concurrently in Python ? I hardly saw that in other languages. You haven't heard of the infamous Perl 6? Which one should I choose to start

Re: raise Exception or raise Exception()

2010-11-14 Thread Chris Rebert
On Sun, Nov 14, 2010 at 8:58 AM, ernest nfdi...@gmail.com wrote: I have seen both forms and I'm not sure if they're both correct, or one is right and the other wrong. They're both acceptable (although obviously you should always raise a more specific error than Exception). `raise SomeException`

Re: subprocess pipe

2010-11-14 Thread Chris Rebert
On Sun, Nov 14, 2010 at 10:50 AM, Camille Harang mammi...@garbure.org wrote: Hi all, I'm having a problem with subprocess.Popen. It seems that its unable to capture the pg_dump's standard inputs outputs in a non-shell mode: from subprocess import Popen, PIPE # fire pg_dump in order to

Re: Objects versus dictionaries

2010-11-14 Thread Chris Rebert
On Sun, Nov 14, 2010 at 11:00 AM, Micah Carrick mi...@greentackle.com wrote: I'm writing a little API that other people will use. There are up to 3 objects that get passed around. One of them has some validation methods, the other two simply store data and probably won't have any validation or

Re: Some syntactic sugar proposals

2010-11-14 Thread Chris Rebert
On Sun, Nov 14, 2010 at 10:39 PM, Dmitry Groshev lambdadmi...@gmail.com wrote: Here are some proposals. They are quite useful at my opinion and I'm interested for suggestions. It's all about some common patterns. snip Second, I saw a lot of questions about using dot notation for a object-like

Re: strange behavor....

2010-11-13 Thread Chris Rebert
On Sat, Nov 13, 2010 at 5:46 AM, Tracubik affdfsdfds...@b.com wrote: hi all, i've this on python 2.6.6: def change_integer(int_value): ...     int_value = 10 ... ... def change_list(list): ...     list[0] = 10 ... ... a = 1 ... l = [1,1,1] ... ... change_integer(a) ... change_list(l)

Re: returning results from function

2010-11-11 Thread Chris Rebert
On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg nb...@atmos.ucla.edu wrote: Hi Python community, In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time.  I am passing

Re: returning results from function

2010-11-11 Thread Chris Rebert
On Nov 11, 2010, at 1:54 PM, Chris Rebert wrote: On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg nb...@atmos.ucla.edu wrote: Hi Python community, In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date

[issue7950] subprocess.Popen documentation should contain a good warning about the security implications when using shell=True

2010-11-11 Thread Chris Rebert
Chris Rebert pyb...@rebertia.com added the comment: the above Note mentioned in those last two lines demonstrates shlex.split() and correct tokenization. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7950

Re: Feed subscription IM bot

2010-11-10 Thread Chris Rebert
On Wed, Nov 10, 2010 at 6:49 AM, alexander bookre...@gmail.com wrote: Hi,   Can anyone help on this? http://stackoverflow.com/questions/1901828/best-python-xmpp-jabber-client-library http://www.djangoproject.com/ Come back when you have a much less nebulous question. And try googling first

Re: Curses Programming

2010-11-10 Thread Chris Rebert
On Wed, Nov 10, 2010 at 6:42 AM, alexander bookre...@gmail.com wrote: Subject: Curses Programming This has nothing whatsoever to do with the (n)curses library or even console programming. Lying in your subject line does not help gain you goodwill. Hi, all     Here is the test. Plz help.

Re: Looping through files in a directory

2010-11-10 Thread Chris Rebert
On Wed, Nov 10, 2010 at 2:46 PM, Matty Sarro msa...@gmail.com wrote: Short story - I have a few thousand files in a directory I need to parse through. Is there a simple way to loop through files? I'd like to avoid writing a python script that can parse 1 file, and have to call it a few

Re: Questions: While And List Comprehension

2010-11-10 Thread Chris Rebert
On Wed, Nov 10, 2010 at 5:38 PM, MRAB pyt...@mrabarnett.plus.com wrote: On 11/11/2010 00:29, James Mills wrote: On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebilleem...@fenx.com  wrote: Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that still reads the entire sys.stdin

Re: subclassing str

2010-11-10 Thread Chris Rebert
On Wed, Nov 10, 2010 at 8:14 PM, not1xor1 (Alessandro) @libero.it wrote: Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto: How exactly does    a.f(b, c) save time over     f(a, b, c) unfortunately in real world you have: objId = objId.method(args) vs. objId =

Re: Looping through files in a directory

2010-11-10 Thread Chris Rebert
On Wed, Nov 10, 2010 at 10:11 PM, r0g aioe@technicalbloke.com wrote: On 11/11/10 00:17, Steve Holden wrote: On 11/10/2010 5:46 PM, Matty Sarro wrote: Short story - I have a few thousand files in a directory I need to parse through. Is there a simple way to loop through files? I'd like to

Re: An easier way to do this? (spoiler if you're using pyschools for fun)

2010-11-09 Thread Chris Rebert
On Tue, Nov 9, 2010 at 11:00 AM, Matty Sarro msa...@gmail.com wrote: Hey everyone, I'm working on one of the puzzles on pyschools.com, and am trying to figure out if I can make my solution a bit more elegant. def getSumOfLastDigit(numList):     sumOfDigits=0     for i in range(0,

Re: JavaScript vs Python (was Re: Commercial or Famous Applicattions.?)

2010-11-08 Thread Chris Rebert
On Mon, Nov 8, 2010 at 10:52 PM, Lawrence D'Oliveiro l...@geek-central.gen.nz wrote: In message mailman.756.1289284312.2218.python-l...@python.org, John Bond wrote: On 9/11/2010 5:54 AM, Lawrence D'Oliveiro wrote: In messagemailman.755.1289276189.2218.python-l...@python.org, John Bond wrote:

Re: subclassing str

2010-11-07 Thread Chris Rebert
On Sat, Nov 6, 2010 at 10:43 PM, not1xor1 (Alessandro) @libero.it wrote: Hi, I'd like to know what is the best way to subclass str I need to add some new methods and that each method (both new and str ones) return my new type For instance I've seen I can do: class mystr(str):   def

Re: A question about yield

2010-11-07 Thread Chris Rebert
On Sun, Nov 7, 2010 at 9:34 AM, chad cdal...@gmail.com wrote: snip #!/usr/local/bin/python import sys def construct_set(data):    for line in data:        lines = line.splitlines()        for curline in lines:            if curline.strip():                key = curline.split(' ')        

Re: A question about yield

2010-11-07 Thread Chris Rebert
On Sun, Nov 7, 2010 at 9:56 AM, chad cdal...@gmail.com wrote: On Nov 7, 9:47 am, Chris Rebert c...@rebertia.com wrote: On Sun, Nov 7, 2010 at 9:34 AM, chad cdal...@gmail.com wrote: snip #!/usr/local/bin/python import sys def construct_set(data):    for line in data:        lines

Re: How to test if a module exists?

2010-11-06 Thread Chris Rebert
On Sat, Nov 6, 2010 at 11:22 AM, Jon Dufresne jon.dufre...@gmail.com wrote: Hi, My python program has an extension system where the extension can have a optional magic python modules. Meaning if the extension module exists, the program will use it and if not, it will continue without the

Re: How to test if a module exists?

2010-11-06 Thread Chris Rebert
On Sat, Nov 6, 2010 at 1:01 PM, Mark Wooding m...@distorted.org.uk wrote: Chris Rebert c...@rebertia.com writes:     if err.message != No module named extension_magic_module: Ugh!  Surely this can break if you use Python with different locale settings! Since when does Python have translated

Re: How to test if a module exists?

2010-11-06 Thread Chris Rebert
On Sat, Nov 6, 2010 at 11:50 AM, Jon Dufresne jon.dufre...@gmail.com wrote: On Sat, Nov 6, 2010 at 11:35 AM, Chris Rebert c...@rebertia.com wrote: Here's what I came up with: try:     import extension_magic_module except ImportError as err:    if err.message != No module named

Re: decimal.py ver 2.6,2.7 not working with python 2.7

2010-11-05 Thread Chris Rebert
On Fri, Nov 5, 2010 at 10:50 AM, robert roze rbr...@yahoo.com wrote: I have a 'Python 2.7' installed. It seems like the decimal.py module that comes with the Python2.7 package is not working. I hope I'm wrong, but here's why I think so: If I simply try to import the module, I get this error:

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Chris Rebert
On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro msa...@gmail.com wrote: I'm currently trying to convert a digit from decimal to hex, however I need the full 4 digit hex form. Python appears to be shortening the form. Example: num = 10 num = %x%(num) print(num) a num = 10 num = %#x%(num)

Re: Using Python for a demonstration in historical linguistics

2010-11-05 Thread Chris Rebert
On Fri, Nov 5, 2010 at 7:17 PM, Dax Bloom bloom@gmail.com wrote: Hello, In the framework of a project on evolutionary linguistics I wish to have a program to process words and simulate the effect of sound shift, for instance following the Rask's-Grimm's rule. I look to have python take a

Re: How convert list to nested dictionary?

2010-11-04 Thread Chris Rebert
On Thu, Nov 4, 2010 at 11:48 AM, macm moura.ma...@gmail.com wrote: Hi Folks How convert list to nested dictionary? l ['k1', 'k2', 'k3', 'k4', 'k5'] result {'k1': {'k2': {'k3': {'k4': {'k5': {}} We don't do homework. Hint: Iterate through the list in reverse order, building up your

Re: Allow multiline conditions and the like

2010-11-04 Thread Chris Rebert
On Thu, Nov 4, 2010 at 11:09 AM, Mark Wooding m...@distorted.org.uk wrote: Chris Rebert c...@rebertia.com writes: Or, if possible, refactor the conditional into a function (call) so it's no longer multiline in the first place. No!  This /increases/ cognitive load for readers, because

Re: How convert list to nested dictionary?

2010-11-04 Thread Chris Rebert
On 4 nov, 16:53, Chris Rebert c...@rebertia.com wrote: On Thu, Nov 4, 2010 at 11:48 AM, macm moura.ma...@gmail.com wrote: Hi Folks How convert list to nested dictionary? l ['k1', 'k2', 'k3', 'k4', 'k5'] result {'k1': {'k2': {'k3': {'k4': {'k5': {}} We don't do homework. Hint

Re: Allowing comments after the line continuation backslash

2010-11-03 Thread Chris Rebert
On Mon, Nov 1, 2010 at 8:15 PM, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message mailman.469.1288654964.2218.python-l...@python.org, Chris Rebert wrote: desc_attr_colors_triples = ((normal, image, MainWindow.ColorsNormalList),     (highlighted, highlight

Re: Serializing a user-defined class

2010-11-03 Thread Chris Rebert
On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons theimmortal...@gmail.com wrote: Hi all, got a question regarding serializing classes that I've defined. I have some classes like class Foo:      def __init__(self, x, y):           self.x = x, self.y = y then a class that can contain multiple

Re: Serializing a user-defined class

2010-11-03 Thread Chris Rebert
On Wed, Nov 3, 2010 at 10:35 AM, Chris Rebert c...@rebertia.com wrote: On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons theimmortal...@gmail.com wrote: Hi all, got a question regarding serializing classes that I've defined. I have some classes like class Foo:      def __init__(self, x, y

Re: Serializing a user-defined class

2010-11-03 Thread Chris Rebert
On Wed, Nov 3, 2010 at 11:18 AM, Chris Rebert c...@rebertia.com wrote: On Wed, Nov 3, 2010 at 10:35 AM, Chris Rebert c...@rebertia.com wrote: On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons theimmortal...@gmail.com wrote: Hi all, got a question regarding serializing classes that I've

Re: Serializing a user-defined class

2010-11-03 Thread Chris Rebert
On Wed, Nov 3, 2010 at 9:48 AM, T.J. Simmons theimmortal...@gmail.com wrote: snip And I was about to ask what top-posting was, but then I realized I wasn't sending this back to the list. So I'm going to assume what that was. Nope, actually it's about placing your reply below the quoted message

Re: functions, list, default parameters

2010-11-02 Thread Chris Rebert
On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Thu, 21 Oct 2010 19:53:53 -0700, John Nagle wrote: This is a common newbie stumbling-block: Don't use lists (or anything mutable) as default argument values      That really should be an error.

Re: Allow multiline conditions and the like

2010-11-01 Thread Chris Rebert
On Mon, Nov 1, 2010 at 12:51 AM, Steven D'Aprano steve-remove-t...@cybersource.com.au wrote: On Sun, 31 Oct 2010 23:02:21 -0700, Yingjie Lan wrote: Hi, This is a mini-proposal I piggy-tailed in the other topic: Allow the conditions in the if-, elif-, while-, for-, and with-clauses to span

Re: factorial of negative one (-1)

2010-11-01 Thread Chris Rebert
On Mon, Nov 1, 2010 at 4:19 AM, Bj Raz whitequill...@gmail.com wrote: On Fri, Oct 29, 2010 at 1:02 AM, Chris Rebert c...@rebertia.com wrote: On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz whitequill...@gmail.com wrote: I am working with differential equations of the higher roots of negative one

Re: Allowing comments after the line continuation backslash

2010-11-01 Thread Chris Rebert
On Mon, Nov 1, 2010 at 3:16 PM, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message 4cce6ff6.2050...@v.loewis.de, Martin v. Loewis wrote: (in fact, I can't think any situation where I would use the backslash).    for \        Description, Attr, ColorList \    in \      

Re: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS ***

2010-11-01 Thread Chris Rebert
-Original Message- From: silver light lightsilv...@gmail.com Sender: python-list-bounces+brf256=gmail@python.org Date: Mon, 1 Nov 2010 18:10:36 To: python-list@python.org Cc: lightsilv...@gmail.com Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT        

Re: [Beginer Question] I heard about python needing some sort of _VariableName_ boiler plate?

2010-10-31 Thread Chris Rebert
On Sun, Oct 31, 2010 at 7:09 PM, Braden Faulkner brad...@hotmail.com wrote: I heard about python needing some sort of _VariableName_ boiler plate? Can anyone explain to me how this works, I don't seem to have to do it in IDLE? Your question is extremely vague. Please give more details.

Re: with block for multiple files

2010-10-31 Thread Chris Rebert
On Sun, Oct 31, 2010 at 10:03 PM, Yingjie Lan lany...@yahoo.com wrote: Hi, Suppose I am working with two files simultaneously, it might make sense to do this: with open('scores.csv'), open('grades.csv', wt) as f,g:     g.write(f.read()) sure, you can do this with nested with-blocks, but

Re: How to write pbm file in Python 3?

2010-10-30 Thread Chris Rebert
On Sat, Oct 30, 2010 at 8:32 PM, André andre.robe...@gmail.com wrote: I'm trying to create pbm (portable bitmap) files using Python 3 and have run into a problem.   The example I am using is the Python 2 Mandelbrot program found at

Re: How to write pbm file in Python 3?

2010-10-30 Thread Chris Rebert
On Sat, Oct 30, 2010 at 9:21 PM, André andre.robe...@gmail.com wrote: On Oct 31, 1:11 am, Chris Rebert c...@rebertia.com wrote: On Sat, Oct 30, 2010 at 8:32 PM, André andre.robe...@gmail.com wrote: I'm trying to create pbm (portable bitmap) files using Python 3 and have run into a problem

Re: Exception Handling in Python 3

2010-10-29 Thread Chris Rebert
On Fri, Oct 29, 2010 at 2:30 AM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Chris Rebert wrote: Your Traceback is merely being made slightly longer/more complicated than you'd prefer; however, conversely, what if a bug was to be introduced into your exception handler? Then you'd likely

Re: Suppressing __context__

2010-10-29 Thread Chris Rebert
On Fri, Oct 29, 2010 at 4:02 AM, Antoine Pitrou solip...@pitrou.net wrote: On Sun, 24 Oct 2010 10:48:23 +0200 Martin v. Loewis mar...@v.loewis.de wrote: You may now wonder whether it is possible to set __context__ to None somehow. See PEP 3134: Open Issue: Suppressing Context     As

Re: is elementTree really a part of python 2.6?

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 1:23 AM, hackingKK hackin...@gmail.com wrote: Hello all, Some days back I had asked a few questions about parsing xml files using python. I have tryed dom.minidom module but I did not like the prittyPrint way of writing nodes. There were many other things I did not

Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 9:33 AM, cbr...@cbrownsystems.com cbr...@cbrownsystems.com wrote: On Oct 28, 9:23 am, John Posner jjpos...@optimum.net wrote: On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote: It's clear but tedious to write: if 'monday in days_off or tuesday in days_off:    

Re: Create a GUI and EXE for a python app?

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 1:53 PM, Braden Faulkner brad...@hotmail.com wrote: Having trouble with my mail client, so sorry if this goes through more than once. I'm worknig on a simple math program as my first application. I would like to make a cross-platform pretty GUI for it and also package

Re: Calling a method from invoking module

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 8:33 PM, Baskaran Sankaran baskar...@gmail.com wrote: Sorry for the confusion; fooz(), track() and barz() are all members of their respective classes. I must have missed the self argument while creating the synthetic example. Yeah, I realize the mutual import is a bad

Re: factorial of negative one (-1)

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz whitequill...@gmail.com wrote: I am working with differential equations of the higher roots of negative one. (dividing enormous numbers into other enormous numbers to come out with very reasonable numbers). I am mixing this in to a script for Maya (the

Re: How on Factorial

2010-10-27 Thread Chris Rebert
On Tue, Oct 26, 2010 at 11:25 PM, Geobird a1chan...@gmail.com wrote:  I  am a beginner in Python and would ask for a help. I  was searching for  smaller  version  of  code  to calculate factorial . Found  this one def fact(x):        return x 1 and x * fact(x - 1) or 1  But I don't  

Re: is list comprehension necessary?

2010-10-26 Thread Chris Rebert
On 10/26/10, Mikael B mba...@live.se wrote: That's from the functional programming crowd. Python isn't a functional language. A noob question: what is a functional language? What does it meen? A language which supports the functional programming paradigm:

Re: Interaction btw unittest.assertRaises and __getattr__. Bug?

2010-10-26 Thread Chris Rebert
On Tue, Oct 26, 2010 at 7:51 PM, Benjamin Peterson benja...@python.org wrote: Inyeol inyeol.lee at gmail.com writes: or am I missing something obvious? The attribute access is evaluated before the call to assertRaises, so unittest never has a cache to cache it. or rather, chance to catch

Re: Unicode questions

2010-10-25 Thread Chris Rebert
On Sun, Oct 24, 2010 at 10:43 PM, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message mailman.33.1287519268.2218.python-l...@python.org, Chris Rebert wrote: There is no such thing as plain Unicode representation. UCS-4 or UTF-16 probably come the closest. How do you

Re: python library for mail/news message headers bodies?

2010-10-25 Thread Chris Rebert
On Mon, Oct 25, 2010 at 7:18 PM, Arthur Divot art...@example.com wrote: Is there a python library equivalent to Perl's News::Article (load a file containing a news or mail message into an object, manipulate the headers and body, create a new empty one, save one to a file)? The `email` package

Re: Interface centering

2010-10-24 Thread Chris Rebert
On Sun, Oct 24, 2010 at 12:21 AM, Jah_Alarm jah.al...@gmail.com wrote: sorry 4 the sillu question. I've designed a GUI. How can I center on the screen? (i.e. it's always launched in the center of the screen) Which GUI toolkit did you use? Cheers, Chris --

Re: newbie to python

2010-10-24 Thread Chris Rebert
On Sun, Oct 24, 2010 at 12:29 AM, Hrishikesh hrishikesh...@gmail.com wrote: I want to start python, I have just downloaded python compiler, Most consider it an interpreter (though it does compile the source code into high-level bytecode). Can somebody please tell me what python really is A

Re: How do I chain methods?

2010-10-24 Thread Chris Rebert
On Sun, Oct 24, 2010 at 3:47 PM, chad cdal...@gmail.com wrote: How do I chain methods? I tried the following... #!/usr/bin/python class foo:    def first(self):        print Chad    def last(self):        print A x = foo() y = x.first() y.last() But when I ran it, I got the

Re: How do I chain methods?

2010-10-24 Thread Chris Rebert
On Sun, Oct 24, 2010 at 4:11 PM, James Mills prolo...@shortcircuit.net.au wrote: On Mon, Oct 25, 2010 at 9:02 AM, Chris Rebert c...@rebertia.com wrote: Method chaining is usually* not idiomatic in Python. I don't agree but anyway... I've just not seen it commonly used amongst python

Re: Unix-head needs to Windows-ize his Python script (II)

2010-10-23 Thread Chris Rebert
On Sat, Oct 23, 2010 at 12:32 AM, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message mailman.128.1287758336.2218.python-l...@python.org, Tim Golden wrote: If you were to rename the .py to a .pyw it would run without a console window showing up. Presumably the “w” stands

Re: inline for and if

2010-10-23 Thread Chris Rebert
On Wed, Oct 20, 2010 at 11:28 AM, Guy Doune cesium5...@yahoo.ca wrote: Hello, I would get : db.table.field1, db.table.field2, etc. Inside a python instruction : db().select(HERE) It is web2py query actually. But I can't do this : db().select( for f in db['table'].fields:     if f not in

Re: yield all entries of an iterable

2010-10-23 Thread Chris Rebert
On Wed, Oct 20, 2010 at 3:27 PM, Sebastian sebastianspublicaddr...@googlemail.com wrote: Hi, Is there a simpler way to yield all elements of a sequence than this? for x in xs:    yield x Not presently. There's a related PEP under discussion though: PEP 380: Syntax for Delegating to a

Re: A question I have...

2010-10-23 Thread Chris Rebert
On Thu, Oct 21, 2010 at 7:25 PM, Joe Shoulak joepshou...@yahoo.com wrote: I'm trying to make a sports simulation program and so far everything has worked until I try entering: Score1 = (Team1Off + Team2Def)/2 I get the error: TypeError: unsupported operand type(s) for /: 'str' and 'int'

Re: A Unique XML Parsing Problem

2010-10-23 Thread Chris Rebert
On Sat, Oct 23, 2010 at 4:40 PM, Devon dshur...@gmail.com wrote: I must quickly and efficiently parse some data contained in multiple XML files in order to perform some learning algorithms on the data. Info: I have thousands of files, each file corresponds to a single song. Each XML file

Re: Exception Handling in Python 3

2010-10-23 Thread Chris Rebert
On Sat, Oct 23, 2010 at 10:01 PM, Steve Holden st...@holdenweb.com wrote: I was somewhat surprised to discover that Python 3 no longer allows an exception to be raised in an except clause (or rather that it reports it as a separate exception that occurred during the handling of the first). snip

Re: embarrassing class question

2010-10-21 Thread Chris Rebert
On Thu, Oct 21, 2010 at 11:53 AM, Brendan brendandetra...@yahoo.com wrote: On Oct 21, 3:47 pm, Carl Banks pavlovevide...@gmail.com wrote: On Oct 21, 11:09 am, Brendan brendandetra...@yahoo.com wrote: Two modules: x.py: class x(object):     pass y.py: from x import x class y(x):  

Re: functions, list, default parameters

2010-10-21 Thread Chris Rebert
On Thu, Oct 21, 2010 at 2:36 PM, Sean Choi gne...@gmail.com wrote: I found two similar questions in the mailing list, but I didn't understand the explanations. I ran this code on Ubuntu 10.04 with Python 2.6.5. Why do the functions g and behave differently? If calls (3) and g(3) both

Re: how to scrutch a dict()

2010-10-20 Thread Chris Rebert
On Wed, Oct 20, 2010 at 9:40 PM, Paul Rubin no.em...@nospam.invalid wrote: Phlip phlip2...@gmail.com writes: def _scrunch(**dict):     result = {}     for key, value in dict.items():         if value is not None:  result[key] = value     return result That says throw away every item in a

Re: choose value from custom distribution

2010-10-19 Thread Chris Rebert
On Mon, Oct 18, 2010 at 11:40 PM, Arnaud Delobelle arno...@gmail.com wrote: elsa kerensael...@hotmail.com writes: Hello, I'm trying to find a way to collect a set of values from real data, and then sample values randomly from this data - so, the data I'm collecting becomes a kind of

Re: Unicode questions

2010-10-19 Thread Chris Rebert
On Tue, Oct 19, 2010 at 12:02 PM, Tobiah t...@rcsreg.com wrote: I've been reading about the Unicode today. I'm only vaguely understanding what it is and how it works. Petite Abeille already pointed to Joel's excellent primer on the subject; I can only second their endorsement of his article.

Re: Unicode questions

2010-10-19 Thread Chris Rebert
On Tue, Oct 19, 2010 at 1:31 PM, Tobiah t...@rcsreg.com wrote: There is no such thing as plain Unicode representation. The closest thing would be an abstract sequence of Unicode codepoints (ala Python's `unicode` type), but this is way too abstract to be used for sharing/interchange, because

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 8:58 AM, Andreas Waldenburger use...@geekmail.invalid wrote: On Mon, 18 Oct 2010 17:17:52 +0200 Christian Heimes li...@cheimes.de wrote: [snip] Don't nest classes. Just don't. This might be a valid and good approach in some programming languages but it's not Pythonic.

Re: How to get key values when iterating a mailbox?

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 8:42 AM, tinn...@isbd.co.uk wrote: I'm trying to delete some messages from a mailbox when they are older than a certain number of days. If I iterate through the mailbox and find a message that needs deleting how do I get its key so I can do remove(key)? The trouble

Re: tkMessageBox

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 11:32 AM, richard catbird.isl...@gmail.com wrote: When I do   import tkMessageBox  the Python Shell tells me that this does not exist.  Where do I find it? What OS are you using? How did you install Python? Can you `import Tkinter`? Cheers, Chris --

Re: Help with paths

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 2:24 PM, Devin M devin...@gmail.com wrote: Hello, I am using os.path to get the absolute paths of a few directories that some python files are in. FIlePath = os.path.dirname(os.path.realpath(__file__)) which returns a path similar to /home/devinm/project/files Now I

Re: Classes in a class: how to access variables from one in another

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 3:24 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: Also, Python's scoping rules, particularly for class-level scopes, don't work the way programmers from languages where nested classes are common

Re: Deferring a function call

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 9:21 PM, TomF tomf.sess...@gmail.com wrote: I'm writing a simple simulator, and I want to schedule an action to occur at a later time.  Basically, at some later point I want to call a function f(a, b, c).  But the values of a, b and c are determined at the current time.

Re: choose value from custom distribution

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 8:27 PM, elsa kerensael...@hotmail.com wrote: Hello, I'm trying to find a way to collect a set of values from real data, and then sample values randomly from this data - so, the data I'm collecting becomes a kind of probability distribution. For instance, I might have

Re: docstring that use globals?

2010-10-16 Thread Chris Rebert
On Sat, Oct 16, 2010 at 10:05 AM, kj no.em...@please.post wrote: In i9clfa$mk...@reader1.panix.com kj no.em...@please.post writes: MRAB, Peter: thanks for the decorator idea! As an afterthought, is there any way to extend this general idea to other docstrings beyond function docstrings? I

Re: GCC process not working as expected when called in Python (3.1.2) subprocess-shell, but OK otherwise

2010-10-14 Thread Chris Rebert
On Wed, Oct 13, 2010 at 7:06 PM, Kingsley Turner kingsley.tur...@openfieldcommunications.com wrote:  Hi, I'm using GCC as a pre-processor for a C-like language (EDDL) to handle all the includes, macros, etc. producing a single source file for another compiler.  My python code massages the

Re: Strong typing vs. strong testing

2010-10-13 Thread Chris Rebert
On Wed, Oct 13, 2010 at 12:31 AM, RG rnospa...@flownet.com wrote: snip This reminds me of back when I was a kid and my dad was trying to teach me basic physics.  He kept saying that the acceleration of gravity was 9.8 meters per second squared and I just couldn't wrap my brain around what it

Re: My first Python program

2010-10-13 Thread Chris Rebert
On Wed, Oct 13, 2010 at 9:56 AM, Seebs usenet-nos...@seebs.net wrote: On 2010-10-12, MRAB pyt...@mrabarnett.plus.com wrote: snip Line 51 The __init__ method should always return None. There's no need to be explicit about it, just use a plain return. The real issue here is that I was

Re: Hyperlink to a file using python

2010-10-13 Thread Chris Rebert
On Wed, Oct 13, 2010 at 1:57 PM, Pratik Khemka pratikkhe...@hotmail.com wrote: I want to create a hyperlink in my excel sheet using python such that when you click on that link (which is a file name (html file)), the file automatically opens. This file is present in the same folder in which the

Re: Hyperlink to a file using python

2010-10-13 Thread Chris Rebert
To: python-list@python.org From: em...@fenx.com Subject: Re: Hyperlink to a file using python Date: Wed, 13 Oct 2010 14:19:36 -0700 On 10/13/2010 1:57 PM Pratik Khemka said... I want to create a hyperlink in my excel sheet using python such that when you click on that link (which is a

Re: sending commands to the unix shell

2010-10-12 Thread Chris Rebert
On Mon, Oct 11, 2010 at 7:30 PM, Rodrick Brown rodrick.br...@gmail.com wrote: Trying to do something very trivial why is it failing It would have been helpful if you had specified in exactly what way(s) they were failing. I've tried three approaches     1. os.system(/bin/cat %s | /bin/mail -s

Re: My first Python program

2010-10-12 Thread Chris Rebert
On Tue, Oct 12, 2010 at 12:14 PM, Seebs usenet-nos...@seebs.net wrote: So, I'm new to Python, though I've got a bit of experience in a few other languages.  My overall impressions are pretty mixed, but overall positive; it's a reasonably expressive language which has a good mix between staying

Re: Reading after a symbol..

2010-10-12 Thread Chris Rebert
On Tue, Oct 12, 2010 at 1:48 PM, Pratik Khemka pratikkhe...@hotmail.com wrote: Say :  line = abcdabcd#12 adssda index = line.find('#') num = line[index:index+2] num will now be 12. No, num will be #1. You wanted: num = line[index+1:index+3] Likewise I want to read the number after the '#'

Re: logging.handlers.SMTPHandler and fileConfig

2010-10-11 Thread Chris Rebert
On Mon, Oct 11, 2010 at 7:52 AM, pstatham pstat...@sefas.com wrote: I'm trying to use pythons logging.handlers.SMTPHandler with a configuration file (so that I don't have to have passwords etc. inside of the script) Now the guide I'm following is [URL=http://docs.python.org/library/

Re: 2D List

2010-10-11 Thread Chris Rebert
On Mon, Oct 11, 2010 at 9:24 AM, Fasihul Kabir rrock...@yahoo.com wrote: a = [0]*5  for i in range(0, 4):     for j in range(0, i):         a[i].append(j) why the above codes show the following error. and how to overcome it. Traceback (most recent call last):   File pyshell#10, line 3, in

Re: emdding python gui in c code - OS independent

2010-10-11 Thread Chris Rebert
On Mon, Oct 11, 2010 at 6:16 AM, tinauser tinau...@libero.it wrote: hi there, i need to embed python GUI in a c++ code. I've seen that,while on windows running GUI is no problem, in mac i need to use pythonw instead python. the question is,how should i tell the program that if the OS is mac,

Re: Class-level variables - a scoping issue

2010-10-11 Thread Chris Rebert
On Mon, Oct 11, 2010 at 9:44 AM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Mon, 11 Oct 2010 10:43:04 -0400, John Posner jjpos...@optimum.net declaimed the following in gmane.comp.python.general: No surprising behavior, just a surprising look:    self.EGGS = ... ... which might

Re: How is correct use of eval()

2010-10-11 Thread Chris Rebert
On Mon, Oct 11, 2010 at 11:11 AM, Cata catalinf...@gmail.com wrote: Hi . I read about eval(). I also read about this bug : cod = raw_input ('Enter:) eval (cod) if i use  rm -rf ~  all files will be deleted . That's incorrect. eval() does not (directly) run shell commands. It does evaluate

Re: How is correct use of eval()

2010-10-11 Thread Chris Rebert
On Mon, Oct 11, 2010 at 5:26 PM, Nobody nob...@nowhere.com wrote: On Mon, 11 Oct 2010 11:18:37 -0700, Chris Rebert wrote: What is correct way to use this function? To not use it in the first place if at all possible (use int(), float(), getattr(), etc. instead, Use read(). Oh wait, Python

Re: UTF-8 problem encoding and decoding in Python3

2010-10-10 Thread Chris Rebert
On Sun, Oct 10, 2010 at 10:25 AM, hid...@gmail.com wrote: Hello everybody i am trying to encode a file string of an upload file and i am facing some problems with the first part of the file. When i open directly and try to decode the file the error is this: `UnicodeDecodeError: 'utf8' codec

Re: unicode problem?

2010-10-09 Thread Chris Rebert
On Sat, Oct 9, 2010 at 4:59 PM, Brian Blais bbl...@bryant.edu wrote: This may be a stemming from my complete ignorance of unicode, but when I do this (Python 2.6): s='\xc2\xa9 2008 \r\n' and I want the ascii version of it, ignoring any non-ascii chars, I thought I could do:

Re: question about a program

2010-10-08 Thread Chris Rebert
On Thu, Oct 7, 2010 at 5:39 PM, Logan Butler killable1...@gmail.com wrote: question about an assignment: places(home sweet home is here,' ') [4, 10, 15, 18] this is my code: def places(x, y):    return [x.index(y) for v in x if (v == y)] so far I'm only getting [4, 4, 4, 4] so the

Re: Unicode Decode Error

2010-10-08 Thread Chris Rebert
On Fri, Oct 8, 2010 at 2:31 PM, Pratik Khemka pratikkhe...@hotmail.com wrote: UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position 152: ordinal not in range(128). Can someone please help me with  this error The error occurs in line wbk.save(p4_merge.xls). I have used import 

Re: list parameter of a recursive function

2010-10-07 Thread Chris Rebert
On Wed, Oct 6, 2010 at 10:25 PM, TP tribulati...@paralleles.invalid wrote: Diez B. Roggisch wrote: Back to your example: your solution is perfectly fine, although a bit costly and more error-prone if you happen to forget to create a copy. A safer alternative for these cases is using tuples,

<    5   6   7   8   9   10   11   12   13   14   >