Re: creating a csv from information I have printed to screen

2020-05-22 Thread Peter Otten
Ciarán Hudson wrote:

> How do I edit the code below to create a csv file which includes the
> information I have printed at the bottom?
> 
> I'm pulling arrival data from an airport website and printing out only the
> flight info. I want to save that flight info to a CSV file.

First of all the data in the html is already structured as a table.
   
You really want to keep that structure instead of reconstructing it from the 
individual cells:

for row in table:
   write cells in row

Then you have to decide on the columns

> print('Arriving From', 'Airline', 'Scheduled to arrive','Latest
> Update','Status')

and I guess they are what you print above. Once you have the data creating 
the csv is easy, Python includes a module for it. So:


import csv, sys
[...]
writer = csv.writer(sys.stdout)
writer.writerow([
'Arriving From',
'Airline',
'Scheduled to arrive', 'Latest Update', 'Status'
])
[table] = soup.find_all("table")
for row in table.find_all("tr"):
writer.writerow(
[td.string.strip() for td in row.find_all("td")]
)

To write to a file instead of stdout pass the writer a file

with open("flight.csv", "w") as f:
writer = csv.writer(f)
...
 
> cells = soup.find_all('td')
> #print(cells)
> 
> for cell in cells:
> for content in cell.contents:
> value = str(content).strip().replace('\n', '')
> if len(value) == 0:
> print('"0"', end=',')
> elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<':
> print('\n' + value, end=',')
> else:
> print('"' + value + '"', end=',')



-- 
https://mail.python.org/mailman/listinfo/python-list


exiting a while loop

2020-05-22 Thread John Yeadon via Python-list

Am I unreasonable in expecting this code to exit when required?


# Add up the powers of 2 starting with 2**0 until 2 million is met.
n = 1
target = 200
sum = 0

while True:
x = 2 ** (n - 1)
sum += x
print(n, sum)
if sum >= target:
print("Target met.")
exit
n += 1

print("\n", n, "terms are required.")

--
https://mail.python.org/mailman/listinfo/python-list


Re: exiting a while loop

2020-05-22 Thread Souvik Dutta
No not really. If you use a breakpoint and a debugger you will find out
that your code continues till 2 M is met and then stops printing numbers
continuously.

On Fri, 22 May, 2020, 5:20 pm John Yeadon via Python-list, <
python-list@python.org> wrote:

> Am I unreasonable in expecting this code to exit when required?
>
>
> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
>
> while True:
>  x = 2 ** (n - 1)
>  sum += x
>  print(n, sum)
>  if sum >= target:
>  print("Target met.")
>  exit
>  n += 1
>
> print("\n", n, "terms are required.")
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exiting a while loop

2020-05-22 Thread Larry Martell
On Fri, May 22, 2020 at 7:51 AM John Yeadon via Python-list
 wrote:
>
> Am I unreasonable in expecting this code to exit when required?
>
>
> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
>
> while True:
>  x = 2 ** (n - 1)
>  sum += x
>  print(n, sum)
>  if sum >= target:
>  print("Target met.")
>  exit
>  n += 1
>
> print("\n", n, "terms are required.")

exit()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exiting a while loop

2020-05-22 Thread Peter Otten
John Yeadon via Python-list wrote:

> Am I unreasonable in expecting this code to exit when required?

It is unreasonable to expect something that doesn't match what you read in 
the tutorial ;)

If you want to terminate the script you can use exit. However exit is a 
function, and you have to call it

exit()

to actually do anything.

If you want to terminate just the loop, which is more likely because there 
is a print() following it, you can do this with break (which is a statement, 
so no trailing ()):


> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
> 
> while True:
>  x = 2 ** (n - 1)
>  sum += x
>  print(n, sum)
>  if sum >= target:
>  print("Target met.")

   break

>  n += 1
> 
> print("\n", n, "terms are required.")


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exiting a while loop

2020-05-22 Thread Dan Sommers

On Friday, May 22, 2020, at  7:49, John Yeadon via Python-list wrote:

> Am I unreasonable in expecting this code to exit when required?

Yes.  :-)

> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
>
> while True:
>  x = 2 ** (n - 1)
>  sum += x
>  print(n, sum)
>  if sum >= target:
>  print("Target met.")
>  exit

Try break instead of exit.  See
https://docs.python.org/3/reference/compound_stmts.html#the-for-statement
for more information.

>  n += 1
>
> print("\n", n, "terms are required.")

-- 
“Atoms are not things.” – Werner Heisenberg
Dan Sommers, http://www.tombstonezero.net/dan
-- 
https://mail.python.org/mailman/listinfo/python-list


creating a table within python code

2020-05-22 Thread Buddy Peacock
I'm working on my first python project in CS50W  and I am trying to create
2 tables.
I am getting the following error when trying to run it:  I have included my
code below the error message.

flask.cli.NoAppException: Failed to find Flask application or factory in
module "create_db". Use "FLASK_APP=create_db:name to specify one.
Traceback (most recent call last)
File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
line 39, in reraise
raise value
File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
line 97, in find_best_app
raise NoAppException(
flask.cli.NoAppException: Failed to find Flask application or factory in
module "create_db". Use "FLASK_APP=create_db:name to specify one.

I used:
FLASK_APP=create_db.py   at the command line

and this is my code:

import os
from flask import Flask, session
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
def main():
db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR NOT
NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT
NULL,)")
db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR
NOT NULL,)")
db.commit()
if __name__ == "__main__":
main()

Does anyone have any ideas?

Al (Buddy) Peacock, PMP, MCCT,  ITILv3, SMC, CSM, SPOC
(920) 740-3411
linkedin.com/in/buddypeacock 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exiting a while loop

2020-05-22 Thread D'Arcy Cain
On 2020-05-22 7:49 a.m., John Yeadon via Python-list wrote:
> Am I unreasonable in expecting this code to exit when required?

Yes.

> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
> 
> while True:
>     x = 2 ** (n - 1)
>     sum += x
>     print(n, sum)
>     if sum >= target:
>     print("Target met.")
>     exit
>     n += 1
> 
> print("\n", n, "terms are required.")

I think that you meant "break", not "exit".

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: creating a csv from information I have printed to screen

2020-05-22 Thread Peter Otten
Ciarán Hudson wrote:

> This has helped a lot; cleaner output, keeping tbl format and creating a
> csv but the csv is not being populated. Any idea what I am doing wrong?

> writer = csv.writer(sys.stdout)
> writer.writerow([
> 'Arriving From'
> 'Airline',
> 'Scheduled to arrive', 'Latest Update', 'Status'
> ])
> 
> #cells = soup.find_all('td')
> #print(cells)
> 
> [table] = soup.find_all("table")
> for row in table.find_all("tr"):
> writer.writerow(
> [td.string.strip() for td in row.find_all("td")]
> )
> 
> 
> # for cell in cells:
> 
> # for content in cell.contents:
> # value = str(content).strip().replace('\n', '')
> # if len(value) == 0:
> # print('"0"', end=',')
> # elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<':
> # print('\n' + value, end=',')
> # else:
> # print('"' + value + '"', end=',')
> 
> 
> 
> 
> with open('flight.csv','w') as f:
> writer = csv.writer(f)

Well you open the file and create a writer but you don't write anything. You 
need this part

  [table] = soup.find_all("table")
  for row in table.find_all("tr"):
  writer.writerow(
  [td.string.strip() for td in row.find_all("td")]
  )

inside the with-suite, too. 

If you are interested in learning Python, you may put it into a function and 
invoke it twice, with the writer writing to stdout and the writer writing to 
the file.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: creating a table within python code

2020-05-22 Thread Souvik Dutta
There will be quotes when doing FLASK_APP="" I think that
should solve the problem.

On Fri, 22 May, 2020, 5:35 pm Buddy Peacock, 
wrote:

