Re: PEP8 compliance
Chris Angelico wrote: ... and THIS RIGHT HERE is why the tool should not be called "pep8". Didn't this exact discussion come up and the tool got renamed? Seems it's been renamed to pycodestyle, but there's still an old project called pep8 on pypi.org. I guess there's always going to be some confusion as long as it's there to be found. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: pep8 Re: Posting warning message
On 14Jun2018 02:35, Tamara Berger wrote: On Thu, Jun 14, 2018 at 1:49 AM Cameron Simpson wrote: Just as you can run your code before you install it, you can lint your code beforehand also. In fact, you should be doing both: run and test the code _before_ installing it, and also lint it (when you care) and test again (because if you made lint changes you want to check they haven't done something unwanted). Great. So I'm using three interfaces: in my case, the text editor, the Python shell, and the UNIX terminal. Is that right? Possibly; I thought you were using IDLE, which is a GUI with a simple editor and a Python interpreter built in? My setup tends to be a terminal with an editor in it, and another terminal with a UNIX shell in it. And sometimes the Python shell in the UNIX shell in the terminal when I'm testing something simple. For example: [~/hg/css(hg:default)]fleet*> python3 + exec /Users/cameron/var/venv/3/bin/python3 Python 3.6.5 (default, Mar 29 2018, 15:38:28) [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> That's a python 3 shell run from the UNIX shell in a terminal. The "[~/hg/css(hg:default)]fleet*>" is my UNIX shell prompt, with my working directory, VCS branch and hostname. So "~/hg/css" is where I'm working, separate from where the code gets installed. For testing I run the local code, which might be arbitrarily bad. I don't do the "install" step until it seems fairly good. Of course, the UNIX shell is there to run whatever I like. So to lint one of my Python files I might do this: [~/hg/css(hg:default)]fleet*> lint cs/sh.py + exec lint cs/sh.py + exec python3 -m py_compile cs/sh.py + exec /Users/cameron/var/venv/3/bin/python3 -m py_compile cs/sh.py + exec pyflakes cs/sh.py + exec pep8 --ignore=E111,E114,E124,E126,E201,E202,E221,E226,E227,E265,E266,E301,E302,E501,E731,W503 cs/sh.py + exec pylint --rcfile=/Users/cameron/.pylintrc --disable=bad-whitespace,invalid-name cs/sh.py Using config file /Users/cameron/.pylintrc * Module python.cs.sh W:105, 2: Using possibly undefined loop variable 'offset' (undefined-loop-variable) -- Your code has been rated at 9.85/10 (previous run: 9.85/10, +0.00) You can see my lint script doing: - test compile the script (no need to bother with the rest if that fails) - run pyflakes on it - run pep8 on it - run pylint on it Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: pattern
On 13Jun2018 19:51, Sharan Basappa wrote: Can anyone explain to me the purpose of "pattern" in the line below: documents.append((w, pattern['class'])) documents is declared as a list as follows: documents.append((w, pattern['class'])) Not without a lot more context. Where did you find this code? Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Design of my project
Hello, thanks for this nice answer I didn't see at first (I have parallely asked again in the list, sorry about the inconvenience). I will read deeply your proposal I will come bakc with my quesitons if any ;) Thanks! June 14 2018 12:37 AM, "Cameron Simpson" wrote: > On 13Jun2018 15:23, Fabien LUCE wrote: > >> Here is a small picture of my project. >> I'd like to fetch several datas from a website representing races results. >> Each line of the result contains rank, runner's name and other attributes >> of the runner (like club etc...). >> For now I have created 2 classes (Race and Runner). >> Methods of Race allow me to fetch datas on the www thanks to beautifulsoup >> module.I instanciate a race at the beginning of the scan and for each line >> I instanciate a Runner. >> I want to store all those information in a database (for both Race and >> Runner), but here is the point, I have the feeling, on a programming >> elegance point of view, that I have to separate methods that fetch from >> method that store and also have a kind of superior object that controls >> those 2 features. >> Moreover fetching will interact with storage: if race is already in >> database, no need to fetch again. >> How should I "design" this? Should I have only (despite my first >> impression) one class and all the methods in it? Should I create a parent >> class along with 2 childrens that manage the two kind of methods? >> Is there a design pattern for this? > > My inclination would be to start by providing a class which "wraps" your Race > database table, and > presents it as a mapping. > > Something along the lines of: > > class RaceTable: > def __init__(self, database_connection, table_name): > self.conn = database_connection > self.table_name = table_name > def __contains__(self, race_id): > ... do SQL to see if the race_id is already present, return True or False > def __getitem__(self, race_id): > ... do SQL to fetch a Race row from the table and return it ... > def __setitem__(self, race_id, race_info): > ... do SQL to store race_info in the table ... > > The special __foo__ methods (called "dunder" methods in the Puython world > because of the "double > underscore") are what make the class look like a Python "dict" from outside: > when you perform a > mapping method like "value in x" or "x[key] = value", Python calls > x.__contains__ or x.__setitem__ > for you. > > Look up "Emulating Container Types" here: > > https://docs.python.org/3/reference/datamodel.html#emulating-container-types > > That will show you how to write a class like the above example to implement a > "maping" interface. > You don't need to implement everything, just what you need. The example above > only implements 3 > methods. > > Then your outer code can look a bit like: > > race_store = RaceTable(database_connection, 'race_table_name_here') > ... > if race_id in race_store: > ... mention that this race_id is already stored ... > else: > race_store[race_id] = race_info > > So the objective here is a simple class that makes it easy to talk about > where your information is > stored in nice Pythonic terms, and which hides the details of database access > - that lets you talk > about the data in a sensbile and clear way outside the storage class, and > also leaves scrope for > changing the storage mechanism later without changing the main code (eg from > a conventional SQL > database to some other service). > > Cheers, > Cameron Simpson > -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Design of my program
Thanks for your answer. The term "picture" was more a metaphor ;) I am not sure I want to dive into ORM, since I am newbie, maybe I want to code something more from scratch to understand well program designing. What would be the best way: - create 2 classes, one that deals with web scraping, the other one with database, and then create child from those 2 parents? - create one unique class dealing with all those things - create one first class that deals with DB things and then a child class that deals additionnaly with web scraping. What would be the ideal way? Thanks June 13 2018 6:50 PM, "Dennis Lee Bieber" wrote: > On Wed, 13 Jun 2018 13:09:10 +, [email protected] declaimed the following: > >> Hello everyone, >> >> Here is a small picture of my project. > > This is a text-only group. Any binary attachments are removed before > messages propagate. > > As for the rest of your post... Possibly look at SQLAlchemy > https://www.sqlalchemy.org or (if it is still in development -- doesn't > seem to have moved since 2013) DABO https://dabodev.com ( > https://github.com/dabodev/dabo shows some action two years ago) > > -- > Wulfraed Dennis Lee Bieber AF6VN > [email protected] HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
On Thu, Jun 14, 2018 at 3:47 PM, T Berger wrote: > On Tuesday, April 10, 2018 at 1:21:53 AM UTC-4, Chris Angelico wrote: > >> I recommend, instead, joining the mailing list: >> >> https://mail.python.org/mailman/listinfo/python-list > > There seem to be two options on the Python-list Information Page. > > * Subscribe to the list (see sections below) > * Send email to [email protected] > > Which are you recommending? > They're connected. "Subscribe to the list" makes you a member of the mailing list (and thus you will start receiving posts), which also entitles you to send to the list. Sending email to that address will send it to the list. So what you're seeing is not options, but steps - first you subscribe, then you send email. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
How to delete a branch permanently in mercurial/bitbucket?
Hi, I need to delete a branch in mercurial in order to move it into a private repository. I have heard of the "hg strip" method but Bitbucket is warning me that this operation will affect branches I would prefer keeping... So I just have no idea right now how to prune this specific branch out of my public repo! :( Any suggestions for doing this would be much appreciated! Kind regards, Etienne -- Etienne Robillard [email protected] https://www.isotopesoftware.ca/ -- https://mail.python.org/mailman/listinfo/python-list
RE: mutable sequences
No, it says lists are mutable and tuples are immutable. Mutable has the same root as "mutation". Mutable means "can be changed in place". Immutable means "cannot be changed in place". Examples: 1) pass your list to a function, the function modifies the list. When the function returns your script gets control back. Your list is modified. 2) pass a tuple to a function. The function wants to modify the tuple. It can't Append( ) to it, if it tries Python will throw an exception because tuples don't have an append method. It can't assign a new value to an element of the tuple. But it can assign different content to the tuple entirely. When the function returns your script gets control back. YOUR tuple is NOT modified. When the function assigned to it, a new tuple with a different ID was created. Basically, from that point on, the function had its own tuple. The original was not modified because it can't be modified. It's immutable. 3) You use a list constructor, i.e., function( list(mylist) ). That passes a copy of your list, which has a different ID, to the function. The function can append to it, or otherwise modify it. When the function returns, YOUR list is not modified because you didn't pass your list to the function; you passed a newly constructed copy of your list to the function. (Advanced comment: If a tuple has an element which is a list, that list is mutable. Thinking about whether the list inside the tuple should be modifiable gives me a headache. Try it and see what happens.) If you don't like the terms mutable and immutable, think of them as related to "pass by reference" and "pass by value" in some other languages. If you pass by reference, you give the function a reference to your object; it modifies your object. If you pass by value, you load a copy of your object probably onto the stack, to pass to the function; the function can modify the copy but your object is not modified (this seems most similar to example 3 above). To avoid having to copy huge things onto the stack, C++ grew a const keyword so that you can pass a const reference to a function, which means the function won't be allowed to modify it. I think this is very much like immutable. I think it's fair to say Python always passes by reference. Immutable types allow Python to have behavior that acts sort of like pass by value, or very much like passing a const reference in C++. (One difference is Python allows a line that looks like it's assigning to the tuple, but really it makes a new tuple.) In example 3 above Python didn't actually pass a copy of your list (which could be huge), it passed a reference to a copy of your list. --- Joseph Schachner -Original Message- From: Sharan Basappa Sent: Wednesday, June 13, 2018 10:57 PM To: [email protected] Subject: mutable sequences The term mutable appears quite often in Python. Can anyone explain what is meant by mutable and immutable sequences. For example, Python lists are mutable. BTW, is the below explanation correct (it is taken from a book I am reading) Python lists are mutable sequences. They are very similar to tuples, but they don't have the restrictions due to immutability. It says lists are mutable and then says they are immutable??? -- https://mail.python.org/mailman/listinfo/python-list
Re: mutable sequences
On Wed, Jun 13, 2018 at 10:56 PM, Sharan Basappa wrote: > The term mutable appears quite often in Python. > Can anyone explain what is meant by mutable and immutable sequences. A string and a list go into a bar. The string asks for a cup of coffee. The bartender says "We don't have coffee." The string asks for a cup of coffee. The bartender says "I told you we don't have coffee." The string asks for a cup of coffee. The bartender says to the list "What is wrong with him? Is he deaf?" The list replies, "No, he's immutable." -- https://mail.python.org/mailman/listinfo/python-list
Re: Stefan's headers [was:Names and identifiers]
On 08/06/18 18:34, Marko Rauhamaa wrote: PS IMO copyright laws should be abolished altogether. At the very least one should pay for copyright protection. One €1 for the first year, €2 for the second, €4 for the third and so on exponentially. Thoughts on the proposed new EU copyright laws are welcome. Here's the first link https://juliareda.eu/eu-copyright-reform/ of the hits from the results of a google search for "eu new copyright proposal". I'll leave you all to read the remaining 26,199,999 hits at your leisure. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
On Thursday, June 14, 2018 at 8:02:44 AM UTC-4, Chris Angelico wrote: > They're connected. "Subscribe to the list" makes you a member of the > mailing list (and thus you will start receiving posts), which also > entitles you to send to the list. Sending email to that address will > send it to the list. So what you're seeing is not options, but steps - > first you subscribe, then you send email. OK. And can you tell me how to apply filters so that only replies to my emails are included. I subscribed to the list a couple of weeks ago and then had to unsubscribe because I was getting emails on every posted topic. Thanks, Tamara -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
On 14/06/18 16:00, T Berger wrote: On Thursday, June 14, 2018 at 8:02:44 AM UTC-4, Chris Angelico wrote: They're connected. "Subscribe to the list" makes you a member of the mailing list (and thus you will start receiving posts), which also entitles you to send to the list. Sending email to that address will send it to the list. So what you're seeing is not options, but steps - first you subscribe, then you send email. OK. And can you tell me how to apply filters so that only replies to my emails are included. I subscribed to the list a couple of weeks ago and then had to unsubscribe because I was getting emails on every posted topic. That's exactly how mailing lists work: you get everything. Any filtering has to be done at your end in your mail program. Personally I use Thunderbird, get it to sort messages into threads (sequences of conversation, in effect) and only read the threads that seem interesting. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
On Thursday, June 14, 2018 at 11:26:00 AM UTC-4, Rhodri James wrote: > On 14/06/18 16:00, T Berger wrote: > > On Thursday, June 14, 2018 at 8:02:44 AM UTC-4, Chris Angelico wrote: > > > >> They're connected. "Subscribe to the list" makes you a member of the > >> mailing list (and thus you will start receiving posts), which also > >> entitles you to send to the list. Sending email to that address will > >> send it to the list. So what you're seeing is not options, but steps - > >> first you subscribe, then you send email. > > > > OK. And can you tell me how to apply filters so that only replies to my > > emails are included. I subscribed to the list a couple of weeks ago and > > then had to unsubscribe because I was getting emails on every posted topic. > > That's exactly how mailing lists work: you get everything. Any > filtering has to be done at your end in your mail program. Personally I > use Thunderbird, get it to sort messages into threads (sequences of > conversation, in effect) and only read the threads that seem interesting. > > -- > Rhodri James *-* Kynesim Ltd Thanks, Rhodri. One more question. What is a daily digest? I'm wondering whether to choose that option. Tamara -- https://mail.python.org/mailman/listinfo/python-list
How can I verify if the regex exist in a file without reading ?
Hi,
Here is my script :
It propose to replace some words in a file with a regular expression.
It create a copy to write on it, and if there isn't an error, it delete the
original by the copy with "os.rename" at the end.
My problem is, if I work on a huge file, I'll try to avoid to read the file
because it will be crash my computer :) and I would to verify if the regex
enter by the user, exist.
I don't know if it's possible, I'm looking for a solution since few hours... so
sorry if the question is easy or wtf :)
import re
import os
try:
path = raw_input('Please enter the path of your file that you want to correct
: \n')
print("")
print('Which regex ? \n')
regex = raw_input('- : ')
print('By what ? \n')
new_word = raw_input('- : ')
# Creating copy file
filenames_regex = re.findall(r'[a-zA-Z0-9]+\.', path)
filename = filenames_regex[len(filenames_regex)-1]
new_filename = filename + 'copy.txt'
# Replace regex by new word line by line on copy file
with open(path) as rf, open(new_filename, 'w') as wf:
for line in rf:
wf.write(re.sub(regex, new_word, line))
except OSError:
print("Permission denied")
except IOError:
print("This file doesn't exist")
else:
os.rename(new_filename, filename + 'txt')
python 2.7.10
Thanks !
Best regards,
François.
--
https://mail.python.org/mailman/listinfo/python-list
Re: How can I verify if the regex exist in a file without reading ?
On Thu, 14 Jun 2018 09:26:44 -0700, francois.rabanel wrote:
> Hi,
>
> Here is my script :
>
> It propose to replace some words in a file with a regular expression. It
> create a copy to write on it, and if there isn't an error, it delete the
> original by the copy with "os.rename" at the end.
>
> My problem is, if I work on a huge file, I'll try to avoid to read the
> file because it will be crash my computer :)
How does reading a file crash your computer?
> and I would to verify if the regex enter by the user, exist.
The only way to know if a regex matches the file is to try to match the
regex and see if it matches.
[...]
> import re
> import os
>
> try:
>
> path = raw_input('Please enter the path of your file that you want to
> correct : \n')
> print("")
> print('Which regex ? \n')
> regex = raw_input('- : ')
> print('By what ? \n')
> new_word = raw_input('- : ')
>
Don't do this:
> # Creating copy file
> filenames_regex = re.findall(r'[a-zA-Z0-9]+\.', path)
> filename = filenames_regex[len(filenames_regex)-1]
> new_filename = filename + 'copy.txt'
Do this instead:
filename, extension = os.path.splitext(path)
new_filename = filename + '.copy' + extension
> # Replace regex by new word line by line on copy file
> with open(path) as rf, open(new_filename, 'w') as wf:
> for line in rf:
> wf.write(re.sub(regex, new_word, line))
>
> except OSError:
> print("Permission denied")
That's not what OSError means. OSError can mean many different things.
That's why it isn't called "PermissionDeniedError".
You need to look at the exception to see what caused it, not just assume
it was a permissions error.
> except IOError:
> print("This file doesn't exist")
That's not what IOError means either. That is why it isn't called
FileDoesntExistError. Again, you need to look at the exception to see
what the error actually is.
> else:
> os.rename(new_filename, filename + 'txt')
os.rename(new_filename, path)
--
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
--
https://mail.python.org/mailman/listinfo/python-list
Re: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!!
On 06/13/2018 11:38 PM, Chris Angelico wrote: On Thu, Jun 14, 2018 at 11:07 AM, Jim Lee wrote: I haven't purchased commercial software in decades, so I'm not up on the prevailing business model, but I have to ask: Why would anyone purchase software and then agree to wait 14 weeks for it to be delivered? I can see that model for hardware, where material resources are limited and a finite number of product is produced, but software? What's the point? For the 50% discount, I presume. If you wait 14 weeks, then buy, then own, you pay full price. From the company's point of view: if the release date is in the future and ALL the revenue is also in the future, cash flow becomes tricky. By getting at least _some_ money in advance, they give themselves a way to pay the bills. ChrisA But the "50% discount" is supposedly good up until the release date. I could purchase the software the day before release and still enjoy the same benefit without the 14 week wait. I understand the advantages *to the company*, but to enjoy those advantages, they need to provide some kind of incentive to the buyer. I don't see one here. Anyway, I was just curious to see if there was any kind of thought process behind the "promotion". -Jim -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
T Berger writes: > Thanks, Rhodri. One more question. What is a daily digest? I'm > wondering whether to choose that option. Don't choose the daily digest, because it makes a special “digest” message for you each day. That message is disconnected from any other message, and so you will not be able to reply correctly to any discussion. It's not appropriate for anyone who wants to also participate in discussions. -- \ “I have said to you to speak the truth is a painful thing. To | `\ be forced to tell lies is much worse.” —Oscar Wilde, _De | _o__) Profundis_, 1897 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: mutable sequences
Larry Martell writes: > A string and a list go into a bar. The string asks for a cup of > coffee. The bartender says "We don't have coffee." The string asks for > a cup of coffee. The bartender says "I told you we don't have coffee." > The string asks for a cup of coffee. The bartender says to the list > "What is wrong with him? Is he deaf?" The list replies, "No, he's > immutable." There need to be more bartender scenarios in programming tutorials. -- \ “The internet's completely over.… Anyway, all these computers | `\and digital gadgets are no good. They just fill your head with | _o__) numbers and that can't be good for you.” —Prince, 2010-07-05 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
On Thursday, June 14, 2018 at 3:39:44 PM UTC-4, Ben Finney wrote: > T Berger writes: > > > Thanks, Rhodri. One more question. What is a daily digest? I'm > > wondering whether to choose that option. > > Don't choose the daily digest, because it makes a special “digest” > message for you each day. That message is disconnected from any other > message, and so you will not be able to reply correctly to any > discussion. It's not appropriate for anyone who wants to also > participate in discussions. > > -- > \ “I have said to you to speak the truth is a painful thing. To | > `\ be forced to tell lies is much worse.” —Oscar Wilde, _De | > _o__) Profundis_, 1897 | > Ben Finney Thanks, Ben -- https://mail.python.org/mailman/listinfo/python-list
Flask not responding after installation
It seems I can’t progress a single step without encountering a wall. I’m trying to build a webapp with flask. I installed flask. I followed the workbook-provided prompts, which should have resulted in a flask confirmation. Nothing happened. Any ideas what’s gone wrong: Last login: Thu Jun 14 13:31:25 on ttys000 Tamaras-iMac:~ TamaraB$ cd Desktop/Web -bash: cd: Desktop/Web: No such file or directory Tamaras-iMac:~ TamaraB$ cd Desktop/Webapp Tamaras-iMac:Webapp TamaraB$ python3 hello_flask.py Tamaras-iMac:Webapp TamaraB$ Thanks, Tamara -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
On 14/06/18 17:23, T Berger wrote: On Thursday, June 14, 2018 at 11:26:00 AM UTC-4, Rhodri James wrote: On 14/06/18 16:00, T Berger wrote: On Thursday, June 14, 2018 at 8:02:44 AM UTC-4, Chris Angelico wrote: They're connected. "Subscribe to the list" makes you a member of the mailing list (and thus you will start receiving posts), which also entitles you to send to the list. Sending email to that address will send it to the list. So what you're seeing is not options, but steps - first you subscribe, then you send email. OK. And can you tell me how to apply filters so that only replies to my emails are included. I subscribed to the list a couple of weeks ago and then had to unsubscribe because I was getting emails on every posted topic. That's exactly how mailing lists work: you get everything. Any filtering has to be done at your end in your mail program. Personally I use Thunderbird, get it to sort messages into threads (sequences of conversation, in effect) and only read the threads that seem interesting. -- Rhodri James *-* Kynesim Ltd Thanks, Rhodri. One more question. What is a daily digest? I'm wondering whether to choose that option. Tamara Please no, not the misery of people replying to daily digests. As I've said previously and as reinforced by Rhodri James above, point Thunderbird or similar at news.gmane.org and read and reply to everything to your hearts content without bothering your own inbox. Simples :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Flask not responding after installation
How did you install flask? Can you paste the content of your flask app .py file? -Sivan On Fri, 15 Jun 2018 12:15 am Tamara Berger, wrote: > It seems I can’t progress a single step without encountering a wall. > I’m trying to build a webapp with flask. I installed flask. I followed > the workbook-provided prompts, which should have resulted in a flask > confirmation. Nothing happened. Any ideas what’s gone wrong: > > Last login: Thu Jun 14 13:31:25 on ttys000 > Tamaras-iMac:~ TamaraB$ cd Desktop/Web > -bash: cd: Desktop/Web: No such file or directory > Tamaras-iMac:~ TamaraB$ cd Desktop/Webapp > Tamaras-iMac:Webapp TamaraB$ python3 hello_flask.py > Tamaras-iMac:Webapp TamaraB$ > > Thanks, > > Tamara > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
On 14Jun2018 09:23, Tamara Berger wrote: Thanks, Rhodri. One more question. What is a daily digest? I'm wondering whether to choose that option. Please don't use the digest mode. They're a terrible way to read lists, and an even worse way to participate - your replies will never be correctly associate with any particular discussion thread and unless you're paying attention, won't even have a decent subject line (which, BTW, is _not_ how discussion threads are connected together). Instead, filter the list messages to their own GMail label and skip your inbox. That way the whole list is off to the side under its own section which you can visit whenever you want to instead of cluttering your inbox. Also, the discussion threads will be nicely collected together, with the most recent at the top where they're easy to see. If the threads you're interested in have a new reply, that thread should be up near the top. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: How can I verify if the regex exist in a file without reading ?
On 14Jun2018 16:54, Steven D'Aprano
wrote:
On Thu, 14 Jun 2018 09:26:44 -0700, francois.rabanel wrote:
My problem is, if I work on a huge file, I'll try to avoid to read the
file because it will be crash my computer :)
How does reading a file crash your computer?
Likely because he tried to read the whole file into memory and match against
it. Guessing:
text = open(the_filename).read()
... search the text for the regexp ...
Francois, unless your regex can cross multiple lines it is better to search
files like this:
with open(the_filename) as f:
for line in f:
... search the line for the regexp ...
That way you only need to keep one line at a time in memory.
except OSError:
print("Permission denied")
That's not what OSError means. OSError can mean many different things.
That's why it isn't called "PermissionDeniedError".
You need to look at the exception to see what caused it, not just assume
it was a permissions error.
except IOError:
print("This file doesn't exist")
That's not what IOError means either. That is why it isn't called
FileDoesntExistError. Again, you need to look at the exception to see
what the error actually is.
In particular, you should always _either_ inspect the exception to see what
went wrong and handle it, _or_ include the exception text in your error
message, for example:
except IOError as e:
print("IO Error on file:", e)
That way an unhandled exception gets reported.
else:
os.rename(new_filename, filename + 'txt')
os.rename(new_filename, path)
Importantly:
os.rename(path, new_filename)
The old name comes first, then the new name.
Also, you might want to ensure that new_filename doesn't already exist...
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
Dennis Lee Bieber writes: > On Fri, 15 Jun 2018 05:39:08 +1000, Ben Finney > declaimed the following: > > >Don't choose the daily digest, because it makes a special “digest” > >message for you each day. That message is disconnected from any other > >message, and so you will not be able to reply correctly to any > > Unless one has a client that can do digest bursting -- if the digest > provides all the proper headers for each message in it, the burst messages > should link properly. At which point, there seems little point in subscribing to the digest: just get all the actual messages delivered, and use the more powerful filtering built into the mail client. -- \ “[Entrenched media corporations will] maintain the status quo, | `\ or die trying. Either is better than actually WORKING for a | _o__) living.” —ringsnake.livejournal.com, 2007-11-12 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: How to apply filters to posts
On 14Jun2018 19:42, Dennis Lee Bieber wrote: On Fri, 15 Jun 2018 05:39:08 +1000, Ben Finney declaimed the following: Don't choose the daily digest, because it makes a special “digest” message for you each day. That message is disconnected from any other message, and so you will not be able to reply correctly to any Unless one has a client that can do digest bursting -- if the digest provides all the proper headers for each message in it, the burst messages should link properly. Though I don't use Forte Agent for email, so don't have actual experience with its bursting feature. Digests drop a lot of headers. Historically, they omit the Message-ID and In-Reply-To headers, and thus completely break threading for new replies. It is better all around to just get individual list messages and arrange to file them off into a folder distinct from your main inbox. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: How can I verify if the regex exist in a file without reading ?
On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote: > Francois, unless your regex can cross multiple lines it is better to > search files like this: > > with open(the_filename) as f: > for line in f: > ... search the line for the regexp ... > > That way you only need to keep one line at a time in memory. That's what François is doing. > Importantly: > > os.rename(path, new_filename) > > The old name comes first, then the new name. Oops! I forgot about that. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson -- https://mail.python.org/mailman/listinfo/python-list
Re: How can I verify if the regex exist in a file without reading ?
On 15Jun2018 00:24, Steven D'Aprano wrote: On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote: Francois, unless your regex can cross multiple lines it is better to search files like this: with open(the_filename) as f: for line in f: ... search the line for the regexp ... That way you only need to keep one line at a time in memory. That's what François is doing. Urr, so he is. Then like you, I don't know why he's concerned about running out of memory. Unless it hasn't been made clear the Python will free up unused memory on its own. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: mutable sequences
Thanks, All, for the responses. -- https://mail.python.org/mailman/listinfo/python-list
Re: pattern
> >Can anyone explain to me the purpose of "pattern" in the line below: > > > >documents.append((w, pattern['class'])) > > > >documents is declared as a list as follows: > >documents.append((w, pattern['class'])) > > Not without a lot more context. Where did you find this code? > > Cheers, I am sorry that partial info was not sufficient. I am actually trying to implement my first text classification code and I am referring to the below URL for that: https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6 I hope this helps. -- https://mail.python.org/mailman/listinfo/python-list
Re: pattern
On 14Jun2018 20:01, Sharan Basappa wrote:
>Can anyone explain to me the purpose of "pattern" in the line below:
>
>documents.append((w, pattern['class']))
>
>documents is declared as a list as follows:
>documents.append((w, pattern['class']))
Not without a lot more context. Where did you find this code?
I am sorry that partial info was not sufficient.
I am actually trying to implement my first text classification code and I am
referring to the below URL for that:
https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6
Ah, ok. It helps to include some cut/paste of the relevant code, though the URL
is a big help.
The wider context of the code you recite looks like this:
words = []
classes = []
documents = []
ignore_words = ['?']
# loop through each sentence in our training data
for pattern in training_data:
# tokenize each word in the sentence
w = nltk.word_tokenize(pattern['sentence'])
# add to our words list
words.extend(w)
# add to documents in our corpus
documents.append((w, pattern['class']))
and the training_data is defined like this:
training_data = []
training_data.append({"class":"greeting", "sentence":"how are you?"})
training_data.append({"class":"greeting", "sentence":"how is your day?"})
... lots more ...
So training data is a list of dicts, each dict holding a "class" and "sentence"
key. The "for pattern in training_data" loop iterates over each item of the
training_data. It calls nltk.word_tokenize on the 'sentence" part of the
training item, presumably getting a list of "word" strings. The documents list
gets this tuple:
(w, pattern['class'])
added to it.
In this way the documents list ends up with tuples of (words, classification),
with the words coming from the sentence via nltk and the classification coming
straight from the train item's "class" value.
So at the end of the loop the documents array will look like:
documents = [
( ['how', 'are', 'you'], 'greeting' ),
( ['how', 'is', 'your', 'day', 'greeting' ),
]
and so forth.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
