0
votes
1answer
5 views

ConfigParser.get returning a string need to convert it to section

I want to use the return value of RawConfigParser.get ('somesection', 'someoption') as the section for another RawConfigParser.get, but in practice the result is a doubly encased string. section = ...
2
votes
1answer
37 views

Convert empty string to zero

I'm doing something like this to sum up all values from start to end. big_list = line.split(delim) sum( [int(float(item)) for item in big_list[start:end]] ) Sometimes an element of big_list may be ...
0
votes
2answers
30 views

String to list of certain characters

So I am working in Python and I would like to turn a string into a list of characters VALID_SYMBOLS is a list of characters and EMPTY_SYMBOL is a dash. I would like to loop over each element in ...
1
vote
8answers
65 views

How to split up a long list using \n

Here is a long string that I convert to a list so I can manipulate it, and then join it back together. I am having some trouble being able to have an iterator go through the list and when the iterator ...
0
votes
1answer
43 views

split and join columns in a file

I have a file in the following format score div del ins sequence begin end (left) repeat class/family begin end (left) ID 35 5.1 8.2 0.0 chrI 2 62 ...
-3
votes
2answers
29 views

useragent from txt file python

i would like my user agent to use diffrent agent on evry try i have txt file with all available agent strings i would to use them...... any idea ? in 2 word use agents randomly import sys import ...
-6
votes
2answers
56 views

How to reverse the order of letters in a string in python

In python, how do you reverse the order of words in a string and also reverse the order of the letters in the word. For example, if the input is: Hello world The output should be: olleH dlrow ...
0
votes
0answers
23 views

ArcPy/Python: How can I add a word into a string infront of a specific word of that string?

I'm working with Arcpy to edit large shapefiles. I'm currently using the UpdateCursor function to find and update a type attribute based on the feature's name. In this case, changing buoys into ...
-2
votes
0answers
19 views

error message when string entered in int(raw_input()) [duplicate]

I am new to python so i need some help. Below is a simple program that require the user to answer x = int(raw_input("how much is 1+1? : ")) if x == 2 : print ("True!") else: print ...
0
votes
2answers
42 views

Boolean to string with lowercase

Can the str.format() method print boolean arguments without capitalized strings? I cannot use str(myVar).lower() as argument of format, because I want to preserve the case of the letters when myVar ...
-1
votes
1answer
28 views

Looping through Python string in search for keywords

I have created a little program that counts kewords in string. As you see, keywords are stored in txt file. Today I realized that if a word in string repeats then keyword counter wont increase its ...
0
votes
1answer
38 views

How to match exception with double character with Python regular expression?

