Re: python package management confusion

2019-01-15 Thread dieter
dcs3spp via Python-list  writes:
> ...
> So to manage the development of private packages, e.g. wheels, I would have 
> to use my own private repository (something like devpi or a an alternative 
> cloud pypi subscription service) to store each private dependency that I have 
> written.

No, you do not need something like "devpi" (or similar).
Instead, you can set up a "virtualenv" (there is a Python package
which can build "virtualenv"s), and use "setuptool"'s "develop"
"setup" command to "install" links to the package sources you
currently have under development. "develop" will automatically
install external requirements via "pypi".

> ...
> However, if I wanted to take a step further and run a CI build using cloud 
> services(e.g. in a private gitlab.com repository) for a package that uses the 
> private packages, then presumably there is no access to the devpi repository 
> on my local system? So, alternatively when developing private Python packages 
> I either use requirements.txt or pay subscription for a private pypi cloud 
> repository and configure pip, setup.cfg on gitlab.com CI to reference it in 
> config files. When the CI build completes it pushes the package to the 
> private pypi repository. 

I assume that you will be able to build an appropriate "virtualenv"
in a CI build setup.

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


Re: get the terminal's size

2019-01-15 Thread Karen Shaeffer
That will tell you the terminal size at the time Python was started.


If the terminal size has changed while Python was running, those

environment variables will be wrong.  You need to use the TIOCGWINSZ

ioctl call:


http://www.delorie.com/djgpp/doc/libc/libc_495.html


And to detect the size changes (so you know _when_ you need to do the

above), you need to attach a signal handler for the WINCH signal.


Hi,

I'm running a python 3 interpreter on linux. I'm actually ssh'd into the
terminal

on a headless server. And so my terminal is my local laptop terminal
window, with

the python interpreter running on the remote linux box terminal,
communicating

over an ssh connection.


$ python3

Python 3.6.7 (default, Oct 22 2018, 11:32:17)

[GCC 8.2.0] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import shutil

>>> print(f"{shutil.get_terminal_size()}\n")

os.terminal_size(columns=118, lines=63)


>>> print(f"{shutil.get_terminal_size()}\n")

os.terminal_size(columns=133, lines=63)


>>> print(f"{shutil.get_terminal_size()}\n")

os.terminal_size(columns=118, lines=65)


>>> print(f"{shutil.get_terminal_size()}\n")

os.terminal_size(columns=118, lines=63)



With the python interpreter running on the remote terminal, I have resized

the terminal window on my local laptop several times. And each time, the
remote

python interpreter knows about the change, correctly printing the new size.
I

have done nothing with environment variables. I have not used a signal
handler

for the WINCH signal. It just works.


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


Re: sampling from frequency distribution / histogram without replacement

2019-01-15 Thread duncan smith
On 15/01/2019 17:59, Ian Hobson wrote:
> Hi,
> 
> If I understand your problem you can do it in two passes through the
> population.
> 

The thing is that I start with the population histogram and I want to
generate a sample histogram. The population itself is too large to deal
with each population member individually.

> First, however, lets work through taking a sample of 2 from 7 to
> demonstrate the method.
> 
> Take the first element with a probability of 2/7. (Note 1).
> If you took it, you only want 1 more, so the probability drops to 1/6.
> If you didn't take it you want 2 from 6, so probability goes to 2/6.
> Take the next in the population with probability 1/6 or 2/6 as appropriate.
> Continue in similar manner until the probability
> drops to 0 (when you have your whole sample). When the
> denominator drops to zero the population is expired.
> 

Yes, based on the chain rule.

> Your first pass has to categorise the population and create your
> histogram, (index N) of frequencies Y(N).
> 
> Then divide up the sample size you wish to take into the histogram,
> giving array X(N) of sample sizes. X(N) need not be integer.
> 
> Then pass through the population again, for each entry:
>    Compute the N it falls in the histogram.
>    Take this entry as a sample with a probability of X(N)/Y(N).  Note 2.
>    If the element was taken, decrement X(N).
>    Decrement Y(N).
>    step to next element.
> 

Ah, I'm not quota sampling. I want a simple random sample without
replacement. I just happen to have the data in the form of categories
and frequencies, and that's the form of output that I want.

