Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

That's the nice thing about the inspection tool. The lower panel allows you to execute Python code on the fly. It also has intellisense. Select the object you are interested in from the top left panel (clicking the Sizer icon on the toolbar will eliminate sizer items from the tree). Then click in the lower panel. You'll see the Size propety in the top right panel. The currently selected object can be referred to by obj. So in the lower panel start typing

obj.

When you type the dot you will get a popup of all valid methods and properties. Either scroll down or continue typing something like

obj.SetSize((1000,800))

and when you press enter you will see the object resized. Very handy for trying out minor code changes or looking for the right method to use.

I frequently use

DEBUG = True

if DEBUG: import wx.lib.mixins.inspection
.
.
.
if DEBUG: wx.lib.inspection.InspectionTool().Show()

in code while I'm developing. Easy to just change it to

DEBUG = False

and just leave it in later.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Easiest way is to add

import wx.lib.mixins.inspection

at the top and

wx.lib.inspection.InspectionTool().Show()

after

self.Show()

This will bring up an inspection window where you can examine all of your display items.

I strongly recommend that you upgrade to Python 3.9.x and the latest wxPython. Don't pick the most recent Python as there is not currently a wxPython build for that release.

I also recommend you take a look at OOP naming conventions. Typically, objects are named for what they are and methods for what they do.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It looks like <\>

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It seems to me that a simple solution would be to set up each script on a loop and put a pause at the end for the interval you want.

import os
import sys
import time

try:

    while True:
        #put your  processing code here
        print('tick')
        time.sleep(5)   #sleep for 5 seconds

except KeyboardInterrupt:

    #This gets triggered on CTRL-C from the keyboard
    #Put your clean-up code here
    sys.exit()

If you wanted to keep all your data in one place you could set up a sqlite database.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In the event that this is for work rather than for personal use I highly recommend adTempus. It is an excellent package for scheduling processes and supports a large variety or trigger types including folder events. I'm not paid to endorse it. I just used the product for several years and was impressed by it's capabilities and the quick response to any questions I had. It is also very reasonably priced. Just a suggestion in case you have an actual budget and the need for such software.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Depending on what the scripts are doing and how fast they need to react you could always build in pauses to reduce cpu loading. Or, if your processing depends on, for example, the appearance of files, you could implement a folder watch which would idle itself until a predefined folder event occurs.

I have a script that I run when I want to download a sequence of images from one or more websites. The main loop watches for the creation of a window titled "Save As". When this window is detected it scans the current folder for names like "Image ####.jpg" and auto-generates the next available number in the sequence. It then pastes this name into the filename box of the Save As window. It then clicks the "Save" button. It saves me a lot of useless typing and clicking. The main loop runs with a one second sleep so there is essentially no overhead when there is nothing to do.

What is it your scripts are supposed to do? Perhaps I can offer some suggestions. The majority of what I did before retiring involved automating real time processes that had to run continuously.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Is there a reason you need to run the scripts from within idle as opposed to just running the scripts directly? If so then I suggest you look at AutoItX. I've been using AutoIt for years in both a corporate and home environments, originally from vbScript but now from Python. While the splash page says "basic like scripting language", it also installs a scriptable (from vbScript/Python) component that you can create by

import win32com.client
aut = win32com.client.Dispatch("AutoItX3.Control")

There is an AutoItX help file that you can refer to after installation to get details. In includes extensive controls for window and mouse manipulation (and a lot more).

It's free.

rproffitt commented: That looks like a "way of achieving this" to me! +15
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

This is the code I am using in my timer app and it works perfectly.

    # Stop timer and sound alarm if timer expired
    if self.txtRem.GetValue() == '00:00:00':
        self.Stop()
        winsound.PlaySound('alarm.wav',winsound.SND_FILENAME | winsound.SND_ASYNC)
        if self.chkPopup.IsChecked():
            dlg = TimerMessage('Timer Expired', self.txtDesc.GetValue())
            dlg.Show(1)

Does your wav file play properly in another app like vlc media player?

mangle200 commented: yes it does and it works in python only if i don't add the SND_ASYNC yet it does outside the dictionary +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try winsound.SND_FILENAME | winsound.SND_ASYNC for the flags

mangle200 commented: i have tried this already +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You're most of the way there. All the code under def ModFalsePos has to be indented to belong to that function, and you have to do a little initialization of some variables. That and fix a typo or two.

def f(x): 
    return -0.6 * x * x + 2.4 * x + 5.5

