character

How to recursively replace character in keys of a nested dictionary?

How to recursively replace character in keys of a nested dictionary? Question: I’m trying to create a generic function that replaces dots in keys of a nested dictionary. I have a non-generic function that goes 3 levels deep, but there must be a way to do this generic. Any help is appreciated! My code so …

Total answers: 9

python pexpect sendcontrol key characters

python pexpect sendcontrol key characters Question: I am working with pythons pexpect module to automate tasks, I need help in figuring out key characters to use with sendcontrol. how could one send the controlkey ENTER ? and for future reference how can we find the key characters? here is the code i am working on. …

Total answers: 2

Get the first character of the first string in a list?

Get the first character of the first string in a list? Question: How would I get the first character from the first string in a list in Python? It seems that I could use mylist[0][1:] but that does not give me the first character. >>> mylist = [] >>> mylist.append(“asdf”) >>> mylist.append(“jkl;”) >>> mylist[0][1:] ‘sdf’ …

Total answers: 5

What is the difference between a string and a byte string?

What is the difference between a string and a byte string? Question: I am working with a library which returns a "byte string" (bytes) and I need to convert this to a string. Is there actually a difference between those two things? How are they related, and how can I do the conversion? Asked By: …

Total answers: 9

Get character position in alphabet

Get character position in alphabet Question: I’m 90% sure there is a built in function that does this. I need to find the position of a character in an alphabet. So the character "b" is position 1 (counting from 0), etc. Does anyone know what the function is called? What I’m trying to do is …

Total answers: 7

How to read a single character at a time from a file in Python?

How can I read a single character at a time from a file in Python? Question: In Python, given the name of a file, how can I write a loop that reads one character each time through the loop? Asked By: kaushik || Source Answers: You should try f.read(1), which is definitely correct and the …

Total answers: 15

Getting two characters from string in python

Getting two characters from string in python Question: how to get in python from string not one character, but two? I have: long_str = ‘abcd’ for c in long_str: print c and it gives me like a b c d but i need to get ab cd I’m new in python.. is there any way? …

Total answers: 2

In Python, how to check if a string only contains certain characters?

In Python, how to check if a string only contains certain characters? Question: In Python, how to check if a string only contains certain characters? I need to check a string containing only a..z, 0..9, and . (period) and no other character. I could iterate over each character and check the character is a..z or …

Total answers: 9