Single format descriptor for list

2016-01-20 Thread Paul Appleby
In BASH, I can have a single format descriptor for a list:

$ a='4 5 6 7'
$ printf "%sth\n" $a
4th
5th
6th
7th

Is this not possible in Python? Using "join" rather than "format" still 
doesn't quite do the job:

>>> a = range(4, 8)
>>> print ('th\n'.join(map(str,a)))
4th
5th
6th
7

Is there an elegant way to print-format an arbitrary length list?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Single format descriptor for list

2016-01-20 Thread Frank Millman
"Paul Appleby"  wrote in message 
news:pan.2016.01.20.09.35.09@nowhere.invalid...


In BASH, I can have a single format descriptor for a list:

$ a='4 5 6 7'
$ printf "%sth\n" $a
4th
5th
6th
7th

Is this not possible in Python? Using "join" rather than "format" still 
doesn't quite do the job:


>>> a = range(4, 8)
>>> print ('th\n'.join(map(str,a)))
4th
5th
6th
7

Is there an elegant way to print-format an arbitrary length list?



How about this -


a = range(4, 8)
print('\n'.join(['{}th'.format(x) for x in a]))

4th
5th
6th
7th




Frank Millman


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


Re: Single format descriptor for list

2016-01-20 Thread Ben Finney
Paul Appleby  writes:

> In BASH, I can have a single format descriptor for a list:
> […]
> Is this not possible in Python?

Not as such; you'll need to treat items differently from sequences of
items.

> Using "join" rather than "format" still doesn't quite do the job:

Right, ‘str.join’ is meant for making a new string by joining
substrings.

What you want is to take each item and *append* some text. You can do
that by constructing a sequence dynamically::

>>> values = range(4, 8)
>>> print("\n".join(
... "{:d}th".format(item) for item in values))
4th
5th
6th
7th

> Is there an elegant way to print-format an arbitrary length list?

In general, if you can figure out an operation you'd like to perform on
each item of a sequence, you may try a generator expression to express
the transformed sequence.

In the above example:

* Express the transformation of the sequence: format each number with
  "{:d}th". This can be done with a generator expression, producing an
  iterable.

* Figure out what to do to the transformed sequence: join them all
  together with "\n" between each item. This can be done by passing the
  transformed iterable as the argument to ‘str.join’.

The built-in collection types – dict, list, set, generator, etc. – are
very powerful in Python because of the built-in syntax for expressing
and interrogating and consuming them. Learning to use them is an
important tool in avoiding more complex and error-prone code.

