Re: [Tutor] Finding the Index of a member of a Tuple

2006-01-11 Thread Terry Carroll
On Wed, 11 Jan 2006, Steve Haley wrote: > I need to do something very simple but I'm having trouble finding the way to > do it - at least easily. I have created a tuple and now need to find the > position of individual members of that tuple. Specifically, the tuple is > something like: words = (

Re: [Tutor] Locating directory of script?

2006-01-11 Thread Brian van den Broek
Liam Clarke said unto the world upon 12/01/06 12:32 AM: > Hi all, > > Let's say I have a script called bob.py in a directory called > c:\pythonstuff, which is in my PATH env_var, and python is also in my > PATH, and from a completely different directory I call "python bob.py" > is there a right wa

Re: [Tutor] Finding the Index of a member of a Tuple

2006-01-11 Thread Brian van den Broek
bob said unto the world upon 11/01/06 10:47 PM: > At 08:31 PM 1/11/2006, Steve Haley wrote: > >>Hello everyone, >> >>I need to do something very simple but I'm having trouble finding >>the way to do it - at least easily. I have created a tuple and now >>need to find the position of individual m

[Tutor] Locating directory of script?

2006-01-11 Thread Liam Clarke
Hi all, Let's say I have a script called bob.py in a directory called c:\pythonstuff, which is in my PATH env_var, and python is also in my PATH, and from a completely different directory I call "python bob.py" is there a right way to determine what directory bob.py resides in? So far I've found

Re: [Tutor] calloc

