PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 30, 2022

[FIXED] What does % mean in a file

 October 30, 2022     bash, eof, python     No comments   

Issue

I am getting a '%' character when I cat the file. When I open this using sublime text or vim, this '%' character does not show up. I am using the following code to generate my json.txt file:

import json

filename = "json.txt"


with open(filename, "r+") as f:
    x = [1, 'simple', 'list']
    json.dumps(x)
    json.dump(x, f)

Solution

If you run cat and see %, as DroidX86 has said, it means that there is no a new line at the end of the file, you can avoid this problem using the following code:

import json

filename = "json.txt"

with open(filename, "r+") as f:
    x = [1, 'simple', 'list']
    print(json.dumps(x, indent=4),file=f)

Now, if you run cat, you no longer will see the % since the function print adds a new line for you.



Answered By - lmiguelvargasf
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing