Re: complete brain fart, it doesn't loop

2014-07-28 Thread Peter Otten
Chris Angelico wrote:

> On Mon, Jul 28, 2014 at 4:07 AM, Peter Otten <__pete...@web.de> wrote:
>> By the way, Python has something similar to a function that temporarily
>> interrupts execution but preserves state. It's called generator.
> 
> Yeah, but I have a suspicion his web framework (which he hasn't
> identified, but I suspect *any* web framework) won't be looking for a
> generator :) More likely, what he wants is to collect up the return
> values in a list, and then return ''.join() that list.

It was just a guess, but as the OP uses bottle, here's a modified 
"hello world" from the bottle site 
:

$ cat app.py 
from bottle import route, run

@route('/hello')
def hello():
yield "Hello "
yield "World!"

run(host='localhost', port=8080, debug=True)
$ python3 app.py &
[1] 3203
$ Bottle v0.12.7 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.


$ python3 -c 'from urllib.request import urlopen; 
print(urlopen("http://localhost:8080/hello";).read())'
127.0.0.1 - - [28/Jul/2014 09:07:15] "GET /hello HTTP/1.1" 200 12
b'Hello World!'
$ 


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


Re: complete brain fart, it doesn't loop

2014-07-28 Thread Chris Angelico
On Mon, Jul 28, 2014 at 5:09 PM, Peter Otten <__pete...@web.de> wrote:
>
> It was just a guess, but as the OP uses bottle, here's a modified
> "hello world" from the bottle site
> :
> (snip example of yielding text to the web browser)

Huh. Very cool! I like it. Was not aware that was possible.

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


reading text files with indentation

2014-07-28 Thread Noah

Hi there,

The following code I am using to read in lines from a text file.  The 
indentation of the text is getting lost.  How can I correct that?



for file in files:
with open (file, "r") as file:
lines = file.readlines()

for line in lines:
line = re.sub("#.*", "", line)
line = line.strip()
policy_lines.append(line)
print line

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


Re: reading text files with indentation

2014-07-28 Thread Peter Otten
Noah wrote:

> Hi there,
> 
> The following code I am using to read in lines from a text file.  The
> indentation of the text is getting lost.  How can I correct that?
> 
> 
>  for file in files:
>with open (file, "r") as file:
> lines = file.readlines()
> 
> for line in lines:
>  line = re.sub("#.*", "", line)
>  line = line.strip()
>  policy_lines.append(line)
>  print line
> 
> Cheers

for line in files:
with open(file) as lines:
for line in lines: # you can iterate over the file directly;
   # no need for the intermediate list built by
   # the readlines() method
line = line.partition("#")[0] # remove comment
line = line.rstrip() # remove trailing whitespace
policy_lines.append(line)
print line


If you want to keep trailing whitespace other than the newline replace

line = line.rstrip()

with 

line = line.rstrip("\n\r")




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


Re: reading text files with indentation

2014-07-28 Thread Gary Herron

On 07/27/2014 11:25 PM, Noah wrote:

Hi there,

The following code I am using to read in lines from a text file. The 
indentation of the text is getting lost.  How can I correct that?



for file in files:
  with open (file, "r") as file:
lines = file.readlines()

for line in lines:
line = re.sub("#.*", "", line)
line = line.strip()


The *strip* method on strings removes all whitespace from both ends.  
There goes your indentation.



policy_lines.append(line)
print line

Cheers


Example:

>>> "   abc   ".strip()
'abc'


Gary Herron

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


Re: What meaning of this ""hello %s you are %s years old" % x"

2014-07-28 Thread Albert-Jan Roskam



 
> That's not tuple%tuple, but rather string%tuple.  And string%tuple is 
> the older method of formatting an output string from a template and a 
> tuple of values.  See 
> https://docs.python.org/2/library/stdtypes.html#string-formatting for 
> details.
> 
> However, if you are just learning Python, you should probably use the 
> *newer* formatting operations.  See 
> https://docs.python.org/3.3/library/string.html#formatspec for details 
> of that.

Do you know what was the reason/consideration to switch to a new formatting 
operation? Ability to have custom formatters with an own __format__ method?

Regards,
Albert-Jan

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


Re: complete brain fart, it doesn't loop

2014-07-28 Thread Martin S
That's neat. I was only aware of the return version.

Anyway, got it working now, simplifying the code in the process. So
all was not lost.

/Martin S

2014-07-28 9:09 GMT+02:00 Peter Otten <__pete...@web.de>:
> Chris Angelico wrote:
>
>> On Mon, Jul 28, 2014 at 4:07 AM, Peter Otten <__pete...@web.de> wrote:
>>> By the way, Python has something similar to a function that temporarily
>>> interrupts execution but preserves state. It's called generator.
>>
>> Yeah, but I have a suspicion his web framework (which he hasn't
>> identified, but I suspect *any* web framework) won't be looking for a
>> generator :) More likely, what he wants is to collect up the return
>> values in a list, and then return ''.join() that list.
>
> It was just a guess, but as the OP uses bottle, here's a modified
> "hello world" from the bottle site
> :
>
> $ cat app.py
> from bottle import route, run
>
> @route('/hello')
> def hello():
> yield "Hello "
> yield "World!"
>
> run(host='localhost', port=8080, debug=True)
> $ python3 app.py &
> [1] 3203
> $ Bottle v0.12.7 server starting up (using WSGIRefServer())...
> Listening on http://localhost:8080/
> Hit Ctrl-C to quit.
>
>
> $ python3 -c 'from urllib.request import urlopen; 
> print(urlopen("http://localhost:8080/hello";).read())'
> 127.0.0.1 - - [28/Jul/2014 09:07:15] "GET /hello HTTP/1.1" 200 12
> b'Hello World!'
> $
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Regards,

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


Re: What meaning of this ""hello %s you are %s years old" % x"

2014-07-28 Thread Chris Angelico
On Mon, Jul 28, 2014 at 5:41 PM, Albert-Jan Roskam
 wrote:
>> That's not tuple%tuple, but rather string%tuple.  And string%tuple is
>> the older method of formatting an output string from a template and a
>> tuple of values.  See
>> https://docs.python.org/2/library/stdtypes.html#string-formatting for
>> details.
>>
>> However, if you are just learning Python, you should probably use the
>> *newer* formatting operations.  See
>> https://docs.python.org/3.3/library/string.html#formatspec for details
>> of that.
>
> Do you know what was the reason/consideration to switch to a new formatting 
> operation? Ability to have custom formatters with an own __format__ method?

Flexibility. You can do a few things with the other formatting style
that you can't do with percent-formatting. However, percent formatting
isn't going anywhere, and there's no particular reason to avoid it,
even in brand new code. It's more portable across languages (heaps of
C-inspired languages have a printf-style function that responds to the
same notations), more compact, and ample to a lot of situations, so
there's no need to go for the other style.

The only real downside of percent formatting is that, since it's an
operator rather than a function call, it can take only one argument -
so there's some magic with tuples, and a few extremely obscure corner
cases as a result. Not a reason to avoid it.

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


Re: rpath alike feature for python scripts

2014-07-28 Thread Olaf Hering
On Sat, Jul 26, dieter wrote:

> The "binary" corresponds to a script. The script could have
> a function "setup_path" which enhances "sys.path" as appropriate
> and ensure that this function is called near its beginning.

Yes, but how does it obtain the required values? In other words, at
buildtime /some/where is known because its the --prefix= value.
How does it know the remainder?

+sys.path.insert(0, "/some/where/lib64/python2.6/site-packages")


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


Re: .Net Like Gui Builder for Python?

2014-07-28 Thread Sturla Molden
Kevin Walzer  wrote:

> I'm not sure which GUI framework you use, but Tkinter is so simple to 
> code in directly that you don't really need a UI builder. Give that a try.

This is always true for GUI toolkits which use layout managers. A sketchpad
is much more useful. If you can quickly sketch ut how space should be
divided, there is no need for a GUI builder to construct the GUI. 

You need a GUI builder if the GUI is based on absolute positioning and
anchors, such as Delphi, VB and .NET. In this case manual coding of the GUI
will be extremely tedious.

If you try a GUI builder with layout managers (cf. wxFormBuilder) you will
also find that it does not behave as you expect. Most will just find it
annoying. But a GUI builder can be a nice way of avoiding having to
remember (or look up) all property names.

Sturla

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


Re: .Net Like Gui Builder for Python?

2014-07-28 Thread Sturla Molden
Michael Torrie  wrote:

> Pages '09 was the last good version.  The latest version is rubbish.
> Lots of removed features, crappy ui.  I think they took the stripped
> down ipad version and tried to make the new desktop version.

I think Apple has realized the mistake, because Pages is gradually
improving and removed features are coming back.

But even if Pages '09 were better, it is still superior to Word and
Publisher if you need a hybrid text processor and desktop publisher tool. 

An inexpensive alternative to MS Publisher on Mac OSX is iStudio Publisher.

Disclaimer: I still prefer LaTeX for anything but trivial manuscripts.


Sturla

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


Re: Prob. Code Downloaded for Programming the Semantic Web (python code)

2014-07-28 Thread Bruce Whealton
On Friday, July 25, 2014 9:28:32 PM UTC-4, Steven D'Aprano wrote:
> On Fri, 25 Jul 2014 17:06:17 -0700, Bruce Whealton wrote:
Steven,
See below please.  The explanation did help.   
> 
> > OK, Eclipse with PyDev doesn't like this first line, with the function:
> 
> > def add(self, (sub, pred, obj)):
> 
> 
> 
> In Python 2, you could include parenthesised parameters inside function
> declarations as above. That is effectively a short cut for this version,
> where you collect a single argument and then expand it into three
> variables:
> 
> 
> 
> def add(self, sub_pred_obj):
> 
> sub, pred, obj = sub_pred_obj
> 
I setup Eclipse to use python 2.7.x and tried to run this and it just gave an 
error on line 9 where the def add function is declared.  It just says invalid 
syntax and points at the parentheses that are in the function definition
def add(self, (subj, pred, obj)):
So, from what you said, and others, it seems like this should have worked but 
eclipse would not run it.  I could try to load it into IDLE.
> 
> 
> 
> In Python 3, that functionality was dropped and is no longer allowed. Now
> you have to use the longer form.
>
I'm not sure I follow what the longer method is.  Can you explain that more, 
please. 
> 
> 
> [...]
> 
> > There are other places where I thought that there were too many
> 
> > parentheses and I tried removing one set of them.  For example this
> 
> > snippet here:
> 
> > 
> 
> > def remove(self, (sub, pred, obj)):
> 
> > """
> 
> > Remove a triple pattern from the graph. """
> 
> > triples = list(self.triples((sub, pred, obj)))
> 
> 
> 
> Firstly, the remove method expects to take a *single* argument (remember
> 
> that self is automatically provided by Python) which is then automatically
> 
> expanded into three variables sub, pred, obj. So you have to call it with a
> 
> list or tuple of three items (or even a string of length exactly 3).
> 

