Re: Problem/bug with class definition inside function definition

2018-05-07 Thread Gregory Ewing

Python 3.5.1 (default, Jun  1 2016, 13:15:26)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(a):
...  class D:
...   pass
...  D.a = a
...  return D
...
>>> c = f(42)
>>> c
.D'>
>>> c.a
42

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


Re: Tracebacks for exceptions in interactively entered code.

2018-05-07 Thread Serhiy Storchaka

07.05.18 22:59, Terry Reedy пише:

I intend to improve the IDLE doc section on IDLE-console differences.


Don't haste to document it. The behavior of the standard interactive 
mode can be changed in 3.8.


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


Suggestion for a "data" object syntax

2018-05-07 Thread Mikhail V
Here is an idea for 'data object' a syntax.
For me it is interesting, how would users find such syntax.
I personally find that this should be attractive from users
perspective.
Main aim is more readable presenting of typical data chunks
and some typical data types (tuples/lists) directly in code.
Further this should significantly simplify typing.

*Example 1. Multi-line strings*

Here is a 3 lines multi-line string, it will be automatically 'dedented'
by the parser by one level of indent:

data === S :
this is multi-line string
escape chars: same as in strings (\\, \\n, \\t ...) ,
but "no need to 'escape' quotes"

(Of course, assuming this feature will be added to the lexers
of your editor, otherwise it may mess up syntax highlighting)

So the proposed statement header is like:

variable === "type" :
...

The "===" token and type id's are of course subject to discussion.
"type" is type of data, which tells the parser to
convert data to specific type of Python object.
The above is type "S", a multi-line string.


*Example 2. Tuples*

Tuple is a data block with normal Python elements.

data === T :
123"hello"
abc + d

Here the separators of elements are : tab character,
new line (and maybe some white-space character like em-space?)
The above construct will be direct synonym for:

data = (1, 2, 3, "hello", a, b, c + d)

Benefits are easy to see: say I want a tuple of strings:

data === T :
"foo bar"
"hello world"
"to be continued..."

VS current:

data = (
"foo bar" ,
"hello world" ,
"to be continued..." ,
)

Main problem with the latter are commas, it is not easy
to type and, whats more important - hard to notice missing commas.
And brackets of course does not make it nicer either.

The above are typical cases where I see clear win, and
IMO they are quite common constructs.

More complicated examples :


*Example 3. Two-dimensional tuple.*

data === T/T :
123"hello"
ab c + de f

is a synonym for:

data = (
(1, 2, 3, "hello") ,
(a, b, c + d, e, f ) )

The rule here is: TAB character is inner elements' separator, and the
new line is outer elements' separator. Line continuation
character is  \  (to help with long lines).

*The benefits is just as in above examples :
readability and 'typeability' boost.*

To present nesting of elements of higher than 2 levels,
normal Python syntax can be used for deeper nesting:

data === T/T :
12(345)
ab c

Or maybe even allow commas:
data === T/T :
12(3, 4, 5)
ab c

VS normal:

data = (
(1, 2, (3, 4, 5) ) ,
(a, b, c ) )

So the idea is to cover only first two levels of
nesting of course.

Further, common types may be defined, like e.g. L/L (list of lists)
but I don't want to go far into details and want to stop
on common cases to help evaluate the idea in general.


*Main rules: *
- the definition is allowed  only as a statement (no passing as argument)
- (imo) data starts always as a new line after the header
- implicit string concatenation disallowed


So the question is, how do you like such syntax, and
if so, what common examples can be fit in here.
Any ideas, comments are of course welcome.
Suggest some data and I'll try to express it in this syntax.



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


Re: Module, Package

2018-05-07 Thread Ben Finney
Sharan Basappa  writes:

> One question. So, we can import the entire package or just a module in
> a given package. Is this correct?

Each time you ‘import foo’, you are getting a module.

> For example,
> import nltk

That results in a module object, and you can use the name ‘nltk’ to
reference that module.

> import nltk.stem

That results in a different module object, and you can use the name
‘nltk.stem’ (which is the name ‘stem’ in the namespace ‘nltk’) to
reference that module.

