Re: How to install Python package from source on Windows

2017-06-01 Thread Gregory Ewing

Deborah Swanson wrote:

I got one suggestion that I could just copy the files to "the appropriate
directories",


That was me, but I've just had a look at the source, and it
seems the core functionality is implemented in C, so scrub
that idea.

But all is not lost. I've found this:

https://pypi.python.org/pypi/namedlist

   "Similar to namedtuple, but instances are mutable."

It's all pure Python -- I checked this time! -- so you
shouldn't have any trouble installing it. In fact it's
just a single source file, namedlist.py. Put that in
your site-packages folder and you should be good to go.

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


Re: How to install Python package from source on Windows

2017-06-01 Thread Gregory Ewing

Deborah Swanson wrote:

Why do you care so deeply what pip does on an operating system that is
no longer supported?


Being pipless is a sufficiently distressing fate that we'd
like to help, even if you didn't explicitly request it.

Particularly since it seems like such an unnecessary one,
because installing pip shouldn't require any kind of compiler
on any version of any operating system, supported or otherwise.
So the fact that it apparently does on your system is very
puzzling, and some of us would like to solve that puzzle.

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


Re: How to install Python package from source on Windows

2017-06-01 Thread Gregory Ewing

Deborah Swanson wrote:

I have already offered to do whatever you would like me to do on this
system


If you wouldn't mind, I'd like to see the output from this command:

   python -m ensurepip

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


Re: Working with dictionaries and keys help please!

2017-06-01 Thread Steve D'Aprano
On Thu, 1 Jun 2017 10:29 am, David D wrote:

> I have a dictionary with a 10 people, the key being a number (0-10) and the
> value being the people's name.  I am in the processing of Insert, Adding and
> deleting from the dictionary.  All seems well until I delete a person and add
> a new one.  The numbers (keys) do not change and so I am getting an
> non-sequential set of numbers for the keys.  Is there a way of performing this
> where the key will update so that is continues to work sequentially?  Here is
> what I mean
> 
> Print dictionary
> {0 John, 1 David, 2 Phil, 3 Bob}
> 
> remove 1 David
> {0 John, 2 Phil, 3 Bob}
> 
> How can I get it so that the VALUE will reset and it will look like this after
> both adding or deleting?
> 
> {0 John, 1 Phil, 2 Bob}


You can't. That's not how dicts work.

The dictionary key is similar to the primary key in a database. The fact that
they start off as sequential values is irrelevant. Imagine that you create an
account for Phil, and he gets account number 2; then Bob gets account number 3:

print(accounts)
=> {0: John, 1: David, 2: Phil, 3: Bob}

Then you delete David's account. Then Phil calls you, tells you his account
number is 2, and you access Bob's records instead of Phil's!

Database keys should never be changed or reused.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Circular iteration on tuple starting from a specific index

2017-06-01 Thread Gregory Ewing

guillaume.pau...@giome.fr wrote:

def cycle_once(iterable, start):
return chain(islice(iterable, start, None), islice(iterable, start))


Another variation, maybe slightly more efficient:

from itertools import islice, cycle

def cycle_once(iterable, start):
return islice(cycle(iterable), start, start + len(iterable))

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


Re: Python DB API - commit() v. execute("commit transaction")?

2017-06-01 Thread Gregory Ewing

Chris Angelico wrote:

In the DB API 3.0, what I would like to see is that the connection
becomes a context manager that gives you a transaction object. With
that transaction, you can perform queries, and you could create
cursors from it if you want them, or just use a single in-built
cursor. But a cursor would relate to a result set, and would have no
meaning outside of it.


A while back I wrote a dedicated wrapper around the Firebird
API (I wasn't impressed by the DB API, for many of the reasons
being discussed here), and this is almost exactly how I structured
it. Except I didn't really have cursors as an explicit concept at
all -- executing a query just gave you an object that you iterate
over to get the results. It just seemed the most Pythonic way to
do it.

It helped that the Firebird API itself was structured that
way, so all I really had to do is wrap it in the most
straightforward way.

