Caching: Access a local file, but ensure it is up-to-date from a remote URL

2014-10-12 Thread Ben Finney
Howdy all,

I'm hoping that the problem I currently have is one already solved,
either in the Python standard library, or with some well-tested obvious
code.

A program I'm working on needs to access a set of files locally; they're
just normal files.

But those files are local cached copies of documents available at remote
URLs — each file has a canonical URL for that file's content.

I'd like an API for ‘get_file_from_cache’ that looks something like::

file_urls = {
"foo.txt": "http://example.org/spam/";,
"bar.data": "https://example.net/beans/flonk.xml";,
}

for (filename, url) in file_urls.items():
infile = get_file_from_cache(filename, canonical=url)
do_stuff_with(infile.read())

* If the local file's modification timestamp is not significantly
  earlier than the Last-Modified timestamp for the document at the
  corresponding URL, ‘get_file_from_cache’ just returns the file object
  without changing the file.

* The local file might be out of date (its modification timestamp may be
  significantly older than the Last-Modified timestamp from the
  corresponding URL). In that case, ‘get_file_from_cache’ should first
  read the document's contents into the file, then return the file
  object.

* The local file may not yet exist. In that case, ‘get_file_from_cache’
  should first read the document content from the corresponding URL,
  create the local file, and then return the file object.

* The remote URL may not be available for some reason. In that case,
  ‘get_file_from_cache’ should simply return the file object, or if that
  can't be done, raise an error.

So this is something similar to an HTTP object cache. Except where those
are usually URL-focussed with the local files a hidden implementation
detail, I want an API that focusses on the local files, with the remote
requests a hidden implementation detail.

Does anything like this exist in the Python library, or as simple code
using it? With or without the specifics of HTTP and URLs, is there some
generic caching recipe already implemented with the standard library?

This local file cache (ignoring the spcifics of URLs and network access)
seems like exactly the kind of thing that is easy to get wrong in
countless ways, and so should have a single obvious implementation
available.

Am I in luck? What do you advise?

