I tried to do it like this:
await message.channel.send("**" + current_text + "**")
But it doesn't work. It will show the result like this:
**
Hey
**
For this, I highly recommend using F-Strings. F-Strings allow you to directly call an variable from a string. This should be easier for you to implement markdown since you can do f"**{current_text}**" and {current_text} will be replaced with the according variable.
Related
Instead of:
=ZÄHLENWENN([B16.xlsx]ListeVU!$Y:$Y;F5)
I would like to have like:
=ZÄHLENWENN(["C6".xlsx]ListeVU!$Y:$Y;F5)
But this does not work.
As per my comment you'd need to use INDIRECT(). The right syntax would be:
=COUNTIF(INDIRECT("'["&C6&".xlsx]ListeVU'!$Y:$Y"),F5)
Or in german:
=ZÄHLENWENN(INDIREKT("'["&C6&".xlsx]ListeVU'!$Y:$Y");F5)
I try to Remove extra char from this URL(Please watch snapshot)
https://test.com/ABC]VR͜
URL Snapshot
but I can't make it perfect URL format,
and I try this code
import re
p = re.compile(r'(?:\w*://)?(?:.*?\.)?(?:([a-zA-Z-1-9]*)\.)?([a-zA-Z-1-9]*\.[a-zA-Z]{1,}).*')
domain = 'https://test.com/ABC]VR͜'
print(p.match(domain))
Code Snapshot
but still, it gives output
https://test.com/ABC]\x1dV\x1dR͜\x1d
where I need output like
https://test.com/ABCVR
So, is there any build-in method in python to do that? or if need to make manually any way without regular expression? if no way without regular expression then how to do that with a regular expression?
Thank you.
I want to use printing command bellow in many places of my script. But I need to keep replacing "Survived" with some other string.
print(df.Survived.value_counts())
Can I automate the process by formating variable the same way as string? So if I want to replace "Survived" with "different" can I use something like:
var = 'different'
text = 'df.{}.value_counts()'.format(var)
print(text)
unfortunately this prints out "df.different.value_counts()" as as a string, while I need to print the value of df.different.value_counts()
I'm pretty sure alot of IDEs, have this option that is called refactoring, and it allows you to change a similar line of code/string on every line of code to what you need it to be.
I'm aware of VSCode's way of refactoring, is by selecting a part of the code and right click to select the option called change all occurances. This will replace the exact code on every line if it exists.
But if you want to do what you proposed, then eval('df.{}.value_counts()'.format(var)) is an option, but this is very unsecured and dangerous, so a more safer approach would be importing the ast module and using it's literal_eval function which is safer. ast.literal_eval('df.{}.value_counts()'.format(var)).
if ast.literal_eval() doesn't work then try this final solution that works.
def cat():
return 1
text = locals()['df.{}.value_counts'.format(var)]()
Found the way: print(df[var].value_counts())
I'm having trouble trying to use replace characters in MS excel. Help says * and ? can both replace characters, but if I try using them in IF, I don't get correct results.
For example:
A1="something"
=IF(A1="*mething";"yes";"no")
I always get no... How to use * correctly?
wildcards don't work with comparison operators like =
To achieve what you want you can use COUNTIF which does accept wildcards, i.e.
=IF(COUNTIF(A1;"*mething")>0;"yes";"no")
or RIGHT function like
=IF(RIGHT(A1;7)="mething";"yes";"no")
Wildcards cannot be used in this context. Use something like:
=IF(ISERROR(FIND("mething",A1)),"No","Yes")
I could almost solve all of my python problems thanks to this great site, however, now I'm on a point where I need some more and specific help.
I have a string fetched from a database which looks like this:
u'\t\t\tcase <<<compute_type>>>:\n\t\t\t\t{\n\t\t\t\t\tif (curr_i <= 1) Messag...
the string is basically plain c code with unix line endings and supposed to be treated in a way that the values of some specific variables are replaced by something else gathered from a Qt UI.
I tried the following to do the replacing:
tmplt.replace(u"<<<compute_type>>>", str(led_coeffs.compute_type))
where 'led_coeffs' is a namedtuple and its value is an integer. I also tried this:
tmplt = Template(u'\t\t\tcase ${compute_type}:\n\t\t\t\t{\n\t\t\t\t\tif (curr_i <= 1) Messag...)
tmplt.substitute(compute_type = str(led_coeffs.compute_type))
however, both approaches do not work and I have no idea why. Finally I was hoping to get some input here. Maybe the whole approach is not right and any hint on how to achieve the replacing in a good manner is highly appreciated.
Thanks,
Ben
str.replace (and other string methods) don't work in-place (string in Python are immutable) - it returns a new string - you will need to assign the result back to the original name for the changes to take effect:
tmplt = tmplt.replace(u"<<<compute_type>>>", str(led_coeffs.compute_type))
You could also invent your own kind of templating:
import re
print re.sub('<<<(.*?)>>>', lambda L, nt=led_coeffs: str(getattr(nt, L.group(1))), your_string)
to automatically lookup attributes on your namedtuple...