Re: [Tutor] Using exec with dict

2005-01-30 Thread Danny Yoo
On Mon, 31 Jan 2005, [ISO-8859-1] André Roberge wrote: > >/ I have a "robot" that can do some actions like "move()" and > />/ "turn_left()". I can program this robot using python like this: > />/ > />/ .def move_and_turn(): > [snip]// > />/ The question I have is: how do I do this with an

[Tutor] Using exec with dict

2005-01-30 Thread André Roberge
Thank you Kent. That worked. André Roberge wrote: / I have a "robot" that can do some actions like "move()" and />/ "turn_left()". I can program this robot using python like this: />/ />/ .def move_and_turn(): [snip]// />/ The question I have is: how do I do this with an explici

Re: [Tutor] Using exec with dict

2005-01-30 Thread Kent Johnson
André Roberge wrote: I have a "robot" that can do some actions like "move()" and "turn_left()". I can program this robot using python like this: .def move_and_turn(): .move() .turn_left() . .def draw_square(): .for i in range(4): .move_and_turn() . .draw_square()

Re: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Kent Johnson
Brandon wrote: PI = 3.14 Incidentally the math module has a more accurate value for pi: >>> import math >>> math.pi 3.1415926535897931 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Using exec with dict

2005-01-30 Thread André Roberge
First things first: I am writing a program which has, among other things, an embedded Python interpreter. So, before telling me that "using exec is unsafe because one could enter <...>", consider that the user could just as well enter <...> in the interpreter. (Having gotten this off my chest

RE: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Tony Meyer
> In that case you need it to use floating point numbers. > The easiest way is to use 1.0 but if it comes from a table > or user entry you might have to explicitly convert: > > one = 1 > other = 42 > result = float(one/other) What Alan meant, presumably, was this: one = 1 other = 42 result = fl

Re: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Alan Gauld
> The archives of the list are available here: > > > And on ActiveState's web site they are even searchable! Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Alan Gauld
> I'm trying to write a program they may involve needing to > divide 1 by another number. In that case you need it to use floating point numbers. The easiest way is to use 1.0 but if it comes from a table or user entry you might have to explicitly convert: one = 1 other = 42 result = float(on

RE: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Tony Meyer
> btw is there a place I can read everyones questions, > like I posted, or does this work my emailing a few > knowledgable people? The archives of the list are available here: (The messages from the future at the top are obviously ones where people's m

Re: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Terry Carroll
On Sun, 30 Jan 2005, Brandon wrote: > I'm trying to write a program they may involve needing to divide 1 by > another number. In the program below when I use 4 for the diameter of > the bore, and 1 for the diameter of the rod, and 60 for the PSI, the > force should be 706.8 . However the program k

Re: [Tutor] rounding

2005-01-30 Thread Kim Branson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 ahhh, the second argument to round. That will do what i want. It was fairly late and i didn't see that argument in the docs. although now i look at it in the light of day its there. neat. I've replaced by divide by 10 stuff with that. now i have di

Re: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Sean Perry
Tony Meyer wrote: Dividing two integers will give you an integer (truncated) result: If you want '1/2' to give you 0.5 (throughout your script), you can do: from __future__ import division Notice that '//' (with or without the from __future__ import) will give you the integer result. or more simply

Re: [Tutor] Append function

2005-01-30 Thread Kent Johnson
zip() is your friend. It turns rows into columns and columns into rows. I think this will do what you want, assuming all the first columns are identical (no missing rows in any files), the row values are separated by spaces or tabs, and all the data will fit in memory: def readColumns(filePath):

RE: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Tony Meyer
> I'm trying to write a program they may involve > needing to divide 1 by another number. In the > program below when I use 4 for the diameter of > the bore, and 1 for the diameter of the rod, > and 60 for the PSI, the force should be 706.8 . > However the program keeps giving me 0 for "rodarea".

[Tutor] Dividing 1 by another number ?

2005-01-30 Thread Brandon
I'm trying to write a program they may involve needing to divide 1 by another number. In the program below when I use 4 for the diameter of the bore, and 1 for the diameter of the rod, and 60 for the PSI, the  force should be 706.8 . However the program keeps giving me 0 for "rodarea". If I

[Tutor] Append function

2005-01-30 Thread kumar s
Hello: In append function instead of appending one below the other can I append one next to other. I have a bunch of files where the first column is always the same. I want to collect all those files, extract the second columns by file wise and write the first column, followed by the other colum

Re: [Tutor] rounding

2005-01-30 Thread Alan Gauld
> The round function will do what you want though not quite what you say you want :-) > > >>> round(15., -1) > 20.0 Interesting, I didn't remember the second parameter to round... let alone the fact it could be negative!! Batteries included once again! Alan G. ___

Re: [Tutor] rounding

2005-01-30 Thread Alan Gauld
> histograms for. I'd like to round the data to the nearest 10, i.e if > the value is 15.34 should we round down to 10? and conversely rounding > say 19.30 to 20. I'm thinking 15.5 and above would round up. Can anyone > point me a at a quick and painless way of achieving this? divide by 10, round

Re: [Tutor] rounding

2005-01-30 Thread Sean Perry
Kim Branson wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi all, heres a quick one for you, I have a series of data that I am using dictionaries to build histograms for. I'd like to round the data to the nearest 10, i.e if the value is 15.34 should we round down to 10? and conversely rou

[Tutor] Newbie struggling with Tkinter/canvas tags

2005-01-30 Thread Glen
As a Python/Tkinter newbie, I thought I was getting on ok... then I hit this problem. I have a canvas (c1) A group of objects are drawn on c1 and given a tag c1.addtag_all('group_A') Another group of objects are drawn, I wish to tag these 'group_B'. At the moment I 'get by' with.

Re: [Tutor] rounding

2005-01-30 Thread Kent Johnson
The round function will do what you want though not quite what you say you want :-) >>> round(15., -1) 20.0 >>> round(15.5, -1) 20.0 >>> round(14, -1) 10.0 15.34 will round to 20, not 10, which is the closest multiple of 10. Kent Kim Branson wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1