Is there any serious work being done on a DB API 3.0?
If there is, I'd be interested in helping with the design.

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


Re: Python DB API - commit() v. execute("commit transaction")?

2017-06-01 Thread Jon Ribbens
On 2017-06-01, Gregory Ewing  wrote:
> Is there any serious work being done on a DB API 3.0?
> If there is, I'd be interested in helping with the design.

There are a bunch of existing APIs in other languages that can easily
be copied ;-) The good news is of course that since the DB-API
'Connection' class has so few existing methods, adding new ones while
maintaining backwards-compatibility should be easy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python DB API - commit() v. execute("commit transaction")?

2017-06-01 Thread Chris Angelico
On Thu, Jun 1, 2017 at 8:05 PM, Gregory Ewing
 wrote:
> A while back I wrote a dedicated wrapper around the Firebird
> API (I wasn't impressed by the DB API, for many of the reasons
> being discussed here), and this is almost exactly how I structured
> it. Except I didn't really have cursors as an explicit concept at
> all -- executing a query just gave you an object that you iterate
> over to get the results. It just seemed the most Pythonic way to
> do it.

Executing a query gives you some sort of object. That object either
contains all the results, or has the resource handle (or whatever)
needed to fetch more from the back end. That basically makes it a
cursor, so we're not far different after all :)

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


RE: How to install Python package from source on Windows

2017-06-01 Thread Deborah Swanson
Gregory Ewing wrote, on Thursday, June 01, 2017 12:59 AM
> 
> Deborah Swanson wrote:
> > I got one suggestion that I could just copy the files to "the 
> > appropriate directories",
> 
> That was me, but I've just had a look at the source, and it 
> seems the core functionality is implemented in C, so scrub that idea.

Yes, memoryslots.c is core functionality, and I was just going to have
to fake it if the compiled file needed more than just being dropped into
Site Packages.
 
> But all is not lost. I've found this:
> 
https://pypi.python.org/pypi/namedlist

"Similar to namedtuple, but instances are mutable."

It's all pure Python -- I checked this time! -- so you shouldn't have
any trouble installing it. In fact it's just a single source file,
namedlist.py. Put that in your site-packages folder and you should be
good to go.

-- 
Greg

Thanks Greg! I just ran into another wall, unsolvable by any methods
I've come up with yet, so I'm trying to unroll the namedtuples into a
list of lists, and that turns out to be trickier than you'd think too.
I'll give namedlist a try, seems the PyPi people have seen that hole in
namedtuples' functionality and have worked on some alternatives.
Spectacular!

Deborah

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


RE: How to install Python package from source on Windows

2017-06-01 Thread Deborah Swanson
Gregory Ewing wrote, on Thursday, June 01, 2017 1:12 AM
> 
> Deborah Swanson wrote:
> > Why do you care so deeply what pip does on an operating 
> system that is 
> > no longer supported?
> 
> Being pipless is a sufficiently distressing fate that we'd
> like to help, even if you didn't explicitly request it.
> 
> Particularly since it seems like such an unnecessary one, 
> because installing pip shouldn't require any kind of compiler 
> on any version of any operating system, supported or 
> otherwise. So the fact that it apparently does on your system 
> is very puzzling, and some of us would like to solve that puzzle.
> 
> -- 
> Greg

That's nice, but as I've said, the problem can be solved by reinstalling

Anaconda3 and PyCharm. Not fun or easy, but at least the outcome would
be known if I really needed pip, which I won't for quite awhile.
Honestly, this installation of Anaconda3 is so unstable it behaves
differently everytime I try to do something with it. Better to leave
well enough alone right now.

I really need what little usable time I have making progress with
Python, and I should be a lot healthier in a few months. And I'd rather
spend the downtime then getting my good computer up and running, and
Python on Linux again. Then this problem vanishes.

Deborah

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


RE: How to install Python package from source on Windows