> Then, having split this list or tuple into three items, it then joins them
> 
> back again into a tuple:
> 
> 
> 
> (sub, pred, obj)
 
> passes that tuple to the triples method:
 
> self.triples((sub, pred, obj))
> 
> 
> 
> (not shown, but presumably it uses the same parenthesised parameter trick),
> 
> and then converts whatever triples returns into a list:
> 
The full code listing should be available in the code paste link that I 
included.
> 
> 
> list(self.triples((sub, pred, obj)))
> 
> 
> 
> that list then being bound to the name "triples".
> 
> 
Thanks, the explanation helped,
Bruce
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Prob. Code Downloaded for Programming the Semantic Web (python code)

2014-07-28 Thread Bruce Whealton
On Friday, July 25, 2014 11:25:15 PM UTC-4, Chris Angelico wrote:
> On Sat, Jul 26, 2014 at 10:06 AM, Bruce Whealton
> 
Chris,
In response to your comments below, I'm comfortable changing this to use 
python 3.
> As others have said, this is something that changed in Python 3. So
> you have two parts to the problem: firstly, your code is bound to
> Python 2 by a triviality, and secondly, Eclipse is complaining about
> it.
> 
 
> 
> But a better solution, IMO, would be to avoid that implicit tuple
> unpacking. It's not a particularly clear feature, and I'm not sorry
> it's gone from Py3. The simplest way to change it is to just move it
> into the body:
> 

OK, that makes sense. So, I cut out the "Alternatively... " suggestion you made.
> 
> 
> def add(self, args):
> 
> sub, pred, obj = args
> 
> # rest of code as before
> 
> 
> 
> Preferably with a better name than 'args'.

Yes, I could call it triples. 
> 
> > triples = list(self.triples((sub, pred, obj)))
> 
> >
> 
> > Are the two sets parentheses needed after self.triples?  That syntax is
> 
> > confusing to me.  It seems that it should be
> 
> > triples = list(self.triples(sub, pred, obj))
> 
> 
> 
> No, that's correct. The extra parens force that triple to be a single
> 
> tuple of three items, rather than three separate arguments. Here's a
> 
> simpler example:
> 
> >>> lst = []
> 
> >>> lst.append(1,2,3)
> 
> Traceback (most recent call last):
> 
>   File "", line 1, in 
> 
> lst.append(1,2,3)
> 
> TypeError: append() takes exactly one argument (3 given)
> 
> >>> lst.append((1,2,3))
> 
> >>> addme = 4,5,6
> 
> >>> lst.append(addme)
> 
> >>> lst
> 
> [(1, 2, 3), (4, 5, 6)]
> 
> 
This is helpful and makes sense... clarifies it for me.
> 
> The list append method wants one argument, and appends that argument 
> to the list. Syntactically, the comma has multiple meanings; when I
> assign 4,5,6 to a single name, it makes a tuple, but in a function
> call, it separates args in the list. I don't see why the triples()
> function should be given a single argument, though; all it does is
> immediately unpack it. It'd be better to just remove the parens and 
> have separate args:
> 
 
> triples = list(self.triples(sub, pred, obj))
>
I didn't see the above in the code... Is this something I would need to add and 
if so, where? 
> 
> 
>def triples(self, sub, pred, obj):
> 
> 
> 
> While I'm looking at the code, a few other comments. I don't know how
> much of this is your code and how much came straight from the book,
> but either way, don't take this as criticism, but just as suggestions 
> for ways to get more out of Python.
> 
So far it is just from the book, and just serves as an example...  It is also a 
few years old, having been published in 2009.
> 
> 
> Inside remove(), you call a generator (triples() uses yield to return
> multiple values), then construct a list, and then iterate exactly once
> over that list. Much more efficient and clean to iterate directly over
> what triples() returns, as in save(); that's what generators are good
> for.
> 
> 
> 
> In triples(), the code is deeply nested and repetitive. I don't know
> if there's a way to truly solve that, but I would be inclined to 
> flatten it out a bit; maybe check for just one presence, to pick your
> index, and then merge some of the code that iterates over an index.
> Not sure though.
> 
I would have to get a better understanding of this.  
> 
> 
> (Also: It's conventional to use "is not None" rather than "!= None" to
> 
> test for singletons. It's possible for something to be equal to None
> 
> without actually being None.)
> 
> 
> 
> I would recommend moving to Python 3, if you can. Among other
> benefits, the Py3 csv module allows you to open a text file rather
> than opening a binary file and manually encoding/decoding all the
> parts separately. Alternatively, if you don't need this to be saving
> and loading another program's files, you could simply use a different
> file format, which would remove the restrictions (and messes) of the 
> CSV structure.

I was curious about why the binary flag was being used.  It just made no sense 
to me.
> 
> 
> 
> Instead of explicitly putting "f.close()" at the end of your load and
> save methods, check out the 'with' statement. It'll guarantee that the
> file's closed even if you leave early, get an exception, or anything
> 
> like that. Also, I'd tend to use the .decode() and .encode() methods,
> rather than the constructors. So here's how I'd write a Py2 load:

I would like to see this in python 3 format.
> 
> def load(self, filename):
> 
> with open(filename, "rb") as f:
> 
> for sub, pred, obj in csv.reader(f):
> 
> self.add((sub.decode("UTF-8"), pred.decode("UTF-8"),
> 
> obj.decode("UTF-8")))
> 
> 
> 
> (You might want to break that back out into three more lines, but this
> 
> parallels save(). If you break this one, you probably want to break
> 
> save() too.)
> 
> 
>

Re: one to many (passing variables)

2014-07-28 Thread Neil D. Cerutti

On 7/25/2014 9:47 PM, C.D. Reimer wrote:

Thank you for the link. I'm curious about one item mentioned in the
article: "Avoid return values that Demand Exceptional Processing: return
zero-length array or empty collection, not null"

Isn't a zero-length array, empty collection and null all the same thing?

Or does the "Demand Exceptional Processing" comes from testing to see if
the object is empty versus being null?


This seems like a specific application of a more general rule (I think I 
remember it from The C Programming Language by Kernighan and Ritchie): 
Whenever possible, manage special cases with data rather than with code. 
Doing so makes your data processing code simpler, and may help prevent 
errors.


This should apply to any programming language.

A mundane example is managing multi-line street addresses in a system 
storing addresses: most applications choose to store address lines as 
Street Address 1, through Street Address N, for some finite value of N, 
even though it results in special cases to handle. This is probably 
because it is more efficient: non-normalised data can be an efficiency 
win. Also, forgetting or refusing to handle the case of multi-line 
street addresses works "well enough" most of the time.


You could instead store multi-line street addresses as a list of 
components in the street address: Forgetting to handle the "special 
cases" would then be impossible. In order to do a cheesy job you'd have 
to explicitly retrieve street_address[0] and ignore the rest.


--
Neil Cerutti

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


Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2014-07-28 Thread chsqyuan
https://github.com/cdhigh/Visual-Tkinter-for-Python

This is a plugin for VB6, generate a full feature gui by using VB IDE.
-- 
https://mail.python.org/mailman/listinfo/python-list


Windows Studio 2008 Download

2014-07-28 Thread Colin J. Williams
I gather that Python is compiled with Windows Studio 2008.

Unfortunately, the MS Download link points to a Studio 2010 advertising .ppx

Could someone point to an alternative please?

Colin W.

PS  I need it for Numpy-1.8.1, which does not seem to be available with a
binary version.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows Studio 2008 Download

2014-07-28 Thread Joel Goldstick
I haven't tried it (linux guy), but people talk about using ActiveState's
binaries


On Mon, Jul 28, 2014 at 10:40 AM, Colin J. Williams 
wrote:

> I gather that Python is compiled with Windows Studio 2008.
>
> Unfortunately, the MS Download link points to a Studio 2010 advertising
> .ppx
>
> Could someone point to an alternative please?
>
> Colin W.
>
> PS  I need it for Numpy-1.8.1, which does not seem to be available with a
> binary version.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: Prob. Code Downloaded for Programming the Semantic Web (python code)

2014-07-28 Thread Steven D'Aprano
On Mon, 28 Jul 2014 03:39:48 -0700, Bruce Whealton wrote:

> I setup Eclipse to use python 2.7.x and tried to run this and it just
> gave an error on line 9 where the def add function is declared.

First step is to confirm that Eclipse actually is using Python 2.7. Can 
you get it to run this code instead? Put this in a module, and then run 
it:

import sys
print(sys.version)


Once you have confirmed that Eclipse really is running 2.7, next is to 
confirm what the syntax error actually is. Carefully check the source 
code that there are no missing close-parentheses just before the "def 
add" method. (Sometimes, a missing parenthesis won't show up as a Syntax 
Error until *after* the actual error.)

It may be helpful to see the exact syntax error. If possible, cut and 
paste (don't retype!) the full error message. It should look something 
like this:

py> def add(a, (b, c)):
  File "", line 1
def add(a, (b, c)):
   ^
SyntaxError: invalid syntax

Notice that the caret ^ points to where Python discovers the error.

If you confirm that Eclipse is using Python 2.7, but it still complains 
about the parenthesis, my guess -- and it's only a guess -- is that 
somehow you have an invisible or non-printing character inserted into the 
file at that position, and that's causing the Python parser to choke. I 
can demonstrate a working example indirectly, with the exec function:

py> exec("def x(a,(b,c)): pass")  # Works fine.
py> x


Now here it is again, but with an invisible control character inserted:

py> exec("def x(a,\a(b,c)): pass")
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1
def x(a,(b,c)): pass
^
SyntaxError: invalid syntax


Notice that when Python prints the error, the \a control character 
doesn't show up. It's there, but you can't see it.


> It just
> says invalid syntax and points at the parentheses that are in the
> function definition def add(self, (subj, pred, obj)):
> So, from what you said, and others, it seems like this should have
> worked but eclipse would not run it.  I could try to load it into IDLE.

Whenever you have trouble with one IDE, it's good to get a second opinion 
in another IDE. They might both be buggy, but they're unlikely to both 
have the same bug.

Also, try to run the file directly from the shell, without an IDE. from 
the system shell (cmd.exe if using Windows, bash or equivalent for 
Linux), run:

python27 /path/to/yourfile.py

You'll obviously need to adjust the pathname, possibly even give the full 
path to the Python executable.


[...]
>> In Python 3, that functionality was dropped and is no longer allowed.
>> Now you have to use the longer form.
>>
> I'm not sure I follow what the longer method is.  Can you explain that
> more, please.

I referred to the parenthesised parameter version as a short cut for a 
method that takes a single argument, then manually expands that argument 
into three items. Let me show them together to make it more obvious:

# Unparenthesised version, with manual step.
def add(self, sub_pred_obj):
sub, pred, obj = sub_pred_obj
do_stuff_with(sub or pred or obj)

# Parenthesised shortcut.
def add(self, (sub, pred, obj)):
do_stuff_with(sub or pred or obj)

Both methods take a single argument, which must be a sequence of exactly 
three values. The second version saves a single line, hence the first 
version is longer :-)


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


