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.get("http://painelvix.com/galaxia4/formulario_testes.php?r=UUVJcFdZMXlZcE5XdVU2cGVEUjVMYllMNnVBYS9GajVVUkZ3em9tRDZObz0,")
    driver.find_element_by_name("nome").click()
    driver.find_element_by_name("nome").clear()
    driver.find_element_by_name("nome").send_keys("Teste de preenchimento")
    driver.find_element_by_name("email").click()
    driver.find_element_by_name("email").clear()
    driver.find_element_by_name("email").send_keys("teste@teste.com.br")
    driver.find_element_by_name("perfil()").click()
    driver.find_element_by_xpath("//*/text()(normalize-space(.)='Solicitar')/parent::*").click()
    self.assertEqual("Existe um teste pra este email cadastrado em: 28/03/2019", self.close_alert_and_get_its_text())
    driver.close()

Plus the youngest:

if __name__ == "__main__":
unittest.main()

Run the Python script using Java code

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

String cmdStr =
      "C:\ProgramData\Anaconda2\python.exe
       C:\dicom\write_pydicom_cmd.py
      -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";

Runtime.getRuntime().exec(cmdStr);

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__

(..)

subprocess.call("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

(Unit)
Description=Notification service

(Service)

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

# keep process after user logs off
RemainAfterExit=false

(Install)
WantedBy=default.target

When I call /usr/bin/python3 /path/to/__main__.py 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': '0.0.0.0:6881'}) 
       self.ip_filter = None
   ….more….

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

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 172.16.100.36, 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 obj.name not in tags_to_leave + value_data, True

def final_collector(obj):
    cnt = 0
    global df
    if obj.name == 'START':
        obj.recurs_drop(dropper)
        obj.recurs_change(rename_attribs)
        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(child.name) in tags_to_leave:
                final_dict.update(dict(child.attribs))
            if str(child.name) in value_data:
                for key_name in child.attribs.keys():
                    print(key_name)
                    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(obj.name) == 'Description':
        obj.attribs("text") = obj.text
    obj.attribs.sub_keys(r"^(.*)$", str(obj.name) + r"_1")
    return obj



if __name__ == '__main__':
    xml = XMLParser.parse(r'./1234.xml')
    xml.recurs_collect(final_collector)
    df.to_csv("./1234.csv")

This is the XML file




    
      
        23423
        342342
      
      The third
      
        
        
        
        
      
    
    
      
        225198
        343243324234234
      
      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):
       B.__init__(self)
       ...
   def func(self):
       B.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) {
#ifdef DEBUG_MODE
            logError("Call failed");
#endif  
        }
    }
    else {
        // Print error if occurred
        printErrors();
#ifdef DEBUG_MODE
        logError("Cannot find callable, or args are not a tuple");
#endif
    }

    // Decrement count for function, ignoring if it is null
    Py_XDECREF(o);

    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!