2017-06-01 Thread Deborah Swanson
Gregory Ewing wrote, on Thursday, June 01, 2017 1:15 AM
> 
> Deborah Swanson wrote:
> > I have already offered to do whatever you would like me to 
> do on this 
> > system
> 
> If you wouldn't mind, I'd like to see the output from this command:
> 
> python -m ensurepip
> 
> -- 
> Greg

The rest of that sentence was something like later, when I have Python
in Linux and don't need this sytem anymore.

I've tried ensurepip 2 or 3 times, with different unsuccessful outcomes
each time. I really am done trying to fix this installation, and I just
hope it holds together for PyCharm's use as long as I need it to. Couple
months, I think. And if I don't touch it, should be ok.

Now please, can we be done with this for now?

Deborah

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


Re: Circular iteration on tuple starting from a specific index

2017-06-01 Thread Ian Kelly
On Thu, Jun 1, 2017 at 4:14 AM, Gregory Ewing
 wrote:
> guillaume.pau...@giome.fr wrote:
>>
>> def cycle_once(iterable, start):
>> return chain(islice(iterable, start, None), islice(iterable, start))

This assumes that iterable is restartable, which is not the case if
iterable is itself an iterator.

> Another variation, maybe slightly more efficient:
>
> from itertools import islice, cycle
>
> def cycle_once(iterable, start):
> return islice(cycle(iterable), start, start + len(iterable))

Similar problem here, len will fail on an iterator.

I know the OP specified a tuple (and that was what my own solution
assumed), but "iterable" implies broader applicability.
-- 
https://mail.python.org/mailman/listinfo/python-list


Converting epoch to string in format yyyy-mm-dd, or maybe it is not necessary

2017-06-01 Thread zljubisic
I have a dataframe with epoh dates, something like this:

df = pd.DataFrame( { 'epoch' : [1493928008, 1493928067, 1493928127, 1493928310, 
1493928428, 1493928547]}) 

I want to create a new column with epoch converted to -mm-dd as string.

Actually, I have a epoch column, and I would like to use it for grouping data 
by day, let's say min, max... mayge there is no need for conversion at all.

How to do that?
-- 
https://mail.python.org/mailman/listinfo/python-list


[OT] How to improve my programming skills?

2017-06-01 Thread Mirko via Python-list


Hello everybody!

TLDR: Sorry for OT. Long-time Linux geek and hobby programmer wants 
to improve his coding skills. What's most important: project 
planing, algorithms and data structures, contributing to FOSS, web 
development, learning other languages or something else?



Sorry for posting such a (long) off-topic question, which even is 
partly even more about psychology, than about technology. But I'm 
mostly using Python and Bash for programming and am reading this 
mailing list/newsgroup for many years now, and hope it's Ok (feel 
free to direct me somewhere more appropriate, as long it's an 
equally helpful and friendly place).


I'm looking for a way (*the* way, ie. the "BEST(tm)" way) to improve 
my coding skills. While I'm a quite hard-core computer geek since 25 
years and a really good (hobbyist) Linux-SOHO-Admin, my programming 
skills are less than sub-par. I wish to change that and become at 
least am average hobby-programmer. I'm an excellent autodidact and 
in fact, all what I know about computers is completely self-taught.


