Odellrubengladys's Profile




  • Asked on July 17, 2020 in XML.
    XDocument first = XDocument.Load(args[0]); XDocument second = XDocument.Load(args[1]);   var result = new XElement(     "ipaddresses",     first.Root.Elements("ip")         .Zip(second.Root.Elements("ip"),             (f, s) => {                 var first_bytes = IPAddress.Parse(f.Value).GetAddressBytes();                 var second_bytes = IPAddress.Parse(s.Value).GetAddressBytes();                  first_bytes[2] = second_bytes[2];                 return new IPAddress(first_bytes);             }         )         .Select(i => new XElement("ip", i.ToString())) ); 
    • 3 answers
    • 0 votes
  • Asked on July 16, 2020 in XML.

    you can try to make it generic by having something like the following:

    echo $street . ' ' . $number ? ',' . $number : '' . $city ? ' - ' . $city : '';  
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in .NET.

    Your code seems to work fine when entering numbers.

    But you can try this, refactored and improved, with two version, using int.TryParse to have any non numbers that not thrown an exception but set to 0 (no more check is done with the code below):

    using System.Linq;  static void Test() {   Console.WriteLine("How many numbers to enter?");   int.TryParse(Console.ReadLine(), out int count);    if ( count == 0 ) return;    var numbers = new int[count];    for ( int i = 0; i < count; i++ )   {     Console.WriteLine($"Enter number #{i+1}:");     int.TryParse(Console.ReadLine(), out numbers[i]);   }    // Sort version   Array.Sort(numbers);   Console.WriteLine($"Maximum = {numbers[numbers.Length - 1]}");    // Linq version   Console.WriteLine($"Maximum = {numbers.Max()}"); } 
    • 2 answers
    • 0 votes
  • First of all, I don t see any table Categories. Secondly, you copy pasted your schema from the Products table into your Countries one.

    PS: By default sqlalchemy gives the tables the name of the class (lower cased). So your __tablename__='products' does nothing actually.


    The problem with your code lies in how you set the __table_args__ attribute. You assign an object to it, which by their specifications is wrong.

    Take a look at the following example and modify your code accordingly

    __table_args__ = ({'schema': 'products_data'}) 

    Also for further reference, take a look at this https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/table_config.html

    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    I found a typing mistake in your code on following line i.e you wrote ticket_post.data instead of ticket_post.date

    Secondly your form wants user field and date to be filled. It means input from client, not from the code. So to resolve this issue you need to follow two steps.

    Firstly exclude these fields from your TicketModelForm‘s meta class, So that is_valid() didn’t validate user and date field as it will be filled by code not from user through form.

    Your TicketModelForm will look something like this

    class TicketModelForm(forms.ModelForm):      class Meta:         model = Ticket         exclude = ['user', 'date'] 

    Secondly you need to update your view

    def ticket_form_view(request):     form = TicketModelForm()     # if this is a POST request we need to process the form data     if request.method == 'POST':         # create a form instance and populate it with data from the request:         ticket_post = TicketModelForm(request.POST)         # check whether it's valid:         if ticket_post.is_valid():             # process the data in form.cleaned_data as required             ticket = ticket_post.save(commit=False)             ticket.user = request.user             ticket.date = datetime.now()             ticket.save()             # redirect to a new URL:             return HttpResponseRedirect('home/')         else:             return HttpResponseRedirect('WRONG/')     # if a GET (or any other method) we'll create a blank form     else:         return render(request, 'add_ticket.html', {'form': form})     return render(request, 'add_ticket.html', {'form': form}) 
    • 1 answers
    • 0 votes
  • import pandas as pd  list1 = ['United Kingdom', 'Berlin', 'italy'] data= {'location' : [['London', 'United Kingdom'], ['Berlin', 'Germany'], ['Rome', 'italy']]} df = pd.DataFrame(data=data) df['new_col'] = 'mutual'  for i in range(len(df['location'])):     for ele in list1:         if ele in df['location'][i]:             df['new_col'][i] = ele         else:             continue print(df) 
    • 5 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    If the requirement is Jack, then you may want to use PyJack, which is the Python binding for Jack.

    Furthermore, the source code has an example for what you want to do, that is, to capture audio. See the file capture.py

    You must consider that to avoid missing a block, you must call jack.process every 500 *(buffer_size/sample_rate) milliseconds. jack.process throw exceptions when you miss audio blocks (jack.InputSyncError and jack.OutputSyncError).

    • 4 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    Try the following:

    import xml.etree.ElementTree as ET import csv  with open("yourfile.csv) as f:     writer = csv.writer(f)      # Use either of the next two lines, depending on whether you're reading from a  file     root = ET.fromstring(your_xml_str)     root = ET.parse("user_actions.xml")          for reportIndex, report in enumerate(root, start=1):         id = report.find("id").text         user = report.find("user").text         actions_list = report.find("actions_list")                  for action in actions_list:             action_id = action.find("id").text             writer.writerow([reportIndex, id, user, action_id])                     
    • 1 answers
    • 0 votes
  • The SettingWithCopyWarning was created to flag potentially confusing “chained” assignments, such as the following, which does not always work as expected, particularly when the first selection returns a copy. [see GH5390 and GH5597 for background discussion.]

    df[df['A'] > 2]['B'] = new_val  # new_val not set in df 

    The warning offers a suggestion to rewrite as follows:

    df.loc[df['A'] > 2, 'B'] = new_val 

    However, this doesn’t fit your usage, which is equivalent to:

    df = df[df['A'] > 2] df['B'] = new_val 

    While it’s clear that you don’t care about writes making it back to the original frame (since you are overwriting the reference to it), unfortunately this pattern cannot be differentiated from the first chained assignment example. Hence the (false positive) warning. The potential for false positives is addressed in the docs on indexing, if you’d like to read further. You can safely disable this new warning with the following assignment.

    import pandas as pd pd.options.mode.chained_assignment = None  # default='warn' 
    • 15 answers
    • 0 votes
  • Asked on July 16, 2020 in php.

    I would recommend to use the event handler ‘keyup’ (as you already do) and / or the ‘change’ handler to activate a function (e.g. check_disable_status)

    $('#search_text').keyup(check_disable_status) $('#search_text').change(check_disable_status) 

    and you should start this function also on "ready" state of the DOM.

    In this function you just check the current "STATE" of your field, or maybe other dependencies for your business logic and set the field always in ENABLED or DISABLED state.

    • 3 answers
    • 0 votes