def ModFalsePos(xl, xu, es, imax, xr, ea):

    iter = 0
    iu   = 0.0
    fl   = f(xl)
    fu   = f(xu)

    while True:

        xrold = xr
        xr = xu - fu * (xl - xu) / (fl - fu)
        fr = f(xr)
        iter += 1

        if xr != 0.0 :
            ea = abs((xr - xrold) / xr) * 100

        test = fl * fr

        if test < 0.0:
            xu = xr
            fu = f(xu)
            iu = 0.0
            il += 1

            if il >= 2:
                fl = fl / 2.0

        elif test > 0.0:
            xl = xr
            fl = f(xl)
            il = 0
            iu += 1

            if iu >= 2:
                fu = fu / 2.0
        else:
            ea = 0.0

        if ea < es or iter > imax:
            break

    return xr

if __name__ == '__main__':
    result = ModFalsePos(xl=2.0, xu=6.0, es=0.001, imax=1000, xr=1.0, ea=0.0001)
    print(f'{result=}')
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What parts are unclear? I think I've pretty much done everything but show you the complete correct code which is almost line for line what is given in the pseudo-code.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

There are a couple of problems.

The spec says to run for xl=2 xu=6 es=0.001 imax=1000 iter=1 ea=0.0001. The problem is that iter is not a parameter. Should this be xr=1?

You don't need to import numpy. Remove it.

You have to define the function f(x), likely as

def f(x): return -0.6 * x * x + 2.4 * x + 5.5

then indent the rest of your code under modfalsepos (define it with the same capitalization as in the spec).

Take out lines 6-11.

Take out the brace brackets. You are not writing c/c++ or java. This is Python and brace brackets are used for dicts and sets.

The line

xrold == xr

compares xrold and xr. It is not an assignment statement.

You may run into a problem with iu. If the code for elif test > 0.0 executes before the code for if test < 0.0 then iu will be undefined when you try to increment it.

In Python you don't assign a value to the function name at the end. You just do

return xr

Finally, you need a mainline to actually call your code. Add

if __name__ == '__main__':
    result = ModFalsePos(xl=2.0, xu=6.0, es=0.001, imax=1000, xr=1.0, ea=0.0001)       
    print(f'{result=}')

at the end

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What attached picture?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I had an external drive "go" on me and it ended up being the controller on the drive enclosure. I got a new (NexStar) external bay, popped in the drive and it was fine. My local computer shop (Itech Computers) has several open external mounts in their service area. They were able to slide the drive in and check it in under 30 seconds. Any reputable place should do that for free.

Carsten_1 commented: Thanks +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

There are also utilities which might be able to recover data from a failed (or near failed) drive. I recommend spinrite.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The first obvious steps:

  1. reboot
  2. try a different cable
  3. try a different USB port
  4. try a different computer
Carsten_1 commented: Tried new computer too. Nothing. Does this mean my drive is bad? +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Please read the Daniweb Posting Rules and Suggestions For Posting Questions. You have to show proof of effort to get help.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Isn't that pretty much the same thing you asked here? Why start a new thread?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

PS. Code Snippet is to be used only for working (debugged), commented, and documented code.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
  1. Why are you calling the multiplication result sum?
  2. Why are you storing an integer result in a Double?
  3. Why aren't you reading the user response from the console?
  4. Why are you comparing a and b?

Use the StrDup method instead of using a loop.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

That was a Duh! moment

We've all been there.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You are calculating

TotalPay = ((float(hrs) * float(HourlyRate)) + ((float(OvrTimehrs) * float(OvertimeRate) *   float(HourlyRate))))

You are using the total hours multiplied by your hourly rate. You want 40 * HourlyRate. That would give you the answer you expect.

littlepr commented: Oh! That was a Duh! moment in my logic. Thank you Reverend Jim. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'm glad we finally got there. I seem to have had a blind spot about the meaning of the last column though. I hope that didn't cause too much confusion.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you are going to use pandas then forget the standard file open and just do

df = pd.read_csv("airlines.txt")

and keep in mind thatin your for loop, Airline will contain both the airline name and the route name. For example, one line of

Alitalia Rome      180

will give you "Alitalia Rome". You might want to try

for route,flights in zip(df['Airline'],df['Flights']):

and then separate the airline portion by

airline,*rest = route.split()

If you are unfamiliar with this expression, what it does is to split the string using a space as a delimiter. The first token (the airline) goes into airline and the remaining tokens go into rest. This saves you from an error if the route has more than one word.

Once you have the dictionary built you'll still need to iterate through it to find the entry with the largest number of flights.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

That's sort of pseudo-code but still too code-ish. Try to write it like you are telling a person how to do it step-wise with pencil and paper. Your pseudo-code shouldn't have terms like 'open file', 'string', 'integer', or whatever a 'boucle' is.