> I'm working on my first python project in CS50W  and I am trying to create
> 2 tables.
> I am getting the following error when trying to run it:  I have included my
> code below the error message.
>
> flask.cli.NoAppException: Failed to find Flask application or factory in
> module "create_db". Use "FLASK_APP=create_db:name to specify one.
> Traceback (most recent call last)
> File
>
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
> line 39, in reraise
> raise value
> File
>
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
> line 97, in find_best_app
> raise NoAppException(
> flask.cli.NoAppException: Failed to find Flask application or factory in
> module "create_db". Use "FLASK_APP=create_db:name to specify one.
>
> I used:
> FLASK_APP=create_db.py   at the command line
>
> and this is my code:
>
> import os
> from flask import Flask, session
> from flask_session import Session
> from sqlalchemy import create_engine
> from sqlalchemy.orm import scoped_session, sessionmaker
> engine = create_engine(os.getenv("DATABASE_URL"))
> db = scoped_session(sessionmaker(bind=engine))
> def main():
> db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR NOT
> NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT
> NULL,)")
> db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR
> NOT NULL,)")
> db.commit()
> if __name__ == "__main__":
> main()
>
> Does anyone have any ideas?
>
> Al (Buddy) Peacock, PMP, MCCT,  ITILv3, SMC, CSM, SPOC
> (920) 740-3411
> linkedin.com/in/buddypeacock 
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyCharm, how to setup self contained subprojects

2020-05-22 Thread Python

Le 22/05/2020 à 03:41, zljubi...@gmail.com a écrit :

Hi,

I should provide python code for (Spring) microservice patform.
In microservice paradigm, each microservice should do a simple task, so python 
code beneath it should be very small.

As a PyCharm (community) user, I don't know how to set up such development 
environment.

Each microservice could be a separate PyCharm project, but these projects 
should share some common classes. For example, let's say that you have a class 
for communication with outer world.
Each PyCharm project (microservice) should use instance of this class, and do 
the different things with its data.

I would like to avoid coping this common object to each PyCharm project (and 
prevent refactoring).

Another, requirement is deployment of PyCharm project to the microservice 
platform.
At the moment, my each microservice code is in separate project.
I am coping each project files on separate folder on deployment server.
So, each PyCharm project has its own main.py (the name of main.py can be 
different for each microservice).

On deployment servers I cannot install anything.

Another approach would be to have single PyCharm project with many root 
directories for microservices and multiple main.py files.

In this case, when I deploy a single microservice, I will have trouble finding 
out what files I should copy (common classes), or to copy everything from 
PyCharm project, but specify main.py for specific microservice (root).

If anyone is in the same situation, please share how you have set up PyCharm 
for such purpose, and how you are doing development.

Regards


You shouldn't rely any software project on any IDE feature.

You're taking the problem from the wrong end. You'd better
have a look on the way cvs systems such as git can hangle
it.

As a matter of fact, imo, any software project based
on a given IDE is doomed ot failed.


--
https://mail.python.org/mailman/listinfo/python-list


Re: creating a table within python code

2020-05-22 Thread Buddy Peacock
Thank you Souvik, but still having issues.  I have pasted the command line
interaction this time.  My prior message is what appeared in the browser.

c:\Harvard\project1>SET FLASK_APP="create_db.py"

c:\Harvard\project1>set DATABASE_URL=postgres://
guaqyugfujbudc:79ae65a6d8966991694906e4b96f20ebcfde5b80fb334e99d79d9300dd6ef...@ec2-34-200-72-77.compute-1.amazonaws.com:5432/dep18tfh5g2eme

c:\Harvard\project1>flask run
 * Serving Flask app ""create_db.py"" (lazy loading)
 * Environment: development
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 124-607-194
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [22/May/2020 10:16:46] " [35m [1mGET / HTTP/1.1 [0m" 500 -
Traceback (most recent call last):
  File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
line 240, in locate_app
__import__(module_name)
ModuleNotFoundError: No module named '"create_db'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
line 338, in __call__
self._flush_bg_loading_exception()
  File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
line 326, in _flush_bg_loading_exception
reraise(*exc_info)
  File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
line 39, in reraise
raise value
  File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
line 314, in _load_app
self._load_unlocked()
  File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
line 330, in _load_unlocked
self._app = rv = self.loader()
  File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
line 388, in load_app
app = locate_app(self, import_name, name)
  File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
