[no subject]

2015-06-22 Thread John T. Haggerty
I'm looking to just have a simple program that will do a SQLite query pull
a random record and then copy that record too the clipboard the system. I'm
not quite seeing how to do this perhaps this is already been done elsewhere
but I spent quite a bit of time trying to figure out how to do that and I'm
not seeing a listing anywhere. any help would be greatly appreciated.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Do I need license to release the Python version of old BASIC games?

2015-06-22 Thread Laura Creighton
In a message of Sun, 21 Jun 2015 22:23:54 -0600, Michael Torrie writes:
>>From some brief research, it appears there is some question about the
>ability to declare something to be in the public domain, but it is by no
>means a sure thing and lots of people feel it's just fine to declare
>something to be in the public domain.  What his heirs try to assert is
>probably not his concern nor would I worry about it.  This is wandering
>in the weeds in typical python-list style!

No the worry about his heirs is something that the users of his code
have to worry about.  i.e. a teacher who wants to use it but needs
to get permission from the school.  The school may have a blanket
'no copyright, no use' policy, just to protect them from the
possible claims of heirs.

Laura

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


Arguments for "type metaclass" __init__ method

2015-06-22 Thread Kaviraj Kanagaraj
Hi All,

I was reading about meta programming in "Pro Django" book.

I came across the "type" class which will be acting as default meta class
for all other class. Also "type" metaclass is where actuall class object is
created

To dynamically create a class:
DynamicClass = type("DynamicClass", (object,), {'eggs' : 'spams'})

which means type's __init__ method accepts ClassName, bases(tuple) and
attrbs(dict) as args.


But in case of creating class via class definition("type" act as default
metaclass), the type is called by following syntax,

type(cls, classname, bases, attrbs)

My doubt is how it possible to pass "cls" as argument(as class is not even
created before calling meta class). Also how "type" is accepting different
args in two different cases?

Need help in understanding

Thanks in advance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Re: Pyitect - Plugin architectural system for Python 3.0+ (feedback?)

2015-06-22 Thread Ben Powers
on Tue, Jun 16,  2015 at 17:49 Ian Kelly  wrote

>On Mon, Jun 8, 2015 at 10:42 PM, Ben Powers  wrote:
>> As importlib has been added in python 3 and up I decided to use it's
>> abilities to create a plugin system for truly modular development in python.
>>
>> Pyitect has the ability to drop in components and resolve dependencies. Even
>> load different versions of a dependency if two different libraries require
>> two different versions.
>>
>> Pyitect gives each "plugin" it won private namespace to import the
>> components it needs. and nothing else.
>>
>> Pyitect  organizes it self around the concept of a System. Each system can
>> scan and load it's own set of plugins, in each system plugins can be enabled
>> individually.
>>
>> Pyitect even comes with a very simple event system that it uses internal to
>> fire event when plugins are found/loaded/ect for the developer to use.
>>
>> I've written up What I think is a quite comprehensive readme to go with it.
>>
>> Available on PyPi https://pypi.python.org/pypi?:action=display&name=pyitect
>> and Github https://github.com/Ryex/pyitect
>>
>> I'm looking for feedback on what flaws the system may have and where I can
>> improve. I'm always open to pull requests
>>
>> Looking forward to what the comunity thinks of this little project of mine.
>> Thanks for your input and criticism.>

>You need to run your readme through a spell-check, as it's riddled
>with typographical errors and quite hard to read. A grammar check and
>a proofreader would also be useful.>


Actually ya, looking through it again there are number that I didn't find

>> "on_enable": "dostuff.py", // optional, runs this file when the plugin is 
>> enabled>

>A path to a function would feel more Pythonic.>


You right that WOULD be more pythonic, Why I didn't think of that at
the time is a compleat mistery to me.


>> mode -> (OPTIONAL) defaults to import on python 3.4 and up ecec otherwise: 
>> sets the import mode>

>Do the plugins need to be on the sys.path in order to be imported?>


No. plugins need only be refered to by a path relative to their .json file.

>> provides -> a mapping of provided component names to prefix mappings>

>What are the "prefix mappings" and what are they used for?>

>On Mon, Jun 8, 2015 at 10:42 PM, Ben Powers  wrote:
>> As importlib has been added in python 3 and up I decided to use it's
>> abilities to create a plugin system for truly modular development in python.
>>
>> Pyitect has the ability to drop in components and resolve dependencies. Even
>> load different versions of a dependency if two different libraries require
>> two different versions.
>>
>> Pyitect gives each "plugin" it won private namespace to import the
>> components it needs. and nothing else.
>>
>> Pyitect  organizes it self around the concept of a System. Each system can
>> scan and load it's own set of plugins, in each system plugins can be enabled
>> individually.
>>
>> Pyitect even comes with a very simple event system that it uses internal to
>> fire event when plugins are found/loaded/ect for the developer to use.
>>
>> I've written up What I think is a quite comprehensive readme to go with it.
>>
>> Available on PyPi https://pypi.python.org/pypi?:action=display&name=pyitect
>> and Github https://github.com/Ryex/pyitect
>>
>> I'm looking for feedback on what flaws the system may have and where I can
>> improve. I'm always open to pull requests
>>
>> Looking forward to what the comunity thinks of this little project of mine.
>> Thanks for your input and criticism.>