-- 
 \ “[F]reedom of speech does not entail freedom to have your ideas |
  `\accepted by governments and incorporated into law and policy.” |
_o__)   —Russell Blackford, 2010-03-06 |
Ben Finney

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


Re: Single format descriptor for list

2016-01-20 Thread Chris Angelico
On Wed, Jan 20, 2016 at 8:35 PM, Paul Appleby  wrote:
> In BASH, I can have a single format descriptor for a list:
>
> $ a='4 5 6 7'
> $ printf "%sth\n" $a
> 4th
> 5th
> 6th
> 7th
>
> Is this not possible in Python? Using "join" rather than "format" still
> doesn't quite do the job:
>
 a = range(4, 8)
 print ('th\n'.join(map(str,a)))
> 4th
> 5th
> 6th
> 7
>
> Is there an elegant way to print-format an arbitrary length list?

Python's string formatting is fairly rich, but not quite that rich.
I'd probably just loop over the range and print them separately:

>>> a = range(4, 8)
>>> for n in a:
... print("%sth" % n)
...
4th
5th
6th
7th

Maybe Python could grow a %{ ... %} marker like Pike's?

> array a = enumerate(4,1,4);
> write("%{%dth\n%}", a);
4th
5th
6th
7th

The semantics are simply recursive - the printf string inside the
markers is evaluated once for each element of the provided sequence
(iterable), and the results concatenated.

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


Re: Single format descriptor for list

2016-01-20 Thread Oscar Benjamin
On 20 January 2016 at 09:35, Paul Appleby  wrote:
> In BASH, I can have a single format descriptor for a list:
>
> $ a='4 5 6 7'
> $ printf "%sth\n" $a
> 4th
> 5th
> 6th
> 7th
>
> Is this not possible in Python? Using "join" rather than "format" still
> doesn't quite do the job:
>
 a = range(4, 8)
 print ('th\n'.join(map(str,a)))
> 4th
> 5th
> 6th
> 7
>
> Is there an elegant way to print-format an arbitrary length list?

There are many ways. Here's a couple:

>>> print(('%sth\n' * len(a)) % tuple(a))
4th
5th
6th
7th

>>> print(('{}th\n' * len(a)).format(*a))
4th
5th
6th
7th

If you particularly like using map then:

>>> print(''.join(map('%sth\n'.__mod__, a)))
4th
5th
6th
7th

>>> print(''.join(map('{}th\n'.format, a)))
4th
5th
6th
7th

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


Re: Single format descriptor for list

2016-01-20 Thread Jussi Piitulainen
"Frank Millman" writes:

> "Paul Appleby"  wrote in message
> news:pan.2016.01.20.09.35.09@nowhere.invalid...
>>
>> In BASH, I can have a single format descriptor for a list:
>>
>> $ a='4 5 6 7'
>> $ printf "%sth\n" $a
>> 4th
>> 5th
>> 6th
>> 7th
>>
>> Is this not possible in Python? Using "join" rather than "format"
>> still doesn't quite do the job:
>>
>> >>> a = range(4, 8)
>> >>> print ('th\n'.join(map(str,a)))
>> 4th
>> 5th
>> 6th
>> 7
>>
>> Is there an elegant way to print-format an arbitrary length list?
>>
>
> How about this -
>
 a = range(4, 8)
 print('\n'.join(['{}th'.format(x) for x in a]))
> 4th
> 5th
> 6th
> 7th


Or this:

>>> print(*map('{}th'.format, range(8)), sep = '\n')
0th
1th
2th
3th
4th
5th
6th
7th

But a separate named function to format an individual number seems like
a good idea, because 1st, 2nd, and 3rd.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Single format descriptor for list

2016-01-20 Thread Mark Lawrence

On 20/01/2016 09:35, Paul Appleby wrote:

In BASH, I can have a single format descriptor for a list:

$ a='4 5 6 7'
$ printf "%sth\n" $a
4th
5th
6th
7th

Is this not possible in Python? Using "join" rather than "format" still
doesn't quite do the job:


a = range(4, 8)
print ('th\n'.join(map(str,a)))

4th
5th
6th
7

Is there an elegant way to print-format an arbitrary length list?



There's a useful recipe here 
http://code.activestate.com/recipes/577845-format_iter-easy-formatting-of-arbitrary-iterables 
hence.


>>> a=range(4,8)
>>> from myutils import format_iter
>>> print(format_iter(a, fmt='{}th', sep='\n'))
4th
5th
6th
7th

--
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


Back links

2016-01-20 Thread Holly Rennels
There are back links here: 
https://mail.python.org/pipermail/python-list/2010-April/574035.html and here: 
https://mail.python.org/pipermail/python-list/2010-April/574036.html 
referencing one of our sites: countrysidecabinetry.com. Please remove this link.

Thank you

Holly Rennels | Webmaster & Technical Writer
324 S. Chestnut St. Arcola, IL 61910
p.888.297.4555 | f. 217.268.5105
[https://www.countrysideamishfurniture.com/media/uploads/signature_logo.png]
Facebook | 
Twitter | 
Pinterest | 
Houzz

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


libre office

2016-01-20 Thread jim-pc
How do I get data from libre office using python?

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


Re: libre office

2016-01-20 Thread Michiel Overtoom

> On 2016-01-20, at 00:01, jim-pc  wrote:
> 
> How do I get data from libre office using python?

Could you be a little more specific? What data? From which part of OpenOffice?

OpenOffice files are actually ZIP files with XML documents in them, but there 
are other ways to interface with OpenOffice.

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


Re: Single format descriptor for list

2016-01-20 Thread Grobu

On 20/01/16 10:35, Paul Appleby wrote:

In BASH, I can have a single format descriptor for a list:

$ a='4 5 6 7'
$ printf "%sth\n" $a
4th
5th
6th
7th

Is this not possible in Python? Using "join" rather than "format" still
doesn't quite do the job:


a = range(4, 8)
print ('th\n'.join(map(str,a)))

4th
5th
6th
7

Is there an elegant way to print-format an arbitrary length list?



In Python 2.7 :

# 
a = '4 5 6 7'
for item in a.split():
print '%sth' % item
# 

or

# 
a = '4 5 6 7'.split()
print ('{}th\n' * len(a)).format(*a),
# 

or

# 
a = '4 5 6 7'
print ''.join( map( '{}th\n'.format, a.split() ) ),
# 

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


RE: libre office

2016-01-20 Thread Albert-Jan Roskam


> From: ji...@frontier.com
> To: python-list@python.org
> Subject: libre office
> Date: Tue, 19 Jan 2016 17:01:40 -0600
> 
> How do I get data from libre office using python?

Does this help?http://www.openoffice.org/udk/python/python-bridge.html  
  
-- 
https://mail.python.org/mailman/listinfo/python-list


[no subject]

2016-01-20 Thread John 111


Sent from Windows Mail
  I can’t use python. I just download it on my windows but when I 
open it they show me three options only change,repair & uninstall. I am looking 
forward for the solution from you.

  Hope to hear from you soon!!!



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


Re:

2016-01-20 Thread Igor Korot
Hi, John,

On Wed, Jan 20, 2016 at 11:29 AM, John 111  wrote:
>
>
> Sent from Windows Mail
>   I can’t use python. I just download it on my windows but when I 
> open it they show me three options only change,repair & uninstall. I am 
> looking forward for the solution from you.

Did you already run it?
If you did then it is already installed and all you need to do is to
open the command prompt window and type "python" (without
the quotes).

Thank you.

>
>   Hope to hear from you soon!!!
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:

2016-01-20 Thread Joel Goldstick
On Wed, Jan 20, 2016 at 11:29 AM, John 111  wrote:

>
>
> Sent from Windows Mail
>   I can’t use python. I just download it on my windows but
> when I open it they show me three options only change,repair & uninstall. I
> am looking forward for the solution from you.
>
>   Hope to hear from you soon!!!
>
> This is a common question.  Search the list and you will probably find an
answer.  First, many people try to use 3.5 on xp and that won't work.
Provide your OS, version and the method you used to download python.  Which
version of python

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



-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


paramiko transport and invoke_shell

2016-01-20 Thread greg . szewski
Hi,
I've found below code which almost suits my needs but I need to interact via 
shell so can do stuff like sudo su - user then when sudo asks for password I 
need to send password and working as user run next commands . I'm pretty sure 
invoke_shell method is the solution but my programing skills are realy low . So 
maybe You will help def method executeShell method for below code .


import paramiko as ssh

class SSHTool():
def __init__(self, host, user, auth,
via=None, via_user=None, via_auth=None):
if via:
t0 = ssh.Transport(via)
t0.start_client()
t0.auth_password(via_user, via_auth)
# setup forwarding from 127.0.0.1: to |host|
channel = t0.open_channel('direct-tcpip', host, ('127.0.0.1', 0))
self.transport = ssh.Transport(channel)
else:
self.transport = ssh.Transport(host)
self.transport.start_client()
self.transport.auth_password(user, auth)

def run(self, cmd):
ch = self.transport.open_session()
ch.set_combine_stderr(True)
ch.exec_command(cmd)
retcode = ch.recv_exit_status()
buf = ''
while ch.recv_ready():
buf += ch.recv(1024)
return (buf, retcode)

def run_in_shell()
...
...

# The example below is equivalent to
# $ ssh 10.10.10.10 ssh 192.168.1.1 uname -a
# The code above works as if these 2 commands were executed:
# $ ssh -L :192.168.1.1:22 10.10.10.10
# $ ssh 127.0.0.1: uname -a
host = ('192.168.1.1', 22)
via_host = ('10.10.10.10', 22)

ssht = SSHTool(host, 'user1', 'pass1',
via=via_host, via_user='user2', via_auth='pass2')

print ssht.run('uname -a')
print ssht.run_in_shell('sudo su - user')
ssht.run_in_shell('password_for_above')
print ssht.run_in_shell('id')
# above id should return user

Regards
Greg



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


Recurring Prompt

2016-01-20 Thread Mansi
Hello,

I just installed Python 3.5.1 but anytime I use Pycharm, a prompt of whether I 
want to modify, repair or uninstall Python keeps on coming up. Even while I'm 
in the midst of typing a program. Please advise. 

Sincerely,
Mansi
-- 
https://mail.python.org/mailman/listinfo/python-list


New user group: Rochester, MN, USA

2016-01-20 Thread Jonathan Hartley

http://www.meetup.com/PyRochesterMN

First meeting planned for Thu 28th January 2016

--
Jonathan Hartley
tart...@tartley.com
+1 507-513-1101
--
https://mail.python.org/mailman/listinfo/python-list


installing

2016-01-20 Thread navneet bhatele
Whenever i try to install   python-3.5.1-amd64  a problem occur , picture
of which has attached. Sometimes "0*80070002 file  error" also occur.

WHAT SHOULD I DO
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: libre office

2016-01-20 Thread Karim



On 20/01/2016 00:01, jim-pc wrote:

How do I get data from libre office using python?



Hello,

The function below search and get text between 2 delimiters inside a 
libre office swriter document.
It is given as an example. You still have to open a document object in 
Swriter server.(In the Libre office UNO website you will find simple 
code to do that step.)


def get_text_inside_delimiters(component=None, delimiter1=None, 
delimiter2=None):

""" Get text between 2 string delimiters."""

# Creation of 2 descriptors from a document w/ search capabilities.
open_search  = component.createSearchDescriptor()
close_search = component.createSearchDescriptor()

# Specify the delimiter texts to find.
open_search.SearchString  = delimiter1
close_search.SearchString = delimiter2

# Find and open the first delimiter object.
open_found = component.findFirst(open_search)
# Unselect the 1rst delimiter from the range selection
# done by findFirst() to not have in the search result.
open_found.goRight(0, False)

# Search for the 2nd delimiter the closest from first delimiter.
close_found = component.findNext(open_found.End, close_search)
# Filter the 2nd delimiter from the range selection
# done by findNext() to not have in the search result.
close_found.goLeft(len(close_found.getString()), False)

# Cursor selection of the target string.
open_found.gotoRange(close_found, True)

# Return target string whithin the cursor selection.
return open_found.getString().strip()

Hope this help.
Karim

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


Re: installing

2016-01-20 Thread Mark Lawrence

On 20/01/2016 20:41, navneet bhatele wrote:

Whenever i try to install   python-3.5.1-amd64  a problem occur , picture
of which has attached. Sometimes "0*80070002 file  error" also occur.

WHAT SHOULD I DO



This has been asked and answered repeatedly over the last few months so 
search the archives and you'll get your answer.


--
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: Recurring Prompt

2016-01-20 Thread Mark Lawrence

On 20/01/2016 19:30, Mansi wrote:

Hello,

I just installed Python 3.5.1 but anytime I use Pycharm, a prompt of whether I 
want to modify, repair or uninstall Python keeps on coming up. Even while I'm 
in the midst of typing a program. Please advise.

Sincerely,
Mansi



This has been asked and answered repeatedly over the last few months so 
search the archives and you'll get your answer.


--
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: installing

2016-01-20 Thread Terry Reedy

On 1/20/2016 3:41 PM, navneet bhatele wrote:

Whenever i try to install   python-3.5.1-amd64  a problem occur , picture
of which has attached.


This is a text only, no attachments allowed mailing list.  So picture 
was discarded.



--
Terry Jan Reedy

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


How to fix my imports/file structure

2016-01-20 Thread Travis Griggs
I wrote a simple set of python3 files for emulating a small set of mongodb 
features on a 32 bit platform. I fired up PyCharm and put together a directory 
that looked like:

minu/
client.py
database.py
collection.py
test_client.py
test_database.py
test_client.py

My imports are simple. For example, client.py has the following at the top:

from collection import Collection

Basically, client has a Client class, collection has a Collection class, and 
database has a Database class. Not too tough.

As long as I cd into the minu directory, I can fire up a python3 interpreter 
and do things like:

>>> from client import Client
>>> c = Client(pathstring='something’)

And everything just works. I can run the test_files as well, which use the same 
sorts of imports.

I'd like to modularize this, so I can use it another project by just dropping 
the minu directory alongside my application's .py files and just have 
everything work. E.g.

SomeDirectory/
application.py
minu/
…

and application.py does something like:

from minu.client import Client

When I try this though, and am running python3 from another directory, the 
local imports don't work. I placed an empty init.py in the minu directory. That 
made it so I could import minu. But the others broke. I tried using things like 

from .collection import Collection #added the dot

but then I can't run things in the original directory anymore, like I could 
before. What is the simple/right way to do this?

I have looked around a bit with Dr. Google, but none of the examples really 
clarify this well (at least, for me), feel free to point out the one I missed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to fix my imports/file structure

2016-01-20 Thread Steven D'Aprano
On Thursday 21 January 2016 12:26, Travis Griggs wrote:

> I wrote a simple set of python3 files for emulating a small set of mongodb
> features on a 32 bit platform. I fired up PyCharm and put together a
> directory that looked like:
> 
> minu/
> client.py
> database.py
> collection.py
> test_client.py
> test_database.py
> test_client.py

This will only work so long as you cd into the minu directory first.

To fix that, you can either:

(1) Add minu to your path. You can put this at the start of your script:

import sys
if "/path/to/minu" not in sys.path:
sys.path.append("/path/to/minu")


(where "/path/to/minu" is the absolute path to the actual directory).

You need this to occur before you start importing from minu.

Or you can adjust the path using an environment variable:

export PYTHONPATH="/path/to/minu"

before you launch Python. (If you're using Linux or Unix, you could put that 
in your .bashrc, or equivalent.)

Or you can create a .pth file that points to your minu directory. 

(I haven't tried this, I might have some of the details wrong.)

In your Python site-packages directory (usually found somewhere like 
/usr/local/lib/python3.4/site-packages/) drop a file called "minu.pth" 
containing a single line of text:

/absolute/path/to/minu

then that path will be automatically added to your python path and you'll be 
able to import any .py file in minu from anywhere.

https://docs.python.org/3/library/site.html



(2) Alternatively, turn minu into a package, rather than a directory of 
unrelated modules.

- Create a file __init__.py and put it in the minu directory.

- Place the minu directory somewhere in your Python path. Or use a .pth 
file, as above.


Now minu is a *package*, and the modules "client.py", "collection.py" etc. 
are assumed to collaborate rather than be a random collection of arbitrary 
modules. From *outside* of minu, you can import submodules of the package:

import minu.collection
from minu.client import Spam

and from submodules *inside* minu, you can either use the same absolute 
imports as above, or you can use relative imports:

# inside minu.client
from .collection import Collection


Google for "relative and absolute imports" for more info.


> My imports are simple. For example, client.py has the following at the
> top:
> 
> from collection import Collection
> 
> Basically, client has a Client class, collection has a Collection class,
> and database has a Database class. Not too tough.

Python isn't Java, you don't have to force each class to live in its own 
file. Sounds like you might simplify the whole job by putting everything in 
a single minu.py file.



> As long as I cd into the minu directory, I can fire up a python3
> interpreter and do things like:
> 
> >>> from client import Client
> >>> c = Client(pathstring='something’)
> 
> And everything just works. I can run the test_files as well, which use the
> same sorts of imports.
> 
> I'd like to modularize this, so I can use it another project by just
> dropping the minu directory alongside my application's .py files and just
> have everything work. E.g.
> 
> SomeDirectory/
> application.py
> minu/
> …
> 
> and application.py does something like:
> 
> from minu.client import Client

Sounds like you want minu to be a package. See (2) above.


> When I try this though, and am running python3 from another directory, the
> local imports don't work. I placed an empty init.py in the minu directory.
> That made it so I could import minu. But the others broke. I tried using
> things like

You still need minu to be somewhere that the main script can see, that is, 
in one of the locations listed in sys.path, but that's not hard to set up. 
If you run:

python3 SomeDirectory/application.py

SomeDirectory will be automatically added to the path and in theory it 
should all Just Work.

If not, start by printing sys.path and see what you have.


> from .collection import Collection #added the dot
> 
> but then I can't run things in the original directory anymore, like I
> could before. What is the simple/right way to do this?

I would say that the right solution is to modify the imports in the minu 
submodules to use package absolute and/or relative import syntax. In theory 
you can probably get it to work by adding sufficient directories to the 
path, but that gets ugly and messy quickly.

Packages were invented to solve your problem, but the submodules do have to 
be written as if they are inside a package, and not as stand alone modules.



-- 
Steve

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


How to use the docstring in this property example

2016-01-20 Thread Robert
Hi,

I read below code snippet on link:
https://docs.python.org/2/library/functions.html#property

--
class C(object):
def __init__(self):
self._x = None

def getx(self):
return self._x

def setx(self, value):
self._x = value

def delx(self):
del self._x

x = property(getx, setx, delx, "I'm the 'x' property.")
If c is an instance of C, c.x will invoke the getter, c.x = value will invoke 
the setter and del c.x the deleter.

If given, doc will be the docstring of the property attribute.


I can use these:
c.x
c.x=42
del c.x

but I don't know how to get the doctring from the property attribute.
Could you show me how to do that?

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


Re: How to fix my imports/file structure

2016-01-20 Thread Terry Reedy

On 1/20/2016 8:26 PM, Travis Griggs wrote:

I wrote a simple set of python3 files for emulating a small set of mongodb 
features on a 32 bit platform. I fired up PyCharm and put together a directory 
that looked like:

minu/
 client.py
 database.py
 collection.py
 test_client.py
 test_database.py
 test_client.py

My imports are simple. For example, client.py has the following at the top:

 from collection import Collection

Basically, client has a Client class, collection has a Collection class, and 
database has a Database class. Not too tough.

As long as I cd into the minu directory, I can fire up a python3 interpreter 
and do things like:

 >>> from client import Client
 >>> c = Client(pathstring='something’)

And everything just works. I can run the test_files as well, which use the same 
sorts of imports.

I'd like to modularize this, so I can use it another project by just dropping 
the minu directory alongside my application's .py files and just have 
everything work. E.g.

 SomeDirectory/
 application.py
 minu/
 …

and application.py does something like:

 from minu.client import Client

When I try this though, and am running python3 from another directory, the 
local imports don't work. I placed an empty init.py in the minu directory. That 
made it so I could import minu. But the others broke. I tried using things like

 from .collection import Collection #added the dot

but then I can't run things in the original directory anymore, like I could 
before. What is the simple/right way to do this?

I have looked around a bit with Dr. Google, but none of the examples really 
clarify this well (at least, for me), feel free to point out the one I missed.


Summary: there are two solutions, one of which I think is better.

Imports of python-coded files are done by searching the directories, 
usually not packages, on sys.path.  Python prepends '' to sys.path, 
standing for the 'directory that contain the startup file'.  In the 
first case, startup is client.py and '' is 'minu', so other modules in 
minu can be imported directly.  In the second case, startup is 
application.py and '' is SomeDirectory, so other modules in 
SomeDirectory can be imported.  There is only one other module, minu. 
The modules within minu must be imported via Minu.


What you want to do is make the two situations identical with respect to 
minu module imports, so the import code will work the same in the two 
scenarios.


1. Make scenario 2 match scenario 1.  In application.py, add 
sys.path.insert(1,path/to/minu).  Then import minu modules directly.


2. Make scenario 1 match scenario 2 in the sense of having the directory 
containing minu be on sys.path.  But be clever.   Suppose minu lives in 
directory Projects.  In your 3.x Lib/site-packages directory, add file 
'Projects.pth' containing path/to/minu (without quotes!).  This makes 
Projects an extension of site-packages, and inserts minu 'virtually' 
into site-packages, so indirect imports for any user.


The negative is having to do this for every 3.x version you want to use 
minu with.  But new versions only appear every 18-24 months, and copying 
the file into a new site-packages is not a big deal.


The positive is that you no longer need to drop minu into SomeDirectory 
but can import its modules into any application module as if minu were 
in site-packages, and as it would (should) be if you were to distribute 
minu to others.  That means that the application is always using the 
latest version of minu without re-dropping.  This also means that you 
can import minu and its module into interactive Python or IDLE's shell, 
without touching sys.path.


--
Terry Jan Reedy


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


Re: How to use the docstring in this property example

2016-01-20 Thread Steven D'Aprano
On Thursday 21 January 2016 15:00, Robert wrote:

> Hi,
> 
> I read below code snippet on link:
> https://docs.python.org/2/library/functions.html#property

Property docstrings are hard to get to. But with the class C you gave, this 
works in the interactive interpreter:

help(C.__dict__['x'])

displays:

I'm the 'x' property.


C.__dict__['x'] will return the property object itself, without running the 
getter or setter, so you can access the dostring:


py> C.__dict__['x']

py> C.__dict__['x'].__doc__
"I'm the 'x' property."



But what happens if you inherit the property from some other class?

py> class D(C): pass
... 
py> class E(D): pass
... 
py> E.__dict__['x']
Traceback (most recent call last):
  File "", line 1, in 
KeyError: 'x'



In Python 3, you can use the inspect module:

py> obj = inspect.getattr_static(E, 'x')
py> inspect.getdoc(obj)
"I'm the 'x' property."



but in Python 2, you may need to walk the class's MRO by hand. Something 
like this:


def getattr_static(obj, name):
if isinstance(obj, type):
for cls in obj.__mro__:
if name in cls.__dict__:
return cls.__dict__[name]


-- 
Steve

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


Installing on linux - missing devel packages

2016-01-20 Thread Frank Millman

Hi all

Fedora 22 comes standard with Python 3.4.2. I want to install 3.5.1.

It is easy enough to download the source and run ./configure;make;make 
altinstall. But then I find that I cannot import gzip because zlib-devel is 
missing. I fix that, then I find that sqlite-devel is missing.


Is there an easy way to find out all the missing components, so that when 
the installation is complete I can be sure I have the entire standard lib?


Thanks

Frank Millman


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


Re: Installing on linux - missing devel packages

2016-01-20 Thread Chris Angelico
On Thu, Jan 21, 2016 at 6:18 PM, Frank Millman  wrote:
> Fedora 22 comes standard with Python 3.4.2. I want to install 3.5.1.
>
> It is easy enough to download the source and run ./configure;make;make
> altinstall. But then I find that I cannot import gzip because zlib-devel is
> missing. I fix that, then I find that sqlite-devel is missing.
>
> Is there an easy way to find out all the missing components, so that when
> the installation is complete I can be sure I have the entire standard lib?

This is a Linux packaging question, more than a Python one. On Debian
systems, the way to do that is "apt-get build-dep python3"; check your
own package manager for an equivalent - it'll probably be called
builddep or similar.

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


Same function but different names with different set of default arguments

2016-01-20 Thread Paulo da Silva
Hi all.

What is the fastest implementation of the following code?

def g(p):
...
return something

def f1(p="p1"):
return g(p)

def f2(p="p2"):
return g(p)

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


Re: Same function but different names with different set of default arguments

2016-01-20 Thread Yann Kaiser
partial treats keyword arguments as default values, though they become
keyword-only as a result :

f1 = functools.partial(g, p="p1")

On Thu, Jan 21, 2016, 08:35 Paulo da Silva 
wrote:

> Hi all.
>
> What is the fastest implementation of the following code?
>
> def g(p):
> ...
> return something
>
> def f1(p="p1"):
> return g(p)
>
> def f2(p="p2"):
> return g(p)
>
> Thanks
> Paulo
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list