Re: Do any of you recommend Python as a first programming language?

2008-03-23 Thread Ben C
On 2008-03-22, bsoist [EMAIL PROTECTED] wrote: On Mar 22, 12:40 pm, jmDesktop [EMAIL PROTECTED] wrote: For students 9th - 12th grade, with at least Algebra I. Do you think Python is a good first programming language for someone with zero programming experience? Using Linux and Python for

Re: About reading Python code

2008-03-17 Thread Ben C
On 2008-03-17, WaterWalk [EMAIL PROTECTED] wrote: Hello. I wonder what's the effective way of figuring out how a piece of python code works. With C I often find it very useful to be able to run the code in step mode and set breakpoints in a debugger so I can watch how the it executes, how the

Re: SV: SV: Regarding coding style

2008-03-08 Thread Ben C
On 2008-03-08, K Viltersten [EMAIL PROTECTED] wrote: If you can't/don't look at the source file, then comments aren't going to help (except in the case of something like docstrings in Python). I strongly disagree. Now, perhaps we're talking about different things, here? Usually, in the

Re: How to manipulate elements of a list in a single line of code?

2008-02-25 Thread Ben C
On 2008-02-25, mrstephengross [EMAIL PROTECTED] wrote: I would like to translate the contents of a list. For instance, let's say I've got a list of strings and I want to append foo to each element. I might do the following; list1 = ['a', 'b', 'c'] for i in range(0, len(list1)): list1[i]

Re: Recursive generator

