[Tutor] Operation Speed Question

2011-11-25 Thread Charles Karl Becker
Dear Pythonistas, http://wiki.python.org/moin/PythonSpeed#Takeadvantageofinterpreteroptimizations%E2%80%8C%E2%80%8Bthis is a link I found concerning optimizing the speed of python code. Is anyone familiar with an article or wiki such as this that may cover the changes that took place in Py3K? An

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Sat, Nov 26, 2011 at 12:49 AM, Andreas Perstinger wrote: > On 2011-11-25 13:40, lina wrote: >> >> On Fri, Nov 25, 2011 at 7:19 PM, Steven D'Aprano >>  wrote: >>> >>>  f = open("some file") >>>  dehydrons = {} >>>  occurrence = {} >>>  pairs = {} >>>  for line in f.readlines(): >>>     parts = l

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Alan Gauld
On 26/11/11 00:07, Steven D'Aprano wrote: Its usually better to paste long programs into a pastebin web site and give us a link. I'd just like to say that some of us disagree with this advice. Some people (e.g. me) often read their where getting access to a browser is less convenient. Its tr

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Steven D'Aprano
Hello Mic, Mic wrote: Its usually better to paste long programs into a pastebin web site and give us a link. This saves cluttering up people mail with long messages, and also the pastebin rendering will usually be easier to read with syntax coloring etc. Please keep a attribution line when

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Steven D'Aprano
Alan Gauld wrote: On 24/11/11 16:20, Mic wrote: and then try to put these parts togheter into a large program, I decided to post my entire program. Its usually better to paste long programs into a pastebin web site and give us a link. This saves cluttering up people mail with long messages,

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Alan Gauld
On 25/11/11 21:14, Mic wrote: Alright. Sorry if I should know this, but what is a pastebin web site and how do I paste my program into a pastebin web site? A web site that you can paste stuff and then provide a link(url) that others can use to view it. You can usually specify the code style

Re: [Tutor] Do loop in Python

2011-11-25 Thread Andreas Perstinger
On 2011-11-25 14:46, stm atoc wrote: Here is the new version of the program: zvalues = [-200] # starting value hvalues = [10] # starting value increments = [1, 1, 1, 1, 1, 1, 1, 1] for N in increments: h = hvalues[-1] - N hvalues.append(h) z = zvalues[-1] + h zv

Re: [Tutor] Shortening the code.

2011-11-25 Thread Alan Gauld
On 25/11/11 17:11, Mic wrote: for making a function that calls another function with a fixed argument is command = lambda button=button: button_clicked(button) Alright! What is a fixed argument? Its onre that is the same every time the function is called. The lambda construct above is eq

Re: [Tutor] Shortening the code of a finsihed program.

2011-11-25 Thread Mic
Its usually better to paste long programs into a pastebin web site and give us a link. This saves cluttering up people mail with long messages, and also the pastebin rendering will usually be easier to read with syntax coloring etc. Alright. Sorry if I should know this, but what is a pastebin

Re: [Tutor] Weird Try..Except Error

2011-11-25 Thread Alan Gauld
On 25/11/11 12:42, nikunj.badja...@emc.com wrote: I had Python27 and Python32 both installed togethar. In Windows the PATH env variable, I had set Python27 exe and lib path. But When I do C:\> Python [PressEnter] I get 2.7 But when I run C:\> script.py [PressEnter] The script is running wi

Re: [Tutor] Shortening the code.

2011-11-25 Thread Peter Otten
Mic wrote: > >> >from functools import partial > >>I use this kind of explicit import for a few names that I use frequently, >>namely defaultdict, contextmanager, everything from itertools... >>I think of these as my personal extended set of builtins ;) > >>As to the actual partial() function,

Re: [Tutor] Shortening the code.

2011-11-25 Thread Mic
>from functools import partial I use this kind of explicit import for a few names that I use frequently, namely defaultdict, contextmanager, everything from itertools... I think of these as my personal extended set of builtins ;) As to the actual partial() function, you probably don't see

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Andreas Perstinger
On 2011-11-25 13:40, lina wrote: On Fri, Nov 25, 2011 at 7:19 PM, Steven D'Aprano wrote: f = open("some file") dehydrons = {} occurrence = {} pairs = {} for line in f.readlines(): parts = line.split() # convert to ints parts = [int(s) for s in parts] pair = frozenset(pa

Re: [Tutor] Weird Try..Except Error

