[Tutor] fast sampling with replacement

2010-02-21 Thread Andrew Fithian
On Sat, Feb 20, 2010 at 11:55 AM, Luke Paireepinart wrote: > > > On Sat, Feb 20, 2010 at 1:50 PM, Kent Johnson wrote: > >> On Sat, Feb 20, 2010 at 11:22 AM, Andrew Fithian >> wrote: >> > can >> > you help me speed it up even more? >> > import random >> > def sample_with_replacement(list): >> >

[Tutor] Using and

2010-02-21 Thread jim serson
Can anyone tell me if I can have my program check to see if something is true the add to count For example something like if c_1 and c_2 and c_3 true: count + 1 or if I can use it after splitting an input the problem is the input is variable so I don't know if I can do such a thi

Re: [Tutor] Using and

2010-02-21 Thread Wayne Werner
On Sun, Feb 21, 2010 at 7:44 AM, jim serson wrote: > Can anyone tell me if I can have my program check to see if something is > true the add to count > > For example something like > > if c_1 and c_2 and c_3 true: > count + 1 > > or if I can use it after splitting an input the proble

Re: [Tutor] Using and

2010-02-21 Thread Benno Lang
On 21 February 2010 22:44, jim serson wrote: > Can anyone tell me if I can have my program check to see if something is > true the add to count > > For example something like > > if c_1 and c_2 and c_3 true: >     count + 1 Your code currently throws the result of the count + 1 expression

Re: [Tutor] Using and

2010-02-21 Thread Kent Johnson
On Sun, Feb 21, 2010 at 8:44 AM, jim serson wrote: > Can anyone tell me if I can have my program check to see if something is > true the add to count > > For example something like > > if c_1 and c_2 and c_3 true: > >     count + 1 This will almost work as written. Try if c_1 and c_2 and

Re: [Tutor] fast sampling with replacement

2010-02-21 Thread Dave Angel
Luke Paireepinart wrote: Can you explain what your function is doing and also post some test code to profile it? On Sat, Feb 20, 2010 at 10:22 AM, Andrew Fithian wrote: Hi tutor, I'm have a statistical bootstrapping script that is bottlenecking on a python function sample_with_replaceme

[Tutor] Functions returning multiple values

2010-02-21 Thread Giorgio
Hi, do you know if there is a way so that i can get multiple values from a function? For example: def count(a,b): c = a + b d = a - b How can I return the value of C and D? Then, i have another question: i've read, some time ago, this guide http://hetland.org/writing/instant-python.html, ski

Re: [Tutor] Functions returning multiple values

2010-02-21 Thread Steven D'Aprano
On Mon, 22 Feb 2010 03:00:32 am Giorgio wrote: > Hi, > > do you know if there is a way so that i can get multiple values from > a function? > > For example: > > def count(a,b): > c = a + b > d = a - b > > How can I return the value of C and D? Return a tuple of c and d: >>> def count(a, b): ...

[Tutor] Using Python with a Mac

2010-02-21 Thread Marco Rompré
Hi everyone, I would like to know how to use python with a mac. For now, I go to spotlight, open terminal then type IDLE and a window pops up but its like the window that opens when you run your programs already saved and I'm not able to open another window to write a script from scratch. Could s

Re: [Tutor] Using Python with a Mac

2010-02-21 Thread Shashwat Anand
mac have python 2.5 and 2.6 installed by default. If you use Vi then you are up for it. If you want IDE then pydev plugin with eclipse can be tried. I had heard good things about it. Also you can try bpython(python fancy interpretor), install it via macports. ~l0nwlf On Sun, Feb 21, 2010 at 10:36

[Tutor] Regex to find files ending with one of a given set of extensions

2010-02-21 Thread Dayo Adewunmi
Hi all I'm trying use regex to match image formats: import re def findImageFiles(): imageRx = re.compile('\.jpe?g$|\.png$|\.gif$|\.tiff?$', re.I) someFiles = ["sdfinsf.png","dsiasd.dgf","wecn.GIF","iewijiefi.jPg","iasjasd.py"] findImages = imageRx(someFiles) print "START: %s" %

Re: [Tutor] fast sampling with replacement

2010-02-21 Thread Steven D'Aprano
On Sun, 21 Feb 2010 03:22:19 am Andrew Fithian wrote: > Hi tutor, > > I'm have a statistical bootstrapping script that is bottlenecking on > a python function sample_with_replacement(). I wrote this function > myself because I couldn't find a similar function in python's random > library. random.

