473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Beginner: String into Integer

1
I'm trying to change a string into an integer,
What I'm trying to do it something like this:

A = 3 #So A is an integer of 3
B = raw_input(">")
> A # So now B is a string of A
int(B) #This gives a error that I don't really understand. :S
print B # With out the int(B) will print A, but I want it to print 3

Any help on how to fix the int function so it'll do that?
Nov 22 '09 #1
2 1822
bvdet
2,851 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. >>> A = 3
  2. >>> B = raw_input(">")
  3. >>> B
  4. 'A'
  5. >>> int(eval(B))
  6. 3
  7. >>> 
Nov 23 '09 #2
Glenton
391 Expert 256MB
eval is a very powerful function, and one of the advantages of scripting languages.

But remember, with great power comes great responsibility! In principle someone could enter some malicious code into B, although the int function mitigates this risk a little.
Nov 25 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Fabio Papa | last post by:
I am trying to write a windows service that sends emails to clients at specific times based on information in a sql db. Since this is done for multiple cities, I start a thread for each city and...
5
by: Tom Keane | last post by:
Okay, this is probably real simple stuff for you guys. I know its simple, I used to know some of this stuff when I was learning Visual Basic in school, but yeah. Only a couple of things. ...
9
by: me | last post by:
Hi All, I am new to Classes and learniing the ropes with VB.NET express Here's my question - say I have a want to manage a list of books. Each book has an Author, Title and ISBN Now, I am...
16
by: SuperHik | last post by:
hi all, I'm trying to understand regex for the first time, and it would be very helpful to get an example. I have an old(er) script with the following task - takes a string I copy-pasted and...
7
by: fool | last post by:
Dear group, Extract the integer value present in a given string. So I tried the following: int main(void) { int val; char *data; data = malloc(sizeof *data); if(data)
4
by: Bails | last post by:
Hi Im an absolute beginner in programming and am using VB.Net Express. To start my larning I decided to do a "Real World" app instead of "hello world" and am creating a Poker Countdown clock. ...
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
26
by: MrHuggykins | last post by:
I need to display the sum and the average without initializing num and num2. I can't figure it out and it's killing me. I can't seem to get the sum or average displayed without assigning the varables...
4
by: brock | last post by:
Hi, I do apologize as I'm sure this kind of post is frowned on... But I'm stumped and just need a kick in the right direction... I'm using Visual Basic 2008 Express Edition. My goal: Take...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.