line 250, in locate_app
raise NoAppException('Could not import
"{name}".'.format(name=module_name))
flask.cli.NoAppException: Could not import ""create_db.py"".
127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
/?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1 [0m" 200 -
127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
/?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1 [0m" 200 -
127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
/?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1 [0m" 200 -
127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
/?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 -
127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
/?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1 [0m" 200 -
127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
/?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 -

Al (Buddy) Peacock, PMP, MCCT,  ITILv3, SMC, CSM, SPOC
(920) 740-3411
linkedin.com/in/buddypeacock 




On Fri, May 22, 2020 at 9:42 AM Souvik Dutta 
wrote:

> There will be quotes when doing FLASK_APP="" I think that
> should solve the problem.
>
> On Fri, 22 May, 2020, 5:35 pm Buddy Peacock, 
> wrote:
>
>> I'm working on my first python project in CS50W  and I am trying to create
>> 2 tables.
>> I am getting the following error when trying to run it:  I have included
>> my
>> code below the error message.
>>
>> flask.cli.NoAppException: Failed to find Flask application or factory in
>> module "create_db". Use "FLASK_APP=create_db:name to specify one.
>> Traceback (most recent call last)
>> File
>>
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
>> line 39, in reraise
>> raise value
>> File
>>
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>> line 97, in find_best_app
>> raise NoAppException(
>> flask.cli.NoAppException: Failed to find Flask application or factory in
>> module "create_db". Use "FLASK_APP=create_db:name to specify one.
>>
>> I used:
>> FLASK_APP=create_db.py   at the command line
>>
>> and this is my code:
>>
>> import os
>> from flask import Flask, session
>> from flask_session import Session
>> from sqlalchemy import create_engine
>> from sqlalchemy.orm import scoped_session, sessionmaker
>> engine = create_engine(os.getenv("DATABASE_URL"))
>> db = scoped_session(sessionmaker(bind=engine))
>> def main():
>> db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR
>> NOT
>> NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT
>> NULL,)")
>> db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR
>> NOT NULL,)")
>> db.commit()
>> if __name__ == "__main__":
>> main()
>>
>> Does anyone have any ideas?
>>
>> Al (Buddy) Peacock, PMP, M

Re: creating a table within python code

2020-05-22 Thread Souvik Dutta
And also you might have to add after the import statements app=
Flask(__name__)
and app.run() inside the main function

On Fri, 22 May, 2020, 8:31 pm Souvik Dutta,  wrote:

>  You might have to add @app.route("/") before the main method.
>
> On Fri, 22 May, 2020, 7:53 pm Buddy Peacock, 
> wrote:
>
>> Thank you Souvik, but still having issues.  I have pasted the command
>> line interaction this time.  My prior message is what appeared in the
>> browser.
>>
>> 
>> c:\Harvard\project1>SET FLASK_APP="create_db.py"
>>
>> c:\Harvard\project1>set DATABASE_URL=postgres://
>> guaqyugfujbudc:79ae65a6d8966991694906e4b96f20ebcfde5b80fb334e99d79d9300dd6ef...@ec2-34-200-72-77.compute-1.amazonaws.com:5432/dep18tfh5g2eme
>>
>> c:\Harvard\project1>flask run
>>  * Serving Flask app ""create_db.py"" (lazy loading)
>>  * Environment: development
>>  * Debug mode: on
>>  * Restarting with stat
>>  * Debugger is active!
>>  * Debugger PIN: 124-607-194
>>  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
>> 127.0.0.1 - - [22/May/2020 10:16:46] " [35m [1mGET / HTTP/1.1 [0m" 500 -
>> Traceback (most recent call last):
>>   File
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>> line 240, in locate_app
>> __import__(module_name)
>> ModuleNotFoundError: No module named '"create_db'
>>
>> During handling of the above exception, another exception occurred:
>>
>> Traceback (most recent call last):
>>   File
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>> line 338, in __call__
>> self._flush_bg_loading_exception()
>>   File
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>> line 326, in _flush_bg_loading_exception
>> reraise(*exc_info)
>>   File
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
>> line 39, in reraise
>> raise value
>>   File
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>> line 314, in _load_app
>> self._load_unlocked()
>>   File
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>> line 330, in _load_unlocked
>> self._app = rv = self.loader()
>>   File
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>> line 388, in load_app
>> app = locate_app(self, import_name, name)
>>   File
>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>> line 250, in locate_app
>> raise NoAppException('Could not import
>> "{name}".'.format(name=module_name))
>> flask.cli.NoAppException: Could not import ""create_db.py"".
>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>> /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1 [0m" 200 -
>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>> /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1 [0m" 200 -
>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>> /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1 [0m" 200 -
>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 -
>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>> /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1 [0m" 200 -
>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 -
>>
>> Al (Buddy) Peacock, PMP, MCCT,  ITILv3, SMC, CSM, SPOC
>> (920) 740-3411
>> linkedin.com/in/buddypeacock 
>>
>>
>>
>>
>> On Fri, May 22, 2020 at 9:42 AM Souvik Dutta 
>> wrote:
>>
>>> There will be quotes when doing FLASK_APP="" I think that
>>> should solve the problem.
>>>
>>> On Fri, 22 May, 2020, 5:35 pm Buddy Peacock, 
>>> wrote:
>>>
 I'm working on my first python project in CS50W  and I am trying to
 create
 2 tables.
 I am getting the following error when trying to run it:  I have
 included my
 code below the error message.

 flask.cli.NoAppException: Failed to find Flask application or factory in
 module "create_db". Use "FLASK_APP=create_db:name to specify one.
 Traceback (most recent call last)
 File

 "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
 line 39, in reraise
 raise value
 File

 "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
 line 97, in find_best_app
 raise NoAppException(
 flask.cli.NoAppException: Failed to find Flask application or factory in
 module "create_db". Use "FLASK_APP=create_db:name to specify one.

 I used:
 FLASK_APP=create_db.py   at the command line

 and this is my code:

 import os
 from flask import Flask, session
 from flask_session import Sess

Re: creating a csv from information I have printed to screen

2020-05-22 Thread Ciarán Hudson
This has helped a lot; cleaner output, keeping tbl format and creating a csv 
but the csv is not being populated. 
Any idea what I am doing wrong?


import requests
import csv, sys

from bs4 import BeautifulSoup

cookies = {
'ApplicationGatewayAffinity': 
'1d2ad8ab214d1293a4e31bcd161589fa82a54a39bb7b3be80b503996092d4296',
'ApplicationGatewayAffinityCORS': 
'1d2ad8ab214d1293a4e31bcd161589fa82a54a39bb7b3be80b503996092d4296',
}

headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
'Accept': 
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Sec-Fetch-Site': 'cross-site',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-User': '?1',
'Sec-Fetch-Dest': 'document',
'Referer': 'https://www.google.com/',
'Accept-Language': 'en-GB,en;q=0.9,en-US;q=0.8,fr;q=0.7,nl;q=0.6',
}

response = requests.get('https://www.corkairport.com/arrivals-departures', 
headers=headers, cookies=cookies)

#print(response.content)
soup = BeautifulSoup(response.content, 'html.parser')
#print(soup.prettify())


## commented out as it did not print as expected
# headers = soup.find_all('th')
# for header in headers:
# for content in header.contents:
# value = str(header).strip().replace('\n', '')
# if len(value) == 0:
# print('"0"', end=',')
# elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<':
# print('\n' + value, end=',')
# else:
# print('"' + value + '"', end=',')


  



#print('Arriving From', 'Airline', 'Scheduled to arrive','Latest 
Update','Status')


writer = csv.writer(sys.stdout)
writer.writerow([
'Arriving From'
'Airline',
'Scheduled to arrive', 'Latest Update', 'Status'
])

#cells = soup.find_all('td')
#print(cells)

[table] = soup.find_all("table")
for row in table.find_all("tr"):
writer.writerow(
[td.string.strip() for td in row.find_all("td")]
)


# for cell in cells:

# for content in cell.contents:
# value = str(content).strip().replace('\n', '')
# if len(value) == 0:
# print('"0"', end=',')
# elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<':
# print('\n' + value, end=',')
# else:
# print('"' + value + '"', end=',')




with open('flight.csv','w') as f:
writer = csv.writer(f)

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: creating a table within python code

2020-05-22 Thread Souvik Dutta
 You might have to add @app.route("/") before the main method.

On Fri, 22 May, 2020, 7:53 pm Buddy Peacock, 
wrote:

> Thank you Souvik, but still having issues.  I have pasted the command line
> interaction this time.  My prior message is what appeared in the browser.
>
> 
> c:\Harvard\project1>SET FLASK_APP="create_db.py"
>
> c:\Harvard\project1>set DATABASE_URL=postgres://
> guaqyugfujbudc:79ae65a6d8966991694906e4b96f20ebcfde5b80fb334e99d79d9300dd6ef...@ec2-34-200-72-77.compute-1.amazonaws.com:5432/dep18tfh5g2eme
>
> c:\Harvard\project1>flask run
>  * Serving Flask app ""create_db.py"" (lazy loading)
>  * Environment: development
>  * Debug mode: on
>  * Restarting with stat
>  * Debugger is active!
>  * Debugger PIN: 124-607-194
>  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
> 127.0.0.1 - - [22/May/2020 10:16:46] " [35m [1mGET / HTTP/1.1 [0m" 500 -
> Traceback (most recent call last):
>   File
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
> line 240, in locate_app
> __import__(module_name)
> ModuleNotFoundError: No module named '"create_db'
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
> line 338, in __call__
> self._flush_bg_loading_exception()
>   File
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
> line 326, in _flush_bg_loading_exception
> reraise(*exc_info)
>   File
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
> line 39, in reraise
> raise value
>   File
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
> line 314, in _load_app
> self._load_unlocked()
>   File
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
> line 330, in _load_unlocked
> self._app = rv = self.loader()
>   File
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
> line 388, in load_app
> app = locate_app(self, import_name, name)
>   File
> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
> line 250, in locate_app
> raise NoAppException('Could not import
> "{name}".'.format(name=module_name))
> flask.cli.NoAppException: Could not import ""create_db.py"".
> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
> /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1 [0m" 200 -
> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
> /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1 [0m" 200 -
> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
> /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1 [0m" 200 -
> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 -
> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
> /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1 [0m" 200 -
> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 -
>
> Al (Buddy) Peacock, PMP, MCCT,  ITILv3, SMC, CSM, SPOC
> (920) 740-3411
> linkedin.com/in/buddypeacock 
>
>
>
>
> On Fri, May 22, 2020 at 9:42 AM Souvik Dutta 
> wrote:
>
>> There will be quotes when doing FLASK_APP="" I think that
>> should solve the problem.
>>
>> On Fri, 22 May, 2020, 5:35 pm Buddy Peacock, 
>> wrote:
>>
>>> I'm working on my first python project in CS50W  and I am trying to
>>> create
>>> 2 tables.
>>> I am getting the following error when trying to run it:  I have included
>>> my
>>> code below the error message.
>>>
>>> flask.cli.NoAppException: Failed to find Flask application or factory in
>>> module "create_db". Use "FLASK_APP=create_db:name to specify one.
>>> Traceback (most recent call last)
>>> File
>>>
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
>>> line 39, in reraise
>>> raise value
>>> File
>>>
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>>> line 97, in find_best_app
>>> raise NoAppException(
>>> flask.cli.NoAppException: Failed to find Flask application or factory in
>>> module "create_db". Use "FLASK_APP=create_db:name to specify one.
>>>
>>> I used:
>>> FLASK_APP=create_db.py   at the command line
>>>
>>> and this is my code:
>>>
>>> import os
>>> from flask import Flask, session
>>> from flask_session import Session
>>> from sqlalchemy import create_engine
>>> from sqlalchemy.orm import scoped_session, sessionmaker
>>> engine = create_engine(os.getenv("DATABASE_URL"))
>>> db = scoped_session(sessionmaker(bind=engine))
>>> def main():
>>> db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR

Re: Strings: double versus single quotes

2020-05-22 Thread Manfred Lotz
On Tue, 19 May 2020 13:36:54 -0500
Tim Chase  wrote:

> On 2020-05-19 20:10, Manfred Lotz wrote:
> > Hi there,
> > I am asking myself if I should preferably use single or double
> > quotes for strings?  
> 
> I'd say your consistency matters more than which one you choose.
> 

First, thanks to all for your opinions and judgements.

I agree to the following:

1. Consistency is important.
2. Single quotes are less noisy.
3. Triple double quotes are to be preferred over triple single quotes.

I also believe that transferring habits from C, Rust or whatever to
Python doesn't make much sense as Python does not distinguish between a
character and string from a type perspective.

Of course, this is my subjective result, and others (may) have
different opinions. 


-- 
Manfred

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: creating a table within python code

2020-05-22 Thread Buddy Peacock
Still no go.  I even tried using the entire path of the py ap in the SET
FLASK_APP command

This is my code now after trying your suggestions.
===
import os

from flask import Flask, session
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

app= Flask(__name__)

engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))

@app.route("/")

def main():
app.run()

db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR NOT
NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT
NULL,)")
db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR
NOT NULL,)")

db.commit()

if __name__ == "__main__":
main()
=
Al (Buddy) Peacock, PMP, MCCT,  ITILv3, SMC, CSM, SPOC
(920) 740-3411
linkedin.com/in/buddypeacock 




On Fri, May 22, 2020 at 11:04 AM Souvik Dutta 
wrote:

> And also you might have to add after the import statements app=
> Flask(__name__)
> and app.run() inside the main function
>
> On Fri, 22 May, 2020, 8:31 pm Souvik Dutta, 
> wrote:
>
>>  You might have to add @app.route("/") before the main method.
>>
>> On Fri, 22 May, 2020, 7:53 pm Buddy Peacock, 
>> wrote:
>>
>>> Thank you Souvik, but still having issues.  I have pasted the command
>>> line interaction this time.  My prior message is what appeared in the
>>> browser.
>>>
>>> 
>>> c:\Harvard\project1>SET FLASK_APP="create_db.py"
>>>
>>> c:\Harvard\project1>set DATABASE_URL=postgres://
>>> guaqyugfujbudc:79ae65a6d8966991694906e4b96f20ebcfde5b80fb334e99d79d9300dd6ef...@ec2-34-200-72-77.compute-1.amazonaws.com:5432/dep18tfh5g2eme
>>>
>>> c:\Harvard\project1>flask run
>>>  * Serving Flask app ""create_db.py"" (lazy loading)
>>>  * Environment: development
>>>  * Debug mode: on
>>>  * Restarting with stat
>>>  * Debugger is active!
>>>  * Debugger PIN: 124-607-194
>>>  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
>>> 127.0.0.1 - - [22/May/2020 10:16:46] " [35m [1mGET / HTTP/1.1 [0m" 500 -
>>> Traceback (most recent call last):
>>>   File
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>>> line 240, in locate_app
>>> __import__(module_name)
>>> ModuleNotFoundError: No module named '"create_db'
>>>
>>> During handling of the above exception, another exception occurred:
>>>
>>> Traceback (most recent call last):
>>>   File
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>>> line 338, in __call__
>>> self._flush_bg_loading_exception()
>>>   File
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>>> line 326, in _flush_bg_loading_exception
>>> reraise(*exc_info)
>>>   File
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
>>> line 39, in reraise
>>> raise value
>>>   File
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>>> line 314, in _load_app
>>> self._load_unlocked()
>>>   File
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>>> line 330, in _load_unlocked
>>> self._app = rv = self.loader()
>>>   File
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>>> line 388, in load_app
>>> app = locate_app(self, import_name, name)
>>>   File
>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
>>> line 250, in locate_app
>>> raise NoAppException('Could not import
>>> "{name}".'.format(name=module_name))
>>> flask.cli.NoAppException: Could not import ""create_db.py"".
>>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>>> /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1 [0m" 200 -
>>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>>> /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1 [0m" 200 -
>>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>>> /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1 [0m" 200 -
>>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>>> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 -
>>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>>> /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1 [0m" 200 -
>>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET
>>> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 -
>>>
>>> Al (Buddy) Peacock, PMP, MCCT,  ITILv3, SMC, CSM, SPOC
>>> (920) 740-3411
>>> linkedin.com/in/buddypeacock 
>>>
>>>
>>>
>>>
>>> On Fri, May 22, 2020 at 9:42 AM Souvik Dutta 
>>> wrote

Re: exiting a while loop

2020-05-22 Thread Grant Edwards
On 2020-05-22, Peter Otten <__pete...@web.de> wrote:

> If you want to terminate the script you can use exit. However exit
> is a function, and you have to call it
>
> exit()



Actually it's an instance of _sitebuiltins.Quitter not a function.

You still have to call it. ;)



--
Grant

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Online training June 11, 12: Docker packaging best practices for Python in production

2020-05-22 Thread DL Neil via Python-list

On 23/05/20 3:40 AM, Itamar Turner-Trauring wrote:

You’re about to ship your Python application into production using Docker: your 
images are going to be critical infrastructure.

...


*The class will take place on two mornings (US East Coast) on June 11th and 12th. You 
can **learn more about the class on the event page* 
*
 (*https://bit.ly/36kBhhN).



Requested/suggested improvements to this 'advert':

1 internationalisation/localisation
Please include the exact times because for many of us, "morning" begins 
a lot sooner than is typical elsewhere, and "EST" is a local-definition.

(preferably use/add international standards for expressing times/dates)

2 community/commercial
Please mention any costs. This list is populated by volunteers.
- if you are volunteering your time, I have almost-insulted you by 
asking (apologies)
- if you are charging for attendance, I shouldn't have to 'click here' 
to ascertain such a basic fact/significant-factor for many.



The topic is a good one; both pertinent and current for Pythonista. 
Wishing it goes well...

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: exiting a while loop

2020-05-22 Thread DL Neil via Python-list

On 23/05/20 4:31 AM, Grant Edwards wrote:

On 2020-05-22, Peter Otten <__pete...@web.de> wrote:


If you want to terminate the script you can use exit. However exit
is a function, and you have to call it

exit()




Actually it's an instance of _sitebuiltins.Quitter not a function.

You still have to call it. ;)





Which definition (may) make it 'worse' (when compared with "break"):
doesn't exit() also close the application-window under some OpSys (if 
not all) - which would 'disappear' the output before it could be read?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Strings: double versus single quotes

2020-05-22 Thread DL Neil via Python-list

I am asking myself if I should preferably use single or double
quotes for strings?

...


I agree to the following:

1. Consistency is important.
2. Single quotes are less noisy.
3. Triple double quotes are to be preferred over triple single quotes.

...


Of course, this is my subjective result, and others (may) have
different opinions.


4. unless a specific objective of a re-factoring exercise, maintain the 
conventions used within the code.


5, adhere to the conventions/standards/requirements of the dev.team or 
organisation.


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Strings: double versus single quotes

2020-05-22 Thread Manfred Lotz
On Sat, 23 May 2020 09:36:13 +1200
DL Neil  wrote:

> >>> I am asking myself if I should preferably use single or double
> >>> quotes for strings?  
> ...
> 
> > I agree to the following:
> > 
> > 1. Consistency is important.
> > 2. Single quotes are less noisy.
> > 3. Triple double quotes are to be preferred over triple single
> > quotes.  
> ...
> 
> > Of course, this is my subjective result, and others (may) have
> > different opinions.  
> 
> 4. unless a specific objective of a re-factoring exercise, maintain
> the conventions used within the code.
> 
> 5, adhere to the conventions/standards/requirements of the dev.team
> or organisation.
> 

Yes, agree.


-- 
Manfred

-- 
https://mail.python.org/mailman/listinfo/python-list


Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers?

2020-05-22 Thread Adam Preble
I wanted to update from 3.6.8 on Windows without necessarily moving on to 3.7+ 
(yet), so I thought I'd try 3.6.9 or 3.6.10. 

All I see for both are source archives:

https://www.python.org/downloads/release/python-369/
https://www.python.org/downloads/release/python-3610/

So, uh, I theoretically did build a 3.6.10 .exe installer, but I don't really 
trust I did everything right. Is there an officially sourced installation?
-- 
https://mail.python.org/mailman/listinfo/python-list