There is a very useful feature in Python called a Dictionary. A dictionary uses key-value pairs. Unlike a list which you index by an integer, a dictionary is indexed by a key which can be any type. If you use the airline name as the key and the number of flights as the value you can keep a running total for each airline. The only gotcha is that you have to check if the key already exists, so your code looks like

totals = {}     # create an empty dictionary

If you split each line into three fields named airline, route and flights then you can do

if airline not in totals: totals[airline] = 0
totals[airline] += flights

So take that and try to figure out the rest.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Let's have a look at what you have now following my suggestions first.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Although I don't know why you are importing collections when you aren't using them, and I think you are over-complicating things by using pandas dataframes for such a simple application. I suggest you write your process as pseudo-code before you try to write actual code. Debug your pseudo-code on pencil and paper first with a small dataset example.

From what I can see you need to add a header line to your CSV to name the columns. For example, if your file looks like

Airline,Flights
Alitalia Rome,180
Alitalia Pisa,82
Germanwings Munich,96
Germanwings Frankfurt,163
NorwegianAir Bergen,202
Wizzair London,184
Wizzair Frankfurt,83
Wizzair Lisbon,198

then to iterate through the records you could do

for airline,flights in zip(df['Airline'],df['Flights']):
    print(airline,flights)

There are likely other ways to do this but I got this from a brief look at the 'getting started' guide. Let me know how it goes and where you are stuck and we can take it from there. I'll check back in a couple of hours.

medsibouh commented: Good +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I've never user pandas or collections but I noticed that although

from collections import counter

does not work,

from collections import Counter

does (upper case c in Counter). Perhaps that will help. I also noticed that the data you posted is not comma delimited,

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try

$stmt = $pdo->prepare("INSERT INTO 'download' ('IP_ADDRESS', 'FILENAME') VALUES (?, ?)");

Note the small change from ") to )")

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I disagree with Dani. I think C++ is a terrible first language for learning the fundamentals of programming and algorithm design. I think Python is much better for that. With C++ you have to be too concerned with the underlying structure of the machine. You shouldn't have to worry about how strings are stored, null termination, pointers as opposed to variables, etc. when learning the fundamentals. Develop good programming habits first. Learn the "how" before the "why". Learn to walk before you learn to fly.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try View -> Group By -> (none), then go to details view (CTRL-SHIFT-6) and pick your sort column.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What you posted is not fully tested, reusable code. What you posted is a question which clearly falls under the default category of "discussion/question".

When you created this thread, right above the area where you pasted your code was:

DO NOT post code with errors or known bugs. Code snippets must be fully tested, reusable code to share with others.

Clearly you found those instructions confusing. Would you care to suggest alternate instructions?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Hope you can keep everything in check

If I didn't know I was sick I wouldn't know I was sick. So, great.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Holy crap. Great to see you in the forums again. I've had not a great year. More surgery in January and 7 weeks of radiation in March/April but things have settled down again and we've beaten the wolf back from the door. I have been trying to hunt down ddanbe because he hasn't checked in in a while. He hasn't been responding to his regular email. While I was checking up on him it occurred to me that we haven't heard from you in ages. How have you been? I'm sure you'll notice a big difference since the last time you were here.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The way I would do this is to make the tables more general. You have a table set up for a specific number of courses. If you need to add or remove courses you have to alter the table. Instead, you should have a table that maps courses to a course ID. Then you can have a table that tracks any number of courses. Adding a new course is simply a matter of adding a record to the mapping table, then adding one or more records to the tracking table. That gives you the ability to query the tracking table for how many times any value appears for any course without having to do the query for every course column.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you want help with code

  1. post valid code (properly formatted)
  2. take the time to explain what you want
  3. if you have a specific problem please state with what (and where)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It seems to me that if you have something that really needs to be hidden, instead of creating a complex workaround to try to hide stuff in (sort of) private properties (resulting in something that may be impossible to maintain), you'd be better off writing the critical stuff in C/C++, compiling it, then adding a wrapper the same way that wxPython is a wrapper for wxWidgits.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

"Driver Hell" is real

To be fair, it's much easier for Apple to minimize driver problems when they have complete control over the hardware. Microsoft can only provide the interface, then hope that the hardware manufacturers follow the rules when it comes to writing the drivers. Of course, that also depends on Microsoft providing proper (complete) documentation, and we know their record on that score.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I posted code that will do that. It's the only solution you have so far so use it until something better comes along. I tested it with the xml text that you provided, and requesting the fields you specified. I loaded the test data with

txtXML.Text = My.Computer.FileSystem.ReadAllText("D:\test.xml")

