Sponsored Content
Top Forums Programming Extracting floats from a string in Python Post 302931208 by ongoto on Monday 12th of January 2015 12:31:29 AM
Old 01-12-2015
Will this work?
Code:
total = 0
for c  in '1.32', '5.32', '4.4', '3.78':
    c = float(c)
    total += c
print total

It might also work without c = float(c)
Code:
    # c = float(c)
    total += float(c)


Last edited by ongoto; 01-12-2015 at 01:37 AM..
This User Gave Thanks to ongoto For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extracting from a string

How do I extract 5th to 10th characters of string as given below stored in a shell variable. "ab cd ef gh ij kl" How is cut to be used on this? Thanks for any help. (1 Reply)
Discussion started by: preetikate
1 Replies

2. Shell Programming and Scripting

Multiplying Floats/Decimals

Is there a way that i can get something like this to work: Number=`expr 80 \* 10.69` i.e. To multiply an integer by a decimal or a decimal by a decimal etc...? thanks (10 Replies)
Discussion started by: rleebife
10 Replies

3. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

4. Shell Programming and Scripting

problem with AWK and floats below 0

Hello. I have a problem with AWK and floats below 0 in a script. It may be simplified to this line (please, take into account that my "locale" is Spanish, so the system will read "," as decimal separator): echo -1,25 2,55745 0,33 ,278 | awk '{print $1+1, $2+1, $3+1, $4+1}'... getting: -0,25... (4 Replies)
Discussion started by: JCastro
4 Replies

5. Shell Programming and Scripting

Extracting String

I am trying to extract a hyperlink from a html document using awk. I have managed to output in the format... href="index.html"> where i would like it just to output index.html. Any ideas on how i would do this? Thanks (2 Replies)
Discussion started by: adpe
2 Replies

6. Shell Programming and Scripting

integers, floats and text

I am using gawk in a dos shell in windows xp and want to read a datafile and reformat it. The datafile consists of columns of integers, floating point numbers and text strings. Each column is a fixed width and each column contains the same data type, eg all integers, all text. I am looking for a... (0 Replies)
Discussion started by: lookingfor help
0 Replies

7. Shell Programming and Scripting

Calculation with floats

I want to make computations using floats. This cannot be done with csh. ksh seem to have a problem as well. What is good shell for computations without having to resort to bc or awk? How about python? (5 Replies)
Discussion started by: kristinu
5 Replies

8. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

9. Programming

Python script for extracting data using two files

Hello, I have two files. File 1 is a list of interested IDs Ex1 Ex2 Ex3File 2 is the original file with over 8000 columns and 20 millions rows and is a compressed file .gz Ex1 xx xx xx xx .... Ex2 xx xx xx xx .... Ex2 xx xx xx xx ....Now I need to extract the information for all the IDs of... (4 Replies)
Discussion started by: nans
4 Replies

10. Shell Programming and Scripting

Extracting substring within string between 2 token within the string

Hello. First best wishes for everybody. here is the input file ("$INPUT1") contents : BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY; BASH_FUNC_message_debug%%=() { local -a L_ARRAY; BASH_FUNC_message_end_script%%=() { local -a L_ARRAY; BASH_FUNC_message_error%%=() { local... (3 Replies)
Discussion started by: jcdole
3 Replies
Viewport(3I)						    InterViews Reference Manual 					      Viewport(3I)

NAME
Viewport - scrollable view SYNOPSIS
#include <InterViews/viewport.h> DESCRIPTION
Viewport is a subclass of MonoScene that allocates its component exactly as much space as it wants (determined from its shape). This space will be clipped to the viewport's size and the viewport maintains a perspective to adjust the portion of the component that is actually displayed. If the component is smaller than the viewport's canvas, then the viewport background will be filled with a light gray pattern. PUBLIC OPERATIONS
Viewport(Interactor* = nil, Alignment = Center) Construct a new viewport. If the interactor is not nil, it is inserted as the viewport's component. The second parameter deter- mines where the component is placed relative to the viewport. Insert(Interactor*) Set the component interactor. void Change(Interactor*) A viewport does not propagate changes. Thus, if the component's shape changes the viewport simply resizes the component according to the new shape. void Remove(Interactor*) Take out the component interactor. virtual void Adjust(Perspective&) Change the viewport's perspective to the given one. This operation will cause the desired area of the component to be drawn. void AdjustTo(float px, float py, float zx, float zy) void AdjustBy(float dpx, float dpy, float dzx, float dzy) void ScrollTo(float px, float py) void ScrollXTo(float px) void ScrollYTo(float py) void ScrollBy(float dpx, float dpy) void ScrollXBy(float dpx) void ScrollYBy(float dpy) void ZoomTo(float zx, float zy) void ZoomXTo(float zx) void ZoomYTo(float zy) void ZoomBy(float dzx, float dzy) void ZoomXBy(float dzx) void ZoomYBy(float dzy) Short-hand operations for explicit manipulation of the viewport's perspective. float XPos() float YPos() float XMag() float YMag() Short-hand for retrieving information about the current perspective. SEE ALSO
Perspective(3I), Scene(3I), Shape(3I) InterViews 10 February 1988 Viewport(3I)
All times are GMT -4. The time now is 08:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy