Building a program that can enter data into a field

Joined
Aug 18, 2022
Messages
2
Reaction score
0
Hello All,

For starters, I'm super green when it comes to python, but it seems like the best language for what I'm trying to do here.

Basically, I have a csv of 2000 users I manually have to delete from our system. Each user has an ID that can be plugged in, then just hitting the delete key, (then hitting ok on the pop-up prompt) will delete that one user. I already have a csv of the user ID's, but I'm really struggling to find a way to only work with one line of the csv at a time with the keystrokes in between each line.

I really just need some resources or examples of similar programs to work off of that describe some of the needs I mentioned above.

Thanks!
 
Joined
Aug 11, 2022
Messages
12
Reaction score
0
I can't give you the code, but here is the algorithm. I do similar stuff all the time, but not with Python.

1) Have the user ID's due for deletion in one file
2) read the file and place all the IDs_for_deletion into an array.
3) Read in the csv file of all users
4) one line at a time, compare the user ID of that line against the contents of the array
5) if this_ID is in the array, skip to the next line (you are going to rebuild the the user.csv file and you don't want this user in it)
6) if this_ID is NOT in the IDs_for_deletion array, write the line into a new csv file (for safety, use a new file name .. you can use the existing formatting of the line)
7) continue until the end of user.csv and your new file will have all the "non-deletable" users in it and none of the IDs_for_deletion.
 
Joined
Aug 18, 2022
Messages
2
Reaction score
0
I can't give you the code, but here is the algorithm. I do similar stuff all the time, but not with Python.

1) Have the user ID's due for deletion in one file
2) read the file and place all the IDs_for_deletion into an array.
3) Read in the csv file of all users
4) one line at a time, compare the user ID of that line against the contents of the array
5) if this_ID is in the array, skip to the next line (you are going to rebuild the the user.csv file and you don't want this user in it)
6) if this_ID is NOT in the IDs_for_deletion array, write the line into a new csv file (for safety, use a new file name .. you can use the existing formatting of the line)
7) continue until the end of user.csv and your new file will have all the "non-deletable" users in it and none of the IDs_for_deletion.
You mention that you don't typically do stuff like this in Python. If you don't mind me asking, is there a language better suited to this sort of task? Or, is your preference away from python more to do with personal taste/experience?
 
Joined
Aug 11, 2022
Messages
12
Reaction score
0
I have just never learned Python. Personally, in my brief exploration of the language, I find the syntax of the code non-intuitive. I much prefer PHP. See my "Hello" post for more info on my background.

The key element in this algorithm is the need to find (or not find) a particular value in an array. Python seems to have something approaching this, but a quick Google search indicated that its index(x) function returns an error if the element is NOT in the array (Python calls these "lists") and some error trapping code is required.

Whereas PHP has the in_array() function. True or False, it's there or it isn't. Exactly what is needed.

in_array​

(PHP 4, PHP 5, PHP 7, PHP 8)
in_array — Checks if a value exists in an array

Description​

in_array(mixed $needle, array $haystack, bool $strict = false): bool
Searches for needle in haystack using loose comparison unless strict is set.

My inclination is to say that your task is so straightforward that it would make a very good practice problem for classes in any programming language. Just write the code for each of the steps, testing each step before adding the next. You will have it done in no time, and you will learn the syntax of your chosen language along the way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top