-1

I am making an apple ][ (2) emulator, and I am working on the last part, writing the code

What I want to happen is when somebody inputs the following:

20 x = 0

In the file, on line 20, it should put:

x = 0

When looking it up, I cant find anything to help with it, other then checking the whole string for numbers.

The 3 problems are:

  1. writing to the correct file line
  2. not writing the file line number to the file line
  3. removing any blank lines

an example for 3 is:

Well say this is the file were using:

x = 0



while True:
    
    
    
    
    if x = 9:
        
        
        
        
        x = 0
        
    
    
    
    x += 1

if somebody inputs '20', the file then should look like this:

x = 0



while True:
    
    
    
    
    if x = 9:
        
        
        
        
        x = 0

Rather then this:

x = 0



while True:
    
    
    
    
    if x = 9:
        
        
        
        
        x = 0
 
 
 
 
 
6
  • This question is too vague. Please post actual code, so we don't have to guess what you meant. Commented Nov 1, 2023 at 17:38
  • @JohnGordon I don't have any code yet, I cant find anything on how to do it, and I don't have any ideas on how to do it either. Commented Nov 1, 2023 at 17:41
  • Beware, you are mixing different aspects. Your question could be related to a Basic language interpretor where all lines in a program are preceded by a line number, or to a text editor where someone could insert a line at a given position. They have always been different environments for a reason... If you want to emulate how old systems used to work, refrain to adding too many new functionalities. Commented Nov 1, 2023 at 17:41
  • @SergeBallesta I am not adding new functionallity. In fact, I still need to add more stuff to it. Commented Nov 1, 2023 at 17:44
  • Split the text input on spaces using split(), then grab the first part and check if it is numeric. What is the difficulty? Commented Nov 1, 2023 at 17:46

1 Answer 1

0

You use .split

You take the obj 0, then use that for placements as far as placing on a specific line goes, you have to make the whole file a list, then write to the list object, then rewrite it to the file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.