Re: Sanitising arguments to shell commands (was: Waiting for a subprocess to exit)

2009-08-21 Thread Chris Rebert
On Fri, Aug 21, 2009 at 2:08 AM, Ben Finneyben+pyt...@benfinney.id.au wrote: snip How can I take a string that is intended to be part of a command line, representing multiple arguments and the shell's own escape characters as in the above example, and end up with a sane command argument list

Re: Sanitising arguments to shell commands

2009-08-21 Thread Chris Rebert
On Fri, Aug 21, 2009 at 3:55 PM, Ben Finneyben+pyt...@benfinney.id.au wrote: Rick King rickbk...@comcast.net writes: shlex doesn't handle unicode input though, so, in general, it's not a good solution. Argh. Is there a Python bug tracker number for fixing that? Indeed there is:

Re: line completion

2009-08-22 Thread Chris Rebert
On Thu, Aug 20, 2009 at 9:06 AM, Steven Woodynarkewo...@gmail.com wrote: Hi, I wrote a program that takes some user input.  Many inputs are quit often used by user, so when a user launch the program, and type in The Sha,  he wants to get wshank Redemption displayed automatically in reversed

Re: conditional for-statement

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 1:36 PM, sebsdemen...@gmail.com wrote: On Aug 23, 6:18 pm, John Posner jjpos...@optimum.net wrote: Hi, i was wondering if there is a syntax alike: for i in range(10) if i 5:     print i You can write for i in filter(lambda i: i 5, range(10)):     print

Re: What is the recommended library for xml parsing?

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 3:07 PM, Raimond Garciavoodoorai2...@gmail.com wrote: Is there a good build in library or should I use a third party one? xml.etree.ElementTree: http://docs.python.org/library/xml.etree.elementtree.html Cheers, Chris -- http://blog.rebertia.com --

Re: Newbie: list comprehension troubles..

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 4:27 PM, mmmatta...@gmail.com wrote: Hi, I'm trying to replace this...        # this works but there must be a more pythonic way, right?        tlist = []        for obj in self.objs:            t = obj.intersect(ray)            if (t != None):                

Re: Newbie: list comprehension troubles..

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 5:09 PM, Ben Finneyben+pyt...@benfinney.id.au wrote: Chris Rebert c...@rebertia.com writes: tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in self.objs) if pair[1] is not None] Should it be done? Probably not. [Compared to a ‘for’ suite

Re: os.popen output different from native shell output

2009-08-25 Thread Chris Rebert
On Tue, Aug 25, 2009 at 1:36 AM, nicknamethebiggestbangthe...@gmail.com wrote: Hi all,       I am a relative newbie to python, I am using os.popen to run an ls command. The output that I get using the read() function is different in look and feel from when I run the ls command natively from

Re: Division and right shift in python

2009-08-25 Thread Chris Rebert
On Tue, Aug 25, 2009 at 8:40 PM, Mark Tolonenmetolone+gm...@gmail.com wrote: Cevahir Demirkiran cevo...@gmail.com wrote in message news:3f74e020908251648k7b391a09g78b155507b2f2...@mail.gmail.com... Hi, I would like to do a floor division by a power of 2 in python to make it faster than /

Re: Move dictionary from instance to class level

2009-08-26 Thread Chris Rebert
On Wed, Aug 26, 2009 at 1:22 AM, Frank Millmanfr...@chagford.com wrote: Hi all I have a class that uses a dictionary to map message numbers to methods. Here is a simple example -    class MyClass(object):        def __init__(self):            self.method_dict = {}            

Re: codecs.open on Win32 -- converting my newlines to CR+LF

2009-08-27 Thread Chris Rebert
On Wed, Aug 26, 2009 at 11:06 PM, Chris Rebertc...@rebertia.com wrote: On Wed, Aug 26, 2009 at 8:40 PM, Ryan McGuireuse...@enigmacurry.com wrote: On Aug 26, 11:04 pm, Philip Semanchuk phi...@semanchuk.com wrote: Try using rb instead of r for the mode in the call to open(). HTH Philip That

Re: codecs.open on Win32 -- converting my newlines to CR+LF

2009-08-27 Thread Chris Rebert
On Wed, Aug 26, 2009 at 8:40 PM, Ryan McGuireuse...@enigmacurry.com wrote: On Aug 26, 11:04 pm, Philip Semanchuk phi...@semanchuk.com wrote: Try using rb instead of r for the mode in the call to open(). HTH Philip That does indeed fix the problem, thanks! Still seems like the docs are

Re: Python Telnet client

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 2:06 PM, Darvinnbdar...@gmail.com wrote: Is there telnet client in python? i want to write NetHack telnet GUI app) http://docs.python.org/library/telnetlib.html Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: variables of the class are not available as default values?

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 2:37 PM, seanacaiskccnos...@glenevin.com wrote: I'm working on a program where I wish to define the default value of a method as a value that was set in __init__.  I get a compilation error saying that self is undefined. As always a code snippet helps :-) class foo:

