[Solved] split a line and print in second line [closed]

with open(‘path/to/input’) as infile: for line in infile: if line.startswith(“@”): line = line.strip() print(line) print(line.rsplit(“#”, 1)[1]) elif any(line.startswith(e) for e in “#+”): print(line.strip()) solved split a line and print in second line [closed]

[Solved] Trying to exctract a char from a list [closed]

As stated in the comments, nodeList is not actually a list, but a dict_keys object. Before trying to index it, you may simply convert it to a list: nodeList = list(nodeList) node = nodeList[0] 2 solved Trying to exctract a char from a list [closed]

[Solved] Python dictionary printing specific value [closed]

In this simple case, you can create a dictionary with the keys being the roles themselves: > roles = {d[‘role’]:d for d in dic} > roles[‘NOC’][’email’] Note that you are still looping through all dictionary items to create the new one. 0 solved Python dictionary printing specific value [closed]

[Solved] Python 3.3.1 While Loops [duplicate]

You never update the value of GuessedNumber inside the loop. Therefore, if the code enters the loop, it will never leave it because RandomNumber != GuessedNumber will always be true. You need to do something like this: import random RandomNumber=(random.randint(0,100)) GuessedNumber=int(input(“Guess any whole number between 0 and 100! “)) while RandomNumber != GuessedNumber: print(“Unlucky guess … Read more

[Solved] get image from hexa string

The solution (in collaboration with OP) is: import PIL from binascii import unhexlify import zlib from cStringIO import StringIO sdata = “789C9D953D56C52010856363696D49E90AAC73ECDD4396C25228B210CE711B2CC2CAC622CECC9D0C0321313A27E411123EEEFCC07B7BFF7A9CC45EA9BD507BD6F620F769CAF4FEE3096DB76DDACEAEE9865D4CF79C6DAB34F46D441F7F23F88F6F728E6AD794724EDD5CBB9B790EF53FBF1595D9524C517E93CDEA3A433D984E83440327B318B633BF867A4C12734A5654CE26F24F29AB28704A067685363C665B0582D30ADF0F39A2717F3979C9412A6108A1D731C6992C04BD96252ECB9A2AC4A60F2B07904AA8166C84B51545D172C3C8D02B4CA3D51D841F7584B5CD2E17E2698A5DDE991302AD6240189666558242122D68F1C0F19F99475104D0F7C6216D5A6665AFAED62F8A27730A57E3BC4858669D25716B387BA04E39B41059BCC7E99CEAF4B05F971C75AAB0181AE938111CA9DB9A71C9B5443EA000D4231183A4F8ECEF79E7E5B40E2DEF647BDEA9AB6250EA59F70B6AC90E9FAABFB7D040E43C010107D4F1086A4ADA6D8DA66C8AEDD9C10E3514196A0F060220B59825C843883F5D71A67586809FEDF17FFCD75C4CFC012B43550B” fh = StringIO(zlib.decompress(unhexlify(sdata))) image = PIL.Image.open(fh) PIL is the Python Imaging Library, and using StringIO, I pretend to have a file-like object. 1 solved get image from hexa string

[Solved] Regular expression to match the string [closed]

Here’s one of many ways to get it: >>> x = r”'”self.unsupported_cmds = [r’\s*clns\s+routing’,””’ >>> print x “self.unsupported_cmds = [r’\s*clns\s+routing’,” >>> import re >>> pattern = re.escape(x) >>> re.match(pattern, x) <_sre.SRE_Match object at 0x7ffca3f66098> >>> print pattern \”self\.unsupported\_cmds\ \=\ \[r\’\\s\*clns\\s\+routing\’\,\” solved Regular expression to match the string [closed]