Re: [Tutor] Regex to find files ending with one of a given set of extensions

2010-02-21 Thread Steven D'Aprano
On Mon, 22 Feb 2010 04:23:04 am Dayo Adewunmi wrote: > Hi all > > I'm trying use regex to match image formats: Perhaps you should use a simpler way. def isimagefile(filename): ext = os.path.splitext(filename)[1] return (ext.lower() in ('.jpg', '.jpeg', '.gif', '.png', '.tif', '.tiff'

[Tutor] Python file escaping issue?

2010-02-21 Thread Sithembewena Lloyd Dube
Hi all, I'm trying to read a file (Python 2.5.2, Windows XP) as follows: assignment_file = open('C:\Documents and Settings\coderoid\My Documents\Downloads\code_sample.txt', 'r+').readlines() new_file = open(new_file.txt, 'w+') for line in assignment_file: new_file.write(line) new_file.close(

Re: [Tutor] Using Python with a Mac

2010-02-21 Thread Monte Milanuk
On Sun, Feb 21, 2010 at 10:36 PM, Marco Rompré wrote: > Hi everyone, I would like to know how to use python with a mac. > > For now, I go to spotlight, open terminal then type IDLE and a window pops > up but its like the window that opens when you run your programs already > saved and I'm not able

Re: [Tutor] Python file escaping issue?

2010-02-21 Thread Wayne Werner
On Sun, Feb 21, 2010 at 12:22 PM, Sithembewena Lloyd Dube wrote: > Hi all, > > I'm trying to read a file (Python 2.5.2, Windows XP) as follows: > > assignment_file = open('C:\Documents and Settings\coderoid\My > Documents\Downloads\code_sample.txt', 'r+').readlines() > new_file = open(new_file.tx

Re: [Tutor] Python file escaping issue?

2010-02-21 Thread Sithembewena Lloyd Dube
@Wayne, sorry to have replied to you directly.. On Sun, Feb 21, 2010 at 9:23 PM, Sithembewena Lloyd Dube wrote: > Solved by moving the file just under C:\ > > Must be an issue with directory name spaces. > > By the way, my code was riddled with bugs. readlines() returns a list > object, which doe

[Tutor] working with email module

2010-02-21 Thread Rick Pasotto
I subscribe to an email list that distributes image files. I'd like to automate the process of saving the images to individual files. I've got it mostly figured out with two exceptions. 1) Sometimes msg.filename returns 'None' even though msg.get_content_type returns 'image/jpeg' and the actual me

Re: [Tutor] Superclass call problem

2010-02-21 Thread Alan Harris-Reid
Hi, I am having trouble understanding how superclass calls work. Here's some code... What version of Python are you using? In Python 2.x, you MUST inherit from object to use super, and you MUST explicitly pass the class and self: class ParentClass(object): def __init__(self, a,

Re: [Tutor] Python file escaping issue?

2010-02-21 Thread Steven D'Aprano
On Mon, 22 Feb 2010 05:22:10 am Sithembewena Lloyd Dube wrote: > Hi all, > > I'm trying to read a file (Python 2.5.2, Windows XP) as follows: > > assignment_file = open('C:\Documents and Settings\coderoid\My > Documents\Downloads\code_sample.txt', 'r+').readlines() > new_file = open(new_file.txt, '

[Tutor] "Two" Card Monty with File Operations--Reading from Wrong Folder (W7?)

2010-02-21 Thread Wayne Watson
I have a program called TrackStudy.py and another called ReportTool.py Track runs above an Events folder that contains txt files that it examines.Report runs in an Events folder on the same txt files. Neither is operated when the other is operating. Both only read the same files. I've bee

[Tutor] Extracting comments from a file

2010-02-21 Thread Lao Mao
Hi, I have an html file, with xml style comments in: I'd like to extract only the comments. My sense of smell suggests that there's probably a library (maybe an xml library) that does this already. Otherwise, my current alogorithm looks a bit like this: * Iterate over file * If current line c

Re: [Tutor] Python file escaping issue?

2010-02-21 Thread spir
Just a little complement to Steven's excellent explanation: On Mon, 22 Feb 2010 10:01:06 +1100 Steven D'Aprano wrote: [...] > So if you write a pathname like this: > > >>> path = 'C:\datafile.txt' > >>> print path > C:\datafile.txt > >>> len(path) > 15 > > It *seems* to work, because \d i