2008-02-13 Thread Ben C
On 2008-02-12, Paul Hankin [EMAIL PROTECTED] wrote: On Feb 12, 10:17 pm, Ben C [EMAIL PROTECTED] wrote: On 2008-02-12, Paul Rubin wrote: Paul Hankin [EMAIL PROTECTED] writes: def genDescendants(self):     return chain([self], *[child.genDescendants()         for child in self.children

Re: Recursive generator

2008-02-13 Thread Ben C
On 2008-02-13, Erich [EMAIL PROTECTED] wrote: On Feb 12, 5:15 am, Ben C [EMAIL PROTECTED] wrote: I think this works OK, but it seems a bit odd. Is there something more Pythonic I should be doing? I have a similar tree to the one you describe here at work. I have a visit function that is very

Re: Recursive generator

2008-02-12 Thread Ben C
On 2008-02-12, Paul Rubin wrote: Paul Hankin [EMAIL PROTECTED] writes: def genDescendants(self): return chain([self], *[child.genDescendants() for child in self.children]) That is scary. It generates an in-memory list the size of the whole subtree, at every level. Total

Re: Recursive generator

2008-02-12 Thread Ben C
On 2008-02-12, Paul Hankin [EMAIL PROTECTED] wrote: On Feb 12, 11:15 am, Ben C [EMAIL PROTECTED] wrote: Suppose I have an object containing an array called children. I can therefore build a tree out of such objects. The best I came up with so far is :     def genDescendents(self

Recursive generator

2008-02-12 Thread Ben C
Suppose I have an object containing an array called children. I can therefore build a tree out of such objects. I thought it might be useful to have a descendent generator, so I could write: for thing in self.genDescendents(): foo(thing) expecting foo to be called for each

Re: MS Word parser

2007-06-14 Thread Ben C
On 2007-06-13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Jun 13, 1:28 am, Tim Golden [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Hi all, I'm currently using antiword to extract content from MS Word files. Is there another way to do this without relying on any command prompt

Re: questions about programming styles

2007-05-20 Thread Ben C
On 2007-05-20, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi all, I'm not skilled at programming, so sorry for my ignorance. My questions: (1) which is the better way to calculate the value of attributes of a class ? for example: (A) def cal_attr(self, args): #do some

Re: Controlling gnuplot via subprocess.Popen

2007-04-25 Thread Ben C
On 2007-04-25, Peter Beattie [EMAIL PROTECTED] wrote: I am trying to plot something in gnuplot 4.2 using co-ordinates a Python 2.5 program computes. Here's what I'm doing: py from subprocess import * py plot = Popen(c:/progs/gp/bin/wgnuplot.exe, stdin=PIPE) py plot.stdin.write(plot x*x)

Re: Strange behaviour of 'is'

2006-09-21 Thread Ben C
On 2006-09-21, Fijoy George [EMAIL PROTECTED] wrote: Hi all, I am a bit perplexed by the following behaviour of the 'is' comparator x = 2. x is 2. False y = [2., 2.] y[0] is y[1] True My understanding was that every literal is a constructure of an object. Thus, the '2.' in 'x = 2.'

Re: PIL Image transform

2006-08-12 Thread Ben C
On 2006-08-11, Dean Card [EMAIL PROTECTED] wrote: [snip] thanks for the reply. I have been able to use the Image.PERSPECTIVE transform via trial and error to get it to work properly for each transform. What I am really looking for I guess is a way to calculate the 8 int tuple to match

Re: PIL Image transform

2006-08-11 Thread Ben C
On 2006-08-09, Dean Card [EMAIL PROTECTED] wrote: Okay, so here is the situation. I have need to do some on-the-fly image creation. I have everything working great except for the last part of it, applying a perspective type transform to the image. The transform will take a rectangular 2D

Re: PIL Image transform

2006-08-11 Thread Ben C
On 2006-08-11, Dean Card [EMAIL PROTECTED] wrote: This looks like a correct description of the sources: In Image.py: elif method == PERSPECTIVE: # change argument order to match implementation data = (data[2], data[0], data[1], data[5], data[3], data[4],

Re: access abook addressbook with curses

2006-08-08 Thread Ben C
On 2006-08-08, Fabian Braennstroem [EMAIL PROTECTED] wrote: Hi Ben, * Ben C [EMAIL PROTECTED] wrote: On 2006-08-06, Fabian Braennstroem [EMAIL PROTECTED] wrote: Hi Ben, * Ben C [EMAIL PROTECTED] wrote: On 2006-08-05, Fabian Braennstroem [EMAIL PROTECTED] wrote: Hi, I want to get access

Re: access abook addressbook with curses

2006-08-06 Thread Ben C
On 2006-08-06, Fabian Braennstroem [EMAIL PROTECTED] wrote: Hi Ben, * Ben C [EMAIL PROTECTED] wrote: On 2006-08-05, Fabian Braennstroem [EMAIL PROTECTED] wrote: Hi, I want to get access to my abook address file with python. Does anyone have some python lines to achive this using curses

Re: access abook addressbook with curses

2006-08-05 Thread Ben C
On 2006-08-05, Fabian Braennstroem [EMAIL PROTECTED] wrote: Hi, I want to get access to my abook address file with python. Does anyone have some python lines to achive this using curses? If not, maybe anybody has small python program doing it with a gui!? You can just parse the abook

Re: solving equation system

2006-07-17 Thread Ben C
On 2006-07-17, TG [EMAIL PROTECTED] wrote: Hi there. Anyone knows how to use numpy / scipy in order to solve this ? * A is an array of shape (n,) * X is a positive float number * B is an array of shape (n,) * O is an array of shape (n,) containing only zeros. A.X - B = O min(X) Are we

Re: solving equation system

2006-07-17 Thread Ben C
On 2006-07-17, TG [EMAIL PROTECTED] wrote: Ben C wrote: On 2006-07-17, TG [EMAIL PROTECTED] wrote: Hi there. Anyone knows how to use numpy / scipy in order to solve this ? * A is an array of shape (n,) * X is a positive float number * B is an array of shape (n,) * O is an array

Re: Configuring IDLE on Linux

2006-07-16 Thread Ben C
On 2006-07-14, Adonis [EMAIL PROTECTED] wrote: Satya Kiran wrote: Hello, I have upgraded to Python2.4 on my Red Hat 9.0 Linux box. I want to work with IDLE and ran a search to check it's presence. Here is what I get. [EMAIL PROTECTED] bin]# find / -iname idlelib

Re: embedding executable code in a regular expression in Python

2006-07-16 Thread Ben C
On 2006-07-16, Avi Kak [EMAIL PROTECTED] wrote: Folks, Does regular expression processing in Python allow for executable code to be embedded inside a regular expression? For example, in Perl the following two statements $regex = qr/hello(?{print saw hello\n})mello(?{print saw mello\n})/;

Re: Accessors in Python (getters and setters)

2006-07-15 Thread Ben C
On 2006-07-15, Gerhard Fiedler [EMAIL PROTECTED] wrote: On 2006-07-15 06:55:14, mystilleef wrote: In very well designed systems, the state of an object should only be changed by the object. IMO that's not quite true. Ultimately, the state always gets changed by something else (user

Re: Absolute noob to Linux programming needs language choice help

2006-06-24 Thread Ben C
On 2006-06-21, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hey guys, I am absolutely new to Linux programming, with no w##s programming experience except a small amount of C++ console apps. Reasonably new to Linux, BSD etc, got good sound networking base of knowledge and dont have any

Re: clear memory? how?

2006-05-10 Thread Ben C
On 2006-05-10, Gr�goire Dooms [EMAIL PROTECTED] wrote: Ben C wrote: On 2006-05-09, Ben C [EMAIL PROTECTED] wrote: def clearall(): all = [var for var in globals() if __ not in (var[:2], var[-2:])] for var in all: del globals()[var] since I think magic things always start

Re: clear memory? how?

2006-05-09 Thread Ben C
On 2006-05-09, Diez B. Roggisch [EMAIL PROTECTED] wrote: N/A wrote: Hi all, I am learning Python. Just wondering how to clear saved memory in Python? Like in Matlab I can simply use clear all to clear all saved memory. You don't - python does it for you. It is called garbage collection.

Re: do some action once a minute

2006-05-09 Thread Ben C
On 2006-05-09, Petr Jakes [EMAIL PROTECTED] wrote: I would like to do some action once a minute. You can try the sched module (import sched). You give it a time at which to call a callback. Then in the callback you can reset the alarm for a minute later, using enterabs. If the task might take

Re: clear memory? how?

2006-05-09 Thread Ben C
On 2006-05-09, Ben C [EMAIL PROTECTED] wrote: def clearall(): all = [var for var in globals() if __ not in (var[:2], var[-2:])] for var in all: del globals()[var] since I think magic things always start and end with __. Oops, got that wrong anyway: should be: all

Re: self modifying code

2006-04-29 Thread Ben C
On 2006-04-29, Robin Becker [EMAIL PROTECTED] wrote: When young I was warned repeatedly by more knowledgeable folk that self modifying code was dangerous. Is the following idiom dangerous or unpythonic? def func(a): global func, data data = somethingcomplexandcostly() def

Re: Events in Python?

2006-04-27 Thread Ben C
On 2006-04-26, nikie [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Here is another non-pythonic question from the Java Developer. (I beg for forgiveness...) Does Python have a mechanism for events/event-driven programming? I'm not necessarily talking about just GUIs either, I'm

Re: a subprocess qns

2006-04-21 Thread Ben C
On 2006-04-21, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: hi i wanted to start execute a command and put it in the background. i am using Unix. If you use subprocess, or even os.spawn, it should be portable and work on all systems (although the docs list some restrictions). Usually i start

Re: lambda

2006-04-21 Thread Ben C
On 2006-04-21, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello, I need your help understanding lambda (and doing it a better way without). f = lambda x : x*x [...] # the idea is now to give the definition of the multiplication of functions and integers # (f * c)(xx) := f(x)*c [lambda

Re: lambda

2006-04-21 Thread Ben C
On 2006-04-21, Ben C [EMAIL PROTECTED] wrote: On 2006-04-21, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello, I need your help understanding lambda (and doing it a better way without). f = lambda x : x*x [...] # the idea is now to give the definition of the multiplication of functions

Re: lambda

2006-04-21 Thread Ben C
On 2006-04-21, Alexis Roda [EMAIL PROTECTED] wrote: Ben C escribió: On 2006-04-21, Ben C [EMAIL PROTECTED] wrote: Having said that, I attempted to confirm this using def rather than lambda, and encountered something I cannot explain at all-- it appears that the functions are getting redefined

Re: Activating Batch Files from Python

2006-04-19 Thread Ben C
On 2006-04-19, Jeff Groves [EMAIL PROTECTED] wrote: I'm writing a launcher that should do the following: 1. Activate a .bat file to set environmental variables. 2. Start 3 programs, using said environmental variables as arguments. However, I can't get the environmental variables to stick

Re: Activating Batch Files from Python

2006-04-19 Thread Ben C
On 2006-04-19, Jeff Groves [EMAIL PROTECTED] wrote: How about sourcing it from a shell, then using that same shell instance to run the programs? How would I do that? As I've said, I haven't found a Python command that lets you send multiple commands to the same shell yet. If I could, my

Re: Decode html, or is it unicode, how?

2006-04-17 Thread Ben C
On 2006-04-17, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi All, I've done a bunch of searching in google and in python's help, but, I haven't found any function to decode a string like: Refresh#33; (ihenvyr) In to plain english. [...] I needed to do that the other day, and did it like

Re: list.clear() missing?!?

2006-04-14 Thread Ben C
On 2006-04-14, Sergei Organov [EMAIL PROTECTED] wrote: Dennis Lee Bieber [EMAIL PROTECTED] writes: It always means bind... But if the LHS is a mutable object, AND you have specified a component of that object, it is the component that is being rebound... lst[:] = [] [...] Me

Re: new-style classes and len method

2006-04-13 Thread Ben C
On 2006-04-13, Thomas Girod [EMAIL PROTECTED] wrote: Hi there. I'm trying to use new-style classes, but there is something i'm obviously missing here it is : class Data(list): __slots__ = [width, height, label] def __init__(self,width,height,label=None):

Re: trying to grasp OO : newbie Q?

2006-04-13 Thread Ben C
On 2006-04-13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I just started with Python and I am new to OO programming. Here is a simple code: class Obj: myVar = 1 def __init__(self): myVar = 2 # myObj = Obj() print myObj.myVar The output is of this

Re: Python2CPP ?

2006-04-12 Thread Ben C
On 2006-04-12, Michael Yanowitz [EMAIL PROTECTED] wrote: Hello: One topic that has always interested me are the Language translators. Are there any that convert between Python and C++ or Python and Java? I remember seeing one that converts from Python to or from Perl but couldn't find it

Re: About classes and OOP in Python

2006-04-11 Thread Ben C
On 2006-04-11, Michele Simionato [EMAIL PROTECTED] wrote: Roy Smith wrote: snip That being said, you can indeed have private data in Python. Just prefix your variable names with two underscores (i.e. __foo), and they effectively become private. Yes, you can bypass this if you really want to,

Re: RegExp question

2006-04-11 Thread Ben C
On 2006-04-11, Michael McGarry [EMAIL PROTECTED] wrote: Hi, I would like to form a regular expression to find a few different tokens (and, or, xor) followed by some variable number of whitespace (i.e., tabs and spaces) followed by a hash mark (i.e., #). What would be the regular expression

Re: RegExp question

2006-04-11 Thread Ben C
On 2006-04-11, Michael McGarry [EMAIL PROTECTED] wrote: Tim, for some reason that does not seem to do the trick. I am testing it with grep. (i.e., grep -e '(and|or|xor)\s*#' myfile) Try with grep -P, which means use perl-compatible regexes as opposed to POSIX ones. I only know for sure that

Re: UnicodeDecodeError help please?

2006-04-07 Thread Ben C
On 2006-04-07, Robin Haswell [EMAIL PROTECTED] wrote: Okay I'm getting really frustrated with Python's Unicode handling, I'm trying everything I can think of an I can't escape Unicode(En|De)codeError no matter what I try. Could someone explain to me what I'm doing wrong here, so I can hope to

Re: wxPython and SuSE 10.0

2006-04-05 Thread Ben C
On 2006-04-05, Steve [EMAIL PROTECTED] wrote: Hello, I was wondering if there is a wxPython RPM for SuSE 10.0 available. I Googled for it with no luck, but I'm hopeful that there is one out there. http://www.novell.com/products/linuxpackages/professional/python-wxgtk.html is the

Re: how to convert string

2006-04-05 Thread Ben C
On 2006-04-05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I want to print number 0 to 9 in one line like this 0 1 2 3 4 5 6 7 8 9 if I do like this, it prints in different lines for i in xrange(10): print i for i in xrange(10): print i, should work (comma after the i). so i

Re: how to convert string

2006-04-05 Thread Ben C
On 2006-04-05, Scott David Daniels [EMAIL PROTECTED] wrote: Ben C wrote: ... But this puts an extra space on the end (so did the print i, version above). Actually, no (the trailing-comma prints do a funny dance). Check it out: [...] You're right, I tried it! Thanks for that. Useful

Re: how to capture os.execvp into variable

2006-03-29 Thread Ben C
On 2006-03-28, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: hi i am using this code to run a ps command in unix def run(program, *args): pid = os.fork() if not pid: os.execvp(program, (program,) + args) return os.wait()[0] run(ps, -eo pid,ppid,args) It runs fine, but

Re: Writing web bots in python

2006-03-19 Thread Ben C
On 2006-03-18, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello, I hav a question..How do I write a webbot that logs onto some website, fills text into a textbox and submit that form, Sorry I am a novice in python, apparently I have to use urllib, but I hav a few queries on this, What happens

Re: calling another python file within python

2006-03-14 Thread Ben C
On 2006-03-14, Kevin [EMAIL PROTECTED] wrote: i have a python file called pyq which outputs stock quotes, currently i also have a html file that takes stock ticker inputs, i would like to bridge the two by building another program that takes the html inputs and uses them to call the pyq

Re: Dictionary project

2006-03-11 Thread Ben C
On 2006-03-11, Michael Spencer [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Hi All, First, I hope this post isn't against list rules; if so, I'll take note in the future. I'm working on a project for school (it's not homework; just for fun). For it, I need to make a list of words,

Re: Dictionary project

2006-03-11 Thread Ben C
So here's a different approach, which I think does meet the spec: from itertools import tee def allwords2(alphabet=abcd, maxlen = 4): def wordgen(): for char in alphabet: yield char for partial in allwordstee[1]: if len(partial) == maxlen: