[Solved] TypeError: unsupported operand type(s) for &: ‘str’ and ‘int’ on compile re [closed]

You are calling the re.compile() function, whose second argument is an integer representing the different regular expression flags (such as IGNORECASE or VERBOSE). Judging by your variable names, I think you wanted to use the re.findall() function instead: findall_localizacao_tema = re.findall( ‘:.? (*)’ + findall_tema[0] + “https://stackoverflow.com/”, arquivo_salva) You can still use re.compile, but then … Read more

[Solved] Convert several YAML files to CSV

I would make use of a Python YAML library to help with doing that. This could be installed using: pip install pyyaml The files you have given could then be converted to CSV as follows: import csv import yaml fieldnames = [‘Name’, ‘Author’, ‘Written’, ‘About’, ‘Body’] with open(‘output.csv’, ‘w’, newline=””) as f_output: csv_output = csv.DictWriter(f_output, … Read more

[Solved] python add value to a list when iterate the list

You iterate over an array which you grow as you iterate over it. First values is [2,3,4] then after the first iteration, values is [2, 3, 4, [2, 255, 255]] then [2, 3, 4, [2, 255, 255], [3, 255, 255]] etc. You should print along the iteration to understand it better. The reason is append … Read more

[Solved] How to convert unformatted time to a python time object

It seems parsedatetime module that should parse human-readable date/time text works in this case: #!/usr/bin/env python from datetime import datetime import parsedatetime as pdt # $ pip install parsedatetime cal = pdt.Calendar() print(datetime.now()) for time_str in [“8 seconds ago”, “5 minutes ago”, “11 hours ago”, “11:34 AM yesterday”]: dt, flags = cal.parseDT(time_str) assert flags print(dt) … Read more

[Solved] multiple search and replace in python

import os parent_folder_path=”somepath/parent_folder” for eachFile in os.listdir(parent_folder_path): if eachFile.endswith(‘.xml’): newfilePath = parent_folder_path+”https://stackoverflow.com/”+eachFile file = open(newfilePath, ‘r’) xml = file.read() file.close() xml = xml.replace(‘thing to replace’, ‘with content’) file = open(newfilePath, ‘w’) file.write(str(xml)) file.close() Hope this is what you are looking for. 3 solved multiple search and replace in python

[Solved] Python maximum and minimum

If you want to find max/min via traversal/iteration – use the following approach: def max_and_min(values): max_v = min_v = values[0] for v in values[1:]: if v < min_v: min_v = v elif v > max_v: max_v = v return (max_v, min_v) l = [1,10,2,3,33] print(max_and_min(l)) The output: (33, 1) 1 solved Python maximum and minimum

[Solved] Python slicing explained [duplicate]

This will probably be deleted but here goes: First one is start at second position, head left as far as you can go. Second is start at rightmost, head left ending before -3. Third is start at-3 and head all the way to left. solved Python slicing explained [duplicate]

[Solved] User input integer list [duplicate]

Your best way of doing this, is probably going to be a list comprehension. user_input = raw_input(“Please enter five numbers separated by a single space only: “) input_numbers = [int(i) for i in user_input.split(‘ ‘) if i.isdigit()] This will split the user’s input at the spaces, and create an integer list. 1 solved User input … Read more

[Solved] Python: return first value by condition of nested dictionary in array [closed]

Your code works fine for me using your (slightly edited) sample data: data = [{‘id’: 1, ‘name’: ‘test’}, {‘id’: 2, ‘name’: ‘test’}, {‘id’: 3, ‘name’: ‘test’}] val = [x[‘id’] for x in data if x[‘name’] == ‘test’][0] >>> print(val) 1 However, if there is no dictionary containing a name that matches the target string: >>> … Read more

[Solved] Unable to communicate with API

CONCLUSION – 07-25-2021 After looking at this problem in more detail, I believe that it is NOT technically possible to use Python Requests to scrape the website and table in your question. Which means that your question cannot be solved in the manner that you would prefer. Why? The website employs anti-scraping mechanisms. The GBK … Read more