Python: convert u'001' to 001 [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Does someone know how to convert this result: u'001' to 001 to put it in a variable path: Z:\ProjectPath\001\
In advance, thanks a lot for your help!

you can use format to achieve you purpose
>>> IN = u'001'
>>> OUT = "Z:\\ProjectPath\\{}\\".format(IN)
>>> print(OUT)
Z:\ProjectPath\001\
According to #hop's suggestion, you can use os.path to compose your path.
>>> OUT = os.path.join("Z:", os.sep, "ProjectPath", "{}".format(IN))

Related

How do I write a Python program to print the pattern? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
How do I write a Python program to print the pattern?
543210
432105
321054
210543
054321
543210
You can do it by something like this:
a = "543210"
print(a)
for i in range(6):
a = a + (a[0])
a = a[1:]
print(a)

HOW TO REMOVE DUPLICATES IN A ROW IN PYTHON [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Hi I need to remove the duplicates in python but only when they are in a row. For example:
Input: AAABBCCDDAA
Output:ABCDA
Could you please help me? thnks.
To learn more about text processing in Python3 I recommend training on codingame.com.
def removeDuplicates(inp):
output =""
lastCharacter=""
for character in inp:
output+=character*(character!=lastCharacter)
lastCharacter=character
return output
inpTest ="AAABBCCDDAA"
print(removeDuplicates(inpTest))
ABCDA

Grab specific text from string in Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How can I grab the invite code from this string?
{awarded:1,inviteURL:https:\/\/www.example.com\/refer\/invite\/111A111A\/}
The expected output would be "111A111A".
Any help is appreciated
I tried it in a simple way, You could give more details for further improvement.
s = "{awarded:1,inviteURL:https:\/\/www.example.com\/refer\/invite\/111A111A\/}"
print(s[-11: -3])
This will do it with ReGex
import re
def findInvite(s):
return re.search(r"(?<=/invite\\/).*(?=\\/)",s).group()
assert findInvite("{awarded:1,inviteURL:https:\/\/www.example.com\/refer\/invite\/111A111A\/}") == "111A111A"
And if this isn't a string but a dict, then change the function to:
def findInvite(d):
s = d["inviteURL"]
return re.search(r"(?<=/invite\\/).*(?=\\/)",s).group()

Variable as part of the generated filename [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Example:
var = "string"
and I want an xml output file: string.xml
Thank you!
It seams to be too easy... maybe i did not get the question right:
var = "String"
fileName = var + ".xml"
print fileName
this will print
String.xml

grep with python to match string inside quotes in html files [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am newbie in grep and I'm familiar with Python. My problem is to find and replace every string inside the quote like "text" by < em >text< /em >
The source file has the html form
Thanks
That'll do the trick
import re
s = '"text" "some"'
res = re.subn('"([^"]*)"', '<em>\\1</em>', s)[0]

Categories

Resources