Re: Windows Studio 2008 Download

2014-07-28 Thread Ned Batchelder

On 7/28/14 10:40 AM, Colin J. Williams wrote:

I gather that Python is compiled with Windows Studio 2008.

Unfortunately, the MS Download link points to a Studio 2010 advertising .ppx

Could someone point to an alternative please?

Colin W.

PS  I need it for Numpy-1.8.1, which does not seem to be available with
a binary version.




Christoph Gohlke builds kits for windows:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy


--
Ned Batchelder, http://nedbatchelder.com

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


Re: Windows Studio 2008 Download

2014-07-28 Thread Chris Angelico
On Tue, Jul 29, 2014 at 12:40 AM, Colin J. Williams
 wrote:
> I gather that Python is compiled with Windows Studio 2008.
>
> Unfortunately, the MS Download link points to a Studio 2010 advertising .ppx
>
> Could someone point to an alternative please?

That would be specific to one particular version of Python; each
version is built with whatever compiler was current at the time. I'm
guessing you're talking about Python 2.7. This is one of the problems
with supporting Python 2.7 longer than Microsoft is supporting VS
2008.

> PS  I need it for Numpy-1.8.1, which does not seem to be available with a
> binary version.

You may be able to get a numpy binary from here:

http://www.lfd.uci.edu/~gohlke/pythonlibs/

But that's unofficial, so you're taking all the usual risks of
downloading binary code from third parties.

Are you able to migrate your project to Python 3? (If you weren't
using 2.7 after all, but were actually talking about 3.1 or 3.2, then
the answer to this is trivially "Yes".) The more recent Pythons are
built with more recent C compilers, so you could get Python 3.4 and
the correct compiler.

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


Re: Windows Studio 2008 Download

2014-07-28 Thread Irmen de Jong
On 28-7-2014 16:40, Colin J. Williams wrote:
> I gather that Python is compiled with Windows Studio 2008.
> 
> Unfortunately, the MS Download link points to a Studio 2010 advertising .ppx
> 
> Could someone point to an alternative please?
> 
> Colin W.
> 
> PS  I need it for Numpy-1.8.1, which does not seem to be available with a
> binary version.
> 



I haven't tried this, but installing the SDK should allow you to build 
extensions as
well for that particular Python build. Be sure to get the SDK that belongs to 
vs2008,
which is this one if I'm not mistaken:

http://www.microsoft.com/en-us/download/details.aspx?id=11310

It should install a command line c/c++ compiler as well and setting the right 
options
will tell pip/setuptools/... to use the sdk compiler rather than visual studio.


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


Re: Parse bug text file

2014-07-28 Thread CM
Thank you, Chris, Terry, and jmf, for these pointers.  Very helpful.

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


Re: one to many (passing variables)

2014-07-28 Thread Terry Reedy

On 7/25/2014 9:47 PM, C.D. Reimer wrote:


On 7/24/2014 2:58 AM, Ben Finney wrote:

Here is an article on good API design; the principles apply to Python
http://blog.isnotworking.com/2007/05/api-design-guidelines.html>.
You know your API and its requirements better than we; see whether that
sheds any light on improvements to make.

Thank you for the link. I'm curious about one item mentioned in the
article: "Avoid return values that Demand Exceptional Processing: return
zero-length array or empty collection, not null"

Isn't a zero-length array, empty collection and null all the same thing?


No. [] is an empty list, None is a null.


Or does the "Demand Exceptional Processing" comes from testing to see if
the object is empty versus being null?


Testing whether null or not.


And does this apply to Python?


Yes. If a function always returns a iterable, sometimes empty, it can be 
used as follows:


for item in f(): process(item)

If the iterable is empty, nothing happens.  If the function returns None 
instead of empty, then the use has to write the following to get the 
same result.


result = f()
if result is not None:
  for item in f(): process(item)

The function user may *elect* to give special processing to empty 
iterables.  A None return *demands* special processing, even if not 
needed, as above.


--
Terry Jan Reedy

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


Re: rpath alike feature for python scripts

2014-07-28 Thread Albert-Jan Roskam


- Original Message -