Got this string and regex findall: txt = """ dx d_2,222.22 ,, dy h..{3,333.33} ,, dz b#(1,111.11) ,, dx-ay relative 4,444.44 ,, """ for n in re.findall( ...
-2
votes
2answers
34 views

Turn to String in Python

I have created the variable block = {} and mapped a string to it. I think its a set of sets but I'm not sure since i get errors when I'm trying to convert it to a string. when i print it i get {(0, ...
1
vote
3answers
23 views

Reading file and comparing to dictionary

I'm stuck on a problem and would appreciate any hints/advice. Here is my code so far: name = input("Enter text file name\n") radio = {'a':'alfa', 'b':'bravo', 'c':'charlie', 'd':'delta','e':'echo', ...
0
votes
1answer
32 views

AttributeError: 'str' object has no attribute 'string'

I am getting the error: AttributeError: 'str' object has no attribute 'string' So here is the code: lnumber=input("please type in numbers:") lnumber.string().sort() print(lnumber) What I'm ...
0
votes
1answer
29 views

Python string has a character that is present in Linux but missing in Windows

This is the first question I'm posting so please pardon my ignorance. I am using python to write into files and then read them. Using the usual suspects (file.read(), file.write()) The code is being ...
2
votes
2answers
44 views

Removing list of words from a string

I have a list of stopwords. And I have a search string. I want to remove the words from the string. As an example: stopwords=['what','who','is','a','at','is','he'] query='What is hello' Now ...
-1
votes
1answer
24 views

Python: sort list of strings in order that they appear in another string

I am looking for a way to sort a list in order of appearance in another string, so that the the follow code thelist = ["a", "b", "c"] thestring = "b c a" will be able to be sorted into ["b", "c", ...
-1
votes
3answers
20 views

Converting a Text File to a String in Python

I am new to python and am trying to find the largest word in the alice_in_worderland.txt. I think I have a good system set up ("See Below"), but my output is returning a "word" with dashes connecting ...
0
votes
3answers
43 views

How to extract substring with base part of path string

There are several questions about string manipulation, but I can't find an answer which allows me to do the following -- I thought it should have been simple... I have a DataFrame which includes a ...
1
vote
2answers
38 views

(python 2.7) Is it possible to push all existing lines of a text file down and write something on first line?

As the title suggests, if I have an existing text file with the following content: 0:'Hello' 1:'This is Line 1' 2:'This is Line 2' Is it possible in any way to probably push everything down a line ...
-1
votes
3answers
38 views

need advice on strings/numbers Python.3x

So there is my code so far, idea is to count number of each characters and it works, but the tweak is I need somehow to replace number with "stars" ('*'). Let me make example so it's easier to ...
1
vote
1answer
28 views

python-string.replace() won't work [duplicate]

So, my extremely nice teacher gave me and my computer science class a whole new programming language to learn by ourselves- Python. here's an excercise (sorry if it's a bad translation-I'm not from an ...
2
votes
2answers
22 views

How to split utf-8 string with a number ahead it in python?

I got a raw utf-8 string: u'1\u670d-\u82f1\u96c4\u96c6\u7ed3' And I convert it to string s = str(u'1\u670d-\u82f1\u96c4\u96c6\u7ed3'.encode('utf8')) print s ...
1
vote
3answers
41 views

stripping strings from “string1234”

I'm new to python and I would like to use this beautiful language in my research of data mining. I got a large data file in hands now and unfortunately the samples identities are defined as strings ...
1
vote
2answers
27 views

Counting Instances of Consecutive Duplicate Letters in a Python String

I'm trying to figure out how I can count the number of letters in a string that occur 3 times. The string is from raw_input(). For example, if my input is: abceeedtyooo The output should be: 2 ...
0
votes
3answers
42 views

Python, how to get substring between two known words

The text is like: <CUSTOMER_ID COL_ID>="4000.01">79997/CUSTOMER_ID> <CUSTOMER_ID COL_ID>="4000.01">799/CUSTOMER_ID> I want to get the number of "79997" and "799" how to ...
1
vote
1answer
44 views

Some issues with Python regex findall

Got string source : string =""" html,, head,, profile http://gmpg.org/xfn/11 ,, lang en-US ,, title,, Some markright page. ,,title ,,head """ ...
3
votes
1answer
50 views

Regex group match exactly n times

I have to validate next string format: text-text-id-text Separator is character '-'. Third column must always be id. I wrote next regex (in python) which validates string: import re s = ...
1
vote
5answers
59 views

Function to get the length of the longest string

I want to define a function that will get the length of the longest string in a variable. I do the below, using the * before strings so that it includes all arguments. But when I test my function, ...
-1
votes
1answer
27 views

Combining get() method and %s string

I'm not sure if combining get() and string is my problem. I'm sure its not my only problem but here is the code. It returns an Attribute error 'str' has no attribute 'get'. Thanks. for i in ...
0
votes
3answers
46 views

Python: creating a variable using retrieved string name

This may be convoluted/unsafe, but I'd appreciate if someone could let me know if there is a way to do the following in Python or not. 1) Using a list of strings (henceforth called the alpha list), ...
3
votes
2answers
38 views

Convert unicode representation of number to ascii string

I've been looking for a simple way to convert a number from a unicode string to an ascii string in python. For example, the input: input = u'\u0663\u0669\u0668\u066b\u0664\u0667' Should yield ...
-1
votes
1answer
47 views

Could Python str.join() coerce its arguments to strings?

Here's a transcript of what I want to do. It currently fails in both Python 2.7 and 3.4: >>> a = [3,4,5] >>> ','.join(a) Traceback (most recent call last): File "<stdin>", ...
0
votes
0answers
49 views

Python prepend to regex match

I am writing a python program that will need to be able to mirror content on another site. After downloading the html, I need to replace all of the relative links (eg. <img src='/foo.png'>) ...
0
votes
1answer
34 views

Keyword search in string

I'm making simple keyword recognition program where I have a txt file and every word is in new line. I open as a list and then I check for every keyword in sentence I will later open from database. ...
0
votes
1answer
22 views

Python Regular Expression Problems With Multiline Split

I have problems splitting multiline matches with re.split in Python. Here's example : str =""" ,,,<?xml version="1.0" encoding="UTF-8"?>,,, SOME STRING -,, Comment ,,- SOME STRING ...
0
votes
2answers
41 views

Reversing a slice of a Python string

I am trying to get this string to read backwards, however I am having trouble shifting it to start iterating back from h instead of g without changing the variables text, start and end? text = ...
0
votes
2answers
44 views

How to print string containing hex as string containing hex?

How to print variable as string with hex from python? Not to convert it and not to print as this: <?php ...
0
votes
2answers
56 views

problems importing text in python

With python, I'm trying to take a text file, and then create one long list of words (with words in the order they appear in the document). What I have so far goes through each line and then just ...
0
votes
3answers
29 views

how to change a character by its position in a string python

Im trying to make a Hangman game and I need to change certain characters in a string. Eg: '-----', I want to change the third dash in this string, with a letter. This would need to work with a word of ...
0
votes
2answers
21 views

Python: Comparing strings with accented characters does not work

I'm quite new to python. I am trying to remove files that appear on one list from another list. The lists were produced by redirecting ll -R on mac and on windows (but have gone some processing since ...
0
votes
1answer
46 views

how to detect the similar unordered sequences?

I want to find the similar intersections in a road network. My trick is to find the most similar sequence of names of streets. I have created several lists of names. one of them is the reference and ...
-1
votes
2answers
35 views

How to change the string to class object in another file

I already use this function to change some string to class object. But now I have defined a new module. How can I implement the same functionality? def str2class(str): return ...
2
votes
2answers
26 views

Split a string in python into only two parts starting from the left

I have a string from input() that I would like to only split into two parts with the delimiter as a space, even though a space may occur more than twice. For instance, if the input string was ...
-1
votes
1answer
32 views

How to insert string variable into this long python SQL string?

I have a MySQL query that is stored in a python string. It looks like this; query = """ SELECT colA, colB FROM table WHERE colC = '1' """ Suppose I want to insert string variable to ...
0
votes
3answers
51 views

Python: Grab text before and after a keyword

keywords = ("banana", "apple", "orange", ...) before = 50 after = 100 TEXT = "a big text string, i.e., a page of a book" for k in keywords: if k in TEXT: #cut = portion of text starting ...
-1
votes
3answers
39 views

Python code keeps giving me the following error… “main loop cannot concatenate 'str' and 'tuple' objects”

I have been trying to run the following code but have looked over stack exchange and Google extensively but can not find the reason why this code keeps giving the following error. main loop cannot ...
-4
votes
2answers
36 views

How to split a string input and append to a list? Python

I want to ask the user what foods they have ate, then split that input up into a list. Right now, the code is spitting out just empty brackets. Also, this is my first post on here, so I apologize in ...
0
votes
0answers
29 views

What is the use of a curly bracket compared to a percentage sign? [duplicate]

I know that you can use %s to put a variable into a string: name = 'Joe' print 'hello my name is %s' % name However on another question here I saw this: print("'{}' vs '{}' -> {}".format(addr, ...