> Note 1 - In most languages you can generate a pseudo-random number
> with a uniform distribution from 0 to Y(N)-1. Take the element if it is
> in range 0 to floor(X(N))-1.
> 
> Note 2 - X(N) need not be integer, but you can't actually take a sample
> of 6.5 out of 1000. You will either run out of population having taken
> 6, or, if you take 7, the probability will go negative, and no more
> should be taken (treat as zero). The number taken in slot N will be
> floor(X(N)) or ceiling(X(N)). The average over many tries will however
> be X(N).

> Sorry I did not come back to you sooner. It took a while to drag the
> method out of my memory from some 35 years ago when I was working on an
> audit package. 

Well I'd already forgotten that I'd coded up something for srs without
replacement only a few years ago. In fact I coded up a few algorithms
(that I can't take credit for) that allowed weighted sampling with
replacement, and at least one that didn't require a priori knowledge of
the population size (a single pass algorithm). The problem is that they
also (mostly) require scanning the whole population.

That was where I learned two things you may be interested
> in.

> 1) Auditors significantly under sample. Our Auditors actually took
> samples that were between 10% and 25% of what was necessary to support
> their claims.
> 

It's not just auditors :-(. The journals are full of claims based on
positive results from low powered tests or from "null fields". i.e. A
very high proportion are likely to be false positives (like 99% when it
comes to foodstuffs and the risks of various diseases). A while ago a
mate of mine (Prof. of statistics in Oz) told me about a student who
engineered a statistically significant result by copying and pasting her
data to double her sample size. That's no worse than some of the stuff
I've come across in the (usually medical) journals.

> 2) Very very few standard pseudo-random number generators are actually
> any good.
> 
> Regards
> 
> Ian

[snip]

BTW, the approach I'm currently using is also based on the chain rule.
Generate the number of sample units for the first category by sampling
from a (bivariate) hypergeometric. The number of sample units for the
second category (conditional on the number sampled for the first) is
another hypergeometric. Iterate until the full sample is obtained. It
helps to order the categories from largest to smallest. But I think I'll
get better performance by recursive partitioning (when I have the time
to try it). Cheers.

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


Re: get the terminal's size

2019-01-15 Thread Cameron Simpson

On 15Jan2019 13:08, Alex Ternaute  wrote:

I tried : P = Popen(['stty', '-a'], stdout=subprocess.PIPE,
universal_newlines=True) and it runs fine too, so the output seems not
really related to that fd.



But it is! stty(1) fetches the terminal settings from its standard
input, so "fd" is used to supply this. In your Popen test case you
simply don't set the stdin parameter, so it is the Python process'
input. Which is usually what you want.



But I want to be able to ask this
of any terminal file, thus the parameter.


Ah, Ok; smthlike:
cs.tty.ttysize(0)
WinSize(rows=50, columns=100)
anotherTty=open('/dev/pts/3', 'rw')
cs.tty.ttysize(anotherTty)
WinSize(rows=43, columns=199)

It runs :)


Exactly so.

BTW, you're aware of:

 from cs.tty import ttysize
 ...
 ttysize(0)

I presume, and the above is just your testing?

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: help with python difference between number

2019-01-15 Thread MRAB

On 2019-01-15 14:07, achyuta2...@gmail.com wrote:


M <01/14/2019 08:07:01> Count:0
Total:50
Free: 20
A
B
 M <01/14/2019 08:07:04> Count:1
Total:5
Free:10
A
B
M <01/14/2019 08:07:07> Count:2
Total:5
Free:3
A
B


I am trying to make a output like where it prints the free and then the 
difference between the current free and previous free
For e.g

M <01/14/2019 08:07:01> Count:0  Free: 20
M <01/14/2019 08:07:04> Count:1  Free: 10  absolute difference between time and 
prev time is -10
M <01/14/2019 08:07:07> Count:2  Free: 3   absolute difference between time and 
prev time is -7


And then later on i need to determine the time when we had the most negative 
free value.


I tried a code like this
Which printed
  with open("summ4.txt") as f:
