Linked Questions

2775 votes
33 answers
4.9m views

How can I convert an str to a float? "545.2222" -> 545.2222 Or an str to a int? "31" -> 31 For the reverse, see Convert integer to string in Python and Converting a float to ...
Tristan Havelick's user avatar
59 votes
5 answers
187k views

I'm trying to read in a string representation of a Tuple from a file, and add the tuple to a list. Here's the relevant code. raw_data = userfile.read().split('\n') for a in raw_data : print a ...
Sinthet's user avatar
  • 903
29 votes
2 answers
3k views

I have a website where the user enters math equations (expressions) and then those equations are evaluated against data (constants) provided by the website. The math operations needed include symbols, ...
Mikko Ohtamaa's user avatar
9 votes
2 answers
4k views

OK. I know the experts have spoken and you should not ever use python's eval() on untrusted data, ever. I'm not smarter than the rest of the world, and shouldn't even try this. But! I'm going to, ...
Nate's user avatar
  • 4,777
4 votes
3 answers
2k views

I have a column Column1 in a pandas dataframe which is of type str, values which are in the following form: import pandas as pd df = pd.read_table("filename.dat") type(df["Column1"].ix[0]) #...
ShanZhengYang's user avatar
3 votes
2 answers
1k views

Say I have a list with mathematical operators in it, like this operators = ['+','-','*','/'] And I am taking a random operator from here, like this op = random.choice(operators) If I take two ...
DW_0505's user avatar
  • 109
0 votes
2 answers
1k views

I'm trying to display a graph with a formula from the user using matplotlib in Python 3.6, but I'm having some problems. I tried import numpy as np import matplotlib.pyplot as plt def graph(x_range):...
HF1's user avatar
  • 495
-1 votes
3 answers
296 views

How can I get a Python list from a text file with the following contents? 'hallo' 'hallo\n' '\x00' * 1 100 '400 + 2' 400 + 2 For example: ll = ["hallo", "hallo\n", "\x00", 100, 402, 402] with the ...
mr.wolle's user avatar
  • 1,394
0 votes
0 answers
571 views

I have a Pandas dataframe that was saved as a csv by using command: file.to_csv(filepath + name + ".csv", encoding='utf-8', sep=";", quoting=csv.QUOTE_NONNUMERIC) I know that while saving, all of the ...
LeeRan's user avatar
  • 1
0 votes
3 answers
121 views

How would you parse a list in python to combine integer while leaving the operator of an equation alone? list =['(' ,'1', '+', '2', ')', '+', '(', '2', '0'. '0', '/', '2', '5', ')'] I would like to ...
user8415791's user avatar
1 vote
1 answer
125 views

I am trying to write a very simple code which I will feed it two numbers (with the input function) and it'll give me a result based on these numbers. When the numbers are just numbers (e.g., 12 or 15) ...
N. Doe's user avatar
  • 75
1 vote
1 answer
128 views

I would like to enable the user to input a formula for calculation given some parameters. What is the best way to do this without making a security hole? Kind of like this: def generate_bills(): ...
William Wino's user avatar
  • 3,929