Re: [Tutor] TypeError: can only concatenate list (not "str") to list

2005-01-30 Thread kumar s
>nmr = nmrows[i] > pbr = cols[0] > print nmrow[i] +'\t'+cols[0] nmr = str(nmrows[i]) pbr = cols[0] print nmrow[i]+'\t'+cols[0] will print what you want. k --- Srinivas Iyyer <[EMAIL PROTECTED]> wrote: > Hello group, > I am trying to print rows from two lists together: > > how can i deal with

[Tutor] rounding

2005-01-30 Thread Kim Branson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi all, heres a quick one for you, I have a series of data that I am using dictionaries to build histograms for. I'd like to round the data to the nearest 10, i.e if the value is 15.34 should we round down to 10? and conversely rounding say 19.30 to

[Tutor] TypeError: can only concatenate list (not "str") to list

2005-01-30 Thread Srinivas Iyyer
Hello group, I am trying to print rows from two lists together: how can i deal with TypeError' where i have to print a list and a string. for line in pb: # tab delim text with 12 columns cols = line.split('\t') temp_seq = cols[7].split('\n') # extract 7thcol seq = temp_

Re: [Tutor] files in a directory

2005-01-30 Thread kumar s
Thank you Jay. It worked, I am V.V.happy. I tried Liam's suggestion also, but some weird things are going and I am not only getting results but also any error. I am working on that. Other thing. I a feeding my parser some coordinates specified by me, where I am asking the parser to extract the

Re: [Tutor] Ports / sockets?

2005-01-30 Thread Kent Johnson
Liam Clarke wrote: Hi, I was reading an article about 'honeytrapping' ports to slow down port scanners, and it made reference to Perl, but I was wondering, how feasible in Python is a script that waits for requests to (normally unused) ports, and then malforms a response to those requests? This i

[Tutor] Ports / sockets?

2005-01-30 Thread Liam Clarke
Hi, I was reading an article about 'honeytrapping' ports to slow down port scanners, and it made reference to Perl, but I was wondering, how feasible in Python is a script that waits for requests to (normally unused) ports, and then malforms a response to those requests? I'm aware this is illega

Re: [Tutor] question regarding python exception handling

2005-01-30 Thread Alan Gauld
> a Nutshell". In the chapter of exception handling, it says: Note that > the try/finally form is distinct from the try/except form: a try > statement cannot have both except and finally clauses, as execution > order might be ambiguous. > > I don't understand the reason why except and finally claus

Re: [Tutor] question regarding python exception handling

2005-01-30 Thread Danny Yoo
On Sat, 29 Jan 2005, Roy wrote: > I am learning about python exception handling. I am reading "Python in a > Nutshell". In the chapter of exception handling, it says: Note that the > try/finally form is distinct from the try/except form: a try statement > cannot have both except and finally clau

Re: [Tutor] carriage return on windows

2005-01-30 Thread Alan Gauld
> print "Percent completed:" + str(percent) + "\r" > > Which should send me back to the beginning of the line and overwrite it > with a new line. But instead I get: > > Percent completed: 50 > Percent completed: 51 Print always adds a newline unless you put a comma at the end. Unfortunately that

Re: [Tutor] files in a directory

2005-01-30 Thread Chad Crabtree
Well in the same vein as what the others put out there I made a verbose 'ls *.ext' so that you can see how to do it in one go. I figured this would give you enough of an example. You can hard code these things into your program. I used a construct similar to this to create an instant html ph

Re: [Tutor] files in a directory

2005-01-30 Thread Liam Clarke
Hey Kumar, You redirect stdin a lot. try this. import os def parse(filename): try: f1 = open(filename,'r') except IOError: return #Listdir returns a list of files and sub-dirs, and an attempt #to open a sub-dir raises an IOError. int = f1.read().split('\n') my

Re: [Tutor] files in a directory

2005-01-30 Thread Jay Loden
There's a few ways to accomplish this...the way that comes to mind is: ## import glob files = glob.glob("/path/to/director/*.dml") # assuming you want only .dml def spot(file): '''search for intensity spots and report them to an output

[Tutor] files in a directory

2005-01-30 Thread kumar s
Hello. I wrote a parser to parse spot intensities. The input to this parser i am giving one single file f1 = open('my_intensity_file.dml','r') int = f1.read().split('\n') my_vals = intParser(int) intParser return a list f2 = open('myvalues.txt','w') for line in my_vals: f2.write(line)