Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 days ago.
Improve this question
I am trying to create from a report (report.txt file) a pdf using python, with the same content.
I cannot figure it out which will be the best way to do this, I was thinking to convert the txt file into html (using python) and after that to convert it into pdf (also using python).
The problem is that I need to create a pdf template (which will contain pictures, tables, different fonts and text sizes) and the initial txt report can be different, it will depend on a series of test cases that will generate this report.
How can I parse the txt file into html if my txt file will have a different template? Will be easier to use cvs?
Thanks for the ideas and inputs!
You can use ReportLab library to generate PDF files from Python.
It should directly convert your text file to pdf.
If you absolutely need to parse the text file to html and process first before making the pdf, then I would suggest using both ReportLab alongside BeautifulSoup or lxml library.
This will allow conversion from text to html first, before finally converting to pdf.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
I have developed a small program that reads and outputs the live data of a machine. However, the data is outputted in a confusing and unordered way.
My question is, what exactly can I do to sort the output data e.g. in a table.
Best
enter image description here
You wrote many (topic, payload) tuples to a file, test_ViperData.txt.
Good.
Now, to view them in an ordered manner, just call /usr/bin/sort:
$ sort test_ViperData.txt
If you wish to do this entirely within python,
without e.g. creating a subprocess,
you might want to build up a long list of result tuples.
results = []
...
results.append((topic, payload))
...
print(sorted(results))
The blank-delimited file format you are using is OK, as far as it goes.
But you might prefer to use comma-delimited CSV format.
Then you could view the file within spreadsheet software,
or could manipulate it with the standard csv module
or various pandas tools.
When you review the text file next week,
you might find it more useful if
each record includes a timestamp:
import datetime as dt
...
results.append((topic, payload, dt.datetime.now()))
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to read an SVG file in python 3.7. I would also like to draw several lines in this file, which contains a drawing. Drawing the lines in a newly created SVG file is no problem. One problem is opening an existing SVG file in Python, drawing in something new and then saving it again. Can someone help and tell me how I can open such a file and draw something in it? I was already looking for solutions on the internet but there was nothing that worked
i use a python lib named PYX
From the PyX Manual:
With the help of the svgfile.svgfile class, you can easily embed another SVG
file in your canvas, thereby scaling, aligning the content at discretion. The
most simple example looks like
from pyx import *
c = canvas.canvas()
c.insert(svgfile.svgfile(0, 0, "file.svg"))
c.writeSVGfile("output")
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Basically I want to store a dictionary in a text file, the reason for this is I want to be able to open the file and edit it even after I finalise the program.
It's a quiz program I'm using to help me learn the dates of certain events in geological history and I want to be able to add more questions without accessing the code.
So I would want a list of questions with their dates next to them that would be imported back to python, basically a file with a bunch of questions like this:
"Pangea formed":335000000, #Carboniferous
"Gondwana split into Africa and South America":180000000, #Jurassic
"The Chicxulub crater, buried in Mexico, formed":66043000, #Cretaceous
The problem is I don't think python is made to tell the difference from the string and the value when reading a notepad file.
Is there a way to do this?
You want to load the content of a dictionary from a file. The file should be human readable/editable. One solution is to keep the file in JSON format.
JSON is a format that can be used to convert basic objects like dictionaries, lists into text and vice versa.
So let the content of the file be:
{
"Pangea formed":335000000,
"Gondwana split into Africa and South America":180000000,
"The Chicxulub crater, buried in Mexico, formed":66043000
}
Now the file, even tough is a text file that you can open and edit in Notepad, is in the JSON format. Notice the opening and closing braces. To load the file into a dictionary you can do:
import json
with open('file.json') as f:
my_dict = json.load(f)
Note that I had removed the comments as JSON doesn't support comments. Also, the last key-value pair doesn't end with a comma.
Yes this is possible. Take a look at ConfigParser. It works based on textfiles with the .ini extension.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
This is related to website we are creating at work. The script for website is written in HTML and Python. We want to translate website in different languages text by text. The idea we have is to save all the words and phrases in the excel file and by using some API it translates everything and saves in the same excel file. I had an idea of using Google API but I want to save all the translations in Excel once so we don't have to pay for using the API again and again.
I am looking for less tedious way to:
1) Save all the words and phrases from website into the excel file
2) Translate those saved words and phrases and be able to save in the same file.
This is actually a common problem that has been solved in a similar way to what you have in mind. I would suggest taking a look at https://www.mattlayman.com/2015/i18n.html https://www.python.org/community/sigs/current/i18n-sig/ and https://docs.python.org/2/library/gettext.html which describe using the gettext method to display the proper translation. This is a common problem in web development that happens out of the box in web frameworks like ruby on rails.
I believe you will still have to find the translations yourself, but if you save them in the proper files there are built in functions that can retrieve the right translation for you based on the user's location.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have html code embeded with java script code related to angular js. Later I realized that rows and columns of html code need to be inter cahnged. As I have bunch of html files so decided to use Python script. Have tried using BeautifulSoup 4.x. I could able to do interchange of rows and columns but while writing back to disk, it is noticed that few java script tags are missing.
My question is can I use beautiful soup for angular js code? if yes, code snippet would be extremely helpful.
Thanks
Beautiful Soup is a Python library for pulling data out of HTML and XML files. You can't directly use it for angular js code.
See this previous answer for a quick look at what some code using Selenium to get at the javascript might look like.
https://stackoverflow.com/a/25985828/4147462