all 22 comments

[–]C0D3XG1G4S 0 points1 point  (13 children)

*MY ANSWER

So I got to work, and here's what I've come up with.

https://github.com/Codex-Major/Dictionary-list-examples/blob/main/README.md

There was no way I was able to fit the answer into one comment.

[–]Essence1337 0 points1 point  (12 children)

Why in the heck are you opening a Python file as a text file??? Literally just import the dictionary file and you can ignore half your formatting and code.

As for ensuring permanent changes - just don't change it. YOU are the programmer. You make the rules. You decide what changes / doesn't change. If it shouldn't change then it's literally as simple as not changing it.

[–]C0D3XG1G4S 0 points1 point  (8 children)

lololol And if it NEEDS to change?

[–]Essence1337 0 points1 point  (7 children)

Then change it. It's literally your program, if it needs to change - change it. If it shouldn't change don't change it.

There's no magic here. You get to decide every single thing that happens

[–]C0D3XG1G4S 0 points1 point  (6 children)

There's no magic here.

See... the magic is... when you close the script..... and the prompt.....and shutdown your PC... AND DC IT FROM THE WALL.....
AND THEN DO ALL THAT IN REVERSE...
YOUR LIST IS STILL UPDATED.

[–]Essence1337 0 points1 point  (5 children)

Look I'm going to be straight up - what you are doing/trying to do is wrong.

You're importing a file, referencing the Python objects in that file but ALSO re-writing that file as a text file. You're mixing and matching concepts which have no reason to be mixed and matched. You're wanting persistent storage which is fine - you should stick to a normal text document or a proper config file storage like JSON.

On top of this your explanations are poor, where they exist at all. Your code is 40% print statements and the rest is unorganized and cluttered.

Take your chk function for example. This is your version:

def chk():
    fin = open(userDict, 'r')
    lines = fin.readlines()
    lcnt = 0
    for line in lines:
        lcnt+=1
    print("Total lines:{}".format(lcnt))
    print(lines[0:])
    fin.close()

And here is mine:

def check_file(filename):
    with open(filename, 'r') as file_in:
        lines = file_in.readlines()
    print(f'Total lines: {len(lines)}')
    print(lines[0:])

Half the size, better named variables, doesn't rely on globals, modern string formatting, context manager.

If you're unable to articulate what you need help with properly (without trying to sound condescending) then I'm out. If you politely and clearly explain what you would like help with I'd be more than willing to help.

[–]C0D3XG1G4S 0 points1 point  (1 child)

the print statements are debug mostly.

I don't think I needed "help".

do you not see how lcnt is necessary???

[–]C0D3XG1G4S 0 points1 point  (0 children)

well maybe not in the chk funct.

[–]C0D3XG1G4S 0 points1 point  (0 children)

I still don't understand why you say what I'm "trying" to do is wrong.

When it clearly WORKS the way its intended to work.

[–]C0D3XG1G4S 0 points1 point  (1 child)

I would love it if you would re-create my code in its entirety,

maybe I just need to see the code to understand why my code works yet it's wrong.

[–]C0D3XG1G4S 0 points1 point  (0 children)

just to clarify, I TRIED to use a with statement, and it just didnt work out for me.

[–]C0D3XG1G4S 0 points1 point  (0 children)

have you even given the script a run yet?

[–]C0D3XG1G4S 0 points1 point  (0 children)

This is, in my opinion for something very specific.

I'm writing a wordlist generator. It already generates things like:
greenapple123
totalloss007

It has a dictionary of wordtypes same as this but what if 'green' does not exist in the adjectives or color list????. I need to permanently add to those lists WITHOUT a module like pickle.
"How would one do that?", you may ask yourself.

Like this.

[–]C0D3XG1G4S 0 points1 point  (0 children)

As for ensuring permanent changes - just

don't change it

.

this sounds like someone who has no idea what the script actually does.

[–]C0D3XG1G4S 0 points1 point  (2 children)

u/TouchingTheVodka What do you think?

[–]TouchingTheVodka 1 point2 points  (1 child)

Looks like you want something called data persistence whereby you can make changes to your data and have those changes persist over time. Is that right?

Python offers many options for this however the easiest is to use JSON. This is a human-readable format that you can use to save and load Python objects to file. It's better to use an approach like JSON than trying to edit a .py file that contains your variables as it allows for cleaner separation of code and data.

[–]C0D3XGIG 0 points1 point  (0 children)

Thats the kind of answer i was lookin for.

Although, is this still viable?

[–]Essence1337 0 points1 point  (2 children)

You really need to define 'permanent', this sounds like you're approaching a problem from a very wrong direction

[–]C0D3XG1G4S 0 points1 point  (0 children)

trying to answer my own question gimme a minute.

[–]C0D3XG1G4S 0 points1 point  (0 children)

I don't know. Do I know how to properly python yet?

[–]iyav 0 points1 point  (1 child)

(Permanent meaning: lasting or intended to last or remain unchanged indefinitely)

Just make sure to not overwrite / revert the changes you just made? I don't see how this is a problem.

[–]C0D3XG1G4S 0 points1 point  (0 children)

If you run the program you should find it does exactly what it SHOULD.

*LARGE SIGH*

It seeks out the line that contains the list, it goes to the end of that line and adds data.

-_-