See the Python documentation for a good description of the import system
https://docs.python.org/3/reference/import.html>.

-- 
 \  “If we could change ourselves, the tendencies in the world |
  `\  would also change.” —Mohandas K. Gandhi, _Collected Works_, 1913 |
_o__)  |
Ben Finney

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


Re: Module, Package

2018-05-07 Thread Sharan Basappa
MRAB, ChirisA,

One question. So, we can import the entire package or just a module in a given 
package. Is this correct?

For example,
import nltk
import nltk.stem
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Module, Package

2018-05-07 Thread Sharan Basappa
On Monday, 7 May 2018 23:09:41 UTC+5:30, Chris Angelico  wrote:
> On Tue, May 8, 2018 at 2:53 AM, Sharan Basappa  
> wrote:
> > I am a bit confused between module and package in Python.
> > Does a module contain package or vice versa?
> > When we import something in Python, do we import a module or a package?
> 
> You import a module.
> 
> A package is one particular form of module, which is built out of
> other modules (usually a directory full of .py files). There are a
> number of different sorts of modules; regardless, you 'import X' and
> get module X.
> 
> ChrisA

Thank you very much. Much appreiated
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: seeking deeper (language theory) reason behind Python design choice

2018-05-07 Thread Steven D'Aprano
On Mon, 07 May 2018 22:27:22 +0200, all-lists wrote:

> Hi,
> 
> I was wondering (and have asked on StackOverflow [1] in a more elaborate
> way) whether there is a deeper reason to not allow assignments in lambda
> expressions.

Currently, the real reason is that lambda expressions are limited to a 
single expression as the body of the function, and binding operations in 
Python are statements. It is as simple as that: you can't have

y = x + 1

inside a lambda for the same reason you can't have

import spam
while condition:
try:
this()
except Exception:
pass

Because lambda takes a single expression.

And the reason for *that* limitation is that after 20+ years of looking, 
nobody has come up with a satisfactory syntax for a multiple statement 
block expression which:

- is not ambiguous

- can be parsed by an LL(1) parser

- and meets Guido's approval.


Nobody has quite ruled out a block expression, in fact it is one of the 
acknowledged useful features which Ruby has that Python doesn't. So its 
not like we don't want it. Its just hard to do without ambiguity or a 
more complex parser.


> 
> I'm not criticising, I'm asking in order to know ;-)
> 
> The surface-reason is the distinction between assignments and
> statements, but why it was designed this way (with respect to lambda,
> not in general)?
> 
> So far, no satisfying answer has come up, except for maybe to avoid a
> programmer accidentally typing `=` instead of `==`, which I find a bit
> unsatisfying as the only reason.

No, that's the reason why = is a statement not an expression. That's not 
why statements aren't allowed in lambdas. If we had blocks, this would be 
perfectly acceptable:

lambda arg: %%%START BLOCK
spam = arg + 1
...
%%%END BLOCK

since = in a statement on its own is not dangerous. People *almost never* 
intend to write == for the side-effects only:

# don't care whether they are actually equal or not
# just want to call the __eq__ method for its side-effects
spam == arg + 1

Since that never happens in real life, there's no risk of accidentally 
writing "spam = arg + 1" when you wanted "spam == arg + 1".




-- 
Steve

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


Re: Tracebacks for exceptions in interactively entered code.

2018-05-07 Thread Steven D'Aprano
On Mon, 07 May 2018 15:59:10 -0400, Terry Reedy wrote:

> I intend to improve the IDLE doc section on IDLE-console differences.
> 
> The following is from standard interactive mode (PSF CPython 3.7.0a4) on
> Windows (Win 10, Command Prompt)
> 
>  >>> def f():
> ... return 1/0
> ...
>  >>> f()
> Traceback (most recent call last):
>File "", line 1, in 
>File "", line 2, in f
> ZeroDivisionError: division by zero
> 
> Each statement is given the same pseudofile name, "", lines are
> numbered within each statement, and the code line is not printed.  As
> far as I remember, this has been the same on Windows since forever,
> though only current versions are relevant to current docs.
> 
> Is the above also the same on other systems (linux, Mac)?  I would like
> to know before I say so ;-).

Its the same here:

[steve@ando Python-3.6.4]$ ./python -E
Python 3.6.4 (default, Apr  2 2018, 12:16:49)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
... return 1/x
...
>>> f()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in f
NameError: name 'x' is not defined



-- 
Steve

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


Re: seeking deeper (language theory) reason behind Python design choice

2018-05-07 Thread Stefan Klinger
Chris Angelico (2018-May-08, excerpt):
> What exactly would be the scope of the assigned name?

Yes, that's more like the kind of answer I was seeking.  But I'm not
entirely satisfied.

> def sort_func(item):
> date = parse_date(item.creation_date)
> return date.day_of_week, date.year, date.month, date.day
> items.sort(key=sort_func)

This function contains two statements.  Would be nice to see a
one-statement variant that exposes the same necessity of local
assignment.

I have not thought about local assignment expressions, but they can
already now be done naturally as follows:

lambda item: (lambda date: date.day_of_week, date.year, date.month, 
date.day)(parse_date(item.creation_date)

But this is stretching the usefulness of Python's lambda (readability)
quite a bit, I have to admit.

Anyway, I was rather thinking about global assignment.  And there
would even be choice in whether it should be always global, Python has
a rule for that in the following case:

x = 23

def foo(y):
x = 2 * y   # this is local
print('x in foo', x)

print('x before foo', x)
foo(42)
print('x after foo', x)


class z:
v = 12345

def bar(y):
z.v = 2 * y # this is global
print('z.v in bar', z.v)

print('z.v before bar', z.v)
bar(0)
print('z.v after bar', z.v)

Cheers
Stefan


--
http://stefan-klinger.de  o/X
Send plain text messages only, not exceeding 32kB./\/
\
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem/bug with class definition inside function definition

2018-05-07 Thread Alexey Muranov

To be more exact, i do see a few workarounds, for example:


   def f4(a):
   b = a
   class D:
   a = b  # Works
   return D

But this is not what i was hoping for.

Alexey.

On Tue, 8 May, 2018 at 12:02 AM, Alexey Muranov 
 wrote:
I have discovered the following bug or problem: it looks like i am 
forced to choose different names for class attributes and function 
arguments, and i see no workaround.  Am i missing some special syntax 
feature ?


Alexey.

---
x = 42

class C1:
   y = x  # Works

class C2:
   x = x  # Works

# ---
def f1(a):
   class D:
   b = a  # Works
   return D

def f2(a):
   class D:
   a = a  # Does not work <
   return D

def f3(a):
   class D:
   nonlocal a
   a = a  # Does not work either <
   return D

# ---
def g1(a):
   def h():
   b = a  # Works
   return b
   return h

def g2(a):
   def h():
   a = a  # Does not work (as expected)
   return a
   return h

def g3(a):
   def h():
   nonlocal a
   a = a  # Works
   return a
   return h

# ---
if __name__ == "__main__":
   assert C1.y == 42
   assert C2.x == 42

   assert f1(13).b == 13

   try:
   f2(13)  # NameError
   except NameError:
   pass
   except Exception as e:
   raise Exception( 'Unexpected exception raised: '
'{}'.format(type(e).__name__) )
   else:
   raise Exception('No exception')

   try:
   f3(13).a  # AttributeError
   except AttributeError:
   pass
   except Exception as e:
   raise Exception( 'Unexpected exception raised: '
'{}'.format(type(e).__name__) )
   else:
   raise Exception('No exception')

   assert g1(13)() == 13

   try:
   g2(13)()  # UnboundLocalError
   except UnboundLocalError:
   pass
   except Exception as e:
   raise Exception( 'Unexpected exception raised: '
'{}'.format(type(e).__name__) )
   else:
   raise Exception('No exception')

   assert g3(13)() == 13



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


Problem/bug with class definition inside function definition

2018-05-07 Thread Alexey Muranov
I have discovered the following bug or problem: it looks like i am 
forced to choose different names for class attributes and function 
arguments, and i see no workaround.  Am i missing some special syntax 
feature ?


Alexey.

---
x = 42

class C1:
   y = x  # Works

class C2:
   x = x  # Works

# ---
def f1(a):
   class D:
   b = a  # Works
   return D

def f2(a):
   class D:
   a = a  # Does not work <
   return D

def f3(a):
   class D:
   nonlocal a
   a = a  # Does not work either <
   return D

# ---
def g1(a):
   def h():
   b = a  # Works
   return b
   return h

def g2(a):
   def h():
   a = a  # Does not work (as expected)
   return a
   return h

def g3(a):
   def h():
   nonlocal a
   a = a  # Works
   return a
   return h

# ---
if __name__ == "__main__":
   assert C1.y == 42
   assert C2.x == 42

   assert f1(13).b == 13

   try:
   f2(13)  # NameError
   except NameError:
   pass
   except Exception as e:
   raise Exception( 'Unexpected exception raised: '
'{}'.format(type(e).__name__) )
   else:
   raise Exception('No exception')

   try:
   f3(13).a  # AttributeError
   except AttributeError:
   pass
   except Exception as e:
   raise Exception( 'Unexpected exception raised: '
'{}'.format(type(e).__name__) )
   else:
   raise Exception('No exception')

   assert g1(13)() == 13

   try:
   g2(13)()  # UnboundLocalError
   except UnboundLocalError:
   pass
   except Exception as e:
   raise Exception( 'Unexpected exception raised: '
'{}'.format(type(e).__name__) )
   else:
   raise Exception('No exception')

   assert g3(13)() == 13

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


Re: seeking deeper (language theory) reason behind Python design choice

2018-05-07 Thread Chris Angelico
On Tue, May 8, 2018 at 6:27 AM,   wrote:
> Hi,
>
> I was wondering (and have asked on StackOverflow [1] in a more
> elaborate way) whether there is a deeper reason to not allow
> assignments in lambda expressions.
>
> I'm not criticising, I'm asking in order to know ;-)
>
> The surface-reason is the distinction between assignments and
> statements, but why it was designed this way (with respect to lambda,
> not in general)?
>
> So far, no satisfying answer has come up, except for maybe to avoid a
> programmer accidentally typing `=` instead of `==`, which I find a bit
> unsatisfying as the only reason.

What exactly would be the scope of the assigned name? Let's say we
have a fairly typical use of a lambda function:

items.sort(key=lambda item: item.creation_date)

Now let's change that a bit. How would assignment fit into that?

def sort_func(item):
date = parse_date(item.creation_date)
return date.day_of_week, date.year, date.month, date.day
items.sort(key=sort_func)

Makes sense - now we're putting everything made on a Tuesday before
everything made on a Friday (I'm sure that's important to someone,
somewhere). So obviously any assignment should be local to the lambda
function, right?

What about this lambda function?

click_count = 0
b = Button(master, text="Click me", command=lambda: click_count += 1)
b.pack()

Equally obviously, this assignment belongs in the surrounding scope.
It can't be both, though. How should that be resolved?

If you want a way to do assignment as part of an expression, join the
discussions about PEP 572. Have fun; it's probably approaching a
thousand emails so far.

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


seeking deeper (language theory) reason behind Python design choice

2018-05-07 Thread all-lists
Hi,

I was wondering (and have asked on StackOverflow [1] in a more
elaborate way) whether there is a deeper reason to not allow
assignments in lambda expressions.

I'm not criticising, I'm asking in order to know ;-)

The surface-reason is the distinction between assignments and
statements, but why it was designed this way (with respect to lambda,
not in general)?

So far, no satisfying answer has come up, except for maybe to avoid a
programmer accidentally typing `=` instead of `==`, which I find a bit
unsatisfying as the only reason.

There's a bounty on the StackOverflow question.

Thanks for reading!
Stefan


[1] 
https://stackoverflow.com/questions/50090868/why-are-assignments-not-allowed-in-pythons-lambda-expressions


--
http://stefan-klinger.de  o/X
Send plain text messages only, not exceeding 32kB./\/
\
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use python to log to a remote supercomputer and transfer files

2018-05-07 Thread Irving Duran
You can also explore this package -> https://github.com/paramiko/paramiko
in order to be able to download or upload the files.

Thank You,

Irving Duran


On Mon, May 7, 2018 at 3:34 PM MRAB  wrote:

> On 2018-05-07 13:29, ruiyan wrote:
> > Hello everyone,
> >
> >
> > I need to conduct massive simulation computations using a software
> called 'lammps' on a remote supercomputer whose operating system is Linux
> every day. It's extremely annoying to log to the remote supercomputer,
> upload files to and download files from the supercomputer using WinSCP and
> Putty on my windows desktop computer. I want to know whether it is possible
> to write some scripts and let python do these things for me, i.e., I want
> to log to the remote supercomputer automatically, upload and download files
> with a simple hit in python (of course with the files specified). Is this
> possible? If it is possible, which packages do I need?
> >
> >
> > Thanks and best wishes,
> >
> There are some examples about scripting in WinSCP here:
>
> https://winscp.net/eng/docs/scripting
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use python to log to a remote supercomputer and transfer files

2018-05-07 Thread MRAB

On 2018-05-07 13:29, ruiyan wrote:

Hello everyone,


I need to conduct massive simulation computations using a software called 
'lammps' on a remote supercomputer whose operating system is Linux every day. 
It's extremely annoying to log to the remote supercomputer,  upload files to 
and download files from the supercomputer using WinSCP and Putty on my windows 
desktop computer. I want to know whether it is possible to write some scripts 
and let python do these things for me, i.e., I want to log to the remote 
supercomputer automatically, upload and download files with a simple hit in 
python (of course with the files specified). Is this possible? If it is 
possible, which packages do I need?


Thanks and best wishes,


There are some examples about scripting in WinSCP here:

https://winscp.net/eng/docs/scripting
--
https://mail.python.org/mailman/listinfo/python-list


Tracebacks for exceptions in interactively entered code.

2018-05-07 Thread Terry Reedy

I intend to improve the IDLE doc section on IDLE-console differences.

The following is from standard interactive mode (PSF CPython 3.7.0a4) on 
Windows (Win 10, Command Prompt)


>>> def f():
... return 1/0
...
>>> f()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in f
ZeroDivisionError: division by zero

Each statement is given the same pseudofile name, "", lines are 
numbered within each statement, and the code line is not printed.  As 
far as I remember, this has been the same on Windows since forever, 
though only current versions are relevant to current docs.


Is the above also the same on other systems (linux, Mac)?  I would like 
to know before I say so ;-).


By comparison, IDLE prints

>>> def f():
return 1/0

>>> f()
Traceback (most recent call last):
  File "", line 1, in 
f()
  File "", line 2, in f
return 1/0
ZeroDivisionError: division by zero

Each statememt has a different pseudofile name (pyshell is the name 
IDLE's shell module) and the code lines are displayed just as when 
running from a real file.


--
Terry Jan Reedy

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


Re: Tk covering the entire screen

2018-05-07 Thread Skip Montanaro
On Sun, May 6, 2018 at 6:47 PM Skip Montanaro 
wrote:

> > Try to upgrade to 2.7.15. It should be shipped with Tk 8.6.
>
> Thanks. I'm using an internal (to work) Anaconda distro at work. Hopefully
> it will update soon.
>

​I got everything up-to-date, but still the cover window only covers two of
my three screens when run on Windows. The only thing I can think of which
might be a problem... When I bring up the Screen Resolution control panel,
my screens are numbered 3, 1, 2 left-to-right. Screens 1 and 2 are covered,
not three. If I change the screen order to 1, 2, 3 in the control panel,
The cover window does cover all three screens, but to move the pointer to
screen one, I have to move off the right of screen 3.

Gotta be a Windows thing. I'll call my help desk.

*sigh* I will never figure out Windows.

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


Re: www.python.org down

2018-05-07 Thread Chris Angelico
On Sun, May 6, 2018 at 9:22 PM, Gilmeh Serda
 wrote:
> On Mon, 30 Apr 2018 10:38:54 -0700, Jorge Gimeno wrote:
>
>> Not sure who to report to, but the site comes back with a 503. Anyone
>> know where I can direct this to?
>
> Why would you report it? Give it at least a day before you're going
> berserk with "reports"! If there's a serious problem, they will see to it
> that a replacement site is launched that will give info on what happened.
> Sit back and stay calm!
>
> Trust me, there is nothing more annoying than having to wade through a
> crapload of "error reports" early in the morning. And especially from
> those morons who end their reports with "What's wrong?" Gee, are you
> coming over to fix things?
>
> I wish I had a penny for every such "report" we receive to our external
> support box, I'd be rich today.
>

So you'd rather the site just stay down until the right person happens
to notice it?

Nice to know that your attitude towards your web site's users is that
they are "morons", and even more indicative that you consider that
people should let the site be down for a minimum of 86,400 seconds
before it's considered serious enough to actually report.

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


use python to log to a remote supercomputer and transfer files

2018-05-07 Thread ruiyan
Hello everyone, 


I need to conduct massive simulation computations using a software called 
'lammps' on a remote supercomputer whose operating system is Linux every day. 
It's extremely annoying to log to the remote supercomputer,  upload files to 
and download files from the supercomputer using WinSCP and Putty on my windows 
desktop computer. I want to know whether it is possible to write some scripts 
and let python do these things for me, i.e., I want to log to the remote 
supercomputer automatically, upload and download files with a simple hit in 
python (of course with the files specified). Is this possible? If it is 
possible, which packages do I need? 


Thanks and best wishes,


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


Re: Module, Package

2018-05-07 Thread Chris Angelico
On Tue, May 8, 2018 at 2:53 AM, Sharan Basappa  wrote:
> I am a bit confused between module and package in Python.
> Does a module contain package or vice versa?
> When we import something in Python, do we import a module or a package?

You import a module.

A package is one particular form of module, which is built out of
other modules (usually a directory full of .py files). There are a
number of different sorts of modules; regardless, you 'import X' and
get module X.

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


Re: Module, Package

2018-05-07 Thread MRAB

On 2018-05-07 17:53, Sharan Basappa wrote:

I am a bit confused between module and package in Python.
Does a module contain package or vice versa?
When we import something in Python, do we import a module or a package?


A module is a file. A package is a collection of one or more modules.
--
https://mail.python.org/mailman/listinfo/python-list


Module, Package

2018-05-07 Thread Sharan Basappa
I am a bit confused between module and package in Python.
Does a module contain package or vice versa?
When we import something in Python, do we import a module or a package?

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


Re: itemgetter with default arguments

2018-05-07 Thread Peter Otten
Antoon Pardon wrote:

> On 05-05-18 09:33, Peter Otten wrote:
>> I think you have established that there is no straight-forward way to
>> write this as a lambda. But is adding a default to itemgetter the right
>> conclusion?
>>
>> If there were an exception-catching decorator you could write
>>
>> f = catch(IndexError, "spam")(itemgetter(2))
> 
> I think your catch function would be a usefull addition, but I don't see
> it solving this problem once we use itemgetter te get multiple entries.

Good catch()

;)

The obvious way, expressing the n-tuple case in terms of the solution for 
scalars

>>> f = lambda items: tuple(catch(IndexError, "spam")(itemgetter(i))(items) 
for i in (2, 1, 5))
>>> >>> f("abc")
('c', 'b', 'spam')

is a bit too complex to inline -- and also inefficient. You'd be tempted to 
factor out the repetetive parts

>>> f = lambda items, gets=[catch(IndexError, "spam")(itemgetter(i)) for i 
in (2, 1, 5)]: tuple(get(items) for get in gets)
>>> f("abc")
('c', 'b', 'spam')

and thus make it even less readable.

That said -- grepping my code I'm a bit surprised to find only

17 itemgetter(0)
 9 itemgetter(1)
 1 itemgetter(1, 0)
 1 itemgetter(*indices)

Checking /usr/lib/python3/dist-packages it looks like the situation is 
similar. I conclude that the most useful addition to the operator module 
would be

first = itemgetter(0)
second = itemgetter(1)


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


Re: Weird side effect of default parameter

2018-05-07 Thread Robert Latest via Python-list
Steven D'Aprano wrote:
> Python function default values use *early binding*: the default parameter 
> is evaluated, ONCE, when the function is defined, and that value is used 
> each time it is needed.

Thanks, "early binding" was the clue I was missing.

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


EuroPython 2018: Call for Proposals (CFP) is open

2018-05-07 Thread M.-A. Lemburg
We’re looking for proposals on every aspect of Python: programming
from novice to advanced levels, applications and frameworks, or how
you have been involved in introducing Python into your
organization. EuroPython is a community conference and we are eager to
hear about your experience.


   * https://ep2018.europython.eu/en/call-for-proposals/ *


Please also forward this Call for Proposals to anyone that you feel
may be interested.


Important Notice: New Conference Layout
---

Please note that the conference layout has changed compared to
previous years, the main conference (talks) is now only three days:

* Monday and Tuesday:
trainings, workshops and Beginners’ Day only
* Wednesday, Thursday, Friday:
talks, panels, posters, helpdesks, open sessions, etc.
(no trainings!)


Submit your proposal


   * https://ep2018.europython.eu/en/call-for-proposals/ *

Submissions will be open until Sunday, May 20.

Given the compact timing this year, one should not bet on an
extension, please submit your proposals as early as possible - also to
reduce work load of the reviewers. Thank you.

Presenting at EuroPython


We will accept a broad range of presentations, from reports on
academic and commercial projects to tutorials and case studies. As
long as the presentation is interesting and potentially useful to the
Python community, it will be considered for inclusion in the program.

Can you show something new and useful? Can you show the attendees how
to: use a module? Explore a Python language feature? Package an
application? If so, please consider submitting a talk.

Submission types


* Regular Talk / approx. 110 slots
* Trainings / 12 slots.
* Panels
* Interactive
* Posters / 15 slots
* Helpdesk / 6 slots

Tracks
--

You may suggest your submission for a track. Tracks are groups of
talks, covering the same domain (e.g. Django), all in the same room in
a row. You may choose one of these specialized domains / tracks:

* Business Track (running a business, being a freelancer)
* DevOps
* Django Track
* Educational Track
* General Python
* Hardware/IoT Track
* PyData Track
* Science Track
* Web Track

PyData EuroPython 2018
--

As usual, there will be a PyData track at this year’s
conference.

The PyData track is run in cooperation with NumFocus and
the PyData Edinburgh meetup.

Discounts for Content Contributors
--

Since EuroPython is a not-for-profit community conference, it is not
possible to pay out rewards for talks or trainings.

For talks, posters, help desk and organizing a panels or interactive
sessions we will give out a 25% discount coupon valid for one
conference ticket.

Trainers will receive a 100% discount coupon for both a conference
ticket and a training pass to compensate for the longer preparation
time.

More details


Since there's a lot more detail to how the CFP works, please check the
CFP page for additional information:

   * https://ep2018.europython.eu/en/call-for-proposals/ *


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


PS: Please forward or retweet to help us reach all interested parties:
https://twitter.com/europython/status/993418719756996608
Thanks.

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


Re: itemgetter with default arguments

2018-05-07 Thread Antoon Pardon
On 05-05-18 09:33, Peter Otten wrote:
> I think you have established that there is no straight-forward way to write 
> this as a lambda. But is adding a default to itemgetter the right 
> conclusion?
>
> If there were an exception-catching decorator you could write
>
> f = catch(IndexError, "spam")(itemgetter(2))

I think your catch function would be a usefull addition, but I don't see
it solving this problem once we use itemgetter te get multiple entries.

-- 
Antoon.

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