Decimals reading Python


 
Thread Tools Search this Thread
Top Forums Programming Decimals reading Python
# 1  
Old 09-05-2015
Decimals reading Python

Hello,

i'm new in python. Consider that i have this function that read me some data from a serial :

Code:
def GetData():
  line = open(serialx).read()
  hash = line.find("#")
  when = line[:hash]
  count = line[hash+1:-1]
  # print when, count, line
  return (float(when), int(count))

it gives me the result with tre digits like 301 300 301 etc.. how i can have more decimals (and precision reading) to achieve a result of ex 3000001 eventually using another counter too like +001 -001?

Thank you

Regards

Last edited by Scrutinizer; 09-05-2015 at 07:48 AM.. Reason: code tags
# 2  
Old 09-05-2015
Hi Board27,

This is the information I have parsed so far.
return (float(when), int(count)) will give you a tuple comprised of a float and an int, but you say -- "it gives me the result with tre digits like 301 300 301 etc ..."
I do not understand, there is no tuple but a number. You say -- "how i can have more decimals (and precision reading)", however there are no decimals in your post.
Somewhat you want to make the number three hundred and one (301) into the number three millions and one (3000001)

A decimal would be 0.301 and if you want to add seven digits of precision it will become 0.3010000, never 0.3000001

Please, could you clarify a bit more your request? Perhaps, could you consider posting the content of the file serialx?

Last edited by Aia; 09-05-2015 at 03:54 PM.. Reason: Adds request for clarification and serialx file
This User Gave Thanks to Aia For This Post:
# 3  
Old 09-05-2015
Thanks, floating points numbers did it.

Thanks

regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python: Redirecting to tty and reading from tty

In bash, you can do something like this: #!/bin/bash echo -n "What is your name? " > /dev/tty read thename < /dev/tty How can I do the same in python? I have a python script that has the following content: #!/usr/bin/python2.7 import getpass import sys import telnetlib import... (2 Replies)
Discussion started by: SkySmart
2 Replies

2. Programming

Python Reading Individual files and Regex through them

As a newbie to Python, I am trying to write a script in which is will add all the log files (*.log) from within a directory to a list, open the files and search for an ip using a regex and single it out (appending the ip's to the list). So far, I have: import re, os def list_files() content = ... (4 Replies)
Discussion started by: metallica1973
4 Replies

3. Programming

Python reading from a file

Hello everyone, I've been learning some python (I was using other commercial software before), and doing plots from data stored on files as X and Y pairs has not been an issue. Know, I have some files that look like this: <Descriptive string> <some "random" number> <number of X values:nx>... (0 Replies)
Discussion started by: jaldo0805
0 Replies

4. Programming

Python reading from a file

Hello everyone, I've been learning some python (I was using other commercial software before), and doing plots from data stored on files as X and Y pairs has not been an issue. Know, I have some files that look like this: <Descriptive string> <some "random" number> <number of X values:nx>... (0 Replies)
Discussion started by: jaldo0805
0 Replies

5. Shell Programming and Scripting

Round up the decimals

Hi All, I would like to do the following in the shell script 561.76 to 562 I tried using this echo 'scale=0; 749 * 75 /100 ' | bc but just returned only 561 Please help me . I appreciate your help Thanks rajeevm (13 Replies)
Discussion started by: rajeevm
13 Replies

6. UNIX for Dummies Questions & Answers

Regarding Decimals in Cshell

Hello... I am new to unix and I am wondering if in a C-shell script , Are we supposed to use only whole numbers........ for example..if a program needs to calculate the average of some numbers........ @ avg = (($1 +$2 + $3)/3)) is returning a whole number.........How can a decimal be achieved... (1 Reply)
Discussion started by: ravindra22
1 Replies

7. Shell Programming and Scripting

Decimals in TCSH

Hello, I want to run a loop with non-integer values (which I know I can't) so I've created a loop of integers and divided it by 10. However, these values are always rounded down to 1 significant figure. How do I get the script to keep and use the decimal value? My script is as follows #... (1 Reply)
Discussion started by: DFr0st
1 Replies

8. Shell Programming and Scripting

Help Reading XML files in Python: Urgent

OK so my objective is to create a python program that will parse an XML file(input.xml), then the program will create an mxml(output.mxml) file. In the program (.py) i need to read between CDATA so that I would get an output the CDATA code in the input.xml INPUT.XML <!]> ... (2 Replies)
Discussion started by: dcfivesixfive
2 Replies

9. Shell Programming and Scripting

convert Regular decimals to Packed decimals

Hi, I am trying to find if there is a way to convert regular decimal values to Paced decimal values. I tried to find a c program but I could get a Packed converted to regular decimal not the other way round. If not unix please let me know if any other progrimming language I can use to do... (2 Replies)
Discussion started by: mgirinath
2 Replies

10. Shell Programming and Scripting

handle decimals

Hi All, How we can handle decimals in (Float) in UNIX. a=73 b=5 c=`expr a / b` i am getting 14 but i need full 14.6 . Can any one help me pls? (1 Reply)
Discussion started by: subin_bala
1 Replies
Login or Register to Ask a Question