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 ... |
#!/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 ... |
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 ... |
I have a parsing system for fixed-length text records based on a layout table:
parse_table = [\
('name', type, length),
....
('numeric_field', int, ...
|
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 ... |
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 ... |
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 ... |
|
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 = '' ...
|
Python code:
str = "123;456;789"
strlist = str.split(";")
strlist = [int("%s" % s) for s in strlist]
print strlist
|
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 ... |
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 ... |
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 ... |
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], ...
|
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 ... |
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 ... |
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:
...
|
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 ...
|
Simply put, how can I differentiate these two in test.py:
python test.py 1
python test.py '1'
Workaround is OK.
Edit:
- This workaround looks cool but too complex: argparse
- Let the invoker specify args later, in ...
|
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 ... |
In Python, given the string'int', how can I get the type int? Using getattr(current_module, 'int') doesn't work.
|
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 ...
|
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 ... |
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 ... |
|
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 ... |
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 ... |
|
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. ... |
|
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 ... |
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 ... |
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." |
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 ... |
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 ... |
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 ... |
|
|
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 + ' ' ... |
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 ... |
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 ... |
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 ... |
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(''): ... |