473,320 Members | 1,821 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,320 software developers and data experts.

integer from argument

Hello, I just started learning Python today. I already know Perl, and they have a veery similar syntax, so it's not really hard. But I cannot manage to get an integer from an argument.
If i use sys.argv, it only gets it as a "string". But I need it as an integer.
If I try to use it in a calculation, I get:
TypeError: cannot concatenate 'str' and 'int' objects

Help?

Thanks
May 9 '07 #1
2 1435
bvdet
2,851 Expert Mod 2GB
Hello, I just started learning Python today. I already know Perl, and they have a veery similar syntax, so it's not really hard. But I cannot manage to get an integer from an argument.
If i use sys.argv, it only gets it as a "string". But I need it as an integer.
If I try to use it in a calculation, I get:
TypeError: cannot concatenate 'str' and 'int' objects

Help?

Thanks
Expand|Select|Wrap|Line Numbers
  1. >>> s = '1234'
  2. >>> type(s)
  3. <type 'str'>
  4. >>> i = int(s)
  5. >>> type(i)
  6. <type 'int'>
  7. >>> 
Sometimes the most obvious is the hardest to see.
May 9 '07 #2
Thanks for your reply.
I started looking into it, and by some testing, I saw that python uses the filename as sys.argv[0](perl doesn't do this, so I wasn't expecting that), so that's the reason a = int(s) didn't work. I used sys.argv[1] and everything is working perfectly.

Thanks a lot :)
May 9 '07 #3

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

Similar topics

14
by: Bart Samwel | last post by:
Hi everybody, I would really like some help explaining this apparent discrepancy, because I really don't get it. Here is the snippet: void foo(int&); void foo(int const&); ...
1
by: WindAndWaves | last post by:
Goodmorning Gurus Here is another of my questions..... When adding code to a control then access sometimes puts in a couple of 'parameters'. Can anyone tell me what the use of them is. I have...
18
by: a | last post by:
short s; long l; s= -2; l= -3; printf("% _ %_",s, l); What characters should be filled out in the formatted string for output? Thanx
11
by: nephish | last post by:
Hello there, i need a way to check to see if a certain value can be an integer. I have looked at is int(), but what is comming out is a string that may be an integer. i mean, it will be formatted...
4
by: metalinc | last post by:
hi...im new to C programming...need help...tried to run this code but got this error fork.c: In function ‘parse’: fork.c:44: warning: comparison between pointer and integer fork.c:51: warning:...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
17
by: matevzb | last post by:
I've ran into some fishy code that, at first glance, is buggy, but it seems to work correctly and none of the compilers I've tried (five so far, on various systems) gives any warnings. The code:...
7
by: Spoon | last post by:
Hello everyone, In my code, I use uint16_t (exactly 16-bit-wide unsigned integer type) and I need to print their value in base 10. ...
130
by: euler70 | last post by:
char and unsigned char have specific purposes: char is useful for representing characters of the basic execution character set and unsigned char is useful for representing the values of individual...
3
by: amija0311 | last post by:
Hi, I am new using DB2 9.1 database by windows base. I want to query the data that contain string then translate the string into integer using DB2. The problems is If the data is null, i got the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.