Python Postgresql complete guide

2018-08-23 Thread vishalhule24


https://pynative.com/python-postgresql-tutorial/

I have added table of content at the start of the article

This tutorial mainly focuses on installing Psycopg2 and use its API to access 
the PostgreSQL database. It then takes you through data insertion, data 
retrieval, data update and data deletion, transaction management, connection 
pooling and error-handling techniques to develop robust python programs with 
PostgreSQL.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Partitioning a list

2018-08-23 Thread Poul Riis
I find it surprisingly difficult to find information on this issue on the 
internet. Until now I've only found this preview of an article:
https://www.jstor.org/stable/3615434?seq=1#page_scan_tab_contents

Still, I can hardly believe that nobody has made some efforts to make a python 
algorithm to solve this classical problem so I'm still hoping
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Partitioning a list

2018-08-23 Thread Sibylle Koczian

Am 21.08.2018 um 23:36 schrieb Poul Riis:

I would like to list all possible ways to put N students in groups of k 
students (suppose that k divides N) with the restriction that no two students 
should ever meet each other in more than one group.
I think this is a classical problem and I think there must be a python solution 
out there but I cannot find it. For instance, numpy's array_split only lists 
one (trivial) split.
I would be happy if someone could refer me to a general python algorithm 
solving the problem.

This is indeed a classic (or rather the generalization of a classic): 
Kirkman's Schoolgirl Problem (for N = 15), first published 1850.
I didn't find a Python solution, but the Wikipedia entry and a MathWorld 
page, both with more links:


https://en.wikipedia.org/wiki/Kirkman%27s_schoolgirl_problem

http://mathworld.wolfram.com/KirkmansSchoolgirlProblem.html

HTH
Sibylle



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


RE: Python Postgresql complete guide

2018-08-23 Thread David Raymond
Looks good.

Having used psycopg2 a fair amount, here are some suggestions I have on extra 
things to cover or emphasize.


-Postgres specific things like remembering to "set search_path to blargh, 
public;" etc as needed before querying.

-An example case of cur.fetchone() returning None, or more importantly, showing 
the error you get when you forget about that case

-Using conn.set_session(isolation_level, readonly, deferrable, autocommit) to 
set up transaction behavior at the start. (Can restrict to setting only the 
ones you care about by using keyword args)

-Going over some of the various caveats of autocommit on vs off
--autocommit on mode still allows transactions and rollbacks when you 
explicitly start a transaction with a cur.execute("begin;")
--To end an explicit autocomit transaction you need to use 
cur.execute("commit;") or cur.execute("rollback;"), you can't use conn.commit() 
or conn.rollback()
--With autocommit off you'll have to make sure you've run rollback or commit to 
use some commands which "cannot be run inside a transaction block" such as 
vacuum
--Autocommit off starts a transaction for any query, and will leave the 
transaction open until you commit it or roll it back. Thus if you run a simple 
select, then walk away for 5 hours with your connection still connected, you'll 
have left a transaction open on the server the whole time.

-Server side cursors: Running a select query that will result in 4 GB of data? 
With a "normal" cursor, even when iterating over the cursor or using fetchmany 
it will try to download the entire result set first before iterating over the 
results. (Actually, the .execute() statement will fetch everything even before 
you get a chance to run any of the .fetchone/many/all methods) Using a server 
side cursor will let you get it in chunks rather than trying to load it all 
into memory first.
--Server side cursors require autocommit off

-Enabling unicode for Python2.x so you get already decoded unicode objects back 
for text, not byte strings.
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)



-Original Message-
From: Python-list 
[mailto:[email protected]] On Behalf Of 
[email protected]
Sent: Thursday, August 23, 2018 8:59 AM
To: [email protected]
Subject: Python Postgresql complete guide


https://pynative.com/python-postgresql-tutorial/

I have added table of content at the start of the article

This tutorial mainly focuses on installing Psycopg2 and use its API to access 
the PostgreSQL database. It then takes you through data insertion, data 
retrieval, data update and data deletion, transaction management, connection 
pooling and error-handling techniques to develop robust python programs with 
PostgreSQL.
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


EuroPython 2018: Videos for Wednesday available

2018-08-23 Thread M.-A. Lemburg
We are pleased to announce the first batch of cut videos from
EuroPython 2018 in Edinburgh, Scotland, UK.


 * EuroPython 2018 YouTube Playlist *

https://www.youtube.com/watch?v=LoRq9yGeBWY&list=PL8uoeex94UhFrNUV2m5MigREebUms39U5


In this batch, we have included all videos for Wednesday, July 25
2018, the first conference day.

