Re: Sqlite pragma statement "locking_mode" set to "EXCLUSIVE" by default

2015-09-22 Thread Sol T
Hi,

I know I can do this per connection, however how can I have it set to
default? Does this need to be compiled into python?

On Tue, Sep 22, 2015 at 2:04 PM, Ryan Stuart 
wrote:

> On Thu, Sep 17, 2015 at 2:24 PM, sol433tt  wrote:
>
>> I would like to have the Sqlite pragma statement "locking_mode" set to
>> "EXCLUSIVE" by default (RO database). Does this need to be compiled in? How
>> might this be achieved?
>>
>
> You can issue any PRAGA statement you like using the execute method on a
> connection as per the documentation (
> https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.execute).
> For information on the specific PRAGMA option you need, see
> https://www.sqlite.org/pragma.html#pragma_locking_mode. I can't see any
> mention of it being a compile time PRAGMA.
>
> Cheers
>
>
>>
>> There is some performance to be gained. I have a number of python
>> scripts, and don't want to alter the pragma statement for every script.
>> This computer never writes to the databases.
>>
>> thank you
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>>
>
>
> --
> Ryan Stuart, B.Eng
> Software Engineer
>
> W: http://www.kapiche.com/
> M: +61-431-299-036
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Postscript to pdf

2015-09-22 Thread Baladjy KICHENASSAMY
Hello,
This is my programe : on mac i was able to output ps file but i didn't
got the pdf file :/

# -*- coding: utf-8 -*-
# script lecture_gif.py
from Tkinter import *
import tkMessageBox
import Tkconstants
import tkFileDialog
from PIL import ImageTk
import PIL.Image
import os, sys
import subprocess


def Ouvrir():
Canevas.delete(ALL) # on efface la zone graphique

filename = tkFileDialog.askopenfilename(title="Ouvrir une
image",filetypes=[('gif files','.gif'),('all files','.*')])
print(filename)
photo = PhotoImage(file=filename)
gifdict[filename] = photo  # référence
print(gifdict)

Canevas.create_image(0,0,anchor=NW,image=photo)
Canevas.config(height=photo.height(),width=photo.width())

Mafenetre.title("Image "+str(photo.width())+" x "+str(photo.height()))

def insertimage():
n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg",
"*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')])
img = PIL.Image.open(n)
img = img.resize((229, 253))
photoimg = ImageTk.PhotoImage(img)
label = Label(image=photoimg)
label.image = photoimg # keep a reference!
Canevas.create_image(65,320,anchor=W,image = photoimg)
def insertsign():
n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg",
"*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')])
img = PIL.Image.open(n)
img = img.resize((300, 100))
photoimg = ImageTk.PhotoImage(img)
Canevas.create_image(600,500,anchor=W,image = photoimg)
Canvas.pack()

def Fermer():
Canevas.delete(ALL)
Mafenetre.title("Image")

def save():
Canevas.update()
Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color')
subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"])

# def convert():
# ps2pdf -dEPSCrop image.ps
# convert -density 300 PASSPORTQUALITE.ps output.png

# class TkFileDialogExample(Tkinter.Frame):
#
# def __init__(self, root):
#
# Tkinter.Frame.__init__(self, root)
# button_opt = {'fill': Tkconstants.BOTH, 'padx': 5, 'pady': 5}
# Tkinter.Button(self, text='Save',
command=self.asksaveasfilename).pack(**button_opt)
#
# self.file_opt = options = {}
# options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
# options['initialfile'] = 'myfile.txt'
# options['parent'] = root
#
# def asksaveasfilename(self):
# filename = tkFileDialog.asksaveasfilename(**self.file_opt)
#
# if filename:
# return open(filename, 'w')
#
# if __name__=='__main__':
# root = Tkinter.Tk()
# TkFileDialogExample(root).pack()
# root.mainloop()
def Apropos():
tkMessageBox.showinfo("A propos","Tutorial")