> From: Olaf Hering 
> To: dieter 
> Cc: python-list@python.org
> Sent: Monday, July 28, 2014 9:57 AM
> Subject: Re: rpath alike feature for python scripts
> 
> On Sat, Jul 26, dieter wrote:
> 
>>  The "binary" corresponds to a script. The script could have
>>  a function "setup_path" which enhances "sys.path" as 
> appropriate
>>  and ensure that this function is called near its beginning.
> 
> Yes, but how does it obtain the required values? In other words, at
> buildtime /some/where is known because its the --prefix= value.
> How does it know the remainder?

Hey, 

does this help: https://nixos.org/patchelf.html. It is not specific to Python, 
though.

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


Re: Windows Studio 2008 Download

2014-07-28 Thread TP
Hmmm. Now that I think about it the full Microsoft Visual Studio 2008
Service Pack 1 download I mentioned in my last email probably needs to have
Visual Studio 2008 already installed (it's been a number of years since I
had to install VS2008)? You could try it and see if it works.

If not download the free Express version I mentioned instead. Trying to
find the download link for the free VS2008 Express version is much harder
so I guess that's why people keep asking for it :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows Studio 2008 Download

2014-07-28 Thread Sturla Molden
You can download the Windows SDK for .NET 3.5, but it is very old.

A better option is to use GCC. The "static mingw toolchain" (gcc 4.8.2
based) created for building the official NumPy and SciPy binary installers
should be rather safe:

https://github.com/numpy/numpy/wiki/Mingw-static-toolchain

Sturla



"Colin J. Williams"  wrote:
> I gather that Python is compiled with Windows Studio 2008.
> 
> Unfortunately, the MS Download link points to a Studio 2010 advertising .ppx
> 
> Could someone point to an alternative please?
> 
> Colin W.
> 
> PS  I need it for Numpy-1.8.1, which does not seem to be available with a
> binary version.

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


Re: Windows Studio 2008 Download

2014-07-28 Thread Sturla Molden
Irmen de Jong  wrote:

> I haven't tried this, but installing the SDK should allow you to build 
> extensions as
> well for that particular Python build. Be sure to get the SDK that belongs to 
> vs2008,
> which is this one if I'm not mistaken:
> 
> http://www.microsoft.com/en-us/download/details.aspx?id=11310

This will work fine, if you remeber to set the environmental variable
DISTUTILS_USE_SDK=1

But it is an old compiler. Unfortunately a more recent Microsoft compiler
cannot be used.

I recommend a recent GCC or Intel compiler unless you have to use a
Microsoft compiler.

Sturla

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


[ANN] Pylint 1.3 / Astroid 1.2 released.

2014-07-28 Thread Claudiu Popa
Hello!

I'm happy to announce that Pylint 1.3 and Astroid 1.2 were released at
the end of the last week.
There has been a lot of enhancements and bug fixes since the latest
release, so you're strongly encouraged to upgrade. More information
about the changes in this release can be found here:
http://www.logilab.org/blogentry/259107.

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


gethostbyaddr()

2014-07-28 Thread Edward Manning
I wrote this code, but it seem to work fine if I only have one ip in the file. 
When I have more than one IP in the file 
I get a error. Does anyone have an idea why.


import socket
 
 
def main():
 
# get file names
infileName = input ("What file our the IP adderss in?  ")
outfileName = input("What file should the results go in?")
 
# open files
infile = open(infileName, "r")
outfile = open(outfileName, "w")
 
 
#Proccess each line of the input file
 
for line in infile:
ipAddress = line.strip()
resluts = socket.gethostbyaddr(ipAddress)
print(resluts[0],resluts[2], end="")-- 
https://mail.python.org/mailman/listinfo/python-list


Re: gethostbyaddr()

2014-07-28 Thread Chris Kaynor
On Mon, Jul 28, 2014 at 2:33 PM, Edward Manning 
wrote:

> I wrote this code, but it seem to work fine if I only have one ip in the
> file. When I have more than one IP in the file
>
> I get a error. Does anyone have an idea why.
>

It would be helpful to know what the error you are getting is. It is also a
good idea to generally provide the Python version and OS version with your
messages, as they can often make a major difference. As it is, I've made my
best guess below (in bold), I've also included some other notes that may
cause issues, but I doubt are causing your error.


> import socket
>
>
>
>
>
> def main():
>
>
>
> # get file names
>
> infileName = input ("What file our the IP adderss in?  ")
>
> outfileName = input("What file should the results go in?")
>
>
>
> # open files
>
> infile = open(infileName, "r")
>
> outfile = open(outfileName, "w")
>

While this shouldn't cause the issue your reporting (without other issues
going on), Its generally a better idea to use the with statement to open
file, like so:
with open(infileName, "r") as infile:
# code that needs infile goes here.

This will ensure that the file is closed when you are done with it, even if
an error occurs in the code that may prevent the code from running to
completion.


>
>
>
>
> #Proccess each line of the input file
>
>
>
> for line in infile:
>
> ipAddress = line.strip()
>

I'm guessing that, when you only have one IP, you do not have a trailing
new-line in the file, but when you put more than one in the file, you have
a trailing new-line. You can try adding:

if not ipAddress:
continue

here to ignore any empty lines (due to the line.strip() above, it will also
ignore all white-space lines) you might get. This may be the cause of your
error...


> resluts = socket.gethostbyaddr(ipAddress)
>
> print(resluts[0],resluts[2], end="")
>