In the coming two weeks we will publish videos for the next two
conference days. In total, we will have more than 130 videos available
for you to watch.

All EuroPython videos, including the ones from previous conferences,
are available on our EuroPython YouTube Channel.


Help spread the word


Please help us spread this message by sharing it on your social
networks as widely as possible. Thank you !

Link to the blog post:

https://blog.europython.eu/post/177312513617/europython-2018-videos-for-wednesday-available

Tweet:

https://twitter.com/europython/status/1032680953758527488

Enjoy,
--
EuroPython 2018 Team
https://ep2018.europython.eu/
https://www.europython-society.org/

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


Re: printing to stdout

2018-08-23 Thread richard lucassen
On Mon, 20 Aug 2018 08:19:12 +1000
Cameron Simpson  wrote:

[sorry for late reply]

> Someone else has descibed zip tersely: it pairs it the elements of 2
> lists. In fact it joins up matching elements of an arbitrary number
> of iterables. Here is a 3 iterable example:
> 
> >>> zip( (1,2,3), (4,5,6), (7,8,9) )
> 
> >>> list( zip( (1,2,3), (4,5,6), (7,8,9) ) )
> [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
> 
> See that is has collected the first element of each tuple, then the
> second and so forth?

Yep, an image or an example says more than 1000 pages of explanation
 
> In my sentence above, "iterable" means any object you can iterate
> over - any object you could use in a for-loop. So, obviously, a list
> as in your programme. And also a tuple like (1,2,3) as in the example
> above (a tuple is an unmodifiable list). ANd any number of other
> things that will yield a sequence of values.
> 
> In Python 3 (which you're using) zip returns a lazy object, which
> does the zipping as you request the values. That is why the example
> shows a base "zip()" returning a "zip object" - we hand it to list()
> to get an actual list of all the values. This is fast (instant return
> of the zip object without doing much work) and cheap in memory (no
> need to make a huge result if you're zipping big lists) and
> cheap in time (no need to make the whole result if you're only using
> the first part of it).
> 
> So, to the code using the zip:
> 
>   for device_nr, (pcf, pcf_value) in enumerate(zip(list_pcf,
> list_pcf_value)):
> 
> The inner zip yields (pcf, pcf_value) pairs from zipping list_pcf and 
> list_pcf_value, an iterable of:
> 
>   (pcf[0], pcf-value[0]), (pcf[1], pcf_value[1]), ...
> 
> and you can write a for loop like this:
> 
>   for pcf, pcf_value in zip(list_pcf, list_pcf_value):
> 
> to deal with each of those pairs in turn.
> 
> However, since you also need the index (device_nr) in order to update 
> list_pcf_value:
> 
>   list_pcf_value[device_nr] = output
> 
> we then hand the whole thing to enumerate:
> 
>   for device_nr, (pcf, pcf_value) in enumerate(zip(list_pcf,
> list_pcf_value)):
> 
> The enumerate does just what the previous one did, yields pairs of
> (index, value). Each value is a pair from the zip, so it yields:
> 
>   (0, (pcf[0], pcf-value[0])),
>   (1, (pcf[1], pcf_value[1])),
>   ...
> 
> and Python's tuple unpacking syntax is fairly generous, so you want
> write:
> 
>   device_nr, (pcf, pcf_value) = (0, (pcf[0], pcf-value[0]))
> 
> and you can stick that in the for loop, getting the syntax you're
> using in the programme:
> 
>   for device_nr, (pcf, pcf_value) in enumerate(zip(list_pcf,
> list_pcf_value)):

Well, that's a nice and clear explanation, at the prompt I played a bit
with the enumerate and zip functions and after all it's quite simple :)

> >The code is now as follows:
> 
> Much nicer. A few tiny nit picks:

[..] changes applied

> >while True:
> >  if GPIO.input(23) == 1: # if still 0, another event has occurred
> >GPIO.wait_for_edge(23, GPIO.FALLING)
> 
> Can the GPIO ops also raise IOErrors? Just wondering.

Probably, sounds logigal, the GPIO pin is read and if something is
wrong it will generate an I/O error. 

R.

-- 
richard lucassen
http://contact.xaq.nl/
-- 
https://mail.python.org/mailman/listinfo/python-list


Unexpected behaviour with DeprecationWarning, Python 3.7 and escape codes

2018-08-23 Thread Peter via Python-list
I understand that Python 3.7 now issues DeprecationWarning for code 
entered in the interactive shell and also for single-module programs. I 
see this behaviour with:


C:\wrk> python
python 3.7.0 (v3.7.0:...

import imp

__main__:1: DeprecationWarning: the imp module is deprecated...

But if I use an unknown escape code, then the expected warning doesn't 
issue:



print('Hello \world')

Hello \world

But if I explicitly turn on default warnings, then I do get it:

C:\wrk> python -Wd

print('Hello \world')

:1: DeprecationWarning: invalid escape sequence \w
Hello \world


Shouldn't I see the "invalid escape sequence" deprecation warning under 
3.7 without having to turn on default warnings? They are both warnings 
of class DeprecationWarning. Am I not seeing something? Is this a bug?


I suspect it might have something to do with /when/ the warning is 
evaluated (parsing time vs runtime), but I'm not sure, and I'm not sure 
if that should be relevant to whether the warning is in fact raised. (I 
am aware of PEP 565)


Running CPython 3.7.0 on Windows 10, standard

Thanks for your insights.

Peter


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


Re: Partitioning a list

2018-08-23 Thread Oscar Benjamin
On Thu, 23 Aug 2018 at 15:32, Sibylle Koczian  wrote:
>
> Am 21.08.2018 um 23:36 schrieb Poul Riis:
> > I would like to list all possible ways to put N students in groups of k 
> > students (suppose that k divides N) with the restriction that no two 
> > students should ever meet each other in more than one group.
> > I think this is a classical problem and I think there must be a python 
> > solution out there but I cannot find it. For instance, numpy's array_split 
> > only lists one (trivial) split.
> > I would be happy if someone could refer me to a general python algorithm 
> > solving the problem.
> >
> This is indeed a classic (or rather the generalization of a classic):
> Kirkman's Schoolgirl Problem (for N = 15), first published 1850.

I think the general concept is called a Steiner system:
https://en.wikipedia.org/wiki/Steiner_system

In the notation of that article you would like to describe S(2, k, N).
The article says:

It can be shown that if there is a Steiner system S(2, k, N),
where k is a prime power greater than 1, then N = 1 or k (mod k(k−1))

which may be relevant for what you are doing. For the case k=3 you can
find more information by searching for Steiner Triple Systems.

I don't know how to construct Steiner systems but without thinking
very hard about it I imagine that you can build larger Steiner systems
from smaller ones in some way. Once you have a Steiner system you can
then consider all the permutations of mapping your students onto the
elements of the system - there will be N! of those but possibly with a
k! duplication so maybe there's an efficient way to only enumerate the
N!/k! possibilities. Hopefully N isn't too large...

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


Re: Bottle framework references

2018-08-23 Thread tommy yama
More specifically, which online docs? 

> On 22 Aug 2018, at 8:38 am, Jason Friedman  wrote:
> 
>> 
>> I am building up the microsite based on Bottle framework now.
>> Any references/books? I am unfamiliar with this framework yet.
>> 
>> I have used it with success.  The online documentation was sufficient for
> my needs, at least.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Unexpected behaviour with DeprecationWarning, Python 3.7 and escape codes

2018-08-23 Thread D'Arcy Cain
On 2018-08-23 06:08 AM, Peter via Python-list wrote:
> I understand that Python 3.7 now issues DeprecationWarning for code
> entered in the interactive shell and also for single-module programs. I
> see this behaviour with:
> 
> C:\wrk> python
> python 3.7.0 (v3.7.0:...
 import imp
> __main__:1: DeprecationWarning: the imp module is deprecated...

Valid warning.

> But if I use an unknown escape code, then the expected warning doesn't
> issue:
> 
 print('Hello \world')
> Hello \world
> 
> But if I explicitly turn on default warnings, then I do get it:
> 
> C:\wrk> python -Wd
 print('Hello \world')
> :1: DeprecationWarning: invalid escape sequence \w
> Hello \world

I don't know why it issues DeprecationWarning but this is not the same
as the previous line.  In this case \w is invalid and, as far as I know,
 has always been invalid.  I think it should be a different warning but
I do understand why it is in a different code path in Python.

It doesn't issue any warning in 2.7 by the way.  It still prints the
same thing so it is still an invalid escape sequence.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:[email protected] VoIP: sip:[email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Fetch data from two dates query in python and mongoengine

2018-08-23 Thread mahesh d
Hii
My model like this
class ProcessedEmails(Document):
  subject = StringField(max_length=200)
fromaddress =StringField(max_length=200)
 dateofprocessing = StringField(max_length=25)
How can find out the records between two dates ??
Note: date of processing is string field
 Mongodb database using .
How to write the query in python by using mongoengine

Thanks
Mahesh D.
-- 
https://mail.python.org/mailman/listinfo/python-list