Tagged Questions
0
votes
2answers
11 views
Python: Setting variables with exec inside a function
Need a little help with this Python 3 problem. Probably really simple, I just started self teaching Python so I don't know a lot. Here's the script:
old_string = "didnt work"
new_string = ...
4
votes
1answer
26 views
Python multiple comparison for string
shift = raw_input("Enter the shift the employee works in: ")
shift = shift.upper()
print shift
while (shift != "A" or shift != "B" or shift != "C" ):
shift = ...
0
votes
1answer
22 views
python search string from socket
I have the following text file:
ADDRESS1 192.168.124.1
ADDRESS2 192.168.124.2
ADDRESS3 192.168.124.3
And I wrote the following string server in python (strsrv.py) :
#!/usr/bin/env python
...
0
votes
3answers
25 views
Formatting python dictionary
I am having an issue formatting my dictionary right now in key value pairs.
x = [('the', 709), ('of',342), ('to',305)]
does anyone know how I can get this to show
the:709
of:342
to:305
I just ...
0
votes
1answer
22 views
Call the name of a data frame rather than its content (Pandas)
I have a list of dataframes but when I call the content of the list it returns the content of the called dataframe.
List = [df1, df2, df3, ..., dfn]
List[1]
will ...
1
vote
2answers
48 views
Python: replace single character in value of dictionary
How do I replace a single character in a string for Python dictionaries for a matched if condition?
Given:
if key[-1] == "d" and val[-1] == "t":
print key, val
versed v3rst
vexed vEkst
voiced ...
3
votes
2answers
49 views
How to get every single permutation of a string?
I know how to get the permutations of just the plain string in python:
>>> from itertools import permutations
>>> perms = [''.join(p) for p in permutations('stack')]
>>> ...
1
vote
5answers
56 views
Python - i can't understand this error
I'm trying to write a program that asks the user for 4 integers and prints the largest odd number that was entered. Here is the code:
a = raw_input("Enter an int: ")
b = raw_input("Enter an int: ")
c ...
-2
votes
3answers
67 views
Check if list of strings exists in another string sequentially
How can I check if a list of strings exists in another string sequentially?
I have found a link which will do the same thing without sequential check.
Check if multiple string exists in another ...
1
vote
2answers
32 views
Making a list of strings with 2 parameters. Python 3.3
So lets say I have a sentence read from a file:
hello what is your name
my name is david
I am trying to make a list of strings from this so it looks like:
...
-9
votes
2answers
47 views
Inputting string while loop Python [on hold]
i have to write a program and the user will input a name, i need make my program so if the user inputs something that is not valid for example an integer. I know how to do this if the user was to ...
0
votes
1answer
38 views
Python: compare two lists and update multiple values
This is a follow up question to: Python: Compare two lists and update value in list2 based on value in list1
I have two lists:
words = ['vestments', 'absence', 'windless']
prons = ['vEstm@nts', ...
1
vote
1answer
63 views
formatting strings in list of lists
I have this list of list
a = [['c', '1.3e-8', '4.5e-8'], ['h', '3.4e-5', '2.3e-7', '2.3e-5']]
I want to format the 'e' strings only as
a = [[ 'c', '0.000000013', '0.000000045'], ['h', '0.000034', ...
-2
votes
6answers
76 views
Is there a way to remove all characters except letters in a string in Python?
I call a function that returns code with all kinds of characters ranging from ( to ", and , and numbers.
Is there an elegant way to remove all of these so I end up with nothing but letters?
0
votes
0answers
18 views
Fuzzy Wuzzy package Q ratio
Does anyone know what the Qratio stands for? Couldn't find it in this documentation.
http://chairnerd.seatgeek.com/fuzzywuzzy-fuzzy-string-matching-in-python/
https://github.com/seatgeek/fuzzywuzzy
-1
votes
1answer
30 views
Issue with saving into a Txt in python 3.3.2
I have created a piece of code to save some data generated by my code into a txt file on my pc, however when ever i run the program i receive this error,
Traceback (most recent call last):
File ...
0
votes
4answers
30 views
Python Convert Int List to Decimal string then back to Int List
I need to pass a list of numbers in a 3D program I'm using but it can only pass a single value. I want to pass the list as a single string separated by decimal points and then later convert that ...
0
votes
4answers
42 views
Spltting a string based on a word
I am currently trying to split a string based on a particular word.
An example of what I am trying to achieve is
string =" Total number of boys is 2020 , Total number of states could be 19? Total ...
0
votes
4answers
50 views
How to get part of string and pass it to other function in python?
My task is to verify whether string is valid date and time or not.
"2013-01-01W23:01:01"
The date and the time are separated with the symbol 'W' or white space.
How can I get the first part of ...
-3
votes
3answers
50 views
How can I return a string from the list of pairs?
I have a list of pairs with word and it's length
list = [("This", 4), ("is", 2), ("a", 1), ("string", 6)]
and I need to return a string separated by spaces like
"This is a string"
How can I do ...
1
vote
4answers
42 views
Pythonic sentence splitting on words starting with capital letter
I have couple of sentences in UTF that I want to split based on first capital letter.
Examples:
"Tough Fox" -> "Tough", "Fox"
"Nice White Cat" -> "Nice", "White Cat"
"This is a lazy Dog" ...
0
votes
2answers
24 views
Strip specific lines from an output and store in a variable in python
I have a output from a command which looks like this :
asdf> show status
Ok
Will be patched
fgh>
Need this
>
What I want to do is strip the output of every line which contains ">" and ...
0
votes
2answers
39 views
Pandas DataFrame stored list as string: How to convert back to list?
I have an n-by-m Pandas DataFrame df defined as follows. (I know this is not the best way to do it. It makes sense for what I'm trying to do in my actual code, but that would be TMI for this post so ...
1
vote
1answer
28 views
Add string to xPath in Selenium
I am trying to add a string to a find by element xpath in Selenium
box = driver.find_element_by_xpath("//label[contains(text(),'Room 227 4:30 AM')]/..")
The part where it says "Room 227 4:30 AM" ...
0
votes
1answer
30 views
Modifying paramiko output before storing it in an array
I have a requirement to log into multiple devices,run multiple commands and store the output.I am currently achieving this using paramiko for remote SSH and then storing the results in an excel sheet ...
0
votes
3answers
55 views
How to separate strings in a list in python? [on hold]
Ok i have this ['state1', ',', 'state2,st6'] and I want it to be like this
[['state1'], ['state2'], ['st6']] or ['state1', 'state2', 'st6']
I dont understand lists that great and i tried myself ...
0
votes
3answers
52 views
Finding a common letter between two words, Can't find what's the bug in my code
I'm supposed to write a code which gets two strings as an input and outputs True if there is a common letter and false if there isn't, I'm supposed to do this using recursion.
Running examples:
...
0
votes
4answers
57 views
ascii string to sequence of 16-bit values
I'm Python newbie and would like to convert ASCII string into a series of 16-bit values that would put ascii codes of two consecutive characters into MSB and LSB byte of 16 bit value and repeat this ...
-1
votes
2answers
25 views
How to merge list to become string without adding any character in python?
I found that I can join them with '-'.join(name) but I dont want to add any character. Lets say I have
['stanje1', '|', 'st6', ',' 'stanje2', '|', '#']
and I want to be like this
...
1
vote
2answers
49 views
Python Match xx-xxxx Numbers - Inaccurate Results
I'm quite weak in regex.
I'm trying to match a string which could be anthing like the following:
12-1234 *string*
12 1234 *string*
or
12 123 *string*
12-1234 *string*
As long as that ...
2
votes
3answers
37 views
Integer list join using string.format
As Joining List has integer values with python, the integer list can be joined by converting str and then joining them.
BTW, I want to get foo bar 10 0 1 2 3 4 5 6 7 8 9 where several data are ...
0
votes
3answers
63 views
why my python code can't get return value?
here is my code:
def similarStrings(str1,str2):
lenth=len(str1)
count=0
i=0
while (count<lenth):
if str1[count]==str2[count]:
i=i+1
else:
i=i
if ...
1
vote
1answer
27 views
Python String to triplet color
Hov can I make a string triplet to a RGB color? Like this:
color = "255,255,255"
background.fill((color))
This code gives me "invalid color argument".
Why I want to do it this way? This string is ...
-13
votes
0answers
99 views
python homework help!!!(about string compare) [on hold]
Write the function similarStrings() that takes two string arguments arguments. The function should return True if the two strings a similar (that is, if they differ by just one character).One way ...
0
votes
0answers
17 views
Defining file paths in python with EOL string literal errors [duplicate]
I'm trying to save figures to a certain directory. I'm trying to define the general path via below
path=r'D:\FLGPR Akela\YPG\test\'
Which I don't quite understand. I thought the r before the string ...
0
votes
1answer
19 views
Converting character counts to token counts
My problem is the following. I have a string that contains a few English sentences. I also have a separate list of annotations that have been made on that string that are of the form
...
0
votes
1answer
59 views
Python 3.4 with an older Python script for use in Blender, TypeErrors
I've converted a older Python script with the Python 2to3 tool to make it compatible with Blender. The script makes communication possible between Blender3D and a OMRON PLC. However after conversion ...
-2
votes
2answers
41 views
'str' and 'list' objects not combining properly
I am trying to link and bind these into a single line field or designator. It all works till I get to the self.pcre portion
def __str__(self):
r = "\nGeneral Fields:\n"
r = r ...
-1
votes
2answers
40 views
How to convert a string into object
How i call an object from a string.
This is my code:
Class main:
a=(input("file name"))
b=(input("insert a word"))
archive.relacao(b,a)
Class archive:
def relacao(self,word,document):
...
1
vote
3answers
48 views
How to split a character in list and must still exist in python?
I have list like
['a', 'pnp', 'a|pnp', 'lab2|pnp']
and I want to split them and have this
['a', 'pnp', 'a', '|', 'pnp', 'lab2', '|', 'pnp']
Any ideas?
1
vote
1answer
49 views
how to find specific string with a substring python
I have similar problem to this guy: find position of a substring in a string
The difference is that I don't know what my "mystr" is. I know my substring but my string in the input file could be ...
0
votes
2answers
20 views
Python MySQL insert and retrieve a list in Blob
I'm trying to insert a list of element into a MySQL database (into a Blob column). This is an example of my code is:
myList = [1345,22,3,4,5]
myListString = str(myList)
myQuery = 'INSERT INTO table ...
0
votes
3answers
29 views
List to str adding backslash \ to string using str()
I am trying to extract file paths from a txt file. My file says C:\logs.
I use
with open(pathfile, "r") as f:
pathlist = f.readlines()
to produce a list with the path in, and then
path1 = ...
0
votes
3answers
45 views
Case insensitive matching python
I want to match items from one list in another without worrying about case sensitivity.
mylist1 = ['fbH_q1ba8', 'fHh_Q1ba9', 'fbh_q1bA10','hoot']
mylist2 = ['FBH_q1ba8', 'trick','FBH_q1ba9', ...
-1
votes
1answer
27 views
python list element from decimal into string
I have one element in each list:
['39.95811864900048']
How can I convert into string. I tried with join:
"".join(item['longitude'])
It rounds off to 2 decimals and returns
36.95
What I need ...
0
votes
2answers
62 views
Stopping a loop when “items run out” even if it doesn't reach the proper if clause
I want to write some code that takes a list of items and concatenates them (separated by commas) to long strings, where each string is not longer than a predefined length.
For example, for this list:
...
1
vote
1answer
38 views
Store reference to a string in a list
The following code prints "original value". I want to store a reference to a string in the list, so that the string stored in the list and first_string always point to the same object. How can I do it ...
-1
votes
3answers
36 views
Search a word in a dictionary
I want to input a letter and i want to return all the words that contain that letter. For example:
String: "I saw a frog in my garden"
input: g
output: frog, garden
How could make this in Python?
-4
votes
1answer
41 views
How can I split a string without using split() method in python? [closed]
-- Anyone know how to write a function that split a string yet not using split() in python?
0
votes
1answer
46 views
Arduino Serial.write() Missing Data
I'm reading data from Serial2 and writing data to Serial3 on Arduino like this:
Serial3.write(Serial2.read());
I am writing a concatenated string from Python that looks like this:
myNum = ...