Now, the problem is, that I'm 41 years old now, have a day job 
(which hasn't much to do with advanced computing stuff), friends and 
all that. There is little time left for this undertaking (something 
like 5 - 10 hours per week), so I'm looking for the most efficient 
ways to do this.


I identify the following problems which could be worth improving:

- I never sit down and plan anything with pencil and paper, 
flowcharts, UML or anything else. I just fire up Vim and start 
typing. That works (albeit slowly) for simple programs, but as soon 
as the project becomes a little more complex the parts and 
components don't match well and I need to botch something together 
to somehow make it work. And in the resulting mess I lose the interest.


- I never learned algorithms and data structures. I know *what* 
(linked) lists, dicts, arrays, structs, and trees are; what binary 
search or bubble-sort is, but I never really studied them, let alone 
implemented them for educative purposes.


- When it comes to coding, I'm heavily shy and unsure. I really know 
my stuff when it's about Linux-SOHO-Administration, but when trying 
to contribute to FOSS projects I always hesitate for several reasons 
(somehow I never find those low-hanging fruits that everybody talks 
about; either it's super-easy or to difficult.)


- For my day job (which is absolutely not my dream job) it would be 
quite useful to know web design/development, especially WordPress 
stuff. But web programming always feel like being trapped in a 
mangrove jungle, with all those browser-specialties, different and 
incompatible JS-engines, PHP versions and all that. I'm almost never 
in the mood to learn web development.


- Beside Python and Bash -- which I both know rather well (for a 
hobbyist at least) -- I only know a little C, some LUA and a tiny 
bit of Scheme.


- I'm very hard to motivate, when the issue or topic doesn't 
interest me much. I know some tricks to increase my motivation in 
such cases, but don't use them enough.




What do you think, which of the problems would be most important to 
overcome? What would be the most efficient way for improving my 
general programming skills? Do you have any other suggestions or tips?



Much thanks for your time!

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


Test to see if message is bounced

2017-06-01 Thread Richard Moseley
Apologies if this appears on the list, but I'm checking whether I have been
placed onto a blacklist since previous postings have been bounced back with
an error that the email address is not on the "subscribers list". I
previously had an email address of "dickie.mose...@virgin.net" which has
now been deactivated.

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


Re: Test to see if message is bounced

2017-06-01 Thread Chris Angelico
On Fri, Jun 2, 2017 at 3:44 AM, Richard Moseley
 wrote:
> Apologies if this appears on the list, but I'm checking whether I have been
> placed onto a blacklist since previous postings have been bounced back with
> an error that the email address is not on the "subscribers list". I
> previously had an email address of "dickie.mose...@virgin.net" which has
> now been deactivated.

Looks fine to me.

Most likely, your *email address*, not you as a person, would have
been blocked for excessive bounces. It's nothing against you as a
person.

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


Re: [OT] How to improve my programming skills?

2017-06-01 Thread MRAB

On 2017-06-01 16:26, Mirko via Python-list wrote:
[snip]


I'm looking for a way (*the* way, ie. the "BEST(tm)" way) to improve
my coding skills. While I'm a quite hard-core computer geek since 25
years and a really good (hobbyist) Linux-SOHO-Admin, my programming
skills are less than sub-par. I wish to change that and become at
least am average hobby-programmer. I'm an excellent autodidact and
in fact, all what I know about computers is completely self-taught.

Now, the problem is, that I'm 41 years old now, have a day job
(which hasn't much to do with advanced computing stuff), friends and
all that. There is little time left for this undertaking (something
like 5 - 10 hours per week), so I'm looking for the most efficient
ways to do this.


The best way is practice, which takes time. I don't know of a shortcut.


I identify the following problems which could be worth improving:

- I never sit down and plan anything with pencil and paper,
flowcharts, UML or anything else. I just fire up Vim and start
typing. That works (albeit slowly) for simple programs, but as soon
as the project becomes a little more complex the parts and
components don't match well and I need to botch something together
to somehow make it work. And in the resulting mess I lose the interest.


Flowcharts? UML? Never used them! :-)

I _have_ used sometimes pseudocode, though. Python has been described as 
"executable pseudocode" in the past, which is probably why I like it so 
much.



- I never learned algorithms and data structures. I know *what*
(linked) lists, dicts, arrays, structs, and trees are; what binary
search or bubble-sort is, but I never really studied them, let alone
implemented them for educative purposes.

Higher-level languages like Python have dicts and sorting built-in, so 
unless you're working on improving the low-level implementation, you 
don't need to know the details.


[snip]


- I'm very hard to motivate, when the issue or topic doesn't
interest me much. I know some tricks to increase my motivation in
such cases, but don't use them enough.

You could pick something that you could automate. That way, you'd be 
learning and also saving time in the long run.



What do you think, which of the problems would be most important to
overcome? What would be the most efficient way for improving my
general programming skills? Do you have any other suggestions or tips?


If you don't enjoy programming, it's probably not for you! :-)
--
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] How to improve my programming skills?