2011-11-25 Thread Steve Willoughby
On 25-Nov-11 04:42, nikunj.badja...@emc.com wrote: Hi All, Thanks for the info. I had Python27 and Python32 both installed togethar. In Windows the PATH env variable, I had set Python27 exe and lib path. But When I do C:\> Python [PressEnter] I get 2.7 But when I run C:\> script.py [PressE

Re: [Tutor] Do loop in Python

2011-11-25 Thread stm atoc
Thank you so much for your reply. It was very helpful information and I used it in order to improve the program Here is the new version of the program: zvalues = [-200] # starting value hvalues = [10] # starting value increments = [1, 1, 1, 1, 1, 1, 1, 1] for N in increments: h = hva

[Tutor] sensing EOF in Python 3.1

2011-11-25 Thread Cranky Frankie
From: Steven D'Aprano wrote: <> Right, thanks. <> I want to include this info in my presentation because it shows how data structures can be externalized. <> Still though, that is important. < Sarcasm aside, what else could "import pickle" mean other than import > the pickle module?>> I wa

Re: [Tutor] Weird Try..Except Error

2011-11-25 Thread Nikunj.Badjatya
Hi All, Thanks for the info. I had Python27 and Python32 both installed togethar. In Windows the PATH env variable, I had set Python27 exe and lib path. But When I do C:\> Python [PressEnter] I get 2.7 But when I run C:\> script.py [PressEnter] The script is running with Python3.2 , thts weir

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Fri, Nov 25, 2011 at 7:19 PM, Steven D'Aprano wrote: > lina wrote: >> >> On Fri, Nov 25, 2011 at 5:06 PM, Steven D'Aprano >> wrote: > >>> pair = frozenset(('66', '69')) >>> pairs[pair] = pairs.get(pair, 0) + value >> >> I don't get this "pairs.get" part. > > The "get" method does a look-up on

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Alan Gauld
On 25/11/11 08:41, lina wrote: pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of those two keys, above is a very simple example: here is the (failed) code: for k, v in pair

Re: [Tutor] Weird Try..Except Error

2011-11-25 Thread Peter Otten
nikunj.badja...@emc.com wrote: > Please look at the snippet below. > When I am running my module its giving me following error. > Using : Python 2.7, windows Env. > > {{{ > # User defined modules > try: > from scripts import precheck > from scripts import input > from scripts import v

[Tutor] Weird Try..Except Error

2011-11-25 Thread Nikunj.Badjatya
Hi All, Please look at the snippet below. When I am running my module its giving me following error. Using : Python 2.7, windows Env. {{{ # User defined modules try: from scripts import precheck from scripts import input from scripts import validate from scripts import logsetup

Re: [Tutor] Do loop in Python

2011-11-25 Thread Steven D'Aprano
stm atoc wrote: Hi there, I am a new python user. I have a question regarding do loop. This is a simple program that I have written: - N=10 h=10.0 # [micrometer] z=-200.0 # [micrometer] You define N, h and z here, but later on you use them as loop variables. So these t

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Steven D'Aprano
lina wrote: On Fri, Nov 25, 2011 at 5:06 PM, Steven D'Aprano wrote: pair = frozenset(('66', '69')) pairs[pair] = pairs.get(pair, 0) + value I don't get this "pairs.get" part. The "get" method does a look-up on a dict, but instead of failing if the key is missing, it returns a default val

Re: [Tutor] Do loop in Python

2011-11-25 Thread stm atoc
regarding to the last email: what I am trying to do is seeing the variation of 'nu' over (changes of) 'z'. My concern is how to arrange this! Basically, I am not able to define the variation of nu by z ( 1 to 200). I am looking for a statement to show the changes of 'nu' for each step of z (

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
for key, value in pairs.items(): if key[::-1] in pairs.keys() and pairs[key] != 0: pairs[key] += pairs[key[::-1]] pairs[key[::-1]]=0 for k, v in pairs.items(): if v != 0: print(v,k) Now very trivial, but works.

Re: [Tutor] Do loop in Python

2011-11-25 Thread Charles Becker
Sue, I'm not familiar with FORTRAN, and since I'm not completely sure what you're trying to accomplish please take this simply as an 'educated guess'. My guess is that you're not getting the curve because Z is only defined to one decimal location (1/10th) precision and probably needs higher p

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
#!/usr/bin/python3 dehydrons={} pairs={} #frozen set way pairs fs_pairs={} occurence={} total=0 dictionary={} candidate_dehydron={} if __name__=="__main__": with open("dehydron_refined_data_18.txt","r") as f: for line in f.readlines(): parts=line.split() #pai

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Fri, Nov 25, 2011 at 5:19 PM, Christian Witts wrote: > On 2011/11/25 11:15 AM, lina wrote: > > On Fri, Nov 25, 2011 at 5:05 PM, Christian Witts > wrote: > > On 2011/11/25 10:41 AM, lina wrote: > > pairs > > {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} > > > such as here ('66', '69')

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Fri, Nov 25, 2011 at 5:06 PM, Steven D'Aprano wrote: > lina wrote: > > pairs >> >> {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} >> >> >> such as here ('66', '69') and ('69', '66') is one key, >> >> I wanna keep only one and add the value of those two keys, above is a >> very

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Christian Witts
On 2011/11/25 11:15 AM, lina wrote: On Fri, Nov 25, 2011 at 5:05 PM, Christian Witts wrote: On 2011/11/25 10:41 AM, lina wrote: pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of th

[Tutor] Do loop in Python

2011-11-25 Thread stm atoc
Hi there, I am a new python user. I have a question regarding do loop. This is a simple program that I have written: - N=10 h=10.0 # [micrometer] z=-200.0 # [micrometer] num = 0.05 #m**2/s dz = 1.0 nuh=[] tmax=3600 dt=20. nu=[]height = arange(z*dz,0,dz) outfile=open('nu.da

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Fri, Nov 25, 2011 at 5:05 PM, Christian Witts wrote: > On 2011/11/25 10:41 AM, lina wrote: > > pairs > > {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} > > > such as here ('66', '69') and ('69', '66') is one key, > > I wanna keep only one and add the value of those two keys, above is a

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Christian Witts
On 2011/11/25 10:41 AM, lina wrote: pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of those two keys, above is a very simple example: here is the (failed) code: for k, v in

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Steven D'Aprano
lina wrote: pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of those two keys, above is a very simple example: Which one do you want to keep? If the order ('66', '69') is unimporta

[Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
>>> pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of those two keys, above is a very simple example: here is the (failed) code: for k, v in pairs.items(): if str(k