Re: [Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .

2012-09-20 Thread eryksun
On Wed, Sep 19, 2012 at 6:13 PM, eryksun wrote: > > cmd = 'python remote.py "%s" "%s" "%s"' % (arg1, arg2, arg3) > > try: > out = subprocess.check_output(['ssh', '%s@%s' % (user, hostname), > cmd]) I forgot you need to escape special characters in the arguments. You can add quoti

[Tutor] "bisect" vs "in"

2012-09-20 Thread Albert-Jan Roskam
Hi,   I want to repeatedly search a list to test whether that list contains a given element X. Of course, I can use membership testing using "in" (list._contains__). But how is this method implemented? It seems to just walk through the whole list from beginning to end (see timeit code below). Is

Re: [Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .

2012-09-20 Thread ashish makani
On Thu, Sep 20, 2012 at 3:43 AM, eryksun wrote: > On Wed, Sep 19, 2012 at 2:47 PM, ashish makani > wrote: > > > > I tried this > import os > os.system ("ssh remoteuser@remote python remote.py arg1 arg2 arg3") > > > > This worked, but if the arguments i tried to pass, had spaces, i was

Re: [Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 6:25 AM, eryksun wrote: > > I forgot you need to escape special characters in the arguments. You > can add quoting and escape special characters at the same time with > the undocumented function pipes.quote: > > import pipes > > args = tuple(pipes.quote(arg) for arg

Re: [Tutor] "bisect" vs "in"

2012-09-20 Thread Peter Otten
Albert-Jan Roskam wrote: > I want to repeatedly search a list to test whether that list contains a > given element X. Of course, I can use membership testing using "in" > (list._contains__). But how is this method implemented? It seems to just > walk through the whole list from beginning to end (s

Re: [Tutor] "bisect" vs "in"

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 7:58 AM, Albert-Jan Roskam wrote: > > Can such a program be scaled to lists that do not fit into memory (maybe > using shelve?)? shelve uses a database (e.g. gdbm) based on hashing. It's an unordered mapping. Unlike a dict, the keys must be strings. http://docs.python.org

[Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Ara Kooser
Morning, I dug out some old code from 5 years ago to clean up and get in working order. It's a simple agent based model. I have class called Ant which contains all the ant-like functions. I have a list that tracks the ants but I did this is a very crude way. I basically copied and pasted everyt

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Emile van Sebille
On 9/20/2012 7:41 AM Ara Kooser said... Morning, I dug out some old code from 5 years ago to clean up and get in working order. It's a simple agent based model. I have class called Ant which contains all the ant-like functions. I have a list that tracks the ants but I did this is a very crud

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Oscar Benjamin
On 20 September 2012 15:41, Ara Kooser wrote: > Morning, > > I dug out some old code from 5 years ago to clean up and get in working > order. It's a simple agent based model. I have class called Ant which > contains all the ant-like functions. > > I have a list that tracks the ants but I did th

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Ara Kooser
Oscar, Thanks for that. I feel a bit silly. I forgot about the % which was hanging me up. I am trying to be a better coder. More work ahead for me! ara On Thu, Sep 20, 2012 at 9:01 AM, Oscar Benjamin wrote: > On 20 September 2012 15:41, Ara Kooser wrote: > >> Morning, >> >> I dug out some

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 10:41 AM, Ara Kooser wrote: > > I have a list that tracks the ants but I did this is a very crude way. I > basically copied and pasted everything in there like this: > > ants = > [Ant("Red_1","Red","yellow_food"),Ant("Yellow_1","Yellow","red_food"), > Ant("Red_2","Red","yel

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 12:25 PM, eryksun wrote: > > cls._count += 1 I forgot the obligatory warning about class variables. The subclass gets a shallow copy of the parent class namespace. The in-place addition above works because numbers are immutable. However, an in-place operation o

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 12:57 PM, eryksun wrote: > > I forgot the obligatory warning about class variables. The subclass > gets a shallow copy of the parent class namespace. The in-place ^^^ > >>> Y.data += [1] > >>> X.data # modified parent, too > [1] > >>> Y.da

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Peter Otten
Ara Kooser wrote: > Morning, > > I dug out some old code from 5 years ago to clean up and get in working > order. It's a simple agent based model. I have class called Ant which > contains all the ant-like functions. > > I have a list that tracks the ants but I did this is a very crude way. I >

[Tutor] Understanding cProfile output

2012-09-20 Thread ranveer raghuwanshi
Hi, I am trying to understand the output of cProfile when run against my python code. The code is: from math import floor,sqrt count = int(floor(sqrt(10))) max_check = range(2,count+1) original_list = range(2,11) for j in max_check: temp_list=[] for i in original_list: if

Re: [Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .

2012-09-20 Thread Modulok
> I forgot you need to escape special characters in the arguments. You > can add quoting and escape special characters at the same time with > the undocumented function pipes.quote: > > import pipes > > args = tuple(pipes.quote(arg) for arg in (arg1, arg2, arg3)) > cmd = 'python test.py

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Steven D'Aprano
On 21/09/12 02:57, eryksun wrote: On Thu, Sep 20, 2012 at 12:25 PM, eryksun wrote: cls._count += 1 I forgot the obligatory warning about class variables. Python is not Java. In Python, classes are first-class objects (no pun intended) and can be assigned to variables the same

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 3:39 PM, Steven D'Aprano wrote: > On 21/09/12 02:57, eryksun wrote: >> >> On Thu, Sep 20, 2012 at 12:25 PM, eryksun wrote: > > Preferred terminology is attribute, not variable. Class attributes live > in the class and are shared across all instances. Instance attributes >

Re: [Tutor] Understanding cProfile output

2012-09-20 Thread Steven D'Aprano
On 21/09/12 04:58, ranveer raghuwanshi wrote: Hi, I am trying to understand the output of cProfile when run against my python code. The code is: [...] What the above code does is it counts the number of prime numbers less than 1,00,000. Now when I profile this code using *python -m cProfile -

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Steven D'Aprano
On 21/09/12 03:18, eryksun wrote: On Thu, Sep 20, 2012 at 12:57 PM, eryksun wrote: I forgot the obligatory warning about class variables. The subclass gets a shallow copy of the parent class namespace. The in-place ^^^ >>> Y.data += [1] >>> X.data # modified p

Re: [Tutor] Understanding cProfile output

2012-09-20 Thread Dave Angel
On 09/20/2012 03:56 PM, Steven D'Aprano wrote: > On 21/09/12 04:58, ranveer raghuwanshi wrote: >> Hi, >> >> I am trying to understand the output of cProfile when run against my >> python >> code. The code is: > [...] >> What the above code does is it counts the number of prime numbers >> less than

Re: [Tutor] Understanding cProfile output

2012-09-20 Thread ranveer raghuwanshi
Thanks for the input everyone. @Dave, I basically implemented the sieve of eratosthenes to fiind the number of prime numbers in a given range. So, yes I am looking for suggestions to speed it up. On Fri, Sep 21, 2012 at 2:16 AM, Dave Angel wrote: > On 09/20/2012 03:56 PM, Steven D'Aprano wrote:

[Tutor] Help

2012-09-20 Thread Brett Dailey
I'm having trouble with a small project. Here's what it needs to do:Has variables for window width and window height and creates a window of that size. Has variables which control the number of columns and number of rows. From this, create a checkboard pattern which evenly fills the window. On appr

Re: [Tutor] Help

2012-09-20 Thread Prasad, Ramit
People on this list are not all receiving this via email. It is recommended that you post 1. plain text (instead of Rich Text or HTML) 2. Just include the code directly in the email if it is short (which this is) or post to a website like pastebin for large samples. I have included the code below

Re: [Tutor] Help

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 6:31 PM, Brett Dailey wrote: > > From this, create a checkboard pattern which evenly fills the window. On > approximately 10% of the squares (chosen at random) draw an image which is > sized to just fit inside a checkboard square (use the smallest dimension). > Keep the pro

Re: [Tutor] Help

2012-09-20 Thread Steven D'Aprano
On 21/09/12 08:54, Prasad, Ramit wrote: People on this list are not all receiving this via email. They're not? How else can you receive this? Unlike the main python-list, this isn't (as far as I know) mirrored on Usenet. I wonder under what circumstances people could read this email without s

Re: [Tutor] Understanding cProfile output

2012-09-20 Thread Dave Angel
On 09/20/2012 05:15 PM, ranveer raghuwanshi wrote: > Thanks for the input everyone. > > @Dave, I basically implemented the sieve of eratosthenes to fiind the > number of prime numbers in a given range. So, yes I am looking for > suggestions to speed it up. > Please don't top-post on this forum.

Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-20 Thread Gregory Lund
> > You need to add the folder where python.exe is to your PATH variable. > > First you need to find the folder where python is on your computer. You can > do this from within a python script using the following two lines: > import sys > print sys.executable > > Once you've found the folder contain