Re: python Store text file in mangodb
On 12/06/2022 14:40, Ayesha Tassaduq wrote:
Hi i am trying to store a text file into MongoDB but i got the error .
"failing because no such method exists." % self.__name.split(".")[-1]
TypeError: 'Collection' object is not callable. If you meant to call the
'insert' method on a 'Collection' object it is failing because no such method
exists.
Can anyone please tell what is wrong here
i also tried to do it with insert_one and insert_many
but when i try to do it with insert_many it shows error
raise TypeError("documents must be a non-empty list")
TypeError: documents must be a non-empty list
Read the error messages carefully:
(1) "...If you meant to call the 'insert' method on a 'Collection'
object it is failing because no such method exists."
It may be a bit unfortunate that attributes spring into existence when
you try to access them, but you want an "insert" method, and the error
message warns you that no such method exists. You can run your script in
idle and then type
>>> collections.insert
to see what it actually is.
(2) "...documents must be a non-empty list"
The insert_many() method expects a non-empty list of documents Example:
collection.insert_many([text_file_doc])
You don't provide an error message for insert_one(), and indeed it
should work where you tried insert():
collection.insert(text_file_doc)
from pymongo import MongoClient
client = MongoClient()
db = client.test_database # use a database called "test_database"
collection = db.files # and inside that DB, a collection called "files"
f = open('hashes.txt') # open a file
# build a document to be inserted
text_file_doc = {"file_name": "hashes.txt"}
# insert the contents into the "file" collection
collection.insert(text_file_doc)
File names Hshes.txt has follown=ing data
You are not yet at the point where you are using the file or its
contents, so the file object and the file's contents could be omitted.
Generally it is a good idea
- to make your script as short as possible as long as it still produces
the error. In the process you will often be able to fix the problem
yourself.
- always provide the tracebacks using cut-and-paste. That is often
sufficient to diagnose and fix the problem.
Hash 1: 39331a6a2ea1cf31a5014b2a7c9e8dfad82df0b0666e81ce04cf8173cc5aed
Hash 2: 0e0ff63b7e5e872b9ea2f0d604b5d5afd6ba05665e52246fa321ead5b79c00ad
Hash 3: 89241ce841704508be1d0b76c478c9575ec8a7ec8be46742fd5acb0dc72787f3
Hash 4: 80283cb08f91b415aae04bcada0da1ca3e37bbe971ae821116b4d29008970bdb
--
https://mail.python.org/mailman/listinfo/python-list
Suggestion. Replace Any with *
It would be nice if we could write something like this
data: dict[str, *] = {}
instead of
data: dict[str, Any] = {}
In import statement asterisk means "all names" in a module.
But in type closure it should mean "all types".
--
https://mail.python.org/mailman/listinfo/python-list
fill out bulletins
Hello everyone, I would like to write a tool to compile post office bulletins because here, unfortunately, they are still the most convenient way to interface the public administration. I don't want to create a UI to edit the bulletin, I will take the data from some file or database but I'd like to print or save the bulletin to the file with all the fields filled in. To accomplish this, I thought about creating a basic graphic (jpg?) file with the bulletin image, filling in the fields and then saving it in a new file. Can you direct me to a better way? And also, direct me to a library that allows me to accomplish this easily? Thank you in advance. -- https://mail.python.org/mailman/listinfo/python-list
Re: Suggestion. Replace Any with *
On Tue, 14 Jun 2022 at 01:59, h3ck phy wrote:
>
> It would be nice if we could write something like this
> data: dict[str, *] = {}
> instead of
> data: dict[str, Any] = {}
>
> In import statement asterisk means "all names" in a module.
> But in type closure it should mean "all types".
Type hints are normal Python syntax. For this to be legal in a type
hint, it would need to be legal in the rest of Python. What would it
mean?
some_object[other_object, *]
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: fill out bulletins
On 13/06/2022 08.49, jak wrote: Hello everyone, I would like to write a tool to compile post office bulletins because here, unfortunately, they are still the most convenient way to interface the public administration. I don't want to create a UI to edit the bulletin, I will take the data from some file or database but I'd like to print or save the bulletin to the file with all the fields filled in. To accomplish this, I thought about creating a basic graphic (jpg?) file with the bulletin image, Please don't create an image. Create something that preserves text as text, so that your recipients can (if they so desire) search on that text, or copy/paste from your bulletin. Somebody suggested TeX/LaTeX. Excellent idea. -- Michael F. Stemper A preposition is something you should never end a sentence with. -- https://mail.python.org/mailman/listinfo/python-list
Re: fill out bulletins
On 6/13/22 11:11, Michael F. Stemper wrote:
> On 13/06/2022 08.49, jak wrote:
>> Hello everyone,
>> I would like to write a tool to compile post office bulletins because
>> here, unfortunately, they are still the most convenient way to interface
>> the public administration. I don't want to create a UI to edit the
>> bulletin, I will take the data from some file or database but I'd like
>> to print or save the bulletin to the file with all the fields filled in.
>> To accomplish this, I thought about creating a basic graphic (jpg?) file
>> with the bulletin image,
>
> Please don't create an image. Create something that preserves
> text as text, so that your recipients can (if they so desire)
> search on that text, or copy/paste from your bulletin.
Absolutely agree. We're having a flood of people post code on Twitter
and LinkedIn, which don't support code markup/markdown, so they post
images. There are several tools that make really pretty pictures... and
they're completely useless as you can't pick the code out of them. Hate
this.
> Somebody suggested TeX/LaTeX. Excellent idea.
>
Don't know what a "post office bulletin" is, but this sounds like a
template problem ("all the fields filled in"). There are a lot of
templating engines in the Python world from string handling in the
standard library
(https://docs.python.org/3/library/string.html#template-strings) to
tools like JInja and Cheetah and a host of others. I think there are
many of these listed on the wiki - maybe something here would suit your
needs?
https://wiki.python.org/moin/Templating
--
https://mail.python.org/mailman/listinfo/python-list
Re: fill out bulletins
Il 13/06/2022 16:12, Stefan Ram ha scritto: jak writes: Can you direct me to a better way? You could use a word processors with a mail-merge feature or generate TeX/troff code for the bulletins. >Of course, for Python, the library PIL/Pillow is available, which can read or write JPG files and has a "text" method to write text to images. I you want to print the bulletins, you could have a first pass where the images are printed and then reinsert the same sheets again to add the text in a second pass. I made a few attempts with libreoffice, unfortunately the bulletin is too complicated to get a good result. I also took a look at Tex/LaTeX as you advised me. Of these I just knew that they existed and their use but I didn't want to learn a new script just for a tool and in any case I think I would encounter the same problems I had with the word processor. I think I will use the PIL/Pillow librariesalso because I wanted to dynamically calculate the size of the characters so as not to go beyond the limits of the fields to be filled in in the image. Thanks for the tips. -- https://mail.python.org/mailman/listinfo/python-list
Re: fill out bulletins
Il 13/06/2022 19:11, Michael F. Stemper ha scritto: On 13/06/2022 08.49, jak wrote: Hello everyone, I would like to write a tool to compile post office bulletins because here, unfortunately, they are still the most convenient way to interface the public administration. I don't want to create a UI to edit the bulletin, I will take the data from some file or database but I'd like to print or save the bulletin to the file with all the fields filled in. To accomplish this, I thought about creating a basic graphic (jpg?) file with the bulletin image, Please don't create an image. Create something that preserves text as text, so that your recipients can (if they so desire) search on that text, or copy/paste from your bulletin. Somebody suggested TeX/LaTeX. Excellent idea. Part of the answer I gave to Stefan, moreover my goal is to get a piece of paper to give to the post office and not a document to share (it could contain personal data). -- https://mail.python.org/mailman/listinfo/python-list
Re: fill out bulletins
Il 13/06/2022 23:58, Mats Wichmann ha scritto:
On 6/13/22 11:11, Michael F. Stemper wrote:
On 13/06/2022 08.49, jak wrote:
Hello everyone,
I would like to write a tool to compile post office bulletins because
here, unfortunately, they are still the most convenient way to interface
the public administration. I don't want to create a UI to edit the
bulletin, I will take the data from some file or database but I'd like
to print or save the bulletin to the file with all the fields filled in.
To accomplish this, I thought about creating a basic graphic (jpg?) file
with the bulletin image,
Please don't create an image. Create something that preserves
text as text, so that your recipients can (if they so desire)
search on that text, or copy/paste from your bulletin.
Absolutely agree. We're having a flood of people post code on Twitter
and LinkedIn, which don't support code markup/markdown, so they post
images. There are several tools that make really pretty pictures... and
they're completely useless as you can't pick the code out of them. Hate
this.
Somebody suggested TeX/LaTeX. Excellent idea.
Don't know what a "post office bulletin" is, but this sounds like a
template problem ("all the fields filled in"). There are a lot of
templating engines in the Python world from string handling in the
standard library
(https://docs.python.org/3/library/string.html#template-strings) to
tools like JInja and Cheetah and a host of others. I think there are
many of these listed on the wiki - maybe something here would suit your
needs?
https://wiki.python.org/moin/Templating
If you are interested in seeing what I called "post office bulletin"
(English is not my language and I don't know the name, sorry), you can
find a sample pdf (fillable) but it works badly here:
https://www.guardiacostiera.gov.it/venezia/Documents/Bollettino%20MOD.%20TD123.pdf
--
https://mail.python.org/mailman/listinfo/python-list
Re: fill out bulletins
On 2022-06-13 23:41, jak wrote: [snip] If you are interested in seeing what I called "post office bulletin" (English is not my language and I don't know the name, sorry), you can find a sample pdf (fillable) but it works badly here: https://www.guardiacostiera.gov.it/venezia/Documents/Bollettino%20MOD.%20TD123.pdf Probably best to just call it a "form". -- https://mail.python.org/mailman/listinfo/python-list
Re: fill out bulletins
Another possibility is to use reportlab to generate a pdf. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: fill out bulletins
On 14/06/2022 11.34, MRAB wrote: > On 2022-06-13 23:41, jak wrote: > [snip] >> >> If you are interested in seeing what I called "post office bulletin" >> (English is not my language and I don't know the name, sorry), you can >> find a sample pdf (fillable) but it works badly here: >> >> https://www.guardiacostiera.gov.it/venezia/Documents/Bollettino%20MOD.%20TD123.pdf >> > > Probably best to just call it a "form". pygame might offer a simple way to add text to a 'form' at appropriate x,y co-ordinates. -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