-- 
 \   “If consumers even know there's a DRM, what it is, and how it |
  `\ works, we've already failed.” —Peter Lee, Disney corporation, |
_o__) 2005 |
Ben Finney

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


Re: problem with pytz

2014-10-12 Thread Mark Lawrence

On 13/10/2014 03:55, ryguy7272 wrote:

I just tried running the code from here.
http://www.thealgoengineer.com/2014/download_sp500_data/

I got this error.
Traceback (most recent call last):
   File "C:/Python27/stock_data.py", line 4, in 


Please don't put your code here, what happens when you upgrade your 
Python version?



 import pytz
ImportError: No module named pytz

So, I got here and download the files.
https://pypi.python.org/pypi/pytz/#downloads

I run this:
python setup.py install

I get this error.
python: can't open file 'setup.py': [Errno 2] No such file or directory

I tried this:
easy_install --upgrade pytz


Now, that seems like it downloaded and installed.  So, I re-run the program, 
and I get the same error I had initially.
Traceback (most recent call last):
   File "C:/Python27/stock_data.py", line 4, in 
 import pytz
ImportError: No module named pytz


I don't get it.  I go to the path 'C:\Python27\pytz' and the folder is right 
there!  It's right there!  It's a little frustrating because all my problems 
seem to be exactly the same, which is running scripts that should run 
easily...bu nothing actually runs.  What else do I need to do to make this 
thing work?



It should be in c:\python27\lib\site-packages.  It's also far easier to 
use pip to install code.  It's already available as an option with 3.4 
and I think will be automatically included with 3.5


Finally it looks as if you're using googlegroups.  If that is the case 
would you please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing 
double line spacing and single line paragraphs.  Better yet access this 
list via https://mail.python.org/mailman/listinfo/python-list, thanks.


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


problem with pytz

2014-10-12 Thread ryguy7272
I just tried running the code from here.
http://www.thealgoengineer.com/2014/download_sp500_data/

I got this error.
Traceback (most recent call last):
  File "C:/Python27/stock_data.py", line 4, in 
import pytz
ImportError: No module named pytz

So, I got here and download the files.
https://pypi.python.org/pypi/pytz/#downloads

I run this:
python setup.py install

I get this error.
python: can't open file 'setup.py': [Errno 2] No such file or directory

I tried this:
easy_install --upgrade pytz


Now, that seems like it downloaded and installed.  So, I re-run the program, 
and I get the same error I had initially.  
Traceback (most recent call last):
  File "C:/Python27/stock_data.py", line 4, in 
import pytz
ImportError: No module named pytz


I don't get it.  I go to the path 'C:\Python27\pytz' and the folder is right 
there!  It's right there!  It's a little frustrating because all my problems 
seem to be exactly the same, which is running scripts that should run 
easily...bu nothing actually runs.  What else do I need to do to make this 
thing work?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what is the easiest way to install multiple Python versions?

2014-10-12 Thread Rustom Mody
On Sunday, October 12, 2014 7:06:14 PM UTC+5:30, Albert-Jan Roskam wrote:
> Hi,
> 
> A few days ago I needed to check whether some Python code ran with Python 
> 2.6. What is the easiest way to install another Python version along side the 
> default Python version? My own computer is Debian Linux 64 bit, but a 
> platform-independent solution would be best.
> 
> 
> 
> Possible solutions that I am aware of
> 
> 
> 
> -make altinstall *). This is what I tried (see below), but not all modules 
> could be built. I gave up because I was in a hurry
> 
> -Pythonbrew. This project is dead
> 
> -Deadsnakes
> 
> -Anaconda
> 
> -Tox? I only know this is as a cross-version/implementation test runner
> 
> -Vagrant. This is what I eventually did, and this was very simple. I ran 
> Ubuntu 10.0.4 LTS, which uses Python 2.6, and used Vagrant SSH to run and 
> check my code in Python 2.6 (and I replaced a dict comprehension with a list 
> comprehension, for example)

Hearing a bit about docker nowadays.

Here's why its supposedly better than a VM:
https://www.docker.com/whatisdocker/

Downsides?? No idea!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to install and run a script?

2014-10-12 Thread ryguy7272
On Sunday, October 12, 2014 4:18:19 PM UTC-4, ryguy7272 wrote:
> I'm an absolute noob to Python, although I have been programming in several 
> other languages for over 10 years.
> 
> 
> 
> I'm trying to install and run some scripts, and I'm not having much success.
> 
> 
> 
> I followed the steps at this site.
> 
> https://docs.python.org/2/install/
> 
> 
> 
> I have Python 2.7.6 Shell.
> 
> 
> 
> If I type this:
> 
> python setup.py install
> 
> 
> 
> I get this:
> 
> SyntaxError: invalid syntax
> 
> 
> 
> 
> 
> If I try this:
> 
> setup.py beautifulsoup
> 
> 
> 
> I get this:
> 
> SyntaxError: invalid syntax
> 
> 
> 
> 
> 
> If I got to File > Open . . . . navigate to a folder and open the setup.py 
> file and hit F5 . . . . it looks like it runs, but I can't tell what it does 
> for sure, and then nothing works after that.For instance, I downloaded 
> something called 'Flask'.  I put that folder in my Python27 folder, and typed 
> 'pip install Flask' and I keep getting errors.  
> 
> 
> 
> Any idea how to run a simple program???


Ah!!!  I didn't know I needed to run it from the command prompt!  Ok, not 
it makes sense, and everything works.

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


Re: what is the easiest way to install multiple Python versions?

2014-10-12 Thread Terry Reedy

On 10/12/2014 9:33 AM, Albert-Jan Roskam wrote:


A few days ago I needed to check whether some Python code ran with
Python 2.6. What is the easiest way to install another Python version
along side the default Python version? My own computer is Debian
Linux 64 bit, but a platform-independent solution would be best.


Installation is platform dependent.  On Windows, the answer would simply 
be 'get the PSF x.y installer and run it'.


--
Terry Jan Reedy

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


Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 11:43 AM, Dennis Lee Bieber
 wrote:
> ONE: Python uses short circuit evaluation: for an OR, the second 
> clause
> is only looked at if the first clause is FALSE (for an AND, the first
> clause has to be TRUE before the second is evaluated).

Short-circuiting doesn't actually matter here, incidentally. It could
be eagerly evaluated and nothing would be different.

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


Re: TypeError: 'kwarg' is an invalid keyword argument for this function

2014-10-12 Thread Terry Reedy

On 10/12/2014 2:45 PM, Ian Kelly wrote:

On Sun, Oct 12, 2014 at 6:55 AM, roro codeath  wrote:

How to implement it in my class?

class Str(str):
 def __init__(self, *args, **kwargs):
 pass

Str('smth', kwarg='a')


The error is coming from the __new__ method. Because str is an
immutable type, you should override the __new__ method, not __init__.


or, if one is mere adding a method, do not add __new__ either.


Example:

class Str(str):
 def __new__(cls, *args, **kwargs):
 return super().__new__(cls, args[0])


Str('smth', kwarg='a')

'smth'




--
Terry Jan Reedy

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


Re: while loop - multiple condition

2014-10-12 Thread Steven D'Aprano
Tim Chase wrote:

> On 2014-10-12 22:16, Marko Rauhamaa wrote:
>> is equivalent with
>> 
>> while ans.lower()[0] != 'y':
>>  ans = input('Do you like python?')
> 
> And still better improved with
> 
>   while ans[:1].lower() != 'y':
> ans = input('Do you like python?')


The intention is to loop forever until the victim breaks down and accepts
that they like Python, by entering "yes" or "y". I'm pretty sure that
entering "yellow" or "you've got to be kidding" should not break the loop.

When you have multiple clauses in the condition, it's easier to reason about
them if you write the clauses as positive statements rather than negative
statements, that is, "something is true" rather than "something is not
true", and then use `not` to reverse it if you want to loop *until* the
overall condition is true.

When checking for equality against multiple values, instead of:

x == a or x == b or x == c

it is usually easier to use `in`:

x in (a, b, c)


So we have:

# loop so long as the victim answers "yes" or "y"
while ans.lower() in ('yes', 'y'):
ans = input('Do you like python? Well, do you?')

# loop until the victim answers "yes" or "y"
while not (ans.lower() in ('yes', 'y')):
ans = input('Do you like python? Well, do you?')


both of which work fine if the user stays mum by entering the empty string.

You can also write:

while ans.lower() not in ('yes', 'y'):
ans = input('Do you like python? Well, do you?')


if you prefer. In my opinion, that's the most readable version of all.

One last note: if you are using Python 3.3 or better, you can support
international text better by using the casefold() method rather than
lower(). In this case, it won't make a difference, but the technically
correct method for doing case-insensitive comparisons is to casefold both
strings rather than lower- or upper-case them.


-- 
Steven

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


Re: while loop - multiple condition

2014-10-12 Thread Tim Chase
On 2014-10-12 22:16, Marko Rauhamaa wrote:
> is equivalent with
> 
> while ans.lower()[0] != 'y':
>  ans = input('Do you like python?')

And still better improved with

  while ans[:1].lower() != 'y':
ans = input('Do you like python?')

in the event that len(ans)==0 (a situation which will crash the
various current examples).

It also only expends the effort to lowercase 0-or-1 characters,
rather than lowercasing an entire string just to throw away
everything except the first character.

-tkc



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


Re: How to install and run a script?

2014-10-12 Thread Mark Lawrence

On 12/10/2014 21:17, Ryan Shuell wrote:

I'm an absolute noob to Python, although I have been programming in several 
other languages for over 10 years.

I'm trying to install and run some scripts, and I'm not having much success.

I followed the steps at this site.
https://docs.python.org/2/install/


You're looking at the wrong docs.  Having said that I'd just grab pip, 
see http://pip.readthedocs.org/en/latest/installing.html


Once it's successfully installed just

pip install beautifulsoup

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


Fwd: How to install and run a script?

2014-10-12 Thread Abhiram


Begin forwarded message:

> From: Ryan Shuell 
> Subject: How to install and run a script?
> Date: 13 October 2014 1:47:58 am IST
> To: python-list@python.org
> 
> I'm an absolute noob to Python, although I have been programming in several 
> other languages for over 10 years.
> 
> I'm trying to install and run some scripts, and I'm not having much success.
> 
> I followed the steps at this site.
> https://docs.python.org/2/install/
> 
> I have Python 2.7.6 Shell.
> 
> If I type this:
> python setup.py install
> 
> I get this:
> SyntaxError: invalid syntax
> 

Have you completed installation?
If you type “Python” in Cmd, or “Python” in terminal, do you get the Python 
prompt “>>>” ?
My guess is that your Python installation’s executable isn’t in the Windows / 
Linux $PATH variable. 
Give us more details so we can help you out further. :)

Thanks
Abhiram
“Py,Py,Py your boat. Gently down the IOstream"-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to install and run a script?

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 7:17 AM, Ryan Shuell  wrote:
> I'm an absolute noob to Python, although I have been programming in several 
> other languages for over 10 years.
>
> I'm trying to install and run some scripts, and I'm not having much success.
>
> I followed the steps at this site.
> https://docs.python.org/2/install/
>
> I have Python 2.7.6 Shell.
>
> If I type this:
> python setup.py install
>
> I get this:
> SyntaxError: invalid syntax

Hi!

The commands you're looking at need to be run from your regular shell;
I'm guessing you may be on Windows, so that would be the command
prompt (cmd.exe). But rather than playing with setup.py directly, you
should now be able to use pip, which is also run from the command
line:

C:\>pip install flask
C:\>\python27\Scripts\pip install flask

The first version works if you've added the appropriate directories to
your PATH, the second is where the executable is actually found. I
have several Pythons installed, so I didn't let it put itself into
PATH; chances are you can take the easy route.

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


How to install and run a script?

2014-10-12 Thread Ryan Shuell
I'm an absolute noob to Python, although I have been programming in several 
other languages for over 10 years.

I'm trying to install and run some scripts, and I'm not having much success.

I followed the steps at this site.
https://docs.python.org/2/install/

I have Python 2.7.6 Shell.

If I type this:
python setup.py install

I get this:
SyntaxError: invalid syntax


If I try this:
setup.py beautifulsoup

I get this:
SyntaxError: invalid syntax


If I got to File > Open . . . . navigate to a folder and open the setup.py file 
and hit F5 . . . . it looks like it runs, but I can't tell what it does for 
sure, and then nothing works after that.For instance, I downloaded 
something called 'Flask'.  I put that folder in my Python27 folder, and typed 
'pip install Flask' and I keep getting errors.  

Any idea how to run a simple program???
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop - multiple condition

2014-10-12 Thread Denis McMahon
On Sun, 12 Oct 2014 17:08:00 +, Shiva wrote:

> while ans.lower() != 'yes' or ans.lower()[0] != 'y':

while ans.lower() is not equal to "yes"
   or ans.lower()[0] is not equal to "y"

the loop will continue to run

Note that if ans.lower() == 'y', then the first clause ( ans.lower() != 
'yes' ) is true, so the loop will continue to run, ignoring the result of 
the second clause ( ans.lower()[0] != 'y' ), This will also be the case 
if you reverse the order of the clauses.

It seems that you need a better understanding of combinatorial logic, 
perhaps http://www.ee.surrey.ac.uk/Projects/Labview/boolalgebra/
index.html#booleantheorems will help.

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


Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 6:16 AM, Marko Rauhamaa  wrote:
> The corrected version
>
> while ans.lower() != 'yes' and ans.lower()[0] != 'y':
>  ans = input('Do you like python?')
>
> is equivalent with
>
> while ans.lower()[0] != 'y':

It's true that the first part is redundant, but trimming that out
wouldn't have taught the OP about boolean logic :)

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


Re: while loop - multiple condition

2014-10-12 Thread Marko Rauhamaa
Chris Angelico :

> On Mon, Oct 13, 2014 at 4:59 AM, Shiva
>  wrote:
>> Bit confusing to use in While loop - Should have used the 'and' condition
>> instead of OR- then it works fine.
>> for OR both condition need to be false to produce a false output and break
>> the loop.
>
> Correct, what you're looking for here is indeed an 'and' (also called
> a conjunction, as opposed to the disjunction of 'or'). Both operators
> are important; and you need to understand what they do so you know
> when to use each.

The corrected version

while ans.lower() != 'yes' and ans.lower()[0] != 'y':
 ans = input('Do you like python?')

is equivalent with

while ans.lower()[0] != 'y':
 ans = input('Do you like python?')


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


Re: TypeError: 'kwarg' is an invalid keyword argument for this function

2014-10-12 Thread Ian Kelly
On Sun, Oct 12, 2014 at 6:55 AM, roro codeath  wrote:
> How to implement it in my class?
>
> class Str(str):
> def __init__(self, *args, **kwargs):
> pass
>
> Str('smth', kwarg='a')

The error is coming from the __new__ method. Because str is an
immutable type, you should override the __new__ method, not __init__.
Example:

class Str(str):
def __new__(cls, *args, **kwargs):
return super().__new__(cls, args[0])

>>> Str('smth', kwarg='a')
'smth'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Toggle

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 5:38 AM, Tony the Tiger  wrote:
>> colour = 'red' if colour == 'blue' else 'blue'
>
> I call that a subtle bug that most likely will jump up and bite your
> behind when you least expect it.

More generally, I'd say that this is solving a (very) slightly
different problem: it's providing a "toggle with default" feature,
where the part after the else is the default. If you don't want a
default, that's a bug. I've known times when that default makes life a
lot easier, in which case it'd be a feature.

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


Re: what is wrong with this script and how do I get the value in a php script

2014-10-12 Thread Denis McMahon
On Sun, 12 Oct 2014 07:24:52 -0700, martijnperdaan wrote:

> what is wrong with this script and how do I get the value Rij1 and Rij2
> and Rij3 and Rij4 and Rij5 and Rij6 in a php script

I can see several pythonic errors in your script, however as for "what is 
wrong", I see no indication from you of what you expect it to do, what 
output you expect, what error messages you get when you try and run it 
etc.

Perhaps a better subject would have been "how to read gpio on raspberry 
pi"

It also helps if you can reduce your code example to the minimum needed 
to demonstrate the error. In this case, I would suggest that once you can 
read one input correctly, you should be able to expand that code to read 
all inputs.

The code below might help (uses 2.x style print):

import RPi.GPIO as GPIO

GPIO.setmode(mode)
GPIO.setup(17, GPIO.IN)

if GPIO.input(17) == GPIO.HIGH:
print True
else:
print False

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


Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 4:59 AM, Shiva
 wrote:
> Bit confusing to use in While loop - Should have used the 'and' condition
> instead of OR- then it works fine.
> for OR both condition need to be false to produce a false output and break
> the loop.

Correct, what you're looking for here is indeed an 'and' (also called
a conjunction, as opposed to the disjunction of 'or'). Both operators
are important; and you need to understand what they do so you know
when to use each.

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


Re: while loop - multiple condition

2014-10-12 Thread Shiva
Bit confusing to use in While loop - Should have used the 'and' condition
instead of OR- then it works fine.
for OR both condition need to be false to produce a false output and break
the loop.
More of SET operations.

Thanks,
Shiva

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


Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 4:21 AM, Shiva
 wrote:
>> The loop will continue while either part is true - that's what "or"
>> means. Is that what you intended it to be doing?
>>
>> ChrisA
>>
>
>
> Yes..however, the second part of the or condition doesn't get evaluated.
> So if I enter a 'y' - I expect the second part to evaluate and the loop to
> break - but that doesn't seem to happen.

Break it down into separate parts and have a look at what's happening.

while ans.lower() != 'yes' or ans.lower()[0] != 'y':
ans = input('Do you like python?')
print("ans.lower() = {!r}; first cond = {!r}, second cond {!r},
disjunction {!r}".format(
ans.lower(), (ans.lower() != 'yes'), (ans.lower()[0] != 'y'),
(ans.lower() != 'yes' or ans.lower()[0] != 'y')
))

The while loop will continue so long as the disjunction is True. See
what it's actually doing.

This is fundamental Boolean logic, a basic skill of programming.
You're going to need to master this. Look at the different pieces, and
get your head around what the 'or' operator actually does.

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


Re: while loop - multiple condition

2014-10-12 Thread Roy Smith
In article ,
 Shiva  wrote:

> Why is the second part of while condition not being checked?
> 
> while ans.lower() != 'yes' or ans.lower()[0] != 'y':
>  ans = input('Do you like python?')
> 
> 
> My intention is if either of the conditions are true the loop should break.
> But the condition after 'or' doesn't seem to evaluate.

A general rule of programming (be it Python or any other language) is to 
break up complicated code into smaller pieces which can be understood 
and tested in isolation.  Your 'while' condition is kind of hairy.  
There's a couple of complicated expressions, a logical conjuction, and 
two different negated comparisons.  That's a lot to understand all at 
once.

I would factor that out into a little function:

---
def is_yes(answer):
  if answer.lower() == 'yes':
return True
  if answer.lower()[0] == 'y':
return True
  return False

while is_yes(ans):
  ans = input('Do you like python?')
---

Now, you can play around with your is_yes() function in an interactive 
session and see what it returns for various inputs, in isolation from 
the rest of your program:

print is_yes('y')
print is_yes('yes')
print is_yes('no')
print is_yes('you bet your sweet bippy')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop - multiple condition

2014-10-12 Thread Shiva

> The loop will continue while either part is true - that's what "or"
> means. Is that what you intended it to be doing?
> 
> ChrisA
> 


Yes..however, the second part of the or condition doesn't get evaluated.
So if I enter a 'y' - I expect the second part to evaluate and the loop to
break - but that doesn't seem to happen.

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


Re: Butterflow installation on windows

2014-10-12 Thread Mark Lawrence

On 11/10/2014 16:20, Virgil Stokes wrote:

The butterflow package (https://pypi.python.org/pypi/butterflow/0.1.4a1)
has recently been released. I would like to know if anyone has been able
to install it on a windows platform.


Short answer no.

Long answer follows.

c:\Users\Mark\PythonIssues>pip install -U --pre butterflow
Downloading/unpacking butterflow
  Downloading butterflow-0.1.4a1.tar.gz
  Running setup.py 
(path:C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\butterflow\setup.py) 
egg_info for package butterflow

Traceback (most recent call last):
  File "", line 17, in 
  File 
"C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\butterflow\setup.py", 
line 287, in 

py_includes = pkg_config_res('--cflags', 'python2')
  File 
"C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\butterflow\setup.py", 
line 205, in pkg_config_res

env=get_extra_envs()).stdout.read()
  File "C:\Python34\lib\subprocess.py", line 858, in __init__
restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line , in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file 
specified

Complete output from command python setup.py egg_info:
Traceback (most recent call last):

  File "", line 17, in 

  File 
"C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\butterflow\setup.py", 
line 287, in 


py_includes = pkg_config_res('--cflags', 'python2')

  File 
"C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\butterflow\setup.py", 
line 205, in pkg_config_res


env=get_extra_envs()).stdout.read()

  File "C:\Python34\lib\subprocess.py", line 858, in __init__

restore_signals, start_new_session)

  File "C:\Python34\lib\subprocess.py", line , in _execute_child

startupinfo)

FileNotFoundError: [WinError 2] The system cannot find the file specified


Cleaning up...
Command python setup.py egg_info failed with error code 1 in 
C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\butterflow

Storing debug log for failure in C:\Users\Mark\pip\pip.log

Quoting from 
http://pip.readthedocs.org/en/latest/reference/pip_install.html#options 
for the --pre flag "Include pre-release and development versions. By 
default, pip only finds stable versions."


Looking at the output above and at the URL you quote I doubt that it'll 
work for me as it seems to be Python 2 only.  The URL also lists a load 
of dependancies and I've no idea whether or not you could get them for 
Windows or not.  There's only one way to find out, so would you like to 
give it a go and let us know how you get on?


--
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: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 4:08 AM, Shiva
 wrote:
> Why is the second part of while condition not being checked?
>
> while ans.lower() != 'yes' or ans.lower()[0] != 'y':
>  ans = input('Do you like python?')
>
>
> My intention is if either of the conditions are true the loop should break.
> But the condition after 'or' doesn't seem to evaluate.

The loop will continue while either part is true - that's what "or"
means. Is that what you intended it to be doing?

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


while loop - multiple condition

2014-10-12 Thread Shiva
Why is the second part of while condition not being checked?

while ans.lower() != 'yes' or ans.lower()[0] != 'y':
 ans = input('Do you like python?')


My intention is if either of the conditions are true the loop should break.
But the condition after 'or' doesn't seem to evaluate.

Thanks,
Shiva.

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


Re: what is wrong with this script and how do I get the value in a php script

2014-10-12 Thread Peter Pearson
On Sun, 12 Oct 2014 07:24:52 -0700 (PDT), martijnperd...@gmail.com wrote:
> what is wrong with this script and how do I get the value Rij1 and 
> Rij2 and Rij3 and Rij4 and Rij5 and Rij6 in a php script
>
> import RPi.GPIO as GPIO
> GPIO.setmode(GPIO.BCM)
>
> GPIO.setup(17, GPIO.IN)
> GPIO.setup(18, GPIO.IN)
> GPIO.setup(21, GPIO.IN)
> GPIO.setup(22, GPIO.IN)
> GPIO.setup(23, GPIO.IN)
> GPIO.setup(24, GPIO.IN)
>
> Rij1 = 0
> Rij2 = 0
> Rij3 = 0
> Rij4 = 0
> Rij5 = 0
> Rij6 = 0
>
>
> while True:
> PRij1 = GPIO.input(17)
>   PRij2 = GPIO.input(18)
>   PRij3 = GPIO.input(21)
>   PRij4 = GPIO.input(22)
>   PRij5 = GPIO.input(23)
>   PRij6 = GPIO.input(24)
>
> if (PRij1 == False):
>   Rij1 = Rij1 + 1
>while PRij1 == False:
> PRij1 = GPIO.input(17)
[snip]

I regret that I can't solve your problem, but perhaps I can move
the conversation in a useful direction.

If this is a question about RPi.GPIO, it would be good to phrase it
as the simplest possible question about RPi.GPIO.  If it's *not* a
question about RPi.GPIO, it would be useful to replace the references
to RPi.GPIO with some artificial substitute, so that people who don't
have RPi.GPIO on their systems can contribute to the discussion.  For
example, I don't know what type of object is returned by GPIO.input.
Your code appears to assume that it's True or False, but I don't know
whether that's a valid assumption.

When asking why something doesn't work, one greatly improves one's
chances of getting a prompt and useful answer if one reveals precisely
(1) what one desires, and (2) what one gets.

Finally, the code you posted is indented in a way that is not legal Python,
leaving people to guess at what you intended to post.

And finally finally, why do you call this a PHP script?  This is a
Python newsgroup.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what is the easiest way to install multiple Python versions?

2014-10-12 Thread Gayathri J
I have been using Anaconda's (Continnum) conda installation for system
installation (python 2.7) and for python 3

conda lets us maintain diferent environments with different python and
different combinations of other packages like numpy etc...

sure not to disappoint!


On 10/12/14, Albert-Jan Roskam  wrote:
> Hi,
>
> (sorry for cross-posting)
>
> A few days ago I needed to check whether some Python code ran with Python
> 2.6. What is the easiest way to install another Python version along side
> the default Python version? My own computer is Debian Linux 64 bit, but a
> platform-independent solution would be best.
>
> Possible solutions that I am aware of
>
> -make altinstall *). This is what I tried (see below), but not all modules
> could be built. I gave up because I was in a hurry
> -Pythonbrew. This project is dead
> -Deadsnakes
> -Anaconda
> -Tox? I only know this is as a cross-version/implementation test runner
> -Vagrant. This is what I eventually did, and this was very simple. I ran
> Ubuntu 10.0.4 LTS, which uses Python 2.6, and used Vagrant SSH to run and
> check my code in Python 2.6 (and I replaced a dict comprehension with a list
> comprehension, for example)
> - ...
>
> What is the recommended way? I don't expect/hope that I'd ever need
> something lower than Python 2.5
>
> Thank you.
>
> Albert-Jan
>
>
> *) Make altinstall
> sudo apt-get install libsqlite3-dev libbz2-dev libgdbm-dev libncurses5-dev
> tk-dev zlib1g-dev
> wget https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz
> tar -zxvf Python-2.6.8.tgz
> cd Python-2.6.8/
> ./configure --prefix=/usr/local
> make  # see 'failed stuff' below
> sudo make altinstall
> mkvirtualenv -p /usr/local/bin/python2.6 python26  # ImportError: No module
> named zlib
>
>
> # Failed stuff
> Failed to find the necessary bits to build these modules:
> _bsddb_curses_curses_panel
> _hashlib  _sqlite3  _ssl
> bsddb185  bz2dbm
> dlgdbm  imageop
> linuxaudiodev  ossaudiodevreadline
> sunaudiodevzlib
>
>
>
>
>
> ~~
>
> All right, but apart from the sanitation, the medicine, education, wine,
> public order, irrigation, roads, a
>
> fresh water system, and public health, what have the Romans ever done for
> us?
>
> ~~
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


what is wrong with this script and how do I get the value in a php script

2014-10-12 Thread martijnperdaan
what is wrong with this script and how do I get the value Rij1 and Rij2 and 
Rij3 and Rij4 and Rij5 and Rij6 in a php script

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

GPIO.setup(17, GPIO.IN)
GPIO.setup(18, GPIO.IN)
GPIO.setup(21, GPIO.IN)
GPIO.setup(22, GPIO.IN)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)

Rij1 = 0
Rij2 = 0
Rij3 = 0
Rij4 = 0
Rij5 = 0
Rij6 = 0


while True:
PRij1 = GPIO.input(17)
PRij2 = GPIO.input(18)
PRij3 = GPIO.input(21)
PRij4 = GPIO.input(22)
PRij5 = GPIO.input(23)
PRij6 = GPIO.input(24)

if (PRij1 == False):
Rij1 = Rij1 + 1
   while PRij1 == False:
PRij1 = GPIO.input(17)

if (PRij2 == False):
Rij2 = Rij2 + 1
   while PRij2 == False:
PRij2 = GPIO.input(18)

if (PRij3 == False):
Rij3 = Rij3 + 1
   while PRij3 == False:
PRij3 = GPIO.input(21)

if (PRij4 == False):
Rij4 = Rij4 + 1
   while PRij4 == False:
PRij4 = GPIO.input(22)

if (PRij5 == False):
Rij5 = Rij5 + 1
   while PRij5 == False:
PRij5 = GPIO.input(23)

if (PRij6 == False):
Rij6 = Rij6 + 1
   while PRij6 == False:
PRij6 = GPIO.input(24)

Totaal = Rij1 + Rij2 + Rij3 + Rij4 + Rij5 + Rij6
print Totaal
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what is the easiest way to install multiple Python versions?

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 12:33 AM, Albert-Jan Roskam
 wrote:
> *) Make altinstall
> sudo apt-get install libsqlite3-dev libbz2-dev libgdbm-dev libncurses5-dev 
> tk-dev zlib1g-dev
> wget https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz
> tar -zxvf Python-2.6.8.tgz
> cd Python-2.6.8/
> ./configure --prefix=/usr/local
> make  # see 'failed stuff' below
> sudo make altinstall
> mkvirtualenv -p /usr/local/bin/python2.6 python26  # ImportError: No module 
> named zlib
>
>
> # Failed stuff
> Failed to find the necessary bits to build these modules:
> _bsddb_curses_curses_panel
> _hashlib  _sqlite3  _ssl
> bsddb185  bz2dbm
> dlgdbm  imageop
> linuxaudiodev  ossaudiodevreadline
> sunaudiodevzlib

Generally, this is the method I would recommend. For a start, run this:

sudo apt-get build-dep python

This is in place of your explicit "apt-get install" command; Debian
keeps track of the dev packages needed to rebuild a given program, and
will go fetch them for you.

After that, just look at exactly what packages you're still lacking.
You may well find that you don't have all the dependencies for all
Python modules, as some of them might not be included in a basic
"apt-get install python" installation; the solution is a bit more
"apt-get build-dep" work, or some manual hunting down of dev packages
(which may well be easier in some situations).

But what version of Debian are you after, and why are you trying to
build a 2.6.8 from source? On Debian Wheezy, getting hold of Python
2.6 should be as easy as:

$ sudo apt-get install python2.6

I believe Squeeze ships 2.6 as its standard system Python, so it's
even easier. Are you on the unreleased Jessie? And why do you even
need 2.6 as opposed to 2.7?

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


Re: Flask and Django

2014-10-12 Thread Chris Angelico
On Sat, Oct 11, 2014 at 9:22 AM, Juan Christian
 wrote:
> So, I'm already familiar with Flask and I fell comfortable using it, but I
> see that no one uses it in "real business", everywhere I look regarding jobs
> and web dev, people always talk about Django, no one mentions Flask, no one
> uses Flask.

I can't really say about job postings, but presumably you've done the
searches and found that to be the case. But there are plenty of jobs
around that don't specifically name the technologies you have to use.
If you're asked to create a web site from nothing, it doesn't much
matter what you use, as long as you get the job done.

The other thing to note is that job postings and resumes form a
feedback loop. Why bother mentioning Flask on your resume, if no
employers ever ask about it? Why bother looking for Flask programmers,
if nobody ever mentions having experience with it?

My personal recommendation: Stick to Flask. It's a good system, and
there's no reason to run away from it. (That said, I've yet to use
Django, and I've used Flask for exactly one web site, which is why I
didn't respond to you when you first posted.) Learn Django if you feel
you need to, but don't avoid Flask just because nobody ever asks you
about it for a job posting.

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


Re: TypeError: 'kwarg' is an invalid keyword argument for this function

2014-10-12 Thread Rustom Mody
Whats the problem??
Seems to work (python 2.7.8)

[Ive added a line so that that you can see]

class C:
   def __init__(self):
   pass

class C2(C):
def __init__(self, *args, **kwargs):
self.dic = kwargs
pass
x = C2(kwarg='a')
y = C2(kwarg='a', kwarg2=8)



>>> x.dic
{'kwarg': 'a'}
>>> y.dic
{'kwarg': 'a', 'kwarg2': 8}
>>> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flask and Django

2014-10-12 Thread Juan Christian
Anyone?

On Fri, Oct 10, 2014 at 7:22 PM, Juan Christian 
wrote:

> So, I'm already familiar with Flask and I fell comfortable using it, but I
> see that no one uses it in "real business", everywhere I look regarding
> jobs and web dev, people always talk about Django, no one mentions Flask,
> no one uses Flask.
>
> I'm coding a personal tool using Flask but I feel the need to "convert" it
> to Django because no ones seems to give attention to Flask, but no matter
> what, I don't like, I don't fully understand Django, there are tons of
> conventions, code generations and and too much red tape.
>
> Maybe that's because I feel the Django doc a bit confuse, I tried reading
> (and practicing!) tutorials, official doc, books, and so on, but I can't
> quite understand the whole thing.
>
> Is Flask really underestimated? Can you guys mention "big name" companies
> or people using it? Does it have real value in real world business?
>
-- 
https://mail.python.org/mailman/listinfo/python-list


what is the easiest way to install multiple Python versions?

2014-10-12 Thread Albert-Jan Roskam
Hi,

(sorry for cross-posting)

A few days ago I needed to check whether some Python code ran with Python 2.6. 
What is the easiest way to install another Python version along side the 
default Python version? My own computer is Debian Linux 64 bit, but a 
platform-independent solution would be best.

Possible solutions that I am aware of

-make altinstall *). This is what I tried (see below), but not all modules 
could be built. I gave up because I was in a hurry
-Pythonbrew. This project is dead
-Deadsnakes
-Anaconda
-Tox? I only know this is as a cross-version/implementation test runner
-Vagrant. This is what I eventually did, and this was very simple. I ran Ubuntu 
10.0.4 LTS, which uses Python 2.6, and used Vagrant SSH to run and check my 
code in Python 2.6 (and I replaced a dict comprehension with a list 
comprehension, for example)
- ...

What is the recommended way? I don't expect/hope that I'd ever need something 
lower than Python 2.5

Thank you.

Albert-Jan


*) Make altinstall
sudo apt-get install libsqlite3-dev libbz2-dev libgdbm-dev libncurses5-dev 
tk-dev zlib1g-dev
wget https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz
tar -zxvf Python-2.6.8.tgz
cd Python-2.6.8/
./configure --prefix=/usr/local
make  # see 'failed stuff' below
sudo make altinstall
mkvirtualenv -p /usr/local/bin/python2.6 python26  # ImportError: No module 
named zlib


# Failed stuff
Failed to find the necessary bits to build these modules:
_bsddb_curses_curses_panel
_hashlib  _sqlite3  _ssl
bsddb185  bz2dbm
dlgdbm  imageop
linuxaudiodev  ossaudiodevreadline
sunaudiodevzlib





~~

All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 

fresh water system, and public health, what have the Romans ever done for us?

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


TypeError: 'kwarg' is an invalid keyword argument for this function

2014-10-12 Thread roro codeath
How to implement it in my class?

class Str(str):
def __init__(self, *args, **kwargs):
pass

Str('smth', kwarg='a')

# How to implement in my class

class C:
   def __init__(self):
   pass

class C2(C):
def __init__(self, *args, **kwargs):
pass
C2(kwarg='a')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Parse bad xml file

2014-10-12 Thread Rustom Mody
On Friday, October 10, 2014 6:03:58 PM UTC+5:30, David Jobes wrote:
> On Friday, October 10, 2014 8:21:17 AM UTC-4, Peter Otten wrote:



> That did it, thank you, and in a lot fewer lines of code than i had, i was 
> trying to use strings and regex. i will read up more on the xml.etree stuff.

Those who parse xml/html with re's should read this --

http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

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


[RELEASED] Python 3.2.6, Python 3.3.6

2014-10-12 Thread Georg Brandl
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On behalf of the Python development team, I'm happy to announce
the release of Python 3.2.6 and 3.3.6.  Both are security-fix releases,
which are provided source-only on python.org.

The list of security-related issues fixed in the releases is given in
the changelogs:

https://hg.python.org/cpython/raw-file/v3.2.6/Misc/NEWS
https://hg.python.org/cpython/raw-file/v3.3.6/Misc/NEWS

To download the releases visit one of:

https://www.python.org/downloads/release/python-326/
https://www.python.org/downloads/release/python-336/

These are production versions, please report any bugs to

 http://bugs.python.org/

Enjoy!

- -- 
Georg Brandl, Release Manager
georg at python.org
(on behalf of the entire python-dev team and contributors)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iEYEARECAAYFAlQ6L/cACgkQN9GcIYhpnLBxIwCeLqjXeIOxGA2vkjbkN5Ic6j2u
7WcAoKgFaB4drMX5ZOVUJ4VLyNTcfycN
=KLlw
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list