Note that this does not seem to be printing into outfile (its printing to
stdout instead). I presume this is for debugging purposes.


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


Re: gethostbyaddr()

2014-07-28 Thread Edward Manning
Chris 

Thank you for the info.  I figure it out. But thank you again.

Ed 
> On Jul 28, 2014, at 5:42 PM, Chris Kaynor  wrote:
> 
> On Mon, Jul 28, 2014 at 2:33 PM, Edward Manning  wrote:
> I wrote this code, but it seem to work fine if I only have one ip in the 
> file. When I have more than one IP in the file 
> I get a error. Does anyone have an idea why.
> 
> It would be helpful to know what the error you are getting is. It is also a 
> good idea to generally provide the Python version and OS version with your 
> messages, as they can often make a major difference. As it is, I've made my 
> best guess below (in bold), I've also included some other notes that may 
> cause issues, but I doubt are causing your error.
>  
> import socket
>  
>  
> def main():
>  
> # get file names
> infileName = input ("What file our the IP adderss in?  ")
> outfileName = input("What file should the results go in?")
>  
> # open files
> infile = open(infileName, "r")
> outfile = open(outfileName, "w")
> 
> While this shouldn't cause the issue your reporting (without other issues 
> going on), Its generally a better idea to use the with statement to open 
> file, like so:
> with open(infileName, "r") as infile:
> # code that needs infile goes here.
> 
> This will ensure that the file is closed when you are done with it, even if 
> an error occurs in the code that may prevent the code from running to 
> completion.
>  
>  
>  
> #Proccess each line of the input file
>  
> for line in infile:
> ipAddress = line.strip()
> 
> I'm guessing that, when you only have one IP, you do not have a trailing 
> new-line in the file, but when you put more than one in the file, you have a 
> trailing new-line. You can try adding:
> 
> if not ipAddress:
> continue
> 
> here to ignore any empty lines (due to the line.strip() above, it will also 
> ignore all white-space lines) you might get. This may be the cause of your 
> error...
>  
> resluts = socket.gethostbyaddr(ipAddress)
> print(resluts[0],resluts[2], end="")
> 
> Note that this does not seem to be printing into outfile (its printing to 
> stdout instead). I presume this is for debugging purposes.
>  
> --
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Exploring Python for next desktop GUI Project

2014-07-28 Thread pecore

>> 2. Python 2 or 3? Which will serve me better in the future?
>
> Long term (7 years), [Python] 3.

I have STRONG suicidal intent and no access to treatment,
should I better learn Python 2?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exploring Python for next desktop GUI Project

2014-07-28 Thread Roy Smith
In article <87mwbtjg9r@pascolo.net>, pec...@pascolo.net wrote:

> >> 2. Python 2 or 3? Which will serve me better in the future?
> >
> > Long term (7 years), [Python] 3.
> 
> I have STRONG suicidal intent and no access to treatment,
> should I better learn Python 2?

In that case, go with PHP.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: one to many (passing variables)

2014-07-28 Thread CHIN Dihedral
On Tuesday, July 29, 2014 3:29:04 AM UTC+8, Terry Reedy wrote:
> On 7/25/2014 9:47 PM, C.D. Reimer wrote:
> 
> >
> 
> > On 7/24/2014 2:58 AM, Ben Finney wrote:
> 
> >> Here is an article on good API design; the principles apply to Python
> 
> >> http://blog.isnotworking.com/2007/05/api-design-guidelines.html>.
> 
> >> You know your API and its requirements better than we; see whether that
> 
> >> sheds any light on improvements to make.
> 
> > Thank you for the link. I'm curious about one item mentioned in the
> 
> > article: "Avoid return values that Demand Exceptional Processing: return
> 
> > zero-length array or empty collection, not null"
> 
> >
> 
> > Isn't a zero-length array, empty collection and null all the same thing?
> 
> 
> 
> No. [] is an empty list, None is a null.
> 
> 
> 
> > Or does the "Demand Exceptional Processing" comes from testing to see if
> 
> > the object is empty versus being null?
> 
> 
> 
> Testing whether null or not.
> 
> 
> 
> > And does this apply to Python?
> 
> 
> 
> Yes. If a function always returns a iterable, sometimes empty, it can be 
> 
> used as follows:
> 
> 
> 
> for item in f(): process(item)
> 
> 
> 
> If the iterable is empty, nothing happens.  If the function returns None 
> 
> instead of empty, then the use has to write the following to get the 
> 
> same result.
> 
> 
> 
> result = f()
> 
> if result is not None:
> 
>for item in f(): process(item)
> 
> 
> 
> The function user may *elect* to give special processing to empty 
> 
> iterables.  A None return *demands* special processing, even if not 
> 
> needed, as above.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

Oh, iterators are better to shoot 
targets in the L1 and L2 cache memory,
but it is not  the same as the old
 reading the whole list way.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Prob. Code Downloaded for Programming the Semantic Web (python code)

2014-07-28 Thread Bruce Whealton
On Monday, July 28, 2014 11:28:40 AM UTC-4, Steven D'Aprano wrote:
> On Mon, 28 Jul 2014 03:39:48 -0700, Bruce Whealton wrote:
Stephen,
I went to my Ubuntu box inside vmware and added a #!/usr/bin/env python2.7 
to the top.  Then I made the file executable and it ran the code perfectly. 