def Write():
def delete():
e1.delete(0,END)
e2.delete(0,END)
e3.delete(0,END)
e4.delete(0,END)
e5.delete(0,END)
e6.delete(0,END)
Canevas.delete("e1")
def valider():
Canevas.create_text(315,200,anchor=W,text="Surname/Nom",fill='Black',font='Arial
14')
Canevas.create_text(315,220,anchor=W,text=e1.get(),fill='Black',font='Arial
30',tags ="e1")
Canevas.create_text(315,250,anchor=W,text="Given
name/Prénom",fill='Black',font='Arial 14')
Canevas.create_text(315,270,anchor=W,text=e2.get(),fill='Black',font='Arial
30',tags ="e1")
Canevas.create_text(315,300,anchor=W,text="Fonction/Function",fill='Black',font='Arial
14')
Canevas.create_text(315,320,anchor=W,text=e3.get(),fill='Black',font='Arial
30',tags ="e1")
Canevas.create_text(470,395,anchor=W,text=e4.get(),fill='Black',font='Arial
30',tags ="e1")
Canevas.create_text(500,438,anchor=W,text=e5.get(),fill='Black',font='Arial
30',tags ="e1")
Canevas.create_text(228,503,anchor=W,text=e6.get(),fill='Black',font='Arial
30',tags ="e1")
master = Tk()
Label(master, text="Surname/Nom").grid(row=0)
Label(master, text="Given name/Prénom").grid(row=1)
Label(master, text="Fonction/Function").grid(row=2)
Label(master, text="Validity Date").grid(row=3)
Label(master, text="Chef").grid(row=4)
Label(master, text="Student number").grid(row=5)
e1 = Entry(master)
e2 = Entry(master)
e3 = Entry(master)
e4 = Entry(master)
e5 = Entry(master)
e6 = Entry(master)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e3.grid(row=2, column=1)
e4.grid(row=3, column=1)
e5.grid(row=4, column=1)
e6.grid(row=5, column=1)
Button(master, text='Ok', command=valider).grid(row=2, column=2,
sticky=W, pady=4)
Button(master, text='Delete', command=delete).grid(row=3, column=2,
sticky=W, pady=4)
mainloop( )

# Main window
Mafenetre = Tk()
Mafenetre.title("Image")

# Création d'un widget Menu
menubar = Menu(Mafenetre)

menufichier = Menu(menubar,tearoff=0)
menufichier.add_command(label="Open mask",command=Ouvrir)
menufichier.add_command(label="Save mask",command=save)
#menufichier.add_command(label="Convert pdf",command=convert)
menufichier.add_command(label="Close mask",command=Fermer)
menufichier.add_command(label="Quit",command=Mafenetre.destroy)
menubar.add_cascade(label="File", menu=menufichier)

menuwrite = Menu(menubar,tearoff=0)
menuwrite.add_command(label="Insert informations",command=Write)
menu

Re: [ANN] floatrange - a range() for floats

2015-09-22 Thread Loïc Grobol
Heureux de voir que Python résiste encore et toujours au LIMSI!

Merci pour ce travail.

On 21 September 2015 at 13:15, Laurent Pointal  wrote:
> Hello,
>
> I'm please to publish a small utility module allowing to produce float based
> range sequences, with I hope a complete range-like interface. Because of
> floating point arithmetic, floatrange allows to specify a precision for
> "equality" when working with operators like 'in'.
>
> It is Python2 and Python3 compatible.
>
> PyPI: https://pypi.python.org/pypi/floatrange/
> Doc: http://floatrange.readthedocs.org/
> Project: https://perso.limsi.fr/pointal/python:floatrange
>
> Float arithmetic: https://docs.python.org/3/tutorial/floatingpoint.html
>
> A+
> Laurent Pointal.
>
> --
> https://mail.python.org/mailman/listinfo/python-announce-list
>
> Support the Python Software Foundation:
> http://www.python.org/psf/donations/



-- 
Loïc Grobol.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can't Install Python 3.5.0

2015-09-22 Thread Ian Kelly
On Mon, Sep 21, 2015 at 7:58 AM, Dave Green 
wrote:
>
> Hi
> I have just spent the last few hours trying to install Python 3.5 64 bit
and 32 bit as I am
> trying to install pygame so I can learn Python. However the only versions
that seems to work
> are Python-2.7.10 with pygame-1.91.win32-py2.7.
>
> I have tried loads of variations but nothing apart from these 2 work.
> They all throw up the error below.
>
> I am running Windows 10 latest release, but the problem appears to be
with the handling of the  import function.  Unfortunately I need Python 3.5
install to follow my course book.
>
> Any suggestion would be most welcome. Thank you. Dave

Looks like Python 3.5 is working, but there's something wrong with your
pygame installation. How did you try to install it? On the bitbucket page I
see there are prebuilt Windows binaries for Python 3.4, but none for Python
3.5 yet, so it looks like you would need to build it yourself.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lightwight socket IO wrapper

2015-09-22 Thread Jorgen Grahn
On Mon, 2015-09-21, Cameron Simpson wrote:
> On 21Sep2015 10:34, Chris Angelico  wrote:
>>If you're going to add sequencing and acknowledgements to UDP,
>>wouldn't it be easier to use TCP and simply prefix every message with
>>a two-byte length?
>
> Frankly, often yes. That's what I do. (different length encoding, but 
> otherwise...)
>
> UDP's neat if you do not care if a packet fails to arrive and if you can 
> guarentee that your data fits in a packet in the face of different MTUs. 

There's also the impact on your application. With TCP you need to
consider that you may block when reading or writing, and you'll be
using threads and/or a state machine driven by select() or something.
UDP is more fire-and-forget.

> I like TCP myself, most of the time. Another nice thing about TCP is that wil 
> a 
> little effort you get to pack multiple data packets (or partial data packets) 
> into a network packet, etc.

That, and also (again) the impact on the application.  With UDP you
can easily end up wasting a lot of time reading tiny datagrams one by
one.  It has often been a performance bottleneck for me, with certain
UDP-based protocols which cannot pack multiple application-level
messages into one datagram.

Although perhaps you tend not to use Python in those situations.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lightwight socket IO wrapper

2015-09-22 Thread Jorgen Grahn
On Mon, 2015-09-21, Chris Angelico wrote:
> On Mon, Sep 21, 2015 at 6:38 PM, Marko Rauhamaa  wrote:
>> Chris Angelico :
>>
>>> On Mon, Sep 21, 2015 at 5:59 PM, Marko Rauhamaa  wrote:
 You can read a full buffer even if you have a variable-length length
 encoding.
>>>
>>> Not sure what you mean there. Unless you can absolutely guarantee that
>>> you didn't read too much, or can absolutely guarantee that your
>>> buffering function will be the ONLY way anything reads from the
>>> socket, buffering is a problem.
>>
>> Only one reader can read a socket safely at any given time so mutual
>> exclusion is needed.
>>
>> If you read "too much," the excess can be put in the application's read
>> buffer where it is available for whoever wants to process the next
>> message.
>
> Oops, premature send - sorry! Trying again.
>
> Which works only if you have a single concept of "application's read
> buffer". That means that you have only one place that can ever read
> data. Imagine a protocol that mainly consists of lines of text
> terminated by CRLF, but allows binary data to be transmitted by
> sending "DATA N\r\n" followed by N arbitrary bytes. The simplest and
> most obvious way to handle the base protocol is to buffer your reads
> as much as possible, but that means potentially reading the beginning
> of the data stream along with its header. You therefore cannot use the
> basic read() method to read that data - you have to use something from
> your line-based wrapper, even though you are decidedly NOT using a
> line-based protocol at that point.
>
> That's what I mean by guaranteeing that your buffering function is the
> only way data gets read from the socket. Either that, or you need an
> underlying facility for un-reading a bunch of data - de-buffering and
> making it readable again.

The way it seems to me, reading a TCP socket always ends up as:

- keep an application buffer
- do one socket read and append to the buffer
- consume 0--more complete "entries" from the beginning
  of the buffer; keep the incomplete one which may exist
  at the end
- go back and read some more when there's a chance more data
  has arrived

So the buffer is a circular buffer of octets, which you chop up
by parsing it so you can see it as a circular buffer of complete and
incomplete entries or messages.

At that level, yes, the line-oriented data and the binary data would
coexist in the same application buffer.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can't Install Python 3.5.0

2015-09-22 Thread Mark Lawrence

On 22/09/2015 08:31, Ian Kelly wrote:

On Mon, Sep 21, 2015 at 7:58 AM, Dave Green mailto:[email protected]>> wrote:
 >
 > Hi
 > I have just spent the last few hours trying to install Python 3.5 64
bit and 32 bit as I am
 > trying to install pygame so I can learn Python. However the only
versions that seems to work
 > are Python-2.7.10 with pygame-1.91.win32-py2.7.
 >
 > I have tried loads of variations but nothing apart from these 2 work.
 > They all throw up the error below.
 >
 > I am running Windows 10 latest release, but the problem appears to be
with the handling of the  import function.  Unfortunately I need Python
3.5 install to follow my course book.
 >
 > Any suggestion would be most welcome. Thank you. Dave

Looks like Python 3.5 is working, but there's something wrong with your
pygame installation. How did you try to install it? On the bitbucket
page I see there are prebuilt Windows binaries for Python 3.4, but none
for Python 3.5 yet, so it looks like you would need to build it yourself.



http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame has Python 3.5 
versions for 32 and 64 bit.


--
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: A photo/image/video sharing app in Python

2015-09-22 Thread Cai Gengyang
On Tuesday, September 22, 2015 at 2:34:20 PM UTC+8, Chris Angelico wrote:
> On Tue, Sep 22, 2015 at 3:53 PM, Cai Gengyang  wrote:
> > A piece of software that would let end users easily create gorgeous 
> > real-life, real-time cartoons on the web might not exist yet. But if it 
> > were possible to invent this and get it commercialised , it could indeed 
> > become a great product that users love and pay good money to use ... You 
> > might even become a billionaire just through inventing and commercialising 
> > such a tool / system  ...
> >
> 
> Yes, you might become a billionaire. Does that suggest something to
> you? If a project could make _that much money_, wouldn't someone have
> done it already? The scope of this project is enormous, and if you're
> to tackle it, you'll need to have a lot more than a basic notion of
> "hey wouldn't this be nice".
> 
> ChrisA


Right  Thats going to take a herculean effort and teamwork. (maybe next 
year)

For now, I am just trying to download Django and Flask and learn how to use it.

I am currently on this page --- https://www.djangoproject.com/download/ and 
clicked on the 
" Latest release: Django-1.8.4.tar.gz " link on the right side of the page  

For the impatient:

Latest release: Django-1.8.4.tar.gz --- This one!
Checksums: Django-1.8.4.checksum.txt
Release notes: Online documentation

and managed to download a folder called django-docs-1. When I opened it ... 
there are a whole bunch of files and folders like "_downloads" , _images , 
_modules , _sources amongst others.

What do I need to do next to install Django ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem building python 3.5 extensions for windows

2015-09-22 Thread Robin Becker

On 22/09/2015 01:36, [email protected] wrote:

On Monday, September 21, 2015 at 9:54:51 AM UTC-7, Robin Becker wrote:



build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.lib
and ob
ject
build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.exp


   | Generating code
Stderr:  | error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio
14.0\\VC\\BIN\\amd64\\link.exe' failed with
exit status 1

so there are some warnings which I don't understand. Maybe I need to do
something special for pyRXP (possibly I have some ifdefs poorly configured).
--
Robin Becker


How long did you let it "hang"? For me the incremental linker took in the order of 30 
minutes to link. I mentioned this on the Python issue tracker at 
.


Thanks for the pointer Christoph.

I certainly didn't let it run for 30 minutes. When I build with 2.7, 3.3 or 3.4 
the whole build including reportlab stuff is over in a couple of minutes. I will 
try again, but a linker that takes 30 minutes to create an extension that ends 
up 204Kb long has to be seriously broken. Is it trying to hard? Most of the code 
size is in arrays for code points etc etc.

--
Robin Becker

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


Re: A photo/image/video sharing app in Python

2015-09-22 Thread Cai Gengyang
On Tuesday, September 22, 2015 at 5:48:26 PM UTC+8, Cai Gengyang wrote:
> On Tuesday, September 22, 2015 at 2:34:20 PM UTC+8, Chris Angelico wrote:
> > On Tue, Sep 22, 2015 at 3:53 PM, Cai Gengyang  wrote:
> > > A piece of software that would let end users easily create gorgeous 
> > > real-life, real-time cartoons on the web might not exist yet. But if it 
> > > were possible to invent this and get it commercialised , it could indeed 
> > > become a great product that users love and pay good money to use ... You 
> > > might even become a billionaire just through inventing and 
> > > commercialising such a tool / system  ...
> > >
> > 
> > Yes, you might become a billionaire. Does that suggest something to
> > you? If a project could make _that much money_, wouldn't someone have
> > done it already? The scope of this project is enormous, and if you're
> > to tackle it, you'll need to have a lot more than a basic notion of
> > "hey wouldn't this be nice".
> > 
> > ChrisA
> 
> 
> Right  Thats going to take a herculean effort and teamwork. (maybe next 
> year)
> 
> For now, I am just trying to download Django and Flask and learn how to use 
> it.
> 
> I am currently on this page --- https://www.djangoproject.com/download/ and 
> clicked on the 
> " Latest release: Django-1.8.4.tar.gz " link on the right side of the page  
> 
> For the impatient:
> 
> Latest release: Django-1.8.4.tar.gz --- This one!
> Checksums: Django-1.8.4.checksum.txt
> Release notes: Online documentation
> 
> and managed to download a folder called django-docs-1. When I opened it ... 
> there are a whole bunch of files and folders like "_downloads" , _images , 
> _modules , _sources amongst others.
> 
> What do I need to do next to install Django ?


Ok, so I typed these commands into "Terminal" in an attempt to install pip and 
use it to install Django. Can anybody let me know if I have performed this 
correctly ? Thanks a lot ...


CaiGengYangs-MacBook-Pro:~ CaiGengYang$ pip

Usage:   
  pip  [options]

Commands:
  install Install packages.
  uninstall   Uninstall packages.
  freeze  Output installed packages in requirements format.
  listList installed packages.
  showShow information about installed packages.
  search  Search PyPI for packages.
  wheel   Build wheels from your requirements.
  zip DEPRECATED. Zip individual packages.
  unzip   DEPRECATED. Unzip individual packages.
  helpShow help for commands.

General Options:
  -h, --help  Show help.
  --isolated  Run pip in an isolated mode, ignoring
  environment variables and user configuration.
  -v, --verbose   Give more output. Option is additive, and can be
  used up to 3 times.
  -V, --version   Show version and exit.
  -q, --quiet Give less output.
  --log Path to a verbose appending log.
  --proxy  Specify a proxy in the form
  [user:passwd@]proxy.server:port.
  --retries  Maximum number of retries each connection should
  attempt (default 5 times).
  --timeout  Set the socket timeout (default 15 seconds).
  --exists-action Default action when a path already exists:
  (s)witch, (i)gnore, (w)ipe, (b)ackup.
  --trusted-hostMark this host as trusted, even though it does
  not have valid or any HTTPS.
  --certPath to alternate CA bundle.
  --client-cert Path to SSL client certificate, a single file
  containing the private key and the certificate
  in PEM format.
  --cache-dirStore the cache data in .
  --no-cache-dir  Disable the cache.
  --disable-pip-version-check
  Don't periodically check PyPI to determine
  whether a new version of pip is available for
  download. Implied with --no-index.
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ pip install django
You are using pip version 6.1.1, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting django
  Downloading Django-1.8.4-py2.py3-none-any.whl (6.2MB)
100% || 6.2MB 79kB/s 
Installing collected packages: django
Successfully installed django-1.8.4
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ 
-- 
https://mail.python.org/mailman/listinfo/python-list


Installing pip and django

2015-09-22 Thread Cai Gengyang
So these are my results when I type these commands into "Terminal" in an 
attempt to install pip and django --- From the output, it seems that I have 
successfully installed pip and django 

CaiGengYangs-MacBook-Pro:~ CaiGengYang$ pip

Usage:   
  pip  [options]

Commands:
  install Install packages.
  uninstall   Uninstall packages.
  freeze  Output installed packages in requirements format.
  listList installed packages.
  showShow information about installed packages.
  search  Search PyPI for packages.
  wheel   Build wheels from your requirements.
  zip DEPRECATED. Zip individual packages.
  unzip   DEPRECATED. Unzip individual packages.
  helpShow help for commands.

General Options:
  -h, --help  Show help.
  --isolated  Run pip in an isolated mode, ignoring
  environment variables and user configuration.
  -v, --verbose   Give more output. Option is additive, and can be
  used up to 3 times.
  -V, --version   Show version and exit.
  -q, --quiet Give less output.
  --log Path to a verbose appending log.
  --proxy  Specify a proxy in the form
  [user:passwd@]proxy.server:port.
  --retries  Maximum number of retries each connection should
  attempt (default 5 times).
  --timeout  Set the socket timeout (default 15 seconds).
  --exists-action Default action when a path already exists:
  (s)witch, (i)gnore, (w)ipe, (b)ackup.
  --trusted-hostMark this host as trusted, even though it does
  not have valid or any HTTPS.
  --certPath to alternate CA bundle.
  --client-cert Path to SSL client certificate, a single file
  containing the private key and the certificate
  in PEM format.
  --cache-dirStore the cache data in .
  --no-cache-dir  Disable the cache.
  --disable-pip-version-check
  Don't periodically check PyPI to determine
  whether a new version of pip is available for
  download. Implied with --no-index.
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ pip install django
You are using pip version 6.1.1, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting django
  Downloading Django-1.8.4-py2.py3-none-any.whl (6.2MB)
100% || 6.2MB 79kB/s 
Installing collected packages: django
Successfully installed django-1.8.4
CaiGengYangs-MacBook-Pro:~ CaiGengYang$ python
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
1.8.4
>>> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Successfully send sms with python

2015-09-22 Thread Timon Rhynix
Hello, I have used pyserial, sms0.4 and other libraries to send sms via huawei 
E1750 modem.
The code runs well and no error is thrown but the text message is not 
sent/delivered to the number.
One of my code is as follows:

import serial
import time

class TextMessage:
def __init__(self, recipient="0123456789", message="TextMessage.content not 
set."):
self.recipient = recipient
self.content = message

def setRecipient(self, number):
self.recipient = number

def setContent(self, message):
self.content = message

def connectPhone(self):
conn = 'COM13'
self.ser = serial.Serial(conn, 460800, timeout=5)
time.sleep(1)

def sendMessage(self):
self.ser.write('ATZ\r')
time.sleep(1)
self.ser.write('AT+CMGF=1\r')
time.sleep(1)
self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''')
time.sleep(1)
self.ser.write(self.content + "\r")
time.sleep(1)
self.ser.write(chr(26))
time.sleep(1)
print "message sent!"

def disconnectPhone(self):
self.ser.close()

When run it, the "message sent!" is printed but no message is sent/delivered.
Please assist on what I am missing. Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sqlite pragma statement "locking_mode" set to "EXCLUSIVE" by default

2015-09-22 Thread Ryan Stuart
On Tue, Sep 22, 2015 at 5:12 PM, Sol T  wrote:

> I know I can do this per connection, however how can I have it set to
> default? Does this need to be compiled into python?
>

If you need to compile sqlite you might want to look at apsw:
https://github.com/rogerbinns/apsw

Cheers


>
> On Tue, Sep 22, 2015 at 2:04 PM, Ryan Stuart 
> wrote:
>
>> On Thu, Sep 17, 2015 at 2:24 PM, sol433tt  wrote:
>>
>>> I would like to have the Sqlite pragma statement "locking_mode" set to
>>> "EXCLUSIVE" by default (RO database). Does this need to be compiled in? How
>>> might this be achieved?
>>>
>>
>> You can issue any PRAGA statement you like using the execute method on a
>> connection as per the documentation (
>> https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.execute).
>> For information on the specific PRAGMA option you need, see
>> https://www.sqlite.org/pragma.html#pragma_locking_mode. I can't see any
>> mention of it being a compile time PRAGMA.
>>
>> Cheers
>>
>>
>>>
>>> There is some performance to be gained. I have a number of python
>>> scripts, and don't want to alter the pragma statement for every script.
>>> This computer never writes to the databases.
>>>
>>> thank you
>>>
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>>
>>>
>>
>>
>> --
>> Ryan Stuart, B.Eng
>> Software Engineer
>>
>> W: http://www.kapiche.com/
>> M: +61-431-299-036
>>
>
>


-- 
Ryan Stuart, B.Eng
Software Engineer

W: http://www.kapiche.com/
M: +61-431-299-036
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Successfully send sms with python

2015-09-22 Thread Pavel S
On Tuesday, September 22, 2015 at 1:20:07 PM UTC+2, Timon Rhynix wrote:
> Hello, I have used pyserial, sms0.4 and other libraries to send sms via 
> huawei E1750 modem.
> The code runs well and no error is thrown but the text message is not 
> sent/delivered to the number.
> One of my code is as follows:
> 
> import serial
> import time
> 
> class TextMessage:
> def __init__(self, recipient="0123456789", message="TextMessage.content 
> not set."):
> self.recipient = recipient
> self.content = message
> 
> def setRecipient(self, number):
> self.recipient = number
> 
> def setContent(self, message):
> self.content = message
> 
> def connectPhone(self):
> conn = 'COM13'
> self.ser = serial.Serial(conn, 460800, timeout=5)
> time.sleep(1)
> 
> def sendMessage(self):
> self.ser.write('ATZ\r')
> time.sleep(1)
> self.ser.write('AT+CMGF=1\r')
> time.sleep(1)
> self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''')
> time.sleep(1)
> self.ser.write(self.content + "\r")
> time.sleep(1)
> self.ser.write(chr(26))
> time.sleep(1)
> print "message sent!"
> 
> def disconnectPhone(self):
> self.ser.close()
> 
> When run it, the "message sent!" is printed but no message is sent/delivered.
> Please assist on what I am missing. Thank you

Hi,

why don't you use http://wammu.eu/python-gammu/
?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem building python 3.5 extensions for windows

2015-09-22 Thread Robin Becker

On 22/09/2015 11:14, Robin Becker wrote:

On 22/09/2015 01:36, [email protected] wrote:

.t

.


Thanks for the pointer Christoph.

I certainly didn't let it run for 30 minutes. When I build with 2.7, 3.3 or 3.4
the whole build including reportlab stuff is over in a couple of minutes. I will
try again, but a linker that takes 30 minutes to create an extension that ends
up 204Kb long has to be seriously broken. Is it trying to hard? Most of the code
size is in arrays for code points etc etc.


I timed my builds of pyRXPU for x86 + amd64; these are on a core i5-3470 @ 
3.20Ghz with 4Gb memory.


python 3.4   1 minute  14 seconds
python 3.5  52 minutes 50 seconds

so with VS2015 it will now take me an hour to make and test any changes to this 
extension. I don't see how the issue can be considered closed. VS2015 is clearly 
not the way forward for any reasonable development process.

--
Robin Becker

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


Re: Successfully send sms with python

2015-09-22 Thread mm0fmf via Python-list

On 22/09/2015 12:19, Timon Rhynix wrote:

Hello, I have used pyserial, sms0.4 and other libraries to send sms via huawei 
E1750 modem.
The code runs well and no error is thrown but the text message is not 
sent/delivered to the number.
One of my code is as follows:

import serial
import time

class TextMessage:
 def __init__(self, recipient="0123456789", message="TextMessage.content not 
set."):
 self.recipient = recipient
 self.content = message

 def setRecipient(self, number):
 self.recipient = number

 def setContent(self, message):
 self.content = message

 def connectPhone(self):
 conn = 'COM13'
 self.ser = serial.Serial(conn, 460800, timeout=5)
 time.sleep(1)

 def sendMessage(self):
 self.ser.write('ATZ\r')
 time.sleep(1)
 self.ser.write('AT+CMGF=1\r')
 time.sleep(1)
 self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''')
 time.sleep(1)
 self.ser.write(self.content + "\r")
 time.sleep(1)
 self.ser.write(chr(26))
 time.sleep(1)
 print "message sent!"

 def disconnectPhone(self):
 self.ser.close()

When run it, the "message sent!" is printed but no message is sent/delivered.
Please assist on what I am missing. Thank you



If it's like the GSM modem I used then you should replace those "\r" 
strings with "\r\n".



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


A little test for you Guys😜

2015-09-22 Thread Python_Teacher via Python-list
you have 10 minutes😂 Good luck!!


1. What is PEP8 ?

2. What are the different ways to distribute some python source code ?

2 Lists

Let's define the function plural :

def plural(words):
plurals = []
for word in words:
   plurals.append(word + 's')
return plurals

for word in plural(['cabagge','owl','toy']):
print word

Question : How could the code of the function plural be optimised?

3 Dictionaries

Here are two dictionnaries :

input = {
'foo1': 'bar1',
'chose': 'truc',
'foo2': 'bar2',
}
output = {
'bar1': 'foo1',
'truc': 'chose',
'bar2': 'foo2'
}

Question : Propose a function that returns output when you provide input ?

4 Iterators

Let's consider this program :

def program_1():
yield 1
yield 2
yield 3

g = program_1()
a = list(g)
b = list(g)
c = g()

Question : At the end of the program,

1. What is the type of g ?
2. What is the value of a ?
3. What is the value of b ?
4. What is the value of c ?

5 Decorators

Let's consider now :

def str2print(f):
def str2print_wrap(*args, **kwargs):
"""wrapper"""
s = f(*args, **kwargs)
print s
   return str2print_wrap

def hello(s):
""" Return "Hello $s" """
return "%s %s" % ("Hello", s)

Questions :

1. Decorate the method 'hello' with 'str2printf' and write the corresponding 
code.
2. What is the effect of the decorator on a call to the new method 'hello' ?
3. What is the return value of hello.__doc__
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A little test for you Guys😜

2015-09-22 Thread Ian Kelly
On Tue, Sep 22, 2015 at 12:43 PM, Python_Teacher via Python-list
 wrote:
> you have 10 minutes😂 Good luck!!

Sorry, I'm more interested in critiquing the questions than answering them.

> Let's define the function plural :
>
> def plural(words):
> plurals = []
> for word in words:
>plurals.append(word + 's')
> return plurals
>
> for word in plural(['cabagge','owl','toy']):
> print word
>
> Question : How could the code of the function plural be optimised?

Optimized in what way? To be faster? Use less memory? Be more readable?

> 3 Dictionaries
>
> Here are two dictionnaries :
>
> input = {
> 'foo1': 'bar1',
> 'chose': 'truc',
> 'foo2': 'bar2',
> }
> output = {
> 'bar1': 'foo1',
> 'truc': 'chose',
> 'bar2': 'foo2'
> }
>
> Question : Propose a function that returns output when you provide input ?

def f(maybe_input):
if maybe_input == input:
return output

I don't think I really understand what it is that you're asking for here.

> 3. What is the return value of hello.__doc__

hello.__doc__ isn't a function, so it doesn't have a return value. I
think you mean to ask what the expression evaluates to.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A little test for you Guys😜

2015-09-22 Thread Sven R. Kunze

Hmm, why not. :D

On 22.09.2015 20:43, Python_Teacher via Python-list wrote:

you have 10 minutes😂 Good luck!!


1. What is PEP8 ?


A PEP.


2. What are the different ways to distribute some python source code ?


unison, rsync, scp, ftp, sftp, samba, http, https, mail, git, 


2 Lists

Let's define the function plural :

def plural(words):
 plurals = []
 for word in words:
plurals.append(word + 's')
 return plurals

for word in plural(['cabagge','owl','toy']):
 print word

Question : How could the code of the function plural be optimised?


Don't optimized until you need to. So, we leave it as is. ;)


3 Dictionaries

Here are two dictionnaries :

input = {
 'foo1': 'bar1',
 'chose': 'truc',
 'foo2': 'bar2',
}
output = {
 'bar1': 'foo1',
 'truc': 'chose',
 'bar2': 'foo2'
}

Question : Propose a function that returns output when you provide input ?


# :-P
def function(input):
return output


4 Iterators

Let's consider this program :

def program_1():
 yield 1
 yield 2
 yield 3

g = program_1()
a = list(g)
b = list(g)
c = g()

Question : At the end of the program,

1. What is the type of g ?
2. What is the value of a ?
3. What is the value of b ?
4. What is the value of c ?


The program ends with a traceback. So, my variables are all gone. :(


5 Decorators

Let's consider now :

def str2print(f):
 def str2print_wrap(*args, **kwargs):
 """wrapper"""
 s = f(*args, **kwargs)
 print s
return str2print_wrap

def hello(s):
 """ Return "Hello $s" """
 return "%s %s" % ("Hello", s)

Questions :

1. Decorate the method 'hello' with 'str2printf' and write the corresponding 
code.


@str2print
def hello(s):
""" Return "Hello $s" but actually returns None """
return "%s %s" % ("Hello", s)



2. What is the effect of the decorator on a call to the new method 'hello' ?

It prints "Hello {s}" and returns None.

3. What is the return value of hello.__doc__

'wrapper'

Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: A little test for you Guys😜

2015-09-22 Thread Akira Li
Python_Teacher via Python-list  writes:

...
> Let's define the function plural :
>
> def plural(words):
> plurals = []
> for word in words:
>plurals.append(word + 's')
> return plurals
>
> for word in plural(['cabagge','owl','toy']):
> print word

plural() should accept a single word. To handle list of words, call
map(plural, words)

...
> def str2print(f):
> def str2print_wrap(*args, **kwargs):
> """wrapper"""
> s = f(*args, **kwargs)
> print s
>return str2print_wrap
>
> def hello(s):
> """ Return "Hello $s" """
> return "%s %s" % ("Hello", s)

Use functools.wraps() to preserve the function info for introspection:

  import functools
  
  def prints_result(function):
  @functools.wraps(function)
  def wrapper(*args, **kwargs):
  result = function(*args, **kwargs)
  print(result)
  return result #XXX return
  return wrapper
  
  @prints_result
  def hello(...):
  pass

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


Re: Lightwight socket IO wrapper

2015-09-22 Thread James Harris
"Dennis Lee Bieber"  wrote in message 
news:[email protected]...

On Sun, 20 Sep 2015 23:36:30 +0100, "James Harris"
 declaimed the following:




There are a few things and more crop up as time goes on. For example,
over TCP it would be helpful to have a function to receive a specific
number of bytes or one to read bytes until reaching a certain 
delimiter
such as newline or zero or space etc. Even better would be to be able 
to

use the iteration protocol so you could just code next() and get the
next such chunk of read in a for loop. When sending it would be good 
to

just say to send a bunch of bytes but know that you will get told how
many were sent (or didn't get sent) if it fails. Sock.sendall() 
doesn't

do that.


Note that the "buffer size" option on a TCP socket.recv() gives you
your "specific number of bytes" -- if available at that time.


"If" is a big word!

AIUI the buffer size is not guaranteed to relate to the number of bytes 
returned except that you won't/shouldn't(!) get more than the buffer 
size.



I wouldn't want to user .recv(1) though to implement your "reaching a
certain delimiter"... Much better to read as much as available and 
search

it for the delimiter.


Yes, that's what I do at the moment. I keep a block of bytes, add any 
new stuff to it and scan it for delimiters.



I'll confess, adding a .readln() FOR TCP ONLY, might
be a nice extension over BSD sockets (might need to allow option for
whether line-ends are Internet standard  or some other marker, 
and
whether they should be converted upon reading to the native format for 
the

host).


Akira Li pointed out that there is just such an extension: makefile. 
Scanning to  is what I do just now as that includes  too and 
I leave them on the string. IIRC file.readline works in the same way.



I thought UDP would deliver (or drop) a whole datagram but cannot find
anything in the Python documentaiton to guarantee that. In fact
documentation for the send() call says that apps are responsible for
checking that all data has been sent. They may mean that to apply to
stream protocols only but it doesn't state that. (Of course, UDP
datagrams are limited in size so the call may validly indicate
incomplete transmission even when the first part of a big message is
sent successfully.)


Looking in the wrong documentation 

You probably should be looking at the UDP RFC. Or maybe just

http://www.diffen.com/difference/TCP_vs_UDP

"""
Packets are sent individually and are checked for integrity only if 
they
arrive. Packets have definite boundaries which are honored upon 
receipt,

meaning a read operation at the receiver socket will yield an entire
message as it was originally sent.
"""


I would rather see it in the Python docs because we program to the 
language standard and there can be - and often are, for good reason - 
areas where Python does not work in the same way as underlying systems.


Even if the IP layer has to fragment a UDP packet to meet limits of 
the
transport media, it should put them back together on the other end 
before
passing it up to the UDP layer. To my knowledge, UDP does not have a 
size
limit on the message (well -- a 16-bit length field in the UDP 
header). But
since it /is/ "got it all" or "dropped" with no inherent confirmation, 
one
would have to embed their own protocol within it -- sequence numbers 
with
ACK/NAK, for example. Problem: if using LARGE UDP packets, this 
protocol
would mean having LARGE resends should packets be dropped or arrive 
out of

sequence (and since the ACK/NAK could be dropped too, you may have to
handle the case of a duplicated packet -- also large).


Yes, it was the 16-bit limitation that I was talking about.


TCP is a stream protocol -- the protocol will ensure that all data
arrives, and that it arrives in order, but does not enforce any 
boundaries

on the data; what started as a relatively large packet at one end may
arrive as lots of small packets due to intermediate transport limits 
(one
can visualize a worst case: each TCP packet is broken up to fit 
Hollerith
cards; 20bytes for header and 60 bytes of data -- then fed to a reader 
and
sent on AS-IS). Boundaries are the end-user responsibility... line 
endings
(look at SMTP, where an email message ends on a line containing just a 
".")

or embedded length counter (not the TCP packet length).


Yes.

Receiving no bytes is taken as indicating the end of the 
communication.

That's OK for TCP but not for UDP so there should be a way to
distinguish between the end of data and receiving an empty datagram.


I don't believe UDP supports a truly empty datagram (length of 0) --
presuming a sending stack actually sends one, the receiving stack will
probably drop it as there is no data to pass on to a client (there is 
a PR
at work because we have a UDP driver that doesn't drop 0-length 
messages,

but also can't deliver them -- so the circular buffer might fill with
undeliverable headers)


As o

Re: Lightwight socket IO wrapper

2015-09-22 Thread James Harris
"Akira Li" <[email protected]> wrote in message 
news:[email protected]...

"James Harris"  writes:
...

There are a few things and more crop up as time goes on. For example,
over TCP it would be helpful to have a function to receive a specific
number of bytes or one to read bytes until reaching a certain
delimiter such as newline or zero or space etc.


The answer is sock.makefile('rb') then `file.read(nbytes)` returns a
specific number of bytes.


Thanks, I hadn't seen that. Now I know of it I see references to it all 
over the place but beforehand it was in hiding


It is exactly the type of convenience wrapper I was expecting Python to 
have but expected it to be in another module. It looks as though it will 
definitely cover some of the issues I had.



`file.readline()` reads until newline (b'\n') There is Python Issue:
"Add support for reading records with arbitrary separators to the
standard IO stack"
 http://bugs.python.org/issue1152248
See also
 http://bugs.python.org/issue17083

Perhaps, it is easier to implement read_until(sep) that is best suited
for a particular case.


OK.

...

When sending it would be good to just say to send a bunch of bytes 
but
know that you will get told how many were sent (or didn't get sent) 
if

it fails. Sock.sendall() doesn't do that.


sock.send() returns the number of bytes sent that may be less than 
given.

You could reimplement sock.sendall() to include the number of bytes
successfully sent in case of an error.


I know. As mentioned, I wondered if there were already such functions to 
save me using my own.


I thought UDP would deliver (or drop) a whole datagram but cannot 
find

anything in the Python documentaiton to guarantee that. In fact
documentation for the send() call says that apps are responsible for
checking that all data has been sent. They may mean that to apply to
stream protocols only but it doesn't state that. (Of course, UDP
datagrams are limited in size so the call may validly indicate
incomplete transmission even when the first part of a big message is
sent successfully.)

Receiving no bytes is taken as indicating the end of the
communication. That's OK for TCP but not for UDP so there should be a
way to distinguish between the end of data and receiving an empty
datagram.


There is no end of communication in UDP and therefore there is no end 
of

data. If you've got a zero bytes in return then it means that you've
received a zero length datagram.

sock.recvfrom() is a thin wrapper around the corresponding C
function. You could read any docs you like about UDP sockets.

http://stackoverflow.com/questions/5307031/how-to-detect-receipt-of-a-0-length-udp-datagram


As mentioned to Dennis just now, I would prefer to write code to conform 
with the documented behaviour of Python and its libraries, as long as 
they were known to be reliable implementations of what was documented, 
of course.


I agree with what you say. A zero-length UDP datagram should be possible 
and not indicate end of input but is that guaranteed and portable? 
(Rhetorical.)  It seems not. Even the Linux man page for recv says: "If 
no  messages  are  available  at  the  socket, the receive calls wait 
for a message to arrive, unless the socket is nonblocking" In that 
case, of course, what it defines as a "message" - and whether it can be 
zero length or not - is not stated.



The recv calls require a buffer size to be supplied which is a
technical detail. A Python wrapper could save the programmer dealing
with that.


It is not just a buffer size. It is the maximum amount of data to be
received at once i.e., sock.recv() may return less but never more.


My point was that we might want to request the entire next line or next 
field of input and not know a maximum length. *C* programmers are used 
to giving buffers fixed sizes often because then they can avoid fiddling 
with memory management but Python normally does that for us. I was 
suggesting that the thin wrapper around the socket recv() call is too 
thin! The makefile() approach that you mentioned seems more Pythonesque, 
though.



You could use makefile() and read() if recv() is too low-level.


Yes.

James

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


Re: A little test for you Guys😜

2015-09-22 Thread James Harris
On Tuesday, September 22, 2015 at 7:45:00 PM UTC+1, Lj Fc wrote:
> you have 10 minutes😂 Good luck!!

A good set of questions, IMO. Am answering as someone coming back to Python 
after a few years.

> 1. What is PEP8 ?

Coding guidelines, I think.

> 2. What are the different ways to distribute some python source code ?

I don't know what that's getting at as it specifically mentions source code 
apart from tar/gzip or zip. Maybe git or other scm?

> 2 Lists
> 
> Let's define the function plural :
> 
> def plural(words):
> plurals = []
> for word in words:
>plurals.append(word + 's')
> return plurals
> 
> for word in plural(['cabagge','owl','toy']):
> print word
> 
> Question : How could the code of the function plural be optimised?

I would go for

  [word + 's' for word in words]

> 3 Dictionaries
> 
> Here are two dictionnaries :
> 
> input = {
> 'foo1': 'bar1',
> 'chose': 'truc',
> 'foo2': 'bar2',
> }
> output = {
> 'bar1': 'foo1',
> 'truc': 'chose',
> 'bar2': 'foo2'
> }
> 
> Question : Propose a function that returns output when you provide input ?

  def f(input):
output = {}
for k,v in input.items():
  output[v] = k
return output

> 4 Iterators
> 
> Let's consider this program :
> 
> def program_1():
> yield 1
> yield 2
> yield 3
> 
> g = program_1()
> a = list(g)
> b = list(g)
> c = g()
> 
> Question : At the end of the program,
> 
> 1. What is the type of g ?
> 2. What is the value of a ?
> 3. What is the value of b ?
> 4. What is the value of c ?

Good one. I checked this and only got 1 and 2 right.

> 5 Decorators

No idea!

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


Re: problem building python 3.5 extensions for windows

2015-09-22 Thread Terry Reedy

On 9/22/2015 9:35 AM, Robin Becker wrote:

On 22/09/2015 11:14, Robin Becker wrote:

On 22/09/2015 01:36, [email protected] wrote:

.t

.


Thanks for the pointer Christoph.

I certainly didn't let it run for 30 minutes. When I build with 2.7,
3.3 or 3.4
the whole build including reportlab stuff is over in a couple of
minutes. I will
try again, but a linker that takes 30 minutes to create an extension
that ends
up 204Kb long has to be seriously broken. Is it trying to hard? Most
of the code
size is in arrays for code points etc etc.


I timed my builds of pyRXPU for x86 + amd64; these are on a core i5-3470
@ 3.20Ghz with 4Gb memory.

python 3.4   1 minute  14 seconds
python 3.5  52 minutes 50 seconds

so with VS2015 it will now take me an hour to make and test any changes
to this extension. I don't see how the issue can be considered closed.
VS2015 is clearly not the way forward for any reasonable development
process.


I think you should add the above to the issue.

--
Terry Jan Reedy

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


Re: Lightwight socket IO wrapper

2015-09-22 Thread Marko Rauhamaa
"James Harris" :

> I agree with what you say. A zero-length UDP datagram should be
> possible and not indicate end of input but is that guaranteed and
> portable?

The zero-length payload size shouldn't be an issue, but UDP doesn't make
any guarantees about delivering the message. Your UDP application must
be prepared for some, most or all of the messages disappearing without
any error indication.

In practice, you'd end up implementing your own TCP on top of UDP
(retries, timeouts, acknowledgements, sequence numbers etc).


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


Re: A little test for you Guys😜

2015-09-22 Thread sohcahtoa82
On Tuesday, September 22, 2015 at 11:45:00 AM UTC-7, Lj Fc wrote:
> you have 10 minutes😂 Good luck!!
> 
> 
> 1. What is PEP8 ?
> 
> 2. What are the different ways to distribute some python source code ?
> 
> 2 Lists
> 
> Let's define the function plural :
> 
> def plural(words):
> plurals = []
> for word in words:
>plurals.append(word + 's')
> return plurals
> 
> for word in plural(['cabagge','owl','toy']):
> print word
> 
> Question : How could the code of the function plural be optimised?
> 
> 3 Dictionaries
> 
> Here are two dictionnaries :
> 
> input = {
> 'foo1': 'bar1',
> 'chose': 'truc',
> 'foo2': 'bar2',
> }
> output = {
> 'bar1': 'foo1',
> 'truc': 'chose',
> 'bar2': 'foo2'
> }
> 
> Question : Propose a function that returns output when you provide input ?
> 
> 4 Iterators
> 
> Let's consider this program :
> 
> def program_1():
> yield 1
> yield 2
> yield 3
> 
> g = program_1()
> a = list(g)
> b = list(g)
> c = g()
> 
> Question : At the end of the program,
> 
> 1. What is the type of g ?
> 2. What is the value of a ?
> 3. What is the value of b ?
> 4. What is the value of c ?
> 
> 5 Decorators
> 
> Let's consider now :
> 
> def str2print(f):
> def str2print_wrap(*args, **kwargs):
> """wrapper"""
> s = f(*args, **kwargs)
> print s
>return str2print_wrap
> 
> def hello(s):
> """ Return "Hello $s" """
> return "%s %s" % ("Hello", s)
> 
> Questions :
> 
> 1. Decorate the method 'hello' with 'str2printf' and write the corresponding 
> code.
> 2. What is the effect of the decorator on a call to the new method 'hello' ?
> 3. What is the return value of hello.__doc__

Pretty sure this guy is asking us to do his homework.  :-P
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lightwight socket IO wrapper

2015-09-22 Thread James Harris
"Marko Rauhamaa"  wrote in message 
news:[email protected]...

"James Harris" :


I agree with what you say. A zero-length UDP datagram should be
possible and not indicate end of input but is that guaranteed and
portable?


The zero-length payload size shouldn't be an issue, but UDP doesn't 
make

any guarantees about delivering the message. Your UDP application must
be prepared for some, most or all of the messages disappearing without
any error indication.

In practice, you'd end up implementing your own TCP on top of UDP
(retries, timeouts, acknowledgements, sequence numbers etc).


The unreliability of UDP was not the case in point here. Rather, it was 
about whether different platforms could be relied upon to deliver 
zero-length datagrams to the app if the datagrams got safely across the 
network.


James

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


Re: A little test for you Guys😜

2015-09-22 Thread Ian Kelly
On Tue, Sep 22, 2015 at 3:18 PM,   wrote:
> On Tuesday, September 22, 2015 at 11:45:00 AM UTC-7, Lj Fc wrote:
>> you have 10 minutes😂 Good luck!!
>
> Pretty sure this guy is asking us to do his homework.  :-P

Well, looks like it was due 2 hours ago.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A little test for you Guys😜

2015-09-22 Thread James Harris
 wrote in message 
news:[email protected]...


...


Pretty sure this guy is asking us to do his homework.  :-P


Maybe (and I hope not) but asking what PEP8 is could be easily found on 
the internet and asking what the values would be at the end of the 
program in question 4 could be easily found by trying it.


James

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


Re: problem building python 3.5 extensions for windows

2015-09-22 Thread cjgohlke
On Tuesday, September 22, 2015 at 1:49:16 PM UTC-7, Terry Reedy wrote:
> On 9/22/2015 9:35 AM, Robin Becker wrote:
> > On 22/09/2015 11:14, Robin Becker wrote:
> >> On 22/09/2015 01:36, CG wrote:
> > .t
> >>> .
> >>>
> >> Thanks for the pointer Christoph.
> >>
> >> I certainly didn't let it run for 30 minutes. When I build with 2.7,
> >> 3.3 or 3.4
> >> the whole build including reportlab stuff is over in a couple of
> >> minutes. I will
> >> try again, but a linker that takes 30 minutes to create an extension
> >> that ends
> >> up 204Kb long has to be seriously broken. Is it trying to hard? Most
> >> of the code
> >> size is in arrays for code points etc etc.
> >
> > I timed my builds of pyRXPU for x86 + amd64; these are on a core i5-3470
> > @ 3.20Ghz with 4Gb memory.
> >
> > python 3.4   1 minute  14 seconds
> > python 3.5  52 minutes 50 seconds
> >
> > so with VS2015 it will now take me an hour to make and test any changes
> > to this extension. I don't see how the issue can be considered closed.
> > VS2015 is clearly not the way forward for any reasonable development
> > process.
> 
> I think you should add the above to the issue.
> 
> -- 
> Terry Jan Reedy

It's a compiler bug. To work around, disable compiler optimizations, i.e. set 
`extra_compile_args=['/Od']` in setup.py.

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


Python, convert an integer into an index?

2015-09-22 Thread Chris Roberts

(How do I make it into an index? )
Preferably something fairly easy to understand as I am new at this.

results = 134523  #(Integer) 

Desired: 
results = [1, 2, 3, 4, 5, 2, 3]   #(INDEX)

Somehow I see ways to convert index to list to int, but not back again.

Thanks, 
crzzy1
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python, convert an integer into an index?

2015-09-22 Thread Ian Kelly
On Sep 22, 2015 3:46 PM, "Chris Roberts"  wrote:
>
>
> (How do I make it into an index? )
> Preferably something fairly easy to understand as I am new at this.
>
> results = 134523  #(Integer)
>
> Desired:
> results = [1, 2, 3, 4, 5, 2, 3]   #(INDEX)
>
> Somehow I see ways to convert index to list to int, but not back again.

I'm not sure what you mean by "index" in this context, but do you just want
to convert the integer into a list of its digits? The simple way is to
convert it to a string, then convert each character back to an int, and put
the results into a list. More efficient way would be to strip the digits
off one at a time by dividing modulo 10.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python, convert an integer into an index?

2015-09-22 Thread Laura Creighton
In a message of Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts writes:
>
>
>(How do I make it into an index? )
>Preferably something fairly easy to understand as I am new at this.
>
>results = 134523  #(Integer) 
>
>Desired: 
>results = [1, 2, 3, 4, 5, 2, 3]   #(INDEX)
>
>Somehow I see ways to convert index to list to int, but not back again.
>
>Thanks, 
>crzzy1

You need to convert your results into a string first.

result_int=1234523
result_list=[]

for digit in str(result_int):   
result_list.append(int(digit))

digit will be assigned to successive 1 character long strings.  Since
you wanted a list of integers, you have to convert it back.

If you are learning python you may be interested in the tutor mailing
list. https://mail.python.org/mailman/listinfo/tutor  

Laura


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


Re: A little test for you Guys😜

2015-09-22 Thread Lj Fc via Python-list
On Tuesday, September 22, 2015 at 11:19:00 PM UTC+2, [email protected] wrote:
> On Tuesday, September 22, 2015 at 11:45:00 AM UTC-7, Lj Fc wrote:
> > you have 10 minutes😂 Good luck!!
> > 
> > 
> > 1. What is PEP8 ?
> > 
> > 2. What are the different ways to distribute some python source code ?
> > 
> > 2 Lists
> > 
> > Let's define the function plural :
> > 
> > def plural(words):
> > plurals = []
> > for word in words:
> >plurals.append(word + 's')
> > return plurals
> > 
> > for word in plural(['cabagge','owl','toy']):
> > print word
> > 
> > Question : How could the code of the function plural be optimised?
> > 
> > 3 Dictionaries
> > 
> > Here are two dictionnaries :
> > 
> > input = {
> > 'foo1': 'bar1',
> > 'chose': 'truc',
> > 'foo2': 'bar2',
> > }
> > output = {
> > 'bar1': 'foo1',
> > 'truc': 'chose',
> > 'bar2': 'foo2'
> > }
> > 
> > Question : Propose a function that returns output when you provide input ?
> > 
> > 4 Iterators
> > 
> > Let's consider this program :
> > 
> > def program_1():
> > yield 1
> > yield 2
> > yield 3
> > 
> > g = program_1()
> > a = list(g)
> > b = list(g)
> > c = g()
> > 
> > Question : At the end of the program,
> > 
> > 1. What is the type of g ?
> > 2. What is the value of a ?
> > 3. What is the value of b ?
> > 4. What is the value of c ?
> > 
> > 5 Decorators
> > 
> > Let's consider now :
> > 
> > def str2print(f):
> > def str2print_wrap(*args, **kwargs):
> > """wrapper"""
> > s = f(*args, **kwargs)
> > print s
> >return str2print_wrap
> > 
> > def hello(s):
> > """ Return "Hello $s" """
> > return "%s %s" % ("Hello", s)
> > 
> > Questions :
> > 
> > 1. Decorate the method 'hello' with 'str2printf' and write the 
> > corresponding code.
> > 2. What is the effect of the decorator on a call to the new method 'hello' ?
> > 3. What is the return value of hello.__doc__
> 
> Pretty sure this guy is asking us to do his homework.  :-P

See Not that Easy Dude...Simple Questions are sometimes the Toughest!! KISS😜
-- 
https://mail.python.org/mailman/listinfo/python-list


sort help

2015-09-22 Thread Larry Martell
I currently have 3 lists of lists and I sort them based on a common
field into a single list like this:

def GetObjKey(a):
return a[2]

sorted(a + b + c, key=GetObjKey)

Which works just fine.

But now, I need to have just the first list (a) also sub sorted by
another field and I can't quite figure out how to do this.

So for example, if my initial data was this (I'll only show the fields
involved with the sort - the first number is a[2] above and the second
is the new additional sorting field, only present in a)

a[1, 4]
a[1, 2]
a[2, 3]
a[2, 1]
a[5, 6]
a[5, 2]
b[2]
b[5]
c[1]
c[6]

Then I'd want my sorted list to be this:

a[1,2]
a[1,4]
c[1]
a[2,1]
a[2,3]
b[2]
a[5,2]
a[5,6]
b[5]
c[6]

I hope that's clear.

So is there some pythonic way to sort this without resorting to a
brute force old fashioned plow through the data?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sort help

2015-09-22 Thread Chris Angelico
On Wed, Sep 23, 2015 at 8:42 AM, Larry Martell  wrote:
> I currently have 3 lists of lists and I sort them based on a common
> field into a single list like this:
>
> def GetObjKey(a):
> return a[2]
>
> sorted(a + b + c, key=GetObjKey)
>
> Which works just fine.
>
> But now, I need to have just the first list (a) also sub sorted by
> another field and I can't quite figure out how to do this.

Have you tried simply sorting a by the other field prior to doing your
merge-and-sort? The Python list.sort() method is guaranteed to be
stable. I can't find a comparable guarantee for sorted(), but worst
case, you should be able to do your list merge, and then explicitly
name it and sort it.

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


Re: sort help

2015-09-22 Thread Ian Kelly
On Tue, Sep 22, 2015 at 4:55 PM, Chris Angelico  wrote:
> The Python list.sort() method is guaranteed to be
> stable. I can't find a comparable guarantee for sorted()

https://docs.python.org/3.5/library/functions.html#sorted
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sort help

2015-09-22 Thread Chris Angelico
On Wed, Sep 23, 2015 at 9:02 AM, Ian Kelly  wrote:
> On Tue, Sep 22, 2015 at 4:55 PM, Chris Angelico  wrote:
>> The Python list.sort() method is guaranteed to be
>> stable. I can't find a comparable guarantee for sorted()
>
> https://docs.python.org/3.5/library/functions.html#sorted

Right, sorry. Since all I looked at was its docstring, I should have
said so :) So, yep, sorted() is guaranteed stable too, and that would
be the easiest way to subsort something.

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


Re: Python, convert an integer into an index?

2015-09-22 Thread Mark Lawrence

On 22/09/2015 22:43, Chris Roberts wrote:


(How do I make it into an index? )
Preferably something fairly easy to understand as I am new at this.

results = 134523  #(Integer)

Desired:
results = [1, 2, 3, 4, 5, 2, 3]   #(INDEX)

Somehow I see ways to convert index to list to int, but not back again.

Thanks,
crzzy1



Please provide the algorithm to convert 134523 into [1, 2, 3, 4, 5, 2, 
3], as I don't see how to convert a six digit integer into a list of 
seven integers.


--
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: Python, convert an integer into an index?

2015-09-22 Thread MRAB

On 2015-09-22 23:21, Laura Creighton wrote:

In a message of Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts writes:



(How do I make it into an index? )
Preferably something fairly easy to understand as I am new at this.

results = 134523  #(Integer)

Desired:
results = [1, 2, 3, 4, 5, 2, 3]   #(INDEX)

Somehow I see ways to convert index to list to int, but not back again.

Thanks,
crzzy1


You need to convert your results into a string first.

result_int=1234523
result_list=[]

for digit in str(result_int):
 result_list.append(int(digit))

digit will be assigned to successive 1 character long strings.  Since
you wanted a list of integers, you have to convert it back.

If you are learning python you may be interested in the tutor mailing
list. https://mail.python.org/mailman/listinfo/tutor


A shorter way using strings:


results = 134523
list(map(int, str(results)))

[1, 3, 4, 5, 2, 3]

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


Re: A little test for you Guys😜

2015-09-22 Thread Mark Lawrence

On 22/09/2015 19:43, Python_Teacher via Python-list wrote:

you have 10 minutes😂 Good luck!!


1. What is PEP8 ?


It's the one between PEP7 and PEP9.



2. What are the different ways to distribute some python source code ?


Write on sheet of paper, fold into paper dart, throw from window.



2 Lists


Tut, tut, tut.



Let's define the function plural :

def plural(words):
 plurals = []
 for word in words:
plurals.append(word + 's')
 return plurals

for word in plural(['cabagge','owl','toy']):
 print word

Question : How could the code of the function plural be optimised?


It is all ready optimised for programmer time so don't bother with it 
unless there are unforeseen bugs.




3 Dictionaries

Here are two dictionnaries :

input = {
 'foo1': 'bar1',
 'chose': 'truc',
 'foo2': 'bar2',
}
output = {
 'bar1': 'foo1',
 'truc': 'chose',
 'bar2': 'foo2'
}

Question : Propose a function that returns output when you provide input ?


def function():
return input("Who cares?")



4 Iterators

Let's consider this program :

def program_1():
 yield 1
 yield 2
 yield 3

g = program_1()
a = list(g)
b = list(g)
c = g()

Question : At the end of the program,

1. What is the type of g ?
2. What is the value of a ?
3. What is the value of b ?
4. What is the value of c ?


How the hell would I know?



5 Decorators

Let's consider now :

def str2print(f):
 def str2print_wrap(*args, **kwargs):
 """wrapper"""
 s = f(*args, **kwargs)
 print s
return str2print_wrap

def hello(s):
 """ Return "Hello $s" """
 return "%s %s" % ("Hello", s)

Questions :

1. Decorate the method 'hello' with 'str2printf' and write the corresponding 
code.
2. What is the effect of the decorator on a call to the new method 'hello' ?
3. What is the return value of hello.__doc__



Can't afford decorators, they cost an arm and a leg in the UK.

--
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: A little test for you Guys😜

2015-09-22 Thread Igor Korot
Hi,
On Tue, Sep 22, 2015 at 7:32 PM, Mark Lawrence 
wrote:

> On 22/09/2015 19:43, Python_Teacher via Python-list wrote:
>
>> you have 10 minutes😂 Good luck!!
>>
>>
>> 1. What is PEP8 ?
>>
>
> It's the one between PEP7 and PEP9.
>
>
>> 2. What are the different ways to distribute some python source code ?
>>
>
> Write on sheet of paper, fold into paper dart, throw from window.
>
>
>> 2 Lists
>>
>
> Tut, tut, tut.
>
>
>> Let's define the function plural :
>>
>> def plural(words):
>>  plurals = []
>>  for word in words:
>> plurals.append(word + 's')
>>  return plurals
>>
>> for word in plural(['cabagge','owl','toy']):
>>  print word
>>
>> Question : How could the code of the function plural be optimised?
>>
>
> It is all ready optimised for programmer time so don't bother with it
> unless there are unforeseen bugs.
>
>
>> 3 Dictionaries
>>
>> Here are two dictionnaries :
>>
>> input = {
>>  'foo1': 'bar1',
>>  'chose': 'truc',
>>  'foo2': 'bar2',
>> }
>> output = {
>>  'bar1': 'foo1',
>>  'truc': 'chose',
>>  'bar2': 'foo2'
>> }
>>
>> Question : Propose a function that returns output when you provide input ?
>>
>
> def function():
> return input("Who cares?")
>
>
>> 4 Iterators
>>
>> Let's consider this program :
>>
>> def program_1():
>>  yield 1
>>  yield 2
>>  yield 3
>>
>> g = program_1()
>> a = list(g)
>> b = list(g)
>> c = g()
>>
>> Question : At the end of the program,
>>
>> 1. What is the type of g ?
>> 2. What is the value of a ?
>> 3. What is the value of b ?
>> 4. What is the value of c ?
>>
>
> How the hell would I know?
>
>
>> 5 Decorators
>>
>> Let's consider now :
>>
>> def str2print(f):
>>  def str2print_wrap(*args, **kwargs):
>>  """wrapper"""
>>  s = f(*args, **kwargs)
>>  print s
>> return str2print_wrap
>>
>> def hello(s):
>>  """ Return "Hello $s" """
>>  return "%s %s" % ("Hello", s)
>>
>> Questions :
>>
>> 1. Decorate the method 'hello' with 'str2printf' and write the
>> corresponding code.
>> 2. What is the effect of the decorator on a call to the new method
>> 'hello' ?
>> 3. What is the return value of hello.__doc__
>>
>>
> Can't afford decorators, they cost an arm and a leg in the UK.


Is it possible those questions are an interview questions? ;-)

Thank you.


>
>
> --
> 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
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A little test for you Guys😜

2015-09-22 Thread Chris Angelico
On Wed, Sep 23, 2015 at 9:32 AM, Mark Lawrence  wrote:
>>
>> 1. What is the type of g ?
>> 2. What is the value of a ?
>> 3. What is the value of b ?
>> 4. What is the value of c ?
>
>
> How the hell would I know?

Basic schooling, Mark, basic schooling.

1. Newton meters squared per kilogram squared.
2. One ampere is equal to one coulomb per second.
3. Quite considerable; given the amount of traffic that /b/ sees, I
would expect it to sell for a high price.
4. 3e8 meters per second.

Bless me, what DO they teach them at these schools...

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


Re: Successfully send sms with python

2015-09-22 Thread Cameron Simpson

On 22Sep2015 04:19, Timon Rhynix  wrote:

Hello, I have used pyserial, sms0.4 and other libraries to send sms via huawei 
E1750 modem.
The code runs well and no error is thrown but the text message is not 
sent/delivered to the number.
One of my code is as follows:

import serial
import time

class TextMessage:
   def __init__(self, recipient="0123456789", message="TextMessage.content not 
set."):
   self.recipient = recipient
   self.content = message

   def setRecipient(self, number):
   self.recipient = number

   def setContent(self, message):
   self.content = message

   def connectPhone(self):
   conn = 'COM13'
   self.ser = serial.Serial(conn, 460800, timeout=5)
   time.sleep(1)

   def sendMessage(self):
   self.ser.write('ATZ\r')
   time.sleep(1)
   self.ser.write('AT+CMGF=1\r')
   time.sleep(1)
   self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''')
   time.sleep(1)
   self.ser.write(self.content + "\r")
   time.sleep(1)
   self.ser.write(chr(26))
   time.sleep(1)
   print "message sent!"

   def disconnectPhone(self):
   self.ser.close()

When run it, the "message sent!" is printed but no message is sent/delivered.
Please assist on what I am missing. Thank you


Two suggestions:

 as already suggested, you may need to send \r\n instead of just \r

 do you need to follow every .write() with a .flush()? if the Serial object is 
 a buffered stream that will be necessary


Cheers,
Cameron Simpson 

Motorcycling is indeed a delightful pastime.- Honda Rider Training Film
--
https://mail.python.org/mailman/listinfo/python-list


Re: Lightwight socket IO wrapper

2015-09-22 Thread Random832
On Tue, Sep 22, 2015, at 15:45, James Harris wrote:
> "Dennis Lee Bieber"  wrote in message 
> news:[email protected]...
> > On Sun, 20 Sep 2015 23:36:30 +0100, "James Harris"
> >  declaimed the following:
> >>Receiving no bytes is taken as indicating the end of the 
> >>communication.
> >>That's OK for TCP but not for UDP so there should be a way to
> >>distinguish between the end of data and receiving an empty datagram.
> >>
> > I don't believe UDP supports a truly empty datagram (length of 0) --
> > presuming a sending stack actually sends one, the receiving stack will
> > probably drop it as there is no data to pass on to a client (there is 
> > a PR
> > at work because we have a UDP driver that doesn't drop 0-length 
> > messages,
> > but also can't deliver them -- so the circular buffer might fill with
> > undeliverable headers)
> 
> As others have pointed out, UDP implementations do seem to work with 
> zero-byte datagrams properly. Again, I would rather see that in the 
> Python documentation which is what, effectively, forms a contract that 
> we should be able to rely on.

Isn't this technically the same problem as pressing ctrl-d at a terminal
- it's not _really_ the end of the input (you can continue reading
after), but it sends the program something it will interpret as such?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A little test for you Guys😜

2015-09-22 Thread MRAB

On 2015-09-23 00:32, Mark Lawrence wrote:

On 22/09/2015 19:43, Python_Teacher via Python-list wrote:

you have 10 minutes😂 Good luck!!


1. What is PEP8 ?


It's the one between PEP7 and PEP9.



2. What are the different ways to distribute some python source code ?


Write on sheet of paper, fold into paper dart, throw from window.



2 Lists


Tut, tut, tut.



Let's define the function plural :

def plural(words):
 plurals = []
 for word in words:
plurals.append(word + 's')
 return plurals

for word in plural(['cabagge','owl','toy']):
 print word

Question : How could the code of the function plural be optimised?


It is all ready optimised for programmer time so don't bother with it
unless there are unforeseen bugs.



3 Dictionaries

Here are two dictionnaries :

input = {
 'foo1': 'bar1',
 'chose': 'truc',
 'foo2': 'bar2',
}
output = {
 'bar1': 'foo1',
 'truc': 'chose',
 'bar2': 'foo2'
}

Question : Propose a function that returns output when you provide input ?


def function():
  return input("Who cares?")


You have a couple of problems:

1. 'input' is already bound to a dict.

2. From question 2, it's clear that Python 2 is being used, so you
should be using 'raw_input' instead.

[snip]

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


Re: Lightwight socket IO wrapper

2015-09-22 Thread Gregory Ewing

Random832 wrote:


Isn't this technically the same problem as pressing ctrl-d at a terminal
- it's not _really_ the end of the input (you can continue reading
after), but it sends the program something it will interpret as such?


Yes. There's no concept of "closing the connection" with UDP,
because there's no connection. So if a read returns 0 bytes,
it must be because someone sent you a 0-length datagram.

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


Re: A little test for you Guys😜

2015-09-22 Thread Ray Cote
On Tue, Sep 22, 2015 at 7:32 PM, Mark Lawrence 
wrote:

>
>> 2 Lists
>>
>
> Tut, tut, tut.


That is not a list, that is a tutple.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sort help

2015-09-22 Thread Paul Rubin
Larry Martell  writes:
> def GetObjKey(a):
> return a[2]

This function is called operator.itemgetter:

from operator import itemgetter
sorted(a + b + c, key=itemgetter(2))

> So for example, if my initial data was this (I'll only show the fields
> involved with the sort - the first number is a[2] above and the second
> is the new additional sorting field, only present in a)

  sorted(sorted(a, key=itemgetter(5)) + b + c, key = itemgetter(2))

or whatever the new field (instead of 5) is for a.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Successfully send sms with python

2015-09-22 Thread Michael Torrie
On 09/22/2015 05:19 AM, Timon Rhynix wrote:
> When run it, the "message sent!" is printed but no message is sent/delivered.
> Please assist on what I am missing. Thank you

Is this "message sent!" from your code or is it a message you get back
on the serial port from the gsm modem? Oh nevermind I see that it comes
from your own code.

Just an observation, but your code looks quite Java-like. Seems to me
that wrapping this up in a class is not necessary, since the goal is to
provide an interface to send a text message, I'd just use a plain
function, stored in its own module so it can also store things like the
name of the serial port, timeout values, etc. There's no need to make
the caller save any state.

Consider something like this with no error checking when using the
serial port, no context managers for the serial device:
file sms.py:
--
import serial
import time

serial_port = 'COM13'
timeout = 5
baud = 460800

def send_message(recipient, message):
ser = serial.Serial(serial_port, baud, timeout=timeout)
time.sleep(1)
self.ser.write('ATZ\r')
time.sleep(1)
self.ser.write('AT+CMGF=1\r')
time.sleep(1)
self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r\n''')
time.sleep(1)
self.ser.write(self.content + "\r\n")
time.sleep(1)
self.ser.write(chr(26))
time.sleep(1)
print "message sent!"

ser.close()


Someone can just do:

import sms
sms.serial_port = "/dev/ttyUSB2"
sms.send_message("555","Hi there")

Call it good.  Unlike Java, Python does not require everything to be
wrapped up in a class.  Particularly if what you really want is a
singleton.  In many respects you can treat a python module (a python
file) as a singleton.  You can use its namespace to store some state or
basic config information, and define the functions you want others to
use.  Private helper functions can start with an underscore, telling
others not to use them.

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


Line by Line Debug Python Scripts In GDB

2015-09-22 Thread Jondy Zhao
There is a gdb extension "libpython.py" within Python sources, it could print 
Python frame, locals/globals variable, Python sources in GDB. But it couldn't 
set breakpoints in Python scripts directly. Finally, I decided to write a 
debugger to extend GDB could debug Python scripts line by line, just like 
debugging c/c++.

This project is published in github, https://jondy.github.io/pyddd

The purpose of this project is to debug Python scripts line by line as debug 
C/C++ in GDB, so that we can easily debug Python scripts and C/C++ extensions 
within GDB.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A little test for you Guys😜

2015-09-22 Thread Christian Gollwitzer

You've got a lot of sensible answers, but let me add to this one:

Am 22.09.15 um 20:43 schrieb Python_Teacher:

input = {
 'foo1': 'bar1',
 'chose': 'truc',
 'foo2': 'bar2',
}
output = {
 'bar1': 'foo1',
 'truc': 'chose',
 'bar2': 'foo2'
}


This one can be done as a dict comprehension:

>>> p = {'foo1': 'bar1', 'foo2': 'bar2', 'chose': 'truc'}

>>> { v:k for k,v in p.items()}
{'bar1': 'foo1', 'truc': 'chose', 'bar2': 'foo2'}

list/dict comprehension is actually one of the features in Python that I 
like most, because it can greatly ease such transformations.



and, as others said, these questions are lightyears apart from 
showing that somebody understands Python programming. They can be solved 
by trying it or googling, and that is what a real programmer would 
actually do if he is stuck.


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


Re: Postscript to pdf

2015-09-22 Thread Christian Gollwitzer

Am 21.09.15 um 17:20 schrieb Baladjy KICHENASSAMY:

Hello,
This is my programe : on mac i was able to output ps file but i didn't
got the pdf file :/


Maybe ps2pdf is not installed? I think it doesn't come with the Mac. You 
need to get it via fink, homebrew, macports or an official ghostscript 
binary. The same holds true for convert, which is a tool from ImageMagick.


Yet another option would be to wrap the pdf4tcl library:

http://sourceforge.net/projects/pdf4tcl/

It can create PDF from a canvas without an external dependency. The Tcl 
code for it looks like this:



package require pdf4tcl
set size [list [winfo width $win] [winfo height $win]]
set pdf [pdf4tcl::new %AUTO% -paper $size -compress false]
$pdf canvas $win
$pdf write -file $fn
$pdf destroy


In principle, you could run this code via Tkinter.eval()
You would need to set "win" to your canvas path and "fn" to the file 
name path.


Yet another option would be to use a Python package like Reportlab to 
create the PDFs, which requires you to reimplement the drawing code.


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