Tagged Questions
0
votes
2answers
20 views
Conditionally parsing a string
I'm working on a small script to compile a CSV file.
I've come up with this code to combine the string.
site = "{}.{}".format(subdomain, fullDomain)
However there are some situation where the ...
0
votes
1answer
23 views
UnicodeEncodeError when formatting string with % in Python
For the life of me, I cannot figure this out: I am just trying to extract messages and who said them from a .json file. While I cannot disclose those data here, this is the line that does it:
print ...
3
votes
4answers
62 views
Get sub-string for major version out of full version string
I have a script in which I must convert strings of full-versions to just their major parts. For example, I must convert 1.2.3.4.5.6.7 into 1.2.
Currently I am using this: '.'.join(s.split('.', ...
1
vote
3answers
25 views
python, hex values to convert to a string/integer
I'm looking how I can take hex values, and turn them into a string or an integer.
Examples:
>>> a = b'\x91\x44\x77\x65\x92'
>>> b = b'\x44\x45\x41\x44\x42\x45\x45\x46'
>>> ...
2
votes
3answers
52 views
'str' object is not callable for string as array
I got an error saying "TypeError: 'str' object is not callable" ;
This is my code:
m=input()
while(m!='0'):
c=0
for letter in range(len(m)):
if(m(letter) == '1'or '2'):
...
0
votes
0answers
16 views
Extract case statement and string start with $ from nvp_add function in loop…
I have 1 ascii plain input text file as below with many case, I'm giving here 2 switch case. What i need is i need to extract all strings start with '$' in details function (as bold) in textfile below ...
1
vote
2answers
67 views
Python - How do i write only case statements and instances start with $ from input text file?
I want to only write into a file case line and all instances start with symbol $ in nvp_add function after statement Extended attributes from below input file, so i'm expecting for output like below ...
2
votes
1answer
34 views
What's the advantage of having multi-line & single-line string literals in python?
I know the triple quote strings are used as docstrings, but is there a real need to have two string literals?
Are there any use case when identifying between single-line & multi-line is useful.
...
0
votes
2answers
25 views
How do I convert a bitstring to an utf-8 string?
I use the bitstring module. What is the easiest way to convert a bitstring to an utf-8 string?
0
votes
4answers
106 views
How can I make a list from the string [on hold]
Is there any way to make from string:
"I like Python!!!"
a list like
['I', 'l', 'i', 'k', 'e', 'P', 'y', 't', 'h', 'o', 'n', '!', '!', '!']
0
votes
1answer
42 views
Jython -Python how to return different parts of string to get grades
how would i go about using strings and splits to be able to get a certain grade from three different grades for a specific person out of three in the list. This is the list.
...
1
vote
4answers
63 views
Python 2: AttributeError: 'str' object has no attribute 'remove'
I have a small problem with a list. I have a list called l1:
l1 = ['Amazon FR: Huawei1 - PRICE ALERT!', 'Amazon FR: Huawei1 - PRICE ALERT!', 'Amazon UK: Huawei1 - PRICE ALERT!']
And I want to ...
3
votes
5answers
145 views
Counting letters in a string with python
I've got the following exercise: Write the function countA(word) that takes in a word as argument and returns the number of 'a' in that word. Examples
>>> countA("apple")
1
>>> ...
-10
votes
2answers
394 views
Declaring encoding in Python
I want to split a string in python using this code:
means="a ، b ، c"
lst=means.split("،")
but I get this error message:
SyntaxError: Non-ASCII character '\xd8' in file dict.py on line 2, but ...
3
votes
5answers
1k views
Best way to count char occurences in a string
Hello I am trying to write these python lines in a single line but getting some errors due to the dictionary modifications the code is doing.
for i in range(len(string)):
if string[i] in dict:
...