Re: How to unencode a string

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 2:10 PM, jakecjacobsonjakecjacob...@gmail.com wrote: This seems like a real simple newbie question but how can a person unencode a string?  In Perl I use something like: $part=~ s/\%([A-Fa- f0-9]{2})/pack('C', hex($1))/seg; If I have a string like Word1%20Word2%20Word3

Re: Algorithms as objects?

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 4:05 PM, Kresokkumnotthi...@thatsearchenginesguglsemail.com wrote: I am writing an application that essentially calculates set of numbers, say N1, N2, ..., where they can be calculated by several different algorithms. (One should be able to choose the algorithm at run

Re: why python got less developers ?

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 5:34 PM, Deep_Feelingsdoctore...@gmail.com wrote: python got relatively fewer numbers of developers than other high level languages like .NET , java .. etc  why ? We lack Sun and Microsoft's massive marketing departments. :) Cheers, Chris -- http://blog.rebertia.com --

Re: Colors on IDLE

2009-08-28 Thread Chris Rebert
On Fri, Aug 28, 2009 at 12:00 PM, vsolervicente.so...@gmail.com wrote: On Aug 28, 8:58 pm, vsoler vicente.so...@gmail.com wrote: Everything that I see in IDLE is in black. I have tried to add colors, without success. I've tried:  /Options/Configure IDLE/Highlighting/IDLE Classic Couldn't

Re: copy construtor question

2009-08-28 Thread Chris Rebert
On Fri, Aug 28, 2009 at 11:38 AM, xiaosong xiaxiaosong...@yahoo.com wrote: Hi all, I am trying to define a class with copy constructor as following: class test: def __init__(self, s=None):   self=s Python uses call-by-object (http://effbot.org/zone/call-by-object.htm), so

Re: How i follow tree folders from url

2009-08-30 Thread Chris Rebert
On Sun, Aug 30, 2009 at 1:20 AM, catalinf...@gmail.comcatalinf...@gmail.com wrote: Hello ! I wanna use python to follow the tree folders from one url. Example : If url is www.site.com/first/ and first is first folder with next subfolders 01,02,03 The result of script should be :

Re: a popen question. Please help

2009-08-30 Thread Chris Rebert
On Sun, Aug 30, 2009 at 4:43 AM, Tim Chasepython.l...@tim.thechases.com wrote: texts = os.popen('top').readlines() print texts It calls the command line top and will print out some texts. But first I have to press the keyboard q to quit the subprocess top, then the texts will be printed,

Re: Popen question (redundant processes)

2009-08-30 Thread Chris Rebert
On Sun, Aug 30, 2009 at 12:33 PM, Sebastianseb...@gmail.com wrote: Hello World! This is my first post on the list and I'm hoping it is the right forum and not OT, I've searched a bit on this, but, none-the-wiser! My question is on the Popen method, here is my snippet: p1 = Popen([cat,

Re: map

2009-08-30 Thread Chris Rebert
On Sun, Aug 30, 2009 at 9:55 PM, elsakerensael...@hotmail.com wrote: Hi, i have a question about the built in map function. Here 'tis: say I have a list, myList. Now say I have a function with more than one argument: myFunc(a, b='None') now, say I want to map myFunc onto myList, with

Re: lambda functions

2009-08-31 Thread Chris Rebert
On Mon, Aug 31, 2009 at 12:41 AM, Pierrepierre.gaill...@gmail.com wrote: Hello, I would like to know if it is possible to define a loop in a lambda function Not possible. Lambdas can only contain a single expression. A loop is a block statement. Just use a named function instead. There's

Re: exec globals and locals

2009-09-02 Thread Chris Rebert
On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampinquentin.lam...@gmail.com wrote: Hi, Being fairly new to Python, I'm trying to figure out the best way to use the exec statement and I must admit that I am a bit lost. Consider this case: exec print 'a' in {},{}   [exp.1] It means  that I'm

Re: exec globals and locals

2009-09-02 Thread Chris Rebert
On Wed, Sep 2, 2009 at 1:13 PM, Quentin Lampinquentin.lam...@gmail.com wrote: 2009/9/2 Chris Rebert c...@rebertia.com On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampinquentin.lam...@gmail.com wrote: Hi, Being fairly new to Python, I'm trying to figure out the best way to use the exec

Re: match braces?

2009-09-03 Thread Chris Rebert
On Thu, Sep 3, 2009 at 2:38 AM, lallouslall...@lgwm.org wrote: Hello In C/C++ you use the braces where as in Python you use the indentation levels. Most editors offer a Ctrl+[ to match the braces so that you can easily identify the scopes (more correctly statements blocks). I am finding it

Re: Modifying a textfile

2009-09-03 Thread Chris Rebert
On Thu, Sep 3, 2009 at 3:21 AM, Olli Virtallvi...@gmail.com wrote: Hi! So I got this big textfile. It's full of data from a database. About 150 or more rows or lines in a textfile. There's three first rows that belong to the same subject. And then next three rows belong to another subject

Re: Running Sum script

2009-09-04 Thread Chris Rebert
On Fri, Sep 4, 2009 at 1:49 PM, juli.dolzhe...@gmail.com wrote: On Sep 4, 4:37 pm, Maggie la.f...@gmail.com wrote: On Sep 4, 4:37 pm, Tobiah t...@tobiah.org wrote: in the terminal i get a very strange permission denied error that might not have anything to do with the code. I checked

Re: How to download directly to a file?

2009-09-04 Thread Chris Rebert
On Fri, Sep 4, 2009 at 4:35 PM, kjno.em...@please.post wrote: In 7gdgslf2ogf8...@mid.uni-berlin.de Diez B. Roggisch de...@nospam.web.de writes: kj schrieb: I want to send a POST request and have the returned content put directly into a file.  Is there a way to do this easily in Python? I've

Re: File Handling Problem

2009-09-05 Thread Chris Rebert
On Fri, Sep 4, 2009 at 11:39 PM, SUBHABRATA BANERJEEsubhakolkata1...@gmail.com wrote: snip And one small question does Python has any increment operator like ++ in C. No. We do x += 1 instead. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Formatted input function

2009-09-05 Thread Chris Rebert
On Sat, Sep 5, 2009 at 3:13 AM, candidecand...@free.invalid wrote: I have a text file and the first line provides the best score of a game. This line has  the following format : Best score : 42 In order to update the score, I try to retrieve the score value. In C, we would manage this with

Re: Formatted input function

2009-09-05 Thread Chris Rebert
On Sat, Sep 5, 2009 at 8:00 AM, Terry Reedytjre...@udel.edu wrote: Chris Rebert wrote: On Sat, Sep 5, 2009 at 3:13 AM, candidecand...@free.invalid wrote: I have a text file and the first line provides the best score of a game. This line has  the following format : Best score : 42

Re: run-time inclusion of files

2009-09-05 Thread Chris Rebert
On Sat, Sep 5, 2009 at 3:23 PM, travis+ml-pyt...@subspacefield.org wrote: Hello, I was wondering if there was something like Perl's require that allows you to import a file whose name is specified at run-time.  So far I've only seen imports of modules that are put in the standard module

Re: beginner's python help

2009-09-06 Thread Chris Rebert
On Sun, Sep 6, 2009 at 12:00 AM, Maggiela.f...@gmail.com wrote: code practice: test = open (test.txt, r) readData = test.readlines() #set up a sum sum = 0; for item in readData:        sum += int(item) print sum A slightly better way to write this: test = open(test.txt, r) #set up a sum

Re: beginner's python help

2009-09-06 Thread Chris Rebert
On Sun, Sep 6, 2009 at 12:46 AM, hrishyhris...@yahoo.co.uk wrote: Hi Chris What if i want to log that bad data and continue processing is there a way to do that ? Tighten the area included in the try...except: sum = 0 for item in readData: try: sum += int(item) except

Re: beginner's python help

2009-09-06 Thread Chris Rebert
On Sun, Sep 6, 2009 at 12:54 AM, hrishyhris...@yahoo.co.uk wrote: Hi sum = 0  for item in readData:     try:         sum += int(item)     except ValueError:         print Oops!  That was no valid number. Instead it was:, item So you mean to say this would ignore the bad data and continue

Re: beginner's python help

2009-09-06 Thread Chris Rebert
On Sun, Sep 6, 2009 at 1:10 AM, Maggiela.f...@gmail.com wrote: On Sep 6, 3:58 am, Chris Rebert c...@rebertia.com wrote: On Sun, Sep 6, 2009 at 12:54 AM, hrishyhris...@yahoo.co.uk wrote: Hi sum = 0  for item in readData:     try:         sum += int(item)     except ValueError

Re: beginner's python help

2009-09-06 Thread Chris Rebert
On Sun, Sep 6, 2009 at 1:28 AM, Maggiela.f...@gmail.com wrote: On Sep 6, 4:19 am, Chris Rebert c...@rebertia.com wrote: On Sun, Sep 6, 2009 at 1:10 AM, Maggiela.f...@gmail.com wrote: On Sep 6, 3:58 am, Chris Rebert c...@rebertia.com wrote: On Sun, Sep 6, 2009 at 12:54 AM, hrishyhris

Re: simple string question

2009-09-07 Thread Chris Rebert
On Sun, Sep 6, 2009 at 10:29 PM, jwitherjwit...@sxder4kmju.com wrote: Given a string (read from a file) which contains raw escape sequences, (specifically, slash n), what is the best way to convert that to a parsed string, where the escape sequence has been replaced (specifically, by a NEWLINE

Re: zip a huge file into multiple small ones

2009-09-07 Thread Chris Rebert
On Mon, Sep 7, 2009 at 4:57 AM, Chris Withersch...@simplistix.co.uk wrote: krishna chaitanya wrote: I am new to dealing with zip files in python. I have a huge file which i need to zip and send as an attachment through email. My email restrictions are not allowing me to send it in one go.

Re: Class variable inheritance

2009-09-07 Thread Chris Rebert
On Mon, Sep 7, 2009 at 7:21 PM, Henry 'Pi' Jameshenrypija...@gmail.com wrote: I've just found out that a subclass shares the class variables of its superclass until it's instantiated for the first time, but not any more afterwards: Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32

Re: zip a huge file into multiple small ones

2009-09-08 Thread Chris Rebert
On Mon, Sep 7, 2009 at 5:31 PM, Chris Rebert c...@rebertia.com wrote: On Mon, Sep 7, 2009 at 4:57 AM, Chris Withersch...@simplistix.co.uk wrote: krishna chaitanya wrote: I am new to dealing with zip files in python. I have a huge file which i need to zip and send as an attachment

Re: Class variable inheritance

2009-09-09 Thread Chris Rebert
On Tue, Sep 8, 2009 at 11:30 PM, Steven D'Apranoste...@remove.this.cybersource.com.au wrote: snip Out of curiosity, are there languages where inheritance means copy? I think some prototype-based ones handle it that way... Cheers, Chris -- http://blog.rebertia.com --

Re: lxml question

2009-09-09 Thread Chris Rebert
On Wed, Sep 9, 2009 at 4:11 PM, mattiager...@gmail.com wrote: I would like to click on an image in a web page that I retrieve using urllib in order to trigger an event. Here is the piece of code with the image that I want to click: input type=image style=border-width: 0px; height: 22px; width:

Re: s.index(x[, i[, j]]) will change the s ?

2009-09-09 Thread Chris Rebert
On Wed, Sep 9, 2009 at 9:00 PM, s7v7nislandss7v7nisla...@gmail.com wrote: hi all:    what is the s.index() mean? does the index() change the s? It tells you the index of the first instance of the given element in the sequence. Or, to quote the docs: s.index(x[, i[, j]]) --- return smallest

Re: s.index(x[, i[, j]]) will change the s ?

2009-09-09 Thread Chris Rebert
On Wed, Sep 9, 2009 at 10:00 PM, s7v7nislandss7v7nisla...@gmail.com wrote: snip? I known index() does not modify the sequence itself. my question is so why the doc put the index() method in the mutable sequence types list? Ah, okay. Now I understand your question. I don't know really. I suppose

Re: Does python 3.1 support sybase module?

2009-09-09 Thread Chris Rebert
On Wed, Sep 9, 2009 at 10:21 PM, Pravinpravinchavan2...@gmail.com wrote: Does python 3.1 support sybase module? It works fine with 2.5. I was getting following error while installing sybase module on python 3.1. bash-3.00$ python3.1 setup.py install  File setup.py, line 248    

Re: How to create an array which can be used also as a dictionary

2009-09-10 Thread Chris Rebert
On Thu, Sep 10, 2009 at 12:51 PM, Hans Müller heint...@web.de wrote: Diez B. Roggisch wrote: Hans Müller wrote: snip But what happens if i modify a[1].value1 = 1000 is d[aax].value1 now 1000 or still hello as in this example ? It's changed. Didn't you try that? to be true, no - not in

Re: Why can't I run this test class?

2009-09-11 Thread Chris Rebert
On Fri, Sep 11, 2009 at 12:30 AM, Kermit Mei kermit@gmail.com wrote: Dear all,    I'm a newbie for python, and I write a program to test how to implement a class: #!/usr/bin/env python class Test:    'My Test class'    def __init__(self):        self.arg1 = 1    def first(self):  

Re: Why can't I run this test class?

2009-09-11 Thread Chris Rebert
On Fri, Sep 11, 2009 at 12:40 AM, Kermit Mei kermit@gmail.com wrote: On Fri, 2009-09-11 at 00:33 -0700, Chris Rebert wrote: On Fri, Sep 11, 2009 at 12:30 AM, Kermit Mei kermit@gmail.com wrote: Dear all,    I'm a newbie for python, and I write a program to test how to implement

Re: How can I use my modules here?

2009-09-11 Thread Chris Rebert
On Fri, Sep 11, 2009 at 2:24 AM, Kermit Mei kermit@gmail.com wrote: Hello community! I write a modules for testing, and my code is like this(under Linux): $ tree . |-- MyTestModules |   |-- Test1.py |   |-- Test2.py |   `-- __init__.py `-- main.py 1 directory, 4 files $ find .

Re: Podcast catcher in Python

2009-09-11 Thread Chris Rebert
On Fri, Sep 11, 2009 at 11:09 AM, Chuck galois...@gmail.com wrote: On Sep 11, 12:56 pm, Chuck galois...@gmail.com wrote: On Sep 11, 10:30 am, Falcolas garri...@gmail.com wrote: On Sep 11, 8:20 am, Chuck galois...@gmail.com wrote: Hi all, I would like to code a simple podcast catcher in

Re: list as an instance attribute

2009-09-12 Thread Chris Rebert
Cheers, Chris -- http://blog.rebertia.com On Sat, Sep 12, 2009 at 8:22 PM, André andre.robe...@gmail.com wrote: On Sep 12, 11:48 pm, Daniel Luis dos Santos daniel.d...@gmail.com wrote: Hello, I have an object definition : class primitive:         def __init__(self)                

Re: How to define a function with an empty body?

2009-09-12 Thread Chris Rebert
On Sat, Sep 12, 2009 at 8:37 PM, Peng Yu pengyu...@gmail.com wrote: Hi, I want to define a function without anything in it body. In C++, I can do something like the following because I can use {} to denote an empty function body. Since python use indentation, I am not sure how to do it. Can

Re: Declaring array of Variables ?

2009-09-12 Thread Chris Rebert
On Sat, Sep 12, 2009 at 9:51 PM, Lennyboi leonidas01@gmail.com wrote: Can I declare an array of variables in python like in C int p[10]; I looked everywhere, but I don't find any mention of it. Python doesn't have C-like variable declarations, and it does not have arrays of static

Re: Odd/Weird errors with FTPLib

2009-09-13 Thread Chris Rebert
On Sun, Sep 13, 2009 at 2:34 PM, Bakes ba...@ymail.com wrote: I am using a simple python script to download my logfiles. This is on a while loop, the logfile grows rapidly, so it is necessary for python to start downloading the new script as soon as it has finished the old. It works fine

Re: Why indentation is use to denote block of code?

2009-09-13 Thread Chris Rebert
On Sun, Sep 13, 2009 at 3:12 PM, Peng Yu pengyu...@gmail.com wrote: Hi, I want to understand why python use indentation to denote block of code. What are the advantages of it? See the FAQ: http://www.python.org/doc/faq/general/#why-does-python-use-indentation-for-grouping-of-statements Is

Re: Commutative object in emulating numbers

2009-09-13 Thread Chris Rebert
On Sun, Sep 13, 2009 at 9:52 PM, iu2 isra...@elbit.co.il wrote: Hi, I reached the chapter Emulating numeric types in the python documentation and I tried this: class A:        def __mul__(self, a):                return 'A' * a Now, this works as expected: a = A() a * 3 'AAA' But

Re: Remove empty strings from list

2009-09-14 Thread Chris Rebert
On Mon, Sep 14, 2009 at 6:49 PM, Helvin helvin...@gmail.com wrote: Hi, Sorry I did not want to bother the group, but I really do not understand this seeming trivial problem. I am reading from a textfile, where each line has 2 values, with spaces before and between the values. I would like

Re: unpacking vars from list of tuples

2009-09-15 Thread Chris Rebert
On Tue, Sep 15, 2009 at 2:51 PM, Ross ros...@gmail.com wrote: I'm inexperienced with some of the fancy list slicing syntaxes where python shines. If I have a list of tuples:   k=[(a, bob, c), (p, joe, d), (x, mary, z)] and I want to pull the middle element out of each tuple to make a new

Re: subprocess woes

2009-09-15 Thread Chris Rebert
On Tue, Sep 15, 2009 at 12:26 PM, kj no.em...@please.post wrote: I'm trying to write a function, sort_data, that takes as argument the path to a file, and sorts it in place, leaving the last sentinel line in its original position (i.e. at the end).  Here's what I have (omitting most

Re: Retrieve url's of all jpegs at a web page URL

2009-09-15 Thread Chris Rebert
On Tue, Sep 15, 2009 at 7:28 AM, grimmus graham.col...@gmail.com wrote: Hi, I would like to achieve something like Facebook has when you post a link. It shows images located at the URL you entered so you can choose what one to display as a summary. I was thinking i could loop through the

Re: Converting a script to Python 3 - having trouble.

2009-09-15 Thread Chris Rebert
On Tue, Sep 15, 2009 at 4:01 PM, Russell Jackson ru...@rcjacksonconsulting.com wrote: snip Attempted code in Python 3: (Doesn't work either) snip         cmd = ' passwd {0}'.format(user)         pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)

Re: Converting a script to Python 3 - having trouble.

2009-09-15 Thread Chris Rebert
On Tue, Sep 15, 2009 at 5:07 PM, Chris Rebert c...@rebertia.com wrote: On Tue, Sep 15, 2009 at 4:01 PM, Russell Jackson ru...@rcjacksonconsulting.com wrote: snip Attempted code in Python 3: (Doesn't work either) snip         cmd = ' passwd {0}'.format(user)         pipe = Popen(p4 + cmd

Re: Fwd: Converting a script to Python 3 - having trouble.

2009-09-15 Thread Chris Rebert
On Tue, Sep 15, 2009 at 4:58 PM, Russell Jackson ru...@rcjacksonconsulting.com wrote: I just get an errorlevel from the executable when I read stdout, but I can't tell what is going on because, of course, I can't tell what Popen is actually doing. I never see the prompt from the executable that

Re: python 3.1 unicode question

2009-09-15 Thread Chris Rebert
On Tue, Sep 15, 2009 at 9:48 PM, jeffunit j...@jeffunit.com wrote: At 09:25 PM 9/15/2009, Mark Tolonen wrote: jeffunit j...@jeffunit.com wrote in message news:20090915144123964.ljka6...@cdptpa-omta01.mail.rr.com... I wrote a program that diffs files and prints out matching file names. I

Re: Shebang line problems and python

2009-09-16 Thread Chris Rebert
On Wed, Sep 16, 2009 at 8:25 PM, Blaine brlafreni...@gmail.com wrote: Hello, Scripts that have #!/usr/bin/python at the top do not parse correctly. Bash treats scripts with that shebang as if they are bash scripts. E.g.: bla...@attila ~/apps/rs-mu $ /usr/sbin/env-update

Re: Redirect output on script

2009-09-17 Thread Chris Rebert
On Thu, Sep 17, 2009 at 3:58 AM, glenn.prin...@gmail.com glenn.prin...@gmail.com wrote: I would like to redirect the output of the command below to another file type test.txt test.bak I'm trying to do this as part of a python script running on Windows XP. I'm using os.system('type

Re: elif alternative

2009-09-17 Thread Chris Rebert
On Thu, Sep 17, 2009 at 12:38 PM, gert gert.cuyk...@gmail.com wrote: Can anybody show me a better looking alternative for this elif structure ? Use a dictionary with functions as values. For example: #untested obviously def admin_remove(db, v, gid): db.execute(DELETE FROM appointments

Re: elif alternative

2009-09-17 Thread Chris Rebert
On Thu, Sep 17, 2009 at 3:09 PM, gert gert.cuyk...@gmail.com wrote: On Sep 17, 9:48 pm, Chris Rebert c...@rebertia.com wrote: On Thu, Sep 17, 2009 at 12:38 PM, gert gert.cuyk...@gmail.com wrote: Can anybody show me a better looking alternative for this elif structure ? Use a dictionary

Re: Podcast catcher in Python

2009-09-18 Thread Chris Rebert
On Fri, Sep 18, 2009 at 7:34 PM, Chuck galois...@gmail.com wrote: snip I am using Python 3.1, but I can't figure out why I can't use xml.dom.minidom.  Here is my code: from xml.dom.minidom import parse, parseString url = 'http://minnesota.publicradio.org/tools/podcasts/ grammar_grater.xml'  

Re: Where are python module installed?

2009-09-20 Thread Chris Rebert
On Sun, Sep 20, 2009 at 6:30 PM, Peng Yu pengyu...@gmail.com wrote: Hi, I configured python-2.6.2 with my own --prefix, then 'make' and 'make install'. I only find the following dirs and I don't find any python modules in the directory. Do python modules come with python-2.6.2? $ ls bin  

Re: Searching a large dictionary

2009-09-22 Thread Chris Rebert
On Tue, Sep 22, 2009 at 2:50 PM, Support Desk support.desk@gmail.com wrote: I need help searching a large python dictionary. The dictionary is setup like so Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]

Re: Searching a large dictionary

2009-09-22 Thread Chris Rebert
On Tue, Sep 22, 2009 at 5:22 PM, Chris Rebert c...@rebertia.com wrote: On Tue, Sep 22, 2009 at 2:50 PM, Support Desk support.desk@gmail.com wrote: I need help searching a large python dictionary. The dictionary is setup like so Key[{'item':value,'item2':value,'item3':value,'item4

Re: Searching a large dictionary

2009-09-22 Thread Chris Rebert
-Original Message- From: Chris Rebert c...@rebertia.com Sent: Tuesday, September 22, 2009 5:35 PM To: Support Desk support.desk@gmail.com Cc: python-list@python.org Subject: Re: Searching a large dictionary On Tue, Sep 22, 2009 at 5:22 PM, Chris Rebert c...@rebertia.com wrote

Re: delete items from list by indices

2009-09-23 Thread Chris Rebert
On Wed, Sep 23, 2009 at 1:25 AM, blumenkraft vohs...@gmail.com wrote: Hi, I have some list: x = [8, 9, 1, 7] and list of indices I want to delete from x: indices_to_delete = [0, 3], so after deletion x must be equal to [9, 1]. What is the fastest way to do this? Is there any builtin?

Re: Single line output, updating output in place

2009-09-23 Thread Chris Rebert
On Wed, Sep 23, 2009 at 9:11 PM, Donavan Lance tusklah...@gmail.com wrote: Hello, I'm a newb and have been playing with Python trying to print a changing value to the screen that updates as the value changes. I have this code, which is pretty much doing what I want: #!/usr/bin/env python3

Re: super() and multiple inheritance failure

2009-09-26 Thread Chris Rebert
On Fri, Sep 25, 2009 at 9:30 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Fri, 25 Sep 2009 20:15:54 -0700, Chris Rebert wrote: Inside MyClass().method(n), I dispatch to either NClass.method() or PClass.method() depending on the value of the argument n. The correct class

Re: unexplainable python

2009-09-26 Thread Chris Rebert
On Sat, Sep 26, 2009 at 7:37 PM, dads wayne.dads.b...@gmail.com wrote: When creating a script that converts digits to words I've come across some unexplainable python. The script works fine until I use a 5 digit number and get a 'IndexError: string index out of range'. Please provide the full

Re: Bash shell to Python shell?

2009-09-27 Thread Chris Rebert
On Sun, Sep 27, 2009 at 8:13 PM, edwithad edwit...@hotmail.com wrote: I am sure you have not read a question this basic in some time, but I am curious. Using Linux I open a terminal window and type: python. Does Bash Shell go away and to become a Python Shell, or is it still a Bash Shell with

Re: UnboundLocalError - (code is short simple)

2009-09-27 Thread Chris Rebert
On Sun, Sep 27, 2009 at 8:53 PM, pylearner for_pyt...@yahoo.com wrote: snip --- Traceback (most recent call last):  File pyshell#2, line 1, in module    toss_winner()  File C:/Python26/toss_winner.py, line 7, in toss_winner    

Re: Global array in python

2009-09-28 Thread Chris Rebert
On Mon, Sep 28, 2009 at 5:48 PM, Rudolf yellowblueyel...@gmail.com wrote: How can i declare a global array in python? Python has no concept of declarations. And it doesn't have arrays, it has dynamically-resizing lists. Some examples: one_empty_list = [] a_list_of 5 zeroes = [0]*5 Might I

Re: Global array in python

2009-09-29 Thread Chris Rebert
On Mon, Sep 28, 2009 at 6:55 PM, rantingrick rantingr...@gmail.com wrote: On Sep 28, 8:04 pm, Chris Rebert c...@rebertia.com wrote: On Mon, Sep 28, 2009 at 5:48 PM, Rudolf yellowblueyel...@gmail.com wrote: How can i declare a global array in python? Python has no concept of declarations

Re: os.listdir unwanted behaviour

2009-09-29 Thread Chris Rebert
On Mon, Sep 28, 2009 at 11:03 PM, Chris Adamson chris.adam...@mcri.edu.au wrote: Hello, I am writing code that cycles through files in a directory and for each file it writes out another file with info in it. It appears that as I am iterating through the list returned by os.listdir it is

Re: UnboundLocalError with extra code after return

2009-09-29 Thread Chris Rebert
On Tue, Sep 29, 2009 at 9:15 PM, Rich Healey healey.r...@gmail.com wrote: However: def callonce(func):    def nullmethod(): pass    def __():        return func()        func = nullmethod When Python sees this assignment to func as it compiles the __() method, it marks func as a local

Re: UnboundLocalError with extra code after return

2009-09-29 Thread Chris Rebert
On Tue, Sep 29, 2009 at 9:41 PM, Chris Rebert c...@rebertia.com wrote: On Tue, Sep 29, 2009 at 9:15 PM, Rich Healey healey.r...@gmail.com wrote: However: def callonce(func):    def nullmethod(): pass    def __():        return func()        func = nullmethod Additionally, to rebind

Re: Enormous Input and Output Test

2009-10-03 Thread Chris Rebert
On Sat, Oct 3, 2009 at 6:54 AM, n00m n...@narod.ru wrote: Hi, py.folk! I need your help to understand how http://www.spoj.pl/problems/INOUTEST/ can be passed in Python. snip def foo():    ##sys.stdin = open('D:/1583.txt', 'rt')    a = sys.stdin.readlines() That line is probably a Very Bad

Re: Identify runs in list

2009-10-03 Thread Chris Rebert
On Sat, Oct 3, 2009 at 7:21 PM, skorpi...@gmail.com skorpi...@gmail.com wrote: Hi all, I have a data structure in a list as in: [0 0 0 3 0 5 0 0 0 0 1 0 4 0 5 0 0 7 0 0 0 0 0 12 0 0 4] I would like to extract three list from this data: 1) runsOfZero: [3 4 5] 2) runsOfNonZero: [3 8 4] 3)

Re: Identify runs in list

2009-10-03 Thread Chris Rebert
On Sat, Oct 3, 2009 at 7:53 PM, skorpi...@gmail.com skorpi...@gmail.com wrote: On Oct 3, 10:36 pm, Chris Rebert c...@rebertia.com wrote: snip Since this sounds like homework, I won't give actual code, but here's a gameplan: 1. Split the list into sublists based on where the runs of zeros stop

Re: defaults for function arguments bound only once(??)

2009-10-04 Thread Chris Rebert
On Sat, Oct 3, 2009 at 11:29 PM, horos11 horo...@gmail.com wrote: All, Another one, this time a bit shorter. It looks like defaults for arguments are only bound once, and every subsequent call reuses the first reference created. Hence the following will print '[10,2]' instead of the

Re: Delete all list entries of length unknown

2009-10-04 Thread Chris Rebert
On Sun, Oct 4, 2009 at 8:09 PM, flebber flebber.c...@gmail.com wrote: Hi Can someone clear up how I can remove all entries of a list when I am unsure how many entries there will be. I have been using sandbox to play essentially I am creating two lists a and b I then want to add a to b and

Re: 'Once' properties.

2009-10-05 Thread Chris Rebert
On Mon, Oct 5, 2009 at 7:56 PM, menomnon p...@well.com wrote: Does python have a ‘once’ (per class) feature? In Python, `class` is an executable statement, so you can put whatever code you want in the class body (along with your method definitions) and it will be run exactly once, at the time

Re: Creating class instance from module and class name

2009-10-06 Thread Chris Rebert
On Tue, Oct 6, 2009 at 12:09 AM, gentlestone tibor.b...@hotmail.com wrote: On 6. Okt, 08:55 h., Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Mon, 05 Oct 2009 23:32:27 -0700, gentlestone wrote: Suppose I've saved the class name and (don't know how) I've also saved the

Re: Multi-arrays python

2009-10-08 Thread Chris Rebert
On Wed, Oct 7, 2009 at 10:21 AM, bbarb...@inescporto.pt wrote: Hi again! After testing the whole day, I have got my goals from the last email, but as always, another issues came up! and now that Ive been able to save a list of list (or multi-arrays) as below : ['100.mp3\n' '10008.mp3\n'

Re: How to find number of line that is currently executing?

2009-10-09 Thread Chris Rebert
On Fri, Oct 9, 2009 at 8:46 PM, Dr. Phillip M. Feldman pfeld...@verizon.net wrote: I would like to put a statement on line N of my program that prints the line number that is currently executing. This may sound fairly trivial, but I don't want to hard code the line number because N will change

Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-12 Thread Chris Rebert
On Mon, Oct 12, 2009 at 4:27 AM, Piet van Oostrum p...@cs.uu.nl wrote: greg g...@cosc.canterbury.ac.nz (g) wrote: g MRAB wrote: And when someone says January 30, do they really mean the day before the last day of the month? g No, no, that's January -2, a *completely* different thing! But

Re: What is the correct way to define __hash__?

2009-10-12 Thread Chris Rebert
On Mon, Oct 12, 2009 at 7:04 PM, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Mon, 12 Oct 2009 15:45:30 -0500, Peng Yu wrote:   def __cmp__(self, other):     if self._a other._a:       return -1     elif self._a other._a:       return 1     elif self._b other._b:    

Re: id( ) function question

2009-10-14 Thread Chris Rebert
On Wed, Oct 14, 2009 at 1:37 PM, Laszlo Nagy gand...@shopzeus.com wrote: Andre Engels schrieb: What is going on is that a few objects that are often used, in particular the small (how small is small depends on the implementation) integers, are 'preloaded'. When one of these is then referred

Re: () vs. [] operator

2009-10-15 Thread Chris Rebert
On Thu, Oct 15, 2009 at 12:14 AM, Ole Streicher ole-usenet-s...@gmx.net wrote: Hi, I am curious when one should implement a __call__() and when a __getitem__() method. For example, I want to display functions and data in the same plot. For a function, the natural interface would to be

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