How can you loop in python, unit test, selenium code?

How do I loop around the code to repeat the same padding N times? Or even take the names from a .txt list and enter them in "name"?

def teste(self):
    driver = self.driver
    driver.find_element_by_name("nome").send_keys("Teste de preenchimento")
    self.assertEqual("Existe um teste pra este email cadastrado em: 28/03/2019", self.close_alert_and_get_its_text())

Plus the youngest:

if __name__ == "__main__":

Run the Python script using Java code

I call a Python script from my Java code with no results:

String cmdStr =
      -ip C:\Reconstructed\Test\2019-12-11_16-13-52\MERGEDBEDS_1FRAME.img
      -hp C:\Reconstructed\Test\2019-12-11_16-13-52\MERGEDBEDS_1FRAME.hdr
      -op C:\Reconstructed\Test\2019-12-11_16-13-52\MERGEDBEDS";


When I open the console and call the same script, it works.

Why does not it work with my java code?

python – Freezes when the notification send service is used by the system

I have the following python script:

# /path/to/__main.py__

(..)"DISPLAY=:0 dbus-launch /usr/bin/notify-send -i dialog-information 'foo' 'bar'", shell=True)


and the following .service file:

# /etc/systemd/system/notification.service

Description=Notification service


# Run permission service
ExecStart=/usr/bin/python3 /path/to/

# keep process after user logs off


When I call /usr/bin/python3 /path/to/ The pop-up window appears in my terminal and no freezing or the like has occurred.

However, when I call sudo systemctl restart notification.serviceIf the system (UI) freezes for approx. 20 seconds (no interactions possible in the UI), the popup is displayed.

The question is: Why does this problem only occur when the script is called from the systemd service?

How do I analyze response.text in Python?

This is the answer I get and I want the question mark sequence, how do I do it?

"Item": {
    "last_data": {
        "S": "{"id":2689,"type":"question","number":12,"offset":12,"status":0,"options":[{"id":8045,"option":"opcion1"},{"id":8046,"option":"opcion2"},{"id":8044,"option":"opcion3"}],"question":"¿pregunta pregunta pregunta pregunta?","ts":1576192609}"

How do I use IP_FILTER with Python libtorrent?

The question I have is: How can I use ip_filter in libtorrent with the Python language.

The goal I am trying to achieve is to block all IP addresses (incoming or outgoing data traffic) with libtorrent ip-filter, with the exception of those I have approved. In the code snippet below, I try to achieve my goal …

class Session:
   def __init__(self)
       self.session = libtorrent.session({'listen_interfaces': ''}) 
       self.ip_filter = None

   def set_access_rules(self):
       self.ip_filter = libtorrent.ip_filter()
       self.ip_filter.add_rule('', '', 1)  # I assume ‘1’ means blocking 
       self.ip_filter.add_rule('', '', 0)  # I assume ‘0’ allow, prob. wrong...

The (c source) documentation states:

// Add a rule to the filter. first and last defines a range of
// IP addresses that are marked with the specified flags. The flags
// can currently be 0, which means allowed, or ip_filter::blocked, Which
// means not allowed.

ip_filter :: locked <- I'm stuck here. How do I use / write this in Python?

When I call "handle.get_peer_info ()" I only expect, but I see all possible public addresses … Note: My torrent has no trackers and I have not configured any trackers elsewhere. Can you give me an example in Python how to achieve my goal?

Python classes and functions separated?

Why my IDE separates class and functions
or otherwise I get an error like this: TypeError: check_turn () is missing 1 required position argument: & # 39; turn & # 39;

def check_turn(players, turn):
    for i in turn:
        if i == 0:
            print("It's {} turn".format(players(0)))
        elif i == 1:
            print("It's {} turn".format(players(1)))
        return i

class Dev:
    players = ('Bob', 'Anne')
    turn = (0, 1)

    check_turn(players, turn)

Python – order of columns everywhere

The following code is part of a parser. These files are also added here: XMLParser, Parser, Name, GenericElement, attrib

It reads an XML file, transforms it into a data frame with pandas, and then parses it into a csv file.

The reason I'm asking this question is that the code works fine and can be easily improved. When parsing the data in CSV files, the header columns are not consistently increased.

from generic_parser import XMLParser
import pandas as pd

final = ()
df = pd.DataFrame()
tags_to_leave = ('Description', 'SetFile')
value_data = ('SetData')

def dropper(obj):
    return not in tags_to_leave + value_data, True

def final_collector(obj):
    cnt = 0
    global df
    if == 'START':
        obj = rename_attribs(obj)
        # opdatas.append(obj)
        final_dict = dict(obj.attribs)
        # final_dict.update({'ValueData' : ()})
        value_data_dict = {}
        for child in obj.children:
            if str( in tags_to_leave:
            if str( in value_data:
                for key_name in child.attribs.keys():
                    final_dict('SetData' + key_name + str(cnt)) = child.attribs(key_name)
                cnt += 1

        df = df.append(final_dict, ignore_index=True)

def rename_attribs(obj):
    if str( == 'Description':
        obj.attribs("text") = obj.text
    obj.attribs.sub_keys(r"^(.*)$", str( + r"_1")
    return obj

if __name__ == '__main__':
    xml = XMLParser.parse(r'./1234.xml')

This is the XML file

      The third
      The forth

SetDataSetData_value1 follows SetDataSetData_value1 instead of SetDataSetData_value2.

They take the correct values, but SetDataSetData_value2 is lower in column Q instead of H.

Enter image description here

The code works fine, but I don't seem to be able to correct the order.

python 3.x – Traveling Clerk – Complete algorithm

I have to create an algorithm that:
1. Discover all possible paths that visit all vertices of a diagram without going through the same vertices twice.
2. Save all results.
3. Return the path with the shortest distance.

In short, a comprehensive / rough solution to the traveling salesman's problem.
I don't even know how to create an algorithm that finds all the possibilities. I thought I was doing an algorithm that randomly tested everything and just saved the different paths already saved, but I still would not know when to stop (since I'll never be sure everything is possible options were really tested ).

Why does inheritance not work properly when embedding Python in a C ++ application?

I had asked this question in another forum, but apparently this problem is more related to Python than I thought. Strangely, I could not find too many topics on this particular topic.

In essence, I have a base class:

class B:
   def __init__(self):
   def func(self):

And a child class:

class C(B):
   def __init__(self):
   def func(self):

When I create these classes and call them only through Python, everything works fine. However, if I try this via the C API, C.func () can not call B.func (). Is the functionality of the API strange, which could lead to it? My call routine looks like this:

PyObject * PythonAPI::call(PyObject * o, PyObject * args)
    PyObject* output = nullptr;
    if (isCallableAttribute(o) && (isTuple(args) || args == NULL)) {
        output = PyObject_CallObject(o, args);
        if (output == NULL) {
            logError("Call failed");
    else {
        // Print error if occurred
        logError("Cannot find callable, or args are not a tuple");

    // Decrement count for function, ignoring if it is null

    return output;

I want users of my application to use a pure Python interface. That's why I want to pack everything they need into Class B, from which they can inherit. Thanks a lot!