2017-06-01 Thread Neil Cerutti
On 2017-06-01, Mirko via Python-list  wrote:
> Hello everybody!
>
> TLDR: Sorry for OT. Long-time Linux geek and hobby programmer
> wants to improve his coding skills. What's most important:
> project planing, algorithms and data structures, contributing
> to FOSS, web development, learning other languages or something
> else?

I recommend a few things you haven't yet mentioned: learning to
use source control, and working toward a systematic way of
composing and runnings tests as you develop..

Secondly, I recommend picking up a programming langauge that
concentrates on functional programming with immutable state if
you haven't done it before. The book that worked for me was
Simply Scheme https://people.eecs.berkeley.edu/~bh/ss-toc2.html,
but that's sorta ancient history now and I'm sure there's lots
more options out there.

-- 
Neil Cerutti

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


Celery + Django logging and RotateFileHandler

2017-06-01 Thread Heron Rossi
I have a Django project setup with Celery and a RotatingFileHandler setting 
like shown below:

LOGGING = {
'version': 1,
'handlers': {
'console':{
'class':'logging.StreamHandler',
'stream': sys.stdout,
},
'celery': {
'class': 'logging.handlers.RotatingFileHandler',
'filename': '/var/log/celery/celery.log',
'formatter': 'verbose',
'maxBytes': (1024 * 1024 * 10),  # 10 mb
'backupCount': 10
},
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d 
%(thread)d %(message)s'
},
},
'loggers': {
'sm9.views': {
'handlers':['console'],
'propagate': True,
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'sm9.helpers': {
'handlers':['console'],
'propagate': True,
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'sm9.soap': {
'handlers':['celery'],
'propagate': True,
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'sm9.tasks': {
'handlers':['celery'],
'propagate': True,
'level': os.getenv('CELERYD_LOG_LEVEL', 'INFO'),
},
'celery': {
'handlers': ['celery'],
'level': os.getenv('CELERYD_LOG_LEVEL', 'INFO'),
'propagate': True
},
},
}

When celery.log reaches 10mb the system is creating 2 more files: celery.log.1, 
celery.log.2 . All files are beeing populated simultaneously instead of 
reaching 10mb and opening a new file. Is this the expected behavior?

Celery is running as a daemon with 3 threads.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] How to improve my programming skills?

2017-06-01 Thread Steve D'Aprano
On Fri, 2 Jun 2017 01:26 am, Mirko wrote:

> TLDR: Sorry for OT. Long-time Linux geek and hobby programmer wants
> to improve his coding skills. What's most important: project
> planing, algorithms and data structures, contributing to FOSS, web
> development, learning other languages or something else?

Programming.

If you want to improve your programming skills, you must *write code* and then
*run that code* and if it breaks you must *fix that code*.

I cannot tell you how many hours I have wasted writing code that I've never
actually run. Its a trap.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Converting epoch to string in format yyyy-mm-dd, or maybe it is not necessary

2017-06-01 Thread dieter
zljubi...@gmail.com writes:

> I have a dataframe with epoh dates, something like this:
>
> df = pd.DataFrame( { 'epoch' : [1493928008, 1493928067, 1493928127, 
> 1493928310, 1493928428, 1493928547]}) 
>
> I want to create a new column with epoch converted to -mm-dd as string.

"epoch" dates usually mean seconds since 1.1.1970, represented
as an integer or float. A single epoch date is usually not represented
as a list (as above).
For details, read the head of the "time" module documentation.

The "time" module contains 2 functions to convert from an
"epoch date" to a time tuple: "gmtime"
(this gives an UTC or Greenwich Mean time tuple) and "localtime" (this
gives a time tuple represented in the local time zone).

You can use "time.strftime" to get a string representation (according
to a format you specify) from a time tuple.


Again, the documentation of the "time" module tells the details.

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