>You need to run your readme through a spell-check, as it's riddled
>with typographical errors and quite hard to read. A grammar check and
>a proofreader would also be useful.>

Actually ya, looking through it again there are number that I didn't find

>> "on_enable": "dostuff.py", // optional, runs this file when the plugin is 
>> enabled>

>A path to a function would feel more Pythonic.>

You right that WOULD be more pythonic, Why I didn't think of that at
the time is a compleat mistery to me.

>> mode -> (OPTIONAL) defaults to import on python 3.4 and up ecec otherwise: 
>> sets the import mode>

>Do the plugins need to be on the sys.path in order to be imported?>


No. plugins need only be refered to by a path relative to their .json file.

>> provides -> a mapping of provided component names to prefix mappings>

>What are the "prefix mappings" and what are they used for?>

That should actually read "postfix mappings" my bad.

normally when you list the components a plugin provides the names of
the components are assumed to exist in the plugin's module name space,
and when the components are required pyitect simply pulls the objects
by name out of the module and passes them along.

postfix mappings allow components to be named differently in the
module than they are provided and allows the developer to attach
version postfixes to the component.

an example from the README:
{
"name": "Im-A-Plugin",
...
"version": 

EuroPython 2015: Partner program deadline extended

2015-06-22 Thread M.-A. Lemburg
We have negotiated an extension of the deadline to register for the
partner program tours with the local tour operator.

  *** EuroPython 2015 Partner Program ***

  https://ep2015.europython.eu/en/events/partner-program/

There is plenty to see in and around Bilbao. We have worked out a
set of interesting tours, together with a local tour company to choose
from, for partners and EuroPython attendees alike:

 * Panoramic tour of Bilbao
 * Excursion to San Sebastian
 * Guggenheim Museum
 * Excursion to La Rioja
 * Boat tour of Bilbao

The tours include travel, lunch and tickets (where needed).

We’d like to encourage early sign-up, since seats are limited.

New registration deadline is July 4th.

Enjoy,
--
EuroPython 2015 Team
http://ep2015.europython.eu/
http://www.europython-society.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: instance as module

2015-06-22 Thread Robin Becker

On 20/06/2015 08:24, Steven D'Aprano wrote:

On Fri, 19 Jun 2015 07:29 pm, Robin Becker wrote:


I'm trying to overcome a recursive import issue in reportlab.

..


I'm afraid I don't understand what you are trying to say here. Why can't the
user just set up "such a default" e.g. canvas_basefontname. Surely that is
a string, e.g. "Comic Sans".

Why will a recursive import occur? If the user doesn't want a recursive
import, they need only ensure that they don't import anything that relies
on rl_config.


I'm afraid this is a failure on the part of reportlab's font handling. For 
almost all user access the font is indeed a string; unfortunately we need also 
to load data for a typical font (eg arial) so that it can be used properly. To 
load the data properly requires other bits of reportlab which use rl_config.


Being able to specify both the font token to use and the method of 
initialization simultaneously seems useful.

--
Robin Becker

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


Re: Opening PDF Using subprocess.Popen Failing

2015-06-22 Thread Robin Becker

.

Naftali,

I ran the following from python prompt


import os
os.system('"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /n 
thello.pdf')



and this worked as did

import subprocess
subprocess.Popen(['C:\Program Files (x86)\Adobe\Reader 
11.0\Reader\AcroRd32.exe','/n','thello.pdf'])


however I also tried running

import subprocess
subprocess.Popen('AcroRd32.exe /nthello.pdf')

which seems closer to your


new_command_str = "AcroRd32.exe /n" + outputname
subprocess.Popen(new_command_str)


and that fails; the python error is



C:\Users\rptlab\tmp>tpdf.py
Traceback (most recent call last):
  File "C:\Users\rptlab\tmp\tpdf.py", line 6, in 
subprocess.Popen('AcroRd32.exe /nthello.pdf')
  File "c:\python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
  File "c:\python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified




--
Robin Becker

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


Re: Opening PDF Using subprocess.Popen Failing

2015-06-22 Thread Robin Becker

On 22/06/2015 11:33, Robin Becker wrote:

.

Naftali,

I ran the following from python prompt









for what it's worth this also works on my machine


Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\rptlab> cd tmp
PS C:\Users\rptlab\tmp> python
Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.

import subprocess
subprocess.Popen(['C:\Program Files (x86)\Adobe\Reader 
11.0\Reader\AcroRd32.exe','/n','thello.pdf'])






not sure if you are using 64bits or 32bit windows, but perhaps you just need to 
specify the full path to your AcroRd32.exe.


--
Robin Becker

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


rl_config

2015-06-22 Thread Robin Becker
Anyone wishing to bend their minds around instance as module can see the code 
I've tested on //annapurna/tmp/rl_config.py.



--
Robin Becker

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


Re: rl_config

2015-06-22 Thread Robin Becker

On 22/06/2015 13:03, Robin Becker wrote:

Anyone wishing to bend their minds around instance as module can see the code
I've tested on //annapurna/tmp/rl_config.py.



whoops misposted sorry

--
Robin Becker

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


Re: Issuing a sqilte query, picking a random result, and copying to the system clipboard

2015-06-22 Thread Tim Chase
On 2015-06-21 17:08, John T. Haggerty wrote:
> I'm looking to just have a simple program that will do a SQLite
> query pull a random record and then copy that record too the
> clipboard the system. I'm not quite seeing how to do this perhaps
> this is already been done elsewhere but I spent quite a bit of time
> trying to figure out how to do that and I'm not seeing a listing
> anywhere. any help would be greatly appreciated.

First, connect to your data source and obtain a cursor:

  import sqlite3
  conn = sqlite3.connect('file.sqlite')
  cur = conn.cursor()

then select a random row:

  cur.execute("SELECT * FROM table ORDER BY RANDOM() LIMIT 1")
  data = cur.fetchone()

then things get tricky because you don't specify what OS you have, as
there are plenty of occasions when there is no system clipboard.

On Win32, you'd need the Win32 add-on libraries to shove things onto
the clipboard, while under X, you'd need other facilities (either
using Tkinter or piping to something like xclip(1)), and yet another
way of doing things on MacOS.

-tkc




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


Re: Opening PDF Using subprocess.Popen Failing

2015-06-22 Thread Naftali
On Friday, June 19, 2015 at 1:25:12 PM UTC-4, Naftali wrote:
> It actually doesn't fail but it 'cannot open in protected mode' (see here 
> http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
> 
> I am using subprocess.Popen("AcroRe32.exe /n ") which is the 
> actuall adobe reader command I'd issue on the command line to open the pdf 
> (the /n option opens it the file in a new instance of reader).
> 
> Now, when I issue the command straight from powershell, the pdf opens no 
> problem, but when I open in my script (whether a .py or py2exe) I get the pop 
> up complaining that the PDF cannot be opened in 'protected mode.' One of the 
> options is to open it anyways, which works. 
> 
> Looking into it (see the link in the first paragraph) my best guess is that 
> it's due to something like "JS-invoked processes: Launching a process through 
> JavaScript is not allowed with Protected Mode enabled." 
> 
> But my naive understanding was that when I give Popen instruction, the 
> command is handed off to windows and the called program is unaware of how it 
> got called, so my thinking is that either that is incorrect or windows 
> somehow 'cooperates' with reader to figure things out. 
> 
> I am looking for *any* insight as to how to deal with this, and the 'turn off 
> protected mode" option wont work for me. 
> 
> Here is my code,
> 
> outputname = " unlocked.pdf"
> 
> commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
> os.system(commandstr)
> 
> new_command_str = "AcroRd32.exe /n" + outputname
> subprocess.Popen(new_command_str)
> 
> sys.exit(0)

Thank you, Robin, just got in, happy Monday. I don't think it's the path 
because I added the acrobat exe to my path env variable which is why it didn't 
crash and burn. I tried running it via the standard prompt (as opposed to 
powershell) and ran into the same issue but the prompt gave a bit more 
information the power shell, in that it said 'open unlocked.pdf: Permission 
denied. based on your success I'm thinking that it has to do with the qpdf 
creates the file. I'm going to play around with that and will update. thank you 
so much for your help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Opening PDF Using subprocess.Popen Failing

2015-06-22 Thread Laura Creighton
I think that your problem is that you have Protected Mode enabled.
If you do, you either have to disable that, or write a policy config
file.

https://www.adobe.com/devnet-docs/acrobatetk/tools/AppSec/protectedmode.html

says.
From: Policy configuration

Protected mode prevents a number of actions which IT can bypass by
creating a white list of allowed actions. The component that reads
these policies is called a “broker.” The broker performs actions based
on those policies, and when an admin provides a properly configured
policy file, the broker can bypass the application’s default
restrictions.

The broker first reads and applies all custom policies prior to
applying the default policies. Since custom policies take precedence,
they are useful for fixing broken workflows, supporting third party
plug-ins, and cases where unsupported machine configurations cause the
Protected Mode to impair required functionality.

Configurable policies have two requirements:

They must reside in the Reader install directory adjacent to
AcroRd32.exe in the install folder. for example: D:\Program
Files (x86)\Adobe\Reader 10.0\Reader\ The name of the policy
file must be ProtectedModeWhitelistConfig.txt.

So, well, I don't have a windows machine.  I cannot test this any more
for you, alas.

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


Re: Opening PDF Using subprocess.Popen Failing

2015-06-22 Thread Naftali
On Friday, June 19, 2015 at 1:25:12 PM UTC-4, Naftali wrote:
> It actually doesn't fail but it 'cannot open in protected mode' (see here 
> http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
> 
> I am using subprocess.Popen("AcroRe32.exe /n ") which is the 
> actuall adobe reader command I'd issue on the command line to open the pdf 
> (the /n option opens it the file in a new instance of reader).
> 
> Now, when I issue the command straight from powershell, the pdf opens no 
> problem, but when I open in my script (whether a .py or py2exe) I get the pop 
> up complaining that the PDF cannot be opened in 'protected mode.' One of the 
> options is to open it anyways, which works. 
> 
> Looking into it (see the link in the first paragraph) my best guess is that 
> it's due to something like "JS-invoked processes: Launching a process through 
> JavaScript is not allowed with Protected Mode enabled." 
> 
> But my naive understanding was that when I give Popen instruction, the 
> command is handed off to windows and the called program is unaware of how it 
> got called, so my thinking is that either that is incorrect or windows 
> somehow 'cooperates' with reader to figure things out. 
> 
> I am looking for *any* insight as to how to deal with this, and the 'turn off 
> protected mode" option wont work for me. 
> 
> Here is my code,
> 
> outputname = " unlocked.pdf"
> 
> commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
> os.system(commandstr)
> 
> new_command_str = "AcroRd32.exe /n" + outputname
> subprocess.Popen(new_command_str)
> 
> sys.exit(0)

Sadly so far it looks like the only answer is to disable protected mode, either 
generally or on a my app basis, which is the same thing because my app will be 
registered as the default handler for pdf. So this is a deal breaker. I've even 
tried routing the opening through a bat file... so either I get this to open up 
in protected mode or I don't see anyway to make it go, with out using a 
different reader. But thank you all for your help, will update should I have 
any success in this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CRLF problems in CPython sources

2015-06-22 Thread Zachary Ware
On Monday, June 22, 2015, Rustom Mody  wrote:

> Trying to setup CPython repo I found some CRLF messes:
>
> 1. Some file-types that are inconsistently LF or CRLF
>Lib/test/decimaltestdata
>
> 2. Some files that are plain dirty (both LF and CRLF)
>Lib/venv/scripts/nt/Activate.ps1
>
> Is this worth a bug report?
> Is python-dev the place for talking of such?
>
> Note 1: Been bitten rather badly by this in svn days and would rather
> waste time
> upfront rather than later.
> Note 2: Not trying to nitpick. git barfed about this
> Looking around I found I can get mercurial to likewise complain
>

For Mercurial, enable the eol extension and then refresh your checkout (hg
update null && hg update ).

Some of the files in the checkout need to be CRLF for Windows' benefit, the
ones in Lib/test/decimaltestdata are as they were when pulled from their
source.  For others, a bug report would be in order. If you submit such a
bug, please make me nosy (zach.ware).

--
Zach


-- 
Sent from Gmail Mobile
-- 
https://mail.python.org/mailman/listinfo/python-list


CRLF problems in CPython sources

2015-06-22 Thread Rustom Mody
Trying to setup CPython repo I found some CRLF messes:

1. Some file-types that are inconsistently LF or CRLF
   Lib/test/decimaltestdata

2. Some files that are plain dirty (both LF and CRLF)
   Lib/venv/scripts/nt/Activate.ps1

Is this worth a bug report?
Is python-dev the place for talking of such?

Note 1: Been bitten rather badly by this in svn days and would rather waste 
time 
upfront rather than later.
Note 2: Not trying to nitpick. git barfed about this
Looking around I found I can get mercurial to likewise complain
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Arguments for "type metaclass" __init__ method

2015-06-22 Thread Chris Angelico
On Mon, Jun 22, 2015 at 1:17 AM, Kaviraj Kanagaraj
 wrote:
> To dynamically create a class:
> DynamicClass = type("DynamicClass", (object,), {'eggs' : 'spams'})
>
> which means type's __init__ method accepts ClassName, bases(tuple) and
> attrbs(dict) as args.
>
>
> But in case of creating class via class definition("type" act as default
> metaclass), the type is called by following syntax,
>
> type(cls, classname, bases, attrbs)
>
> My doubt is how it possible to pass "cls" as argument(as class is not even
> created before calling meta class). Also how "type" is accepting different
> args in two different cases?

If you're looking at the parameters to __init__, it's normal for the
first parameter to be called 'self', and to be the newly-created
object. I suspect that might be what you're seeing here; when you
explicitly call the type, it goes through standard object creation
steps, calling __new__ and (usually) then __init__, resulting in a
call that has the additional argument on it.

So 'cls' is the class that's busily being defined.

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


Re: Opening PDF Using subprocess.Popen Failing

2015-06-22 Thread Naftali
On Friday, June 19, 2015 at 1:25:12 PM UTC-4, Naftali wrote:
> It actually doesn't fail but it 'cannot open in protected mode' (see here 
> http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
> 
> I am using subprocess.Popen("AcroRe32.exe /n ") which is the 
> actuall adobe reader command I'd issue on the command line to open the pdf 
> (the /n option opens it the file in a new instance of reader).
> 
> Now, when I issue the command straight from powershell, the pdf opens no 
> problem, but when I open in my script (whether a .py or py2exe) I get the pop 
> up complaining that the PDF cannot be opened in 'protected mode.' One of the 
> options is to open it anyways, which works. 
> 
> Looking into it (see the link in the first paragraph) my best guess is that 
> it's due to something like "JS-invoked processes: Launching a process through 
> JavaScript is not allowed with Protected Mode enabled." 
> 
> But my naive understanding was that when I give Popen instruction, the 
> command is handed off to windows and the called program is unaware of how it 
> got called, so my thinking is that either that is incorrect or windows 
> somehow 'cooperates' with reader to figure things out. 
> 
> I am looking for *any* insight as to how to deal with this, and the 'turn off 
> protected mode" option wont work for me. 
> 
> Here is my code,
> 
> outputname = " unlocked.pdf"
> 
> commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
> os.system(commandstr)
> 
> new_command_str = "AcroRd32.exe /n" + outputname
> subprocess.Popen(new_command_str)
> 
> sys.exit(0)

Well a happy if not completely satisfying ending. So alternative readers worked 
ok, but IT was ok with turning off protective mode and also disabling 
javascript in adobe reader, considering the relative benign provenance of the 
pdf's coming into the system (though I am curious whether or not disabling java 
script is actually *more* secure than a sandbox, i.e. can a system be harmed by 
rendering a pdf with no java script?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CRLF problems in CPython sources

2015-06-22 Thread Rustom Mody
On Monday, June 22, 2015 at 2:53:21 PM UTC, Zachary Ware wrote:
> On Monday, June 22, 2015, Rustom Mody  wrote:
> Trying to setup CPython repo I found some CRLF messes:
> 
> 
> 
> 1. Some file-types that are inconsistently LF or CRLF
> 
>    Lib/test/decimaltestdata
> 
> 
> 
> 2. Some files that are plain dirty (both LF and CRLF)
> 
>    Lib/venv/scripts/nt/Activate.ps1
> 
> 
> 
> Is this worth a bug report?
> 
> Is python-dev the place for talking of such?
> 
> 
> 
> Note 1: Been bitten rather badly by this in svn days and would rather waste 
> time
> 
> upfront rather than later.
> 
> Note 2: Not trying to nitpick. git barfed about this
> 
> Looking around I found I can get mercurial to likewise complain
> 
> 
> 
> 
> For Mercurial, enable the eol extension and then refresh your checkout (hg 
> update null && hg update ).

Yeah It was a bit of a struggle to get that up.
[hg docs quite poor in this area]

> 
> 
> Some of the files in the checkout need to be CRLF for Windows' benefit, the 
> ones in Lib/test/decimaltestdata are as they were when pulled from their 
> source.  For others, a bug report would be in order. If you submit such a 
> bug, please make me nosy (zach.ware).

Thanks Zachary -- will do.
[On an half-installed machine right now... Repos elsewhere]
-- 
https://mail.python.org/mailman/listinfo/python-list


what should every python expert know

2015-06-22 Thread baha
I don't like to move to another programming language until being guru .. 
(python is my first programming language) what are things that I must know and 
discover and understand more deeply 
what are the projects that can be useful for a beginner like me and the 
advanced tricks 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what should every python expert know

2015-06-22 Thread Steven D'Aprano
On Tue, 23 Jun 2015 04:30 am, baha wrote:

> I don't like to move to another programming language until being guru ..
> (python is my first programming language) what are things that I must know
> and discover and understand more deeply what are the projects that can be
> useful for a beginner like me and the advanced tricks

What should every Python expert know? That depends what they want to do.

Your question is a bit like "what should every artist know" -- some artists
specialise, others generalise. Same goes for engineers, doctors, scientists
(actually, these days, pretty much all scientists specialise).


What could you learn?

- web frameworks like Django, CherryPy and others, HTML, Javascript;
- databases and SQL;
- floating point maths and numeric algorithms, including numpy, scipy, 
  sage and others;
- writing extensions in C, Fortran, Java, or other languages;
- or using numba, cython, hope or others;
- integration with other tools using Applescript, Swift, bash scripting 
  or Windows Powershell;
- Unicode and legacy encodings;
- natural language processing with nltk;
- text processing with regular expressions;
- text parsers;
- source control using hg, git or others;
- graphics using PIL or pillow;
- GUI applications with tkinter, PyQt or others;
- decorators, metaclasses, comprehensions, closures;
- mixins, traits, multiple inheritance;
- doc tests, unit tests, regression tests, smoke tests, integration tests,
  fuzz tests, and others;
- writing documentation;
- project planning;
- and many other things.


It is difficult for us to teach you "the advanced tricks" when we don't know
what you already know and what you don't know. For example, maybe you will
consider this an advanced trick:


py> a = 1
py> b = 2
py> print a, b
1 2
py> a, b = b, a
py> print a, b
2 1


and maybe you won't.



-- 
Steven

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


Re: Re: Pyitect - Plugin architectural system for Python 3.0+ (feedback?)

2015-06-22 Thread Ian Kelly
On Mon, Jun 22, 2015 at 2:32 AM, Ben Powers  wrote:
> on Tue, Jun 16,  2015 at 17:49 Ian Kelly  wrote
>
>>On Mon, Jun 8, 2015 at 10:42 PM, Ben Powers  wrote:
>>> #file.py
>>> from PyitectConsumes import foo
>>>
>>> class Bar(object):
>>> def __init__():
>>> foo("it's a good day to be a plugin")>
>
>>I don't understand this example. Is "PyitectConsumes" the name of a
>>component or part of Pyitect? Or is "foo" the name of the component?>
>
>
> `PyitectComsumes` is a special module injected into sys.modules when the
> plugin module is imported and removed after the import is complete. it's
> name-space contains all the components declared as required in the plugin's
> .json

So this import can only be performed when the module is loaded, not
later when a component's functionality is being invoked?

>>> Plugins are loaded on demand when a component is loaded via
>>>
>>> System.load("")>
>
>>What's the difference between this and the "PyitectConsumes" import?>
>
>
> The PyitectConsumes import is for use inside plugins where dependencies are
> declared prior to import.
>
> System.load is for use in the application to load components. Plugins are
> not intended to know about the System they are being used in.
>
>
>>> Loaded pluginss do NOT store their module object in sys.modules>
>
>>What about imports of plugin-local modules that are performed inside
>>the plugins? Do those also get cleaned up from sys.modules?>
>
>
> Actually no... thats an oversight on my part. really I should temporally
> clone sys.modules inject the PyitectConsumes special module and then set it
> back to the original sys.modules dict after the import has been performed,
> that would secure the process more and prevent cluttering of sys.modules.

It seems to me that this could create new problems. For example,
suppose a plugin being loaded imports urllib, and then later the
application tries to import urllib. It's not in sys.modules, so the
import framework loads it again, and now there are two copies of
urllib floating around in the interpreter. I think you actually need
to diff sys.modules and then remove anything that's added but only if
its path falls within the path of the plugin directory.

The more that I think about this, I don't think that overloading the
import machinery like this is the right way for plugins to gain access
to components. If instead you just pass the module a context object
with a get_component method, then you won't have to muck around with
sys.modules as much, and the context object can remain available to
the plugin for later use.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to check in script if Python or Jython is used

2015-06-22 Thread Dan Stromberg
IMO, it's usually better to test for features and use them if they are
present, than to build a list of features available in specific
interpreters.

I see it as analogous to the difference between huge C #ifdef's on OS,
and autoconf.

On Sun, Jun 21, 2015 at 1:12 AM, Cecil Westerhof  wrote:
> I installed Jython and will start playing with it. There probably will
> be differences between Python and Jython. Is there a way to determine
> if a script is run by Python or Jython? Then different execution paths
> could be taken. With sys.version(_info) you do not get this
> information.
>
> --
> Cecil Westerhof
> Senior Software Engineer
> LinkedIn: http://www.linkedin.com/in/cecilwesterhof
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Published timeDecebal.py

2015-06-22 Thread Cecil Westerhof
I published timeDecebal.py:
https://github.com/CecilWesterhof/PythonLibrary/blob/master/timeDecebal.py

Not much yet: the Timer class from Steven D'Aprano and the function
time_test. With this function you can get the results of a function
AND the time it took to execute the function. (I find that useful.)

Requests for extra functionality are welcome. :-D 
No guarantees for implementation o-course. ;-)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Calling a function is faster than not calling it?

2015-06-22 Thread Piet van Oostrum
Steven D'Aprano  wrote:

> Why is calling a function faster than bypassing the function object and
> evaluating the code object itself? And not by a little, but by a lot?
>
> Here I have a file, eval_test.py:
>
> # === cut ===
> from timeit import Timer
>
> def func():
> a = 2
> b = 3
> c = 4
> return (a+b)*(a-b)/(a*c + b*c)
>
>
> code = func.__code__
> assert func() == eval(code)
>
> t1 = Timer("eval; func()", setup="from __main__ import func")
> t2 = Timer("eval(code)", setup="from __main__ import code")
>
> # Best of 10 trials.
> print (min(t1.repeat(repeat=10)))
> print (min(t2.repeat(repeat=10)))
>
> # === cut ===
>
>
> Note that both tests include a name lookup for eval, so that as much as
> possible I am comparing the two pieces of code on an equal footing.

They are not on equal footing. The first one only looks up eval, but the second 
actually calls eval. The overhead of calling eval is what makes the difference. 
To get them on equal footing you will have to insert an eval call also in the 
first example.

dummy = compile("0", 'string', "eval")

t1 = Timer("eval(dummy); func()", setup="from __main__ import dummy, func")
t2 = Timer("0; eval(code)", setup="from __main__ import code")

And then you'll see that t1 is slightly slower than t2.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Simplest/Idiomatic way to count files in a directory (using pathlib)

2015-06-22 Thread Travis Griggs
Subject nearly says it all.

If i’m using pathlib, what’s the simplest/idiomatic way to simply count how 
many files are in a given directory?

I was surprised (at first) when

len(self.path.iterdir())

I don’t say anything on the in the .stat() object that helps me.

I could of course do the 4 liner:

count = 0
for _ in self.path.iterdir():
count += 1
return count

The following seems to obtuse/clever for its own good:

return sum(1 for _ in self.path.iterdir())
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

2015-06-22 Thread Travis Griggs


Subject nearly says it all.

If i’m using pathlib, what’s the simplest/idiomatic way to simply count how 
many files are in a given directory?

I was surprised (at first) when

   len(self.path.iterdir())

didn’t work.

I don’t see anything in the .stat() object that helps me.

I could of course do the 4 liner:

   count = 0
   for _ in self.path.iterdir():
   count += 1
   return count

The following seems to obtuse/clever for its own good:

   return sum(1 for _ in self.path.iterdir())
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

2015-06-22 Thread Ian Kelly
On Mon, Jun 22, 2015 at 4:33 PM, Travis Griggs  wrote:
> 
>
> Subject nearly says it all.
>
> If i’m using pathlib, what’s the simplest/idiomatic way to simply count how 
> many files are in a given directory?
>
> I was surprised (at first) when
>
>len(self.path.iterdir())
>
> didn’t work.

len doesn't work on iterators for a number of reasons:

* It would exhaust the iterator, preventing further use.
* The iterator is not necessarily finite.
* Even if it's finite, the length is not necessarily deterministic.
Consider this simple generator:

def gen():
while random.randrange(2):
yield 42

> I don’t see anything in the .stat() object that helps me.
>
> I could of course do the 4 liner:
>
>count = 0
>for _ in self.path.iterdir():
>count += 1
>return count
>
> The following seems to obtuse/clever for its own good:
>
>return sum(1 for _ in self.path.iterdir())

This is the usual idiom for counting the number of items yielded from
an iterator. Alternatively you can use len(list(self.path.iterdir()))
if you don't mind constructing a list of the entire directory listing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JSON Object to CSV File Troubleshooting

2015-06-22 Thread Chris Angelico
On Mon, Jun 22, 2015 at 9:33 AM, Denis McMahon  wrote:
> This is the sort of data conversion code I generally turn out in a day or
> so, it's hardly rocket science as long as you have a clear description of
> what is required. If you don't have a clear description of what is
> required, you have to keep asking questions until you get one.

And this all before you even write a line of code. Getting the specs
down is simply a matter of taking an input file and hand-crafting an
ideal output file. One of my brothers claims he isn't a programmer
(though he's better than he lets on), but when it comes to figuring
iout a coherent spec, he's awesome... if I could put someone like him
between the programmer and the end user, it'd save so much time.

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


How do I get the currently installed tab completion function?

2015-06-22 Thread Steven D'Aprano
I have two (or more) different types of tab completion, and I want one to
apply under certain circumstances, and the other to apply at others. For
example, let's say I want one to apply inside a function which uses
raw_input (or input in Python 3), and the other to apply the rest of the
time.

So I might use this:

def getfilename():
prev = get_the_current_completer()  # <<--- this
readline.set_completer(filename_completer)
try:
return raw_input("What file do you want? ")
finally:
readline.set_completer(prev)


Is that the best (only) way?

How do I get the currently installed completer?

Solutions for any version of Python acceptable, but if they work all the way
back to 2.4 or older, even better.



-- 
Steven

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


Re: How do I get the currently installed tab completion function?

2015-06-22 Thread Chris Angelico
On Tue, Jun 23, 2015 at 11:02 AM, Steven D'Aprano  wrote:
> How do I get the currently installed completer?
>
> Solutions for any version of Python acceptable, but if they work all the way
> back to 2.4 or older, even better.

Whether there's a way to avoid the whole try/finally I can't say, but
I just went looking for the obvious "readline.get_completer()", and it
does seem to be there. Is there something I'm missing here?

Found it on 3.4, 3.5, 3.6, and 2.7, but I don't have anything older to test on.

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


Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

2015-06-22 Thread Paul Rubin
Travis Griggs  writes:
> The following seems to obtuse/clever for its own good:
> return sum(1 for _ in self.path.iterdir())

I've generally done something like that.  I suppose it could be added to
itertools.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get the currently installed tab completion function?

2015-06-22 Thread Steven D'Aprano
On Tue, 23 Jun 2015 11:23 am, Chris Angelico wrote:

> On Tue, Jun 23, 2015 at 11:02 AM, Steven D'Aprano 
> wrote:
>> How do I get the currently installed completer?
>>
>> Solutions for any version of Python acceptable, but if they work all the
>> way back to 2.4 or older, even better.
> 
> Whether there's a way to avoid the whole try/finally I can't say, but
> I just went looking for the obvious "readline.get_completer()", and it
> does seem to be there. Is there something I'm missing here?

No, but there's obviously something *I'm* missing.

I don't know how I missed that :-(

It's especially embarrassing because it is available all the way back to
version 2.4, which is exactly what I need.


Sorry for the noise.


-- 
Steven

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


Re: How do I get the currently installed tab completion function?

2015-06-22 Thread Chris Angelico
On Tue, Jun 23, 2015 at 11:41 AM, Steven D'Aprano  wrote:
> On Tue, 23 Jun 2015 11:23 am, Chris Angelico wrote:
>
>> On Tue, Jun 23, 2015 at 11:02 AM, Steven D'Aprano 
>> wrote:
>>> How do I get the currently installed completer?
>>>
>>> Solutions for any version of Python acceptable, but if they work all the
>>> way back to 2.4 or older, even better.
>>
>> Whether there's a way to avoid the whole try/finally I can't say, but
>> I just went looking for the obvious "readline.get_completer()", and it
>> does seem to be there. Is there something I'm missing here?
>
> No, but there's obviously something *I'm* missing.
>
> I don't know how I missed that :-(
>
> It's especially embarrassing because it is available all the way back to
> version 2.4, which is exactly what I need.
>
>
> Sorry for the noise.

That's still only the lesser option, of course. Better would be a way
to say raw_input("prompt? ", completer=filename_completer) but that's
not an option, so it'd have to be an explicit readline.something()
call. I can't find any way to actually ask the readline module to read
a line, though, but given that my experience with that module is
effectively zip, someone else may well be able to offer a superior
suggestion.

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


Re: How do I get the currently installed tab completion function?

2015-06-22 Thread Steven D'Aprano
On Tue, 23 Jun 2015 12:02 pm, Chris Angelico wrote:

> On Tue, Jun 23, 2015 at 11:41 AM, Steven D'Aprano 
> wrote:
>> On Tue, 23 Jun 2015 11:23 am, Chris Angelico wrote:
>>
>>> On Tue, Jun 23, 2015 at 11:02 AM, Steven D'Aprano 
>>> wrote:
 How do I get the currently installed completer?

 Solutions for any version of Python acceptable, but if they work all
 the way back to 2.4 or older, even better.
>>>
>>> Whether there's a way to avoid the whole try/finally I can't say, but
>>> I just went looking for the obvious "readline.get_completer()", and it
>>> does seem to be there. Is there something I'm missing here?
>>
>> No, but there's obviously something *I'm* missing.
>>
>> I don't know how I missed that :-(
>>
>> It's especially embarrassing because it is available all the way back to
>> version 2.4, which is exactly what I need.
>>
>>
>> Sorry for the noise.
> 
> That's still only the lesser option, of course. Better would be a way
> to say raw_input("prompt? ", completer=filename_completer) but that's
> not an option, so it'd have to be an explicit readline.something()
> call. I can't find any way to actually ask the readline module to read
> a line, though, but given that my experience with that module is
> effectively zip, someone else may well be able to offer a superior
> suggestion.

The point is to have the completion available while the user types at the
prompt, not to apply it afterwards. So you have to install it as a
completer function under readline.




-- 
Steven

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


Re: JSON Object to CSV File Troubleshooting

2015-06-22 Thread Denis McMahon
On Sun, 21 Jun 2015 16:56:27 -0700, Sahlusar wrote:

> Here is an example XML document that I am working with:

> You are welcome to contribute and provide me with feedback. Thank you
> for your continued feedback and guidance.

Your XML is invalid! You have a closing MO tag with no opening tag.

> This is the output that I seek:

> > "a","b"   // headers 
> > "b",1 // data row 1 
> > "b",2 // data row 2

I assume from this that where you have a list of identical elements at 
the deepest nesting level of the XML file, you require one CSV record for 
each element in that list, and that you want all higher level element 
values and attributes duplicated in each CSV record.

I assume that you want to use the tag name of each element as the 
identifier for the text content of the element (where there is any), and 
that where an element has no text content, a 0 value is appropriate.

I also assume that as long as the relationship between the headers and 
the data is correct, it does not matter what order the headers are in, ie 
the data and headers can both be sorted by the header.

The output of my code generated once I had corrected your broken XML by 
inserting an 'MO' opening tag between the 'Response' opening tag and the 
'MonthDayCount' opening tag can be seen at:

http://www.sined.co.uk/tmp/xml_to_csv.txt

This was generated from xml file:

http://www.sined.co.uk/tmp/xml_data.txt

If you want the code that produced it, we can discuss fees, it took a few 
hours and for consultancy like this I expect a few 10s of $ per hour.

There may be a generic method to do what you want involving parsing the 
xml to a nested dictionary / list data object, and then flattening that 
object, but I don't see that generating you one line of CSV for each 
Int32 in MonthDayCount.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list