2019-06-26_111457.jpg

2019-06-26_111253.jpg

2019-06-26_111309.jpg

cheikh06 commented: thank you very much it works well with your function +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Dang. I always complain when other people do this and now I did it. I left out the import when I posted the code. Please add the following:

Imports System.Text.RegularExpressions

I'll see if I can figure out the Linq version. I'll post it later if I have any luck.

cheikh06 commented: Thank you for your help with this function but it returns me not found +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I've never had much luck working with XML and I'm sure there is a better way to do this via Linq but you could try a regular expression approace as in

Private Function GetField(name As String) As String

    Dim pattern = name & "=""(.*?)"""
    Dim rex = New Regex(pattern)
    Dim match = rex.Matches(txtXML.Text)

    Try
        Return match(0).Groups(1).Value
    Catch ex As Exception
        Return "not found"
    End Try

End Function

Pass it a field name like "supercollection name" (case sensitive) and it will return a field value as a string. If you want someone to post a Linq solution you'll have to post a complete xml sample document.

rproffitt commented: This is my story. Client hands me XML, Microsoft XMLreader blows up. I parse it with my own code. +15
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

For future reference, Code Snippet is meant for posting working and documented snippets of code. It is not to be used when you are posting a piece of code that you are having problems with. Please post under Discussion/Question.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You are allowed to edit your post within 30 minutes of iniitially posting it.

Gloak commented: I don't like it... I was planning to delete and post the same thing again... but I can't. +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It's a combination of syntax and addressing. Try

const int NUMSTUDENTS = 10;

int main()
{
    int marks[2][NUMSTUDENTS];
    printf("Enter the marks of the %d students :\n",NUMSTUDENTS);

    for (int i = 0; i < NUMSTUDENTS; i++)
    {
        printf("\nEnter the marks of student :%d", i+1);
        printf("\nAssignment Mark :");
        scanf("%d", &marks[0][i]);
        printf("Exam Mark :");
        scanf("%d", &marks[1][i]);
    }
    printf("****************************************************************\n");
    for (int i = 0; i < NUMSTUDENTS; i++)
    {
        printf("Student No :%d\n", i+1);
        printf("Assignment Marks :%d\n", marks[0][i]);
        printf("Exam Marks :%d\n", marks[1][i]);
    }
    getchar();
    return 0;
}

Please note that I replaced the literal 10 with NUMSTUDENTS. You should really break the habit of hard coding literals. If you had a longer program with a 10 sprinkled throughout you could easily bury yourself in bugs if you later had to change the 10 to some other value. And you might end up changing a non-related 10 by mistake. The const NUMSTUDENTS is clear and unambiguous.

Malpractice makes malperfect.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

There is a lot of the same old mindless drivel about SEO, backlinks and such, and a lot of homework posting. There was one interesting discussion a while back in the former geeks-lounge re Quebec's proposed religious symbols legislation. Aside from java questions (which I am not qualified to answer) there hasn't been much going on outside of pharma-banning and necro-posting.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

it just told me no such command exists

You'd either have to:

  1. Run it from the folder containing the executable
  2. Run it from another folder but fully qualify the executable
  3. Place the executable in a folder contained in your PATH environment variable

I have a folder namedf D:\Utils and have added it to PATH. That way any custom command line apps I write or download can be placed there and accessible from anywhere.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You use it like it says.

nlist_it filename.ext

Run it with the name of a text file as a parameter and it will list that file to the console. I compiled and ran it and it works as it is supposed to.

By the way, no book will teach you a language in 21 days.

rproffitt commented: Or how to use the command line or what the command line is and all you can command on the command line. ;) +15
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What part of "it's a hoax" was unclear?

rproffitt commented: I wonder how many don't know how to research such things. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
  1. Open an Explorer window
  2. Right click on This PC and select Properties from the pop-up menu
  3. In the Control Panel window click on Advanced system settings
  4. Click on Environment Variables

At this point you have to decide if you want the change to apply to just the current user, or for all users. You will click on Path in either the upper list (current user) of the lower list (all users).

  1. Click on the appropriate Edit... button.
  2. In the Edit environment variable window click New
  3. Enter the desired path info into the edit box
  4. Click OK
  5. Click OK
  6. Click OK
rproffitt commented: OK. OK. OK. Don't take this wrong, that's how it's done. (Are your sure? OK!) +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I suggest you do something like

dim qry as string = "INSERT INTO Table VALUES ('" & PatientID.Text & "', '" & fname.Text & "'," & lname.Text & "')"

and examine the contents of qry. There is no way for us to see what the query is without knowing the values of the text fields that make it up.