> 
> First step is to confirm that Eclipse actually is using Python 2.7. Can 
> 
> you get it to run this code instead? Put this in a module, and then run 
> 
> it:
> 
> 
> 
> import sys
> 
> print(sys.version)
> 
> 
I had both python2.7 and python3.4.  I could be less specific with my shebang 
line but what the heck.  
> 
> 
> 
I then installed pydev into my eclipse environment within the Ubuntu virtual 
machine and it ran the program just fine.  So, I suspect the extra character 
was 
only an issue on Windows.  I thought I had it setup to show even hidden 
characters.  
Anyway, thanks so much for all the help...everyone.  It might be interesting 
for me to convert this to a module that runs with python 3.
Bruce 
> 
> 
> > It just
> 
> > says invalid syntax and points at the parentheses that are in the
> 
> > function definition def add(self, (subj, pred, obj)):
> 
> > So, from what you said, and others, it seems like this should have
> 
> > worked but eclipse would not run it.  I could try to load it into IDLE.
> 
> 
> 
> Whenever you have trouble with one IDE, it's good to get a second opinion 
> 
> in another IDE. They might both be buggy, but they're unlikely to both 
> 
> have the same bug.
> 
> 
> 
> Also, try to run the file directly from the shell, without an IDE. from 
> 
> the system shell (cmd.exe if using Windows, bash or equivalent for 
> 
> Linux), run:
> 
> 
> 
> python27 /path/to/yourfile.py
> 
> 
> 
> You'll obviously need to adjust the pathname, possibly even give the full 
> 
> path to the Python executable.
> 
> 
> 
> 
> 
> [...]
> 
> >> In Python 3, that functionality was dropped and is no longer allowed.
> 
> >> Now you have to use the longer form.
> 
> >>
> 
> > I'm not sure I follow what the longer method is.  Can you explain that
> 
> > more, please.
> 
> 
> 
> I referred to the parenthesised parameter version as a short cut for a 
> 
> method that takes a single argument, then manually expands that argument 
> 
> into three items. Let me show them together to make it more obvious:
> 
> 
> 
> # Unparenthesised version, with manual step.
> 
> def add(self, sub_pred_obj):
> 
> sub, pred, obj = sub_pred_obj
> 
> do_stuff_with(sub or pred or obj)
> 
> 
> 
> # Parenthesised shortcut.
> 
> def add(self, (sub, pred, obj)):
> 
> do_stuff_with(sub or pred or obj)
> 
> 
> 
> Both methods take a single argument, which must be a sequence of exactly 
> 
> three values. The second version saves a single line, hence the first 
> 
> version is longer :-)
> 
> 
> 
> 
> 
> -- 
> 
> Steven

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


Re: rpath alike feature for python scripts

2014-07-28 Thread dieter
Olaf Hering  writes:

> On Sat, Jul 26, dieter wrote:
>
>> The "binary" corresponds to a script. The script could have
>> a function "setup_path" which enhances "sys.path" as appropriate
>> and ensure that this function is called near its beginning.
>
> Yes, but how does it obtain the required values? In other words, at
> buildtime /some/where is known because its the --prefix= value.
> How does it know the remainder?

You must tell it -- as you do for POSIX binaries.

For POSIX binaries, you specify the values as parameters for the
linker. Which Python scripts, you do not have a linker but you
can put the necessary values in the script itself - e.g. in the form
of an "RPATH = [...]" definition.

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


TypeError: 'NoneType' object is not callable

2014-07-28 Thread Satish ML
Hi,

TypeError: 'NoneType' object is not callable? Why this error and what is the 
solution?
Code:
class SuperMeta:
def __call__(self, classname, supers, classdict):
print('In SuperMeta.call: ', classname, supers, classdict, sep='\n...')
Class = self.__New__(classname, supers, classdict)
self.__Init__(Class, classname, supers, classdict)
class SubMeta(SuperMeta):
def __New__(self, classname, supers, classdict):
print('In SubMeta.new: ', classname, supers, classdict, sep='\n...')
return type(classname, supers, classdict)
def __Init__(self, Class, classname, supers, classdict):
print('In SubMeta init:', classname, supers, classdict, sep='\n...')
print('...init class object:', list(Class.__dict__.keys()))
class Eggs:
pass
print('making class')
class Spam(Eggs, metaclass=SubMeta()):
data = 1
def meth(self, arg):
pass
print('making instance')
X = Spam()

print('data:', X.data)
Output:
making class
In SuperMeta.call: 
...Spam
...(,)
...{'meth': , '__module__': 
'__main__', '__qualname__': 'Spam', 'data': 1}
In SubMeta.new: 
...Spam
...(,)
...{'meth': , '__module__': 
'__main__', '__qualname__': 'Spam', 'data': 1}
In SubMeta init:
...Spam
...(,)
...{'meth': , '__module__': 
'__main__', '__qualname__': 'Spam', 'data': 1}
...init class object: ['meth', '__module__', 'data', '__doc__']
making instance
Traceback (most recent call last):
  File "C:/Users/Satish/Desktop/Python/Metaclasses7.py", line 21, in 
X = Spam()
TypeError: 'NoneType' object is not callable
-- 
https://mail.python.org/mailman/listinfo/python-list