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

Sunday, June 26, 2022

[FIXED] How to make a print("{}") with another File?

 June 26, 2022     compiler-errors, file, python     No comments   

Issue

I want to make the print({}) display something from another File. What I have been trying:

main.py:

with open("Filename.txt", "tr") as f:
  data = f.readlines()
 if "print({})" in data:
  print("{}".format(data))

Filename.txt:

print("Hello world")

result:

This means I have made an error. But there were no error messages. What did I do wrong?


Solution

It will search for the exact string print({}). It seems like you need the text within that print statement, its better to use regex and find text between print( and ). See https://stackoverflow.com/a/3369000/7334699

I don't know what your goal exactly is, but you can also take a look at the eval() function which just runs python code within a string.



Answered By - ToTheMax
Answer Checked By - Marilyn (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