# get first line/number
nxt = int(next(f))
for n in f:
 print("absolute difference between {} and {} = {}"
   .format(n.rstrip(), nxt, abs(int(nxt) - int(n
 # set nxt equal to the next number
 nxt = int(next(f,0))
a=open('summ1.txt','r').readlines()
b=open('summ3.txt','r').readlines()
 with open('summ.txt','w') as out:
   for i in range(0,365):
print>>out,a[i].rstrip(),b[i]


I hit error as
Traceback (most recent call last):
File "3.py", line 39, 
in 
   .format(n.rstrip(), 
nxt, abs(int(nxt) - int(n
ValueError: 
zero length field name in format

I guess my input file has a tab in the start and not able to get a difference 
rightly.
.
Any pointers on how to achieve the desired result?


You didn't say Which version of Python you're using.

The "print>>" tells me that it's Python 2.

It's complaining about the '{}' in the format string.

Format strings were introduced in Python 2.6 and auto-numbering ('{}' 
allowed instead of '{0}') was introduced in Python 2.7.


As it's complaining about a missing field name in '{}', it must be 
Python 2.6, which is ancient!


And Python 2.7 reaches its end of life soon.

You should switch to Python 3 unless you have a very good reason for 
staying on Python 2, and, if you must use Python 2, use Python 2.7.

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


Re: sampling from frequency distribution / histogram without replacement

2019-01-15 Thread Ian Hobson

Hi,

If I understand your problem you can do it in two passes through the 
population.


First, however, lets work through taking a sample of 2 from 7 to 
demonstrate the method.


Take the first element with a probability of 2/7. (Note 1).
If you took it, you only want 1 more, so the probability drops to 1/6.
If you didn't take it you want 2 from 6, so probability goes to 2/6.
Take the next in the population with probability 1/6 or 2/6 as appropriate.
Continue in similar manner until the probability
drops to 0 (when you have your whole sample). When the
denominator drops to zero the population is expired.

Your first pass has to categorise the population and create your 
histogram, (index N) of frequencies Y(N).


Then divide up the sample size you wish to take into the histogram,
giving array X(N) of sample sizes. X(N) need not be integer.

Then pass through the population again, for each entry:
   Compute the N it falls in the histogram.
   Take this entry as a sample with a probability of X(N)/Y(N).  Note 2.
   If the element was taken, decrement X(N).
   Decrement Y(N).
   step to next element.

Note 1 - In most languages you can generate a pseudo-random number
with a uniform distribution from 0 to Y(N)-1. Take the element if it is 
in range 0 to floor(X(N))-1.


Note 2 - X(N) need not be integer, but you can't actually take a sample 
of 6.5 out of 1000. You will either run out of population having taken 
6, or, if you take 7, the probability will go negative, and no more 
should be taken (treat as zero). The number taken in slot N will be 
floor(X(N)) or ceiling(X(N)). The average over many tries will however 
be X(N).


Sorry I did not come back to you sooner. It took a while to drag the 
method out of my memory from some 35 years ago when I was working on an 
audit package. That was where I learned two things you may be interested in.


1) Auditors significantly under sample. Our Auditors actually took 
samples that were between 10% and 25% of what was necessary to support 
their claims.


2) Very very few standard pseudo-random number generators are actually 
any good.


Regards

Ian

On 14/01/2019 20:11, duncan smith wrote:

Hello,
   Just checking to see if anyone has attacked this problem before
for cases where the population size is unfeasibly large. i.e. The number
of categories is manageable, but the sum of the frequencies, N,
precludes simple solutions such as creating a list, shuffling it and
using the first n items to populate the sample (frequency distribution /
histogram).

I note that numpy.random.hypergeometric will allow me to generate a
sample when I only have two categories, and that I could probably
implement some kind of iterative / partitioning approach calling this
repeatedly. But before I do I thought I'd ask if anyone has tackled this
before. Can't find much on the web. Cheers.

Duncan



--
Ian Hobson
Tel (+351) 910 418 473
--
https://mail.python.org/mailman/listinfo/python-list


Re: sampling from frequency distribution / histogram without replacement

2019-01-15 Thread duncan smith
On 15/01/2019 02:41, Spencer Graves wrote:
> 
> 
> On 2019-01-14 18:40, duncan smith wrote:
>> On 14/01/2019 22:59, Gregory Ewing wrote:
>>> duncan smith wrote:
 Hello,
    Just checking to see if anyone has attacked this problem before
 for cases where the population size is unfeasibly large.
>>> The fastest way I know of is to create a list of cumulative
>>> frequencies, then generate uniformly distributed numbers and
>>> use a binary search to find where they fall in the list.
>>> That's O(log n) per sample in the size of the list once it's
>>> been set up.
>>>
>> That's the sort of thing I've been thinking about. But once I'd found
>> the relevant category I'd need to reduce its frequency by 1 and
>> correspondingly update the cumulative frequencies. Alternatively, I
>> could add an extra step where I selected a unit from the relevant
>> category with probability equal to the proportion of non-sampled units
>> from the category. I could maybe set up an alias table and do something
>> similar.
>>
>> The other thing I was thinking about was iterating through the
>> categories (ideally from largest frequency to smallest frequency),
>> generating the numbers to be sampled from the current category and the
>> remaining categories (using numpy.random.hypergeometric). With a few
>> large frequencies and lots of small frequencies that could be quite
>> quick (on average). Alternatively I could partition the categories into
>> two sets, generate the number to be sampled from each partition, then
>> partition the partitions etc. binary search style.
>>
>> I suppose I'll try the both the alias table + rejection step and the
>> recursive partitioning approach and see how they turn out. Cheers.
> 
> 
>   R has functions "sample" and "sample.int";  see
> "https://www.rdocumentation.org/packages/base/versions/3.5.2/topics/sample";.
> You can call R from Python,
> "https://sites.google.com/site/aslugsguidetopython/data-analysis/pandas/calling-r-from-python";.
> 
> 
> 
>   These are in the "base" package.  I believe they have been an
> important part of the base R language almost since its inception and
> have been used extensively.  You'd have to work really hard to do
> better, in my judgment.
> 
> 
>       Spencer Graves
> 
> 
> DISCLAIMER:  I'm primarily an R guy and only use Python when I can't
> find a sensible way to do what I want in R.
>>
>> Duncan
> 

Despite being a statistician I'm primarily a Python guy and only use R
when I can't find a sensible way to do what I want in Python :-). The
problem with the R solution is that it doesn't seem to get round the
issue of having an unfeasibly large population size, but a reasonable
number of categories. It turns out I've already coded up a few reservoir
based algorithms for sampling without replacement that work with data
streams. So I can get round the space issues, but it still means
processing each data point rather than generating the sample frequencies
directly.

After much searching all I've been able to find is the approach I
suggested above, iterating through the frequencies. My implementation:


import numpy

def hypgeom_variate(freqs, n):
sample = [0] * len(freqs)
nbad = sum(freqs)
hypergeometric = numpy.random.hypergeometric
for i, ngood in enumerate(freqs):
nbad -= ngood
x = hypergeometric(ngood, nbad, n, 1)[0]
if x:
sample[i] = x
n -= x
if not n:
break
return sample


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


Re: Encounter issues to install Python

2019-01-15 Thread Anthony Flury via Python-list

What error are you getting ?

'Can not install the software' isn't enough information for me to assist 
in detail


In the mean time - things to check :

 * Does your user have permission to install to the directory you are
   trying to install to ?
 * Does the disk have enough disk space to install Python ?
 * have you actually got a 32 bit windows installation - many modern
   PCs are actually 64 bit now.

On 06/01/2019 15:20, Olivier Oussou wrote:

Hi dear Anthony,
I am using Windows systeme. I have download the set up uf python 3.6.4 
(32-bit) and I can not install the software on my computer.
I need your technical assistance to solve this matter and I will be 
glad if you do so.

Best regard!
Olivier
Medical entomologist, Benin



Le samedi 13 octobre 2018 à 19:24:28 UTC+2, Anthony Flury 
 a écrit :



Olivier,

Welcome to the list - before we can help you, we need some more 
information :


  * What Operating system are you using - Windows/Mac/Linux/Raspberry
Pi/Android for something else ?
  * What command or installer did you use to try to install Python.
  * What issues did you have during installation - if any ?
  * What interface are you trying to access, and how are you doing that ?
  * Do you get error messages?

Unless you tell us what the problem is we can't possibly help.

On 08/10/18 20:21, Olivier Oussou via Python-list wrote:

Hi!I downloaded and installed python 3.6.4 (32-bit) on my computer but I have 
problems and can not access the python interface.
I need your technical assistance to solve this matter.

Best regard!

Olivier OUSSOUMedical entomologist, Benin


--
Anthony Flury
*Email* : anthony.fl...@btinternet.com 


*Twitter* : @TonyFlury 

--
Anthony Flury
*Email* : anthony.fl...@btinternet.com 
*Twitter* : @TonyFlury 
--
https://mail.python.org/mailman/listinfo/python-list


Re: 3 random numbers

2019-01-15 Thread Alister via Python-list
On Tue, 15 Jan 2019 06:13:00 -0800, Gengyang Cai wrote:

> I managed to solve the problem and also another problem with different 3
> random numbers. But it wasn't a very good question in the first place, i
> admit 
> 
>
Indeed it is a poorly write exercise & I suspect it has been 
misinterpreted.

unless i am very much mistaken the tutor expects the program to pick the 
3 random numbers each time it is run, not the programmer  

-- 
We've picked COBOL as the language of choice.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python read text file columnwise

2019-01-15 Thread Neil Cerutti
On 2019-01-15, Juris __  wrote:
> Hi!
>
> On 15/01/2019 17:04, Neil Cerutti wrote:
>> On 2019-01-11, shibashib...@gmail.com  wrote:
>>> Hello

 I'm very new in python. I have a file in the format:

 2018-05-31   16:00:0028.90   81.77   4.3
 2018-05-31   20:32:0028.17   84.89   4.1
 2018-06-20   04:09:0027.36   88.01   4.8
 2018-06-20   04:15:0027.31   87.09   4.7
 2018-06-28   04.07:0027.87   84.91   5.0
 2018-06-29   00.42:0032.20   104.61  4.8
>>>
>>> I would like to read this file in python column-wise.
>>>
>>> I tried this way but not working 
>>>event_list = open('seismicity_R023E.txt',"r")
>>>  info_event = read(event_list,'%s %s %f %f %f %f\n');
>> 
>> If it's really tabular data in fixed-width columns you can read
>> it that way with Python.
>> 
>> records = []
>> for line in file:
>>  record = []
>>  i = 0
>>  for width in (30, 8, 7, 5): # approximations
>>  item = line[i:i+width]
>>  record.append(item)
>>  i += width
>>  records.append(record)
>> 
>> This leaves them all strings, which in my experience is more
>> convenient in practice. You can convert as you go if you
>> want,though it won't look nice and simple any longer.
>>
>
> Perhaps even better approach is to use csv module from standard library:
>
> import csv
>
> csv_reader = csv.reader(file, dialect="excel-tab")
> for row in csv_reader:
>  # do something with record data which is conveniently parsed to list
>  print(row)
>
> ['2018-05-31', '16:00:00', '28.90', '81.77', '4.3']
> ...
> ['2018-06-29', '00.42:00', '32.20', '104.61', '4.8']

Yes, if applicable it is awesome!

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


Re: Python read text file columnwise

2019-01-15 Thread Juris __
Hi!

On 15/01/2019 17:04, Neil Cerutti wrote:
> On 2019-01-11, shibashib...@gmail.com  wrote:
>> Hello
>>>
>>> I'm very new in python. I have a file in the format:
>>>
>>> 2018-05-31   16:00:0028.90   81.77   4.3
>>> 2018-05-31   20:32:0028.17   84.89   4.1
>>> 2018-06-20   04:09:0027.36   88.01   4.8
>>> 2018-06-20   04:15:0027.31   87.09   4.7
>>> 2018-06-28   04.07:0027.87   84.91   5.0
>>> 2018-06-29   00.42:0032.20   104.61  4.8
>>
>> I would like to read this file in python column-wise.
>>
>> I tried this way but not working 
>>event_list = open('seismicity_R023E.txt',"r")
>>  info_event = read(event_list,'%s %s %f %f %f %f\n');
> 
> If it's really tabular data in fixed-width columns you can read
> it that way with Python.
> 
> records = []
> for line in file:
>  record = []
>  i = 0
>  for width in (30, 8, 7, 5): # approximations
>  item = line[i:i+width]
>  record.append(item)
>  i += width
>  records.append(record)
> 
> This leaves them all strings, which in my experience is more
> convenient in practice. You can convert as you go if you
> want,though it won't look nice and simple any longer.
>

Perhaps even better approach is to use csv module from standard library:

import csv

csv_reader = csv.reader(file, dialect="excel-tab")
for row in csv_reader:
 # do something with record data which is conveniently parsed to list
 print(row)

['2018-05-31', '16:00:00', '28.90', '81.77', '4.3']
...
['2018-06-29', '00.42:00', '32.20', '104.61', '4.8']


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


Re: Python read text file columnwise

2019-01-15 Thread Neil Cerutti
On 2019-01-11, shibashib...@gmail.com  wrote:
> Hello
>> 
>> I'm very new in python. I have a file in the format:
>> 
>> 2018-05-31   16:00:0028.90   81.77   4.3
>> 2018-05-31   20:32:0028.17   84.89   4.1
>> 2018-06-20   04:09:0027.36   88.01   4.8
>> 2018-06-20   04:15:0027.31   87.09   4.7
>> 2018-06-28   04.07:0027.87   84.91   5.0
>> 2018-06-29   00.42:0032.20   104.61  4.8
>
> I would like to read this file in python column-wise.  
>
> I tried this way but not working 
>   event_list = open('seismicity_R023E.txt',"r")
> info_event = read(event_list,'%s %s %f %f %f %f\n');

If it's really tabular data in fixed-width columns you can read
it that way with Python.

records = []
for line in file:
record = []
i = 0
for width in (30, 8, 7, 5): # approximations
item = line[i:i+width]
record.append(item)
i += width
records.append(record)

This leaves them all strings, which in my experience is more
convenient in practice. You can convert as you go if you
want,though it won't look nice and simple any longer.

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


Re: 3 random numbers

2019-01-15 Thread Gengyang Cai
I managed to solve the problem and also another problem with different 3 random 
numbers. But it wasn't a very good question in the first place, i admit 



On Tuesday, January 15, 2019 at 9:55:00 PM UTC+8, Rick Johnson wrote:
> Gengyang Cai wrote:
> > Can anyone understand it and explain it to me please ? 
> 
> Instead of attempting to read source code that you obviously have no 
> qualification to read, why don't you try _thinking_ like a programmer? 
> 
> "But Rick! How will i think like a programmer if i cannot even read source 
> code?!"
> 
> Forget about reading source code, kid! Reading source code is only a small 
> part of being a programmer. Are you any less intelligent because you can't 
> speak every language on the freakin' planet including Klingon, Elvish and the 
> black tongue of the Mordor Orc? No. Of course not! You can still tie you 
> tennis shoes, yes? Okay... Thus, programming languages are like natural 
> language, in that they are merely a means to communicate. Tools. That's all. 
> So, if you can become competent with a rake, then you can probably do the 
> same with a shovel, and a hoe. All of these tools will help you build a 
> garden. Or bury a skeleton in the backyard -- after dark, when the nosy 
> neighbors are sleeping!
> 
> <_<
> 
> >_>
> 
> "Okay Rick... i sorta understand your point here, but... i'm not having that 
> ah-hah! moment. How do i think like a programmer?"
> 
> Simple! You look at a problem, and then you ask yourself: "What are the 
> fundamental steps required to solve this problem?" And sometimes scratching 
> the head helps...
> 
> ASSIGNMENT: "Pick any 3 random ascending numbers and write out a loop 
> function that prints out all 3 numbers"""
> 
> Looking at this sentence, i see two specific problems:
> 
> 
> 
> So, in the case of your assignment, the first step would be to pick three 
> numbers. 
> 
> STEP_1. Pick three numbers. 
> 
>numbers = [400, 467, 851]

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


help with python difference between number

2019-01-15 Thread achyuta2017


M <01/14/2019 08:07:01> Count:0 
Total:50
Free: 20
A
B
M <01/14/2019 08:07:04> Count:1
Total:5
Free:10
A
B
M <01/14/2019 08:07:07> Count:2
Total:5
Free:3
A
B


I am trying to make a output like where it prints the free and then the 
difference between the current free and previous free
For e.g

M <01/14/2019 08:07:01> Count:0  Free: 20
M <01/14/2019 08:07:04> Count:1  Free: 10  absolute difference between time and 
prev time is -10
M <01/14/2019 08:07:07> Count:2  Free: 3   absolute difference between time and 
prev time is -7


And then later on i need to determine the time when we had the most negative 
free value.


I tried a code like this
Which printed 
 with open("summ4.txt") as f:
# get first line/number
nxt = int(next(f))
for n in f:
print("absolute difference between {} and {} = {}"
  .format(n.rstrip(), nxt, abs(int(nxt) - int(n
# set nxt equal to the next number
nxt = int(next(f,0))
   a=open('summ1.txt','r').readlines()
   b=open('summ3.txt','r').readlines()
with open('summ.txt','w') as out:
  for i in range(0,365): 
print>>out,a[i].rstrip(),b[i]


I hit error as
Traceback (most recent call last):
File "3.py", 
line 39, in 
   .format(n.rstrip(), 
nxt, abs(int(nxt) - int(n
ValueError: 
zero length field name in format 

I guess my input file has a tab in the start and not able to get a difference 
rightly.
.
Any pointers on how to achieve the desired result?

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


Re: [tkinter] question about correct use of validation

2019-01-15 Thread steve

On 15/01/2019 14:16, Rick Johnson wrote:

steve wrote:

Then it's just a matter of passing a keyword argument:

 myEntry = MyEntry(master, maxlen=20)

What you have above is a tightly coiled, steaming dogpile that will litter your 
code base. Encapsulate that stench, would ya?



sure, everything will go into a "label_entry" function

It's similar to this:

def __label_entry (self, frame, text_label, width_label, width_entry, 
maxlen):

 '' 'Private utility function for a couple of labels + entry.
 Return istance of entry itself.
 '' '
 Label (frame, padx=10, pady=10, width=width_label,
text=text_label) .Pack (side=LEFT)
 entry = Entry (frame, width=width_entry)
 entry.configure (highlightcolor='blue')
 entry.pack (side=LEFT)
..
 return entry

I wrote voluntarily in order to better understand the question
--
https://mail.python.org/mailman/listinfo/python-list


Re: get the terminal's size

2019-01-15 Thread Alex Ternaute
Hi Cameron,

>>I tried : P = Popen(['stty', '-a'], stdout=subprocess.PIPE,
>>universal_newlines=True) and it runs fine too, so the output seems not
>>really related to that fd.
 
> But it is! stty(1) fetches the terminal settings from its standard
> input, so "fd" is used to supply this. In your Popen test case you
> simply don't set the stdin parameter, so it is the Python process'
> input. Which is usually what you want.

> But I want to be able to ask this
> of any terminal file, thus the parameter.

Ah, Ok; smthlike:
 cs.tty.ttysize(0)
 WinSize(rows=50, columns=100)
 anotherTty=open('/dev/pts/3', 'rw')
 cs.tty.ttysize(anotherTty)
 WinSize(rows=43, columns=199)

It runs :)

I do not need that today but one day orother it could help.
 
Cheers
-- 
Alex
-- 
https://mail.python.org/mailman/listinfo/python-list


[tkinter] question about correct use of validation

2019-01-15 Thread steve

for determine the maximum number of characters in an entry

I have read several interpretations for the solution of the problem, but 
I wanted to find an alternative way (for convenience of the code)


I kindly ask for an opinion on the use of validation in this way.

-

problem: limit number of characters in different entries of a form.

code:

#!/usr/bin/python
# -*- coding: utf-8 -*

from Tkinter import *


class View():

def __init__(self, parent):
self.parent = parent
self.make_ui()

def make_ui(self):
''' create user interface '''
self.id_entry = Entry(self.parent, width=6)
# take out the properties for understanding

vcmd = (self.parent.register(self.maxlength_validate), '%P', 4)
# 4 is my question

self.id_entry.configure(validate="key", validatecommand=vcmd)
self.id_entry.pack()

self.name_entry = Entry(self.parent, width=30)
# take out the properties for understanding

vcmd = (self.parent.register(self.maxlength_validate), '%P', 20)
# 20 is my question

self.name_entry.configure(validate="key", validatecommand=vcmd)
self.name_entry.pack()

def maxlength_validate(self, value, maxlength):
''' function validated for maximum number of characters '''
maxlength = int(maxlength)
if len(value) > maxlength:
value = value[:maxlength]
return (value == ' ')
return True


def run():
root = Tk()
root.title('test')
View(root)
root.mainloop()

if __name__ == "__main__":
run()

The code works well :-) but...

in vcmd i use this:

vcmd = (self.parent.register(self.maxlength_validate), '%P', 20)
# '20' argument is my question, is not default value (is max length of 
char, different for each entry... very comfortable for me)


is it all right, according to you, to pass a non-default argument? (no 
error from the interpreter)


Without this way I would not know how to pass the maximum number of 
characters to the validation function, I can not use one variable

self.--- for each entry ... it would become aesthetically unattractive.

I would not even like to add a textvariable variable because anyway then

I should always pass the comparison value.

thank you in advance

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


Re: get the terminal's size

2019-01-15 Thread Cameron Simpson

On 15Jan2019 10:26, Alex Ternaute  wrote:

My cs.tty module (on PyPI) has a ttysize function:
  https://pypi.org/project/cs.tty/
which just parses the output of the stty command.

[...]

Fine, indeed ! I've installed cs.ttyy.

I just don't understand the reason why it takes "fd" as an argument.


"fd" may be a file descriptor or a file (from which it gets the 
underlying fd).



I tried : P = Popen(['stty', '-a'], stdout=subprocess.PIPE,
universal_newlines=True) and it runs fine too, so the output seems not
really related to that fd.


But it is! stty(1) fetches the terminal settings from its standard 
input, so "fd" is used to supply this. In your Popen test case you 
simply don't set the stdin parameter, so it is the Python process' 
input. Which is usually what you want. But I want to be able to ask this 
of any terminal file, thus the parameter.


Just pass 0 to ttysize, or sys.stdin. Arguably that should be a default 
value.



Btw I did not know about namedtuple, thanks for that too.


Yes, it is very handy.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: get the terminal's size

2019-01-15 Thread Alex Ternaute
Hi there :

> On 2019-01-14, Bob van der Poel  wrote:
>> http://stackoverflow.com/questions/566746/how-to-get-console-window-
width-in-python

Simple and direct, I think I'll use this one.
Thanks a lot.

John Doe :
> and have a look at this one too:
> https://stackoverflow.com/questions/1396820/apt-like-column-output-
python-library/1446973#1446973

Fine, but It meets much more needs than my present one.
But thanks too.

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


Re: python package management confusion

2019-01-15 Thread dcs3spp via Python-list
On Tuesday, 15 January 2019 07:48:57 UTC, Chris Angelico  wrote:
> On Tue, Jan 15, 2019 at 6:18 PM dieter  wrote:
> >
> > dcs3spp via Python-list  writes:
> > > I am a newbie completely confused with python package management.
> > >
> > > I have a setup.py file (listed below) and have setup pip and setup.cfg to 
> > > install my own dependencies  from a local devpi repository.
> > >
> > > Can setup.py reference a git repository so that I can install from that 
> > > url?
> >
> > I doubt it:
> > A primary goal of the Python package management is to allow users
> > to easily install prepackaged components (published in a repository
> > like PyPI) - not to integrate transparently with source code control
> > systems.
> 
> You can use pip to install from a git repo, but I don't know the details.
> 
> ChrisA

Ok cheers all for responding, appreciated

So to manage the development of private packages, e.g. wheels, I would have to 
use my own private repository (something like devpi or a an alternative cloud 
pypi subscription service) to store each private dependency that I have 
written.  Alternatively, I would rely on pip requirement files. Will have to 
investigate zbuildout...

The package source for each dependency package could be managed in source 
control (git, gitlab etc.) and tested in CI build  gitlab-runner/Jenkins.
In the local development environment, packages that use the dependency package 
could use the local devpi repository. This would work in a private bare metal 
environment. 

However, if I wanted to take a step further and run a CI build using cloud 
services(e.g. in a private gitlab.com repository) for a package that uses the 
private packages, then presumably there is no access to the devpi repository on 
my local system? So, alternatively when developing private Python packages I 
either use requirements.txt or pay subscription for a private pypi cloud 
repository and configure pip, setup.cfg on gitlab.com CI to reference it in 
config files. When the CI build completes it pushes the package to the private 
pypi repository. 

Alternatively:
1. Avoid cloud CI services when developing private Python packages and use 
private bare metal CI server, e.g. gitlab, Jenkins etc.  

2. Use one monolithic package.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get the terminal's size

2019-01-15 Thread Alex Ternaute
Hi Cameron,

> My cs.tty module (on PyPI) has a ttysize function:
>   https://pypi.org/project/cs.tty/
> which just parses the output of the stty command.

> If you don't want the cs.tty module, the ttysize code is just this:
> 
> WinSize = namedtuple('WinSize', 'rows columns')
> 
> def ttysize(fd):
>   ''' Return a (rows, columns) tuple for the specified file
>   descriptor.
> [...]

Fine, indeed ! I've installed cs.ttyy.

I just don't understand the reason why it takes "fd" as an argument.
 
I tried : P = Popen(['stty', '-a'], stdout=subprocess.PIPE, 
universal_newlines=True) and it runs fine too, so the output seems not 
really related to that fd.

Btw I did not know about namedtuple, thanks for that too.

> Hope this helps.
Greatly.

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