2006-01-11 Thread Danny Yoo
On Thu, 12 Jan 2006, Burge Kurt wrote: > Again thank you :( and sorry for asking that much questions in one day > and I know most of them were nonsense .. Don't worry about it; please feel free to continue to ask questions on the list. It wasn't quite clear what experience you had before: I ha

Re: [Tutor] Finding the Index of a member of a Tuple

2006-01-11 Thread bob
At 08:31 PM 1/11/2006, Steve Haley wrote: >Hello everyone, > >I need to do something very simple but I'm having trouble finding >the way to do it - at least easily. I have created a tuple and now >need to find the position of individual members of that >tuple. Specifically, the tuple is someth

[Tutor] Finding the Index of a member of a Tuple

2006-01-11 Thread Steve Haley
Hello everyone,   I need to do something very simple but I'm having trouble finding the way to do it - at least easily.  I have created a tuple and now need to find the position of individual members of that tuple.  Specifically, the tuple is something like: words = ("you", "me", "us", "we", "and",

Re: [Tutor] declaring list

2006-01-11 Thread Logesh Pillay
hello list I asked yesterday how we can "declare" an array in python. Thanks Brian van den Broek and Frank Schley for your responses. A[None] * n works for me. To answer Brian's question, I was writing the standard backtracking procedure to find the permutations of 1..n taken r at a time. def

Re: [Tutor] calloc

2006-01-11 Thread Danny Yoo
On Thu, 12 Jan 2006, Burge Kurt wrote: > How can I use calloc in python ? Before computing and processing my data > I want to know how many bytes are available? Hi Burge, There's no concept of manual memory allocation in Python, and we don't have direct access to calloc/malloc/free. You're as

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Kent Johnson
Hans Dushanthakumar wrote: > Oops answered my own question. Dynamic importing is done using the > __import__ function: > > t = ["test1.py", "test2.py"] #Actually this list is filled in by a > Tkinter Listbox selection. > > for f in t: > testname = f[:-3] > test = __import__("%s"%(testname

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Orri Ganel
Hans Dushanthakumar wrote: >Oops answered my own question. Dynamic importing is done using the >__import__ function: > >t = ["test1.py", "test2.py"] #Actually this list is filled in by a >Tkinter Listbox selection. > >for f in t: >testname = f[:-3] >test = __import__("%s"%(testname)) >

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Orri Ganel
Hans Dushanthakumar wrote: >Thanks for your reply Kent. > >Is it possible to dynamically import a module? > >The foll snippet of code throws an error "ImportError: No module named >testname" > > >t = ["test1.py", "test2.py"] #Actually this list is filled in by a >Tkinter Listbox selection. > >for

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread John Fouhy
On 12/01/06, Hans Dushanthakumar <[EMAIL PROTECTED]> wrote: > Any other means of importing dynamically? There's an __import__ builtin. It's a function that takes a string and returns the module. eg: >>> sys = __import__('sys') >>> sys.platform 'win32' [actually, it does a bit more than just tha

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Hans Dushanthakumar
Oops answered my own question. Dynamic importing is done using the __import__ function: t = ["test1.py", "test2.py"] #Actually this list is filled in by a Tkinter Listbox selection. for f in t: testname = f[:-3] test = __import__("%s"%(testname)) res = test.run_test() Cheers Hans -

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Hans Dushanthakumar
Thanks for your reply Kent. Is it possible to dynamically import a module? The foll snippet of code throws an error "ImportError: No module named testname" t = ["test1.py", "test2.py"] #Actually this list is filled in by a Tkinter Listbox selection. for f in t: testname = f[:-3] import

[Tutor] calloc

2006-01-11 Thread Burge Kurt
Hi again (:   How can I use calloc in python ? Before computing and processing my data I want to know how many bytes are available?   Thanks in advance and best wishes,   Burge ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinf

Re: [Tutor] div_t

2006-01-11 Thread Kent Johnson
Burge Kurt wrote: > Hi, > > What is the usage of div_t in python? > > I have some unsigned integer variables and want to use ; > > div_t div_T; > div_t div_N; > div_t div_B; I guess this is more C code. It doesn't have any Python equivalent - Python doesn't declare variables and doesn't hav

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Kent Johnson
Hans Dushanthakumar wrote: > Yes I agree that it'd be cleaner to import the second script and call > it. > > The reason I'm keen to find a alternate method is that I have a whole > lot of scripts that were designed to run only as standalone scripts. ie > each of these scripts is not a "function" t

Re: [Tutor] need help with syntax

2006-01-11 Thread bill nieuwendorp
This list is full of people ready to help, I thank you all for the time you have taken to reply. Danny now I see where readline could cause headaches,. Liam thanks for the examples they work great. The endianess will always be in Big Endian (Motorola type) for this format. I see why I should be

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Hans Dushanthakumar
Yes I agree that it'd be cleaner to import the second script and call it. The reason I'm keen to find a alternate method is that I have a whole lot of scripts that were designed to run only as standalone scripts. ie each of these scripts is not a "function" that I could just call from another scri

Re: [Tutor] div_t

2006-01-11 Thread bob
At 02:59 PM 1/11/2006, Burge Kurt wrote: >Hi, > >What is the usage of div_t in python? > >I have some unsigned integer variables and want to use ; > >div_t div_T; >div_t div_N; >div_t div_B; Your question is meaningless to me! Please clarify. div_t is not a Python constant or built_in. div_t div

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Kent Johnson
Hans Dushanthakumar wrote: > Hi, >Can a script return multiple values to the os? Is there a reason why you have to call the second test.py using os.system()? I would write it to be imported and called. test.py -- def findR(): return 7, 'Hans' script1.py - import test res

[Tutor] div_t

2006-01-11 Thread Burge Kurt
Hi,   What is the usage of div_t in python?   I have some unsigned integer variables and want to use ;   div_t div_T; div_t div_N; div_t div_B; . . ..   Best for all,   Burge ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/

[Tutor] Returning multiple values from a script

2006-01-11 Thread Hans Dushanthakumar
Hi, Can a script return multiple values to the os? What I have in mind is something like the following: 1) Test.py --- import sys r = 7 sys.exit(r) # What I really want to do is something along the lines of sys.exit(r, "Hans") 2) Script1.py (This script executes script test.py and pri

Re: [Tutor] CPU Utilization

2006-01-11 Thread DS
Thanks for your responses. Michael Janssen wrote: >It's perhaps easier to read the information from the /proc filesystem >(this is where top gets it itself). "man proc" tells where the info is >stored (guess: /proc/stat). > > > stat does look in some ways easier. I will say that I found the st

Re: [Tutor] need help with syntax

2006-01-11 Thread Liam Clarke
> > You mentioned earlier that you're expecting an integer, an integer, and > then a sequence of float. Don't count bytes if you can help it: let > Python's struct.calcsize() do this for you. > >http://www.python.org/doc/lib/module-struct.html > > Your machine may align bytes differently than

Re: [Tutor] CPU Utilization

2006-01-11 Thread Hugo González Monteverde
Hi, top is very interactive so it would not be easy at all to parse. I can suggest reading /proc/loadavg if you're in Linux. proc(5) ('man 5 proc') says that /proc/loadavg is The load average numbers give the number of jobs in the run queue averaged over 1, 5 and 15 minutes. They

Re: [Tutor] pointers

2006-01-11 Thread Danny Yoo
On Wed, 11 Jan 2006, Burge Kurt wrote: > I f I want to translate C code to Python and have a function like > > void get_args(int argc, char* argv[], Argument* args) > { Hi Burge, Also wanted to note that the Standard Library already contains an argument-parsing library, so you may want to tak

Re: [Tutor] pointers

2006-01-11 Thread w chun
On 1/11/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Burge Kurt wrote: > > > > void get_args(int argc, char* argv[], Argument* args) > > > > My first question about the pointers here; how can I convert them to > > Python? > > Python doesn't have pointers in the sense of direct references to > memo

[Tutor] CPU Utilization

2006-01-11 Thread DS
I am implementing a computational cluster and am using a job controller (for want of a better term) that contacts the worker computers, determines how busy they currently are, and then assigns more work if the worker computer is below a certain cpu utilization threshhold. For the cpu threshhold,

Re: [Tutor] pointers

2006-01-11 Thread Kent Johnson
Burge Kurt wrote: > Sorry for the previous message I did it by mistake.. > the function was like below: > > void get_args(int argc, char* argv[], Argument* args) > { > //check the amount of the arguments > if(argc%2 == 0) >{ >printf("Error, incorrect argument numbers : %d\n",a

Re: [Tutor] pointers

2006-01-11 Thread Bernard Lebel
Hi Burge, You can access command line argument via sys.argv: import sys print sys.argv This prints a list of the command line arguments. Since argv is a list, it means you can check its length to get the argument count: print len( sys.argv ) There is always at least one argument in this list,

Re: [Tutor] extra characters in XML

2006-01-11 Thread Kent Johnson
Ben Vinger wrote: > Found the following (which solved the problem, though > not on the console) at > http://www.jorendorff.com/articles/unicode/python.html > > import codecs > # Open a UTF-8 file in read mode > infile = codecs.open("infile.txt", "r", "utf-8") > # Read its contents as one l

Re: [Tutor] extra characters in XML

2006-01-11 Thread Ben Vinger
Found the following (which solved the problem, though not on the console) at http://www.jorendorff.com/articles/unicode/python.html import codecs # Open a UTF-8 file in read mode infile = codecs.open("infile.txt", "r", "utf-8") # Read its contents as one large Unicode string. text = infi

Re: [Tutor] pointers

2006-01-11 Thread Burge Kurt
Sorry for the previous message I did it by mistake..the function was like below:   void get_args(int argc, char* argv[], Argument* args){    //check the amount of the arguments    if(argc%2 == 0)    {   printf("Error, incorrect argument numbers : %d\n",argc);       print_help();   exit(1); 

[Tutor] pointers

2006-01-11 Thread Burge Kurt
Hi,   I f I want to translate C code to Python and have a function like   void get_args(int argc, char* argv[], Argument* args) {   ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] extra characters in XML

2006-01-11 Thread Ben Vinger
Hello all I want to do the following in an XML file: XFile = open(XmlFile,'r') for line in XFile.readlines(): if line.find('') > 0: print line However, it does not work due to extra characters that appear in the XML file. For example if I use the previous code without the if condition

Re: [Tutor] How can I make a python script go directory by directory and excecute on files of choice

2006-01-11 Thread Ed Singleton
On 11/01/06, Liam Clarke <[EMAIL PROTECTED]> wrote: > Hi Srinivas - > > For walking a directory, you can use os.walk() or os.path.walk(), but > I prefer the path module here - > http://www.jorendorff.com/articles/python/path/. The Path module is excellent, but it's walk still doesn't take into acc

Re: [Tutor] need help with syntax

2006-01-11 Thread Danny Yoo
On Tue, 10 Jan 2006, bill nieuwendorp wrote: > I am trying to convert binary file to ascii > > here is the format spec > > steps = int 4 > value = int 4 > time = float 4 * steps Hi Bill, Ok, that structure seems fairly simple so far. > >>> import struct > >>> import string > >>> f = file('b