Package gui :: Package components :: Module conversion
[hide private]
[frames] | no frames]

Source Code for Module gui.components.conversion

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2010 Michael Bieri                                            # 
 4  #                                                                             # 
 5  # This file is part of the program relax.                                     # 
 6  #                                                                             # 
 7  # relax is free software; you can redistribute it and/or modify               # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation; either version 2 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # relax is distributed in the hope that it will be useful,                    # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with relax; if not, write to the Free Software                        # 
19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  # Package docstring. 
24  """Package for the different conversion tools used to bring together the GUI and API of relax.""" 
25   
26  from string import replace, strip, split 
27   
28   
29 -def str_to_float(string):
30 """Function to convert a float in a string object to a real float object. 31 32 such as: "3.5 * 1e6" to 3.5*1e6 33 34 35 @param string: Float in string that will be converted to float object. 36 @type string: str 37 """ 38 39 # Delete whitespace. 40 string = replace(string, ' ', '') 41 42 # Strip string. 43 values = split(string, '*') 44 45 # Detect exponent. 46 if '1e' in values[1]: 47 exponent = float(replace(values[1], '1e', '')) 48 if '10^' in values[1]: 49 exponent = float(replace(values[1], '10^', '')) 50 51 # Calculate float. 52 float_obj = float(values[0]) * 10**exponent 53 54 return float_obj
55