[Solved] Another Traceback Error When I Run My Python Code

[ad_1] You just have to many brackets ((df[‘Location’].str.contains(‘- Display’) & df[‘Lancaster’] == ” & df[‘Dakota’] == ‘D’ & df[‘Spitfire’] == ‘SS’ & df[‘Hurricane’] == ”)) You needed to remove a ‘)’ after each (‘- Display’) it looks like you will still have some problems with sorting through your data. But this should get you past … Read more

[Solved] Sum of multiples of two numbers

[ad_1] Try this code: a = input(“enter first number\n”) b= input(“enter second number\n”) limit=[] limit.append(a) limit.append(b) natNo=range(1,1000) xyz = [] for i in limit: xyz +=filter(lambda x: x == i or x % i==0, natNo) set = {} map(set.__setitem__, xyz, []) nums=set.keys() print “the multiples of the given numbers are: “+str(nums) c=reduce(lambda x, y:x+y, nums) … Read more

[Solved] Python: Extract text from Word files in a url

[ad_1] I finally found a solution, I hope someone helps from urllib.request import urlopen from bs4 import BeautifulSoup from io import BytesIO from zipfile import ZipFile file = urlopen(url).read() file = BytesIO(file) document = ZipFile(file) content = document.read(‘word/document.xml’) word_obj = BeautifulSoup(content.decode(‘utf-8’)) text_document = word_obj.findAll(‘w:t’) for t in text_document: print(t.text) [ad_2] solved Python: Extract text from … Read more

[Solved] Python – Read string from log file

[ad_1] Can be extracted with a simple regular expression, as long as the text file is in the same format as the Python log output you posted (Returns all of them): import re file=””.join([i for i in open(“yourfileinthesamefolder.txt”)]) serials=re.findall(“u’serial_number’: u'(.+)'”,file) print(serials) I suggest reading up on how to use regular expressions in Python: Regular Expression … Read more

[Solved] a=’01101′ this has to be converted to [‘0′,’1′,’1′,’0′,’1’] ?? IN PYTHON [duplicate]

[ad_1] There is a function called list to do this directly.This can convert any string into list of characters. list(‘01101’) will return [‘0’, ‘1’, ‘1’, ‘0’, ‘1’] One more way is a=”01101″ a_list=[] for item in a: a_list.append(item) print(a_list) 5 [ad_2] solved a=’01101′ this has to be converted to [‘0′,’1′,’1′,’0′,’1’] ?? IN PYTHON [duplicate]

[Solved] How can I store an element permanetly, even if I restart the program again

[ad_1] As far as I know, there are actually a few options: An external .txt file The module Pickle A database The module Pickle – simple example of how to pickle work import pickle element= [“Summer”,”Sun”] element.append(“Ice”) pickling_on = open(“Element.pickle”,”wb”) pickle.dump(element, pickling_on) pickling_on.close() So, now that the data has been pickled pickle_off = open(“Element.pickle”,”rb”) element … Read more

[Solved] How to split multiple string formats using regex and assigning its different groups to variable [closed]

[ad_1] You can use this code: import re domain = “collabedge-123.dc-01.com” # preg_match(“/^(collabedge-|cb|ss)([0-9]+).dc-([0-9]+).com$/”, $domain, $matches); regex = r”^(collabedge-|cb|ss)([0-9]+).dc-([0-9]+).com$” res = re.match(regex,domain) print(res.group(0)) print(res.group(1)) print(res.group(2)) print(res.group(3)) Output: collabedge-123.dc-01.com collabedge- 123 01 1 [ad_2] solved How to split multiple string formats using regex and assigning its different groups to variable [closed]

[Solved] Converting a code from Python to Ruby [closed]

[ad_1] Your Python code outputs: a=1&b=2&aaa=bbb In Ruby we might do this as: require ‘cgi’ parameters = {a: 1, b: 2} encoded = parameters.merge(Hash[*[‘aaa’, ‘bbb’]]) .map { |key, value| “#{CGI.escape key.to_s}=#{CGI.escape value.to_s}” } .join(‘&’) p encoded Which outputs the same: a=1&b=2&aaa=bbb It’s longer than the Python code, but IMHO also slightly more readable … You … Read more

[Solved] os.path.isfile isn’t working as expected

[ad_1] Your code, as posted, works: File exists /usr/bin/python2.7 /home/surest/github/tests/test.py Enter the directory to the ISO file (or just drag the file here): /home/surest/Desktop/duties.odt /home/surest/Desktop/duties.odt <type ‘str’> True Process finished with exit code 0 Typo in filename/path /usr/bin/python2.7 /home/surest/github/tests/test.py Enter the directory to the ISO file (or just drag the file here): /home/surest/Desktop/meesa-typoed.odt /home/surest/Desktop/meesa-typoed.odt <type … Read more