Tagged Questions
1
vote
3answers
40 views
Find most common sub-string pattern in a file
You are given a string like:
input_string = """
HIYourName=this is not true
HIYourName=Have a good day
HIYourName=nope
HIYourName=Bye!"""
Find the most common sub-string in the file.
Here the ...
0
votes
1answer
16 views
Building a string and running it in terminal python
Hey guys I'm creating a python script to download youtube videos. I know I could do it in native linux scripting language, but I'm trying to learn how to do scripts in python since in my work, I use ...
0
votes
1answer
23 views
Python: Converting HEX string to bytes
I'm trying to make byte frame which I will send via UDP. I have class Frame which has attributes sync, frameSize, data, checksum etc. I'm using hex strings for value representation. Like this:
...
-5
votes
1answer
38 views
Convert Python List to JSON Separate Objects [on hold]
I have a l̶i̶s̶t̶ string in Python
[Volume:vol-XXXXXXXX, Volume:vol-YYYYYYYY]
that I want to change to into JSON. The final result should be
{ volumes: ["Volume:vol-XXXXXXXX", ...
-1
votes
1answer
22 views
Split characters from a list of tuples?
Im new at python and i have the following list of n tuples:
[('Mi', 'dp1css'), ('colega', 'nccs000'), ('me', 'pp1cs000'), ('ayuda', 'ncfs000'), ('a', 'sps00'), ('programar', None), ('cosas<', ...
-2
votes
2answers
54 views
what does backward-slash b do in Python?
what is the purpose of backward-slash b in python, I ran print "\"foo\bar" in the python interpreter and got this result:
>>>print "\"foo\bar"
"foar
0
votes
0answers
10 views
How to check membership of string-type items in a set in Python 3 [duplicate]
I'm creating a 4x4 sudoku solver, and now I need to check if the numbers 1, 2, 3, 4 are in every line/column/square of the sudoku. Here you have the code (the sudoku is an incorrect one for problem ...
0
votes
2answers
37 views
Python Log Parsing [on hold]
I am new to parsing in Python. I have a log file of the following format:
<20>1 2008-12-18T09:46:28.806-07:00 NET-RT - RT_FLOW_CREATE [[email protected] source-address="192.168.30.170" ...
0
votes
2answers
33 views
Can't find split() method or replacement in string module in python 3.4.1? [duplicate]
I'm trying some text manipulation stuff out and am bumping into the error:
wordlist = string.split(" ")
AttributeError: 'module' object has no attribute 'split'
I have imported the string module ...
2
votes
2answers
16 views
How to check issubset for the whole words separated by commas?
string = 'NotAllowed,Trinity,Allowed'
string1 = 'NotAllowed,Allowe'
name = frozenset(string1)
if name.issubset(string) == 1:
print 'yes'
else:
print 'no'
This produces the output of yes. ...
0
votes
2answers
57 views
How do I properly format this string in Python?
I am parsing through a folder of txt files. These text files have a Dell computer service tag on the second line. I'd like to grab the second line and eventually place it in a csv spreadsheet.
When ...
2
votes
0answers
59 views
Replacing special patterns in a string, reading from a file
I'm trying to replace special patterns in string by tabs. This string ( if i may call it) is a result from reading a file, that has accents (I'm portuguese, so UTF-8 or LATIN-1 is the encoding ...
2
votes
2answers
34 views
Croatian characters and python
I have done a simple program which finds out if given string is found in file.
a=raw_input('write some string ')
f1=open("croatian.txt",'r')
def check():
found = False
for line in f1:
...
0
votes
2answers
42 views
What's the fastest way to make string combinations out of lists in python?
Lets say we have the following lists
lsta = ['a','b','c']
lstb = ['1','2','3','4']
lstc = ['x','y']
I'd like to make a function that can consume an arbitrary number of different lists and append ...
0
votes
4answers
49 views
How to remove space in python 2.7.5
When I use the code in python 2.7.5
for i in [1,2]:
print 'distance',':400@CA',':',i,'@CA'
I got the following
distance :400@CA : 1 @CA
distance :400@CA : 2 @CA
I want to remove the ...
-2
votes
2answers
40 views
Python, regular expression, strings inside brackets [ ]
In lines like:
(bla - means not important)
> blabla|blabla|bla|blabla| blabla [Geobacter sp. M21]
> blabla|blabla|bla|blabla| blabla [Acetobacter pasteurianus IFO 3283-07]
> ...
-4
votes
0answers
27 views
Clustering method for strings in python
I am working on a clustering algorithm for related sequences, having this input:
--ADIKYTWNVPKIA----- 4
---DIKYTWNVPKIAPKSEN 5
ILSDENYLL----------- 1
--VWINNSWKF--------- 2
--GLNDYLHSV--------- 3
...
0
votes
1answer
21 views
Python RSS reader text filtering
On my quest to better learn python 3.4, I decided to create a 'practical' program that simply reads the RSS feed of a link you give it. I was testing using the CNN RSS feed and got the description to ...
0
votes
3answers
49 views
Extracting part of a string based on its naming convention
I'm trying to extract a piece of information about a certain file. The file name is extracted from an xml file.
The information I want is stored in the name of the file, I want to know how to extract ...
0
votes
1answer
18 views
str.format on non-template string silently ignores template arguments
>>> 'potato'.format(123)
'potato'
>>> 'potato'.format(kw='hello')
'potato'
I really expected an exception to be raised here rather than templating silently ignored.
Why is this ...
0
votes
4answers
65 views
How to read a dataset from a txt file in pyhton?
I have a dataset in this format:
I need to import the data and working with them.
The main problem is that the first and the forth culomns are strings while the second and the third culomns are ...
2
votes
4answers
37 views
Cast list of lists to floats while ignoring column of strings
Very similar to the question: Convert Python list of strings into floats, where list also contains words
Except I have a 2 Dimensional list (a list of lists) and the structure is predictable.
...
-7
votes
2answers
38 views
Python make simple string computation [on hold]
I have one string initalized
9300.1 9600.6 9300.2 9300.1 9600.5 9600.7
Wanna make it like
9300.4 9600.18
How ?
It's really simple.
But I cant figure it out.
Sorry I mean
9300 Make as a list
...
0
votes
0answers
33 views
Python- Tracking bytes parsed while parsing
I wish to know if there is something that help me keep track of HTML bytes parsed vs string (i.e. between tags text) parsed while parsing.
How can I do so?
0
votes
8answers
85 views
How to use recursion to determine if characters are in a string? [on hold]
Right now I'm trying to use recursion of a function with two parameters to find whether or not the second is included in the first. As an example:
def recurseString(full, inclusive):
...
1
vote
2answers
26 views
Finding the rest of the string with newlines Python
I have a string msg like this
msg = "abc 123 \n 456"
I want to do something like this
m = re.match('abc (.*)',msg)
and have m.groups return "123 \n 456"
but currently it only returns "123 "
...
-1
votes
1answer
21 views
String Output in a data file
How to print string in data file ? I have checked this Python Print String To Text File. But this is not really helping me.
The part of the code is like this :
for k in range(len(energy)):
...
1
vote
1answer
42 views
Split Sentence on Punctuation or Camel-Case
I have a very long string in python and i'm trying to break it up into a list of sentences. Only some of these sentences are missing puntuation and spaces between them.
Example
I have 9 sheep in ...
1
vote
3answers
45 views
string recursion problems
I am relatively new to python and especially recursion.
I have been trying to solve this problem for a while now but it's bested me so far
I have to create a function that takes in 2 strings and ...
1
vote
0answers
40 views
Resursive string replacement with escaping in Python
I made a simple script in Python to do some project generation based on sources directory structure. In it I used Formatter as it proved quite handy with the ability to use a dictionary (also nested!) ...
1
vote
2answers
43 views
Find the last substring after a character
I know many ways how to find a substring: from start index to end index, between characters etc., but I have a problem which I don't know how to solve:
I have a string like for example a path: ...
0
votes
3answers
49 views
Python: looping over characters in a string when string is changing
def substitutionEncrypt1(text,key):
plaintext=text.lower()
alphabet="abcdefghijklmnopqrstuvwxyz "
for ch in plaintext:
r=plaintext.index(ch)
...
0
votes
4answers
24 views
Extracting url from style: background-url: with beautifulsoup and without regex?
I have:
<div class="image" style="background-image: url('/uploads/images/players/16113-1399107741.jpeg');"
I want to get the url, however I cannot how to do that without the use of regex. Is it ...
0
votes
4answers
34 views
python string replace() method when replacing a character with surrounding spaces only replaces the first occurrence
I have a string that I'm trying to replace when it has spaces surrounding the character like below:
>>> strvar = " a a b b "
>>> strvar.replace('a', 'r')
" r r b b " # WORKS!
...
0
votes
1answer
16 views
Faster string assignment using Numpy
Can Numpy be used to do faster string assignment?
I want my string array like
[['x1-y1', 'x1-y2'...],
['x2-y2, 'x2-y2' ...],
.....
]
so on
So, the string at every (i,j) = "x%d-y%d" % (i,j)
Can ...
0
votes
3answers
48 views
Count length of string without vowels
I've a string:-
a = 'abcderui'
I want to count the length of the string a minus the vowels. What would be the fasstest wat to implement that?
Currently I'm doing:-
a = list(a)
for i in a:
if ...
0
votes
1answer
46 views
How to add text to python calculation?
I'm trying to create this with the help of python:
in a for loop (from 1,10)
text i+(i*(i+2.5)) text [i+(i*(i+2.5))] text
results:
text 1+(1*(1+2.5) text 4.5 text
text 2+(2*(2+2.5) text 11 text
...
0
votes
1answer
37 views
Python Regex catch multi caps words and adjacent words
I have a regex that does the following:
Find a word that has two or more adjacent capital letters A-Z ("multi caps word");
When possible, extend the match to the left and to the right up to another ...
-7
votes
1answer
35 views
Changing string into integers for variables inside function, Python
why the assign() function does not change the string into integer?
the assign function does not return the values i set in if statement!
p1 = raw_input("Player 1 ?")
p2 = raw_input("Player 2 ?")
def ...
0
votes
3answers
39 views
How to get numbers out of this list of strings in python
I have a list of strings in python which I reading from a file:
lines = ['4 11', '8 4', '10 5', '15 8', '4 3']
If I want to assign 4 and 11 to some variables. I do some thing like:
a, b = ...
0
votes
1answer
13 views
How can I print the raw unicode in python?
I am novice in python, so maybe I can't express it well...
I got a string '\xb9\xfe'
I want it print in this very fashion '\xb9\xfe', not converting to a Chinese character '哈'.
What is the proper ...
3
votes
2answers
43 views
Python - Parse a string and convert it into list
I've a string
a = "sequence=1,2,3,4&counter=3,4,5,6"
How do I convert it into a list,ie
sequence = [1,2,3,4]
counter = [3,4,5,6]
0
votes
1answer
46 views
Python beginner issues - dictionary
I've been trying to produce a program with an output:
Enter line: which witch
Enter line: is which
Enter line:
is 1
which 2
witch 1
How I want it to work is for you to enter a few lines, and when ...
0
votes
1answer
14 views
Python 3 DictWriter csv BytesIO TypeError
I'm using python 3 trying to generate a csv on the file.
I want to ensure that I'm writing utf8 so I'm converting values of my list of dicts into byte strings
field_order = ['field1', 'field2', ...
0
votes
1answer
40 views
Python: Convert String to Object Name
This may be a very simple question, but how can I use a string for the name of a class/object declaration? I'm working with PySide, and I have code that will make a text input for every entry in an ...
0
votes
2answers
29 views
Python substring search not working
name is a list of tuples which are len(1) and contain string
When I use:
if word in (name[0] for name in t):
return name[0]
return None
then I am getting None(search unsuccessful)
But ...
3
votes
1answer
49 views
Python: How do I format numbers for a fixed width?
let's say
numbers = [ 0.7653, 10.2, 100.2325, 500.9874 ]
I'd like to output the numbers with a fixed width by varying the number of decimal places to get an output like this:
0.7653
10.200
100.23
...
0
votes
1answer
29 views
How to use __get__ to make object JSON serializable?
I have a decorator that returns a string on __get__. How can I make it compatible with json.dumps?
import json
class Decorator(object):
def __init__(self, value=''):
self.value = value
...
1
vote
2answers
12 views
Insert String in Python SQLite Statement
I'm trying to insert a string into a SQLite Select statement in python. When I try this code:
cur.execute("SELECT * FROM DB WHERE employeeNum = '?'",(empNum,))
I get this error: ...
0
votes
1answer
32 views
Extra characters when sending String from Android client to Python Server
I am sending a String from an Android device to a python server via TCP socket, but when the message arrives on the server, there are extra characters in the front. For example, if I send the string
...