string « integer « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » integer » string 

1. Python Newbie: Returning Multiple Int/String Results in Python    stackoverflow.com

I have a function that has several outputs, all of which "native", i.e. integers and strings. For example, let's say I have a function that analyzes a string, and finds both ...

2. Strip final 0 off a python string    stackoverflow.com

#!/usr/bin/env python
import os, sys, subprocess, time
while True:    
    print subprocess.call("xsel", shell=True);
    time.sleep(1);
Takes an entry from the clipboard and prints it, every 1 ...

3. [Python]String and integer concatenation    stackoverflow.com

I want to create string in a for.

# Create string0, string1 ..... string10
for i in range [1,10]:
 string="string"+i
But I have returned an error because i is not a string but integer. How ...

4. How to make "int" parse blank strings?    stackoverflow.com

I have a parsing system for fixed-length text records based on a layout table:

parse_table = [\
    ('name', type, length),
    ....
    ('numeric_field', int, ...

5. "Function object is unsubscriptable" in basic integer to string mapping function    stackoverflow.com

I'm trying to write a function to return the word string of any number less than 1000. Everytime I run my code at the interactive prompt it appears to work without issue ...

6. How to add the binary of a int with the binary of a string    stackoverflow.com

Basically i want to be able to get a 32bit int and attach its binary to the binary of a string. E.g. (IM going to use 8bit instead of 32bit) i want 255 + hi 11111111 ...

7. Integer to Unique String    stackoverflow.com

There's probably someone else who asked a similar question, but I didn't take much time to search for this, so just point me to it if someone's already answered this. I'm trying ...

8. How to concatenate strings and integer in a variable    stackoverflow.com

I have a variable of int type. I am running for loop on it and making a variable with adding some string info.

a = 5 // variable with integer value
list = '' ...

9. How can I write this Python code in Java (parsing a string of ints, using delimiter)?    stackoverflow.com

Python code:

str = "123;456;789"
strlist = str.split(";")
strlist = [int("%s" % s) for s in strlist]
print strlist

10. Being able to detect int's in strings, Python    stackoverflow.com

I'm trying to seperate a number from a string in python. Basically I want it so if color == 'gray' + a number, then it will return that number. For example ...

11. Python integers to strings    stackoverflow.com

Could you say me, how to write a function, which takes as its (one an only) argument a list of numbers and returns a list of string representations of those numbers? For ...

12. Unscriptable Int Error for String Slice    stackoverflow.com

I'm writing a webscraper and I have a table full of links to .pdf files that I want to download, save, and later analyze. I was using beautiful soup and ...

13. How to plot confusion matrix with string axis rather than integer in python    stackoverflow.com

I am following a previous thread on how to plot confusion matrix in Matplotlib. The script is as follows:

from numpy import *
import matplotlib.pyplot as plt
from pylab import *

conf_arr = [[33,2,0,0,0,0,0,0,0,1,3], [3,31,0,0,0,0,0,0,0,0,0], ...

14. Why am I seeing "TypeError: string indices must be integers"?    stackoverflow.com

I'm playing with both learning python and trying to get github issues into a readable form. Using the advice on convert from json to csv using python I came up ...

15. How are basic data types (strings and integers) implemented in Python and Perl    stackoverflow.com

I've been wondering lately how various operations I perform on basic types like strings and integers work in terms of performance, and I figure I could get a much better idea ...

16. Using a variable as both an integer and a string (Python)    stackoverflow.com

I would like to use a variable as an integer and a string in the same statement. In BASIC, it would look like this:

cnt = 0

while cnt < 10:
   ...

17. TypeError: cannot concatenate 'str' and 'int' objects    stackoverflow.com

I'm learning Python now, yay! Anyway, I have small problem. I don't see problem in here:

x = 3
y = 7
z = 2

print "I told to the Python, that the first variable ...

18. python sys.argv differentiate int and string    stackoverflow.com

Simply put, how can I differentiate these two in test.py:

python test.py 1
python test.py '1'
Workaround is OK.

Edit:

  1. This workaround looks cool but too complex: argparse
  2. Let the invoker specify args later, in ...

19. Python integer issues    stackoverflow.com

EDIT: SOLVED--SOURCE CODE HERE: http://matthewdowney20.blogspot.com/2011/09/source-code-for-roku-remote-hack.html thanks in advance for reading and possibly answering this. So I have a slice of code that looks like this (the commands Down() Select() and ...

20. Get int-type from 'int' string    stackoverflow.com

In Python, given the string'int', how can I get the type int? Using getattr(current_module, 'int') doesn't work.

21. How do I use a Radiobutton to input a set integer to a variable?    stackoverflow.com

I have used the line of code below to input a variable for "BAI_var1" in a multiple choice command line software.

BAI_var1 = input ("Please enter 0 for not ...

22. How to parse a string into two different strings based on first instance of an integer? (Python)    stackoverflow.com

I'm trying to take a string like "PR405j" and separate it into two strings. In this instance, the two strings would be "PR" and "405j." There are a variety of strings ...

23. How can I create variables by iterating through a combination of integers and strings?    stackoverflow.com

So I want to create variables by looping through some sort of name assigning statement or function. I want to end up having variables titled "t1, t2, t3" etc. How can ...

24. Beginner: String into Integer    bytes.com

25. problem with input: get input as int , turn into a string    dreamincode.net

In python 2.x that was possible, in Python 3.x it's a little harder. If you want in to be one of several types, then I would do something like this: x = input("yo: ") if x.isdigit(): #int! elif x.replace('.','').isdigit(): #double! elif x[0] = '[': #list! elif x.lower() == "true" or x.lower() == "false": #bool baby! else: #String! However, you really should ...

26. How to process userinput strings or integers?    dreamincode.net

I am building a basic numerology calculator. I want to know how to take in the raw_input(), process it via a characterdict which looks like def Main(name): #generating a lettermap. CharacterMapDict {'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':8,'i':9,'j':1,'k':2,'l':3,'m':4,'n':5,'o':6,'p':7,'q':8,'r':9,'s':1,'t':2,'u':3,'v':4,'w':5,'x':6,'y':7,'z':8} This is supposed to map the letters to numbers in the dictionary. The user is supposed to enter their name via Raw_input() or Input(), or whichever method can be ...

27. Concatenating a String and int in Python    dreamincode.net

28. Error msg about can't Concatenate string and integer    python-forum.org

Error msg about can't Concatenate string and integer by MPachlhofer Fri Nov 21, 2008 10:48 am Ok. This is probably a simple problem, but I have stared at my code for a while now and I can't see the problem. I have written a simple script for use in ArcGIS to make a folder or directory on my M:\ drive. ...

30. Reading integer and string from same line    python-forum.org

rfile = open("data.txt",'r') # change to your file value = {} for r in rfile: val,key = r.split() value[key] = float(val) exec('%s = %s' %(key,val)) # or exec into variables rfile.close() # don't forget to close print value #dict method print value['taco'] print value['pizza'] print #exec method print taco ...

31. String entered into int(raw_input)    python-forum.org

String entered into int(raw_input) by Tamer Wed Mar 16, 2011 6:52 pm Hey im making a basic script for my class that generates a random number and then allows the user to attempt to guess the number. I have all of this done but one of the criteria is that the user needs to be able to quit at any ...

32. Entering only strings and giving error for integers.    python-forum.org

enteredNumbers = "0" while len(enteredNames) > 0: try: enteredNumbers = int(raw_input("Enter Numbers or press ENTER to quit: ")) except(ValueError): print "Wrong data entered! Please enter a Number."

33. Entering string in int(raw_input(    python-forum.org

I'm making a guessing game where I take an integer from the user input. When I enter a string into the user input the program errors/crashes like so: ValueError: invalid literal for int() with base 10: 'STRING' How would I make Python give an error message such as "Error, please enter an integer!" when I enter a string into the user ...

34. Raising an syntax error exception for string to integer    python-forum.org

I am having problems trying to solve the following problem, any help would be appreciated- 'You are to write a function string2int that attempts to convert a string to an integer. If the string does represent an integer then that integer should be returned. If the string does not represent an integer then you should raise a syntax exception (raise syntax ...

35. [3.1.1] Concatenate String and Int    python-forum.org

Really easy question for 3.1.1 Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 I'm using an old book "http://www.amazon.com/Python-Programming-Absolute-Beginner-Michael/dp/1592000738" which is based on 2.1 (i think) but i'm using the version described above. The code is as follows: Code: Select all # Trust Fund Buddy - Bad # Demonstrates a logical error print ("Trust Fund ...

36. string to int    python-forum.org

38. Newbie question about print strings and ints    python-forum.org

PLEASE TYPE IN LOWER CASE What measurement are you converting from?: centimetres What measurement do you want to convert to?: millimetres How many centimetres are there?: 10 Traceback (most recent call last): File "C:\Documents and Settings\officeworks\Desktop\conversion.py", line 8, in print(amount + ' ' + unit1 + ' equals ' + amount*10 + ' ' ...

39. parse integers from a string    python-forum.org

I have a probably simple question....I need to extract all the integers from a string, returning an array or list of them. I suspect this requires regular expressions? I've not been able to find out how yet. here's an example, like a line from a file: If I have the string 'your mother 42 was a hampster 77 and your 54 ...

40. Integer to string help?    python-forum.org

I need to take an entered integer such as 1234 Split it into 1+2+3+4 and get the sum of 10 and now for the integer to be 10 and repeat the process until you cant anymore. I am having trouble figuring out how to split these number up after a number has been entered in as a raw_input. If you cant ...

41. Saving strings and integers; for running program next time..    python-forum.org

There are plenty of ways to save strings and integers. The simplest is probably shelve. To quote the shelve documentation: To summarize the interface (key is a string, data is an arbitrary object): import shelve d = shelve.open(filename) # open, with (g)dbm filename -- no suffix d[key] = data # store data at key (overwrites old data if # using an ...

42. How to check if a string is an int    python-forum.org

Basically the same as ochichinyezaboombwa's, except returns False if it's a float. Code: Select all def is_int(s): if type(s) == type(1): # not a string, it's already an int return True if type(s) == type(''): ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.